]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/mmc/host/tmio_mmc_pio.c
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / mmc / host / tmio_mmc_pio.c
index 2064fa1a5bf11f9a5ca994b94087e389703bb550..6b789a739d4dfeb598a1fced82130ee05f1e4dc6 100644 (file)
@@ -134,18 +134,25 @@ static void tmio_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
        struct tmio_mmc_host *host = mmc_priv(mmc);
 
        if (enable && !host->sdio_irq_enabled) {
+               u16 sdio_status;
+
                /* Keep device active while SDIO irq is enabled */
                pm_runtime_get_sync(mmc_dev(mmc));
-               host->sdio_irq_enabled = true;
 
+               host->sdio_irq_enabled = true;
                host->sdio_irq_mask = TMIO_SDIO_MASK_ALL &
                                        ~TMIO_SDIO_STAT_IOIRQ;
-               sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
+
+               /* Clear obsolete interrupts before enabling */
+               sdio_status = sd_ctrl_read16(host, CTL_SDIO_STATUS) & ~TMIO_SDIO_MASK_ALL;
+               if (host->pdata->flags & TMIO_MMC_SDIO_STATUS_SETBITS)
+                       sdio_status |= TMIO_SDIO_SETBITS_MASK;
+               sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status);
+
                sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
        } else if (!enable && host->sdio_irq_enabled) {
                host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
                sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
-               sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000);
 
                host->sdio_irq_enabled = false;
                pm_runtime_mark_last_busy(mmc_dev(mmc));
@@ -711,9 +718,8 @@ static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
        return false;
 }
 
-static void tmio_mmc_sdio_irq(int irq, void *devid)
+static void __tmio_mmc_sdio_irq(struct tmio_mmc_host *host)
 {
-       struct tmio_mmc_host *host = devid;
        struct mmc_host *mmc = host->mmc;
        struct tmio_mmc_data *pdata = host->pdata;
        unsigned int ireg, status;
@@ -726,8 +732,8 @@ static void tmio_mmc_sdio_irq(int irq, void *devid)
        ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdio_irq_mask;
 
        sdio_status = status & ~TMIO_SDIO_MASK_ALL;
-       if (pdata->flags & TMIO_MMC_SDIO_STATUS_QUIRK)
-               sdio_status |= 6;
+       if (pdata->flags & TMIO_MMC_SDIO_STATUS_SETBITS)
+               sdio_status |= TMIO_SDIO_SETBITS_MASK;
 
        sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status);
 
@@ -754,7 +760,7 @@ irqreturn_t tmio_mmc_irq(int irq, void *devid)
        if (__tmio_mmc_sdcard_irq(host, ireg, status))
                return IRQ_HANDLED;
 
-       tmio_mmc_sdio_irq(irq, devid);
+       __tmio_mmc_sdio_irq(host);
 
        return IRQ_HANDLED;
 }
@@ -902,6 +908,12 @@ static int tmio_mmc_clk_enable(struct tmio_mmc_host *host)
        return host->clk_enable(host);
 }
 
+static void tmio_mmc_clk_disable(struct tmio_mmc_host *host)
+{
+       if (host->clk_disable)
+               host->clk_disable(host);
+}
+
 static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd)
 {
        struct mmc_host *mmc = host->mmc;
@@ -1145,7 +1157,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
 
        ret = mmc_of_parse(mmc);
        if (ret < 0)
-               goto host_free;
+               return ret;
 
        _host->pdata = pdata;
        platform_set_drvdata(pdev, mmc);
@@ -1155,14 +1167,12 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
 
        ret = tmio_mmc_init_ocr(_host);
        if (ret < 0)
-               goto host_free;
+               return ret;
 
        _host->ctl = devm_ioremap(&pdev->dev,
                                  res_ctl->start, resource_size(res_ctl));
-       if (!_host->ctl) {
-               ret = -ENOMEM;
-               goto host_free;
-       }
+       if (!_host->ctl)
+               return -ENOMEM;
 
        tmio_mmc_ops.card_busy = _host->card_busy;
        tmio_mmc_ops.start_signal_voltage_switch = _host->start_signal_voltage_switch;
@@ -1179,8 +1189,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
 
        _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD ||
                                  mmc->caps & MMC_CAP_NEEDS_POLL ||
-                                 !mmc_card_is_removable(mmc) ||
-                                 mmc->slot.cd_irq >= 0);
+                                 !mmc_card_is_removable(mmc));
 
        /*
         * On Gen2+, eMMC with NONREMOVABLE currently fails because native
@@ -1200,10 +1209,8 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
         * Check the sanity of mmc->f_min to prevent tmio_mmc_set_clock() from
         * looping forever...
         */
-       if (mmc->f_min == 0) {
-               ret = -EINVAL;
-               goto host_free;
-       }
+       if (mmc->f_min == 0)
+               return -EINVAL;
 
        /*
         * While using internal tmio hardware logic for card detection, we need
@@ -1232,7 +1239,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
        if (pdata->flags & TMIO_MMC_SDIO_IRQ) {
                _host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
                sd_ctrl_write16(_host, CTL_SDIO_IRQ_MASK, _host->sdio_irq_mask);
-               sd_ctrl_write16(_host, CTL_TRANSACTION_CTL, 0x0000);
+               sd_ctrl_write16(_host, CTL_TRANSACTION_CTL, 0x0001);
        }
 
        spin_lock_init(&_host->lock);
@@ -1268,10 +1275,6 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
        }
 
        return 0;
-
-host_free:
-
-       return ret;
 }
 EXPORT_SYMBOL(tmio_mmc_host_probe);
 
@@ -1280,6 +1283,9 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
        struct platform_device *pdev = host->pdev;
        struct mmc_host *mmc = host->mmc;
 
+       if (host->pdata->flags & TMIO_MMC_SDIO_IRQ)
+               sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000);
+
        if (!host->native_hotplug)
                pm_runtime_get_sync(&pdev->dev);
 
@@ -1292,6 +1298,8 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
 
        pm_runtime_put_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
+
+       tmio_mmc_clk_disable(host);
 }
 EXPORT_SYMBOL(tmio_mmc_host_remove);
 
@@ -1306,8 +1314,7 @@ int tmio_mmc_host_runtime_suspend(struct device *dev)
        if (host->clk_cache)
                tmio_mmc_clk_stop(host);
 
-       if (host->clk_disable)
-               host->clk_disable(host);
+       tmio_mmc_clk_disable(host);
 
        return 0;
 }