Home | History | Annotate | Line # | Download | only in ic
tcic2var.h revision 1.10
      1  1.10        ad /*	$NetBSD: tcic2var.h,v 1.10 2007/07/09 21:00:39 ad Exp $	*/
      2   1.1       bad 
      3   1.1       bad /*
      4   1.1       bad  * Copyright (c) 1998, 1999 Christoph Badura.  All rights reserved.
      5   1.1       bad  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      6   1.1       bad  *
      7   1.1       bad  * Redistribution and use in source and binary forms, with or without
      8   1.1       bad  * modification, are permitted provided that the following conditions
      9   1.1       bad  * are met:
     10   1.1       bad  * 1. Redistributions of source code must retain the above copyright
     11   1.1       bad  *    notice, this list of conditions and the following disclaimer.
     12   1.1       bad  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       bad  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       bad  *    documentation and/or other materials provided with the distribution.
     15   1.1       bad  * 3. All advertising materials mentioning features or use of this software
     16   1.1       bad  *    must display the following acknowledgement:
     17   1.1       bad  *	This product includes software developed by Marc Horowitz.
     18   1.1       bad  * 4. The name of the author may not be used to endorse or promote products
     19   1.1       bad  *    derived from this software without specific prior written permission.
     20   1.1       bad  *
     21   1.1       bad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1       bad  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1       bad  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1       bad  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1       bad  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1       bad  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1       bad  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1       bad  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1       bad  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1       bad  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1       bad  */
     32   1.1       bad 
     33   1.1       bad #ifndef _TCIC2VAR_H
     34   1.1       bad #define _TCIC2VAR_H
     35   1.1       bad 
     36   1.1       bad #include <sys/device.h>
     37   1.1       bad 
     38   1.1       bad #include <dev/pcmcia/pcmciareg.h>
     39   1.1       bad #include <dev/pcmcia/pcmciachip.h>
     40   1.1       bad 
     41   1.1       bad #include <dev/ic/tcic2reg.h>
     42   1.1       bad 
     43   1.1       bad struct proc;
     44   1.1       bad 
     45   1.1       bad struct tcic_event {
     46   1.1       bad 	SIMPLEQ_ENTRY(tcic_event) pe_q;
     47   1.1       bad 	int pe_type;
     48   1.1       bad };
     49   1.1       bad 
     50   1.1       bad /* pe_type */
     51   1.1       bad #define	TCIC_EVENT_INSERTION	0
     52   1.1       bad #define	TCIC_EVENT_REMOVAL	1
     53   1.1       bad 
     54   1.1       bad 
     55   1.1       bad struct tcic_handle {
     56   1.1       bad 	struct tcic_softc *sc;
     57   1.1       bad 	int	sock;				/* socket number */
     58   1.1       bad 	int	flags;
     59   1.1       bad 	int	sstat;				/* last value of R_SSTAT */
     60   1.1       bad 	int	memalloc;
     61   1.1       bad 	int	memwins;
     62   1.1       bad 	struct {
     63   1.1       bad 		bus_addr_t	addr;
     64   1.1       bad 		bus_size_t	size;
     65   1.1       bad 		int		size2;		/* size as 2^n scaled by 4K */
     66   1.1       bad 		long		offset;
     67   1.1       bad 		int		speed;		/* in ns */
     68   1.1       bad 		int		kind;
     69   1.1       bad 	} mem[TCIC_MAX_MEM_WINS];
     70   1.1       bad 	int	ioalloc;
     71   1.1       bad 	struct {
     72   1.1       bad 		bus_addr_t	addr;
     73   1.1       bad 		bus_size_t	size;
     74   1.1       bad 		int		width;
     75   1.1       bad 		int		speed;		/* in ns */
     76   1.1       bad 	} io[TCIC_IO_WINS];
     77   1.1       bad 	int	ih_irq;
     78   1.1       bad 	struct device *pcmcia;
     79   1.1       bad 
     80   1.1       bad 	int shutdown;
     81  1.10        ad 	struct lwp *event_thread;
     82   1.1       bad 	SIMPLEQ_HEAD(, tcic_event) events;
     83   1.1       bad };
     84   1.1       bad 
     85   1.1       bad #define	TCIC_FLAG_SOCKETP	0x0001
     86   1.1       bad #define	TCIC_FLAG_CARDP		0x0002
     87   1.1       bad 
     88   1.1       bad /*
     89   1.1       bad  * This is sort of arbitrary.  It merely needs to be "enough". It can be
     90   1.1       bad  * overridden in the conf file, anyway.
     91   1.1       bad  */
     92   1.1       bad 
     93   1.1       bad #define	TCIC_MEM_PAGES	4
     94   1.1       bad #define	TCIC_MEMSIZE	TCIC_MEM_PAGES*TCIC_MEM_PAGESIZE
     95   1.1       bad 
     96   1.1       bad #define	TCIC_NSLOTS	2
     97   1.1       bad 
     98   1.1       bad struct tcic_softc {
     99   1.1       bad 	struct device dev;
    100   1.1       bad 
    101   1.1       bad 	bus_space_tag_t memt;
    102   1.1       bad 	bus_space_handle_t memh;
    103   1.1       bad 	bus_space_tag_t iot;
    104   1.1       bad 	bus_space_handle_t ioh;
    105   1.1       bad 
    106   1.1       bad 	int	chipid;
    107   1.1       bad 	int	validirqs;
    108   1.1       bad 	int	pwrena;		/* holds TCIC_PWR_ENA on'084 and successors */
    109   1.1       bad 
    110   1.1       bad 	/* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */
    111   1.1       bad 	void	*intr_est;
    112   1.1       bad 
    113   1.1       bad 	pcmcia_chipset_tag_t pct;
    114   1.1       bad 
    115   1.1       bad 	/* this needs to be large enough to hold TCIC_MEM_PAGES bits */
    116   1.1       bad 	int	subregionmask;
    117   1.1       bad 
    118   1.1       bad 	/* used by memory window mapping functions */
    119   1.1       bad 	bus_addr_t membase;
    120   1.1       bad 	int	memsize2;		/* int(log2(memsize)) */
    121   1.1       bad 
    122   1.1       bad 	/*
    123   1.1       bad 	 * used by io window mapping functions.  These can actually overlap
    124   1.1       bad 	 * with another tcic, since the underlying extent mapper will deal
    125   1.1       bad 	 * with individual allocations.  This is here to deal with the fact
    126   1.1       bad 	 * that different busses have different real widths (different pc
    127   1.1       bad 	 * hardware seems to use 10 or 12 bits for the I/O bus).
    128   1.1       bad 	 */
    129   1.1       bad 	bus_addr_t iobase;
    130   1.1       bad 	bus_size_t iosize;
    131   1.1       bad 
    132   1.1       bad 	int	irq;
    133   1.1       bad 	void	*ih;
    134   1.1       bad 
    135   1.1       bad 	struct tcic_handle handle[TCIC_NSLOTS];
    136   1.1       bad };
    137   1.1       bad 
    138   1.4     perry int	tcic_log2(u_int);
    139   1.4     perry int	tcic_ns2wscnt(int);
    140   1.1       bad 
    141   1.4     perry int	tcic_check_reserved_bits(bus_space_tag_t, bus_space_handle_t);
    142   1.4     perry int	tcic_chipid(bus_space_tag_t, bus_space_handle_t);
    143   1.4     perry int	tcic_chipid_known(int);
    144   1.5  christos const char *tcic_chipid_to_string(int);
    145   1.4     perry int	tcic_validirqs(int);
    146   1.4     perry 
    147   1.4     perry void	tcic_attach(struct tcic_softc *);
    148   1.4     perry void	tcic_attach_sockets(struct tcic_softc *);
    149   1.4     perry int	tcic_intr(void *arg);
    150   1.4     perry 
    151   1.8     perry static __inline int tcic_read_1(struct tcic_handle *, int);
    152   1.8     perry static __inline int tcic_read_2(struct tcic_handle *, int);
    153   1.8     perry static __inline int tcic_read_4(struct tcic_handle *, int);
    154   1.8     perry static __inline void tcic_write_1(struct tcic_handle *, int, int);
    155   1.8     perry static __inline void tcic_write_2(struct tcic_handle *, int, int);
    156   1.8     perry static __inline void tcic_write_4(struct tcic_handle *, int, int);
    157   1.8     perry static __inline int tcic_read_ind_2(struct tcic_handle *, int);
    158   1.8     perry static __inline void tcic_write_ind_2(struct tcic_handle *, int, int);
    159   1.8     perry static __inline void tcic_sel_sock(struct tcic_handle *);
    160   1.8     perry static __inline void tcic_wait_ready(struct tcic_handle *);
    161   1.8     perry static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
    162   1.8     perry static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
    163   1.8     perry static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
    164   1.8     perry static __inline void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
    165   1.4     perry 
    166   1.4     perry int	tcic_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
    167   1.4     perry 	    struct pcmcia_mem_handle *);
    168   1.4     perry void	tcic_chip_mem_free(pcmcia_chipset_handle_t,
    169   1.4     perry 	    struct pcmcia_mem_handle *);
    170   1.4     perry int	tcic_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    171   1.4     perry 	    bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
    172   1.4     perry void	tcic_chip_mem_unmap(pcmcia_chipset_handle_t, int);
    173   1.4     perry 
    174   1.4     perry int	tcic_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
    175   1.4     perry 	    bus_size_t, bus_size_t, struct pcmcia_io_handle *);
    176   1.4     perry void	tcic_chip_io_free(pcmcia_chipset_handle_t,
    177   1.4     perry 	    struct pcmcia_io_handle *);
    178   1.4     perry int	tcic_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    179   1.4     perry 	    bus_size_t, struct pcmcia_io_handle *, int *);
    180   1.4     perry void	tcic_chip_io_unmap(pcmcia_chipset_handle_t, int);
    181   1.4     perry 
    182   1.4     perry void	tcic_chip_socket_enable(pcmcia_chipset_handle_t);
    183   1.4     perry void	tcic_chip_socket_disable(pcmcia_chipset_handle_t);
    184   1.4     perry void	tcic_chip_socket_settype(pcmcia_chipset_handle_t, int);
    185   1.1       bad 
    186   1.8     perry static __inline int tcic_read_1(struct tcic_handle *, int);
    187   1.8     perry static __inline int
    188   1.1       bad tcic_read_1(h, reg)
    189   1.1       bad 	struct tcic_handle *h;
    190   1.1       bad 	int reg;
    191   1.1       bad {
    192   1.1       bad 	return (bus_space_read_1(h->sc->iot, h->sc->ioh, reg));
    193   1.1       bad }
    194   1.1       bad 
    195   1.8     perry static __inline int tcic_read_2(struct tcic_handle *, int);
    196   1.8     perry static __inline int
    197   1.1       bad tcic_read_2(h, reg)
    198   1.1       bad 	struct tcic_handle *h;
    199   1.1       bad 	int reg;
    200   1.1       bad {
    201   1.1       bad 	return (bus_space_read_2(h->sc->iot, h->sc->ioh, reg));
    202   1.1       bad }
    203   1.1       bad 
    204   1.8     perry static __inline int tcic_read_4(struct tcic_handle *, int);
    205   1.8     perry static __inline int
    206   1.1       bad tcic_read_4(h, reg)
    207   1.1       bad 	struct tcic_handle *h;
    208   1.1       bad 	int reg;
    209   1.1       bad {
    210   1.1       bad 	int val;
    211   1.1       bad 	val = bus_space_read_2(h->sc->iot, h->sc->ioh, reg);
    212   1.1       bad 	val |= bus_space_read_2(h->sc->iot, h->sc->ioh, reg+2) << 16;
    213   1.1       bad 	return val;
    214   1.1       bad }
    215   1.1       bad 
    216   1.8     perry static __inline void tcic_write_1(struct tcic_handle *, int, int);
    217   1.8     perry static __inline void
    218   1.1       bad tcic_write_1(h, reg, data)
    219   1.1       bad 	struct tcic_handle *h;
    220   1.1       bad 	int reg;
    221   1.1       bad 	int data;
    222   1.1       bad {
    223   1.1       bad 	bus_space_write_1(h->sc->iot, h->sc->ioh, reg, (data));
    224   1.1       bad }
    225   1.1       bad 
    226   1.8     perry static __inline void tcic_write_2(struct tcic_handle *, int, int);
    227   1.8     perry static __inline void
    228   1.1       bad tcic_write_2(h, reg, data)
    229   1.1       bad 	struct tcic_handle *h;
    230   1.1       bad 	int reg;
    231   1.1       bad 	int data;
    232   1.1       bad {
    233   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
    234   1.1       bad }
    235   1.1       bad 
    236   1.8     perry static __inline void tcic_write_4(struct tcic_handle *, int, int);
    237   1.8     perry static __inline void
    238   1.1       bad tcic_write_4(h, reg, data)
    239   1.1       bad 	struct tcic_handle *h;
    240   1.1       bad 	int reg;
    241   1.1       bad 	int data;
    242   1.1       bad {
    243   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
    244   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, reg+2, (data)>>16);
    245   1.1       bad }
    246   1.1       bad 
    247   1.8     perry static __inline int tcic_read_ind_2(struct tcic_handle *, int);
    248   1.8     perry static __inline int
    249   1.1       bad tcic_read_ind_2(h, reg)
    250   1.1       bad 	struct tcic_handle *h;
    251   1.1       bad 	int reg;
    252   1.1       bad {
    253   1.1       bad 	int r_addr, val;
    254   1.1       bad 	r_addr = tcic_read_4(h, TCIC_R_ADDR);
    255   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
    256   1.1       bad 	val = bus_space_read_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA);
    257   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, r_addr);
    258   1.1       bad 	return val;
    259   1.1       bad }
    260   1.1       bad 
    261   1.8     perry static __inline void tcic_write_ind_2(struct tcic_handle *, int, int);
    262   1.8     perry static __inline void
    263   1.1       bad tcic_write_ind_2(h, reg, data)
    264   1.1       bad 	struct tcic_handle *h;
    265   1.1       bad 	int reg;
    266   1.1       bad 	int data;
    267   1.1       bad {
    268   1.1       bad 	int r_addr;
    269   1.1       bad 	r_addr = tcic_read_4(h, TCIC_R_ADDR);
    270   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
    271   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA, (data));
    272   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, r_addr);
    273   1.1       bad }
    274   1.1       bad 
    275   1.8     perry static __inline void tcic_sel_sock(struct tcic_handle *);
    276   1.8     perry static __inline void
    277   1.1       bad tcic_sel_sock(h)
    278   1.1       bad 	struct tcic_handle *h;
    279   1.1       bad {
    280   1.1       bad 	int r_addr;
    281   1.1       bad 	r_addr = tcic_read_2(h, TCIC_R_ADDR2);
    282   1.1       bad 	tcic_write_2(h, TCIC_R_ADDR2,
    283   1.1       bad 	    (h->sock<<TCIC_ADDR2_SS_SHFT)|(r_addr & ~TCIC_ADDR2_SS_MASK));
    284   1.1       bad }
    285   1.1       bad 
    286   1.8     perry static __inline void tcic_wait_ready(struct tcic_handle *);
    287   1.8     perry static __inline void
    288   1.1       bad tcic_wait_ready(h)
    289   1.1       bad 	struct tcic_handle *h;
    290   1.1       bad {
    291   1.1       bad 	int i;
    292   1.1       bad 
    293   1.1       bad 	/* XXX appropriate socket must have been selected already. */
    294   1.1       bad 	for (i = 0; i < 10000; i++) {
    295   1.1       bad 		if (tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_RDY)
    296   1.1       bad 			return;
    297   1.1       bad 		delay(500);
    298   1.1       bad 	}
    299   1.1       bad 
    300   1.1       bad #ifdef DIAGNOSTIC
    301   1.1       bad 	printf("tcic_wait_ready ready never happened\n");
    302   1.1       bad #endif
    303   1.1       bad }
    304   1.1       bad 
    305   1.8     perry static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
    306   1.8     perry static __inline int
    307   1.1       bad tcic_read_aux_1(iot, ioh, auxreg, reg)
    308   1.1       bad 	bus_space_tag_t iot;
    309   1.1       bad 	bus_space_handle_t ioh;
    310   1.1       bad 	int auxreg;
    311   1.9  christos 	int reg;
    312   1.1       bad {
    313   1.1       bad 	int mode, val;
    314   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    315   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    316   1.1       bad 	val = bus_space_read_1(iot, ioh, reg);
    317   1.1       bad 	return val;
    318   1.1       bad }
    319   1.1       bad 
    320   1.8     perry static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
    321   1.8     perry static __inline int
    322   1.1       bad tcic_read_aux_2(iot, ioh, auxreg)
    323   1.1       bad 	bus_space_tag_t iot;
    324   1.1       bad 	bus_space_handle_t ioh;
    325   1.1       bad 	int auxreg;
    326   1.1       bad {
    327   1.1       bad 	int mode, val;
    328   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    329   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    330   1.1       bad 	val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
    331   1.1       bad 	return val;
    332   1.1       bad }
    333   1.1       bad 
    334   1.8     perry static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
    335   1.8     perry static __inline void
    336   1.1       bad tcic_write_aux_1(iot, ioh, auxreg, reg, val)
    337   1.1       bad 	bus_space_tag_t iot;
    338   1.1       bad 	bus_space_handle_t ioh;
    339   1.1       bad 	int auxreg, reg, val;
    340   1.1       bad {
    341   1.1       bad 	int mode;
    342   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    343   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    344   1.1       bad 	bus_space_write_1(iot, ioh, reg, val);
    345   1.1       bad }
    346   1.1       bad 
    347   1.8     perry static __inline void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
    348   1.8     perry static __inline void
    349   1.1       bad tcic_write_aux_2(iot, ioh, auxreg, val)
    350   1.1       bad 	bus_space_tag_t iot;
    351   1.1       bad 	bus_space_handle_t ioh;
    352   1.1       bad 	int auxreg, val;
    353   1.1       bad {
    354   1.1       bad 	int mode;
    355   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    356   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    357   1.1       bad 	bus_space_write_2(iot, ioh, TCIC_R_AUX, val);
    358   1.1       bad }
    359   1.1       bad 
    360   1.1       bad #endif	/* _TCIC2VAR_H */
    361