Lines Matching +full:otg +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0-only
7 * board-mapphone-usb.c and cpcap-usb-det.c:
8 * Copyright (C) 2007 - 2011 Motorola, Inc.
24 #include <linux/gpio/consumer.h>
25 #include <linux/mfd/motorola-cpcap.h>
122 struct gpio_desc *gpio[2]; member
135 error = iio_read_channel_processed(ddata->vbus, &value); in cpcap_usb_vbus_valid()
139 dev_err(ddata->dev, "error reading VBUS: %i\n", error); in cpcap_usb_vbus_valid()
144 static int cpcap_usb_phy_set_host(struct usb_otg *otg, struct usb_bus *host) in cpcap_usb_phy_set_host() argument
146 otg->host = host; in cpcap_usb_phy_set_host()
148 otg->state = OTG_STATE_UNDEFINED; in cpcap_usb_phy_set_host()
153 static int cpcap_usb_phy_set_peripheral(struct usb_otg *otg, in cpcap_usb_phy_set_peripheral() argument
156 otg->gadget = gadget; in cpcap_usb_phy_set_peripheral()
158 otg->state = OTG_STATE_UNDEFINED; in cpcap_usb_phy_set_peripheral()
172 error = regmap_read(ddata->reg, CPCAP_REG_INTS1, &val); in cpcap_phy_get_ints_state()
176 s->id_ground = val & BIT(15); in cpcap_phy_get_ints_state()
177 s->id_float = val & BIT(14); in cpcap_phy_get_ints_state()
178 s->vbusov = val & BIT(11); in cpcap_phy_get_ints_state()
180 error = regmap_read(ddata->reg, CPCAP_REG_INTS2, &val); in cpcap_phy_get_ints_state()
184 s->vbusvld = val & BIT(3); in cpcap_phy_get_ints_state()
185 s->sessvld = val & BIT(2); in cpcap_phy_get_ints_state()
186 s->sessend = val & BIT(1); in cpcap_phy_get_ints_state()
187 s->se1 = val & BIT(0); in cpcap_phy_get_ints_state()
189 error = regmap_read(ddata->reg, CPCAP_REG_INTS4, &val); in cpcap_phy_get_ints_state()
193 s->dm = val & BIT(1); in cpcap_phy_get_ints_state()
194 s->dp = val & BIT(0); in cpcap_phy_get_ints_state()
211 dev_dbg(ddata->dev, "%s: musb_mailbox failed: %i\n", in cpcap_usb_try_musb_mailbox()
230 /* We need to kick the VBUS as USB A-host */ in cpcap_usb_detect()
231 if (s.id_ground && ddata->vbus_provider) { in cpcap_usb_detect()
232 dev_dbg(ddata->dev, "still in USB A-host mode, kicking VBUS\n"); in cpcap_usb_detect()
236 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3, in cpcap_usb_detect()
246 if (vbus && s.id_ground && ddata->docked) { in cpcap_usb_detect()
247 dev_dbg(ddata->dev, "still docked as A-host, signal ID down\n"); in cpcap_usb_detect()
255 if (vbus && s.id_ground && !ddata->vbus_provider) { in cpcap_usb_detect()
256 dev_dbg(ddata->dev, "connected to a dock\n"); in cpcap_usb_detect()
258 ddata->docked = true; in cpcap_usb_detect()
271 schedule_delayed_work(&ddata->detect_work, in cpcap_usb_detect()
277 if (s.id_ground && !ddata->docked) { in cpcap_usb_detect()
278 dev_dbg(ddata->dev, "id ground, USB host mode\n"); in cpcap_usb_detect()
280 ddata->vbus_provider = true; in cpcap_usb_detect()
288 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3, in cpcap_usb_detect()
298 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3, in cpcap_usb_detect()
308 dev_dbg(ddata->dev, "connected to USB host\n"); in cpcap_usb_detect()
317 ddata->vbus_provider = false; in cpcap_usb_detect()
318 ddata->docked = false; in cpcap_usb_detect()
326 dev_dbg(ddata->dev, "set UART mode\n"); in cpcap_usb_detect()
331 dev_err(ddata->dev, "error setting cable state: %i\n", error); in cpcap_usb_detect()
338 if (!atomic_read(&ddata->active)) in cpcap_phy_irq_thread()
341 schedule_delayed_work(&ddata->detect_work, msecs_to_jiffies(1)); in cpcap_phy_irq_thread()
354 return -ENODEV; in cpcap_usb_init_irq()
356 error = devm_request_threaded_irq(ddata->dev, irq, NULL, in cpcap_usb_init_irq()
362 dev_err(ddata->dev, "could not get irq %s: %i\n", in cpcap_usb_init_irq()
405 if (!ddata->gpio[0] || !ddata->gpio[1]) in cpcap_usb_gpio_set_mode()
408 gpiod_set_value(ddata->gpio[0], mode & 1); in cpcap_usb_gpio_set_mode()
409 gpiod_set_value(ddata->gpio[1], mode >> 1); in cpcap_usb_gpio_set_mode()
423 if (ddata->pins_uart) { in cpcap_usb_set_uart_mode()
424 error = pinctrl_select_state(ddata->pins, ddata->pins_uart); in cpcap_usb_set_uart_mode()
429 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC1, in cpcap_usb_set_uart_mode()
435 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC2, in cpcap_usb_set_uart_mode()
441 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3, 0x7fff, in cpcap_usb_set_uart_mode()
454 dev_err(ddata->dev, "%s failed with %i\n", __func__, error); in cpcap_usb_set_uart_mode()
468 if (ddata->pins_utmi) { in cpcap_usb_set_usb_mode()
469 error = pinctrl_select_state(ddata->pins, ddata->pins_utmi); in cpcap_usb_set_usb_mode()
471 dev_err(ddata->dev, "could not set usb mode: %i\n", in cpcap_usb_set_usb_mode()
478 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC1, in cpcap_usb_set_usb_mode()
483 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3, in cpcap_usb_set_usb_mode()
492 error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC2, in cpcap_usb_set_usb_mode()
506 dev_err(ddata->dev, "%s failed with %i\n", __func__, error); in cpcap_usb_set_usb_mode()
513 ddata->pins = devm_pinctrl_get(ddata->dev); in cpcap_usb_init_optional_pins()
514 if (IS_ERR(ddata->pins)) { in cpcap_usb_init_optional_pins()
515 dev_info(ddata->dev, "default pins not configured: %ld\n", in cpcap_usb_init_optional_pins()
516 PTR_ERR(ddata->pins)); in cpcap_usb_init_optional_pins()
517 ddata->pins = NULL; in cpcap_usb_init_optional_pins()
522 ddata->pins_ulpi = pinctrl_lookup_state(ddata->pins, "ulpi"); in cpcap_usb_init_optional_pins()
523 if (IS_ERR(ddata->pins_ulpi)) { in cpcap_usb_init_optional_pins()
524 dev_info(ddata->dev, "ulpi pins not configured\n"); in cpcap_usb_init_optional_pins()
525 ddata->pins_ulpi = NULL; in cpcap_usb_init_optional_pins()
528 ddata->pins_utmi = pinctrl_lookup_state(ddata->pins, "utmi"); in cpcap_usb_init_optional_pins()
529 if (IS_ERR(ddata->pins_utmi)) { in cpcap_usb_init_optional_pins()
530 dev_info(ddata->dev, "utmi pins not configured\n"); in cpcap_usb_init_optional_pins()
531 ddata->pins_utmi = NULL; in cpcap_usb_init_optional_pins()
534 ddata->pins_uart = pinctrl_lookup_state(ddata->pins, "uart"); in cpcap_usb_init_optional_pins()
535 if (IS_ERR(ddata->pins_uart)) { in cpcap_usb_init_optional_pins()
536 dev_info(ddata->dev, "uart pins not configured\n"); in cpcap_usb_init_optional_pins()
537 ddata->pins_uart = NULL; in cpcap_usb_init_optional_pins()
540 if (ddata->pins_uart) in cpcap_usb_init_optional_pins()
541 return pinctrl_select_state(ddata->pins, ddata->pins_uart); in cpcap_usb_init_optional_pins()
551 ddata->gpio[i] = devm_gpiod_get_index(ddata->dev, "mode", in cpcap_usb_init_optional_gpios()
553 if (IS_ERR(ddata->gpio[i])) { in cpcap_usb_init_optional_gpios()
554 dev_info(ddata->dev, "no mode change GPIO%i: %li\n", in cpcap_usb_init_optional_gpios()
555 i, PTR_ERR(ddata->gpio[i])); in cpcap_usb_init_optional_gpios()
556 ddata->gpio[i] = NULL; in cpcap_usb_init_optional_gpios()
566 ddata->vbus = devm_iio_channel_get(ddata->dev, "vbus"); in cpcap_usb_init_iio()
567 if (IS_ERR(ddata->vbus)) { in cpcap_usb_init_iio()
568 error = PTR_ERR(ddata->vbus); in cpcap_usb_init_iio()
572 if (!ddata->vbus->indio_dev) { in cpcap_usb_init_iio()
573 error = -ENXIO; in cpcap_usb_init_iio()
577 error = iio_get_channel_type(ddata->vbus, &type); in cpcap_usb_init_iio()
582 error = -EINVAL; in cpcap_usb_init_iio()
589 dev_err(ddata->dev, "could not initialize VBUS or ID IIO: %i\n", in cpcap_usb_init_iio()
598 .compatible = "motorola,cpcap-usb-phy",
601 .compatible = "motorola,mapphone-cpcap-usb-phy",
613 struct usb_otg *otg; in cpcap_usb_phy_probe() local
616 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); in cpcap_usb_phy_probe()
618 return -ENOMEM; in cpcap_usb_phy_probe()
620 ddata->reg = dev_get_regmap(pdev->dev.parent, NULL); in cpcap_usb_phy_probe()
621 if (!ddata->reg) in cpcap_usb_phy_probe()
622 return -ENODEV; in cpcap_usb_phy_probe()
624 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); in cpcap_usb_phy_probe()
625 if (!otg) in cpcap_usb_phy_probe()
626 return -ENOMEM; in cpcap_usb_phy_probe()
628 ddata->dev = &pdev->dev; in cpcap_usb_phy_probe()
629 ddata->phy.dev = ddata->dev; in cpcap_usb_phy_probe()
630 ddata->phy.label = "cpcap_usb_phy"; in cpcap_usb_phy_probe()
631 ddata->phy.otg = otg; in cpcap_usb_phy_probe()
632 ddata->phy.type = USB_PHY_TYPE_USB2; in cpcap_usb_phy_probe()
633 otg->set_host = cpcap_usb_phy_set_host; in cpcap_usb_phy_probe()
634 otg->set_peripheral = cpcap_usb_phy_set_peripheral; in cpcap_usb_phy_probe()
635 otg->usb_phy = &ddata->phy; in cpcap_usb_phy_probe()
636 INIT_DELAYED_WORK(&ddata->detect_work, cpcap_usb_detect); in cpcap_usb_phy_probe()
639 ddata->vusb = devm_regulator_get(&pdev->dev, "vusb"); in cpcap_usb_phy_probe()
640 if (IS_ERR(ddata->vusb)) in cpcap_usb_phy_probe()
641 return PTR_ERR(ddata->vusb); in cpcap_usb_phy_probe()
643 error = regulator_enable(ddata->vusb); in cpcap_usb_phy_probe()
647 generic_phy = devm_phy_create(ddata->dev, NULL, &ops); in cpcap_usb_phy_probe()
655 phy_provider = devm_of_phy_provider_register(ddata->dev, in cpcap_usb_phy_probe()
676 usb_add_phy_dev(&ddata->phy); in cpcap_usb_phy_probe()
677 atomic_set(&ddata->active, 1); in cpcap_usb_phy_probe()
678 schedule_delayed_work(&ddata->detect_work, msecs_to_jiffies(1)); in cpcap_usb_phy_probe()
683 regulator_disable(ddata->vusb); in cpcap_usb_phy_probe()
693 atomic_set(&ddata->active, 0); in cpcap_usb_phy_remove()
696 dev_err(ddata->dev, "could not set UART mode\n"); in cpcap_usb_phy_remove()
700 usb_remove_phy(&ddata->phy); in cpcap_usb_phy_remove()
701 cancel_delayed_work_sync(&ddata->detect_work); in cpcap_usb_phy_remove()
702 regulator_disable(ddata->vusb); in cpcap_usb_phy_remove()
709 .name = "cpcap-usb-phy",