summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2018-12-11 06:34:00 +0000
committerthorpej <thorpej@NetBSD.org>2018-12-11 06:34:00 +0000
commita813db806e5bb1db99e2da8a25f3e9c96ab54649 (patch)
tree0473678dce005af905cb032d33ea29b6da8dbaf8 /sys/dev
parentcfec4bd15f0c636b80b0a0995487d6ff963571aa (diff)
Add a convenience function, com_init_regs_stride(), that shifts the register
offsets and size by the specified amount. Use in front-ends as appropriate.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ic/com.c21
-rw-r--r--sys/dev/ic/comvar.h4
-rw-r--r--sys/dev/marvell/com_mv.c18
3 files changed, 29 insertions, 14 deletions
diff --git a/sys/dev/ic/com.c b/sys/dev/ic/com.c
index 0db131a8418..76e46353454 100644
--- a/sys/dev/ic/com.c
+++ b/sys/dev/ic/com.c
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.353 2018/12/09 16:00:40 thorpej Exp $ */
+/* $NetBSD: com.c,v 1.354 2018/12/11 06:34:00 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.353 2018/12/09 16:00:40 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.354 2018/12/11 06:34:00 thorpej Exp $");
#include "opt_com.h"
#include "opt_ddb.h"
@@ -276,6 +276,23 @@ com_init_regs(struct com_regs *regs, bus_space_tag_t st, bus_space_handle_t sh,
memcpy(regs->cr_map, com_std_map, sizeof(regs->cr_map));
}
+/*
+ * com_init_regs_stride --
+ * Convenience function for front-ends that have a stride between
+ * registers.
+ */
+void
+com_init_regs_stride(struct com_regs *regs, bus_space_tag_t st,
+ bus_space_handle_t sh, bus_addr_t addr, u_int regshift)
+{
+
+ com_init_regs(regs, st, sh, addr);
+ for (size_t i = 0; i < __arraycount(regs->cr_map); i++) {
+ regs->cr_map[i] <<= regshift;
+ }
+ regs->cr_nports <<= regshift;
+}
+
/*ARGSUSED*/
int
comspeed(long speed, long frequency, int type)
diff --git a/sys/dev/ic/comvar.h b/sys/dev/ic/comvar.h
index 018037a0c84..cc4e8927950 100644
--- a/sys/dev/ic/comvar.h
+++ b/sys/dev/ic/comvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: comvar.h,v 1.90 2018/12/08 21:14:37 thorpej Exp $ */
+/* $NetBSD: comvar.h,v 1.91 2018/12/11 06:34:00 thorpej Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -106,6 +106,8 @@ struct com_regs {
void com_init_regs(struct com_regs *, bus_space_tag_t, bus_space_handle_t,
bus_addr_t);
+void com_init_regs_stride(struct com_regs *, bus_space_tag_t,
+ bus_space_handle_t, bus_addr_t, u_int);
struct comcons_info {
struct com_regs regs;
diff --git a/sys/dev/marvell/com_mv.c b/sys/dev/marvell/com_mv.c
index 7bcb1115374..892661db4b7 100644
--- a/sys/dev/marvell/com_mv.c
+++ b/sys/dev/marvell/com_mv.c
@@ -1,4 +1,4 @@
-/* $NetBSD: com_mv.c,v 1.9 2018/12/08 21:14:37 thorpej Exp $ */
+/* $NetBSD: com_mv.c,v 1.10 2018/12/11 06:34:00 thorpej Exp $ */
/*
* Copyright (c) 2007, 2010 KIYOHARA Takashi
* All rights reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1.9 2018/12/08 21:14:37 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1.10 2018/12/11 06:34:00 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -55,13 +55,10 @@ CFATTACH_DECL_NEW(mvuart_mbus, sizeof(struct com_softc),
static void
mvuart_init_regs(struct com_regs *regs, bus_space_tag_t tag,
- bus_space_handle_t hdl, bus_addr_t addr, bus_size_t size)
+ bus_space_handle_t hdl, bus_addr_t addr);
{
- com_init_regs(regs, tag, hdl, addr);
- for (size_t i = 0; i < __arraycount(regs->cr_map); i++)
- regs->cr_map[i] = regs->cr_map[i] << 2;
- regs->cr_nports = size;
+ com_init_regs_stride(regs, tag, hdl, addr, 2);
}
@@ -85,8 +82,7 @@ mvuart_match(device_t parent, struct cfdata *match, void *aux)
if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
MVUART_SIZE, &ioh))
return 0;
- mvuart_init_regs(&regs, mva->mva_iot, ioh, mva->mva_offset,
- MVUART_SIZE);
+ mvuart_init_regs(&regs, mva->mva_iot, ioh, mva->mva_offset);
if (!com_probe_subr(&regs))
return 0;
@@ -121,7 +117,7 @@ mvuart_attach(device_t parent, device_t self, void *aux)
}
}
mvuart_init_regs(&sc->sc_regs,
- iot, ioh, mva->mva_addr + mva->mva_offset, mva->mva_size);
+ iot, ioh, mva->mva_addr + mva->mva_offset);
com_attach_subr(sc);
@@ -136,7 +132,7 @@ mvuart_cnattach(bus_space_tag_t iot, bus_addr_t addr, int baud,
{
struct com_regs regs;
- mvuart_init_regs(&regs, iot, 0x0, addr, MVUART_SIZE);
+ mvuart_init_regs(&regs, iot, 0x0, addr);
return comcnattach1(&regs, baud, sysfreq, COM_TYPE_16550_NOERS, mode);
}