]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mmc/omap.c
Change OMAP_MMC_{READ,WRITE} macros to use the host pointer
[linux-2.6-omap-h63xx.git] / drivers / mmc / omap.c
index becb3c68c34d7578043a9a0885705ae4d63c9597..efd14cf60f891c5debb2afba442a2976f0c77199 100644 (file)
@@ -11,7 +11,6 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
@@ -61,7 +60,9 @@ struct mmc_omap_host {
        unsigned char           id; /* 16xx chips have 2 MMC blocks */
        struct clk *            iclk;
        struct clk *            fclk;
-       void __iomem            *base;
+       struct resource         *mem_res;
+       void __iomem            *virt_base;
+       unsigned int            phys_base;
        int                     irq;
        unsigned char           bus_mode;
        unsigned char           hw_bus_mode;
@@ -191,16 +192,16 @@ mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd)
 
        clk_enable(host->fclk);
 
-       OMAP_MMC_WRITE(host->base, CTO, 200);
-       OMAP_MMC_WRITE(host->base, ARGL, cmd->arg & 0xffff);
-       OMAP_MMC_WRITE(host->base, ARGH, cmd->arg >> 16);
-       OMAP_MMC_WRITE(host->base, IE,
+       OMAP_MMC_WRITE(host, CTO, 200);
+       OMAP_MMC_WRITE(host, ARGL, cmd->arg & 0xffff);
+       OMAP_MMC_WRITE(host, ARGH, cmd->arg >> 16);
+       OMAP_MMC_WRITE(host, IE,
                       OMAP_MMC_STAT_A_EMPTY    | OMAP_MMC_STAT_A_FULL    |
                       OMAP_MMC_STAT_CMD_CRC    | OMAP_MMC_STAT_CMD_TOUT  |
                       OMAP_MMC_STAT_DATA_CRC   | OMAP_MMC_STAT_DATA_TOUT |
                       OMAP_MMC_STAT_END_OF_CMD | OMAP_MMC_STAT_CARD_ERR  |
                       OMAP_MMC_STAT_END_OF_DATA);
-       OMAP_MMC_WRITE(host->base, CMD, cmdreg);
+       OMAP_MMC_WRITE(host, CMD, cmdreg);
 }
 
 static void
@@ -296,22 +297,22 @@ mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
                if (cmd->flags & MMC_RSP_136) {
                        /* response type 2 */
                        cmd->resp[3] =
-                               OMAP_MMC_READ(host->base, RSP0) |
-                               (OMAP_MMC_READ(host->base, RSP1) << 16);
+                               OMAP_MMC_READ(host, RSP0) |
+                               (OMAP_MMC_READ(host, RSP1) << 16);
                        cmd->resp[2] =
-                               OMAP_MMC_READ(host->base, RSP2) |
-                               (OMAP_MMC_READ(host->base, RSP3) << 16);
+                               OMAP_MMC_READ(host, RSP2) |
+                               (OMAP_MMC_READ(host, RSP3) << 16);
                        cmd->resp[1] =
-                               OMAP_MMC_READ(host->base, RSP4) |
-                               (OMAP_MMC_READ(host->base, RSP5) << 16);
+                               OMAP_MMC_READ(host, RSP4) |
+                               (OMAP_MMC_READ(host, RSP5) << 16);
                        cmd->resp[0] =
-                               OMAP_MMC_READ(host->base, RSP6) |
-                               (OMAP_MMC_READ(host->base, RSP7) << 16);
+                               OMAP_MMC_READ(host, RSP6) |
+                               (OMAP_MMC_READ(host, RSP7) << 16);
                } else {
                        /* response types 1, 1b, 3, 4, 5, 6 */
                        cmd->resp[0] =
-                               OMAP_MMC_READ(host->base, RSP6) |
-                               (OMAP_MMC_READ(host->base, RSP7) << 16);
+                               OMAP_MMC_READ(host, RSP6) |
+                               (OMAP_MMC_READ(host, RSP7) << 16);
                }
        }
 
@@ -340,8 +341,6 @@ static void
 mmc_omap_xfer_data(struct mmc_omap_host *host, int write)
 {
        int n;
-       void __iomem *reg;
-       u16 *p;
 
        if (host->buffer_bytes_left == 0) {
                host->sg_idx++;
@@ -356,9 +355,9 @@ mmc_omap_xfer_data(struct mmc_omap_host *host, int write)
        host->data->bytes_xfered += n;
 
        if (write) {
-               __raw_writesw(host->base + OMAP_MMC_REG_DATA, host->buffer, n);
+               __raw_writesw(host->virt_base + OMAP_MMC_REG_DATA, host->buffer, n);
        } else {
-               __raw_readsw(host->base + OMAP_MMC_REG_DATA, host->buffer, n);
+               __raw_readsw(host->virt_base + OMAP_MMC_REG_DATA, host->buffer, n);
        }
 }
 
@@ -379,7 +378,7 @@ static inline void mmc_omap_report_irq(u16 status)
                }
 }
 
-static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
 {
        struct mmc_omap_host * host = (struct mmc_omap_host *)dev_id;
        u16 status;
@@ -388,11 +387,11 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs)
        int transfer_error;
 
        if (host->cmd == NULL && host->data == NULL) {
-               status = OMAP_MMC_READ(host->base, STAT);
+               status = OMAP_MMC_READ(host, STAT);
                dev_info(mmc_dev(host->mmc),"spurious irq 0x%04x\n", status);
                if (status != 0) {
-                       OMAP_MMC_WRITE(host->base, STAT, status);
-                       OMAP_MMC_WRITE(host->base, IE, 0);
+                       OMAP_MMC_WRITE(host, STAT, status);
+                       OMAP_MMC_WRITE(host, IE, 0);
                }
                return IRQ_HANDLED;
        }
@@ -401,8 +400,8 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs)
        end_transfer = 0;
        transfer_error = 0;
 
-       while ((status = OMAP_MMC_READ(host->base, STAT)) != 0) {
-               OMAP_MMC_WRITE(host->base, STAT, status);
+       while ((status = OMAP_MMC_READ(host, STAT)) != 0) {
+               OMAP_MMC_WRITE(host, STAT, status);
 #ifdef CONFIG_MMC_DEBUG
                dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ",
                        status, host->cmd != NULL ? host->cmd->opcode : -1);
@@ -472,8 +471,8 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs)
 
                if (status & OMAP_MMC_STAT_CARD_ERR) {
                        if (host->cmd && host->cmd->opcode == MMC_STOP_TRANSMISSION) {
-                               u32 response = OMAP_MMC_READ(host->base, RSP6)
-                                       | (OMAP_MMC_READ(host->base, RSP7) << 16);
+                               u32 response = OMAP_MMC_READ(host, RSP6)
+                                       | (OMAP_MMC_READ(host, RSP7) << 16);
                                /* STOP sometimes sets must-ignore bits */
                                if (!(response & (R1_CC_ERROR
                                                                | R1_ILLEGAL_COMMAND
@@ -516,7 +515,7 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_HANDLED;
 }
 
-static irqreturn_t mmc_omap_switch_irq(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t mmc_omap_switch_irq(int irq, void *dev_id)
 {
        struct mmc_omap_host *host = (struct mmc_omap_host *) dev_id;
 
@@ -583,11 +582,11 @@ mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data)
        int dst_port = 0;
        int sync_dev = 0;
 
-       data_addr = io_v2p((u32) host->base) + OMAP_MMC_REG_DATA;
-       frame = 1 << data->blksz_bits;
+       data_addr = host->phys_base + OMAP_MMC_REG_DATA;
+       frame = data->blksz;
        count = sg_dma_len(sg);
 
-       if ((data->blocks == 1) && (count > (1 << data->blksz_bits)))
+       if ((data->blocks == 1) && (count > data->blksz))
                count = frame;
 
        host->dma_len = count;
@@ -645,7 +644,7 @@ mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data)
        if (unlikely(count > 0xffff))
                BUG();
 
-       OMAP_MMC_WRITE(host->base, BUF, buf);
+       OMAP_MMC_WRITE(host, BUF, buf);
        omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S16,
                                     frame, count, OMAP_DMA_SYNC_FRAME,
                                     sync_dev, 0);
@@ -658,12 +657,12 @@ static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
        struct mmc_data *mmcdat = host->data;
 
        if (unlikely(host->dma_ch < 0)) {
-               dev_err(mmc_dev(host->mmc), "DMA callback while DMA not
-                               enabled\n");
+               dev_err(mmc_dev(host->mmc),
+                       "DMA callback while DMA not enabled\n");
                return;
        }
        /* FIXME: We really should do something to _handle_ the errors */
-       if (ch_status & OMAP_DMA_TOUT_IRQ) {
+       if (ch_status & OMAP1_DMA_TOUT_IRQ) {
                dev_err(mmc_dev(host->mmc),"DMA timeout\n");
                return;
        }
@@ -730,11 +729,11 @@ static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_reques
 {
        u16 reg;
 
-       reg = OMAP_MMC_READ(host->base, SDIO);
+       reg = OMAP_MMC_READ(host, SDIO);
        reg &= ~(1 << 5);
-       OMAP_MMC_WRITE(host->base, SDIO, reg);
+       OMAP_MMC_WRITE(host, SDIO, reg);
        /* Set maximum timeout */
-       OMAP_MMC_WRITE(host->base, CTO, 0xff);
+       OMAP_MMC_WRITE(host, CTO, 0xff);
 }
 
 static inline void set_data_timeout(struct mmc_omap_host *host, struct mmc_request *req)
@@ -748,14 +747,14 @@ static inline void set_data_timeout(struct mmc_omap_host *host, struct mmc_reque
        timeout = req->data->timeout_clks + req->data->timeout_ns / 500;
 
        /* Check if we need to use timeout multiplier register */
-       reg = OMAP_MMC_READ(host->base, SDIO);
+       reg = OMAP_MMC_READ(host, SDIO);
        if (timeout > 0xffff) {
                reg |= (1 << 5);
                timeout /= 1024;
        } else
                reg &= ~(1 << 5);
-       OMAP_MMC_WRITE(host->base, SDIO, reg);
-       OMAP_MMC_WRITE(host->base, DTO, timeout);
+       OMAP_MMC_WRITE(host, SDIO, reg);
+       OMAP_MMC_WRITE(host, DTO, timeout);
 }
 
 static void
@@ -767,19 +766,19 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
 
        host->data = data;
        if (data == NULL) {
-               OMAP_MMC_WRITE(host->base, BLEN, 0);
-               OMAP_MMC_WRITE(host->base, NBLK, 0);
-               OMAP_MMC_WRITE(host->base, BUF, 0);
+               OMAP_MMC_WRITE(host, BLEN, 0);
+               OMAP_MMC_WRITE(host, NBLK, 0);
+               OMAP_MMC_WRITE(host, BUF, 0);
                host->dma_in_use = 0;
                set_cmd_timeout(host, req);
                return;
        }
 
 
-       block_size = 1 << data->blksz_bits;
+       block_size = data->blksz;
 
-       OMAP_MMC_WRITE(host->base, NBLK, data->blocks - 1);
-       OMAP_MMC_WRITE(host->base, BLEN, block_size - 1);
+       OMAP_MMC_WRITE(host, NBLK, data->blocks - 1);
+       OMAP_MMC_WRITE(host, BLEN, block_size - 1);
        set_data_timeout(host, req);
 
        /* cope with calling layer confusion; it issues "single
@@ -821,7 +820,7 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
 
        /* Revert to PIO? */
        if (!use_dma) {
-               OMAP_MMC_WRITE(host->base, BUF, 0x1f1f);
+               OMAP_MMC_WRITE(host, BUF, 0x1f1f);
                host->total_bytes_left = data->blocks * block_size;
                host->sg_len = sg_len;
                mmc_omap_sg_to_buf(host);
@@ -873,8 +872,8 @@ static void mmc_omap_power(struct mmc_omap_host *host, int on)
                        /* GPIO 4 of TPS65010 sends SD_EN signal */
                        tps65010_set_gpio_out_value(GPIO4, HIGH);
                else if (cpu_is_omap24xx()) {
-                       u16 reg = OMAP_MMC_READ(host->base, CON);
-                       OMAP_MMC_WRITE(host->base, CON, reg | (1 << 11));
+                       u16 reg = OMAP_MMC_READ(host, CON);
+                       OMAP_MMC_WRITE(host, CON, reg | (1 << 11));
                } else
                        if (host->power_pin >= 0)
                                omap_set_gpio_dataout(host->power_pin, 1);
@@ -886,8 +885,8 @@ static void mmc_omap_power(struct mmc_omap_host *host, int on)
                else if (machine_is_omap_h3())
                        tps65010_set_gpio_out_value(GPIO4, LOW);
                else if (cpu_is_omap24xx()) {
-                       u16 reg = OMAP_MMC_READ(host->base, CON);
-                       OMAP_MMC_WRITE(host->base, CON, reg & ~(1 << 11));
+                       u16 reg = OMAP_MMC_READ(host, CON);
+                       OMAP_MMC_WRITE(host, CON, reg & ~(1 << 11));
                } else
                        if (host->power_pin >= 0)
                                omap_set_gpio_dataout(host->power_pin, 0);
@@ -943,14 +942,14 @@ static void mmc_omap_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
         * which results in the while loop below getting stuck.
         * Writing to the CON register twice seems to do the trick. */
        for (i = 0; i < 2; i++)
-               OMAP_MMC_WRITE(host->base, CON, dsor);
+               OMAP_MMC_WRITE(host, CON, dsor);
        if (ios->power_mode == MMC_POWER_UP) {
                /* Send clock cycles, poll completion */
-               OMAP_MMC_WRITE(host->base, IE, 0);
-               OMAP_MMC_WRITE(host->base, STAT, 0xffff);
-               OMAP_MMC_WRITE(host->base, CMD, 1<<7);
-               while (0 == (OMAP_MMC_READ(host->base, STAT) & 1));
-               OMAP_MMC_WRITE(host->base, STAT, 1);
+               OMAP_MMC_WRITE(host, IE, 0);
+               OMAP_MMC_WRITE(host, STAT, 0xffff);
+               OMAP_MMC_WRITE(host, CMD, 1<<7);
+               while (0 == (OMAP_MMC_READ(host, STAT) & 1));
+               OMAP_MMC_WRITE(host, STAT, 1);
        }
        clk_disable(host->fclk);
 }
@@ -962,7 +961,7 @@ static int mmc_omap_get_ro(struct mmc_host *mmc)
        return host->wp_pin && omap_get_gpio_datain(host->wp_pin);
 }
 
-static struct mmc_host_ops mmc_omap_ops = {
+static const struct mmc_host_ops mmc_omap_ops = {
        .request        = mmc_omap_request,
        .set_ios        = mmc_omap_set_ios,
        .get_ro         = mmc_omap_get_ro,
@@ -973,20 +972,20 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
        struct omap_mmc_conf *minfo = pdev->dev.platform_data;
        struct mmc_host *mmc;
        struct mmc_omap_host *host = NULL;
+       struct resource *r;
        int ret = 0;
+       int irq;
        
-       if (platform_get_resource(pdev, IORESOURCE_MEM, 0) ||
-                       platform_get_irq(pdev, IORESOURCE_IRQ, 0)) {
-               dev_err(&pdev->dev, "mmc_omap_probe: invalid resource type\n");
-               return -ENODEV;
-       }
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       irq = platform_get_irq(pdev, 0);
+       if (!r || irq < 0)
+               return -ENXIO;
 
-       if (!request_mem_region(pdev->resource[0].start,
+       r = request_mem_region(pdev->resource[0].start,
                                pdev->resource[0].end - pdev->resource[0].start + 1,
-                               pdev->name)) {
-               dev_dbg(&pdev->dev, "request_mem_region failed\n");
+                              pdev->name);
+       if (!r)
                return -EBUSY;
-       }
 
        mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
        if (!mmc) {
@@ -1003,6 +1002,8 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
        host->dma_timer.data = (unsigned long) host;
 
        host->id = pdev->id;
+       host->mem_res = r;
+       host->irq = irq;
 
        if (cpu_is_omap24xx()) {
                host->iclk = clk_get(&pdev->dev, "mmc_ick");
@@ -1032,19 +1033,17 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
        host->dma_ch = -1;
 
        host->irq = pdev->resource[1].start;
-       host->base = ioremap(pdev->res.start, SZ_4K);
-       if (!host->base) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-        if (minfo->wire4)
-                mmc->caps |= MMC_CAP_4_BIT_DATA;
+       host->phys_base = host->mem_res->start;
+       host->virt_base = (void __iomem *) IO_ADDRESS(host->phys_base);
 
        mmc->ops = &mmc_omap_ops;
        mmc->f_min = 400000;
        mmc->f_max = 24000000;
        mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
+       mmc->caps = MMC_CAP_BYTEBLOCK;
+
+       if (minfo->wire4)
+                mmc->caps |= MMC_CAP_4_BIT_DATA;
 
        /* Use scatterlist DMA to reduce per-transfer costs.
         * NOTE max_seg_size assumption that small blocks aren't
@@ -1057,8 +1056,8 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
 
        if (host->power_pin >= 0) {
                if ((ret = omap_request_gpio(host->power_pin)) != 0) {
-                       dev_err(mmc_dev(host->mmc), "Unable to get GPIO
-                                       pin for MMC power\n");
+                       dev_err(mmc_dev(host->mmc),
+                               "Unable to get GPIO pin for MMC power\n");
                        goto out;
                }
                omap_set_gpio_direction(host->power_pin, 0);
@@ -1086,7 +1085,7 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
 
                omap_set_gpio_direction(host->switch_pin, 1);
                ret = request_irq(OMAP_GPIO_IRQ(host->switch_pin),
-                                 mmc_omap_switch_irq, SA_TRIGGER_RISING, DRIVER_NAME, host);
+                                 mmc_omap_switch_irq, IRQF_TRIGGER_RISING, DRIVER_NAME, host);
                if (ret) {
                        dev_warn(mmc_dev(host->mmc), "Unable to get IRQ for MMC cover switch\n");
                        omap_free_gpio(host->switch_pin);
@@ -1100,7 +1099,7 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
                                device_remove_file(&pdev->dev, &dev_attr_cover_switch);
                }
                if (ret) {
-                       dev_wan(mmc_dev(host->mmc), "Unable to create sysfs attributes\n");
+                       dev_warn(mmc_dev(host->mmc), "Unable to create sysfs attributes\n");
                        free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
                        omap_free_gpio(host->switch_pin);
                        host->switch_pin = -1;