Example #1
0
static int pm800_probe(struct i2c_client *client,
                       const struct i2c_device_id *id)
{
    int ret = 0;
    struct pm80x_chip *chip;
    struct pm80x_platform_data *pdata = dev_get_platdata(&client->dev);
    struct pm80x_subchip *subchip;

    ret = pm80x_init(client);
    if (ret) {
        dev_err(&client->dev, "pm800_init fail\n");
        goto out_init;
    }

    chip = i2c_get_clientdata(client);

    /* init subchip for PM800 */
    subchip =
        devm_kzalloc(&client->dev, sizeof(struct pm80x_subchip),
                     GFP_KERNEL);
    if (!subchip) {
        ret = -ENOMEM;
        goto err_subchip_alloc;
    }

    /* pm800 has 2 addtional pages to support power and gpadc. */
    subchip->power_page_addr = client->addr + 1;
    subchip->gpadc_page_addr = client->addr + 2;
    chip->subchip = subchip;

    ret = pm800_pages_init(chip);
    if (ret) {
        dev_err(&client->dev, "pm800_pages_init failed!\n");
        goto err_page_init;
    }

    ret = device_800_init(chip, pdata);
    if (ret) {
        dev_err(chip->dev, "Failed to initialize 88pm800 devices\n");
        goto err_device_init;
    }

    if (pdata && pdata->plat_config)
        pdata->plat_config(chip, pdata);

    return 0;

err_device_init:
    pm800_pages_exit(chip);
err_page_init:
err_subchip_alloc:
    pm80x_deinit();
out_init:
    return ret;
}
Example #2
0
static int __devinit pm800_probe(struct i2c_client *client,
				 const struct i2c_device_id *id)
{
	int ret = 0;
	struct pm80x_chip *chip;
	struct pm80x_platform_data *pdata = client->dev.platform_data;
	struct pm80x_subchip *subchip;

	ret = pm80x_init(client, id);
	if (ret) {
		dev_err(&client->dev, "pm800_init fail\n");
		goto out_init;
	}

	chip = i2c_get_clientdata(client);

	/* init subchip for PM800 */
	subchip =
	    devm_kzalloc(&client->dev, sizeof(struct pm80x_subchip),
			 GFP_KERNEL);
	if (!subchip) {
		ret = -ENOMEM;
		goto err_subchip_alloc;
	}

	subchip->power_page_addr = pdata->power_page_addr;
	subchip->gpadc_page_addr = pdata->gpadc_page_addr;
	chip->subchip = subchip;

	ret = device_800_init(chip, pdata);
	if (ret) {
		dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id);
		goto err_800_init;
	}

	ret = pm800_pages_init(chip);
	if (ret) {
		dev_err(&client->dev, "pm800_pages_init failed!\n");
		goto err_page_init;
	}

	if (pdata->plat_config)
		pdata->plat_config(chip, pdata);

err_page_init:
	mfd_remove_devices(chip->dev);
	device_irq_exit_800(chip);
err_800_init:
	devm_kfree(&client->dev, subchip);
err_subchip_alloc:
	pm80x_deinit(client);
out_init:
	return ret;
}