2008-04-24 06:37:04 +08:00
|
|
|
/*
|
|
|
|
* Glue code for the ISP1760 driver and bus
|
|
|
|
* Currently there is support for
|
|
|
|
* - OpenFirmware
|
|
|
|
* - PCI
|
2009-07-16 11:22:54 +08:00
|
|
|
* - PDEV (generic platform device centralized driver model)
|
2008-04-24 06:37:04 +08:00
|
|
|
*
|
|
|
|
* (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/io.h>
|
2011-07-04 04:09:31 +08:00
|
|
|
#include <linux/module.h>
|
2015-01-21 06:55:44 +08:00
|
|
|
#include <linux/of.h>
|
2009-02-11 00:55:51 +08:00
|
|
|
#include <linux/platform_device.h>
|
2015-01-21 06:55:44 +08:00
|
|
|
#include <linux/slab.h>
|
2009-07-16 11:22:54 +08:00
|
|
|
#include <linux/usb/isp1760.h>
|
2010-04-25 05:21:52 +08:00
|
|
|
#include <linux/usb/hcd.h>
|
2008-04-24 06:37:04 +08:00
|
|
|
|
2015-01-21 06:55:57 +08:00
|
|
|
#include "isp1760-core.h"
|
2015-01-21 06:55:56 +08:00
|
|
|
#include "isp1760-regs.h"
|
2008-04-24 06:37:04 +08:00
|
|
|
|
2017-02-25 19:20:55 +08:00
|
|
|
#ifdef CONFIG_USB_PCI
|
2008-04-24 06:37:04 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#endif
|
|
|
|
|
2017-02-25 19:20:55 +08:00
|
|
|
#ifdef CONFIG_USB_PCI
|
2015-01-21 06:55:53 +08:00
|
|
|
static int isp1761_pci_init(struct pci_dev *dev)
|
2008-04-24 06:37:04 +08:00
|
|
|
{
|
2015-01-21 06:55:53 +08:00
|
|
|
resource_size_t mem_start;
|
|
|
|
resource_size_t mem_length;
|
|
|
|
u8 __iomem *iobase;
|
2008-04-24 06:37:04 +08:00
|
|
|
u8 latency, limit;
|
|
|
|
int retry_count;
|
2015-01-21 06:55:53 +08:00
|
|
|
u32 reg_data;
|
2008-04-24 06:37:04 +08:00
|
|
|
|
|
|
|
/* Grab the PLX PCI shared memory of the ISP 1761 we need */
|
2015-01-21 06:55:53 +08:00
|
|
|
mem_start = pci_resource_start(dev, 3);
|
|
|
|
mem_length = pci_resource_len(dev, 3);
|
|
|
|
if (mem_length < 0xffff) {
|
2008-12-01 18:47:40 +08:00
|
|
|
printk(KERN_ERR "memory length for this resource is wrong\n");
|
2015-01-21 06:55:53 +08:00
|
|
|
return -ENOMEM;
|
2008-04-24 06:37:04 +08:00
|
|
|
}
|
|
|
|
|
2015-01-21 06:55:53 +08:00
|
|
|
if (!request_mem_region(mem_start, mem_length, "ISP-PCI")) {
|
2008-04-24 06:37:04 +08:00
|
|
|
printk(KERN_ERR "host controller already in use\n");
|
2015-01-21 06:55:53 +08:00
|
|
|
return -EBUSY;
|
2008-12-01 18:47:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* map available memory */
|
2015-01-21 06:55:53 +08:00
|
|
|
iobase = ioremap_nocache(mem_start, mem_length);
|
|
|
|
if (!iobase) {
|
2008-12-01 18:47:40 +08:00
|
|
|
printk(KERN_ERR "Error ioremap failed\n");
|
2015-01-21 06:55:53 +08:00
|
|
|
release_mem_region(mem_start, mem_length);
|
|
|
|
return -ENOMEM;
|
2008-04-24 06:37:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* bad pci latencies can contribute to overruns */
|
|
|
|
pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
|
|
|
|
if (latency) {
|
|
|
|
pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
|
|
|
|
if (limit && limit < latency)
|
|
|
|
pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to check whether we can access Scratch Register of
|
|
|
|
* Host Controller or not. The initial PCI access is retried until
|
|
|
|
* local init for the PCI bridge is completed
|
|
|
|
*/
|
|
|
|
retry_count = 20;
|
|
|
|
reg_data = 0;
|
|
|
|
while ((reg_data != 0xFACE) && retry_count) {
|
|
|
|
/*by default host is in 16bit mode, so
|
|
|
|
* io operations at this stage must be 16 bit
|
|
|
|
* */
|
2015-01-21 06:55:53 +08:00
|
|
|
writel(0xface, iobase + HC_SCRATCH_REG);
|
2008-04-24 06:37:04 +08:00
|
|
|
udelay(100);
|
2015-01-21 06:55:53 +08:00
|
|
|
reg_data = readl(iobase + HC_SCRATCH_REG) & 0x0000ffff;
|
2008-04-24 06:37:04 +08:00
|
|
|
retry_count--;
|
|
|
|
}
|
|
|
|
|
2015-01-21 06:55:53 +08:00
|
|
|
iounmap(iobase);
|
|
|
|
release_mem_region(mem_start, mem_length);
|
2008-12-01 18:47:40 +08:00
|
|
|
|
2008-04-24 06:37:04 +08:00
|
|
|
/* Host Controller presence is detected by writing to scratch register
|
|
|
|
* and reading back and checking the contents are same or not
|
|
|
|
*/
|
|
|
|
if (reg_data != 0xFACE) {
|
2008-08-15 00:37:34 +08:00
|
|
|
dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
|
2015-01-21 06:55:53 +08:00
|
|
|
return -ENOMEM;
|
2008-04-24 06:37:04 +08:00
|
|
|
}
|
|
|
|
|
2015-01-21 06:55:53 +08:00
|
|
|
/* Grab the PLX PCI mem maped port start address we need */
|
|
|
|
mem_start = pci_resource_start(dev, 0);
|
|
|
|
mem_length = pci_resource_len(dev, 0);
|
|
|
|
|
|
|
|
if (!request_mem_region(mem_start, mem_length, "ISP1761 IO MEM")) {
|
|
|
|
printk(KERN_ERR "request region #1\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
iobase = ioremap_nocache(mem_start, mem_length);
|
|
|
|
if (!iobase) {
|
|
|
|
printk(KERN_ERR "ioremap #1\n");
|
|
|
|
release_mem_region(mem_start, mem_length);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-04-24 06:37:04 +08:00
|
|
|
|
2008-12-01 18:47:40 +08:00
|
|
|
/* configure PLX PCI chip to pass interrupts */
|
|
|
|
#define PLX_INT_CSR_REG 0x68
|
|
|
|
reg_data = readl(iobase + PLX_INT_CSR_REG);
|
|
|
|
reg_data |= 0x900;
|
|
|
|
writel(reg_data, iobase + PLX_INT_CSR_REG);
|
2008-04-24 06:37:04 +08:00
|
|
|
|
2008-12-01 18:47:40 +08:00
|
|
|
/* done with PLX IO access */
|
2008-04-24 06:37:04 +08:00
|
|
|
iounmap(iobase);
|
2015-01-21 06:55:53 +08:00
|
|
|
release_mem_region(mem_start, mem_length);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int isp1761_pci_probe(struct pci_dev *dev,
|
|
|
|
const struct pci_device_id *id)
|
|
|
|
{
|
|
|
|
unsigned int devflags = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!dev->irq)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (pci_enable_device(dev) < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = isp1761_pci_init(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
pci_set_master(dev);
|
2008-12-01 18:47:40 +08:00
|
|
|
|
2015-01-21 06:55:52 +08:00
|
|
|
dev->dev.dma_mask = NULL;
|
2015-01-21 06:55:58 +08:00
|
|
|
ret = isp1760_register(&dev->resource[3], dev->irq, 0, &dev->dev,
|
|
|
|
devflags);
|
2015-01-21 06:55:53 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
2008-12-01 18:47:40 +08:00
|
|
|
|
2015-01-21 06:55:53 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
pci_disable_device(dev);
|
|
|
|
return ret;
|
2008-04-24 06:37:04 +08:00
|
|
|
}
|
2008-12-01 18:47:40 +08:00
|
|
|
|
2008-04-24 06:37:04 +08:00
|
|
|
static void isp1761_pci_remove(struct pci_dev *dev)
|
|
|
|
{
|
2015-01-21 06:55:45 +08:00
|
|
|
isp1760_unregister(&dev->dev);
|
2008-04-24 06:37:04 +08:00
|
|
|
|
|
|
|
pci_disable_device(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void isp1761_pci_shutdown(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
printk(KERN_ERR "ips1761_pci_shutdown\n");
|
|
|
|
}
|
|
|
|
|
2016-05-04 10:15:37 +08:00
|
|
|
static const struct pci_device_id isp1760_plx[] = {
|
2008-11-30 23:50:04 +08:00
|
|
|
{
|
|
|
|
.class = PCI_CLASS_BRIDGE_OTHER << 8,
|
|
|
|
.class_mask = ~0,
|
|
|
|
.vendor = PCI_VENDOR_ID_PLX,
|
|
|
|
.device = 0x5406,
|
|
|
|
.subvendor = PCI_VENDOR_ID_PLX,
|
|
|
|
.subdevice = 0x9054,
|
|
|
|
},
|
|
|
|
{ }
|
2008-04-24 06:37:04 +08:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, isp1760_plx);
|
|
|
|
|
|
|
|
static struct pci_driver isp1761_pci_driver = {
|
|
|
|
.name = "isp1760",
|
|
|
|
.id_table = isp1760_plx,
|
|
|
|
.probe = isp1761_pci_probe,
|
|
|
|
.remove = isp1761_pci_remove,
|
|
|
|
.shutdown = isp1761_pci_shutdown,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-11-20 02:21:48 +08:00
|
|
|
static int isp1760_plat_probe(struct platform_device *pdev)
|
2009-02-11 00:55:51 +08:00
|
|
|
{
|
2015-01-21 06:55:58 +08:00
|
|
|
unsigned long irqflags;
|
2015-01-21 06:55:44 +08:00
|
|
|
unsigned int devflags = 0;
|
2009-02-11 00:55:51 +08:00
|
|
|
struct resource *mem_res;
|
|
|
|
struct resource *irq_res;
|
2015-01-21 06:55:44 +08:00
|
|
|
int ret;
|
2009-02-11 00:55:51 +08:00
|
|
|
|
|
|
|
mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
|
|
|
irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (!irq_res) {
|
2016-09-28 00:16:59 +08:00
|
|
|
pr_warn("isp1760: IRQ resource not available\n");
|
2015-01-21 06:55:52 +08:00
|
|
|
return -ENODEV;
|
2009-02-11 00:55:51 +08:00
|
|
|
}
|
2015-01-21 06:55:58 +08:00
|
|
|
irqflags = irq_res->flags & IRQF_TRIGGER_MASK;
|
2009-02-11 00:55:51 +08:00
|
|
|
|
2015-01-21 06:55:44 +08:00
|
|
|
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
|
|
|
|
struct device_node *dp = pdev->dev.of_node;
|
|
|
|
u32 bus_width = 0;
|
|
|
|
|
|
|
|
if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
|
2009-07-16 11:22:54 +08:00
|
|
|
devflags |= ISP1760_FLAG_ISP1761;
|
2015-01-21 06:55:44 +08:00
|
|
|
|
|
|
|
/* Some systems wire up only 16 of the 32 data lines */
|
|
|
|
of_property_read_u32(dp, "bus-width", &bus_width);
|
|
|
|
if (bus_width == 16)
|
2009-07-16 11:22:54 +08:00
|
|
|
devflags |= ISP1760_FLAG_BUS_WIDTH_16;
|
2015-01-21 06:55:44 +08:00
|
|
|
|
|
|
|
if (of_property_read_bool(dp, "port1-otg"))
|
2009-07-16 11:22:54 +08:00
|
|
|
devflags |= ISP1760_FLAG_OTG_EN;
|
2015-01-21 06:55:44 +08:00
|
|
|
|
|
|
|
if (of_property_read_bool(dp, "analog-oc"))
|
2009-07-16 11:22:54 +08:00
|
|
|
devflags |= ISP1760_FLAG_ANALOG_OC;
|
2015-01-21 06:55:44 +08:00
|
|
|
|
|
|
|
if (of_property_read_bool(dp, "dack-polarity"))
|
2009-07-16 11:22:54 +08:00
|
|
|
devflags |= ISP1760_FLAG_DACK_POL_HIGH;
|
2015-01-21 06:55:44 +08:00
|
|
|
|
|
|
|
if (of_property_read_bool(dp, "dreq-polarity"))
|
|
|
|
devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
|
|
|
|
} else if (dev_get_platdata(&pdev->dev)) {
|
|
|
|
struct isp1760_platform_data *pdata =
|
|
|
|
dev_get_platdata(&pdev->dev);
|
|
|
|
|
|
|
|
if (pdata->is_isp1761)
|
|
|
|
devflags |= ISP1760_FLAG_ISP1761;
|
|
|
|
if (pdata->bus_width_16)
|
|
|
|
devflags |= ISP1760_FLAG_BUS_WIDTH_16;
|
|
|
|
if (pdata->port1_otg)
|
|
|
|
devflags |= ISP1760_FLAG_OTG_EN;
|
|
|
|
if (pdata->analog_oc)
|
|
|
|
devflags |= ISP1760_FLAG_ANALOG_OC;
|
|
|
|
if (pdata->dack_polarity_high)
|
|
|
|
devflags |= ISP1760_FLAG_DACK_POL_HIGH;
|
|
|
|
if (pdata->dreq_polarity_high)
|
2009-07-16 11:22:54 +08:00
|
|
|
devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
|
|
|
|
}
|
|
|
|
|
2015-01-21 06:55:51 +08:00
|
|
|
ret = isp1760_register(mem_res, irq_res->start, irqflags, &pdev->dev,
|
|
|
|
devflags);
|
2015-01-21 06:55:47 +08:00
|
|
|
if (ret < 0)
|
2015-01-21 06:55:52 +08:00
|
|
|
return ret;
|
2009-02-11 00:55:51 +08:00
|
|
|
|
|
|
|
pr_info("ISP1760 USB device initialised\n");
|
2015-01-21 06:55:44 +08:00
|
|
|
return 0;
|
2009-02-11 00:55:51 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:20 +08:00
|
|
|
static int isp1760_plat_remove(struct platform_device *pdev)
|
2009-02-11 00:55:51 +08:00
|
|
|
{
|
2015-01-21 06:55:45 +08:00
|
|
|
isp1760_unregister(&pdev->dev);
|
2012-04-05 20:56:07 +08:00
|
|
|
|
2009-02-11 00:55:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-21 06:55:44 +08:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id isp1760_of_match[] = {
|
|
|
|
{ .compatible = "nxp,usb-isp1760", },
|
|
|
|
{ .compatible = "nxp,usb-isp1761", },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, isp1760_of_match);
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 00:55:51 +08:00
|
|
|
static struct platform_driver isp1760_plat_driver = {
|
|
|
|
.probe = isp1760_plat_probe,
|
2012-11-20 02:21:08 +08:00
|
|
|
.remove = isp1760_plat_remove,
|
2009-02-11 00:55:51 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "isp1760",
|
2015-01-21 06:55:44 +08:00
|
|
|
.of_match_table = of_match_ptr(isp1760_of_match),
|
2009-02-11 00:55:51 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2008-04-24 06:37:04 +08:00
|
|
|
static int __init isp1760_init(void)
|
|
|
|
{
|
2009-02-11 00:55:51 +08:00
|
|
|
int ret, any_ret = -ENODEV;
|
2008-04-24 06:37:04 +08:00
|
|
|
|
2015-01-21 06:55:49 +08:00
|
|
|
isp1760_init_kmem_once();
|
2008-04-24 06:37:04 +08:00
|
|
|
|
2009-02-11 00:55:51 +08:00
|
|
|
ret = platform_driver_register(&isp1760_plat_driver);
|
|
|
|
if (!ret)
|
|
|
|
any_ret = 0;
|
2017-02-25 19:20:55 +08:00
|
|
|
#ifdef CONFIG_USB_PCI
|
2008-04-24 06:37:04 +08:00
|
|
|
ret = pci_register_driver(&isp1761_pci_driver);
|
2009-02-11 00:55:51 +08:00
|
|
|
if (!ret)
|
|
|
|
any_ret = 0;
|
2008-04-24 06:37:04 +08:00
|
|
|
#endif
|
|
|
|
|
2009-02-11 00:55:51 +08:00
|
|
|
if (any_ret)
|
2015-01-21 06:55:49 +08:00
|
|
|
isp1760_deinit_kmem_cache();
|
2009-02-11 00:55:51 +08:00
|
|
|
return any_ret;
|
2008-04-24 06:37:04 +08:00
|
|
|
}
|
|
|
|
module_init(isp1760_init);
|
|
|
|
|
|
|
|
static void __exit isp1760_exit(void)
|
|
|
|
{
|
2009-02-11 00:55:51 +08:00
|
|
|
platform_driver_unregister(&isp1760_plat_driver);
|
2017-02-25 19:20:55 +08:00
|
|
|
#ifdef CONFIG_USB_PCI
|
2008-04-24 06:37:04 +08:00
|
|
|
pci_unregister_driver(&isp1761_pci_driver);
|
|
|
|
#endif
|
2015-01-21 06:55:49 +08:00
|
|
|
isp1760_deinit_kmem_cache();
|
2008-04-24 06:37:04 +08:00
|
|
|
}
|
|
|
|
module_exit(isp1760_exit);
|