static int tps80031_rtc_set_time(struct device *dev, struct rtc_time *tm) { u8 buff[7]; int ret; buff[0] = bin2bcd(tm->tm_sec); buff[1] = bin2bcd(tm->tm_min); buff[2] = bin2bcd(tm->tm_hour); buff[3] = bin2bcd(tm->tm_mday); buff[4] = bin2bcd(tm->tm_mon + 1); buff[5] = bin2bcd(tm->tm_year % RTC_YEAR_OFFSET); buff[6] = bin2bcd(tm->tm_wday); /* Stop RTC while updating the RTC time registers */ ret = tps80031_clr_bits(dev->parent, TPS80031_SLAVE_ID1, TPS80031_RTC_CTRL_REG, STOP_RTC); if (ret < 0) { dev_err(dev->parent, "Stop RTC failed, err = %d\n", ret); return ret; } ret = tps80031_writes(dev->parent, TPS80031_SLAVE_ID1, TPS80031_SECONDS_REG, TPS80031_RTC_TIME_NUM_REGS, buff); if (ret < 0) { dev_err(dev, "writing RTC_SECONDS_REG failed, err %d\n", ret); return ret; } ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1, TPS80031_RTC_CTRL_REG, STOP_RTC); if (ret < 0) dev_err(dev->parent, "Start RTC failed, err = %d\n", ret); return ret; }
static int tps80031_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) { struct tps80031_rtc *rtc = dev_get_drvdata(dev); int err; struct device *p = dev->parent; if (rtc->irq == -1) return -EIO; if (enable) { if (rtc->irq_en == true) return 0; err = tps80031_set_bits(p, 1, RTC_INT, ENABLE_ALARM_INT); if (err < 0) { dev_err(p, "failed to set ALRM int. err: %d\n", err); return err; } rtc->irq_en = true; } else { if (rtc->irq_en == false) return 0; err = tps80031_clr_bits(p, 1, RTC_INT, ENABLE_ALARM_INT); if (err < 0) { dev_err(p, "failed to clear ALRM int. err: %d\n", err); return err; } rtc->irq_en = false; } return 0; }
static int tps80031_rtc_stop(struct device *dev) { int err; err = tps80031_clr_bits(dev->parent, 1, RTC_CTRL, STOP_RTC); if (err < 0) dev_err(dev->parent, "failed to stop RTC. err: %d\n", err); return err; }
static int tps80031_vbus_disable(struct regulator_dev *rdev) { struct tps80031_regulator *ri = rdev_get_drvdata(rdev); struct device *parent = to_tps80031_dev(rdev); int ret = 0; if (ri->config_flags & TPS80031_VBUS_DISCHRG_EN_PDN) { ret = tps80031_write(parent, TPS80031_SLAVE_ID2, USB_VBUS_CTRL_SET, VBUS_DISCHRG); if (ret < 0) { dev_err(ri->dev, "reg 0x%02x write failed, e = %d\n", USB_VBUS_CTRL_SET, ret); return ret; } } ret = tps80031_clr_bits(parent, TPS80031_SLAVE_ID2, TPS80031_CHARGERUSB_CTRL1, OPA_MODE_EN); if (ret < 0) { dev_err(ri->dev, "reg 0x%02x clearbit failed, e = %d\n", TPS80031_CHARGERUSB_CTRL1, ret); return ret; } ret = tps80031_clr_bits(parent, TPS80031_SLAVE_ID2, TPS80031_CHARGERUSB_CTRL3, BOOST_HW_PWR_EN); if (ret < 0) { dev_err(ri->dev, "reg 0x%02x clearbit failed, e = %d\n", TPS80031_CHARGERUSB_CTRL3, ret); return ret; } mdelay(DIV_ROUND_UP(ri->rinfo->desc.enable_time, 1000)); if (ri->config_flags & TPS80031_VBUS_DISCHRG_EN_PDN) { ret = tps80031_write(parent, TPS80031_SLAVE_ID2, USB_VBUS_CTRL_CLR, VBUS_DISCHRG); if (ret < 0) { dev_err(ri->dev, "reg 0x%02x write failed, e = %d\n", USB_VBUS_CTRL_CLR, ret); return ret; } } return ret; }
static int tps80031_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) { int ret; if (enable) ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1, TPS80031_RTC_INTERRUPTS_REG, ENABLE_ALARM_INT); else ret = tps80031_clr_bits(dev->parent, TPS80031_SLAVE_ID1, TPS80031_RTC_INTERRUPTS_REG, ENABLE_ALARM_INT); if (ret < 0) { dev_err(dev, "Update on RTC_INT failed, err = %d\n", ret); return ret; } return 0; }