static int tps65217_pmic_dcdc_set_voltage(struct regulator_dev *dev,
				  int min_uV, int max_uV, unsigned *selector)
{
	int ret;
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int dcdc = rdev_get_id(dev);

	if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
		return -EINVAL;

	if (min_uV < tps->info[dcdc]->min_uV
		|| min_uV > tps->info[dcdc]->max_uV)
		return -EINVAL;

	if (max_uV < tps->info[dcdc]->min_uV
		|| max_uV > tps->info[dcdc]->max_uV)
		return -EINVAL;

	ret = tps->info[dcdc]->uv_to_vsel(min_uV, selector);
	if (ret)
		return ret;

	/* Set the voltage based on vsel value and write protect level is 2 */
	ret = tps65217_set_bits(tps, tps->info[dcdc]->set_vout_reg,
					tps->info[dcdc]->set_vout_mask,
					*selector, TPS65217_PROTECT_L2);
	if (ret)
		return ret;

	/* Set GO bit to initiate voltage transistion */
	return tps65217_set_bits(tps, TPS65217_REG_DEFSLEW,
				TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO,
				TPS65217_PROTECT_L2);
}
static int tps65217_pmic_ldo_set_voltage(struct regulator_dev *dev,
				  int min_uV, int max_uV, unsigned *selector)
{
	int ret;
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int ldo = rdev_get_id(dev);

	if (ldo < TPS65217_LDO_2 || ldo > TPS65217_LDO_4)
		return -EINVAL;

	if (min_uV < tps->info[ldo]->min_uV
		|| min_uV > tps->info[ldo]->max_uV)
		return -EINVAL;

	if (max_uV < tps->info[ldo]->min_uV
		|| max_uV > tps->info[ldo]->max_uV)
		return -EINVAL;

	ret = tps->info[ldo]->uv_to_vsel(min_uV, selector);
	if (ret)
		return ret;

	/* Set the voltage based on vsel value and write protect level is 2 */
	return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg,
					tps->info[ldo]->set_vout_mask,
					*selector, TPS65217_PROTECT_L2);
}
static int tps65217_pmic_set_voltage(struct regulator_dev *dev,
				  int min_uV, int max_uV, unsigned *selector)
{
	int ret;
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int rid = rdev_get_id(dev);

	
	if (rid == TPS65217_LDO_1)
		return -EINVAL;

	if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
		return -EINVAL;

	if (min_uV < tps->info[rid]->min_uV
		|| min_uV > tps->info[rid]->max_uV)
		return -EINVAL;

	if (max_uV < tps->info[rid]->min_uV
		|| max_uV > tps->info[rid]->max_uV)
		return -EINVAL;

	ret = tps->info[rid]->uv_to_vsel(min_uV, selector);
	if (ret)
		return ret;

	
	ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg,
				tps->info[rid]->set_vout_mask,
				*selector, TPS65217_PROTECT_L2);

	
	switch (rid) {
	case TPS65217_DCDC_1 ... TPS65217_DCDC_3:
		ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW,
				       TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO,
				       TPS65217_PROTECT_L2);
		break;
	}

	return ret;
}
static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
					 unsigned selector)
{
	int ret;
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int rid = rdev_get_id(dev);

	/* Set the voltage based on vsel value and write protect level is 2 */
	ret = tps65217_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask,
				selector, TPS65217_PROTECT_L2);

	/* Set GO bit for DCDCx to initiate voltage transistion */
	switch (rid) {
	case TPS65217_DCDC_1 ... TPS65217_DCDC_3:
		ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW,
				       TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO,
				       TPS65217_PROTECT_L2);
		break;
	}

	return ret;
}
static int tps65217_pmic_enable(struct regulator_dev *dev)
{
	struct tps65217 *tps = rdev_get_drvdata(dev);
	int rid = rdev_get_id(dev);

	if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
		return -EINVAL;

	/* Enable the regulator and password protection is level 1 */
	return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
				 dev->desc->enable_mask, dev->desc->enable_mask,
				 TPS65217_PROTECT_L1);
}
static int tps65217_pmic_enable(struct regulator_dev *dev)
{
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int rid = rdev_get_id(dev);

	if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
		return -EINVAL;

	
	return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
				tps->info[rid]->enable_mask,
				tps->info[rid]->enable_mask,
				TPS65217_PROTECT_L1);
}
static int tps65217_pmic_ldo_enable(struct regulator_dev *dev)
{
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int ldo = rdev_get_id(dev);

	if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4)
		return -EINVAL;

	/* Enable the regulator and password protection is level 1 */
	return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
				tps->info[ldo]->enable_mask,
				tps->info[ldo]->enable_mask,
				TPS65217_PROTECT_L1);
}
static int tps65217_pmic_dcdc_enable(struct regulator_dev *dev)
{
	struct tps65217 *tps = rdev_get_drvdata(dev);
	unsigned int dcdc = rdev_get_id(dev);

	if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
		return -EINVAL;

	/* Enable the regulator and password protection is level 1 */
	return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
				tps->info[dcdc]->enable_mask,
				tps->info[dcdc]->enable_mask,
				TPS65217_PROTECT_L1);
}
static int tps65217_pmic_ldo1_set_voltage_sel(struct regulator_dev *dev,
						unsigned selector)
{
	struct tps65217 *tps = rdev_get_drvdata(dev);
	int ldo = rdev_get_id(dev);

	if (ldo != TPS65217_LDO_1)
		return -EINVAL;

	if (selector >= tps->info[ldo]->table_len)
		return -EINVAL;

	
	return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg,
					tps->info[ldo]->set_vout_mask,
					selector, TPS65217_PROTECT_L2);
}
Ejemplo n.º 10
0
static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev,
						unsigned selector)
{
	struct tps65217 *tps = rdev_get_drvdata(dev);
	int ldo = rdev_get_id(dev);

	if (ldo != TPS65217_LDO_1)
		return -EINVAL;

	if (selector >= tps->info[ldo]->table_len)
		return -EINVAL;

	/* Set the voltage based on vsel value and write protect level is 2 */
	return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg,
					tps->info[ldo]->set_vout_mask,
					selector, TPS65217_PROTECT_L2);
}
Ejemplo n.º 11
0
static int tps65217_bl_enable(struct tps65217_bl *tps65217_bl)
{
	int rc;

	rc = tps65217_set_bits(tps65217_bl->tps, TPS65217_REG_WLEDCTRL1,
			TPS65217_WLEDCTRL1_ISINK_ENABLE,
			TPS65217_WLEDCTRL1_ISINK_ENABLE, TPS65217_PROTECT_NONE);
	if (rc) {
		dev_err(tps65217_bl->dev,
			"failed to enable backlight: %d\n", rc);
		return rc;
	}

	tps65217_bl->on = 1;

	dev_dbg(tps65217_bl->dev, "backlight enabled\n");

	return 0;
}
Ejemplo n.º 12
0
static int tps65217_enable_charging(struct tps65217_charger *charger)
{
	int ret;

	/* charger already enabled */
	if (charger->ac_online)
		return 0;

	dev_dbg(charger->dev, "%s: enable charging\n", __func__);
	ret = tps65217_set_bits(charger->tps, TPS65217_REG_CHGCONFIG1,
				TPS65217_CHGCONFIG1_CHG_EN,
				TPS65217_CHGCONFIG1_CHG_EN,
				TPS65217_PROTECT_NONE);
	if (ret) {
		dev_err(charger->dev,
			"%s: Error in writing CHG_EN in reg 0x%x: %d\n",
			__func__, TPS65217_REG_CHGCONFIG1, ret);
		return ret;
	}

	charger->ac_online = 1;

	return 0;
}
Ejemplo n.º 13
0
static int tps65217_bl_hw_init(struct tps65217_bl *tps65217_bl,
			struct tps65217_bl_pdata *pdata)
{
	int rc;

	rc = tps65217_bl_disable(tps65217_bl);
	if (rc)
		return rc;

	switch (pdata->isel) {
	case TPS65217_BL_ISET1:
		/* select ISET_1 current level */
		rc = tps65217_clear_bits(tps65217_bl->tps,
					TPS65217_REG_WLEDCTRL1,
					TPS65217_WLEDCTRL1_ISEL,
					TPS65217_PROTECT_NONE);
		if (rc) {
			dev_err(tps65217_bl->dev,
				"failed to select ISET1 current level: %d)\n",
				rc);
			return rc;
		}

		dev_dbg(tps65217_bl->dev, "selected ISET1 current level\n");

		break;

	case TPS65217_BL_ISET2:
		/* select ISET2 current level */
		rc = tps65217_set_bits(tps65217_bl->tps, TPS65217_REG_WLEDCTRL1,
				TPS65217_WLEDCTRL1_ISEL,
				TPS65217_WLEDCTRL1_ISEL, TPS65217_PROTECT_NONE);
		if (rc) {
			dev_err(tps65217_bl->dev,
				"failed to select ISET2 current level: %d\n",
				rc);
			return rc;
		}

		dev_dbg(tps65217_bl->dev, "selected ISET2 current level\n");

		break;

	default:
		dev_err(tps65217_bl->dev,
			"invalid value for current level: %d\n", pdata->isel);
		return -EINVAL;
	}

	/* set PWM frequency */
	rc = tps65217_set_bits(tps65217_bl->tps,
			TPS65217_REG_WLEDCTRL1,
			TPS65217_WLEDCTRL1_FDIM_MASK,
			pdata->fdim,
			TPS65217_PROTECT_NONE);
	if (rc) {
		dev_err(tps65217_bl->dev,
			"failed to select PWM dimming frequency: %d\n",
			rc);
		return rc;
	}

	return 0;
}
Ejemplo n.º 14
0
static int tps65217_probe(struct i2c_client *client,
				const struct i2c_device_id *ids)
{
	struct tps65217 *tps;
	unsigned int version;
	unsigned long chip_id = ids->driver_data;
	const struct of_device_id *match;
	bool status_off = false;
	int ret;

	if (client->dev.of_node) {
		match = of_match_device(tps65217_of_match, &client->dev);
		if (!match) {
			dev_err(&client->dev,
				"Failed to find matching dt id\n");
			return -EINVAL;
		}
		chip_id = (unsigned long)match->data;
		status_off = of_property_read_bool(client->dev.of_node,
					"ti,pmic-shutdown-controller");
	}

	if (!chip_id) {
		dev_err(&client->dev, "id is null.\n");
		return -ENODEV;
	}

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

	i2c_set_clientdata(client, tps);
	tps->dev = &client->dev;
	tps->id = chip_id;

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

	ret = mfd_add_devices(tps->dev, -1, tps65217s,
			      ARRAY_SIZE(tps65217s), NULL, 0, NULL);
	if (ret < 0) {
		dev_err(tps->dev, "mfd_add_devices failed: %d\n", ret);
		return ret;
	}

	ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, &version);
	if (ret < 0) {
		dev_err(tps->dev, "Failed to read revision register: %d\n",
			ret);
		return ret;
	}

	/* Set the PMIC to shutdown on PWR_EN toggle */
	if (status_off) {
		ret = tps65217_set_bits(tps, TPS65217_REG_STATUS,
				TPS65217_STATUS_OFF, TPS65217_STATUS_OFF,
				TPS65217_PROTECT_NONE);
		if (ret)
			dev_warn(tps->dev, "unable to set the status OFF\n");
	}

	dev_info(tps->dev, "TPS65217 ID %#x version 1.%d\n",
			(version & TPS65217_CHIPID_CHIP_MASK) >> 4,
			version & TPS65217_CHIPID_REV_MASK);

	return 0;
}
Ejemplo n.º 15
0
static int __devinit tps65217_probe(struct i2c_client *client,
				const struct i2c_device_id *ids)
{
	struct tps65217 *tps;
	struct tps65217_board *pdata = client->dev.platform_data;
	int i, ret;
	unsigned int version;

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

	tps->pdata = pdata;
	tps->regmap = regmap_init_i2c(client, &tps65217_regmap_config);
	if (IS_ERR(tps->regmap)) {
		ret = PTR_ERR(tps->regmap);
		dev_err(tps->dev, "Failed to allocate register map: %d\n",
			ret);
		return ret;
	}

	i2c_set_clientdata(client, tps);
	tps->dev = &client->dev;

	ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, &version);
	if (ret < 0) {
		dev_err(tps->dev, "Failed to read revision"
					" register: %d\n", ret);
		goto err_regmap;
	}

	/* Set the PMIC to shutdown on PWR_EN toggle */
	if (pdata->status_off) {
		ret = tps65217_set_bits(tps, TPS65217_REG_STATUS,
				TPS65217_STATUS_OFF, TPS65217_STATUS_OFF,
				TPS65217_PROTECT_NONE);
		if (ret) {
			dev_err(tps->dev, "Failed to set the status OFF\n");
			goto err_regmap;
		}
	}

	dev_info(tps->dev, "TPS65217 ID %#x version 1.%d\n",
			(version & TPS65217_CHIPID_CHIP_MASK) >> 4,
			version & TPS65217_CHIPID_REV_MASK);

	for (i = 0; i < TPS65217_NUM_REGULATOR; i++) {
		struct platform_device *pdev;

		pdev = platform_device_alloc("tps65217-pmic", i);
		if (!pdev) {
			dev_err(tps->dev, "Cannot create regulator %d\n", i);
			continue;
		}

		pdev->dev.parent = tps->dev;
		platform_device_add_data(pdev, &pdata->tps65217_init_data[i],
					sizeof(pdata->tps65217_init_data[i]));
		tps->regulator_pdev[i] = pdev;

		platform_device_add(pdev);
	}

	return 0;

err_regmap:
	regmap_exit(tps->regmap);

	return ret;
}