예제 #1
0
static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
					 unsigned selector)
{
	struct tps62360_chip *tps = rdev_get_drvdata(dev);
	int ret;
	bool found = false;
	int new_vset_id = tps->curr_vset_id;

	/*
	 * If gpios are available to select the VSET register then least
	 * recently used register for new configuration.
	 */
	if (tps->valid_gpios)
		found = find_voltage_set_register(tps, selector, &new_vset_id);

	if (!found) {
		ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
				tps->voltage_reg_mask, selector);
		if (ret < 0) {
			dev_err(tps->dev,
				"%s(): register %d update failed with err %d\n",
				 __func__, REG_VSET0 + new_vset_id, ret);
			return ret;
		}
		tps->curr_vset_id = new_vset_id;
		tps->curr_vset_vsel[new_vset_id] = selector;
	}

	/* Select proper VSET register vio gpios */
	if (tps->valid_gpios) {
		gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
		gpio_set_value_cansleep(tps->vsel1_gpio,
					(new_vset_id >> 1) & 0x1);
	}
예제 #2
0
static int tps62360_dcdc_set_voltage(struct regulator_dev *dev,
                                     int min_uV, int max_uV, unsigned *selector)
{
    struct tps62360_chip *tps = rdev_get_drvdata(dev);
    int vsel;
    int ret;
    bool found = false;
    int new_vset_id = tps->curr_vset_id;

    if (max_uV < min_uV)
        return -EINVAL;

    if (min_uV >
            ((tps->voltage_base + (tps->desc.n_voltages - 1) * 10) * 1000))
        return -EINVAL;

    if (max_uV < tps->voltage_base * 1000)
        return -EINVAL;

    vsel = DIV_ROUND_UP(min_uV - (tps->voltage_base * 1000), 10000);
    if (selector)
        *selector = (vsel & tps->voltage_reg_mask);

    /*
     * If gpios are available to select the VSET register then least
     * recently used register for new configuration.
     */
    if (tps->valid_gpios)
        found = find_voltage_set_register(tps, vsel, &new_vset_id);

    if (!found) {
        ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
                                 tps->voltage_reg_mask, vsel);
        if (ret < 0) {
            dev_err(tps->dev, "%s: Error in updating register %d\n",
                    __func__, REG_VSET0 + new_vset_id);
            return ret;
        }
        tps->curr_vset_id = new_vset_id;
        tps->curr_vset_vsel[new_vset_id] = vsel;
    }

    /* Select proper VSET register vio gpios */
    if (tps->valid_gpios) {
        gpio_set_value_cansleep(tps->vsel0_gpio,
                                new_vset_id & 0x1);
        gpio_set_value_cansleep(tps->vsel1_gpio,
                                (new_vset_id >> 1) & 0x1);
    }
static int max8973_dcdc_set_voltage(struct regulator_dev *rdev,
	     int min_uV, int max_uV, unsigned *selector)
{
	struct max8973_chip *max = rdev_get_drvdata(rdev);
	int vsel;
	int ret;
	bool found = false;
	int vout_reg = max->curr_vout_reg;
	int gpio_val = max->curr_gpio_val;

	if ((max_uV < min_uV) || (max_uV < MAX8973_MIN_VOLATGE) ||
			(min_uV > MAX8973_MAX_VOLATGE))
		return -EINVAL;

	vsel = DIV_ROUND_UP(min_uV - MAX8973_MIN_VOLATGE, MAX8973_VOLATGE_STEP);
	if (selector)
		*selector = (vsel & MAX8973_VOUT_MASK);

	/*
	 * If gpios are available to select the VOUT register then least
	 * recently used register for new configuration.
	 */
	if (max->valid_dvs_gpio)
		found = find_voltage_set_register(max, vsel,
					&vout_reg, &gpio_val);

	if (!found) {
		ret = regmap_update_bits(max->regmap, vout_reg,
						MAX8973_VOUT_MASK, vsel);
		if (ret < 0) {
			dev_err(max->dev,
				"%s(): register %d update failed with err %d\n",
				 __func__, vout_reg, ret);
			return ret;
		}
		max->curr_vout_reg = vout_reg;
		max->curr_vout_val[gpio_val] = vsel;
	}

	/* Select proper VOUT register vio gpios */
	if (max->valid_dvs_gpio) {
		gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
		max->curr_gpio_val = gpio_val;
	}
	return 0;
}
예제 #4
0
static int tps6238x0_set_voltage(struct regulator_dev *dev,
	     int min_uV, int max_uV, unsigned *selector)
{
	struct tps6238x0_chip *tps = rdev_get_drvdata(dev);
	int vsel;
	int ret;
	bool found = false;
	int new_vset_id = tps->curr_vset_id;

	if (min_uV >
		((TPS6238X0_BASE_VOLTAGE + (TPS6238X0_N_VOLTAGES - 1) * 10000)))
		return -EINVAL;

	if ((max_uV < min_uV) || (max_uV < TPS6238X0_BASE_VOLTAGE))
		return -EINVAL;

	vsel = DIV_ROUND_UP(min_uV - TPS6238X0_BASE_VOLTAGE, 10000);
	if (selector)
		*selector = (vsel & TPS6238X0_VOUT_MASK);

	/*
	 * If gpios are available to select the VSET register then least
	 * recently used register for new configuration.
	 */
	if (tps->valid_gpios)
		found = find_voltage_set_register(tps, vsel, &new_vset_id);

	if (!found) {
		ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
				TPS6238X0_VOUT_MASK, vsel);
		if (ret < 0) {
			dev_err(tps->dev, "%s: Error in updating register %d\n",
				 __func__, REG_VSET0 + new_vset_id);
			return ret;
		}
		tps->curr_vset_id = new_vset_id;
		tps->curr_vset_vsel[new_vset_id] = vsel;
	}

	/* Select proper VSET register vio gpios */
	if (tps->valid_gpios)
		gpio_set_value_cansleep(tps->vsel_gpio, new_vset_id & 0x1);
	return 0;
}
static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
	     unsigned vsel)
{
	struct max8973_chip *max = rdev_get_drvdata(rdev);
	int ret;
	bool found = false;
	int vout_reg = max->curr_vout_reg;
	int gpio_val = max->curr_gpio_val;

	/*
	 * If gpios are available to select the VOUT register then least
	 * recently used register for new configuration.
	 */
	if (max->valid_dvs_gpio)
		found = find_voltage_set_register(max, vsel,
					&vout_reg, &gpio_val);

	if (!found) {
		ret = regmap_update_bits(max->regmap, vout_reg,
					MAX8973_VOUT_MASK, vsel);
		if (ret < 0) {
			dev_err(max->dev, "register %d update failed, err %d\n",
				 vout_reg, ret);
			return ret;
		}
		max->curr_vout_reg = vout_reg;
		max->curr_vout_val[gpio_val] = vsel;
	}

	/* Select proper VOUT register vio gpios */
	if (max->valid_dvs_gpio) {
		gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
		max->curr_gpio_val = gpio_val;
	}
	return 0;
}