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)  *  Atari Falcon IDE Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *     Created 12 Jul 1997 by Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  License.  See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/atarihw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/atariints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/atari_stdma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DRV_NAME "falconide"
^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)      *  Offsets from base address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define ATA_HD_CONTROL	0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)      *  falconide_intr_lock is used to obtain access to the IDE interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)      *  which is shared between several drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int falconide_intr_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static void falconide_release_lock(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (falconide_intr_lock == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		printk(KERN_ERR "%s: bug\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	falconide_intr_lock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	stdma_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static void falconide_get_lock(irq_handler_t handler, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (falconide_intr_lock == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (in_interrupt() > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			panic("Falcon IDE hasn't ST-DMA lock in interrupt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		stdma_lock(handler, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		falconide_intr_lock = 1;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static void falconide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				 void *buf, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	unsigned long data_addr = drive->hwif->io_ports.data_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		__ide_mm_insw(data_addr, buf, (len + 1) / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	raw_insw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
^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 void falconide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				  void *buf, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	unsigned long data_addr = drive->hwif->io_ports.data_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		__ide_mm_outsw(data_addr, buf, (len + 1) / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return;
^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) 	raw_outsw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) /* Atari has a byte-swapped IDE interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static const struct ide_tp_ops falconide_tp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.exec_command		= ide_exec_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.read_status		= ide_read_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.read_altstatus		= ide_read_altstatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.write_devctl		= ide_write_devctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.dev_select		= ide_dev_select,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.tf_load		= ide_tf_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.tf_read		= ide_tf_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	.input_data		= falconide_input_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.output_data		= falconide_output_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static const struct ide_port_info falconide_port_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.get_lock		= falconide_get_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.release_lock		= falconide_release_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.tp_ops			= &falconide_tp_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.host_flags		= IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				  IDE_HFLAG_NO_DMA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.irq_flags		= IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.chipset		= ide_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void __init falconide_setup_ports(struct ide_hw *hw, unsigned long base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	memset(hw, 0, sizeof(*hw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	hw->io_ports.data_addr = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	for (i = 1; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		hw->io_ports_array[i] = base + 1 + i * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	hw->io_ports.ctl_addr = base + ATA_HD_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	hw->irq = IRQ_MFP_IDE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)      *  Probe for a Falcon IDE interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int __init falconide_init(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct ide_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct ide_hw hw, *hws[] = { &hw };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	unsigned long base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	dev_info(&pdev->dev, "Atari Falcon IDE controller\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (!devm_request_mem_region(&pdev->dev, res->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				     resource_size(res), DRV_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		dev_err(&pdev->dev, "resources busy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	base = (unsigned long)res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	falconide_setup_ports(&hw, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	host = ide_host_alloc(&falconide_port_info, hws, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (host == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	falconide_get_lock(NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	rc = ide_host_register(host, &falconide_port_info, hws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	falconide_release_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	platform_set_drvdata(pdev, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ide_host_free(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	release_mem_region(res->start, resource_size(res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int falconide_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct ide_host *host = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ide_host_remove(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static struct platform_driver ide_falcon_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.remove = falconide_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.driver   = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		.name	= "atari-falcon-ide",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) module_platform_driver_probe(ide_falcon_driver, falconide_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) MODULE_AUTHOR("Geert Uytterhoeven");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) MODULE_DESCRIPTION("low-level driver for Atari Falcon IDE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MODULE_ALIAS("platform:atari-falcon-ide");