scc_bfe.h revision 176772
1193323Sed/*- 2193323Sed * Copyright (c) 2004-2006 Marcel Moolenaar 3193323Sed * All rights reserved. 4193323Sed * 5193323Sed * Redistribution and use in source and binary forms, with or without 6193323Sed * modification, are permitted provided that the following conditions 7193323Sed * are met: 8193323Sed * 9193323Sed * 1. Redistributions of source code must retain the above copyright 10193323Sed * notice, this list of conditions and the following disclaimer. 11193323Sed * 2. Redistributions in binary form must reproduce the above copyright 12193323Sed * notice, this list of conditions and the following disclaimer in the 13193323Sed * documentation and/or other materials provided with the distribution. 14193323Sed * 15249423Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16193323Sed * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17193323Sed * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18249423Sdim * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19249423Sdim * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20205218Srdivacky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21206274Srdivacky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22249423Sdim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23205218Srdivacky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24249423Sdim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25249423Sdim * 26206274Srdivacky * $FreeBSD: head/sys/dev/scc/scc_bfe.h 176772 2008-03-03 18:20:17Z raj $ 27198090Srdivacky */ 28198090Srdivacky 29218893Sdim#ifndef _DEV_SCC_BFE_H_ 30193323Sed#define _DEV_SCC_BFE_H_ 31193323Sed 32193323Sed#include <sys/serial.h> 33193323Sed 34198892Srdivacky/* 35193323Sed * Bus access structure. This structure holds the minimum information needed 36206274Srdivacky * to access the SCC. The rclk field, although not important to actually 37206274Srdivacky * access the SCC, is important for baudrate programming, delay loops and 38193323Sed * other timing related computations. 39193323Sed */ 40193323Sedstruct scc_bas { 41193323Sed bus_space_tag_t bst; 42193323Sed bus_space_handle_t bsh; 43193323Sed u_int range; 44193323Sed u_int rclk; 45193323Sed u_int regshft; 46193323Sed}; 47206274Srdivacky 48193323Sed#define scc_regofs(bas, reg) ((reg) << (bas)->regshft) 49193323Sed 50206274Srdivacky#define scc_getreg(bas, reg) \ 51206274Srdivacky bus_space_read_1((bas)->bst, (bas)->bsh, scc_regofs(bas, reg)) 52206274Srdivacky#define scc_setreg(bas, reg, value) \ 53206274Srdivacky bus_space_write_1((bas)->bst, (bas)->bsh, scc_regofs(bas, reg), value) 54206274Srdivacky 55206274Srdivacky#define scc_barrier(bas) \ 56210299Sed bus_space_barrier((bas)->bst, (bas)->bsh, 0, (bas)->range, \ 57193323Sed BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE) 58206274Srdivacky 59210299Sed/* 60206274Srdivacky * SCC mode (child) and channel control structures. 61206274Srdivacky */ 62210299Sed 63206274Srdivacky#define SCC_NMODES 3 64193323Sed#define SCC_ISRCCNT 5 65206274Srdivacky 66206274Srdivackystruct scc_chan; 67193323Sed 68193323Sedstruct scc_mode { 69206274Srdivacky struct scc_chan *m_chan; 70198090Srdivacky device_t m_dev; 71206274Srdivacky 72193323Sed u_int m_mode; 73198090Srdivacky int m_attached:1; 74206274Srdivacky int m_fastintr:1; 75193323Sed int m_hasintr:1; 76193323Sed int m_probed:1; 77193323Sed int m_sysdev:1; 78193323Sed 79193323Sed driver_filter_t *ih; 80193323Sed serdev_intr_t *ih_src[SCC_ISRCCNT]; 81193323Sed void *ih_arg; 82193323Sed}; 83193323Sed 84193323Sedstruct scc_chan { 85193323Sed struct resource ch_rres; 86193323Sed struct resource_list ch_rlist; 87193323Sed 88193323Sed struct resource *ch_ires; /* Interrupt resource. */ 89193323Sed void *ch_icookie; 90193323Sed int ch_irid; 91193323Sed 92193323Sed struct scc_mode ch_mode[SCC_NMODES]; 93206274Srdivacky 94243830Sdim u_int ch_nr; 95193323Sed int ch_enabled:1; 96198090Srdivacky int ch_sysdev:1; 97206274Srdivacky 98193323Sed uint32_t ch_ipend; 99198090Srdivacky uint32_t ch_hwsig; 100206274Srdivacky}; 101193323Sed 102206274Srdivacky/* 103249423Sdim * SCC class & instance (=softc) 104193323Sed */ 105198090Srdivackystruct scc_class { 106206274Srdivacky KOBJ_CLASS_FIELDS; 107193323Sed u_int cl_channels; /* Number of independent channels. */ 108208599Srdivacky u_int cl_class; /* SCC bus class ID. */ 109193323Sed u_int cl_modes; /* Supported modes (bitset). */ 110193323Sed int cl_range; 111208599Srdivacky}; 112208599Srdivacky 113208599Srdivackyextern struct scc_class scc_quicc_class; 114208599Srdivackyextern struct scc_class scc_sab82532_class; 115193323Sedextern struct scc_class scc_z8530_class; 116208599Srdivacky 117208599Srdivackystruct scc_softc { 118208599Srdivacky KOBJ_FIELDS; 119208599Srdivacky struct scc_class *sc_class; 120208599Srdivacky struct scc_bas sc_bas; 121208599Srdivacky device_t sc_dev; 122208599Srdivacky 123208599Srdivacky struct mtx sc_hwmtx; /* Spinlock protecting hardware. */ 124208599Srdivacky 125208599Srdivacky struct resource *sc_rres; /* Register resource. */ 126193323Sed int sc_rrid; 127193323Sed int sc_rtype; /* SYS_RES_{IOPORT|MEMORY}. */ 128207618Srdivacky 129207618Srdivacky struct scc_chan *sc_chan; 130207618Srdivacky 131207618Srdivacky int sc_fastintr:1; 132207618Srdivacky int sc_leaving:1; 133193323Sed int sc_polled:1; 134193323Sed 135206274Srdivacky uint32_t sc_hwsig; /* Signal state. Used by HW driver. */ 136206274Srdivacky}; 137206274Srdivacky 138193323Sedextern devclass_t scc_devclass; 139193323Sedextern char scc_driver_name[]; 140193323Sed 141193323Sedint scc_bfe_attach(device_t dev); 142207618Srdivackyint scc_bfe_detach(device_t dev); 143207618Srdivackyint scc_bfe_probe(device_t dev, u_int regshft, u_int rclk, u_int rid); 144207618Srdivacky 145207618Srdivackystruct resource *scc_bus_alloc_resource(device_t, device_t, int, int *, 146193323Sed u_long, u_long, u_long, u_int); 147193323Sedint scc_bus_get_resource(device_t, device_t, int, int, u_long *, u_long *); 148249423Sdimint scc_bus_read_ivar(device_t, device_t, int, uintptr_t *); 149193323Sedint scc_bus_release_resource(device_t, device_t, int, int, struct resource *); 150193323Sedint scc_bus_setup_intr(device_t, device_t, struct resource *, int, 151193323Sed driver_filter_t *, void (*)(void *), void *, void **); 152193323Sedint scc_bus_teardown_intr(device_t, device_t, struct resource *, void *); 153193323Sed 154208599Srdivacky#endif /* _DEV_SCC_BFE_H_ */ 155208599Srdivacky