11.13Sthorpej/*	$NetBSD: com_mainbus.c,v 1.13 2018/12/08 17:46:12 thorpej Exp $	*/
21.1Such
31.1Such/*-
41.1Such * Copyright (c) 2002 The NetBSD Foundation, Inc.
51.1Such * All rights reserved.
61.1Such *
71.1Such * Redistribution and use in source and binary forms, with or without
81.1Such * modification, are permitted provided that the following conditions
91.1Such * are met:
101.1Such * 1. Redistributions of source code must retain the above copyright
111.1Such *    notice, this list of conditions and the following disclaimer.
121.1Such * 2. Redistributions in binary form must reproduce the above copyright
131.1Such *    notice, this list of conditions and the following disclaimer in the
141.1Such *    documentation and/or other materials provided with the distribution.
151.1Such *
161.1Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Such * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Such * POSSIBILITY OF SUCH DAMAGE.
271.1Such */
281.5Slukem
291.5Slukem#include <sys/cdefs.h>
301.13Sthorpej__KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.13 2018/12/08 17:46:12 thorpej Exp $");
311.1Such
321.1Such#include <sys/param.h>
331.1Such#include <sys/systm.h>
341.1Such#include <sys/device.h>
351.1Such
361.1Such#include <sys/termios.h>
371.1Such#include <dev/cons.h>
381.1Such#include <sys/conf.h>
391.12Sdyoung#include <sys/bus.h>
401.1Such
411.1Such#include <machine/intr.h>
421.1Such#include <machine/autoconf.h>
431.1Such#include <machine/mmeye.h>
441.1Such
451.1Such#include <dev/ic/comvar.h>
461.1Such#include <dev/ic/comreg.h>
471.1Such
481.1Such#ifndef COMCN_SPEED
491.1Such#define COMCN_SPEED	19200
501.1Such#endif
511.1Such#ifndef CONADDR
521.1Such#define CONADDR		0xa4000000
531.1Such#endif
541.1Such#ifndef CONMODE
551.1Such#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
561.1Such#endif
571.1Such
581.1Suchstruct com_mainbus_softc {
591.1Such	struct	com_softc sc_com;	/* real "com" softc */
601.1Such};
611.1Such
621.8Scubeint com_mainbus_match(device_t, cfdata_t , void *);
631.8Scubevoid com_mainbus_attach(device_t, device_t, void *);
641.1Suchvoid comcnprobe(struct consdev *);
651.1Suchvoid comcninit(struct consdev *);
661.1Such
671.8ScubeCFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
681.3Sthorpej    com_mainbus_match, com_mainbus_attach, NULL, NULL);
691.1Such
701.1Suchint
711.8Scubecom_mainbus_match(device_t parent, cfdata_t match, void *aux)
721.1Such{
731.1Such	struct mainbus_attach_args *ma = aux;
741.1Such
751.10Skiyohara	if (strcmp(ma->ma_name, match->cf_name) == 0)
761.1Such		return (1);
771.1Such
781.1Such	return (0);
791.1Such}
801.1Such
811.1Suchvoid
821.8Scubecom_mainbus_attach(device_t parent, device_t self, void *aux)
831.1Such{
841.1Such	struct mainbus_attach_args *ma = aux;
851.8Scube	struct com_mainbus_softc *sc = device_private(self);
861.1Such	struct com_softc *csc = &sc->sc_com;
871.11Skiyohara#if defined(SH7750R)
881.11Skiyohara	const bus_space_tag_t iot = SH3_BUS_SPACE_PCMCIA_IO8;
891.11Skiyohara#else
901.10Skiyohara	const bus_space_tag_t iot = 0;
911.11Skiyohara#endif
921.10Skiyohara	bus_space_handle_t ioh;
931.1Such
941.10Skiyohara	if (!com_is_console(iot, ma->ma_addr1, &ioh))
951.10Skiyohara		if (bus_space_map(iot, ma->ma_addr1, COM_NPORTS, 0, &ioh)) {
961.10Skiyohara			aprint_error(": can't map i/o space\n");
971.10Skiyohara			return;
981.10Skiyohara		}
991.8Scube	csc->sc_dev = self;
1001.1Such	csc->sc_frequency = COM_FREQ;
1011.13Sthorpej	com_init_regs(&csc->sc_regs, iot, ioh, ma->ma_addr1);
1021.1Such
1031.1Such	/* sanity check */
1041.10Skiyohara	if (!comprobe1(iot, ioh)) {
1051.8Scube		aprint_error(": device problem. don't attach.\n");
1061.1Such		return;
1071.1Such	}
1081.1Such
1091.1Such	com_attach_subr(csc);
1101.1Such
1111.1Such	mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_SERIAL, comintr, sc);
1121.1Such}
1131.1Such
1141.1Suchvoid
1151.1Suchcomcnprobe(struct consdev *cp)
1161.1Such{
1171.1Such
1181.1Such#ifdef  COMCONSOLE
1191.1Such	cp->cn_pri = CN_REMOTE;	/* Force a serial port console */
1201.1Such#else
1211.1Such	cp->cn_pri = CN_NORMAL;
1221.1Such#endif
1231.1Such}
1241.1Such
1251.1Suchvoid
1261.8Scubecomcninit(struct consdev *cp)
1271.1Such{
1281.11Skiyohara#if defined(SH7750R)
1291.11Skiyohara	const bus_space_tag_t iot = SH3_BUS_SPACE_PCMCIA_IO8;
1301.11Skiyohara#else
1311.10Skiyohara	const bus_space_tag_t iot = 0;
1321.11Skiyohara#endif
1331.1Such
1341.10Skiyohara	comcnattach(iot, CONADDR, COMCN_SPEED, COM_FREQ, COM_TYPE_NORMAL,
1351.4Sthorpej	    CONMODE);
1361.1Such}
137