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$"); 33239691Srwatson 34274823Sbrooks#include "opt_syscons.h" 35274823Sbrooks 36239691Srwatson#include <sys/param.h> 37239691Srwatson#include <sys/bus.h> 38239691Srwatson#include <sys/condvar.h> 39239691Srwatson#include <sys/conf.h> 40239691Srwatson#include <sys/consio.h> /* struct vt_mode */ 41274823Sbrooks#include <sys/endian.h> 42239691Srwatson#include <sys/fbio.h> /* video_adapter_t */ 43239691Srwatson#include <sys/kernel.h> 44239691Srwatson#include <sys/lock.h> 45239691Srwatson#include <sys/malloc.h> 46239691Srwatson#include <sys/module.h> 47239691Srwatson#include <sys/mutex.h> 48239691Srwatson#include <sys/rman.h> 49239691Srwatson#include <sys/systm.h> 50239691Srwatson 51239691Srwatson#include <machine/bus.h> 52239691Srwatson#include <machine/resource.h> 53239691Srwatson 54239691Srwatson#include <dev/terasic/mtl/terasic_mtl.h> 55239691Srwatson 56239691Srwatson/* 57239691Srwatson * Device driver for the Terasic Multitouch LCD (MTL). Three separate 58239691Srwatson * sub-drivers that support, respectively, access to device control registers, 59274823Sbrooks * the pixel frame buffer, and the text frame buffer. The pixel frame buffer 60274823Sbrooks * is hooked up to vt(4), and the text frame buffer to syscons(4). 61239691Srwatson * 62239691Srwatson * Eventually, the frame buffer control registers and touch screen input FIFO 63239691Srwatson * will end up being separate sub-drivers as well. 64239691Srwatson * 65239691Srwatson * Note: sub-driver detach routines must check whether or not they have 66239691Srwatson * attached as they may be called even if the attach routine hasn't been, on 67239691Srwatson * an error. 68239691Srwatson */ 69245380Srwatson 70245380Srwatsondevclass_t terasic_mtl_devclass; 71245380Srwatson 72239691Srwatsonint 73239691Srwatsonterasic_mtl_attach(struct terasic_mtl_softc *sc) 74239691Srwatson{ 75239691Srwatson int error; 76239691Srwatson 77239691Srwatson error = terasic_mtl_reg_attach(sc); 78239691Srwatson if (error) 79239691Srwatson goto error; 80239691Srwatson error = terasic_mtl_pixel_attach(sc); 81239691Srwatson if (error) 82239691Srwatson goto error; 83239691Srwatson error = terasic_mtl_text_attach(sc); 84239691Srwatson if (error) 85239691Srwatson goto error; 86239691Srwatson /* 87274823Sbrooks * XXXRW: Once we've attached syscons or vt, we can't detach it, so do 88274823Sbrooks * it last. 89239691Srwatson */ 90274823Sbrooks#if defined(DEV_VT) 91274823Sbrooks terasic_mtl_reg_pixel_endian_set(sc, BYTE_ORDER == BIG_ENDIAN); 92274823Sbrooks error = terasic_mtl_fbd_attach(sc); 93274823Sbrooks if (error) 94274823Sbrooks goto error; 95274823Sbrooks terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 96274823Sbrooks terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); 97274823Sbrooks terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); 98274823Sbrooks#endif 99274823Sbrooks#if defined(DEV_SC) 100239691Srwatson error = terasic_mtl_syscons_attach(sc); 101239691Srwatson if (error) 102239691Srwatson goto error; 103239691Srwatson terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); 104239691Srwatson terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 105239691Srwatson terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); 106274823Sbrooks#endif 107274823Sbrooks terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK); 108239691Srwatson return (0); 109239691Srwatsonerror: 110239691Srwatson terasic_mtl_text_detach(sc); 111239691Srwatson terasic_mtl_pixel_detach(sc); 112239691Srwatson terasic_mtl_reg_detach(sc); 113239691Srwatson return (error); 114239691Srwatson} 115239691Srwatson 116239691Srwatsonvoid 117239691Srwatsonterasic_mtl_detach(struct terasic_mtl_softc *sc) 118239691Srwatson{ 119239691Srwatson 120274823Sbrooks /* XXXRW: syscons and vt can't detach, but try anyway, only to panic. */ 121274823Sbrooks#if defined(DEV_SC) 122239691Srwatson terasic_mtl_syscons_detach(sc); 123274823Sbrooks#endif 124274823Sbrooks#if defined(DEV_VT) 125274823Sbrooks terasic_mtl_fbd_detach(sc); 126274823Sbrooks#endif 127239691Srwatson 128239691Srwatson /* All other aspects of the driver can detach just fine. */ 129239691Srwatson terasic_mtl_text_detach(sc); 130239691Srwatson terasic_mtl_pixel_detach(sc); 131239691Srwatson terasic_mtl_reg_detach(sc); 132239691Srwatson} 133