Beispiel #1
0
static int __devinit mcu_probe(struct i2c_client *client,
			       const struct i2c_device_id *id)
{
	struct mcu *mcu;
	int ret;

	mcu = kzalloc(sizeof(*mcu), GFP_KERNEL);
	if (!mcu)
		return -ENOMEM;

	mutex_init(&mcu->lock);
	mcu->client = client;
	i2c_set_clientdata(client, mcu);

	ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
	if (ret < 0)
		goto err;
	mcu->reg_ctrl = ret;

	ret = mcu_gpiochip_add(mcu);
	if (ret)
		goto err;

	/* XXX: this is potentially racy, but there is no lock for ppc_md */
	if (!ppc_md.power_off) {
		glob_mcu = mcu;
		ppc_md.power_off = mcu_power_off;
		dev_info(&client->dev, "will provide power-off service\n");
	}

	return 0;
err:
	kfree(mcu);
	return ret;
}
static int __devinit mcu_probe(struct i2c_client *client,
                               const struct i2c_device_id *id)
{
    struct mcu *mcu;
    int ret;

    mcu = kzalloc(sizeof(*mcu), GFP_KERNEL);
    if (!mcu)
        return -ENOMEM;

    mutex_init(&mcu->lock);
    mcu->client = client;
    i2c_set_clientdata(client, mcu);

    ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
    if (ret < 0)
        goto err;
    mcu->reg_ctrl = ret;

    ret = mcu_gpiochip_add(mcu);
    if (ret)
        goto err;

    /* XXX: this is potentially racy, but there is no lock for ppc_md */
    if (!ppc_md.power_off) {
        glob_mcu = mcu;
        ppc_md.power_off = mcu_power_off;
        dev_info(&client->dev, "will provide power-off service\n");
    }

    if (device_create_file(&client->dev, &dev_attr_status))
        dev_err(&client->dev,
                "couldn't create device file for status\n");

    shutdown_thread = kthread_run(shutdown_thread_fn, NULL,
                                  "mcu-i2c-shdn");

    return 0;
err:
    kfree(mcu);
    return ret;
}