diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-06-05 11:58:17 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-06-06 11:06:43 +0000 |
commit | 2b23d3ecaf2074ad640f66ff198b6043f3ea9e6e (patch) | |
tree | 465de543e13bcada2ffe2ba7346a10d57fdbe0be | |
parent | e85bc74b307365e9a7b4adab51d646638db12fbd (diff) | |
download | rockbox-2b23d3ecaf2074ad640f66ff198b6043f3ea9e6e.tar.gz rockbox-2b23d3ecaf2074ad640f66ff198b6043f3ea9e6e.zip |
x1000: Allow setting IRQ handlers dynamically
Avoids having to #define the names of GPIO pin interrupt handlers,
as they can now be set at runtime instead.
Change-Id: Ib5da1bdb475ff7b64280fe7cdd00adab63389152
6 files changed, 26 insertions, 16 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c index 47b5e3d6dc..d566ccb6c8 100644 --- a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c +++ b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c | |||
@@ -35,8 +35,6 @@ | |||
35 | # include "font.h" | 35 | # include "font.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #define ft_interrupt GPIOB12 | ||
39 | |||
40 | /* Touch event types */ | 38 | /* Touch event types */ |
41 | #define EVENT_NONE (-1) | 39 | #define EVENT_NONE (-1) |
42 | #define EVENT_PRESS 0 | 40 | #define EVENT_PRESS 0 |
@@ -348,7 +346,8 @@ static void ft_i2c_callback(int status, i2c_descriptor* desc) | |||
348 | ft_step_state(__ost_read32(), evt, tx, ty); | 346 | ft_step_state(__ost_read32(), evt, tx, ty); |
349 | } | 347 | } |
350 | 348 | ||
351 | void ft_interrupt(void) | 349 | /* ft6x06 interrupt pin */ |
350 | void GPIOB12(void) | ||
352 | { | 351 | { |
353 | /* We don't care if this fails */ | 352 | /* We don't care if this fails */ |
354 | i2c_async_queue(FT6x06_BUS, TIMEOUT_NOBLOCK, I2C_Q_ONCE, | 353 | i2c_async_queue(FT6x06_BUS, TIMEOUT_NOBLOCK, I2C_Q_ONCE, |
diff --git a/firmware/target/mips/ingenic_x1000/gpio-x1000.h b/firmware/target/mips/ingenic_x1000/gpio-x1000.h index 5d147fc18f..eac5f8651f 100644 --- a/firmware/target/mips/ingenic_x1000/gpio-x1000.h +++ b/firmware/target/mips/ingenic_x1000/gpio-x1000.h | |||
@@ -57,6 +57,9 @@ | |||
57 | #define GPIO_PC(x) GPION_CREATE(GPIO_C, x) | 57 | #define GPIO_PC(x) GPION_CREATE(GPIO_C, x) |
58 | #define GPIO_PD(x) GPION_CREATE(GPIO_D, x) | 58 | #define GPIO_PD(x) GPION_CREATE(GPIO_D, x) |
59 | 59 | ||
60 | /* GPIO number to IRQ number (need to include "irq-x1000.h") */ | ||
61 | #define GPIO_TO_IRQ(gpio) IRQ_GPIO(GPION_PORT(gpio), GPION_PIN(gpio)) | ||
62 | |||
60 | /* Pingroup settings are used for system devices */ | 63 | /* Pingroup settings are used for system devices */ |
61 | struct pingroup_setting { | 64 | struct pingroup_setting { |
62 | int port; | 65 | int port; |
diff --git a/firmware/target/mips/ingenic_x1000/msc-x1000.c b/firmware/target/mips/ingenic_x1000/msc-x1000.c index 92b3d4206a..27929cced5 100644 --- a/firmware/target/mips/ingenic_x1000/msc-x1000.c +++ b/firmware/target/mips/ingenic_x1000/msc-x1000.c | |||
@@ -42,7 +42,6 @@ | |||
42 | static const msc_config msc_configs[] = { | 42 | static const msc_config msc_configs[] = { |
43 | #ifdef FIIO_M3K | 43 | #ifdef FIIO_M3K |
44 | #define MSC_CLOCK_SOURCE X1000_CLK_SCLK_A | 44 | #define MSC_CLOCK_SOURCE X1000_CLK_SCLK_A |
45 | #define msc0_cd_interrupt GPIOB06 | ||
46 | { | 45 | { |
47 | .msc_nr = 0, | 46 | .msc_nr = 0, |
48 | .msc_type = MSC_TYPE_SD, | 47 | .msc_type = MSC_TYPE_SD, |
@@ -67,6 +66,9 @@ static const msc_config* msc_lookup_config(int msc) | |||
67 | 66 | ||
68 | static msc_drv msc_drivers[MSC_COUNT]; | 67 | static msc_drv msc_drivers[MSC_COUNT]; |
69 | 68 | ||
69 | static void msc0_cd_interrupt(void); | ||
70 | static void msc1_cd_interrupt(void); | ||
71 | |||
70 | /* --------------------------------------------------------------------------- | 72 | /* --------------------------------------------------------------------------- |
71 | * Initialization | 73 | * Initialization |
72 | */ | 74 | */ |
@@ -123,6 +125,8 @@ static void msc_init_one(msc_drv* d, int msc) | |||
123 | if(gpio_get_level(d->config->cd_gpio) != d->config->cd_active_level) | 125 | if(gpio_get_level(d->config->cd_gpio) != d->config->cd_active_level) |
124 | d->card_present = 0; | 126 | d->card_present = 0; |
125 | 127 | ||
128 | system_set_irq_handler(GPIO_TO_IRQ(d->config->cd_gpio), | ||
129 | msc == 0 ? msc0_cd_interrupt : msc1_cd_interrupt); | ||
126 | gpio_set_function(d->config->cd_gpio, GPIOF_IRQ_EDGE(1)); | 130 | gpio_set_function(d->config->cd_gpio, GPIOF_IRQ_EDGE(1)); |
127 | gpio_flip_edge_irq(d->config->cd_gpio); | 131 | gpio_flip_edge_irq(d->config->cd_gpio); |
128 | gpio_enable_irq(d->config->cd_gpio); | 132 | gpio_enable_irq(d->config->cd_gpio); |
@@ -647,19 +651,15 @@ void MSC1(void) | |||
647 | msc_interrupt(&msc_drivers[1]); | 651 | msc_interrupt(&msc_drivers[1]); |
648 | } | 652 | } |
649 | 653 | ||
650 | #ifdef msc0_cd_interrupt | 654 | static void msc0_cd_interrupt(void) |
651 | void msc0_cd_interrupt(void) | ||
652 | { | 655 | { |
653 | msc_cd_interrupt(&msc_drivers[0]); | 656 | msc_cd_interrupt(&msc_drivers[0]); |
654 | } | 657 | } |
655 | #endif | ||
656 | 658 | ||
657 | #ifdef msc1_cd_interrupt | 659 | static void msc1_cd_interrupt(void) |
658 | void msc1_cd_interrupt(void) | ||
659 | { | 660 | { |
660 | msc_cd_interrupt(&msc_drivers[1]); | 661 | msc_cd_interrupt(&msc_drivers[1]); |
661 | } | 662 | } |
662 | #endif | ||
663 | 663 | ||
664 | /* --------------------------------------------------------------------------- | 664 | /* --------------------------------------------------------------------------- |
665 | * SD command helpers | 665 | * SD command helpers |
diff --git a/firmware/target/mips/ingenic_x1000/system-target.h b/firmware/target/mips/ingenic_x1000/system-target.h index 1390faf43a..7cea654865 100644 --- a/firmware/target/mips/ingenic_x1000/system-target.h +++ b/firmware/target/mips/ingenic_x1000/system-target.h | |||
@@ -90,6 +90,9 @@ static inline void core_sleep(void) | |||
90 | } | 90 | } |
91 | 91 | ||
92 | /* IRQ control */ | 92 | /* IRQ control */ |
93 | typedef void(*irq_handler_t)(void); | ||
94 | |||
95 | extern irq_handler_t system_set_irq_handler(int irq, irq_handler_t handler); | ||
93 | extern void system_enable_irq(int irq); | 96 | extern void system_enable_irq(int irq); |
94 | extern void system_disable_irq(int irq); | 97 | extern void system_disable_irq(int irq); |
95 | 98 | ||
diff --git a/firmware/target/mips/ingenic_x1000/system-x1000.c b/firmware/target/mips/ingenic_x1000/system-x1000.c index c0b0dbc65e..779bb2055c 100644 --- a/firmware/target/mips/ingenic_x1000/system-x1000.c +++ b/firmware/target/mips/ingenic_x1000/system-x1000.c | |||
@@ -233,7 +233,7 @@ intr(OST); | |||
233 | 233 | ||
234 | #undef intr | 234 | #undef intr |
235 | 235 | ||
236 | static void(*const irqvector[])(void) = { | 236 | static void(*irqvector[])(void) = { |
237 | /* ICSR0: 0 - 31 */ | 237 | /* ICSR0: 0 - 31 */ |
238 | DMIC, AIC, UIRQ, UIRQ, UIRQ, UIRQ, UIRQ, SFC, | 238 | DMIC, AIC, UIRQ, UIRQ, UIRQ, UIRQ, UIRQ, SFC, |
239 | SSI0, UIRQ, PDMA, PDMAD, UIRQ, UIRQ, UIRQ, UIRQ, | 239 | SSI0, UIRQ, PDMA, PDMAD, UIRQ, UIRQ, UIRQ, UIRQ, |
@@ -263,6 +263,13 @@ static void(*const irqvector[])(void) = { | |||
263 | GPIOD00, GPIOD01, GPIOD02, GPIOD03, GPIOD04, GPIOD05, | 263 | GPIOD00, GPIOD01, GPIOD02, GPIOD03, GPIOD04, GPIOD05, |
264 | }; | 264 | }; |
265 | 265 | ||
266 | irq_handler_t system_set_irq_handler(int irq, irq_handler_t handler) | ||
267 | { | ||
268 | irq_handler_t old_handler = irqvector[irq]; | ||
269 | irqvector[irq] = handler; | ||
270 | return old_handler; | ||
271 | } | ||
272 | |||
266 | void system_enable_irq(int irq) | 273 | void system_enable_irq(int irq) |
267 | { | 274 | { |
268 | if(IRQ_IS_GROUP0(irq)) { | 275 | if(IRQ_IS_GROUP0(irq)) { |
diff --git a/firmware/target/mips/ingenic_x1000/usb-x1000.c b/firmware/target/mips/ingenic_x1000/usb-x1000.c index 1cedac4fa7..1a31d8db2e 100644 --- a/firmware/target/mips/ingenic_x1000/usb-x1000.c +++ b/firmware/target/mips/ingenic_x1000/usb-x1000.c | |||
@@ -28,10 +28,6 @@ | |||
28 | #include "gpio-x1000.h" | 28 | #include "gpio-x1000.h" |
29 | #include "x1000/cpm.h" | 29 | #include "x1000/cpm.h" |
30 | 30 | ||
31 | #ifdef FIIO_M3K | ||
32 | # define USB_DETECT_PIN_INT GPIOB11 // TODO remove me | ||
33 | #endif | ||
34 | |||
35 | /* | 31 | /* |
36 | * USB-Designware driver API | 32 | * USB-Designware driver API |
37 | */ | 33 | */ |
@@ -150,6 +146,7 @@ void usb_dw_target_clear_irq(void) | |||
150 | 146 | ||
151 | #ifdef USB_STATUS_BY_EVENT | 147 | #ifdef USB_STATUS_BY_EVENT |
152 | static volatile int usb_status = USB_EXTRACTED; | 148 | static volatile int usb_status = USB_EXTRACTED; |
149 | static void usb_detect_interrupt(void); | ||
153 | #endif | 150 | #endif |
154 | 151 | ||
155 | static int __usb_detect(void) | 152 | static int __usb_detect(void) |
@@ -184,6 +181,7 @@ void usb_init_device(void) | |||
184 | #ifdef USB_STATUS_BY_EVENT | 181 | #ifdef USB_STATUS_BY_EVENT |
185 | /* Setup USB detect pin IRQ */ | 182 | /* Setup USB detect pin IRQ */ |
186 | usb_status = __usb_detect(); | 183 | usb_status = __usb_detect(); |
184 | system_set_irq_handler(GPIO_TO_IRQ(GPIO_USB_DETECT), usb_detect_interrupt); | ||
187 | gpio_set_function(GPIO_USB_DETECT, GPIOF_IRQ_EDGE(1)); | 185 | gpio_set_function(GPIO_USB_DETECT, GPIOF_IRQ_EDGE(1)); |
188 | gpio_flip_edge_irq(GPIO_USB_DETECT); | 186 | gpio_flip_edge_irq(GPIO_USB_DETECT); |
189 | gpio_enable_irq(GPIO_USB_DETECT); | 187 | gpio_enable_irq(GPIO_USB_DETECT); |
@@ -201,7 +199,7 @@ int usb_detect(void) | |||
201 | return usb_status; | 199 | return usb_status; |
202 | } | 200 | } |
203 | 201 | ||
204 | void USB_DETECT_PIN_INT(void) | 202 | static void usb_detect_interrupt(void) |
205 | { | 203 | { |
206 | /* Update status and flip the IRQ trigger edge */ | 204 | /* Update status and flip the IRQ trigger edge */ |
207 | usb_status = __usb_detect(); | 205 | usb_status = __usb_detect(); |