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;
}
Beispiel #2
0
static ssize_t store_usb_sel(struct device *dev,
			     struct device_attribute *attr,
			     const char *buf, size_t count)
{
	int ret, usb_sel;
	ret = sscanf(buf, "%d", &usb_sel);

	if (ret != 1)
		return -EINVAL;

	pr_err("%s: %d\n", __func__, usb_sel);
	/* 1 for AP, 0 for CP */
	if (usb_sel == 1)
		usb_switch_clr_path(USB_PATH_CP);
	else if (usb_sel == 0)
		usb_switch_set_path(USB_PATH_CP);

	return count;
}