Shiyu Sun has uploaded this change for review.

View Change

realtek_mst_i2c_spi.c: Update wp disable function and add param

The write protection trigger has been updated by the vendor so update
here as well. Also added parameter to allower user to decide turn off
protection or not before an operation.

Change-Id: I1aed0086f917e31bebb51857ad5cce138158fe82
Signed-off-by: Shiyu Sun <sshiyu@chromium.org>
---
M realtek_mst_i2c_spi.c
1 file changed, 43 insertions(+), 16 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/89/46089/1
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index d1f7227..2e5872e 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -146,27 +146,36 @@
return ret;
}

-static int realtek_mst_i2c_spi_disable_protection(int fd)
+static int realtek_mst_i2c_spi_disable_hw_protection(int fd)
{
int ret = 0;
uint8_t val = 0;
- // 0xAB[2:0] = b001

+ // Configure Pin to Push-Pull GPIO
ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x9F);
ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, 0x10);
- ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0xAB);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x4F);

ret |= realtek_mst_i2c_spi_read_register(fd, 0xF5, &val);

ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x9F);
ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, 0x10);
- ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0xAB);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x4F);

- ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, (val & 0xF8) | 0x01);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, (val & 0xF0) | 0x01);

- /* Set pin value to high, 0xFFD7[0] = 1. */
- ret |= realtek_mst_i2c_spi_read_register(fd, 0xD7, &val);
- ret |= realtek_mst_i2c_spi_write_register(fd, 0xD7, (val & 0xFE) | 0x01);
+ // Set Pin Value to High
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x9F);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, 0xFE);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x3F);
+
+ ret |= realtek_mst_i2c_spi_read_register(fd, 0xF5, &val);
+
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x9F);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, 0xFE);
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF4, 0x3F);
+
+ ret |= realtek_mst_i2c_spi_write_register(fd, 0xF5, (val & 0xFE) | 0x01);

return ret;
}
@@ -333,10 +342,6 @@
if (fd < 0)
return SPI_GENERIC_ERROR;

- ret = realtek_mst_i2c_spi_disable_protection(fd);
- if (ret)
- return ret;
-
ret |= realtek_mst_i2c_spi_write_register(fd, 0x6D, 0x02); /* write opcode */
ret |= realtek_mst_i2c_spi_write_register(fd, 0x71, (PAGE_SIZE - 1)); /* fit len=256 */

@@ -404,9 +409,9 @@
return ret;
}

-static int get_params(int *i2c_bus, int *reset)
+static int get_params(int *i2c_bus, int *reset, int *wp_disable)
{
- char *bus_str = NULL, *reset_str = NULL;
+ char *bus_str = NULL, *reset_str = NULL, *wp_str = NULL;
int ret = SPI_GENERIC_ERROR;

bus_str = extract_programmer_param("bus");
@@ -450,6 +455,20 @@
*reset = 0; /* Default behaviour is no MCU reset on tear-down. */
free(reset_str);

+ wp_str = extract_programmer_param("wp-disable");
+ if (wp_str) {
+ if (wp_str[0] == '1')
+ *wp_disable = 1;
+ else if (wp_str[0] == '0')
+ *wp_disable = 0;
+ else {
+ msg_perr("%s: Incorrect param format, wp-disable=1 or 0.\n", __func__);
+ ret = SPI_GENERIC_ERROR;
+ }
+ } else
+ *wp_disable = 0; /* Default behaviour is not have hardware write protect disabled. */
+ free(wp_str);
+
_get_params_failed:
if (bus_str)
free(bus_str);
@@ -460,9 +479,9 @@
int realtek_mst_i2c_spi_init(void)
{
int ret = 0;
- int i2c_bus = 0, reset = 0;
+ int i2c_bus = 0, reset = 0, wp_disable = 0;

- if (get_params(&i2c_bus, &reset))
+ if (get_params(&i2c_bus, &reset, &wp_disable))
return SPI_GENERIC_ERROR;

int fd = i2c_open(i2c_bus, REGISTER_ADDRESS, 0);
@@ -473,6 +492,14 @@
if (ret)
return ret;

+ if (wp_disable) {
+ ret |= realtek_mst_i2c_spi_disable_hw_protection(fd);
+ if (ret != 0) {
+ msg_perr("%s: failed to disable the write protection.\n", __func__);
+ return ret;
+ }
+ }
+
struct realtek_mst_i2c_spi_data *data = calloc(1, sizeof(struct realtek_mst_i2c_spi_data));
if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n");

To view, visit change 46089. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I1aed0086f917e31bebb51857ad5cce138158fe82
Gerrit-Change-Number: 46089
Gerrit-PatchSet: 1
Gerrit-Owner: Shiyu Sun <sshiyu@google.com>
Gerrit-MessageType: newchange