mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
rk31:pmu:rt5025:updata drivers,modify charger & fg bug,support otg
This commit is contained in:
@@ -82,6 +82,16 @@ static int rt5025_post_init(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rt5025_set_otg_enable(int enable)
|
||||
{
|
||||
if (enable)
|
||||
rt5025_ext_set_charging_buck(0);
|
||||
else
|
||||
rt5025_ext_set_charging_buck(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct regulator_consumer_supply rt5025_dcdc1_supply[] = {
|
||||
{
|
||||
.supply = "rt5025-dcdc1",
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/wakelock.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/irq.h>
|
||||
@@ -32,8 +34,10 @@ struct rt5025_irq_info {
|
||||
struct workqueue_struct *wq;
|
||||
struct rt5025_event_callback *event_cb;
|
||||
struct delayed_work delayed_work;
|
||||
struct wake_lock irq_wake_lock;
|
||||
int intr_pin;
|
||||
int irq;
|
||||
int suspend;
|
||||
};
|
||||
|
||||
static void rt5025_work_func(struct work_struct *work)
|
||||
@@ -41,8 +45,16 @@ static void rt5025_work_func(struct work_struct *work)
|
||||
struct delayed_work *delayed_work = (struct delayed_work *)container_of(work, struct delayed_work, work);
|
||||
struct rt5025_irq_info *ii = (struct rt5025_irq_info *)container_of(delayed_work, struct rt5025_irq_info, delayed_work);
|
||||
unsigned char irq_stat[6] = {0};
|
||||
unsigned char irq_enable[6] = {0};
|
||||
uint32_t chg_event = 0, pwr_event = 0;
|
||||
|
||||
//Add this to prevent i2c xfer before i2c chip is in suspend mode
|
||||
if (ii->suspend)
|
||||
{
|
||||
queue_delayed_work(ii->wq, &ii->delayed_work, msecs_to_jiffies(1));
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_POWER_RT5025
|
||||
if (!ii->chip->power_info || !ii->chip->jeita_info || !ii->chip->battery_info)
|
||||
{
|
||||
@@ -55,6 +67,21 @@ static void rt5025_work_func(struct work_struct *work)
|
||||
if (rt5025_reg_block_read(ii->i2c, RT5025_REG_IRQEN1, 10, irq_stat) >= 0)
|
||||
{
|
||||
#endif
|
||||
/* backup the irq enable bit */
|
||||
irq_enable[0] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQEN1);
|
||||
irq_enable[1] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQEN2);
|
||||
irq_enable[2] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQEN3);
|
||||
irq_enable[3] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQEN4);
|
||||
irq_enable[4] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQEN5);
|
||||
irq_enable[5] = rt5025_reg_read(ii->i2c, RT5025_REG_GAUGEIRQEN);
|
||||
/* disable all irq enable bit first */
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN1, irq_enable[0]&RT5025_ADAPIRQ_MASK);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN2, 0x00);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN3, 0x00);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN4, 0x00);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN5, 0x00);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_GAUGEIRQEN, 0x00);
|
||||
/* read irq status bit */
|
||||
irq_stat[0] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQSTATUS1);
|
||||
irq_stat[1] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQSTATUS2);
|
||||
irq_stat[2] = rt5025_reg_read(ii->i2c, RT5025_REG_IRQSTATUS3);
|
||||
@@ -68,11 +95,38 @@ static void rt5025_work_func(struct work_struct *work)
|
||||
chg_event = irq_stat[0]<<16 | irq_stat[1]<<8 | irq_stat[2];
|
||||
pwr_event = irq_stat[3]<<8 | irq_stat[4];
|
||||
#ifdef CONFIG_POWER_RT5025
|
||||
if (chg_event & CHARGER_DETECT_MASK)
|
||||
if ((chg_event & CHARGER_DETECT_MASK) && ii->chip->power_info->otg_en == 0)
|
||||
{
|
||||
if (chg_event & CHG_EVENT_CHTERMI)
|
||||
{
|
||||
ii->chip->power_info->chg_term++;
|
||||
rt5025_power_charge_detect(ii->chip->power_info);
|
||||
if (ii->chip->power_info->chg_term > 3)
|
||||
ii->chip->power_info->chg_term = 4;
|
||||
}
|
||||
|
||||
if (chg_event & CHG_EVENT_CHRCHGI)
|
||||
ii->chip->power_info->chg_term = 0;
|
||||
|
||||
if (chg_event & (CHG_EVENT_CHSLPI_INAC | CHG_EVENT_CHSLPI_INUSB))
|
||||
{
|
||||
ii->chip->power_info->chg_term = 0;
|
||||
}
|
||||
|
||||
if (chg_event & (CHG_EVENT_INAC_PLUGIN | CHG_EVENT_INUSB_PLUGIN))
|
||||
{
|
||||
rt5025_set_charging_buck(ii->i2c, 0);
|
||||
mdelay(50);
|
||||
rt5025_set_charging_buck(ii->i2c, 1);
|
||||
mdelay(100);
|
||||
rt5025_set_charging_buck(ii->i2c, 0);
|
||||
mdelay(50);
|
||||
rt5025_set_charging_buck(ii->i2c, 1);
|
||||
mdelay(200);
|
||||
}
|
||||
|
||||
if (ii->chip->power_info->chg_term <= 3)
|
||||
rt5025_power_charge_detect(ii->chip->power_info);
|
||||
|
||||
}
|
||||
#endif /* CONFIG_POWER_RT5025 */
|
||||
if (ii->event_cb)
|
||||
@@ -96,6 +150,15 @@ static void rt5025_work_func(struct work_struct *work)
|
||||
rt5025_gauge_irq_handler(ii->chip->battery_info, irq_stat[5] & RT5025_FLG_VOLT);
|
||||
#endif /* CONFIG_POWER_RT5025 */
|
||||
|
||||
/* restore all irq enable bit */
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN1, irq_enable[0]);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN2, irq_enable[1]);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN3, irq_enable[2]);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN4, irq_enable[3]);
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_IRQEN5, irq_enable[4]);
|
||||
if (rt5025_reg_read(ii->i2c, RT5025_REG_GAUGEIRQEN) == 0)
|
||||
rt5025_reg_write(ii->i2c, RT5025_REG_GAUGEIRQEN, irq_enable[5]);
|
||||
|
||||
//enable_irq(ii->irq);
|
||||
}
|
||||
|
||||
@@ -104,6 +167,7 @@ static irqreturn_t rt5025_interrupt(int irqno, void *param)
|
||||
struct rt5025_irq_info *ii = (struct rt5025_irq_info *)param;
|
||||
|
||||
//disable_irq_nosync(ii->irq);
|
||||
wake_lock_timeout(&ii->irq_wake_lock, 1*HZ);
|
||||
queue_delayed_work(ii->wq, &ii->delayed_work, 0);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
@@ -193,11 +257,13 @@ static int __devinit rt5025_irq_probe(struct platform_device *pdev)
|
||||
ii->irq = chip->irq;//gpio_to_irq(pdata->intr_pin);
|
||||
if (pdata->cb)
|
||||
ii->event_cb = pdata->cb;
|
||||
wake_lock_init(&ii->irq_wake_lock, WAKE_LOCK_SUSPEND, "rt_irq_wake");
|
||||
|
||||
rt5025_irq_reg_init(ii, pdata->irq_data);
|
||||
rt5025_interrupt_init(ii);
|
||||
|
||||
platform_set_drvdata(pdev, ii);
|
||||
RTINFO("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -205,8 +271,11 @@ static int __devexit rt5025_irq_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct rt5025_irq_info *ii = platform_get_drvdata(pdev);
|
||||
|
||||
wake_lock_destroy(&ii->irq_wake_lock);
|
||||
rt5025_interrupt_deinit(ii);
|
||||
platform_set_drvdata(pdev, NULL);
|
||||
kfree(ii);
|
||||
RTINFO("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -222,6 +291,25 @@ static void rt5025_irq_shutdown(struct platform_device *pdev)
|
||||
cancel_delayed_work_sync(&ii->delayed_work);
|
||||
flush_workqueue(ii->wq);
|
||||
}
|
||||
RTINFO("\n");
|
||||
}
|
||||
|
||||
static int rt5025_irq_suspend(struct platform_device *pdev, pm_message_t state)
|
||||
{
|
||||
struct rt5025_irq_info *ii = platform_get_drvdata(pdev);
|
||||
|
||||
RTINFO("\n");
|
||||
ii->suspend = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt5025_irq_resume(struct platform_device *pdev)
|
||||
{
|
||||
struct rt5025_irq_info *ii = platform_get_drvdata(pdev);
|
||||
|
||||
RTINFO("\n");
|
||||
ii->suspend = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver rt5025_irq_driver =
|
||||
@@ -233,6 +321,8 @@ static struct platform_driver rt5025_irq_driver =
|
||||
.probe = rt5025_irq_probe,
|
||||
.remove = __devexit_p(rt5025_irq_remove),
|
||||
.shutdown = rt5025_irq_shutdown,
|
||||
.suspend = rt5025_irq_suspend,
|
||||
.resume = rt5025_irq_resume,
|
||||
};
|
||||
|
||||
static int __init rt5025_irq_init(void)
|
||||
|
||||
@@ -956,6 +956,7 @@ static void rt5025_get_soc(struct rt5025_battery_info *bi)
|
||||
#endif
|
||||
}
|
||||
#if RT5025_CSV
|
||||
RTINFO("soc=%d, permille=%d, rm=%d, fcc=%d, smooth_flag=%d\n", bi->soc,bi->permille,bi->rm,bi->fcc,bi->smooth_flag);
|
||||
// pr_info("%d,%d,%d,%d,%d", bi->soc,bi->permille,bi->rm,bi->fcc,bi->smooth_flag);
|
||||
#else
|
||||
RTINFO("soc=%d, permille=%d, rm=%d, fcc=%d, smooth_flag=%d\n", bi->soc,bi->permille,bi->rm,bi->fcc,bi->smooth_flag);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <linux/power/rt5025-power.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
static struct platform_device *dev_ptr;
|
||||
|
||||
|
||||
static enum power_supply_property rt5025_adap_props[] = {
|
||||
POWER_SUPPLY_PROP_ONLINE,
|
||||
@@ -34,8 +36,7 @@ static char *rt5025_supply_list[] = {
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
static int rt5025_set_charging_current_switch (struct i2c_client *i2c, int onoff)
|
||||
int rt5025_set_charging_current_switch (struct i2c_client *i2c, int onoff)
|
||||
{
|
||||
int ret;
|
||||
if (onoff)
|
||||
@@ -44,8 +45,9 @@ static int rt5025_set_charging_current_switch (struct i2c_client *i2c, int onoff
|
||||
ret = rt5025_clr_bits(i2c, RT5025_REG_CHGCTL7, RT5025_CHGCEN_MASK);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(rt5025_set_charging_current_switch);
|
||||
|
||||
static int rt5025_set_charging_buck(struct i2c_client *i2c, int onoff)
|
||||
int rt5025_set_charging_buck(struct i2c_client *i2c, int onoff)
|
||||
{
|
||||
int ret;
|
||||
if (onoff)
|
||||
@@ -54,7 +56,27 @@ static int rt5025_set_charging_buck(struct i2c_client *i2c, int onoff)
|
||||
ret = rt5025_clr_bits(i2c, RT5025_REG_CHGCTL2, RT5025_CHGBUCKEN_MASK);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
EXPORT_SYMBOL(rt5025_set_charging_buck);
|
||||
|
||||
int rt5025_ext_set_charging_buck(int onoff)
|
||||
{
|
||||
struct rt5025_power_info *pi = platform_get_drvdata(dev_ptr);
|
||||
int ret;
|
||||
if (onoff)
|
||||
{
|
||||
pi->otg_en = 0;
|
||||
ret = rt5025_set_bits(pi->i2c, RT5025_REG_CHGCTL2, RT5025_CHGBUCKEN_MASK);
|
||||
msleep(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
pi->otg_en = 1;
|
||||
ret = rt5025_clr_bits(pi->i2c, RT5025_REG_CHGCTL2, RT5025_CHGBUCKEN_MASK);
|
||||
msleep(100);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(rt5025_ext_set_charging_buck);
|
||||
|
||||
static int rt5025_set_charging_current(struct i2c_client *i2c, int cur_value)
|
||||
{
|
||||
@@ -98,14 +120,15 @@ static int rt5025_chgstat_changed(struct rt5025_power_info *info, unsigned new_v
|
||||
#if 1
|
||||
if (info->chip->battery_info)
|
||||
{
|
||||
if (info->chg_term == 0)
|
||||
if (info->chg_term <= 1)
|
||||
rt5025_gauge_set_status(info->chip->battery_info, POWER_SUPPLY_STATUS_CHARGING);
|
||||
else if (info->chg_term > 0)
|
||||
else if (info->chg_term == 2)
|
||||
{
|
||||
rt5025_gauge_set_status(info->chip->battery_info, POWER_SUPPLY_STATUS_FULL);
|
||||
info->chg_term = 0;
|
||||
//info->chg_term = 0;
|
||||
}
|
||||
|
||||
else if (info->chg_term > 2)
|
||||
;
|
||||
}
|
||||
#else
|
||||
if (info->event_callback)
|
||||
@@ -151,13 +174,15 @@ static int rt5025_chgstat_changed(struct rt5025_power_info *info, unsigned new_v
|
||||
#if 1
|
||||
if (info->chip->battery_info)
|
||||
{
|
||||
if (info->chg_term == 0)
|
||||
if (info->chg_term <= 1)
|
||||
rt5025_gauge_set_status(info->chip->battery_info, POWER_SUPPLY_STATUS_CHARGING);
|
||||
else if (info->chg_term > 1)
|
||||
else if (info->chg_term == 2)
|
||||
{
|
||||
rt5025_gauge_set_status(info->chip->battery_info, POWER_SUPPLY_STATUS_FULL);
|
||||
info->chg_term = 0;
|
||||
//info->chg_term = 0;
|
||||
}
|
||||
else if (info->chg_term > 2)
|
||||
;
|
||||
}
|
||||
#else
|
||||
if (info->event_callback)
|
||||
@@ -190,7 +215,7 @@ int rt5025_power_charge_detect(struct rt5025_power_info *info)
|
||||
old_usbval = info->usb_online;
|
||||
old_chgval = info->chg_stat;
|
||||
|
||||
mdelay(10);
|
||||
mdelay(50);
|
||||
|
||||
ret = rt5025_reg_read(info->i2c, RT5025_REG_CHGSTAT);
|
||||
if (ret<0)
|
||||
@@ -199,6 +224,7 @@ int rt5025_power_charge_detect(struct rt5025_power_info *info)
|
||||
return ret;
|
||||
}
|
||||
chgstatval = ret;
|
||||
RTINFO("chgstat = 0x%02x\n", chgstatval);
|
||||
|
||||
new_acval = (chgstatval&RT5025_CHG_ACONLINE)>>RT5025_CHG_ACSHIFT;
|
||||
if (old_acval != new_acval)
|
||||
@@ -386,6 +412,7 @@ static int __devinit rt5025_power_probe(struct platform_device *pdev)
|
||||
#endif
|
||||
|
||||
platform_set_drvdata(pdev, pi);
|
||||
dev_ptr = pdev;
|
||||
|
||||
pi->ac.name = "rt5025-dc";
|
||||
pi->ac.type = POWER_SUPPLY_TYPE_MAINS;
|
||||
@@ -410,6 +437,8 @@ static int __devinit rt5025_power_probe(struct platform_device *pdev)
|
||||
rt5025_init_charger(pi, pdata->power_data);
|
||||
chip->power_info = pi;
|
||||
|
||||
pr_info("rt5025-power driver is successfully loaded\n");
|
||||
|
||||
return ret;
|
||||
out_usb:
|
||||
power_supply_unregister(&pi->ac);
|
||||
@@ -456,6 +485,7 @@ static int __devexit rt5025_power_remove(struct platform_device *pdev)
|
||||
power_supply_unregister(&pi->ac);
|
||||
chip->power_info = NULL;
|
||||
kfree(pi);
|
||||
RTINFO("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -476,7 +506,7 @@ static int __init rt5025_power_init(void)
|
||||
{
|
||||
return platform_driver_register(&rt5025_power_driver);
|
||||
}
|
||||
late_initcall_sync(rt5025_power_init);
|
||||
fs_initcall_sync(rt5025_power_init);
|
||||
|
||||
static void __exit rt5025_power_exit(void)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
#define RT5025_REG_IRQEN5 0x38
|
||||
#define RT5025_REG_IRQSTATUS5 0x39
|
||||
|
||||
#define RT5025_INACIRQ_MASK 0x40
|
||||
#define RT5025_INUSBIRQ_MASK 0x08
|
||||
#define RT5025_ADAPIRQ_MASK (RT5025_INACIRQ_MASK|RT5025_INUSBIRQ_MASK)
|
||||
|
||||
#define RT5025_REG_GAUGEIRQEN 0x50
|
||||
#define RT5025_REG_GAUGEIRQFLG 0x51
|
||||
#define RT5025_FLG_TEMP 0x30
|
||||
#define RT5025_FLG_VOLT 0x07
|
||||
|
||||
5
include/linux/mfd/rt5025-misc.h
Executable file → Normal file
5
include/linux/mfd/rt5025-misc.h
Executable file → Normal file
@@ -2,12 +2,13 @@
|
||||
* include/linux/mfd/rt5025-misc.h
|
||||
* Include header file for Richtek RT5025 PMIC Misc
|
||||
*
|
||||
* Copyright (C) 2013 Richtek Electronics
|
||||
* Copyright (C) 2013 Richtek Technology Corp.
|
||||
* cy_huang <cy_huang@richtek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
* published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_RT5025_MISC_H
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <linux/android_alarm.h>
|
||||
|
||||
#define RT5025_DEVICE_NAME "RT5025"
|
||||
#define RT5025_DRV_VER "1.0.2_R"
|
||||
#define RT5025_DRV_VER "1.0.4_R"
|
||||
|
||||
enum {
|
||||
RT5025_RSTDELAY1_100MS,
|
||||
@@ -422,6 +422,7 @@ struct rt5025_power_info {
|
||||
struct delayed_work usb_detect_work;
|
||||
int usb_cnt;
|
||||
int chg_term;
|
||||
int otg_en;
|
||||
unsigned ac_online:1;
|
||||
unsigned usb_online:1;
|
||||
unsigned chg_stat:3;
|
||||
@@ -612,6 +613,7 @@ struct rt5025_platform_data {
|
||||
int (*pre_init)(struct rt5025_chip *rt5025_chip);
|
||||
/** Called after subdevices are set up */
|
||||
int (*post_init)(void);
|
||||
int (*set_otg_enable)(int);
|
||||
int intr_pin;
|
||||
};
|
||||
|
||||
@@ -620,6 +622,9 @@ extern void rt5025_power_off(void);
|
||||
#endif /* CONFIG_MFD_RT5025_MISC */
|
||||
|
||||
#ifdef CONFIG_POWER_RT5025
|
||||
extern int rt5025_ext_set_charging_buck(int);
|
||||
extern int rt5025_set_charging_buck(struct i2c_client *, int);
|
||||
extern int rt5025_set_charging_current_switch(struct i2c_client *, int);
|
||||
extern void rt5025_gauge_set_status(struct rt5025_battery_info *, int);
|
||||
extern void rt5025_gauge_set_online(struct rt5025_battery_info *, bool);
|
||||
extern void rt5025_gauge_irq_handler(struct rt5025_battery_info *, u8);
|
||||
|
||||
Reference in New Issue
Block a user