[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20211207062155.10689-1-nishadkamdar@gmail.com>
Date: Tue, 7 Dec 2021 11:51:55 +0530
From: Nishad Kamdar <nishadkamdar@...il.com>
To: nishadkamdar@...il.com, Stephen Boyd <swboyd@...omium.org>,
Ulf Hansson <ulf.hansson@...aro.org>,
Jens Axboe <axboe@...nel.dk>,
Adrian Hunter <adrian.hunter@...el.com>,
Bean Huo <beanhuo@...ron.com>,
Shawn Lin <shawn.lin@...k-chips.com>,
Avri Altman <avri.altman@....com>,
Huijin Park <huijin.park@...sung.com>,
Yue Hu <huyue2@...ong.com>,
Wolfram Sang <wsa+renesas@...g-engineering.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-mmc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v2] mmc: core: Add support for the eMMC RTC feature in mmc_ops
This patch adds support to set the RTC information in
the eMMC device. This is based on the JEDEC specification.
There is no way however, to read the RTC time from the
device. Hence we rely on the response of the CMD49 to
confirm the completion of the operation.
This patch has been tested successfully with the ioctl
interface. This patch has also been tested suceessfully
with all the three RTC_INFO_TYPEs.
Signed-off-by: Nishad Kamdar <nishadkamdar@...il.com>
---
Changes in v2:
- Use sizeof(seconds) instead of sizeof(u64)
- Drop out: and the assignment of err to 0
- Keep 512 value as it is as no #define available for the same and
other functions in the file use the 512 value
drivers/mmc/core/mmc_ops.c | 56 ++++++++++++++++++++++++++++++++++++++
drivers/mmc/core/mmc_ops.h | 2 ++
include/linux/mmc/mmc.h | 1 +
3 files changed, 59 insertions(+)
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index d63d1c735335..d3ca68585c71 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -1063,3 +1063,59 @@ int mmc_sanitize(struct mmc_card *card, unsigned int timeout_ms)
return err;
}
EXPORT_SYMBOL_GPL(mmc_sanitize);
+
+int mmc_set_time(struct mmc_card *card, struct mmc_host *host,
+ u8 rtc_info_type, u64 seconds)
+{
+ struct mmc_request mrq = {};
+ struct mmc_command cmd = {};
+ struct mmc_data data = {};
+ struct scatterlist sg;
+ int err;
+ u8 *data_buf;
+
+ data_buf = kzalloc(512, GFP_KERNEL);
+ if (!data_buf)
+ return -ENOMEM;
+
+ if (rtc_info_type == 0x01 || rtc_info_type == 0x02 ||
+ rtc_info_type == 0x03) {
+ data_buf[0] = 0x01;
+ data_buf[1] = rtc_info_type;
+ memcpy(&data_buf[2], &seconds, sizeof(seconds));
+ } else {
+ pr_err("%s: invalid rtc_info_type %d\n",
+ mmc_hostname(host), rtc_info_type);
+ kfree(data_buf);
+ return -EINVAL;
+ }
+
+ mrq.cmd = &cmd;
+ mrq.data = &data;
+
+ cmd.opcode = MMC_SET_TIME;
+ cmd.arg = 0;
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
+
+ data.blksz = 512;
+ data.blocks = 1;
+ data.flags = MMC_DATA_WRITE;
+ data.sg = &sg;
+ data.sg_len = 1;
+ sg_init_one(&sg, data_buf, 512);
+
+ mmc_set_data_timeout(&data, card);
+
+ mmc_wait_for_req(host, &mrq);
+
+ if (cmd.error)
+ err = cmd.error;
+ else if (data.error)
+ err = data.error;
+ else
+ err = 0;
+
+ kfree(data_buf);
+ return err;
+}
+EXPORT_SYMBOL_GPL(mmc_set_time);
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index 9c813b851d0b..0c8695d1b363 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -55,6 +55,8 @@ void mmc_run_bkops(struct mmc_card *card);
int mmc_cmdq_enable(struct mmc_card *card);
int mmc_cmdq_disable(struct mmc_card *card);
int mmc_sanitize(struct mmc_card *card, unsigned int timeout_ms);
+int mmc_set_time(struct mmc_card *card, struct mmc_host *host,
+ u8 rtc_info_type, u64 seconds);
#endif
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index d9a65c6a8816..52a3bf873d50 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -64,6 +64,7 @@
#define MMC_WRITE_MULTIPLE_BLOCK 25 /* adtc R1 */
#define MMC_PROGRAM_CID 26 /* adtc R1 */
#define MMC_PROGRAM_CSD 27 /* adtc R1 */
+#define MMC_SET_TIME 49 /* adtc R1 */
/* class 6 */
#define MMC_SET_WRITE_PROT 28 /* ac [31:0] data addr R1b */
--
2.17.1
Powered by blists - more mailing lists