Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 186909
b: refs/heads/master
c: e8343dd
h: refs/heads/master
i:
  186907: bc47122
v: v3
  • Loading branch information
Haojian Zhuang authored and Samuel Ortiz committed Mar 7, 2010
1 parent 906c316 commit ca5be59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 53 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 34c9120805ff4b3f7a8053bd64157ba564774433
refs/heads/master: e8343ddaccb322b1a2a989ac362cabd1e94597ad
72 changes: 20 additions & 52 deletions trunk/drivers/mfd/88pm860x-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,78 +157,46 @@ static int __devinit pm860x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct pm860x_platform_data *pdata = client->dev.platform_data;
static struct pm860x_chip *chip;
struct i2c_board_info i2c_info = {
.type = "88PM860x",
.platform_data = client->dev.platform_data,
};
int addr_c, found_companion = 0;

if (pdata == NULL) {
struct pm860x_chip *chip;

if (!pdata) {
pr_info("No platform data in %s!\n", __func__);
return -EINVAL;
}

chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;

chip->id = verify_addr(client);
chip->client = client;
i2c_set_clientdata(client, chip);
chip->dev = &client->dev;
mutex_init(&chip->io_lock);
dev_set_drvdata(chip->dev, chip);

/*
* Both client and companion client shares same platform driver.
* Driver distinguishes them by pdata->companion_addr.
* pdata->companion_addr is only assigned if companion chip exists.
* At the same time, the companion_addr shouldn't equal to client
* address.
*/
addr_c = pdata->companion_addr;
if (addr_c && (addr_c != client->addr)) {
i2c_info.addr = addr_c;
found_companion = 1;
}

if (found_companion || (addr_c == 0)) {
chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;

chip->id = verify_addr(client);
chip->companion_addr = addr_c;
chip->client = client;
i2c_set_clientdata(client, chip);
chip->dev = &client->dev;
mutex_init(&chip->io_lock);
dev_set_drvdata(chip->dev, chip);

if (found_companion) {
/*
* If this driver is built in, probe function is
* recursive.
* If this driver is built as module, the next probe
* function is called after the first one finished.
*/
chip->companion = i2c_new_device(client->adapter,
&i2c_info);
}
}

/*
* If companion chip existes, it's called by companion probe.
* If there's no companion chip, it's called by client probe.
*/
if ((addr_c == 0) || (addr_c == client->addr)) {
chip->companion = client;
if (pdata->companion_addr && (pdata->companion_addr != client->addr)) {
chip->companion_addr = pdata->companion_addr;
chip->companion = i2c_new_dummy(chip->client->adapter,
chip->companion_addr);
i2c_set_clientdata(chip->companion, chip);
pm860x_device_init(chip, pdata);
}

pm860x_device_init(chip, pdata);
return 0;
}

static int __devexit pm860x_remove(struct i2c_client *client)
{
struct pm860x_chip *chip = i2c_get_clientdata(client);

/*
* If companion existes, companion client is removed first.
* Because companion client is registered last and removed first.
*/
if (chip->companion_addr == client->addr)
return 0;
pm860x_device_exit(chip);
i2c_unregister_device(chip->companion);
i2c_set_clientdata(chip->companion, NULL);
Expand Down

0 comments on commit ca5be59

Please sign in to comment.