blob: 3d77b3808b50c49e85ea979e85e1889ef1052d87 [file] [log] [blame]
Johan RUDHOLMa8bfde72012-02-12 11:46:44 -05001/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
15 */
16
17#include <asm-generic/int-ll64.h>
18#include <linux/mmc/ioctl.h>
19#include <linux/major.h>
20#include <stdio.h>
21
22#define CHECK(expr, msg, err_stmt) { if (expr) { fprintf(stderr, msg); err_stmt; } }
23
24/* From kernel linux/mmc/mmc.h */
25#define MMC_SWITCH 6 /* ac [31:0] See below R1b */
26#define MMC_SEND_EXT_CSD 8 /* adtc R1 */
27#define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */
28
29/*
30 * EXT_CSD fields
31 */
Giuseppe CAVALLAROa5bf4a22012-02-20 09:45:29 +010032#define EXT_CSD_S_CMD_SET 504
33#define EXT_CSD_HPI_FEATURE 503
Jaehoon Chung86496512012-09-21 10:08:05 +000034#define EXT_CSD_BKOPS_SUPPORT 502 /* RO */
Giuseppe CAVALLAROa5bf4a22012-02-20 09:45:29 +010035#define EXT_CSD_BOOT_INFO 228 /* R/W */
36#define EXT_CSD_PART_SWITCH_TIME 199
37#define EXT_CSD_BOOT_CFG 179
Giuseppe CAVALLARO7bd13202012-04-19 10:58:37 +020038#define EXT_CSD_PART_CONFIG 179
Saugata Dasb7e25992012-05-17 09:26:34 -040039#define EXT_CSD_BOOT_WP 173
40#define EXT_CSD_WR_REL_PARAM 166
Jaehoon Chung86496512012-09-21 10:08:05 +000041#define EXT_CSD_BKOPS_EN 163 /* R/W */
Saugata Dasb7e25992012-05-17 09:26:34 -040042#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */
43#define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */
44#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */
45
46/*
47 * WR_REL_PARAM field definitions
48 */
49#define HS_CTRL_REL (1<<0)
50#define EN_REL_WR (1<<2)
Johan RUDHOLMa8bfde72012-02-12 11:46:44 -050051
52/*
Jaehoon Chung86496512012-09-21 10:08:05 +000053 * BKOPS_EN field definition
54 */
55#define BKOPS_ENABLE (1<<0)
56
57/*
Johan RUDHOLMa8bfde72012-02-12 11:46:44 -050058 * EXT_CSD field definitions
59 */
Giuseppe CAVALLAROa5bf4a22012-02-20 09:45:29 +010060#define EXT_CSD_HPI_SUPP (1<<0)
61#define EXT_CSD_HPI_IMPL (1<<1)
Johan RUDHOLMa8bfde72012-02-12 11:46:44 -050062#define EXT_CSD_CMD_SET_NORMAL (1<<0)
63#define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40)
64#define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10)
65#define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04)
66#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01)
Giuseppe CAVALLAROa5bf4a22012-02-20 09:45:29 +010067#define EXT_CSD_BOOT_INFO_HS_MODE (1<<2)
68#define EXT_CSD_BOOT_INFO_DDR_DDR (1<<1)
69#define EXT_CSD_BOOT_INFO_ALT (1<<0)
70#define EXT_CSD_BOOT_CFG_ACK (1<<6)
71#define EXT_CSD_BOOT_CFG_EN (0x38)
72#define EXT_CSD_BOOT_CFG_ACC (0x03)
Giuseppe CAVALLARO7bd13202012-04-19 10:58:37 +020073#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7)
74#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
75#define EXT_CSD_PART_CONFIG_ACC_BOOT1 (0x2)
76#define EXT_CSD_PART_CONFIG_ACC_USER_AREA (0x7)
77#define EXT_CSD_PART_CONFIG_ACC_ACK (0x40)
Johan RUDHOLMa8bfde72012-02-12 11:46:44 -050078
79/* From kernel linux/mmc/core.h */
80#define MMC_RSP_PRESENT (1 << 0)
81#define MMC_RSP_136 (1 << 1) /* 136 bit response */
82#define MMC_RSP_CRC (1 << 2) /* expect valid crc */
83#define MMC_RSP_BUSY (1 << 3) /* card may send busy */
84#define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
85
86#define MMC_CMD_AC (0 << 5)
87#define MMC_CMD_ADTC (1 << 5)
88
89#define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */
90#define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */
91
92#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
93#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
94
95#define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
96#define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)