Home | History | Annotate | Line # | Download | only in ic
i82365var.h revision 1.25.4.1
      1  1.25.4.1    rpaulo /*	$NetBSD: i82365var.h,v 1.25.4.1 2006/09/09 02:50:02 rpaulo Exp $	*/
      2       1.2   thorpej 
      3       1.2   thorpej /*
      4       1.2   thorpej  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5       1.2   thorpej  *
      6       1.2   thorpej  * Redistribution and use in source and binary forms, with or without
      7       1.2   thorpej  * modification, are permitted provided that the following conditions
      8       1.2   thorpej  * are met:
      9       1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     10       1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     11       1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     13       1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     14       1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     15       1.2   thorpej  *    must display the following acknowledgement:
     16       1.2   thorpej  *	This product includes software developed by Marc Horowitz.
     17       1.2   thorpej  * 4. The name of the author may not be used to endorse or promote products
     18       1.2   thorpej  *    derived from this software without specific prior written permission.
     19       1.2   thorpej  *
     20       1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21       1.2   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22       1.2   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23       1.2   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24       1.2   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25       1.2   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26       1.2   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27       1.2   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28       1.2   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29       1.2   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30       1.2   thorpej  */
     31       1.2   thorpej 
     32       1.2   thorpej #include <sys/device.h>
     33      1.15   thorpej #include <sys/callout.h>
     34      1.14   thorpej #include <sys/lock.h>
     35       1.2   thorpej 
     36       1.2   thorpej #include <dev/pcmcia/pcmciareg.h>
     37       1.2   thorpej #include <dev/pcmcia/pcmciachip.h>
     38       1.2   thorpej 
     39       1.2   thorpej #include <dev/ic/i82365reg.h>
     40       1.2   thorpej 
     41       1.5   thorpej struct proc;
     42       1.5   thorpej 
     43       1.5   thorpej struct pcic_event {
     44       1.5   thorpej 	SIMPLEQ_ENTRY(pcic_event) pe_q;
     45       1.5   thorpej 	int pe_type;
     46       1.5   thorpej };
     47       1.5   thorpej 
     48       1.5   thorpej /* pe_type */
     49       1.5   thorpej #define	PCIC_EVENT_INSERTION	0
     50       1.5   thorpej #define	PCIC_EVENT_REMOVAL	1
     51       1.5   thorpej 
     52       1.2   thorpej struct pcic_handle {
     53       1.9    chopps 	struct device *ph_parent;
     54       1.9    chopps 	bus_space_tag_t ph_bus_t;	/* I/O or MEM?  I don't mind */
     55       1.9    chopps 	bus_space_handle_t ph_bus_h;
     56      1.22     perry 	u_int8_t (*ph_read)(struct pcic_handle *, int);
     57      1.22     perry 	void (*ph_write)(struct pcic_handle *, int, u_int8_t);
     58       1.8      haya 
     59       1.9    chopps 	int	vendor;		/* vendor of chip */
     60       1.9    chopps 	int	chip;		/* chip index 0 or 1 */
     61      1.21  drochner 	int	socket;		/* socket index 0 or 1 */
     62      1.21  drochner 	int	sock;		/* register offset */
     63       1.2   thorpej 	int	flags;
     64       1.9    chopps 	int	laststate;
     65       1.2   thorpej 	int	memalloc;
     66       1.2   thorpej 	struct {
     67       1.2   thorpej 		bus_addr_t	addr;
     68       1.2   thorpej 		bus_size_t	size;
     69       1.2   thorpej 		long		offset;
     70       1.2   thorpej 		int		kind;
     71       1.2   thorpej 	} mem[PCIC_MEM_WINS];
     72       1.2   thorpej 	int	ioalloc;
     73       1.2   thorpej 	struct {
     74       1.2   thorpej 		bus_addr_t	addr;
     75       1.2   thorpej 		bus_size_t	size;
     76       1.2   thorpej 		int		width;
     77       1.2   thorpej 	} io[PCIC_IO_WINS];
     78       1.2   thorpej 	int	ih_irq;
     79       1.2   thorpej 	struct device *pcmcia;
     80       1.5   thorpej 
     81       1.5   thorpej 	int shutdown;
     82       1.5   thorpej 	struct proc *event_thread;
     83       1.5   thorpej 	SIMPLEQ_HEAD(, pcic_event) events;
     84       1.2   thorpej };
     85       1.2   thorpej 
     86       1.2   thorpej #define	PCIC_FLAG_SOCKETP	0x0001
     87       1.2   thorpej #define	PCIC_FLAG_CARDP		0x0002
     88      1.11    chopps #define	PCIC_FLAG_ENABLED	0x0004
     89       1.7   msaitoh 
     90      1.20   mycroft #define PCIC_LASTSTATE_PRESENT	0x0001
     91       1.7   msaitoh #define PCIC_LASTSTATE_EMPTY	0x0000
     92       1.2   thorpej 
     93       1.9    chopps #define	C0SA	0
     94       1.9    chopps #define	C0SB	PCIC_SOCKET_OFFSET
     95       1.9    chopps #define	C1SA	PCIC_CHIP_OFFSET
     96       1.9    chopps #define	C1SB	PCIC_CHIP_OFFSET + PCIC_SOCKET_OFFSET
     97       1.9    chopps 
     98      1.18   mycroft #define	PCIC_VENDOR_NONE		-1
     99       1.9    chopps #define	PCIC_VENDOR_UNKNOWN		0
    100       1.9    chopps #define	PCIC_VENDOR_I82365SLR0		1
    101       1.9    chopps #define	PCIC_VENDOR_I82365SLR1		2
    102      1.18   mycroft #define	PCIC_VENDOR_CIRRUS_PD67XX	3
    103      1.18   mycroft #define PCIC_VENDOR_I82365SL_DF		4
    104      1.18   mycroft #define PCIC_VENDOR_IBM			5
    105      1.18   mycroft #define PCIC_VENDOR_IBM_KING		6
    106      1.18   mycroft #define PCIC_VENDOR_RICOH_5C296		7
    107      1.18   mycroft #define PCIC_VENDOR_RICOH_5C396		8
    108       1.2   thorpej 
    109       1.2   thorpej /*
    110       1.2   thorpej  * This is sort of arbitrary.  It merely needs to be "enough". It can be
    111       1.2   thorpej  * overridden in the conf file, anyway.
    112       1.2   thorpej  */
    113       1.2   thorpej 
    114       1.2   thorpej #define	PCIC_MEM_PAGES	4
    115       1.2   thorpej #define	PCIC_MEMSIZE	PCIC_MEM_PAGES*PCIC_MEM_PAGESIZE
    116       1.2   thorpej 
    117       1.2   thorpej #define	PCIC_NSLOTS	4
    118       1.2   thorpej 
    119       1.2   thorpej struct pcic_softc {
    120       1.2   thorpej 	struct device dev;
    121       1.2   thorpej 
    122       1.2   thorpej 	bus_space_tag_t memt;
    123       1.2   thorpej 	bus_space_handle_t memh;
    124       1.2   thorpej 	bus_space_tag_t iot;
    125       1.2   thorpej 	bus_space_handle_t ioh;
    126      1.15   thorpej 
    127      1.15   thorpej 	struct callout poll_ch;
    128      1.15   thorpej 	int poll_established;
    129       1.2   thorpej 
    130       1.2   thorpej 	pcmcia_chipset_tag_t pct;
    131      1.14   thorpej 
    132      1.14   thorpej 	struct lock sc_pcic_lock;
    133       1.2   thorpej 
    134       1.2   thorpej 	/* this needs to be large enough to hold PCIC_MEM_PAGES bits */
    135       1.2   thorpej 	int	subregionmask;
    136       1.6  christos #define PCIC_MAX_MEM_PAGES	(8 * sizeof(int))
    137       1.2   thorpej 
    138       1.2   thorpej 	/* used by memory window mapping functions */
    139       1.2   thorpej 	bus_addr_t membase;
    140       1.2   thorpej 
    141       1.2   thorpej 	/*
    142       1.2   thorpej 	 * used by io window mapping functions.  These can actually overlap
    143       1.2   thorpej 	 * with another pcic, since the underlying extent mapper will deal
    144       1.2   thorpej 	 * with individual allocations.  This is here to deal with the fact
    145       1.2   thorpej 	 * that different busses have different real widths (different pc
    146       1.2   thorpej 	 * hardware seems to use 10 or 12 bits for the I/O bus).
    147       1.2   thorpej 	 */
    148       1.2   thorpej 	bus_addr_t iobase;
    149       1.2   thorpej 	bus_addr_t iosize;
    150       1.2   thorpej 
    151       1.2   thorpej 	int	irq;
    152       1.2   thorpej 	void	*ih;
    153       1.2   thorpej 
    154       1.2   thorpej 	struct pcic_handle handle[PCIC_NSLOTS];
    155       1.9    chopps 
    156       1.9    chopps 	/* for use by underlying chip code for discovering irqs */
    157      1.12   mycroft 	int intr_detect, intr_false;
    158       1.9    chopps 	int intr_mask[PCIC_NSLOTS / 2];	/* probed intterupts if possible */
    159       1.2   thorpej };
    160       1.2   thorpej 
    161       1.2   thorpej 
    162      1.22     perry int	pcic_ident_ok(int);
    163      1.22     perry int	pcic_vendor(struct pcic_handle *);
    164      1.23  christos const char *pcic_vendor_to_string(int);
    165      1.22     perry 
    166      1.22     perry void	pcic_attach(struct pcic_softc *);
    167      1.22     perry void	pcic_attach_sockets(struct pcic_softc *);
    168      1.22     perry void	pcic_attach_sockets_finish(struct pcic_softc *);
    169      1.22     perry int	pcic_intr(void *arg);
    170       1.2   thorpej 
    171       1.8      haya /*
    172  1.25.4.1    rpaulo static __inline int pcic_read(struct pcic_handle *, int);
    173  1.25.4.1    rpaulo static __inline void pcic_write(struct pcic_handle *, int, u_int8_t);
    174       1.8      haya */
    175       1.2   thorpej 
    176      1.22     perry int	pcic_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
    177      1.22     perry 	    struct pcmcia_mem_handle *);
    178      1.22     perry void	pcic_chip_mem_free(pcmcia_chipset_handle_t,
    179      1.22     perry 	    struct pcmcia_mem_handle *);
    180      1.22     perry int	pcic_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    181      1.22     perry 	    bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
    182      1.22     perry void	pcic_chip_mem_unmap(pcmcia_chipset_handle_t, int);
    183      1.22     perry 
    184      1.22     perry int	pcic_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
    185      1.22     perry 	    bus_size_t, bus_size_t, struct pcmcia_io_handle *);
    186      1.22     perry void	pcic_chip_io_free(pcmcia_chipset_handle_t,
    187      1.22     perry 	    struct pcmcia_io_handle *);
    188      1.22     perry int	pcic_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
    189      1.22     perry 	    bus_size_t, struct pcmcia_io_handle *, int *);
    190      1.22     perry void	pcic_chip_io_unmap(pcmcia_chipset_handle_t, int);
    191      1.22     perry 
    192      1.22     perry void	pcic_chip_socket_enable(pcmcia_chipset_handle_t);
    193      1.22     perry void	pcic_chip_socket_disable(pcmcia_chipset_handle_t);
    194      1.22     perry void	pcic_chip_socket_settype(pcmcia_chipset_handle_t, int);
    195       1.2   thorpej 
    196       1.8      haya #if 0
    197       1.8      haya 
    198  1.25.4.1    rpaulo static __inline int pcic_read(struct pcic_handle *, int);
    199  1.25.4.1    rpaulo static __inline int
    200       1.2   thorpej pcic_read(h, idx)
    201       1.2   thorpej 	struct pcic_handle *h;
    202       1.2   thorpej 	int idx;
    203       1.2   thorpej {
    204       1.2   thorpej 	if (idx != -1)
    205       1.2   thorpej 		bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_INDEX,
    206       1.2   thorpej 		    h->sock + idx);
    207       1.2   thorpej 	return (bus_space_read_1(h->sc->iot, h->sc->ioh, PCIC_REG_DATA));
    208       1.2   thorpej }
    209       1.2   thorpej 
    210  1.25.4.1    rpaulo static __inline void pcic_write(struct pcic_handle *, int, int);
    211  1.25.4.1    rpaulo static __inline void
    212       1.2   thorpej pcic_write(h, idx, data)
    213       1.2   thorpej 	struct pcic_handle *h;
    214       1.2   thorpej 	int idx;
    215       1.2   thorpej 	int data;
    216       1.2   thorpej {
    217       1.2   thorpej 	if (idx != -1)
    218       1.2   thorpej 		bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_INDEX,
    219       1.2   thorpej 		    h->sock + idx);
    220       1.2   thorpej 	bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_DATA, (data));
    221       1.2   thorpej }
    222       1.8      haya #else
    223       1.8      haya #define pcic_read(h, idx) \
    224       1.8      haya 	(*(h)->ph_read)((h), (idx))
    225       1.8      haya 
    226       1.8      haya #define pcic_write(h, idx, data) \
    227       1.8      haya 	(*(h)->ph_write)((h), (idx), (data))
    228       1.8      haya 
    229       1.8      haya #endif
    230