Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Glue code for the ISP1760 driver and bus |
| 3 | * Currently there is support for |
| 4 | * - OpenFirmware |
| 5 | * - PCI |
Michael Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 6 | * - PDEV (generic platform device centralized driver model) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 7 | * |
| 8 | * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de> |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/usb.h> |
| 13 | #include <linux/io.h> |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Michael Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 15 | #include <linux/usb/isp1760.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 16 | #include <linux/usb/hcd.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 17 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 18 | #include "isp1760-hcd.h" |
| 19 | |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 20 | #ifdef CONFIG_PPC_OF |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/of_platform.h> |
| 23 | #endif |
| 24 | |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 25 | #ifdef CONFIG_PCI |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 26 | #include <linux/pci.h> |
| 27 | #endif |
| 28 | |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 29 | #ifdef CONFIG_PPC_OF |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 30 | static int of_isp1760_probe(struct platform_device *dev, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 31 | const struct of_device_id *match) |
| 32 | { |
| 33 | struct usb_hcd *hcd; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 34 | struct device_node *dp = dev->dev.of_node; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 35 | struct resource *res; |
| 36 | struct resource memory; |
| 37 | struct of_irq oirq; |
| 38 | int virq; |
Tobias Klauser | e07afd3 | 2010-05-05 11:18:41 +0200 | [diff] [blame] | 39 | resource_size_t res_len; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 40 | int ret; |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 41 | const unsigned int *prop; |
| 42 | unsigned int devflags = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 43 | |
| 44 | ret = of_address_to_resource(dp, 0, &memory); |
| 45 | if (ret) |
| 46 | return -ENXIO; |
| 47 | |
Tobias Klauser | e07afd3 | 2010-05-05 11:18:41 +0200 | [diff] [blame] | 48 | res_len = resource_size(&memory); |
| 49 | |
| 50 | res = request_mem_region(memory.start, res_len, dev_name(&dev->dev)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 51 | if (!res) |
| 52 | return -EBUSY; |
| 53 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 54 | if (of_irq_map_one(dp, 0, &oirq)) { |
| 55 | ret = -ENODEV; |
| 56 | goto release_reg; |
| 57 | } |
| 58 | |
| 59 | virq = irq_create_of_mapping(oirq.controller, oirq.specifier, |
| 60 | oirq.size); |
| 61 | |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 62 | if (of_device_is_compatible(dp, "nxp,usb-isp1761")) |
| 63 | devflags |= ISP1760_FLAG_ISP1761; |
| 64 | |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 65 | /* Some systems wire up only 16 of the 32 data lines */ |
| 66 | prop = of_get_property(dp, "bus-width", NULL); |
| 67 | if (prop && *prop == 16) |
| 68 | devflags |= ISP1760_FLAG_BUS_WIDTH_16; |
| 69 | |
| 70 | if (of_get_property(dp, "port1-otg", NULL) != NULL) |
| 71 | devflags |= ISP1760_FLAG_OTG_EN; |
| 72 | |
| 73 | if (of_get_property(dp, "analog-oc", NULL) != NULL) |
| 74 | devflags |= ISP1760_FLAG_ANALOG_OC; |
| 75 | |
| 76 | if (of_get_property(dp, "dack-polarity", NULL) != NULL) |
| 77 | devflags |= ISP1760_FLAG_DACK_POL_HIGH; |
| 78 | |
| 79 | if (of_get_property(dp, "dreq-polarity", NULL) != NULL) |
| 80 | devflags |= ISP1760_FLAG_DREQ_POL_HIGH; |
| 81 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 82 | hcd = isp1760_register(memory.start, res_len, virq, |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 83 | IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev), |
| 84 | devflags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 85 | if (IS_ERR(hcd)) { |
| 86 | ret = PTR_ERR(hcd); |
| 87 | goto release_reg; |
| 88 | } |
| 89 | |
| 90 | dev_set_drvdata(&dev->dev, hcd); |
| 91 | return ret; |
| 92 | |
| 93 | release_reg: |
Tobias Klauser | e07afd3 | 2010-05-05 11:18:41 +0200 | [diff] [blame] | 94 | release_mem_region(memory.start, res_len); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 95 | return ret; |
| 96 | } |
| 97 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 98 | static int of_isp1760_remove(struct platform_device *dev) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 99 | { |
| 100 | struct usb_hcd *hcd = dev_get_drvdata(&dev->dev); |
| 101 | |
| 102 | dev_set_drvdata(&dev->dev, NULL); |
| 103 | |
| 104 | usb_remove_hcd(hcd); |
| 105 | iounmap(hcd->regs); |
| 106 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 107 | usb_put_hcd(hcd); |
| 108 | return 0; |
| 109 | } |
| 110 | |
Németh Márton | c4386ad | 2010-01-10 15:35:03 +0100 | [diff] [blame] | 111 | static const struct of_device_id of_isp1760_match[] = { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 112 | { |
| 113 | .compatible = "nxp,usb-isp1760", |
| 114 | }, |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 115 | { |
| 116 | .compatible = "nxp,usb-isp1761", |
| 117 | }, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 118 | { }, |
| 119 | }; |
| 120 | MODULE_DEVICE_TABLE(of, of_isp1760_match); |
| 121 | |
| 122 | static struct of_platform_driver isp1760_of_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 123 | .driver = { |
| 124 | .name = "nxp-isp1760", |
| 125 | .owner = THIS_MODULE, |
| 126 | .of_match_table = of_isp1760_match, |
| 127 | }, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 128 | .probe = of_isp1760_probe, |
| 129 | .remove = of_isp1760_remove, |
| 130 | }; |
| 131 | #endif |
| 132 | |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 133 | #ifdef CONFIG_PCI |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 134 | static int __devinit isp1761_pci_probe(struct pci_dev *dev, |
| 135 | const struct pci_device_id *id) |
| 136 | { |
| 137 | u8 latency, limit; |
| 138 | __u32 reg_data; |
| 139 | int retry_count; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 140 | struct usb_hcd *hcd; |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 141 | unsigned int devflags = 0; |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 142 | int ret_status = 0; |
| 143 | |
| 144 | resource_size_t pci_mem_phy0; |
| 145 | resource_size_t memlength; |
| 146 | |
| 147 | u8 __iomem *chip_addr; |
| 148 | u8 __iomem *iobase; |
| 149 | resource_size_t nxp_pci_io_base; |
| 150 | resource_size_t iolength; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 151 | |
| 152 | if (usb_disabled()) |
| 153 | return -ENODEV; |
| 154 | |
| 155 | if (pci_enable_device(dev) < 0) |
| 156 | return -ENODEV; |
| 157 | |
| 158 | if (!dev->irq) |
| 159 | return -ENODEV; |
| 160 | |
| 161 | /* Grab the PLX PCI mem maped port start address we need */ |
| 162 | nxp_pci_io_base = pci_resource_start(dev, 0); |
| 163 | iolength = pci_resource_len(dev, 0); |
| 164 | |
| 165 | if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) { |
| 166 | printk(KERN_ERR "request region #1\n"); |
| 167 | return -EBUSY; |
| 168 | } |
| 169 | |
| 170 | iobase = ioremap_nocache(nxp_pci_io_base, iolength); |
| 171 | if (!iobase) { |
| 172 | printk(KERN_ERR "ioremap #1\n"); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 173 | ret_status = -ENOMEM; |
| 174 | goto cleanup1; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 175 | } |
| 176 | /* Grab the PLX PCI shared memory of the ISP 1761 we need */ |
| 177 | pci_mem_phy0 = pci_resource_start(dev, 3); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 178 | memlength = pci_resource_len(dev, 3); |
| 179 | if (memlength < 0xffff) { |
| 180 | printk(KERN_ERR "memory length for this resource is wrong\n"); |
| 181 | ret_status = -ENOMEM; |
| 182 | goto cleanup2; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 185 | if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 186 | printk(KERN_ERR "host controller already in use\n"); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 187 | ret_status = -EBUSY; |
| 188 | goto cleanup2; |
| 189 | } |
| 190 | |
| 191 | /* map available memory */ |
| 192 | chip_addr = ioremap_nocache(pci_mem_phy0,memlength); |
| 193 | if (!chip_addr) { |
| 194 | printk(KERN_ERR "Error ioremap failed\n"); |
| 195 | ret_status = -ENOMEM; |
| 196 | goto cleanup3; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* bad pci latencies can contribute to overruns */ |
| 200 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency); |
| 201 | if (latency) { |
| 202 | pci_read_config_byte(dev, PCI_MAX_LAT, &limit); |
| 203 | if (limit && limit < latency) |
| 204 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit); |
| 205 | } |
| 206 | |
| 207 | /* Try to check whether we can access Scratch Register of |
| 208 | * Host Controller or not. The initial PCI access is retried until |
| 209 | * local init for the PCI bridge is completed |
| 210 | */ |
| 211 | retry_count = 20; |
| 212 | reg_data = 0; |
| 213 | while ((reg_data != 0xFACE) && retry_count) { |
| 214 | /*by default host is in 16bit mode, so |
| 215 | * io operations at this stage must be 16 bit |
| 216 | * */ |
| 217 | writel(0xface, chip_addr + HC_SCRATCH_REG); |
| 218 | udelay(100); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 219 | reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 220 | retry_count--; |
| 221 | } |
| 222 | |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 223 | iounmap(chip_addr); |
| 224 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 225 | /* Host Controller presence is detected by writing to scratch register |
| 226 | * and reading back and checking the contents are same or not |
| 227 | */ |
| 228 | if (reg_data != 0xFACE) { |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 229 | dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 230 | ret_status = -ENOMEM; |
| 231 | goto cleanup3; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | pci_set_master(dev); |
| 235 | |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 236 | /* configure PLX PCI chip to pass interrupts */ |
| 237 | #define PLX_INT_CSR_REG 0x68 |
| 238 | reg_data = readl(iobase + PLX_INT_CSR_REG); |
| 239 | reg_data |= 0x900; |
| 240 | writel(reg_data, iobase + PLX_INT_CSR_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 241 | |
| 242 | dev->dev.dma_mask = NULL; |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 243 | hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq, |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 244 | IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev), |
| 245 | devflags); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 246 | if (IS_ERR(hcd)) { |
| 247 | ret_status = -ENODEV; |
| 248 | goto cleanup3; |
Julien Brunel | ce5dee5 | 2008-09-24 18:00:36 +0200 | [diff] [blame] | 249 | } |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 250 | |
| 251 | /* done with PLX IO access */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 252 | iounmap(iobase); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 253 | release_mem_region(nxp_pci_io_base, iolength); |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 254 | |
| 255 | pci_set_drvdata(dev, hcd); |
| 256 | return 0; |
| 257 | |
| 258 | cleanup3: |
| 259 | release_mem_region(pci_mem_phy0, memlength); |
| 260 | cleanup2: |
| 261 | iounmap(iobase); |
| 262 | cleanup1: |
| 263 | release_mem_region(nxp_pci_io_base, iolength); |
| 264 | return ret_status; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 265 | } |
Karl Bongers | 6013bbb | 2008-12-01 11:47:40 +0100 | [diff] [blame] | 266 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 267 | static void isp1761_pci_remove(struct pci_dev *dev) |
| 268 | { |
| 269 | struct usb_hcd *hcd; |
| 270 | |
| 271 | hcd = pci_get_drvdata(dev); |
| 272 | |
| 273 | usb_remove_hcd(hcd); |
| 274 | iounmap(hcd->regs); |
| 275 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 276 | usb_put_hcd(hcd); |
| 277 | |
| 278 | pci_disable_device(dev); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static void isp1761_pci_shutdown(struct pci_dev *dev) |
| 282 | { |
| 283 | printk(KERN_ERR "ips1761_pci_shutdown\n"); |
| 284 | } |
| 285 | |
Sebastian Andrzej Siewior | 6c07356 | 2008-11-30 16:50:04 +0100 | [diff] [blame] | 286 | static const struct pci_device_id isp1760_plx [] = { |
| 287 | { |
| 288 | .class = PCI_CLASS_BRIDGE_OTHER << 8, |
| 289 | .class_mask = ~0, |
| 290 | .vendor = PCI_VENDOR_ID_PLX, |
| 291 | .device = 0x5406, |
| 292 | .subvendor = PCI_VENDOR_ID_PLX, |
| 293 | .subdevice = 0x9054, |
| 294 | }, |
| 295 | { } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 296 | }; |
| 297 | MODULE_DEVICE_TABLE(pci, isp1760_plx); |
| 298 | |
| 299 | static struct pci_driver isp1761_pci_driver = { |
| 300 | .name = "isp1760", |
| 301 | .id_table = isp1760_plx, |
| 302 | .probe = isp1761_pci_probe, |
| 303 | .remove = isp1761_pci_remove, |
| 304 | .shutdown = isp1761_pci_shutdown, |
| 305 | }; |
| 306 | #endif |
| 307 | |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 308 | static int __devinit isp1760_plat_probe(struct platform_device *pdev) |
| 309 | { |
| 310 | int ret = 0; |
| 311 | struct usb_hcd *hcd; |
| 312 | struct resource *mem_res; |
| 313 | struct resource *irq_res; |
| 314 | resource_size_t mem_size; |
Michael Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 315 | struct isp1760_platform_data *priv = pdev->dev.platform_data; |
| 316 | unsigned int devflags = 0; |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 317 | unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED; |
| 318 | |
| 319 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 320 | if (!mem_res) { |
| 321 | pr_warning("isp1760: Memory resource not available\n"); |
| 322 | ret = -ENODEV; |
| 323 | goto out; |
| 324 | } |
| 325 | mem_size = resource_size(mem_res); |
| 326 | if (!request_mem_region(mem_res->start, mem_size, "isp1760")) { |
| 327 | pr_warning("isp1760: Cannot reserve the memory resource\n"); |
| 328 | ret = -EBUSY; |
| 329 | goto out; |
| 330 | } |
| 331 | |
| 332 | irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 333 | if (!irq_res) { |
| 334 | pr_warning("isp1760: IRQ resource not available\n"); |
| 335 | return -ENODEV; |
| 336 | } |
| 337 | irqflags |= irq_res->flags & IRQF_TRIGGER_MASK; |
| 338 | |
Michael Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 339 | if (priv) { |
| 340 | if (priv->is_isp1761) |
| 341 | devflags |= ISP1760_FLAG_ISP1761; |
| 342 | if (priv->bus_width_16) |
| 343 | devflags |= ISP1760_FLAG_BUS_WIDTH_16; |
| 344 | if (priv->port1_otg) |
| 345 | devflags |= ISP1760_FLAG_OTG_EN; |
| 346 | if (priv->analog_oc) |
| 347 | devflags |= ISP1760_FLAG_ANALOG_OC; |
| 348 | if (priv->dack_polarity_high) |
| 349 | devflags |= ISP1760_FLAG_DACK_POL_HIGH; |
| 350 | if (priv->dreq_polarity_high) |
| 351 | devflags |= ISP1760_FLAG_DREQ_POL_HIGH; |
| 352 | } |
| 353 | |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 354 | hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, |
Michael Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 355 | irqflags, &pdev->dev, dev_name(&pdev->dev), devflags); |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 356 | if (IS_ERR(hcd)) { |
| 357 | pr_warning("isp1760: Failed to register the HCD device\n"); |
| 358 | ret = -ENODEV; |
| 359 | goto cleanup; |
| 360 | } |
| 361 | |
| 362 | pr_info("ISP1760 USB device initialised\n"); |
| 363 | return ret; |
| 364 | |
| 365 | cleanup: |
| 366 | release_mem_region(mem_res->start, mem_size); |
| 367 | out: |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | static int __devexit isp1760_plat_remove(struct platform_device *pdev) |
| 372 | { |
| 373 | struct resource *mem_res; |
| 374 | resource_size_t mem_size; |
| 375 | |
| 376 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 377 | mem_size = resource_size(mem_res); |
| 378 | release_mem_region(mem_res->start, mem_size); |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | static struct platform_driver isp1760_plat_driver = { |
| 384 | .probe = isp1760_plat_probe, |
Mike Frysinger | 4198e4f | 2009-06-11 21:59:00 -0400 | [diff] [blame] | 385 | .remove = __devexit_p(isp1760_plat_remove), |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 386 | .driver = { |
| 387 | .name = "isp1760", |
| 388 | }, |
| 389 | }; |
| 390 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 391 | static int __init isp1760_init(void) |
| 392 | { |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 393 | int ret, any_ret = -ENODEV; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 394 | |
| 395 | init_kmem_once(); |
| 396 | |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 397 | ret = platform_driver_register(&isp1760_plat_driver); |
| 398 | if (!ret) |
| 399 | any_ret = 0; |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 400 | #ifdef CONFIG_PPC_OF |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 401 | ret = of_register_platform_driver(&isp1760_of_driver); |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 402 | if (!ret) |
| 403 | any_ret = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 404 | #endif |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 405 | #ifdef CONFIG_PCI |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 406 | ret = pci_register_driver(&isp1761_pci_driver); |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 407 | if (!ret) |
| 408 | any_ret = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 409 | #endif |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 410 | |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 411 | if (any_ret) |
| 412 | deinit_kmem_cache(); |
| 413 | return any_ret; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 414 | } |
| 415 | module_init(isp1760_init); |
| 416 | |
| 417 | static void __exit isp1760_exit(void) |
| 418 | { |
Catalin Marinas | f7e7aa5 | 2009-02-10 16:55:51 +0000 | [diff] [blame] | 419 | platform_driver_unregister(&isp1760_plat_driver); |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 420 | #ifdef CONFIG_PPC_OF |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 421 | of_unregister_platform_driver(&isp1760_of_driver); |
| 422 | #endif |
Sebastian Andrzej Siewior | ff30bf1 | 2008-11-02 15:25:42 +0100 | [diff] [blame] | 423 | #ifdef CONFIG_PCI |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 424 | pci_unregister_driver(&isp1761_pci_driver); |
| 425 | #endif |
| 426 | deinit_kmem_cache(); |
| 427 | } |
| 428 | module_exit(isp1760_exit); |