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: releng/10.2/sys/dev/terasic/mtl/terasic_mtl.c 245380 2013-01-13 16:57:11Z 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 */ 66245380Srwatson 67245380Srwatsondevclass_t terasic_mtl_devclass; 68245380Srwatson 69239691Srwatsonint 70239691Srwatsonterasic_mtl_attach(struct terasic_mtl_softc *sc) 71239691Srwatson{ 72239691Srwatson int error; 73239691Srwatson 74239691Srwatson error = terasic_mtl_reg_attach(sc); 75239691Srwatson if (error) 76239691Srwatson goto error; 77239691Srwatson error = terasic_mtl_pixel_attach(sc); 78239691Srwatson if (error) 79239691Srwatson goto error; 80239691Srwatson error = terasic_mtl_text_attach(sc); 81239691Srwatson if (error) 82239691Srwatson goto error; 83239691Srwatson /* 84239691Srwatson * XXXRW: Once we've attached syscons, we can't detach it, so do it 85239691Srwatson * last. 86239691Srwatson */ 87239691Srwatson error = terasic_mtl_syscons_attach(sc); 88239691Srwatson if (error) 89239691Srwatson goto error; 90239691Srwatson terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK); 91239691Srwatson terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); 92239691Srwatson terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 93239691Srwatson terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 94239691Srwatson return (0); 95239691Srwatsonerror: 96239691Srwatson terasic_mtl_text_detach(sc); 97239691Srwatson terasic_mtl_pixel_detach(sc); 98239691Srwatson terasic_mtl_reg_detach(sc); 99239691Srwatson return (error); 100239691Srwatson} 101239691Srwatson 102239691Srwatsonvoid 103239691Srwatsonterasic_mtl_detach(struct terasic_mtl_softc *sc) 104239691Srwatson{ 105239691Srwatson 106239691Srwatson /* XXXRW: syscons can't detach, but we try anyway, only to panic. */ 107239691Srwatson terasic_mtl_syscons_detach(sc); 108239691Srwatson 109239691Srwatson /* All other aspects of the driver can detach just fine. */ 110239691Srwatson terasic_mtl_text_detach(sc); 111239691Srwatson terasic_mtl_pixel_detach(sc); 112239691Srwatson terasic_mtl_reg_detach(sc); 113239691Srwatson} 114