static int __devinit pm860x_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pm860x_platform_data *pdata = client->dev.platform_data; struct pm860x_chip *chip; int ret; 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->regmap = regmap_init_i2c(client, &pm860x_regmap_config); if (IS_ERR(chip->regmap)) { ret = PTR_ERR(chip->regmap); dev_err(&client->dev, "Failed to allocate register map: %d\n", ret); kfree(chip); return ret; } chip->client = client; i2c_set_clientdata(client, chip); chip->dev = &client->dev; 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. */ 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); chip->regmap_companion = regmap_init_i2c(chip->companion, &pm860x_regmap_config); if (IS_ERR(chip->regmap_companion)) { ret = PTR_ERR(chip->regmap_companion); dev_err(&chip->companion->dev, "Failed to allocate register map: %d\n", ret); return ret; } i2c_set_clientdata(chip->companion, chip); } pm860x_device_init(chip, pdata); return 0; }
static int __devinit pm860x_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pm860x_platform_data *pdata = client->dev.platform_data; 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. */ 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); return 0; }