aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/88pm860x-i2c.c
diff options
context:
space:
mode:
authorJett.Zhou <jtzhou@marvell.com>2011-11-11 02:38:27 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2012-01-08 18:37:30 -0500
commitb46a36c0e0adc92c8be2c8a6fa68d979f6eee124 (patch)
tree8553651cc4963fdeb4e2c56f39e69889baf1f399 /drivers/mfd/88pm860x-i2c.c
parent5bdf7411bc2329cfe015ba6dcf59531e0c6891b8 (diff)
mfd: Convert 88pm860x to use regmap api
Convert the 88pm860x normal bank register read/write to use the register map API. Signed-off-by: Jett.Zhou <jtzhou@marvell.com> Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/88pm860x-i2c.c')
-rw-r--r--drivers/mfd/88pm860x-i2c.c105
1 files changed, 44 insertions, 61 deletions
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c
index f629d6f4e3e9..630f1b545fc4 100644
--- a/drivers/mfd/88pm860x-i2c.c
+++ b/drivers/mfd/88pm860x-i2c.c
@@ -12,51 +12,20 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/err.h>
16#include <linux/regmap.h>
15#include <linux/mfd/88pm860x.h> 17#include <linux/mfd/88pm860x.h>
16#include <linux/slab.h> 18#include <linux/slab.h>
17 19
18static inline int pm860x_read_device(struct i2c_client *i2c,
19 int reg, int bytes, void *dest)
20{
21 unsigned char data;
22 int ret;
23
24 data = (unsigned char)reg;
25 ret = i2c_master_send(i2c, &data, 1);
26 if (ret < 0)
27 return ret;
28
29 ret = i2c_master_recv(i2c, dest, bytes);
30 if (ret < 0)
31 return ret;
32 return 0;
33}
34
35static inline int pm860x_write_device(struct i2c_client *i2c,
36 int reg, int bytes, void *src)
37{
38 unsigned char buf[bytes + 1];
39 int ret;
40
41 buf[0] = (unsigned char)reg;
42 memcpy(&buf[1], src, bytes);
43
44 ret = i2c_master_send(i2c, buf, bytes + 1);
45 if (ret < 0)
46 return ret;
47 return 0;
48}
49
50int pm860x_reg_read(struct i2c_client *i2c, int reg) 20int pm860x_reg_read(struct i2c_client *i2c, int reg)
51{ 21{
52 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 22 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
53 unsigned char data; 23 struct regmap *map = (i2c == chip->client) ? chip->regmap
24 : chip->regmap_companion;
25 unsigned int data;
54 int ret; 26 int ret;
55 27
56 mutex_lock(&chip->io_lock); 28 ret = regmap_read(map, reg, &data);
57 ret = pm860x_read_device(i2c, reg, 1, &data);
58 mutex_unlock(&chip->io_lock);
59
60 if (ret < 0) 29 if (ret < 0)
61 return ret; 30 return ret;
62 else 31 else
@@ -68,12 +37,11 @@ int pm860x_reg_write(struct i2c_client *i2c, int reg,
68 unsigned char data) 37 unsigned char data)
69{ 38{
70 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 39 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
40 struct regmap *map = (i2c == chip->client) ? chip->regmap
41 : chip->regmap_companion;
71 int ret; 42 int ret;
72 43
73 mutex_lock(&chip->io_lock); 44 ret = regmap_write(map, reg, data);
74 ret = pm860x_write_device(i2c, reg, 1, &data);
75 mutex_unlock(&chip->io_lock);
76
77 return ret; 45 return ret;
78} 46}
79EXPORT_SYMBOL(pm860x_reg_write); 47EXPORT_SYMBOL(pm860x_reg_write);
@@ -82,12 +50,11 @@ int pm860x_bulk_read(struct i2c_client *i2c, int reg,
82 int count, unsigned char *buf) 50 int count, unsigned char *buf)
83{ 51{
84 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 52 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
53 struct regmap *map = (i2c == chip->client) ? chip->regmap
54 : chip->regmap_companion;
85 int ret; 55 int ret;
86 56
87 mutex_lock(&chip->io_lock); 57 ret = regmap_raw_read(map, reg, buf, count);
88 ret = pm860x_read_device(i2c, reg, count, buf);
89 mutex_unlock(&chip->io_lock);
90
91 return ret; 58 return ret;
92} 59}
93EXPORT_SYMBOL(pm860x_bulk_read); 60EXPORT_SYMBOL(pm860x_bulk_read);
@@ -96,12 +63,11 @@ int pm860x_bulk_write(struct i2c_client *i2c, int reg,
96 int count, unsigned char *buf) 63 int count, unsigned char *buf)
97{ 64{
98 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 65 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
66 struct regmap *map = (i2c == chip->client) ? chip->regmap
67 : chip->regmap_companion;
99 int ret; 68 int ret;
100 69
101 mutex_lock(&chip->io_lock); 70 ret = regmap_raw_write(map, reg, buf, count);
102 ret = pm860x_write_device(i2c, reg, count, buf);
103 mutex_unlock(&chip->io_lock);
104
105 return ret; 71 return ret;
106} 72}
107EXPORT_SYMBOL(pm860x_bulk_write); 73EXPORT_SYMBOL(pm860x_bulk_write);
@@ -110,18 +76,11 @@ int pm860x_set_bits(struct i2c_client *i2c, int reg,
110 unsigned char mask, unsigned char data) 76 unsigned char mask, unsigned char data)
111{ 77{
112 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 78 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
113 unsigned char value; 79 struct regmap *map = (i2c == chip->client) ? chip->regmap
80 : chip->regmap_companion;
114 int ret; 81 int ret;
115 82
116 mutex_lock(&chip->io_lock); 83 ret = regmap_update_bits(map, reg, mask, data);
117 ret = pm860x_read_device(i2c, reg, 1, &value);
118 if (ret < 0)
119 goto out;
120 value &= ~mask;
121 value |= data;
122 ret = pm860x_write_device(i2c, reg, 1, &value);
123out:
124 mutex_unlock(&chip->io_lock);
125 return ret; 84 return ret;
126} 85}
127EXPORT_SYMBOL(pm860x_set_bits); 86EXPORT_SYMBOL(pm860x_set_bits);
@@ -300,11 +259,17 @@ static int verify_addr(struct i2c_client *i2c)
300 return 0; 259 return 0;
301} 260}
302 261
262static struct regmap_config pm860x_regmap_config = {
263 .reg_bits = 8,
264 .val_bits = 8,
265};
266
303static int __devinit pm860x_probe(struct i2c_client *client, 267static int __devinit pm860x_probe(struct i2c_client *client,
304 const struct i2c_device_id *id) 268 const struct i2c_device_id *id)
305{ 269{
306 struct pm860x_platform_data *pdata = client->dev.platform_data; 270 struct pm860x_platform_data *pdata = client->dev.platform_data;
307 struct pm860x_chip *chip; 271 struct pm860x_chip *chip;
272 int ret;
308 273
309 if (!pdata) { 274 if (!pdata) {
310 pr_info("No platform data in %s!\n", __func__); 275 pr_info("No platform data in %s!\n", __func__);
@@ -316,10 +281,16 @@ static int __devinit pm860x_probe(struct i2c_client *client,
316 return -ENOMEM; 281 return -ENOMEM;
317 282
318 chip->id = verify_addr(client); 283 chip->id = verify_addr(client);
284 chip->regmap = regmap_init_i2c(client, &pm860x_regmap_config);
285 if (IS_ERR(chip->regmap)) {
286 ret = PTR_ERR(chip->regmap);
287 dev_err(&client->dev, "Failed to allocate register map: %d\n",
288 ret);
289 return ret;
290 }
319 chip->client = client; 291 chip->client = client;
320 i2c_set_clientdata(client, chip); 292 i2c_set_clientdata(client, chip);
321 chip->dev = &client->dev; 293 chip->dev = &client->dev;
322 mutex_init(&chip->io_lock);
323 dev_set_drvdata(chip->dev, chip); 294 dev_set_drvdata(chip->dev, chip);
324 295
325 /* 296 /*
@@ -333,6 +304,14 @@ static int __devinit pm860x_probe(struct i2c_client *client,
333 chip->companion_addr = pdata->companion_addr; 304 chip->companion_addr = pdata->companion_addr;
334 chip->companion = i2c_new_dummy(chip->client->adapter, 305 chip->companion = i2c_new_dummy(chip->client->adapter,
335 chip->companion_addr); 306 chip->companion_addr);
307 chip->regmap_companion = regmap_init_i2c(chip->companion,
308 &pm860x_regmap_config);
309 if (IS_ERR(chip->regmap_companion)) {
310 ret = PTR_ERR(chip->regmap_companion);
311 dev_err(&chip->companion->dev,
312 "Failed to allocate register map: %d\n", ret);
313 return ret;
314 }
336 i2c_set_clientdata(chip->companion, chip); 315 i2c_set_clientdata(chip->companion, chip);
337 } 316 }
338 317
@@ -345,7 +324,11 @@ static int __devexit pm860x_remove(struct i2c_client *client)
345 struct pm860x_chip *chip = i2c_get_clientdata(client); 324 struct pm860x_chip *chip = i2c_get_clientdata(client);
346 325
347 pm860x_device_exit(chip); 326 pm860x_device_exit(chip);
348 i2c_unregister_device(chip->companion); 327 if (chip->companion) {
328 regmap_exit(chip->regmap_companion);
329 i2c_unregister_device(chip->companion);
330 }
331 regmap_exit(chip->regmap);
349 kfree(chip); 332 kfree(chip);
350 return 0; 333 return 0;
351} 334}