diff options
author | Marc Zyngier <maz@kernel.org> | 2023-08-27 10:29:31 +0100 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2023-08-27 10:32:57 +0100 |
commit | f684a2d9bdf7cad9a032792c95eca65a730f10bf (patch) | |
tree | 70af9313f8b556d5d7367d51399aa197bca12f51 | |
parent | 345ba0375a347b0696c15df23aae3841d75bdc32 (diff) | |
download | cs-sw-f684a2d9bdf7cad9a032792c95eca65a730f10bf.tar.gz |
Add support for Waveshare 2CH RS232 daughter board
Signed-off-by: Marc Zyngier <maz@kernel.org>
-rw-r--r-- | m1-pd-bmc.h | 4 | ||||
-rw-r--r-- | start.c | 56 |
2 files changed, 59 insertions, 1 deletions
diff --git a/m1-pd-bmc.h b/m1-pd-bmc.h index edad800..83abc9c 100644 --- a/m1-pd-bmc.h +++ b/m1-pd-bmc.h @@ -29,7 +29,9 @@ enum m1_pd_bmc_pins { UART_RX, SBU_SWAP, SEL_USB, - M1_BMC_PIN_END = SEL_USB, + LED_R_TX, + LED_R_RX, + M1_BMC_PIN_END = LED_R_RX, }; struct hw_context { @@ -54,6 +54,25 @@ static const struct gpio_pin_config m1_pd_bmc_pin_config0[] = { }, }; +static const struct gpio_pin_config waveshare_2ch_rs232_config0[] = { + [M1_BMC_PIN_START ... M1_BMC_PIN_END] = { + .skip = true, + }, + /* Prevent the unused leds from drawing much curent */ + [LED_R_TX] = { + .pin = 0, + .mode = GPIO_FUNC_SIO, + .dir = GPIO_IN, + .pu = true, + }, + [LED_R_RX] = { + .pin = 1, + .mode = GPIO_FUNC_SIO, + .dir = GPIO_IN, + .pu = true, + }, +}; + static const struct gpio_pin_config m1_pd_bmc_pin_config1[] = { [M1_BMC_PIN_START ... M1_BMC_PIN_END] = { .skip = true, @@ -102,6 +121,20 @@ static const struct gpio_pin_config m1_pd_bmc_pin_config1[] = { }, }; +static const struct gpio_pin_config waveshare_2ch_rs232_config1[] = { + [M1_BMC_PIN_START ... M1_BMC_PIN_END] = { + .skip = true, + }, + [UART_TX] = { /* UART1 */ + .pin = 4, + .mode = GPIO_FUNC_UART, + }, + [UART_RX] = { /* UART1 */ + .pin = 5, + .mode = GPIO_FUNC_UART, + }, +}; + static struct { /* * we rely on prod/cons rollover behaviour, and buf must cover @@ -205,6 +238,26 @@ static void m1_pd_bmc_system_init(const struct hw_context *hw) m1_pd_bmc_gpio_setup_one(&hw->pins[i]); } +static bool apply_waveshare_2ch_rs232_overrides(void) +{ + /* + * Hack: check for PUPs on 0/1, and assumes this is a dual + * RS232 board plugged in. Ideally, we'd also check UART1 on + * 4/5, but this looks unreliable. If this gets in the way, + * turn it into a compilation option instead. + */ + if (!(gpio_get(waveshare_2ch_rs232_config0[LED_R_TX].pin) && + gpio_get(waveshare_2ch_rs232_config0[LED_R_RX].pin))) + return false; + + for (int i = 0; i < ARRAY_SIZE(waveshare_2ch_rs232_config0); i++) + m1_pd_bmc_gpio_setup_one(&waveshare_2ch_rs232_config0[i]); + for (int i = 0; i < ARRAY_SIZE(waveshare_2ch_rs232_config1); i++) + m1_pd_bmc_gpio_setup_one(&waveshare_2ch_rs232_config1[i]); + + return true; +} + static void usb_tx_bytes(int32_t port, const char *ptr, int len) { if (!tud_cdc_n_connected(port)) @@ -353,6 +406,9 @@ int main(void) if (!success) __printf(port, "WARNING: Nominal frequency NOT reached\n"); + if (apply_waveshare_2ch_rs232_overrides()) + __printf(port, "Detected Waveshare 2CH RS232, switching UART1\n"); + m1_pd_bmc_fusb_setup(0, &hw0); m1_pd_bmc_fusb_setup(1, &hw1); |