scc_bfe.h revision 167996
1265285Spluknet/*- 2265285Spluknet * Copyright (c) 2004-2006 Marcel Moolenaar 3265285Spluknet * All rights reserved. 4265285Spluknet * 5265285Spluknet * Redistribution and use in source and binary forms, with or without 6265285Spluknet * modification, are permitted provided that the following conditions 7265285Spluknet * are met: 8265285Spluknet * 9265285Spluknet * 1. Redistributions of source code must retain the above copyright 10265285Spluknet * notice, this list of conditions and the following disclaimer. 11265285Spluknet * 2. Redistributions in binary form must reproduce the above copyright 12265285Spluknet * notice, this list of conditions and the following disclaimer in the 13265285Spluknet * documentation and/or other materials provided with the distribution. 14265285Spluknet * 15265285Spluknet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16265285Spluknet * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17265285Spluknet * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18265285Spluknet * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19265285Spluknet * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20265285Spluknet * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21265285Spluknet * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22265285Spluknet * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23265285Spluknet * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24265285Spluknet * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25265285Spluknet * 26265285Spluknet * $FreeBSD: head/sys/dev/scc/scc_bfe.h 167996 2007-03-28 18:05:17Z marcel $ 27265285Spluknet */ 28265285Spluknet 29265285Spluknet#ifndef _DEV_SCC_BFE_H_ 30265285Spluknet#define _DEV_SCC_BFE_H_ 31265285Spluknet 32265285Spluknet#include <sys/serial.h> 33265285Spluknet 34265285Spluknet/* 35265285Spluknet * Bus access structure. This structure holds the minimum information needed 36265285Spluknet * to access the SCC. The rclk field, although not important to actually 37265285Spluknet * access the SCC, is important for baudrate programming, delay loops and 38265285Spluknet * other timing related computations. 39265285Spluknet */ 40265285Spluknetstruct scc_bas { 41265285Spluknet bus_space_tag_t bst; 42265285Spluknet bus_space_handle_t bsh; 43265285Spluknet u_int range; 44265285Spluknet u_int rclk; 45265285Spluknet u_int regshft; 46265285Spluknet}; 47265285Spluknet 48265285Spluknet#define scc_regofs(bas, reg) ((reg) << (bas)->regshft) 49265320Spluknet 50265285Spluknet#define scc_getreg(bas, reg) \ 51265285Spluknet bus_space_read_1((bas)->bst, (bas)->bsh, scc_regofs(bas, reg)) 52265285Spluknet#define scc_setreg(bas, reg, value) \ 53265320Spluknet bus_space_write_1((bas)->bst, (bas)->bsh, scc_regofs(bas, reg), value) 54265285Spluknet 55265320Spluknet#define scc_barrier(bas) \ 56265285Spluknet bus_space_barrier((bas)->bst, (bas)->bsh, 0, (bas)->range, \ 57265285Spluknet BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE) 58265285Spluknet 59265285Spluknet/* 60265285Spluknet * SCC mode (child) and channel control structures. 61265285Spluknet */ 62265285Spluknet 63265285Spluknet#define SCC_NMODES 3 64265285Spluknet#define SCC_ISRCCNT 5 65265285Spluknet 66265285Spluknetstruct scc_chan; 67265285Spluknet 68265320Spluknetstruct scc_mode { 69265285Spluknet struct scc_chan *m_chan; 70265285Spluknet device_t m_dev; 71265285Spluknet 72265285Spluknet u_int m_mode; 73265285Spluknet int m_attached:1; 74265285Spluknet int m_fastintr:1; 75265285Spluknet int m_hasintr:1; 76265285Spluknet int m_probed:1; 77265285Spluknet int m_sysdev:1; 78265285Spluknet 79265285Spluknet driver_filter_t *ih; 80265285Spluknet serdev_intr_t *ih_src[SCC_ISRCCNT]; 81265285Spluknet void *ih_arg; 82265285Spluknet}; 83265285Spluknet 84265285Spluknetstruct scc_chan { 85265285Spluknet struct resource ch_rres; 86265285Spluknet struct resource_list ch_rlist; 87265285Spluknet 88265285Spluknet struct resource *ch_ires; /* Interrupt resource. */ 89265285Spluknet void *ch_icookie; 90265285Spluknet int ch_irid; 91265285Spluknet 92265285Spluknet struct scc_mode ch_mode[SCC_NMODES]; 93265285Spluknet 94265285Spluknet u_int ch_nr; 95265285Spluknet int ch_enabled:1; 96265320Spluknet int ch_sysdev:1; 97265320Spluknet 98265285Spluknet uint32_t ch_ipend; 99265285Spluknet uint32_t ch_hwsig; 100265285Spluknet}; 101265285Spluknet 102265285Spluknet/* 103265285Spluknet * SCC class & instance (=softc) 104265285Spluknet */ 105265285Spluknetstruct scc_class { 106265285Spluknet KOBJ_CLASS_FIELDS; 107265285Spluknet u_int cl_channels; /* Number of independent channels. */ 108 u_int cl_class; /* SCC bus class ID. */ 109 u_int cl_modes; /* Supported modes (bitset). */ 110 int cl_range; 111}; 112 113extern struct scc_class scc_sab82532_class; 114extern struct scc_class scc_z8530_class; 115 116struct scc_softc { 117 KOBJ_FIELDS; 118 struct scc_class *sc_class; 119 struct scc_bas sc_bas; 120 device_t sc_dev; 121 122 struct mtx sc_hwmtx; /* Spinlock protecting hardware. */ 123 124 struct resource *sc_rres; /* Register resource. */ 125 int sc_rrid; 126 int sc_rtype; /* SYS_RES_{IOPORT|MEMORY}. */ 127 128 struct scc_chan *sc_chan; 129 130 int sc_fastintr:1; 131 int sc_leaving:1; 132 int sc_polled:1; 133 134 uint32_t sc_hwsig; /* Signal state. Used by HW driver. */ 135}; 136 137extern devclass_t scc_devclass; 138extern char scc_driver_name[]; 139 140int scc_bfe_attach(device_t dev); 141int scc_bfe_detach(device_t dev); 142int scc_bfe_probe(device_t dev, u_int regshft, u_int rclk, u_int rid); 143 144struct resource *scc_bus_alloc_resource(device_t, device_t, int, int *, 145 u_long, u_long, u_long, u_int); 146int scc_bus_get_resource(device_t, device_t, int, int, u_long *, u_long *); 147int scc_bus_read_ivar(device_t, device_t, int, uintptr_t *); 148int scc_bus_release_resource(device_t, device_t, int, int, struct resource *); 149int scc_bus_setup_intr(device_t, device_t, struct resource *, int, 150 driver_filter_t *, void (*)(void *), void *, void **); 151int scc_bus_teardown_intr(device_t, device_t, struct resource *, void *); 152 153#endif /* _DEV_SCC_BFE_H_ */ 154