diff options
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); |