2 * Driver for TPS61050/61052 boost converters, typically used for white LEDs
5 * Copyright (C) 2011 ST-Ericsson SA
6 * Written on behalf of Linaro for ST-Ericsson
8 * Author: Linus Walleij <linus.walleij@linaro.org>
10 * License terms: GNU General Public License (GPL) version 2
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/err.h>
17 #include <linux/i2c.h>
18 #include <linux/platform_device.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/mfd/core.h>
21 #include <linux/mfd/tps6105x.h>
23 static const int tps6105x_voltages
[] = {
27 5000000, /* There is an additional 5V */
30 static int tps6105x_regulator_enable(struct regulator_dev
*rdev
)
32 struct tps6105x
*tps6105x
= rdev_get_drvdata(rdev
);
35 /* Activate voltage mode */
36 ret
= tps6105x_mask_and_set(tps6105x
, TPS6105X_REG_0
,
37 TPS6105X_REG0_MODE_MASK
,
38 TPS6105X_REG0_MODE_VOLTAGE
<< TPS6105X_REG0_MODE_SHIFT
);
45 static int tps6105x_regulator_disable(struct regulator_dev
*rdev
)
47 struct tps6105x
*tps6105x
= rdev_get_drvdata(rdev
);
50 /* Set into shutdown mode */
51 ret
= tps6105x_mask_and_set(tps6105x
, TPS6105X_REG_0
,
52 TPS6105X_REG0_MODE_MASK
,
53 TPS6105X_REG0_MODE_SHUTDOWN
<< TPS6105X_REG0_MODE_SHIFT
);
60 static int tps6105x_regulator_is_enabled(struct regulator_dev
*rdev
)
62 struct tps6105x
*tps6105x
= rdev_get_drvdata(rdev
);
66 ret
= tps6105x_get(tps6105x
, TPS6105X_REG_0
, ®val
);
69 regval
&= TPS6105X_REG0_MODE_MASK
;
70 regval
>>= TPS6105X_REG0_MODE_SHIFT
;
72 if (regval
== TPS6105X_REG0_MODE_VOLTAGE
)
78 static int tps6105x_regulator_get_voltage_sel(struct regulator_dev
*rdev
)
80 struct tps6105x
*tps6105x
= rdev_get_drvdata(rdev
);
84 ret
= tps6105x_get(tps6105x
, TPS6105X_REG_0
, ®val
);
88 regval
&= TPS6105X_REG0_VOLTAGE_MASK
;
89 regval
>>= TPS6105X_REG0_VOLTAGE_SHIFT
;
93 static int tps6105x_regulator_set_voltage_sel(struct regulator_dev
*rdev
,
96 struct tps6105x
*tps6105x
= rdev_get_drvdata(rdev
);
99 ret
= tps6105x_mask_and_set(tps6105x
, TPS6105X_REG_0
,
100 TPS6105X_REG0_VOLTAGE_MASK
,
101 selector
<< TPS6105X_REG0_VOLTAGE_SHIFT
);
108 static int tps6105x_regulator_list_voltage(struct regulator_dev
*rdev
,
111 if (selector
>= ARRAY_SIZE(tps6105x_voltages
))
114 return tps6105x_voltages
[selector
];
117 static struct regulator_ops tps6105x_regulator_ops
= {
118 .enable
= tps6105x_regulator_enable
,
119 .disable
= tps6105x_regulator_disable
,
120 .is_enabled
= tps6105x_regulator_is_enabled
,
121 .get_voltage_sel
= tps6105x_regulator_get_voltage_sel
,
122 .set_voltage_sel
= tps6105x_regulator_set_voltage_sel
,
123 .list_voltage
= tps6105x_regulator_list_voltage
,
126 static struct regulator_desc tps6105x_regulator_desc
= {
127 .name
= "tps6105x-boost",
128 .ops
= &tps6105x_regulator_ops
,
129 .type
= REGULATOR_VOLTAGE
,
131 .owner
= THIS_MODULE
,
132 .n_voltages
= ARRAY_SIZE(tps6105x_voltages
),
136 * Registers the chip as a voltage regulator
138 static int __devinit
tps6105x_regulator_probe(struct platform_device
*pdev
)
140 struct tps6105x
*tps6105x
= dev_get_platdata(&pdev
->dev
);
141 struct tps6105x_platform_data
*pdata
= tps6105x
->pdata
;
144 /* This instance is not set for regulator mode so bail out */
145 if (pdata
->mode
!= TPS6105X_MODE_VOLTAGE
) {
147 "chip not in voltage mode mode, exit probe \n");
151 /* Register regulator with framework */
152 tps6105x
->regulator
= regulator_register(&tps6105x_regulator_desc
,
153 &tps6105x
->client
->dev
,
154 pdata
->regulator_data
, tps6105x
,
156 if (IS_ERR(tps6105x
->regulator
)) {
157 ret
= PTR_ERR(tps6105x
->regulator
);
158 dev_err(&tps6105x
->client
->dev
,
159 "failed to register regulator\n");
162 platform_set_drvdata(pdev
, tps6105x
);
167 static int __devexit
tps6105x_regulator_remove(struct platform_device
*pdev
)
169 struct tps6105x
*tps6105x
= dev_get_platdata(&pdev
->dev
);
170 regulator_unregister(tps6105x
->regulator
);
174 static struct platform_driver tps6105x_regulator_driver
= {
176 .name
= "tps6105x-regulator",
177 .owner
= THIS_MODULE
,
179 .probe
= tps6105x_regulator_probe
,
180 .remove
= __devexit_p(tps6105x_regulator_remove
),
183 static __init
int tps6105x_regulator_init(void)
185 return platform_driver_register(&tps6105x_regulator_driver
);
187 subsys_initcall(tps6105x_regulator_init
);
189 static __exit
void tps6105x_regulator_exit(void)
191 platform_driver_unregister(&tps6105x_regulator_driver
);
193 module_exit(tps6105x_regulator_exit
);
195 MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
196 MODULE_DESCRIPTION("TPS6105x regulator driver");
197 MODULE_LICENSE("GPL v2");
198 MODULE_ALIAS("platform:tps6105x-regulator");