aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/88pm860x-i2c.c
diff options
context:
space:
mode:
authorHaojian Zhuang <haojian.zhuang@marvell.com>2010-02-03 15:38:12 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2010-03-07 16:17:18 -0500
commite8343ddaccb322b1a2a989ac362cabd1e94597ad (patch)
treefde51c79821ce433eaadb1a0a28bdb9d07a838bc /drivers/mfd/88pm860x-i2c.c
parent34c9120805ff4b3f7a8053bd64157ba564774433 (diff)
mfd: Use i2c_dummy in 88pm860x
Use i2c_dummy in 88pm860x driver to avoid using static in probe function. Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.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.c72
1 files changed, 20 insertions, 52 deletions
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c
index 6d7dba2bce8a..c37e12bf3004 100644
--- a/drivers/mfd/88pm860x-i2c.c
+++ b/drivers/mfd/88pm860x-i2c.c
@@ -157,18 +157,24 @@ static int __devinit pm860x_probe(struct i2c_client *client,
157 const struct i2c_device_id *id) 157 const struct i2c_device_id *id)
158{ 158{
159 struct pm860x_platform_data *pdata = client->dev.platform_data; 159 struct pm860x_platform_data *pdata = client->dev.platform_data;
160 static struct pm860x_chip *chip; 160 struct pm860x_chip *chip;
161 struct i2c_board_info i2c_info = { 161
162 .type = "88PM860x", 162 if (!pdata) {
163 .platform_data = client->dev.platform_data,
164 };
165 int addr_c, found_companion = 0;
166
167 if (pdata == NULL) {
168 pr_info("No platform data in %s!\n", __func__); 163 pr_info("No platform data in %s!\n", __func__);
169 return -EINVAL; 164 return -EINVAL;
170 } 165 }
171 166
167 chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
168 if (chip == NULL)
169 return -ENOMEM;
170
171 chip->id = verify_addr(client);
172 chip->client = client;
173 i2c_set_clientdata(client, chip);
174 chip->dev = &client->dev;
175 mutex_init(&chip->io_lock);
176 dev_set_drvdata(chip->dev, chip);
177
172 /* 178 /*
173 * Both client and companion client shares same platform driver. 179 * Both client and companion client shares same platform driver.
174 * Driver distinguishes them by pdata->companion_addr. 180 * Driver distinguishes them by pdata->companion_addr.
@@ -176,46 +182,14 @@ static int __devinit pm860x_probe(struct i2c_client *client,
176 * At the same time, the companion_addr shouldn't equal to client 182 * At the same time, the companion_addr shouldn't equal to client
177 * address. 183 * address.
178 */ 184 */
179 addr_c = pdata->companion_addr; 185 if (pdata->companion_addr && (pdata->companion_addr != client->addr)) {
180 if (addr_c && (addr_c != client->addr)) { 186 chip->companion_addr = pdata->companion_addr;
181 i2c_info.addr = addr_c; 187 chip->companion = i2c_new_dummy(chip->client->adapter,
182 found_companion = 1; 188 chip->companion_addr);
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); 189 i2c_set_clientdata(chip->companion, chip);
217 pm860x_device_init(chip, pdata);
218 } 190 }
191
192 pm860x_device_init(chip, pdata);
219 return 0; 193 return 0;
220} 194}
221 195
@@ -223,12 +197,6 @@ static int __devexit pm860x_remove(struct i2c_client *client)
223{ 197{
224 struct pm860x_chip *chip = i2c_get_clientdata(client); 198 struct pm860x_chip *chip = i2c_get_clientdata(client);
225 199
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); 200 pm860x_device_exit(chip);
233 i2c_unregister_device(chip->companion); 201 i2c_unregister_device(chip->companion);
234 i2c_set_clientdata(chip->companion, NULL); 202 i2c_set_clientdata(chip->companion, NULL);