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/msc-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/msc-x1000.c')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/msc-x1000.c | 47 |
1 files changed, 10 insertions, 37 deletions
diff --git a/firmware/target/mips/ingenic_x1000/msc-x1000.c b/firmware/target/mips/ingenic_x1000/msc-x1000.c index b8f23053dc..92b3d4206a 100644 --- a/firmware/target/mips/ingenic_x1000/msc-x1000.c +++ b/firmware/target/mips/ingenic_x1000/msc-x1000.c | |||
@@ -48,7 +48,8 @@ static const msc_config msc_configs[] = { | |||
48 | .msc_type = MSC_TYPE_SD, | 48 | .msc_type = MSC_TYPE_SD, |
49 | .bus_width = 4, | 49 | .bus_width = 4, |
50 | .label = "microSD", | 50 | .label = "microSD", |
51 | .cd_gpio = {GPIO_B, 1 << 6, 0}, | 51 | .cd_gpio = GPIO_MSC0_CD, |
52 | .cd_active_level = 0, | ||
52 | }, | 53 | }, |
53 | #else | 54 | #else |
54 | # error "Please add X1000 MSC config" | 55 | # error "Please add X1000 MSC config" |
@@ -117,40 +118,14 @@ static void msc_init_one(msc_drv* d, int msc) | |||
117 | msc_full_reset(d); | 118 | msc_full_reset(d); |
118 | system_enable_irq(msc == 0 ? IRQ_MSC0 : IRQ_MSC1); | 119 | system_enable_irq(msc == 0 ? IRQ_MSC0 : IRQ_MSC1); |
119 | 120 | ||
120 | /* Configure bus pins */ | ||
121 | int port, device; | ||
122 | unsigned pins; | ||
123 | if(msc == 0) { | ||
124 | port = GPIO_A; | ||
125 | device = 1; | ||
126 | switch(d->config->bus_width) { | ||
127 | case 8: pins = 0x3ff << 16; break; | ||
128 | case 4: pins = 0x03f << 20; break; | ||
129 | case 1: pins = 0x007 << 23; break; | ||
130 | default: pins = 0; break; | ||
131 | } | ||
132 | } else { | ||
133 | port = GPIO_C; | ||
134 | device = 0; | ||
135 | switch(d->config->bus_width) { | ||
136 | case 4: pins = 0x3f; break; | ||
137 | case 1: pins = 0x07; break; | ||
138 | default: pins = 0; break; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | gpio_config(port, pins, GPIO_DEVICE(device)); | ||
143 | |||
144 | /* Setup the card detect IRQ */ | 121 | /* Setup the card detect IRQ */ |
145 | if(d->config->cd_gpio.pin) { | 122 | if(d->config->cd_gpio != GPIO_NONE) { |
146 | port = d->config->cd_gpio.port; | 123 | if(gpio_get_level(d->config->cd_gpio) != d->config->cd_active_level) |
147 | pins = d->config->cd_gpio.pin; | ||
148 | int level = (REG_GPIO_PIN(port) & pins) ? 1 : 0; | ||
149 | if(level != d->config->cd_gpio.active_level) | ||
150 | d->card_present = 0; | 124 | d->card_present = 0; |
151 | 125 | ||
152 | gpio_config(port, pins, GPIO_IRQ_EDGE(level ? 0 : 1)); | 126 | gpio_set_function(d->config->cd_gpio, GPIOF_IRQ_EDGE(1)); |
153 | gpio_enable_irq(port, pins); | 127 | gpio_flip_edge_irq(d->config->cd_gpio); |
128 | gpio_enable_irq(d->config->cd_gpio); | ||
154 | } | 129 | } |
155 | } | 130 | } |
156 | 131 | ||
@@ -212,12 +187,10 @@ void msc_full_reset(msc_drv* d) | |||
212 | 187 | ||
213 | bool msc_card_detect(msc_drv* d) | 188 | bool msc_card_detect(msc_drv* d) |
214 | { | 189 | { |
215 | if(!d->config->cd_gpio.pin) | 190 | if(d->config->cd_gpio == GPIO_NONE) |
216 | return true; | 191 | return true; |
217 | 192 | ||
218 | int l = REG_GPIO_PIN(d->config->cd_gpio.port) & d->config->cd_gpio.pin; | 193 | return gpio_get_level(d->config->cd_gpio) == d->config->cd_active_level; |
219 | l = l ? 1 : 0; | ||
220 | return l == d->config->cd_gpio.active_level; | ||
221 | } | 194 | } |
222 | 195 | ||
223 | /* --------------------------------------------------------------------------- | 196 | /* --------------------------------------------------------------------------- |
@@ -661,7 +634,7 @@ static void msc_cd_interrupt(msc_drv* d) | |||
661 | } | 634 | } |
662 | 635 | ||
663 | /* Invert the IRQ */ | 636 | /* Invert the IRQ */ |
664 | REG_GPIO_PAT0(d->config->cd_gpio.port) ^= d->config->cd_gpio.pin; | 637 | gpio_flip_edge_irq(d->config->cd_gpio); |
665 | } | 638 | } |
666 | 639 | ||
667 | void MSC0(void) | 640 | void MSC0(void) |