libata: implement and use ata_port_desc() to report port configuration
[safe/jmp/linux-2.6] / drivers / ata / pata_pcmcia.c
index 2abe0a3..782ff4a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   pata_pcmcia.c - PCMCIA PATA controller driver.
  *   Copyright 2005-2006 Red Hat Inc <alan@redhat.com>, all rights reserved.
- *   PCMCIA ident update Copyright 2006 Marcin Juszkiewicz 
+ *   PCMCIA ident update Copyright 2006 Marcin Juszkiewicz
  *                                             <openembedded@hrw.one.pl>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -42,7 +42,7 @@
 
 
 #define DRV_NAME "pata_pcmcia"
-#define DRV_VERSION "0.2.9"
+#define DRV_VERSION "0.3.2"
 
 /*
  *     Private data structure to glue stuff together
@@ -54,6 +54,39 @@ struct ata_pcmcia_info {
        dev_node_t      node;
 };
 
+/**
+ *     pcmcia_set_mode -       PCMCIA specific mode setup
+ *     @link: link
+ *     @r_failed_dev: Return pointer for failed device
+ *
+ *     Perform the tuning and setup of the devices and timings, which
+ *     for PCMCIA is the same as any other controller. We wrap it however
+ *     as we need to spot hardware with incorrect or missing master/slave
+ *     decode, which alas is embarrassingly common in the PC world
+ */
+
+static int pcmcia_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
+{
+       struct ata_device *master = &link->device[0];
+       struct ata_device *slave = &link->device[1];
+
+       if (!ata_dev_enabled(master) || !ata_dev_enabled(slave))
+               return ata_do_set_mode(link, r_failed_dev);
+
+       if (memcmp(master->id + ATA_ID_FW_REV,  slave->id + ATA_ID_FW_REV,
+                          ATA_ID_FW_REV_LEN + ATA_ID_PROD_LEN) == 0)
+       {
+               /* Suspicious match, but could be two cards from
+                  the same vendor - check serial */
+               if (memcmp(master->id + ATA_ID_SERNO, slave->id + ATA_ID_SERNO,
+                          ATA_ID_SERNO_LEN) == 0 && master->id[ATA_ID_SERNO] >> 8) {
+                       ata_dev_printk(slave, KERN_WARNING, "is a ghost device, ignoring.\n");
+                       ata_dev_disable(slave);
+               }
+       }
+       return ata_do_set_mode(link, r_failed_dev);
+}
+
 static struct scsi_host_template pcmcia_sht = {
        .module                 = THIS_MODULE,
        .name                   = DRV_NAME,
@@ -62,18 +95,18 @@ static struct scsi_host_template pcmcia_sht = {
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
        .sg_tablesize           = LIBATA_MAX_PRD,
-       .max_sectors            = ATA_MAX_SECTORS,
        .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,
 };
 
 static struct ata_port_operations pcmcia_port_ops = {
-       .port_disable   = ata_port_disable,
+       .set_mode       = pcmcia_set_mode,
        .tf_load        = ata_tf_load,
        .tf_read        = ata_tf_read,
        .check_status   = ata_check_status,
@@ -84,18 +117,17 @@ static struct ata_port_operations pcmcia_port_ops = {
        .thaw           = ata_bmdma_thaw,
        .error_handler  = ata_bmdma_error_handler,
        .post_internal_cmd = ata_bmdma_post_internal_cmd,
+       .cable_detect   = ata_cable_40wire,
 
        .qc_prep        = ata_qc_prep,
        .qc_issue       = ata_qc_issue_prot,
-       .eng_timeout    = ata_eng_timeout,
-       .data_xfer      = ata_pio_data_xfer_noirq,
 
-       .irq_handler    = ata_interrupt,
+       .data_xfer      = ata_data_xfer_noirq,
+
        .irq_clear      = ata_bmdma_irq_clear,
+       .irq_on         = ata_irq_on,
 
-       .port_start     = ata_port_start,
-       .port_stop      = ata_port_stop,
-       .host_stop      = ata_host_stop
+       .port_start     = ata_sff_port_start,
 };
 
 #define CS_CHECK(fn, ret) \
@@ -111,7 +143,8 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
 static int pcmcia_init_one(struct pcmcia_device *pdev)
 {
-       struct ata_probe_ent ae;
+       struct ata_host *host;
+       struct ata_port *ap;
        struct ata_pcmcia_info *info;
        tuple_t tuple;
        struct {
@@ -123,6 +156,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        cistpl_cftable_entry_t *cfg;
        int pass, last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM;
        unsigned long io_base, ctl_base;
+       void __iomem *io_addr, *ctl_addr;
 
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (info == NULL)
@@ -154,19 +188,12 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        tuple.TupleOffset = 0;
        tuple.TupleDataMax = 255;
        tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CONFIG;
-
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(pdev, &tuple));
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(pdev, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(pdev, &tuple, &stk->parse));
-       pdev->conf.ConfigBase = stk->parse.config.base;
-       pdev->conf.Present = stk->parse.config.rmask[0];
 
        /* See if we have a manufacturer identifier. Use it to set is_kme for
           vendor quirks */
-       tuple.DesiredTuple = CISTPL_MANFID;
-       if (!pcmcia_get_first_tuple(pdev, &tuple) && !pcmcia_get_tuple_data(pdev, &tuple) && !pcmcia_parse_tuple(pdev, &tuple, &stk->parse))
-                       is_kme = ((stk->parse.manfid.manf == MANFID_KME) && ((stk->parse.manfid.card == PRODID_KME_KXLC005_A) || (stk->parse.manfid.card == PRODID_KME_KXLC005_B)));
+       is_kme = ((pdev->manf_id == MANFID_KME) &&
+                 ((pdev->card_id == PRODID_KME_KXLC005_A) ||
+                  (pdev->card_id == PRODID_KME_KXLC005_B)));
 
        /* Not sure if this is right... look up the current Vcc */
        CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(pdev, &stk->conf));
@@ -240,10 +267,17 @@ next_entry:
        CS_CHECK(RequestIRQ, pcmcia_request_irq(pdev, &pdev->irq));
        CS_CHECK(RequestConfiguration, pcmcia_request_configuration(pdev, &pdev->conf));
 
+       /* iomap */
+       ret = -ENOMEM;
+       io_addr = devm_ioport_map(&pdev->dev, io_base, 8);
+       ctl_addr = devm_ioport_map(&pdev->dev, ctl_base, 1);
+       if (!io_addr || !ctl_addr)
+               goto failed;
+
        /* Success. Disable the IRQ nIEN line, do quirks */
-       outb(0x02, ctl_base);
+       iowrite8(0x02, ctl_addr);
        if (is_kme)
-               outb(0x81, ctl_base + 0x01);
+               iowrite8(0x81, ctl_addr + 0x01);
 
        /* FIXME: Could be more ports at base + 0x10 but we only deal with
           one right now */
@@ -254,23 +288,26 @@ next_entry:
         *      Having done the PCMCIA plumbing the ATA side is relatively
         *      sane.
         */
-
-       memset(&ae, 0, sizeof(struct ata_probe_ent));
-       INIT_LIST_HEAD(&ae.node);
-       ae.dev = &pdev->dev;
-       ae.port_ops = &pcmcia_port_ops;
-       ae.sht = &pcmcia_sht;
-       ae.n_ports = 1;
-       ae.pio_mask = 1;                /* ISA so PIO 0 cycles */
-       ae.irq = pdev->irq.AssignedIRQ;
-       ae.irq_flags = SA_SHIRQ;
-       ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
-       ae.port[0].cmd_addr = io_base;
-       ae.port[0].altstatus_addr = ctl_base;
-       ae.port[0].ctl_addr = ctl_base;
-       ata_std_ports(&ae.port[0]);
-
-       if (ata_device_add(&ae) == 0)
+       ret = -ENOMEM;
+       host = ata_host_alloc(&pdev->dev, 1);
+       if (!host)
+               goto failed;
+       ap = host->ports[0];
+
+       ap->ops = &pcmcia_port_ops;
+       ap->pio_mask = 1;               /* ISA so PIO 0 cycles */
+       ap->flags |= ATA_FLAG_SLAVE_POSS;
+       ap->ioaddr.cmd_addr = io_addr;
+       ap->ioaddr.altstatus_addr = ctl_addr;
+       ap->ioaddr.ctl_addr = ctl_addr;
+       ata_std_ports(&ap->ioaddr);
+
+       ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", io_base, ctl_base);
+
+       /* activate */
+       ret = ata_host_activate(host, pdev->irq.AssignedIRQ, ata_interrupt,
+                               IRQF_SHARED, &pcmcia_sht);
+       if (ret)
                goto failed;
 
        info->ndev = 1;
@@ -305,8 +342,7 @@ static void pcmcia_remove_one(struct pcmcia_device *pdev)
                /* If we have attached the device to the ATA layer, detach it */
                if (info->ndev) {
                        struct ata_host *host = dev_get_drvdata(dev);
-                       ata_host_remove(host);
-                       dev_set_drvdata(dev, NULL);
+                       ata_host_detach(host);
                }
                info->ndev = 0;
                pdev->priv = NULL;
@@ -318,14 +354,18 @@ static void pcmcia_remove_one(struct pcmcia_device *pdev)
 static struct pcmcia_device_id pcmcia_devices[] = {
        PCMCIA_DEVICE_FUNC_ID(4),
        PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000),        /* Hitachi */
+       PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000),        /* I-O Data CFA */
+       PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001),        /* Mitsubishi CFA */
        PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
-       PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),
+       PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
+       PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),        /* SanDisk CFA */
        PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000),        /* Toshiba */
        PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
        PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000),        /* Samsung */
        PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000),        /* Hitachi */
        PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
-       PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200),        /* Lexar */
+       PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0100),        /* Viking CFA */
+       PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200),        /* Lexar, Viking CFA */
        PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
        PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
        PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
@@ -342,6 +382,7 @@ static struct pcmcia_device_id pcmcia_devices[] = {
        PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
        PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
        PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
+       PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
        PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2      ", 0x547e66dc, 0x8671043b),
        PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
        PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
@@ -355,7 +396,12 @@ static struct pcmcia_device_id pcmcia_devices[] = {
        PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "04/05/06", 0x43d74cb4, 0x6a22777d),
        PCMCIA_DEVICE_PROD_ID12("SMI VENDOR", "SMI PRODUCT", 0x30896c92, 0x703cc5f6),
        PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
+       PCMCIA_DEVICE_PROD_ID1("TRANSCEND    512M   ", 0xd0909443),
+       PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF80", 0x709b1bf1, 0x2a54d4b1),
+       PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS2GCF120", 0x709b1bf1, 0x969aa4f2),
+       PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF120", 0x709b1bf1, 0xf54a91c8),
        PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
+       PCMCIA_DEVICE_PROD_ID12("WEIDA", "TWTTI", 0xcc7cf69c, 0x212bb918),
        PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
        PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e),
        PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6),