envctrl.c (167753) | envctrl.c (181303) |
---|---|
1/*- 2 * Copyright (c) 2004 Joerg Wunsch 3 * 4 * derived from sys/i386/isa/pcf.c which is: 5 * 6 * Copyright (c) 1998 Nicolas Souchu, Marc Bouget 7 * All rights reserved. 8 * --- 14 unchanged lines hidden (view full) --- 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2004 Joerg Wunsch 3 * 4 * derived from sys/i386/isa/pcf.c which is: 5 * 6 * Copyright (c) 1998 Nicolas Souchu, Marc Bouget 7 * All rights reserved. 8 * --- 14 unchanged lines hidden (view full) --- 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/pcf/envctrl.c 167753 2007-03-21 03:38:37Z nyan $"); | 31__FBSDID("$FreeBSD: head/sys/dev/pcf/envctrl.c 181303 2008-08-04 20:46:15Z jhb $"); |
32 33/* 34 * Device specific driver for the SUNW,envctrl device found on some 35 * UltraSPARC Sun systems. This device is a Philips PCF8584 sitting 36 * on the Ebus2. 37 */ 38 39#include <sys/param.h> | 32 33/* 34 * Device specific driver for the SUNW,envctrl device found on some 35 * UltraSPARC Sun systems. This device is a Philips PCF8584 sitting 36 * on the Ebus2. 37 */ 38 39#include <sys/param.h> |
40#include <sys/systm.h> | |
41#include <sys/bus.h> 42#include <sys/conf.h> 43#include <sys/kernel.h> | 40#include <sys/bus.h> 41#include <sys/conf.h> 42#include <sys/kernel.h> |
43#include <sys/lock.h> |
|
44#include <sys/malloc.h> 45#include <sys/module.h> | 44#include <sys/malloc.h> 45#include <sys/module.h> |
46#include <sys/mutex.h> |
|
46#include <sys/resource.h> | 47#include <sys/resource.h> |
48#include <sys/systm.h> |
|
47#include <sys/uio.h> 48 49#include <dev/ofw/ofw_bus.h> 50 51#include <machine/bus.h> 52#include <machine/resource.h> 53 54#include <sys/rman.h> --- 47 unchanged lines hidden (view full) --- 102 103static int 104envctrl_attach(device_t dev) 105{ 106 struct pcf_softc *sc; 107 int rv = ENXIO; 108 109 sc = DEVTOSOFTC(dev); | 49#include <sys/uio.h> 50 51#include <dev/ofw/ofw_bus.h> 52 53#include <machine/bus.h> 54#include <machine/resource.h> 55 56#include <sys/rman.h> --- 47 unchanged lines hidden (view full) --- 104 105static int 106envctrl_attach(device_t dev) 107{ 108 struct pcf_softc *sc; 109 int rv = ENXIO; 110 111 sc = DEVTOSOFTC(dev); |
110 bzero(sc, sizeof(struct pcf_softc)); | 112 mtx_init(&sc->pcf_lock, device_get_nameunit(dev), "pcf", MTX_DEF); |
111 112 /* IO port is mandatory */ 113 sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 114 &sc->rid_ioport, RF_ACTIVE); 115 if (sc->res_ioport == 0) { 116 device_printf(dev, "cannot reserve I/O port range\n"); 117 goto error; 118 } | 113 114 /* IO port is mandatory */ 115 sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 116 &sc->rid_ioport, RF_ACTIVE); 117 if (sc->res_ioport == 0) { 118 device_printf(dev, "cannot reserve I/O port range\n"); 119 goto error; 120 } |
119 sc->bt_ioport = rman_get_bustag(sc->res_ioport); 120 sc->bh_ioport = rman_get_bushandle(sc->res_ioport); | |
121 122 sc->pcf_flags = device_get_flags(dev); 123 124 if (!(sc->pcf_flags & IIC_POLLED)) { 125 sc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->rid_irq, 126 RF_ACTIVE); 127 if (sc->res_irq == 0) { 128 device_printf(dev, "can't reserve irq, polled mode.\n"); 129 sc->pcf_flags |= IIC_POLLED; 130 } 131 } 132 133 /* reset the chip */ 134 pcf_rst_card(dev, IIC_FASTEST, PCF_DEFAULT_ADDR, NULL); 135 136 rv = bus_setup_intr(dev, sc->res_irq, | 121 122 sc->pcf_flags = device_get_flags(dev); 123 124 if (!(sc->pcf_flags & IIC_POLLED)) { 125 sc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->rid_irq, 126 RF_ACTIVE); 127 if (sc->res_irq == 0) { 128 device_printf(dev, "can't reserve irq, polled mode.\n"); 129 sc->pcf_flags |= IIC_POLLED; 130 } 131 } 132 133 /* reset the chip */ 134 pcf_rst_card(dev, IIC_FASTEST, PCF_DEFAULT_ADDR, NULL); 135 136 rv = bus_setup_intr(dev, sc->res_irq, |
137 INTR_TYPE_NET /* | INTR_ENTROPY */, | 137 INTR_TYPE_NET | INTR_MPSAFE /* | INTR_ENTROPY */, |
138 NULL, pcf_intr, sc, &sc->intr_cookie); 139 if (rv) { 140 device_printf(dev, "could not setup IRQ\n"); 141 goto error; 142 } 143 144 if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL) 145 device_printf(dev, "could not allocate iicbus instance\n"); --- 7 unchanged lines hidden (view full) --- 153 if (sc->res_irq != 0) { 154 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq, 155 sc->res_irq); 156 } 157 if (sc->res_ioport != 0) { 158 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport, 159 sc->res_ioport); 160 } | 138 NULL, pcf_intr, sc, &sc->intr_cookie); 139 if (rv) { 140 device_printf(dev, "could not setup IRQ\n"); 141 goto error; 142 } 143 144 if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL) 145 device_printf(dev, "could not allocate iicbus instance\n"); --- 7 unchanged lines hidden (view full) --- 153 if (sc->res_irq != 0) { 154 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq, 155 sc->res_irq); 156 } 157 if (sc->res_ioport != 0) { 158 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport, 159 sc->res_ioport); 160 } |
161 mtx_destroy(&sc->pcf_lock); |
|
161 return (rv); 162} 163 164static int 165envctrl_detach(device_t dev) 166{ 167 struct pcf_softc *sc; 168 int rv; --- 7 unchanged lines hidden (view full) --- 176 return (rv); 177 178 if (sc->res_irq != 0) { 179 bus_teardown_intr(dev, sc->res_irq, sc->intr_cookie); 180 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq, sc->res_irq); 181 } 182 183 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport, sc->res_ioport); | 162 return (rv); 163} 164 165static int 166envctrl_detach(device_t dev) 167{ 168 struct pcf_softc *sc; 169 int rv; --- 7 unchanged lines hidden (view full) --- 177 return (rv); 178 179 if (sc->res_irq != 0) { 180 bus_teardown_intr(dev, sc->res_irq, sc->intr_cookie); 181 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq, sc->res_irq); 182 } 183 184 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport, sc->res_ioport); |
185 mtx_destroy(&sc->pcf_lock); |
|
184 185 return (0); 186} 187 188DRIVER_MODULE(envctrl, ebus, envctrl_driver, envctrl_devclass, 0, 0); | 186 187 return (0); 188} 189 190DRIVER_MODULE(envctrl, ebus, envctrl_driver, envctrl_devclass, 0, 0); |
191DRIVER_MODULE(iicbus, envctrl, iicbus_driver, iicbus_devclass, 0, 0); |
|
189MODULE_DEPEND(envctrl, iicbus, PCF_MINVER, PCF_PREFVER, PCF_MAXVER); 190MODULE_VERSION(envctrl, PCF_MODVER); | 192MODULE_DEPEND(envctrl, iicbus, PCF_MINVER, PCF_PREFVER, PCF_MAXVER); 193MODULE_VERSION(envctrl, PCF_MODVER); |