Esempio n. 1
0
/*
 * vt1603_reg_dump - dubug function, for dump vt1603 related registers
 * @bat_drv: vt1603 battery driver data
 */
static void vt1603_reg_dump(struct vt1603_bat_drvdata *bat_drv, u8 addr, int len)
{
    u8 i;
    for (i = addr; i < addr + len; i += 2)
        dbg("reg[%d]:0x%02X,  reg[%d]:0x%02X\n", 
            i, vt1603_get_reg8(bat_drv, i), i + 1, vt1603_get_reg8(bat_drv, i + 1));
}
Esempio n. 2
0
/*
 * vt1603_get_bat_convert_data - get battery converted data
 * @bat_drv: vt1603 battery driver data
 */
static u16 vt1603_get_bat_convert_data(struct vt1603_bat_drvdata *bat_drv)
{
    u8 data_l, data_h;

    data_l = vt1603_get_reg8(bat_drv, VT1603_DATL_REG);
    data_h = vt1603_get_reg8(bat_drv, VT1603_DATH_REG);
    return ADC_DATA(data_l, data_h);
}
Esempio n. 3
0
static void vt1603_bat_power_up(struct vt1603_bat_drvdata *bat_drv)
{
    if (vt1603_get_reg8(bat_drv, VT1603_PWC_REG) != 0x08)
        vt1603_set_reg8(bat_drv, VT1603_PWC_REG, 0x08);

    return ;
}
Esempio n. 4
0
/*
 * vt1603_bat_work - vt1603 battery workqueue routine, switch 
 *  vt1603 working mode to battery detecting
 * @work: battery work struct
 */
static void vt1603_bat_work(struct work_struct *work)
{
    int tmp = 0;
    int timeout, i = 0;
    int bat_arrary[DFLT_BAT_VAL_AVG]={0};
    struct vt1603_bat_drvdata *bat_drv;

    dbg("Enter\n");
    bat_drv = container_of(work, struct vt1603_bat_drvdata, work);
    if (unlikely(vt1603_get_pen_state(bat_drv) == TS_PENDOWN_STATE)) {
        dbg("vt1603 pendown when battery detect\n");
        goto out;
    }
	
    /* enable sar-adc power and clock        */
    vt1603_bat_power_up(bat_drv);
    /* enable pen down/up to avoid miss irq  */
    vt1603_bat_pen_manual(bat_drv);
    /* switch vt1603 to battery detect mode  */
    vt1603_switch_to_bat_mode(bat_drv);
    /* do conversion use battery manual mode */
    vt1603_setbits(bat_drv, VT1603_INTS_REG, BIT0);
    vt1603_set_reg8(bat_drv, VT1603_CR_REG, BIT4);
	
    for(i=0; i<DFLT_BAT_VAL_AVG; i++){
        timeout = 2000;
    	while(--timeout && (vt1603_get_reg8(bat_drv, VT1603_INTS_REG) & BIT0)==0)
		;

        if(timeout){
	        if(vt1603_get_bat_data(bat_drv,&bat_arrary[i]) < 0) 
                dbg_err("vt1603 get bat adc data Failed!\n");
	    }else {
		    dbg_err("wait adc end timeout ?!\n");
		    goto out;
	    }
		
		vt1603_setbits(bat_drv, VT1603_INTS_REG, BIT0);
		vt1603_set_reg8(bat_drv, VT1603_CR_REG, BIT4);//start manual ADC mode
    }
    
    tmp = vt1603_bat_avg(bat_arrary,DFLT_BAT_VAL_AVG);
    bat_drv->bat_new = tmp;
    vt1603_fifo_push(&Bat_buf, tmp);
    vt1603_fifo_avg(Bat_buf, &tmp);
    bat_drv->bat_val = tmp;
    	
    //printk(KERN_ERR"reported battery val:%d, new val:%d\n",tmp, bat_drv->bat_new);
out:
    vt1603_clrbits(bat_drv, VT1603_INTCR_REG, BIT7);
    vt1603_setbits(bat_drv, VT1603_INTS_REG, BIT0 | BIT3);
    vt1603_set_reg8(bat_drv, VT1603_CR_REG, BIT1);
    mod_timer(&bat_drv->bat_tmr, jiffies + msecs_to_jiffies(DFLT_POLLING_BAT_INTERVAL* 1000));
    dbg("Exit\n\n\n");
    return ;
}
Esempio n. 5
0
/*
 * vt1603_get_pen_state - get touch panel pen state from vt1603 
 *         interrup status register
 * @bat_drv: vt1603 battery driver data
 */
static inline int vt1603_get_pen_state(struct vt1603_bat_drvdata *bat_drv)
{
    u8 state ;

    if(!bat_drv->tch_enabled)
        return TS_PENUP_STATE;
    
    state = vt1603_get_reg8(bat_drv, VT1603_INTS_REG);
    return (((state & BIT4) == 0) ? TS_PENDOWN_STATE : TS_PENUP_STATE);
}
Esempio n. 6
0
/*
 * vt1603_clrbits - write bit0 to related register's bit
 * @bat_drv: vt1603 battery driver data
 * @reg: vt1603 register address
 * @mask:bit setting mask
 */
static void vt1603_clrbits(struct vt1603_bat_drvdata *bat_drv, u8 reg, u8 mask)
{
    u8 tmp = vt1603_get_reg8(bat_drv, reg) & (~mask);
    vt1603_set_reg8(bat_drv, reg, tmp);
}
Esempio n. 7
0
/*
 * vt1603_bat_work - vt1603 battery workqueue routine, switch 
 *  vt1603 working mode to battery detecting
 * @work: battery work struct
 */
static void vt1603_bat_work(struct work_struct *work)
{
    u8 tmp = 0;
    u16 val = 0;
    int tout = 0;
    unsigned long now = 0;
    struct vt1603_bat_drvdata *bat_drv;

    bat_dbg("Enter\n");
    bat_drv = container_of(work, struct vt1603_bat_drvdata, work);
    if (unlikely(vt1603_get_pen_state(bat_drv) == TS_PENDOWN_STATE)) {
        bat_dbg("vt1603 pendown when battery detect\n");
        tout = 1000;
        goto out;
    }
    /* enable sar-adc power and clock        */
    vt1603_bat_power_up(bat_drv);
    /* enable pen down/up to avoid miss irq  */
    vt1603_bat_pen_manual(bat_drv);
    /* switch vt1603 to battery detect mode  */
    vt1603_switch_to_bat_mode(bat_drv);
    /* do conversion use battery manual mode */
    vt1603_setbits(bat_drv, VT1603_INTS_REG, BIT0);
    if (vt1603_get_reg8(bat_drv, VT1603_AMCR_REG) != 0x01) {
        tout = 1000;
        bat_dbg("vt1603 battery channel changed already?\n");
        goto out;
    }
    vt1603_set_reg8(bat_drv, VT1603_CR_REG, BIT4);
    now = jiffies;
    while (time_before(jiffies, now + msecs_to_jiffies(POLL_TOUT))) {
        tmp = vt1603_get_reg8(bat_drv, VT1603_INTS_REG);
        if (tmp & BIT0) {
            val = vt1603_get_bat_convert_data(bat_drv);
            bat_dbg("vt1603 battery value is %d\n", val);
            if (vt1603_get_reg8(bat_drv, VT1603_AMCR_REG) != 0x01) {
                tout = 1000;
                bat_dbg("vt1603 battery channel changed already?\n");
                goto out;
            }
            if (val < 2048) {
                tout = 1000;
                printk(KERN_ERR "vt1603 battery conversion failed?!\n");
                goto out;
            }
            bat_drv->bat_val = val;
            bat_drv->detect_time++;
            bat_drv->time_stamp = jiffies;
            tout = bat_drv->interval;
            goto out;
        }
    }
    bat_dbg("vt1603 battery detect failed, conversion timeout!\n");
    tout = 1000;
    goto out;

out:
    vt1603_clrbits(bat_drv, VT1603_INTCR_REG, BIT7);
    vt1603_setbits(bat_drv, VT1603_INTS_REG, BIT0 | BIT3);
    vt1603_set_reg8(bat_drv, VT1603_CR_REG, BIT1);
    mod_timer(&bat_drv->bat_tmr, jiffies + msecs_to_jiffies(tout));
    bat_dbg("Exit\n\n\n");
    return ;
}