Skip to content

Commit 41e84fe

Browse files
author
Ulf Hansson
committed
mmc: core: Drop open coding in mmc_sd_switch()
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
1 parent cec18ad commit 41e84fe

1 file changed

Lines changed: 7 additions & 31 deletions

File tree

‎drivers/mmc/core/sd_ops.c‎

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "core.h"
1919
#include "sd_ops.h"
20+
#include "mmc_ops.h"
2021

2122
int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
2223
{
@@ -309,43 +310,18 @@ int mmc_app_send_scr(struct mmc_card *card)
309310
int mmc_sd_switch(struct mmc_card *card, int mode, int group,
310311
u8 value, u8 *resp)
311312
{
312-
struct mmc_request mrq = {};
313-
struct mmc_command cmd = {};
314-
struct mmc_data data = {};
315-
struct scatterlist sg;
313+
u32 cmd_args;
316314

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

319317
mode = !!mode;
320318
value &= 0xF;
319+
cmd_args = mode << 31 | 0x00FFFFFF;
320+
cmd_args &= ~(0xF << (group * 4));
321+
cmd_args |= value << (group * 4);
321322

322-
mrq.cmd = &cmd;
323-
mrq.data = &data;
324-
325-
cmd.opcode = SD_SWITCH;
326-
cmd.arg = mode << 31 | 0x00FFFFFF;
327-
cmd.arg &= ~(0xF << (group * 4));
328-
cmd.arg |= value << (group * 4);
329-
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
330-
331-
data.blksz = 64;
332-
data.blocks = 1;
333-
data.flags = MMC_DATA_READ;
334-
data.sg = &sg;
335-
data.sg_len = 1;
336-
337-
sg_init_one(&sg, resp, 64);
338-
339-
mmc_set_data_timeout(&data, card);
340-
341-
mmc_wait_for_req(card->host, &mrq);
342-
343-
if (cmd.error)
344-
return cmd.error;
345-
if (data.error)
346-
return data.error;
347-
348-
return 0;
323+
return mmc_send_adtc_data(card, card->host, SD_SWITCH, cmd_args, resp,
324+
64);
349325
}
350326

351327
int mmc_app_sd_status(struct mmc_card *card, void *ssr)

0 commit comments

Comments
 (0)