The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/pccard/pcic_isa.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2001 M. Warner Losh.  All Rights Reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   23  *
   24  * $FreeBSD: releng/5.2/sys/pccard/pcic_isa.c 116238 2003-06-12 04:46:43Z imp $
   25  */
   26 
   27 #define OBSOLETE_IN_6
   28 
   29 #include <sys/param.h>
   30 #include <sys/bus.h>
   31 #include <sys/kernel.h>
   32 #include <sys/module.h>
   33 #include <sys/sysctl.h>
   34 #include <sys/systm.h>
   35 
   36 #include <pccard/i82365.h>
   37 #include <pccard/cardinfo.h>
   38 #include <pccard/slot.h>
   39 #include <pccard/pcicvar.h>
   40 
   41 /* Get pnp IDs */
   42 #include <isa/isavar.h>
   43 #include <dev/pcic/i82365reg.h>
   44 
   45 #include <dev/pccard/pccardvar.h>
   46 #include "card_if.h"
   47 
   48 static struct isa_pnp_id pcic_ids[] = {
   49         {PCIC_PNP_ACTIONTEC,            NULL},          /* AEI0218 */
   50         {PCIC_PNP_IBM3765,              NULL},          /* IBM3765 */
   51         {PCIC_PNP_82365,                NULL},          /* PNP0E00 */
   52         {PCIC_PNP_CL_PD6720,            NULL},          /* PNP0E01 */
   53         {PCIC_PNP_VLSI_82C146,          NULL},          /* PNP0E02 */
   54         {PCIC_PNP_82365_CARDBUS,        NULL},          /* PNP0E03 */
   55         {PCIC_PNP_SCM_SWAPBOX,          NULL},          /* SCM0469 */ 
   56         {PCIC_NEC_PC9801_102,           NULL},          /* NEC8091 */
   57         {PCIC_NEC_PC9821RA_E01,         NULL},          /* NEC8121 */
   58         {0}
   59 };
   60 
   61 static struct {
   62         const char *name;
   63         u_int32_t flags;
   64 } bridges[] = {
   65         { "Intel i82365SL-A/B", PCIC_AB_POWER},
   66         { "IBM PCIC",           PCIC_AB_POWER},
   67         { "VLSI 82C146",        PCIC_AB_POWER},
   68         { "Cirrus logic 6722",  PCIC_PD_POWER},
   69         { "Cirrus logic 6710",  PCIC_PD_POWER},
   70         { "Vadem 365",          PCIC_VG_POWER},
   71         { "Vadem 465",          PCIC_VG_POWER},
   72         { "Vadem 468",          PCIC_VG_POWER},
   73         { "Vadem 469",          PCIC_VG_POWER},
   74         { "Ricoh RF5C296",      PCIC_RICOH_POWER},
   75         { "Ricoh RF5C396",      PCIC_RICOH_POWER},
   76         { "IBM KING",           PCIC_KING_POWER},
   77         { "Intel i82365SL-DF",  PCIC_DF_POWER}
   78 };
   79 
   80 static pcic_intr_way_t pcic_isa_intr_way;
   81 static pcic_init_t pcic_isa_init;
   82 
   83 struct pcic_chip pcic_isa_chip = {
   84         pcic_isa_intr_way,
   85         pcic_isa_intr_way,
   86         pcic_isa_mapirq,
   87         pcic_isa_init
   88 };
   89 
   90 /*
   91  *      Look for an Intel PCIC (or compatible).
   92  *      For each available slot, allocate a PC-CARD slot.
   93  */
   94 static int
   95 pcic_isa_probe(device_t dev)
   96 {
   97         int slotnum, validslots = 0;
   98         struct pcic_slot *sp;
   99         struct pcic_slot *sp0;
  100         struct pcic_slot *sp1;
  101         struct pcic_slot spsave;
  102         unsigned char c;
  103         struct resource *r;
  104         int rid;
  105         struct pcic_softc *sc;
  106         int error;
  107 
  108         /* Check isapnp ids */
  109         error = ISA_PNP_PROBE(device_get_parent(dev), dev, pcic_ids);
  110         if (error == ENXIO)
  111                 return (ENXIO);
  112 
  113         if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
  114                 bus_set_resource(dev, SYS_RES_IOPORT, 0, PCIC_PORT_0,
  115                     PCIC_NPORT);
  116         rid = 0;
  117         r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
  118         if (!r) {
  119                 if (bootverbose)
  120                         device_printf(dev, "Cannot get I/O range\n");
  121                 return (ENOMEM);
  122         }
  123 
  124         sc = (struct pcic_softc *) device_get_softc(dev);
  125         sc->dev = dev;
  126         sp = &sc->slots[0];
  127         for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
  128                 /*
  129                  *      Initialise the PCIC slot table.
  130                  */
  131                 sp->getb = pcic_getb_io;
  132                 sp->putb = pcic_putb_io;
  133                 sp->bst = rman_get_bustag(r);
  134                 sp->bsh = rman_get_bushandle(r);
  135                 sp->offset = slotnum * PCIC_SLOT_SIZE;
  136                 sp->controller = -1;
  137         }
  138 
  139         /*
  140          * Prescan for the broken VLSI chips.
  141          *
  142          * According to the Linux PCMCIA code from David Hinds,
  143          * working chipsets return 0x84 from their (correct) ID ports,
  144          * while the broken ones would need to be probed at the new
  145          * offset we set after we assume it's broken.
  146          *
  147          * Note: because of this, we may incorrectly detect a single
  148          * slot vlsi chip as an i82365sl step D.  I cannot find a
  149          * datasheet for the affected chip, so that's the best we can
  150          * do for now.
  151          */
  152         sp0 = &sc->slots[0];
  153         sp1 = &sc->slots[1];
  154         if (sp0->getb(sp0, PCIC_ID_REV) == PCIC_VLSI82C146 &&
  155             sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
  156                 spsave = *sp1;
  157                 sp1->bsh += 4;
  158                 sp1->offset = PCIC_SLOT_SIZE << 1;
  159                 if (sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
  160                         *sp1 = spsave;
  161                 } else {
  162                         sp0->controller = PCIC_VLSI;
  163                         sp1->controller = PCIC_VLSI;
  164                 }
  165         }
  166         
  167         /*
  168          * Look for normal chipsets here.
  169          */
  170         sp = &sc->slots[0];
  171         for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
  172                 /*
  173                  * see if there's a PCMCIA controller here
  174                  * Intel PCMCIA controllers use 0x82 and 0x83
  175                  * IBM clone chips use 0x88 and 0x89, apparently
  176                  */
  177                 c = sp->getb(sp, PCIC_ID_REV);
  178                 sp->revision = -1;
  179                 switch(c) {
  180                 /*
  181                  *      82365 or clones.
  182                  */
  183                 case PCIC_INTEL0:
  184                 case PCIC_INTEL1:
  185                         sp->controller = PCIC_I82365;
  186                         sp->revision = c & 1;
  187                         /*
  188                          * Check for Vadem chips by unlocking their extra
  189                          * registers and looking for valid ID.  Bit 3 in
  190                          * the ID register is normally 0, except when
  191                          * PCIC_VADEMREV is set.  Other bridges appear
  192                          * to ignore this frobbing.
  193                          */
  194                         bus_space_write_1(sp->bst, sp->bsh, PCIC_INDEX, 0x0E);
  195                         bus_space_write_1(sp->bst, sp->bsh, PCIC_INDEX, 0x37);
  196                         pcic_setb(sp, PCIC_VMISC, PCIC_VADEMREV);
  197                         c = sp->getb(sp, PCIC_ID_REV);
  198                         if (c & 0x08) {
  199                                 switch (sp->revision = c & 7) {
  200                                 case 1:
  201                                         sp->controller = PCIC_VG365;
  202                                         break;
  203                                 case 2:
  204                                         sp->controller = PCIC_VG465;
  205                                         break;
  206                                 case 3:
  207                                         sp->controller = PCIC_VG468;
  208                                         break;
  209                                 default:
  210                                         sp->controller = PCIC_VG469;
  211                                         break;
  212                                 }
  213                                 pcic_clrb(sp, PCIC_VMISC, PCIC_VADEMREV);
  214                         }
  215 
  216                         /*
  217                          * Check for RICOH RF5C[23]96 PCMCIA Controller
  218                          */
  219                         c = sp->getb(sp, PCIC_RICOH_ID);
  220                         if (c == PCIC_RID_396)
  221                                 sp->controller = PCIC_RF5C396;
  222                         else if (c == PCIC_RID_296)
  223                                 sp->controller = PCIC_RF5C296;
  224 
  225                         break;
  226                 /*
  227                  *      Intel i82365sl-DF step or maybe a vlsi 82c146
  228                  * we detected the vlsi case earlier, so if the controller
  229                  * isn't set, we know it is an i82365sl step D.
  230                  */
  231                 case PCIC_INTEL2:
  232                         if (sp->controller == -1)
  233                                 sp->controller = PCIC_I82365SL_DF;
  234                         break;
  235                 case PCIC_IBM1:
  236                 case PCIC_IBM2:
  237                         sp->controller = PCIC_IBM;
  238                         sp->revision = c & 1;
  239                         break;
  240                 case PCIC_IBM3:
  241                         sp->controller = PCIC_IBM_KING;
  242                         sp->revision = c & 1;
  243                         break;
  244                 default:
  245                         continue;
  246                 }
  247                 /*
  248                  *      Check for Cirrus logic chips.
  249                  */
  250                 sp->putb(sp, PCIC_CLCHIP, 0);
  251                 c = sp->getb(sp, PCIC_CLCHIP);
  252                 if ((c & PCIC_CLC_TOGGLE) == PCIC_CLC_TOGGLE) {
  253                         c = sp->getb(sp, PCIC_CLCHIP);
  254                         if ((c & PCIC_CLC_TOGGLE) == 0) {
  255                                 if (c & PCIC_CLC_DUAL)
  256                                         sp->controller = PCIC_PD6722;
  257                                 else
  258                                         sp->controller = PCIC_PD6710;
  259                                 sp->revision = 8 - ((c & 0x1F) >> 2);
  260                         }
  261                 }
  262                 device_set_desc(dev, bridges[(int) sp->controller].name);
  263                 sc->flags = bridges[(int) sp->controller].flags;
  264                 /*
  265                  *      OK it seems we have a PCIC or lookalike.
  266                  *      Allocate a slot and initialise the data structures.
  267                  */
  268                 validslots++;
  269                 sp->slt = (struct slot *) 1;
  270                 /*
  271                  * Modem cards send the speaker audio (dialing noises)
  272                  * to the host's speaker.  Cirrus Logic PCIC chips must
  273                  * enable this.  There is also a Low Power Dynamic Mode bit
  274                  * that claims to reduce power consumption by 30%, so
  275                  * enable it and hope for the best.
  276                  */
  277                 if (sp->controller == PCIC_PD6722) {
  278                         pcic_setb(sp, PCIC_MISC1, PCIC_MISC1_SPEAKER);
  279                         pcic_setb(sp, PCIC_MISC2, PCIC_LPDM_EN);
  280                 }
  281         }
  282         bus_release_resource(dev, SYS_RES_IOPORT, rid, r);
  283         return (validslots ? 0 : ENXIO);
  284 }
  285 
  286 static int
  287 pcic_isa_attach(device_t dev)
  288 {
  289         struct pcic_softc *sc;
  290         int rid;
  291         struct resource *r;
  292         int             irq = 0;
  293         int error;
  294 
  295         sc = device_get_softc(dev);
  296         rid = 0;
  297         r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
  298         if (!r) {
  299                 pcic_dealloc(dev);
  300                 return (ENXIO);
  301         }
  302         sc->iorid = rid;
  303         sc->iores = r;
  304         sc->csc_route = pcic_iw_isa;
  305         sc->func_route = pcic_iw_isa;
  306         sc->chip = &pcic_isa_chip;
  307 
  308         rid = 0;
  309         r = NULL;
  310         r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE);
  311         if (r == NULL && pcic_override_irq != 0) {
  312                 irq = pcic_override_irq;
  313                 r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1,
  314                     RF_ACTIVE);
  315         }
  316         if (r && ((1 << (rman_get_start(r))) & PCIC_INT_MASK_ALLOWED) == 0) {
  317                 device_printf(dev,
  318                     "Hardware does not support irq %d, trying polling.\n",
  319                     irq);
  320                 bus_release_resource(dev, SYS_RES_IRQ, rid, r);
  321                 irq = 0;
  322                 r = NULL;
  323         }
  324         sc->irqrid = rid;
  325         sc->irqres = r;
  326         irq = 0;
  327         if (r != NULL) {
  328                 error = bus_setup_intr(dev, r, INTR_TYPE_MISC,
  329                     pcic_isa_intr, (void *) sc, &sc->ih);
  330                 if (error) {
  331                         pcic_dealloc(dev);
  332                         return (error);
  333                 }
  334                 irq = rman_get_start(r);
  335                 device_printf(dev, "management irq %d\n", irq);
  336         }
  337         sc->irq = irq;
  338         if (irq == 0) {
  339                 sc->slot_poll = pcic_timeout;
  340                 sc->timeout_ch = timeout(sc->slot_poll, (void *) sc, hz/2);
  341                 device_printf(dev, "Polling mode\n");
  342         }
  343 
  344         return (pcic_attach(dev));
  345 }
  346 
  347 /*
  348  * ISA cards can only do ISA interrupts.  There's no need to do
  349  * anything but check args for sanity.
  350  */
  351 static int
  352 pcic_isa_intr_way(struct pcic_slot *sp, enum pcic_intr_way iw)
  353 {
  354         if (iw != pcic_iw_isa)
  355                 return (EINVAL);
  356         return (0);
  357 }
  358 
  359 /*
  360  * No speicial initialization is necesary for ISA cards.
  361  */
  362 static void
  363 pcic_isa_init(device_t dev)
  364 {
  365 }
  366 
  367 static device_method_t pcic_methods[] = {
  368         /* Device interface */
  369         DEVMETHOD(device_probe,         pcic_isa_probe),
  370         DEVMETHOD(device_attach,        pcic_isa_attach),
  371         DEVMETHOD(device_detach,        bus_generic_detach),
  372         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  373         DEVMETHOD(device_suspend,       bus_generic_suspend),
  374         DEVMETHOD(device_resume,        bus_generic_resume),
  375 
  376         /* Bus interface */
  377         DEVMETHOD(bus_print_child,      bus_generic_print_child),
  378         DEVMETHOD(bus_alloc_resource,   pcic_alloc_resource),
  379         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
  380         DEVMETHOD(bus_activate_resource, pcic_activate_resource),
  381         DEVMETHOD(bus_deactivate_resource, pcic_deactivate_resource),
  382         DEVMETHOD(bus_setup_intr,       pcic_setup_intr),
  383         DEVMETHOD(bus_teardown_intr,    pcic_teardown_intr),
  384 
  385         /* Card interface */
  386         DEVMETHOD(card_set_res_flags,   pcic_set_res_flags),
  387         DEVMETHOD(card_get_res_flags,   pcic_get_res_flags),
  388         DEVMETHOD(card_set_memory_offset, pcic_set_memory_offset),
  389         DEVMETHOD(card_get_memory_offset, pcic_get_memory_offset),
  390 
  391         { 0, 0 }
  392 };
  393 
  394 static driver_t pcic_driver = {
  395         "pcic",
  396         pcic_methods,
  397         sizeof(struct pcic_softc)
  398 };
  399 
  400 DRIVER_MODULE(pcic, isa, pcic_driver, pcic_devclass, 0, 0);

Cache object: 74455e26be6806d9750235e2af7a9528


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.