Lines Matching refs:ext
117 static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts) in cht_wc_extcon_get_id() argument
143 static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext, in cht_wc_extcon_get_charger() argument
152 ret = regmap_read(ext->regmap, CHT_WC_USBSRC, &usbsrc); in cht_wc_extcon_get_charger()
154 dev_err(ext->dev, "Error reading usbsrc: %d\n", ret); in cht_wc_extcon_get_charger()
169 dev_warn(ext->dev, "Could not detect charger type\n"); in cht_wc_extcon_get_charger()
171 dev_warn(ext->dev, "Timeout detecting charger type\n"); in cht_wc_extcon_get_charger()
181 dev_warn(ext->dev, in cht_wc_extcon_get_charger()
184 ext->usb_type = POWER_SUPPLY_USB_TYPE_SDP; in cht_wc_extcon_get_charger()
189 ext->usb_type = POWER_SUPPLY_USB_TYPE_SDP; in cht_wc_extcon_get_charger()
192 ext->usb_type = POWER_SUPPLY_USB_TYPE_CDP; in cht_wc_extcon_get_charger()
197 ext->usb_type = POWER_SUPPLY_USB_TYPE_DCP; in cht_wc_extcon_get_charger()
200 ext->usb_type = POWER_SUPPLY_USB_TYPE_ACA; in cht_wc_extcon_get_charger()
205 static void cht_wc_extcon_set_phymux(struct cht_wc_extcon_data *ext, u8 state) in cht_wc_extcon_set_phymux() argument
209 ret = regmap_write(ext->regmap, CHT_WC_PHYCTRL, state); in cht_wc_extcon_set_phymux()
211 dev_err(ext->dev, "Error writing phyctrl: %d\n", ret); in cht_wc_extcon_set_phymux()
214 static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext, in cht_wc_extcon_set_5v_boost() argument
227 ret = regmap_write(ext->regmap, CHT_WC_VBUS_GPIO_CTLO, val); in cht_wc_extcon_set_5v_boost()
229 dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret); in cht_wc_extcon_set_5v_boost()
232 static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext, in cht_wc_extcon_set_otgmode() argument
238 ret = regmap_update_bits(ext->regmap, CHT_WC_CHGRCTRL1, in cht_wc_extcon_set_otgmode()
241 dev_err(ext->dev, "Error updating CHGRCTRL1 reg: %d\n", ret); in cht_wc_extcon_set_otgmode()
243 if (ext->vbus_boost && ext->vbus_boost_enabled != enable) { in cht_wc_extcon_set_otgmode()
245 ret = regulator_enable(ext->vbus_boost); in cht_wc_extcon_set_otgmode()
247 ret = regulator_disable(ext->vbus_boost); in cht_wc_extcon_set_otgmode()
250 dev_err(ext->dev, "Error updating Vbus boost regulator: %d\n", ret); in cht_wc_extcon_set_otgmode()
252 ext->vbus_boost_enabled = enable; in cht_wc_extcon_set_otgmode()
256 static void cht_wc_extcon_enable_charging(struct cht_wc_extcon_data *ext, in cht_wc_extcon_enable_charging() argument
262 ret = regmap_update_bits(ext->regmap, CHT_WC_CHGDISCTRL, in cht_wc_extcon_enable_charging()
265 dev_err(ext->dev, "Error updating CHGDISCTRL reg: %d\n", ret); in cht_wc_extcon_enable_charging()
269 static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext, in cht_wc_extcon_set_state() argument
272 extcon_set_state_sync(ext->edev, cable, state); in cht_wc_extcon_set_state()
274 extcon_set_state_sync(ext->edev, EXTCON_USB, state); in cht_wc_extcon_set_state()
277 static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) in cht_wc_extcon_pwrsrc_event() argument
282 bool ignore_get_charger_errors = ext->usb_host; in cht_wc_extcon_pwrsrc_event()
285 ext->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in cht_wc_extcon_pwrsrc_event()
287 ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); in cht_wc_extcon_pwrsrc_event()
289 dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret); in cht_wc_extcon_pwrsrc_event()
293 id = cht_wc_extcon_get_id(ext, pwrsrc_sts); in cht_wc_extcon_pwrsrc_event()
295 cht_wc_extcon_enable_charging(ext, false); in cht_wc_extcon_pwrsrc_event()
296 cht_wc_extcon_set_otgmode(ext, true); in cht_wc_extcon_pwrsrc_event()
302 cht_wc_extcon_set_otgmode(ext, false); in cht_wc_extcon_pwrsrc_event()
303 cht_wc_extcon_enable_charging(ext, true); in cht_wc_extcon_pwrsrc_event()
308 cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC); in cht_wc_extcon_pwrsrc_event()
312 ret = cht_wc_extcon_get_charger(ext, ignore_get_charger_errors); in cht_wc_extcon_pwrsrc_event()
318 cht_wc_extcon_set_phymux(ext, MUX_SEL_SOC); in cht_wc_extcon_pwrsrc_event()
321 if (cable != ext->previous_cable) { in cht_wc_extcon_pwrsrc_event()
322 cht_wc_extcon_set_state(ext, cable, true); in cht_wc_extcon_pwrsrc_event()
323 cht_wc_extcon_set_state(ext, ext->previous_cable, false); in cht_wc_extcon_pwrsrc_event()
324 ext->previous_cable = cable; in cht_wc_extcon_pwrsrc_event()
327 ext->usb_host = ((id == INTEL_USB_ID_GND) || (id == INTEL_USB_RID_A)); in cht_wc_extcon_pwrsrc_event()
328 extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host); in cht_wc_extcon_pwrsrc_event()
330 if (ext->usb_host) in cht_wc_extcon_pwrsrc_event()
338 ret = usb_role_switch_set_role(ext->role_sw, role); in cht_wc_extcon_pwrsrc_event()
340 dev_err(ext->dev, "Error setting USB-role: %d\n", ret); in cht_wc_extcon_pwrsrc_event()
342 if (ext->psy) in cht_wc_extcon_pwrsrc_event()
343 power_supply_changed(ext->psy); in cht_wc_extcon_pwrsrc_event()
348 struct cht_wc_extcon_data *ext = data; in cht_wc_extcon_isr() local
351 ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_IRQ, &irqs); in cht_wc_extcon_isr()
353 dev_err(ext->dev, "Error reading irqs: %d\n", ret); in cht_wc_extcon_isr()
357 cht_wc_extcon_pwrsrc_event(ext); in cht_wc_extcon_isr()
359 ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ, irqs); in cht_wc_extcon_isr()
361 dev_err(ext->dev, "Error writing irqs: %d\n", ret); in cht_wc_extcon_isr()
368 static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable) in cht_wc_extcon_sw_control() argument
373 ret = regmap_update_bits(ext->regmap, CHT_WC_CHGDISCTRL, in cht_wc_extcon_sw_control()
376 dev_err(ext->dev, in cht_wc_extcon_sw_control()
382 ret = regmap_update_bits(ext->regmap, CHT_WC_CHGRCTRL0, mask, val); in cht_wc_extcon_sw_control()
384 dev_err(ext->dev, "Error setting sw control: %d\n", ret); in cht_wc_extcon_sw_control()
389 static int cht_wc_extcon_find_role_sw(struct cht_wc_extcon_data *ext) in cht_wc_extcon_find_role_sw() argument
399 ext->role_sw = usb_role_switch_find_by_fwnode(fwnode); in cht_wc_extcon_find_role_sw()
402 return ext->role_sw ? 0 : -EPROBE_DEFER; in cht_wc_extcon_find_role_sw()
407 struct cht_wc_extcon_data *ext = data; in cht_wc_extcon_put_role_sw() local
409 usb_role_switch_put(ext->role_sw); in cht_wc_extcon_put_role_sw()
413 static int cht_wc_extcon_get_role_sw_and_regulator(struct cht_wc_extcon_data *ext) in cht_wc_extcon_get_role_sw_and_regulator() argument
417 ret = cht_wc_extcon_find_role_sw(ext); in cht_wc_extcon_get_role_sw_and_regulator()
421 ret = devm_add_action_or_reset(ext->dev, cht_wc_extcon_put_role_sw, ext); in cht_wc_extcon_get_role_sw_and_regulator()
432 ext->vbus_boost = devm_regulator_get_optional(ext->dev, "vbus"); in cht_wc_extcon_get_role_sw_and_regulator()
433 if (IS_ERR(ext->vbus_boost)) { in cht_wc_extcon_get_role_sw_and_regulator()
434 ret = PTR_ERR(ext->vbus_boost); in cht_wc_extcon_get_role_sw_and_regulator()
438 return dev_err_probe(ext->dev, ret, "getting Vbus regulator"); in cht_wc_extcon_get_role_sw_and_regulator()
448 struct cht_wc_extcon_data *ext = power_supply_get_drvdata(psy); in cht_wc_extcon_psy_get_prop() local
452 val->intval = ext->usb_type; in cht_wc_extcon_psy_get_prop()
455 val->intval = ext->usb_type ? 1 : 0; in cht_wc_extcon_psy_get_prop()
487 static int cht_wc_extcon_register_psy(struct cht_wc_extcon_data *ext) in cht_wc_extcon_register_psy() argument
489 struct power_supply_config psy_cfg = { .drv_data = ext }; in cht_wc_extcon_register_psy()
491 ext->psy = devm_power_supply_register(ext->dev, in cht_wc_extcon_register_psy()
494 return PTR_ERR_OR_ZERO(ext->psy); in cht_wc_extcon_register_psy()
500 struct cht_wc_extcon_data *ext; in cht_wc_extcon_probe() local
509 ext = devm_kzalloc(&pdev->dev, sizeof(*ext), GFP_KERNEL); in cht_wc_extcon_probe()
510 if (!ext) in cht_wc_extcon_probe()
513 ext->dev = &pdev->dev; in cht_wc_extcon_probe()
514 ext->regmap = pmic->regmap; in cht_wc_extcon_probe()
515 ext->previous_cable = EXTCON_NONE; in cht_wc_extcon_probe()
518 ext->edev = devm_extcon_dev_allocate(ext->dev, cht_wc_extcon_cables); in cht_wc_extcon_probe()
519 if (IS_ERR(ext->edev)) in cht_wc_extcon_probe()
520 return PTR_ERR(ext->edev); in cht_wc_extcon_probe()
537 cht_wc_extcon_set_5v_boost(ext, false); in cht_wc_extcon_probe()
542 ret = cht_wc_extcon_get_role_sw_and_regulator(ext); in cht_wc_extcon_probe()
552 ret = cht_wc_extcon_register_psy(ext); in cht_wc_extcon_probe()
557 ret = cht_wc_extcon_get_role_sw_and_regulator(ext); in cht_wc_extcon_probe()
566 ret = cht_wc_extcon_sw_control(ext, true); in cht_wc_extcon_probe()
571 cht_wc_extcon_enable_charging(ext, false); in cht_wc_extcon_probe()
574 ret = devm_extcon_dev_register(ext->dev, ext->edev); in cht_wc_extcon_probe()
576 dev_err(ext->dev, "Error registering extcon device: %d\n", ret); in cht_wc_extcon_probe()
580 ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); in cht_wc_extcon_probe()
582 dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret); in cht_wc_extcon_probe()
590 id = cht_wc_extcon_get_id(ext, pwrsrc_sts); in cht_wc_extcon_probe()
592 cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC); in cht_wc_extcon_probe()
595 cht_wc_extcon_pwrsrc_event(ext); in cht_wc_extcon_probe()
597 ret = devm_request_threaded_irq(ext->dev, irq, NULL, cht_wc_extcon_isr, in cht_wc_extcon_probe()
598 IRQF_ONESHOT, pdev->name, ext); in cht_wc_extcon_probe()
600 dev_err(ext->dev, "Error requesting interrupt: %d\n", ret); in cht_wc_extcon_probe()
605 ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ_MASK, mask); in cht_wc_extcon_probe()
607 dev_err(ext->dev, "Error writing irq-mask: %d\n", ret); in cht_wc_extcon_probe()
611 platform_set_drvdata(pdev, ext); in cht_wc_extcon_probe()
616 cht_wc_extcon_sw_control(ext, false); in cht_wc_extcon_probe()
622 struct cht_wc_extcon_data *ext = platform_get_drvdata(pdev); in cht_wc_extcon_remove() local
624 cht_wc_extcon_sw_control(ext, false); in cht_wc_extcon_remove()