Lines Matching +full:reset +full:- +full:phy +full:- +full:on +full:- +full:wake
1 // SPDX-License-Identifier: GPL-2.0
3 * Motorola Mapphone MDM6600 modem GPIO controlled USB PHY driver
18 #include <linux/phy/phy.h>
21 #define PHY_MDM6600_PHY_DELAY_MS 4000 /* PHY enable 2.2s to 3.5s */
23 #define PHY_MDM6600_WAKE_KICK_MS 600 /* time on after GPIO toggle */
28 PHY_MDM6600_ENABLE, /* USB PHY enable */
30 PHY_MDM6600_RESET, /* Device reset */
35 PHY_MDM6600_MODE0, /* out USB mode0 and OOB wake */
36 PHY_MDM6600_MODE1, /* out USB mode1, in OOB wake */
55 * MDM6600 command codes. These are based on Motorola Mapphone Linux
60 PHY_MDM6600_CMD_DATA_ONLY_BYPASS, /* Reroute USB to CPCAP PHY */
61 PHY_MDM6600_CMD_FULL_BYPASS, /* Reroute USB to CPCAP PHY */
70 * MDM6600 status codes. These are based on Motorola Mapphone Linux
92 struct phy *generic_phy;
102 bool enabled; /* mdm6600 phy enabled */
104 bool awake; /* mdm6600 respnds on n_gsm */
108 static int phy_mdm6600_init(struct phy *x) in phy_mdm6600_init()
111 struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE]; in phy_mdm6600_init()
113 if (!ddata->enabled) in phy_mdm6600_init()
114 return -EPROBE_DEFER; in phy_mdm6600_init()
121 static int phy_mdm6600_power_on(struct phy *x) in phy_mdm6600_power_on()
124 struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE]; in phy_mdm6600_power_on()
126 if (!ddata->enabled) in phy_mdm6600_power_on()
127 return -ENODEV; in phy_mdm6600_power_on()
132 if (pm_runtime_enabled(&x->dev)) in phy_mdm6600_power_on()
138 static int phy_mdm6600_power_off(struct phy *x) in phy_mdm6600_power_off()
141 struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE]; in phy_mdm6600_power_off()
144 if (!ddata->enabled) in phy_mdm6600_power_off()
145 return -ENODEV; in phy_mdm6600_power_off()
148 if (pm_runtime_enabled(&x->dev)) { in phy_mdm6600_power_off()
150 if (error < 0 && error != -EINPROGRESS) in phy_mdm6600_power_off()
151 dev_warn(ddata->dev, "%s: phy_pm_runtime_get: %i\n", in phy_mdm6600_power_off()
168 * phy_mdm6600_cmd() - send a command request to mdm6600
181 ddata->cmd_gpios->desc, in phy_mdm6600_cmd()
182 ddata->cmd_gpios->info, values); in phy_mdm6600_cmd()
186 * phy_mdm6600_status() - read mdm6600 status lines
197 dev = ddata->dev; in phy_mdm6600_status()
200 ddata->status_gpios->desc, in phy_mdm6600_status()
201 ddata->status_gpios->info, in phy_mdm6600_status()
206 ddata->status = values[0] & ((1 << PHY_MDM6600_NR_STATUS_LINES) - 1); in phy_mdm6600_status()
209 ddata->status, in phy_mdm6600_status()
210 phy_mdm6600_status_name[ddata->status]); in phy_mdm6600_status()
211 complete(&ddata->ack); in phy_mdm6600_status()
218 schedule_delayed_work(&ddata->status_work, msecs_to_jiffies(10)); in phy_mdm6600_irq_thread()
224 * phy_mdm6600_wakeirq_thread - handle mode1 line OOB wake after booting
229 * mode for mdm6600. After booting it is used as input for OOB wake
239 mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1]; in phy_mdm6600_wakeirq_thread()
244 dev_dbg(ddata->dev, "OOB wake on mode_gpio1: %i\n", wakeup); in phy_mdm6600_wakeirq_thread()
245 error = pm_runtime_get_sync(ddata->dev); in phy_mdm6600_wakeirq_thread()
247 pm_runtime_put_noidle(ddata->dev); in phy_mdm6600_wakeirq_thread()
252 /* Just wake-up and kick the autosuspend timer */ in phy_mdm6600_wakeirq_thread()
253 pm_runtime_mark_last_busy(ddata->dev); in phy_mdm6600_wakeirq_thread()
254 pm_runtime_put_autosuspend(ddata->dev); in phy_mdm6600_wakeirq_thread()
260 * phy_mdm6600_init_irq() - initialize mdm6600 status IRQ lines
265 struct device *dev = ddata->dev; in phy_mdm6600_init_irq()
270 struct gpio_desc *gpio = ddata->status_gpios->desc[i]; in phy_mdm6600_init_irq()
296 { "enable", GPIOD_OUT_LOW, }, /* low = phy disabled */
298 { "reset", GPIOD_OUT_HIGH, }, /* high = reset */
302 * phy_mdm6600_init_lines() - initialize mdm6600 GPIO lines
307 struct device *dev = ddata->dev; in phy_mdm6600_init_lines()
314 struct gpio_desc **gpio = &ddata->ctrl_gpios[i]; in phy_mdm6600_init_lines()
316 *gpio = devm_gpiod_get(dev, map->name, map->direction); in phy_mdm6600_init_lines()
319 map->name, PTR_ERR(*gpio)); in phy_mdm6600_init_lines()
324 /* MDM6600 USB start-up mode output lines */ in phy_mdm6600_init_lines()
325 ddata->mode_gpios = devm_gpiod_get_array(dev, "motorola,mode", in phy_mdm6600_init_lines()
327 if (IS_ERR(ddata->mode_gpios)) in phy_mdm6600_init_lines()
328 return PTR_ERR(ddata->mode_gpios); in phy_mdm6600_init_lines()
330 if (ddata->mode_gpios->ndescs != PHY_MDM6600_NR_MODE_LINES) in phy_mdm6600_init_lines()
331 return -EINVAL; in phy_mdm6600_init_lines()
334 ddata->status_gpios = devm_gpiod_get_array(dev, "motorola,status", in phy_mdm6600_init_lines()
336 if (IS_ERR(ddata->status_gpios)) in phy_mdm6600_init_lines()
337 return PTR_ERR(ddata->status_gpios); in phy_mdm6600_init_lines()
339 if (ddata->status_gpios->ndescs != PHY_MDM6600_NR_STATUS_LINES) in phy_mdm6600_init_lines()
340 return -EINVAL; in phy_mdm6600_init_lines()
343 ddata->cmd_gpios = devm_gpiod_get_array(dev, "motorola,cmd", in phy_mdm6600_init_lines()
345 if (IS_ERR(ddata->cmd_gpios)) in phy_mdm6600_init_lines()
346 return PTR_ERR(ddata->cmd_gpios); in phy_mdm6600_init_lines()
348 if (ddata->cmd_gpios->ndescs != PHY_MDM6600_NR_CMD_LINES) in phy_mdm6600_init_lines()
349 return -EINVAL; in phy_mdm6600_init_lines()
355 * phy_mdm6600_device_power_on() - power on mdm6600 device
358 * To get the integrated USB phy in MDM6600 takes some hoops. We must ensure
359 * the shared USB bootmode GPIOs are configured, then request modem start-up,
360 * reset and power-up.. And then we need to recycle the shared USB bootmode
361 * GPIOs as they are also used for Out of Band (OOB) wake for the USB and
369 mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0]; in phy_mdm6600_device_power_on()
370 mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1]; in phy_mdm6600_device_power_on()
371 reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET]; in phy_mdm6600_device_power_on()
372 power_gpio = ddata->ctrl_gpios[PHY_MDM6600_POWER]; in phy_mdm6600_device_power_on()
376 * they are used for OOB wake signaling. These can be also used in phy_mdm6600_device_power_on()
377 * to configure USB flashing mode later on based on a module in phy_mdm6600_device_power_on()
383 /* Request start-up mode */ in phy_mdm6600_device_power_on()
386 /* Request a reset first */ in phy_mdm6600_device_power_on()
396 * Looks like the USB PHY needs between 2.2 to 4 seconds. in phy_mdm6600_device_power_on()
398 * from omap-usb-host trying to access the PHY. See also in phy_mdm6600_device_power_on()
399 * phy_mdm6600_init() for -EPROBE_DEFER. in phy_mdm6600_device_power_on()
402 ddata->enabled = true; in phy_mdm6600_device_power_on()
405 dev_info(ddata->dev, "Waiting for power up request to complete..\n"); in phy_mdm6600_device_power_on()
406 if (wait_for_completion_timeout(&ddata->ack, in phy_mdm6600_device_power_on()
408 if (ddata->status > PHY_MDM6600_STATUS_PANIC && in phy_mdm6600_device_power_on()
409 ddata->status < PHY_MDM6600_STATUS_SHUTDOWN_ACK) in phy_mdm6600_device_power_on()
410 dev_info(ddata->dev, "Powered up OK\n"); in phy_mdm6600_device_power_on()
412 ddata->enabled = false; in phy_mdm6600_device_power_on()
413 error = -ETIMEDOUT; in phy_mdm6600_device_power_on()
414 dev_err(ddata->dev, "Timed out powering up\n"); in phy_mdm6600_device_power_on()
417 /* Reconfigure mode1 GPIO as input for OOB wake */ in phy_mdm6600_device_power_on()
424 error = devm_request_threaded_irq(ddata->dev, wakeirq, NULL, in phy_mdm6600_device_power_on()
429 "mdm6600-wake", in phy_mdm6600_device_power_on()
432 dev_warn(ddata->dev, "no modem wakeirq irq%i: %i\n", in phy_mdm6600_device_power_on()
435 ddata->running = true; in phy_mdm6600_device_power_on()
441 * phy_mdm6600_device_power_off() - power off mdm6600 device
447 ddata->ctrl_gpios[PHY_MDM6600_RESET]; in phy_mdm6600_device_power_off()
450 ddata->enabled = false; in phy_mdm6600_device_power_off()
456 dev_info(ddata->dev, "Waiting for power down request to complete.. "); in phy_mdm6600_device_power_off()
457 if (wait_for_completion_timeout(&ddata->ack, in phy_mdm6600_device_power_off()
459 if (ddata->status == PHY_MDM6600_STATUS_PANIC) in phy_mdm6600_device_power_off()
460 dev_info(ddata->dev, "Powered down OK\n"); in phy_mdm6600_device_power_off()
462 dev_err(ddata->dev, "Timed out powering down\n"); in phy_mdm6600_device_power_off()
466 * Keep reset gpio high with padconf internal pull-up resistor to in phy_mdm6600_device_power_off()
468 * gpio bank lines can have glitches if not in the always-on wkup in phy_mdm6600_device_power_off()
471 error = pinctrl_pm_select_sleep_state(ddata->dev); in phy_mdm6600_device_power_off()
473 dev_warn(ddata->dev, "%s: error with sleep_state: %i\n", in phy_mdm6600_device_power_off()
486 dev_err(ddata->dev, "Device not functional\n"); in phy_mdm6600_deferred_power_on()
500 mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0]; in phy_mdm6600_wake_modem()
504 if (ddata->awake) in phy_mdm6600_wake_modem()
519 * the wake GPIO, and sometimes it idles after about some 600 ms in phy_mdm6600_modem_wake()
522 schedule_delayed_work(&ddata->modem_wake_work, in phy_mdm6600_modem_wake()
530 cancel_delayed_work_sync(&ddata->modem_wake_work); in phy_mdm6600_runtime_suspend()
531 ddata->awake = false; in phy_mdm6600_runtime_suspend()
540 phy_mdm6600_modem_wake(&ddata->modem_wake_work.work); in phy_mdm6600_runtime_resume()
541 ddata->awake = true; in phy_mdm6600_runtime_resume()
552 { .compatible = "motorola,mapphone-mdm6600", },
562 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); in phy_mdm6600_probe()
564 return -ENOMEM; in phy_mdm6600_probe()
566 INIT_DELAYED_WORK(&ddata->bootup_work, in phy_mdm6600_probe()
568 INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status); in phy_mdm6600_probe()
569 INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake); in phy_mdm6600_probe()
570 init_completion(&ddata->ack); in phy_mdm6600_probe()
572 ddata->dev = &pdev->dev; in phy_mdm6600_probe()
580 schedule_delayed_work(&ddata->bootup_work, 0); in phy_mdm6600_probe()
584 * to remove this eventually when ohci-platform can deal in phy_mdm6600_probe()
585 * with -EPROBE_DEFER. in phy_mdm6600_probe()
590 * Enable PM runtime only after PHY has been powered up properly. in phy_mdm6600_probe()
593 * gpio mode0 pin doubles as mdm6600 wake-up gpio. in phy_mdm6600_probe()
595 pm_runtime_use_autosuspend(ddata->dev); in phy_mdm6600_probe()
596 pm_runtime_set_autosuspend_delay(ddata->dev, in phy_mdm6600_probe()
598 pm_runtime_enable(ddata->dev); in phy_mdm6600_probe()
599 error = pm_runtime_get_sync(ddata->dev); in phy_mdm6600_probe()
601 dev_warn(ddata->dev, "failed to wake modem: %i\n", error); in phy_mdm6600_probe()
602 pm_runtime_put_noidle(ddata->dev); in phy_mdm6600_probe()
606 ddata->generic_phy = devm_phy_create(ddata->dev, NULL, &gpio_usb_ops); in phy_mdm6600_probe()
607 if (IS_ERR(ddata->generic_phy)) { in phy_mdm6600_probe()
608 error = PTR_ERR(ddata->generic_phy); in phy_mdm6600_probe()
612 phy_set_drvdata(ddata->generic_phy, ddata); in phy_mdm6600_probe()
614 ddata->phy_provider = in phy_mdm6600_probe()
615 devm_of_phy_provider_register(ddata->dev, in phy_mdm6600_probe()
617 if (IS_ERR(ddata->phy_provider)) in phy_mdm6600_probe()
618 error = PTR_ERR(ddata->phy_provider); in phy_mdm6600_probe()
621 pm_runtime_mark_last_busy(ddata->dev); in phy_mdm6600_probe()
622 pm_runtime_put_autosuspend(ddata->dev); in phy_mdm6600_probe()
627 pm_runtime_disable(ddata->dev); in phy_mdm6600_probe()
628 pm_runtime_dont_use_autosuspend(ddata->dev); in phy_mdm6600_probe()
637 struct gpio_desc *reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET]; in phy_mdm6600_remove()
639 pm_runtime_get_noresume(ddata->dev); in phy_mdm6600_remove()
640 pm_runtime_dont_use_autosuspend(ddata->dev); in phy_mdm6600_remove()
641 pm_runtime_put_sync(ddata->dev); in phy_mdm6600_remove()
642 pm_runtime_disable(ddata->dev); in phy_mdm6600_remove()
644 if (!ddata->running) in phy_mdm6600_remove()
645 wait_for_completion_timeout(&ddata->ack, in phy_mdm6600_remove()
651 cancel_delayed_work_sync(&ddata->modem_wake_work); in phy_mdm6600_remove()
652 cancel_delayed_work_sync(&ddata->bootup_work); in phy_mdm6600_remove()
653 cancel_delayed_work_sync(&ddata->status_work); in phy_mdm6600_remove()
660 .name = "phy-mapphone-mdm6600",
670 MODULE_DESCRIPTION("mdm6600 gpio usb phy driver");