smartreflex.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 <plat/voltage.h>
  24. /*
  25. * Different Smartreflex IPs version. The v1 is the 65nm version used in
  26. * OMAP3430. The v2 is the update for the 45nm version of the IP
  27. * used in OMAP3630 and OMAP4430
  28. */
  29. #define SR_TYPE_V1 1
  30. #define SR_TYPE_V2 2
  31. /* SMART REFLEX REG ADDRESS OFFSET */
  32. #define SRCONFIG 0x00
  33. #define SRSTATUS 0x04
  34. #define SENVAL 0x08
  35. #define SENMIN 0x0C
  36. #define SENMAX 0x10
  37. #define SENAVG 0x14
  38. #define AVGWEIGHT 0x18
  39. #define NVALUERECIPROCAL 0x1c
  40. #define SENERROR_V1 0x20
  41. #define ERRCONFIG_V1 0x24
  42. #define IRQ_EOI 0x20
  43. #define IRQSTATUS_RAW 0x24
  44. #define IRQSTATUS 0x28
  45. #define IRQENABLE_SET 0x2C
  46. #define IRQENABLE_CLR 0x30
  47. #define SENERROR_V2 0x34
  48. #define ERRCONFIG_V2 0x38
  49. /* Bit/Shift Positions */
  50. /* SRCONFIG */
  51. #define SRCONFIG_ACCUMDATA_SHIFT 22
  52. #define SRCONFIG_SRCLKLENGTH_SHIFT 12
  53. #define SRCONFIG_SENNENABLE_V1_SHIFT 5
  54. #define SRCONFIG_SENPENABLE_V1_SHIFT 3
  55. #define SRCONFIG_SENNENABLE_V2_SHIFT 1
  56. #define SRCONFIG_SENPENABLE_V2_SHIFT 0
  57. #define SRCONFIG_CLKCTRL_SHIFT 0
  58. #define SRCONFIG_ACCUMDATA_MASK (0x3ff << 22)
  59. #define SRCONFIG_SRENABLE BIT(11)
  60. #define SRCONFIG_SENENABLE BIT(10)
  61. #define SRCONFIG_ERRGEN_EN BIT(9)
  62. #define SRCONFIG_MINMAXAVG_EN BIT(8)
  63. #define SRCONFIG_DELAYCTRL BIT(2)
  64. /* AVGWEIGHT */
  65. #define AVGWEIGHT_SENPAVGWEIGHT_SHIFT 2
  66. #define AVGWEIGHT_SENNAVGWEIGHT_SHIFT 0
  67. /* NVALUERECIPROCAL */
  68. #define NVALUERECIPROCAL_SENPGAIN_SHIFT 20
  69. #define NVALUERECIPROCAL_SENNGAIN_SHIFT 16
  70. #define NVALUERECIPROCAL_RNSENP_SHIFT 8
  71. #define NVALUERECIPROCAL_RNSENN_SHIFT 0
  72. /* ERRCONFIG */
  73. #define ERRCONFIG_ERRWEIGHT_SHIFT 16
  74. #define ERRCONFIG_ERRMAXLIMIT_SHIFT 8
  75. #define ERRCONFIG_ERRMINLIMIT_SHIFT 0
  76. #define SR_ERRWEIGHT_MASK (0x07 << 16)
  77. #define SR_ERRMAXLIMIT_MASK (0xff << 8)
  78. #define SR_ERRMINLIMIT_MASK (0xff << 0)
  79. #define ERRCONFIG_VPBOUNDINTEN_V1 BIT(31)
  80. #define ERRCONFIG_VPBOUNDINTST_V1 BIT(30)
  81. #define ERRCONFIG_MCUACCUMINTEN BIT(29)
  82. #define ERRCONFIG_MCUACCUMINTST BIT(28)
  83. #define ERRCONFIG_MCUVALIDINTEN BIT(27)
  84. #define ERRCONFIG_MCUVALIDINTST BIT(26)
  85. #define ERRCONFIG_MCUBOUNDINTEN BIT(25)
  86. #define ERRCONFIG_MCUBOUNDINTST BIT(24)
  87. #define ERRCONFIG_MCUDISACKINTEN BIT(23)
  88. #define ERRCONFIG_VPBOUNDINTST_V2 BIT(23)
  89. #define ERRCONFIG_MCUDISACKINTST BIT(22)
  90. #define ERRCONFIG_VPBOUNDINTEN_V2 BIT(22)
  91. #define ERRCONFIG_STATUS_V1_MASK (ERRCONFIG_VPBOUNDINTST_V1 | \
  92. ERRCONFIG_MCUACCUMINTST | \
  93. ERRCONFIG_MCUVALIDINTST | \
  94. ERRCONFIG_MCUBOUNDINTST | \
  95. ERRCONFIG_MCUDISACKINTST)
  96. /* IRQSTATUS */
  97. #define IRQSTATUS_MCUACCUMINT BIT(3)
  98. #define IRQSTATUS_MCVALIDINT BIT(2)
  99. #define IRQSTATUS_MCBOUNDSINT BIT(1)
  100. #define IRQSTATUS_MCUDISABLEACKINT BIT(0)
  101. /* IRQENABLE_SET and IRQENABLE_CLEAR */
  102. #define IRQENABLE_MCUACCUMINT BIT(3)
  103. #define IRQENABLE_MCUVALIDINT BIT(2)
  104. #define IRQENABLE_MCUBOUNDSINT BIT(1)
  105. #define IRQENABLE_MCUDISABLEACKINT BIT(0)
  106. /* Common Bit values */
  107. #define SRCLKLENGTH_12MHZ_SYSCLK 0x3c
  108. #define SRCLKLENGTH_13MHZ_SYSCLK 0x41
  109. #define SRCLKLENGTH_19MHZ_SYSCLK 0x60
  110. #define SRCLKLENGTH_26MHZ_SYSCLK 0x82
  111. #define SRCLKLENGTH_38MHZ_SYSCLK 0xC0
  112. /*
  113. * 3430 specific values. Maybe these should be passed from board file or
  114. * pmic structures.
  115. */
  116. #define OMAP3430_SR_ACCUMDATA 0x1f4
  117. #define OMAP3430_SR1_SENPAVGWEIGHT 0x03
  118. #define OMAP3430_SR1_SENNAVGWEIGHT 0x03
  119. #define OMAP3430_SR2_SENPAVGWEIGHT 0x01
  120. #define OMAP3430_SR2_SENNAVGWEIGHT 0x01
  121. #define OMAP3430_SR_ERRWEIGHT 0x04
  122. #define OMAP3430_SR_ERRMAXLIMIT 0x02
  123. struct omap_sr {
  124. char *name;
  125. struct list_head node;
  126. struct platform_device *pdev;
  127. struct omap_sr_nvalue_table *nvalue_table;
  128. struct voltagedomain *voltdm;
  129. struct dentry *dbg_dir;
  130. unsigned int irq;
  131. int srid;
  132. int ip_type;
  133. int nvalue_count;
  134. bool autocomp_active;
  135. u32 clk_length;
  136. u32 err_weight;
  137. u32 err_minlimit;
  138. u32 err_maxlimit;
  139. u32 accum_data;
  140. u32 senn_avgweight;
  141. u32 senp_avgweight;
  142. u32 senp_mod;
  143. u32 senn_mod;
  144. void __iomem *base;
  145. };
  146. /**
  147. * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
  148. * pmic specific info to smartreflex driver
  149. *
  150. * @sr_pmic_init: API to initialize smartreflex on the PMIC side.
  151. */
  152. struct omap_sr_pmic_data {
  153. void (*sr_pmic_init) (void);
  154. };
  155. /**
  156. * struct omap_smartreflex_dev_attr - Smartreflex Device attribute.
  157. *
  158. * @sensor_voltdm_name: Name of voltdomain of SR instance
  159. */
  160. struct omap_smartreflex_dev_attr {
  161. const char *sensor_voltdm_name;
  162. };
  163. #ifdef CONFIG_OMAP_SMARTREFLEX
  164. /*
  165. * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
  166. * The smartreflex class driver should pass the class type.
  167. * Should be used to populate the class_type field of the
  168. * omap_smartreflex_class_data structure.
  169. */
  170. #define SR_CLASS1 0x1
  171. #define SR_CLASS2 0x2
  172. #define SR_CLASS3 0x3
  173. /**
  174. * struct omap_sr_class_data - Smartreflex class driver info
  175. *
  176. * @enable: API to enable a particular class smaartreflex.
  177. * @disable: API to disable a particular class smartreflex.
  178. * @configure: API to configure a particular class smartreflex.
  179. * @notify: API to notify the class driver about an event in SR.
  180. * Not needed for class3.
  181. * @notify_flags: specify the events to be notified to the class driver
  182. * @class_type: specify which smartreflex class.
  183. * Can be used by the SR driver to take any class
  184. * based decisions.
  185. */
  186. struct omap_sr_class_data {
  187. int (*enable)(struct omap_sr *sr);
  188. int (*disable)(struct omap_sr *sr, int is_volt_reset);
  189. int (*configure)(struct omap_sr *sr);
  190. int (*notify)(struct omap_sr *sr, u32 status);
  191. u8 notify_flags;
  192. u8 class_type;
  193. };
  194. /**
  195. * struct omap_sr_nvalue_table - Smartreflex n-target value info
  196. *
  197. * @efuse_offs: The offset of the efuse where n-target values are stored.
  198. * @nvalue: The n-target value.
  199. */
  200. struct omap_sr_nvalue_table {
  201. u32 efuse_offs;
  202. u32 nvalue;
  203. };
  204. /**
  205. * struct omap_sr_data - Smartreflex platform data.
  206. *
  207. * @name: instance name
  208. * @ip_type: Smartreflex IP type.
  209. * @senp_mod: SENPENABLE value for the sr
  210. * @senn_mod: SENNENABLE value for sr
  211. * @nvalue_count: Number of distinct nvalues in the nvalue table
  212. * @enable_on_init: whether this sr module needs to enabled at
  213. * boot up or not.
  214. * @nvalue_table: table containing the efuse offsets and nvalues
  215. * corresponding to them.
  216. * @voltdm: Pointer to the voltage domain associated with the SR
  217. */
  218. struct omap_sr_data {
  219. const char *name;
  220. int ip_type;
  221. u32 senp_mod;
  222. u32 senn_mod;
  223. int nvalue_count;
  224. bool enable_on_init;
  225. struct omap_sr_nvalue_table *nvalue_table;
  226. struct voltagedomain *voltdm;
  227. };
  228. /* Smartreflex module enable/disable interface */
  229. void omap_sr_enable(struct voltagedomain *voltdm);
  230. void omap_sr_disable(struct voltagedomain *voltdm);
  231. void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
  232. /* API to register the pmic specific data with the smartreflex driver. */
  233. void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
  234. /* Smartreflex driver hooks to be called from Smartreflex class driver */
  235. int sr_enable(struct voltagedomain *voltdm, unsigned long volt);
  236. void sr_disable(struct voltagedomain *voltdm);
  237. int sr_configure_errgen(struct voltagedomain *voltdm);
  238. int sr_disable_errgen(struct voltagedomain *voltdm);
  239. int sr_configure_minmax(struct voltagedomain *voltdm);
  240. /* API to register the smartreflex class driver with the smartreflex driver */
  241. int sr_register_class(struct omap_sr_class_data *class_data);
  242. #else
  243. static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
  244. static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
  245. static inline void omap_sr_disable_reset_volt(
  246. struct voltagedomain *voltdm) {}
  247. static inline void omap_sr_register_pmic(
  248. struct omap_sr_pmic_data *pmic_data) {}
  249. #endif
  250. #endif