2 * OMAP SmartReflex Voltage Control
4 * Author: Thara Gopinath <thara@ti.com>
6 * Copyright (C) 2010 Texas Instruments, Inc.
7 * Thara Gopinath <thara@ti.com>
9 * Copyright (C) 2008 Nokia Corporation
12 * Copyright (C) 2007 Texas Instruments, Inc.
13 * Lesly A M <x0080970@ti.com>
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.
20 #include <linux/module.h>
21 #include <linux/interrupt.h>
22 #include <linux/clk.h>
24 #include <linux/debugfs.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pm_runtime.h>
32 #include "smartreflex.h"
34 #define SMARTREFLEX_NAME_LEN 16
35 #define NVALUE_NAME_LEN 40
36 #define SR_DISABLE_TIMEOUT 200
54 struct platform_device
*pdev
;
55 struct list_head node
;
56 struct omap_sr_nvalue_table
*nvalue_table
;
57 struct voltagedomain
*voltdm
;
58 struct dentry
*dbg_dir
;
61 /* sr_list contains all the instances of smartreflex module */
62 static LIST_HEAD(sr_list
);
64 static struct omap_sr_class_data
*sr_class
;
65 static struct omap_sr_pmic_data
*sr_pmic_data
;
66 static struct dentry
*sr_dbg_dir
;
68 static inline void sr_write_reg(struct omap_sr
*sr
, unsigned offset
, u32 value
)
70 __raw_writel(value
, (sr
->base
+ offset
));
73 static inline void sr_modify_reg(struct omap_sr
*sr
, unsigned offset
, u32 mask
,
77 u32 errconfig_offs
= 0, errconfig_mask
= 0;
79 reg_val
= __raw_readl(sr
->base
+ offset
);
83 * Smartreflex error config register is special as it contains
84 * certain status bits which if written a 1 into means a clear
85 * of those bits. So in order to make sure no accidental write of
86 * 1 happens to those status bits, do a clear of them in the read
87 * value. This mean this API doesn't rewrite values in these bits
88 * if they are currently set, but does allow the caller to write
91 if (sr
->ip_type
== SR_TYPE_V1
) {
92 errconfig_offs
= ERRCONFIG_V1
;
93 errconfig_mask
= ERRCONFIG_STATUS_V1_MASK
;
94 } else if (sr
->ip_type
== SR_TYPE_V2
) {
95 errconfig_offs
= ERRCONFIG_V2
;
96 errconfig_mask
= ERRCONFIG_VPBOUNDINTST_V2
;
99 if (offset
== errconfig_offs
)
100 reg_val
&= ~errconfig_mask
;
104 __raw_writel(reg_val
, (sr
->base
+ offset
));
107 static inline u32
sr_read_reg(struct omap_sr
*sr
, unsigned offset
)
109 return __raw_readl(sr
->base
+ offset
);
112 static struct omap_sr
*_sr_lookup(struct voltagedomain
*voltdm
)
114 struct omap_sr
*sr_info
;
117 pr_err("%s: Null voltage domain passed!\n", __func__
);
118 return ERR_PTR(-EINVAL
);
121 list_for_each_entry(sr_info
, &sr_list
, node
) {
122 if (voltdm
== sr_info
->voltdm
)
126 return ERR_PTR(-ENODATA
);
129 static irqreturn_t
sr_interrupt(int irq
, void *data
)
131 struct omap_sr
*sr_info
= (struct omap_sr
*)data
;
134 if (sr_info
->ip_type
== SR_TYPE_V1
) {
135 /* Read the status bits */
136 status
= sr_read_reg(sr_info
, ERRCONFIG_V1
);
138 /* Clear them by writing back */
139 sr_write_reg(sr_info
, ERRCONFIG_V1
, status
);
140 } else if (sr_info
->ip_type
== SR_TYPE_V2
) {
141 /* Read the status bits */
142 status
= sr_read_reg(sr_info
, IRQSTATUS
);
144 /* Clear them by writing back */
145 sr_write_reg(sr_info
, IRQSTATUS
, status
);
148 if (sr_class
->notify
)
149 sr_class
->notify(sr_info
->voltdm
, status
);
154 static void sr_set_clk_length(struct omap_sr
*sr
)
159 if (cpu_is_omap34xx())
160 sys_ck
= clk_get(NULL
, "sys_ck");
162 sys_ck
= clk_get(NULL
, "sys_clkin_ck");
164 if (IS_ERR(sys_ck
)) {
165 dev_err(&sr
->pdev
->dev
, "%s: unable to get sys clk\n",
169 sys_clk_speed
= clk_get_rate(sys_ck
);
172 switch (sys_clk_speed
) {
174 sr
->clk_length
= SRCLKLENGTH_12MHZ_SYSCLK
;
177 sr
->clk_length
= SRCLKLENGTH_13MHZ_SYSCLK
;
180 sr
->clk_length
= SRCLKLENGTH_19MHZ_SYSCLK
;
183 sr
->clk_length
= SRCLKLENGTH_26MHZ_SYSCLK
;
186 sr
->clk_length
= SRCLKLENGTH_38MHZ_SYSCLK
;
189 dev_err(&sr
->pdev
->dev
, "%s: Invalid sysclk value: %d\n",
190 __func__
, sys_clk_speed
);
195 static void sr_set_regfields(struct omap_sr
*sr
)
198 * For time being these values are defined in smartreflex.h
199 * and populated during init. May be they can be moved to board
200 * file or pmic specific data structure. In that case these structure
201 * fields will have to be populated using the pdata or pmic structure.
203 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
204 sr
->err_weight
= OMAP3430_SR_ERRWEIGHT
;
205 sr
->err_maxlimit
= OMAP3430_SR_ERRMAXLIMIT
;
206 sr
->accum_data
= OMAP3430_SR_ACCUMDATA
;
207 if (!(strcmp(sr
->voltdm
->name
, "mpu"))) {
208 sr
->senn_avgweight
= OMAP3430_SR1_SENNAVGWEIGHT
;
209 sr
->senp_avgweight
= OMAP3430_SR1_SENPAVGWEIGHT
;
211 sr
->senn_avgweight
= OMAP3430_SR2_SENNAVGWEIGHT
;
212 sr
->senp_avgweight
= OMAP3430_SR2_SENPAVGWEIGHT
;
217 static void sr_start_vddautocomp(struct omap_sr
*sr
)
219 if (!sr_class
|| !(sr_class
->enable
) || !(sr_class
->configure
)) {
220 dev_warn(&sr
->pdev
->dev
,
221 "%s: smartreflex class driver not registered\n",
226 if (!sr_class
->enable(sr
->voltdm
))
227 sr
->autocomp_active
= true;
230 static void sr_stop_vddautocomp(struct omap_sr
*sr
)
232 if (!sr_class
|| !(sr_class
->disable
)) {
233 dev_warn(&sr
->pdev
->dev
,
234 "%s: smartreflex class driver not registered\n",
239 if (sr
->autocomp_active
) {
240 sr_class
->disable(sr
->voltdm
, 1);
241 sr
->autocomp_active
= false;
246 * This function handles the intializations which have to be done
247 * only when both sr device and class driver regiter has
248 * completed. This will be attempted to be called from both sr class
249 * driver register and sr device intializtion API's. Only one call
250 * will ultimately succeed.
252 * Currently this function registers interrupt handler for a particular SR
253 * if smartreflex class driver is already registered and has
254 * requested for interrupts and the SR interrupt line in present.
256 static int sr_late_init(struct omap_sr
*sr_info
)
259 struct omap_sr_data
*pdata
= sr_info
->pdev
->dev
.platform_data
;
260 struct resource
*mem
;
263 if (sr_class
->notify
&& sr_class
->notify_flags
&& sr_info
->irq
) {
264 name
= kasprintf(GFP_KERNEL
, "sr_%s", sr_info
->voltdm
->name
);
269 ret
= request_irq(sr_info
->irq
, sr_interrupt
,
270 0, name
, (void *)sr_info
);
273 disable_irq(sr_info
->irq
);
276 if (pdata
&& pdata
->enable_on_init
)
277 sr_start_vddautocomp(sr_info
);
282 iounmap(sr_info
->base
);
283 mem
= platform_get_resource(sr_info
->pdev
, IORESOURCE_MEM
, 0);
284 release_mem_region(mem
->start
, resource_size(mem
));
285 list_del(&sr_info
->node
);
286 dev_err(&sr_info
->pdev
->dev
, "%s: ERROR in registering"
287 "interrupt handler. Smartreflex will"
288 "not function as desired\n", __func__
);
294 static void sr_v1_disable(struct omap_sr
*sr
)
298 /* Enable MCUDisableAcknowledge interrupt */
299 sr_modify_reg(sr
, ERRCONFIG_V1
,
300 ERRCONFIG_MCUDISACKINTEN
, ERRCONFIG_MCUDISACKINTEN
);
302 /* SRCONFIG - disable SR */
303 sr_modify_reg(sr
, SRCONFIG
, SRCONFIG_SRENABLE
, 0x0);
305 /* Disable all other SR interrupts and clear the status */
306 sr_modify_reg(sr
, ERRCONFIG_V1
,
307 (ERRCONFIG_MCUACCUMINTEN
| ERRCONFIG_MCUVALIDINTEN
|
308 ERRCONFIG_MCUBOUNDINTEN
| ERRCONFIG_VPBOUNDINTEN_V1
),
309 (ERRCONFIG_MCUACCUMINTST
| ERRCONFIG_MCUVALIDINTST
|
310 ERRCONFIG_MCUBOUNDINTST
|
311 ERRCONFIG_VPBOUNDINTST_V1
));
314 * Wait for SR to be disabled.
315 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
317 omap_test_timeout((sr_read_reg(sr
, ERRCONFIG_V1
) &
318 ERRCONFIG_MCUDISACKINTST
), SR_DISABLE_TIMEOUT
,
321 if (timeout
>= SR_DISABLE_TIMEOUT
)
322 dev_warn(&sr
->pdev
->dev
, "%s: Smartreflex disable timedout\n",
325 /* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
326 sr_modify_reg(sr
, ERRCONFIG_V1
, ERRCONFIG_MCUDISACKINTEN
,
327 ERRCONFIG_MCUDISACKINTST
);
330 static void sr_v2_disable(struct omap_sr
*sr
)
334 /* Enable MCUDisableAcknowledge interrupt */
335 sr_write_reg(sr
, IRQENABLE_SET
, IRQENABLE_MCUDISABLEACKINT
);
337 /* SRCONFIG - disable SR */
338 sr_modify_reg(sr
, SRCONFIG
, SRCONFIG_SRENABLE
, 0x0);
340 /* Disable all other SR interrupts and clear the status */
341 sr_modify_reg(sr
, ERRCONFIG_V2
, ERRCONFIG_VPBOUNDINTEN_V2
,
342 ERRCONFIG_VPBOUNDINTST_V2
);
343 sr_write_reg(sr
, IRQENABLE_CLR
, (IRQENABLE_MCUACCUMINT
|
344 IRQENABLE_MCUVALIDINT
|
345 IRQENABLE_MCUBOUNDSINT
));
346 sr_write_reg(sr
, IRQSTATUS
, (IRQSTATUS_MCUACCUMINT
|
347 IRQSTATUS_MCVALIDINT
|
348 IRQSTATUS_MCBOUNDSINT
));
351 * Wait for SR to be disabled.
352 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
354 omap_test_timeout((sr_read_reg(sr
, IRQSTATUS
) &
355 IRQSTATUS_MCUDISABLEACKINT
), SR_DISABLE_TIMEOUT
,
358 if (timeout
>= SR_DISABLE_TIMEOUT
)
359 dev_warn(&sr
->pdev
->dev
, "%s: Smartreflex disable timedout\n",
362 /* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
363 sr_write_reg(sr
, IRQENABLE_CLR
, IRQENABLE_MCUDISABLEACKINT
);
364 sr_write_reg(sr
, IRQSTATUS
, IRQSTATUS_MCUDISABLEACKINT
);
367 static u32
sr_retrieve_nvalue(struct omap_sr
*sr
, u32 efuse_offs
)
371 if (!sr
->nvalue_table
) {
372 dev_warn(&sr
->pdev
->dev
, "%s: Missing ntarget value table\n",
377 for (i
= 0; i
< sr
->nvalue_count
; i
++) {
378 if (sr
->nvalue_table
[i
].efuse_offs
== efuse_offs
)
379 return sr
->nvalue_table
[i
].nvalue
;
385 /* Public Functions */
388 * sr_configure_errgen() - Configures the smrtreflex to perform AVS using the
389 * error generator module.
390 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
392 * This API is to be called from the smartreflex class driver to
393 * configure the error generator module inside the smartreflex module.
394 * SR settings if using the ERROR module inside Smartreflex.
395 * SR CLASS 3 by default uses only the ERROR module where as
396 * SR CLASS 2 can choose between ERROR module and MINMAXAVG
397 * module. Returns 0 on success and error value in case of failure.
399 int sr_configure_errgen(struct voltagedomain
*voltdm
)
401 u32 sr_config
, sr_errconfig
, errconfig_offs
, vpboundint_en
;
402 u32 vpboundint_st
, senp_en
= 0, senn_en
= 0;
403 u8 senp_shift
, senn_shift
;
404 struct omap_sr
*sr
= _sr_lookup(voltdm
);
407 pr_warning("%s: omap_sr struct for sr_%s not found\n",
408 __func__
, voltdm
->name
);
413 sr_set_clk_length(sr
);
415 senp_en
= sr
->senp_mod
;
416 senn_en
= sr
->senn_mod
;
418 sr_config
= (sr
->clk_length
<< SRCONFIG_SRCLKLENGTH_SHIFT
) |
419 SRCONFIG_SENENABLE
| SRCONFIG_ERRGEN_EN
;
421 if (sr
->ip_type
== SR_TYPE_V1
) {
422 sr_config
|= SRCONFIG_DELAYCTRL
;
423 senn_shift
= SRCONFIG_SENNENABLE_V1_SHIFT
;
424 senp_shift
= SRCONFIG_SENPENABLE_V1_SHIFT
;
425 errconfig_offs
= ERRCONFIG_V1
;
426 vpboundint_en
= ERRCONFIG_VPBOUNDINTEN_V1
;
427 vpboundint_st
= ERRCONFIG_VPBOUNDINTST_V1
;
428 } else if (sr
->ip_type
== SR_TYPE_V2
) {
429 senn_shift
= SRCONFIG_SENNENABLE_V2_SHIFT
;
430 senp_shift
= SRCONFIG_SENPENABLE_V2_SHIFT
;
431 errconfig_offs
= ERRCONFIG_V2
;
432 vpboundint_en
= ERRCONFIG_VPBOUNDINTEN_V2
;
433 vpboundint_st
= ERRCONFIG_VPBOUNDINTST_V2
;
435 dev_err(&sr
->pdev
->dev
, "%s: Trying to Configure smartreflex"
436 "module without specifying the ip\n", __func__
);
440 sr_config
|= ((senn_en
<< senn_shift
) | (senp_en
<< senp_shift
));
441 sr_write_reg(sr
, SRCONFIG
, sr_config
);
442 sr_errconfig
= (sr
->err_weight
<< ERRCONFIG_ERRWEIGHT_SHIFT
) |
443 (sr
->err_maxlimit
<< ERRCONFIG_ERRMAXLIMIT_SHIFT
) |
444 (sr
->err_minlimit
<< ERRCONFIG_ERRMINLIMIT_SHIFT
);
445 sr_modify_reg(sr
, errconfig_offs
, (SR_ERRWEIGHT_MASK
|
446 SR_ERRMAXLIMIT_MASK
| SR_ERRMINLIMIT_MASK
),
449 /* Enabling the interrupts if the ERROR module is used */
450 sr_modify_reg(sr
, errconfig_offs
,
451 vpboundint_en
, (vpboundint_en
| vpboundint_st
));
457 * sr_configure_minmax() - Configures the smrtreflex to perform AVS using the
459 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
461 * This API is to be called from the smartreflex class driver to
462 * configure the minmaxavg module inside the smartreflex module.
463 * SR settings if using the ERROR module inside Smartreflex.
464 * SR CLASS 3 by default uses only the ERROR module where as
465 * SR CLASS 2 can choose between ERROR module and MINMAXAVG
466 * module. Returns 0 on success and error value in case of failure.
468 int sr_configure_minmax(struct voltagedomain
*voltdm
)
470 u32 sr_config
, sr_avgwt
;
471 u32 senp_en
= 0, senn_en
= 0;
472 u8 senp_shift
, senn_shift
;
473 struct omap_sr
*sr
= _sr_lookup(voltdm
);
476 pr_warning("%s: omap_sr struct for sr_%s not found\n",
477 __func__
, voltdm
->name
);
482 sr_set_clk_length(sr
);
484 senp_en
= sr
->senp_mod
;
485 senn_en
= sr
->senn_mod
;
487 sr_config
= (sr
->clk_length
<< SRCONFIG_SRCLKLENGTH_SHIFT
) |
489 (sr
->accum_data
<< SRCONFIG_ACCUMDATA_SHIFT
);
491 if (sr
->ip_type
== SR_TYPE_V1
) {
492 sr_config
|= SRCONFIG_DELAYCTRL
;
493 senn_shift
= SRCONFIG_SENNENABLE_V1_SHIFT
;
494 senp_shift
= SRCONFIG_SENPENABLE_V1_SHIFT
;
495 } else if (sr
->ip_type
== SR_TYPE_V2
) {
496 senn_shift
= SRCONFIG_SENNENABLE_V2_SHIFT
;
497 senp_shift
= SRCONFIG_SENPENABLE_V2_SHIFT
;
499 dev_err(&sr
->pdev
->dev
, "%s: Trying to Configure smartreflex"
500 "module without specifying the ip\n", __func__
);
504 sr_config
|= ((senn_en
<< senn_shift
) | (senp_en
<< senp_shift
));
505 sr_write_reg(sr
, SRCONFIG
, sr_config
);
506 sr_avgwt
= (sr
->senp_avgweight
<< AVGWEIGHT_SENPAVGWEIGHT_SHIFT
) |
507 (sr
->senn_avgweight
<< AVGWEIGHT_SENNAVGWEIGHT_SHIFT
);
508 sr_write_reg(sr
, AVGWEIGHT
, sr_avgwt
);
511 * Enabling the interrupts if MINMAXAVG module is used.
512 * TODO: check if all the interrupts are mandatory
514 if (sr
->ip_type
== SR_TYPE_V1
) {
515 sr_modify_reg(sr
, ERRCONFIG_V1
,
516 (ERRCONFIG_MCUACCUMINTEN
| ERRCONFIG_MCUVALIDINTEN
|
517 ERRCONFIG_MCUBOUNDINTEN
),
518 (ERRCONFIG_MCUACCUMINTEN
| ERRCONFIG_MCUACCUMINTST
|
519 ERRCONFIG_MCUVALIDINTEN
| ERRCONFIG_MCUVALIDINTST
|
520 ERRCONFIG_MCUBOUNDINTEN
| ERRCONFIG_MCUBOUNDINTST
));
521 } else if (sr
->ip_type
== SR_TYPE_V2
) {
522 sr_write_reg(sr
, IRQSTATUS
,
523 IRQSTATUS_MCUACCUMINT
| IRQSTATUS_MCVALIDINT
|
524 IRQSTATUS_MCBOUNDSINT
| IRQSTATUS_MCUDISABLEACKINT
);
525 sr_write_reg(sr
, IRQENABLE_SET
,
526 IRQENABLE_MCUACCUMINT
| IRQENABLE_MCUVALIDINT
|
527 IRQENABLE_MCUBOUNDSINT
| IRQENABLE_MCUDISABLEACKINT
);
534 * sr_enable() - Enables the smartreflex module.
535 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
536 * @volt: The voltage at which the Voltage domain associated with
537 * the smartreflex module is operating at.
538 * This is required only to program the correct Ntarget value.
540 * This API is to be called from the smartreflex class driver to
541 * enable a smartreflex module. Returns 0 on success. Returns error
542 * value if the voltage passed is wrong or if ntarget value is wrong.
544 int sr_enable(struct voltagedomain
*voltdm
, unsigned long volt
)
546 u32 nvalue_reciprocal
;
547 struct omap_volt_data
*volt_data
;
548 struct omap_sr
*sr
= _sr_lookup(voltdm
);
552 pr_warning("%s: omap_sr struct for sr_%s not found\n",
553 __func__
, voltdm
->name
);
557 volt_data
= omap_voltage_get_voltdata(sr
->voltdm
, volt
);
559 if (IS_ERR(volt_data
)) {
560 dev_warn(&sr
->pdev
->dev
, "%s: Unable to get voltage table"
561 "for nominal voltage %ld\n", __func__
, volt
);
565 nvalue_reciprocal
= sr_retrieve_nvalue(sr
, volt_data
->sr_efuse_offs
);
567 if (!nvalue_reciprocal
) {
568 dev_warn(&sr
->pdev
->dev
, "%s: NVALUE = 0 at voltage %ld\n",
573 /* errminlimit is opp dependent and hence linked to voltage */
574 sr
->err_minlimit
= volt_data
->sr_errminlimit
;
576 pm_runtime_get_sync(&sr
->pdev
->dev
);
578 /* Check if SR is already enabled. If yes do nothing */
579 if (sr_read_reg(sr
, SRCONFIG
) & SRCONFIG_SRENABLE
)
583 ret
= sr_class
->configure(voltdm
);
587 sr_write_reg(sr
, NVALUERECIPROCAL
, nvalue_reciprocal
);
589 /* SRCONFIG - enable SR */
590 sr_modify_reg(sr
, SRCONFIG
, SRCONFIG_SRENABLE
, SRCONFIG_SRENABLE
);
595 * sr_disable() - Disables the smartreflex module.
596 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
598 * This API is to be called from the smartreflex class driver to
599 * disable a smartreflex module.
601 void sr_disable(struct voltagedomain
*voltdm
)
603 struct omap_sr
*sr
= _sr_lookup(voltdm
);
606 pr_warning("%s: omap_sr struct for sr_%s not found\n",
607 __func__
, voltdm
->name
);
611 /* Check if SR clocks are already disabled. If yes do nothing */
612 if (pm_runtime_suspended(&sr
->pdev
->dev
))
616 * Disable SR if only it is indeed enabled. Else just
617 * disable the clocks.
619 if (sr_read_reg(sr
, SRCONFIG
) & SRCONFIG_SRENABLE
) {
620 if (sr
->ip_type
== SR_TYPE_V1
)
622 else if (sr
->ip_type
== SR_TYPE_V2
)
626 pm_runtime_put_sync_suspend(&sr
->pdev
->dev
);
630 * sr_register_class() - API to register a smartreflex class parameters.
631 * @class_data: The structure containing various sr class specific data.
633 * This API is to be called by the smartreflex class driver to register itself
634 * with the smartreflex driver during init. Returns 0 on success else the
637 int sr_register_class(struct omap_sr_class_data
*class_data
)
639 struct omap_sr
*sr_info
;
642 pr_warning("%s:, Smartreflex class data passed is NULL\n",
648 pr_warning("%s: Smartreflex class driver already registered\n",
653 sr_class
= class_data
;
656 * Call into late init to do intializations that require
657 * both sr driver and sr class driver to be initiallized.
659 list_for_each_entry(sr_info
, &sr_list
, node
)
660 sr_late_init(sr_info
);
666 * omap_sr_enable() - API to enable SR clocks and to call into the
667 * registered smartreflex class enable API.
668 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
670 * This API is to be called from the kernel in order to enable
671 * a particular smartreflex module. This API will do the initial
672 * configurations to turn on the smartreflex module and in turn call
673 * into the registered smartreflex class enable API.
675 void omap_sr_enable(struct voltagedomain
*voltdm
)
677 struct omap_sr
*sr
= _sr_lookup(voltdm
);
680 pr_warning("%s: omap_sr struct for sr_%s not found\n",
681 __func__
, voltdm
->name
);
685 if (!sr
->autocomp_active
)
688 if (!sr_class
|| !(sr_class
->enable
) || !(sr_class
->configure
)) {
689 dev_warn(&sr
->pdev
->dev
, "%s: smartreflex class driver not"
690 "registered\n", __func__
);
694 sr_class
->enable(voltdm
);
698 * omap_sr_disable() - API to disable SR without resetting the voltage
700 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
702 * This API is to be called from the kernel in order to disable
703 * a particular smartreflex module. This API will in turn call
704 * into the registered smartreflex class disable API. This API will tell
705 * the smartreflex class disable not to reset the VP voltage after
706 * disabling smartreflex.
708 void omap_sr_disable(struct voltagedomain
*voltdm
)
710 struct omap_sr
*sr
= _sr_lookup(voltdm
);
713 pr_warning("%s: omap_sr struct for sr_%s not found\n",
714 __func__
, voltdm
->name
);
718 if (!sr
->autocomp_active
)
721 if (!sr_class
|| !(sr_class
->disable
)) {
722 dev_warn(&sr
->pdev
->dev
, "%s: smartreflex class driver not"
723 "registered\n", __func__
);
727 sr_class
->disable(voltdm
, 0);
731 * omap_sr_disable_reset_volt() - API to disable SR and reset the
732 * voltage processor voltage
733 * @voltdm: VDD pointer to which the SR module to be configured belongs to.
735 * This API is to be called from the kernel in order to disable
736 * a particular smartreflex module. This API will in turn call
737 * into the registered smartreflex class disable API. This API will tell
738 * the smartreflex class disable to reset the VP voltage after
739 * disabling smartreflex.
741 void omap_sr_disable_reset_volt(struct voltagedomain
*voltdm
)
743 struct omap_sr
*sr
= _sr_lookup(voltdm
);
746 pr_warning("%s: omap_sr struct for sr_%s not found\n",
747 __func__
, voltdm
->name
);
751 if (!sr
->autocomp_active
)
754 if (!sr_class
|| !(sr_class
->disable
)) {
755 dev_warn(&sr
->pdev
->dev
, "%s: smartreflex class driver not"
756 "registered\n", __func__
);
760 sr_class
->disable(voltdm
, 1);
764 * omap_sr_register_pmic() - API to register pmic specific info.
765 * @pmic_data: The structure containing pmic specific data.
767 * This API is to be called from the PMIC specific code to register with
768 * smartreflex driver pmic specific info. Currently the only info required
769 * is the smartreflex init on the PMIC side.
771 void omap_sr_register_pmic(struct omap_sr_pmic_data
*pmic_data
)
774 pr_warning("%s: Trying to register NULL PMIC data structure"
775 "with smartreflex\n", __func__
);
779 sr_pmic_data
= pmic_data
;
782 /* PM Debug Fs enteries to enable disable smartreflex. */
783 static int omap_sr_autocomp_show(void *data
, u64
*val
)
785 struct omap_sr
*sr_info
= (struct omap_sr
*) data
;
788 pr_warning("%s: omap_sr struct not found\n", __func__
);
792 *val
= sr_info
->autocomp_active
;
797 static int omap_sr_autocomp_store(void *data
, u64 val
)
799 struct omap_sr
*sr_info
= (struct omap_sr
*) data
;
802 pr_warning("%s: omap_sr struct not found\n", __func__
);
807 if (val
&& (val
!= 1)) {
808 pr_warning("%s: Invalid argument %lld\n", __func__
, val
);
812 /* control enable/disable only if there is a delta in value */
813 if (sr_info
->autocomp_active
!= val
) {
815 sr_stop_vddautocomp(sr_info
);
817 sr_start_vddautocomp(sr_info
);
823 DEFINE_SIMPLE_ATTRIBUTE(pm_sr_fops
, omap_sr_autocomp_show
,
824 omap_sr_autocomp_store
, "%llu\n");
826 static int __init
omap_sr_probe(struct platform_device
*pdev
)
828 struct omap_sr
*sr_info
= kzalloc(sizeof(struct omap_sr
), GFP_KERNEL
);
829 struct omap_sr_data
*pdata
= pdev
->dev
.platform_data
;
830 struct resource
*mem
, *irq
;
831 struct dentry
*nvalue_dir
;
832 struct omap_volt_data
*volt_data
;
837 dev_err(&pdev
->dev
, "%s: unable to allocate sr_info\n",
843 dev_err(&pdev
->dev
, "%s: platform data missing\n", __func__
);
845 goto err_free_devinfo
;
848 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
850 dev_err(&pdev
->dev
, "%s: no mem resource\n", __func__
);
852 goto err_free_devinfo
;
855 mem
= request_mem_region(mem
->start
, resource_size(mem
),
856 dev_name(&pdev
->dev
));
858 dev_err(&pdev
->dev
, "%s: no mem region\n", __func__
);
860 goto err_free_devinfo
;
863 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
865 pm_runtime_enable(&pdev
->dev
);
866 pm_runtime_irq_safe(&pdev
->dev
);
868 sr_info
->pdev
= pdev
;
869 sr_info
->srid
= pdev
->id
;
870 sr_info
->voltdm
= pdata
->voltdm
;
871 sr_info
->nvalue_table
= pdata
->nvalue_table
;
872 sr_info
->nvalue_count
= pdata
->nvalue_count
;
873 sr_info
->senn_mod
= pdata
->senn_mod
;
874 sr_info
->senp_mod
= pdata
->senp_mod
;
875 sr_info
->autocomp_active
= false;
876 sr_info
->ip_type
= pdata
->ip_type
;
877 sr_info
->base
= ioremap(mem
->start
, resource_size(mem
));
878 if (!sr_info
->base
) {
879 dev_err(&pdev
->dev
, "%s: ioremap fail\n", __func__
);
881 goto err_release_region
;
885 sr_info
->irq
= irq
->start
;
887 sr_set_clk_length(sr_info
);
888 sr_set_regfields(sr_info
);
890 list_add(&sr_info
->node
, &sr_list
);
893 * Call into late init to do intializations that require
894 * both sr driver and sr class driver to be initiallized.
897 ret
= sr_late_init(sr_info
);
899 pr_warning("%s: Error in SR late init\n", __func__
);
904 dev_info(&pdev
->dev
, "%s: SmartReflex driver initialized\n", __func__
);
906 sr_dbg_dir
= debugfs_create_dir("smartreflex", NULL
);
908 ret
= PTR_ERR(sr_dbg_dir
);
909 pr_err("%s:sr debugfs dir creation failed(%d)\n",
915 name
= kasprintf(GFP_KERNEL
, "sr_%s", sr_info
->voltdm
->name
);
917 dev_err(&pdev
->dev
, "%s: Unable to alloc debugfs name\n",
922 sr_info
->dbg_dir
= debugfs_create_dir(name
, sr_dbg_dir
);
924 if (IS_ERR(sr_info
->dbg_dir
)) {
925 dev_err(&pdev
->dev
, "%s: Unable to create debugfs directory\n",
927 ret
= PTR_ERR(sr_info
->dbg_dir
);
931 (void) debugfs_create_file("autocomp", S_IRUGO
| S_IWUSR
,
932 sr_info
->dbg_dir
, (void *)sr_info
, &pm_sr_fops
);
933 (void) debugfs_create_x32("errweight", S_IRUGO
, sr_info
->dbg_dir
,
934 &sr_info
->err_weight
);
935 (void) debugfs_create_x32("errmaxlimit", S_IRUGO
, sr_info
->dbg_dir
,
936 &sr_info
->err_maxlimit
);
937 (void) debugfs_create_x32("errminlimit", S_IRUGO
, sr_info
->dbg_dir
,
938 &sr_info
->err_minlimit
);
940 nvalue_dir
= debugfs_create_dir("nvalue", sr_info
->dbg_dir
);
941 if (IS_ERR(nvalue_dir
)) {
942 dev_err(&pdev
->dev
, "%s: Unable to create debugfs directory"
943 "for n-values\n", __func__
);
944 ret
= PTR_ERR(nvalue_dir
);
948 omap_voltage_get_volttable(sr_info
->voltdm
, &volt_data
);
950 dev_warn(&pdev
->dev
, "%s: No Voltage table for the"
951 " corresponding vdd vdd_%s. Cannot create debugfs"
952 "entries for n-values\n",
953 __func__
, sr_info
->voltdm
->name
);
958 for (i
= 0; i
< sr_info
->nvalue_count
; i
++) {
959 char name
[NVALUE_NAME_LEN
+ 1];
961 snprintf(name
, sizeof(name
), "volt_%d",
962 volt_data
[i
].volt_nominal
);
963 (void) debugfs_create_x32(name
, S_IRUGO
| S_IWUSR
, nvalue_dir
,
964 &(sr_info
->nvalue_table
[i
].nvalue
));
970 debugfs_remove_recursive(sr_info
->dbg_dir
);
972 list_del(&sr_info
->node
);
973 iounmap(sr_info
->base
);
975 release_mem_region(mem
->start
, resource_size(mem
));
982 static int __devexit
omap_sr_remove(struct platform_device
*pdev
)
984 struct omap_sr_data
*pdata
= pdev
->dev
.platform_data
;
985 struct omap_sr
*sr_info
;
986 struct resource
*mem
;
989 dev_err(&pdev
->dev
, "%s: platform data missing\n", __func__
);
993 sr_info
= _sr_lookup(pdata
->voltdm
);
994 if (IS_ERR(sr_info
)) {
995 dev_warn(&pdev
->dev
, "%s: omap_sr struct not found\n",
1000 if (sr_info
->autocomp_active
)
1001 sr_stop_vddautocomp(sr_info
);
1002 if (sr_info
->dbg_dir
)
1003 debugfs_remove_recursive(sr_info
->dbg_dir
);
1005 list_del(&sr_info
->node
);
1006 iounmap(sr_info
->base
);
1008 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1009 release_mem_region(mem
->start
, resource_size(mem
));
1014 static struct platform_driver smartreflex_driver
= {
1015 .remove
= omap_sr_remove
,
1017 .name
= "smartreflex",
1021 static int __init
sr_init(void)
1026 * sr_init is a late init. If by then a pmic specific API is not
1027 * registered either there is no need for anything to be done on
1028 * the PMIC side or somebody has forgotten to register a PMIC
1029 * handler. Warn for the second condition.
1031 if (sr_pmic_data
&& sr_pmic_data
->sr_pmic_init
)
1032 sr_pmic_data
->sr_pmic_init();
1034 pr_warning("%s: No PMIC hook to init smartreflex\n", __func__
);
1036 ret
= platform_driver_probe(&smartreflex_driver
, omap_sr_probe
);
1038 pr_err("%s: platform driver register failed for SR\n",
1046 static void __exit
sr_exit(void)
1048 platform_driver_unregister(&smartreflex_driver
);
1050 late_initcall(sr_init
);
1051 module_exit(sr_exit
);
1053 MODULE_DESCRIPTION("OMAP Smartreflex Driver");
1054 MODULE_LICENSE("GPL");
1055 MODULE_ALIAS("platform:" DRIVER_NAME
);
1056 MODULE_AUTHOR("Texas Instruments Inc");