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/usb-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/usb-x1000.c')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/usb-x1000.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/firmware/target/mips/ingenic_x1000/usb-x1000.c b/firmware/target/mips/ingenic_x1000/usb-x1000.c index 32413b0b94..1cedac4fa7 100644 --- a/firmware/target/mips/ingenic_x1000/usb-x1000.c +++ b/firmware/target/mips/ingenic_x1000/usb-x1000.c | |||
@@ -29,20 +29,9 @@ | |||
29 | #include "x1000/cpm.h" | 29 | #include "x1000/cpm.h" |
30 | 30 | ||
31 | #ifdef FIIO_M3K | 31 | #ifdef FIIO_M3K |
32 | # define USB_DETECT_PORT GPIO_B | 32 | # define USB_DETECT_PIN_INT GPIOB11 // TODO remove me |
33 | # define USB_DETECT_PIN (1 << 11) | ||
34 | # define USB_DETECT_PIN_INT GPIOB11 | ||
35 | # define USB_ID_PORT GPIO_B | ||
36 | # define USB_ID_PIN (1 << 7) | ||
37 | #else | ||
38 | # ifndef USB_NONE | ||
39 | # error "please add USB GPIO pins" | ||
40 | # endif | ||
41 | #endif | 33 | #endif |
42 | 34 | ||
43 | #define USB_DRVVBUS_PORT GPIO_B | ||
44 | #define USB_DRVVBUS_PIN (1 << 25) | ||
45 | |||
46 | /* | 35 | /* |
47 | * USB-Designware driver API | 36 | * USB-Designware driver API |
48 | */ | 37 | */ |
@@ -165,7 +154,8 @@ static volatile int usb_status = USB_EXTRACTED; | |||
165 | 154 | ||
166 | static int __usb_detect(void) | 155 | static int __usb_detect(void) |
167 | { | 156 | { |
168 | if(REG_GPIO_PIN(USB_DETECT_PORT) & USB_DETECT_PIN) | 157 | /* XXX: Do we need an active level define for this? */ |
158 | if(gpio_get_level(GPIO_USB_DETECT)) | ||
169 | return USB_INSERTED; | 159 | return USB_INSERTED; |
170 | else | 160 | else |
171 | return USB_EXTRACTED; | 161 | return USB_EXTRACTED; |
@@ -183,7 +173,7 @@ void usb_init_device(void) | |||
183 | { | 173 | { |
184 | /* Disable drvvbus pin -- it is only used when acting as a host, | 174 | /* Disable drvvbus pin -- it is only used when acting as a host, |
185 | * which Rockbox does not support */ | 175 | * which Rockbox does not support */ |
186 | gpio_config(USB_DRVVBUS_PORT, USB_DRVVBUS_PIN, GPIO_OUTPUT(0)); | 176 | gpio_set_function(GPIO_USB_DRVVBUS, GPIOF_OUTPUT(0)); |
187 | 177 | ||
188 | /* Power up the core clocks to allow writing | 178 | /* Power up the core clocks to allow writing |
189 | to some registers needed to power it down */ | 179 | to some registers needed to power it down */ |
@@ -194,9 +184,9 @@ void usb_init_device(void) | |||
194 | #ifdef USB_STATUS_BY_EVENT | 184 | #ifdef USB_STATUS_BY_EVENT |
195 | /* Setup USB detect pin IRQ */ | 185 | /* Setup USB detect pin IRQ */ |
196 | usb_status = __usb_detect(); | 186 | usb_status = __usb_detect(); |
197 | int level = (REG_GPIO_PIN(USB_DETECT_PORT) & USB_DETECT_PIN) ? 1 : 0; | 187 | gpio_set_function(GPIO_USB_DETECT, GPIOF_IRQ_EDGE(1)); |
198 | gpio_config(USB_DETECT_PORT, USB_DETECT_PIN, GPIO_IRQ_EDGE(level ? 0 : 1)); | 188 | gpio_flip_edge_irq(GPIO_USB_DETECT); |
199 | gpio_enable_irq(USB_DETECT_PORT, USB_DETECT_PIN); | 189 | gpio_enable_irq(GPIO_USB_DETECT); |
200 | #endif | 190 | #endif |
201 | } | 191 | } |
202 | 192 | ||
@@ -215,7 +205,7 @@ void USB_DETECT_PIN_INT(void) | |||
215 | { | 205 | { |
216 | /* Update status and flip the IRQ trigger edge */ | 206 | /* Update status and flip the IRQ trigger edge */ |
217 | usb_status = __usb_detect(); | 207 | usb_status = __usb_detect(); |
218 | REG_GPIO_PAT0(USB_DETECT_PORT) ^= USB_DETECT_PIN; | 208 | gpio_flip_edge_irq(GPIO_USB_DETECT); |
219 | 209 | ||
220 | /* Notify Rockbox of event */ | 210 | /* Notify Rockbox of event */ |
221 | usb_status_event(usb_status); | 211 | usb_status_event(usb_status); |