From 971b4afb180858e4acb179a5aaba9484432fb228 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BC=A0=E6=99=B4?= Date: Thu, 8 May 2014 15:29:05 +0800 Subject: [PATCH] rk3288:pmic:rk808:modify power off have lock;add protect for i2c error --- drivers/mfd/rk808.c | 40 ++++++++++++++++++++++++--------------- include/linux/mfd/rk808.h | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c index 93c9e85a0270..7132dd37aeeb 100755 --- a/drivers/mfd/rk808.c +++ b/drivers/mfd/rk808.c @@ -513,6 +513,9 @@ static int rk808_dcdc_set_voltage(struct regulator_dev *dev, ret = rk808_set_bits(rk808, rk808_BUCK_SET_VOL_REG(buck), BUCK_VOL_MASK, val); #endif } + if(ret<0) + printk("################WARNING:set voltage is error!voltage set is %d mv %d\n",min_uV,ret); + return ret; } static int rk808_dcdc_set_sleep_voltage(struct regulator_dev *dev, @@ -767,7 +770,7 @@ static struct regulator_desc regulators[] = { ret = i2c_transfer(adap, msgs, 2); DBG("***run in %s %x % x\n",__FUNCTION__,i2c->addr,*(msgs[1].buf)); - return 0; + return ret; } int rk808_i2c_write(struct rk808 *rk808, char reg, int count, const u8 src) @@ -797,15 +800,17 @@ int rk808_i2c_write(struct rk808 *rk808, char reg, int count, const u8 src) return ret; } -u8 rk808_reg_read(struct rk808 *rk808, u8 reg) +int rk808_reg_read(struct rk808 *rk808, u8 reg) { u8 val = 0; + int ret; mutex_lock(&rk808->io_lock); - rk808_i2c_read(rk808, reg, 1, &val); - + ret = rk808_i2c_read(rk808, reg, 1, &val); DBG("reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val&0xff); + if (ret < 0) + return ret; mutex_unlock(&rk808->io_lock); @@ -837,12 +842,17 @@ EXPORT_SYMBOL_GPL(rk808_reg_write); ret = rk808_i2c_read(rk808, reg, 1, &tmp); DBG("1 reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)tmp&0xff); + if (ret < 0) + return ret; tmp = (tmp & ~mask) | val; - if (ret == 0) { - ret = rk808_i2c_write(rk808, reg, 1, tmp); - DBG("reg write 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val&0xff); - } - rk808_i2c_read(rk808, reg, 1, &tmp); + ret = rk808_i2c_write(rk808, reg, 1, tmp); + DBG("reg write 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val&0xff); + if (ret < 0) + return ret; + + ret = rk808_i2c_read(rk808, reg, 1, &tmp); + if (ret < 0) + return ret; DBG("2 reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)tmp&0xff); mutex_unlock(&rk808->io_lock); @@ -1126,6 +1136,9 @@ static int rk808_shutdown(void) printk("%s,line=%d dc[%d]= %d\n", __func__,__LINE__,(i+1),val); } /*****************************************************/ + ret = rk808_set_bits(rk808, RK808_INT_STS_MSK_REG1,(0x3<<5),(0x3<<5)); //close rtc int when power off + ret = rk808_clear_bits(rk808, RK808_RTC_INT_REG,(0x3<<2)); //close rtc int when power off + return 0; } EXPORT_SYMBOL_GPL(rk808_shutdown); @@ -1134,16 +1147,13 @@ static int rk808_device_shutdown(void) { int ret,i,val; int err = -1; - u16 reg = 0; + u8 reg = 0; struct rk808 *rk808 = g_rk808; printk("%s\n",__func__); - ret = rk808_set_bits(rk808, RK808_INT_STS_MSK_REG1,(0x3<<5),(0x3<<5)); //close rtc int when power off - ret = rk808_clear_bits(rk808, RK808_RTC_INT_REG,(0x3<<2)); //close rtc int when power off - ret = rk808_reg_read(rk808,RK808_DEVCTRL_REG); - ret = rk808_set_bits(rk808, RK808_DEVCTRL_REG,(0x1<<3),(0x1<<3)); -// ret = rk808_set_bits(rk808, RK808_DEVCTRL_REG,(0x1<<4),(0x1<<4)); + ret = rk808_i2c_read(rk808,RK808_DEVCTRL_REG,1,®); + ret = rk808_i2c_write(rk808, RK808_DEVCTRL_REG, 1,(reg |(0x1 <<3))); if (ret < 0) { printk("rk808 power off error!\n"); return err; diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h index 04bd5c4a82ce..f59f327ca80b 100755 --- a/include/linux/mfd/rk808.h +++ b/include/linux/mfd/rk808.h @@ -180,7 +180,7 @@ int rk808_irq_init(struct rk808 *rk808, int irq,struct rk808_board *pdata); int rk808_i2c_write(struct rk808 *rk808, char reg, int count, const u8 src); int rk808_set_bits(struct rk808 *rk808, u8 reg, u8 mask, u8 val); int rk808_clear_bits(struct rk808 *rk808, u8 reg, u8 mask); -u8 rk808_reg_read(struct rk808 *rk808, u8 reg); +int rk808_reg_read(struct rk808 *rk808, u8 reg); int rk808_reg_write(struct rk808 *rk808, u8 reg, u8 val); int rk808_bulk_read(struct rk808 *rk808, u8 reg, int count, u8 *buf); -- 2.34.1