[BACK]Return to sa11x1_pcic.c CVS log [TXT][DIR] Up to [local] / sys / arch / arm / sa11x0

Annotation of sys/arch/arm/sa11x0/sa11x1_pcic.c, Revision 1.1.1.1

1.1       nbrk        1: /*      $NetBSD: sa11x1_pcic.c,v 1.16 2007/10/17 19:53:43 garbled Exp $        */
                      2:
                      3: /*-
                      4:  * Copyright (c) 2001 The NetBSD Foundation, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by IWAMOTO Toshihiro.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *        This product includes software developed by the NetBSD
                     21:  *        Foundation, Inc. and its contributors.
                     22:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     23:  *    contributors may be used to endorse or promote products derived
                     24:  *    from this software without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39: #include <sys/cdefs.h>
                     40: __KERNEL_RCSID(0, "$NetBSD: sa11x1_pcic.c,v 1.16 2007/10/17 19:53:43 garbled Exp $");
                     41:
                     42: #include <sys/param.h>
                     43: #include <sys/systm.h>
                     44: #include <sys/types.h>
                     45: #include <sys/conf.h>
                     46: #include <sys/file.h>
                     47: #include <sys/device.h>
                     48: #include <sys/kernel.h>
                     49: #include <sys/kthread.h>
                     50: #include <sys/malloc.h>
                     51:
                     52: #include <machine/bus.h>
                     53:
                     54: #include <dev/pcmcia/pcmciachip.h>
                     55: #include <dev/pcmcia/pcmciavar.h>
                     56: #include <arm/sa11x0/sa11x0_reg.h>
                     57: #include <arm/sa11x0/sa11x0_var.h>
                     58: #include <arm/sa11x0/sa1111_reg.h>
                     59: #include <arm/sa11x0/sa1111_var.h>
                     60: #include <arm/sa11x0/sa11x1_pcicreg.h>
                     61: #include <arm/sa11x0/sa11xx_pcicvar.h>
                     62: #include <arm/sa11x0/sa11x1_pcicvar.h>
                     63:
                     64: #include "sacpcic.h"
                     65:
                     66: static int     sacpcic_print(void *, const char *);
                     67:
                     68: void
                     69: sacpcic_attach_common(struct sacc_softc *psc, struct sacpcic_softc *sc,
                     70:     void *aux, void (* socket_setup_hook)(struct sapcic_socket *))
                     71: {
                     72:        int i;
                     73:        struct pcmciabus_attach_args paa;
                     74:
                     75:        printf("\n");
                     76:
                     77:        sc->sc_pc.sc_iot = psc->sc_iot;
                     78:        sc->sc_ioh = psc->sc_ioh;
                     79:
                     80:        for (i = 0; i < 2; i++) {
                     81:                sc->sc_socket[i].sc = (struct sapcic_softc *)sc;
                     82:                sc->sc_socket[i].socket = i;
                     83:                sc->sc_socket[i].pcictag_cookie = psc;
                     84:                sc->sc_socket[i].pcictag = NULL;
                     85:                sc->sc_socket[i].event_thread = NULL;
                     86:                sc->sc_socket[i].event = 0;
                     87:                sc->sc_socket[i].laststatus = SAPCIC_CARD_INVALID;
                     88:                sc->sc_socket[i].shutdown = 0;
                     89:
                     90:                socket_setup_hook(&sc->sc_socket[i]);
                     91:
                     92:                paa.paa_busname = "pcmcia";
                     93:                paa.pct = (pcmcia_chipset_tag_t)&sa11x0_pcmcia_functions;
                     94:                paa.pch = (pcmcia_chipset_handle_t)&sc->sc_socket[i];
                     95:                paa.iobase = 0;
                     96:                paa.iosize = 0x4000000;
                     97:
                     98:                sc->sc_socket[i].pcmcia =
                     99:                    config_found_ia(&sc->sc_pc.sc_dev, "pcmciabus", &paa,
                    100:                                    sacpcic_print);
                    101:
                    102:                sacc_intr_establish((sacc_chipset_tag_t)psc,
                    103:                                    i ? IRQ_S1_CDVALID : IRQ_S0_CDVALID,
                    104:                                    IST_EDGE_RAISE, IPL_BIO, sapcic_intr,
                    105:                                    &sc->sc_socket[i]);
                    106:
                    107:                /* create kthread */
                    108:                sapcic_kthread_create(&sc->sc_socket[i]);
                    109: #if 0 /* XXX */
                    110:                /* establish_intr should be after creating the kthread */
                    111:                config_interrupt(&sc->sc_socket[i], sapcic_config_intr);
                    112: #endif
                    113:        }
                    114: }
                    115:
                    116: int
                    117: sacpcic_print(void *aux, const char *name)
                    118: {
                    119:
                    120:        return UNCONF;
                    121: }
                    122:
                    123: int
                    124: sacpcic_read(struct sapcic_socket *so, int reg)
                    125: {
                    126:        int cr, bit;
                    127:        struct sacpcic_softc *sc = (struct sacpcic_softc *)so->sc;
                    128:
                    129:        cr = bus_space_read_4(sc->sc_pc.sc_iot, sc->sc_ioh, SACPCIC_SR);
                    130:
                    131:        switch (reg) {
                    132:        case SAPCIC_STATUS_CARD:
                    133:                bit = (so->socket ? SR_S1_CARDDETECT : SR_S0_CARDDETECT) & cr;
                    134:                if (bit)
                    135:                        return SAPCIC_CARD_INVALID;
                    136:                else
                    137:                        return SAPCIC_CARD_VALID;
                    138:
                    139:        case SAPCIC_STATUS_VS1:
                    140:                bit = (so->socket ? SR_S1_VS1 : SR_S0_VS1);
                    141:                return (bit & cr);
                    142:
                    143:        case SAPCIC_STATUS_VS2:
                    144:                bit = (so->socket ? SR_S1_VS2 : SR_S0_VS2);
                    145:                return (bit & cr);
                    146:
                    147:        case SAPCIC_STATUS_READY:
                    148:                bit = (so->socket ? SR_S1_READY : SR_S0_READY);
                    149:                return (bit & cr);
                    150:
                    151:        default:
                    152:                panic("sacpcic_read: bogus register");
                    153:        }
                    154: }
                    155:
                    156: void
                    157: sacpcic_write(struct sapcic_socket *so, int reg, int arg)
                    158: {
                    159:        int s, oldvalue, newvalue, mask;
                    160:        struct sacpcic_softc *sc = (struct sacpcic_softc *)so->sc;
                    161:
                    162:        s = splhigh();
                    163:        oldvalue = bus_space_read_4(sc->sc_pc.sc_iot, sc->sc_ioh, SACPCIC_CR);
                    164:
                    165:        switch (reg) {
                    166:        case SAPCIC_CONTROL_RESET:
                    167:                mask = so->socket ? CR_S1_RST : CR_S0_RST;
                    168:
                    169:                newvalue = (oldvalue & ~mask) | (arg ? mask : 0);
                    170:                break;
                    171:
                    172:        case SAPCIC_CONTROL_LINEENABLE:
                    173:                mask = so->socket ? CR_S1_FLT : CR_S0_FLT;
                    174:
                    175:                newvalue = (oldvalue & ~mask) | (arg ? mask : 0);
                    176:                break;
                    177:
                    178:        case SAPCIC_CONTROL_WAITENABLE:
                    179:                mask = so->socket ? CR_S1_PWAITEN : CR_S0_PWAITEN;
                    180:
                    181:                newvalue = (oldvalue & ~mask) | (arg ? mask : 0);
                    182:                break;
                    183:
                    184:        case SAPCIC_CONTROL_POWERSELECT:
                    185:                mask = so->socket ? CR_S1_PSE : CR_S0_PSE;
                    186:                newvalue = oldvalue & ~mask;
                    187:
                    188:                switch (arg) {
                    189:                case SAPCIC_POWER_3V:
                    190:                        break;
                    191:                case SAPCIC_POWER_5V:
                    192:                        newvalue |= mask;
                    193:                        break;
                    194:                default:
                    195:                        splx(s);
                    196:                        panic("sacpcic_write: bogus arg");
                    197:                }
                    198:                break;
                    199:
                    200:        default:
                    201:                splx(s);
                    202:                panic("sacpcic_write: bogus register");
                    203:        }
                    204:        bus_space_write_4(sc->sc_pc.sc_iot, sc->sc_ioh, SACPCIC_CR, newvalue);
                    205:        splx(s);
                    206: }
                    207:
                    208: void
                    209: sacpcic_clear_intr(int arg)
                    210: {
                    211:        /* sacc_intr_dispatch takes care of intr status */
                    212: }
                    213:
                    214: void *
                    215: sacpcic_intr_establish(struct sapcic_socket *so, int level,
                    216:     int (*ih_fun)(void *), void *ih_arg)
                    217: {
                    218:        int irq;
                    219:
                    220:        irq = so->socket ? IRQ_S1_READY : IRQ_S0_READY;
                    221:        return sacc_intr_establish((sacc_chipset_tag_t)so->pcictag_cookie, irq,
                    222:                                    IST_EDGE_FALL, level, ih_fun, ih_arg);
                    223: }
                    224:
                    225: void
                    226: sacpcic_intr_disestablish(struct sapcic_socket *so, void *ih)
                    227: {
                    228:        sacc_intr_disestablish((sacc_chipset_tag_t)so->pcictag_cookie, ih);
                    229: }

CVSweb