1139749Simp/*-
2133553Simp * Copyright (c) 2003-2004 Warner Losh.
367276Sjon * Copyright (c) 2000,2001 Jonathan Chen.
467276Sjon * All rights reserved.
567276Sjon *
667276Sjon * Redistribution and use in source and binary forms, with or without
767276Sjon * modification, are permitted provided that the following conditions
867276Sjon * are met:
967276Sjon * 1. Redistributions of source code must retain the above copyright
10140197Simp *    notice, this list of conditions and the following disclaimer.
1167276Sjon * 2. Redistributions in binary form must reproduce the above copyright
12140197Simp *    notice, this list of conditions and the following disclaimer in the
13140197Simp *    documentation and/or other materials provided with the distribution.
1467276Sjon *
1567276Sjon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1667276Sjon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1767276Sjon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18140197Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19140197Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2067276Sjon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2167276Sjon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2267276Sjon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2367276Sjon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2467276Sjon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2567276Sjon * SUCH DAMAGE.
2667276Sjon *
2767276Sjon * $FreeBSD$
2867276Sjon */
2967276Sjon
3067276Sjon/*
3167276Sjon * Structure definitions for the Cardbus Bridge driver
3267276Sjon */
3367276Sjon
34104642Simpstruct cbb_intrhand {
35170163Spiso	driver_filter_t	*filt;
36116232Simp	driver_intr_t	*intr;
37116232Simp	void 		*arg;
38133553Simp	struct cbb_softc *sc;
39133553Simp	void		*cookie;
4067276Sjon};
4167276Sjon
42101904Simpstruct cbb_reslist {
43101904Simp	SLIST_ENTRY(cbb_reslist) link;
4482378Sjon	struct	resource *res;
4582375Sjon	int	type;
4682375Sjon	int	rid;
4782378Sjon		/* note: unlike the regular resource list, there can be
4882378Sjon		 * duplicate rid's in the same list.  However, the
4982378Sjon		 * combination of rid and res->r_dev should be unique.
5082378Sjon		 */
5182378Sjon	bus_addr_t cardaddr; /* for 16-bit pccard memory */
5267276Sjon};
5367276Sjon
54101904Simp#define	CBB_AUTO_OPEN_SMALLHOLE 0x100
55133553Simp#define CBB_NSLOTS		4
5667276Sjon
57101904Simpstruct cbb_softc {
5890751Simp	device_t	dev;
59133553Simp	struct exca_softc exca[CBB_NSLOTS];
6090751Simp	struct		resource *base_res;
6190751Simp	struct		resource *irq_res;
6290751Simp	void		*intrhand;
6390751Simp	bus_space_tag_t bst;
6490751Simp	bus_space_handle_t bsh;
65172394Smarius	uint32_t	domain;
66158893Simp	unsigned int	pribus;
67158893Simp	unsigned int	secbus;
68158893Simp	unsigned int	subbus;
6998156Simp	struct mtx	mtx;
70170272Simp	int		cardok;
7190751Simp	u_int32_t	flags;
72101904Simp#define	CBB_16BIT_CARD		0x20000000
73101904Simp#define	CBB_KTHREAD_RUNNING	0x40000000
74101904Simp#define	CBB_KTHREAD_DONE	0x80000000
7590751Simp	int		chipset;		/* chipset id */
7667276Sjon#define	CB_UNKNOWN	0		/* NOT Cardbus-PCI bridge */
7767276Sjon#define	CB_TI113X	1		/* TI PCI1130/1131 */
78100704Simp#define	CB_TI12XX	2		/* TI PCI12xx/14xx/44xx/15xx/45xx */
79100704Simp#define	CB_TI125X	3		/* TI PCI1250/1251(B)/1450 */
80100704Simp#define	CB_RF5C47X	4		/* RICOH RF5C475/476/477 */
81100704Simp#define	CB_RF5C46X	5		/* RICOH RF5C465/466/467 */
82100704Simp#define	CB_CIRRUS	6		/* Cirrus Logic CLPD683x */
83100704Simp#define	CB_TOPIC95	7		/* Toshiba ToPIC95 */
84100704Simp#define	CB_TOPIC97	8		/* Toshiba ToPIC97/100 */
85115887Simp#define	CB_O2MICRO	9		/* O2Micro chips */
86101904Simp	SLIST_HEAD(, cbb_reslist) rl;
8790751Simp	device_t	cbdev;
8890751Simp	struct proc	*event_thread;
89133553Simp	void (*chipinit)(struct cbb_softc *);
90185625Simp	int	powerintr;
91188701Simp	struct root_hold_token *sc_root_token;
9267276Sjon};
9367276Sjon
9469288Sjon/* result of detect_card */
9582375Sjon#define	CARD_UKN_CARD	0x00
9682375Sjon#define	CARD_5V_CARD	0x01
9782375Sjon#define	CARD_3V_CARD	0x02
9882375Sjon#define	CARD_XV_CARD	0x04
9982375Sjon#define	CARD_YV_CARD	0x08
10069288Sjon
10169288Sjon/* for power_socket */
102115986Simp#define	CARD_VCC(X)	(X)
103115986Simp#define CARD_VPP_VCC	0xf0
104115986Simp#define CARD_VCCMASK	0xf
105115986Simp#define CARD_VCCSHIFT	0
106115986Simp#define XV		2
107115986Simp#define YV		1
108115986Simp
109115986Simp#define CARD_OFF	(CARD_VCC(0))
110133553Simp
111133553Simpextern int cbb_debug;
112133553Simpextern devclass_t cbb_devclass;
113133553Simp
114133553Simpint	cbb_activate_resource(device_t brdev, device_t child,
115133553Simp	    int type, int rid, struct resource *r);
116133553Simpstruct resource	*cbb_alloc_resource(device_t brdev, device_t child,
117133553Simp	    int type, int *rid, u_long start, u_long end, u_long count,
118133553Simp	    u_int flags);
119133553Simpvoid	cbb_child_detached(device_t brdev, device_t child);
120188129Simpint	cbb_child_present(device_t parent, device_t child);
121133553Simpint	cbb_deactivate_resource(device_t brdev, device_t child,
122133553Simp	    int type, int rid, struct resource *r);
123133553Simpint	cbb_detach(device_t brdev);
124133553Simpvoid	cbb_disable_func_intr(struct cbb_softc *sc);
125133553Simpvoid	cbb_driver_added(device_t brdev, driver_t *driver);
126133553Simpvoid	cbb_event_thread(void *arg);
127133553Simpint	cbb_pcic_set_memory_offset(device_t brdev, device_t child, int rid,
128133553Simp	    uint32_t cardaddr, uint32_t *deltap);
129133553Simpint	cbb_pcic_set_res_flags(device_t brdev, device_t child, int type,
130188129Simp	    int rid, u_long flags);
131133553Simpint	cbb_power(device_t brdev, int volts);
132133553Simpint	cbb_power_enable_socket(device_t brdev, device_t child);
133188129Simpint	cbb_power_disable_socket(device_t brdev, device_t child);
134133553Simpint	cbb_read_ivar(device_t brdev, device_t child, int which,
135133553Simp	    uintptr_t *result);
136133553Simpint	cbb_release_resource(device_t brdev, device_t child,
137133553Simp	    int type, int rid, struct resource *r);
138133553Simpint	cbb_resume(device_t self);
139133553Simpint	cbb_setup_intr(device_t dev, device_t child, struct resource *irq,
140166901Spiso	    int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
141166901Spiso	    void **cookiep);
142133553Simpint	cbb_suspend(device_t self);
143133553Simpint	cbb_teardown_intr(device_t dev, device_t child, struct resource *irq,
144133553Simp	    void *cookie);
145133553Simpint	cbb_write_ivar(device_t brdev, device_t child, int which,
146133553Simp	    uintptr_t value);
147133553Simp
148133553Simp/*
149133553Simp */
150133553Simpstatic __inline void
151133553Simpcbb_set(struct cbb_softc *sc, uint32_t reg, uint32_t val)
152133553Simp{
153133553Simp	bus_space_write_4(sc->bst, sc->bsh, reg, val);
154133553Simp}
155133553Simp
156133553Simpstatic __inline uint32_t
157133553Simpcbb_get(struct cbb_softc *sc, uint32_t reg)
158133553Simp{
159133553Simp	return (bus_space_read_4(sc->bst, sc->bsh, reg));
160133553Simp}
161133553Simp
162133553Simpstatic __inline void
163133553Simpcbb_setb(struct cbb_softc *sc, uint32_t reg, uint32_t bits)
164133553Simp{
165133553Simp	cbb_set(sc, reg, cbb_get(sc, reg) | bits);
166133553Simp}
167133553Simp
168133553Simpstatic __inline void
169133553Simpcbb_clrb(struct cbb_softc *sc, uint32_t reg, uint32_t bits)
170133553Simp{
171133553Simp	cbb_set(sc, reg, cbb_get(sc, reg) & ~bits);
172133553Simp}
173