static int __tps6586x_ldo_set_voltage(struct device *parent,
				      struct tps6586x_regulator *ri,
				      int min_uV, int max_uV)
{
	int val, uV;
	uint8_t mask;

	for (val = 0; val < ri->desc.n_voltages; val++) {
		uV = ri->voltages[val] * 1000;

		/* LDO0 has minimal voltage 1.2 rather than 1.25 */
		if (ri->desc.id == TPS6586X_ID_LDO_0 && val == 0)
			uV -= 50 * 1000;

		/* use the first in-range value */
		if (min_uV <= uV && uV <= max_uV) {

			val <<= ri->volt_shift;
			mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;

			return tps6586x_update(parent, ri->volt_reg, val, mask);
		}
	}

	return -EINVAL;
}
Esempio n. 2
0
static int __tps6586x_ldo_set_voltage(struct device *parent,
				      struct tps6586x_regulator *ri,
				      int min_uV, int max_uV,
				      unsigned *selector)
{
	int val, uV;
	uint8_t mask;

	for (val = 0; val < ri->desc.n_voltages; val++) {
		uV = ri->voltages[val] * 1000;

		/* use the first in-range value */
		if (min_uV <= uV && uV <= max_uV) {

			*selector = val;

			val <<= ri->volt_shift;
			mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;

			return tps6586x_update(parent, ri->volt_reg, val, mask);
		}
	}

	return -EINVAL;
}
static void tps6586x_gpio_set(struct gpio_chip *chip, unsigned offset,
			      int value)
{
	struct tps6586x *tps6586x = container_of(chip, struct tps6586x, gpio);

	tps6586x_update(tps6586x->dev, TPS6586X_GPIOSET2,
			value << offset, 1 << offset);
}
Esempio n. 4
0
static void tps6586x_gpio_set(struct gpio_chip *gc, unsigned offset,
			      int value)
{
	struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc);

	tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET2,
			value << offset, 1 << offset);
}
static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset,
				int value)
{
	struct tps6586x *tps6586x = container_of(gc, struct tps6586x, gpio);
	uint8_t val, mask;
	int ret;

	val = value << offset;
	mask = 0x1 << offset;
	ret = tps6586x_update(tps6586x->dev, TPS6586X_GPIOSET2, val, mask);
	if (ret)
		return ret;

	val = 0x1 << (offset * 2);
	mask = 0x3 << (offset * 2);

	return tps6586x_update(tps6586x->dev, TPS6586X_GPIOSET1, val, mask);
}
Esempio n. 6
0
static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset,
				int value)
{
	struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc);
	uint8_t val, mask;

	tps6586x_gpio_set(gc, offset, value);

	val = 0x1 << (offset * 2);
	mask = 0x3 << (offset * 2);

	return tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET1,
				val, mask);
}
/*
 * TPS6586X has 2 enable bits that are OR'ed to determine the actual
 * regulator state. Clearing one of this bits allows switching
 * regulator on and of with single register write.
 */
static inline int tps6586x_regulator_preinit(struct device *parent,
					     struct tps6586x_regulator *ri)
{
	uint8_t val1, val2;
	int ret;

	/* To prevent voltage negative overshoot, set slew rate to 3.52mV/us
	 * from 7.04mV/us. Because voltage negative overshoot was occured
	 * on some devices. */
	if (ri->desc.id == TPS6586X_ID_SM_1) {
		ret = tps6586x_update(parent, TPS6586X_SM1SL,
				      TPS6586X_SMSL_1_76, TPS6586X_SMSL_MASK);
		if (ret)
			return ret;
	}

	if (ri->enable_reg[0] == ri->enable_reg[1] &&
	    ri->enable_bit[0] == ri->enable_bit[1])
			return 0;

	ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
	if (ret)
		return ret;

	ret = tps6586x_read(parent, ri->enable_reg[1], &val2);
	if (ret)
		return ret;

	if (!(val2 & (1 << ri->enable_bit[1])))
		return 0;

	/*
	 * The regulator is on, but it's enabled with the bit we don't
	 * want to use, so we switch the enable bits
	 */
	if (!(val1 & (1 << ri->enable_bit[0]))) {
		ret = tps6586x_set_bits(parent, ri->enable_reg[0],
					1 << ri->enable_bit[0]);
		if (ret)
			return ret;
	}

	return tps6586x_clr_bits(parent, ri->enable_reg[1],
				 1 << ri->enable_bit[1]);
}