From e85bc74b307365e9a7b4adab51d646638db12fbd Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 5 Jun 2021 00:12:01 +0100 Subject: x1000: GPIO refactor The GPIO API was pretty clunky and pin settings were decentralized, making it hard to see what was happening and making GPIO stuff look like a mess, frankly. Instead of passing clunky (port, pin) pairs everywhere, GPIOs are now identified with a single int. The extra overhead should be minimal as GPIO configuration is generally not on a performance-critical path. Pin assignments are now mostly consolidated in gpio-target.h and put in various tables so gpio_init() can assign most pins at boot time. Most drivers no longer need to touch GPIOs and basic pin I/O stuff can happen without config since pins are put into the right state. IRQ pins still need to be configured manually before use. Change-Id: Ic5326284b0b2a2f613e9e76a41cb50e24af3aa47 --- firmware/target/mips/ingenic_x1000/pwm-x1000.c | 39 +++++++++++++------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'firmware/target/mips/ingenic_x1000/pwm-x1000.c') diff --git a/firmware/target/mips/ingenic_x1000/pwm-x1000.c b/firmware/target/mips/ingenic_x1000/pwm-x1000.c index 8530a38af5..e8243a42ce 100644 --- a/firmware/target/mips/ingenic_x1000/pwm-x1000.c +++ b/firmware/target/mips/ingenic_x1000/pwm-x1000.c @@ -26,12 +26,6 @@ #include "kernel.h" #include "x1000/tcu.h" -struct pwm_gpio_data { - int port; - unsigned pin; - int func; -}; - struct pwm_state { int period_ns; int duty_ns; @@ -40,14 +34,6 @@ struct pwm_state { int prescaler; }; -static const struct pwm_gpio_data pwm_gpios[] = { - {GPIO_C, 1 << 25, GPIO_DEVICE(0)}, - {GPIO_C, 1 << 26, GPIO_DEVICE(1)}, - {GPIO_C, 1 << 27, GPIO_DEVICE(1)}, - {GPIO_B, 1 << 6, GPIO_DEVICE(2)}, - {GPIO_C, 1 << 24, GPIO_DEVICE(0)}, -}; - static struct pwm_state pwm_state[] = { {-1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1}, @@ -56,6 +42,22 @@ static struct pwm_state pwm_state[] = { {-1, -1, -1, -1, -1}, }; +static const int pwm_gpio[] = { + GPIO_PC(25), + GPIO_PC(26), + GPIO_PC(27), + GPIO_PB(6), + GPIO_PC(24), +}; + +static const int pwm_gpio_func[] = { + GPIOF_DEVICE(0), + GPIOF_DEVICE(1), + GPIOF_DEVICE(1), + GPIOF_DEVICE(2), + GPIOF_DEVICE(0), +}; + void pwm_init(int chn) { /* clear cached state */ @@ -67,8 +69,7 @@ void pwm_init(int chn) st->prescaler = -1; /* clear GPIO and disable timer */ - const struct pwm_gpio_data* pg = &pwm_gpios[chn]; - gpio_config(pg->port, pg->pin, GPIO_OUTPUT(0)); + gpio_set_function(pwm_gpio[chn], GPIOF_OUTPUT(0)); jz_clr(TCU_STOP, 1 << chn); jz_clr(TCU_ENABLE, 1 << chn); jz_set(TCU_STOP, 1 << chn); @@ -161,15 +162,13 @@ void pwm_enable(int chn) jz_set(TCU_ENABLE, 1 << chn); /* Configure GPIO function */ - const struct pwm_gpio_data* pg = &pwm_gpios[chn]; - gpio_config(pg->port, pg->pin, pg->func); + gpio_set_function(pwm_gpio[chn], pwm_gpio_func[chn]); } void pwm_disable(int chn) { /* Set GPIO to output 0 */ - const struct pwm_gpio_data* pg = &pwm_gpios[chn]; - gpio_config(pg->port, pg->pin, GPIO_OUTPUT(0)); + gpio_set_function(pwm_gpio[chn], GPIOF_OUTPUT(0)); /* Stop timer */ jz_clr(TCU_ENABLE, 1 << chn); -- cgit v1.2.3