ZhiYuanNJ has uploaded this change for review.

View Change

ch347_spi: Add spi clock frequency selection

CH347 SPI interface supports up to 60M.
For example, to set a 30M spi rate, use - p ch347_spi: spispeed=30M.

Change-Id: If2be48929db540a6598ac0b60b37e64597156db7
Signed-off-by: ZhiYuanNJ Liu <871238103@qq.com>
---
M ch347_spi.c
1 file changed, 35 insertions(+), 3 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/76/82776/1
diff --git a/ch347_spi.c b/ch347_spi.c
index 21dcabb..85435bb 100644
--- a/ch347_spi.c
+++ b/ch347_spi.c
@@ -51,6 +51,11 @@
int interface;
};

+struct device_speeds {
+ const char *name;
+ const int speed;
+};
+
/* TODO: Add support for HID mode */
static const struct dev_entry devs_ch347_spi[] = {
{0x1A86, 0x55DB, OK, "QinHeng Electronics", "USB To UART+SPI+I2C"}, /* CH347T */
@@ -63,6 +68,18 @@
CH347F_IFACE,
};

+static const struct device_speeds spispeeds[] = {
+ {"60M", 0x0},
+ {"30M", 0x1},
+ {"15M", 0x2},
+ {"7.5M", 0x3},
+ {"3.75M", 0x4},
+ {"1.875M", 0x5},
+ {"937.5K", 0x6},
+ {"468.75K", 0x7},
+ {NULL, 0x0}
+};
+
static int ch347_spi_shutdown(void *data)
{
struct ch347_spi_data *ch347_data = data;
@@ -332,9 +349,24 @@
(desc.bcdDevice >> 4) & 0x000F,
(desc.bcdDevice >> 0) & 0x000F);

- /* TODO: add programmer cfg for things like CS pin and divisor */
- if (ch347_spi_config(ch347_data, 2) < 0)
+ /* TODO: set CH347 clock division */
+ arg = extract_programmer_param_str(cfg, "spispeed");
+ if (arg) {
+ for (index = 0; spispeeds[index].name; index++) {
+ if (!strncasecmp(spispeeds[index].name, arg, strlen(spispeeds[index].name))) {
+ spispeed = spispeeds[index].speed;
+ break;
+ }
+ }
+ }
+ if (!spispeeds[index].name || !arg)
+ msg_perr("Invalid SPI speed, using defaul(60M clock spi).\n");
+ free(arg);
+ if (ch347_spi_config(ch347_data, spispeed) < 0) {
goto error_exit;
+ } else {
+ msg_pinfo("CH347 SPI clock set to %s.\n", spispeeds[index].name);
+ }

return register_spi_master(&spi_master_ch347_spi, ch347_data);

@@ -348,4 +380,4 @@
.type = USB,
.devs.dev = devs_ch347_spi,
.init = ch347_spi_init,
-};
+};
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: If2be48929db540a6598ac0b60b37e64597156db7
Gerrit-Change-Number: 82776
Gerrit-PatchSet: 1
Gerrit-Owner: ZhiYuanNJ