summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/msc-x1000.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/msc-x1000.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/msc-x1000.c47
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
213bool msc_card_detect(msc_drv* d) 188bool 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
667void MSC0(void) 640void MSC0(void)