1 From 4bdb576667a976996f870d36c5bb841b9d0c1258 Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Tue, 26 Mar 2024 13:25:01 +0000
4 Subject: [PATCH 0994/1085] drivers: mmc: export SD extension register
7 Certain status bits in these registers may need polling outside of
8 SD-specific code. Export in sd_ops.h
10 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
12 drivers/mmc/core/sd.c | 97 ++++-----------------------------------
13 drivers/mmc/core/sd_ops.c | 83 +++++++++++++++++++++++++++++++--
14 drivers/mmc/core/sd_ops.h | 4 ++
15 3 files changed, 93 insertions(+), 91 deletions(-)
17 --- a/drivers/mmc/core/sd.c
18 +++ b/drivers/mmc/core/sd.c
19 @@ -1015,83 +1015,6 @@ static bool mmc_sd_card_using_v18(struct
20 (SD_MODE_UHS_SDR50 | SD_MODE_UHS_SDR104 | SD_MODE_UHS_DDR50);
23 -int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset,
26 - struct mmc_host *host = card->host;
27 - struct mmc_request mrq = {};
28 - struct mmc_command cmd = {};
29 - struct mmc_data data = {};
30 - struct scatterlist sg;
33 - reg_buf = card->ext_reg_buf;
34 - memset(reg_buf, 0, 512);
40 - * Arguments of CMD49:
41 - * [31:31] MIO (0 = memory).
42 - * [30:27] FNO (function number).
43 - * [26:26] MW - mask write mode (0 = disable).
44 - * [25:18] page number.
45 - * [17:9] offset address.
46 - * [8:0] length (0 = 1 byte).
48 - cmd.arg = fno << 27 | page << 18 | offset << 9;
50 - /* The first byte in the buffer is the data to be written. */
51 - reg_buf[0] = reg_data;
53 - data.flags = MMC_DATA_WRITE;
58 - sg_init_one(&sg, reg_buf, 512);
60 - cmd.opcode = SD_WRITE_EXTR_SINGLE;
61 - cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
63 - mmc_set_data_timeout(&data, card);
64 - mmc_wait_for_req(host, &mrq);
67 - * Note that, the SD card is allowed to signal busy on DAT0 up to 1s
68 - * after the CMD49. Although, let's leave this to be managed by the
80 -static int sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page,
81 - u16 offset, u16 len, u8 *reg_buf)
86 - * Command arguments of CMD48:
87 - * [31:31] MIO (0 = memory).
88 - * [30:27] FNO (function number).
89 - * [26:26] reserved (0).
90 - * [25:18] page number.
91 - * [17:9] offset address.
92 - * [8:0] length (0 = 1 byte, 1ff = 512 bytes).
94 - cmd_args = fno << 27 | page << 18 | offset << 9 | (len -1);
96 - return mmc_send_adtc_data(card, card->host, SD_READ_EXTR_SINGLE,
97 - cmd_args, reg_buf, 512);
100 static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page,
103 @@ -1101,7 +1024,7 @@ static int sd_parse_ext_reg_power(struct
104 reg_buf = card->ext_reg_buf;
106 /* Read the extension register for power management function. */
107 - err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
108 + err = mmc_sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
110 pr_warn("%s: error %d reading PM func of ext reg\n",
111 mmc_hostname(card->host), err);
112 @@ -1139,7 +1062,7 @@ static int sd_parse_ext_reg_perf(struct
114 reg_buf = card->ext_reg_buf;
116 - err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
117 + err = mmc_sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
119 pr_warn("%s: error %d reading PERF func of ext reg\n",
120 mmc_hostname(card->host), err);
121 @@ -1234,7 +1157,7 @@ static int sd_parse_ext_reg(struct mmc_c
125 -static int sd_read_ext_regs(struct mmc_card *card)
126 +static int mmc_sd_read_ext_regs(struct mmc_card *card)
129 u8 num_ext, *gen_info_buf;
130 @@ -1260,7 +1183,7 @@ static int sd_read_ext_regs(struct mmc_c
131 * Read 512 bytes of general info, which is found at function number 0,
132 * at page 0 and with no offset.
134 - err = sd_read_ext_reg(card, 0, 0, 0, 512, gen_info_buf);
135 + err = mmc_sd_read_ext_reg(card, 0, 0, 0, 512, gen_info_buf);
137 pr_err("%s: error %d reading general info of SD ext reg\n",
138 mmc_hostname(card->host), err);
139 @@ -1332,7 +1255,7 @@ static int sd_flush_cache(struct mmc_hos
140 page = card->ext_perf.page;
141 offset = card->ext_perf.offset + 261;
143 - err = sd_write_ext_reg(card, fno, page, offset, BIT(0));
144 + err = mmc_sd_write_ext_reg(card, fno, page, offset, BIT(0));
146 pr_warn("%s: error %d writing Cache Flush bit\n",
147 mmc_hostname(host), err);
148 @@ -1348,7 +1271,7 @@ static int sd_flush_cache(struct mmc_hos
149 * Read the Flush Cache bit. The card shall reset it, to confirm that
150 * it's has completed the flushing of the cache.
152 - err = sd_read_ext_reg(card, fno, page, offset, 1, reg_buf);
153 + err = mmc_sd_read_ext_reg(card, fno, page, offset, 1, reg_buf);
155 pr_warn("%s: error %d reading Cache Flush bit\n",
156 mmc_hostname(host), err);
157 @@ -1371,7 +1294,7 @@ static int sd_enable_cache(struct mmc_ca
158 * Set Cache Enable at bit 0 in the performance enhancement register at
161 - err = sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page,
162 + err = mmc_sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page,
163 card->ext_perf.offset + 260, BIT(0));
165 pr_warn("%s: error %d writing Cache Enable bit\n",
166 @@ -1541,7 +1464,7 @@ retry:
169 /* Read/parse the extension registers. */
170 - err = sd_read_ext_regs(card);
171 + err = mmc_sd_read_ext_regs(card);
175 @@ -1668,7 +1591,7 @@ static int sd_busy_poweroff_notify_cb(vo
176 * one byte offset and is one byte long. The Power Off Notification
179 - err = sd_read_ext_reg(card, card->ext_power.fno, card->ext_power.page,
180 + err = mmc_sd_read_ext_reg(card, card->ext_power.fno, card->ext_power.page,
181 card->ext_power.offset + 1, 1, data->reg_buf);
183 pr_warn("%s: error %d reading status reg of PM func\n",
184 @@ -1694,7 +1617,7 @@ static int sd_poweroff_notify(struct mmc
185 * Set the Power Off Notification bit in the power management settings
186 * register at 2 bytes offset.
188 - err = sd_write_ext_reg(card, card->ext_power.fno, card->ext_power.page,
189 + err = mmc_sd_write_ext_reg(card, card->ext_power.fno, card->ext_power.page,
190 card->ext_power.offset + 2, BIT(0));
192 pr_warn("%s: error %d writing Power Off Notify bit\n",
193 --- a/drivers/mmc/core/sd_ops.c
194 +++ b/drivers/mmc/core/sd_ops.c
195 @@ -366,8 +366,83 @@ int mmc_app_sd_status(struct mmc_card *c
199 -int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset,
202 +int mmc_sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset,
205 + struct mmc_host *host = card->host;
206 + struct mmc_request mrq = {};
207 + struct mmc_command cmd = {};
208 + struct mmc_data data = {};
209 + struct scatterlist sg;
212 + reg_buf = card->ext_reg_buf;
213 + memset(reg_buf, 0, 512);
219 + * Arguments of CMD49:
220 + * [31:31] MIO (0 = memory).
221 + * [30:27] FNO (function number).
222 + * [26:26] MW - mask write mode (0 = disable).
223 + * [25:18] page number.
224 + * [17:9] offset address.
225 + * [8:0] length (0 = 1 byte).
227 + cmd.arg = fno << 27 | page << 18 | offset << 9;
229 + /* The first byte in the buffer is the data to be written. */
230 + reg_buf[0] = reg_data;
232 + data.flags = MMC_DATA_WRITE;
237 + sg_init_one(&sg, reg_buf, 512);
239 + cmd.opcode = SD_WRITE_EXTR_SINGLE;
240 + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
242 + mmc_set_data_timeout(&data, card);
243 + mmc_wait_for_req(host, &mrq);
246 + * Note that, the SD card is allowed to signal busy on DAT0 up to 1s
247 + * after the CMD49. Although, let's leave this to be managed by the
259 +int mmc_sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page,
260 + u16 offset, u16 len, u8 *reg_buf)
265 + * Command arguments of CMD48:
266 + * [31:31] MIO (0 = memory).
267 + * [30:27] FNO (function number).
268 + * [26:26] reserved (0).
269 + * [25:18] page number.
270 + * [17:9] offset address.
271 + * [8:0] length (0 = 1 byte, 1ff = 512 bytes).
273 + cmd_args = fno << 27 | page << 18 | offset << 9 | (len - 1);
275 + return mmc_send_adtc_data(card, card->host, SD_READ_EXTR_SINGLE,
276 + cmd_args, reg_buf, 512);
279 static int mmc_sd_cmdq_switch(struct mmc_card *card, bool enable)
281 @@ -383,8 +458,8 @@ static int mmc_sd_cmdq_switch(struct mmc
284 /* Performance enhancement register byte 262 controls command queueing */
285 - err = sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page,
286 - card->ext_perf.offset + 262, reg);
287 + err = mmc_sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page,
288 + card->ext_perf.offset + 262, reg);
290 card->ext_csd.cmdq_en = enable;
292 --- a/drivers/mmc/core/sd_ops.h
293 +++ b/drivers/mmc/core/sd_ops.h
294 @@ -23,6 +23,10 @@ int mmc_app_sd_status(struct mmc_card *c
295 int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card);
296 int mmc_sd_cmdq_enable(struct mmc_card *card);
297 int mmc_sd_cmdq_disable(struct mmc_card *card);
298 +int mmc_sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset,
300 +int mmc_sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page,
301 + u16 offset, u16 len, u8 *reg_buf);