diff mbox series

[07/11] mmc: core: Drop open coding in mmc_sd_switch()

Message ID 20210504161222.101536-8-ulf.hansson@linaro.org (mailing list archive)
State New, archived
Headers show
Series Initital support for new power/perf features for SD cards | expand

Commit Message

Ulf Hansson May 4, 2021, 4:12 p.m. UTC
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>
---
 drivers/mmc/core/sd_ops.c | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)

Comments

Linus Walleij May 6, 2021, 12:57 p.m. UTC | #1
On Tue, May 4, 2021 at 6:12 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:

> 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>

Yours,
Linus Walleij
Shawn Lin May 7, 2021, 1:54 a.m. UTC | #2
On 2021/5/5 0:12, Ulf Hansson wrote:
> 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().

Nice cleanup.

Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>

> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>   drivers/mmc/core/sd_ops.c | 38 +++++++-------------------------------
>   1 file changed, 7 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
> index d61ff811218c..ef8d1dce5af1 100644
> --- a/drivers/mmc/core/sd_ops.c
> +++ b/drivers/mmc/core/sd_ops.c
> @@ -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)
>   {
> @@ -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)
>
diff mbox series

Patch

diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index d61ff811218c..ef8d1dce5af1 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -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)
 {
@@ -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)