static int aw2013_probe()

in leds-aw2013.c [327:402]


static int aw2013_probe(struct i2c_client *client)
{
	struct aw2013 *chip;
	int ret;
	unsigned int chipid;

	chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
		return -ENOMEM;

	mutex_init(&chip->mutex);
	mutex_lock(&chip->mutex);

	chip->client = client;
	i2c_set_clientdata(client, chip);

	chip->regmap = devm_regmap_init_i2c(client, &aw2013_regmap_config);
	if (IS_ERR(chip->regmap)) {
		ret = PTR_ERR(chip->regmap);
		dev_err(&client->dev, "Failed to allocate register map: %d\n",
			ret);
		goto error;
	}

	chip->vcc_regulator = devm_regulator_get(&client->dev, "vcc");
	ret = PTR_ERR_OR_ZERO(chip->vcc_regulator);
	if (ret) {
		if (ret != -EPROBE_DEFER)
			dev_err(&client->dev,
				"Failed to request regulator: %d\n", ret);
		goto error;
	}

	ret = regulator_enable(chip->vcc_regulator);
	if (ret) {
		dev_err(&client->dev,
			"Failed to enable regulator: %d\n", ret);
		goto error;
	}

	ret = regmap_read(chip->regmap, AW2013_RSTR, &chipid);
	if (ret) {
		dev_err(&client->dev, "Failed to read chip ID: %d\n",
			ret);
		goto error_reg;
	}

	if (chipid != AW2013_RSTR_CHIP_ID) {
		dev_err(&client->dev, "Chip reported wrong ID: %x\n",
			chipid);
		ret = -ENODEV;
		goto error_reg;
	}

	ret = aw2013_probe_dt(chip);
	if (ret < 0)
		goto error_reg;

	ret = regulator_disable(chip->vcc_regulator);
	if (ret) {
		dev_err(&client->dev,
			"Failed to disable regulator: %d\n", ret);
		goto error;
	}

	mutex_unlock(&chip->mutex);

	return 0;

error_reg:
	regulator_disable(chip->vcc_regulator);

error:
	mutex_destroy(&chip->mutex);
	return ret;
}