Lines Matching +full:usb +full:- +full:sdp

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ON Semiconductor LC824206XA Micro USB Switch driver
8 * (ENA2222-D.PDF), but no full datasheet. So there is no documentation
11 * This driver is based on the register info from the extcon-fsa9285.c driver,
22 #include <linux/extcon-provider.h>
57 /* 5 bits? ADC 0x10 GND, 0x1a-0x1f ACA, 0x1f float */
82 * auto-reset to 0, so these must be set to 0 manually after clearing.
139 ret = i2c_smbus_read_byte_data(data->client, reg); in lc824206xa_read_reg()
141 dev_err(&data->client->dev, "Error %d reading reg 0x%02x\n", ret, reg); in lc824206xa_read_reg()
150 ret = i2c_smbus_write_byte_data(data->client, reg, val); in lc824206xa_write_reg()
152 dev_err(&data->client->dev, "Error %d writing reg 0x%02x\n", ret, reg); in lc824206xa_write_reg()
176 if (data->vbus_boost_enabled == enable) in lc824206xa_set_vbus_boost()
180 ret = regulator_enable(data->vbus_boost); in lc824206xa_set_vbus_boost()
182 ret = regulator_disable(data->vbus_boost); in lc824206xa_set_vbus_boost()
185 data->vbus_boost_enabled = enable; in lc824206xa_set_vbus_boost()
187 dev_err(&data->client->dev, "Error updating Vbus boost regulator: %d\n", ret); in lc824206xa_set_vbus_boost()
198 dev_dbg(&data->client->dev, "charger type 0x%02x\n", charger_type); in lc824206xa_charger_detect()
202 data->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in lc824206xa_charger_detect()
203 /* Treat as SDP */ in lc824206xa_charger_detect()
204 data->cable = EXTCON_CHG_USB_SDP; in lc824206xa_charger_detect()
205 data->switch_control = SWITCH_USB_DEVICE; in lc824206xa_charger_detect()
208 data->usb_type = POWER_SUPPLY_USB_TYPE_SDP; in lc824206xa_charger_detect()
209 data->cable = EXTCON_CHG_USB_SDP; in lc824206xa_charger_detect()
210 data->switch_control = SWITCH_USB_DEVICE; in lc824206xa_charger_detect()
220 data->usb_type = POWER_SUPPLY_USB_TYPE_CDP; in lc824206xa_charger_detect()
221 data->cable = EXTCON_CHG_USB_CDP; in lc824206xa_charger_detect()
227 data->usb_type = POWER_SUPPLY_USB_TYPE_DCP; in lc824206xa_charger_detect()
228 data->cable = EXTCON_CHG_USB_DCP; in lc824206xa_charger_detect()
229 if (data->fastcharge_over_miclr) in lc824206xa_charger_detect()
230 data->switch_control = SWITCH_STEREO_MIC; in lc824206xa_charger_detect()
232 data->switch_control = SWITCH_DISCONNECTED; in lc824206xa_charger_detect()
235 data->usb_type = POWER_SUPPLY_USB_TYPE_DCP; in lc824206xa_charger_detect()
236 data->cable = EXTCON_CHG_USB_DCP; in lc824206xa_charger_detect()
237 data->switch_control = SWITCH_DISCONNECTED; in lc824206xa_charger_detect()
240 dev_warn(&data->client->dev, "Unknown charger type: 0x%02x\n", charger_type); in lc824206xa_charger_detect()
255 dev_dbg(&data->client->dev, "status 0x%02x\n", status); in lc824206xa_work()
257 data->vbus_ok = (status & (STATUS_VBUS_PRESENT | STATUS_OVP)) == STATUS_VBUS_PRESENT; in lc824206xa_work()
266 dev_dbg(&data->client->dev, "Unknown status 0x%02x\n", status); in lc824206xa_work()
270 dev_dbg(&data->client->dev, "RID 0x%02x\n", id); in lc824206xa_work()
282 dev_warn(&data->client->dev, "Unknown RID 0x%02x\n", id); in lc824206xa_work()
289 data->vbus_ok && !data->vbus_boost_enabled) { in lc824206xa_work()
290 …dev_info(&data->client->dev, "Out of spec USB host adapter with Vbus present, not enabling 5V outp… in lc824206xa_work()
296 data->usb_type = POWER_SUPPLY_USB_TYPE_ACA; in lc824206xa_work()
297 data->cable = EXTCON_CHG_USB_ACA; in lc824206xa_work()
298 data->switch_control = SWITCH_USB_HOST; in lc824206xa_work()
301 data->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in lc824206xa_work()
302 data->cable = EXTCON_USB_HOST; in lc824206xa_work()
303 data->switch_control = SWITCH_USB_HOST; in lc824206xa_work()
308 if (data->fastcharge_over_miclr && in lc824206xa_work()
309 data->switch_control == SWITCH_STEREO_MIC && in lc824206xa_work()
311 data->cable = EXTCON_CHG_USB_FAST; in lc824206xa_work()
315 if (data->vbus_ok) { in lc824206xa_work()
318 data->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in lc824206xa_work()
319 data->cable = EXTCON_NONE; in lc824206xa_work()
320 data->switch_control = SWITCH_DISCONNECTED; in lc824206xa_work()
327 if (data->switch_control != data->previous_switch_control) { in lc824206xa_work()
328 lc824206xa_write_reg(data, REG_SWITCH_CONTROL, data->switch_control); in lc824206xa_work()
329 data->previous_switch_control = data->switch_control; in lc824206xa_work()
332 if (data->cable != data->previous_cable) { in lc824206xa_work()
333 extcon_set_state_sync(data->edev, data->previous_cable, false); in lc824206xa_work()
334 extcon_set_state_sync(data->edev, data->cable, true); in lc824206xa_work()
335 data->previous_cable = data->cable; in lc824206xa_work()
338 power_supply_changed(data->psy); in lc824206xa_work()
350 dev_dbg(&data->client->dev, "interrupt 0x%02x\n", intr_status); in lc824206xa_irq()
355 schedule_work(&data->work); in lc824206xa_irq()
371 val->intval = data->vbus_ok && !data->vbus_boost_enabled; in lc824206xa_psy_get_prop()
374 val->intval = data->usb_type; in lc824206xa_psy_get_prop()
377 switch (data->usb_type) { in lc824206xa_psy_get_prop()
380 val->intval = 2000000; in lc824206xa_psy_get_prop()
383 val->intval = 1500000; in lc824206xa_psy_get_prop()
386 val->intval = 500000; in lc824206xa_psy_get_prop()
390 return -EINVAL; in lc824206xa_psy_get_prop()
403 .name = "lc824206xa-charger-detect",
418 struct device *dev = &client->dev; in lc824206xa_probe()
424 return -ENOMEM; in lc824206xa_probe()
426 data->client = client; in lc824206xa_probe()
427 INIT_WORK(&data->work, lc824206xa_work); in lc824206xa_probe()
428 data->cable = EXTCON_NONE; in lc824206xa_probe()
429 data->previous_cable = EXTCON_NONE; in lc824206xa_probe()
430 data->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in lc824206xa_probe()
431 /* Some designs use a custom fast-charge protocol over the mic L/R inputs */ in lc824206xa_probe()
432 data->fastcharge_over_miclr = in lc824206xa_probe()
433 device_property_read_bool(dev, "onnn,enable-miclr-for-dcp"); in lc824206xa_probe()
435 data->vbus_boost = devm_regulator_get(dev, "vbus"); in lc824206xa_probe()
436 if (IS_ERR(data->vbus_boost)) in lc824206xa_probe()
437 return dev_err_probe(dev, PTR_ERR(data->vbus_boost), in lc824206xa_probe()
450 return -EIO; in lc824206xa_probe()
453 data->edev = devm_extcon_dev_allocate(dev, lc824206xa_cables); in lc824206xa_probe()
454 if (IS_ERR(data->edev)) in lc824206xa_probe()
455 return PTR_ERR(data->edev); in lc824206xa_probe()
457 ret = devm_extcon_dev_register(dev, data->edev); in lc824206xa_probe()
462 data->psy = devm_power_supply_register(dev, &lc824206xa_psy_desc, &psy_cfg); in lc824206xa_probe()
463 if (IS_ERR(data->psy)) in lc824206xa_probe()
464 return dev_err_probe(dev, PTR_ERR(data->psy), "registering power supply\n"); in lc824206xa_probe()
466 ret = devm_request_threaded_irq(dev, client->irq, NULL, lc824206xa_irq, in lc824206xa_probe()
473 schedule_work(&data->work); in lc824206xa_probe()
494 MODULE_DESCRIPTION("LC824206XA Micro USB Switch driver");