xref: /linux/drivers/regulator/tps6586x-regulator.c (revision 4f58670709af7b890eceab325e9e470f209459ca)
149610235SMike Rapoport /*
249610235SMike Rapoport  * Regulator driver for TI TPS6586x
349610235SMike Rapoport  *
449610235SMike Rapoport  * Copyright (C) 2010 Compulab Ltd.
549610235SMike Rapoport  * Author: Mike Rapoport <mike@compulab.co.il>
649610235SMike Rapoport  *
749610235SMike Rapoport  * Based on da903x
849610235SMike Rapoport  * Copyright (C) 2006-2008 Marvell International Ltd.
949610235SMike Rapoport  * Copyright (C) 2008 Compulab Ltd.
1049610235SMike Rapoport  *
1149610235SMike Rapoport  * This program is free software; you can redistribute it and/or modify
1249610235SMike Rapoport  * it under the terms of the GNU General Public License version 2 as
1349610235SMike Rapoport  * published by the Free Software Foundation.
1449610235SMike Rapoport  */
1549610235SMike Rapoport 
1649610235SMike Rapoport #include <linux/kernel.h>
1749610235SMike Rapoport #include <linux/init.h>
1849610235SMike Rapoport #include <linux/err.h>
1949610235SMike Rapoport #include <linux/slab.h>
2049610235SMike Rapoport #include <linux/platform_device.h>
2149610235SMike Rapoport #include <linux/regulator/driver.h>
2249610235SMike Rapoport #include <linux/regulator/machine.h>
2349610235SMike Rapoport #include <linux/mfd/tps6586x.h>
2449610235SMike Rapoport 
2549610235SMike Rapoport /* supply control and voltage setting  */
2649610235SMike Rapoport #define TPS6586X_SUPPLYENA	0x10
2749610235SMike Rapoport #define TPS6586X_SUPPLYENB	0x11
2849610235SMike Rapoport #define TPS6586X_SUPPLYENC	0x12
2949610235SMike Rapoport #define TPS6586X_SUPPLYEND	0x13
3049610235SMike Rapoport #define TPS6586X_SUPPLYENE	0x14
3149610235SMike Rapoport #define TPS6586X_VCC1		0x20
3249610235SMike Rapoport #define TPS6586X_VCC2		0x21
3349610235SMike Rapoport #define TPS6586X_SM1V1		0x23
3449610235SMike Rapoport #define TPS6586X_SM1V2		0x24
3549610235SMike Rapoport #define TPS6586X_SM1SL		0x25
3649610235SMike Rapoport #define TPS6586X_SM0V1		0x26
3749610235SMike Rapoport #define TPS6586X_SM0V2		0x27
3849610235SMike Rapoport #define TPS6586X_SM0SL		0x28
3949610235SMike Rapoport #define TPS6586X_LDO2AV1	0x29
4049610235SMike Rapoport #define TPS6586X_LDO2AV2	0x2A
4149610235SMike Rapoport #define TPS6586X_LDO2BV1	0x2F
4249610235SMike Rapoport #define TPS6586X_LDO2BV2	0x30
4349610235SMike Rapoport #define TPS6586X_LDO4V1		0x32
4449610235SMike Rapoport #define TPS6586X_LDO4V2		0x33
4549610235SMike Rapoport 
4649610235SMike Rapoport /* converter settings  */
4749610235SMike Rapoport #define TPS6586X_SUPPLYV1	0x41
4849610235SMike Rapoport #define TPS6586X_SUPPLYV2	0x42
4949610235SMike Rapoport #define TPS6586X_SUPPLYV3	0x43
5049610235SMike Rapoport #define TPS6586X_SUPPLYV4	0x44
5149610235SMike Rapoport #define TPS6586X_SUPPLYV5	0x45
5249610235SMike Rapoport #define TPS6586X_SUPPLYV6	0x46
5349610235SMike Rapoport #define TPS6586X_SMODE1		0x47
5449610235SMike Rapoport #define TPS6586X_SMODE2		0x48
5549610235SMike Rapoport 
5649610235SMike Rapoport struct tps6586x_regulator {
5749610235SMike Rapoport 	struct regulator_desc desc;
5849610235SMike Rapoport 
5949610235SMike Rapoport 	int volt_reg;
6049610235SMike Rapoport 	int volt_shift;
6149610235SMike Rapoport 	int volt_nbits;
6249610235SMike Rapoport 	int enable_bit[2];
6349610235SMike Rapoport 	int enable_reg[2];
6449610235SMike Rapoport 
6549610235SMike Rapoport 	int *voltages;
6649610235SMike Rapoport 
6749610235SMike Rapoport 	/* for DVM regulators */
6849610235SMike Rapoport 	int go_reg;
6949610235SMike Rapoport 	int go_bit;
7049610235SMike Rapoport };
7149610235SMike Rapoport 
7249610235SMike Rapoport static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev)
7349610235SMike Rapoport {
7449610235SMike Rapoport 	return rdev_get_dev(rdev)->parent->parent;
7549610235SMike Rapoport }
7649610235SMike Rapoport 
7749610235SMike Rapoport static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
7849610235SMike Rapoport 				     unsigned selector)
7949610235SMike Rapoport {
8049610235SMike Rapoport 	struct tps6586x_regulator *info = rdev_get_drvdata(rdev);
8149610235SMike Rapoport 
824cc2e393SGary King 	return info->voltages[selector] * 1000;
8349610235SMike Rapoport }
8449610235SMike Rapoport 
8549610235SMike Rapoport 
8649610235SMike Rapoport static int __tps6586x_ldo_set_voltage(struct device *parent,
8749610235SMike Rapoport 				      struct tps6586x_regulator *ri,
8849610235SMike Rapoport 				      int min_uV, int max_uV)
8949610235SMike Rapoport {
9049610235SMike Rapoport 	int val, uV;
9149610235SMike Rapoport 	uint8_t mask;
9249610235SMike Rapoport 
9349610235SMike Rapoport 	for (val = 0; val < ri->desc.n_voltages; val++) {
9449610235SMike Rapoport 		uV = ri->voltages[val] * 1000;
9549610235SMike Rapoport 
9649610235SMike Rapoport 		/* LDO0 has minimal voltage 1.2 rather than 1.25 */
9749610235SMike Rapoport 		if (ri->desc.id == TPS6586X_ID_LDO_0 && val == 0)
9849610235SMike Rapoport 			uV -= 50 * 1000;
9949610235SMike Rapoport 
10049610235SMike Rapoport 		/* use the first in-range value */
10149610235SMike Rapoport 		if (min_uV <= uV && uV <= max_uV) {
10249610235SMike Rapoport 
10349610235SMike Rapoport 			val <<= ri->volt_shift;
10449610235SMike Rapoport 			mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
10549610235SMike Rapoport 
10649610235SMike Rapoport 			return tps6586x_update(parent, ri->volt_reg, val, mask);
10749610235SMike Rapoport 		}
10849610235SMike Rapoport 	}
10949610235SMike Rapoport 
11049610235SMike Rapoport 	return -EINVAL;
11149610235SMike Rapoport }
11249610235SMike Rapoport 
11349610235SMike Rapoport static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev,
11449610235SMike Rapoport 				    int min_uV, int max_uV)
11549610235SMike Rapoport {
11649610235SMike Rapoport 	struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
11749610235SMike Rapoport 	struct device *parent = to_tps6586x_dev(rdev);
11849610235SMike Rapoport 
11949610235SMike Rapoport 	return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV);
12049610235SMike Rapoport }
12149610235SMike Rapoport 
12249610235SMike Rapoport static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
12349610235SMike Rapoport {
12449610235SMike Rapoport 	struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
12549610235SMike Rapoport 	struct device *parent = to_tps6586x_dev(rdev);
12649610235SMike Rapoport 	uint8_t val, mask;
12749610235SMike Rapoport 	int ret;
12849610235SMike Rapoport 
12949610235SMike Rapoport 	ret = tps6586x_read(parent, ri->volt_reg, &val);
13049610235SMike Rapoport 	if (ret)
13149610235SMike Rapoport 		return ret;
13249610235SMike Rapoport 
13349610235SMike Rapoport 	mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
13449610235SMike Rapoport 	val = (val & mask) >> ri->volt_shift;
13549610235SMike Rapoport 
136327531baSAxel Lin 	if (val >= ri->desc.n_voltages)
13749610235SMike Rapoport 		BUG();
13849610235SMike Rapoport 
1394cc2e393SGary King 	return ri->voltages[val] * 1000;
14049610235SMike Rapoport }
14149610235SMike Rapoport 
14249610235SMike Rapoport static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev,
14349610235SMike Rapoport 				    int min_uV, int max_uV)
14449610235SMike Rapoport {
14549610235SMike Rapoport 	struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
14649610235SMike Rapoport 	struct device *parent = to_tps6586x_dev(rdev);
14749610235SMike Rapoport 	int ret;
14849610235SMike Rapoport 
14949610235SMike Rapoport 	ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV);
15049610235SMike Rapoport 	if (ret)
15149610235SMike Rapoport 		return ret;
15249610235SMike Rapoport 
153938b4592SAxel Lin 	return tps6586x_set_bits(parent, ri->go_reg, 1 << ri->go_bit);
15449610235SMike Rapoport }
15549610235SMike Rapoport 
15649610235SMike Rapoport static int tps6586x_regulator_enable(struct regulator_dev *rdev)
15749610235SMike Rapoport {
15849610235SMike Rapoport 	struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
15949610235SMike Rapoport 	struct device *parent = to_tps6586x_dev(rdev);
16049610235SMike Rapoport 
16149610235SMike Rapoport 	return tps6586x_set_bits(parent, ri->enable_reg[0],
16249610235SMike Rapoport 				 1 << ri->enable_bit[0]);
16349610235SMike Rapoport }
16449610235SMike Rapoport 
16549610235SMike Rapoport static int tps6586x_regulator_disable(struct regulator_dev *rdev)
16649610235SMike Rapoport {
16749610235SMike Rapoport 	struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
16849610235SMike Rapoport 	struct device *parent = to_tps6586x_dev(rdev);
16949610235SMike Rapoport 
17049610235SMike Rapoport 	return tps6586x_clr_bits(parent, ri->enable_reg[0],
17149610235SMike Rapoport 				 1 << ri->enable_bit[0]);
17249610235SMike Rapoport }
17349610235SMike Rapoport 
17449610235SMike Rapoport static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev)
17549610235SMike Rapoport {
17649610235SMike Rapoport 	struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
17749610235SMike Rapoport 	struct device *parent = to_tps6586x_dev(rdev);
17849610235SMike Rapoport 	uint8_t reg_val;
17949610235SMike Rapoport 	int ret;
18049610235SMike Rapoport 
18149610235SMike Rapoport 	ret = tps6586x_read(parent, ri->enable_reg[0], &reg_val);
18249610235SMike Rapoport 	if (ret)
18349610235SMike Rapoport 		return ret;
18449610235SMike Rapoport 
18549610235SMike Rapoport 	return !!(reg_val & (1 << ri->enable_bit[0]));
18649610235SMike Rapoport }
18749610235SMike Rapoport 
18849610235SMike Rapoport static struct regulator_ops tps6586x_regulator_ldo_ops = {
18949610235SMike Rapoport 	.list_voltage = tps6586x_ldo_list_voltage,
19049610235SMike Rapoport 	.get_voltage = tps6586x_ldo_get_voltage,
19149610235SMike Rapoport 	.set_voltage = tps6586x_ldo_set_voltage,
19249610235SMike Rapoport 
19349610235SMike Rapoport 	.is_enabled = tps6586x_regulator_is_enabled,
19449610235SMike Rapoport 	.enable = tps6586x_regulator_enable,
19549610235SMike Rapoport 	.disable = tps6586x_regulator_disable,
19649610235SMike Rapoport };
19749610235SMike Rapoport 
19849610235SMike Rapoport static struct regulator_ops tps6586x_regulator_dvm_ops = {
19949610235SMike Rapoport 	.list_voltage = tps6586x_ldo_list_voltage,
20049610235SMike Rapoport 	.get_voltage = tps6586x_ldo_get_voltage,
20149610235SMike Rapoport 	.set_voltage = tps6586x_dvm_set_voltage,
20249610235SMike Rapoport 
20349610235SMike Rapoport 	.is_enabled = tps6586x_regulator_is_enabled,
20449610235SMike Rapoport 	.enable = tps6586x_regulator_enable,
20549610235SMike Rapoport 	.disable = tps6586x_regulator_disable,
20649610235SMike Rapoport };
20749610235SMike Rapoport 
20849610235SMike Rapoport static int tps6586x_ldo_voltages[] = {
20949610235SMike Rapoport 	1250, 1500, 1800, 2500, 2700, 2850, 3100, 3300,
21049610235SMike Rapoport };
21149610235SMike Rapoport 
21249610235SMike Rapoport static int tps6586x_ldo4_voltages[] = {
21349610235SMike Rapoport 	1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875,
21449610235SMike Rapoport 	1900, 1925, 1950, 1975, 2000, 2025, 2050, 2075,
21549610235SMike Rapoport 	2100, 2125, 2150, 2175, 2200, 2225, 2250, 2275,
21649610235SMike Rapoport 	2300, 2325, 2350, 2375, 2400, 2425, 2450, 2475,
21749610235SMike Rapoport };
21849610235SMike Rapoport 
2194cc2e393SGary King static int tps6586x_sm2_voltages[] = {
2204cc2e393SGary King 	3000, 3050, 3100, 3150, 3200, 3250, 3300, 3350,
2214cc2e393SGary King 	3400, 3450, 3500, 3550, 3600, 3650, 3700, 3750,
2224cc2e393SGary King 	3800, 3850, 3900, 3950, 4000, 4050, 4100, 4150,
2234cc2e393SGary King 	4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550,
2244cc2e393SGary King };
2254cc2e393SGary King 
22649610235SMike Rapoport static int tps6586x_dvm_voltages[] = {
22749610235SMike Rapoport 	 725,  750,  775,  800,  825,  850,  875,  900,
22849610235SMike Rapoport 	 925,  950,  975, 1000, 1025, 1050, 1075, 1100,
22949610235SMike Rapoport 	1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300,
23049610235SMike Rapoport 	1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500,
23149610235SMike Rapoport };
23249610235SMike Rapoport 
23349610235SMike Rapoport #define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits,	\
23449610235SMike Rapoport 			   ereg0, ebit0, ereg1, ebit1, goreg, gobit)	\
23549610235SMike Rapoport {									\
23649610235SMike Rapoport 	.desc	= {							\
23749610235SMike Rapoport 		.name	= "REG-" #_id,					\
23849610235SMike Rapoport 		.ops	= &tps6586x_regulator_##_ops,			\
23949610235SMike Rapoport 		.type	= REGULATOR_VOLTAGE,				\
24049610235SMike Rapoport 		.id	= TPS6586X_ID_##_id,				\
24149610235SMike Rapoport 		.n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages),	\
24249610235SMike Rapoport 		.owner	= THIS_MODULE,					\
24349610235SMike Rapoport 	},								\
24449610235SMike Rapoport 	.volt_reg	= TPS6586X_##vreg,				\
24549610235SMike Rapoport 	.volt_shift	= (shift),					\
24649610235SMike Rapoport 	.volt_nbits	= (nbits),					\
24749610235SMike Rapoport 	.enable_reg[0]	= TPS6586X_SUPPLY##ereg0,			\
24849610235SMike Rapoport 	.enable_bit[0]	= (ebit0),					\
24949610235SMike Rapoport 	.enable_reg[1]	= TPS6586X_SUPPLY##ereg1,			\
25049610235SMike Rapoport 	.enable_bit[1]	= (ebit1),					\
25149610235SMike Rapoport 	.voltages	= tps6586x_##vdata##_voltages,			\
25249610235SMike Rapoport }
25349610235SMike Rapoport 
25449610235SMike Rapoport #define TPS6586X_LDO(_id, vdata, vreg, shift, nbits,			\
25549610235SMike Rapoport 		     ereg0, ebit0, ereg1, ebit1)			\
25649610235SMike Rapoport 	TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits,	\
25749610235SMike Rapoport 			   ereg0, ebit0, ereg1, ebit1, 0, 0)
25849610235SMike Rapoport 
25949610235SMike Rapoport #define TPS6586X_DVM(_id, vdata, vreg, shift, nbits,			\
26049610235SMike Rapoport 		     ereg0, ebit0, ereg1, ebit1, goreg, gobit)		\
26149610235SMike Rapoport 	TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits,	\
26249610235SMike Rapoport 			   ereg0, ebit0, ereg1, ebit1, goreg, gobit)
26349610235SMike Rapoport 
26449610235SMike Rapoport static struct tps6586x_regulator tps6586x_regulator[] = {
26549610235SMike Rapoport 	TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0),
26649610235SMike Rapoport 	TPS6586X_LDO(LDO_3, ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2),
26749610235SMike Rapoport 	TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
26849610235SMike Rapoport 	TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
26949610235SMike Rapoport 	TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
27049610235SMike Rapoport 	TPS6586X_LDO(LDO_8, ldo, SUPPLYV1, 5, 3, ENC, 6, END, 6),
27149610235SMike Rapoport 	TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
27249610235SMike Rapoport 	TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, ENE, 7, ENE, 7),
27349610235SMike Rapoport 	TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
2744cc2e393SGary King 	TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 1, END, 1),
27549610235SMike Rapoport 
27649610235SMike Rapoport 	TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6),
27749610235SMike Rapoport 	TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6),
27849610235SMike Rapoport 	TPS6586X_DVM(SM_0, dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2),
27949610235SMike Rapoport 	TPS6586X_DVM(SM_1, dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0),
28049610235SMike Rapoport };
28149610235SMike Rapoport 
28249610235SMike Rapoport /*
28349610235SMike Rapoport  * TPS6586X has 2 enable bits that are OR'ed to determine the actual
28449610235SMike Rapoport  * regulator state. Clearing one of this bits allows switching
28549610235SMike Rapoport  * regulator on and of with single register write.
28649610235SMike Rapoport  */
28749610235SMike Rapoport static inline int tps6586x_regulator_preinit(struct device *parent,
28849610235SMike Rapoport 					     struct tps6586x_regulator *ri)
28949610235SMike Rapoport {
29049610235SMike Rapoport 	uint8_t val1, val2;
29149610235SMike Rapoport 	int ret;
29249610235SMike Rapoport 
29349610235SMike Rapoport 	ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
29449610235SMike Rapoport 	if (ret)
29549610235SMike Rapoport 		return ret;
29649610235SMike Rapoport 
29749610235SMike Rapoport 	ret = tps6586x_read(parent, ri->enable_reg[1], &val2);
29849610235SMike Rapoport 	if (ret)
29949610235SMike Rapoport 		return ret;
30049610235SMike Rapoport 
301*4f586707SDanny Huang 	if (!(val2 & (1 << ri->enable_bit[1])))
30249610235SMike Rapoport 		return 0;
30349610235SMike Rapoport 
30449610235SMike Rapoport 	/*
30549610235SMike Rapoport 	 * The regulator is on, but it's enabled with the bit we don't
30649610235SMike Rapoport 	 * want to use, so we switch the enable bits
30749610235SMike Rapoport 	 */
308*4f586707SDanny Huang 	if (!(val1 & (1 << ri->enable_bit[0]))) {
30949610235SMike Rapoport 		ret = tps6586x_set_bits(parent, ri->enable_reg[0],
31049610235SMike Rapoport 					1 << ri->enable_bit[0]);
31149610235SMike Rapoport 		if (ret)
31249610235SMike Rapoport 			return ret;
31349610235SMike Rapoport 	}
31449610235SMike Rapoport 
31549610235SMike Rapoport 	return tps6586x_clr_bits(parent, ri->enable_reg[1],
31649610235SMike Rapoport 				 1 << ri->enable_bit[1]);
31749610235SMike Rapoport }
31849610235SMike Rapoport 
31949610235SMike Rapoport static inline struct tps6586x_regulator *find_regulator_info(int id)
32049610235SMike Rapoport {
32149610235SMike Rapoport 	struct tps6586x_regulator *ri;
32249610235SMike Rapoport 	int i;
32349610235SMike Rapoport 
32449610235SMike Rapoport 	for (i = 0; i < ARRAY_SIZE(tps6586x_regulator); i++) {
32549610235SMike Rapoport 		ri = &tps6586x_regulator[i];
32649610235SMike Rapoport 		if (ri->desc.id == id)
32749610235SMike Rapoport 			return ri;
32849610235SMike Rapoport 	}
32949610235SMike Rapoport 	return NULL;
33049610235SMike Rapoport }
33149610235SMike Rapoport 
33249610235SMike Rapoport static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
33349610235SMike Rapoport {
33449610235SMike Rapoport 	struct tps6586x_regulator *ri = NULL;
33549610235SMike Rapoport 	struct regulator_dev *rdev;
33649610235SMike Rapoport 	int id = pdev->id;
33749610235SMike Rapoport 	int err;
33849610235SMike Rapoport 
33949610235SMike Rapoport 	dev_dbg(&pdev->dev, "Probing reulator %d\n", id);
34049610235SMike Rapoport 
34149610235SMike Rapoport 	ri = find_regulator_info(id);
34249610235SMike Rapoport 	if (ri == NULL) {
34349610235SMike Rapoport 		dev_err(&pdev->dev, "invalid regulator ID specified\n");
34449610235SMike Rapoport 		return -EINVAL;
34549610235SMike Rapoport 	}
34649610235SMike Rapoport 
34749610235SMike Rapoport 	err = tps6586x_regulator_preinit(pdev->dev.parent, ri);
34849610235SMike Rapoport 	if (err)
34949610235SMike Rapoport 		return err;
35049610235SMike Rapoport 
35149610235SMike Rapoport 	rdev = regulator_register(&ri->desc, &pdev->dev,
35249610235SMike Rapoport 				  pdev->dev.platform_data, ri);
35349610235SMike Rapoport 	if (IS_ERR(rdev)) {
35449610235SMike Rapoport 		dev_err(&pdev->dev, "failed to register regulator %s\n",
35549610235SMike Rapoport 				ri->desc.name);
35649610235SMike Rapoport 		return PTR_ERR(rdev);
35749610235SMike Rapoport 	}
35849610235SMike Rapoport 
359e7973c3cSAxel Lin 	platform_set_drvdata(pdev, rdev);
36049610235SMike Rapoport 
36149610235SMike Rapoport 	return 0;
36249610235SMike Rapoport }
36349610235SMike Rapoport 
36449610235SMike Rapoport static int __devexit tps6586x_regulator_remove(struct platform_device *pdev)
36549610235SMike Rapoport {
366e7973c3cSAxel Lin 	struct regulator_dev *rdev = platform_get_drvdata(pdev);
367e7973c3cSAxel Lin 
368e7973c3cSAxel Lin 	regulator_unregister(rdev);
36949610235SMike Rapoport 	return 0;
37049610235SMike Rapoport }
37149610235SMike Rapoport 
37249610235SMike Rapoport static struct platform_driver tps6586x_regulator_driver = {
37349610235SMike Rapoport 	.driver	= {
37449610235SMike Rapoport 		.name	= "tps6586x-regulator",
37549610235SMike Rapoport 		.owner	= THIS_MODULE,
37649610235SMike Rapoport 	},
37749610235SMike Rapoport 	.probe		= tps6586x_regulator_probe,
37849610235SMike Rapoport 	.remove		= __devexit_p(tps6586x_regulator_remove),
37949610235SMike Rapoport };
38049610235SMike Rapoport 
38149610235SMike Rapoport static int __init tps6586x_regulator_init(void)
38249610235SMike Rapoport {
38349610235SMike Rapoport 	return platform_driver_register(&tps6586x_regulator_driver);
38449610235SMike Rapoport }
38549610235SMike Rapoport subsys_initcall(tps6586x_regulator_init);
38649610235SMike Rapoport 
38749610235SMike Rapoport static void __exit tps6586x_regulator_exit(void)
38849610235SMike Rapoport {
38949610235SMike Rapoport 	platform_driver_unregister(&tps6586x_regulator_driver);
39049610235SMike Rapoport }
39149610235SMike Rapoport module_exit(tps6586x_regulator_exit);
39249610235SMike Rapoport 
39349610235SMike Rapoport MODULE_LICENSE("GPL");
39449610235SMike Rapoport MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
39549610235SMike Rapoport MODULE_DESCRIPTION("Regulator Driver for TI TPS6586X PMIC");
39649610235SMike Rapoport MODULE_ALIAS("platform:tps6586x-regulator");
397