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> |
| 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 CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 32 | #define EXT_CSD_S_CMD_SET 504 |
| 33 | #define EXT_CSD_HPI_FEATURE 503 |
| 34 | #define EXT_CSD_BOOT_INFO 228 /* R/W */ |
| 35 | #define EXT_CSD_PART_SWITCH_TIME 199 |
| 36 | #define EXT_CSD_BOOT_CFG 179 |
| 37 | #define EXT_CSD_BOOT_WP 173 |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * EXT_CSD field definitions |
| 41 | */ |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 42 | #define EXT_CSD_HPI_SUPP (1<<0) |
| 43 | #define EXT_CSD_HPI_IMPL (1<<1) |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 44 | #define EXT_CSD_CMD_SET_NORMAL (1<<0) |
| 45 | #define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40) |
| 46 | #define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10) |
| 47 | #define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04) |
| 48 | #define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 49 | #define EXT_CSD_BOOT_INFO_HS_MODE (1<<2) |
| 50 | #define EXT_CSD_BOOT_INFO_DDR_DDR (1<<1) |
| 51 | #define EXT_CSD_BOOT_INFO_ALT (1<<0) |
| 52 | #define EXT_CSD_BOOT_CFG_ACK (1<<6) |
| 53 | #define EXT_CSD_BOOT_CFG_EN (0x38) |
| 54 | #define EXT_CSD_BOOT_CFG_ACC (0x03) |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 55 | |
| 56 | /* From kernel linux/mmc/core.h */ |
| 57 | #define MMC_RSP_PRESENT (1 << 0) |
| 58 | #define MMC_RSP_136 (1 << 1) /* 136 bit response */ |
| 59 | #define MMC_RSP_CRC (1 << 2) /* expect valid crc */ |
| 60 | #define MMC_RSP_BUSY (1 << 3) /* card may send busy */ |
| 61 | #define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */ |
| 62 | |
| 63 | #define MMC_CMD_AC (0 << 5) |
| 64 | #define MMC_CMD_ADTC (1 << 5) |
| 65 | |
| 66 | #define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */ |
| 67 | #define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */ |
| 68 | |
| 69 | #define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1) |
| 70 | #define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY) |
| 71 | |
| 72 | #define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) |
| 73 | #define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY) |