diff options
author | Haojian Zhuang <haojian.zhuang@marvell.com> | 2010-01-08 06:01:24 -0500 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-03-07 16:17:01 -0500 |
commit | 53dbab7af9ca13fa95605e9a5c31bb803dcba363 (patch) | |
tree | 652214fb5b3cee8195e253e56314b913ed78cf88 /drivers | |
parent | bbd51b1ff1bf57b9ed7f062486a415509968d4d9 (diff) |
mfd: Support 88pm8606 in 860x driver
88PM8606 and 88PM8607 are two discrete chips used for power management.
Hardware designer can use them together or only one of them according to
requirement.
There's some logic tightly linked between these two chips. For example, USB
charger driver needs to access both chips by I2C interface.
Now share one driver to these two devices. Only one I2C client is identified
in platform init data. If another chip is also used, user should mark it in
companion_addr field of platform init data. Then driver could create another
I2C client for the companion chip.
All I2C operations are accessed by 860x-i2c driver. In order to support both
I2C client address, the read/write API is changed in below.
reg_read(client, offset)
reg_write(client, offset, data)
The benefit is that client drivers only need one kind of read/write API. I2C
and MFD driver can be shared in both 8606 and 8607.
Since API is changed, update API in 8607 regulator driver.
Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mfd/88pm860x-core.c | 61 | ||||
-rw-r--r-- | drivers/mfd/88pm860x-i2c.c | 172 | ||||
-rw-r--r-- | drivers/regulator/88pm8607.c | 32 |
3 files changed, 175 insertions, 90 deletions
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c index d1464e54e656..72b00304dc3a 100644 --- a/drivers/mfd/88pm860x-core.c +++ b/drivers/mfd/88pm860x-core.c | |||
@@ -14,7 +14,7 @@ | |||
14 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
15 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
16 | #include <linux/mfd/core.h> | 16 | #include <linux/mfd/core.h> |
17 | #include <linux/mfd/88pm8607.h> | 17 | #include <linux/mfd/88pm860x.h> |
18 | 18 | ||
19 | 19 | ||
20 | #define PM8607_REG_RESOURCE(_start, _end) \ | 20 | #define PM8607_REG_RESOURCE(_start, _end) \ |
@@ -67,18 +67,23 @@ static struct mfd_cell pm8607_devs[] = { | |||
67 | PM8607_REG_DEVS(ldo14, LDO14), | 67 | PM8607_REG_DEVS(ldo14, LDO14), |
68 | }; | 68 | }; |
69 | 69 | ||
70 | int pm860x_device_init(struct pm8607_chip *chip, | 70 | static void device_8606_init(struct pm860x_chip *chip, struct i2c_client *i2c, |
71 | struct pm8607_platform_data *pdata) | 71 | struct pm860x_platform_data *pdata) |
72 | { | ||
73 | } | ||
74 | |||
75 | static void device_8607_init(struct pm860x_chip *chip, struct i2c_client *i2c, | ||
76 | struct pm860x_platform_data *pdata) | ||
72 | { | 77 | { |
73 | int i, count; | 78 | int i, count; |
74 | int ret; | 79 | int ret; |
75 | 80 | ||
76 | ret = pm8607_reg_read(chip, PM8607_CHIP_ID); | 81 | ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); |
77 | if (ret < 0) { | 82 | if (ret < 0) { |
78 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); | 83 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); |
79 | goto out; | 84 | goto out; |
80 | } | 85 | } |
81 | if ((ret & PM8607_ID_MASK) == PM8607_ID) | 86 | if ((ret & PM8607_VERSION_MASK) == PM8607_VERSION) |
82 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", | 87 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", |
83 | ret); | 88 | ret); |
84 | else { | 89 | else { |
@@ -86,9 +91,9 @@ int pm860x_device_init(struct pm8607_chip *chip, | |||
86 | "Chip ID: %02x\n", ret); | 91 | "Chip ID: %02x\n", ret); |
87 | goto out; | 92 | goto out; |
88 | } | 93 | } |
89 | chip->chip_id = ret; | 94 | chip->chip_version = ret; |
90 | 95 | ||
91 | ret = pm8607_reg_read(chip, PM8607_BUCK3); | 96 | ret = pm860x_reg_read(i2c, PM8607_BUCK3); |
92 | if (ret < 0) { | 97 | if (ret < 0) { |
93 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); | 98 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); |
94 | goto out; | 99 | goto out; |
@@ -96,20 +101,11 @@ int pm860x_device_init(struct pm8607_chip *chip, | |||
96 | if (ret & PM8607_BUCK3_DOUBLE) | 101 | if (ret & PM8607_BUCK3_DOUBLE) |
97 | chip->buck3_double = 1; | 102 | chip->buck3_double = 1; |
98 | 103 | ||
99 | ret = pm8607_reg_read(chip, PM8607_MISC1); | 104 | ret = pm860x_reg_read(i2c, PM8607_MISC1); |
100 | if (ret < 0) { | 105 | if (ret < 0) { |
101 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); | 106 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); |
102 | goto out; | 107 | goto out; |
103 | } | 108 | } |
104 | if (pdata->i2c_port == PI2C_PORT) | ||
105 | ret |= PM8607_MISC1_PI2C; | ||
106 | else | ||
107 | ret &= ~PM8607_MISC1_PI2C; | ||
108 | ret = pm8607_reg_write(chip, PM8607_MISC1, ret); | ||
109 | if (ret < 0) { | ||
110 | dev_err(chip->dev, "Failed to write MISC1 register: %d\n", ret); | ||
111 | goto out; | ||
112 | } | ||
113 | 109 | ||
114 | count = ARRAY_SIZE(pm8607_devs); | 110 | count = ARRAY_SIZE(pm8607_devs); |
115 | for (i = 0; i < count; i++) { | 111 | for (i = 0; i < count; i++) { |
@@ -121,14 +117,39 @@ int pm860x_device_init(struct pm8607_chip *chip, | |||
121 | } | 117 | } |
122 | } | 118 | } |
123 | out: | 119 | out: |
124 | return ret; | 120 | return; |
121 | } | ||
122 | |||
123 | int pm860x_device_init(struct pm860x_chip *chip, | ||
124 | struct pm860x_platform_data *pdata) | ||
125 | { | ||
126 | switch (chip->id) { | ||
127 | case CHIP_PM8606: | ||
128 | device_8606_init(chip, chip->client, pdata); | ||
129 | break; | ||
130 | case CHIP_PM8607: | ||
131 | device_8607_init(chip, chip->client, pdata); | ||
132 | break; | ||
133 | } | ||
134 | |||
135 | if (chip->companion) { | ||
136 | switch (chip->id) { | ||
137 | case CHIP_PM8607: | ||
138 | device_8606_init(chip, chip->companion, pdata); | ||
139 | break; | ||
140 | case CHIP_PM8606: | ||
141 | device_8607_init(chip, chip->companion, pdata); | ||
142 | break; | ||
143 | } | ||
144 | } | ||
145 | return 0; | ||
125 | } | 146 | } |
126 | 147 | ||
127 | void pm8607_device_exit(struct pm8607_chip *chip) | 148 | void pm860x_device_exit(struct pm860x_chip *chip) |
128 | { | 149 | { |
129 | mfd_remove_devices(chip->dev); | 150 | mfd_remove_devices(chip->dev); |
130 | } | 151 | } |
131 | 152 | ||
132 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM8607"); | 153 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x"); |
133 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | 154 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); |
134 | MODULE_LICENSE("GPL"); | 155 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c index dda23cbfe415..6d7dba2bce8a 100644 --- a/drivers/mfd/88pm860x-i2c.c +++ b/drivers/mfd/88pm860x-i2c.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * I2C driver for Marvell 88PM8607 | 2 | * I2C driver for Marvell 88PM860x |
3 | * | 3 | * |
4 | * Copyright (C) 2009 Marvell International Ltd. | 4 | * Copyright (C) 2009 Marvell International Ltd. |
5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | 5 | * Haojian Zhuang <haojian.zhuang@marvell.com> |
@@ -12,12 +12,11 @@ | |||
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/mfd/88pm8607.h> | 15 | #include <linux/mfd/88pm860x.h> |
16 | 16 | ||
17 | static inline int pm8607_read_device(struct pm8607_chip *chip, | 17 | static inline int pm860x_read_device(struct i2c_client *i2c, |
18 | int reg, int bytes, void *dest) | 18 | int reg, int bytes, void *dest) |
19 | { | 19 | { |
20 | struct i2c_client *i2c = chip->client; | ||
21 | unsigned char data; | 20 | unsigned char data; |
22 | int ret; | 21 | int ret; |
23 | 22 | ||
@@ -32,10 +31,9 @@ static inline int pm8607_read_device(struct pm8607_chip *chip, | |||
32 | return 0; | 31 | return 0; |
33 | } | 32 | } |
34 | 33 | ||
35 | static inline int pm8607_write_device(struct pm8607_chip *chip, | 34 | static inline int pm860x_write_device(struct i2c_client *i2c, |
36 | int reg, int bytes, void *src) | 35 | int reg, int bytes, void *src) |
37 | { | 36 | { |
38 | struct i2c_client *i2c = chip->client; | ||
39 | unsigned char buf[bytes + 1]; | 37 | unsigned char buf[bytes + 1]; |
40 | int ret; | 38 | int ret; |
41 | 39 | ||
@@ -48,13 +46,14 @@ static inline int pm8607_write_device(struct pm8607_chip *chip, | |||
48 | return 0; | 46 | return 0; |
49 | } | 47 | } |
50 | 48 | ||
51 | int pm8607_reg_read(struct pm8607_chip *chip, int reg) | 49 | int pm860x_reg_read(struct i2c_client *i2c, int reg) |
52 | { | 50 | { |
51 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
53 | unsigned char data; | 52 | unsigned char data; |
54 | int ret; | 53 | int ret; |
55 | 54 | ||
56 | mutex_lock(&chip->io_lock); | 55 | mutex_lock(&chip->io_lock); |
57 | ret = chip->read(chip, reg, 1, &data); | 56 | ret = pm860x_read_device(i2c, reg, 1, &data); |
58 | mutex_unlock(&chip->io_lock); | 57 | mutex_unlock(&chip->io_lock); |
59 | 58 | ||
60 | if (ret < 0) | 59 | if (ret < 0) |
@@ -62,111 +61,178 @@ int pm8607_reg_read(struct pm8607_chip *chip, int reg) | |||
62 | else | 61 | else |
63 | return (int)data; | 62 | return (int)data; |
64 | } | 63 | } |
65 | EXPORT_SYMBOL(pm8607_reg_read); | 64 | EXPORT_SYMBOL(pm860x_reg_read); |
66 | 65 | ||
67 | int pm8607_reg_write(struct pm8607_chip *chip, int reg, | 66 | int pm860x_reg_write(struct i2c_client *i2c, int reg, |
68 | unsigned char data) | 67 | unsigned char data) |
69 | { | 68 | { |
69 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
70 | int ret; | 70 | int ret; |
71 | 71 | ||
72 | mutex_lock(&chip->io_lock); | 72 | mutex_lock(&chip->io_lock); |
73 | ret = chip->write(chip, reg, 1, &data); | 73 | ret = pm860x_write_device(i2c, reg, 1, &data); |
74 | mutex_unlock(&chip->io_lock); | 74 | mutex_unlock(&chip->io_lock); |
75 | 75 | ||
76 | return ret; | 76 | return ret; |
77 | } | 77 | } |
78 | EXPORT_SYMBOL(pm8607_reg_write); | 78 | EXPORT_SYMBOL(pm860x_reg_write); |
79 | 79 | ||
80 | int pm8607_bulk_read(struct pm8607_chip *chip, int reg, | 80 | int pm860x_bulk_read(struct i2c_client *i2c, int reg, |
81 | int count, unsigned char *buf) | 81 | int count, unsigned char *buf) |
82 | { | 82 | { |
83 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
83 | int ret; | 84 | int ret; |
84 | 85 | ||
85 | mutex_lock(&chip->io_lock); | 86 | mutex_lock(&chip->io_lock); |
86 | ret = chip->read(chip, reg, count, buf); | 87 | ret = pm860x_read_device(i2c, reg, count, buf); |
87 | mutex_unlock(&chip->io_lock); | 88 | mutex_unlock(&chip->io_lock); |
88 | 89 | ||
89 | return ret; | 90 | return ret; |
90 | } | 91 | } |
91 | EXPORT_SYMBOL(pm8607_bulk_read); | 92 | EXPORT_SYMBOL(pm860x_bulk_read); |
92 | 93 | ||
93 | int pm8607_bulk_write(struct pm8607_chip *chip, int reg, | 94 | int pm860x_bulk_write(struct i2c_client *i2c, int reg, |
94 | int count, unsigned char *buf) | 95 | int count, unsigned char *buf) |
95 | { | 96 | { |
97 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
96 | int ret; | 98 | int ret; |
97 | 99 | ||
98 | mutex_lock(&chip->io_lock); | 100 | mutex_lock(&chip->io_lock); |
99 | ret = chip->write(chip, reg, count, buf); | 101 | ret = pm860x_write_device(i2c, reg, count, buf); |
100 | mutex_unlock(&chip->io_lock); | 102 | mutex_unlock(&chip->io_lock); |
101 | 103 | ||
102 | return ret; | 104 | return ret; |
103 | } | 105 | } |
104 | EXPORT_SYMBOL(pm8607_bulk_write); | 106 | EXPORT_SYMBOL(pm860x_bulk_write); |
105 | 107 | ||
106 | int pm8607_set_bits(struct pm8607_chip *chip, int reg, | 108 | int pm860x_set_bits(struct i2c_client *i2c, int reg, |
107 | unsigned char mask, unsigned char data) | 109 | unsigned char mask, unsigned char data) |
108 | { | 110 | { |
111 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); | ||
109 | unsigned char value; | 112 | unsigned char value; |
110 | int ret; | 113 | int ret; |
111 | 114 | ||
112 | mutex_lock(&chip->io_lock); | 115 | mutex_lock(&chip->io_lock); |
113 | ret = chip->read(chip, reg, 1, &value); | 116 | ret = pm860x_read_device(i2c, reg, 1, &value); |
114 | if (ret < 0) | 117 | if (ret < 0) |
115 | goto out; | 118 | goto out; |
116 | value &= ~mask; | 119 | value &= ~mask; |
117 | value |= data; | 120 | value |= data; |
118 | ret = chip->write(chip, reg, 1, &value); | 121 | ret = pm860x_write_device(i2c, reg, 1, &value); |
119 | out: | 122 | out: |
120 | mutex_unlock(&chip->io_lock); | 123 | mutex_unlock(&chip->io_lock); |
121 | return ret; | 124 | return ret; |
122 | } | 125 | } |
123 | EXPORT_SYMBOL(pm8607_set_bits); | 126 | EXPORT_SYMBOL(pm860x_set_bits); |
124 | 127 | ||
125 | 128 | ||
126 | static const struct i2c_device_id pm860x_id_table[] = { | 129 | static const struct i2c_device_id pm860x_id_table[] = { |
127 | { "88PM8607", 0 }, | 130 | { "88PM860x", 0 }, |
128 | {} | 131 | {} |
129 | }; | 132 | }; |
130 | MODULE_DEVICE_TABLE(i2c, pm860x_id_table); | 133 | MODULE_DEVICE_TABLE(i2c, pm860x_id_table); |
131 | 134 | ||
135 | static int verify_addr(struct i2c_client *i2c) | ||
136 | { | ||
137 | unsigned short addr_8607[] = {0x30, 0x34}; | ||
138 | unsigned short addr_8606[] = {0x10, 0x11}; | ||
139 | int size, i; | ||
140 | |||
141 | if (i2c == NULL) | ||
142 | return 0; | ||
143 | size = ARRAY_SIZE(addr_8606); | ||
144 | for (i = 0; i < size; i++) { | ||
145 | if (i2c->addr == *(addr_8606 + i)) | ||
146 | return CHIP_PM8606; | ||
147 | } | ||
148 | size = ARRAY_SIZE(addr_8607); | ||
149 | for (i = 0; i < size; i++) { | ||
150 | if (i2c->addr == *(addr_8607 + i)) | ||
151 | return CHIP_PM8607; | ||
152 | } | ||
153 | return 0; | ||
154 | } | ||
155 | |||
132 | static int __devinit pm860x_probe(struct i2c_client *client, | 156 | static int __devinit pm860x_probe(struct i2c_client *client, |
133 | const struct i2c_device_id *id) | 157 | const struct i2c_device_id *id) |
134 | { | 158 | { |
135 | struct pm8607_platform_data *pdata = client->dev.platform_data; | 159 | struct pm860x_platform_data *pdata = client->dev.platform_data; |
136 | struct pm8607_chip *chip; | 160 | static struct pm860x_chip *chip; |
137 | int ret; | 161 | struct i2c_board_info i2c_info = { |
138 | 162 | .type = "88PM860x", | |
139 | chip = kzalloc(sizeof(struct pm8607_chip), GFP_KERNEL); | 163 | .platform_data = client->dev.platform_data, |
140 | if (chip == NULL) | 164 | }; |
141 | return -ENOMEM; | 165 | int addr_c, found_companion = 0; |
142 | 166 | ||
143 | chip->client = client; | 167 | if (pdata == NULL) { |
144 | chip->dev = &client->dev; | 168 | pr_info("No platform data in %s!\n", __func__); |
145 | chip->read = pm8607_read_device; | 169 | return -EINVAL; |
146 | chip->write = pm8607_write_device; | 170 | } |
147 | memcpy(&chip->id, id, sizeof(struct i2c_device_id)); | 171 | |
148 | i2c_set_clientdata(client, chip); | 172 | /* |
149 | 173 | * Both client and companion client shares same platform driver. | |
150 | mutex_init(&chip->io_lock); | 174 | * Driver distinguishes them by pdata->companion_addr. |
151 | dev_set_drvdata(chip->dev, chip); | 175 | * pdata->companion_addr is only assigned if companion chip exists. |
152 | 176 | * At the same time, the companion_addr shouldn't equal to client | |
153 | ret = pm860x_device_init(chip, pdata); | 177 | * address. |
154 | if (ret < 0) | 178 | */ |
155 | goto out; | 179 | addr_c = pdata->companion_addr; |
156 | 180 | if (addr_c && (addr_c != client->addr)) { | |
157 | 181 | i2c_info.addr = addr_c; | |
182 | found_companion = 1; | ||
183 | } | ||
184 | |||
185 | if (found_companion || (addr_c == 0)) { | ||
186 | chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL); | ||
187 | if (chip == NULL) | ||
188 | return -ENOMEM; | ||
189 | |||
190 | chip->id = verify_addr(client); | ||
191 | chip->companion_addr = addr_c; | ||
192 | chip->client = client; | ||
193 | i2c_set_clientdata(client, chip); | ||
194 | chip->dev = &client->dev; | ||
195 | mutex_init(&chip->io_lock); | ||
196 | dev_set_drvdata(chip->dev, chip); | ||
197 | |||
198 | if (found_companion) { | ||
199 | /* | ||
200 | * If this driver is built in, probe function is | ||
201 | * recursive. | ||
202 | * If this driver is built as module, the next probe | ||
203 | * function is called after the first one finished. | ||
204 | */ | ||
205 | chip->companion = i2c_new_device(client->adapter, | ||
206 | &i2c_info); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | /* | ||
211 | * If companion chip existes, it's called by companion probe. | ||
212 | * If there's no companion chip, it's called by client probe. | ||
213 | */ | ||
214 | if ((addr_c == 0) || (addr_c == client->addr)) { | ||
215 | chip->companion = client; | ||
216 | i2c_set_clientdata(chip->companion, chip); | ||
217 | pm860x_device_init(chip, pdata); | ||
218 | } | ||
158 | return 0; | 219 | return 0; |
159 | |||
160 | out: | ||
161 | i2c_set_clientdata(client, NULL); | ||
162 | kfree(chip); | ||
163 | return ret; | ||
164 | } | 220 | } |
165 | 221 | ||
166 | static int __devexit pm860x_remove(struct i2c_client *client) | 222 | static int __devexit pm860x_remove(struct i2c_client *client) |
167 | { | 223 | { |
168 | struct pm8607_chip *chip = i2c_get_clientdata(client); | 224 | struct pm860x_chip *chip = i2c_get_clientdata(client); |
169 | 225 | ||
226 | /* | ||
227 | * If companion existes, companion client is removed first. | ||
228 | * Because companion client is registered last and removed first. | ||
229 | */ | ||
230 | if (chip->companion_addr == client->addr) | ||
231 | return 0; | ||
232 | pm860x_device_exit(chip); | ||
233 | i2c_unregister_device(chip->companion); | ||
234 | i2c_set_clientdata(chip->companion, NULL); | ||
235 | i2c_set_clientdata(chip->client, NULL); | ||
170 | kfree(chip); | 236 | kfree(chip); |
171 | return 0; | 237 | return 0; |
172 | } | 238 | } |
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c index 04719551381b..97897a6bf4f3 100644 --- a/drivers/regulator/88pm8607.c +++ b/drivers/regulator/88pm8607.c | |||
@@ -11,15 +11,17 @@ | |||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/err.h> | 13 | #include <linux/err.h> |
14 | #include <linux/i2c.h> | ||
14 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
15 | #include <linux/regulator/driver.h> | 16 | #include <linux/regulator/driver.h> |
16 | #include <linux/regulator/machine.h> | 17 | #include <linux/regulator/machine.h> |
17 | #include <linux/mfd/88pm8607.h> | 18 | #include <linux/mfd/88pm860x.h> |
18 | 19 | ||
19 | struct pm8607_regulator_info { | 20 | struct pm8607_regulator_info { |
20 | struct regulator_desc desc; | 21 | struct regulator_desc desc; |
21 | struct pm8607_chip *chip; | 22 | struct pm860x_chip *chip; |
22 | struct regulator_dev *regulator; | 23 | struct regulator_dev *regulator; |
24 | struct i2c_client *i2c; | ||
23 | 25 | ||
24 | int min_uV; | 26 | int min_uV; |
25 | int max_uV; | 27 | int max_uV; |
@@ -46,7 +48,7 @@ static inline int check_range(struct pm8607_regulator_info *info, | |||
46 | static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) | 48 | static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) |
47 | { | 49 | { |
48 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 50 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
49 | uint8_t chip_id = info->chip->chip_id; | 51 | uint8_t chip_id = info->chip->chip_version; |
50 | int ret = -EINVAL; | 52 | int ret = -EINVAL; |
51 | 53 | ||
52 | switch (info->desc.id) { | 54 | switch (info->desc.id) { |
@@ -169,7 +171,7 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) | |||
169 | static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) | 171 | static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) |
170 | { | 172 | { |
171 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 173 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
172 | uint8_t chip_id = info->chip->chip_id; | 174 | uint8_t chip_id = info->chip->chip_version; |
173 | int val = -ENOENT; | 175 | int val = -ENOENT; |
174 | int ret; | 176 | int ret; |
175 | 177 | ||
@@ -428,7 +430,6 @@ static int pm8607_set_voltage(struct regulator_dev *rdev, | |||
428 | int min_uV, int max_uV) | 430 | int min_uV, int max_uV) |
429 | { | 431 | { |
430 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 432 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
431 | struct pm8607_chip *chip = info->chip; | ||
432 | uint8_t val, mask; | 433 | uint8_t val, mask; |
433 | int ret; | 434 | int ret; |
434 | 435 | ||
@@ -443,13 +444,13 @@ static int pm8607_set_voltage(struct regulator_dev *rdev, | |||
443 | val = (uint8_t)(ret << info->vol_shift); | 444 | val = (uint8_t)(ret << info->vol_shift); |
444 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 445 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
445 | 446 | ||
446 | ret = pm8607_set_bits(chip, info->vol_reg, mask, val); | 447 | ret = pm860x_set_bits(info->i2c, info->vol_reg, mask, val); |
447 | if (ret) | 448 | if (ret) |
448 | return ret; | 449 | return ret; |
449 | switch (info->desc.id) { | 450 | switch (info->desc.id) { |
450 | case PM8607_ID_BUCK1: | 451 | case PM8607_ID_BUCK1: |
451 | case PM8607_ID_BUCK3: | 452 | case PM8607_ID_BUCK3: |
452 | ret = pm8607_set_bits(chip, info->update_reg, | 453 | ret = pm860x_set_bits(info->i2c, info->update_reg, |
453 | 1 << info->update_bit, | 454 | 1 << info->update_bit, |
454 | 1 << info->update_bit); | 455 | 1 << info->update_bit); |
455 | break; | 456 | break; |
@@ -460,11 +461,10 @@ static int pm8607_set_voltage(struct regulator_dev *rdev, | |||
460 | static int pm8607_get_voltage(struct regulator_dev *rdev) | 461 | static int pm8607_get_voltage(struct regulator_dev *rdev) |
461 | { | 462 | { |
462 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 463 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
463 | struct pm8607_chip *chip = info->chip; | ||
464 | uint8_t val, mask; | 464 | uint8_t val, mask; |
465 | int ret; | 465 | int ret; |
466 | 466 | ||
467 | ret = pm8607_reg_read(chip, info->vol_reg); | 467 | ret = pm860x_reg_read(info->i2c, info->vol_reg); |
468 | if (ret < 0) | 468 | if (ret < 0) |
469 | return ret; | 469 | return ret; |
470 | 470 | ||
@@ -477,9 +477,8 @@ static int pm8607_get_voltage(struct regulator_dev *rdev) | |||
477 | static int pm8607_enable(struct regulator_dev *rdev) | 477 | static int pm8607_enable(struct regulator_dev *rdev) |
478 | { | 478 | { |
479 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 479 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
480 | struct pm8607_chip *chip = info->chip; | ||
481 | 480 | ||
482 | return pm8607_set_bits(chip, info->enable_reg, | 481 | return pm860x_set_bits(info->i2c, info->enable_reg, |
483 | 1 << info->enable_bit, | 482 | 1 << info->enable_bit, |
484 | 1 << info->enable_bit); | 483 | 1 << info->enable_bit); |
485 | } | 484 | } |
@@ -487,19 +486,17 @@ static int pm8607_enable(struct regulator_dev *rdev) | |||
487 | static int pm8607_disable(struct regulator_dev *rdev) | 486 | static int pm8607_disable(struct regulator_dev *rdev) |
488 | { | 487 | { |
489 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 488 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
490 | struct pm8607_chip *chip = info->chip; | ||
491 | 489 | ||
492 | return pm8607_set_bits(chip, info->enable_reg, | 490 | return pm860x_set_bits(info->i2c, info->enable_reg, |
493 | 1 << info->enable_bit, 0); | 491 | 1 << info->enable_bit, 0); |
494 | } | 492 | } |
495 | 493 | ||
496 | static int pm8607_is_enabled(struct regulator_dev *rdev) | 494 | static int pm8607_is_enabled(struct regulator_dev *rdev) |
497 | { | 495 | { |
498 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 496 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
499 | struct pm8607_chip *chip = info->chip; | ||
500 | int ret; | 497 | int ret; |
501 | 498 | ||
502 | ret = pm8607_reg_read(chip, info->enable_reg); | 499 | ret = pm860x_reg_read(info->i2c, info->enable_reg); |
503 | if (ret < 0) | 500 | if (ret < 0) |
504 | return ret; | 501 | return ret; |
505 | 502 | ||
@@ -589,8 +586,8 @@ static inline struct pm8607_regulator_info *find_regulator_info(int id) | |||
589 | 586 | ||
590 | static int __devinit pm8607_regulator_probe(struct platform_device *pdev) | 587 | static int __devinit pm8607_regulator_probe(struct platform_device *pdev) |
591 | { | 588 | { |
592 | struct pm8607_chip *chip = dev_get_drvdata(pdev->dev.parent); | 589 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
593 | struct pm8607_platform_data *pdata = chip->dev->platform_data; | 590 | struct pm860x_platform_data *pdata = chip->dev->platform_data; |
594 | struct pm8607_regulator_info *info = NULL; | 591 | struct pm8607_regulator_info *info = NULL; |
595 | 592 | ||
596 | info = find_regulator_info(pdev->id); | 593 | info = find_regulator_info(pdev->id); |
@@ -599,6 +596,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev) | |||
599 | return -EINVAL; | 596 | return -EINVAL; |
600 | } | 597 | } |
601 | 598 | ||
599 | info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; | ||
602 | info->chip = chip; | 600 | info->chip = chip; |
603 | 601 | ||
604 | info->regulator = regulator_register(&info->desc, &pdev->dev, | 602 | info->regulator = regulator_register(&info->desc, &pdev->dev, |