Subject: CardBus patches
To: None <netbsd@arresum.inka.de, jonathan@DSG.Stanford.EDU, haya@arch.sony.co.jp,>
From: Paul B Dokas <dokas@cs.umn.edu>
List: current-users
Date: 06/04/1999 11:03:48
Here's the patches that I applied to NetBSD-1.4 + the Apr 28 Cardbus
patches found in ftp://ftp.netbsd.org/pub/incoming/jonathan/

I've left in all of the debugging printf()s, so feel free to rip them
out if you don't like the overly verbose output.

Also, make *sure* that you don't attempt to use the ep driver.  It's
got some serious problems.

Paul



*** ./dev/pci/pccbb.c.orig	Tue Apr 27 14:49:19 1999
--- ./dev/pci/pccbb.c	Thu Jun  3 10:12:20 1999
***************
*** 94,105 ****
  #define CB_TOPIC95  5		/* Toshiba ToPIC95 */
  #define CB_TOPIC95B 6		/* Toshiba ToPIC95B */
  #define CB_TOPIC97  7		/* Toshiba ToPIC97 */
! #define CB_CHIPS_LAST  8	/* Sentinel */
  
  #if 0
  static char *cb_chipset_name[CB_CHIPS_LAST] = {
    "unknown", "TI 113X", "TI 12XX", "RF5C47X", "RF5C46X", "ToPIC95",
!   "ToPIC95B", "ToPIC97"
  };
  #endif
  
--- 95,107 ----
  #define CB_TOPIC95  5		/* Toshiba ToPIC95 */
  #define CB_TOPIC95B 6		/* Toshiba ToPIC95B */
  #define CB_TOPIC97  7		/* Toshiba ToPIC97 */
! #define CB_CIRRUS   8		/* Cirrus Logic CL-PD683X */
! #define CB_CHIPS_LAST  9	/* Sentinel */
  
  #if 0
  static char *cb_chipset_name[CB_CHIPS_LAST] = {
    "unknown", "TI 113X", "TI 12XX", "RF5C47X", "RF5C46X", "ToPIC95",
!   "ToPIC95B", "ToPIC97", "CL-PD 683X"
  };
  #endif
  
***************
*** 488,493 ****
--- 490,501 ----
    {MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC95B), "ToPIC97",
       CB_TOPIC97, PCCBB_PCMCIA_MEM_32},
  
+   /* Cirrus products */
+   {MAKEID(PCI_VENDOR_CIRRUS, PCI_PRODUCT_CIRRUS_CL_PD6832), "CL-PD683X",
+      CB_CIRRUS, PCCBB_PCMCIA_MEM_32},
+   {MAKEID(PCI_VENDOR_CIRRUS, PCI_PRODUCT_CIRRUS_CL_PD6833), "CL-PD683X",
+      CB_CIRRUS, PCCBB_PCMCIA_MEM_32},
+ 
    /* sentinel */
    {0 /* null id */, "unknown",
       CB_UNKNOWN, 0},
***************
*** 753,771 ****
      cba.cba_iot = pa->pa_iot;
      cba.cba_memt = pa->pa_memt;
      cba.cba_dmat = pa->pa_dmat;
  #if 0
      cba.cba_function = pa->pa_function;
  #else
      cba.cba_function = 0;
  #endif
!     cba.cba_bus = (busreg >> 8) & 0x0ff;
      cba.cba_cc = (void *)sc;
      cba.cba_cf = &pccbb_funcs;
      cba.cba_intrline = pa->pa_intrline;
  
      cba.cba_uni_parent = sc->sc_uni;
  
! #if SHOW_REGS
      cb_show_regs(sc->sc_pc, sc->sc_tag, sc->sc_base_memt, sc->sc_base_memh);
  #endif
  
--- 761,783 ----
      cba.cba_iot = pa->pa_iot;
      cba.cba_memt = pa->pa_memt;
      cba.cba_dmat = pa->pa_dmat;
+ #ifdef pciinc
+     cba.cba_pc = sc->sc_pc;
+     cba.cba_tag = sc->sc_tag;
+ #endif
  #if 0
      cba.cba_function = pa->pa_function;
  #else
      cba.cba_function = 0;
  #endif
!     cba.cba_bus = (busreg >> PCI_CB_CARDBUS_SHIFT) & PCI_CB_CARDBUS_MASK;
      cba.cba_cc = (void *)sc;
      cba.cba_cf = &pccbb_funcs;
      cba.cba_intrline = pa->pa_intrline;
  
      cba.cba_uni_parent = sc->sc_uni;
  
! #if defined SHOW_REGS
      cb_show_regs(sc->sc_pc, sc->sc_tag, sc->sc_base_memt, sc->sc_base_memh);
  #endif
  
***************
*** 858,863 ****
--- 871,901 ----
    }
  
    /*
+      Set the CardBus number and Subordinate Bus number
+    */
+   {
+     pcireg_t pci_lscp = pci_conf_read(pc, pa->pa_tag, PCI_CB_LSCP_REG);
+     int pcibus, cardbus, subordbus;
+ 
+     pcibus = PCI_CB_PCIBUS(pci_lscp);
+     cardbus = PCI_CB_CARDBUS(pci_lscp);
+     subordbus = PCI_CB_SUBORDBUS(pci_lscp);
+       
+     if (cardbus == 0x00) {
+       cardbus = 0x20 + (0x03 * sc->sc_dev.dv_unit);
+       subordbus = cardbus + 0x02;
+ 
+       pci_lscp &= ~(PCI_CB_CARDBUS_MASK << PCI_CB_CARDBUS_SHIFT);
+       pci_lscp |= (cardbus << PCI_CB_CARDBUS_SHIFT);
+       pci_lscp &= ~(PCI_CB_SUBORDBUS_MASK << PCI_CB_SUBORDBUS_SHIFT);
+       pci_lscp |= (subordbus << PCI_CB_SUBORDBUS_SHIFT);
+ 
+       pci_conf_write(pc, pa->pa_tag, PCI_CB_LSCP_REG, pci_lscp);
+     }
+     printf("CardBus location 0x%2x/0x%2x/0x%2x\n", PCI_CB_PCIBUS(pci_lscp), PCI_CB_CARDBUS(pci_lscp), PCI_CB_SUBORDBUS(pci_lscp));
+   }
+ 
+   /*
       Set PCI latency timer
     */
    {
***************
*** 2691,2696 ****
--- 2731,2741 ----
       bus_space_handle_t memh;
  {
    int i;
+   int b, d, f;
+ 
+   pci_decompose_tag(pc, tag, &b, &d, &f);
+   printf("b=%d, d=%d, f=%d\n", b, d, f);
+ 
    printf("PCI config regs:");
    for (i = 0; i < 0x50; i += 4) {
      if (i % 16 == 0) {
*** ./dev/pci/pccbbreg.h.orig	Tue Apr 27 14:49:19 1999
--- ./dev/pci/pccbbreg.h	Thu Jun  3 09:16:54 1999
***************
*** 68,73 ****
--- 68,85 ----
  #define PCI_CB_LATENCY_MASK  0xff
  #define PCI_CB_LATENCY(x) (((x) >> PCI_CB_LATENCY_SHIFT) & PCI_CB_LATENCY_MASK)
  
+ #define PCI_CB_SUBORDBUS_SHIFT 16
+ #define PCI_CB_SUBORDBUS_MASK  0xff
+ #define PCI_CB_SUBORDBUS(x) (((x) >> PCI_CB_SUBORDBUS_SHIFT) & PCI_CB_SUBORDBUS_MASK)
+ 
+ #define PCI_CB_CARDBUS_SHIFT 8
+ #define PCI_CB_CARDBUS_MASK  0xff
+ #define PCI_CB_CARDBUS(x) (((x) >> PCI_CB_CARDBUS_SHIFT) & PCI_CB_CARDBUS_MASK)
+ 
+ #define PCI_CB_PCIBUS_SHIFT 0
+ #define PCI_CB_PCIBUS_MASK  0xff
+ #define PCI_CB_PCIBUS(x) (((x) >> PCI_CB_PCIBUS_SHIFT) & PCI_CB_PCIBUS_MASK)
+ 
  
  
  /* PCI_BCR_INTR bits for generic PCI-CardBus bridge */
*** ./dev/pci/pccbbvar.h.orig	Tue Apr 27 14:49:19 1999
--- ./dev/pci/pccbbvar.h	Wed Jun  2 05:22:38 1999
***************
*** 51,62 ****
  #define CB_TOPIC95  5		/* Toshiba ToPIC95 */
  #define CB_TOPIC95B 6		/* Toshiba ToPIC95B */
  #define CB_TOPIC97  7		/* Toshiba ToPIC97 */
! #define CB_CHIPS_LAST  8	/* Sentinel */
  
  #if 0
  static char *cb_chipset_name[CB_CHIPS_LAST] = {
    "unknown", "TI 113X", "TI 12XX", "RF5C47X", "RF5C46X", "ToPIC95",
!   "ToPIC95B", "ToPIC97"
  };
  #endif
  
--- 51,63 ----
  #define CB_TOPIC95  5		/* Toshiba ToPIC95 */
  #define CB_TOPIC95B 6		/* Toshiba ToPIC95B */
  #define CB_TOPIC97  7		/* Toshiba ToPIC97 */
! #define CB_CIRRUS   8		/* */
! #define CB_CHIPS_LAST  9	/* Sentinel */
  
  #if 0
  static char *cb_chipset_name[CB_CHIPS_LAST] = {
    "unknown", "TI 113X", "TI 12XX", "RF5C47X", "RF5C46X", "ToPIC95",
!   "ToPIC95B", "ToPIC97", "CL-PD 683X"
  };
  #endif
  
*** ./dev/cardbus/cardbus.c.orig	Tue Jun  1 15:15:46 1999
--- ./dev/cardbus/cardbus.c	Thu Jun  3 16:00:42 1999
***************
*** 54,59 ****
--- 54,67 ----
  #include <dev/pci/pcivar.h>	/* XXX */
  #include <dev/pci/pcireg.h>	/* XXX */
  
+ /* #ifdef pciinc */
+ #include <dev/pci/pcidevs.h>
+ #include <dev/pcmcia/pcmciareg.h>
+ #include <dev/pcmcia/pcmciavar.h>
+ #include <dev/ic/i82365reg.h>
+ #include <dev/pci/pccbbvar.h>
+ /* #endif */
+ 
  #if defined CARDBUS_DEBUG
  #define STATIC
  #define DPRINTF(a) printf a
***************
*** 156,161 ****
--- 164,173 ----
    sc->sc_iot = cba->cba_iot;	/* CardBus I/O space tag */
    sc->sc_memt = cba->cba_memt;	/* CardBus MEM space tag */
    sc->sc_dmat = cba->cba_dmat;	/* DMA tag */
+ #ifdef pciinc
+   sc->sc_pc = cba->cba_pc;
+   sc->sc_tag = cba->cba_tag;
+ #endif
    sc->sc_cc = cba->cba_cc;
    sc->sc_cf = cba->cba_cf;
  
***************
*** 181,186 ****
--- 193,202 ----
  cardbus_attach_card(sc)
       struct cardbus_softc *sc;
  {
+ #ifdef pciinc
+   pci_chipset_tag_t pc;
+   pcitag_t pci_tag;
+ #endif
    cardbus_chipset_tag_t cc;
    cardbus_function_tag_t cf;
    int cdstatus;
***************
*** 190,195 ****
--- 206,215 ----
    u_int8_t tuple[2048];
    int function, nfunction;
  
+ #ifdef pciinc
+   pc = sc->sc_pc;
+   pci_tag = sc->sc_tag;
+ #endif
    cc = sc->sc_cc;
    cf = sc->sc_cf;
  
***************
*** 209,221 ****
--- 229,244 ----
  
    function = 0;
  
+   printf("bus=%d, device=%d, function=%d\n", sc->sc_bus, sc->sc_device, function);
    tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, function);
  
    bhlc = cardbus_conf_read(cc, cf, tag, CARDBUS_BHLC_REG);
+   printf("bhlc=0x%x before\n", bhlc);
    if (CARDBUS_LATTIMER(bhlc) < 0x10) {
      bhlc &= (CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
      bhlc |= (0x10 << CARDBUS_LATTIMER_SHIFT);
      cardbus_conf_write(cc, cf, tag, CARDBUS_BHLC_REG, bhlc);
+     printf("bhlc=0x%x after\n", bhlc);
    }
  
    nfunction = CARDBUS_HDRTYPE_MULTIFN(bhlc) ? 8 : 1;
***************
*** 235,240 ****
--- 258,286 ----
  	   CARDBUS_VENDOR(id), CARDBUS_PRODUCT(id), cis_ptr));
  
    bzero(tuple, 2048);
+ 
+   {
+     struct pccbb_softc *sc = (struct pccbb_softc *)cc;
+     int i, b, d, f;
+ 
+     pci_decompose_tag(sc->sc_pc, tag, &b, &d, &f);
+     printf("b=%d, d=%d, f=%d\n", b, d, f);
+ 
+     printf("PCI config regs:");
+     for (i = 0; i < 0x50; i += 4) {
+       if (i % 16 == 0) {
+         printf("\n 0x%02x:", i);
+       } 
+       printf(" %08x", pci_conf_read(sc->sc_pc, tag, i));
+     }
+     for (i = 0x80; i < 0xb0; i += 4) {
+       if (i % 16 == 0) {
+         printf("\n 0x%02x:", i);
+       }
+       printf(" %08x", pci_conf_read(sc->sc_pc, tag, i));
+     }
+     printf("\n");
+   }
  
    if (0 == (cis_ptr & CARDBUS_CIS_ASIMASK)) {
      int i = cis_ptr & CARDBUS_CIS_ADDRMASK;
*** ./dev/cardbus/cardbusvar.h.orig	Tue Apr 27 14:49:17 1999
--- ./dev/cardbus/cardbusvar.h	Wed Jun  2 18:25:23 1999
***************
*** 174,179 ****
--- 174,180 ----
  
  #ifdef pciinc
    pci_chipset_tag_t cba_pc;	/* XXX pci chipset */
+   pcitag_t cba_tag;		/* XXX pci chipset */
  #endif
    cardbus_chipset_tag_t cba_cc;	/* cardbus chipset */
    cardbus_function_tag_t cba_cf; /* cardbus functions */
***************
*** 205,212 ****
    bus_space_tag_t sc_iot;	/* CardBus I/O space tag */
    bus_space_tag_t sc_memt;	/* CardBus MEM space tag */
    bus_dma_tag_t sc_dmat;	/* DMA tag */
! #if pciinc
    pci_chipset_tag_t sc_pc;	/* XXX: pci chipset */
  #endif
    cardbus_chipset_tag_t sc_cc;	/* CardBus chipset */
    cardbus_function_tag_t sc_cf;	/* CardBus function */
--- 206,214 ----
    bus_space_tag_t sc_iot;	/* CardBus I/O space tag */
    bus_space_tag_t sc_memt;	/* CardBus MEM space tag */
    bus_dma_tag_t sc_dmat;	/* DMA tag */
! #ifdef pciinc
    pci_chipset_tag_t sc_pc;	/* XXX: pci chipset */
+   pcitag_t sc_tag;		/* XXX: pci chipset tag */
  #endif
    cardbus_chipset_tag_t sc_cc;	/* CardBus chipset */
    cardbus_function_tag_t sc_cf;	/* CardBus function */


--
Paul Dokas                                            dokas@cs.umn.edu
======================================================================
Don Juan Matus:  "an enigma wrapped in mystery wrapped in a tortilla."