pccbbvar.h revision 185625
11590Srgrimes/*-
21590Srgrimes * Copyright (c) 2003-2004 Warner Losh.
31590Srgrimes * Copyright (c) 2000,2001 Jonathan Chen.
41590Srgrimes * All rights reserved.
51590Srgrimes *
61590Srgrimes * Redistribution and use in source and binary forms, with or without
71590Srgrimes * modification, are permitted provided that the following conditions
81590Srgrimes * are met:
91590Srgrimes * 1. Redistributions of source code must retain the above copyright
101590Srgrimes *    notice, this list of conditions and the following disclaimer.
111590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
121590Srgrimes *    notice, this list of conditions and the following disclaimer in the
131590Srgrimes *    documentation and/or other materials provided with the distribution.
141590Srgrimes *
151590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251590Srgrimes * SUCH DAMAGE.
261590Srgrimes *
271590Srgrimes * $FreeBSD: head/sys/dev/pccbb/pccbbvar.h 185625 2008-12-05 05:20:08Z imp $
281590Srgrimes */
291590Srgrimes
301590Srgrimes/*
311590Srgrimes * Structure definitions for the Cardbus Bridge driver
321590Srgrimes */
331590Srgrimes
341590Srgrimesstruct cbb_intrhand {
351590Srgrimes	driver_filter_t	*filt;
361590Srgrimes	driver_intr_t	*intr;
371590Srgrimes	void 		*arg;
381590Srgrimes	struct cbb_softc *sc;
391590Srgrimes	void		*cookie;
401590Srgrimes};
411590Srgrimes
421590Srgrimesstruct cbb_reslist {
431590Srgrimes	SLIST_ENTRY(cbb_reslist) link;
441590Srgrimes	struct	resource *res;
451590Srgrimes	int	type;
461590Srgrimes	int	rid;
471590Srgrimes		/* note: unlike the regular resource list, there can be
481590Srgrimes		 * duplicate rid's in the same list.  However, the
491590Srgrimes		 * combination of rid and res->r_dev should be unique.
501590Srgrimes		 */
511590Srgrimes	bus_addr_t cardaddr; /* for 16-bit pccard memory */
521590Srgrimes};
531590Srgrimes
541590Srgrimes#define	CBB_AUTO_OPEN_SMALLHOLE 0x100
551590Srgrimes#define CBB_NSLOTS		4
561590Srgrimes
571590Srgrimesstruct cbb_softc {
581590Srgrimes	device_t	dev;
591590Srgrimes	struct exca_softc exca[CBB_NSLOTS];
601590Srgrimes	struct		resource *base_res;
611590Srgrimes	struct		resource *irq_res;
621590Srgrimes	void		*intrhand;
631590Srgrimes	bus_space_tag_t bst;
641590Srgrimes	bus_space_handle_t bsh;
651590Srgrimes	uint32_t	domain;
661590Srgrimes	unsigned int	pribus;
671590Srgrimes	unsigned int	secbus;
681590Srgrimes	unsigned int	subbus;
691590Srgrimes	struct mtx	mtx;
701590Srgrimes	int		cardok;
711590Srgrimes	u_int32_t	flags;
721590Srgrimes#define	CBB_16BIT_CARD		0x20000000
731590Srgrimes#define	CBB_KTHREAD_RUNNING	0x40000000
741590Srgrimes#define	CBB_KTHREAD_DONE	0x80000000
751590Srgrimes	int		chipset;		/* chipset id */
766988Sdg#define	CB_UNKNOWN	0		/* NOT Cardbus-PCI bridge */
771590Srgrimes#define	CB_TI113X	1		/* TI PCI1130/1131 */
781590Srgrimes#define	CB_TI12XX	2		/* TI PCI12xx/14xx/44xx/15xx/45xx */
791590Srgrimes#define	CB_TI125X	3		/* TI PCI1250/1251(B)/1450 */
801590Srgrimes#define	CB_RF5C47X	4		/* RICOH RF5C475/476/477 */
811590Srgrimes#define	CB_RF5C46X	5		/* RICOH RF5C465/466/467 */
821590Srgrimes#define	CB_CIRRUS	6		/* Cirrus Logic CLPD683x */
831590Srgrimes#define	CB_TOPIC95	7		/* Toshiba ToPIC95 */
841590Srgrimes#define	CB_TOPIC97	8		/* Toshiba ToPIC97/100 */
851590Srgrimes#define	CB_O2MICRO	9		/* O2Micro chips */
861590Srgrimes	SLIST_HEAD(, cbb_reslist) rl;
871590Srgrimes	device_t	cbdev;
881590Srgrimes	struct proc	*event_thread;
891590Srgrimes	void (*chipinit)(struct cbb_softc *);
901590Srgrimes	int	powerintr;
911590Srgrimes};
921590Srgrimes
931590Srgrimes/* result of detect_card */
941590Srgrimes#define	CARD_UKN_CARD	0x00
951590Srgrimes#define	CARD_5V_CARD	0x01
961590Srgrimes#define	CARD_3V_CARD	0x02
971590Srgrimes#define	CARD_XV_CARD	0x04
981590Srgrimes#define	CARD_YV_CARD	0x08
991590Srgrimes
1001590Srgrimes/* for power_socket */
1011590Srgrimes#define	CARD_VCC(X)	(X)
1021590Srgrimes#define CARD_VPP_VCC	0xf0
1031590Srgrimes#define CARD_VCCMASK	0xf
1041590Srgrimes#define CARD_VCCSHIFT	0
1051590Srgrimes#define XV		2
1061590Srgrimes#define YV		1
1071590Srgrimes
1081590Srgrimes#define CARD_OFF	(CARD_VCC(0))
1091590Srgrimes
1101590Srgrimesextern int cbb_debug;
1111590Srgrimesextern devclass_t cbb_devclass;
1121590Srgrimes
1131590Srgrimesint	cbb_activate_resource(device_t brdev, device_t child,
1141590Srgrimes	    int type, int rid, struct resource *r);
1151590Srgrimesstruct resource	*cbb_alloc_resource(device_t brdev, device_t child,
1161590Srgrimes	    int type, int *rid, u_long start, u_long end, u_long count,
1171590Srgrimes	    u_int flags);
1181590Srgrimesvoid	cbb_child_detached(device_t brdev, device_t child);
1191590Srgrimesint	cbb_child_present(device_t self);
1201590Srgrimesint	cbb_deactivate_resource(device_t brdev, device_t child,
1211590Srgrimes	    int type, int rid, struct resource *r);
1221590Srgrimesint	cbb_detach(device_t brdev);
1231590Srgrimesvoid	cbb_disable_func_intr(struct cbb_softc *sc);
1241590Srgrimesvoid	cbb_driver_added(device_t brdev, driver_t *driver);
1251590Srgrimesvoid	cbb_event_thread(void *arg);
1261590Srgrimesint	cbb_pcic_set_memory_offset(device_t brdev, device_t child, int rid,
1271590Srgrimes	    uint32_t cardaddr, uint32_t *deltap);
1281590Srgrimesint	cbb_pcic_set_res_flags(device_t brdev, device_t child, int type,
1291590Srgrimes	    int rid, uint32_t flags);
1301590Srgrimesint	cbb_power(device_t brdev, int volts);
1311590Srgrimesint	cbb_power_enable_socket(device_t brdev, device_t child);
1321590Srgrimesvoid	cbb_power_disable_socket(device_t brdev, device_t child);
1331590Srgrimesint	cbb_read_ivar(device_t brdev, device_t child, int which,
1341590Srgrimes	    uintptr_t *result);
1351590Srgrimesint	cbb_release_resource(device_t brdev, device_t child,
1361590Srgrimes	    int type, int rid, struct resource *r);
1371590Srgrimesint	cbb_resume(device_t self);
1381590Srgrimesint	cbb_setup_intr(device_t dev, device_t child, struct resource *irq,
1391590Srgrimes	    int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
1401590Srgrimes	    void **cookiep);
1411590Srgrimesint	cbb_suspend(device_t self);
1421590Srgrimesint	cbb_teardown_intr(device_t dev, device_t child, struct resource *irq,
1431590Srgrimes	    void *cookie);
1441590Srgrimesint	cbb_write_ivar(device_t brdev, device_t child, int which,
1451590Srgrimes	    uintptr_t value);
1461590Srgrimes
1471590Srgrimes/*
1481590Srgrimes */
1491590Srgrimesstatic __inline void
1501590Srgrimescbb_set(struct cbb_softc *sc, uint32_t reg, uint32_t val)
1511590Srgrimes{
1521590Srgrimes	bus_space_write_4(sc->bst, sc->bsh, reg, val);
1531590Srgrimes}
1541590Srgrimes
1551590Srgrimesstatic __inline uint32_t
1561590Srgrimescbb_get(struct cbb_softc *sc, uint32_t reg)
1571590Srgrimes{
1586988Sdg	return (bus_space_read_4(sc->bst, sc->bsh, reg));
1596988Sdg}
1601590Srgrimes
1611590Srgrimesstatic __inline void
1621590Srgrimescbb_setb(struct cbb_softc *sc, uint32_t reg, uint32_t bits)
1631590Srgrimes{
1641590Srgrimes	cbb_set(sc, reg, cbb_get(sc, reg) | bits);
1651590Srgrimes}
1661590Srgrimes
1671590Srgrimesstatic __inline void
1681590Srgrimescbb_clrb(struct cbb_softc *sc, uint32_t reg, uint32_t bits)
1691590Srgrimes{
1701590Srgrimes	cbb_set(sc, reg, cbb_get(sc, reg) & ~bits);
1711590Srgrimes}
1721590Srgrimes