diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-06-05 00:12:01 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-06-06 11:06:14 +0000 |
commit | e85bc74b307365e9a7b4adab51d646638db12fbd (patch) | |
tree | c45ba9079344b5cc0ea48a77b6aa77aacd71cdc5 /firmware/target/mips/ingenic_x1000/pwm-x1000.c | |
parent | 695d1701cdd1bb4539f652c2204f7787097b2715 (diff) | |
download | rockbox-e85bc74b307365e9a7b4adab51d646638db12fbd.tar.gz rockbox-e85bc74b307365e9a7b4adab51d646638db12fbd.zip |
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
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/pwm-x1000.c')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/pwm-x1000.c | 39 |
1 files changed, 19 insertions, 20 deletions
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 @@ | |||
26 | #include "kernel.h" | 26 | #include "kernel.h" |
27 | #include "x1000/tcu.h" | 27 | #include "x1000/tcu.h" |
28 | 28 | ||
29 | struct pwm_gpio_data { | ||
30 | int port; | ||
31 | unsigned pin; | ||
32 | int func; | ||
33 | }; | ||
34 | |||
35 | struct pwm_state { | 29 | struct pwm_state { |
36 | int period_ns; | 30 | int period_ns; |
37 | int duty_ns; | 31 | int duty_ns; |
@@ -40,14 +34,6 @@ struct pwm_state { | |||
40 | int prescaler; | 34 | int prescaler; |
41 | }; | 35 | }; |
42 | 36 | ||
43 | static const struct pwm_gpio_data pwm_gpios[] = { | ||
44 | {GPIO_C, 1 << 25, GPIO_DEVICE(0)}, | ||
45 | {GPIO_C, 1 << 26, GPIO_DEVICE(1)}, | ||
46 | {GPIO_C, 1 << 27, GPIO_DEVICE(1)}, | ||
47 | {GPIO_B, 1 << 6, GPIO_DEVICE(2)}, | ||
48 | {GPIO_C, 1 << 24, GPIO_DEVICE(0)}, | ||
49 | }; | ||
50 | |||
51 | static struct pwm_state pwm_state[] = { | 37 | static struct pwm_state pwm_state[] = { |
52 | {-1, -1, -1, -1, -1}, | 38 | {-1, -1, -1, -1, -1}, |
53 | {-1, -1, -1, -1, -1}, | 39 | {-1, -1, -1, -1, -1}, |
@@ -56,6 +42,22 @@ static struct pwm_state pwm_state[] = { | |||
56 | {-1, -1, -1, -1, -1}, | 42 | {-1, -1, -1, -1, -1}, |
57 | }; | 43 | }; |
58 | 44 | ||
45 | static const int pwm_gpio[] = { | ||
46 | GPIO_PC(25), | ||
47 | GPIO_PC(26), | ||
48 | GPIO_PC(27), | ||
49 | GPIO_PB(6), | ||
50 | GPIO_PC(24), | ||
51 | }; | ||
52 | |||
53 | static const int pwm_gpio_func[] = { | ||
54 | GPIOF_DEVICE(0), | ||
55 | GPIOF_DEVICE(1), | ||
56 | GPIOF_DEVICE(1), | ||
57 | GPIOF_DEVICE(2), | ||
58 | GPIOF_DEVICE(0), | ||
59 | }; | ||
60 | |||
59 | void pwm_init(int chn) | 61 | void pwm_init(int chn) |
60 | { | 62 | { |
61 | /* clear cached state */ | 63 | /* clear cached state */ |
@@ -67,8 +69,7 @@ void pwm_init(int chn) | |||
67 | st->prescaler = -1; | 69 | st->prescaler = -1; |
68 | 70 | ||
69 | /* clear GPIO and disable timer */ | 71 | /* clear GPIO and disable timer */ |
70 | const struct pwm_gpio_data* pg = &pwm_gpios[chn]; | 72 | gpio_set_function(pwm_gpio[chn], GPIOF_OUTPUT(0)); |
71 | gpio_config(pg->port, pg->pin, GPIO_OUTPUT(0)); | ||
72 | jz_clr(TCU_STOP, 1 << chn); | 73 | jz_clr(TCU_STOP, 1 << chn); |
73 | jz_clr(TCU_ENABLE, 1 << chn); | 74 | jz_clr(TCU_ENABLE, 1 << chn); |
74 | jz_set(TCU_STOP, 1 << chn); | 75 | jz_set(TCU_STOP, 1 << chn); |
@@ -161,15 +162,13 @@ void pwm_enable(int chn) | |||
161 | jz_set(TCU_ENABLE, 1 << chn); | 162 | jz_set(TCU_ENABLE, 1 << chn); |
162 | 163 | ||
163 | /* Configure GPIO function */ | 164 | /* Configure GPIO function */ |
164 | const struct pwm_gpio_data* pg = &pwm_gpios[chn]; | 165 | gpio_set_function(pwm_gpio[chn], pwm_gpio_func[chn]); |
165 | gpio_config(pg->port, pg->pin, pg->func); | ||
166 | } | 166 | } |
167 | 167 | ||
168 | void pwm_disable(int chn) | 168 | void pwm_disable(int chn) |
169 | { | 169 | { |
170 | /* Set GPIO to output 0 */ | 170 | /* Set GPIO to output 0 */ |
171 | const struct pwm_gpio_data* pg = &pwm_gpios[chn]; | 171 | gpio_set_function(pwm_gpio[chn], GPIOF_OUTPUT(0)); |
172 | gpio_config(pg->port, pg->pin, GPIO_OUTPUT(0)); | ||
173 | 172 | ||
174 | /* Stop timer */ | 173 | /* Stop timer */ |
175 | jz_clr(TCU_ENABLE, 1 << chn); | 174 | jz_clr(TCU_ENABLE, 1 << chn); |