Example #1
0
void rk28_usb( void )
{
        if( get_msc_connect_flag() &&  adb_enabled() ){
                usb_power_suspend = 2;
                return;
        }
        adb_function_enable(1);
        rk28_usb_force_resume();
        usb_power_suspend = 2;
        dwc_otg_reset();
}
Example #2
0
static int rk2918_get_bat_capacity_raw(int BatVoltage)
{
    int i = 0;
	int capacity = 0;
	int *p = adc_raw_table_bat;
#ifdef RK29_USB_CHARGE_SUPPORT
	if(gpio_get_value(RK29_PIN0_PA0)==0)//有USB插入。。
	{
		//printk("====>USB inster, gBatChargeStatus = %d  \n", gBatChargeStatus);
		if(0 == get_msc_connect_flag()) //(gBatChargeStatus == 1)
		{
			p = adc_raw_table_ac;
			usb_charging_on = 0;
		}
		else
		{
			p = adc_raw_table_usb;
			usb_charging_on = 1;
		}
	}
#else 
    if (gBatChargeStatus == 1)
    {
        p = adc_raw_table_ac;
    }
#endif
	
	if(BatVoltage >= p[BAT_ADC_TABLE_LEN - 1])
	{
	    //当电压超过最大值
	    capacity = 100;
	}	
	else if(BatVoltage <= p[0])
	{
	    //当电压低于最小值
	    capacity = 0;
	}
	else
	{
    	//计算容量
    	for(i = 0; i < BAT_ADC_TABLE_LEN - 1; i++)
        {
    		
    		if((p[i] <= BatVoltage) && (BatVoltage < p[i+1]))
    		{
    			capacity = i * 10 + ((BatVoltage - p[i]) * 10) / (p[i+1] - p[i]);
    			break;
    		}
    	}
    }	
	//DBG("bryan-->BatVoltage = %d, capacity = %d\n", BatVoltage, capacity);
    return capacity;
}
static int rk29_adc_battery_get_charge_level(struct rk29_adc_battery_data *bat)
{
	int charge_on = 0;
	struct rk29_adc_battery_platform_data *pdata = bat->pdata;

#if defined(CONFIG_BATTERY_RK29_AC_CHARGE)
	/* AX: In this case the battery manager signals the presence of the
	 * AC supply. It does not signal if it really charges.
	 * It would make more sense to supply the charging information represented
	 * by
	 */
	if (pdata->dc_det_pin != INVALID_GPIO)
	{
		if (gpio_get_value (pdata->dc_det_pin) == pdata->dc_det_level)
		{
			charge_on = 1;
			goto charge_out;
		}
	}
#endif

#if defined(CONFIG_BATTERY_RK29_USB_CHARGE)
	if (charge_on == 0)
	{
		if (suspend_flag) return;

		if (1 == dwc_vbus_status()) //��⵽USB���룬�����޷�ʶ���Ƿ��dz����
		{ //ͨ����ʱ���PCʶ���־�����ʱ��ⲻ����˵���dz��
			if (0 == get_msc_connect_flag())
			{ //��������ʱ�����һ��ʱ��֮�󣬿�ʼ������״̬
				if (++gBatUsbChargeCnt >= NUM_USBCHARGE_IDENTIFY_TIMES)
				{
					gBatUsbChargeCnt = NUM_USBCHARGE_IDENTIFY_TIMES + 1;
					charge_on = 1;
					goto charge_out;
				}
			} //���򣬲�������ģʽ
		}
		else
		{
			gBatUsbChargeCnt = 0;
			if (2 == dwc_vbus_status())
			{
				charge_on = 1;
				goto charge_out;
			}
		}
	}
#endif

	charge_out: return charge_on;
}
static int rk29_adc_battery_get_charge_level(struct rk29_adc_battery_data *bat)
{
    int charge_on = 0;
    struct rk29_adc_battery_platform_data *pdata = bat->pdata;
    
#if defined(CONFIG_BATTERY_RK29_AC_CHARGE)
    if (pdata->dc_det_pin != INVALID_GPIO)
    {
        if (gpio_get_value (pdata->dc_det_pin) == pdata->dc_det_level)
        {
            charge_on = 1;
            wake_lock(&batt_wake_lock);
        }
        else
            wake_unlock(&batt_wake_lock);
    }
#endif
    
#if defined(CONFIG_BATTERY_RK29_USB_CHARGE)
    if (charge_on == 0)
    {
        if (suspend_flag) return;
            
        if (1 == dwc_vbus_status())         //检测到USB插入,但是无法识别是否是充电器
        {                                   //通过延时检测PC识别标志,如果超时检测不到,说明是充电
            if (0 == get_msc_connect_flag())
            {                               //插入充电器时间大于一定时间之后,开始进入充电状态
                if (++gBatUsbChargeCnt >= NUM_USBCHARGE_IDENTIFY_TIMES)
                {
                    gBatUsbChargeCnt = NUM_USBCHARGE_IDENTIFY_TIMES + 1;
                    charge_on = 1;
                }
            }                               //否则,不进入充电模式
        }                   
        else
        {
            gBatUsbChargeCnt = 0;
            if (2 == dwc_vbus_status()) 
            {
                charge_on = 1;
            }
        }
    }
#endif

    return charge_on;
}
static int rk2918_usb_get_property(struct power_supply *psy, 
				    enum power_supply_property psp,
				    union power_supply_propval *val)
{
	charger_type_t charger;
	charger =  CHARGER_USB;

	switch (psp) {
	case POWER_SUPPLY_PROP_ONLINE:
		if (psy->type == POWER_SUPPLY_TYPE_USB)
			val->intval = get_msc_connect_flag();
		printk("%s:%d\n",__FUNCTION__,val->intval);
		break;

	default:
		return -EINVAL;
	}
	
	return 0;

}
Example #6
0
//extern int suspend_flag;
static int rk30_adc_battery_get_charge_level(struct rk30_adc_battery_data *bat)
{
	int charge_on = 0;
	struct rk30_adc_battery_platform_data *pdata = bat->pdata;

#if defined (CONFIG_BATTERY_RK30_AC_CHARGE)
	if (pdata->dc_det_pin != INVALID_GPIO){
		if (gpio_get_value (pdata->dc_det_pin) == pdata->dc_det_level){
			charge_on = 1;
		}
	}
#endif

#if defined  (CONFIG_BATTERY_RK30_USB_CHARGE)
	if (charge_on == 0){
		if (suspend_flag)
			return;
		if (1 == dwc_vbus_status()) {

			if (0 == get_msc_connect_flag()) {
				if (++gBatUsbChargeCnt >= NUM_USBCHARGE_IDENTIFY_TIMES) {
					gBatUsbChargeCnt = NUM_USBCHARGE_IDENTIFY_TIMES + 1;
					charge_on = 1;
				}
			}
		}                   
		else {
			gBatUsbChargeCnt = 0;
			if (2 == dwc_vbus_status()) {
				charge_on = 1;
			}
		}
	}
#endif
	return charge_on;
}
static void rk2918_get_charge_status(void)
{
    int charge_on = 0;
    
    if (gBatteryData->dc_det_pin != INVALID_GPIO)
    {
        if (gpio_get_value (gBatteryData->dc_det_pin) == gBatteryData->dc_det_level)
        {
            charge_on = 1;
        }
    }
    
#ifdef RK29_USB_CHARGE_SUPPORT
    if (charge_on == 0)
    {
        if (suspend_flag) return;
            
        if (1 == dwc_vbus_status())         //检测到USB插入,但是无法识别是否是充电器
        {                                   //通过延时检测PC识别标志,如果超时检测不到,说明是充电
            if (0 == get_msc_connect_flag())
            {                               //插入充电器时间大于一定时间之后,开始进入充电状态
                if (++gBatUsbChargeCnt >= NUM_USBCHARGE_IDENTIFY_TIMES)
                {
                    gBatUsbChargeCnt = NUM_USBCHARGE_IDENTIFY_TIMES + 1;
                    charge_on = 1;
                }
            }                               //否则,不进入充电模式
            #if defined(CONFIG_MACH_RK29_ACH8)
            charge_on = 1;
            #endif
        }                   
        else
        {
            gBatUsbChargeCnt = 0;
            if (2 == dwc_vbus_status()) 
            {
                charge_on = 1;
            }
        }
    }
#endif
        
    if (charge_on)
    {
        if(gBatChargeStatus !=1) 
        {            
            gBatChargeStatus = 1;
            gBatStatusChangeCnt = 0;        //状态变化开始计数
            rk2918_charge_enable();
        }
    } 
    else 
    {
        if(gBatChargeStatus != 0) 
        {
            gBatChargeStatus = 0;
            gBatStatusChangeCnt = 0;        //状态变化开始计数
            rk2918_charge_disable();
        }
    }
}
Example #8
0
static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
{
	struct twl6030_usb *twl = _twl;
	int status;
	u8 vbus_state, hw_state, misc2_data;
	unsigned charger_type;

	hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);

	vbus_state = twl6030_readb(twl, TWL_MODULE_MAIN_CHARGE,
						CONTROLLER_STAT1);
	vbus_state = vbus_state & VBUS_DET;

	/* Ignore charger events other than VBUS */
	if (vbus_state == twl->prev_vbus)
		return IRQ_HANDLED;

	if ((vbus_state) && !(hw_state & STS_USB_ID)) {
		/* Program MISC2 register and set bit VUSB_IN_VBAT */
		misc2_data = twl6030_readb(twl, TWL6030_MODULE_ID0,
						TWL6030_MISC2);
		misc2_data |= 0x10;
		twl6030_writeb(twl, TWL6030_MODULE_ID0, misc2_data,
						TWL6030_MISC2);

		regulator_enable(twl->usb3v3);
		twl6030_phy_suspend(&twl->otg, 0);
		if(0 == get_msc_connect_flag())
			charger_type = POWER_SUPPLY_TYPE_USB_DCP;
		else
			charger_type = POWER_SUPPLY_TYPE_USB;
		
		twl6030_phy_suspend(&twl->otg, 1);
		if ((charger_type == POWER_SUPPLY_TYPE_USB_CDP)
				|| (charger_type == POWER_SUPPLY_TYPE_USB)) {

			status = USB_EVENT_VBUS;
			twl->otg.default_a = false;
			twl->asleep = 1;
			twl->otg.state = OTG_STATE_B_IDLE;
			twl->linkstat = status;
			twl->otg.last_event = status;
		} else if (charger_type == POWER_SUPPLY_TYPE_USB_DCP) {
			regulator_disable(twl->usb3v3);
			status = USB_EVENT_CHARGER;
			twl->usb_cinlimit_mA = 1800;
			twl->otg.state = OTG_STATE_B_IDLE;
			twl->linkstat = status;
			twl->otg.last_event = status;
		} else {
			regulator_disable(twl->usb3v3);
			goto vbus_notify;
		}
		atomic_notifier_call_chain(&twl->otg.notifier,
				status, &charger_type);
	}
	if (!vbus_state) {
		status = USB_EVENT_NONE;
		twl->linkstat = status;
		twl->otg.last_event = status;
		atomic_notifier_call_chain(&twl->otg.notifier,
				status, twl->otg.gadget);
		if (twl->asleep) {
			regulator_disable(twl->usb3v3);
			twl->asleep = 0;
			/* Program MISC2 register and clear bit VUSB_IN_VBAT */
			misc2_data = twl6030_readb(twl, TWL6030_MODULE_ID0,
							TWL6030_MISC2);
			misc2_data &= 0xEF;
			twl6030_writeb(twl, TWL6030_MODULE_ID0, misc2_data,
							TWL6030_MISC2);
		}
	}

vbus_notify:
	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
	twl->prev_vbus = vbus_state;
	return IRQ_HANDLED;
}
Example #9
0
void rk2918_get_charge_status(void)
{
    int charge_on = 0;
    int tmp = get_msc_connect_flag();
	int flag = dwc_vbus_status();
	static  char  last_flag = 0;


	//printk("%s...........get_msc_connect_flag=%d,dwc_vbus_status=%d\n",__FUNCTION__,tmp,flag);
#ifdef RK29_USB_CHARGE_SUPPORT
    if ((gpio_get_value(RK29_PIN0_PA0) == 0) &&(charge_on == 0) )
    {
        //if (suspend_flag) return;
 #if 1           
        if (1 == flag)         //USB PC
        {   
			charge_on = 1;
			//printk("PC\n");
        } 
 
        else
        {
             if (2 == flag)  //充电器
            {
                charge_on = 1;
				//printk("charger\n");
            }
        }
#endif
#if 0
	if (usb_insert == 2)
	{
		charge_on = 1;
		//printk("%s.......charging  with charger\n",__FUNCTION__);
	}   
#endif 
    }
	
#endif
//printk("%s...dwc_vbus_status=%d,get_msc_connect_flag=%d\n",__FUNCTION__,dwc_vbus_status(),tmp);
   if (charge_on)
    {
        if((gBatChargeStatus !=1) || (last_flag != flag)) 
        {            
            gBatChargeStatus = 1;
			last_flag = flag;
            gBatStatusChangeCnt = 0;        //状态变化开始计数
            wake_lock(&battery_wake_lock);
			if (flag == 2)
			{
				rk2918_charge_enable();
			}		
			
        }

    } 
    else 
    {
        if(gBatChargeStatus != 0) 
        {
            gBatChargeStatus = 0;
            gBatStatusChangeCnt = 0;        //状态变化开始计数
            wake_unlock(&battery_wake_lock);
		    rk2918_charge_disable();
			
        }
    }

}
Example #10
0
static void rk2918_get_charge_status(void)
{
    int charge_on = 0;
    
    if (gBatteryData->dc_det_pin != INVALID_GPIO)
    {
        if (gpio_get_value (gBatteryData->dc_det_pin) == gBatteryData->dc_det_level)
        {
            charge_on = 1;
        }
    }
    
#ifdef RK29_USB_CHARGE_SUPPORT
    if (charge_on == 0)
    {
        if (suspend_flag) return;
            
        if (1 == dwc_vbus_status())         //��⵽USB���룬�����޷�ʶ���Ƿ��dz����
        {                                   //ͨ����ʱ���PCʶ���־�����ʱ��ⲻ����˵���dz��
            if (0 == get_msc_connect_flag())
            {                               //��������ʱ�����һ��ʱ��֮�󣬿�ʼ������״̬
                if (++gBatUsbChargeCnt >= NUM_USBCHARGE_IDENTIFY_TIMES)
                {
                    gBatUsbChargeCnt = NUM_USBCHARGE_IDENTIFY_TIMES + 1;
                    charge_on = 1;
                }
            }                               //���򣬲�������ģʽ
            #if defined(CONFIG_MACH_RK29_ACH8)
            charge_on = 1;
            #endif
        }                   
        else
        {
            gBatUsbChargeCnt = 0;
            if (2 == dwc_vbus_status()) 
            {
                charge_on = 1;
            }
        }
    }
#endif
        
    if (charge_on)
    {
        if(gBatChargeStatus !=1) 
        {            
            gBatChargeStatus = 1;
            gBatStatusChangeCnt = 0;        //״̬�仯��ʼ����
            rk2918_charge_enable();
        }
    } 
    else 
    {
        if(gBatChargeStatus != 0) 
        {
            gBatChargeStatus = 0;
            gBatStatusChangeCnt = 0;        //״̬�仯��ʼ����
            rk2918_charge_disable();
        }
    }
}