smartreflex.h 9.3 KB

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