Sun Jan 24 18:01:14 2021 UTC ()
Support non-FDT attachment.


(jmcneill)
diff -r1.8 -r1.9 src/sys/dev/i2c/motoi2c.c
diff -r1.6 -r1.7 src/sys/dev/i2c/motoi2cvar.h

cvs diff -r1.8 -r1.9 src/sys/dev/i2c/motoi2c.c (expand / switch to unified diff)

--- src/sys/dev/i2c/motoi2c.c 2020/12/23 16:02:11 1.8
+++ src/sys/dev/i2c/motoi2c.c 2021/01/24 18:01:13 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: motoi2c.c,v 1.8 2020/12/23 16:02:11 thorpej Exp $ */ 1/* $NetBSD: motoi2c.c,v 1.9 2021/01/24 18:01:13 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas. 8 * by Matt Thomas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.8 2020/12/23 16:02:11 thorpej Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.9 2021/01/24 18:01:13 jmcneill Exp $");
34 34
35#if defined(__arm__) || defined(__aarch64__) 35#if defined(__arm__) || defined(__aarch64__)
36#include "opt_fdt.h" 36#include "opt_fdt.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/device.h> 40#include <sys/device.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/mutex.h> 42#include <sys/mutex.h>
43#include <sys/bus.h> 43#include <sys/bus.h>
44#include <sys/intr.h> 44#include <sys/intr.h>
45 45
46#include <dev/i2c/i2cvar.h> 46#include <dev/i2c/i2cvar.h>
@@ -97,41 +97,42 @@ motoi2c_attach_common(device_t self, str @@ -97,41 +97,42 @@ motoi2c_attach_common(device_t self, str
97 i2c = &motoi2c_default_settings; 97 i2c = &motoi2c_default_settings;
98 98
99 iic_tag_init(&sc->sc_i2c); 99 iic_tag_init(&sc->sc_i2c);
100 sc->sc_i2c.ic_cookie = sc; 100 sc->sc_i2c.ic_cookie = sc;
101 sc->sc_i2c.ic_acquire_bus = motoi2c_acquire_bus; 101 sc->sc_i2c.ic_acquire_bus = motoi2c_acquire_bus;
102 sc->sc_i2c.ic_release_bus = motoi2c_release_bus; 102 sc->sc_i2c.ic_release_bus = motoi2c_release_bus;
103 sc->sc_i2c.ic_exec = motoi2c_exec; 103 sc->sc_i2c.ic_exec = motoi2c_exec;
104 if (sc->sc_iord == NULL) 104 if (sc->sc_iord == NULL)
105 sc->sc_iord = motoi2c_iord1; 105 sc->sc_iord = motoi2c_iord1;
106 if (sc->sc_iowr == NULL) 106 if (sc->sc_iowr == NULL)
107 sc->sc_iowr = motoi2c_iowr1; 107 sc->sc_iowr = motoi2c_iowr1;
108 memset(&iba, 0, sizeof(iba)); 108 memset(&iba, 0, sizeof(iba));
109 iba.iba_tag = &sc->sc_i2c; 109 iba.iba_tag = &sc->sc_i2c;
 110 iba.iba_child_devices = sc->sc_child_devices;
110 111
111 I2C_WRITE(I2CCR, 0); /* reset before changing anything */ 112 I2C_WRITE(I2CCR, 0); /* reset before changing anything */
112 I2C_WRITE(I2CDFSRR, i2c->i2c_dfsrr); /* sampling units */ 113 I2C_WRITE(I2CDFSRR, i2c->i2c_dfsrr); /* sampling units */
113 I2C_WRITE(I2CFDR, i2c->i2c_fdr); /* divider 3072 (0x31) */ 114 I2C_WRITE(I2CFDR, i2c->i2c_fdr); /* divider 3072 (0x31) */
114 I2C_WRITE(I2CADR, i2c->i2c_adr); /* our slave address is 0x7f */ 115 I2C_WRITE(I2CADR, i2c->i2c_adr); /* our slave address is 0x7f */
115 I2C_WRITE(I2CSR, 0); /* clear status flags */ 116 I2C_WRITE(I2CSR, 0); /* clear status flags */
116 117
117#ifdef FDT 118#ifdef FDT
118 KASSERT(sc->sc_phandle != 0); 119 if (sc->sc_phandle != 0) {
119 fdtbus_register_i2c_controller(&sc->sc_i2c, sc->sc_phandle); 120 fdtbus_register_i2c_controller(&sc->sc_i2c, sc->sc_phandle);
120 121 fdtbus_attach_i2cbus(self, sc->sc_phandle, &sc->sc_i2c,
121 fdtbus_attach_i2cbus(self, sc->sc_phandle, &sc->sc_i2c, iicbus_print); 122 iicbus_print);
122#else 123 } else
123 config_found_ia(self, "i2cbus", &iba, iicbus_print); 
124#endif 124#endif
 125 config_found_ia(self, "i2cbus", &iba, iicbus_print);
125} 126}
126 127
127static int 128static int
128motoi2c_acquire_bus(void *v, int flags) 129motoi2c_acquire_bus(void *v, int flags)
129{ 130{
130 struct motoi2c_softc * const sc = v; 131 struct motoi2c_softc * const sc = v;
131 132
132 I2C_WRITE(I2CCR, CR_MEN); /* enable the I2C module */ 133 I2C_WRITE(I2CCR, CR_MEN); /* enable the I2C module */
133 134
134 return 0; 135 return 0;
135} 136}
136 137
137static void 138static void

cvs diff -r1.6 -r1.7 src/sys/dev/i2c/motoi2cvar.h (expand / switch to unified diff)

--- src/sys/dev/i2c/motoi2cvar.h 2019/12/22 23:23:32 1.6
+++ src/sys/dev/i2c/motoi2cvar.h 2021/01/24 18:01:13 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: motoi2cvar.h,v 1.6 2019/12/22 23:23:32 thorpej Exp $ */ 1/* $NetBSD: motoi2cvar.h,v 1.7 2021/01/24 18:01:13 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas. 8 * by Matt Thomas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -41,26 +41,27 @@ typedef void (*motoi2c_iowr_t)(struct mo @@ -41,26 +41,27 @@ typedef void (*motoi2c_iowr_t)(struct mo
41struct motoi2c_settings { 41struct motoi2c_settings {
42 uint8_t i2c_adr; 42 uint8_t i2c_adr;
43 uint8_t i2c_fdr; 43 uint8_t i2c_fdr;
44 uint8_t i2c_dfsrr; 44 uint8_t i2c_dfsrr;
45}; 45};
46 46
47struct motoi2c_softc { 47struct motoi2c_softc {
48 bus_space_tag_t sc_iot; 48 bus_space_tag_t sc_iot;
49 bus_space_handle_t sc_ioh; 49 bus_space_handle_t sc_ioh;
50 struct i2c_controller sc_i2c; 50 struct i2c_controller sc_i2c;
51 motoi2c_iord_t sc_iord; 51 motoi2c_iord_t sc_iord;
52 motoi2c_iowr_t sc_iowr; 52 motoi2c_iowr_t sc_iowr;
53 int sc_phandle; 53 int sc_phandle;
 54 prop_array_t sc_child_devices;
54}; 55};
55 56
56#define MOTOI2C_ADR_DEFAULT (0x7e << 1) 57#define MOTOI2C_ADR_DEFAULT (0x7e << 1)
57#define MOTOI2C_FDR_DEFAULT 0x31 /* 3072 */ 58#define MOTOI2C_FDR_DEFAULT 0x31 /* 3072 */
58#define MOTOI2C_DFSRR_DEFAULT 0x10 59#define MOTOI2C_DFSRR_DEFAULT 0x10
59 60
60#ifdef _KERNEL 61#ifdef _KERNEL
61void motoi2c_attach_common(device_t, struct motoi2c_softc *, 62void motoi2c_attach_common(device_t, struct motoi2c_softc *,
62 const struct motoi2c_settings *); 63 const struct motoi2c_settings *);
63int motoi2c_intr(void *); 64int motoi2c_intr(void *);
64#endif 65#endif
65 66
66#endif /* !_DEV_I2C_MOTOI2CVAR_H_ */ 67#endif /* !_DEV_I2C_MOTOI2CVAR_H_ */