From: Sergey Matyukevich <geomatsi@gmail.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: linux-ide@vger.kernel.org, Sergey Lapin <slapin@ossfans.org>,
Andrew Victor <avictor.za@gmail.com>
Subject: Re: [git patches] libata updates
Date: Tue, 23 Jun 2009 23:42:14 +0400 [thread overview]
Message-ID: <20090623234214.1b3018fd@realm> (raw)
In-Reply-To: <4A411810.6070308@garzik.org>
On Tue, 23 Jun 2009 13:59:44 -0400
Jeff Garzik <jeff@garzik.org> wrote:
> Sergey Matyukevich wrote:
> > Could you tell me where to send update for pata_at91 driver modified
> > according to Andrew's remarks ? To Jeff ?
>
> Me and linux-ide...
>
> Jeff
>
>
Jeff,
Here is updated pata_at91 driver according to comments by Andrew Morton.
This patch provides PATA driver for CompactFlash interface in True IDE
mode on AT91SAM9260 SoC.
Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
---
drivers/ata/Kconfig | 8 +
drivers/ata/Makefile | 1 +
drivers/ata/pata_at91.c | 367 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 376 insertions(+), 0 deletions(-)
create mode 100644 drivers/ata/pata_at91.c
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 2aa1908..b17c57f 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -679,6 +679,14 @@ config PATA_PLATFORM
If unsure, say N.
+config PATA_AT91
+ tristate "PATA support for AT91SAM9260"
+ depends on ARM && ARCH_AT91
+ help
+ This option enables support for IDE devices on the Atmel AT91SAM9260 SoC.
+
+ If unsure, say N.
+
config PATA_OF_PLATFORM
tristate "OpenFirmware platform device PATA support"
depends on PATA_PLATFORM && PPC_OF
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 1558059..38906f9 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_PATA_SCH) += pata_sch.o
obj-$(CONFIG_PATA_BF54X) += pata_bf54x.o
obj-$(CONFIG_PATA_OCTEON_CF) += pata_octeon_cf.o
obj-$(CONFIG_PATA_PLATFORM) += pata_platform.o
+obj-$(CONFIG_PATA_AT91) += pata_at91.o
obj-$(CONFIG_PATA_OF_PLATFORM) += pata_of_platform.o
obj-$(CONFIG_PATA_ICSIDE) += pata_icside.o
# Should be last but two libata driver
diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
new file mode 100644
index 0000000..7dcd551
--- /dev/null
+++ b/drivers/ata/pata_at91.c
@@ -0,0 +1,367 @@
+/*
+ * PATA driver for AT91SAM9260 Static Memory Controller
+ * with CompactFlash interface in True IDE mode
+ *
+ * Copyright (C) 2009 Matyukevich Sergey
+ *
+ * Based on:
+ * * generic platform driver by Paul Mundt: drivers/ata/pata_platform.c
+ * * pata_at32 driver by Kristoffer Nyborg Gregertsen
+ * * at91_ide driver by Stanislaw Gruszka
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/blkdev.h>
+#include <scsi/scsi_host.h>
+#include <linux/ata.h>
+#include <linux/clk.h>
+#include <linux/libata.h>
+#include <linux/platform_device.h>
+#include <linux/ata_platform.h>
+
+#include <mach/at91sam9260_matrix.h>
+#include <mach/at91sam9_smc.h>
+#include <mach/at91sam9260.h>
+#include <mach/board.h>
+#include <mach/gpio.h>
+
+
+#define DRV_NAME "pata_at91"
+#define DRV_VERSION "0.1"
+
+#define CF_IDE_OFFSET 0x00c00000
+#define CF_ALT_IDE_OFFSET 0x00e00000
+#define CF_IDE_RES_SIZE 0x08
+
+struct at91_ide_info {
+ unsigned long mode;
+ unsigned int cs;
+ struct clk *mck;
+
+ void __iomem *ide_addr;
+ void __iomem *alt_addr;
+};
+
+static const struct ata_timing initial_timing =
+ {XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0};
+
+static unsigned long calc_mck_cycles(unsigned long ns, unsigned long mck_hz)
+{
+ unsigned long mul;
+
+ /*
+ * cycles = x [nsec] * f [Hz] / 10^9 [ns in sec] =
+ * x * (f / 1_000_000_000) =
+ * x * ((f * 65536) / 1_000_000_000) / 65536 =
+ * x * (((f / 10_000) * 65536) / 100_000) / 65536 =
+ */
+
+ mul = (mck_hz / 10000) << 16;
+ mul /= 100000;
+
+ return (ns * mul + 65536) >> 16; /* rounding */
+}
+
+static void set_smc_mode(struct at91_ide_info *info)
+{
+ at91_sys_write(AT91_SMC_MODE(info->cs), info->mode);
+ return;
+}
+
+static void set_smc_timing(struct device *dev,
+ struct at91_ide_info *info, const struct ata_timing *ata)
+{
+ unsigned long read_cycle, write_cycle, active, recover;
+ unsigned long nrd_setup, nrd_pulse, nrd_recover;
+ unsigned long nwe_setup, nwe_pulse;
+
+ unsigned long ncs_write_setup, ncs_write_pulse;
+ unsigned long ncs_read_setup, ncs_read_pulse;
+
+ unsigned long mck_hz;
+
+ read_cycle = ata->cyc8b;
+ nrd_setup = ata->setup;
+ nrd_pulse = ata->act8b;
+ nrd_recover = ata->rec8b;
+
+ mck_hz = clk_get_rate(info->mck);
+
+ read_cycle = calc_mck_cycles(read_cycle, mck_hz);
+ nrd_setup = calc_mck_cycles(nrd_setup, mck_hz);
+ nrd_pulse = calc_mck_cycles(nrd_pulse, mck_hz);
+ nrd_recover = calc_mck_cycles(nrd_recover, mck_hz);
+
+ active = nrd_setup + nrd_pulse;
+ recover = read_cycle - active;
+
+ /* Need at least two cycles recovery */
+ if (recover < 2)
+ read_cycle = active + 2;
+
+ /* (CS0, CS1, DIR, OE) <= (CFCE1, CFCE2, CFRNW, NCSX) timings */
+ ncs_read_setup = 1;
+ ncs_read_pulse = read_cycle - 2;
+
+ /* Write timings same as read timings */
+ write_cycle = read_cycle;
+ nwe_setup = nrd_setup;
+ nwe_pulse = nrd_pulse;
+ ncs_write_setup = ncs_read_setup;
+ ncs_write_pulse = ncs_read_pulse;
+
+ dev_dbg(dev, "ATA timings: nrd_setup = %lu nrd_pulse = %lu nrd_cycle = %lu\n",
+ nrd_setup, nrd_pulse, read_cycle);
+ dev_dbg(dev, "ATA timings: nwe_setup = %lu nwe_pulse = %lu nwe_cycle = %lu\n",
+ nwe_setup, nwe_pulse, write_cycle);
+ dev_dbg(dev, "ATA timings: ncs_read_setup = %lu ncs_read_pulse = %lu\n",
+ ncs_read_setup, ncs_read_pulse);
+ dev_dbg(dev, "ATA timings: ncs_write_setup = %lu ncs_write_pulse = %lu\n",
+ ncs_write_setup, ncs_write_pulse);
+
+ at91_sys_write(AT91_SMC_SETUP(info->cs),
+ AT91_SMC_NWESETUP_(nwe_setup) |
+ AT91_SMC_NRDSETUP_(nrd_setup) |
+ AT91_SMC_NCS_WRSETUP_(ncs_write_setup) |
+ AT91_SMC_NCS_RDSETUP_(ncs_read_setup));
+
+ at91_sys_write(AT91_SMC_PULSE(info->cs),
+ AT91_SMC_NWEPULSE_(nwe_pulse) |
+ AT91_SMC_NRDPULSE_(nrd_pulse) |
+ AT91_SMC_NCS_WRPULSE_(ncs_write_pulse) |
+ AT91_SMC_NCS_RDPULSE_(ncs_read_pulse));
+
+ at91_sys_write(AT91_SMC_CYCLE(info->cs),
+ AT91_SMC_NWECYCLE_(write_cycle) |
+ AT91_SMC_NRDCYCLE_(read_cycle));
+
+ return;
+}
+
+static void pata_at91_set_piomode(struct ata_port *ap, struct ata_device *adev)
+{
+ struct at91_ide_info *info = ap->host->private_data;
+ struct ata_timing timing;
+ int ret;
+
+ /* Compute ATA timing and set it to SMC */
+ ret = ata_timing_compute(adev, adev->pio_mode, &timing, 1000, 0);
+ if (ret) {
+ dev_warn(ap->dev, "Failed to compute ATA timing %d, \
+ set PIO_0 timing\n", ret);
+ set_smc_timing(ap->dev, info, &initial_timing);
+ } else {
+ set_smc_timing(ap->dev, info, &timing);
+ }
+
+ /* Setup SMC mode */
+ set_smc_mode(info);
+
+ return;
+}
+
+static unsigned int pata_at91_data_xfer_noirq(struct ata_device *dev,
+ unsigned char *buf, unsigned int buflen, int rw)
+{
+ struct at91_ide_info *info = dev->link->ap->host->private_data;
+ unsigned int consumed;
+ unsigned long flags;
+ unsigned int mode;
+
+ local_irq_save(flags);
+ mode = at91_sys_read(AT91_SMC_MODE(info->cs));
+
+ /* set 16bit mode before writing data */
+ at91_sys_write(AT91_SMC_MODE(info->cs),
+ (mode & ~AT91_SMC_DBW) | AT91_SMC_DBW_16);
+
+ consumed = ata_sff_data_xfer(dev, buf, buflen, rw);
+
+ /* restore 8bit mode after data is written */
+ at91_sys_write(AT91_SMC_MODE(info->cs),
+ (mode & ~AT91_SMC_DBW) | AT91_SMC_DBW_8);
+
+ local_irq_restore(flags);
+ return consumed;
+}
+
+static struct scsi_host_template pata_at91_sht = {
+ ATA_PIO_SHT(DRV_NAME),
+};
+
+static struct ata_port_operations pata_at91_port_ops = {
+ .inherits = &ata_sff_port_ops,
+
+ .sff_data_xfer = pata_at91_data_xfer_noirq,
+ .set_piomode = pata_at91_set_piomode,
+ .cable_detect = ata_cable_40wire,
+ .port_start = ATA_OP_NULL,
+};
+
+static int __devinit pata_at91_probe(struct platform_device *pdev)
+{
+ struct at91_cf_data *board = pdev->dev.platform_data;
+ struct device *dev = &pdev->dev;
+ struct at91_ide_info *info;
+ struct resource *mem_res;
+ struct ata_host *host;
+ struct ata_port *ap;
+
+ int irq_flags = 0;
+ int irq = 0;
+ int ret;
+
+ /* get platform resources: IO/CTL memories and irq/rst pins */
+
+ if (pdev->num_resources != 1) {
+ dev_err(&pdev->dev, "invalid number of resources\n");
+ return -EINVAL;
+ }
+
+ mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+ if (!mem_res) {
+ dev_err(dev, "failed to get mem resource\n");
+ return -EINVAL;
+ }
+
+ irq = board->irq_pin;
+
+ /* init ata host */
+
+ host = ata_host_alloc(dev, 1);
+
+ if (!host)
+ return -ENOMEM;
+
+ ap = host->ports[0];
+ ap->ops = &pata_at91_port_ops;
+ ap->flags |= ATA_FLAG_SLAVE_POSS;
+ ap->pio_mask = ATA_PIO4;
+
+ if (!irq) {
+ ap->flags |= ATA_FLAG_PIO_POLLING;
+ ata_port_desc(ap, "no IRQ, using PIO polling");
+ }
+
+ info = kzalloc(sizeof(*info), GFP_KERNEL);
+
+ if (!info) {
+ dev_err(dev, "failed to allocate memory for private data\n");
+ return -ENOMEM;
+ }
+
+ info->mck = clk_get(NULL, "mck");
+
+ if (IS_ERR(info->mck)) {
+ dev_err(dev, "failed to get access to mck clock\n");
+ return -ENODEV;
+ }
+
+ info->cs = board->chipselect;
+ info->mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
+ AT91_SMC_EXNWMODE_READY | AT91_SMC_BAT_SELECT |
+ AT91_SMC_DBW_8 | AT91_SMC_TDF_(0);
+
+ info->ide_addr = devm_ioremap(dev,
+ mem_res->start + CF_IDE_OFFSET, CF_IDE_RES_SIZE);
+
+ if (!info->ide_addr) {
+ dev_err(dev, "failed to map IO base\n");
+ ret = -ENOMEM;
+ goto err_ide_ioremap;
+ }
+
+ info->alt_addr = devm_ioremap(dev,
+ mem_res->start + CF_ALT_IDE_OFFSET, CF_IDE_RES_SIZE);
+
+ if (!info->alt_addr) {
+ dev_err(dev, "failed to map CTL base\n");
+ ret = -ENOMEM;
+ goto err_alt_ioremap;
+ }
+
+ ap->ioaddr.cmd_addr = info->ide_addr;
+ ap->ioaddr.ctl_addr = info->alt_addr + 0x06;
+ ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;
+
+ ata_sff_std_ports(&ap->ioaddr);
+
+ ata_port_desc(ap, "mmio cmd 0x%llx ctl 0x%llx",
+ (unsigned long long)mem_res->start + CF_IDE_OFFSET,
+ (unsigned long long)mem_res->start + CF_ALT_IDE_OFFSET);
+
+ host->private_data = info;
+
+ return ata_host_activate(host, irq ? gpio_to_irq(irq) : 0,
+ irq ? ata_sff_interrupt : NULL,
+ irq_flags, &pata_at91_sht);
+
+err_alt_ioremap:
+ devm_iounmap(dev, info->ide_addr);
+
+err_ide_ioremap:
+ clk_put(info->mck);
+ kfree(info);
+
+ return ret;
+}
+
+static int __devexit pata_at91_remove(struct platform_device *pdev)
+{
+ struct ata_host *host = dev_get_drvdata(&pdev->dev);
+ struct at91_ide_info *info = host->private_data;
+ struct device *dev = &pdev->dev;
+
+ if (!host)
+ return 0;
+
+ ata_host_detach(host);
+
+ if (!info)
+ return 0;
+
+ devm_iounmap(dev, info->ide_addr);
+ devm_iounmap(dev, info->alt_addr);
+ clk_put(info->mck);
+
+ kfree(info);
+ return 0;
+}
+
+static struct platform_driver pata_at91_driver = {
+ .probe = pata_at91_probe,
+ .remove = __devexit_p(pata_at91_remove),
+ .driver = {
+ .name = DRV_NAME,
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init pata_at91_init(void)
+{
+ return platform_driver_register(&pata_at91_driver);
+}
+
+static void __exit pata_at91_exit(void)
+{
+ platform_driver_unregister(&pata_at91_driver);
+}
+
+
+module_init(pata_at91_init);
+module_exit(pata_at91_exit);
+
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Driver for CF in True IDE mode on AT91SAM9260 SoC");
+MODULE_AUTHOR("Matyukevich Sergey");
+MODULE_VERSION(DRV_VERSION);
+
--
1.6.2.5
next prev parent reply other threads:[~2009-06-23 19:49 UTC|newest]
Thread overview: 103+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-23 6:06 [git patches] libata updates Jeff Garzik
2009-06-23 6:31 ` Andrew Morton
2009-06-23 17:37 ` Sergey Matyukevich
2009-06-23 17:59 ` Jeff Garzik
2009-06-23 19:42 ` Sergey Matyukevich [this message]
2009-06-23 21:30 ` Jeff Garzik
2009-06-24 17:51 ` [PATCH] pata_at91: Updates for pata_at91 driver Sergey Matyukevich
2009-06-23 18:01 ` [git patches] libata updates Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2013-04-30 22:26 Jeff Garzik
2013-04-30 23:18 ` Linus Torvalds
2012-07-25 20:35 Jeff Garzik
2012-07-25 20:43 ` Jeff Garzik
2012-07-25 22:06 ` Linus Torvalds
2012-07-25 22:26 ` Jeff Garzik
2012-07-25 22:31 ` Linus Torvalds
2012-07-25 22:58 ` Jeff Garzik
2012-07-25 23:30 ` Linus Torvalds
2012-07-26 2:10 ` Jeff Garzik
2012-07-26 17:14 ` Linus Torvalds
2012-07-26 7:44 ` Ingo Molnar
2012-07-25 21:38 ` Jeff Garzik
2012-07-26 4:47 ` Aaron Lu
2012-07-26 5:05 ` James Bottomley
2012-07-26 5:17 ` Aaron Lu
2012-07-26 14:58 ` Alan Stern
2011-01-28 8:29 Jeff Garzik
2010-08-04 1:55 Jeff Garzik
2010-08-04 18:32 ` Linus Torvalds
2010-08-04 18:46 ` Jeff Garzik
2010-06-02 18:08 Jeff Garzik
2010-05-28 1:18 Jeff Garzik
2009-12-19 18:13 Jeff Garzik
2009-12-19 19:05 ` Linus Torvalds
2009-12-19 20:11 ` Jeff Garzik
2009-09-17 20:49 Jeff Garzik
2009-09-20 21:05 ` Bartlomiej Zolnierkiewicz
2009-09-22 2:36 ` Jung-Ik (John) Lee
2009-09-28 15:34 ` Bartlomiej Zolnierkiewicz
2009-09-28 20:20 ` Jung-Ik (John) Lee
2009-09-28 20:36 ` Jeff Garzik
2009-09-28 20:49 ` Jung-Ik (John) Lee
2009-10-06 4:24 ` Jeff Garzik
2009-10-06 22:26 ` Bartlomiej Zolnierkiewicz
2009-10-06 23:02 ` Jeff Garzik
2009-04-07 1:42 Jeff Garzik
2009-03-25 3:01 Jeff Garzik
2009-02-03 4:27 Jeff Garzik
2009-01-08 21:46 Jeff Garzik
2008-10-28 4:45 Jeff Garzik
2008-08-22 7:04 Jeff Garzik
2008-07-31 6:51 Jeff Garzik
2008-05-19 22:57 Jeff Garzik
2008-05-06 15:48 Jeff Garzik
2008-05-06 16:23 ` Linus Torvalds
2008-04-29 6:25 Jeff Garzik
2008-02-25 22:38 Jeff Garzik
2008-02-06 12:14 Jeff Garzik
2008-02-01 18:33 Jeff Garzik
2008-01-25 23:16 Jeff Garzik
2007-10-25 7:49 Jeff Garzik
2007-10-15 20:20 Jeff Garzik
2007-07-20 15:00 Jeff Garzik
2007-07-12 20:20 Jeff Garzik
2007-07-10 18:36 Jeff Garzik
2007-05-11 22:32 Jeff Garzik
2007-05-12 10:06 ` Andreas Arens
2007-04-29 16:15 Jeff Garzik
2007-04-30 19:52 ` Chuck Ebbert
2007-04-30 20:05 ` Jeff Garzik
2007-04-30 20:22 ` Stephen Clark
2007-04-30 20:31 ` Alan Cox
2007-04-30 20:51 ` alan
2007-04-30 20:31 ` Jeff Garzik
2007-05-01 11:55 ` Stephen Clark
2007-05-01 21:38 ` Jesse Barnes
2007-05-01 22:45 ` Stephen Clark
2007-05-01 22:49 ` Jesse Barnes
2007-05-01 22:49 ` Chuck Ebbert
2007-05-02 0:48 ` Stephen Clark
2007-04-30 22:06 ` Chuck Ebbert
2007-04-30 22:11 ` Jeff Garzik
2007-05-01 21:34 ` Jesse Barnes
2007-05-10 0:18 ` Jeff Garzik
2006-12-14 23:08 Jeff Garzik
2006-12-15 1:14 ` Alan
2006-12-07 12:40 Jeff Garzik
2006-10-04 6:02 Jeff Garzik
2006-10-04 11:47 ` Alan Cox
2006-10-04 14:34 ` Alan Cox
[not found] <20060924162850.GA14323@havoc.gtf.org>
2006-09-24 16:33 ` Jeff Garzik
2006-03-30 22:01 Jeff Garzik
2006-03-24 15:59 Jeff Garzik
2006-03-23 1:15 Jeff Garzik
2006-03-23 1:36 ` Jeff Garzik
2006-03-20 11:16 Jeff Garzik
2006-03-20 16:35 ` Alan Cox
2006-03-21 1:12 ` Jeff Garzik
2006-03-21 10:20 ` Alan Cox
2006-03-21 16:40 ` Jeff Garzik
2006-03-21 17:23 ` Alan Cox
2006-02-01 4:14 Jeff Garzik
2005-09-23 23:11 Jeff Garzik
2005-09-07 6:10 Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090623234214.1b3018fd@realm \
--to=geomatsi@gmail.com \
--cc=avictor.za@gmail.com \
--cc=jeff@garzik.org \
--cc=linux-ide@vger.kernel.org \
--cc=slapin@ossfans.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).