Mercurial > ecos-v3_0-branch
comparison packages/devs/pcmcia/arm/assabet/current/src/assabet_pcmcia.c @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | |
| children | bd1a71e3e476 |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // devs/pcmcia/assabet/assabet_pcmcia.c | |
| 4 // | |
| 5 // PCMCIA support (Card Services) | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Red Hat eCos Public License | |
| 12 // Version 1.1 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://www.redhat.com/ | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Configurable Operating System, | |
| 22 // released September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Red Hat. | |
| 25 // Portions created by Red Hat are | |
| 26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 27 // All Rights Reserved. | |
| 28 // ------------------------------------------- | |
| 29 // | |
| 30 //####COPYRIGHTEND#### | |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): gthomas | |
| 35 // Contributors: gthomas | |
| 36 // Date: 2000-07-06 | |
| 37 // Purpose: PCMCIA support | |
| 38 // Description: | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 // | |
| 42 //========================================================================== | |
| 43 | |
| 44 #include <pkgconf/io_pcmcia.h> | |
| 45 | |
| 46 #include <cyg/hal/hal_io.h> // IO macros | |
| 47 #include <cyg/hal/hal_arch.h> // Register state info | |
| 48 #include <cyg/hal/hal_intr.h> // HAL interrupt macros | |
| 49 | |
| 50 #ifdef CYGPKG_KERNEL | |
| 51 #include <pkgconf/kernel.h> // Configuration header | |
| 52 #include <cyg/kernel/kapi.h> | |
| 53 #else | |
| 54 #include <cyg/hal/hal_if.h> | |
| 55 #endif | |
| 56 | |
| 57 #include <cyg/io/pcmcia.h> | |
| 58 #include <cyg/infra/diag.h> | |
| 59 | |
| 60 #include <cyg/hal/hal_sa11x0.h> // Board definitions | |
| 61 #include <cyg/hal/assabet.h> | |
| 62 | |
| 63 #ifdef CYGPKG_KERNEL | |
| 64 static cyg_interrupt cf_detect_interrupt; | |
| 65 static cyg_handle_t cf_detect_interrupt_handle; | |
| 66 static cyg_interrupt cf_irq_interrupt; | |
| 67 static cyg_handle_t cf_irq_interrupt_handle; | |
| 68 | |
| 69 // This ISR is called when a CompactFlash board is inserted | |
| 70 static int | |
| 71 cf_detect_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs) | |
| 72 { | |
| 73 cyg_interrupt_mask(SA1110_CF_DETECT); | |
| 74 return (CYG_ISR_HANDLED|CYG_ISR_CALL_DSR); // Run the DSR | |
| 75 } | |
| 76 | |
| 77 // This DSR handles the board insertion | |
| 78 static void | |
| 79 cf_detect_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) | |
| 80 { | |
| 81 unsigned long new_state = *SA11X0_GPIO_PIN_LEVEL; | |
| 82 struct cf_slot *slot = (struct cf_slot *)data; | |
| 83 if ((new_state & SA1110_GPIO_CF_DETECT) == SA1110_GPIO_CF_PRESENT) { | |
| 84 slot->state = CF_SLOT_STATE_Inserted; | |
| 85 } else { | |
| 86 slot->state = CF_SLOT_STATE_Removed; // Implies powered up, etc. | |
| 87 } | |
| 88 cyg_interrupt_acknowledge(SA1110_CF_DETECT); | |
| 89 cyg_interrupt_unmask(SA1110_CF_DETECT); | |
| 90 } | |
| 91 | |
| 92 // This ISR is called when the card interrupt occurs | |
| 93 static int | |
| 94 cf_irq_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs) | |
| 95 { | |
| 96 cyg_drv_interrupt_mask(SA1110_CF_IRQ); | |
| 97 return (CYG_ISR_HANDLED|CYG_ISR_CALL_DSR); // Run the DSR | |
| 98 } | |
| 99 | |
| 100 // This DSR handles the card interrupt | |
| 101 static void | |
| 102 cf_irq_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) | |
| 103 { | |
| 104 struct cf_slot *slot = (struct cf_slot *)data; | |
| 105 // Clear interrupt [edge indication] | |
| 106 cyg_drv_interrupt_acknowledge(SA1110_CF_IRQ); | |
| 107 // Process interrupt | |
| 108 (slot->irq_handler.handler)(slot->irq_handler.param); | |
| 109 // Allow interrupts to happen again | |
| 110 cyg_drv_interrupt_unmask(SA1110_CF_IRQ); | |
| 111 } | |
| 112 #endif | |
| 113 | |
| 114 // | |
| 115 // Fill in the details of a PCMCIA slot and initialize the device | |
| 116 // | |
| 117 void | |
| 118 cf_hwr_init(struct cf_slot *slot) | |
| 119 { | |
| 120 static int int_init = 0; | |
| 121 unsigned long new_state = *SA11X0_GPIO_PIN_LEVEL; | |
| 122 if (!int_init) { | |
| 123 int_init = 1; | |
| 124 #ifdef CYGPKG_KERNEL | |
| 125 // Set up interrupts | |
| 126 cyg_interrupt_create(SA1110_CF_DETECT, | |
| 127 99, // Priority - what goes here? | |
| 128 (cyg_addrword_t) slot, // Data item passed to interrupt handler | |
| 129 (cyg_ISR_t *)cf_detect_isr, | |
| 130 (cyg_DSR_t *)cf_detect_dsr, | |
| 131 &cf_detect_interrupt_handle, | |
| 132 &cf_detect_interrupt); | |
| 133 cyg_interrupt_attach(cf_detect_interrupt_handle); | |
| 134 cyg_interrupt_configure(SA1110_CF_DETECT, true, true); // Detect either edge | |
| 135 cyg_interrupt_acknowledge(SA1110_CF_DETECT); | |
| 136 cyg_interrupt_unmask(SA1110_CF_DETECT); | |
| 137 cyg_interrupt_create(SA1110_CF_IRQ, | |
| 138 99, // Priority - what goes here? | |
| 139 (cyg_addrword_t) slot, // Data item passed to interrupt handler | |
| 140 (cyg_ISR_t *)cf_irq_isr, | |
| 141 (cyg_DSR_t *)cf_irq_dsr, | |
| 142 &cf_irq_interrupt_handle, | |
| 143 &cf_irq_interrupt); | |
| 144 cyg_interrupt_attach(cf_irq_interrupt_handle); | |
| 145 cyg_interrupt_configure(SA1110_CF_IRQ, false, false); // Falling edge | |
| 146 cyg_interrupt_acknowledge(SA1110_CF_IRQ); | |
| 147 cyg_interrupt_unmask(SA1110_CF_IRQ); | |
| 148 #endif | |
| 149 } | |
| 150 slot->attr = (unsigned char *)0x38000000; | |
| 151 slot->attr_length = 0x200; | |
| 152 slot->io = (unsigned char *)0x30000000; | |
| 153 slot->io_length = 0x04000000; | |
| 154 slot->mem = (unsigned char *)0x3C000000; | |
| 155 slot->mem_length = 0x04000000; | |
| 156 slot->int_num = SA1110_CF_IRQ; | |
| 157 // Disable CF bus & power (idle/off) | |
| 158 assabet_BCR(SA1110_BCR_CF_POWER | | |
| 159 SA1110_BCR_CF_RESET | | |
| 160 SA1110_BCR_CF_BUS, | |
| 161 SA1110_BCR_CF_POWER_OFF | | |
| 162 SA1110_BCR_CF_RESET_DISABLE | | |
| 163 SA1110_BCR_CF_BUS_OFF); | |
| 164 if ((new_state & SA1110_GPIO_CF_DETECT) == SA1110_GPIO_CF_PRESENT) { | |
| 165 slot->state = CF_SLOT_STATE_Inserted; | |
| 166 } else { | |
| 167 slot->state = CF_SLOT_STATE_Empty; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 void | |
| 172 cf_hwr_poll(struct cf_slot *slot) | |
| 173 { | |
| 174 unsigned long new_state = *SA11X0_GPIO_PIN_LEVEL; | |
| 175 if ((new_state & SA1110_GPIO_CF_DETECT) == SA1110_GPIO_CF_PRESENT) { | |
| 176 slot->state = CF_SLOT_STATE_Inserted; | |
| 177 } else { | |
| 178 slot->state = CF_SLOT_STATE_Empty; | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 static void | |
| 183 do_delay(int ticks) | |
| 184 { | |
| 185 #ifdef CYGPKG_KERNEL | |
| 186 cyg_thread_delay(ticks); | |
| 187 #else | |
| 188 CYGACC_CALL_IF_DELAY_US(10000*ticks); | |
| 189 #endif | |
| 190 } | |
| 191 | |
| 192 // | |
| 193 // Transition the card/slot to a new state | |
| 194 // note: currently only supports transitions to Ready, Empty | |
| 195 // | |
| 196 bool | |
| 197 cf_hwr_change_state(struct cf_slot *slot, int new_state) | |
| 198 { | |
| 199 int i, ptr, len; | |
| 200 unsigned char buf[64]; | |
| 201 | |
| 202 if (new_state == CF_SLOT_STATE_Ready) { | |
| 203 if (slot->state == CF_SLOT_STATE_Inserted) { | |
| 204 assabet_BCR(SA1110_BCR_CF_POWER | | |
| 205 SA1110_BCR_CF_RESET | | |
| 206 SA1110_BCR_CF_BUS, | |
| 207 SA1110_BCR_CF_POWER_ON | | |
| 208 SA1110_BCR_CF_RESET_DISABLE | | |
| 209 SA1110_BCR_CF_BUS_OFF); | |
| 210 do_delay(30); // At least 300 ms | |
| 211 slot->state = CF_SLOT_STATE_Powered; | |
| 212 assabet_BCR(SA1110_BCR_CF_POWER | | |
| 213 SA1110_BCR_CF_RESET | | |
| 214 SA1110_BCR_CF_BUS, | |
| 215 SA1110_BCR_CF_POWER_ON | | |
| 216 SA1110_BCR_CF_RESET_ENABLE | | |
| 217 SA1110_BCR_CF_BUS_ON); | |
| 218 do_delay(1); // At least 10 us | |
| 219 slot->state = CF_SLOT_STATE_Reset; | |
| 220 assabet_BCR(SA1110_BCR_CF_POWER | | |
| 221 SA1110_BCR_CF_RESET | | |
| 222 SA1110_BCR_CF_BUS, | |
| 223 SA1110_BCR_CF_POWER_ON | | |
| 224 SA1110_BCR_CF_RESET_DISABLE | | |
| 225 SA1110_BCR_CF_BUS_ON); | |
| 226 do_delay(5); // At least 20 ms | |
| 227 // Wait until the card is ready to talk | |
| 228 for (i = 0; i < 10; i++) { | |
| 229 ptr = 0; | |
| 230 if (cf_get_CIS(slot, CF_CISTPL_MANFID, buf, &len, &ptr)) { | |
| 231 slot->state = CF_SLOT_STATE_Ready; | |
| 232 break; | |
| 233 } | |
| 234 do_delay(10); | |
| 235 } | |
| 236 } | |
| 237 } | |
| 238 } |
