Skip to content

Commit

Permalink
mmc: core: Drop open coding in mmc_sd_switch()
Browse files Browse the repository at this point in the history
The SD_SWITCH (CMD6) is an ADTC type of command with an R1 response, which
can be sent by using the mmc_send_adtc_data(). Let's do that and drop the
open coding in mmc_sd_switch().

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20210504161222.101536-8-ulf.hansson@linaro.org
  • Loading branch information
Ulf Hansson committed Jun 14, 2021
1 parent cec18ad commit 41e84fe
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions drivers/mmc/core/sd_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "core.h"
#include "sd_ops.h"
#include "mmc_ops.h"

int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
{
Expand Down Expand Up @@ -309,43 +310,18 @@ int mmc_app_send_scr(struct mmc_card *card)
int mmc_sd_switch(struct mmc_card *card, int mode, int group,
u8 value, u8 *resp)
{
struct mmc_request mrq = {};
struct mmc_command cmd = {};
struct mmc_data data = {};
struct scatterlist sg;
u32 cmd_args;

/* NOTE: caller guarantees resp is heap-allocated */

mode = !!mode;
value &= 0xF;
cmd_args = mode << 31 | 0x00FFFFFF;
cmd_args &= ~(0xF << (group * 4));
cmd_args |= value << (group * 4);

mrq.cmd = &cmd;
mrq.data = &data;

cmd.opcode = SD_SWITCH;
cmd.arg = mode << 31 | 0x00FFFFFF;
cmd.arg &= ~(0xF << (group * 4));
cmd.arg |= value << (group * 4);
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;

data.blksz = 64;
data.blocks = 1;
data.flags = MMC_DATA_READ;
data.sg = &sg;
data.sg_len = 1;

sg_init_one(&sg, resp, 64);

mmc_set_data_timeout(&data, card);

mmc_wait_for_req(card->host, &mrq);

if (cmd.error)
return cmd.error;
if (data.error)
return data.error;

return 0;
return mmc_send_adtc_data(card, card->host, SD_SWITCH, cmd_args, resp,
64);
}

int mmc_app_sd_status(struct mmc_card *card, void *ssr)
Expand Down

0 comments on commit 41e84fe

Please sign in to comment.