示例#1
0
static int as3722_gpio_set(struct udevice *pmic, unsigned int gpio,
			   unsigned int level)
{
	const char *l;
	u8 value;
	int err;

	if (gpio > 7)
		return -EINVAL;

	err = as3722_read(pmic, AS3722_GPIO_SIGNAL_OUT, &value);
	if (err < 0) {
		error("failed to read GPIO signal out register: %d", err);
		return err;
	}

	if (level == 0) {
		value &= ~(1 << gpio);
		l = "low";
	} else {
		value |= 1 << gpio;
		l = "high";
	}

	err = as3722_write(pmic, AS3722_GPIO_SIGNAL_OUT, value);
	if (err) {
		error("failed to set GPIO#%u %s: %d", gpio, l, err);
		return err;
	}

	return 0;
}
示例#2
0
int as3722_gpio_direction_output(struct udevice *pmic, unsigned int gpio,
				 unsigned int level)
{
	u8 value;
	int err;

	if (gpio > 7)
		return -EINVAL;

	if (level == 0)
		value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL;
	else
		value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;

	err = as3722_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
	if (err) {
		error("failed to configure GPIO#%u as output: %d", gpio, err);
		return err;
	}

	err = as3722_gpio_set(pmic, gpio, level);
	if (err < 0) {
		error("failed to set GPIO#%u high: %d", gpio, err);
		return err;
	}

	return 0;
}
示例#3
0
文件: nyan-big.c 项目: 01hyang/u-boot
int tegra_lcd_pmic_init(int board_id)
{
	struct udevice *pmic;
	int ret;

	ret = as3722_get(&pmic);
	if (ret)
		return -ENOENT;

	if (board_id == 0)
		as3722_write(pmic, 0x00, 0x3c);
	else
		as3722_write(pmic, 0x00, 0x50);
	as3722_write(pmic, 0x12, 0x10);
	as3722_write(pmic, 0x0c, 0x07);
	as3722_write(pmic, 0x20, 0x10);

	return 0;
}
示例#4
0
static void as3722rtc_init(void)
{
	static int initialized;
	if (initialized)
		return;

	uint8_t control = as3722_read(AS3722_RTC_CONTROL);
	as3722_write(AS3722_RTC_CONTROL, control | AS3722_RTC_CONTROL_ON);

	initialized = 1;
}
示例#5
0
int as3722_sd_set_voltage(struct udevice *pmic, unsigned int sd, u8 value)
{
	int err;

	if (sd > 6)
		return -EINVAL;

	err = as3722_write(pmic, AS3722_SD_VOLTAGE(sd), value);
	if (err < 0) {
		error("failed to write SD%u voltage register: %d", sd, err);
		return err;
	}

	return 0;
}
示例#6
0
int as3722_ldo_set_voltage(struct udevice *pmic, unsigned int ldo, u8 value)
{
	int err;

	if (ldo > 11)
		return -EINVAL;

	err = as3722_write(pmic, AS3722_LDO_VOLTAGE(ldo), value);
	if (err < 0) {
		error("failed to write LDO%u voltage register: %d", ldo,
		      err);
		return err;
	}

	return 0;
}
示例#7
0
int rtc_set(const struct rtc_time *time)
{
	as3722rtc_init();

	as3722_write(AS3722_RTC_SECOND, bin2bcd(time->sec));
	as3722_write(AS3722_RTC_MINUTE, bin2bcd(time->min));
	as3722_write(AS3722_RTC_HOUR, bin2bcd(time->hour));
	as3722_write(AS3722_RTC_DAY, bin2bcd(time->mday));
	as3722_write(AS3722_RTC_MONTH, bin2bcd(time->mon));
	as3722_write(AS3722_RTC_YEAR, bin2bcd(time->year));
	return 0;
}
示例#8
0
int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
			  unsigned long flags)
{
	u8 value = 0;
	int err;

	if (flags & AS3722_GPIO_OUTPUT_VDDH)
		value |= AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;

	if (flags & AS3722_GPIO_INVERT)
		value |= AS3722_GPIO_CONTROL_INVERT;

	err = as3722_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
	if (err) {
		error("failed to configure GPIO#%u: %d", gpio, err);
		return err;
	}

	return 0;
}
示例#9
0
static void
as3722_attach(device_t parent, device_t self, void *aux)
{
	struct as3722_softc * const sc = device_private(self);
	struct i2c_attach_args *ia = aux;
	int error;

	sc->sc_dev = self;
	sc->sc_i2c = ia->ia_tag;
	sc->sc_addr = ia->ia_addr;

	aprint_naive("\n");
	aprint_normal(": AMS AS3822\n");

	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
	error = as3722_write(sc, AS3722_GPIO0_CTRL_REG,
	    __SHIFTIN(AS3722_GPIO0_CTRL_IOSF_GPIO,
		      AS3722_GPIO0_CTRL_IOSF) |
	    __SHIFTIN(AS3722_GPIO0_CTRL_MODE_PULLDOWN,
		      AS3722_GPIO0_CTRL_MODE),
	    I2C_F_POLL);
	error += as3722_set_clear(sc, AS3722_WATCHDOG_CTRL_REG,
	    __SHIFTIN(1, AS3722_WATCHDOG_CTRL_MODE), 0, I2C_F_POLL);
	iic_release_bus(sc->sc_i2c, I2C_F_POLL);

	if (error)
		aprint_error_dev(self, "couldn't setup watchdog\n");

	sc->sc_smw.smw_name = device_xname(self);
	sc->sc_smw.smw_cookie = sc;
	sc->sc_smw.smw_setmode = as3722_wdt_setmode;
	sc->sc_smw.smw_tickle = as3722_wdt_tickle;
	sc->sc_smw.smw_period = AS3722_WATCHDOG_DEFAULT_PERIOD;

	aprint_normal_dev(self, "default watchdog period is %u seconds\n",
	    sc->sc_smw.smw_period);

	if (sysmon_wdog_register(&sc->sc_smw) != 0)
		aprint_error_dev(self, "couldn't register with sysmon\n");
}
示例#10
0
int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
{
	u8 value;
	int err;

	if (sd > 6)
		return -EINVAL;

	err = as3722_read(pmic, AS3722_SD_CONTROL, &value);
	if (err) {
		error("failed to read SD control register: %d", err);
		return err;
	}

	value |= 1 << sd;

	err = as3722_write(pmic, AS3722_SD_CONTROL, value);
	if (err < 0) {
		error("failed to write SD control register: %d", err);
		return err;
	}

	return 0;
}
示例#11
0
int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo)
{
	u8 value;
	int err;

	if (ldo > 11)
		return -EINVAL;

	err = as3722_read(pmic, AS3722_LDO_CONTROL, &value);
	if (err) {
		error("failed to read LDO control register: %d", err);
		return err;
	}

	value |= 1 << ldo;

	err = as3722_write(pmic, AS3722_LDO_CONTROL, value);
	if (err < 0) {
		error("failed to write LDO control register: %d", err);
		return err;
	}

	return 0;
}