Deleted Added
full compact
mmcreg.h (312399) mmcreg.h (318197)
1/*-
2 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
1/*-
2 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
3 * Copyright (c) 2017 Marius Strobl <marius@FreeBSD.org>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 32 unchanged lines hidden (view full) ---

43 * right of the SD Group, SD-3C LLC, the SD Card Association or any third
44 * parties, which may result from its use. No license is granted by
45 * implication, estoppel or otherwise under any patent or other rights of the
46 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
47 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
48 * or the SD Card Association to disclose or distribute any technical
49 * information, know-how or other confidential information to any third party.
50 *
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the

--- 32 unchanged lines hidden (view full) ---

44 * right of the SD Group, SD-3C LLC, the SD Card Association or any third
45 * parties, which may result from its use. No license is granted by
46 * implication, estoppel or otherwise under any patent or other rights of the
47 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
48 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
49 * or the SD Card Association to disclose or distribute any technical
50 * information, know-how or other confidential information to any third party.
51 *
51 * $FreeBSD: stable/11/sys/dev/mmc/mmcreg.h 312399 2017-01-18 23:25:46Z marius $
52 * $FreeBSD: stable/11/sys/dev/mmc/mmcreg.h 318197 2017-05-11 20:55:11Z marius $
52 */
53
54#ifndef DEV_MMC_MMCREG_H
55#define DEV_MMC_MMCREG_H
56
57/*
58 * This file contains the register definitions for the mmc and sd busses.
59 * They are taken from publicly available sources.

--- 35 unchanged lines hidden (view full) ---

95 uint32_t error;
96#define MMC_ERR_NONE 0
97#define MMC_ERR_TIMEOUT 1
98#define MMC_ERR_BADCRC 2
99#define MMC_ERR_FIFO 3
100#define MMC_ERR_FAILED 4
101#define MMC_ERR_INVALID 5
102#define MMC_ERR_NO_MEMORY 6
53 */
54
55#ifndef DEV_MMC_MMCREG_H
56#define DEV_MMC_MMCREG_H
57
58/*
59 * This file contains the register definitions for the mmc and sd busses.
60 * They are taken from publicly available sources.

--- 35 unchanged lines hidden (view full) ---

96 uint32_t error;
97#define MMC_ERR_NONE 0
98#define MMC_ERR_TIMEOUT 1
99#define MMC_ERR_BADCRC 2
100#define MMC_ERR_FIFO 3
101#define MMC_ERR_FAILED 4
102#define MMC_ERR_INVALID 5
103#define MMC_ERR_NO_MEMORY 6
103#define MMC_ERR_MAX 6
104#define MMC_ERR_MAX 6
104 struct mmc_data *data; /* Data segment with cmd */
105 struct mmc_request *mrq; /* backpointer to request */
106};
107
108/*
109 * R1 responses
110 *
111 * Types (per SD 2.0 standard)

--- 23 unchanged lines hidden (view full) ---

135#define R1_CC_ERROR (1u << 20) /* erx, c */
136#define R1_ERROR (1u << 19) /* erx, c */
137#define R1_CSD_OVERWRITE (1u << 16) /* erx, c */
138#define R1_WP_ERASE_SKIP (1u << 15) /* erx, c */
139#define R1_CARD_ECC_DISABLED (1u << 14) /* sx, a */
140#define R1_ERASE_RESET (1u << 13) /* sr, c */
141#define R1_CURRENT_STATE_MASK (0xfu << 9) /* sx, b */
142#define R1_READY_FOR_DATA (1u << 8) /* sx, a */
105 struct mmc_data *data; /* Data segment with cmd */
106 struct mmc_request *mrq; /* backpointer to request */
107};
108
109/*
110 * R1 responses
111 *
112 * Types (per SD 2.0 standard)

--- 23 unchanged lines hidden (view full) ---

136#define R1_CC_ERROR (1u << 20) /* erx, c */
137#define R1_ERROR (1u << 19) /* erx, c */
138#define R1_CSD_OVERWRITE (1u << 16) /* erx, c */
139#define R1_WP_ERASE_SKIP (1u << 15) /* erx, c */
140#define R1_CARD_ECC_DISABLED (1u << 14) /* sx, a */
141#define R1_ERASE_RESET (1u << 13) /* sr, c */
142#define R1_CURRENT_STATE_MASK (0xfu << 9) /* sx, b */
143#define R1_READY_FOR_DATA (1u << 8) /* sx, a */
144#define R1_SWITCH_ERROR (1u << 7) /* sx, c */
143#define R1_APP_CMD (1u << 5) /* sr, c */
144#define R1_AKE_SEQ_ERROR (1u << 3) /* er, c */
145#define R1_STATUS(x) ((x) & 0xFFFFE000)
146#define R1_CURRENT_STATE(x) (((x) & R1_CURRENT_STATE_MASK) >> 9)
147#define R1_STATE_IDLE 0
148#define R1_STATE_READY 1
149#define R1_STATE_IDENT 2
150#define R1_STATE_STBY 3

--- 28 unchanged lines hidden (view full) ---

179
180/* Class 0 and 1: Basic commands & read stream commands */
181#define MMC_GO_IDLE_STATE 0
182#define MMC_SEND_OP_COND 1
183#define MMC_ALL_SEND_CID 2
184#define MMC_SET_RELATIVE_ADDR 3
185#define SD_SEND_RELATIVE_ADDR 3
186#define MMC_SET_DSR 4
145#define R1_APP_CMD (1u << 5) /* sr, c */
146#define R1_AKE_SEQ_ERROR (1u << 3) /* er, c */
147#define R1_STATUS(x) ((x) & 0xFFFFE000)
148#define R1_CURRENT_STATE(x) (((x) & R1_CURRENT_STATE_MASK) >> 9)
149#define R1_STATE_IDLE 0
150#define R1_STATE_READY 1
151#define R1_STATE_IDENT 2
152#define R1_STATE_STBY 3

--- 28 unchanged lines hidden (view full) ---

181
182/* Class 0 and 1: Basic commands & read stream commands */
183#define MMC_GO_IDLE_STATE 0
184#define MMC_SEND_OP_COND 1
185#define MMC_ALL_SEND_CID 2
186#define MMC_SET_RELATIVE_ADDR 3
187#define SD_SEND_RELATIVE_ADDR 3
188#define MMC_SET_DSR 4
187 /* reserved: 5 */
189#define MMC_SLEEP_AWAKE 5
188#define MMC_SWITCH_FUNC 6
189#define MMC_SWITCH_FUNC_CMDS 0
190#define MMC_SWITCH_FUNC_SET 1
191#define MMC_SWITCH_FUNC_CLR 2
192#define MMC_SWITCH_FUNC_WR 3
193#define MMC_SELECT_CARD 7
194#define MMC_DESELECT_CARD 7
195#define MMC_SEND_EXT_CSD 8

--- 77 unchanged lines hidden (view full) ---

273#define SD_SWITCH_FUNC 6
274 /* reserved: 34 */
275 /* reserved: 35 */
276 /* reserved: 36 */
277 /* reserved: 37 */
278 /* reserved: 50 */
279 /* reserved: 57 */
280
190#define MMC_SWITCH_FUNC 6
191#define MMC_SWITCH_FUNC_CMDS 0
192#define MMC_SWITCH_FUNC_SET 1
193#define MMC_SWITCH_FUNC_CLR 2
194#define MMC_SWITCH_FUNC_WR 3
195#define MMC_SELECT_CARD 7
196#define MMC_DESELECT_CARD 7
197#define MMC_SEND_EXT_CSD 8

--- 77 unchanged lines hidden (view full) ---

275#define SD_SWITCH_FUNC 6
276 /* reserved: 34 */
277 /* reserved: 35 */
278 /* reserved: 36 */
279 /* reserved: 37 */
280 /* reserved: 50 */
281 /* reserved: 57 */
282
281
282/* Application specific commands for SD */
283#define ACMD_SET_BUS_WIDTH 6
284#define ACMD_SD_STATUS 13
285#define ACMD_SEND_NUM_WR_BLOCKS 22
286#define ACMD_SET_WR_BLK_ERASE_COUNT 23
287#define ACMD_SD_SEND_OP_COND 41
288#define ACMD_SET_CLR_CARD_DETECT 42
289#define ACMD_SEND_SCR 51
290
291/*
292 * EXT_CSD fields
293 */
283/* Application specific commands for SD */
284#define ACMD_SET_BUS_WIDTH 6
285#define ACMD_SD_STATUS 13
286#define ACMD_SEND_NUM_WR_BLOCKS 22
287#define ACMD_SET_WR_BLK_ERASE_COUNT 23
288#define ACMD_SD_SEND_OP_COND 41
289#define ACMD_SET_CLR_CARD_DETECT 42
290#define ACMD_SEND_SCR 51
291
292/*
293 * EXT_CSD fields
294 */
294#define EXT_CSD_ERASE_GRP_DEF 175 /* R/W */
295#define EXT_CSD_BUS_WIDTH 183 /* R/W */
296#define EXT_CSD_HS_TIMING 185 /* R/W */
297#define EXT_CSD_CARD_TYPE 196 /* RO */
298#define EXT_CSD_REV 192 /* RO */
299#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
300#define EXT_CSD_ERASE_TO_MULT 223 /* RO */
301#define EXT_CSD_ERASE_GRP_SIZE 224 /* RO */
295#define EXT_CSD_EXT_PART_ATTR 52 /* R/W, 2 bytes */
296#define EXT_CSD_ENH_START_ADDR 136 /* R/W, 4 bytes */
297#define EXT_CSD_ENH_SIZE_MULT 140 /* R/W, 3 bytes */
298#define EXT_CSD_GP_SIZE_MULT 143 /* R/W, 12 bytes */
299#define EXT_CSD_PART_SET 155 /* R/W */
300#define EXT_CSD_PART_ATTR 156 /* R/W */
301#define EXT_CSD_PART_SUPPORT 160 /* RO */
302#define EXT_CSD_RPMB_MULT 168 /* RO */
303#define EXT_CSD_BOOT_WP_STATUS 174 /* RO */
304#define EXT_CSD_ERASE_GRP_DEF 175 /* R/W */
305#define EXT_CSD_PART_CONFIG 179 /* R/W */
306#define EXT_CSD_BUS_WIDTH 183 /* R/W */
307#define EXT_CSD_HS_TIMING 185 /* R/W */
308#define EXT_CSD_CARD_TYPE 196 /* RO */
309#define EXT_CSD_REV 192 /* RO */
310#define EXT_CSD_PART_SWITCH_TO 199 /* RO */
311#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
312#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
313#define EXT_CSD_ERASE_TO_MULT 223 /* RO */
314#define EXT_CSD_ERASE_GRP_SIZE 224 /* RO */
315#define EXT_CSD_BOOT_SIZE_MULT 226 /* RO */
316#define EXT_CSD_GEN_CMD6_TIME 248 /* RO */
302
303/*
304 * EXT_CSD field definitions
305 */
317
318/*
319 * EXT_CSD field definitions
320 */
306#define EXT_CSD_CMD_SET_NORMAL 1
307#define EXT_CSD_CMD_SET_SECURE 2
308#define EXT_CSD_CMD_SET_CPSECURE 4
321#define EXT_CSD_EXT_PART_ATTR_DEFAULT 0x0
322#define EXT_CSD_EXT_PART_ATTR_SYSTEMCODE 0x1
323#define EXT_CSD_EXT_PART_ATTR_NPERSISTENT 0x2
309
324
310#define EXT_CSD_CARD_TYPE_26 1
311#define EXT_CSD_CARD_TYPE_52 2
325#define EXT_CSD_PART_SET_COMPLETED 0x01
312
326
313#define EXT_CSD_BUS_WIDTH_1 0
314#define EXT_CSD_BUS_WIDTH_4 1
315#define EXT_CSD_BUS_WIDTH_8 2
327#define EXT_CSD_PART_ATTR_ENH_USR 0x01
328#define EXT_CSD_PART_ATTR_ENH_GP0 0x02
329#define EXT_CSD_PART_ATTR_ENH_GP1 0x04
330#define EXT_CSD_PART_ATTR_ENH_GP2 0x08
331#define EXT_CSD_PART_ATTR_ENH_GP3 0x10
332#define EXT_CSD_PART_ATTR_ENH_MASK 0x1f
316
333
317#define MMC_TYPE_26_MAX_HS 26000000
318#define MMC_TYPE_52_MAX_HS 52000000
334#define EXT_CSD_PART_SUPPORT_EN 0x01
335#define EXT_CSD_PART_SUPPORT_ENH_ATTR_EN 0x02
336#define EXT_CSD_PART_SUPPORT_EXT_ATTR_EN 0x04
319
337
338#define EXT_CSD_BOOT_WP_STATUS_BOOT0_PWR 0x01
339#define EXT_CSD_BOOT_WP_STATUS_BOOT0_PERM 0x02
340#define EXT_CSD_BOOT_WP_STATUS_BOOT0_MASK 0x03
341#define EXT_CSD_BOOT_WP_STATUS_BOOT1_PWR 0x04
342#define EXT_CSD_BOOT_WP_STATUS_BOOT1_PERM 0x08
343#define EXT_CSD_BOOT_WP_STATUS_BOOT1_MASK 0x0c
344
345#define EXT_CSD_ERASE_GRP_DEF_EN 0x01
346
347#define EXT_CSD_PART_CONFIG_ACC_DEFAULT 0x00
348#define EXT_CSD_PART_CONFIG_ACC_BOOT0 0x01
349#define EXT_CSD_PART_CONFIG_ACC_BOOT1 0x02
350#define EXT_CSD_PART_CONFIG_ACC_RPMB 0x03
351#define EXT_CSD_PART_CONFIG_ACC_GP0 0x04
352#define EXT_CSD_PART_CONFIG_ACC_GP1 0x05
353#define EXT_CSD_PART_CONFIG_ACC_GP2 0x06
354#define EXT_CSD_PART_CONFIG_ACC_GP3 0x07
355#define EXT_CSD_PART_CONFIG_ACC_MASK 0x07
356#define EXT_CSD_PART_CONFIG_BOOT0 0x08
357#define EXT_CSD_PART_CONFIG_BOOT1 0x10
358#define EXT_CSD_PART_CONFIG_BOOT_USR 0x38
359#define EXT_CSD_PART_CONFIG_BOOT_MASK 0x38
360#define EXT_CSD_PART_CONFIG_BOOT_ACK 0x40
361
362#define EXT_CSD_CMD_SET_NORMAL 1
363#define EXT_CSD_CMD_SET_SECURE 2
364#define EXT_CSD_CMD_SET_CPSECURE 4
365
366#define EXT_CSD_CARD_TYPE_26 1
367#define EXT_CSD_CARD_TYPE_52 2
368
369#define EXT_CSD_BUS_WIDTH_1 0
370#define EXT_CSD_BUS_WIDTH_4 1
371#define EXT_CSD_BUS_WIDTH_8 2
372
373#define MMC_TYPE_26_MAX_HS 26000000
374#define MMC_TYPE_52_MAX_HS 52000000
375
320/*
321 * SD bus widths
322 */
376/*
377 * SD bus widths
378 */
323#define SD_BUS_WIDTH_1 0
324#define SD_BUS_WIDTH_4 2
379#define SD_BUS_WIDTH_1 0
380#define SD_BUS_WIDTH_4 2
325
326/*
327 * SD Switch
328 */
381
382/*
383 * SD Switch
384 */
329#define SD_SWITCH_MODE_CHECK 0
330#define SD_SWITCH_MODE_SET 1
331#define SD_SWITCH_GROUP1 0
332#define SD_SWITCH_NORMAL_MODE 0
333#define SD_SWITCH_HS_MODE 1
334#define SD_SWITCH_NOCHANGE 0xF
385#define SD_SWITCH_MODE_CHECK 0
386#define SD_SWITCH_MODE_SET 1
387#define SD_SWITCH_GROUP1 0
388#define SD_SWITCH_NORMAL_MODE 0
389#define SD_SWITCH_HS_MODE 1
390#define SD_SWITCH_NOCHANGE 0xF
335
336#define SD_CLR_CARD_DETECT 0
337#define SD_SET_CARD_DETECT 1
338
339#define SD_MAX_HS 50000000
340
341/* OCR bits */
342

--- 71 unchanged lines hidden (view full) ---

414 erase_blk_en:1,
415 wp_grp_enable:1;
416};
417
418struct mmc_scr
419{
420 unsigned char sda_vsn;
421 unsigned char bus_widths;
391
392#define SD_CLR_CARD_DETECT 0
393#define SD_SET_CARD_DETECT 1
394
395#define SD_MAX_HS 50000000
396
397/* OCR bits */
398

--- 71 unchanged lines hidden (view full) ---

470 erase_blk_en:1,
471 wp_grp_enable:1;
472};
473
474struct mmc_scr
475{
476 unsigned char sda_vsn;
477 unsigned char bus_widths;
422#define SD_SCR_BUS_WIDTH_1 (1<<0)
423#define SD_SCR_BUS_WIDTH_4 (1<<2)
478#define SD_SCR_BUS_WIDTH_1 (1 << 0)
479#define SD_SCR_BUS_WIDTH_4 (1 << 2)
424};
425
426struct mmc_sd_status
427{
428 uint8_t bus_width;
429 uint8_t secured_mode;
430 uint16_t card_type;
431 uint16_t prot_area;
432 uint8_t speed_class;
433 uint8_t perf_move;
434 uint8_t au_size;
435 uint16_t erase_size;
436 uint8_t erase_timeout;
437 uint8_t erase_offset;
438};
439
440/*
480};
481
482struct mmc_sd_status
483{
484 uint8_t bus_width;
485 uint8_t secured_mode;
486 uint16_t card_type;
487 uint16_t prot_area;
488 uint8_t speed_class;
489 uint8_t perf_move;
490 uint8_t au_size;
491 uint16_t erase_size;
492 uint8_t erase_timeout;
493 uint8_t erase_offset;
494};
495
496/*
497 * Various MMC/SD constants
498 */
499#define MMC_BOOT_RPMB_BLOCK_SIZE (128 * 1024)
500
501#define MMC_EXTCSD_SIZE 512
502
503#define MMC_PART_GP_MAX 4
504#define MMC_PART_MAX 8
505
506/*
441 * Older versions of the MMC standard had a variable sector size. However,
442 * I've been able to find no old MMC or SD cards that have a non 512
443 * byte sector size anywhere, so we assume that such cards are very rare
444 * and only note their existence in passing here...
445 */
507 * Older versions of the MMC standard had a variable sector size. However,
508 * I've been able to find no old MMC or SD cards that have a non 512
509 * byte sector size anywhere, so we assume that such cards are very rare
510 * and only note their existence in passing here...
511 */
446#define MMC_SECTOR_SIZE 512
512#define MMC_SECTOR_SIZE 512
447
448#endif /* DEV_MMCREG_H */
513
514#endif /* DEV_MMCREG_H */