History

mfd: cros_ec: Add Flash V2 commands API

Added for supporting larger embedded controller flash.

Gwendal Grignou committed 7 years ago

Commit 3c46ae61 parent fd3bbf41 file · +147 −3Browse files

Unified · Split

include/linux/mfd/cros_ec_commands.h+147−3
@@ -1138,6 +1138,7 @@ struct ec_response_get_features { · 1137 unmodified lines
11381138
11391139 /* Get flash info */
11401140 #define EC_CMD_FLASH_INFO 0x0010
1141+#define EC_VER_FLASH_INFO 2
11411142
11421143 /**
11431144 * struct ec_response_flash_info - Response to the flash info command.
@@ -1164,6 +1165,15 @@ struct ec_response_flash_info { · 20 unmodified lines
11641165 */
11651166 #define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
11661167
1168+/*
1169+ * Flash must be selected for read/write/erase operations to succeed. This may
1170+ * be necessary on a chip where write/erase can be corrupted by other board
1171+ * activity, or where the chip needs to enable some sort of programming voltage,
1172+ * or where the read/write/erase operations require cleanly suspending other
1173+ * chip functionality.
1174+ */
1175+#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
1176+
11671177 /**
11681178 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
11691179 * @flash_size: Usable flash size in bytes.
@@ -1186,6 +1196,12 @@ struct ec_response_flash_info { · 16 unmodified lines
11861196 * gcc anonymous structs don't seem to get along with the __packed directive;
11871197 * if they did we'd define the version 0 structure as a sub-structure of this
11881198 * one.
1199+ *
1200+ * Version 2 supports flash banks of different sizes:
1201+ * The caller specified the number of banks it has preallocated
1202+ * (num_banks_desc)
1203+ * The EC returns the number of banks describing the flash memory.
1204+ * It adds banks descriptions up to num_banks_desc.
11891205 */
11901206 struct ec_response_flash_info_1 {
11911207 /* Version 0 fields; see above for description */
@@ -1199,6 +1215,42 @@ struct ec_response_flash_info_1 { · 7 unmodified lines
11991215 uint32_t flags;
12001216 } __ec_align4;
12011217
1218+struct ec_params_flash_info_2 {
1219+ /* Number of banks to describe */
1220+ uint16_t num_banks_desc;
1221+ /* Reserved; set 0; ignore on read */
1222+ uint8_t reserved[2];
1223+} __ec_align4;
1224+
1225+struct ec_flash_bank {
1226+ /* Number of sector is in this bank. */
1227+ uint16_t count;
1228+ /* Size in power of 2 of each sector (8 --> 256 bytes) */
1229+ uint8_t size_exp;
1230+ /* Minimal write size for the sectors in this bank */
1231+ uint8_t write_size_exp;
1232+ /* Erase size for the sectors in this bank */
1233+ uint8_t erase_size_exp;
1234+ /* Size for write protection, usually identical to erase size. */
1235+ uint8_t protect_size_exp;
1236+ /* Reserved; set 0; ignore on read */
1237+ uint8_t reserved[2];
1238+};
1239+
1240+struct ec_response_flash_info_2 {
1241+ /* Total flash in the EC. */
1242+ uint32_t flash_size;
1243+ /* Flags; see EC_FLASH_INFO_* */
1244+ uint32_t flags;
1245+ /* Maximum size to use to send data to write to the EC. */
1246+ uint32_t write_ideal_size;
1247+ /* Number of banks present in the EC. */
1248+ uint16_t num_banks_total;
1249+ /* Number of banks described in banks array. */
1250+ uint16_t num_banks_desc;
1251+ struct ec_flash_bank banks[0];
1252+} __ec_align4;
1253+
12021254 /*
12031255 * Read flash
12041256 *
@@ -1238,7 +1290,7 @@ struct ec_params_flash_write { · 33 unmodified lines
12381290 #define EC_CMD_FLASH_ERASE 0x0013
12391291
12401292 /**
1241− * struct ec_params_flash_erase - Parameters for the flash erase command.
1293+ * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
12421294 * @offset: Byte offset to erase.
12431295 * @size: Size to erase in bytes.
12441296 */
@@ -1247,6 +1299,43 @@ struct ec_params_flash_erase { · 2 unmodified lines
12471299 uint32_t size;
12481300 } __ec_align4;
12491301
1302+/*
1303+ * v1 add async erase:
1304+ * subcommands can returns:
1305+ * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1306+ * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1307+ * EC_RES_ERROR : other errors.
1308+ * EC_RES_BUSY : an existing erase operation is in progress.
1309+ * EC_RES_ACCESS_DENIED: Trying to erase running image.
1310+ *
1311+ * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1312+ * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1313+ * the proper result.
1314+ * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1315+ * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1316+ * ERASE_GET_RESULT command may timeout on EC where flash access is not
1317+ * permitted while erasing. (For instance, STM32F4).
1318+ */
1319+enum ec_flash_erase_cmd {
1320+ FLASH_ERASE_SECTOR, /* Erase and wait for result */
1321+ FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1322+ FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1323+};
1324+
1325+/**
1326+ * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1327+ * @cmd: One of ec_flash_erase_cmd.
1328+ * @reserved: Pad byte; currently always contains 0.
1329+ * @flag: No flags defined yet; set to 0.
1330+ * @params: Same as v0 parameters.
1331+ */
1332+struct ec_params_flash_erase_v1 {
1333+ uint8_t cmd;
1334+ uint8_t reserved;
1335+ uint16_t flag;
1336+ struct ec_params_flash_erase params;
1337+} __ec_align4;
1338+
12501339 /*
12511340 * Get/set flash protection.
12521341 *
@@ -1282,6 +1371,15 @@ struct ec_params_flash_erase { · 29 unmodified lines
12821371 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
12831372 /* Entire flash code protected when the EC boots */
12841373 #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
1374+/* RW flash code protected when the EC boots */
1375+#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
1376+/* RW flash code protected now. */
1377+#define EC_FLASH_PROTECT_RW_NOW BIT(8)
1378+/* Rollback information flash region protected when the EC boots */
1379+#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
1380+/* Rollback information flash region protected now */
1381+#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
1382+
12851383
12861384 /**
12871385 * struct ec_params_flash_protect - Parameters for the flash protect command.
@@ -1320,16 +1418,31 @@ struct ec_response_flash_protect { · 32 unmodified lines
13201418 enum ec_flash_region {
13211419 /* Region which holds read-only EC image */
13221420 EC_FLASH_REGION_RO = 0,
1323− /* Region which holds rewritable EC image */
1324− EC_FLASH_REGION_RW,
1421+ /*
1422+ * Region which holds active RW image. 'Active' is different from
1423+ * 'running'. Active means 'scheduled-to-run'. Since RO image always
1424+ * scheduled to run, active/non-active applies only to RW images (for
1425+ * the same reason 'update' applies only to RW images. It's a state of
1426+ * an image on a flash. Running image can be RO, RW_A, RW_B but active
1427+ * image can only be RW_A or RW_B. In recovery mode, an active RW image
1428+ * doesn't enter 'running' state but it's still active on a flash.
1429+ */
1430+ EC_FLASH_REGION_ACTIVE,
13251431 /*
13261432 * Region which should be write-protected in the factory (a superset of
13271433 * EC_FLASH_REGION_RO)
13281434 */
13291435 EC_FLASH_REGION_WP_RO,
1436+ /* Region which holds updatable (non-active) RW image */
1437+ EC_FLASH_REGION_UPDATE,
13301438 /* Number of regions */
13311439 EC_FLASH_REGION_COUNT,
13321440 };
1441+/*
1442+ * 'RW' is vague if there are multiple RW images; we mean the active one,
1443+ * so the old constant is deprecated.
1444+ */
1445+#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
13331446
13341447 /**
13351448 * struct ec_params_flash_region_info - Parameters for the flash region info
@@ -1364,6 +1477,37 @@ struct ec_response_vbnvcontext { · 28 unmodified lines
13641477 uint8_t block[EC_VBNV_BLOCK_SIZE];
13651478 } __ec_align4;
13661479
1480+
1481+/* Get SPI flash information */
1482+#define EC_CMD_FLASH_SPI_INFO 0x0018
1483+
1484+struct ec_response_flash_spi_info {
1485+ /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1486+ uint8_t jedec[3];
1487+
1488+ /* Pad byte; currently always contains 0 */
1489+ uint8_t reserved0;
1490+
1491+ /* Manufacturer / device ID from command 0x90 */
1492+ uint8_t mfr_dev_id[2];
1493+
1494+ /* Status registers from command 0x05 and 0x35 */
1495+ uint8_t sr1, sr2;
1496+} __ec_align1;
1497+
1498+
1499+/* Select flash during flash operations */
1500+#define EC_CMD_FLASH_SELECT 0x0019
1501+
1502+/**
1503+ * struct ec_params_flash_select - Parameters for the flash select command.
1504+ * @select: 1 to select flash, 0 to deselect flash
1505+ */
1506+struct ec_params_flash_select {
1507+ uint8_t select;
1508+} __ec_align4;
1509+
1510+
13671511 /*****************************************************************************/
13681512 /* PWM commands */
13691513

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t