| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: voyager.c,v 1.6 2011/10/20 22:04:10 macallan Exp $ */ | | 1 | /* $NetBSD: voyager.c,v 1.7 2011/12/07 09:08:00 macallan Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2009, 2011 Michael Lorenz | | 4 | * Copyright (c) 2009, 2011 Michael Lorenz |
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. |
| @@ -16,27 +16,27 @@ | | | @@ -16,27 +16,27 @@ |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: voyager.c,v 1.6 2011/10/20 22:04:10 macallan Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: voyager.c,v 1.7 2011/12/07 09:08:00 macallan Exp $"); |
30 | | | 30 | |
31 | #include <sys/param.h> | | 31 | #include <sys/param.h> |
32 | #include <sys/systm.h> | | 32 | #include <sys/systm.h> |
33 | #include <sys/kernel.h> | | 33 | #include <sys/kernel.h> |
34 | #include <sys/device.h> | | 34 | #include <sys/device.h> |
35 | #include <sys/malloc.h> | | 35 | #include <sys/malloc.h> |
36 | #include <sys/lwp.h> | | 36 | #include <sys/lwp.h> |
37 | #include <sys/kauth.h> | | 37 | #include <sys/kauth.h> |
38 | | | 38 | |
39 | #include <dev/pci/pcivar.h> | | 39 | #include <dev/pci/pcivar.h> |
40 | #include <dev/pci/pcireg.h> | | 40 | #include <dev/pci/pcireg.h> |
41 | #include <dev/pci/pcidevs.h> | | 41 | #include <dev/pci/pcidevs.h> |
42 | #include <dev/pci/pciio.h> | | 42 | #include <dev/pci/pciio.h> |
| @@ -212,48 +212,57 @@ voyager_attach(device_t parent, device_t | | | @@ -212,48 +212,57 @@ voyager_attach(device_t parent, device_t |
212 | | | 212 | |
213 | /* attach the framebuffer driver */ | | 213 | /* attach the framebuffer driver */ |
214 | vaa.vaa_memh = sc->sc_fbh; | | 214 | vaa.vaa_memh = sc->sc_fbh; |
215 | vaa.vaa_mem_pa = sc->sc_fb; | | 215 | vaa.vaa_mem_pa = sc->sc_fb; |
216 | vaa.vaa_regh = sc->sc_regh; | | 216 | vaa.vaa_regh = sc->sc_regh; |
217 | vaa.vaa_reg_pa = sc->sc_reg; | | 217 | vaa.vaa_reg_pa = sc->sc_reg; |
218 | vaa.vaa_tag = sc->sc_memt; | | 218 | vaa.vaa_tag = sc->sc_memt; |
219 | vaa.vaa_pc = sc->sc_pc; | | 219 | vaa.vaa_pc = sc->sc_pc; |
220 | vaa.vaa_pcitag = sc->sc_pcitag; | | 220 | vaa.vaa_pcitag = sc->sc_pcitag; |
221 | strcpy(vaa.vaa_name, "voyagerfb"); | | 221 | strcpy(vaa.vaa_name, "voyagerfb"); |
222 | config_found_ia(sc->sc_dev, "voyagerbus", &vaa, voyager_print); | | 222 | config_found_ia(sc->sc_dev, "voyagerbus", &vaa, voyager_print); |
223 | strcpy(vaa.vaa_name, "pwmclock"); | | 223 | strcpy(vaa.vaa_name, "pwmclock"); |
224 | config_found_ia(sc->sc_dev, "voyagerbus", &vaa, voyager_print); | | 224 | config_found_ia(sc->sc_dev, "voyagerbus", &vaa, voyager_print); |
| | | 225 | strcpy(vaa.vaa_name, "vac"); |
| | | 226 | config_found_ia(sc->sc_dev, "voyagerbus", &vaa, voyager_print); |
| | | 227 | |
| | | 228 | /* we use this mutex wether there's an i2c bus or not */ |
| | | 229 | mutex_init(&sc->sc_i2c_lock, MUTEX_DEFAULT, IPL_NONE); |
225 | | | 230 | |
| | | 231 | /* |
| | | 232 | * see if the i2c pins are configured as gpio and if so, use them |
| | | 233 | * should probably be a compile time option |
| | | 234 | */ |
226 | reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_GPIO0_CONTROL); | | 235 | reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_GPIO0_CONTROL); |
227 | if ((reg & GPIO_I2C_BITS) == 0) { | | 236 | if ((reg & GPIO_I2C_BITS) == 0) { |
228 | /* both bits as outputs */ | | 237 | /* both bits as outputs */ |
229 | reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_GPIO_DIR0); | | 238 | voyager_gpio_dir(sc, 0xffffffff, GPIO_I2C_BITS); |
230 | reg |= GPIO_I2C_BITS; | | | |
231 | bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_GPIO_DIR0, reg); | | | |
232 | | | 239 | |
233 | /* Fill in the i2c tag */ | | 240 | /* Fill in the i2c tag */ |
234 | sc->sc_i2c.ic_cookie = sc; | | 241 | sc->sc_i2c.ic_cookie = sc; |
235 | sc->sc_i2c.ic_acquire_bus = voyager_i2c_acquire_bus; | | 242 | sc->sc_i2c.ic_acquire_bus = voyager_i2c_acquire_bus; |
236 | sc->sc_i2c.ic_release_bus = voyager_i2c_release_bus; | | 243 | sc->sc_i2c.ic_release_bus = voyager_i2c_release_bus; |
237 | sc->sc_i2c.ic_send_start = voyager_i2c_send_start; | | 244 | sc->sc_i2c.ic_send_start = voyager_i2c_send_start; |
238 | sc->sc_i2c.ic_send_stop = voyager_i2c_send_stop; | | 245 | sc->sc_i2c.ic_send_stop = voyager_i2c_send_stop; |
239 | sc->sc_i2c.ic_initiate_xfer = voyager_i2c_initiate_xfer; | | 246 | sc->sc_i2c.ic_initiate_xfer = voyager_i2c_initiate_xfer; |
240 | sc->sc_i2c.ic_read_byte = voyager_i2c_read_byte; | | 247 | sc->sc_i2c.ic_read_byte = voyager_i2c_read_byte; |
241 | sc->sc_i2c.ic_write_byte = voyager_i2c_write_byte; | | 248 | sc->sc_i2c.ic_write_byte = voyager_i2c_write_byte; |
242 | sc->sc_i2c.ic_exec = NULL; | | 249 | sc->sc_i2c.ic_exec = NULL; |
243 | mutex_init(&sc->sc_i2c_lock, MUTEX_DEFAULT, IPL_NONE); | | | |
244 | iba.iba_tag = &sc->sc_i2c; | | 250 | iba.iba_tag = &sc->sc_i2c; |
245 | config_found_ia(self, "i2cbus", &iba, iicbus_print); | | 251 | config_found_ia(self, "i2cbus", &iba, iicbus_print); |
246 | } | | 252 | } |
| | | 253 | voyager_control_gpio(sc, ~(1 << 16), 0); |
| | | 254 | voyager_gpio_dir(sc, 0xffffffff, 1 << 16); |
| | | 255 | voyager_write_gpio(sc, 0xffffffff, 1 << 16); |
247 | } | | 256 | } |
248 | | | 257 | |
249 | static int | | 258 | static int |
250 | voyager_print(void *aux, const char *what) | | 259 | voyager_print(void *aux, const char *what) |
251 | { | | 260 | { |
252 | /*struct voyager_attach_args *vaa = aux;*/ | | 261 | /*struct voyager_attach_args *vaa = aux;*/ |
253 | | | 262 | |
254 | if (what == NULL) | | 263 | if (what == NULL) |
255 | return 0; | | 264 | return 0; |
256 | | | 265 | |
257 | printf("%s:", what); | | 266 | printf("%s:", what); |
258 | | | 267 | |
259 | return 0; | | 268 | return 0; |
| @@ -344,54 +353,38 @@ voyager_i2c_read_byte(void *cookie, uint | | | @@ -344,54 +353,38 @@ voyager_i2c_read_byte(void *cookie, uint |
344 | return ret; | | 353 | return ret; |
345 | } | | 354 | } |
346 | | | 355 | |
347 | static int | | 356 | static int |
348 | voyager_i2c_write_byte(void *cookie, uint8_t val, int flags) | | 357 | voyager_i2c_write_byte(void *cookie, uint8_t val, int flags) |
349 | { | | 358 | { |
350 | int ret; | | 359 | int ret; |
351 | | | 360 | |
352 | ret = i2c_bitbang_write_byte(cookie, val, flags, &voyager_i2cbb_ops); | | 361 | ret = i2c_bitbang_write_byte(cookie, val, flags, &voyager_i2cbb_ops); |
353 | delay(500); | | 362 | delay(500); |
354 | return ret; | | 363 | return ret; |
355 | } | | 364 | } |
356 | | | 365 | |
357 | /* gpio stuff */ | | | |
358 | void | | 366 | void |
359 | voyager_write_gpio(void *cookie, uint32_t mask, uint32_t bits) | | 367 | voyager_twiddle_bits(void *cookie, int regnum, uint32_t mask, uint32_t bits) |
360 | { | | 368 | { |
361 | struct voyager_softc *sc = cookie; | | 369 | struct voyager_softc *sc = cookie; |
362 | uint32_t reg; | | 370 | uint32_t reg; |
363 | | | 371 | |
364 | /* don't interfere with i2c ops */ | | 372 | /* don't interfere with i2c ops */ |
365 | mutex_enter(&sc->sc_i2c_lock); | | 373 | mutex_enter(&sc->sc_i2c_lock); |
366 | reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_GPIO_DATA0); | | 374 | reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, regnum); |
367 | reg &= mask; | | | |
368 | reg |= bits; | | | |
369 | bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_GPIO_DATA0, reg); | | | |
370 | mutex_exit(&sc->sc_i2c_lock); | | | |
371 | } | | | |
372 | | | | |
373 | void | | | |
374 | voyager_control_gpio(void *cookie, uint32_t mask, uint32_t bits) | | | |
375 | { | | | |
376 | struct voyager_softc *sc = cookie; | | | |
377 | uint32_t reg; | | | |
378 | | | | |
379 | /* don't interfere with i2c ops */ | | | |
380 | mutex_enter(&sc->sc_i2c_lock); | | | |
381 | reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_GPIO0_CONTROL); | | | |
382 | reg &= mask; | | 375 | reg &= mask; |
383 | reg |= bits; | | 376 | reg |= bits; |
384 | bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_GPIO0_CONTROL, reg); | | 377 | bus_space_write_4(sc->sc_memt, sc->sc_regh, regnum, reg); |
385 | mutex_exit(&sc->sc_i2c_lock); | | 378 | mutex_exit(&sc->sc_i2c_lock); |
386 | } | | 379 | } |
387 | | | 380 | |
388 | static int | | 381 | static int |
389 | voyager_intr(void *cookie) | | 382 | voyager_intr(void *cookie) |
390 | { | | 383 | { |
391 | struct voyager_softc *sc = cookie; | | 384 | struct voyager_softc *sc = cookie; |
392 | struct voyager_intr *ih; | | 385 | struct voyager_intr *ih; |
393 | uint32_t intrs; | | 386 | uint32_t intrs; |
394 | uint32_t mask, bit; | | 387 | uint32_t mask, bit; |
395 | int num; | | 388 | int num; |
396 | | | 389 | |
397 | intrs = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_INTR_STATUS); | | 390 | intrs = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_INTR_STATUS); |