The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/mmc/mmcreg.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2006 M. Warner Losh.  All rights reserved.
    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
   11  *    documentation and/or other materials provided with the distribution.
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   23  *
   24  * $FreeBSD: releng/6.4/sys/dev/mmc/mmcreg.h 164433 2006-11-20 07:16:28Z imp $
   25  */
   26 
   27 #ifndef DEV_MMC_MMCREG_H
   28 #define DEV_MMC_MMCREG_H
   29 
   30 /*
   31  * This file contains the register definitions for the mmc and sd busses.
   32  * They are taken from publicly available sources.
   33  */
   34 
   35 struct mmc_data;
   36 struct mmc_request;
   37 
   38 struct mmc_command {
   39         uint32_t        opcode;
   40         uint32_t        arg;
   41         uint32_t        resp[4];
   42         uint32_t        flags;          /* Expected responses */
   43 #define MMC_RSP_PRESENT (1ul << 0)      /* Response */
   44 #define MMC_RSP_136     (1ul << 1)      /* 136 bit response */
   45 #define MMC_RSP_CRC     (1ul << 2)      /* Expect valid crc */
   46 #define MMC_RSP_BUSY    (1ul << 3)      /* Card may send busy */
   47 #define MMC_RSP_OPCODE  (1ul << 4)      /* Response include opcode */
   48 #define MMC_RSP_MASK    0x1ful
   49 #define MMC_CMD_AC      (0ul << 5)      /* Addressed Command, no data */
   50 #define MMC_CMD_ADTC    (1ul << 5)      /* Addressed Data transfer cmd */
   51 #define MMC_CMD_BC      (2ul << 5)      /* Broadcast command, no response */
   52 #define MMC_CMD_BCR     (3ul << 5)      /* Broadcast command with response */
   53 #define MMC_CMD_MASK    (3ul << 5)
   54 
   55 /* Possible response types defined in the standard: */
   56 #define MMC_RSP_NONE    (0)
   57 #define MMC_RSP_R1      (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
   58 #define MMC_RSP_R1B     (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE | MMC_RSP_BUSY)
   59 #define MMC_RSP_R2      (MMC_RSP_PRESENT | MMC_RSP_136 | MMC_RSP_CRC)
   60 #define MMC_RSP_R3      (MMC_RSP_PRESENT)
   61 #define MMC_RSP_R6      (MMC_RSP_PRESENT | MMC_RSP_CRC)
   62 /* R7 -- new in sd 2.0 */
   63 #define MMC_RSP(x)      ((x) & MMC_RSP_MASK)
   64         uint32_t        retries;
   65         uint32_t        error;
   66 #define MMC_ERR_NONE    0
   67 #define MMC_ERR_TIMEOUT 1
   68 #define MMC_ERR_BADCRC  2
   69 #define MMC_ERR_FIFO    3
   70 #define MMC_ERR_FAILED  4
   71 #define MMC_ERR_INVALID 5
   72 #define MMC_ERR_NO_MEMORY 6
   73         struct mmc_data *data;          /* Data segment with cmd */
   74         struct mmc_request *mrq;        /* backpointer to request */
   75 };
   76 
   77 /*
   78  * R1 responses
   79  *
   80  * Types (per SD 2.0 standard)
   81  *      e : error bit
   82  *      s : status bit
   83  *      r : detected and set for the actual command response
   84  *      x : Detected and set during command execution.  The host can get
   85  *          the status by issuing a command with R1 response.
   86  *
   87  * Clear Condition (per SD 2.0 standard)
   88  *      a : according to the card current state.
   89  *      b : always related to the previous command.  reception of a valid
   90  *          command will clear it (with a delay of one command).
   91  *      c : clear by read
   92  */
   93 #define R1_OUT_OF_RANGE (1u << 31)              /* erx, c */
   94 #define R1_ADDRESS_ERROR (1u << 30)             /* erx, c */
   95 #define R1_BLOCK_LEN_ERROR (1u << 29)           /* erx, c */
   96 #define R1_ERASE_SEQ_ERROR (1u << 28)           /* er, c */
   97 #define R1_ERASE_PARAM (1u << 27)               /* erx, c */
   98 #define R1_WP_VIOLATION (1u << 26)              /* erx, c */
   99 #define R1_CARD_IS_LOCKED (1u << 25)            /* sx, a */
  100 #define R1_LOCK_UNLOCK_FAILED (1u << 24)        /* erx, c */
  101 #define R1_COM_CRC_ERROR (1u << 23)             /* er, b */
  102 #define R1_ILLEGAL_COMMAND (1u << 22)           /* er, b */
  103 #define R1_CARD_ECC_FAILED (1u << 21)           /* erx, c */
  104 #define R1_CC_ERROR (1u << 20)                  /* erx, c */
  105 #define R1_ERROR (1u << 19)                     /* erx, c */
  106 #define R1_CSD_OVERWRITE (1u << 16)             /* erx, c */
  107 #define R1_WP_ERASE_SKIP (1u << 15)             /* erx, c */
  108 #define R1_CARD_ECC_DISABLED (1u << 14)         /* sx, a */
  109 #define R1_ERASE_RESET (1u << 13)               /* sr, c */
  110 #define R1_CURRENT_STATE_MASK (0xfu << 9)       /* sx, b */
  111 #define R1_READY_FOR_DATA (1u << 8)             /* sx, a */
  112 #define R1_APP_CMD (1u << 5)                    /* sr, c */
  113 #define R1_AKE_SEQ_ERROR (1u << 3)              /* er, c */
  114 #define R1_STATUS(x)            (x & 0xFFFFE000
  115 #define R1_CURRENT_STATE(x) ((x) & R1_CURRENT_STATE_MASK) >> 9
  116 #define R1_STATE_IDLE   0
  117 #define R1_STATE_READY  1
  118 #define R1_STATE_IDENT  2
  119 #define R1_STATE_STBY   3
  120 #define R1_STATE_TRAN   4
  121 #define R1_STATE_DATA   5
  122 #define R1_STATE_RCV    6
  123 #define R1_STATE_PRG    7
  124 #define R1_STATE_DIS    8
  125 
  126 struct mmc_data {
  127         size_t len;             /* size of the data */
  128         size_t xfer_len;
  129         void *data;             /* data buffer */
  130         uint32_t        flags;
  131 #define MMC_DATA_WRITE  (1UL << 0)
  132 #define MMC_DATA_READ   (1UL << 1)
  133 #define MMC_DATA_STREAM (1UL << 2)
  134 #define MMC_DATA_MULTI  (1UL << 3)
  135         struct mmc_request *mrq;
  136 };
  137 
  138 struct mmc_request {
  139         struct mmc_command *cmd;
  140         struct mmc_command *stop;
  141         void (*done)(struct mmc_request *); /* Completion function */
  142         void *done_data;                /* requestor set data */
  143         uint32_t flags;
  144 #define MMC_REQ_DONE    1
  145 };
  146 
  147 /* Command definitions */
  148 
  149 /* Class 0 and 1: Basic commands & read stream commands */
  150 #define MMC_GO_IDLE_STATE       0
  151 #define MMC_SEND_OP_COND        1
  152 #define MMC_ALL_SEND_CID        2
  153 #define MMC_SET_RELATIVE_ADDR   3
  154 #define SD_SEND_RELATIVE_ADDR   3
  155 #define MMC_SET_DSR             4
  156                         /* reserved: 5 */
  157 #define MMC_SELECT_CARD         7
  158 #define MMC_DESELECT_CARD       7
  159 #define MMC_SEND_IF_COND        8
  160 #define MMC_SEND_CSD            9
  161 #define MMC_SEND_CID            10
  162 #define MMC_READ_DAT_UNTIL_STOP 11
  163 #define MMC_STOP_TRANSMISSION   12
  164 #define MMC_SEND_STATUS         13
  165                         /* reserved: 14 */
  166 #define MMC_GO_INACTIVE_STATE   15
  167 
  168 /* Class 2: Block oriented read commands */
  169 #define MMC_SET_BLOCKLEN        16
  170 #define MMC_READ_SINGLE_BLOCK   17
  171 #define MMC_READ_MULTIPLE_BLOCK 18
  172                         /* reserved: 19 */
  173 
  174 /* Class 3: Stream write commands */
  175 #define MMC_WRITE_DAT_UNTIL_STOP 20
  176                         /* reserved: 21 */
  177                         /* reserved: 22 */
  178 
  179 /* Class 4: Block oriented write commands */
  180 #define MMC_SET_BLOCK_COUNT     23
  181 #define MMC_WRITE_BLOCK         24
  182 #define MMC_WRITE_MULTIPLE_BLOCK 25
  183 #define MMC_PROGARM_CID         26
  184 #define MMC_PROGRAM_CSD         27
  185 
  186 /* Class 6: Block oriented write protection commands */
  187 #define MMC_SET_WRITE_PROT      28
  188 #define MMC_CLR_WRITE_PROT      29
  189 #define MMC_SEND_WRITE_PROT     30
  190                         /* reserved: 31 */
  191 
  192 /* Class 5: Erase commands */
  193 #define SD_ERASE_WR_BLK_START   32
  194 #define SD_ERASE_WR_BLK_END     33
  195                         /* 34 -- reserved old command */
  196 #define MMC_ERASE_GROUP_START   35
  197 #define MMC_ERASE_GROUP_END     36
  198                         /* 37 -- reserved old command */
  199 #define MMC_ERASE               38
  200 
  201 /* Class 9: I/O mode commands */
  202 #define MMC_FAST_IO             39
  203 #define MMC_GO_IRQ_STATE        40
  204                         /* reserved: 41 */
  205 
  206 /* Class 7: Lock card */
  207 #define MMC_LOCK_UNLOCK         42
  208                         /* reserved: 43 */
  209                         /* reserved: 44 */
  210                         /* reserved: 45 */
  211                         /* reserved: 46 */
  212                         /* reserved: 47 */
  213                         /* reserved: 48 */
  214                         /* reserved: 49 */
  215                         /* reserved: 50 */
  216                         /* reserved: 51 */
  217                         /* reserved: 54 */
  218 
  219 /* Class 8: Application specific commands */
  220 #define MMC_APP_CMD             55
  221 #define MMC_GEN_CMD             56
  222                         /* reserved: 57 */
  223                         /* reserved: 58 */
  224                         /* reserved: 59 */
  225                         /* reserved for mfg: 60 */
  226                         /* reserved for mfg: 61 */
  227                         /* reserved for mfg: 62 */
  228                         /* reserved for mfg: 63 */
  229 
  230 /* Class 9: I/O cards (sd) */
  231 #define SD_IO_RW_DIRECT         52
  232 #define SD_IO_RW_EXTENDED       53
  233 
  234 /* Class 10: Switch function commands */
  235 #define SD_SWITCH_FUNC          6
  236                         /* reserved: 34 */
  237                         /* reserved: 35 */
  238                         /* reserved: 36 */
  239                         /* reserved: 37 */
  240                         /* reserved: 50 */
  241                         /* reserved: 57 */
  242 
  243 
  244 /* Application specific commands for SD */
  245 #define ACMD_SET_BUS_WIDTH      6
  246 #define ACMD_SD_STATUS          13
  247 #define ACMD_SEND_NUM_WR_BLOCKS 22
  248 #define ACMD_SET_WR_BLK_ERASE_COUNT 23
  249 #define ACMD_SD_SEND_OP_COND    41
  250 #define ACMD_SET_CLR_CARD_DETECT 42
  251 #define ACMD_SEND_SCR           51
  252 
  253 /* OCR bits */
  254 
  255 /*
  256  * in SD 2.0 spec, bits 8-14 are now marked reserved
  257  * Low voltage in SD2.0 spec is bit 7, TBD voltage
  258  * Low voltage in MC 3.31 spec is bit 7, 1.65-1.95V
  259  * Specs prior to  MMC 3.31 defined bits 0-7 as voltages down to 1.5V.
  260  * 3.31 redefined them to be reserved and also said that cards had to
  261  * support the 2.7-3.6V and fixed the OCR to be 0xfff8000 for high voltage
  262  * cards.  MMC 4.0 says that a dual voltage card responds with 0xfff8080.
  263  * Looks like the fine-grained control of the voltage tolerance ranges
  264  * was abandoned.
  265  *
  266  * The MMC_OCR_CCS appears to be valid for only SD cards.
  267  */
  268 #define MMC_OCR_LOW_VOLTAGE (1u << 7)   /* Low Voltage Range -- tbd */
  269 #define MMC_OCR_200_210 (1U << 8)       /* Vdd voltage 2.00 ~ 2.10 */
  270 #define MMC_OCR_210_220 (1U << 9)       /* Vdd voltage 2.10 ~ 2.20 */
  271 #define MMC_OCR_220_230 (1U << 10)      /* Vdd voltage 2.20 ~ 2.30 */
  272 #define MMC_OCR_230_240 (1U << 11)      /* Vdd voltage 2.30 ~ 2.40 */
  273 #define MMC_OCR_240_250 (1U << 12)      /* Vdd voltage 2.40 ~ 2.50 */
  274 #define MMC_OCR_250_260 (1U << 13)      /* Vdd voltage 2.50 ~ 2.60 */
  275 #define MMC_OCR_260_270 (1U << 14)      /* Vdd voltage 2.60 ~ 2.70 */
  276 #define MMC_OCR_270_280 (1U << 15)      /* Vdd voltage 2.70 ~ 2.80 */
  277 #define MMC_OCR_280_290 (1U << 16)      /* Vdd voltage 2.80 ~ 2.90 */
  278 #define MMC_OCR_290_300 (1U << 17)      /* Vdd voltage 2.90 ~ 3.00 */
  279 #define MMC_OCR_300_310 (1U << 18)      /* Vdd voltage 3.00 ~ 3.10 */
  280 #define MMC_OCR_310_320 (1U << 19)      /* Vdd voltage 3.10 ~ 3.20 */
  281 #define MMC_OCR_320_330 (1U << 20)      /* Vdd voltage 3.20 ~ 3.30 */
  282 #define MMC_OCR_330_340 (1U << 21)      /* Vdd voltage 3.30 ~ 3.40 */
  283 #define MMC_OCR_340_350 (1U << 22)      /* Vdd voltage 3.40 ~ 3.50 */
  284 #define MMC_OCR_350_360 (1U << 23)      /* Vdd voltage 3.50 ~ 3.60 */
  285 #define MMC_OCR_CCS     (1u << 30)      /* Card Capacity status (SD vs SDHC) */
  286 #define MMC_OCR_CARD_BUSY (1U << 31)    /* Card Power up status */
  287 
  288 /* CSD -- decoded structure */
  289 struct mmc_cid {
  290         uint32_t mid;
  291         char pnm[8];
  292         uint32_t psn;
  293         uint16_t oid;
  294         uint16_t mdt_year;
  295         uint8_t mdt_month;
  296         uint8_t prv;
  297         uint8_t fwrev;
  298 };
  299 
  300 struct mmc_csd 
  301 {
  302         uint8_t csd_structure;
  303         uint16_t ccc;
  304         uint16_t tacc;
  305         uint32_t nsac;
  306         uint32_t r2w_factor;
  307         uint32_t tran_speed;
  308         uint32_t read_bl_len;
  309         uint32_t write_bl_len;
  310         uint32_t vdd_r_curr_min;
  311         uint32_t vdd_r_curr_max;
  312         uint32_t vdd_w_curr_min;
  313         uint32_t vdd_w_curr_max;
  314         uint32_t wp_grp_size;
  315         uint32_t sector_size;   /* Erase sector size! */
  316         uint64_t capacity;
  317         unsigned int read_bl_partial:1,
  318             read_blk_misalign:1,
  319             write_bl_partial:1,
  320             write_blk_misalign:1,
  321             dsr_imp:1,
  322             erase_blk_en:1,
  323             wp_grp_enable:1;
  324 };
  325 
  326 #endif /* DEV_MMCREG_H */

Cache object: d95f991b84e213e08ed3b1f161d20580


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.