aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/88pm860x-core.c61
-rw-r--r--drivers/mfd/88pm860x-i2c.c172
2 files changed, 160 insertions, 73 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
70int pm860x_device_init(struct pm8607_chip *chip, 70static 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
75static 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 }
123out: 119out:
124 return ret; 120 return;
121}
122
123int 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
127void pm8607_device_exit(struct pm8607_chip *chip) 148void 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
132MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM8607"); 153MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
133MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); 154MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
134MODULE_LICENSE("GPL"); 155MODULE_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
17static inline int pm8607_read_device(struct pm8607_chip *chip, 17static 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
35static inline int pm8607_write_device(struct pm8607_chip *chip, 34static 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
51int pm8607_reg_read(struct pm8607_chip *chip, int reg) 49int 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}
65EXPORT_SYMBOL(pm8607_reg_read); 64EXPORT_SYMBOL(pm860x_reg_read);
66 65
67int pm8607_reg_write(struct pm8607_chip *chip, int reg, 66int 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}
78EXPORT_SYMBOL(pm8607_reg_write); 78EXPORT_SYMBOL(pm860x_reg_write);
79 79
80int pm8607_bulk_read(struct pm8607_chip *chip, int reg, 80int 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}
91EXPORT_SYMBOL(pm8607_bulk_read); 92EXPORT_SYMBOL(pm860x_bulk_read);
92 93
93int pm8607_bulk_write(struct pm8607_chip *chip, int reg, 94int 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}
104EXPORT_SYMBOL(pm8607_bulk_write); 106EXPORT_SYMBOL(pm860x_bulk_write);
105 107
106int pm8607_set_bits(struct pm8607_chip *chip, int reg, 108int 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);
119out: 122out:
120 mutex_unlock(&chip->io_lock); 123 mutex_unlock(&chip->io_lock);
121 return ret; 124 return ret;
122} 125}
123EXPORT_SYMBOL(pm8607_set_bits); 126EXPORT_SYMBOL(pm860x_set_bits);
124 127
125 128
126static const struct i2c_device_id pm860x_id_table[] = { 129static const struct i2c_device_id pm860x_id_table[] = {
127 { "88PM8607", 0 }, 130 { "88PM860x", 0 },
128 {} 131 {}
129}; 132};
130MODULE_DEVICE_TABLE(i2c, pm860x_id_table); 133MODULE_DEVICE_TABLE(i2c, pm860x_id_table);
131 134
135static 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
132static int __devinit pm860x_probe(struct i2c_client *client, 156static 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
160out:
161 i2c_set_clientdata(client, NULL);
162 kfree(chip);
163 return ret;
164} 220}
165 221
166static int __devexit pm860x_remove(struct i2c_client *client) 222static 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}