smartreflex.h 7.4 KB

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