static int __devinit tps51632_probe(struct i2c_client *client,
				const struct i2c_device_id *id)
{
	struct tps51632_regulator_platform_data *pdata;
	struct regulator_dev *rdev;
	struct tps51632_chip *tps;
	int ret;

	pdata = client->dev.platform_data;
	if (!pdata) {
		dev_err(&client->dev, "No Platform data\n");
		return -EINVAL;
	}

	tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
	if (!tps) {
		dev_err(&client->dev, "Memory allocation failed\n");
		return -ENOMEM;
	}

	tps->dev = &client->dev;
	tps->desc.name = id->name;
	tps->desc.id = 0;
	tps->desc.ops = &tps51632_dcdc_ops;
	tps->desc.type = REGULATOR_VOLTAGE;
	tps->desc.owner = THIS_MODULE;
	tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config);
	if (IS_ERR(tps->regmap)) {
		ret = PTR_ERR(tps->regmap);
		dev_err(&client->dev, "regmap init failed, err %d\n", ret);
		return ret;
	}
	i2c_set_clientdata(client, tps);

	ret = tps51632_init_dcdc(tps, pdata);
	if (ret < 0) {
		dev_err(tps->dev, "Init failed, err = %d\n", ret);
		return ret;
	}

	/* Register the regulators */
	rdev = regulator_register(&tps->desc, &client->dev,
			pdata->reg_init_data, tps, NULL);
	if (IS_ERR(rdev)) {
		dev_err(tps->dev, "regulator register failed\n");
		return PTR_ERR(rdev);
	}

	tps->rdev = rdev;
	return 0;
}
예제 #2
0
static int tps51632_probe(struct i2c_client *client,
                          const struct i2c_device_id *id)
{
    struct tps51632_regulator_platform_data *pdata;
    struct regulator_dev *rdev;
    struct tps51632_chip *tps;
    int ret;
    struct regulator_config config = { };

    if (client->dev.of_node) {
        const struct of_device_id *match;
        match = of_match_device(of_match_ptr(tps51632_of_match),
                                &client->dev);
        if (!match) {
            dev_err(&client->dev, "Error: No device match found\n");
            return -ENODEV;
        }
    }

    pdata = client->dev.platform_data;
    if (!pdata && client->dev.of_node)
        pdata = of_get_tps51632_platform_data(&client->dev);
    if (!pdata) {
        dev_err(&client->dev, "No Platform data\n");
        return -EINVAL;
    }

    if (pdata->enable_pwm_dvfs) {
        if ((pdata->base_voltage_uV < TPS51632_MIN_VOLATGE) ||
                (pdata->base_voltage_uV > TPS51632_MAX_VOLATGE)) {
            dev_err(&client->dev, "Invalid base_voltage_uV setting\n");
            return -EINVAL;
        }

        if ((pdata->max_voltage_uV) &&
                ((pdata->max_voltage_uV < TPS51632_MIN_VOLATGE) ||
                 (pdata->max_voltage_uV > TPS51632_MAX_VOLATGE))) {
            dev_err(&client->dev, "Invalid max_voltage_uV setting\n");
            return -EINVAL;
        }
    }

    tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
    if (!tps) {
        dev_err(&client->dev, "Memory allocation failed\n");
        return -ENOMEM;
    }

    tps->dev = &client->dev;
    tps->desc.name = id->name;
    tps->desc.id = 0;
    tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY;
    tps->desc.min_uV = TPS51632_MIN_VOLATGE;
    tps->desc.uV_step = TPS51632_VOLATGE_STEP_10mV;
    tps->desc.linear_min_sel = TPS51632_MIN_VSEL;
    tps->desc.n_voltages = TPS51632_MAX_VSEL + 1;
    tps->desc.ops = &tps51632_dcdc_ops;
    tps->desc.type = REGULATOR_VOLTAGE;
    tps->desc.owner = THIS_MODULE;

    if (pdata->enable_pwm_dvfs)
        tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG;
    else
        tps->desc.vsel_reg = TPS51632_VOLTAGE_SELECT_REG;
    tps->desc.vsel_mask = TPS51632_VOUT_MASK;

    tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config);
    if (IS_ERR(tps->regmap)) {
        ret = PTR_ERR(tps->regmap);
        dev_err(&client->dev, "regmap init failed, err %d\n", ret);
        return ret;
    }
    i2c_set_clientdata(client, tps);

    ret = tps51632_init_dcdc(tps, pdata);
    if (ret < 0) {
        dev_err(tps->dev, "Init failed, err = %d\n", ret);
        return ret;
    }

    /* Register the regulators */
    config.dev = &client->dev;
    config.init_data = pdata->reg_init_data;
    config.driver_data = tps;
    config.regmap = tps->regmap;
    config.of_node = client->dev.of_node;
    if (pdata->ena_gpio) {
        config.ena_gpio = pdata->ena_gpio;
        config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
    } else {
        config.ena_gpio = -EINVAL;
        config.ena_gpio_flags = 0;
    }
    rdev = regulator_register(&tps->desc, &config);
    if (IS_ERR(rdev)) {
        dev_err(tps->dev, "regulator register failed\n");
        return PTR_ERR(rdev);
    }

    tps->rdev = rdev;
    return 0;
}