terasic_mtl.c revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2012 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * This software was developed by SRI International and the University of
8 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
9 * ("CTSRD"), as part of the DARPA CRASH research programme.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: stable/11/sys/dev/terasic/mtl/terasic_mtl.c 330897 2018-03-14 03:19:51Z eadler $");
35
36#include "opt_syscons.h"
37
38#include <sys/param.h>
39#include <sys/bus.h>
40#include <sys/condvar.h>
41#include <sys/conf.h>
42#include <sys/consio.h>				/* struct vt_mode */
43#include <sys/endian.h>
44#include <sys/fbio.h>				/* video_adapter_t */
45#include <sys/kernel.h>
46#include <sys/lock.h>
47#include <sys/malloc.h>
48#include <sys/module.h>
49#include <sys/mutex.h>
50#include <sys/rman.h>
51#include <sys/systm.h>
52
53#include <machine/bus.h>
54#include <machine/resource.h>
55
56#include <dev/terasic/mtl/terasic_mtl.h>
57
58/*
59 * Device driver for the Terasic Multitouch LCD (MTL).  Three separate
60 * sub-drivers that support, respectively, access to device control registers,
61 * the pixel frame buffer, and the text frame buffer.  The pixel frame buffer
62 * is hooked up to vt(4), and the text frame buffer to syscons(4).
63 *
64 * Eventually, the frame buffer control registers and touch screen input FIFO
65 * will end up being separate sub-drivers as well.
66 *
67 * Note: sub-driver detach routines must check whether or not they have
68 * attached as they may be called even if the attach routine hasn't been, on
69 * an error.
70 */
71
72devclass_t	terasic_mtl_devclass;
73
74int
75terasic_mtl_attach(struct terasic_mtl_softc *sc)
76{
77	int error;
78
79	error = terasic_mtl_reg_attach(sc);
80	if (error)
81		goto error;
82	error = terasic_mtl_pixel_attach(sc);
83	if (error)
84		goto error;
85	error = terasic_mtl_text_attach(sc);
86	if (error)
87		goto error;
88	/*
89	 * XXXRW: Once we've attached syscons or vt, we can't detach it, so do
90	 * it last.
91	 */
92#if defined(DEV_VT)
93	terasic_mtl_reg_pixel_endian_set(sc, BYTE_ORDER == BIG_ENDIAN);
94	error = terasic_mtl_fbd_attach(sc);
95	if (error)
96		goto error;
97	terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_OPAQUE);
98	terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT);
99	terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT);
100#endif
101#if defined(DEV_SC)
102	error = terasic_mtl_syscons_attach(sc);
103	if (error)
104		goto error;
105	terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT);
106	terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_OPAQUE);
107	terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_OPAQUE);
108#endif
109	terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK);
110	return (0);
111error:
112	terasic_mtl_text_detach(sc);
113	terasic_mtl_pixel_detach(sc);
114	terasic_mtl_reg_detach(sc);
115	return (error);
116}
117
118void
119terasic_mtl_detach(struct terasic_mtl_softc *sc)
120{
121
122	/* XXXRW: syscons and vt can't detach, but try anyway, only to panic. */
123#if defined(DEV_SC)
124	terasic_mtl_syscons_detach(sc);
125#endif
126#if defined(DEV_VT)
127	terasic_mtl_fbd_detach(sc);
128#endif
129
130	/* All other aspects of the driver can detach just fine. */
131	terasic_mtl_text_detach(sc);
132	terasic_mtl_pixel_detach(sc);
133	terasic_mtl_reg_detach(sc);
134}
135