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>
31 #include <linux/platform_data/usb-ohci-pxa27x.h>
32 #include <linux/platform_data/usb-pxa3xx-ulpi.h>
47 * UHC: USB Host Controller (OHCI-like) register definitions
70 #define UHCRHDA_OCPM (1 << 11) /* Over Current Protection Mode */
81 #define UHCSTAT_UPS3 (1 << 16) /* USB Power Sense Port3 */
85 #define UHCSTAT_UPS2 (1 << 12) /* USB Power Sense Port 2 */
86 #define UHCSTAT_UPS1 (1 << 11) /* USB Power Sense Port 1 */
96 #define UHCHR_PSPL (1 << 6) /* Power sense polarity low */
105 #define UHCHIE_UPS3IE (1 << 14) /* Power Sense Port3 IntEn */
107 #define UHCHIE_UPS2IE (1 << 12) /* Power Sense Port2 IntEn */
108 #define UHCHIE_UPS1IE (1 << 11) /* Power Sense Port1 IntEn */
112 #define UHCHIE_RWIE (1 << 7) /* Remote Wake-up IntEn */
118 static const char hcd_name[] = "ohci-pxa27x";
129 #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv)
132 PMM_NPS_MODE -- PMM Non-power switching mode
135 PMM_GLOBAL_MODE -- PMM global switching mode
138 PMM_PERPORT_MODE -- PMM per port switching mode
141 static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *pxa_ohci, int mode) in pxa27x_ohci_select_pmm() argument
143 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA); in pxa27x_ohci_select_pmm()
144 uint32_t uhcrhdb = __raw_readl(pxa_ohci->mmio_base + UHCRHDB); in pxa27x_ohci_select_pmm()
146 switch (mode) { in pxa27x_ohci_select_pmm()
162 "Invalid mode %d, set to non-power switch mode.\n", in pxa27x_ohci_select_pmm()
163 mode ); in pxa27x_ohci_select_pmm()
168 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA); in pxa27x_ohci_select_pmm()
169 __raw_writel(uhcrhdb, pxa_ohci->mmio_base + UHCRHDB); in pxa27x_ohci_select_pmm()
176 struct regulator *vbus = pxa_ohci->vbus[port]; in pxa27x_ohci_set_vbus_power()
182 if (enable && !pxa_ohci->vbus_enabled[port]) in pxa27x_ohci_set_vbus_power()
184 else if (!enable && pxa_ohci->vbus_enabled[port]) in pxa27x_ohci_set_vbus_power()
190 pxa_ohci->vbus_enabled[port] = enable; in pxa27x_ohci_set_vbus_power()
205 return -EPIPE; in pxa27x_ohci_hub_control()
210 ret = pxa27x_ohci_set_vbus_power(pxa_ohci, wIndex - 1, in pxa27x_ohci_hub_control()
219 /*-------------------------------------------------------------------------*/
224 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR); in pxa27x_setup_hc()
225 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA); in pxa27x_setup_hc()
227 if (inf->flags & ENABLE_PORT1) in pxa27x_setup_hc()
230 if (inf->flags & ENABLE_PORT2) in pxa27x_setup_hc()
233 if (inf->flags & ENABLE_PORT3) in pxa27x_setup_hc()
236 if (inf->flags & POWER_CONTROL_LOW) in pxa27x_setup_hc()
239 if (inf->flags & POWER_SENSE_LOW) in pxa27x_setup_hc()
242 if (inf->flags & NO_OC_PROTECTION) in pxa27x_setup_hc()
247 if (inf->flags & OC_MODE_PERPORT) in pxa27x_setup_hc()
252 if (inf->power_on_delay) { in pxa27x_setup_hc()
254 uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); in pxa27x_setup_hc()
257 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); in pxa27x_setup_hc()
258 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA); in pxa27x_setup_hc()
263 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR); in pxa27x_reset_hc()
265 __raw_writel(uhchr | UHCHR_FHR, pxa_ohci->mmio_base + UHCHR); in pxa27x_reset_hc()
267 __raw_writel(uhchr & ~UHCHR_FHR, pxa_ohci->mmio_base + UHCHR); in pxa27x_reset_hc()
285 retval = clk_prepare_enable(pxa_ohci->clk); in pxa27x_start_hc()
291 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) | UHCHR_FSBIR; in pxa27x_start_hc()
292 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); in pxa27x_start_hc()
294 while (__raw_readl(pxa_ohci->mmio_base + UHCHR) & UHCHR_FSBIR) in pxa27x_start_hc()
299 if (inf->init) in pxa27x_start_hc()
300 retval = inf->init(dev); in pxa27x_start_hc()
303 clk_disable_unprepare(pxa_ohci->clk); in pxa27x_start_hc()
308 pxa3xx_u2d_start_hc(&hcd->self); in pxa27x_start_hc()
310 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) & ~UHCHR_SSE; in pxa27x_start_hc()
311 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR); in pxa27x_start_hc()
312 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, pxa_ohci->mmio_base + UHCHIE); in pxa27x_start_hc()
328 pxa3xx_u2d_stop_hc(&hcd->self); in pxa27x_stop_hc()
330 if (inf->exit) in pxa27x_stop_hc()
331 inf->exit(dev); in pxa27x_stop_hc()
336 uhccoms = __raw_readl(pxa_ohci->mmio_base + UHCCOMS) | 0x01; in pxa27x_stop_hc()
337 __raw_writel(uhccoms, pxa_ohci->mmio_base + UHCCOMS); in pxa27x_stop_hc()
340 clk_disable_unprepare(pxa_ohci->clk); in pxa27x_stop_hc()
345 { .compatible = "marvell,pxa-ohci" },
353 struct device_node *np = pdev->dev.of_node; in ohci_pxa_of_init()
361 /* Right now device-tree probed devices don't get dma_mask set. in ohci_pxa_of_init()
365 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); in ohci_pxa_of_init()
369 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in ohci_pxa_of_init()
371 return -ENOMEM; in ohci_pxa_of_init()
373 if (of_property_read_bool(np, "marvell,enable-port1")) in ohci_pxa_of_init()
374 pdata->flags |= ENABLE_PORT1; in ohci_pxa_of_init()
375 if (of_property_read_bool(np, "marvell,enable-port2")) in ohci_pxa_of_init()
376 pdata->flags |= ENABLE_PORT2; in ohci_pxa_of_init()
377 if (of_property_read_bool(np, "marvell,enable-port3")) in ohci_pxa_of_init()
378 pdata->flags |= ENABLE_PORT3; in ohci_pxa_of_init()
379 if (of_property_read_bool(np, "marvell,port-sense-low")) in ohci_pxa_of_init()
380 pdata->flags |= POWER_SENSE_LOW; in ohci_pxa_of_init()
381 if (of_property_read_bool(np, "marvell,power-control-low")) in ohci_pxa_of_init()
382 pdata->flags |= POWER_CONTROL_LOW; in ohci_pxa_of_init()
383 if (of_property_read_bool(np, "marvell,no-oc-protection")) in ohci_pxa_of_init()
384 pdata->flags |= NO_OC_PROTECTION; in ohci_pxa_of_init()
385 if (of_property_read_bool(np, "marvell,oc-mode-perport")) in ohci_pxa_of_init()
386 pdata->flags |= OC_MODE_PERPORT; in ohci_pxa_of_init()
387 if (!of_property_read_u32(np, "marvell,power-on-delay", &tmp)) in ohci_pxa_of_init()
388 pdata->power_on_delay = tmp; in ohci_pxa_of_init()
389 if (!of_property_read_u32(np, "marvell,port-mode", &tmp)) in ohci_pxa_of_init()
390 pdata->port_mode = tmp; in ohci_pxa_of_init()
391 if (!of_property_read_u32(np, "marvell,power-budget", &tmp)) in ohci_pxa_of_init()
392 pdata->power_budget = tmp; in ohci_pxa_of_init()
394 pdev->dev.platform_data = pdata; in ohci_pxa_of_init()
405 /*-------------------------------------------------------------------------*/
412 * ohci_hcd_pxa27x_probe - initialize pxa27x-based HCDs
435 inf = dev_get_platdata(&pdev->dev); in ohci_hcd_pxa27x_probe()
438 return -ENODEV; in ohci_hcd_pxa27x_probe()
446 usb_clk = devm_clk_get(&pdev->dev, NULL); in ohci_hcd_pxa27x_probe()
450 hcd = usb_create_hcd(&ohci_pxa27x_hc_driver, &pdev->dev, "pxa27x"); in ohci_hcd_pxa27x_probe()
452 return -ENOMEM; in ohci_hcd_pxa27x_probe()
455 hcd->regs = devm_ioremap_resource(&pdev->dev, r); in ohci_hcd_pxa27x_probe()
456 if (IS_ERR(hcd->regs)) { in ohci_hcd_pxa27x_probe()
457 retval = PTR_ERR(hcd->regs); in ohci_hcd_pxa27x_probe()
460 hcd->rsrc_start = r->start; in ohci_hcd_pxa27x_probe()
461 hcd->rsrc_len = resource_size(r); in ohci_hcd_pxa27x_probe()
465 pxa_ohci->clk = usb_clk; in ohci_hcd_pxa27x_probe()
466 pxa_ohci->mmio_base = (void __iomem *)hcd->regs; in ohci_hcd_pxa27x_probe()
471 if (!(inf->flags & (ENABLE_PORT1 << i))) in ohci_hcd_pxa27x_probe()
475 pxa_ohci->vbus[i] = devm_regulator_get(&pdev->dev, name); in ohci_hcd_pxa27x_probe()
478 retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); in ohci_hcd_pxa27x_probe()
484 /* Select Power Management Mode */ in ohci_hcd_pxa27x_probe()
485 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode); in ohci_hcd_pxa27x_probe()
487 if (inf->power_budget) in ohci_hcd_pxa27x_probe()
488 hcd->power_budget = inf->power_budget; in ohci_hcd_pxa27x_probe()
492 ohci->num_ports = 3; in ohci_hcd_pxa27x_probe()
496 device_wakeup_enable(hcd->self.controller); in ohci_hcd_pxa27x_probe()
500 pxa27x_stop_hc(pxa_ohci, &pdev->dev); in ohci_hcd_pxa27x_probe()
511 * ohci_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
527 pxa27x_stop_hc(pxa_ohci, &pdev->dev); in ohci_hcd_pxa27x_remove()
536 /*-------------------------------------------------------------------------*/
548 if (time_before(jiffies, ohci->next_statechange)) in ohci_hcd_pxa27x_drv_suspend()
550 ohci->next_statechange = jiffies; in ohci_hcd_pxa27x_drv_suspend()
568 if (time_before(jiffies, ohci->next_statechange)) in ohci_hcd_pxa27x_drv_resume()
570 ohci->next_statechange = jiffies; in ohci_hcd_pxa27x_drv_resume()
576 /* Select Power Management Mode */ in ohci_hcd_pxa27x_drv_resume()
577 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode); in ohci_hcd_pxa27x_drv_resume()
594 .name = "pxa27x-ohci",
609 return -ENODEV; in ohci_pxa27x_init()
628 MODULE_ALIAS("platform:pxa27x-ohci");