11 #include <linux/module.h>
13 #include <linux/i2c.h>
14 #include <linux/slab.h>
19 #define AD5398_CURRENT_EN_MASK 0x8000
54 static int ad5398_write_reg(
struct i2c_client *client,
const unsigned short data)
74 ret = ad5398_read_reg(client, &data);
80 return ad5398_calc_current(chip, ret);
83 static int ad5398_set_current_limit(
struct regulator_dev *rdev,
int min_uA,
int max_uA)
92 if (min_uA < chip->min_uA)
97 if (min_uA > chip->
max_uA || max_uA < chip->min_uA)
102 if (ad5398_calc_current(chip, selector) > max_uA)
105 dev_dbg(&client->
dev,
"changing current %duA\n",
106 ad5398_calc_current(chip, selector));
109 ret = ad5398_read_reg(client, &data);
118 ret = ad5398_write_reg(client, data);
130 ret = ad5398_read_reg(client, &data);
147 ret = ad5398_read_reg(client, &data);
156 ret = ad5398_write_reg(client, data);
168 ret = ad5398_read_reg(client, &data);
175 data &= ~AD5398_CURRENT_EN_MASK;
177 ret = ad5398_write_reg(client, data);
183 .get_current_limit = ad5398_get_current_limit,
184 .set_current_limit = ad5398_set_current_limit,
185 .enable = ad5398_enable,
186 .disable = ad5398_disable,
187 .is_enabled = ad5398_is_enabled,
231 config.
dev = &client->
dev;
244 if (IS_ERR(chip->
rdev)) {
245 ret = PTR_ERR(chip->
rdev);
246 dev_err(&client->
dev,
"failed to register %s %s\n",
251 i2c_set_clientdata(client, chip);
252 dev_dbg(&client->
dev,
"%s regulator driver is registered.\n", id->
name);
268 .probe = ad5398_probe,
273 .id_table = ad5398_id,
276 static int __init ad5398_init(
void)
278 return i2c_add_driver(&ad5398_driver);
282 static void __exit ad5398_exit(
void)