[PATCH] jz battery driver cleanup

ZhangJieJing kzjeef at gmail.com
Fri Sep 18 14:22:46 EDT 2009


Hi, xiangfu ,

sorry , this one is not good enough.
please ignore this.

---
Best regards,
Zhang Jiejing


On Sat, Sep 19, 2009 at 2:17 AM, JieJing.Zhang <kzjeef at gmail.com> wrote:

> Signed-off-by: JieJing.Zhang <kzjeef at gmail.com>
> ---
>  .../xburst/files-2.6.31/drivers/power/jz_battery.c |   58
> +++++++++++++-------
>  1 files changed, 39 insertions(+), 19 deletions(-)
>
> diff --git a/target/linux/xburst/files-2.6.31/drivers/power/jz_battery.c
> b/target/linux/xburst/files-2.6.31/drivers/power/jz_battery.c
> index 80b3747..514f2d2 100755
> --- a/target/linux/xburst/files-2.6.31/drivers/power/jz_battery.c
> +++ b/target/linux/xburst/files-2.6.31/drivers/power/jz_battery.c
> @@ -28,10 +28,10 @@
>  #define dprintk(x...) while(0){}
>  #endif
>
> -#define JZ_BAT_MAX_VOLTAGE 4200000 // uV
> +/* uV */
> +#define JZ_BAT_MAX_VOLTAGE 4200000
>  #define JZ_BAT_MIN_VOLTAGE 3600000
>
> -static DEFINE_MUTEX(bat_lock);
>  struct workqueue_struct *monitor_wqueue;
>  struct delayed_work bat_work;
>  struct mutex work_lock;
> @@ -54,7 +54,7 @@ static int jz_get_power_prop(struct power_supply *psy,
>                if (psy->type == POWER_SUPPLY_TYPE_MAINS)
>                        val->intval = !__gpio_get_pin(GPIO_DC_DETE_N);
>                else
> -                       val->intval = __gpio_get_pin(GPIO_USB_DETE);
> +                       val->intval = (!!__gpio_get_pin(GPIO_USB_DETE));
>                break;
>        default:
>                return -EINVAL;
> @@ -92,13 +92,26 @@ static unsigned long jz_read_bat(struct power_supply
> *bat_ps)
>  {
>        unsigned long val;
>        if (CFG_PBAT_DIV == 1)
> -               val = (((unsigned long long)jz_read_battery() * 7500000))
> >> 12;
> +               val = (((unsigned long long)jz_read_battery() * 7500000L)
> >> 12) + 33000L;
>        else
> -               val = (((unsigned long long)jz_read_battery() *
> CFG_PBAT_DIV * 2500000)) >> 12;
> -       dprintk("--raw_batter_vol=%d uV\n", val);
> +               val = ((unsigned long long)jz_read_battery() * CFG_PBAT_DIV
> * 2500000L) >> 12;
> +       dev_dbg(bat_ps->dev, "%s: raw_batter_vol = %d uV\n",__func__,val);
>        return val;
>  }
>
> +static int jz_bat_get_capacity(struct power_supply *bat_ps)
> +{
> +       int ret;
> +       ret = (jz_read_bat(bat_ps) - JZ_BAT_MIN_VOLTAGE) * 100
> +               / (JZ_BAT_MAX_VOLTAGE - JZ_BAT_MIN_VOLTAGE);
> +       if (ret > 100) {
> +               dev_warn(bat_ps->dev, "%s: capacity=%d which exceeds 100,"
> +                        "set to 100\n", __func__, ret);
> +               ret = 100;
> +       }
> +       return ret;
> +}
> +
>  static int jz_bat_get_property(struct power_supply *bat_ps,
>                            enum power_supply_property psp,
>                            union power_supply_propval *val)
> @@ -111,19 +124,20 @@ static int jz_bat_get_property(struct power_supply
> *bat_ps,
>                val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
>                break;
>        case POWER_SUPPLY_PROP_HEALTH:
> -               if(jz_read_bat(bat_ps) < 3600000) {
> -                       dprintk("--battery dead\n");
> +               if(jz_read_bat(bat_ps) < JZ_BAT_MIN_VOLTAGE) {
> +                       dev_dbg(bat_ps->dev, "%s: battery is dead,"
> +                               "voltage too low!\n", __func__);
>                        val->intval = POWER_SUPPLY_HEALTH_DEAD;
>                } else {
> -                       dprintk("--battery good\n");
> +                       dev_dbg(bat_ps->dev, "%s: battery is good,"
> +                               "voltage normal.\n", __func__);
>                        val->intval = POWER_SUPPLY_HEALTH_GOOD;
>                }
>                break;
>        case POWER_SUPPLY_PROP_CAPACITY:
> -               val->intval = (jz_read_bat(bat_ps) - 3600000) * 100 /
> (4200000 - 3600000);
> -               if (val->intval > 100)
> -                       val->intval = 100;
> -               dprintk("--battery_capacity=%d\%\n",val->intval);
> +               val->intval = jz_bat_get_capacity(bat_ps);
> +               dev_dbg(bat_ps->dev, "%s: battery_capacity = %d\%\n",
> +                       __func__, val->intval);
>                break;
>        case POWER_SUPPLY_PROP_VOLTAGE_NOW:
>                val->intval = jz_read_bat(bat_ps);
> @@ -140,7 +154,8 @@ static int jz_bat_get_property(struct power_supply
> *bat_ps,
>                break;
>        case POWER_SUPPLY_PROP_TEMP:
>        case POWER_SUPPLY_PROP_VOL:
> -               val->intval = 0; // reading TEMP and VOL aren't supported
> +               /* reading TEMP and VOL aren't supported */
> +               val->intval = 0;
>                break;
>        default:
>                return -EINVAL;
> @@ -174,12 +189,16 @@ static void jz_bat_update(struct power_supply
> *bat_ps)
>                bat_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
>        }
>
> -       dprintk("--battery status=%s\n", status_text[bat_status]);
> +       dev_dbg(bat_ps->dev, "%s: battery status=%s\n",
> +               __func__, status_text[bat_status]);
> +
>        if ((old_status != bat_status) ||
>            (old_batt_vol - batt_vol > 50000)) {
> -               pr_debug("%s %s -> %s\n", bat_ps->name,
> -                               status_text[old_status],
> -                               status_text[bat_status]);
> +               dev_dbg(bat_ps->dev, "%s %s -> %s\n",
> +                        bat_ps->name,
> +                        status_text[old_status],
> +                        status_text[bat_status]);
> +
>                power_supply_changed(bat_ps);
>        }
>
> @@ -212,7 +231,8 @@ struct power_supply bat_ps = {
>
>  static void jz_bat_work(struct work_struct *work)
>  {
> -       const int interval = HZ * 6;
> +       /* query interval too small will increase system workload*/
> +       const int interval = HZ * 30;
>
>        jz_bat_update(&bat_ps);
>        queue_delayed_work(monitor_wqueue, &bat_work, interval);
> --
> 1.6.0.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.en.qi-hardware.com/pipermail/discussion/attachments/20090919/625ce3c5/attachment.htm>


More information about the discussion mailing list


interactive