libata-sff: ap->[last_]ctl are SFF specific
[safe/jmp/linux-2.6] / drivers / ata / pata_at32.c
index bb250a4..66ce6a5 100644 (file)
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/slab.h>
 #include <scsi/scsi_host.h>
 #include <linux/ata.h>
 #include <linux/libata.h>
 #include <linux/err.h>
 #include <linux/io.h>
 
-#include <asm/arch/board.h>
-#include <asm/arch/smc.h>
+#include <mach/board.h>
+#include <mach/smc.h>
 
 #define DRV_NAME "pata_at32"
-#define DRV_VERSION "0.0.2"
+#define DRV_VERSION "0.0.3"
 
 /*
  * CompactFlash controller memory layout relative to the base address:
  *     Mode 2  | 8.3   | 240 ns         | 0x07
  *     Mode 3  | 11.1  | 180 ns         | 0x0f
  *     Mode 4  | 16.7  | 120 ns         | 0x1f
+ *
+ * Alter PIO_MASK below according to table to set maximal PIO mode.
  */
-#define PIO_MASK (0x1f)
+enum {
+  PIO_MASK = ATA_PIO4,
+};
 
 /*
  * Struct containing private information about device.
@@ -85,36 +90,40 @@ struct at32_ide_info {
  */
 static int pata_at32_setup_timing(struct device *dev,
                                  struct at32_ide_info *info,
-                                 const struct ata_timing *timing)
+                                 const struct ata_timing *ata)
 {
-       /* These two values are found through testing */
-       const int min_recover = 25;
-       const int ncs_hold    = 15;
-
        struct smc_config *smc = &info->smc;
+       struct smc_timing timing;
 
        int active;
        int recover;
 
+       memset(&timing, 0, sizeof(struct smc_timing));
+
        /* Total cycle time */
-       smc->read_cycle = timing->cyc8b;
+       timing.read_cycle  = ata->cyc8b;
 
        /* DIOR <= CFIOR timings */
-       smc->nrd_setup = timing->setup;
-       smc->nrd_pulse = timing->act8b;
+       timing.nrd_setup   = ata->setup;
+       timing.nrd_pulse   = ata->act8b;
+       timing.nrd_recover = ata->rec8b;
+
+       /* Convert nanosecond timing to clock cycles */
+       smc_set_timing(smc, &timing);
 
-       /* Compute recover, extend total cycle if needed */
-       active  = smc->nrd_setup + smc->nrd_pulse;
+       /* Add one extra cycle setup due to signal ring */
+       smc->nrd_setup = smc->nrd_setup + 1;
+
+       active  = smc->nrd_setup + smc->nrd_pulse;
        recover = smc->read_cycle - active;
 
-       if (recover < min_recover) {
-               smc->read_cycle = active + min_recover;
-               recover = min_recover;
-       }
+       /* Need at least two cycles recovery */
+       if (recover < 2)
+         smc->read_cycle = active + 2;
 
        /* (CS0, CS1, DIR, OE) <= (CFCE1, CFCE2, CFRNW, NCSX) timings */
-       smc->ncs_read_setup  = 0;
-       smc->ncs_read_pulse  = active + ncs_hold;
+       smc->ncs_read_setup = 1;
+       smc->ncs_read_pulse = smc->read_cycle - 2;
 
        /* Write timings same as read timings */
        smc->write_cycle = smc->read_cycle;
@@ -123,11 +132,13 @@ static int pata_at32_setup_timing(struct device *dev,
        smc->ncs_write_setup = smc->ncs_read_setup;
        smc->ncs_write_pulse = smc->ncs_read_pulse;
 
-       /* Do some debugging output */
-       dev_dbg(dev, "SMC: C=%d S=%d P=%d R=%d NCSS=%d NCSP=%d NCSR=%d\n",
+       /* Do some debugging output of ATA and SMC timings */
+       dev_dbg(dev, "ATA: C=%d S=%d P=%d R=%d\n",
+               ata->cyc8b, ata->setup, ata->act8b, ata->rec8b);
+
+       dev_dbg(dev, "SMC: C=%d S=%d P=%d NS=%d NP=%d\n",
                smc->read_cycle, smc->nrd_setup, smc->nrd_pulse,
-               recover, smc->ncs_read_setup, smc->ncs_read_pulse,
-               smc->read_cycle - smc->ncs_read_pulse);
+               smc->ncs_read_setup, smc->ncs_read_pulse);
 
        /* Finally, configure the SMC */
        return smc_set_configuration(info->cs, smc);
@@ -158,54 +169,14 @@ static void pata_at32_set_piomode(struct ata_port *ap, struct ata_device *adev)
        }
 }
 
-static void pata_at32_irq_clear(struct ata_port *ap)
-{
-       /* No DMA controller yet */
-}
-
 static struct scsi_host_template at32_sht = {
-       .module                 = THIS_MODULE,
-       .name                   = DRV_NAME,
-       .ioctl                  = ata_scsi_ioctl,
-       .queuecommand           = ata_scsi_queuecmd,
-       .can_queue              = ATA_DEF_QUEUE,
-       .this_id                = ATA_SHT_THIS_ID,
-       .sg_tablesize           = LIBATA_MAX_PRD,
-       .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
-       .emulated               = ATA_SHT_EMULATED,
-       .use_clustering         = ATA_SHT_USE_CLUSTERING,
-       .proc_name              = DRV_NAME,
-       .dma_boundary           = ATA_DMA_BOUNDARY,
-       .slave_configure        = ata_scsi_slave_config,
-       .slave_destroy          = ata_scsi_slave_destroy,
-       .bios_param             = ata_std_bios_param,
+       ATA_PIO_SHT(DRV_NAME),
 };
 
 static struct ata_port_operations at32_port_ops = {
-       .port_disable           = ata_port_disable,
-       .set_piomode            = pata_at32_set_piomode,
-       .tf_load                = ata_tf_load,
-       .tf_read                = ata_tf_read,
-       .exec_command           = ata_exec_command,
-       .check_status           = ata_check_status,
-       .dev_select             = ata_std_dev_select,
-
-       .freeze                 = ata_bmdma_freeze,
-       .thaw                   = ata_bmdma_thaw,
-       .error_handler          = ata_bmdma_error_handler,
-       .post_internal_cmd      = ata_bmdma_post_internal_cmd,
+       .inherits               = &ata_sff_port_ops,
        .cable_detect           = ata_cable_40wire,
-
-       .qc_prep                = ata_qc_prep,
-       .qc_issue               = ata_qc_issue_prot,
-
-       .data_xfer              = ata_data_xfer,
-
-       .irq_clear              = pata_at32_irq_clear,
-       .irq_on                 = ata_irq_on,
-       .irq_ack                = ata_irq_ack,
-
-       .port_start             = ata_sff_port_start,
+       .set_piomode            = pata_at32_set_piomode,
 };
 
 static int __init pata_at32_init_one(struct device *dev,
@@ -223,8 +194,7 @@ static int __init pata_at32_init_one(struct device *dev,
        /* Setup ATA bindings */
        ap->ops      = &at32_port_ops;
        ap->pio_mask = PIO_MASK;
-       ap->flags    = ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS
-               | ATA_FLAG_PIO_POLLING;
+       ap->flags   |= ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS;
 
        /*
         * Since all 8-bit taskfile transfers has to go on the lower
@@ -256,7 +226,7 @@ static int __init pata_at32_init_one(struct device *dev,
        host->private_data = info;
 
        /* Register ATA device and return */
-       return ata_host_activate(host, info->irq, ata_interrupt,
+       return ata_host_activate(host, info->irq, ata_sff_interrupt,
                                 IRQF_SHARED | IRQF_TRIGGER_RISING,
                                 &at32_sht);
 }
@@ -319,13 +289,11 @@ static int __init pata_at32_probe(struct platform_device *pdev)
        if (irq < 0)
                return irq;
 
-       /* Setup struct containing private infomation */
+       /* Setup struct containing private information */
        info = kzalloc(sizeof(struct at32_ide_info), GFP_KERNEL);
        if (!info)
                return -ENOMEM;
 
-       memset(info, 0, sizeof(struct at32_ide_info));
-
        info->irq = irq;
        info->cs  = board->cs;
 
@@ -357,12 +325,12 @@ static int __init pata_at32_probe(struct platform_device *pdev)
        info->smc.tdf_mode       = 0; /* TDF optimization disabled */
        info->smc.tdf_cycles     = 0; /* No TDF wait cycles */
 
-       /* Setup ATA timing */
+       /* Setup SMC to ATA timing */
        ret = pata_at32_setup_timing(dev, info, &initial_timing);
        if (ret)
                goto err_setup_timing;
 
-       /* Setup ATA addresses */
+       /* Map ATA address space */
        ret = -ENOMEM;
        info->ide_addr = devm_ioremap(dev, info->res_ide.start, 16);
        info->alt_addr = devm_ioremap(dev, info->res_alt.start, 16);
@@ -373,7 +341,7 @@ static int __init pata_at32_probe(struct platform_device *pdev)
        pata_at32_debug_bus(dev, info);
 #endif
 
-       /* Register ATA device */
+       /* Setup and register ATA device */
        ret = pata_at32_init_one(dev, info);
        if (ret)
                goto err_ata_device;
@@ -414,6 +382,9 @@ static int __exit pata_at32_remove(struct platform_device *pdev)
        return 0;
 }
 
+/* work with hotplug and coldplug */
+MODULE_ALIAS("platform:at32_ide");
+
 static struct platform_driver pata_at32_driver = {
        .remove        = __exit_p(pata_at32_remove),
        .driver        = {