1 /* SPDX-License-Identifier: GPL-2.0 */
3 * OMAP Smartreflex Defines and Routines
7 * Copyright (C) 2010 Texas Instruments, Inc.
10 * Copyright (C) 2008 Nokia Corporation
13 * Copyright (C) 2007 Texas Instruments, Inc.
17 #ifndef __POWER_SMARTREFLEX_H
18 #define __POWER_SMARTREFLEX_H
20 #include <linux/types.h>
21 #include <linux/platform_device.h>
22 #include <linux/delay.h>
23 #include <linux/platform_data/voltage-omap.h>
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
33 /* SMART REFLEX REG ADDRESS OFFSET */
40 #define AVGWEIGHT 0x18
41 #define NVALUERECIPROCAL 0x1c
42 #define SENERROR_V1 0x20
43 #define ERRCONFIG_V1 0x24
45 #define IRQSTATUS_RAW 0x24
46 #define IRQSTATUS 0x28
47 #define IRQENABLE_SET 0x2C
48 #define IRQENABLE_CLR 0x30
49 #define SENERROR_V2 0x34
50 #define ERRCONFIG_V2 0x38
52 /* Bit/Shift Positions */
55 #define SRCONFIG_ACCUMDATA_SHIFT 22
56 #define SRCONFIG_SRCLKLENGTH_SHIFT 12
57 #define SRCONFIG_SENNENABLE_V1_SHIFT 5
58 #define SRCONFIG_SENPENABLE_V1_SHIFT 3
59 #define SRCONFIG_SENNENABLE_V2_SHIFT 1
60 #define SRCONFIG_SENPENABLE_V2_SHIFT 0
61 #define SRCONFIG_CLKCTRL_SHIFT 0
63 #define SRCONFIG_ACCUMDATA_MASK (0x3ff << 22)
65 #define SRCONFIG_SRENABLE BIT(11)
66 #define SRCONFIG_SENENABLE BIT(10)
67 #define SRCONFIG_ERRGEN_EN BIT(9)
68 #define SRCONFIG_MINMAXAVG_EN BIT(8)
69 #define SRCONFIG_DELAYCTRL BIT(2)
72 #define AVGWEIGHT_SENPAVGWEIGHT_SHIFT 2
73 #define AVGWEIGHT_SENNAVGWEIGHT_SHIFT 0
75 /* NVALUERECIPROCAL */
76 #define NVALUERECIPROCAL_SENPGAIN_SHIFT 20
77 #define NVALUERECIPROCAL_SENNGAIN_SHIFT 16
78 #define NVALUERECIPROCAL_RNSENP_SHIFT 8
79 #define NVALUERECIPROCAL_RNSENN_SHIFT 0
82 #define ERRCONFIG_ERRWEIGHT_SHIFT 16
83 #define ERRCONFIG_ERRMAXLIMIT_SHIFT 8
84 #define ERRCONFIG_ERRMINLIMIT_SHIFT 0
86 #define SR_ERRWEIGHT_MASK (0x07 << 16)
87 #define SR_ERRMAXLIMIT_MASK (0xff << 8)
88 #define SR_ERRMINLIMIT_MASK (0xff << 0)
90 #define ERRCONFIG_VPBOUNDINTEN_V1 BIT(31)
91 #define ERRCONFIG_VPBOUNDINTST_V1 BIT(30)
92 #define ERRCONFIG_MCUACCUMINTEN BIT(29)
93 #define ERRCONFIG_MCUACCUMINTST BIT(28)
94 #define ERRCONFIG_MCUVALIDINTEN BIT(27)
95 #define ERRCONFIG_MCUVALIDINTST BIT(26)
96 #define ERRCONFIG_MCUBOUNDINTEN BIT(25)
97 #define ERRCONFIG_MCUBOUNDINTST BIT(24)
98 #define ERRCONFIG_MCUDISACKINTEN BIT(23)
99 #define ERRCONFIG_VPBOUNDINTST_V2 BIT(23)
100 #define ERRCONFIG_MCUDISACKINTST BIT(22)
101 #define ERRCONFIG_VPBOUNDINTEN_V2 BIT(22)
103 #define ERRCONFIG_STATUS_V1_MASK (ERRCONFIG_VPBOUNDINTST_V1 | \
104 ERRCONFIG_MCUACCUMINTST | \
105 ERRCONFIG_MCUVALIDINTST | \
106 ERRCONFIG_MCUBOUNDINTST | \
107 ERRCONFIG_MCUDISACKINTST)
109 #define IRQSTATUS_MCUACCUMINT BIT(3)
110 #define IRQSTATUS_MCVALIDINT BIT(2)
111 #define IRQSTATUS_MCBOUNDSINT BIT(1)
112 #define IRQSTATUS_MCUDISABLEACKINT BIT(0)
114 /* IRQENABLE_SET and IRQENABLE_CLEAR */
115 #define IRQENABLE_MCUACCUMINT BIT(3)
116 #define IRQENABLE_MCUVALIDINT BIT(2)
117 #define IRQENABLE_MCUBOUNDSINT BIT(1)
118 #define IRQENABLE_MCUDISABLEACKINT BIT(0)
120 /* Common Bit values */
122 #define SRCLKLENGTH_12MHZ_SYSCLK 0x3c
123 #define SRCLKLENGTH_13MHZ_SYSCLK 0x41
124 #define SRCLKLENGTH_19MHZ_SYSCLK 0x60
125 #define SRCLKLENGTH_26MHZ_SYSCLK 0x82
126 #define SRCLKLENGTH_38MHZ_SYSCLK 0xC0
129 * 3430 specific values. Maybe these should be passed from board file or
132 #define OMAP3430_SR_ACCUMDATA 0x1f4
134 #define OMAP3430_SR1_SENPAVGWEIGHT 0x03
135 #define OMAP3430_SR1_SENNAVGWEIGHT 0x03
137 #define OMAP3430_SR2_SENPAVGWEIGHT 0x01
138 #define OMAP3430_SR2_SENNAVGWEIGHT 0x01
140 #define OMAP3430_SR_ERRWEIGHT 0x04
141 #define OMAP3430_SR_ERRMAXLIMIT 0x02
144 OMAP_SR_MPU, /* shared with iva on omap3 */
152 struct list_head node;
153 struct platform_device *pdev;
154 struct omap_sr_nvalue_table *nvalue_table;
155 struct voltagedomain *voltdm;
156 struct dentry *dbg_dir;
161 bool autocomp_active;
175 * test_cond_timeout - busy-loop, testing a condition
176 * @cond: condition to test until it evaluates to true
177 * @timeout: maximum number of microseconds in the timeout
178 * @index: loop index (integer)
180 * Loop waiting for @cond to become true or until at least @timeout
181 * microseconds have passed. To use, define some integer @index in the
182 * calling code. After running, if @index == @timeout, then the loop has
185 * Copied from omap_test_timeout */
186 #define sr_test_cond_timeout(cond, timeout, index) \
188 for (index = 0; index < timeout; index++) { \
196 * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
197 * pmic specific info to smartreflex driver
199 * @sr_pmic_init: API to initialize smartreflex on the PMIC side.
201 struct omap_sr_pmic_data {
202 void (*sr_pmic_init) (void);
206 * struct omap_smartreflex_dev_attr - Smartreflex Device attribute.
208 * @sensor_voltdm_name: Name of voltdomain of SR instance
210 struct omap_smartreflex_dev_attr {
211 const char *sensor_voltdm_name;
215 * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
216 * The smartreflex class driver should pass the class type.
217 * Should be used to populate the class_type field of the
218 * omap_smartreflex_class_data structure.
220 #define SR_CLASS1 0x1
221 #define SR_CLASS2 0x2
222 #define SR_CLASS3 0x3
225 * struct omap_sr_class_data - Smartreflex class driver info
227 * @enable: API to enable a particular class smaartreflex.
228 * @disable: API to disable a particular class smartreflex.
229 * @configure: API to configure a particular class smartreflex.
230 * @notify: API to notify the class driver about an event in SR.
231 * Not needed for class3.
232 * @notify_flags: specify the events to be notified to the class driver
233 * @class_type: specify which smartreflex class.
234 * Can be used by the SR driver to take any class
237 struct omap_sr_class_data {
238 int (*enable)(struct omap_sr *sr);
239 int (*disable)(struct omap_sr *sr, int is_volt_reset);
240 int (*configure)(struct omap_sr *sr);
241 int (*notify)(struct omap_sr *sr, u32 status);
247 * struct omap_sr_nvalue_table - Smartreflex n-target value info
249 * @efuse_offs: The offset of the efuse where n-target values are stored.
250 * @nvalue: The n-target value.
251 * @errminlimit: The value of the ERRMINLIMIT bitfield for this n-target
252 * @volt_nominal: microvolts DC that the VDD is initially programmed to
254 struct omap_sr_nvalue_table {
258 unsigned long volt_nominal;
262 * struct omap_sr_data - Smartreflex platform data.
264 * @name: instance name
265 * @ip_type: Smartreflex IP type.
266 * @senp_mod: SENPENABLE value of the sr CONFIG register
267 * @senn_mod: SENNENABLE value for sr CONFIG register
268 * @err_weight ERRWEIGHT value of the sr ERRCONFIG register
269 * @err_maxlimit ERRMAXLIMIT value of the sr ERRCONFIG register
270 * @accum_data ACCUMDATA value of the sr CONFIG register
271 * @senn_avgweight SENNAVGWEIGHT value of the sr AVGWEIGHT register
272 * @senp_avgweight SENPAVGWEIGHT value of the sr AVGWEIGHT register
273 * @nvalue_count: Number of distinct nvalues in the nvalue table
274 * @enable_on_init: whether this sr module needs to enabled at
276 * @nvalue_table: table containing the efuse offsets and nvalues
277 * corresponding to them.
278 * @voltdm: Pointer to the voltage domain associated with the SR
280 struct omap_sr_data {
292 struct omap_sr_nvalue_table *nvalue_table;
293 struct voltagedomain *voltdm;
296 #ifdef CONFIG_POWER_AVS_OMAP
298 /* Smartreflex module enable/disable interface */
299 void omap_sr_enable(struct voltagedomain *voltdm);
300 void omap_sr_disable(struct voltagedomain *voltdm);
301 void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
303 /* Smartreflex driver hooks to be called from Smartreflex class driver */
304 int sr_enable(struct omap_sr *sr, unsigned long volt);
305 void sr_disable(struct omap_sr *sr);
306 int sr_configure_errgen(struct omap_sr *sr);
307 int sr_disable_errgen(struct omap_sr *sr);
308 int sr_configure_minmax(struct omap_sr *sr);
310 /* API to register the smartreflex class driver with the smartreflex driver */
311 int sr_register_class(struct omap_sr_class_data *class_data);
313 static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
314 static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
315 static inline void omap_sr_disable_reset_volt(
316 struct voltagedomain *voltdm) {}