]> Pileus Git - ~andy/linux/blobdiff - drivers/mmc/tifm_sd.c
Driver core: add device symlink back to sysfs
[~andy/linux] / drivers / mmc / tifm_sd.c
index 2adfe3467019225bf20e86290ceefb452439abfe..0581d09c58fc6424a075cf36b9ad25560bbe872c 100644 (file)
@@ -36,8 +36,8 @@ module_param(fixed_timeout, bool, 0644);
 #define TIFM_MMCSD_INAB       0x0080   /* abort / initialize command */
 #define TIFM_MMCSD_READ       0x8000
 
-#define TIFM_MMCSD_DATAMASK   0x001d   /* set bits: EOFB, BRS, CB, EOC */
-#define TIFM_MMCSD_ERRMASK    0x41e0   /* set bits: CERR, CCRC, CTO, DCRC, DTO */
+#define TIFM_MMCSD_DATAMASK   0x401d   /* set bits: CERR, EOFB, BRS, CB, EOC */
+#define TIFM_MMCSD_ERRMASK    0x01e0   /* set bits: CCRC, CTO, DCRC, DTO */
 #define TIFM_MMCSD_EOC        0x0001   /* end of command phase  */
 #define TIFM_MMCSD_CB         0x0004   /* card enter busy state */
 #define TIFM_MMCSD_BRS        0x0008   /* block received/sent   */
@@ -107,14 +107,9 @@ struct tifm_sd {
 
 };
 
-static char* tifm_sd_kmap_atomic(struct mmc_data *data)
+static char* tifm_sd_data_buffer(struct mmc_data *data)
 {
-       return kmap_atomic(data->sg->page, KM_BIO_SRC_IRQ) + data->sg->offset;
-}
-
-static void tifm_sd_kunmap_atomic(char *buffer, struct mmc_data *data)
-{
-       kunmap_atomic(buffer - data->sg->offset, KM_BIO_SRC_IRQ);
+       return page_address(data->sg->page) + data->sg->offset;
 }
 
 static int tifm_sd_transfer_data(struct tifm_dev *sock, struct tifm_sd *host,
@@ -127,18 +122,17 @@ static int tifm_sd_transfer_data(struct tifm_dev *sock, struct tifm_sd *host,
        if (host_status & TIFM_MMCSD_BRS) {
                /* in non-dma rx mode BRS fires when fifo is still not empty */
                if (no_dma && (cmd->data->flags & MMC_DATA_READ)) {
-                       buffer = tifm_sd_kmap_atomic(host->req->data);
+                       buffer = tifm_sd_data_buffer(host->req->data);
                        while (host->buffer_size > host->buffer_pos) {
                                t_val = readl(sock->addr + SOCK_MMCSD_DATA);
                                buffer[host->buffer_pos++] = t_val & 0xff;
                                buffer[host->buffer_pos++] =
                                                        (t_val >> 8) & 0xff;
                        }
-                       tifm_sd_kunmap_atomic(buffer, host->req->data);
                }
                return 1;
        } else if (no_dma) {
-               buffer = tifm_sd_kmap_atomic(host->req->data);
+               buffer = tifm_sd_data_buffer(host->req->data);
                if ((cmd->data->flags & MMC_DATA_READ) &&
                                (host_status & TIFM_MMCSD_AF)) {
                        for (cnt = 0; cnt < TIFM_MMCSD_FIFO_SIZE; cnt++) {
@@ -163,7 +157,6 @@ static int tifm_sd_transfer_data(struct tifm_dev *sock, struct tifm_sd *host,
                                }
                        }
                }
-               tifm_sd_kunmap_atomic(buffer, host->req->data);
        }
        return 0;
 }
@@ -249,7 +242,7 @@ change_state:
        case IDLE:
                return;
        case CMD:
-               if (host_status & TIFM_MMCSD_EOC) {
+               if (host_status & (TIFM_MMCSD_EOC | TIFM_MMCSD_CERR)) {
                        tifm_sd_fetch_resp(cmd, sock);
                        if (cmd->data) {
                                host->state = BRS;
@@ -348,10 +341,7 @@ static void tifm_sd_signal_irq(struct tifm_dev *sock,
                        goto done;
 
                if (host_status & TIFM_MMCSD_ERRMASK) {
-                       if (host_status & TIFM_MMCSD_CERR)
-                               error_code = MMC_ERR_FAILED;
-                       else if (host_status
-                                & (TIFM_MMCSD_CTO | TIFM_MMCSD_DTO))
+                       if (host_status & (TIFM_MMCSD_CTO | TIFM_MMCSD_DTO))
                                error_code = MMC_ERR_TIMEOUT;
                        else if (host_status
                                 & (TIFM_MMCSD_CCRC | TIFM_MMCSD_DCRC))
@@ -885,8 +875,13 @@ static int tifm_sd_probe(struct tifm_dev *sock)
        mmc->f_max = 24000000;
        mmc->max_hw_segs = 1;
        mmc->max_phys_segs = 1;
-       mmc->max_sectors = 127;
-       mmc->max_seg_size = mmc->max_sectors << 11; //2k maximum hw block length
+       // limited by DMA counter - it's safer to stick with
+       // block counter has 11 bits though
+       mmc->max_blk_count = 256;
+       // 2k maximum hw block length
+       mmc->max_blk_size = 2048;
+       mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
+       mmc->max_seg_size = mmc->max_req_size;
        sock->signal_irq = tifm_sd_signal_irq;
        rc = tifm_sd_initialize_host(host);
 
@@ -921,6 +916,41 @@ static void tifm_sd_remove(struct tifm_dev *sock)
        mmc_free_host(mmc);
 }
 
+#ifdef CONFIG_PM
+
+static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state)
+{
+       struct mmc_host *mmc = tifm_get_drvdata(sock);
+       int rc;
+
+       rc = mmc_suspend_host(mmc, state);
+       /* The meaning of the bit majority in this constant is unknown. */
+       writel(0xfff8 & readl(sock->addr + SOCK_CONTROL),
+              sock->addr + SOCK_CONTROL);
+       return rc;
+}
+
+static int tifm_sd_resume(struct tifm_dev *sock)
+{
+       struct mmc_host *mmc = tifm_get_drvdata(sock);
+       struct tifm_sd *host = mmc_priv(mmc);
+
+       if (sock->media_id != FM_SD
+           || tifm_sd_initialize_host(host)) {
+               tifm_eject(sock);
+               return 0;
+       } else {
+               return mmc_resume_host(mmc);
+       }
+}
+
+#else
+
+#define tifm_sd_suspend NULL
+#define tifm_sd_resume NULL
+
+#endif /* CONFIG_PM */
+
 static tifm_media_id tifm_sd_id_tbl[] = {
        FM_SD, 0
 };
@@ -932,7 +962,9 @@ static struct tifm_driver tifm_sd_driver = {
        },
        .id_table = tifm_sd_id_tbl,
        .probe    = tifm_sd_probe,
-       .remove   = tifm_sd_remove
+       .remove   = tifm_sd_remove,
+       .suspend  = tifm_sd_suspend,
+       .resume   = tifm_sd_resume
 };
 
 static int __init tifm_sd_init(void)