Home | History | Annotate | Line # | Download | only in ic
      1  1.15  riastrad /*	$NetBSD: tcic2var.h,v 1.15 2020/03/05 15:18:55 riastradh 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.12    cegger 	device_t 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.13       chs 	device_t sc_dev;
    100   1.1       bad 	bus_space_tag_t memt;
    101   1.1       bad 	bus_space_handle_t memh;
    102   1.1       bad 	bus_space_tag_t iot;
    103   1.1       bad 	bus_space_handle_t ioh;
    104   1.1       bad 
    105   1.1       bad 	int	chipid;
    106   1.1       bad 	int	validirqs;
    107   1.1       bad 	int	pwrena;		/* holds TCIC_PWR_ENA on'084 and successors */
    108   1.1       bad 
    109   1.1       bad 	/* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */
    110   1.1       bad 	void	*intr_est;
    111   1.1       bad 
    112   1.1       bad 	pcmcia_chipset_tag_t pct;
    113   1.1       bad 
    114   1.1       bad 	/* this needs to be large enough to hold TCIC_MEM_PAGES bits */
    115   1.1       bad 	int	subregionmask;
    116   1.1       bad 
    117   1.1       bad 	/* used by memory window mapping functions */
    118   1.1       bad 	bus_addr_t membase;
    119   1.1       bad 	int	memsize2;		/* int(log2(memsize)) */
    120   1.1       bad 
    121   1.1       bad 	/*
    122   1.1       bad 	 * used by io window mapping functions.  These can actually overlap
    123   1.1       bad 	 * with another tcic, since the underlying extent mapper will deal
    124   1.1       bad 	 * with individual allocations.  This is here to deal with the fact
    125   1.1       bad 	 * that different busses have different real widths (different pc
    126   1.1       bad 	 * hardware seems to use 10 or 12 bits for the I/O bus).
    127   1.1       bad 	 */
    128   1.1       bad 	bus_addr_t iobase;
    129   1.1       bad 	bus_size_t iosize;
    130   1.1       bad 
    131   1.1       bad 	int	irq;
    132   1.1       bad 	void	*ih;
    133   1.1       bad 
    134   1.1       bad 	struct tcic_handle handle[TCIC_NSLOTS];
    135   1.1       bad };
    136   1.1       bad 
    137   1.4     perry int	tcic_log2(u_int);
    138   1.4     perry int	tcic_ns2wscnt(int);
    139   1.1       bad 
    140   1.4     perry int	tcic_check_reserved_bits(bus_space_tag_t, bus_space_handle_t);
    141   1.4     perry int	tcic_chipid(bus_space_tag_t, bus_space_handle_t);
    142   1.4     perry int	tcic_chipid_known(int);
    143   1.5  christos const char *tcic_chipid_to_string(int);
    144   1.4     perry int	tcic_validirqs(int);
    145   1.4     perry 
    146   1.4     perry void	tcic_attach(struct tcic_softc *);
    147   1.4     perry void	tcic_attach_sockets(struct tcic_softc *);
    148   1.4     perry int	tcic_intr(void *arg);
    149   1.4     perry 
    150   1.8     perry static __inline int tcic_read_1(struct tcic_handle *, int);
    151   1.8     perry static __inline int tcic_read_2(struct tcic_handle *, int);
    152   1.8     perry static __inline int tcic_read_4(struct tcic_handle *, int);
    153   1.8     perry static __inline void tcic_write_1(struct tcic_handle *, int, int);
    154   1.8     perry static __inline void tcic_write_2(struct tcic_handle *, int, int);
    155   1.8     perry static __inline void tcic_write_4(struct tcic_handle *, int, int);
    156   1.8     perry static __inline int tcic_read_ind_2(struct tcic_handle *, int);
    157   1.8     perry static __inline void tcic_write_ind_2(struct tcic_handle *, int, int);
    158   1.8     perry static __inline void tcic_sel_sock(struct tcic_handle *);
    159   1.8     perry static __inline void tcic_wait_ready(struct tcic_handle *);
    160   1.8     perry static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
    161   1.8     perry static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
    162   1.8     perry static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
    163   1.8     perry static __inline void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
    164   1.4     perry 
    165   1.4     perry int	tcic_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
    166   1.4     perry 	    struct pcmcia_mem_handle *);
    167   1.4     perry void	tcic_chip_mem_free(pcmcia_chipset_handle_t,
    168   1.4     perry 	    struct pcmcia_mem_handle *);
    169   1.4     perry int	tcic_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    170   1.4     perry 	    bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
    171   1.4     perry void	tcic_chip_mem_unmap(pcmcia_chipset_handle_t, int);
    172   1.4     perry 
    173   1.4     perry int	tcic_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
    174   1.4     perry 	    bus_size_t, bus_size_t, struct pcmcia_io_handle *);
    175   1.4     perry void	tcic_chip_io_free(pcmcia_chipset_handle_t,
    176   1.4     perry 	    struct pcmcia_io_handle *);
    177   1.4     perry int	tcic_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    178   1.4     perry 	    bus_size_t, struct pcmcia_io_handle *, int *);
    179   1.4     perry void	tcic_chip_io_unmap(pcmcia_chipset_handle_t, int);
    180   1.4     perry 
    181   1.4     perry void	tcic_chip_socket_enable(pcmcia_chipset_handle_t);
    182   1.4     perry void	tcic_chip_socket_disable(pcmcia_chipset_handle_t);
    183   1.4     perry void	tcic_chip_socket_settype(pcmcia_chipset_handle_t, int);
    184   1.1       bad 
    185   1.8     perry static __inline int tcic_read_1(struct tcic_handle *, int);
    186   1.8     perry static __inline int
    187  1.11    cegger tcic_read_1(struct tcic_handle *h, int reg)
    188   1.1       bad {
    189   1.1       bad 	return (bus_space_read_1(h->sc->iot, h->sc->ioh, reg));
    190   1.1       bad }
    191   1.1       bad 
    192   1.8     perry static __inline int tcic_read_2(struct tcic_handle *, int);
    193   1.8     perry static __inline int
    194  1.11    cegger tcic_read_2(struct tcic_handle *h, int reg)
    195   1.1       bad {
    196   1.1       bad 	return (bus_space_read_2(h->sc->iot, h->sc->ioh, reg));
    197   1.1       bad }
    198   1.1       bad 
    199   1.8     perry static __inline int tcic_read_4(struct tcic_handle *, int);
    200   1.8     perry static __inline int
    201  1.11    cegger tcic_read_4(struct tcic_handle *h, int reg)
    202   1.1       bad {
    203   1.1       bad 	int val;
    204   1.1       bad 	val = bus_space_read_2(h->sc->iot, h->sc->ioh, reg);
    205   1.1       bad 	val |= bus_space_read_2(h->sc->iot, h->sc->ioh, reg+2) << 16;
    206   1.1       bad 	return val;
    207   1.1       bad }
    208   1.1       bad 
    209   1.8     perry static __inline void tcic_write_1(struct tcic_handle *, int, int);
    210   1.8     perry static __inline void
    211  1.11    cegger tcic_write_1(struct tcic_handle *h, int reg, int data)
    212   1.1       bad {
    213   1.1       bad 	bus_space_write_1(h->sc->iot, h->sc->ioh, reg, (data));
    214   1.1       bad }
    215   1.1       bad 
    216   1.8     perry static __inline void tcic_write_2(struct tcic_handle *, int, int);
    217   1.8     perry static __inline void
    218  1.11    cegger tcic_write_2(struct tcic_handle *h, int reg, int data)
    219   1.1       bad {
    220   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
    221   1.1       bad }
    222   1.1       bad 
    223   1.8     perry static __inline void tcic_write_4(struct tcic_handle *, int, int);
    224   1.8     perry static __inline void
    225  1.11    cegger tcic_write_4(struct tcic_handle *h, int reg, int data)
    226   1.1       bad {
    227   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
    228   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, reg+2, (data)>>16);
    229   1.1       bad }
    230   1.1       bad 
    231   1.8     perry static __inline int tcic_read_ind_2(struct tcic_handle *, int);
    232   1.8     perry static __inline int
    233  1.11    cegger tcic_read_ind_2(struct tcic_handle *h, int reg)
    234   1.1       bad {
    235   1.1       bad 	int r_addr, val;
    236   1.1       bad 	r_addr = tcic_read_4(h, TCIC_R_ADDR);
    237   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
    238   1.1       bad 	val = bus_space_read_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA);
    239   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, r_addr);
    240   1.1       bad 	return val;
    241   1.1       bad }
    242   1.1       bad 
    243   1.8     perry static __inline void tcic_write_ind_2(struct tcic_handle *, int, int);
    244   1.8     perry static __inline void
    245  1.11    cegger tcic_write_ind_2(struct tcic_handle *h, int reg, int data)
    246   1.1       bad {
    247   1.1       bad 	int r_addr;
    248   1.1       bad 	r_addr = tcic_read_4(h, TCIC_R_ADDR);
    249   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
    250   1.1       bad 	bus_space_write_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA, (data));
    251   1.1       bad 	tcic_write_4(h, TCIC_R_ADDR, r_addr);
    252   1.1       bad }
    253   1.1       bad 
    254   1.8     perry static __inline void tcic_sel_sock(struct tcic_handle *);
    255   1.8     perry static __inline void
    256  1.11    cegger tcic_sel_sock(struct tcic_handle *h)
    257   1.1       bad {
    258   1.1       bad 	int r_addr;
    259   1.1       bad 	r_addr = tcic_read_2(h, TCIC_R_ADDR2);
    260   1.1       bad 	tcic_write_2(h, TCIC_R_ADDR2,
    261   1.1       bad 	    (h->sock<<TCIC_ADDR2_SS_SHFT)|(r_addr & ~TCIC_ADDR2_SS_MASK));
    262   1.1       bad }
    263   1.1       bad 
    264   1.8     perry static __inline void tcic_wait_ready(struct tcic_handle *);
    265   1.8     perry static __inline void
    266  1.11    cegger tcic_wait_ready(struct tcic_handle *h)
    267   1.1       bad {
    268   1.1       bad 	int i;
    269   1.1       bad 
    270   1.1       bad 	/* XXX appropriate socket must have been selected already. */
    271   1.1       bad 	for (i = 0; i < 10000; i++) {
    272   1.1       bad 		if (tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_RDY)
    273   1.1       bad 			return;
    274   1.1       bad 		delay(500);
    275   1.1       bad 	}
    276   1.1       bad 
    277   1.1       bad #ifdef DIAGNOSTIC
    278   1.1       bad 	printf("tcic_wait_ready ready never happened\n");
    279   1.1       bad #endif
    280   1.1       bad }
    281   1.1       bad 
    282   1.8     perry static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
    283   1.8     perry static __inline int
    284  1.11    cegger tcic_read_aux_1(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int reg)
    285   1.1       bad {
    286   1.1       bad 	int mode, val;
    287   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    288   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    289   1.1       bad 	val = bus_space_read_1(iot, ioh, reg);
    290   1.1       bad 	return val;
    291   1.1       bad }
    292   1.1       bad 
    293   1.8     perry static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
    294   1.8     perry static __inline int
    295  1.11    cegger tcic_read_aux_2(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg)
    296   1.1       bad {
    297   1.1       bad 	int mode, val;
    298   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    299   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    300   1.1       bad 	val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
    301   1.1       bad 	return val;
    302   1.1       bad }
    303   1.1       bad 
    304   1.8     perry static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
    305   1.8     perry static __inline void
    306  1.11    cegger tcic_write_aux_1(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int reg, int val)
    307   1.1       bad {
    308   1.1       bad 	int mode;
    309   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    310   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    311   1.1       bad 	bus_space_write_1(iot, ioh, reg, val);
    312   1.1       bad }
    313   1.1       bad 
    314   1.8     perry static __inline void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
    315   1.8     perry static __inline void
    316  1.11    cegger tcic_write_aux_2(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int val)
    317   1.1       bad {
    318   1.1       bad 	int mode;
    319   1.1       bad 	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
    320   1.1       bad 	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
    321   1.1       bad 	bus_space_write_2(iot, ioh, TCIC_R_AUX, val);
    322   1.1       bad }
    323   1.1       bad 
    324   1.1       bad #endif	/* _TCIC2VAR_H */
    325