terasic_mtl.c revision 239691
1239691Srwatson/*- 2239691Srwatson * Copyright (c) 2012 Robert N. M. Watson 3239691Srwatson * All rights reserved. 4239691Srwatson * 5239691Srwatson * This software was developed by SRI International and the University of 6239691Srwatson * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7239691Srwatson * ("CTSRD"), as part of the DARPA CRASH research programme. 8239691Srwatson * 9239691Srwatson * Redistribution and use in source and binary forms, with or without 10239691Srwatson * modification, are permitted provided that the following conditions 11239691Srwatson * are met: 12239691Srwatson * 1. Redistributions of source code must retain the above copyright 13239691Srwatson * notice, this list of conditions and the following disclaimer. 14239691Srwatson * 2. Redistributions in binary form must reproduce the above copyright 15239691Srwatson * notice, this list of conditions and the following disclaimer in the 16239691Srwatson * documentation and/or other materials provided with the distribution. 17239691Srwatson * 18239691Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19239691Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20239691Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21239691Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22239691Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23239691Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24239691Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25239691Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26239691Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27239691Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28239691Srwatson * SUCH DAMAGE. 29239691Srwatson */ 30239691Srwatson 31239691Srwatson#include <sys/cdefs.h> 32239691Srwatson__FBSDID("$FreeBSD: head/sys/dev/terasic/mtl/terasic_mtl.c 239691 2012-08-25 22:35:29Z rwatson $"); 33239691Srwatson 34239691Srwatson#include <sys/param.h> 35239691Srwatson#include <sys/bus.h> 36239691Srwatson#include <sys/condvar.h> 37239691Srwatson#include <sys/conf.h> 38239691Srwatson#include <sys/consio.h> /* struct vt_mode */ 39239691Srwatson#include <sys/fbio.h> /* video_adapter_t */ 40239691Srwatson#include <sys/kernel.h> 41239691Srwatson#include <sys/lock.h> 42239691Srwatson#include <sys/malloc.h> 43239691Srwatson#include <sys/module.h> 44239691Srwatson#include <sys/mutex.h> 45239691Srwatson#include <sys/rman.h> 46239691Srwatson#include <sys/systm.h> 47239691Srwatson 48239691Srwatson#include <machine/bus.h> 49239691Srwatson#include <machine/resource.h> 50239691Srwatson 51239691Srwatson#include <dev/terasic/mtl/terasic_mtl.h> 52239691Srwatson 53239691Srwatson/* 54239691Srwatson * Device driver for the Terasic Multitouch LCD (MTL). Three separate 55239691Srwatson * sub-drivers that support, respectively, access to device control registers, 56239691Srwatson * the pixel frame buffer, and the text frame buffer. The last of these is 57239691Srwatson * also hooked up to syscons. 58239691Srwatson * 59239691Srwatson * Eventually, the frame buffer control registers and touch screen input FIFO 60239691Srwatson * will end up being separate sub-drivers as well. 61239691Srwatson * 62239691Srwatson * Note: sub-driver detach routines must check whether or not they have 63239691Srwatson * attached as they may be called even if the attach routine hasn't been, on 64239691Srwatson * an error. 65239691Srwatson */ 66239691Srwatsonint 67239691Srwatsonterasic_mtl_attach(struct terasic_mtl_softc *sc) 68239691Srwatson{ 69239691Srwatson int error; 70239691Srwatson 71239691Srwatson error = terasic_mtl_reg_attach(sc); 72239691Srwatson if (error) 73239691Srwatson goto error; 74239691Srwatson error = terasic_mtl_pixel_attach(sc); 75239691Srwatson if (error) 76239691Srwatson goto error; 77239691Srwatson error = terasic_mtl_text_attach(sc); 78239691Srwatson if (error) 79239691Srwatson goto error; 80239691Srwatson /* 81239691Srwatson * XXXRW: Once we've attached syscons, we can't detach it, so do it 82239691Srwatson * last. 83239691Srwatson */ 84239691Srwatson error = terasic_mtl_syscons_attach(sc); 85239691Srwatson if (error) 86239691Srwatson goto error; 87239691Srwatson terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK); 88239691Srwatson terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); 89239691Srwatson terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 90239691Srwatson terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 91239691Srwatson return (0); 92239691Srwatsonerror: 93239691Srwatson terasic_mtl_text_detach(sc); 94239691Srwatson terasic_mtl_pixel_detach(sc); 95239691Srwatson terasic_mtl_reg_detach(sc); 96239691Srwatson return (error); 97239691Srwatson} 98239691Srwatson 99239691Srwatsonvoid 100239691Srwatsonterasic_mtl_detach(struct terasic_mtl_softc *sc) 101239691Srwatson{ 102239691Srwatson 103239691Srwatson /* XXXRW: syscons can't detach, but we try anyway, only to panic. */ 104239691Srwatson terasic_mtl_syscons_detach(sc); 105239691Srwatson 106239691Srwatson /* All other aspects of the driver can detach just fine. */ 107239691Srwatson terasic_mtl_text_detach(sc); 108239691Srwatson terasic_mtl_pixel_detach(sc); 109239691Srwatson terasic_mtl_reg_detach(sc); 110239691Srwatson} 111