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