terasic_mtl.c revision 239691
1/*- 2 * Copyright (c) 2012 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 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 31#include <sys/cdefs.h> 32__FBSDID("$FreeBSD: head/sys/dev/terasic/mtl/terasic_mtl.c 239691 2012-08-25 22:35:29Z rwatson $"); 33 34#include <sys/param.h> 35#include <sys/bus.h> 36#include <sys/condvar.h> 37#include <sys/conf.h> 38#include <sys/consio.h> /* struct vt_mode */ 39#include <sys/fbio.h> /* video_adapter_t */ 40#include <sys/kernel.h> 41#include <sys/lock.h> 42#include <sys/malloc.h> 43#include <sys/module.h> 44#include <sys/mutex.h> 45#include <sys/rman.h> 46#include <sys/systm.h> 47 48#include <machine/bus.h> 49#include <machine/resource.h> 50 51#include <dev/terasic/mtl/terasic_mtl.h> 52 53/* 54 * Device driver for the Terasic Multitouch LCD (MTL). Three separate 55 * sub-drivers that support, respectively, access to device control registers, 56 * the pixel frame buffer, and the text frame buffer. The last of these is 57 * also hooked up to syscons. 58 * 59 * Eventually, the frame buffer control registers and touch screen input FIFO 60 * will end up being separate sub-drivers as well. 61 * 62 * Note: sub-driver detach routines must check whether or not they have 63 * attached as they may be called even if the attach routine hasn't been, on 64 * an error. 65 */ 66int 67terasic_mtl_attach(struct terasic_mtl_softc *sc) 68{ 69 int error; 70 71 error = terasic_mtl_reg_attach(sc); 72 if (error) 73 goto error; 74 error = terasic_mtl_pixel_attach(sc); 75 if (error) 76 goto error; 77 error = terasic_mtl_text_attach(sc); 78 if (error) 79 goto error; 80 /* 81 * XXXRW: Once we've attached syscons, we can't detach it, so do it 82 * last. 83 */ 84 error = terasic_mtl_syscons_attach(sc); 85 if (error) 86 goto error; 87 terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK); 88 terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); 89 terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 90 terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 91 return (0); 92error: 93 terasic_mtl_text_detach(sc); 94 terasic_mtl_pixel_detach(sc); 95 terasic_mtl_reg_detach(sc); 96 return (error); 97} 98 99void 100terasic_mtl_detach(struct terasic_mtl_softc *sc) 101{ 102 103 /* XXXRW: syscons can't detach, but we try anyway, only to panic. */ 104 terasic_mtl_syscons_detach(sc); 105 106 /* All other aspects of the driver can detach just fine. */ 107 terasic_mtl_text_detach(sc); 108 terasic_mtl_pixel_detach(sc); 109 terasic_mtl_reg_detach(sc); 110} 111