1/*	$NetBSD: vidc20.c,v 1.19 2021/08/07 16:18:44 thorpej Exp $	*/
2
3/*
4 * Copyright (c) 1997 Mark Brinicombe
5 * Copyright (c) 1997 Causality Limited
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by Mark Brinicombe
19 * 4. The name of the company nor the name of the author may be used to
20 *    endorse or promote products derived from this software without specific
21 *    prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24 * OR IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * RiscBSD kernel project
36 *
37 * vidc20.c
38 *
39 * VIDC20 driver
40 *
41 * Created      : 22/02/97
42 */
43
44#include <sys/cdefs.h>
45__KERNEL_RCSID(0, "$NetBSD: vidc20.c,v 1.19 2021/08/07 16:18:44 thorpej Exp $");
46
47#include <sys/types.h>
48#include <sys/param.h>
49#include <sys/systm.h>
50#include <sys/device.h>
51
52#include <sys/bus.h>
53#include <arm/iomd/vidc.h>
54#include <machine/io.h>
55#include <arm/iomd/iomdreg.h>
56#include <arm/iomd/iomdvar.h>
57#include <arm/mainbus/mainbus.h>
58
59#include "locators.h"
60
61struct vidc20_softc {
62	device_t	sc_dev;
63	bus_space_tag_t	sc_iot;
64};
65
66static int  vidcmatch(device_t , cfdata_t , void *);
67static void vidcattach(device_t , device_t , void *);
68static int  vidcsearch(device_t , cfdata_t , const int *, void *);
69
70/*
71 * vidc_base gives the base of the VIDC chip in memory; this is for
72 * the rest isnt busspaceified yet. Initialised with VIDC_BASE for
73 * backwards compatibility.
74 */
75int *vidc_base = (int *)VIDC_BASE;
76
77
78/*
79 * vidc_fref is the reference frequency in MHz of the detected VIDC
80 * (dependent on IOMD/IOC)
81 * XXX default is RPC600 ?
82 */
83int  vidc_fref = 24000000;
84
85
86CFATTACH_DECL_NEW(vidc, sizeof (struct vidc20_softc),
87    vidcmatch, vidcattach, NULL, NULL);
88
89/*
90 * vidcmatch()
91 *
92 * VIDC20 is a write only device so we cannot probe it
93 * We must assume things are ok.
94 */
95static int
96vidcmatch(device_t parent, cfdata_t cf, void *aux)
97{
98
99	return 1;
100}
101
102/*
103 * vidcsearch()
104 *
105 * search routine used during the config of children
106 */
107
108static int
109vidcsearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
110{
111
112	if (config_probe(parent, cf, NULL))
113		config_attach(parent, cf, NULL, NULL, CFARGS_NONE);
114
115	return 0;
116}
117
118/*
119 * vidcattach()
120 *
121 * Configure all the child devices of the VIDC
122 */
123static void
124vidcattach(device_t parent, device_t self, void *aux)
125{
126	struct vidc20_softc *sc = device_private(self);
127	struct mainbus_attach_args *mb = aux;
128
129	sc->sc_dev = self;
130	sc->sc_iot = mb->mb_iot;
131
132	/*
133	 * Since the VIDC is write-only, infer the type of VIDC from the
134	 * type of IOMD.
135	 */
136	switch (IOMD_ID) {
137	case ARM7500_IOC_ID:
138		aprint_normal(": ARM7500 video and sound macrocell\n");
139		vidc_fref = 32000000;
140		break;
141	case ARM7500FE_IOC_ID:
142		aprint_normal(": ARM7500FE video and sound macrocell\n");
143		vidc_fref = 32000000;
144		break;
145	default:				/* XXX default? */
146	case RPC600_IOMD_ID:
147		aprint_normal(": VIDC20\n");
148		vidc_fref = 24000000;
149		break;
150	}
151
152	config_search(self, NULL,
153	    CFARGS(.search = vidcsearch));
154}
155
156/* End of vidc20.c */
157