Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 1 | /* |
| 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> |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | |
| 21 | #define CHECK(expr, msg, err_stmt) { if (expr) { fprintf(stderr, msg); err_stmt; } } |
| 22 | |
Oleg Matcovschi | 294bf86 | 2013-05-23 17:11:06 -0700 | [diff] [blame] | 23 | /* From kernel linux/major.h */ |
| 24 | #define MMC_BLOCK_MAJOR 179 |
| 25 | |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 26 | /* From kernel linux/mmc/mmc.h */ |
| 27 | #define MMC_SWITCH 6 /* ac [31:0] See below R1b */ |
| 28 | #define MMC_SEND_EXT_CSD 8 /* adtc R1 */ |
Ben Gardiner | 27c357d | 2013-05-30 17:12:47 -0400 | [diff] [blame] | 29 | #define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */ |
| 30 | #define R1_SWITCH_ERROR (1 << 7) /* sx, c */ |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 31 | #define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */ |
| 32 | |
| 33 | /* |
| 34 | * EXT_CSD fields |
| 35 | */ |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 36 | #define EXT_CSD_S_CMD_SET 504 |
| 37 | #define EXT_CSD_HPI_FEATURE 503 |
Jaehoon Chung | 8649651 | 2012-09-21 10:08:05 +0000 | [diff] [blame] | 38 | #define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 39 | #define EXT_CSD_BOOT_INFO 228 /* R/W */ |
| 40 | #define EXT_CSD_PART_SWITCH_TIME 199 |
| 41 | #define EXT_CSD_BOOT_CFG 179 |
Giuseppe CAVALLARO | 7bd1320 | 2012-04-19 10:58:37 +0200 | [diff] [blame] | 42 | #define EXT_CSD_PART_CONFIG 179 |
Saugata Das | b7e2599 | 2012-05-17 09:26:34 -0400 | [diff] [blame] | 43 | #define EXT_CSD_BOOT_WP 173 |
| 44 | #define EXT_CSD_WR_REL_PARAM 166 |
Yaniv Gardi | 21bb473 | 2013-05-26 13:25:33 -0400 | [diff] [blame] | 45 | #define EXT_CSD_SANITIZE_START 165 |
Jaehoon Chung | 8649651 | 2012-09-21 10:08:05 +0000 | [diff] [blame] | 46 | #define EXT_CSD_BKOPS_EN 163 /* R/W */ |
Chris Ball | f74dfe2 | 2012-10-19 16:49:55 -0400 | [diff] [blame] | 47 | #define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ |
Ben Gardiner | 82bd950 | 2013-06-27 11:04:10 -0400 | [diff] [blame] | 48 | #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */ |
Ben Gardiner | a6cd98d | 2013-05-30 17:12:46 -0400 | [diff] [blame] | 49 | #define EXT_CSD_PARTITION_SETTING_COMPLETED 155 /* R/W */ |
Ben Gardiner | 68f490b | 2013-05-30 17:12:48 -0400 | [diff] [blame^] | 50 | #define EXT_CSD_ENH_START_ADDR_3 139 |
| 51 | #define EXT_CSD_ENH_START_ADDR_2 138 |
| 52 | #define EXT_CSD_ENH_START_ADDR_1 137 |
| 53 | #define EXT_CSD_ENH_START_ADDR_0 136 |
Saugata Das | b7e2599 | 2012-05-17 09:26:34 -0400 | [diff] [blame] | 54 | #define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ |
| 55 | #define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */ |
| 56 | #define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ |
| 57 | |
| 58 | /* |
| 59 | * WR_REL_PARAM field definitions |
| 60 | */ |
| 61 | #define HS_CTRL_REL (1<<0) |
| 62 | #define EN_REL_WR (1<<2) |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 63 | |
| 64 | /* |
Jaehoon Chung | 8649651 | 2012-09-21 10:08:05 +0000 | [diff] [blame] | 65 | * BKOPS_EN field definition |
| 66 | */ |
| 67 | #define BKOPS_ENABLE (1<<0) |
| 68 | |
| 69 | /* |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 70 | * EXT_CSD field definitions |
| 71 | */ |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 72 | #define EXT_CSD_HPI_SUPP (1<<0) |
| 73 | #define EXT_CSD_HPI_IMPL (1<<1) |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 74 | #define EXT_CSD_CMD_SET_NORMAL (1<<0) |
| 75 | #define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40) |
| 76 | #define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10) |
| 77 | #define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04) |
| 78 | #define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 79 | #define EXT_CSD_BOOT_INFO_HS_MODE (1<<2) |
| 80 | #define EXT_CSD_BOOT_INFO_DDR_DDR (1<<1) |
| 81 | #define EXT_CSD_BOOT_INFO_ALT (1<<0) |
| 82 | #define EXT_CSD_BOOT_CFG_ACK (1<<6) |
| 83 | #define EXT_CSD_BOOT_CFG_EN (0x38) |
Mario Schuknecht | 8c0c40d | 2013-05-15 08:28:04 +0200 | [diff] [blame] | 84 | #define EXT_CSD_BOOT_CFG_ACC (0x07) |
Chris Ball | f74dfe2 | 2012-10-19 16:49:55 -0400 | [diff] [blame] | 85 | #define EXT_CSD_RST_N_EN_MASK (0x03) |
| 86 | #define EXT_CSD_HW_RESET_EN (0x01) |
| 87 | #define EXT_CSD_HW_RESET_DIS (0x02) |
Giuseppe CAVALLARO | 7bd1320 | 2012-04-19 10:58:37 +0200 | [diff] [blame] | 88 | #define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) |
| 89 | #define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) |
| 90 | #define EXT_CSD_PART_CONFIG_ACC_BOOT1 (0x2) |
| 91 | #define EXT_CSD_PART_CONFIG_ACC_USER_AREA (0x7) |
| 92 | #define EXT_CSD_PART_CONFIG_ACC_ACK (0x40) |
Ben Gardiner | 82bd950 | 2013-06-27 11:04:10 -0400 | [diff] [blame] | 93 | #define EXT_CSD_PARTITIONING_EN (1<<0) |
| 94 | #define EXT_CSD_ENH_ATTRIBUTE_EN (1<<1) |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 95 | |
| 96 | /* From kernel linux/mmc/core.h */ |
| 97 | #define MMC_RSP_PRESENT (1 << 0) |
| 98 | #define MMC_RSP_136 (1 << 1) /* 136 bit response */ |
| 99 | #define MMC_RSP_CRC (1 << 2) /* expect valid crc */ |
| 100 | #define MMC_RSP_BUSY (1 << 3) /* card may send busy */ |
| 101 | #define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */ |
| 102 | |
| 103 | #define MMC_CMD_AC (0 << 5) |
| 104 | #define MMC_CMD_ADTC (1 << 5) |
| 105 | |
| 106 | #define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */ |
| 107 | #define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */ |
| 108 | |
| 109 | #define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1) |
| 110 | #define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY) |
| 111 | |
| 112 | #define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) |
| 113 | #define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY) |