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