ixp425_com.c revision 1.19 1 1.19 thorpej /* $NetBSD: ixp425_com.c,v 1.19 2018/12/08 17:46:10 thorpej Exp $ */
2 1.14 scw
3 1.1 ichiro /*
4 1.14 scw * Copyright 2003 Wasabi Systems, Inc.
5 1.1 ichiro * All rights reserved.
6 1.1 ichiro *
7 1.14 scw * Written by Steve C. Woodford for Wasabi Systems, Inc.
8 1.14 scw *
9 1.1 ichiro * Redistribution and use in source and binary forms, with or without
10 1.1 ichiro * modification, are permitted provided that the following conditions
11 1.1 ichiro * are met:
12 1.1 ichiro * 1. Redistributions of source code must retain the above copyright
13 1.1 ichiro * notice, this list of conditions and the following disclaimer.
14 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 ichiro * notice, this list of conditions and the following disclaimer in the
16 1.1 ichiro * documentation and/or other materials provided with the distribution.
17 1.1 ichiro * 3. All advertising materials mentioning features or use of this software
18 1.1 ichiro * must display the following acknowledgement:
19 1.14 scw * This product includes software developed for the NetBSD Project by
20 1.14 scw * Wasabi Systems, Inc.
21 1.14 scw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.14 scw * or promote products derived from this software without specific prior
23 1.14 scw * written permission.
24 1.1 ichiro *
25 1.14 scw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.14 scw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.14 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.14 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.14 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.14 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.14 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.14 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.14 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.14 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.14 scw * POSSIBILITY OF SUCH DAMAGE.
36 1.1 ichiro */
37 1.1 ichiro
38 1.1 ichiro #include <sys/cdefs.h>
39 1.19 thorpej __KERNEL_RCSID(0, "$NetBSD: ixp425_com.c,v 1.19 2018/12/08 17:46:10 thorpej Exp $");
40 1.1 ichiro
41 1.14 scw #include "opt_com.h"
42 1.14 scw #ifndef COM_PXA2X0
43 1.14 scw #error "You must use options COM_PXA2X0 to get IXP425 serial port support"
44 1.1 ichiro #endif
45 1.1 ichiro
46 1.14 scw #include <sys/systm.h>
47 1.1 ichiro #include <sys/param.h>
48 1.1 ichiro #include <sys/device.h>
49 1.14 scw #include <sys/termios.h>
50 1.1 ichiro
51 1.1 ichiro #include <machine/intr.h>
52 1.18 dyoung #include <sys/bus.h>
53 1.1 ichiro
54 1.14 scw #include <dev/ic/comreg.h>
55 1.14 scw #include <dev/ic/comvar.h>
56 1.14 scw
57 1.1 ichiro #include <arm/xscale/ixp425reg.h>
58 1.14 scw #include <arm/xscale/ixp425var.h>
59 1.14 scw #include <arm/xscale/ixp425_sipvar.h>
60 1.1 ichiro
61 1.17 cube static int ixsipcom_match(device_t, cfdata_t , void *);
62 1.17 cube static void ixsipcom_attach(device_t, device_t, void *);
63 1.1 ichiro
64 1.17 cube CFATTACH_DECL_NEW(ixsipcom, sizeof(struct com_softc),
65 1.14 scw ixsipcom_match, ixsipcom_attach, NULL, NULL);
66 1.1 ichiro
67 1.14 scw static const int uart_irq[] = {IXP425_INT_UART0, IXP425_INT_UART1};
68 1.1 ichiro
69 1.1 ichiro static int
70 1.17 cube ixsipcom_match(device_t parent, cfdata_t match, void *aux)
71 1.1 ichiro {
72 1.14 scw struct ixpsip_attach_args *sa = aux;
73 1.14 scw bus_space_tag_t bt = &ixp425_a4x_bs_tag;
74 1.14 scw bus_space_handle_t bh;
75 1.14 scw int rv;
76 1.1 ichiro
77 1.14 scw if (strcmp(match->cf_name, "ixsipcom") == 0)
78 1.14 scw return 1;
79 1.1 ichiro
80 1.14 scw if (com_is_console(bt, sa->sa_addr, NULL))
81 1.14 scw return (1);
82 1.1 ichiro
83 1.14 scw if (bus_space_map(bt, sa->sa_addr, sa->sa_size, 0, &bh))
84 1.1 ichiro return (0);
85 1.1 ichiro
86 1.14 scw /* Make sure the UART is enabled */
87 1.14 scw bus_space_write_1(bt, bh, com_ier, IER_EUART);
88 1.1 ichiro
89 1.14 scw rv = comprobe1(bt, bh);
90 1.14 scw bus_space_unmap(bt, bh, sa->sa_size);
91 1.1 ichiro
92 1.14 scw return (rv);
93 1.1 ichiro }
94 1.1 ichiro
95 1.1 ichiro static void
96 1.17 cube ixsipcom_attach(device_t parent, device_t self, void *aux)
97 1.1 ichiro {
98 1.17 cube struct com_softc *sc = device_private(self);
99 1.14 scw struct ixpsip_attach_args *sa = aux;
100 1.16 gdamore bus_space_tag_t iot;
101 1.16 gdamore bus_space_handle_t ioh;
102 1.16 gdamore bus_addr_t iobase;
103 1.1 ichiro
104 1.17 cube sc->sc_dev = self;
105 1.16 gdamore iot = &ixp425_a4x_bs_tag;
106 1.16 gdamore iobase = sa->sa_addr;
107 1.14 scw sc->sc_frequency = IXP425_UART_FREQ;
108 1.14 scw sc->sc_type = COM_TYPE_PXA2x0;
109 1.1 ichiro
110 1.16 gdamore if (com_is_console(iot, iobase, &ioh) == 0 &&
111 1.16 gdamore bus_space_map(iot, iobase, sa->sa_size, 0, &ioh)) {
112 1.17 cube aprint_error(": can't map registers\n");
113 1.1 ichiro return;
114 1.1 ichiro }
115 1.19 thorpej com_init_regs(&sc->sc_regs, iot, ioh, iobase);
116 1.11 ichiro
117 1.14 scw com_attach_subr(sc);
118 1.1 ichiro
119 1.14 scw ixp425_intr_establish(uart_irq[sa->sa_index], IPL_SERIAL, comintr, sc);
120 1.1 ichiro }
121