1c3ee5891SWarner Losh
2098ca2bdSWarner Losh /*-
34d846d26SWarner Losh * SPDX-License-Identifier: BSD-4-Clause AND BSD-2-Clause
4718cf2ccSPedro F. Giffuni *
5f86e6000SWarner Losh * Copyright (c) 2002 M. Warner Losh <imp@FreeBSD.org>
6c3ee5891SWarner Losh *
7c3ee5891SWarner Losh * Redistribution and use in source and binary forms, with or without
8c3ee5891SWarner Losh * modification, are permitted provided that the following conditions
9c3ee5891SWarner Losh * are met:
10c3ee5891SWarner Losh * 1. Redistributions of source code must retain the above copyright
11c3ee5891SWarner Losh * notice, this list of conditions and the following disclaimer.
12c3ee5891SWarner Losh * 2. Redistributions in binary form must reproduce the above copyright
13c3ee5891SWarner Losh * notice, this list of conditions and the following disclaimer in the
14c3ee5891SWarner Losh * documentation and/or other materials provided with the distribution.
15c3ee5891SWarner Losh *
16c3ee5891SWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17c3ee5891SWarner Losh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18c3ee5891SWarner Losh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19c3ee5891SWarner Losh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20c3ee5891SWarner Losh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21c3ee5891SWarner Losh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22c3ee5891SWarner Losh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23c3ee5891SWarner Losh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24c3ee5891SWarner Losh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25c3ee5891SWarner Losh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26c3ee5891SWarner Losh *
27c3ee5891SWarner Losh * This software may be derived from NetBSD i82365.c and other files with
28c3ee5891SWarner Losh * the following copyright:
29c3ee5891SWarner Losh *
30c3ee5891SWarner Losh * Copyright (c) 1997 Marc Horowitz. All rights reserved.
31c3ee5891SWarner Losh *
32c3ee5891SWarner Losh * Redistribution and use in source and binary forms, with or without
33c3ee5891SWarner Losh * modification, are permitted provided that the following conditions
34c3ee5891SWarner Losh * are met:
35c3ee5891SWarner Losh * 1. Redistributions of source code must retain the above copyright
36c3ee5891SWarner Losh * notice, this list of conditions and the following disclaimer.
37c3ee5891SWarner Losh * 2. Redistributions in binary form must reproduce the above copyright
38c3ee5891SWarner Losh * notice, this list of conditions and the following disclaimer in the
39c3ee5891SWarner Losh * documentation and/or other materials provided with the distribution.
40c3ee5891SWarner Losh * 3. All advertising materials mentioning features or use of this software
41c3ee5891SWarner Losh * must display the following acknowledgement:
42c3ee5891SWarner Losh * This product includes software developed by Marc Horowitz.
43c3ee5891SWarner Losh * 4. The name of the author may not be used to endorse or promote products
44c3ee5891SWarner Losh * derived from this software without specific prior written permission.
45c3ee5891SWarner Losh *
46c3ee5891SWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47c3ee5891SWarner Losh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48c3ee5891SWarner Losh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49c3ee5891SWarner Losh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50c3ee5891SWarner Losh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51c3ee5891SWarner Losh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52c3ee5891SWarner Losh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53c3ee5891SWarner Losh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54c3ee5891SWarner Losh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55c3ee5891SWarner Losh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56c3ee5891SWarner Losh */
57c3ee5891SWarner Losh
586dfd31d4SWarner Losh #ifndef _SYS_DEV_EXCA_EXCAVAR_H
596dfd31d4SWarner Losh #define _SYS_DEV_EXCA_EXCAVAR_H
606dfd31d4SWarner Losh
61c3ee5891SWarner Losh /*
62c3ee5891SWarner Losh * Structure to manage the ExCA part of the chip.
63c3ee5891SWarner Losh */
64c3ee5891SWarner Losh struct exca_softc;
65e0ba3d7eSWarner Losh typedef uint8_t (exca_getb_fn)(struct exca_softc *, int);
66e0ba3d7eSWarner Losh typedef void (exca_putb_fn)(struct exca_softc *, int, uint8_t);
67c3ee5891SWarner Losh
68c3ee5891SWarner Losh struct exca_softc
69c3ee5891SWarner Losh {
70c3ee5891SWarner Losh device_t dev;
71c3ee5891SWarner Losh int memalloc;
72c3ee5891SWarner Losh struct pccard_mem_handle mem[EXCA_MEM_WINS];
73c3ee5891SWarner Losh int ioalloc;
74c3ee5891SWarner Losh struct pccard_io_handle io[EXCA_IO_WINS];
75c3ee5891SWarner Losh bus_space_tag_t bst;
76c3ee5891SWarner Losh bus_space_handle_t bsh;
77c3ee5891SWarner Losh uint32_t flags;
78c3ee5891SWarner Losh #define EXCA_SOCKET_PRESENT 0x00000001
796dfd31d4SWarner Losh #define EXCA_HAS_MEMREG_WIN 0x00000002
80090555daSWarner Losh #define EXCA_CARD_OK 0x00000004
81cc81f0c3SWarner Losh #define EXCA_EVENT 0x80000000
82c3ee5891SWarner Losh uint32_t offset;
83e0ba3d7eSWarner Losh int chipset;
84e0ba3d7eSWarner Losh #define EXCA_CARDBUS 0
85e0ba3d7eSWarner Losh #define EXCA_I82365 1 /* Intel i82365SL-A/B or clone */
86e0ba3d7eSWarner Losh #define EXCA_I82365SL_DF 2 /* Intel i82365sl-DF step */
87e0ba3d7eSWarner Losh #define EXCA_VLSI 3 /* VLSI chip */
88e0ba3d7eSWarner Losh #define EXCA_PD6710 4 /* Cirrus logic PD6710 */
89e0ba3d7eSWarner Losh #define EXCA_PD6722 5 /* Cirrus logic PD6722 */
90e0ba3d7eSWarner Losh #define EXCA_PD6729 6 /* Cirrus Logic PD6729 */
91e0ba3d7eSWarner Losh #define EXCA_VG365 7 /* Vadem 365 */
92e0ba3d7eSWarner Losh #define EXCA_VG465 8 /* Vadem 465 */
93e0ba3d7eSWarner Losh #define EXCA_VG468 9 /* Vadem 468 */
94e0ba3d7eSWarner Losh #define EXCA_VG469 10 /* Vadem 469 */
95e0ba3d7eSWarner Losh #define EXCA_RF5C296 11 /* Ricoh RF5C296 */
96e0ba3d7eSWarner Losh #define EXCA_RF5C396 12 /* Ricoh RF5C396 */
97e0ba3d7eSWarner Losh #define EXCA_IBM 13 /* IBM clone */
98e0ba3d7eSWarner Losh #define EXCA_IBM_KING 14 /* IBM KING PCMCIA Controller */
99090555daSWarner Losh #define EXCA_BOGUS -1 /* Invalid/not present/etc */
100e0ba3d7eSWarner Losh exca_getb_fn *getb;
101e0ba3d7eSWarner Losh exca_putb_fn *putb;
102090555daSWarner Losh device_t pccarddev;
103cc81f0c3SWarner Losh uint32_t status; /* status, hw dependent */
104c3ee5891SWarner Losh };
105c3ee5891SWarner Losh
1066dfd31d4SWarner Losh void exca_init(struct exca_softc *sc, device_t dev,
1076dfd31d4SWarner Losh bus_space_tag_t, bus_space_handle_t, uint32_t);
108090555daSWarner Losh void exca_insert(struct exca_softc *sc);
109c3ee5891SWarner Losh int exca_io_map(struct exca_softc *sc, int width, struct resource *r);
110c3ee5891SWarner Losh int exca_io_unmap_res(struct exca_softc *sc, struct resource *res);
111c3ee5891SWarner Losh int exca_is_pcic(struct exca_softc *sc);
112c3ee5891SWarner Losh int exca_mem_map(struct exca_softc *sc, int kind, struct resource *res);
113c3ee5891SWarner Losh int exca_mem_set_flags(struct exca_softc *sc, struct resource *res,
114c3ee5891SWarner Losh uint32_t flags);
115c3ee5891SWarner Losh int exca_mem_set_offset(struct exca_softc *sc, struct resource *res,
116c3ee5891SWarner Losh uint32_t cardaddr, uint32_t *deltap);
117c3ee5891SWarner Losh int exca_mem_unmap_res(struct exca_softc *sc, struct resource *res);
118e0ba3d7eSWarner Losh int exca_probe_slots(device_t dev, struct exca_softc *exca,
119e0ba3d7eSWarner Losh bus_space_tag_t iot, bus_space_handle_t ioh);
120090555daSWarner Losh void exca_removal(struct exca_softc *);
121c3ee5891SWarner Losh void exca_reset(struct exca_softc *, device_t child);
122c3ee5891SWarner Losh
123090555daSWarner Losh /* bus/device interfaces */
124*2baed46eSJohn Baldwin int exca_activate_resource(struct exca_softc *exca, device_t child,
125*2baed46eSJohn Baldwin struct resource *res);
126*2baed46eSJohn Baldwin int exca_deactivate_resource(struct exca_softc *exca, device_t child,
127*2baed46eSJohn Baldwin struct resource *res);
128090555daSWarner Losh
129c3ee5891SWarner Losh static __inline uint8_t
exca_getb(struct exca_softc * sc,int reg)130e0ba3d7eSWarner Losh exca_getb(struct exca_softc *sc, int reg)
131c3ee5891SWarner Losh {
132e0ba3d7eSWarner Losh return (sc->getb(sc, reg));
133c3ee5891SWarner Losh }
134c3ee5891SWarner Losh
135c3ee5891SWarner Losh static __inline void
exca_putb(struct exca_softc * sc,int reg,uint8_t val)136e0ba3d7eSWarner Losh exca_putb(struct exca_softc *sc, int reg, uint8_t val)
137c3ee5891SWarner Losh {
138e0ba3d7eSWarner Losh sc->putb(sc, reg, val);
139c3ee5891SWarner Losh }
140c3ee5891SWarner Losh
141c3ee5891SWarner Losh static __inline void
exca_setb(struct exca_softc * sc,int reg,uint8_t mask)142c3ee5891SWarner Losh exca_setb(struct exca_softc *sc, int reg, uint8_t mask)
143c3ee5891SWarner Losh {
144e0ba3d7eSWarner Losh exca_putb(sc, reg, exca_getb(sc, reg) | mask);
145c3ee5891SWarner Losh }
146c3ee5891SWarner Losh
147c3ee5891SWarner Losh static __inline void
exca_clrb(struct exca_softc * sc,int reg,uint8_t mask)148c3ee5891SWarner Losh exca_clrb(struct exca_softc *sc, int reg, uint8_t mask)
149c3ee5891SWarner Losh {
150e0ba3d7eSWarner Losh exca_putb(sc, reg, exca_getb(sc, reg) & ~mask);
151c3ee5891SWarner Losh }
1526dfd31d4SWarner Losh
1531187f0caSWarner Losh enum {
1541187f0caSWarner Losh EXCA_IVAR_SLOT = 100,
1551187f0caSWarner Losh };
1561187f0caSWarner Losh
1571187f0caSWarner Losh #define EXCA_ACCESSOR(A, B, T) \
1581187f0caSWarner Losh static inline int \
1591187f0caSWarner Losh exca_get_ ## A(device_t dev, T *t) \
1601187f0caSWarner Losh { \
1611187f0caSWarner Losh return BUS_READ_IVAR(device_get_parent(dev), dev, \
1621187f0caSWarner Losh EXCA_IVAR_ ## B, (uintptr_t *) t); \
1631187f0caSWarner Losh }
1641187f0caSWarner Losh
1651187f0caSWarner Losh EXCA_ACCESSOR(slot, SLOT, uint32_t)
1666dfd31d4SWarner Losh #endif /* !_SYS_DEV_EXCA_EXCAVAR_H */
167