11.1Sskrll/*	$OpenBSD: com_dino.c,v 1.4 2007/07/15 19:25:49 kettenis Exp $	*/
21.1Sskrll
31.1Sskrll/*
41.1Sskrll * Copyright (c) 2004 Michael Shalayeff
51.1Sskrll * All rights reserved.
61.1Sskrll *
71.1Sskrll * Redistribution and use in source and binary forms, with or without
81.1Sskrll * modification, are permitted provided that the following conditions
91.1Sskrll * are met:
101.1Sskrll * 1. Redistributions of source code must retain the above copyright
111.1Sskrll *    notice, this list of conditions and the following disclaimer.
121.1Sskrll * 2. Redistributions in binary form must reproduce the above copyright
131.1Sskrll *    notice, this list of conditions and the following disclaimer in the
141.1Sskrll *    documentation and/or other materials provided with the distribution.
151.1Sskrll *
161.1Sskrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171.1Sskrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181.1Sskrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191.1Sskrll * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
201.1Sskrll * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
211.1Sskrll * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
221.1Sskrll * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231.1Sskrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
241.1Sskrll * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
251.1Sskrll * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
261.1Sskrll * THE POSSIBILITY OF SUCH DAMAGE.
271.1Sskrll */
281.1Sskrll
291.1Sskrll#include <sys/param.h>
301.1Sskrll#include <sys/systm.h>
311.1Sskrll#include <sys/device.h>
321.1Sskrll#include <sys/tty.h>
331.1Sskrll
341.1Sskrll#include <sys/bus.h>
351.1Sskrll#include <machine/intr.h>
361.1Sskrll#include <machine/iomod.h>
371.1Sskrll#include <machine/autoconf.h>
381.1Sskrll
391.1Sskrll#include <dev/ic/comreg.h>
401.1Sskrll#include <dev/ic/comvar.h>
411.1Sskrll
421.1Sskrll#include <hppa/dev/cpudevs.h>
431.1Sskrll#include <hppa/hppa/machdep.h>
441.1Sskrll
451.1Sskrllvoid *dino_intr_establish(void *sc, int irq, int pri,
461.1Sskrll    int (*handler)(void *v), void *arg);
471.1Sskrll
481.1Sskrll#define	COM_DINO_FREQ	7272700
491.1Sskrll
501.1Sskrllstruct com_dino_softc {
511.1Sskrll	struct  com_softc sc_com;	/* real "com" softc */
521.1Sskrll	void	*sc_ih;			/* interrupt handler */
531.1Sskrll};
541.1Sskrll
551.1Sskrllstruct com_dino_regs {
561.1Sskrll	uint8_t		reset;
571.1Sskrll	uint8_t		pad0[3];
581.1Sskrll	uint8_t		test;
591.1Sskrll#define	COM_DINO_PAR_LOOP	0x01
601.1Sskrll#define	COM_DINO_CLK_SEL	0x02
611.1Sskrll	uint8_t		pad1[3];
621.1Sskrll	uint32_t	iodc;
631.1Sskrll	uint8_t		pad2[0x54];
641.1Sskrll	uint8_t		dither;
651.1Sskrll};
661.1Sskrll
671.1Sskrllint	com_dino_match(device_t, cfdata_t, void *);
681.1Sskrllvoid	com_dino_attach(device_t, device_t, void *);
691.1Sskrll
701.1SskrllCFATTACH_DECL_NEW(com_dino, sizeof(struct com_dino_softc), com_dino_match,
711.1Sskrll    com_dino_attach, NULL, NULL);
721.1Sskrll
731.1Sskrllint
741.1Sskrllcom_dino_match(device_t parent, cfdata_t match, void *aux)
751.1Sskrll{
761.1Sskrll	struct confargs *ca = aux;
771.1Sskrll
781.1Sskrll	if (ca->ca_type.iodc_type != HPPA_TYPE_FIO ||
791.1Sskrll	    ca->ca_type.iodc_sv_model != HPPA_FIO_GRS232)
801.3Sskrll		return 0;
811.1Sskrll
821.3Sskrll	return 1;
831.1Sskrll	/* HOZER comprobe1(ca->ca_iot, ca->ca_hpa + IOMOD_DEVOFFSET); */
841.1Sskrll}
851.1Sskrll
861.1Sskrllvoid
871.1Sskrllcom_dino_attach(device_t parent, device_t self, void *aux)
881.1Sskrll{
891.1Sskrll	void *sc_dino = device_private(parent);
901.1Sskrll	struct com_dino_softc *sc_comdino = device_private(self);
911.1Sskrll	struct com_softc *sc = &sc_comdino->sc_com;
921.1Sskrll	struct confargs *ca = aux;
931.1Sskrll	struct com_dino_regs *regs = (struct com_dino_regs *)ca->ca_hpa;
941.1Sskrll	int pagezero_cookie;
951.1Sskrll
961.1Sskrll	bus_addr_t iobase;
971.1Sskrll	bus_space_handle_t ioh;
981.1Sskrll
991.1Sskrll	sc->sc_dev = self;
1001.1Sskrll	iobase = (bus_addr_t)ca->ca_hpa + IOMOD_DEVOFFSET;
1011.1Sskrll	sc->sc_frequency = COM_DINO_FREQ;
1021.1Sskrll
1031.1Sskrll	/* Test if this is the console.  Compare either HPA or device path. */
1041.1Sskrll	pagezero_cookie = hppa_pagezero_map();
1051.1Sskrll	if (PAGE0->mem_cons.pz_class == PCL_DUPLEX &&
1061.1Sskrll	    PAGE0->mem_cons.pz_hpa == (struct iomod *)ca->ca_hpa) {
1071.1Sskrll
1081.1Sskrll		/*
1091.1Sskrll		 * This port is the console.  In this case we must call
1101.1Sskrll		 * comcnattach() and later com_is_console() to initialize
1111.1Sskrll		 * everything properly.
1121.1Sskrll		 */
1131.1Sskrll
1141.1Sskrll		if (comcnattach(ca->ca_iot, iobase, B9600,
1151.1Sskrll		    sc->sc_frequency, COM_TYPE_NORMAL,
1161.1Sskrll		    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0) {
1171.1Sskrll			aprint_error(": can't comcnattach\n");
1181.1Sskrll			hppa_pagezero_unmap(pagezero_cookie);
1191.1Sskrll			return;
1201.1Sskrll		}
1211.1Sskrll	}
1221.1Sskrll	hppa_pagezero_unmap(pagezero_cookie);
1231.1Sskrll
1241.1Sskrll	/*
1251.1Sskrll	 * Get the already initialized console ioh via com_is_console() if
1261.1Sskrll	 * this is the console or map the I/O space if this isn't the console.
1271.1Sskrll	 */
1281.1Sskrll
1291.1Sskrll	if (!com_is_console(ca->ca_iot, iobase, &ioh) &&
1301.1Sskrll	    bus_space_map(ca->ca_iot, iobase, COM_NPORTS, 0, &ioh) != 0) {
1311.1Sskrll		aprint_error(": can't map I/O space\n");
1321.1Sskrll		return;
1331.1Sskrll	}
1341.2Sthorpej	com_init_regs(&sc->sc_regs, ca->ca_iot, ioh, iobase);
1351.1Sskrll
1361.1Sskrll	/* select clock freq */
1371.1Sskrll	regs->test = COM_DINO_CLK_SEL;
1381.1Sskrll
1391.1Sskrll	com_attach_subr(sc);
1401.1Sskrll
1411.1Sskrll	ca->ca_irq = 10;
1421.1Sskrll
1431.1Sskrll	sc_comdino->sc_ih = dino_intr_establish(sc_dino, ca->ca_irq, IPL_TTY,
1441.1Sskrll	    comintr, sc);
1451.1Sskrll}
146