Mac Lin | 760efe6 | 2010-11-25 23:58:00 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Cavium Networks |
| 3 | * |
| 4 | * This file is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License, Version 2, as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/atomic.h> |
| 11 | #include <mach/cns3xxx.h> |
| 12 | #include <mach/pm.h> |
| 13 | |
| 14 | static int cns3xxx_ehci_init(struct usb_hcd *hcd) |
| 15 | { |
| 16 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 17 | int retval; |
| 18 | |
| 19 | /* |
| 20 | * EHCI and OHCI share the same clock and power, |
| 21 | * resetting twice would cause the 1st controller been reset. |
| 22 | * Therefore only do power up at the first up device, and |
| 23 | * power down at the last down device. |
| 24 | * |
| 25 | * Set USB AHB INCR length to 16 |
| 26 | */ |
| 27 | if (atomic_inc_return(&usb_pwr_ref) == 1) { |
| 28 | cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB); |
| 29 | cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST); |
| 30 | cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST); |
| 31 | __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)), |
| 32 | MISC_CHIP_CONFIG_REG); |
| 33 | } |
| 34 | |
| 35 | ehci->caps = hcd->regs; |
Mac Lin | 760efe6 | 2010-11-25 23:58:00 +0800 | [diff] [blame] | 36 | |
| 37 | hcd->has_tt = 0; |
Mac Lin | 760efe6 | 2010-11-25 23:58:00 +0800 | [diff] [blame] | 38 | |
Alan Stern | 1a49e2a | 2012-07-09 15:55:14 -0400 | [diff] [blame] | 39 | retval = ehci_setup(hcd); |
Mac Lin | 760efe6 | 2010-11-25 23:58:00 +0800 | [diff] [blame] | 40 | if (retval) |
| 41 | return retval; |
| 42 | |
| 43 | ehci_port_power(ehci, 0); |
| 44 | |
| 45 | return retval; |
| 46 | } |
| 47 | |
| 48 | static const struct hc_driver cns3xxx_ehci_hc_driver = { |
| 49 | .description = hcd_name, |
| 50 | .product_desc = "CNS3XXX EHCI Host Controller", |
| 51 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 52 | .irq = ehci_irq, |
| 53 | .flags = HCD_MEMORY | HCD_USB2, |
| 54 | .reset = cns3xxx_ehci_init, |
| 55 | .start = ehci_run, |
| 56 | .stop = ehci_stop, |
| 57 | .shutdown = ehci_shutdown, |
| 58 | .urb_enqueue = ehci_urb_enqueue, |
| 59 | .urb_dequeue = ehci_urb_dequeue, |
| 60 | .endpoint_disable = ehci_endpoint_disable, |
| 61 | .endpoint_reset = ehci_endpoint_reset, |
| 62 | .get_frame_number = ehci_get_frame, |
| 63 | .hub_status_data = ehci_hub_status_data, |
| 64 | .hub_control = ehci_hub_control, |
| 65 | #ifdef CONFIG_PM |
| 66 | .bus_suspend = ehci_bus_suspend, |
| 67 | .bus_resume = ehci_bus_resume, |
| 68 | #endif |
| 69 | .relinquish_port = ehci_relinquish_port, |
| 70 | .port_handed_over = ehci_port_handed_over, |
| 71 | |
| 72 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 73 | }; |
| 74 | |
| 75 | static int cns3xxx_ehci_probe(struct platform_device *pdev) |
| 76 | { |
| 77 | struct device *dev = &pdev->dev; |
| 78 | struct usb_hcd *hcd; |
| 79 | const struct hc_driver *driver = &cns3xxx_ehci_hc_driver; |
| 80 | struct resource *res; |
| 81 | int irq; |
| 82 | int retval; |
| 83 | |
| 84 | if (usb_disabled()) |
| 85 | return -ENODEV; |
| 86 | |
| 87 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 88 | if (!res) { |
| 89 | dev_err(dev, "Found HC with no IRQ.\n"); |
| 90 | return -ENODEV; |
| 91 | } |
| 92 | irq = res->start; |
| 93 | |
| 94 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); |
| 95 | if (!hcd) |
| 96 | return -ENOMEM; |
| 97 | |
| 98 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 99 | if (!res) { |
| 100 | dev_err(dev, "Found HC with no register addr.\n"); |
| 101 | retval = -ENODEV; |
| 102 | goto err1; |
| 103 | } |
| 104 | |
| 105 | hcd->rsrc_start = res->start; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 106 | hcd->rsrc_len = resource_size(res); |
Mac Lin | 760efe6 | 2010-11-25 23:58:00 +0800 | [diff] [blame] | 107 | |
| 108 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, |
| 109 | driver->description)) { |
| 110 | dev_dbg(dev, "controller already in use\n"); |
| 111 | retval = -EBUSY; |
| 112 | goto err1; |
| 113 | } |
| 114 | |
| 115 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 116 | if (hcd->regs == NULL) { |
| 117 | dev_dbg(dev, "error mapping memory\n"); |
| 118 | retval = -EFAULT; |
| 119 | goto err2; |
| 120 | } |
| 121 | |
| 122 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 123 | if (retval == 0) |
| 124 | return retval; |
| 125 | |
| 126 | iounmap(hcd->regs); |
| 127 | err2: |
| 128 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 129 | err1: |
| 130 | usb_put_hcd(hcd); |
| 131 | |
| 132 | return retval; |
| 133 | } |
| 134 | |
| 135 | static int cns3xxx_ehci_remove(struct platform_device *pdev) |
| 136 | { |
| 137 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 138 | |
| 139 | usb_remove_hcd(hcd); |
| 140 | iounmap(hcd->regs); |
| 141 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 142 | |
| 143 | /* |
| 144 | * EHCI and OHCI share the same clock and power, |
| 145 | * resetting twice would cause the 1st controller been reset. |
| 146 | * Therefore only do power up at the first up device, and |
| 147 | * power down at the last down device. |
| 148 | */ |
| 149 | if (atomic_dec_return(&usb_pwr_ref) == 0) |
| 150 | cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST); |
| 151 | |
| 152 | usb_put_hcd(hcd); |
| 153 | |
| 154 | platform_set_drvdata(pdev, NULL); |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | MODULE_ALIAS("platform:cns3xxx-ehci"); |
| 160 | |
| 161 | static struct platform_driver cns3xxx_ehci_driver = { |
| 162 | .probe = cns3xxx_ehci_probe, |
| 163 | .remove = cns3xxx_ehci_remove, |
| 164 | .driver = { |
| 165 | .name = "cns3xxx-ehci", |
| 166 | }, |
| 167 | }; |