static int sec_bat_check_cable_callback(void) { struct usb_gadget *gadget = platform_get_drvdata(&s3c_device_usbgadget); bool attach = true; int adc_1, adc_2, avg_adc; if (!charger_supply) { charger_supply = power_supply_get_by_name("sec-charger"); if (!charger_supply) pr_err("%s: failed to get power supplies\n", __func__); } /* ADC check margin (300~500ms) */ msleep(150); usb_switch_lock(); usb_switch_set_path(USB_PATH_ADCCHECK); adc_1 = stmpe811_get_adc_data(6); adc_2 = stmpe811_get_adc_data(6); avg_adc = (adc_1 + adc_2)/2; usb_switch_clr_path(USB_PATH_ADCCHECK); usb_switch_unlock(); pr_info("[BAT] %s: Adc value (%d)\n", __func__, avg_adc); attach = !gpio_get_value(GPIO_TA_nCONNECTED) ? true : false; if(attach) { if(avg_adc > TA_ADC_LOW) current_cable_type = POWER_SUPPLY_TYPE_MAINS; else current_cable_type = POWER_SUPPLY_TYPE_USB; } else current_cable_type = POWER_SUPPLY_TYPE_BATTERY; /* temp code : only set vbus enable when usb attaced */ if (gadget) { if (attach) usb_gadget_vbus_connect(gadget); else usb_gadget_vbus_disconnect(gadget); } #if 0 pr_info("%s: Cable type(%s), Attach(%d), Adc(%d)\n", __func__, current_cable_type == POWER_SUPPLY_TYPE_BATTERY ? "Battery" : current_cable_type == POWER_SUPPLY_TYPE_USB ? "USB" : "TA", attach, adc); #endif return current_cable_type; }
static int acc_get_adc_accessroy_id(struct s3c_adc_client *padc) { int adc_data; #if defined(CONFIG_STMPE811_ADC) adc_data = stmpe811_get_adc_data(ACCESSORY_ID_ADC_CH); #else adc_data = s3c_adc_read(padc, ACCESSORY_ID_ADC_CH); #endif /* ACC_CONDEV_DBG("[ACC] adc_data = %d..\n",adc_data); */ return adc_data; }
static int sec_bat_adc_ic_read(unsigned int channel) { int data = 0; int max_voltage = 3300; switch (channel) { case SEC_BAT_ADC_CHANNEL_CABLE_CHECK: data = stmpe811_get_adc_data(SMTPE811_CHANNEL_ADC_CHECK_1); data = data * max_voltage / 4095; /* 4096 ? */ break; } return data; }