Lines Matching refs:data

128 	struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);  in sun4i_usb_phy0_update_iscr()  local
131 iscr = readl(data->base + REG_ISCR); in sun4i_usb_phy0_update_iscr()
134 writel(iscr, data->base + REG_ISCR); in sun4i_usb_phy0_update_iscr()
157 static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data, in sun4i_usb_phy_write() argument
187 if (data & 0x1) in sun4i_usb_phy_write()
203 data >>= 1; in sun4i_usb_phy_write()
231 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); in sun4i_usb_phy_init() local
252 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2); in sun4i_usb_phy_init()
257 data->phy0_init = true; in sun4i_usb_phy_init()
263 if (data->id_det_gpio) { in sun4i_usb_phy_init()
265 data->id_det = -1; in sun4i_usb_phy_init()
266 data->vbus_det = -1; in sun4i_usb_phy_init()
267 queue_delayed_work(system_wq, &data->detect, 0); in sun4i_usb_phy_init()
281 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); in sun4i_usb_phy_exit() local
287 data->phy0_init = false; in sun4i_usb_phy_exit()
297 static int sun4i_usb_phy0_get_vbus_det(struct sun4i_usb_phy_data *data) in sun4i_usb_phy0_get_vbus_det() argument
299 if (data->vbus_det_gpio) in sun4i_usb_phy0_get_vbus_det()
300 return gpiod_get_value_cansleep(data->vbus_det_gpio); in sun4i_usb_phy0_get_vbus_det()
302 if (data->vbus_power_supply) { in sun4i_usb_phy0_get_vbus_det()
306 r = power_supply_get_property(data->vbus_power_supply, in sun4i_usb_phy0_get_vbus_det()
316 static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data) in sun4i_usb_phy0_have_vbus_det() argument
318 return data->vbus_det_gpio || data->vbus_power_supply; in sun4i_usb_phy0_have_vbus_det()
324 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); in sun4i_usb_phy_power_on() local
331 if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) && in sun4i_usb_phy_power_on()
332 data->vbus_det) in sun4i_usb_phy_power_on()
342 if (phy->index == 0 && data->vbus_det_gpio && data->phy0_poll) in sun4i_usb_phy_power_on()
343 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME); in sun4i_usb_phy_power_on()
351 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); in sun4i_usb_phy_power_off() local
363 if (phy->index == 0 && data->vbus_det_gpio && !data->phy0_poll) in sun4i_usb_phy_power_off()
364 mod_delayed_work(system_wq, &data->detect, POLL_TIME); in sun4i_usb_phy_power_off()
387 struct sun4i_usb_phy_data *data = in sun4i_usb_phy0_id_vbus_det_scan() local
389 struct phy *phy0 = data->phys[0].phy; in sun4i_usb_phy0_id_vbus_det_scan()
392 id_det = gpiod_get_value_cansleep(data->id_det_gpio); in sun4i_usb_phy0_id_vbus_det_scan()
393 vbus_det = sun4i_usb_phy0_get_vbus_det(data); in sun4i_usb_phy0_id_vbus_det_scan()
397 if (!data->phy0_init) { in sun4i_usb_phy0_id_vbus_det_scan()
402 if (id_det != data->id_det) { in sun4i_usb_phy0_id_vbus_det_scan()
408 if (!sun4i_usb_phy0_have_vbus_det(data) && id_det == 0) { in sun4i_usb_phy0_id_vbus_det_scan()
414 data->id_det = id_det; in sun4i_usb_phy0_id_vbus_det_scan()
418 if (vbus_det != data->vbus_det) { in sun4i_usb_phy0_id_vbus_det_scan()
420 data->vbus_det = vbus_det; in sun4i_usb_phy0_id_vbus_det_scan()
427 extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST, in sun4i_usb_phy0_id_vbus_det_scan()
434 if (!sun4i_usb_phy0_have_vbus_det(data) && id_det == 1) { in sun4i_usb_phy0_id_vbus_det_scan()
444 extcon_set_cable_state_(data->extcon, EXTCON_USB, vbus_det); in sun4i_usb_phy0_id_vbus_det_scan()
446 if (data->phy0_poll) in sun4i_usb_phy0_id_vbus_det_scan()
447 queue_delayed_work(system_wq, &data->detect, POLL_TIME); in sun4i_usb_phy0_id_vbus_det_scan()
452 struct sun4i_usb_phy_data *data = dev_id; in sun4i_usb_phy0_id_vbus_det_irq() local
455 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME); in sun4i_usb_phy0_id_vbus_det_irq()
463 struct sun4i_usb_phy_data *data = in sun4i_usb_phy0_vbus_notify() local
468 if (val == PSY_EVENT_PROP_CHANGED && psy == data->vbus_power_supply) in sun4i_usb_phy0_vbus_notify()
469 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME); in sun4i_usb_phy0_vbus_notify()
477 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev); in sun4i_usb_phy_xlate() local
479 if (args->args[0] >= data->num_phys) in sun4i_usb_phy_xlate()
482 return data->phys[args->args[0]].phy; in sun4i_usb_phy_xlate()
488 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev); in sun4i_usb_phy_remove() local
490 if (data->vbus_power_nb_registered) in sun4i_usb_phy_remove()
491 power_supply_unreg_notifier(&data->vbus_power_nb); in sun4i_usb_phy_remove()
492 if (data->id_det_irq >= 0) in sun4i_usb_phy_remove()
493 devm_free_irq(dev, data->id_det_irq, data); in sun4i_usb_phy_remove()
494 if (data->vbus_det_irq >= 0) in sun4i_usb_phy_remove()
495 devm_free_irq(dev, data->vbus_det_irq, data); in sun4i_usb_phy_remove()
497 cancel_delayed_work_sync(&data->detect); in sun4i_usb_phy_remove()
510 struct sun4i_usb_phy_data *data; in sun4i_usb_phy_probe() local
518 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in sun4i_usb_phy_probe()
519 if (!data) in sun4i_usb_phy_probe()
522 mutex_init(&data->mutex); in sun4i_usb_phy_probe()
523 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan); in sun4i_usb_phy_probe()
524 dev_set_drvdata(dev, data); in sun4i_usb_phy_probe()
529 data->num_phys = 2; in sun4i_usb_phy_probe()
531 data->num_phys = 3; in sun4i_usb_phy_probe()
535 data->disc_thresh = 2; in sun4i_usb_phy_probe()
537 data->disc_thresh = 3; in sun4i_usb_phy_probe()
547 data->has_a33_phyctl = true; in sun4i_usb_phy_probe()
550 data->base = devm_ioremap_resource(dev, res); in sun4i_usb_phy_probe()
551 if (IS_ERR(data->base)) in sun4i_usb_phy_probe()
552 return PTR_ERR(data->base); in sun4i_usb_phy_probe()
554 data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det", in sun4i_usb_phy_probe()
556 if (IS_ERR(data->id_det_gpio)) in sun4i_usb_phy_probe()
557 return PTR_ERR(data->id_det_gpio); in sun4i_usb_phy_probe()
559 data->vbus_det_gpio = devm_gpiod_get_optional(dev, "usb0_vbus_det", in sun4i_usb_phy_probe()
561 if (IS_ERR(data->vbus_det_gpio)) in sun4i_usb_phy_probe()
562 return PTR_ERR(data->vbus_det_gpio); in sun4i_usb_phy_probe()
565 data->vbus_power_supply = devm_power_supply_get_by_phandle(dev, in sun4i_usb_phy_probe()
567 if (IS_ERR(data->vbus_power_supply)) in sun4i_usb_phy_probe()
568 return PTR_ERR(data->vbus_power_supply); in sun4i_usb_phy_probe()
570 if (!data->vbus_power_supply) in sun4i_usb_phy_probe()
575 if (sun4i_usb_phy0_have_vbus_det(data) && !data->id_det_gpio) { in sun4i_usb_phy_probe()
580 if (data->id_det_gpio) { in sun4i_usb_phy_probe()
581 data->extcon = devm_extcon_dev_allocate(dev, in sun4i_usb_phy_probe()
583 if (IS_ERR(data->extcon)) in sun4i_usb_phy_probe()
584 return PTR_ERR(data->extcon); in sun4i_usb_phy_probe()
586 ret = devm_extcon_dev_register(dev, data->extcon); in sun4i_usb_phy_probe()
593 for (i = 0; i < data->num_phys; i++) { in sun4i_usb_phy_probe()
594 struct sun4i_usb_phy *phy = data->phys + i; in sun4i_usb_phy_probe()
639 phy_set_drvdata(phy->phy, &data->phys[i]); in sun4i_usb_phy_probe()
642 data->id_det_irq = gpiod_to_irq(data->id_det_gpio); in sun4i_usb_phy_probe()
643 data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio); in sun4i_usb_phy_probe()
644 if ((data->id_det_gpio && data->id_det_irq < 0) || in sun4i_usb_phy_probe()
645 (data->vbus_det_gpio && data->vbus_det_irq < 0)) in sun4i_usb_phy_probe()
646 data->phy0_poll = true; in sun4i_usb_phy_probe()
648 if (data->id_det_irq >= 0) { in sun4i_usb_phy_probe()
649 ret = devm_request_irq(dev, data->id_det_irq, in sun4i_usb_phy_probe()
652 "usb0-id-det", data); in sun4i_usb_phy_probe()
659 if (data->vbus_det_irq >= 0) { in sun4i_usb_phy_probe()
660 ret = devm_request_irq(dev, data->vbus_det_irq, in sun4i_usb_phy_probe()
663 "usb0-vbus-det", data); in sun4i_usb_phy_probe()
666 data->vbus_det_irq = -1; in sun4i_usb_phy_probe()
672 if (data->vbus_power_supply) { in sun4i_usb_phy_probe()
673 data->vbus_power_nb.notifier_call = sun4i_usb_phy0_vbus_notify; in sun4i_usb_phy_probe()
674 data->vbus_power_nb.priority = 0; in sun4i_usb_phy_probe()
675 ret = power_supply_reg_notifier(&data->vbus_power_nb); in sun4i_usb_phy_probe()
680 data->vbus_power_nb_registered = true; in sun4i_usb_phy_probe()