2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006-2007 Daniel Roethlisberger <daniel@roe.ch>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #define CMX_MIN_RDLEN 10 /* min read length */
35 #define CMX_MIN_WRLEN 5 /* min write length */
36 #define CMX_BUFSZ 512 /* I/O block size */
39 device_t dev; /* pccard device */
40 struct cdev *cdev; /* character device */
42 struct resource *ioport; /* io port resource descriptor */
43 int ioport_rid; /* io port resource identification */
45 bus_space_tag_t bst; /* bus space tag */
46 bus_space_handle_t bsh; /* bus space handle */
49 struct resource* irq; /* irq resource descriptor */
50 int irq_rid; /* irq resource identification */
51 void *ih; /* intr handle */
54 struct mtx mtx; /* per-unit lock */
55 struct callout ch; /* callout handle */
56 struct selinfo sel; /* select/poll queue handle */
58 int open; /* is chardev open? */
59 int polling; /* are we polling? */
60 int dying; /* are we detaching? */
62 unsigned long timeout; /* response timeout */
64 uint8_t buf[CMX_BUFSZ]; /* read/write buffer */
67 extern devclass_t cmx_devclass;
69 void cmx_init_softc(device_t);
70 int cmx_alloc_resources(device_t);
71 void cmx_release_resources(device_t);
72 int cmx_attach(device_t);
73 int cmx_detach(device_t);
75 #define CMX_READ_1(sc, off) \
76 (bus_space_read_1((sc)->bst, (sc)->bsh, off))
77 #define CMX_WRITE_1(sc, off, val) \
78 (bus_space_write_1((sc)->bst, (sc)->bsh, off, val))
80 #define cmx_read_BSR(sc) \
81 CMX_READ_1(sc, REG_OFFSET_BSR)
82 #define cmx_write_BSR(sc, val) \
83 CMX_WRITE_1(sc, REG_OFFSET_BSR, val)
84 #define cmx_read_SCR(sc) \
85 CMX_READ_1(sc, REG_OFFSET_SCR)
86 #define cmx_write_SCR(sc, val) \
87 CMX_WRITE_1(sc, REG_OFFSET_SCR, val)
88 #define cmx_read_DTR(sc) \
89 CMX_READ_1(sc, REG_OFFSET_DTR)
90 #define cmx_write_DTR(sc, val) \
91 CMX_WRITE_1(sc, REG_OFFSET_DTR, val)
93 #define cmx_test(byte, flags, test) \
94 (((byte) & (flags)) == ((test) ? (flags) : 0))
96 #define cmx_test_BSR(sc, flags, test) \
97 cmx_test(cmx_read_BSR(sc), flags, test)
99 #define CMX_LOCK(sc) mtx_lock(&(sc)->mtx)
100 #define CMX_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
101 #define CMX_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->mtx, (what))