1 /* $NetBSD: com_ssio.c,v 1.3 2019/04/15 20:40:37 skrll Exp $ */
2
3 /* $OpenBSD: com_ssio.c,v 1.2 2007/06/24 16:28:39 kettenis Exp $ */
4
5 /*
6 * Copyright (c) 2007 Mark Kettenis
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21 #include <sys/param.h>
22 #include <sys/systm.h>
23 #include <sys/device.h>
24 #include <sys/tty.h>
25
26 #include <sys/bus.h>
27 #include <machine/iomod.h>
28
29 #include <dev/ic/comreg.h>
30 #include <dev/ic/comvar.h>
31
32 #include <hppa/hppa/machdep.h>
33 #include <hppa/dev/ssiovar.h>
34
35 void *ssio_intr_establish(int, int, int (*)(void *), void *,
36 const char *);
37
38 #define COM_SSIO_FREQ 1843200
39
40 struct com_ssio_softc {
41 struct com_softc sc_com; /* real "com" softc */
42 void *sc_ih; /* interrupt handler */
43 };
44
45 int com_ssio_match(device_t, cfdata_t, void *);
46 void com_ssio_attach(device_t, device_t, void *);
47
48 CFATTACH_DECL_NEW(com_ssio, sizeof(struct com_ssio_softc), com_ssio_match,
49 com_ssio_attach, NULL, NULL);
50
51 int
com_ssio_match(device_t parent,cfdata_t match,void * aux)52 com_ssio_match(device_t parent, cfdata_t match, void *aux)
53 {
54 cfdata_t cf = match;
55 struct ssio_attach_args *saa = aux;
56
57 if (strcmp(saa->saa_name, "com") != 0)
58 return (0);
59
60 /* Check locators. */
61 if (cf->ssiocf_irq != SSIO_UNK_IRQ && cf->ssiocf_irq != saa->saa_irq)
62 return (0);
63
64 return (1);
65 }
66
67 void
com_ssio_attach(device_t parent,device_t self,void * aux)68 com_ssio_attach(device_t parent, device_t self, void *aux)
69 {
70 struct com_ssio_softc *sc_ssio = device_private(self);
71 struct com_softc *sc = &sc_ssio->sc_com;
72 struct ssio_attach_args *saa = aux;
73 int pagezero_cookie;
74
75 bus_addr_t iobase;
76 bus_space_handle_t ioh;
77 bus_space_tag_t iot;
78
79 sc->sc_dev = self;
80 iobase = saa->saa_iobase;
81 iot = saa->saa_iot;
82 if (bus_space_map(iot, iobase, COM_NPORTS,
83 0, &ioh)) {
84 aprint_error(": can't map I/O space\n");
85 return;
86 }
87
88 /* Test if this is the console. */
89 pagezero_cookie = hppa_pagezero_map();
90 if (PAGE0->mem_cons.pz_class == PCL_DUPLEX &&
91 PAGE0->mem_cons.pz_hpa == (struct iomod *)ioh) {
92 bus_space_unmap(iot, ioh, COM_NPORTS);
93 if (comcnattach(iot, iobase, B9600, COM_SSIO_FREQ,
94 COM_TYPE_NORMAL,
95 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0) {
96 aprint_error(": can't comcnattach\n");
97 hppa_pagezero_unmap(pagezero_cookie);
98 return;
99 }
100 }
101 hppa_pagezero_unmap(pagezero_cookie);
102
103 sc->sc_frequency = COM_SSIO_FREQ;
104 com_init_regs(&sc->sc_regs, iot, ioh, iobase);
105 com_attach_subr(sc);
106
107 sc_ssio->sc_ih = ssio_intr_establish(IPL_TTY, saa->saa_irq,
108 comintr, sc, device_xname(self));
109 }
110