• Home
  • Raw
  • Download

Lines Matching +full:can +full:- +full:transceiver

1 // SPDX-License-Identifier: GPL-2.0+
3 * NOP USB transceiver for all USB transceiver which are either built-in
10 * This provides a "nop" transceiver for PHYs which are
16 #include <linux/dma-mapping.h>
27 #include "phy-generic.h"
48 struct usb_phy_generic *nop = dev_get_drvdata(x->dev); in nop_set_suspend()
50 if (!IS_ERR(nop->clk)) { in nop_set_suspend()
52 clk_disable_unprepare(nop->clk); in nop_set_suspend()
54 clk_prepare_enable(nop->clk); in nop_set_suspend()
62 if (!nop->gpiod_reset) in nop_reset()
65 gpiod_set_value_cansleep(nop->gpiod_reset, 1); in nop_reset()
67 gpiod_set_value_cansleep(nop->gpiod_reset, 0); in nop_reset()
73 struct regulator *vbus_draw = nop->vbus_draw; in nop_set_vbus_draw()
80 enabled = nop->vbus_draw_enabled; in nop_set_vbus_draw()
87 nop->vbus_draw_enabled = 1; in nop_set_vbus_draw()
94 nop->vbus_draw_enabled = 0; in nop_set_vbus_draw()
97 nop->mA = mA; in nop_set_vbus_draw()
104 struct usb_otg *otg = nop->phy.otg; in nop_gpio_vbus_thread()
107 vbus = gpiod_get_value(nop->gpiod_vbus); in nop_gpio_vbus_thread()
108 if ((vbus ^ nop->vbus) == 0) in nop_gpio_vbus_thread()
110 nop->vbus = vbus; in nop_gpio_vbus_thread()
114 otg->state = OTG_STATE_B_PERIPHERAL; in nop_gpio_vbus_thread()
115 nop->phy.last_event = status; in nop_gpio_vbus_thread()
120 atomic_notifier_call_chain(&nop->phy.notifier, status, in nop_gpio_vbus_thread()
121 otg->gadget); in nop_gpio_vbus_thread()
126 otg->state = OTG_STATE_B_IDLE; in nop_gpio_vbus_thread()
127 nop->phy.last_event = status; in nop_gpio_vbus_thread()
129 atomic_notifier_call_chain(&nop->phy.notifier, status, in nop_gpio_vbus_thread()
130 otg->gadget); in nop_gpio_vbus_thread()
137 struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); in usb_gen_phy_init()
140 if (!IS_ERR(nop->vcc)) { in usb_gen_phy_init()
141 if (regulator_enable(nop->vcc)) in usb_gen_phy_init()
142 dev_err(phy->dev, "Failed to enable power\n"); in usb_gen_phy_init()
145 if (!IS_ERR(nop->clk)) { in usb_gen_phy_init()
146 ret = clk_prepare_enable(nop->clk); in usb_gen_phy_init()
159 struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); in usb_gen_phy_shutdown()
161 gpiod_set_value_cansleep(nop->gpiod_reset, 1); in usb_gen_phy_shutdown()
163 if (!IS_ERR(nop->clk)) in usb_gen_phy_shutdown()
164 clk_disable_unprepare(nop->clk); in usb_gen_phy_shutdown()
166 if (!IS_ERR(nop->vcc)) { in usb_gen_phy_shutdown()
167 if (regulator_disable(nop->vcc)) in usb_gen_phy_shutdown()
168 dev_err(phy->dev, "Failed to disable power\n"); in usb_gen_phy_shutdown()
176 return -ENODEV; in nop_set_peripheral()
179 otg->gadget = NULL; in nop_set_peripheral()
180 return -ENODEV; in nop_set_peripheral()
183 otg->gadget = gadget; in nop_set_peripheral()
184 if (otg->state == OTG_STATE_B_PERIPHERAL) in nop_set_peripheral()
185 atomic_notifier_call_chain(&otg->usb_phy->notifier, in nop_set_peripheral()
186 USB_EVENT_VBUS, otg->gadget); in nop_set_peripheral()
188 otg->state = OTG_STATE_B_IDLE; in nop_set_peripheral()
195 return -ENODEV; in nop_set_host()
198 otg->host = NULL; in nop_set_host()
199 return -ENODEV; in nop_set_host()
202 otg->host = host; in nop_set_host()
214 if (dev->of_node) { in usb_phy_gen_create_phy()
215 struct device_node *node = dev->of_node; in usb_phy_gen_create_phy()
217 if (of_property_read_u32(node, "clock-frequency", &clk_rate)) in usb_phy_gen_create_phy()
220 needs_vcc = of_property_read_bool(node, "vcc-supply"); in usb_phy_gen_create_phy()
223 nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset", in usb_phy_gen_create_phy()
225 err = PTR_ERR_OR_ZERO(nop->gpiod_reset); in usb_phy_gen_create_phy()
227 nop->gpiod_vbus = devm_gpiod_get_optional(dev, in usb_phy_gen_create_phy()
228 "vbus-detect", in usb_phy_gen_create_phy()
230 err = PTR_ERR_OR_ZERO(nop->gpiod_vbus); in usb_phy_gen_create_phy()
233 if (err == -EPROBE_DEFER) in usb_phy_gen_create_phy()
234 return -EPROBE_DEFER; in usb_phy_gen_create_phy()
239 if (nop->gpiod_reset) in usb_phy_gen_create_phy()
240 gpiod_direction_output(nop->gpiod_reset, 1); in usb_phy_gen_create_phy()
242 nop->phy.otg = devm_kzalloc(dev, sizeof(*nop->phy.otg), in usb_phy_gen_create_phy()
244 if (!nop->phy.otg) in usb_phy_gen_create_phy()
245 return -ENOMEM; in usb_phy_gen_create_phy()
247 nop->clk = devm_clk_get(dev, "main_clk"); in usb_phy_gen_create_phy()
248 if (IS_ERR(nop->clk)) { in usb_phy_gen_create_phy()
249 dev_dbg(dev, "Can't get phy clock: %ld\n", in usb_phy_gen_create_phy()
250 PTR_ERR(nop->clk)); in usb_phy_gen_create_phy()
252 return PTR_ERR(nop->clk); in usb_phy_gen_create_phy()
255 if (!IS_ERR(nop->clk) && clk_rate) { in usb_phy_gen_create_phy()
256 err = clk_set_rate(nop->clk, clk_rate); in usb_phy_gen_create_phy()
263 nop->vcc = devm_regulator_get(dev, "vcc"); in usb_phy_gen_create_phy()
264 if (IS_ERR(nop->vcc)) { in usb_phy_gen_create_phy()
266 PTR_ERR(nop->vcc)); in usb_phy_gen_create_phy()
268 return -EPROBE_DEFER; in usb_phy_gen_create_phy()
271 nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus"); in usb_phy_gen_create_phy()
272 if (PTR_ERR(nop->vbus_draw) == -ENODEV) in usb_phy_gen_create_phy()
273 nop->vbus_draw = NULL; in usb_phy_gen_create_phy()
274 if (IS_ERR(nop->vbus_draw)) in usb_phy_gen_create_phy()
275 return dev_err_probe(dev, PTR_ERR(nop->vbus_draw), in usb_phy_gen_create_phy()
278 nop->dev = dev; in usb_phy_gen_create_phy()
279 nop->phy.dev = nop->dev; in usb_phy_gen_create_phy()
280 nop->phy.label = "nop-xceiv"; in usb_phy_gen_create_phy()
281 nop->phy.set_suspend = nop_set_suspend; in usb_phy_gen_create_phy()
282 nop->phy.type = type; in usb_phy_gen_create_phy()
284 nop->phy.otg->state = OTG_STATE_UNDEFINED; in usb_phy_gen_create_phy()
285 nop->phy.otg->usb_phy = &nop->phy; in usb_phy_gen_create_phy()
286 nop->phy.otg->set_host = nop_set_host; in usb_phy_gen_create_phy()
287 nop->phy.otg->set_peripheral = nop_set_peripheral; in usb_phy_gen_create_phy()
295 struct device *dev = &pdev->dev; in usb_phy_generic_probe()
301 return -ENOMEM; in usb_phy_generic_probe()
306 if (nop->gpiod_vbus) { in usb_phy_generic_probe()
307 err = devm_request_threaded_irq(&pdev->dev, in usb_phy_generic_probe()
308 gpiod_to_irq(nop->gpiod_vbus), in usb_phy_generic_probe()
313 dev_err(&pdev->dev, "can't request irq %i, err: %d\n", in usb_phy_generic_probe()
314 gpiod_to_irq(nop->gpiod_vbus), err); in usb_phy_generic_probe()
317 nop->phy.otg->state = gpiod_get_value(nop->gpiod_vbus) ? in usb_phy_generic_probe()
321 nop->phy.init = usb_gen_phy_init; in usb_phy_generic_probe()
322 nop->phy.shutdown = usb_gen_phy_shutdown; in usb_phy_generic_probe()
324 err = usb_add_phy_dev(&nop->phy); in usb_phy_generic_probe()
326 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", in usb_phy_generic_probe()
340 usb_remove_phy(&nop->phy); in usb_phy_generic_remove()
346 { .compatible = "usb-nop-xceiv" },
375 MODULE_DESCRIPTION("NOP USB Transceiver driver");