Lines Matching +full:autosuspend +full:- +full:delay +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/delay.h>
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()
124 struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE]; in phy_mdm6600_power_on()
127 if (!ddata->enabled) in phy_mdm6600_power_on()
128 return -ENODEV; in phy_mdm6600_power_on()
130 error = pinctrl_pm_select_default_state(ddata->dev); in phy_mdm6600_power_on()
132 dev_warn(ddata->dev, "%s: error with default_state: %i\n", in phy_mdm6600_power_on()
138 if (pm_runtime_enabled(&x->dev)) in phy_mdm6600_power_on()
147 struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE]; in phy_mdm6600_power_off()
150 if (!ddata->enabled) in phy_mdm6600_power_off()
151 return -ENODEV; in phy_mdm6600_power_off()
154 if (pm_runtime_enabled(&x->dev)) { in phy_mdm6600_power_off()
156 if (error < 0 && error != -EINPROGRESS) in phy_mdm6600_power_off()
157 dev_warn(ddata->dev, "%s: phy_pm_runtime_get: %i\n", in phy_mdm6600_power_off()
163 error = pinctrl_pm_select_sleep_state(ddata->dev); in phy_mdm6600_power_off()
165 dev_warn(ddata->dev, "%s: error with sleep_state: %i\n", in phy_mdm6600_power_off()
179 * phy_mdm6600_cmd() - send a command request to mdm6600
192 ddata->cmd_gpios->desc, in phy_mdm6600_cmd()
193 ddata->cmd_gpios->info, values); in phy_mdm6600_cmd()
197 * phy_mdm6600_status() - read mdm6600 status lines
208 dev = ddata->dev; in phy_mdm6600_status()
211 ddata->status_gpios->desc, in phy_mdm6600_status()
212 ddata->status_gpios->info, in phy_mdm6600_status()
217 ddata->status = values[0] & ((1 << PHY_MDM6600_NR_STATUS_LINES) - 1); in phy_mdm6600_status()
220 ddata->status, in phy_mdm6600_status()
221 phy_mdm6600_status_name[ddata->status]); in phy_mdm6600_status()
222 complete(&ddata->ack); in phy_mdm6600_status()
229 schedule_delayed_work(&ddata->status_work, msecs_to_jiffies(10)); in phy_mdm6600_irq_thread()
235 * phy_mdm6600_wakeirq_thread - handle mode1 line OOB wake after booting
250 mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1]; in phy_mdm6600_wakeirq_thread()
255 dev_dbg(ddata->dev, "OOB wake on mode_gpio1: %i\n", wakeup); in phy_mdm6600_wakeirq_thread()
256 error = pm_runtime_get_sync(ddata->dev); in phy_mdm6600_wakeirq_thread()
258 pm_runtime_put_noidle(ddata->dev); in phy_mdm6600_wakeirq_thread()
263 /* Just wake-up and kick the autosuspend timer */ in phy_mdm6600_wakeirq_thread()
264 pm_runtime_mark_last_busy(ddata->dev); in phy_mdm6600_wakeirq_thread()
265 pm_runtime_put_autosuspend(ddata->dev); in phy_mdm6600_wakeirq_thread()
271 * phy_mdm6600_init_irq() - initialize mdm6600 status IRQ lines
276 struct device *dev = ddata->dev; in phy_mdm6600_init_irq()
281 struct gpio_desc *gpio = ddata->status_gpios->desc[i]; in phy_mdm6600_init_irq()
313 * phy_mdm6600_init_lines() - initialize mdm6600 GPIO lines
318 struct device *dev = ddata->dev; in phy_mdm6600_init_lines()
325 struct gpio_desc **gpio = &ddata->ctrl_gpios[i]; in phy_mdm6600_init_lines()
327 *gpio = devm_gpiod_get(dev, map->name, map->direction); in phy_mdm6600_init_lines()
330 map->name, PTR_ERR(*gpio)); in phy_mdm6600_init_lines()
335 /* MDM6600 USB start-up mode output lines */ in phy_mdm6600_init_lines()
336 ddata->mode_gpios = devm_gpiod_get_array(dev, "motorola,mode", in phy_mdm6600_init_lines()
338 if (IS_ERR(ddata->mode_gpios)) in phy_mdm6600_init_lines()
339 return PTR_ERR(ddata->mode_gpios); in phy_mdm6600_init_lines()
341 if (ddata->mode_gpios->ndescs != PHY_MDM6600_NR_MODE_LINES) in phy_mdm6600_init_lines()
342 return -EINVAL; in phy_mdm6600_init_lines()
345 ddata->status_gpios = devm_gpiod_get_array(dev, "motorola,status", in phy_mdm6600_init_lines()
347 if (IS_ERR(ddata->status_gpios)) in phy_mdm6600_init_lines()
348 return PTR_ERR(ddata->status_gpios); in phy_mdm6600_init_lines()
350 if (ddata->status_gpios->ndescs != PHY_MDM6600_NR_STATUS_LINES) in phy_mdm6600_init_lines()
351 return -EINVAL; in phy_mdm6600_init_lines()
354 ddata->cmd_gpios = devm_gpiod_get_array(dev, "motorola,cmd", in phy_mdm6600_init_lines()
356 if (IS_ERR(ddata->cmd_gpios)) in phy_mdm6600_init_lines()
357 return PTR_ERR(ddata->cmd_gpios); in phy_mdm6600_init_lines()
359 if (ddata->cmd_gpios->ndescs != PHY_MDM6600_NR_CMD_LINES) in phy_mdm6600_init_lines()
360 return -EINVAL; in phy_mdm6600_init_lines()
366 * phy_mdm6600_device_power_on() - power on mdm6600 device
370 * the shared USB bootmode GPIOs are configured, then request modem start-up,
371 * reset and power-up.. And then we need to recycle the shared USB bootmode
380 mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0]; in phy_mdm6600_device_power_on()
381 mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1]; in phy_mdm6600_device_power_on()
382 reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET]; in phy_mdm6600_device_power_on()
383 power_gpio = ddata->ctrl_gpios[PHY_MDM6600_POWER]; in phy_mdm6600_device_power_on()
394 /* Request start-up mode */ in phy_mdm6600_device_power_on()
409 * from omap-usb-host trying to access the PHY. See also in phy_mdm6600_device_power_on()
410 * phy_mdm6600_init() for -EPROBE_DEFER. in phy_mdm6600_device_power_on()
413 ddata->enabled = true; in phy_mdm6600_device_power_on()
416 dev_info(ddata->dev, "Waiting for power up request to complete..\n"); in phy_mdm6600_device_power_on()
417 if (wait_for_completion_timeout(&ddata->ack, in phy_mdm6600_device_power_on()
419 if (ddata->status > PHY_MDM6600_STATUS_PANIC && in phy_mdm6600_device_power_on()
420 ddata->status < PHY_MDM6600_STATUS_SHUTDOWN_ACK) in phy_mdm6600_device_power_on()
421 dev_info(ddata->dev, "Powered up OK\n"); in phy_mdm6600_device_power_on()
423 ddata->enabled = false; in phy_mdm6600_device_power_on()
424 error = -ETIMEDOUT; in phy_mdm6600_device_power_on()
425 dev_err(ddata->dev, "Timed out powering up\n"); in phy_mdm6600_device_power_on()
435 error = devm_request_threaded_irq(ddata->dev, wakeirq, NULL, in phy_mdm6600_device_power_on()
440 "mdm6600-wake", in phy_mdm6600_device_power_on()
443 dev_warn(ddata->dev, "no modem wakeirq irq%i: %i\n", in phy_mdm6600_device_power_on()
446 ddata->running = true; in phy_mdm6600_device_power_on()
452 * phy_mdm6600_device_power_off() - power off mdm6600 device
458 ddata->ctrl_gpios[PHY_MDM6600_RESET]; in phy_mdm6600_device_power_off()
460 ddata->enabled = false; in phy_mdm6600_device_power_off()
466 dev_info(ddata->dev, "Waiting for power down request to complete.. "); in phy_mdm6600_device_power_off()
467 if (wait_for_completion_timeout(&ddata->ack, in phy_mdm6600_device_power_off()
469 if (ddata->status == PHY_MDM6600_STATUS_PANIC) in phy_mdm6600_device_power_off()
470 dev_info(ddata->dev, "Powered down OK\n"); in phy_mdm6600_device_power_off()
472 dev_err(ddata->dev, "Timed out powering down\n"); in phy_mdm6600_device_power_off()
485 dev_err(ddata->dev, "Device not functional\n"); in phy_mdm6600_deferred_power_on()
499 mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0]; in phy_mdm6600_wake_modem()
503 if (ddata->awake) in phy_mdm6600_wake_modem()
518 * the wake GPIO, and sometimes it idles after about some 600 ms in phy_mdm6600_modem_wake()
521 schedule_delayed_work(&ddata->modem_wake_work, in phy_mdm6600_modem_wake()
529 cancel_delayed_work_sync(&ddata->modem_wake_work); in phy_mdm6600_runtime_suspend()
530 ddata->awake = false; in phy_mdm6600_runtime_suspend()
539 phy_mdm6600_modem_wake(&ddata->modem_wake_work.work); in phy_mdm6600_runtime_resume()
540 ddata->awake = true; in phy_mdm6600_runtime_resume()
551 { .compatible = "motorola,mapphone-mdm6600", },
561 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); in phy_mdm6600_probe()
563 return -ENOMEM; in phy_mdm6600_probe()
565 INIT_DELAYED_WORK(&ddata->bootup_work, in phy_mdm6600_probe()
567 INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status); in phy_mdm6600_probe()
568 INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake); in phy_mdm6600_probe()
569 init_completion(&ddata->ack); in phy_mdm6600_probe()
571 ddata->dev = &pdev->dev; in phy_mdm6600_probe()
575 error = pinctrl_pm_select_sleep_state(ddata->dev); in phy_mdm6600_probe()
577 dev_warn(ddata->dev, "%s: error with sleep_state: %i\n", in phy_mdm6600_probe()
585 schedule_delayed_work(&ddata->bootup_work, 0); in phy_mdm6600_probe()
589 * to remove this eventually when ohci-platform can deal in phy_mdm6600_probe()
590 * with -EPROBE_DEFER. in phy_mdm6600_probe()
598 * gpio mode0 pin doubles as mdm6600 wake-up gpio. in phy_mdm6600_probe()
600 pm_runtime_use_autosuspend(ddata->dev); in phy_mdm6600_probe()
601 pm_runtime_set_autosuspend_delay(ddata->dev, in phy_mdm6600_probe()
603 pm_runtime_enable(ddata->dev); in phy_mdm6600_probe()
604 error = pm_runtime_get_sync(ddata->dev); in phy_mdm6600_probe()
606 dev_warn(ddata->dev, "failed to wake modem: %i\n", error); in phy_mdm6600_probe()
607 pm_runtime_put_noidle(ddata->dev); in phy_mdm6600_probe()
611 ddata->generic_phy = devm_phy_create(ddata->dev, NULL, &gpio_usb_ops); in phy_mdm6600_probe()
612 if (IS_ERR(ddata->generic_phy)) { in phy_mdm6600_probe()
613 error = PTR_ERR(ddata->generic_phy); in phy_mdm6600_probe()
617 phy_set_drvdata(ddata->generic_phy, ddata); in phy_mdm6600_probe()
619 ddata->phy_provider = in phy_mdm6600_probe()
620 devm_of_phy_provider_register(ddata->dev, in phy_mdm6600_probe()
622 if (IS_ERR(ddata->phy_provider)) in phy_mdm6600_probe()
623 error = PTR_ERR(ddata->phy_provider); in phy_mdm6600_probe()
626 pm_runtime_mark_last_busy(ddata->dev); in phy_mdm6600_probe()
627 pm_runtime_put_autosuspend(ddata->dev); in phy_mdm6600_probe()
632 pm_runtime_disable(ddata->dev); in phy_mdm6600_probe()
633 pm_runtime_dont_use_autosuspend(ddata->dev); in phy_mdm6600_probe()
640 struct gpio_desc *reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET]; in phy_mdm6600_remove()
642 pm_runtime_dont_use_autosuspend(ddata->dev); in phy_mdm6600_remove()
643 pm_runtime_put_sync(ddata->dev); in phy_mdm6600_remove()
644 pm_runtime_disable(ddata->dev); in phy_mdm6600_remove()
646 if (!ddata->running) in phy_mdm6600_remove()
647 wait_for_completion_timeout(&ddata->ack, in phy_mdm6600_remove()
653 cancel_delayed_work_sync(&ddata->modem_wake_work); in phy_mdm6600_remove()
654 cancel_delayed_work_sync(&ddata->bootup_work); in phy_mdm6600_remove()
655 cancel_delayed_work_sync(&ddata->status_work); in phy_mdm6600_remove()
664 .name = "phy-mapphone-mdm6600",