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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  Created 20 Oct 2004 by Mark Lord
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Basic support for Delkin/ASKA/Workbit Cardbus CompactFlash adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Modeled after the 16-bit PCMCIA driver: ide-cs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  This is slightly peculiar, in that it is a PCI driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  but is NOT an IDE PCI driver -- the IDE layer does not directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  support hot insertion/removal of PCI interfaces, so this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  is unable to use the IDE PCI interfaces.  Instead, it uses the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  same interfaces as the ide-cs (PCMCIA) driver uses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  On the plus side, the driver is also smaller/simpler this way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *  License.  See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * No chip documentation has yet been found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * so these configuration values were pulled from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * a running Win98 system using "debug".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * This gives around 3MByte/second read performance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * which is about 2/3 of what the chip is capable of.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * There is also a 4KByte mmio region on the card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * but its purpose has yet to be reverse-engineered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static const u8 setup[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	0x00, 0x05, 0xbe, 0x01, 0x20, 0x8f, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	0xa4, 0x1f, 0xb3, 0x1b, 0x00, 0x00, 0x00, 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	0x00, 0x00, 0x00, 0x00, 0xa4, 0x83, 0x02, 0x13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static const struct ide_port_ops delkin_cb_port_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.quirkproc		= ide_undecoded_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int delkin_cb_init_chipset(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned long base = pci_resource_start(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	outb(0x02, base + 0x1e);	/* set nIEN to block interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	inb(base + 0x17);		/* read status to clear interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	for (i = 0; i < sizeof(setup); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		if (setup[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			outb(setup[i], base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static const struct ide_port_info delkin_cb_port_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.port_ops		= &delkin_cb_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.host_flags		= IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				  IDE_HFLAG_NO_DMA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.irq_flags		= IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.init_chipset		= delkin_cb_init_chipset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.chipset		= ide_pci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int delkin_cb_probe(struct pci_dev *dev, const struct pci_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct ide_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	unsigned long base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct ide_hw hw, *hws[] = { &hw };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	rc = pci_enable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	rc = pci_request_regions(dev, "delkin_cb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	base = pci_resource_start(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	delkin_cb_init_chipset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	memset(&hw, 0, sizeof(hw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	hw.irq = dev->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	hw.dev = &dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	rc = ide_host_add(&delkin_cb_port_info, hws, 1, &host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		goto out_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	pci_set_drvdata(dev, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) out_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	pci_release_regions(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) delkin_cb_remove (struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct ide_host *host = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ide_host_remove(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	pci_release_regions(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int delkin_cb_suspend(struct pci_dev *dev, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	pci_save_state(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	pci_disable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	pci_set_power_state(dev, pci_choose_state(dev, state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int delkin_cb_resume(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct ide_host *host = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	pci_set_power_state(dev, PCI_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	rc = pci_enable_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	pci_restore_state(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	pci_set_master(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (host->init_chipset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		host->init_chipset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define delkin_cb_suspend NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define delkin_cb_resume NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static struct pci_device_id delkin_cb_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	{ 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	{ 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	{ 0, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static struct pci_driver delkin_cb_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.name		= "Delkin-ASKA-Workbit Cardbus IDE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	.id_table	= delkin_cb_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	.probe		= delkin_cb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	.remove		= delkin_cb_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	.suspend	= delkin_cb_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	.resume		= delkin_cb_resume,
^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) module_pci_driver(delkin_cb_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) MODULE_AUTHOR("Mark Lord");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)