* A low-level PATA driver to handle a Compact Flash connected on the
* Mikrotik's RouterBoard 153 board.
*
- * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
+ * Copyright (C) 2007,2008 Gabor Juhos <juhosg at openwrt.org>
*
* This file was based on: drivers/ata/pata_ixp4xx_cf.c
* Copyright (C) 2006-07 Tower Technologies
* their RouterBoard 1xx and 5xx series devices. The original Mikrotik code
* seems not to have a license.
*
- * 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.
+ * 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 <asm/gpio.h>
#define DRV_NAME "pata-rb153-cf"
-#define DRV_VERSION "0.2"
+#define DRV_VERSION "0.4.0"
#define DRV_DESC "PATA driver for RouterBOARD 153 Compact Flash"
#define RB153_CF_MAXPORTS 1
#define RB153_CF_REG_DATA 0x0C00
struct rb153_cf_info {
+ unsigned int irq;
void __iomem *iobase;
unsigned int gpio_line;
int frozen;
static inline void rb153_pata_finish_io(struct ata_port *ap)
{
- struct ata_host *ah = ap->host;
+ struct rb153_cf_info *info = ap->host->private_data;
ata_altstatus(ap);
ndelay(RB153_CF_IO_DELAY);
- set_irq_type(ah->irq, IRQ_TYPE_LEVEL_HIGH);
+ set_irq_type(info->irq, IRQ_TYPE_LEVEL_HIGH);
}
static void rb153_pata_exec_command(struct ata_port *ap,
rb153_pata_finish_io(ap);
}
-static void rb153_pata_data_xfer(struct ata_device *adev, unsigned char *buf,
+static unsigned int rb153_pata_data_xfer(struct ata_device *adev, unsigned char *buf,
unsigned int buflen, int write_data)
{
- void __iomem *ioaddr = adev->ap->ioaddr.data_addr;
-
+ void __iomem *ioaddr = adev->link->ap->ioaddr.data_addr;
+ unsigned int t;
+
+ t = buflen;
if (write_data) {
- for (; buflen > 0; buflen--, buf++)
+ for (; t > 0; t--, buf++)
writeb(*buf, ioaddr);
} else {
- for (; buflen > 0; buflen--, buf++)
+ for (; t > 0; t--, buf++)
*buf = readb(ioaddr);
}
- rb153_pata_finish_io(adev->ap);
+ rb153_pata_finish_io(adev->link->ap);
+ return buflen;
}
static void rb153_pata_freeze(struct ata_port *ap)
struct rb153_cf_info *info = ah->private_data;
if (gpio_get_value(info->gpio_line)) {
- set_irq_type(ah->irq, IRQ_TYPE_LEVEL_LOW);
+ set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW);
if (!info->frozen)
ata_interrupt(irq, dev_instance);
} else {
- set_irq_type(ah->irq, IRQ_TYPE_LEVEL_HIGH);
+ set_irq_type(info->irq, IRQ_TYPE_LEVEL_HIGH);
}
return IRQ_HANDLED;
}
static struct ata_port_operations rb153_pata_port_ops = {
- .port_disable = ata_port_disable,
-
.tf_load = ata_tf_load,
.tf_read = ata_tf_read,
.freeze = rb153_pata_freeze,
.thaw = rb153_pata_thaw,
.error_handler = ata_bmdma_error_handler,
+ .cable_detect = ata_cable_40wire,
.irq_handler = rb153_pata_irq_handler,
.irq_clear = rb153_pata_irq_clear,
/* ------------------------------------------------------------------------ */
-static void rb153_pata_setup_ports(struct ata_host *ah)
+static void rb153_pata_setup_port(struct ata_port *ap,
+ struct rb153_cf_info *info, unsigned long raw_cmd)
{
- struct rb153_cf_info *info = ah->private_data;
- struct ata_port *ap;
- struct ata_ioports *iop;
+ ap->ioaddr.cmd_addr = info->iobase + RB153_CF_REG_CMD;
+ ap->ioaddr.ctl_addr = info->iobase + RB153_CF_REG_CTRL;
+ ap->ioaddr.altstatus_addr = info->iobase + RB153_CF_REG_CTRL;
- ap = ah->ports[0];
- iop = &ap->ioaddr;
+ ata_std_ports(&ap->ioaddr);
- ap->ops = &rb153_pata_port_ops;
- ap->pio_mask = 0x1f; /* PIO4 */
- ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY;
+ ap->ioaddr.data_addr = info->iobase + RB153_CF_REG_DATA;
- iop->cmd_addr = info->iobase + RB153_CF_REG_CMD;
- iop->ctl_addr = info->iobase + RB153_CF_REG_CTRL;
- iop->altstatus_addr = info->iobase + RB153_CF_REG_CTRL;
- iop->data_addr = info->iobase + RB153_CF_REG_DATA;
-
- ata_std_ports(iop);
+ ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", raw_cmd,
+ raw_cmd + RB153_CF_REG_CTRL);
}
static __devinit int rb153_pata_driver_probe(struct platform_device *pdev)
int gpio;
struct resource *res;
struct ata_host *ah;
+ struct ata_port *ap;
struct rb153_cf_info *info;
int ret;
return -ENOMEM;
ah->private_data = info;
+ info->gpio_line = gpio;
+ info->irq = irq;
info->iobase = devm_ioremap_nocache(&pdev->dev, res->start,
res->end - res->start + 1);
goto err_free_gpio;
}
- rb153_pata_setup_ports(ah);
+ ap = ah->ports[0];
+
+ ap->ops = &rb153_pata_port_ops;
+ ap->pio_mask = 0x1f; /* PIO4 */
+ ap->flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO;
+
+ rb153_pata_setup_port(ap, info, res->start);
- ret = ata_host_activate(ah, irq, ata_interrupt, IRQF_TRIGGER_HIGH,
- &rb153_pata_sht);
+ ret = ata_host_activate(ah, irq, rb153_pata_irq_handler,
+ IRQF_TRIGGER_LOW, &rb153_pata_sht);
if (ret)
goto err_free_gpio;
MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
MODULE_DESCRIPTION(DRV_DESC);
MODULE_VERSION(DRV_VERSION);
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
module_init(rb153_pata_module_init);
module_exit(rb153_pata_module_exit);