Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2
  3/*
  4 * Atari Falcon PATA controller driver
  5 *
  6 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  7 *		http://www.samsung.com
  8 *
  9 * Based on falconide.c:
 10 *
 11 *     Created 12 Jul 1997 by Geert Uytterhoeven
 12 */
 13
 14#include <linux/kernel.h>
 15#include <linux/module.h>
 16#include <linux/init.h>
 17#include <linux/blkdev.h>
 18#include <linux/delay.h>
 19#include <scsi/scsi_host.h>
 20#include <scsi/scsi_cmnd.h>
 21#include <linux/ata.h>
 22#include <linux/libata.h>
 23#include <linux/mm.h>
 24#include <linux/interrupt.h>
 25#include <linux/platform_device.h>
 26
 27#include <asm/setup.h>
 28#include <asm/atarihw.h>
 29#include <asm/atariints.h>
 30#include <asm/atari_stdma.h>
 31#include <asm/ide.h>
 32
 33#define DRV_NAME "pata_falcon"
 34#define DRV_VERSION "0.1.0"
 35
 
 
 
 36static struct scsi_host_template pata_falcon_sht = {
 37	ATA_PIO_SHT(DRV_NAME),
 38};
 39
 40static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 41					  unsigned char *buf,
 42					  unsigned int buflen, int rw)
 43{
 44	struct ata_device *dev = qc->dev;
 45	struct ata_port *ap = dev->link->ap;
 46	void __iomem *data_addr = ap->ioaddr.data_addr;
 47	unsigned int words = buflen >> 1;
 48	struct scsi_cmnd *cmd = qc->scsicmd;
 49	bool swap = 1;
 50
 51	if (dev->class == ATA_DEV_ATA && cmd &&
 52	    !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
 53		swap = 0;
 54
 55	/* Transfer multiple of 2 bytes */
 56	if (rw == READ) {
 57		if (swap)
 58			raw_insw_swapw(data_addr, (u16 *)buf, words);
 59		else
 60			raw_insw(data_addr, (u16 *)buf, words);
 61	} else {
 62		if (swap)
 63			raw_outsw_swapw(data_addr, (u16 *)buf, words);
 64		else
 65			raw_outsw(data_addr, (u16 *)buf, words);
 66	}
 67
 68	/* Transfer trailing byte, if any. */
 69	if (unlikely(buflen & 0x01)) {
 70		unsigned char pad[2] = { };
 71
 72		/* Point buf to the tail of buffer */
 73		buf += buflen - 1;
 74
 75		if (rw == READ) {
 76			if (swap)
 77				raw_insw_swapw(data_addr, (u16 *)pad, 1);
 78			else
 79				raw_insw(data_addr, (u16 *)pad, 1);
 80			*buf = pad[0];
 81		} else {
 82			pad[0] = *buf;
 83			if (swap)
 84				raw_outsw_swapw(data_addr, (u16 *)pad, 1);
 85			else
 86				raw_outsw(data_addr, (u16 *)pad, 1);
 87		}
 88		words++;
 89	}
 90
 91	return words << 1;
 92}
 93
 94/*
 95 * Provide our own set_mode() as we don't want to change anything that has
 96 * already been configured..
 97 */
 98static int pata_falcon_set_mode(struct ata_link *link,
 99				struct ata_device **unused)
100{
101	struct ata_device *dev;
102
103	ata_for_each_dev(dev, link, ENABLED) {
104		/* We don't really care */
105		dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
106		dev->xfer_shift = ATA_SHIFT_PIO;
107		dev->flags |= ATA_DFLAG_PIO;
108		ata_dev_info(dev, "configured for PIO\n");
109	}
110	return 0;
111}
112
113static struct ata_port_operations pata_falcon_ops = {
114	.inherits	= &ata_sff_port_ops,
115	.sff_data_xfer	= pata_falcon_data_xfer,
116	.cable_detect	= ata_cable_unknown,
117	.set_mode	= pata_falcon_set_mode,
118};
119
120static int __init pata_falcon_init_one(struct platform_device *pdev)
121{
122	struct resource *base_mem_res, *ctl_mem_res;
123	struct resource *base_res, *ctl_res, *irq_res;
124	struct ata_host *host;
125	struct ata_port *ap;
 
126	void __iomem *base;
127	int irq = 0;
128
129	dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
 
130
131	base_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
132	if (base_res && !devm_request_region(&pdev->dev, base_res->start,
133					   resource_size(base_res), DRV_NAME)) {
134		dev_err(&pdev->dev, "resources busy\n");
135		return -EBUSY;
136	}
137
138	ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
139	if (ctl_res && !devm_request_region(&pdev->dev, ctl_res->start,
140					    resource_size(ctl_res), DRV_NAME)) {
141		dev_err(&pdev->dev, "resources busy\n");
142		return -EBUSY;
143	}
144
145	base_mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146	if (!base_mem_res)
147		return -ENODEV;
148	if (!devm_request_mem_region(&pdev->dev, base_mem_res->start,
149				     resource_size(base_mem_res), DRV_NAME)) {
150		dev_err(&pdev->dev, "resources busy\n");
151		return -EBUSY;
152	}
153
154	ctl_mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
155	if (!ctl_mem_res)
156		return -ENODEV;
157
158	/* allocate host */
159	host = ata_host_alloc(&pdev->dev, 1);
160	if (!host)
161		return -ENOMEM;
162	ap = host->ports[0];
163
164	ap->ops = &pata_falcon_ops;
165	ap->pio_mask = ATA_PIO4;
166	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
 
167
168	base = (void __iomem *)base_mem_res->start;
169	/* N.B. this assumes data_addr will be used for word-sized I/O only */
170	ap->ioaddr.data_addr		= base + 0 + 0 * 4;
171	ap->ioaddr.error_addr		= base + 1 + 1 * 4;
172	ap->ioaddr.feature_addr		= base + 1 + 1 * 4;
173	ap->ioaddr.nsect_addr		= base + 1 + 2 * 4;
174	ap->ioaddr.lbal_addr		= base + 1 + 3 * 4;
175	ap->ioaddr.lbam_addr		= base + 1 + 4 * 4;
176	ap->ioaddr.lbah_addr		= base + 1 + 5 * 4;
177	ap->ioaddr.device_addr		= base + 1 + 6 * 4;
178	ap->ioaddr.status_addr		= base + 1 + 7 * 4;
179	ap->ioaddr.command_addr		= base + 1 + 7 * 4;
180
181	base = (void __iomem *)ctl_mem_res->start;
182	ap->ioaddr.altstatus_addr	= base + 1;
183	ap->ioaddr.ctl_addr		= base + 1;
184
185	ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx",
186		      (unsigned long)base_mem_res->start,
187		      (unsigned long)ctl_mem_res->start);
188
189	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
190	if (irq_res && irq_res->start > 0) {
191		irq = irq_res->start;
192	} else {
193		ap->flags |= ATA_FLAG_PIO_POLLING;
194		ata_port_desc(ap, "no IRQ, using PIO polling");
195	}
196
197	/* activate */
198	return ata_host_activate(host, irq, irq ? ata_sff_interrupt : NULL,
199				 IRQF_SHARED, &pata_falcon_sht);
200}
201
202static int __exit pata_falcon_remove_one(struct platform_device *pdev)
203{
204	struct ata_host *host = platform_get_drvdata(pdev);
205
206	ata_host_detach(host);
 
207
208	return 0;
 
209}
210
211static struct platform_driver pata_falcon_driver = {
212	.remove = __exit_p(pata_falcon_remove_one),
213	.driver   = {
214		.name	= "atari-falcon-ide",
215	},
216};
217
218module_platform_driver_probe(pata_falcon_driver, pata_falcon_init_one);
219
220MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
221MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
222MODULE_LICENSE("GPL v2");
223MODULE_ALIAS("platform:atari-falcon-ide");
224MODULE_VERSION(DRV_VERSION);
v5.4
  1// SPDX-License-Identifier: GPL-2.0
  2
  3/*
  4 * Atari Falcon PATA controller driver
  5 *
  6 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  7 *		http://www.samsung.com
  8 *
  9 * Based on falconide.c:
 10 *
 11 *     Created 12 Jul 1997 by Geert Uytterhoeven
 12 */
 13
 14#include <linux/kernel.h>
 15#include <linux/module.h>
 16#include <linux/init.h>
 17#include <linux/blkdev.h>
 18#include <linux/delay.h>
 19#include <scsi/scsi_host.h>
 20#include <scsi/scsi_cmnd.h>
 21#include <linux/ata.h>
 22#include <linux/libata.h>
 23#include <linux/mm.h>
 24#include <linux/interrupt.h>
 25#include <linux/platform_device.h>
 26
 27#include <asm/setup.h>
 28#include <asm/atarihw.h>
 29#include <asm/atariints.h>
 30#include <asm/atari_stdma.h>
 31#include <asm/ide.h>
 32
 33#define DRV_NAME "pata_falcon"
 34#define DRV_VERSION "0.1.0"
 35
 36#define ATA_HD_BASE	0xfff00000
 37#define ATA_HD_CONTROL	0x39
 38
 39static struct scsi_host_template pata_falcon_sht = {
 40	ATA_PIO_SHT(DRV_NAME),
 41};
 42
 43static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
 44					  unsigned char *buf,
 45					  unsigned int buflen, int rw)
 46{
 47	struct ata_device *dev = qc->dev;
 48	struct ata_port *ap = dev->link->ap;
 49	void __iomem *data_addr = ap->ioaddr.data_addr;
 50	unsigned int words = buflen >> 1;
 51	struct scsi_cmnd *cmd = qc->scsicmd;
 52	bool swap = 1;
 53
 54	if (dev->class == ATA_DEV_ATA && cmd && cmd->request &&
 55	    !blk_rq_is_passthrough(cmd->request))
 56		swap = 0;
 57
 58	/* Transfer multiple of 2 bytes */
 59	if (rw == READ) {
 60		if (swap)
 61			raw_insw_swapw((u16 *)data_addr, (u16 *)buf, words);
 62		else
 63			raw_insw((u16 *)data_addr, (u16 *)buf, words);
 64	} else {
 65		if (swap)
 66			raw_outsw_swapw((u16 *)data_addr, (u16 *)buf, words);
 67		else
 68			raw_outsw((u16 *)data_addr, (u16 *)buf, words);
 69	}
 70
 71	/* Transfer trailing byte, if any. */
 72	if (unlikely(buflen & 0x01)) {
 73		unsigned char pad[2] = { };
 74
 75		/* Point buf to the tail of buffer */
 76		buf += buflen - 1;
 77
 78		if (rw == READ) {
 79			if (swap)
 80				raw_insw_swapw((u16 *)data_addr, (u16 *)pad, 1);
 81			else
 82				raw_insw((u16 *)data_addr, (u16 *)pad, 1);
 83			*buf = pad[0];
 84		} else {
 85			pad[0] = *buf;
 86			if (swap)
 87				raw_outsw_swapw((u16 *)data_addr, (u16 *)pad, 1);
 88			else
 89				raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
 90		}
 91		words++;
 92	}
 93
 94	return words << 1;
 95}
 96
 97/*
 98 * Provide our own set_mode() as we don't want to change anything that has
 99 * already been configured..
100 */
101static int pata_falcon_set_mode(struct ata_link *link,
102				struct ata_device **unused)
103{
104	struct ata_device *dev;
105
106	ata_for_each_dev(dev, link, ENABLED) {
107		/* We don't really care */
108		dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
109		dev->xfer_shift = ATA_SHIFT_PIO;
110		dev->flags |= ATA_DFLAG_PIO;
111		ata_dev_info(dev, "configured for PIO\n");
112	}
113	return 0;
114}
115
116static struct ata_port_operations pata_falcon_ops = {
117	.inherits	= &ata_sff_port_ops,
118	.sff_data_xfer	= pata_falcon_data_xfer,
119	.cable_detect	= ata_cable_unknown,
120	.set_mode	= pata_falcon_set_mode,
121};
122
123static int pata_falcon_init_one(void)
124{
 
 
125	struct ata_host *host;
126	struct ata_port *ap;
127	struct platform_device *pdev;
128	void __iomem *base;
 
129
130	if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
131		return -ENODEV;
132
133	pr_info(DRV_NAME ": Atari Falcon PATA controller\n");
 
 
 
 
 
134
135	pdev = platform_device_register_simple(DRV_NAME, 0, NULL, 0);
136	if (IS_ERR(pdev))
137		return PTR_ERR(pdev);
 
 
 
138
139	if (!devm_request_mem_region(&pdev->dev, ATA_HD_BASE, 0x40, DRV_NAME)) {
140		pr_err(DRV_NAME ": resources busy\n");
 
 
 
 
141		return -EBUSY;
142	}
143
 
 
 
 
144	/* allocate host */
145	host = ata_host_alloc(&pdev->dev, 1);
146	if (!host)
147		return -ENOMEM;
148	ap = host->ports[0];
149
150	ap->ops = &pata_falcon_ops;
151	ap->pio_mask = ATA_PIO4;
152	ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
153	ap->flags |= ATA_FLAG_PIO_POLLING;
154
155	base = (void __iomem *)ATA_HD_BASE;
156	ap->ioaddr.data_addr		= base;
 
157	ap->ioaddr.error_addr		= base + 1 + 1 * 4;
158	ap->ioaddr.feature_addr		= base + 1 + 1 * 4;
159	ap->ioaddr.nsect_addr		= base + 1 + 2 * 4;
160	ap->ioaddr.lbal_addr		= base + 1 + 3 * 4;
161	ap->ioaddr.lbam_addr		= base + 1 + 4 * 4;
162	ap->ioaddr.lbah_addr		= base + 1 + 5 * 4;
163	ap->ioaddr.device_addr		= base + 1 + 6 * 4;
164	ap->ioaddr.status_addr		= base + 1 + 7 * 4;
165	ap->ioaddr.command_addr		= base + 1 + 7 * 4;
166
167	ap->ioaddr.altstatus_addr	= base + ATA_HD_CONTROL;
168	ap->ioaddr.ctl_addr		= base + ATA_HD_CONTROL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170	ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", (unsigned long)base,
171		      (unsigned long)base + ATA_HD_CONTROL);
172
173	/* activate */
174	return ata_host_activate(host, 0, NULL, 0, &pata_falcon_sht);
175}
176
177module_init(pata_falcon_init_one);
 
 
 
 
 
 
 
178
179MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
180MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
181MODULE_LICENSE("GPL v2");
 
182MODULE_VERSION(DRV_VERSION);