Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Glue code for the ISP1760 driver and bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Currently there is support for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * - OpenFirmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * - PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * - PDEV (generic platform device centralized driver model)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/usb/isp1760.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "isp1760-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "isp1760-regs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #ifdef CONFIG_USB_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef CONFIG_USB_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int isp1761_pci_init(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	resource_size_t mem_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	resource_size_t mem_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u8 __iomem *iobase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u8 latency, limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u32 reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* Grab the PLX PCI shared memory of the ISP 1761 we need  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	mem_start = pci_resource_start(dev, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	mem_length = pci_resource_len(dev, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (mem_length < 0xffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		printk(KERN_ERR "memory length for this resource is wrong\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (!request_mem_region(mem_start, mem_length, "ISP-PCI")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		printk(KERN_ERR "host controller already in use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* map available memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	iobase = ioremap(mem_start, mem_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!iobase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		printk(KERN_ERR "Error ioremap failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		release_mem_region(mem_start, mem_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/* bad pci latencies can contribute to overruns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (latency) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		if (limit && limit < latency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/* Try to check whether we can access Scratch Register of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * Host Controller or not. The initial PCI access is retried until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * local init for the PCI bridge is completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	retry_count = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	reg_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	while ((reg_data != 0xFACE) && retry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		/*by default host is in 16bit mode, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		 * io operations at this stage must be 16 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		 * */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		writel(0xface, iobase + HC_SCRATCH_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		reg_data = readl(iobase + HC_SCRATCH_REG) & 0x0000ffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		retry_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	iounmap(iobase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	release_mem_region(mem_start, mem_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/* Host Controller presence is detected by writing to scratch register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * and reading back and checking the contents are same or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (reg_data != 0xFACE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Grab the PLX PCI mem maped port start address we need  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	mem_start = pci_resource_start(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	mem_length = pci_resource_len(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (!request_mem_region(mem_start, mem_length, "ISP1761 IO MEM")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		printk(KERN_ERR "request region #1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	iobase = ioremap(mem_start, mem_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!iobase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		printk(KERN_ERR "ioremap #1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		release_mem_region(mem_start, mem_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/* configure PLX PCI chip to pass interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define PLX_INT_CSR_REG 0x68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	reg_data = readl(iobase + PLX_INT_CSR_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	reg_data |= 0x900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	writel(reg_data, iobase + PLX_INT_CSR_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* done with PLX IO access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	iounmap(iobase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	release_mem_region(mem_start, mem_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int isp1761_pci_probe(struct pci_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		const struct pci_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	unsigned int devflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!dev->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (pci_enable_device(dev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ret = isp1761_pci_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	pci_set_master(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	ret = isp1760_register(&dev->resource[3], dev->irq, 0, &dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			       devflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void isp1761_pci_remove(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	isp1760_unregister(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void isp1761_pci_shutdown(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	printk(KERN_ERR "ips1761_pci_shutdown\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static const struct pci_device_id isp1760_plx[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		.class          = PCI_CLASS_BRIDGE_OTHER << 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		.class_mask     = ~0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		.vendor		= PCI_VENDOR_ID_PLX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		.device		= 0x5406,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		.subvendor	= PCI_VENDOR_ID_PLX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		.subdevice	= 0x9054,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) MODULE_DEVICE_TABLE(pci, isp1760_plx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static struct pci_driver isp1761_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.name =         "isp1760",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.id_table =     isp1760_plx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.probe =        isp1761_pci_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	.remove =       isp1761_pci_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.shutdown =     isp1761_pci_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int isp1760_plat_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	unsigned long irqflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	unsigned int devflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct resource *mem_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct resource *irq_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (!irq_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		pr_warn("isp1760: IRQ resource not available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	irqflags = irq_res->flags & IRQF_TRIGGER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		struct device_node *dp = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		u32 bus_width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			devflags |= ISP1760_FLAG_ISP1761;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		/* Some systems wire up only 16 of the 32 data lines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		of_property_read_u32(dp, "bus-width", &bus_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (bus_width == 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			devflags |= ISP1760_FLAG_BUS_WIDTH_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (of_property_read_bool(dp, "port1-otg"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			devflags |= ISP1760_FLAG_OTG_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		if (of_property_read_bool(dp, "analog-oc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			devflags |= ISP1760_FLAG_ANALOG_OC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (of_property_read_bool(dp, "dack-polarity"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			devflags |= ISP1760_FLAG_DACK_POL_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (of_property_read_bool(dp, "dreq-polarity"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	} else if (dev_get_platdata(&pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		struct isp1760_platform_data *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		if (pdata->is_isp1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			devflags |= ISP1760_FLAG_ISP1761;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (pdata->bus_width_16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			devflags |= ISP1760_FLAG_BUS_WIDTH_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (pdata->port1_otg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			devflags |= ISP1760_FLAG_OTG_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (pdata->analog_oc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			devflags |= ISP1760_FLAG_ANALOG_OC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		if (pdata->dack_polarity_high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			devflags |= ISP1760_FLAG_DACK_POL_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (pdata->dreq_polarity_high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	ret = isp1760_register(mem_res, irq_res->start, irqflags, &pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			       devflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	pr_info("ISP1760 USB device initialised\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int isp1760_plat_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	isp1760_unregister(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct of_device_id isp1760_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	{ .compatible = "nxp,usb-isp1760", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	{ .compatible = "nxp,usb-isp1761", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) MODULE_DEVICE_TABLE(of, isp1760_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static struct platform_driver isp1760_plat_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.probe	= isp1760_plat_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.remove	= isp1760_plat_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		.name	= "isp1760",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		.of_match_table = of_match_ptr(isp1760_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int __init isp1760_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	int ret, any_ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	isp1760_init_kmem_once();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	ret = platform_driver_register(&isp1760_plat_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		any_ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #ifdef CONFIG_USB_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	ret = pci_register_driver(&isp1761_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		any_ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (any_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		isp1760_deinit_kmem_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return any_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) module_init(isp1760_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static void __exit isp1760_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	platform_driver_unregister(&isp1760_plat_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #ifdef CONFIG_USB_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	pci_unregister_driver(&isp1761_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	isp1760_deinit_kmem_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) module_exit(isp1760_exit);