ricoh619:update the 619 drivers

This commit is contained in:
张晴 2013-06-01 16:02:55 +08:00
parent 54b820dfdb
commit d710d2c98d
7 changed files with 795 additions and 307 deletions

2
arch/arm/mach-rk30/board-pmu-ricoh619.c Normal file → Executable file
View File

@ -20,7 +20,7 @@ static int ricoh619_pre_init(struct ricoh619 *ricoh619){
uint8_t cont;
int ret;
ret = ricoh619_clr_bits(ricoh619->dev,RICOH619_PWR_REP_CNT,(1 << 0)); //set restart when power off
ret = ricoh619_set_bits(ricoh619->dev,RICOH619_PWR_REP_CNT,(1 << 0)); //set restart when power off
/**********set dcdc mode when in sleep mode **************/

View File

@ -39,15 +39,15 @@
#include <linux/mfd/ricoh619.h>
#define RICOH619_ONKEY_TRIGGER_LEVEL 0
#define RICOH619_ONKEY_OFF_IRQ 0
#define RICOH619_ONKEY_OFF_IRQ 0
struct ricoh619_pwrkey {
struct device * dev;
struct device *dev;
struct input_dev *pwr;
#if RICOH619_ONKEY_TRIGGER_LEVEL
struct timer_list timer;
#endif
struct workqueue_struct * workqueue;
struct workqueue_struct *workqueue;
struct work_struct work;
unsigned long delay;
int key_irq;
@ -57,7 +57,6 @@ struct ricoh619_pwrkey {
};
struct ricoh619_pwrkey *g_pwrkey;
//static int test_set = 0;
#if RICOH619_ONKEY_TRIGGER_LEVEL
void ricoh619_pwrkey_timer(unsigned long t)
@ -66,10 +65,9 @@ void ricoh619_pwrkey_timer(unsigned long t)
}
#endif
extern int pwrkey_wakeup;
static void ricoh619_irq_work(struct work_struct * work)
static void ricoh619_irq_work(struct work_struct *work)
{
unsigned long flags;
/* unsigned long flags; */
uint8_t val;
// printk("PMU: %s: \n",__func__);
@ -86,8 +84,9 @@ static void ricoh619_irq_work(struct work_struct * work)
return;
}
ricoh619_read(g_pwrkey->dev->parent, RICOH619_INT_MON_SYS, &val);
dev_dbg(g_pwrkey->dev, "pwrkey is pressed?(0x%x): 0x%x\n", RICOH619_INT_MON_SYS, val);
// printk("PMU: %s: val=0x%x\n",__func__,val);
dev_dbg(g_pwrkey->dev, "pwrkey is pressed?(0x%x): 0x%x\n",
RICOH619_INT_MON_SYS, val);
// printk(KERN_INFO "PMU: %s: val=0x%x\n", __func__, val);
val &= 0x1;
if(val){
#if (RICOH619_ONKEY_TRIGGER_LEVEL)
@ -102,32 +101,30 @@ static void ricoh619_irq_work(struct work_struct * work)
input_event(g_pwrkey->pwr, EV_KEY, KEY_POWER, 1);
input_event(g_pwrkey->pwr, EV_SYN, 0, 0);
}
}
else{
if (g_pwrkey->pressed_first){
// printk("PMU2: %s: Power Key!!!\n",__func__);
//input_report_key(g_pwrkey->pwr, KEY_POWER, 0);
//input_sync(g_pwrkey->pwr);
} else {
if (g_pwrkey->pressed_first) {
// printk(KERN_INFO "PMU2: %s: Power Key!!!\n", __func__);
/* input_report_key(g_pwrkey->pwr, KEY_POWER, 0); */
/* input_sync(g_pwrkey->pwr); */
input_event(g_pwrkey->pwr, EV_KEY, KEY_POWER, 0);
input_event(g_pwrkey->pwr, EV_SYN, 0, 0);
}
g_pwrkey->pressed_first = false;
}
//spin_unlock_irqrestore(&g_pwrkey->lock, flags);
/* spin_unlock_irqrestore(&g_pwrkey->lock, flags); */
}
extern struct ricoh619 *g_ricoh619;
static irqreturn_t pwrkey_irq(int irq, void *_pwrkey)
{
// printk("PMU: %s: \n",__func__);
struct ricoh619 *ricoh619 = g_ricoh619;
// printk(KERN_INFO "PMU: %s:\n", __func__);
#if (RICOH619_ONKEY_TRIGGER_LEVEL)
g_pwrkey->timer.expires = jiffies + g_pwrkey->delay;
add_timer(&g_pwrkey->timer);
#else
queue_work(g_pwrkey->workqueue, &g_pwrkey->work);
#endif
ricoh619_clr_bits(g_ricoh619->dev, RICOH619_INT_IR_SYS, 0x1); //clr power-on interrupt
return IRQ_HANDLED;
}
@ -191,7 +188,7 @@ static int __devinit ricoh619_pwrkey_probe(struct platform_device *pdev)
pwrkey->pwr = pwr;
platform_set_drvdata(pdev, pwrkey);
// Check if power-key is pressed at boot up
/* Check if power-key is pressed at boot up */
err = ricoh619_read(pwrkey->dev->parent, RICOH619_INT_MON_SYS, &val);
if (err < 0) {
dev_err(&pdev->dev, "Key-press status at boot failed rc=%d\n",
@ -207,7 +204,8 @@ static int __devinit ricoh619_pwrkey_probe(struct platform_device *pdev)
}
#if !(RICOH619_ONKEY_TRIGGER_LEVEL)
ricoh619_set_bits(pwrkey->dev->parent, RICOH619_PWR_IRSEL, 0x1); //trigger both edge
/* trigger both edge */
ricoh619_set_bits(pwrkey->dev->parent, RICOH619_PWR_IRSEL, 0x1);
#endif
err = request_threaded_irq(key_irq, NULL, pwrkey_irq,

View File

@ -345,29 +345,6 @@ static irqreturn_t ricoh619_irq(int irq, void *data)
return IRQ_HANDLED;
}
/* Mask Charger Interrupt */
if((CHG_INT | ADC_INT) & master_int){
for (i=8; i < MAX_INTERRUPT_MASKS; i++) {
ret = ricoh619_write(ricoh619->dev,
irq_en_add[i], 0xff);
if (ret < 0) {
dev_err(ricoh619->dev,
"Error in write reg 0x%02x "
"error: %d\n",
irq_en_add[i], ret);
}
}
//Disable ADC interrupt
for (i=3; i < 6; i++) {
ret = ricoh619_write(ricoh619->dev, irq_en_add[i], 0x0);
if (ret < 0) {
dev_err(ricoh619->dev, "Error in write reg 0x%02x "
"error: %d\n", irq_en_add[i],
ret);
}
}
}
for (i = 0; i < MAX_INTERRUPT_MASKS; ++i) {
/* Even if INTC_INTMON register = 1, INT signal might not output
because INTC_INTMON register indicates only interrupt facter level.
@ -393,16 +370,41 @@ static irqreturn_t ricoh619_irq(int irq, void *data)
if (int_sts[i] & 0x4)
rtc_int_sts |= BIT(0);
}
ret = ricoh619_write(ricoh619->dev,
irq_clr_add[i], ~int_sts[i]);
if (ret < 0) {
dev_err(ricoh619->dev, "Error in reading reg 0x%02x "
"error: %d\n", irq_clr_add[i], ret);
if (i != 2) {
ret = ricoh619_write(ricoh619->dev,
irq_clr_add[i], ~int_sts[i]);
if (ret < 0) {
dev_err(ricoh619->dev, "Error in reading reg 0x%02x "
"error: %d\n", irq_clr_add[i], ret);
}
}
if (main_int_type[i] & RTC_INT)
int_sts[i] = rtc_int_sts;
/* Mask Charger Interrupt */
if (main_int_type[i] & CHG_INT) {
if (int_sts[i])
ret = ricoh619_write(ricoh619->dev,
irq_en_add[i], 0xff);
if (ret < 0) {
dev_err(ricoh619->dev,
"Error in write reg 0x%02x error: %d\n",
irq_en_add[i], ret);
}
}
/* Mask ADC Interrupt */
if (main_int_type[i] & ADC_INT) {
if (int_sts[i])
ret = ricoh619_write(ricoh619->dev,
irq_en_add[i], 0);
if (ret < 0) {
dev_err(ricoh619->dev,
"Error in write reg 0x%02x error: %d\n",
irq_en_add[i], ret);
}
}
}

View File

@ -24,6 +24,7 @@
*/
/*#define DEBUG 1*/
/*#define VERBOSE_DEBUG 1*/
#define CONFIG_DEBUG_FS
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/kernel.h>
@ -800,8 +801,8 @@ static int ricoh619_i2c_resume(struct i2c_client *client)
__ricoh619_write(client, RICOH619_INT_IR_SYS, 0x0); //Clear PWR_KEY IRQ
}
__ricoh619_write(client, RICOH619_INT_IR_CHGCTR, 0);
__ricoh619_write(client, RICOH619_INT_IR_CHGSTS1, 0);
//__ricoh619_write(client, RICOH619_INT_IR_CHGCTR, 0);
//__ricoh619_write(client, RICOH619_INT_IR_CHGSTS1, 0);
__ricoh619_write(client, RICOH619_INT_IR_ADCL, 0);
__ricoh619_write(client, RICOH619_INT_IR_ADCH, 0);

939
drivers/power/ricoh619-battery.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -267,14 +267,14 @@ static irqreturn_t ricoh619_rtc_irq(int irq, void *data)
/* clear alarm-D status bits.*/
err = ricoh619_read_regs(dev, rtc_ctrl2, 1, &reg);
if (err) {
if (err)
dev_err(dev->parent, "unable to read rtc_ctrl2 reg\n");
}
reg &= ~0x81; /* to clear alarm-D flag, and set adjustment parameter */
/* to clear alarm-D flag, and set adjustment parameter */
reg &= ~0x81;
err = ricoh619_write_regs(dev, rtc_ctrl2, 1, &reg);
if (err) {
if (err)
dev_err(dev->parent, "unable to program rtc_status reg\n");
}
rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
return IRQ_HANDLED;
@ -313,13 +313,6 @@ static int __devinit ricoh619_rtc_probe(struct platform_device *pdev)
goto fail;
}
reg = 0x20; /* to clear power-on-reset flag */
err = ricoh619_write_regs(&pdev->dev, rtc_ctrl2, 1, &reg);
if (err) {
dev_err(&pdev->dev, "failed rtc setup\n");
return -EBUSY;
}
reg = 0x60; /* to enable alarm_d and 24-hour format */
err = ricoh619_write_regs(&pdev->dev, rtc_ctrl1, 1, &reg);
if (err) {
@ -333,11 +326,35 @@ static int __devinit ricoh619_rtc_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "unable to program rtc_adjust reg\n");
return -EBUSY;
}
err = ricoh619_rtc_read_time(&pdev->dev, &tm);
/* Set default time-1970.1.1-0h:0m:0s if PON is on */
err = ricoh619_read_regs(&pdev->dev, rtc_ctrl2, 1, &reg);
if (err) {
dev_err(&pdev->dev, "\n failed to read time\n");
return err;
dev_err(&pdev->dev, "\n failed to read rtc ctl2 reg\n");
return -EBUSY;
}
if (reg&0x10) {
printk("%s,PON=1 -- CTRL2=%x\n", __func__, reg);
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 0;
tm.tm_wday = 4;
tm.tm_mday = 1;
tm.tm_mon = 0;
tm.tm_year = 0x70;
/* VDET & PON = 0, others are not changed */
reg &= ~0x50;
err = ricoh619_write_regs(&pdev->dev, rtc_ctrl2, 1, &reg);
if (err) {
dev_err(&pdev->dev, "\n failed to write rtc ctl2 reg\n");
return -EBUSY;
}
} else {
err = ricoh619_rtc_read_time(&pdev->dev, &tm);
if (err) {
dev_err(&pdev->dev, "\n failed to read time\n");
return err;
}
}
if (ricoh619_rtc_valid_tm(&pdev->dev, &tm)) {
if (pdata->time.tm_year < 2000 || pdata->time.tm_year > 2100) {

View File

@ -26,7 +26,7 @@
/* #include <linux/types.h> */
#if 0
#define RICOH_FG_DBG(fmt, args...) printk(KERN_DEBUG "RICOH_FG_DBG:\t"fmt, ##args)
#define RICOH_FG_DBG(fmt, args...) printk( "RICOH_FG_DBG:\t"fmt, ##args)
#else
#define RICOH_FG_DBG(fmt, args...) {while(0);}
#endif
@ -46,6 +46,9 @@
#define VBATDATAH_REG 0x6A
#define VBATDATAL_REG 0x6B
#define VSYSDATAH_REG 0x70
#define VSYSDATAL_REG 0x71
#define CHGCTL1_REG 0xB3
#define REGISET1_REG 0xB6
#define REGISET2_REG 0xB7