| @@ -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 | |
127 | static int | | 128 | static int |
128 | motoi2c_acquire_bus(void *v, int flags) | | 129 | motoi2c_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 | |
137 | static void | | 138 | static void |