static void isp1704_charger_work(struct work_struct *data) { int detect; struct isp1704_charger *isp = container_of(data, struct isp1704_charger, work); /* * FIXME Only supporting dedicated chargers even though isp1704 can * detect HUB and HOST chargers. If the device has already been * enumerated, the detection will break the connection. */ if (isp->otg->state != OTG_STATE_B_IDLE) return; /* disable data pullups */ if (isp->otg->gadget) usb_gadget_disconnect(isp->otg->gadget); /* detect charger */ detect = isp1704_charger_detect(isp); if (detect) { isp->present = detect; power_supply_changed(&isp->psy); } /* enable data pullups */ if (isp->otg->gadget) usb_gadget_connect(isp->otg->gadget); }
static inline int isp1704_charger_detect_dcp(struct isp1704_charger *isp) { if (isp1704_charger_detect(isp) && isp1704_charger_type(isp) == POWER_SUPPLY_TYPE_USB_DCP) return true; else return false; }
static void isp1704_charger_work(struct work_struct *data) { int detect; unsigned long event; unsigned power; struct isp1704_charger *isp = container_of(data, struct isp1704_charger, work); static DEFINE_MUTEX(lock); event = isp->event; power = isp->max_power; mutex_lock(&lock); if (event != USB_EVENT_NONE) isp1704_charger_set_power(isp, 1); switch (event) { case USB_EVENT_VBUS: isp->online = true; /* detect charger */ detect = isp1704_charger_detect(isp); if (detect) { isp->present = detect; isp->psy.type = isp1704_charger_type(isp); } switch (isp->psy.type) { case POWER_SUPPLY_TYPE_USB_DCP: isp->current_max = 1800; break; case POWER_SUPPLY_TYPE_USB_CDP: /* * Only 500mA here or high speed chirp * handshaking may break */ isp->current_max = 500; /* FALLTHROUGH */ case POWER_SUPPLY_TYPE_USB: default: /* enable data pullups */ if (isp->phy->otg->gadget) usb_gadget_connect(isp->phy->otg->gadget); } break; case USB_EVENT_NONE: isp->online = false; isp->current_max = 0; isp->present = 0; isp->current_max = 0; isp->psy.type = POWER_SUPPLY_TYPE_USB; /* * Disable data pullups. We need to prevent the controller from * enumerating. * * FIXME: This is here to allow charger detection with Host/HUB * chargers. The pullups may be enabled elsewhere, so this can * not be the final solution. */ if (isp->phy->otg->gadget) usb_gadget_disconnect(isp->phy->otg->gadget); isp1704_charger_set_power(isp, 0); break; case USB_EVENT_ENUMERATED: if (isp->present) isp->current_max = 1800; else isp->current_max = power; break; default: goto out; } power_supply_changed(&isp->psy); out: mutex_unlock(&lock); }