| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: exynos_i2c.c,v 1.11 2016/02/14 19:54:20 chs Exp $ */ | | 1 | /* $NetBSD: exynos_i2c.c,v 1.12 2017/06/11 00:54:26 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | * | | 27 | * |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include "opt_exynos.h" | | 30 | #include "opt_exynos.h" |
31 | #include "opt_arm_debug.h" | | 31 | #include "opt_arm_debug.h" |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: exynos_i2c.c,v 1.11 2016/02/14 19:54:20 chs Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: exynos_i2c.c,v 1.12 2017/06/11 00:54:26 jmcneill Exp $"); |
35 | | | 35 | |
36 | #include <sys/param.h> | | 36 | #include <sys/param.h> |
37 | #include <sys/bus.h> | | 37 | #include <sys/bus.h> |
38 | #include <sys/device.h> | | 38 | #include <sys/device.h> |
39 | #include <sys/intr.h> | | 39 | #include <sys/intr.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/kernel.h> | | 41 | #include <sys/kernel.h> |
42 | #include <sys/kmem.h> | | 42 | #include <sys/kmem.h> |
43 | | | 43 | |
44 | #include <arm/samsung/exynos_reg.h> | | 44 | #include <arm/samsung/exynos_reg.h> |
45 | #include <arm/samsung/exynos_var.h> | | 45 | #include <arm/samsung/exynos_var.h> |
46 | #include <arm/samsung/exynos_intr.h> | | 46 | #include <arm/samsung/exynos_intr.h> |
47 | | | 47 | |
| @@ -128,27 +128,28 @@ exynos_i2c_match(device_t self, cfdata_t | | | @@ -128,27 +128,28 @@ exynos_i2c_match(device_t self, cfdata_t |
128 | const char * const compatible[] = { "samsung,s3c2440-i2c", NULL }; | | 128 | const char * const compatible[] = { "samsung,s3c2440-i2c", NULL }; |
129 | struct fdt_attach_args * const faa = aux; | | 129 | struct fdt_attach_args * const faa = aux; |
130 | | | 130 | |
131 | return of_match_compatible(faa->faa_phandle, compatible); | | 131 | return of_match_compatible(faa->faa_phandle, compatible); |
132 | } | | 132 | } |
133 | | | 133 | |
134 | static void | | 134 | static void |
135 | exynos_i2c_attach(device_t parent, device_t self, void *aux) | | 135 | exynos_i2c_attach(device_t parent, device_t self, void *aux) |
136 | { | | 136 | { |
137 | struct exynos_i2c_softc * const sc = device_private(self); | | 137 | struct exynos_i2c_softc * const sc = device_private(self); |
138 | struct fdt_attach_args * const faa = aux; | | 138 | struct fdt_attach_args * const faa = aux; |
139 | const int phandle = faa->faa_phandle; | | 139 | const int phandle = faa->faa_phandle; |
140 | struct i2cbus_attach_args iba; | | 140 | struct i2cbus_attach_args iba; |
141 | | | 141 | prop_dictionary_t devs; |
| | | 142 | uint32_t address_cells; |
142 | char intrstr[128]; | | 143 | char intrstr[128]; |
143 | bus_addr_t addr; | | 144 | bus_addr_t addr; |
144 | bus_size_t size; | | 145 | bus_size_t size; |
145 | int error; | | 146 | int error; |
146 | | | 147 | |
147 | if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { | | 148 | if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { |
148 | aprint_error(": couldn't get registers\n"); | | 149 | aprint_error(": couldn't get registers\n"); |
149 | return; | | 150 | return; |
150 | } | | 151 | } |
151 | | | 152 | |
152 | sc->sc_dev = self; | | 153 | sc->sc_dev = self; |
153 | sc->sc_bst = faa->faa_bst; | | 154 | sc->sc_bst = faa->faa_bst; |
154 | error = bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh); | | 155 | error = bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh); |
| @@ -177,27 +178,42 @@ exynos_i2c_attach(device_t parent, devic | | | @@ -177,27 +178,42 @@ exynos_i2c_attach(device_t parent, devic |
177 | aprint_normal_dev(self, "interrupting on %s\n", intrstr); | | 178 | aprint_normal_dev(self, "interrupting on %s\n", intrstr); |
178 | | | 179 | |
179 | fdtbus_pinctrl_set_config_index(phandle, 0); | | 180 | fdtbus_pinctrl_set_config_index(phandle, 0); |
180 | | | 181 | |
181 | sc->sc_ic.ic_cookie = sc; | | 182 | sc->sc_ic.ic_cookie = sc; |
182 | sc->sc_ic.ic_acquire_bus = exynos_i2c_acquire_bus; | | 183 | sc->sc_ic.ic_acquire_bus = exynos_i2c_acquire_bus; |
183 | sc->sc_ic.ic_release_bus = exynos_i2c_release_bus; | | 184 | sc->sc_ic.ic_release_bus = exynos_i2c_release_bus; |
184 | sc->sc_ic.ic_send_start = exynos_i2c_send_start; | | 185 | sc->sc_ic.ic_send_start = exynos_i2c_send_start; |
185 | sc->sc_ic.ic_send_stop = exynos_i2c_send_stop; | | 186 | sc->sc_ic.ic_send_stop = exynos_i2c_send_stop; |
186 | sc->sc_ic.ic_initiate_xfer = exynos_i2c_initiate_xfer; | | 187 | sc->sc_ic.ic_initiate_xfer = exynos_i2c_initiate_xfer; |
187 | sc->sc_ic.ic_read_byte = exynos_i2c_read_byte; | | 188 | sc->sc_ic.ic_read_byte = exynos_i2c_read_byte; |
188 | sc->sc_ic.ic_write_byte = exynos_i2c_write_byte; | | 189 | sc->sc_ic.ic_write_byte = exynos_i2c_write_byte; |
189 | | | 190 | |
| | | 191 | fdtbus_register_i2c_controller(self, phandle, &exynos_i2c_funcs); |
| | | 192 | |
| | | 193 | devs = prop_dictionary_create(); |
| | | 194 | if (of_getprop_uint32(phandle, "#address-cells", &address_cells)) |
| | | 195 | address_cells = 1; |
| | | 196 | of_enter_i2c_devs(devs, phandle, address_cells * 4, 0); |
| | | 197 | |
190 | memset(&iba, 0, sizeof(iba)); | | 198 | memset(&iba, 0, sizeof(iba)); |
| | | 199 | iba.iba_tag = &sc->sc_ic; |
| | | 200 | iba.iba_child_devices = prop_dictionary_get(devs, "i2c-child-devices"); |
| | | 201 | if (iba.iba_child_devices != NULL) |
| | | 202 | prop_object_retain(iba.iba_child_devices); |
| | | 203 | else |
| | | 204 | iba.iba_child_devices = prop_array_create(); |
| | | 205 | prop_object_release(devs); |
| | | 206 | |
191 | sc->sc_i2cdev = config_found_ia(self, "i2cbus", &iba, iicbus_print); | | 207 | sc->sc_i2cdev = config_found_ia(self, "i2cbus", &iba, iicbus_print); |
192 | } | | 208 | } |
193 | | | 209 | |
194 | static i2c_tag_t | | 210 | static i2c_tag_t |
195 | exynos_i2c_get_tag(device_t dev) | | 211 | exynos_i2c_get_tag(device_t dev) |
196 | { | | 212 | { |
197 | struct exynos_i2c_softc * const sc = device_private(dev); | | 213 | struct exynos_i2c_softc * const sc = device_private(dev); |
198 | | | 214 | |
199 | return &sc->sc_ic; | | 215 | return &sc->sc_ic; |
200 | } | | 216 | } |
201 | | | 217 | |
202 | static int | | 218 | static int |
203 | exynos_i2c_intr(void *priv) | | 219 | exynos_i2c_intr(void *priv) |