--- zzzz-none-000/linux-4.9.279/drivers/mmc/core/core.c 2021-08-08 06:38:54.000000000 +0000 +++ puma7-atom-6591-750/linux-4.9.279/drivers/mmc/core/core.c 2023-02-08 11:43:42.000000000 +0000 @@ -49,6 +49,11 @@ #include "sd_ops.h" #include "sdio_ops.h" +#ifdef CONFIG_HW_MUTEXES +#include +#include "../host/sdhci.h" +#endif + /* If the device is not responding */ #define MMC_CORE_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ @@ -201,6 +206,7 @@ pr_debug("%s: %d bytes transferred: %d\n", mmc_hostname(host), mrq->data->bytes_xfered, mrq->data->error); + trace_mmc_blk_rw_end(cmd->opcode, cmd->arg, mrq->data); } if (mrq->stop) { @@ -575,7 +581,7 @@ mmc_retune_recheck(host); - pr_debug("%s: req failed (CMD%u): %d, retrying...\n", + pr_info("%s: req failed (CMD%u): %d, retrying...\n", mmc_hostname(host), cmd->opcode, cmd->error); cmd->retries--; cmd->error = 0; @@ -699,8 +705,12 @@ } } - if (!err && areq) + if (!err && areq) { + trace_mmc_blk_rw_start(areq->mrq->cmd->opcode, + areq->mrq->cmd->arg, + areq->mrq->data); start_err = __mmc_start_data_req(host, areq->mrq); + } if (host->areq) mmc_post_req(host, host->areq->mrq, 0); @@ -782,7 +792,7 @@ break; default: /* In all other states, it's illegal to issue HPI */ - pr_debug("%s: HPI cannot be sent. Card state=%d\n", + pr_info("%s: HPI cannot be sent. Card state=%d\n", mmc_hostname(card->host), R1_CURRENT_STATE(status)); err = -EINVAL; goto out; @@ -1056,6 +1066,20 @@ spin_unlock_irqrestore(&host->lock, flags); remove_wait_queue(&host->wq, &wait); +#ifdef CONFIG_HW_MUTEXES + + spin_lock_irqsave(&host->lock, flags); + + if((host->claimer == current) && (host->claim_cnt == 1)) { + spin_unlock_irqrestore(&host->lock, flags); + MMC_LOCK_HW_MUTEX(host); + } + else { + spin_unlock_irqrestore(&host->lock, flags); + } + +#endif + if (pm) pm_runtime_get_sync(mmc_dev(host)); @@ -1084,6 +1108,10 @@ host->claimed = 0; host->claimer = NULL; spin_unlock_irqrestore(&host->lock, flags); + +#ifdef CONFIG_HW_MUTEXES + MMC_UNLOCK_HW_MUTEX(host); +#endif wake_up(&host->wq); pm_runtime_mark_last_busy(mmc_dev(host)); pm_runtime_put_autosuspend(mmc_dev(host)); @@ -1742,7 +1770,7 @@ power_cycle: if (err) { - pr_debug("%s: Signal voltage switch failed, " + pr_info("%s: Signal voltage switch failed, " "power cycling card\n", mmc_hostname(host)); mmc_power_cycle(host, ocr); } @@ -2159,8 +2187,13 @@ unsigned int qty = 0, busy_timeout = 0; bool use_r1b_resp = false; unsigned long timeout; + unsigned int fr, nr; int err; + fr = from; + nr = to - from + 1; + trace_mmc_blk_erase_start(arg, fr, nr); + mmc_retune_hold(card->host); /* @@ -2288,6 +2321,7 @@ (R1_CURRENT_STATE(cmd.resp[0]) == R1_STATE_PRG)); out: mmc_retune_release(card->host); + trace_mmc_blk_erase_end(arg, fr, nr); return err; } @@ -2808,12 +2842,26 @@ goto out; } + +#ifdef CONFIG_HW_MUTEXES + if (MMC_HOST_SUPPORTS_HW_MUTEX(host)) + { + // We disabled register writes during initialization and the host is not + // currently initialized. Power up then power cycle the emmc/host to + // ensure it is configured as it believes it is currently off and during + // the cycle, the off is ignored when it shouldn't be. + mmc_power_up(host, host->ocr_avail); + mmc_power_cycle(host, host->ocr_avail); + } +#endif + for (i = 0; i < ARRAY_SIZE(freqs); i++) { if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) break; if (freqs[i] <= host->f_min) break; } + mmc_release_host(host); out: