diff options
author | Joonyoung Shim <jy0922.shim@samsung.com> | 2010-08-05 22:28:06 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-10-28 18:29:02 -0400 |
commit | 676e02d7a2ed9bb02994670a07df533a29a99de6 (patch) | |
tree | f429e20f654790895b44aca9193b6082da2a9669 /drivers | |
parent | 1203a1e6424d502e9c12d29512218487af5fdd1c (diff) |
mfd: Use i2c_client as an argument on MAX8998 i2c routines
The MAX8998 chip have regulator and rtc features. The i2c slave address
of regulator and rtc is different, so needs each i2c client on i2c
operation functions.
Also, this patch exports i2c operation functions instead of callback to
make easy to read.
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mfd/max8998.c | 29 | ||||
-rw-r--r-- | drivers/regulator/max8998.c | 17 |
2 files changed, 25 insertions, 21 deletions
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c index f1c928915880..3b8a5076d351 100644 --- a/drivers/mfd/max8998.c +++ b/drivers/mfd/max8998.c | |||
@@ -36,13 +36,13 @@ static struct mfd_cell max8998_devs[] = { | |||
36 | } | 36 | } |
37 | }; | 37 | }; |
38 | 38 | ||
39 | static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest) | 39 | int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) |
40 | { | 40 | { |
41 | struct i2c_client *client = max8998->i2c_client; | 41 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
42 | int ret; | 42 | int ret; |
43 | 43 | ||
44 | mutex_lock(&max8998->iolock); | 44 | mutex_lock(&max8998->iolock); |
45 | ret = i2c_smbus_read_byte_data(client, reg); | 45 | ret = i2c_smbus_read_byte_data(i2c, reg); |
46 | mutex_unlock(&max8998->iolock); | 46 | mutex_unlock(&max8998->iolock); |
47 | if (ret < 0) | 47 | if (ret < 0) |
48 | return ret; | 48 | return ret; |
@@ -51,36 +51,38 @@ static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest | |||
51 | *dest = ret; | 51 | *dest = ret; |
52 | return 0; | 52 | return 0; |
53 | } | 53 | } |
54 | EXPORT_SYMBOL(max8998_read_reg); | ||
54 | 55 | ||
55 | static int max8998_i2c_device_write(struct max8998_dev *max8998, u8 reg, u8 value) | 56 | int max8998_write_reg(struct i2c_client *i2c, u8 reg, u8 value) |
56 | { | 57 | { |
57 | struct i2c_client *client = max8998->i2c_client; | 58 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
58 | int ret; | 59 | int ret; |
59 | 60 | ||
60 | mutex_lock(&max8998->iolock); | 61 | mutex_lock(&max8998->iolock); |
61 | ret = i2c_smbus_write_byte_data(client, reg, value); | 62 | ret = i2c_smbus_write_byte_data(i2c, reg, value); |
62 | mutex_unlock(&max8998->iolock); | 63 | mutex_unlock(&max8998->iolock); |
63 | return ret; | 64 | return ret; |
64 | } | 65 | } |
66 | EXPORT_SYMBOL(max8998_write_reg); | ||
65 | 67 | ||
66 | static int max8998_i2c_device_update(struct max8998_dev *max8998, u8 reg, | 68 | int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) |
67 | u8 val, u8 mask) | ||
68 | { | 69 | { |
69 | struct i2c_client *client = max8998->i2c_client; | 70 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
70 | int ret; | 71 | int ret; |
71 | 72 | ||
72 | mutex_lock(&max8998->iolock); | 73 | mutex_lock(&max8998->iolock); |
73 | ret = i2c_smbus_read_byte_data(client, reg); | 74 | ret = i2c_smbus_read_byte_data(i2c, reg); |
74 | if (ret >= 0) { | 75 | if (ret >= 0) { |
75 | u8 old_val = ret & 0xff; | 76 | u8 old_val = ret & 0xff; |
76 | u8 new_val = (val & mask) | (old_val & (~mask)); | 77 | u8 new_val = (val & mask) | (old_val & (~mask)); |
77 | ret = i2c_smbus_write_byte_data(client, reg, new_val); | 78 | ret = i2c_smbus_write_byte_data(i2c, reg, new_val); |
78 | if (ret >= 0) | 79 | if (ret >= 0) |
79 | ret = 0; | 80 | ret = 0; |
80 | } | 81 | } |
81 | mutex_unlock(&max8998->iolock); | 82 | mutex_unlock(&max8998->iolock); |
82 | return ret; | 83 | return ret; |
83 | } | 84 | } |
85 | EXPORT_SYMBOL(max8998_update_reg); | ||
84 | 86 | ||
85 | static int max8998_i2c_probe(struct i2c_client *i2c, | 87 | static int max8998_i2c_probe(struct i2c_client *i2c, |
86 | const struct i2c_device_id *id) | 88 | const struct i2c_device_id *id) |
@@ -94,10 +96,7 @@ static int max8998_i2c_probe(struct i2c_client *i2c, | |||
94 | 96 | ||
95 | i2c_set_clientdata(i2c, max8998); | 97 | i2c_set_clientdata(i2c, max8998); |
96 | max8998->dev = &i2c->dev; | 98 | max8998->dev = &i2c->dev; |
97 | max8998->i2c_client = i2c; | 99 | max8998->i2c = i2c; |
98 | max8998->dev_read = max8998_i2c_device_read; | ||
99 | max8998->dev_write = max8998_i2c_device_write; | ||
100 | max8998->dev_update = max8998_i2c_device_update; | ||
101 | mutex_init(&max8998->iolock); | 100 | mutex_init(&max8998->iolock); |
102 | 101 | ||
103 | ret = mfd_add_devices(max8998->dev, -1, | 102 | ret = mfd_add_devices(max8998->dev, -1, |
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index a1baf1fbe004..7f5fe6f198cf 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c | |||
@@ -173,6 +173,7 @@ static int max8998_get_enable_register(struct regulator_dev *rdev, | |||
173 | static int max8998_ldo_is_enabled(struct regulator_dev *rdev) | 173 | static int max8998_ldo_is_enabled(struct regulator_dev *rdev) |
174 | { | 174 | { |
175 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 175 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
176 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
176 | int ret, reg, shift = 8; | 177 | int ret, reg, shift = 8; |
177 | u8 val; | 178 | u8 val; |
178 | 179 | ||
@@ -180,7 +181,7 @@ static int max8998_ldo_is_enabled(struct regulator_dev *rdev) | |||
180 | if (ret) | 181 | if (ret) |
181 | return ret; | 182 | return ret; |
182 | 183 | ||
183 | ret = max8998_read_reg(max8998->iodev, reg, &val); | 184 | ret = max8998_read_reg(i2c, reg, &val); |
184 | if (ret) | 185 | if (ret) |
185 | return ret; | 186 | return ret; |
186 | 187 | ||
@@ -190,25 +191,27 @@ static int max8998_ldo_is_enabled(struct regulator_dev *rdev) | |||
190 | static int max8998_ldo_enable(struct regulator_dev *rdev) | 191 | static int max8998_ldo_enable(struct regulator_dev *rdev) |
191 | { | 192 | { |
192 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 193 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
194 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
193 | int reg, shift = 8, ret; | 195 | int reg, shift = 8, ret; |
194 | 196 | ||
195 | ret = max8998_get_enable_register(rdev, ®, &shift); | 197 | ret = max8998_get_enable_register(rdev, ®, &shift); |
196 | if (ret) | 198 | if (ret) |
197 | return ret; | 199 | return ret; |
198 | 200 | ||
199 | return max8998_update_reg(max8998->iodev, reg, 1<<shift, 1<<shift); | 201 | return max8998_update_reg(i2c, reg, 1<<shift, 1<<shift); |
200 | } | 202 | } |
201 | 203 | ||
202 | static int max8998_ldo_disable(struct regulator_dev *rdev) | 204 | static int max8998_ldo_disable(struct regulator_dev *rdev) |
203 | { | 205 | { |
204 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 206 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
207 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
205 | int reg, shift = 8, ret; | 208 | int reg, shift = 8, ret; |
206 | 209 | ||
207 | ret = max8998_get_enable_register(rdev, ®, &shift); | 210 | ret = max8998_get_enable_register(rdev, ®, &shift); |
208 | if (ret) | 211 | if (ret) |
209 | return ret; | 212 | return ret; |
210 | 213 | ||
211 | return max8998_update_reg(max8998->iodev, reg, 0, 1<<shift); | 214 | return max8998_update_reg(i2c, reg, 0, 1<<shift); |
212 | } | 215 | } |
213 | 216 | ||
214 | static int max8998_get_voltage_register(struct regulator_dev *rdev, | 217 | static int max8998_get_voltage_register(struct regulator_dev *rdev, |
@@ -276,6 +279,7 @@ static int max8998_get_voltage_register(struct regulator_dev *rdev, | |||
276 | static int max8998_get_voltage(struct regulator_dev *rdev) | 279 | static int max8998_get_voltage(struct regulator_dev *rdev) |
277 | { | 280 | { |
278 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 281 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
282 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
279 | int reg, shift = 0, mask, ret; | 283 | int reg, shift = 0, mask, ret; |
280 | u8 val; | 284 | u8 val; |
281 | 285 | ||
@@ -283,7 +287,7 @@ static int max8998_get_voltage(struct regulator_dev *rdev) | |||
283 | if (ret) | 287 | if (ret) |
284 | return ret; | 288 | return ret; |
285 | 289 | ||
286 | ret = max8998_read_reg(max8998->iodev, reg, &val); | 290 | ret = max8998_read_reg(i2c, reg, &val); |
287 | if (ret) | 291 | if (ret) |
288 | return ret; | 292 | return ret; |
289 | 293 | ||
@@ -297,6 +301,7 @@ static int max8998_set_voltage(struct regulator_dev *rdev, | |||
297 | int min_uV, int max_uV) | 301 | int min_uV, int max_uV) |
298 | { | 302 | { |
299 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 303 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
304 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
300 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | 305 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; |
301 | int previous_vol = 0; | 306 | int previous_vol = 0; |
302 | const struct voltage_map_desc *desc; | 307 | const struct voltage_map_desc *desc; |
@@ -330,14 +335,14 @@ static int max8998_set_voltage(struct regulator_dev *rdev, | |||
330 | /* wait for RAMP_UP_DELAY if rdev is BUCK1/2 and | 335 | /* wait for RAMP_UP_DELAY if rdev is BUCK1/2 and |
331 | * ENRAMP is ON */ | 336 | * ENRAMP is ON */ |
332 | if (ldo == MAX8998_BUCK1 || ldo == MAX8998_BUCK2) { | 337 | if (ldo == MAX8998_BUCK1 || ldo == MAX8998_BUCK2) { |
333 | max8998_read_reg(max8998->iodev, MAX8998_REG_ONOFF4, &val); | 338 | max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val); |
334 | if (val & (1 << 4)) { | 339 | if (val & (1 << 4)) { |
335 | en_ramp = true; | 340 | en_ramp = true; |
336 | previous_vol = max8998_get_voltage(rdev); | 341 | previous_vol = max8998_get_voltage(rdev); |
337 | } | 342 | } |
338 | } | 343 | } |
339 | 344 | ||
340 | ret = max8998_update_reg(max8998->iodev, reg, i<<shift, mask<<shift); | 345 | ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); |
341 | 346 | ||
342 | if (en_ramp == true) { | 347 | if (en_ramp == true) { |
343 | int difference = desc->min + desc->step*i - previous_vol/1000; | 348 | int difference = desc->min + desc->step*i - previous_vol/1000; |