diff options
Diffstat (limited to 'drivers/mfd/wm8350-i2c.c')
-rw-r--r-- | drivers/mfd/wm8350-i2c.c | 61 |
1 files changed, 15 insertions, 46 deletions
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c index d955faaf27c4..a68aceb4e48c 100644 --- a/drivers/mfd/wm8350-i2c.c +++ b/drivers/mfd/wm8350-i2c.c | |||
@@ -15,47 +15,18 @@ | |||
15 | 15 | ||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/moduleparam.h> | 17 | #include <linux/moduleparam.h> |
18 | #include <linux/err.h> | ||
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
19 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
20 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
21 | #include <linux/mfd/wm8350/core.h> | 22 | #include <linux/mfd/wm8350/core.h> |
23 | #include <linux/regmap.h> | ||
22 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
23 | 25 | ||
24 | static int wm8350_i2c_read_device(struct wm8350 *wm8350, char reg, | 26 | static const struct regmap_config wm8350_regmap = { |
25 | int bytes, void *dest) | 27 | .reg_bits = 8, |
26 | { | 28 | .val_bits = 16, |
27 | int ret; | 29 | }; |
28 | |||
29 | ret = i2c_master_send(wm8350->i2c_client, ®, 1); | ||
30 | if (ret < 0) | ||
31 | return ret; | ||
32 | ret = i2c_master_recv(wm8350->i2c_client, dest, bytes); | ||
33 | if (ret < 0) | ||
34 | return ret; | ||
35 | if (ret != bytes) | ||
36 | return -EIO; | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg, | ||
41 | int bytes, void *src) | ||
42 | { | ||
43 | /* we add 1 byte for device register */ | ||
44 | u8 msg[(WM8350_MAX_REGISTER << 1) + 1]; | ||
45 | int ret; | ||
46 | |||
47 | if (bytes > ((WM8350_MAX_REGISTER << 1) + 1)) | ||
48 | return -EINVAL; | ||
49 | |||
50 | msg[0] = reg; | ||
51 | memcpy(&msg[1], src, bytes); | ||
52 | ret = i2c_master_send(wm8350->i2c_client, msg, bytes + 1); | ||
53 | if (ret < 0) | ||
54 | return ret; | ||
55 | if (ret != bytes + 1) | ||
56 | return -EIO; | ||
57 | return 0; | ||
58 | } | ||
59 | 30 | ||
60 | static int wm8350_i2c_probe(struct i2c_client *i2c, | 31 | static int wm8350_i2c_probe(struct i2c_client *i2c, |
61 | const struct i2c_device_id *id) | 32 | const struct i2c_device_id *id) |
@@ -67,20 +38,18 @@ static int wm8350_i2c_probe(struct i2c_client *i2c, | |||
67 | if (wm8350 == NULL) | 38 | if (wm8350 == NULL) |
68 | return -ENOMEM; | 39 | return -ENOMEM; |
69 | 40 | ||
41 | wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap); | ||
42 | if (IS_ERR(wm8350->regmap)) { | ||
43 | ret = PTR_ERR(wm8350->regmap); | ||
44 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", | ||
45 | ret); | ||
46 | return ret; | ||
47 | } | ||
48 | |||
70 | i2c_set_clientdata(i2c, wm8350); | 49 | i2c_set_clientdata(i2c, wm8350); |
71 | wm8350->dev = &i2c->dev; | 50 | wm8350->dev = &i2c->dev; |
72 | wm8350->i2c_client = i2c; | ||
73 | wm8350->read_dev = wm8350_i2c_read_device; | ||
74 | wm8350->write_dev = wm8350_i2c_write_device; | ||
75 | |||
76 | ret = wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data); | ||
77 | if (ret < 0) | ||
78 | goto err; | ||
79 | |||
80 | return ret; | ||
81 | 51 | ||
82 | err: | 52 | return wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data); |
83 | return ret; | ||
84 | } | 53 | } |
85 | 54 | ||
86 | static int wm8350_i2c_remove(struct i2c_client *i2c) | 55 | static int wm8350_i2c_remove(struct i2c_client *i2c) |