xref: /OK3568_Linux_fs/kernel/drivers/soc/ti/smartreflex.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * OMAP SmartReflex Voltage Control
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Author: Thara Gopinath	<thara@ti.com>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (C) 2012 Texas Instruments, Inc.
8*4882a593Smuzhiyun  * Thara Gopinath <thara@ti.com>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Copyright (C) 2008 Nokia Corporation
11*4882a593Smuzhiyun  * Kalle Jokiniemi
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Copyright (C) 2007 Texas Instruments, Inc.
14*4882a593Smuzhiyun  * Lesly A M <x0080970@ti.com>
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/module.h>
18*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
19*4882a593Smuzhiyun #include <linux/interrupt.h>
20*4882a593Smuzhiyun #include <linux/clk.h>
21*4882a593Smuzhiyun #include <linux/io.h>
22*4882a593Smuzhiyun #include <linux/debugfs.h>
23*4882a593Smuzhiyun #include <linux/delay.h>
24*4882a593Smuzhiyun #include <linux/slab.h>
25*4882a593Smuzhiyun #include <linux/pm_runtime.h>
26*4882a593Smuzhiyun #include <linux/power/smartreflex.h>
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #define DRIVER_NAME	"smartreflex"
29*4882a593Smuzhiyun #define SMARTREFLEX_NAME_LEN	32
30*4882a593Smuzhiyun #define NVALUE_NAME_LEN		40
31*4882a593Smuzhiyun #define SR_DISABLE_TIMEOUT	200
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /* sr_list contains all the instances of smartreflex module */
34*4882a593Smuzhiyun static LIST_HEAD(sr_list);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun static struct omap_sr_class_data *sr_class;
37*4882a593Smuzhiyun static struct dentry		*sr_dbg_dir;
38*4882a593Smuzhiyun 
sr_write_reg(struct omap_sr * sr,unsigned offset,u32 value)39*4882a593Smuzhiyun static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	__raw_writel(value, (sr->base + offset));
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun 
sr_modify_reg(struct omap_sr * sr,unsigned offset,u32 mask,u32 value)44*4882a593Smuzhiyun static inline void sr_modify_reg(struct omap_sr *sr, unsigned offset, u32 mask,
45*4882a593Smuzhiyun 					u32 value)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	u32 reg_val;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	/*
50*4882a593Smuzhiyun 	 * Smartreflex error config register is special as it contains
51*4882a593Smuzhiyun 	 * certain status bits which if written a 1 into means a clear
52*4882a593Smuzhiyun 	 * of those bits. So in order to make sure no accidental write of
53*4882a593Smuzhiyun 	 * 1 happens to those status bits, do a clear of them in the read
54*4882a593Smuzhiyun 	 * value. This mean this API doesn't rewrite values in these bits
55*4882a593Smuzhiyun 	 * if they are currently set, but does allow the caller to write
56*4882a593Smuzhiyun 	 * those bits.
57*4882a593Smuzhiyun 	 */
58*4882a593Smuzhiyun 	if (sr->ip_type == SR_TYPE_V1 && offset == ERRCONFIG_V1)
59*4882a593Smuzhiyun 		mask |= ERRCONFIG_STATUS_V1_MASK;
60*4882a593Smuzhiyun 	else if (sr->ip_type == SR_TYPE_V2 && offset == ERRCONFIG_V2)
61*4882a593Smuzhiyun 		mask |= ERRCONFIG_VPBOUNDINTST_V2;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	reg_val = __raw_readl(sr->base + offset);
64*4882a593Smuzhiyun 	reg_val &= ~mask;
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	value &= mask;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	reg_val |= value;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	__raw_writel(reg_val, (sr->base + offset));
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun 
sr_read_reg(struct omap_sr * sr,unsigned offset)73*4882a593Smuzhiyun static inline u32 sr_read_reg(struct omap_sr *sr, unsigned offset)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun 	return __raw_readl(sr->base + offset);
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun 
_sr_lookup(struct voltagedomain * voltdm)78*4882a593Smuzhiyun static struct omap_sr *_sr_lookup(struct voltagedomain *voltdm)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun 	struct omap_sr *sr_info;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	if (!voltdm) {
83*4882a593Smuzhiyun 		pr_err("%s: Null voltage domain passed!\n", __func__);
84*4882a593Smuzhiyun 		return ERR_PTR(-EINVAL);
85*4882a593Smuzhiyun 	}
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 	list_for_each_entry(sr_info, &sr_list, node) {
88*4882a593Smuzhiyun 		if (voltdm == sr_info->voltdm)
89*4882a593Smuzhiyun 			return sr_info;
90*4882a593Smuzhiyun 	}
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	return ERR_PTR(-ENODATA);
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun 
sr_interrupt(int irq,void * data)95*4882a593Smuzhiyun static irqreturn_t sr_interrupt(int irq, void *data)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun 	struct omap_sr *sr_info = data;
98*4882a593Smuzhiyun 	u32 status = 0;
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun 	switch (sr_info->ip_type) {
101*4882a593Smuzhiyun 	case SR_TYPE_V1:
102*4882a593Smuzhiyun 		/* Read the status bits */
103*4882a593Smuzhiyun 		status = sr_read_reg(sr_info, ERRCONFIG_V1);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 		/* Clear them by writing back */
106*4882a593Smuzhiyun 		sr_write_reg(sr_info, ERRCONFIG_V1, status);
107*4882a593Smuzhiyun 		break;
108*4882a593Smuzhiyun 	case SR_TYPE_V2:
109*4882a593Smuzhiyun 		/* Read the status bits */
110*4882a593Smuzhiyun 		status = sr_read_reg(sr_info, IRQSTATUS);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 		/* Clear them by writing back */
113*4882a593Smuzhiyun 		sr_write_reg(sr_info, IRQSTATUS, status);
114*4882a593Smuzhiyun 		break;
115*4882a593Smuzhiyun 	default:
116*4882a593Smuzhiyun 		dev_err(&sr_info->pdev->dev, "UNKNOWN IP type %d\n",
117*4882a593Smuzhiyun 			sr_info->ip_type);
118*4882a593Smuzhiyun 		return IRQ_NONE;
119*4882a593Smuzhiyun 	}
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	if (sr_class->notify)
122*4882a593Smuzhiyun 		sr_class->notify(sr_info, status);
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	return IRQ_HANDLED;
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun 
sr_set_clk_length(struct omap_sr * sr)127*4882a593Smuzhiyun static void sr_set_clk_length(struct omap_sr *sr)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun 	struct clk *fck;
130*4882a593Smuzhiyun 	u32 fclk_speed;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	/* Try interconnect target module fck first if it already exists */
133*4882a593Smuzhiyun 	fck = clk_get(sr->pdev->dev.parent, "fck");
134*4882a593Smuzhiyun 	if (IS_ERR(fck)) {
135*4882a593Smuzhiyun 		fck = clk_get(&sr->pdev->dev, "fck");
136*4882a593Smuzhiyun 		if (IS_ERR(fck)) {
137*4882a593Smuzhiyun 			dev_err(&sr->pdev->dev,
138*4882a593Smuzhiyun 				"%s: unable to get fck for device %s\n",
139*4882a593Smuzhiyun 				__func__, dev_name(&sr->pdev->dev));
140*4882a593Smuzhiyun 			return;
141*4882a593Smuzhiyun 		}
142*4882a593Smuzhiyun 	}
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	fclk_speed = clk_get_rate(fck);
145*4882a593Smuzhiyun 	clk_put(fck);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	switch (fclk_speed) {
148*4882a593Smuzhiyun 	case 12000000:
149*4882a593Smuzhiyun 		sr->clk_length = SRCLKLENGTH_12MHZ_SYSCLK;
150*4882a593Smuzhiyun 		break;
151*4882a593Smuzhiyun 	case 13000000:
152*4882a593Smuzhiyun 		sr->clk_length = SRCLKLENGTH_13MHZ_SYSCLK;
153*4882a593Smuzhiyun 		break;
154*4882a593Smuzhiyun 	case 19200000:
155*4882a593Smuzhiyun 		sr->clk_length = SRCLKLENGTH_19MHZ_SYSCLK;
156*4882a593Smuzhiyun 		break;
157*4882a593Smuzhiyun 	case 26000000:
158*4882a593Smuzhiyun 		sr->clk_length = SRCLKLENGTH_26MHZ_SYSCLK;
159*4882a593Smuzhiyun 		break;
160*4882a593Smuzhiyun 	case 38400000:
161*4882a593Smuzhiyun 		sr->clk_length = SRCLKLENGTH_38MHZ_SYSCLK;
162*4882a593Smuzhiyun 		break;
163*4882a593Smuzhiyun 	default:
164*4882a593Smuzhiyun 		dev_err(&sr->pdev->dev, "%s: Invalid fclk rate: %d\n",
165*4882a593Smuzhiyun 			__func__, fclk_speed);
166*4882a593Smuzhiyun 		break;
167*4882a593Smuzhiyun 	}
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun 
sr_start_vddautocomp(struct omap_sr * sr)170*4882a593Smuzhiyun static void sr_start_vddautocomp(struct omap_sr *sr)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun 	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
173*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev,
174*4882a593Smuzhiyun 			 "%s: smartreflex class driver not registered\n",
175*4882a593Smuzhiyun 			 __func__);
176*4882a593Smuzhiyun 		return;
177*4882a593Smuzhiyun 	}
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 	if (!sr_class->enable(sr))
180*4882a593Smuzhiyun 		sr->autocomp_active = true;
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun 
sr_stop_vddautocomp(struct omap_sr * sr)183*4882a593Smuzhiyun static void sr_stop_vddautocomp(struct omap_sr *sr)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun 	if (!sr_class || !(sr_class->disable)) {
186*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev,
187*4882a593Smuzhiyun 			 "%s: smartreflex class driver not registered\n",
188*4882a593Smuzhiyun 			 __func__);
189*4882a593Smuzhiyun 		return;
190*4882a593Smuzhiyun 	}
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	if (sr->autocomp_active) {
193*4882a593Smuzhiyun 		sr_class->disable(sr, 1);
194*4882a593Smuzhiyun 		sr->autocomp_active = false;
195*4882a593Smuzhiyun 	}
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /*
199*4882a593Smuzhiyun  * This function handles the initializations which have to be done
200*4882a593Smuzhiyun  * only when both sr device and class driver regiter has
201*4882a593Smuzhiyun  * completed. This will be attempted to be called from both sr class
202*4882a593Smuzhiyun  * driver register and sr device intializtion API's. Only one call
203*4882a593Smuzhiyun  * will ultimately succeed.
204*4882a593Smuzhiyun  *
205*4882a593Smuzhiyun  * Currently this function registers interrupt handler for a particular SR
206*4882a593Smuzhiyun  * if smartreflex class driver is already registered and has
207*4882a593Smuzhiyun  * requested for interrupts and the SR interrupt line in present.
208*4882a593Smuzhiyun  */
sr_late_init(struct omap_sr * sr_info)209*4882a593Smuzhiyun static int sr_late_init(struct omap_sr *sr_info)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun 	struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
212*4882a593Smuzhiyun 	int ret = 0;
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 	if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
215*4882a593Smuzhiyun 		ret = devm_request_irq(&sr_info->pdev->dev, sr_info->irq,
216*4882a593Smuzhiyun 				       sr_interrupt, 0, sr_info->name, sr_info);
217*4882a593Smuzhiyun 		if (ret)
218*4882a593Smuzhiyun 			goto error;
219*4882a593Smuzhiyun 		disable_irq(sr_info->irq);
220*4882a593Smuzhiyun 	}
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	if (pdata && pdata->enable_on_init)
223*4882a593Smuzhiyun 		sr_start_vddautocomp(sr_info);
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun 	return ret;
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun error:
228*4882a593Smuzhiyun 	list_del(&sr_info->node);
229*4882a593Smuzhiyun 	dev_err(&sr_info->pdev->dev, "%s: ERROR in registering interrupt handler. Smartreflex will not function as desired\n",
230*4882a593Smuzhiyun 		__func__);
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	return ret;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun 
sr_v1_disable(struct omap_sr * sr)235*4882a593Smuzhiyun static void sr_v1_disable(struct omap_sr *sr)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun 	int timeout = 0;
238*4882a593Smuzhiyun 	int errconf_val = ERRCONFIG_MCUACCUMINTST | ERRCONFIG_MCUVALIDINTST |
239*4882a593Smuzhiyun 			ERRCONFIG_MCUBOUNDINTST;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	/* Enable MCUDisableAcknowledge interrupt */
242*4882a593Smuzhiyun 	sr_modify_reg(sr, ERRCONFIG_V1,
243*4882a593Smuzhiyun 			ERRCONFIG_MCUDISACKINTEN, ERRCONFIG_MCUDISACKINTEN);
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	/* SRCONFIG - disable SR */
246*4882a593Smuzhiyun 	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 	/* Disable all other SR interrupts and clear the status as needed */
249*4882a593Smuzhiyun 	if (sr_read_reg(sr, ERRCONFIG_V1) & ERRCONFIG_VPBOUNDINTST_V1)
250*4882a593Smuzhiyun 		errconf_val |= ERRCONFIG_VPBOUNDINTST_V1;
251*4882a593Smuzhiyun 	sr_modify_reg(sr, ERRCONFIG_V1,
252*4882a593Smuzhiyun 			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
253*4882a593Smuzhiyun 			ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_VPBOUNDINTEN_V1),
254*4882a593Smuzhiyun 			errconf_val);
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun 	/*
257*4882a593Smuzhiyun 	 * Wait for SR to be disabled.
258*4882a593Smuzhiyun 	 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
259*4882a593Smuzhiyun 	 */
260*4882a593Smuzhiyun 	sr_test_cond_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
261*4882a593Smuzhiyun 			     ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
262*4882a593Smuzhiyun 			     timeout);
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	if (timeout >= SR_DISABLE_TIMEOUT)
265*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
266*4882a593Smuzhiyun 			 __func__);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
269*4882a593Smuzhiyun 	sr_modify_reg(sr, ERRCONFIG_V1, ERRCONFIG_MCUDISACKINTEN,
270*4882a593Smuzhiyun 			ERRCONFIG_MCUDISACKINTST);
271*4882a593Smuzhiyun }
272*4882a593Smuzhiyun 
sr_v2_disable(struct omap_sr * sr)273*4882a593Smuzhiyun static void sr_v2_disable(struct omap_sr *sr)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun 	int timeout = 0;
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun 	/* Enable MCUDisableAcknowledge interrupt */
278*4882a593Smuzhiyun 	sr_write_reg(sr, IRQENABLE_SET, IRQENABLE_MCUDISABLEACKINT);
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 	/* SRCONFIG - disable SR */
281*4882a593Smuzhiyun 	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun 	/*
284*4882a593Smuzhiyun 	 * Disable all other SR interrupts and clear the status
285*4882a593Smuzhiyun 	 * write to status register ONLY on need basis - only if status
286*4882a593Smuzhiyun 	 * is set.
287*4882a593Smuzhiyun 	 */
288*4882a593Smuzhiyun 	if (sr_read_reg(sr, ERRCONFIG_V2) & ERRCONFIG_VPBOUNDINTST_V2)
289*4882a593Smuzhiyun 		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
290*4882a593Smuzhiyun 			ERRCONFIG_VPBOUNDINTST_V2);
291*4882a593Smuzhiyun 	else
292*4882a593Smuzhiyun 		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
293*4882a593Smuzhiyun 				0x0);
294*4882a593Smuzhiyun 	sr_write_reg(sr, IRQENABLE_CLR, (IRQENABLE_MCUACCUMINT |
295*4882a593Smuzhiyun 			IRQENABLE_MCUVALIDINT |
296*4882a593Smuzhiyun 			IRQENABLE_MCUBOUNDSINT));
297*4882a593Smuzhiyun 	sr_write_reg(sr, IRQSTATUS, (IRQSTATUS_MCUACCUMINT |
298*4882a593Smuzhiyun 			IRQSTATUS_MCVALIDINT |
299*4882a593Smuzhiyun 			IRQSTATUS_MCBOUNDSINT));
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 	/*
302*4882a593Smuzhiyun 	 * Wait for SR to be disabled.
303*4882a593Smuzhiyun 	 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
304*4882a593Smuzhiyun 	 */
305*4882a593Smuzhiyun 	sr_test_cond_timeout((sr_read_reg(sr, IRQSTATUS) &
306*4882a593Smuzhiyun 			     IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
307*4882a593Smuzhiyun 			     timeout);
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun 	if (timeout >= SR_DISABLE_TIMEOUT)
310*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
311*4882a593Smuzhiyun 			 __func__);
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun 	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
314*4882a593Smuzhiyun 	sr_write_reg(sr, IRQENABLE_CLR, IRQENABLE_MCUDISABLEACKINT);
315*4882a593Smuzhiyun 	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun 
sr_retrieve_nvalue_row(struct omap_sr * sr,u32 efuse_offs)318*4882a593Smuzhiyun static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
319*4882a593Smuzhiyun 				struct omap_sr *sr, u32 efuse_offs)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun 	int i;
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 	if (!sr->nvalue_table) {
324*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
325*4882a593Smuzhiyun 			 __func__);
326*4882a593Smuzhiyun 		return NULL;
327*4882a593Smuzhiyun 	}
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 	for (i = 0; i < sr->nvalue_count; i++) {
330*4882a593Smuzhiyun 		if (sr->nvalue_table[i].efuse_offs == efuse_offs)
331*4882a593Smuzhiyun 			return &sr->nvalue_table[i];
332*4882a593Smuzhiyun 	}
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	return NULL;
335*4882a593Smuzhiyun }
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun /* Public Functions */
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun /**
340*4882a593Smuzhiyun  * sr_configure_errgen() - Configures the SmartReflex to perform AVS using the
341*4882a593Smuzhiyun  *			 error generator module.
342*4882a593Smuzhiyun  * @sr:			SR module to be configured.
343*4882a593Smuzhiyun  *
344*4882a593Smuzhiyun  * This API is to be called from the smartreflex class driver to
345*4882a593Smuzhiyun  * configure the error generator module inside the smartreflex module.
346*4882a593Smuzhiyun  * SR settings if using the ERROR module inside Smartreflex.
347*4882a593Smuzhiyun  * SR CLASS 3 by default uses only the ERROR module where as
348*4882a593Smuzhiyun  * SR CLASS 2 can choose between ERROR module and MINMAXAVG
349*4882a593Smuzhiyun  * module. Returns 0 on success and error value in case of failure.
350*4882a593Smuzhiyun  */
sr_configure_errgen(struct omap_sr * sr)351*4882a593Smuzhiyun int sr_configure_errgen(struct omap_sr *sr)
352*4882a593Smuzhiyun {
353*4882a593Smuzhiyun 	u32 sr_config, sr_errconfig, errconfig_offs;
354*4882a593Smuzhiyun 	u32 vpboundint_en, vpboundint_st;
355*4882a593Smuzhiyun 	u32 senp_en = 0, senn_en = 0;
356*4882a593Smuzhiyun 	u8 senp_shift, senn_shift;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	if (!sr) {
359*4882a593Smuzhiyun 		pr_warn("%s: NULL omap_sr from %pS\n",
360*4882a593Smuzhiyun 			__func__, (void *)_RET_IP_);
361*4882a593Smuzhiyun 		return -EINVAL;
362*4882a593Smuzhiyun 	}
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun 	if (!sr->clk_length)
365*4882a593Smuzhiyun 		sr_set_clk_length(sr);
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 	senp_en = sr->senp_mod;
368*4882a593Smuzhiyun 	senn_en = sr->senn_mod;
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun 	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
371*4882a593Smuzhiyun 		SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN;
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun 	switch (sr->ip_type) {
374*4882a593Smuzhiyun 	case SR_TYPE_V1:
375*4882a593Smuzhiyun 		sr_config |= SRCONFIG_DELAYCTRL;
376*4882a593Smuzhiyun 		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
377*4882a593Smuzhiyun 		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
378*4882a593Smuzhiyun 		errconfig_offs = ERRCONFIG_V1;
379*4882a593Smuzhiyun 		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
380*4882a593Smuzhiyun 		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
381*4882a593Smuzhiyun 		break;
382*4882a593Smuzhiyun 	case SR_TYPE_V2:
383*4882a593Smuzhiyun 		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
384*4882a593Smuzhiyun 		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
385*4882a593Smuzhiyun 		errconfig_offs = ERRCONFIG_V2;
386*4882a593Smuzhiyun 		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
387*4882a593Smuzhiyun 		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
388*4882a593Smuzhiyun 		break;
389*4882a593Smuzhiyun 	default:
390*4882a593Smuzhiyun 		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex module without specifying the ip\n",
391*4882a593Smuzhiyun 			__func__);
392*4882a593Smuzhiyun 		return -EINVAL;
393*4882a593Smuzhiyun 	}
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun 	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
396*4882a593Smuzhiyun 	sr_write_reg(sr, SRCONFIG, sr_config);
397*4882a593Smuzhiyun 	sr_errconfig = (sr->err_weight << ERRCONFIG_ERRWEIGHT_SHIFT) |
398*4882a593Smuzhiyun 		(sr->err_maxlimit << ERRCONFIG_ERRMAXLIMIT_SHIFT) |
399*4882a593Smuzhiyun 		(sr->err_minlimit <<  ERRCONFIG_ERRMINLIMIT_SHIFT);
400*4882a593Smuzhiyun 	sr_modify_reg(sr, errconfig_offs, (SR_ERRWEIGHT_MASK |
401*4882a593Smuzhiyun 		SR_ERRMAXLIMIT_MASK | SR_ERRMINLIMIT_MASK),
402*4882a593Smuzhiyun 		sr_errconfig);
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	/* Enabling the interrupts if the ERROR module is used */
405*4882a593Smuzhiyun 	sr_modify_reg(sr, errconfig_offs, (vpboundint_en | vpboundint_st),
406*4882a593Smuzhiyun 		      vpboundint_en);
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun 	return 0;
409*4882a593Smuzhiyun }
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun /**
412*4882a593Smuzhiyun  * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component
413*4882a593Smuzhiyun  * @sr:			SR module to be configured.
414*4882a593Smuzhiyun  *
415*4882a593Smuzhiyun  * This API is to be called from the smartreflex class driver to
416*4882a593Smuzhiyun  * disable the error generator module inside the smartreflex module.
417*4882a593Smuzhiyun  *
418*4882a593Smuzhiyun  * Returns 0 on success and error value in case of failure.
419*4882a593Smuzhiyun  */
sr_disable_errgen(struct omap_sr * sr)420*4882a593Smuzhiyun int sr_disable_errgen(struct omap_sr *sr)
421*4882a593Smuzhiyun {
422*4882a593Smuzhiyun 	u32 errconfig_offs;
423*4882a593Smuzhiyun 	u32 vpboundint_en, vpboundint_st;
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun 	if (!sr) {
426*4882a593Smuzhiyun 		pr_warn("%s: NULL omap_sr from %pS\n",
427*4882a593Smuzhiyun 			__func__, (void *)_RET_IP_);
428*4882a593Smuzhiyun 		return -EINVAL;
429*4882a593Smuzhiyun 	}
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 	switch (sr->ip_type) {
432*4882a593Smuzhiyun 	case SR_TYPE_V1:
433*4882a593Smuzhiyun 		errconfig_offs = ERRCONFIG_V1;
434*4882a593Smuzhiyun 		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
435*4882a593Smuzhiyun 		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
436*4882a593Smuzhiyun 		break;
437*4882a593Smuzhiyun 	case SR_TYPE_V2:
438*4882a593Smuzhiyun 		errconfig_offs = ERRCONFIG_V2;
439*4882a593Smuzhiyun 		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
440*4882a593Smuzhiyun 		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
441*4882a593Smuzhiyun 		break;
442*4882a593Smuzhiyun 	default:
443*4882a593Smuzhiyun 		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex module without specifying the ip\n",
444*4882a593Smuzhiyun 			__func__);
445*4882a593Smuzhiyun 		return -EINVAL;
446*4882a593Smuzhiyun 	}
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun 	/* Disable the Sensor and errorgen */
449*4882a593Smuzhiyun 	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0);
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun 	/*
452*4882a593Smuzhiyun 	 * Disable the interrupts of ERROR module
453*4882a593Smuzhiyun 	 * NOTE: modify is a read, modify,write - an implicit OCP barrier
454*4882a593Smuzhiyun 	 * which is required is present here - sequencing is critical
455*4882a593Smuzhiyun 	 * at this point (after errgen is disabled, vpboundint disable)
456*4882a593Smuzhiyun 	 */
457*4882a593Smuzhiyun 	sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun 	return 0;
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun /**
463*4882a593Smuzhiyun  * sr_configure_minmax() - Configures the SmartReflex to perform AVS using the
464*4882a593Smuzhiyun  *			 minmaxavg module.
465*4882a593Smuzhiyun  * @sr:			SR module to be configured.
466*4882a593Smuzhiyun  *
467*4882a593Smuzhiyun  * This API is to be called from the smartreflex class driver to
468*4882a593Smuzhiyun  * configure the minmaxavg module inside the smartreflex module.
469*4882a593Smuzhiyun  * SR settings if using the ERROR module inside Smartreflex.
470*4882a593Smuzhiyun  * SR CLASS 3 by default uses only the ERROR module where as
471*4882a593Smuzhiyun  * SR CLASS 2 can choose between ERROR module and MINMAXAVG
472*4882a593Smuzhiyun  * module. Returns 0 on success and error value in case of failure.
473*4882a593Smuzhiyun  */
sr_configure_minmax(struct omap_sr * sr)474*4882a593Smuzhiyun int sr_configure_minmax(struct omap_sr *sr)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun 	u32 sr_config, sr_avgwt;
477*4882a593Smuzhiyun 	u32 senp_en = 0, senn_en = 0;
478*4882a593Smuzhiyun 	u8 senp_shift, senn_shift;
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun 	if (!sr) {
481*4882a593Smuzhiyun 		pr_warn("%s: NULL omap_sr from %pS\n",
482*4882a593Smuzhiyun 			__func__, (void *)_RET_IP_);
483*4882a593Smuzhiyun 		return -EINVAL;
484*4882a593Smuzhiyun 	}
485*4882a593Smuzhiyun 
486*4882a593Smuzhiyun 	if (!sr->clk_length)
487*4882a593Smuzhiyun 		sr_set_clk_length(sr);
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun 	senp_en = sr->senp_mod;
490*4882a593Smuzhiyun 	senn_en = sr->senn_mod;
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun 	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
493*4882a593Smuzhiyun 		SRCONFIG_SENENABLE |
494*4882a593Smuzhiyun 		(sr->accum_data << SRCONFIG_ACCUMDATA_SHIFT);
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun 	switch (sr->ip_type) {
497*4882a593Smuzhiyun 	case SR_TYPE_V1:
498*4882a593Smuzhiyun 		sr_config |= SRCONFIG_DELAYCTRL;
499*4882a593Smuzhiyun 		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
500*4882a593Smuzhiyun 		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
501*4882a593Smuzhiyun 		break;
502*4882a593Smuzhiyun 	case SR_TYPE_V2:
503*4882a593Smuzhiyun 		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
504*4882a593Smuzhiyun 		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
505*4882a593Smuzhiyun 		break;
506*4882a593Smuzhiyun 	default:
507*4882a593Smuzhiyun 		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex module without specifying the ip\n",
508*4882a593Smuzhiyun 			__func__);
509*4882a593Smuzhiyun 		return -EINVAL;
510*4882a593Smuzhiyun 	}
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun 	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
513*4882a593Smuzhiyun 	sr_write_reg(sr, SRCONFIG, sr_config);
514*4882a593Smuzhiyun 	sr_avgwt = (sr->senp_avgweight << AVGWEIGHT_SENPAVGWEIGHT_SHIFT) |
515*4882a593Smuzhiyun 		(sr->senn_avgweight << AVGWEIGHT_SENNAVGWEIGHT_SHIFT);
516*4882a593Smuzhiyun 	sr_write_reg(sr, AVGWEIGHT, sr_avgwt);
517*4882a593Smuzhiyun 
518*4882a593Smuzhiyun 	/*
519*4882a593Smuzhiyun 	 * Enabling the interrupts if MINMAXAVG module is used.
520*4882a593Smuzhiyun 	 * TODO: check if all the interrupts are mandatory
521*4882a593Smuzhiyun 	 */
522*4882a593Smuzhiyun 	switch (sr->ip_type) {
523*4882a593Smuzhiyun 	case SR_TYPE_V1:
524*4882a593Smuzhiyun 		sr_modify_reg(sr, ERRCONFIG_V1,
525*4882a593Smuzhiyun 			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
526*4882a593Smuzhiyun 			ERRCONFIG_MCUBOUNDINTEN),
527*4882a593Smuzhiyun 			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUACCUMINTST |
528*4882a593Smuzhiyun 			 ERRCONFIG_MCUVALIDINTEN | ERRCONFIG_MCUVALIDINTST |
529*4882a593Smuzhiyun 			 ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_MCUBOUNDINTST));
530*4882a593Smuzhiyun 		break;
531*4882a593Smuzhiyun 	case SR_TYPE_V2:
532*4882a593Smuzhiyun 		sr_write_reg(sr, IRQSTATUS,
533*4882a593Smuzhiyun 			IRQSTATUS_MCUACCUMINT | IRQSTATUS_MCVALIDINT |
534*4882a593Smuzhiyun 			IRQSTATUS_MCBOUNDSINT | IRQSTATUS_MCUDISABLEACKINT);
535*4882a593Smuzhiyun 		sr_write_reg(sr, IRQENABLE_SET,
536*4882a593Smuzhiyun 			IRQENABLE_MCUACCUMINT | IRQENABLE_MCUVALIDINT |
537*4882a593Smuzhiyun 			IRQENABLE_MCUBOUNDSINT | IRQENABLE_MCUDISABLEACKINT);
538*4882a593Smuzhiyun 		break;
539*4882a593Smuzhiyun 	default:
540*4882a593Smuzhiyun 		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex module without specifying the ip\n",
541*4882a593Smuzhiyun 			__func__);
542*4882a593Smuzhiyun 		return -EINVAL;
543*4882a593Smuzhiyun 	}
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun 	return 0;
546*4882a593Smuzhiyun }
547*4882a593Smuzhiyun 
548*4882a593Smuzhiyun /**
549*4882a593Smuzhiyun  * sr_enable() - Enables the smartreflex module.
550*4882a593Smuzhiyun  * @sr:		pointer to which the SR module to be configured belongs to.
551*4882a593Smuzhiyun  * @volt:	The voltage at which the Voltage domain associated with
552*4882a593Smuzhiyun  *		the smartreflex module is operating at.
553*4882a593Smuzhiyun  *		This is required only to program the correct Ntarget value.
554*4882a593Smuzhiyun  *
555*4882a593Smuzhiyun  * This API is to be called from the smartreflex class driver to
556*4882a593Smuzhiyun  * enable a smartreflex module. Returns 0 on success. Returns error
557*4882a593Smuzhiyun  * value if the voltage passed is wrong or if ntarget value is wrong.
558*4882a593Smuzhiyun  */
sr_enable(struct omap_sr * sr,unsigned long volt)559*4882a593Smuzhiyun int sr_enable(struct omap_sr *sr, unsigned long volt)
560*4882a593Smuzhiyun {
561*4882a593Smuzhiyun 	struct omap_volt_data *volt_data;
562*4882a593Smuzhiyun 	struct omap_sr_nvalue_table *nvalue_row;
563*4882a593Smuzhiyun 	int ret;
564*4882a593Smuzhiyun 
565*4882a593Smuzhiyun 	if (!sr) {
566*4882a593Smuzhiyun 		pr_warn("%s: NULL omap_sr from %pS\n",
567*4882a593Smuzhiyun 			__func__, (void *)_RET_IP_);
568*4882a593Smuzhiyun 		return -EINVAL;
569*4882a593Smuzhiyun 	}
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun 	volt_data = omap_voltage_get_voltdata(sr->voltdm, volt);
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun 	if (IS_ERR(volt_data)) {
574*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: Unable to get voltage table for nominal voltage %ld\n",
575*4882a593Smuzhiyun 			 __func__, volt);
576*4882a593Smuzhiyun 		return PTR_ERR(volt_data);
577*4882a593Smuzhiyun 	}
578*4882a593Smuzhiyun 
579*4882a593Smuzhiyun 	nvalue_row = sr_retrieve_nvalue_row(sr, volt_data->sr_efuse_offs);
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	if (!nvalue_row) {
582*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
583*4882a593Smuzhiyun 			 __func__, volt);
584*4882a593Smuzhiyun 		return -ENODATA;
585*4882a593Smuzhiyun 	}
586*4882a593Smuzhiyun 
587*4882a593Smuzhiyun 	/* errminlimit is opp dependent and hence linked to voltage */
588*4882a593Smuzhiyun 	sr->err_minlimit = nvalue_row->errminlimit;
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun 	pm_runtime_get_sync(&sr->pdev->dev);
591*4882a593Smuzhiyun 
592*4882a593Smuzhiyun 	/* Check if SR is already enabled. If yes do nothing */
593*4882a593Smuzhiyun 	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE)
594*4882a593Smuzhiyun 		return 0;
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun 	/* Configure SR */
597*4882a593Smuzhiyun 	ret = sr_class->configure(sr);
598*4882a593Smuzhiyun 	if (ret)
599*4882a593Smuzhiyun 		return ret;
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
602*4882a593Smuzhiyun 
603*4882a593Smuzhiyun 	/* SRCONFIG - enable SR */
604*4882a593Smuzhiyun 	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
605*4882a593Smuzhiyun 	return 0;
606*4882a593Smuzhiyun }
607*4882a593Smuzhiyun 
608*4882a593Smuzhiyun /**
609*4882a593Smuzhiyun  * sr_disable() - Disables the smartreflex module.
610*4882a593Smuzhiyun  * @sr:		pointer to which the SR module to be configured belongs to.
611*4882a593Smuzhiyun  *
612*4882a593Smuzhiyun  * This API is to be called from the smartreflex class driver to
613*4882a593Smuzhiyun  * disable a smartreflex module.
614*4882a593Smuzhiyun  */
sr_disable(struct omap_sr * sr)615*4882a593Smuzhiyun void sr_disable(struct omap_sr *sr)
616*4882a593Smuzhiyun {
617*4882a593Smuzhiyun 	if (!sr) {
618*4882a593Smuzhiyun 		pr_warn("%s: NULL omap_sr from %pS\n",
619*4882a593Smuzhiyun 			__func__, (void *)_RET_IP_);
620*4882a593Smuzhiyun 		return;
621*4882a593Smuzhiyun 	}
622*4882a593Smuzhiyun 
623*4882a593Smuzhiyun 	/* Check if SR clocks are already disabled. If yes do nothing */
624*4882a593Smuzhiyun 	if (pm_runtime_suspended(&sr->pdev->dev))
625*4882a593Smuzhiyun 		return;
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun 	/*
628*4882a593Smuzhiyun 	 * Disable SR if only it is indeed enabled. Else just
629*4882a593Smuzhiyun 	 * disable the clocks.
630*4882a593Smuzhiyun 	 */
631*4882a593Smuzhiyun 	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE) {
632*4882a593Smuzhiyun 		switch (sr->ip_type) {
633*4882a593Smuzhiyun 		case SR_TYPE_V1:
634*4882a593Smuzhiyun 			sr_v1_disable(sr);
635*4882a593Smuzhiyun 			break;
636*4882a593Smuzhiyun 		case SR_TYPE_V2:
637*4882a593Smuzhiyun 			sr_v2_disable(sr);
638*4882a593Smuzhiyun 			break;
639*4882a593Smuzhiyun 		default:
640*4882a593Smuzhiyun 			dev_err(&sr->pdev->dev, "UNKNOWN IP type %d\n",
641*4882a593Smuzhiyun 				sr->ip_type);
642*4882a593Smuzhiyun 		}
643*4882a593Smuzhiyun 	}
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun 	pm_runtime_put_sync_suspend(&sr->pdev->dev);
646*4882a593Smuzhiyun }
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun /**
649*4882a593Smuzhiyun  * sr_register_class() - API to register a smartreflex class parameters.
650*4882a593Smuzhiyun  * @class_data:	The structure containing various sr class specific data.
651*4882a593Smuzhiyun  *
652*4882a593Smuzhiyun  * This API is to be called by the smartreflex class driver to register itself
653*4882a593Smuzhiyun  * with the smartreflex driver during init. Returns 0 on success else the
654*4882a593Smuzhiyun  * error value.
655*4882a593Smuzhiyun  */
sr_register_class(struct omap_sr_class_data * class_data)656*4882a593Smuzhiyun int sr_register_class(struct omap_sr_class_data *class_data)
657*4882a593Smuzhiyun {
658*4882a593Smuzhiyun 	struct omap_sr *sr_info;
659*4882a593Smuzhiyun 
660*4882a593Smuzhiyun 	if (!class_data) {
661*4882a593Smuzhiyun 		pr_warn("%s:, Smartreflex class data passed is NULL\n",
662*4882a593Smuzhiyun 			__func__);
663*4882a593Smuzhiyun 		return -EINVAL;
664*4882a593Smuzhiyun 	}
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	if (sr_class) {
667*4882a593Smuzhiyun 		pr_warn("%s: Smartreflex class driver already registered\n",
668*4882a593Smuzhiyun 			__func__);
669*4882a593Smuzhiyun 		return -EBUSY;
670*4882a593Smuzhiyun 	}
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun 	sr_class = class_data;
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun 	/*
675*4882a593Smuzhiyun 	 * Call into late init to do initializations that require
676*4882a593Smuzhiyun 	 * both sr driver and sr class driver to be initiallized.
677*4882a593Smuzhiyun 	 */
678*4882a593Smuzhiyun 	list_for_each_entry(sr_info, &sr_list, node)
679*4882a593Smuzhiyun 		sr_late_init(sr_info);
680*4882a593Smuzhiyun 
681*4882a593Smuzhiyun 	return 0;
682*4882a593Smuzhiyun }
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun /**
685*4882a593Smuzhiyun  * omap_sr_enable() -  API to enable SR clocks and to call into the
686*4882a593Smuzhiyun  *			registered smartreflex class enable API.
687*4882a593Smuzhiyun  * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
688*4882a593Smuzhiyun  *
689*4882a593Smuzhiyun  * This API is to be called from the kernel in order to enable
690*4882a593Smuzhiyun  * a particular smartreflex module. This API will do the initial
691*4882a593Smuzhiyun  * configurations to turn on the smartreflex module and in turn call
692*4882a593Smuzhiyun  * into the registered smartreflex class enable API.
693*4882a593Smuzhiyun  */
omap_sr_enable(struct voltagedomain * voltdm)694*4882a593Smuzhiyun void omap_sr_enable(struct voltagedomain *voltdm)
695*4882a593Smuzhiyun {
696*4882a593Smuzhiyun 	struct omap_sr *sr = _sr_lookup(voltdm);
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun 	if (IS_ERR(sr)) {
699*4882a593Smuzhiyun 		pr_warn("%s: omap_sr struct for voltdm not found\n", __func__);
700*4882a593Smuzhiyun 		return;
701*4882a593Smuzhiyun 	}
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun 	if (!sr->autocomp_active)
704*4882a593Smuzhiyun 		return;
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun 	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
707*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not registered\n",
708*4882a593Smuzhiyun 			 __func__);
709*4882a593Smuzhiyun 		return;
710*4882a593Smuzhiyun 	}
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun 	sr_class->enable(sr);
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun /**
716*4882a593Smuzhiyun  * omap_sr_disable() - API to disable SR without resetting the voltage
717*4882a593Smuzhiyun  *			processor voltage
718*4882a593Smuzhiyun  * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
719*4882a593Smuzhiyun  *
720*4882a593Smuzhiyun  * This API is to be called from the kernel in order to disable
721*4882a593Smuzhiyun  * a particular smartreflex module. This API will in turn call
722*4882a593Smuzhiyun  * into the registered smartreflex class disable API. This API will tell
723*4882a593Smuzhiyun  * the smartreflex class disable not to reset the VP voltage after
724*4882a593Smuzhiyun  * disabling smartreflex.
725*4882a593Smuzhiyun  */
omap_sr_disable(struct voltagedomain * voltdm)726*4882a593Smuzhiyun void omap_sr_disable(struct voltagedomain *voltdm)
727*4882a593Smuzhiyun {
728*4882a593Smuzhiyun 	struct omap_sr *sr = _sr_lookup(voltdm);
729*4882a593Smuzhiyun 
730*4882a593Smuzhiyun 	if (IS_ERR(sr)) {
731*4882a593Smuzhiyun 		pr_warn("%s: omap_sr struct for voltdm not found\n", __func__);
732*4882a593Smuzhiyun 		return;
733*4882a593Smuzhiyun 	}
734*4882a593Smuzhiyun 
735*4882a593Smuzhiyun 	if (!sr->autocomp_active)
736*4882a593Smuzhiyun 		return;
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun 	if (!sr_class || !(sr_class->disable)) {
739*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not registered\n",
740*4882a593Smuzhiyun 			 __func__);
741*4882a593Smuzhiyun 		return;
742*4882a593Smuzhiyun 	}
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun 	sr_class->disable(sr, 0);
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun 
747*4882a593Smuzhiyun /**
748*4882a593Smuzhiyun  * omap_sr_disable_reset_volt() - API to disable SR and reset the
749*4882a593Smuzhiyun  *				voltage processor voltage
750*4882a593Smuzhiyun  * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
751*4882a593Smuzhiyun  *
752*4882a593Smuzhiyun  * This API is to be called from the kernel in order to disable
753*4882a593Smuzhiyun  * a particular smartreflex module. This API will in turn call
754*4882a593Smuzhiyun  * into the registered smartreflex class disable API. This API will tell
755*4882a593Smuzhiyun  * the smartreflex class disable to reset the VP voltage after
756*4882a593Smuzhiyun  * disabling smartreflex.
757*4882a593Smuzhiyun  */
omap_sr_disable_reset_volt(struct voltagedomain * voltdm)758*4882a593Smuzhiyun void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
759*4882a593Smuzhiyun {
760*4882a593Smuzhiyun 	struct omap_sr *sr = _sr_lookup(voltdm);
761*4882a593Smuzhiyun 
762*4882a593Smuzhiyun 	if (IS_ERR(sr)) {
763*4882a593Smuzhiyun 		pr_warn("%s: omap_sr struct for voltdm not found\n", __func__);
764*4882a593Smuzhiyun 		return;
765*4882a593Smuzhiyun 	}
766*4882a593Smuzhiyun 
767*4882a593Smuzhiyun 	if (!sr->autocomp_active)
768*4882a593Smuzhiyun 		return;
769*4882a593Smuzhiyun 
770*4882a593Smuzhiyun 	if (!sr_class || !(sr_class->disable)) {
771*4882a593Smuzhiyun 		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not registered\n",
772*4882a593Smuzhiyun 			 __func__);
773*4882a593Smuzhiyun 		return;
774*4882a593Smuzhiyun 	}
775*4882a593Smuzhiyun 
776*4882a593Smuzhiyun 	sr_class->disable(sr, 1);
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun 
779*4882a593Smuzhiyun /* PM Debug FS entries to enable and disable smartreflex. */
omap_sr_autocomp_show(void * data,u64 * val)780*4882a593Smuzhiyun static int omap_sr_autocomp_show(void *data, u64 *val)
781*4882a593Smuzhiyun {
782*4882a593Smuzhiyun 	struct omap_sr *sr_info = data;
783*4882a593Smuzhiyun 
784*4882a593Smuzhiyun 	if (!sr_info) {
785*4882a593Smuzhiyun 		pr_warn("%s: omap_sr struct not found\n", __func__);
786*4882a593Smuzhiyun 		return -EINVAL;
787*4882a593Smuzhiyun 	}
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun 	*val = sr_info->autocomp_active;
790*4882a593Smuzhiyun 
791*4882a593Smuzhiyun 	return 0;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun 
omap_sr_autocomp_store(void * data,u64 val)794*4882a593Smuzhiyun static int omap_sr_autocomp_store(void *data, u64 val)
795*4882a593Smuzhiyun {
796*4882a593Smuzhiyun 	struct omap_sr *sr_info = data;
797*4882a593Smuzhiyun 
798*4882a593Smuzhiyun 	if (!sr_info) {
799*4882a593Smuzhiyun 		pr_warn("%s: omap_sr struct not found\n", __func__);
800*4882a593Smuzhiyun 		return -EINVAL;
801*4882a593Smuzhiyun 	}
802*4882a593Smuzhiyun 
803*4882a593Smuzhiyun 	/* Sanity check */
804*4882a593Smuzhiyun 	if (val > 1) {
805*4882a593Smuzhiyun 		pr_warn("%s: Invalid argument %lld\n", __func__, val);
806*4882a593Smuzhiyun 		return -EINVAL;
807*4882a593Smuzhiyun 	}
808*4882a593Smuzhiyun 
809*4882a593Smuzhiyun 	/* control enable/disable only if there is a delta in value */
810*4882a593Smuzhiyun 	if (sr_info->autocomp_active != val) {
811*4882a593Smuzhiyun 		if (!val)
812*4882a593Smuzhiyun 			sr_stop_vddautocomp(sr_info);
813*4882a593Smuzhiyun 		else
814*4882a593Smuzhiyun 			sr_start_vddautocomp(sr_info);
815*4882a593Smuzhiyun 	}
816*4882a593Smuzhiyun 
817*4882a593Smuzhiyun 	return 0;
818*4882a593Smuzhiyun }
819*4882a593Smuzhiyun 
820*4882a593Smuzhiyun DEFINE_SIMPLE_ATTRIBUTE(pm_sr_fops, omap_sr_autocomp_show,
821*4882a593Smuzhiyun 			omap_sr_autocomp_store, "%llu\n");
822*4882a593Smuzhiyun 
omap_sr_probe(struct platform_device * pdev)823*4882a593Smuzhiyun static int omap_sr_probe(struct platform_device *pdev)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun 	struct omap_sr *sr_info;
826*4882a593Smuzhiyun 	struct omap_sr_data *pdata = pdev->dev.platform_data;
827*4882a593Smuzhiyun 	struct resource *mem, *irq;
828*4882a593Smuzhiyun 	struct dentry *nvalue_dir;
829*4882a593Smuzhiyun 	int i, ret = 0;
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun 	sr_info = devm_kzalloc(&pdev->dev, sizeof(struct omap_sr), GFP_KERNEL);
832*4882a593Smuzhiyun 	if (!sr_info)
833*4882a593Smuzhiyun 		return -ENOMEM;
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun 	sr_info->name = devm_kzalloc(&pdev->dev,
836*4882a593Smuzhiyun 				     SMARTREFLEX_NAME_LEN, GFP_KERNEL);
837*4882a593Smuzhiyun 	if (!sr_info->name)
838*4882a593Smuzhiyun 		return -ENOMEM;
839*4882a593Smuzhiyun 
840*4882a593Smuzhiyun 	platform_set_drvdata(pdev, sr_info);
841*4882a593Smuzhiyun 
842*4882a593Smuzhiyun 	if (!pdata) {
843*4882a593Smuzhiyun 		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
844*4882a593Smuzhiyun 		return -EINVAL;
845*4882a593Smuzhiyun 	}
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
848*4882a593Smuzhiyun 	sr_info->base = devm_ioremap_resource(&pdev->dev, mem);
849*4882a593Smuzhiyun 	if (IS_ERR(sr_info->base)) {
850*4882a593Smuzhiyun 		dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
851*4882a593Smuzhiyun 		return PTR_ERR(sr_info->base);
852*4882a593Smuzhiyun 	}
853*4882a593Smuzhiyun 
854*4882a593Smuzhiyun 	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun 	pm_runtime_enable(&pdev->dev);
857*4882a593Smuzhiyun 	pm_runtime_irq_safe(&pdev->dev);
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun 	snprintf(sr_info->name, SMARTREFLEX_NAME_LEN, "%s", pdata->name);
860*4882a593Smuzhiyun 
861*4882a593Smuzhiyun 	sr_info->pdev = pdev;
862*4882a593Smuzhiyun 	sr_info->srid = pdev->id;
863*4882a593Smuzhiyun 	sr_info->voltdm = pdata->voltdm;
864*4882a593Smuzhiyun 	sr_info->nvalue_table = pdata->nvalue_table;
865*4882a593Smuzhiyun 	sr_info->nvalue_count = pdata->nvalue_count;
866*4882a593Smuzhiyun 	sr_info->senn_mod = pdata->senn_mod;
867*4882a593Smuzhiyun 	sr_info->senp_mod = pdata->senp_mod;
868*4882a593Smuzhiyun 	sr_info->err_weight = pdata->err_weight;
869*4882a593Smuzhiyun 	sr_info->err_maxlimit = pdata->err_maxlimit;
870*4882a593Smuzhiyun 	sr_info->accum_data = pdata->accum_data;
871*4882a593Smuzhiyun 	sr_info->senn_avgweight = pdata->senn_avgweight;
872*4882a593Smuzhiyun 	sr_info->senp_avgweight = pdata->senp_avgweight;
873*4882a593Smuzhiyun 	sr_info->autocomp_active = false;
874*4882a593Smuzhiyun 	sr_info->ip_type = pdata->ip_type;
875*4882a593Smuzhiyun 
876*4882a593Smuzhiyun 	if (irq)
877*4882a593Smuzhiyun 		sr_info->irq = irq->start;
878*4882a593Smuzhiyun 
879*4882a593Smuzhiyun 	sr_set_clk_length(sr_info);
880*4882a593Smuzhiyun 
881*4882a593Smuzhiyun 	list_add(&sr_info->node, &sr_list);
882*4882a593Smuzhiyun 
883*4882a593Smuzhiyun 	ret = pm_runtime_get_sync(&pdev->dev);
884*4882a593Smuzhiyun 	if (ret < 0) {
885*4882a593Smuzhiyun 		pm_runtime_put_noidle(&pdev->dev);
886*4882a593Smuzhiyun 		goto err_list_del;
887*4882a593Smuzhiyun 	}
888*4882a593Smuzhiyun 
889*4882a593Smuzhiyun 	/*
890*4882a593Smuzhiyun 	 * Call into late init to do initializations that require
891*4882a593Smuzhiyun 	 * both sr driver and sr class driver to be initiallized.
892*4882a593Smuzhiyun 	 */
893*4882a593Smuzhiyun 	if (sr_class) {
894*4882a593Smuzhiyun 		ret = sr_late_init(sr_info);
895*4882a593Smuzhiyun 		if (ret) {
896*4882a593Smuzhiyun 			pr_warn("%s: Error in SR late init\n", __func__);
897*4882a593Smuzhiyun 			goto err_list_del;
898*4882a593Smuzhiyun 		}
899*4882a593Smuzhiyun 	}
900*4882a593Smuzhiyun 
901*4882a593Smuzhiyun 	dev_info(&pdev->dev, "%s: SmartReflex driver initialized\n", __func__);
902*4882a593Smuzhiyun 	if (!sr_dbg_dir)
903*4882a593Smuzhiyun 		sr_dbg_dir = debugfs_create_dir("smartreflex", NULL);
904*4882a593Smuzhiyun 
905*4882a593Smuzhiyun 	sr_info->dbg_dir = debugfs_create_dir(sr_info->name, sr_dbg_dir);
906*4882a593Smuzhiyun 
907*4882a593Smuzhiyun 	debugfs_create_file("autocomp", S_IRUGO | S_IWUSR, sr_info->dbg_dir,
908*4882a593Smuzhiyun 			    sr_info, &pm_sr_fops);
909*4882a593Smuzhiyun 	debugfs_create_x32("errweight", S_IRUGO, sr_info->dbg_dir,
910*4882a593Smuzhiyun 			   &sr_info->err_weight);
911*4882a593Smuzhiyun 	debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
912*4882a593Smuzhiyun 			   &sr_info->err_maxlimit);
913*4882a593Smuzhiyun 
914*4882a593Smuzhiyun 	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun 	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
917*4882a593Smuzhiyun 		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
918*4882a593Smuzhiyun 			 __func__, sr_info->name);
919*4882a593Smuzhiyun 
920*4882a593Smuzhiyun 		ret = -ENODATA;
921*4882a593Smuzhiyun 		goto err_debugfs;
922*4882a593Smuzhiyun 	}
923*4882a593Smuzhiyun 
924*4882a593Smuzhiyun 	for (i = 0; i < sr_info->nvalue_count; i++) {
925*4882a593Smuzhiyun 		char name[NVALUE_NAME_LEN + 1];
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun 		snprintf(name, sizeof(name), "volt_%lu",
928*4882a593Smuzhiyun 				sr_info->nvalue_table[i].volt_nominal);
929*4882a593Smuzhiyun 		debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
930*4882a593Smuzhiyun 				   &(sr_info->nvalue_table[i].nvalue));
931*4882a593Smuzhiyun 		snprintf(name, sizeof(name), "errminlimit_%lu",
932*4882a593Smuzhiyun 			 sr_info->nvalue_table[i].volt_nominal);
933*4882a593Smuzhiyun 		debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
934*4882a593Smuzhiyun 				   &(sr_info->nvalue_table[i].errminlimit));
935*4882a593Smuzhiyun 
936*4882a593Smuzhiyun 	}
937*4882a593Smuzhiyun 
938*4882a593Smuzhiyun 	pm_runtime_put_sync(&pdev->dev);
939*4882a593Smuzhiyun 
940*4882a593Smuzhiyun 	return ret;
941*4882a593Smuzhiyun 
942*4882a593Smuzhiyun err_debugfs:
943*4882a593Smuzhiyun 	debugfs_remove_recursive(sr_info->dbg_dir);
944*4882a593Smuzhiyun err_list_del:
945*4882a593Smuzhiyun 	list_del(&sr_info->node);
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun 	pm_runtime_put_sync(&pdev->dev);
948*4882a593Smuzhiyun 
949*4882a593Smuzhiyun 	return ret;
950*4882a593Smuzhiyun }
951*4882a593Smuzhiyun 
omap_sr_remove(struct platform_device * pdev)952*4882a593Smuzhiyun static int omap_sr_remove(struct platform_device *pdev)
953*4882a593Smuzhiyun {
954*4882a593Smuzhiyun 	struct omap_sr_data *pdata = pdev->dev.platform_data;
955*4882a593Smuzhiyun 	struct omap_sr *sr_info;
956*4882a593Smuzhiyun 
957*4882a593Smuzhiyun 	if (!pdata) {
958*4882a593Smuzhiyun 		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
959*4882a593Smuzhiyun 		return -EINVAL;
960*4882a593Smuzhiyun 	}
961*4882a593Smuzhiyun 
962*4882a593Smuzhiyun 	sr_info = _sr_lookup(pdata->voltdm);
963*4882a593Smuzhiyun 	if (IS_ERR(sr_info)) {
964*4882a593Smuzhiyun 		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
965*4882a593Smuzhiyun 			__func__);
966*4882a593Smuzhiyun 		return PTR_ERR(sr_info);
967*4882a593Smuzhiyun 	}
968*4882a593Smuzhiyun 
969*4882a593Smuzhiyun 	if (sr_info->autocomp_active)
970*4882a593Smuzhiyun 		sr_stop_vddautocomp(sr_info);
971*4882a593Smuzhiyun 	debugfs_remove_recursive(sr_info->dbg_dir);
972*4882a593Smuzhiyun 
973*4882a593Smuzhiyun 	pm_runtime_disable(&pdev->dev);
974*4882a593Smuzhiyun 	list_del(&sr_info->node);
975*4882a593Smuzhiyun 	return 0;
976*4882a593Smuzhiyun }
977*4882a593Smuzhiyun 
omap_sr_shutdown(struct platform_device * pdev)978*4882a593Smuzhiyun static void omap_sr_shutdown(struct platform_device *pdev)
979*4882a593Smuzhiyun {
980*4882a593Smuzhiyun 	struct omap_sr_data *pdata = pdev->dev.platform_data;
981*4882a593Smuzhiyun 	struct omap_sr *sr_info;
982*4882a593Smuzhiyun 
983*4882a593Smuzhiyun 	if (!pdata) {
984*4882a593Smuzhiyun 		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
985*4882a593Smuzhiyun 		return;
986*4882a593Smuzhiyun 	}
987*4882a593Smuzhiyun 
988*4882a593Smuzhiyun 	sr_info = _sr_lookup(pdata->voltdm);
989*4882a593Smuzhiyun 	if (IS_ERR(sr_info)) {
990*4882a593Smuzhiyun 		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
991*4882a593Smuzhiyun 			__func__);
992*4882a593Smuzhiyun 		return;
993*4882a593Smuzhiyun 	}
994*4882a593Smuzhiyun 
995*4882a593Smuzhiyun 	if (sr_info->autocomp_active)
996*4882a593Smuzhiyun 		sr_stop_vddautocomp(sr_info);
997*4882a593Smuzhiyun 
998*4882a593Smuzhiyun 	return;
999*4882a593Smuzhiyun }
1000*4882a593Smuzhiyun 
1001*4882a593Smuzhiyun static const struct of_device_id omap_sr_match[] = {
1002*4882a593Smuzhiyun 	{ .compatible = "ti,omap3-smartreflex-core", },
1003*4882a593Smuzhiyun 	{ .compatible = "ti,omap3-smartreflex-mpu-iva", },
1004*4882a593Smuzhiyun 	{ .compatible = "ti,omap4-smartreflex-core", },
1005*4882a593Smuzhiyun 	{ .compatible = "ti,omap4-smartreflex-mpu", },
1006*4882a593Smuzhiyun 	{ .compatible = "ti,omap4-smartreflex-iva", },
1007*4882a593Smuzhiyun 	{  },
1008*4882a593Smuzhiyun };
1009*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, omap_sr_match);
1010*4882a593Smuzhiyun 
1011*4882a593Smuzhiyun static struct platform_driver smartreflex_driver = {
1012*4882a593Smuzhiyun 	.probe		= omap_sr_probe,
1013*4882a593Smuzhiyun 	.remove         = omap_sr_remove,
1014*4882a593Smuzhiyun 	.shutdown	= omap_sr_shutdown,
1015*4882a593Smuzhiyun 	.driver		= {
1016*4882a593Smuzhiyun 		.name	= DRIVER_NAME,
1017*4882a593Smuzhiyun 		.of_match_table	= omap_sr_match,
1018*4882a593Smuzhiyun 	},
1019*4882a593Smuzhiyun };
1020*4882a593Smuzhiyun 
sr_init(void)1021*4882a593Smuzhiyun static int __init sr_init(void)
1022*4882a593Smuzhiyun {
1023*4882a593Smuzhiyun 	int ret = 0;
1024*4882a593Smuzhiyun 
1025*4882a593Smuzhiyun 	ret = platform_driver_register(&smartreflex_driver);
1026*4882a593Smuzhiyun 	if (ret) {
1027*4882a593Smuzhiyun 		pr_err("%s: platform driver register failed for SR\n",
1028*4882a593Smuzhiyun 		       __func__);
1029*4882a593Smuzhiyun 		return ret;
1030*4882a593Smuzhiyun 	}
1031*4882a593Smuzhiyun 
1032*4882a593Smuzhiyun 	return 0;
1033*4882a593Smuzhiyun }
1034*4882a593Smuzhiyun late_initcall(sr_init);
1035*4882a593Smuzhiyun 
sr_exit(void)1036*4882a593Smuzhiyun static void __exit sr_exit(void)
1037*4882a593Smuzhiyun {
1038*4882a593Smuzhiyun 	platform_driver_unregister(&smartreflex_driver);
1039*4882a593Smuzhiyun }
1040*4882a593Smuzhiyun module_exit(sr_exit);
1041*4882a593Smuzhiyun 
1042*4882a593Smuzhiyun MODULE_DESCRIPTION("OMAP Smartreflex Driver");
1043*4882a593Smuzhiyun MODULE_LICENSE("GPL");
1044*4882a593Smuzhiyun MODULE_ALIAS("platform:" DRIVER_NAME);
1045*4882a593Smuzhiyun MODULE_AUTHOR("Texas Instruments Inc");
1046