]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/mmc/host/sdhci.c
mmc: sdhci: Use work structs instead of tasklets
[karo-tx-linux.git] / drivers / mmc / host / sdhci.c
index 7a7fb4f0d5a43a4829fa1e258afbf112f4dd9b82..53befafe8ff8efe0404559067af0e36a43c80500 100644 (file)
@@ -13,6 +13,7 @@
  *     - JMicron (hardware and technical support)
  */
 
+#include <linux/workqueue.h>
 #include <linux/delay.h>
 #include <linux/highmem.h>
 #include <linux/io.h>
@@ -49,10 +50,9 @@ static unsigned int debug_quirks2;
 
 static void sdhci_finish_data(struct sdhci_host *);
 
-static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
 static void sdhci_finish_command(struct sdhci_host *);
 static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
-static void sdhci_tuning_timer(unsigned long data);
+static void sdhci_tuning_timeout_work(struct work_struct *wk);
 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
 
 #ifdef CONFIG_PM_RUNTIME
@@ -267,7 +267,7 @@ static void sdhci_reinit(struct sdhci_host *host)
        if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                host->flags &= ~SDHCI_USING_RETUNING_TIMER;
 
-               del_timer_sync(&host->tuning_timer);
+               flush_delayed_work(&host->tuning_timeout_work);
                host->flags &= ~SDHCI_NEEDS_RETUNING;
                host->mmc->max_blk_count =
                        (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535;
@@ -978,10 +978,10 @@ static void sdhci_finish_data(struct sdhci_host *host)
 
                sdhci_send_command(host, data->stop);
        } else
-               tasklet_schedule(&host->finish_tasklet);
+               schedule_work(&host->finish_work);
 }
 
-static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
+void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 {
        int flags;
        u32 mask;
@@ -1007,14 +1007,14 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
                                "inhibit bit(s).\n", mmc_hostname(host->mmc));
                        sdhci_dumpregs(host);
                        cmd->error = -EIO;
-                       tasklet_schedule(&host->finish_tasklet);
+                       schedule_work(&host->finish_work);
                        return;
                }
                timeout--;
                mdelay(1);
        }
 
-       mod_timer(&host->timer, jiffies + 10 * HZ);
+       schedule_delayed_work(&host->timeout_work, 10 * HZ);
 
        host->cmd = cmd;
 
@@ -1028,7 +1028,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
                pr_err("%s: Unsupported response type!\n",
                        mmc_hostname(host->mmc));
                cmd->error = -EINVAL;
-               tasklet_schedule(&host->finish_tasklet);
+               schedule_work(&host->finish_work);
                return;
        }
 
@@ -1053,6 +1053,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 
        sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
 }
+EXPORT_SYMBOL_GPL(sdhci_send_command);
 
 static void sdhci_finish_command(struct sdhci_host *host)
 {
@@ -1089,7 +1090,7 @@ static void sdhci_finish_command(struct sdhci_host *host)
                        sdhci_finish_data(host);
 
                if (!host->cmd->data)
-                       tasklet_schedule(&host->finish_tasklet);
+                       schedule_work(&host->finish_work);
 
                host->cmd = NULL;
        }
@@ -1373,13 +1374,13 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
        if (!present || host->flags & SDHCI_DEVICE_DEAD) {
                host->mrq->cmd->error = -ENOMEDIUM;
-               tasklet_schedule(&host->finish_tasklet);
+               schedule_work(&host->finish_work);
        } else {
                u32 present_state;
 
                present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
                /*
-                * Check if the re-tuning timer has already expired and there
+                * Check if the re-tuning timeout has already expired and there
                 * is no on-going data transfer. If so, we need to execute
                 * tuning procedure before sending command.
                 */
@@ -1435,7 +1436,8 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
        }
 
        if (host->version >= SDHCI_SPEC_300 &&
-               (ios->power_mode == MMC_POWER_UP))
+               (ios->power_mode == MMC_POWER_UP) &&
+               !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN))
                sdhci_enable_preset_value(host, false);
 
        sdhci_set_clock(host, ios->clock);
@@ -1875,6 +1877,14 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
                return 0;
        }
 
+       if (host->ops->platform_execute_tuning) {
+               spin_unlock(&host->lock);
+               enable_irq(host->irq);
+               err = host->ops->platform_execute_tuning(host, opcode);
+               sdhci_runtime_pm_put(host);
+               return err;
+       }
+
        sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
 
        /*
@@ -1981,6 +1991,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
        if (!tuning_loop_counter || !timeout) {
                ctrl &= ~SDHCI_CTRL_TUNED_CLK;
                sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+               err = -EIO;
        } else {
                if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
                        pr_info(DRIVER_NAME ": Tuning procedure"
@@ -1993,32 +2004,33 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 out:
        /*
         * If this is the very first time we are here, we start the retuning
-        * timer. Since only during the first time, SDHCI_NEEDS_RETUNING
-        * flag won't be set, we check this condition before actually starting
-        * the timer.
+        * timeout workqueue. Since only during the first time,
+        * SDHCI_NEEDS_RETUNING flag won't be set, we check this condition
+        * before actually starting the timeout worqueue.
         */
        if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
            (host->tuning_mode == SDHCI_TUNING_MODE_1)) {
                host->flags |= SDHCI_USING_RETUNING_TIMER;
-               mod_timer(&host->tuning_timer, jiffies +
+               schedule_delayed_work(&host->tuning_timeout_work,
                        host->tuning_count * HZ);
                /* Tuning mode 1 limits the maximum data length to 4MB */
                mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
        } else {
                host->flags &= ~SDHCI_NEEDS_RETUNING;
-               /* Reload the new initial value for timer */
+               /* Reload the new initial value for timeout workqueue */
                if (host->tuning_mode == SDHCI_TUNING_MODE_1)
-                       mod_timer(&host->tuning_timer, jiffies +
+                       schedule_delayed_work(&host->tuning_timeout_work,
                                host->tuning_count * HZ);
        }
 
        /*
         * In case tuning fails, host controllers which support re-tuning can
-        * try tuning again at a later time, when the re-tuning timer expires.
+        * try tuning again at a later time, when the re-tuning timeout
+        * workqueue expires.
         * So for these controllers, we return 0. Since there might be other
         * controllers who do not have this capability, we return error for
         * them. SDHCI_USING_RETUNING_TIMER means the host is currently using
-        * a retuning timer to do the retuning for the card.
+        * a retuning timeout workqueue to do the retuning for the card.
         */
        if (err && (host->flags & SDHCI_USING_RETUNING_TIMER))
                err = 0;
@@ -2079,7 +2091,7 @@ static void sdhci_card_event(struct mmc_host *mmc)
                sdhci_reset(host, SDHCI_RESET_DATA);
 
                host->mrq->cmd->error = -ENOMEDIUM;
-               tasklet_schedule(&host->finish_tasklet);
+               schedule_work(&host->finish_work);
        }
 
        spin_unlock_irqrestore(&host->lock, flags);
@@ -2104,35 +2116,36 @@ static const struct mmc_host_ops sdhci_ops = {
  *                                                                           *
 \*****************************************************************************/
 
-static void sdhci_tasklet_card(unsigned long param)
+static void sdhci_card_detect_work(struct work_struct *wk)
 {
-       struct sdhci_host *host = (struct sdhci_host*)param;
+       struct sdhci_host *host = container_of(wk, struct sdhci_host,
+                                                  card_detect_work);
 
        sdhci_card_event(host->mmc);
 
        mmc_detect_change(host->mmc, msecs_to_jiffies(200));
 }
 
-static void sdhci_tasklet_finish(unsigned long param)
+static void sdhci_finish_work(struct work_struct *wk)
 {
        struct sdhci_host *host;
        unsigned long flags;
        struct mmc_request *mrq;
 
-       host = (struct sdhci_host*)param;
+       host = container_of(wk, struct sdhci_host, finish_work);
 
        spin_lock_irqsave(&host->lock, flags);
 
-        /*
-         * If this tasklet gets rescheduled while running, it will
-         * be run again afterwards but without any active request.
-         */
+       /*
+        * If this work gets rescheduled while running, it will
+        * be run again afterwards but without any active request.
+        */
        if (!host->mrq) {
                spin_unlock_irqrestore(&host->lock, flags);
                return;
        }
 
-       del_timer(&host->timer);
+       cancel_delayed_work(&host->timeout_work);
 
        mrq = host->mrq;
 
@@ -2172,12 +2185,12 @@ static void sdhci_tasklet_finish(unsigned long param)
        sdhci_runtime_pm_put(host);
 }
 
-static void sdhci_timeout_timer(unsigned long data)
+static void sdhci_timeout_work(struct work_struct *wk)
 {
        struct sdhci_host *host;
        unsigned long flags;
 
-       host = (struct sdhci_host*)data;
+       host = container_of(wk, struct sdhci_host, timeout_work.work);
 
        spin_lock_irqsave(&host->lock, flags);
 
@@ -2195,7 +2208,7 @@ static void sdhci_timeout_timer(unsigned long data)
                        else
                                host->mrq->cmd->error = -ETIMEDOUT;
 
-                       tasklet_schedule(&host->finish_tasklet);
+                       schedule_work(&host->finish_work);
                }
        }
 
@@ -2203,12 +2216,12 @@ static void sdhci_timeout_timer(unsigned long data)
        spin_unlock_irqrestore(&host->lock, flags);
 }
 
-static void sdhci_tuning_timer(unsigned long data)
+static void sdhci_tuning_timeout_work(struct work_struct *wk)
 {
        struct sdhci_host *host;
        unsigned long flags;
 
-       host = (struct sdhci_host *)data;
+       host = container_of(wk, struct sdhci_host, tuning_timeout_work.work);
 
        spin_lock_irqsave(&host->lock, flags);
 
@@ -2242,7 +2255,7 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
                host->cmd->error = -EILSEQ;
 
        if (host->cmd->error) {
-               tasklet_schedule(&host->finish_tasklet);
+               schedule_work(&host->finish_work);
                return;
        }
 
@@ -2451,7 +2464,7 @@ again:
                sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT |
                             SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
                intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
-               tasklet_schedule(&host->card_tasklet);
+               schedule_work(&host->card_detect_work);
        }
 
        if (intmask & SDHCI_INT_CMD_MASK) {
@@ -2555,7 +2568,7 @@ int sdhci_suspend_host(struct sdhci_host *host)
 
        /* Disable tuning since we are suspending */
        if (host->flags & SDHCI_USING_RETUNING_TIMER) {
-               del_timer_sync(&host->tuning_timer);
+               flush_delayed_work(&host->tuning_timeout_work);
                host->flags &= ~SDHCI_NEEDS_RETUNING;
        }
 
@@ -2563,7 +2576,7 @@ int sdhci_suspend_host(struct sdhci_host *host)
        if (ret) {
                if (host->flags & SDHCI_USING_RETUNING_TIMER) {
                        host->flags |= SDHCI_NEEDS_RETUNING;
-                       mod_timer(&host->tuning_timer, jiffies +
+                       schedule_delayed_work(&host->tuning_timeout_work,
                                        host->tuning_count * HZ);
                }
 
@@ -2667,7 +2680,7 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host)
 
        /* Disable tuning since we are suspending */
        if (host->flags & SDHCI_USING_RETUNING_TIMER) {
-               del_timer_sync(&host->tuning_timer);
+               flush_delayed_work(&host->tuning_timeout_work);
                host->flags &= ~SDHCI_NEEDS_RETUNING;
        }
 
@@ -3025,13 +3038,13 @@ int sdhci_add_host(struct sdhci_host *host)
        if (caps[1] & SDHCI_DRIVER_TYPE_D)
                mmc->caps |= MMC_CAP_DRIVER_TYPE_D;
 
-       /* Initial value for re-tuning timer count */
+       /* Initial value for re-tuning timeout count */
        host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >>
                              SDHCI_RETUNING_TIMER_COUNT_SHIFT;
 
        /*
-        * In case Re-tuning Timer is not disabled, the actual value of
-        * re-tuning timer will be 2 ^ (n - 1).
+        * In case Re-tuning Timeout is not disabled, the actual value of
+        * re-tuning timeout will be 2 ^ (n - 1).
         */
        if (host->tuning_count)
                host->tuning_count = 1 << (host->tuning_count - 1);
@@ -3198,22 +3211,19 @@ int sdhci_add_host(struct sdhci_host *host)
        mmc->max_blk_count = (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535;
 
        /*
-        * Init tasklets.
+        * Init work structs.
         */
-       tasklet_init(&host->card_tasklet,
-               sdhci_tasklet_card, (unsigned long)host);
-       tasklet_init(&host->finish_tasklet,
-               sdhci_tasklet_finish, (unsigned long)host);
+       INIT_WORK(&host->card_detect_work, sdhci_card_detect_work);
+       INIT_WORK(&host->finish_work, sdhci_finish_work);
 
-       setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host);
+       INIT_DELAYED_WORK(&host->timeout_work, sdhci_timeout_work);
 
        if (host->version >= SDHCI_SPEC_300) {
                init_waitqueue_head(&host->buf_ready_int);
 
-               /* Initialize re-tuning timer */
-               init_timer(&host->tuning_timer);
-               host->tuning_timer.data = (unsigned long)host;
-               host->tuning_timer.function = sdhci_tuning_timer;
+               /* Initialize re-tuning timeout work */
+               INIT_DELAYED_WORK(&host->tuning_timeout_work,
+                                       sdhci_tuning_timeout_work);
        }
 
        sdhci_init(host, 0);
@@ -3223,7 +3233,7 @@ int sdhci_add_host(struct sdhci_host *host)
        if (ret) {
                pr_err("%s: Failed to request IRQ %d: %d\n",
                       mmc_hostname(mmc), host->irq, ret);
-               goto untasklet;
+               return ret;
        }
 
 #ifdef CONFIG_MMC_DEBUG
@@ -3265,10 +3275,6 @@ reset:
        sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
        free_irq(host->irq, host);
 #endif
-untasklet:
-       tasklet_kill(&host->card_tasklet);
-       tasklet_kill(&host->finish_tasklet);
-
        return ret;
 }
 
@@ -3288,7 +3294,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
                                " transfer!\n", mmc_hostname(host->mmc));
 
                        host->mrq->cmd->error = -ENOMEDIUM;
-                       tasklet_schedule(&host->finish_tasklet);
+                       schedule_work(&host->finish_work);
                }
 
                spin_unlock_irqrestore(&host->lock, flags);
@@ -3308,10 +3314,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
        sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
        free_irq(host->irq, host);
 
-       del_timer_sync(&host->timer);
+       flush_delayed_work(&host->timeout_work);
 
-       tasklet_kill(&host->card_tasklet);
-       tasklet_kill(&host->finish_tasklet);
+       flush_work(&host->card_detect_work);
+       flush_work(&host->finish_work);
 
        if (host->vmmc) {
                regulator_disable(host->vmmc);