ohci-spear.c (3de80bfc1c9dc2b791e1f00671356279f2a9442b) | ohci-spear.c (22d9d8e8316d7f69046c8805ce9aa8d9c43d4e5b) |
---|---|
1/* 2* OHCI HCD (Host Controller Driver) for USB. 3* 4* Copyright (C) 2010 ST Microelectronics. 5* Deepak Sikri<deepak.sikri@st.com> 6* 7* Based on various ohci-*.c drivers 8* 9* This file is licensed under the terms of the GNU General Public 10* License version 2. This program is licensed "as is" without any 11* warranty of any kind, whether express or implied. 12*/ 13 | 1/* 2* OHCI HCD (Host Controller Driver) for USB. 3* 4* Copyright (C) 2010 ST Microelectronics. 5* Deepak Sikri<deepak.sikri@st.com> 6* 7* Based on various ohci-*.c drivers 8* 9* This file is licensed under the terms of the GNU General Public 10* License version 2. This program is licensed "as is" without any 11* warranty of any kind, whether express or implied. 12*/ 13 |
14#include <linux/signal.h> 15#include <linux/platform_device.h> |
|
14#include <linux/clk.h> | 16#include <linux/clk.h> |
15#include <linux/dma-mapping.h> 16#include <linux/io.h> 17#include <linux/kernel.h> 18#include <linux/module.h> | |
19#include <linux/of.h> | 17#include <linux/of.h> |
20#include <linux/platform_device.h> 21#include <linux/signal.h> 22#include <linux/usb.h> 23#include <linux/usb/hcd.h> | |
24 | 18 |
25#include "ohci.h" 26 27#define DRIVER_DESC "OHCI SPEAr driver" 28 29static const char hcd_name[] = "SPEAr-ohci"; | |
30struct spear_ohci { | 19struct spear_ohci { |
20 struct ohci_hcd ohci; |
|
31 struct clk *clk; 32}; 33 | 21 struct clk *clk; 22}; 23 |
34#define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv) | 24#define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd) |
35 | 25 |
36static struct hc_driver __read_mostly ohci_spear_hc_driver; | 26static void spear_start_ohci(struct spear_ohci *ohci) 27{ 28 clk_prepare_enable(ohci->clk); 29} |
37 | 30 |
31static void spear_stop_ohci(struct spear_ohci *ohci) 32{ 33 clk_disable_unprepare(ohci->clk); 34} 35 36static int ohci_spear_start(struct usb_hcd *hcd) 37{ 38 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 39 int ret; 40 41 ret = ohci_init(ohci); 42 if (ret < 0) 43 return ret; 44 ohci->regs = hcd->regs; 45 46 ret = ohci_run(ohci); 47 if (ret < 0) { 48 dev_err(hcd->self.controller, "can't start\n"); 49 ohci_stop(hcd); 50 return ret; 51 } 52 53 create_debug_files(ohci); 54 55#ifdef DEBUG 56 ohci_dump(ohci, 1); 57#endif 58 return 0; 59} 60 61static const struct hc_driver ohci_spear_hc_driver = { 62 .description = hcd_name, 63 .product_desc = "SPEAr OHCI", 64 .hcd_priv_size = sizeof(struct spear_ohci), 65 66 /* generic hardware linkage */ 67 .irq = ohci_irq, 68 .flags = HCD_USB11 | HCD_MEMORY, 69 70 /* basic lifecycle operations */ 71 .start = ohci_spear_start, 72 .stop = ohci_stop, 73 .shutdown = ohci_shutdown, 74#ifdef CONFIG_PM 75 .bus_suspend = ohci_bus_suspend, 76 .bus_resume = ohci_bus_resume, 77#endif 78 79 /* managing i/o requests and associated device resources */ 80 .urb_enqueue = ohci_urb_enqueue, 81 .urb_dequeue = ohci_urb_dequeue, 82 .endpoint_disable = ohci_endpoint_disable, 83 84 /* scheduling support */ 85 .get_frame_number = ohci_get_frame, 86 87 /* root hub support */ 88 .hub_status_data = ohci_hub_status_data, 89 .hub_control = ohci_hub_control, 90 91 .start_port_reset = ohci_start_port_reset, 92}; 93 |
|
38static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) 39{ 40 const struct hc_driver *driver = &ohci_spear_hc_driver; | 94static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) 95{ 96 const struct hc_driver *driver = &ohci_spear_hc_driver; |
41 struct ohci_hcd *ohci; | |
42 struct usb_hcd *hcd = NULL; 43 struct clk *usbh_clk; | 97 struct usb_hcd *hcd = NULL; 98 struct clk *usbh_clk; |
44 struct spear_ohci *sohci_p; | 99 struct spear_ohci *ohci_p; |
45 struct resource *res; 46 int retval, irq; 47 48 irq = platform_get_irq(pdev, 0); 49 if (irq < 0) { 50 retval = irq; 51 goto fail; 52 } 53 54 /* 55 * Right now device-tree probed devices don't get dma_mask set. 56 * Since shared usb code relies on it, set it here for now. 57 * Once we have dma capability bindings this can go away. 58 */ 59 if (!pdev->dev.dma_mask) 60 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; | 100 struct resource *res; 101 int retval, irq; 102 103 irq = platform_get_irq(pdev, 0); 104 if (irq < 0) { 105 retval = irq; 106 goto fail; 107 } 108 109 /* 110 * Right now device-tree probed devices don't get dma_mask set. 111 * Since shared usb code relies on it, set it here for now. 112 * Once we have dma capability bindings this can go away. 113 */ 114 if (!pdev->dev.dma_mask) 115 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; |
61 if (!pdev->dev.coherent_dma_mask) 62 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); | 116 retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 117 if (retval) 118 goto fail; |
63 64 usbh_clk = devm_clk_get(&pdev->dev, NULL); 65 if (IS_ERR(usbh_clk)) { 66 dev_err(&pdev->dev, "Error getting interface clock\n"); 67 retval = PTR_ERR(usbh_clk); 68 goto fail; 69 } 70 --- 20 unchanged lines hidden (view full) --- 91 92 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); 93 if (!hcd->regs) { 94 dev_dbg(&pdev->dev, "ioremap failed\n"); 95 retval = -ENOMEM; 96 goto err_put_hcd; 97 } 98 | 119 120 usbh_clk = devm_clk_get(&pdev->dev, NULL); 121 if (IS_ERR(usbh_clk)) { 122 dev_err(&pdev->dev, "Error getting interface clock\n"); 123 retval = PTR_ERR(usbh_clk); 124 goto fail; 125 } 126 --- 20 unchanged lines hidden (view full) --- 147 148 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); 149 if (!hcd->regs) { 150 dev_dbg(&pdev->dev, "ioremap failed\n"); 151 retval = -ENOMEM; 152 goto err_put_hcd; 153 } 154 |
99 sohci_p = to_spear_ohci(hcd); 100 sohci_p->clk = usbh_clk; | 155 ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd); 156 ohci_p->clk = usbh_clk; 157 spear_start_ohci(ohci_p); 158 ohci_hcd_init(hcd_to_ohci(hcd)); |
101 | 159 |
102 clk_prepare_enable(sohci_p->clk); 103 104 ohci = hcd_to_ohci(hcd); 105 | |
106 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); 107 if (retval == 0) 108 return retval; 109 | 160 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); 161 if (retval == 0) 162 return retval; 163 |
110 clk_disable_unprepare(sohci_p->clk); | 164 spear_stop_ohci(ohci_p); |
111err_put_hcd: 112 usb_put_hcd(hcd); 113fail: 114 dev_err(&pdev->dev, "init fail, %d\n", retval); 115 116 return retval; 117} 118 119static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) 120{ 121 struct usb_hcd *hcd = platform_get_drvdata(pdev); | 165err_put_hcd: 166 usb_put_hcd(hcd); 167fail: 168 dev_err(&pdev->dev, "init fail, %d\n", retval); 169 170 return retval; 171} 172 173static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) 174{ 175 struct usb_hcd *hcd = platform_get_drvdata(pdev); |
122 struct spear_ohci *sohci_p = to_spear_ohci(hcd); | 176 struct spear_ohci *ohci_p = to_spear_ohci(hcd); |
123 124 usb_remove_hcd(hcd); | 177 178 usb_remove_hcd(hcd); |
125 if (sohci_p->clk) 126 clk_disable_unprepare(sohci_p->clk); | 179 if (ohci_p->clk) 180 spear_stop_ohci(ohci_p); |
127 128 usb_put_hcd(hcd); 129 return 0; 130} 131 132#if defined(CONFIG_PM) 133static int spear_ohci_hcd_drv_suspend(struct platform_device *dev, 134 pm_message_t message) 135{ 136 struct usb_hcd *hcd = platform_get_drvdata(dev); 137 struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 181 182 usb_put_hcd(hcd); 183 return 0; 184} 185 186#if defined(CONFIG_PM) 187static int spear_ohci_hcd_drv_suspend(struct platform_device *dev, 188 pm_message_t message) 189{ 190 struct usb_hcd *hcd = platform_get_drvdata(dev); 191 struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
138 struct spear_ohci *sohci_p = to_spear_ohci(hcd); | 192 struct spear_ohci *ohci_p = to_spear_ohci(hcd); |
139 140 if (time_before(jiffies, ohci->next_statechange)) 141 msleep(5); 142 ohci->next_statechange = jiffies; 143 | 193 194 if (time_before(jiffies, ohci->next_statechange)) 195 msleep(5); 196 ohci->next_statechange = jiffies; 197 |
144 clk_disable_unprepare(sohci_p->clk); 145 | 198 spear_stop_ohci(ohci_p); |
146 return 0; 147} 148 149static int spear_ohci_hcd_drv_resume(struct platform_device *dev) 150{ 151 struct usb_hcd *hcd = platform_get_drvdata(dev); 152 struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 199 return 0; 200} 201 202static int spear_ohci_hcd_drv_resume(struct platform_device *dev) 203{ 204 struct usb_hcd *hcd = platform_get_drvdata(dev); 205 struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
153 struct spear_ohci *sohci_p = to_spear_ohci(hcd); | 206 struct spear_ohci *ohci_p = to_spear_ohci(hcd); |
154 155 if (time_before(jiffies, ohci->next_statechange)) 156 msleep(5); 157 ohci->next_statechange = jiffies; 158 | 207 208 if (time_before(jiffies, ohci->next_statechange)) 209 msleep(5); 210 ohci->next_statechange = jiffies; 211 |
159 clk_prepare_enable(sohci_p->clk); | 212 spear_start_ohci(ohci_p); |
160 ohci_resume(hcd, false); 161 return 0; 162} 163#endif 164 165static struct of_device_id spear_ohci_id_table[] = { 166 { .compatible = "st,spear600-ohci", }, 167 { }, --- 9 unchanged lines hidden (view full) --- 177#endif 178 .driver = { 179 .owner = THIS_MODULE, 180 .name = "spear-ohci", 181 .of_match_table = spear_ohci_id_table, 182 }, 183}; 184 | 213 ohci_resume(hcd, false); 214 return 0; 215} 216#endif 217 218static struct of_device_id spear_ohci_id_table[] = { 219 { .compatible = "st,spear600-ohci", }, 220 { }, --- 9 unchanged lines hidden (view full) --- 230#endif 231 .driver = { 232 .owner = THIS_MODULE, 233 .name = "spear-ohci", 234 .of_match_table = spear_ohci_id_table, 235 }, 236}; 237 |
185static const struct ohci_driver_overrides spear_overrides __initconst = { 186 .extra_priv_size = sizeof(struct spear_ohci), 187}; 188static int __init ohci_spear_init(void) 189{ 190 if (usb_disabled()) 191 return -ENODEV; 192 193 pr_info("%s: " DRIVER_DESC "\n", hcd_name); 194 195 ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides); 196 return platform_driver_register(&spear_ohci_hcd_driver); 197} 198module_init(ohci_spear_init); 199 200static void __exit ohci_spear_cleanup(void) 201{ 202 platform_driver_unregister(&spear_ohci_hcd_driver); 203} 204module_exit(ohci_spear_cleanup); 205 206MODULE_DESCRIPTION(DRIVER_DESC); 207MODULE_AUTHOR("Deepak Sikri"); 208MODULE_LICENSE("GPL v2"); | |
209MODULE_ALIAS("platform:spear-ohci"); | 238MODULE_ALIAS("platform:spear-ohci"); |