Lines Matching +full:sense +full:- +full:mode
1 // SPDX-License-Identifier: GPL-1.0+
6 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * (C) Copyright 2002 Hewlett-Packard Company
14 * Modified for LH7A404 from ohci-sa1111.c
17 * Modified for pxa27x from ohci-lh7a404.c
18 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
25 #include <linux/dma-mapping.h>
30 #include <linux/platform_data/usb-ohci-pxa27x.h>
45 * UHC: USB Host Controller (OHCI-like) register definitions
68 #define UHCRHDA_OCPM (1 << 11) /* Over Current Protection Mode */
79 #define UHCSTAT_UPS3 (1 << 16) /* USB Power Sense Port3 */
83 #define UHCSTAT_UPS2 (1 << 12) /* USB Power Sense Port 2 */
84 #define UHCSTAT_UPS1 (1 << 11) /* USB Power Sense Port 1 */
94 #define UHCHR_PSPL (1 << 6) /* Power sense polarity low */
103 #define UHCHIE_UPS3IE (1 << 14) /* Power Sense Port3 IntEn */
105 #define UHCHIE_UPS2IE (1 << 12) /* Power Sense Port2 IntEn */
106 #define UHCHIE_UPS1IE (1 << 11) /* Power Sense Port1 IntEn */
110 #define UHCHIE_RWIE (1 << 7) /* Remote Wake-up IntEn */
125 #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv)
128 PMM_NPS_MODE -- PMM Non-power switching mode
131 PMM_GLOBAL_MODE -- PMM global switching mode
134 PMM_PERPORT_MODE -- PMM per port switching mode
137 static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *pxa_ohci, int mode) in pxa27x_ohci_select_pmm() argument
139 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA); in pxa27x_ohci_select_pmm()
140 uint32_t uhcrhdb = __raw_readl(pxa_ohci->mmio_base + UHCRHDB); in pxa27x_ohci_select_pmm()
142 switch (mode) { in pxa27x_ohci_select_pmm()
158 "Invalid mode %d, set to non-power switch mode.\n", in pxa27x_ohci_select_pmm()
159 mode ); in pxa27x_ohci_select_pmm()
164 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA); in pxa27x_ohci_select_pmm()
165 __raw_writel(uhcrhdb, pxa_ohci->mmio_base + UHCRHDB); in pxa27x_ohci_select_pmm()
172 struct regulator *vbus = pxa_ohci->vbus[port]; in pxa27x_ohci_set_vbus_power()
178 if (enable && !pxa_ohci->vbus_enabled[port]) in pxa27x_ohci_set_vbus_power()
180 else if (!enable && pxa_ohci->vbus_enabled[port]) in pxa27x_ohci_set_vbus_power()
186 pxa_ohci->vbus_enabled[port] = enable; in pxa27x_ohci_set_vbus_power()
201 return -EPIPE; in pxa27x_ohci_hub_control()
206 ret = pxa27x_ohci_set_vbus_power(pxa_ohci, wIndex - 1, in pxa27x_ohci_hub_control()
215 /*-------------------------------------------------------------------------*/
220 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR); in pxa27x_setup_hc()
221 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA); in pxa27x_setup_hc()
223 if (inf->flags & ENABLE_PORT1) in pxa27x_setup_hc()
226 if (inf->flags & ENABLE_PORT2) in pxa27x_setup_hc()
229 if (inf->flags & ENABLE_PORT3) in pxa27x_setup_hc()
232 if (inf->flags & POWER_CONTROL_LOW) in pxa27x_setup_hc()
235 if (inf->flags & POWER_SENSE_LOW) in pxa27x_setup_hc()
238 if (inf->flags & NO_OC_PROTECTION) in pxa27x_setup_hc()
243 if (inf->flags & OC_MODE_PERPORT) in pxa27x_setup_hc()
248 if (inf->power_on_delay) { in pxa27x_setup_hc()
250 uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); in pxa27x_setup_hc()
253 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); in pxa27x_setup_hc()
254 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA); in pxa27x_setup_hc()
259 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR); in pxa27x_reset_hc()
261 __raw_writel(uhchr | UHCHR_FHR, pxa_ohci->mmio_base + UHCHR); in pxa27x_reset_hc()
263 __raw_writel(uhchr & ~UHCHR_FHR, pxa_ohci->mmio_base + UHCHR); in pxa27x_reset_hc()
274 retval = clk_prepare_enable(pxa_ohci->clk); in pxa27x_start_hc()
280 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) | UHCHR_FSBIR; in pxa27x_start_hc()
281 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); in pxa27x_start_hc()
283 while (__raw_readl(pxa_ohci->mmio_base + UHCHR) & UHCHR_FSBIR) in pxa27x_start_hc()
288 if (inf->init) in pxa27x_start_hc()
289 retval = inf->init(dev); in pxa27x_start_hc()
292 clk_disable_unprepare(pxa_ohci->clk); in pxa27x_start_hc()
296 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) & ~UHCHR_SSE; in pxa27x_start_hc()
297 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); in pxa27x_start_hc()
298 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, pxa_ohci->mmio_base + UHCHIE); in pxa27x_start_hc()
312 if (inf->exit) in pxa27x_stop_hc()
313 inf->exit(dev); in pxa27x_stop_hc()
318 uhccoms = __raw_readl(pxa_ohci->mmio_base + UHCCOMS) | 0x01; in pxa27x_stop_hc()
319 __raw_writel(uhccoms, pxa_ohci->mmio_base + UHCCOMS); in pxa27x_stop_hc()
322 clk_disable_unprepare(pxa_ohci->clk); in pxa27x_stop_hc()
327 { .compatible = "marvell,pxa-ohci" },
335 struct device_node *np = pdev->dev.of_node; in ohci_pxa_of_init()
343 /* Right now device-tree probed devices don't get dma_mask set. in ohci_pxa_of_init()
347 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); in ohci_pxa_of_init()
351 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in ohci_pxa_of_init()
353 return -ENOMEM; in ohci_pxa_of_init()
355 if (of_property_read_bool(np, "marvell,enable-port1")) in ohci_pxa_of_init()
356 pdata->flags |= ENABLE_PORT1; in ohci_pxa_of_init()
357 if (of_property_read_bool(np, "marvell,enable-port2")) in ohci_pxa_of_init()
358 pdata->flags |= ENABLE_PORT2; in ohci_pxa_of_init()
359 if (of_property_read_bool(np, "marvell,enable-port3")) in ohci_pxa_of_init()
360 pdata->flags |= ENABLE_PORT3; in ohci_pxa_of_init()
361 if (of_property_read_bool(np, "marvell,port-sense-low")) in ohci_pxa_of_init()
362 pdata->flags |= POWER_SENSE_LOW; in ohci_pxa_of_init()
363 if (of_property_read_bool(np, "marvell,power-control-low")) in ohci_pxa_of_init()
364 pdata->flags |= POWER_CONTROL_LOW; in ohci_pxa_of_init()
365 if (of_property_read_bool(np, "marvell,no-oc-protection")) in ohci_pxa_of_init()
366 pdata->flags |= NO_OC_PROTECTION; in ohci_pxa_of_init()
367 if (of_property_read_bool(np, "marvell,oc-mode-perport")) in ohci_pxa_of_init()
368 pdata->flags |= OC_MODE_PERPORT; in ohci_pxa_of_init()
369 if (!of_property_read_u32(np, "marvell,power-on-delay", &tmp)) in ohci_pxa_of_init()
370 pdata->power_on_delay = tmp; in ohci_pxa_of_init()
371 if (!of_property_read_u32(np, "marvell,port-mode", &tmp)) in ohci_pxa_of_init()
372 pdata->port_mode = tmp; in ohci_pxa_of_init()
373 if (!of_property_read_u32(np, "marvell,power-budget", &tmp)) in ohci_pxa_of_init()
374 pdata->power_budget = tmp; in ohci_pxa_of_init()
376 pdev->dev.platform_data = pdata; in ohci_pxa_of_init()
387 /*-------------------------------------------------------------------------*/
394 * ohci_hcd_pxa27x_probe - initialize pxa27x-based HCDs
418 inf = dev_get_platdata(&pdev->dev); in ohci_hcd_pxa27x_probe()
421 return -ENODEV; in ohci_hcd_pxa27x_probe()
429 usb_clk = devm_clk_get(&pdev->dev, NULL); in ohci_hcd_pxa27x_probe()
433 hcd = usb_create_hcd(&ohci_pxa27x_hc_driver, &pdev->dev, "pxa27x"); in ohci_hcd_pxa27x_probe()
435 return -ENOMEM; in ohci_hcd_pxa27x_probe()
437 hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &r); in ohci_hcd_pxa27x_probe()
438 if (IS_ERR(hcd->regs)) { in ohci_hcd_pxa27x_probe()
439 retval = PTR_ERR(hcd->regs); in ohci_hcd_pxa27x_probe()
442 hcd->rsrc_start = r->start; in ohci_hcd_pxa27x_probe()
443 hcd->rsrc_len = resource_size(r); in ohci_hcd_pxa27x_probe()
447 pxa_ohci->clk = usb_clk; in ohci_hcd_pxa27x_probe()
448 pxa_ohci->mmio_base = (void __iomem *)hcd->regs; in ohci_hcd_pxa27x_probe()
453 if (!(inf->flags & (ENABLE_PORT1 << i))) in ohci_hcd_pxa27x_probe()
457 pxa_ohci->vbus[i] = devm_regulator_get(&pdev->dev, name); in ohci_hcd_pxa27x_probe()
460 retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); in ohci_hcd_pxa27x_probe()
466 /* Select Power Management Mode */ in ohci_hcd_pxa27x_probe()
467 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode); in ohci_hcd_pxa27x_probe()
469 if (inf->power_budget) in ohci_hcd_pxa27x_probe()
470 hcd->power_budget = inf->power_budget; in ohci_hcd_pxa27x_probe()
474 ohci->num_ports = 3; in ohci_hcd_pxa27x_probe()
478 device_wakeup_enable(hcd->self.controller); in ohci_hcd_pxa27x_probe()
482 pxa27x_stop_hc(pxa_ohci, &pdev->dev); in ohci_hcd_pxa27x_probe()
493 * ohci_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
509 pxa27x_stop_hc(pxa_ohci, &pdev->dev); in ohci_hcd_pxa27x_remove()
517 /*-------------------------------------------------------------------------*/
529 if (time_before(jiffies, ohci->next_statechange)) in ohci_hcd_pxa27x_drv_suspend()
531 ohci->next_statechange = jiffies; in ohci_hcd_pxa27x_drv_suspend()
549 if (time_before(jiffies, ohci->next_statechange)) in ohci_hcd_pxa27x_drv_resume()
551 ohci->next_statechange = jiffies; in ohci_hcd_pxa27x_drv_resume()
557 /* Select Power Management Mode */ in ohci_hcd_pxa27x_drv_resume()
558 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode); in ohci_hcd_pxa27x_drv_resume()
575 .name = "pxa27x-ohci",
590 return -ENODEV; in ohci_pxa27x_init()
607 MODULE_ALIAS("platform:pxa27x-ohci");