smartreflex.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * OMAP Smartreflex Defines and Routines
  3. *
  4. * Author: Thara Gopinath <thara@ti.com>
  5. *
  6. * Copyright (C) 2010 Texas Instruments, Inc.
  7. * Thara Gopinath <thara@ti.com>
  8. *
  9. * Copyright (C) 2008 Nokia Corporation
  10. * Kalle Jokiniemi
  11. *
  12. * Copyright (C) 2007 Texas Instruments, Inc.
  13. * Lesly A M <x0080970@ti.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. */
  19. #ifndef __POWER_SMARTREFLEX_H
  20. #define __POWER_SMARTREFLEX_H
  21. #include <linux/types.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/delay.h>
  24. #include <linux/platform_data/voltage-omap.h>
  25. /*
  26. * Different Smartreflex IPs version. The v1 is the 65nm version used in
  27. * OMAP3430. The v2 is the update for the 45nm version of the IP
  28. * used in OMAP3630 and OMAP4430
  29. */
  30. #define SR_TYPE_V1 1
  31. #define SR_TYPE_V2 2
  32. /* SMART REFLEX REG ADDRESS OFFSET */
  33. #define SRCONFIG 0x00
  34. #define SRSTATUS 0x04
  35. #define SENVAL 0x08
  36. #define SENMIN 0x0C
  37. #define SENMAX 0x10
  38. #define SENAVG 0x14
  39. #define AVGWEIGHT 0x18
  40. #define NVALUERECIPROCAL 0x1c
  41. #define SENERROR_V1 0x20
  42. #define ERRCONFIG_V1 0x24
  43. #define IRQ_EOI 0x20
  44. #define IRQSTATUS_RAW 0x24
  45. #define IRQSTATUS 0x28
  46. #define IRQENABLE_SET 0x2C
  47. #define IRQENABLE_CLR 0x30
  48. #define SENERROR_V2 0x34
  49. #define ERRCONFIG_V2 0x38
  50. /* Bit/Shift Positions */
  51. /* SRCONFIG */
  52. #define SRCONFIG_ACCUMDATA_SHIFT 22
  53. #define SRCONFIG_SRCLKLENGTH_SHIFT 12
  54. #define SRCONFIG_SENNENABLE_V1_SHIFT 5
  55. #define SRCONFIG_SENPENABLE_V1_SHIFT 3
  56. #define SRCONFIG_SENNENABLE_V2_SHIFT 1
  57. #define SRCONFIG_SENPENABLE_V2_SHIFT 0
  58. #define SRCONFIG_CLKCTRL_SHIFT 0
  59. #define SRCONFIG_ACCUMDATA_MASK (0x3ff << 22)
  60. #define SRCONFIG_SRENABLE BIT(11)
  61. #define SRCONFIG_SENENABLE BIT(10)
  62. #define SRCONFIG_ERRGEN_EN BIT(9)
  63. #define SRCONFIG_MINMAXAVG_EN BIT(8)
  64. #define SRCONFIG_DELAYCTRL BIT(2)
  65. /* AVGWEIGHT */
  66. #define AVGWEIGHT_SENPAVGWEIGHT_SHIFT 2
  67. #define AVGWEIGHT_SENNAVGWEIGHT_SHIFT 0
  68. /* NVALUERECIPROCAL */
  69. #define NVALUERECIPROCAL_SENPGAIN_SHIFT 20
  70. #define NVALUERECIPROCAL_SENNGAIN_SHIFT 16
  71. #define NVALUERECIPROCAL_RNSENP_SHIFT 8
  72. #define NVALUERECIPROCAL_RNSENN_SHIFT 0
  73. /* ERRCONFIG */
  74. #define ERRCONFIG_ERRWEIGHT_SHIFT 16
  75. #define ERRCONFIG_ERRMAXLIMIT_SHIFT 8
  76. #define ERRCONFIG_ERRMINLIMIT_SHIFT 0
  77. #define SR_ERRWEIGHT_MASK (0x07 << 16)
  78. #define SR_ERRMAXLIMIT_MASK (0xff << 8)
  79. #define SR_ERRMINLIMIT_MASK (0xff << 0)
  80. #define ERRCONFIG_VPBOUNDINTEN_V1 BIT(31)
  81. #define ERRCONFIG_VPBOUNDINTST_V1 BIT(30)
  82. #define ERRCONFIG_MCUACCUMINTEN BIT(29)
  83. #define ERRCONFIG_MCUACCUMINTST BIT(28)
  84. #define ERRCONFIG_MCUVALIDINTEN BIT(27)
  85. #define ERRCONFIG_MCUVALIDINTST BIT(26)
  86. #define ERRCONFIG_MCUBOUNDINTEN BIT(25)
  87. #define ERRCONFIG_MCUBOUNDINTST BIT(24)
  88. #define ERRCONFIG_MCUDISACKINTEN BIT(23)
  89. #define ERRCONFIG_VPBOUNDINTST_V2 BIT(23)
  90. #define ERRCONFIG_MCUDISACKINTST BIT(22)
  91. #define ERRCONFIG_VPBOUNDINTEN_V2 BIT(22)
  92. #define ERRCONFIG_STATUS_V1_MASK (ERRCONFIG_VPBOUNDINTST_V1 | \
  93. ERRCONFIG_MCUACCUMINTST | \
  94. ERRCONFIG_MCUVALIDINTST | \
  95. ERRCONFIG_MCUBOUNDINTST | \
  96. ERRCONFIG_MCUDISACKINTST)
  97. /* IRQSTATUS */
  98. #define IRQSTATUS_MCUACCUMINT BIT(3)
  99. #define IRQSTATUS_MCVALIDINT BIT(2)
  100. #define IRQSTATUS_MCBOUNDSINT BIT(1)
  101. #define IRQSTATUS_MCUDISABLEACKINT BIT(0)
  102. /* IRQENABLE_SET and IRQENABLE_CLEAR */
  103. #define IRQENABLE_MCUACCUMINT BIT(3)
  104. #define IRQENABLE_MCUVALIDINT BIT(2)
  105. #define IRQENABLE_MCUBOUNDSINT BIT(1)
  106. #define IRQENABLE_MCUDISABLEACKINT BIT(0)
  107. /* Common Bit values */
  108. #define SRCLKLENGTH_12MHZ_SYSCLK 0x3c
  109. #define SRCLKLENGTH_13MHZ_SYSCLK 0x41
  110. #define SRCLKLENGTH_19MHZ_SYSCLK 0x60
  111. #define SRCLKLENGTH_26MHZ_SYSCLK 0x82
  112. #define SRCLKLENGTH_38MHZ_SYSCLK 0xC0
  113. /*
  114. * 3430 specific values. Maybe these should be passed from board file or
  115. * pmic structures.
  116. */
  117. #define OMAP3430_SR_ACCUMDATA 0x1f4
  118. #define OMAP3430_SR1_SENPAVGWEIGHT 0x03
  119. #define OMAP3430_SR1_SENNAVGWEIGHT 0x03
  120. #define OMAP3430_SR2_SENPAVGWEIGHT 0x01
  121. #define OMAP3430_SR2_SENNAVGWEIGHT 0x01
  122. #define OMAP3430_SR_ERRWEIGHT 0x04
  123. #define OMAP3430_SR_ERRMAXLIMIT 0x02
  124. struct omap_sr {
  125. char *name;
  126. struct list_head node;
  127. struct platform_device *pdev;
  128. struct omap_sr_nvalue_table *nvalue_table;
  129. struct voltagedomain *voltdm;
  130. struct dentry *dbg_dir;
  131. unsigned int irq;
  132. int srid;
  133. int ip_type;
  134. int nvalue_count;
  135. bool autocomp_active;
  136. u32 clk_length;
  137. u32 err_weight;
  138. u32 err_minlimit;
  139. u32 err_maxlimit;
  140. u32 accum_data;
  141. u32 senn_avgweight;
  142. u32 senp_avgweight;
  143. u32 senp_mod;
  144. u32 senn_mod;
  145. void __iomem *base;
  146. };
  147. /**
  148. * test_cond_timeout - busy-loop, testing a condition
  149. * @cond: condition to test until it evaluates to true
  150. * @timeout: maximum number of microseconds in the timeout
  151. * @index: loop index (integer)
  152. *
  153. * Loop waiting for @cond to become true or until at least @timeout
  154. * microseconds have passed. To use, define some integer @index in the
  155. * calling code. After running, if @index == @timeout, then the loop has
  156. * timed out.
  157. *
  158. * Copied from omap_test_timeout */
  159. #define sr_test_cond_timeout(cond, timeout, index) \
  160. ({ \
  161. for (index = 0; index < timeout; index++) { \
  162. if (cond) \
  163. break; \
  164. udelay(1); \
  165. } \
  166. })
  167. /**
  168. * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
  169. * pmic specific info to smartreflex driver
  170. *
  171. * @sr_pmic_init: API to initialize smartreflex on the PMIC side.
  172. */
  173. struct omap_sr_pmic_data {
  174. void (*sr_pmic_init) (void);
  175. };
  176. /**
  177. * struct omap_smartreflex_dev_attr - Smartreflex Device attribute.
  178. *
  179. * @sensor_voltdm_name: Name of voltdomain of SR instance
  180. */
  181. struct omap_smartreflex_dev_attr {
  182. const char *sensor_voltdm_name;
  183. };
  184. #ifdef CONFIG_POWER_AVS_OMAP
  185. /*
  186. * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
  187. * The smartreflex class driver should pass the class type.
  188. * Should be used to populate the class_type field of the
  189. * omap_smartreflex_class_data structure.
  190. */
  191. #define SR_CLASS1 0x1
  192. #define SR_CLASS2 0x2
  193. #define SR_CLASS3 0x3
  194. /**
  195. * struct omap_sr_class_data - Smartreflex class driver info
  196. *
  197. * @enable: API to enable a particular class smaartreflex.
  198. * @disable: API to disable a particular class smartreflex.
  199. * @configure: API to configure a particular class smartreflex.
  200. * @notify: API to notify the class driver about an event in SR.
  201. * Not needed for class3.
  202. * @notify_flags: specify the events to be notified to the class driver
  203. * @class_type: specify which smartreflex class.
  204. * Can be used by the SR driver to take any class
  205. * based decisions.
  206. */
  207. struct omap_sr_class_data {
  208. int (*enable)(struct omap_sr *sr);
  209. int (*disable)(struct omap_sr *sr, int is_volt_reset);
  210. int (*configure)(struct omap_sr *sr);
  211. int (*notify)(struct omap_sr *sr, u32 status);
  212. u8 notify_flags;
  213. u8 class_type;
  214. };
  215. /**
  216. * struct omap_sr_nvalue_table - Smartreflex n-target value info
  217. *
  218. * @efuse_offs: The offset of the efuse where n-target values are stored.
  219. * @nvalue: The n-target value.
  220. * @errminlimit: The value of the ERRMINLIMIT bitfield for this n-target
  221. * @volt_nominal: microvolts DC that the VDD is initially programmed to
  222. */
  223. struct omap_sr_nvalue_table {
  224. u32 efuse_offs;
  225. u32 nvalue;
  226. u32 errminlimit;
  227. unsigned long volt_nominal;
  228. };
  229. /**
  230. * struct omap_sr_data - Smartreflex platform data.
  231. *
  232. * @name: instance name
  233. * @ip_type: Smartreflex IP type.
  234. * @senp_mod: SENPENABLE value of the sr CONFIG register
  235. * @senn_mod: SENNENABLE value for sr CONFIG register
  236. * @err_weight ERRWEIGHT value of the sr ERRCONFIG register
  237. * @err_maxlimit ERRMAXLIMIT value of the sr ERRCONFIG register
  238. * @accum_data ACCUMDATA value of the sr CONFIG register
  239. * @senn_avgweight SENNAVGWEIGHT value of the sr AVGWEIGHT register
  240. * @senp_avgweight SENPAVGWEIGHT value of the sr AVGWEIGHT register
  241. * @nvalue_count: Number of distinct nvalues in the nvalue table
  242. * @enable_on_init: whether this sr module needs to enabled at
  243. * boot up or not.
  244. * @nvalue_table: table containing the efuse offsets and nvalues
  245. * corresponding to them.
  246. * @voltdm: Pointer to the voltage domain associated with the SR
  247. */
  248. struct omap_sr_data {
  249. const char *name;
  250. int ip_type;
  251. u32 senp_mod;
  252. u32 senn_mod;
  253. u32 err_weight;
  254. u32 err_maxlimit;
  255. u32 accum_data;
  256. u32 senn_avgweight;
  257. u32 senp_avgweight;
  258. int nvalue_count;
  259. bool enable_on_init;
  260. struct omap_sr_nvalue_table *nvalue_table;
  261. struct voltagedomain *voltdm;
  262. };
  263. /* Smartreflex module enable/disable interface */
  264. void omap_sr_enable(struct voltagedomain *voltdm);
  265. void omap_sr_disable(struct voltagedomain *voltdm);
  266. void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
  267. /* API to register the pmic specific data with the smartreflex driver. */
  268. void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
  269. /* Smartreflex driver hooks to be called from Smartreflex class driver */
  270. int sr_enable(struct omap_sr *sr, unsigned long volt);
  271. void sr_disable(struct omap_sr *sr);
  272. int sr_configure_errgen(struct omap_sr *sr);
  273. int sr_disable_errgen(struct omap_sr *sr);
  274. int sr_configure_minmax(struct omap_sr *sr);
  275. /* API to register the smartreflex class driver with the smartreflex driver */
  276. int sr_register_class(struct omap_sr_class_data *class_data);
  277. #else
  278. static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
  279. static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
  280. static inline void omap_sr_disable_reset_volt(
  281. struct voltagedomain *voltdm) {}
  282. static inline void omap_sr_register_pmic(
  283. struct omap_sr_pmic_data *pmic_data) {}
  284. #endif
  285. #endif