4 * Support for Intersil ISL6271A voltage regulator
6 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
13 * whether express or implied; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/err.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/driver.h>
24 #include <linux/i2c.h>
25 #include <linux/slab.h>
27 #define ISL6271A_VOLTAGE_MIN 850000
28 #define ISL6271A_VOLTAGE_MAX 1600000
29 #define ISL6271A_VOLTAGE_STEP 50000
33 struct i2c_client
*client
;
37 static int isl6271a_get_voltage_sel(struct regulator_dev
*dev
)
39 struct isl_pmic
*pmic
= rdev_get_drvdata(dev
);
42 mutex_lock(&pmic
->mtx
);
44 idx
= i2c_smbus_read_byte(pmic
->client
);
46 dev_err(&pmic
->client
->dev
, "Error getting voltage\n");
48 mutex_unlock(&pmic
->mtx
);
52 static int isl6271a_set_voltage_sel(struct regulator_dev
*dev
,
55 struct isl_pmic
*pmic
= rdev_get_drvdata(dev
);
58 mutex_lock(&pmic
->mtx
);
60 err
= i2c_smbus_write_byte(pmic
->client
, selector
);
62 dev_err(&pmic
->client
->dev
, "Error setting voltage\n");
64 mutex_unlock(&pmic
->mtx
);
68 static const struct regulator_ops isl_core_ops
= {
69 .get_voltage_sel
= isl6271a_get_voltage_sel
,
70 .set_voltage_sel
= isl6271a_set_voltage_sel
,
71 .list_voltage
= regulator_list_voltage_linear
,
72 .map_voltage
= regulator_map_voltage_linear
,
75 static const struct regulator_ops isl_fixed_ops
= {
76 .list_voltage
= regulator_list_voltage_linear
,
79 static const struct regulator_desc isl_rd
[] = {
85 .type
= REGULATOR_VOLTAGE
,
87 .min_uV
= ISL6271A_VOLTAGE_MIN
,
88 .uV_step
= ISL6271A_VOLTAGE_STEP
,
93 .ops
= &isl_fixed_ops
,
94 .type
= REGULATOR_VOLTAGE
,
101 .ops
= &isl_fixed_ops
,
102 .type
= REGULATOR_VOLTAGE
,
103 .owner
= THIS_MODULE
,
108 static int isl6271a_probe(struct i2c_client
*i2c
,
109 const struct i2c_device_id
*id
)
111 struct regulator_dev
*rdev
;
112 struct regulator_config config
= { };
113 struct regulator_init_data
*init_data
= dev_get_platdata(&i2c
->dev
);
114 struct isl_pmic
*pmic
;
117 if (!i2c_check_functionality(i2c
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
120 pmic
= devm_kzalloc(&i2c
->dev
, sizeof(struct isl_pmic
), GFP_KERNEL
);
126 mutex_init(&pmic
->mtx
);
128 for (i
= 0; i
< 3; i
++) {
129 config
.dev
= &i2c
->dev
;
131 config
.init_data
= init_data
;
133 config
.init_data
= NULL
;
134 config
.driver_data
= pmic
;
136 rdev
= devm_regulator_register(&i2c
->dev
, &isl_rd
[i
], &config
);
138 dev_err(&i2c
->dev
, "failed to register %s\n", id
->name
);
139 return PTR_ERR(rdev
);
143 i2c_set_clientdata(i2c
, pmic
);
148 static const struct i2c_device_id isl6271a_id
[] = {
149 {.name
= "isl6271a", 0 },
153 MODULE_DEVICE_TABLE(i2c
, isl6271a_id
);
155 static struct i2c_driver isl6271a_i2c_driver
= {
159 .probe
= isl6271a_probe
,
160 .id_table
= isl6271a_id
,
163 static int __init
isl6271a_init(void)
165 return i2c_add_driver(&isl6271a_i2c_driver
);
168 static void __exit
isl6271a_cleanup(void)
170 i2c_del_driver(&isl6271a_i2c_driver
);
173 subsys_initcall(isl6271a_init
);
174 module_exit(isl6271a_cleanup
);
176 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
177 MODULE_DESCRIPTION("Intersil ISL6271A voltage regulator driver");
178 MODULE_LICENSE("GPL v2");