diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2011-05-15 09:10:27 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2011-05-15 09:10:27 +0000 |
commit | ba4a2dd268e0b0f4a560e51e8b0d8fde9e11fea0 (patch) | |
tree | 72404b966034fa5c72d2c657ea92c5e46db3b970 /sys | |
parent | b23c9010b334312c087e605426a2d7ff7324fd9f (diff) |
Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.
On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.
looks fine to kettenis@, ok miod@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/macppc/dev/i2s.c | 30 | ||||
-rw-r--r-- | sys/arch/macppc/dev/smu.c | 13 | ||||
-rw-r--r-- | sys/arch/macppc/dev/xlights.c | 11 | ||||
-rw-r--r-- | sys/arch/macppc/pci/macobio.c | 23 | ||||
-rw-r--r-- | sys/arch/macppc/pci/macobio.h | 33 |
5 files changed, 60 insertions, 50 deletions
diff --git a/sys/arch/macppc/dev/i2s.c b/sys/arch/macppc/dev/i2s.c index 3d0727fee02..40774112d96 100644 --- a/sys/arch/macppc/dev/i2s.c +++ b/sys/arch/macppc/dev/i2s.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i2s.c,v 1.20 2011/05/05 18:54:23 jasper Exp $ */ +/* $OpenBSD: i2s.c,v 1.21 2011/05/15 09:10:26 mpi Exp $ */ /* $NetBSD: i2s.c,v 1.1 2003/12/27 02:19:34 grant Exp $ */ /*- @@ -46,6 +46,7 @@ #include <macppc/dev/i2svar.h> #include <macppc/dev/i2sreg.h> +#include <macppc/pci/macobio.h> #ifdef I2S_DEBUG # define DPRINTF(x) printf x @@ -78,10 +79,6 @@ void i2s_init(struct i2s_softc *, int); int i2s_intr(void *); int i2s_iintr(void *); -/* XXX */ -void keylargo_fcr_enable(int, u_int32_t); -void keylargo_fcr_disable(int, u_int32_t); - struct cfdriver i2s_cd = { NULL, "i2s", DV_DULL }; @@ -95,25 +92,6 @@ static int headphone_detect_active; static u_char *lineout_detect; static int lineout_detect_active; -/* GPIO bits */ -#define GPIO_OUTSEL 0xf0 /* Output select */ - /* 0x00 GPIO bit0 is output - 0x10 media-bay power - 0x20 reserved - 0x30 MPIC */ - -#define GPIO_ALTOE 0x08 /* Alternate output enable */ - /* 0x00 Use DDR - 0x08 Use output select */ - -#define GPIO_DDR 0x04 /* Data direction */ -#define GPIO_DDR_OUTPUT 0x04 /* Output */ -#define GPIO_DDR_INPUT 0x00 /* Input */ - -#define GPIO_LEVEL 0x02 /* Pin level (RO) */ - -#define GPIO_DATA 0x01 /* Data */ - void i2s_attach(struct device *parent, struct i2s_softc *sc, struct confargs *ca) { @@ -992,7 +970,7 @@ i2s_set_rate(sc, rate) /* Clear CLKSTOPPEND */ out32rb(sc->sc_reg + I2S_INT, I2S_INT_CLKSTOPPEND); - keylargo_fcr_disable(I2SClockOffset, I2S0CLKEN); + macobio_disable(I2SClockOffset, I2S0CLKEN); /* Wait until clock is stopped */ for (timo = 50; timo > 0; timo--) { @@ -1008,7 +986,7 @@ done: in32rb(sc->sc_reg + I2S_FORMAT), reg)); out32rb(sc->sc_reg + I2S_FORMAT, reg); - keylargo_fcr_enable(I2SClockOffset, I2S0CLKEN); + macobio_enable(I2SClockOffset, I2S0CLKEN); sc->sc_rate = rate; diff --git a/sys/arch/macppc/dev/smu.c b/sys/arch/macppc/dev/smu.c index dc933372032..1285278fe48 100644 --- a/sys/arch/macppc/dev/smu.c +++ b/sys/arch/macppc/dev/smu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smu.c,v 1.22 2009/08/12 14:11:52 kettenis Exp $ */ +/* $OpenBSD: smu.c,v 1.23 2011/05/15 09:10:26 mpi Exp $ */ /* * Copyright (c) 2005 Mark Kettenis @@ -31,7 +31,8 @@ #include <dev/i2c/i2cvar.h> #include <dev/ofw/openfirm.h> -#include <arch/macppc/dev/maci2cvar.h> +#include <macppc/dev/maci2cvar.h> +#include <macppc/pci/macobio.h> int smu_match(struct device *, void *, void *); void smu_attach(struct device *, struct device *, void *); @@ -154,14 +155,6 @@ int smu_i2c_exec(void *, i2c_op_t, i2c_addr_t, void smu_slew_voltage(u_int); -#define GPIO_DDR 0x04 /* Data direction */ -#define GPIO_DDR_OUTPUT 0x04 /* Output */ -#define GPIO_DDR_INPUT 0x00 /* Input */ - -#define GPIO_LEVEL 0x02 /* Pin level (RO) */ - -#define GPIO_DATA 0x01 /* Data */ - int smu_match(struct device *parent, void *cf, void *aux) { diff --git a/sys/arch/macppc/dev/xlights.c b/sys/arch/macppc/dev/xlights.c index 8793070c851..daf2e0e2603 100644 --- a/sys/arch/macppc/dev/xlights.c +++ b/sys/arch/macppc/dev/xlights.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xlights.c,v 1.4 2008/09/30 04:54:00 drahn Exp $ */ +/* $OpenBSD: xlights.c,v 1.5 2011/05/15 09:10:26 mpi Exp $ */ /* * Copyright (c) 2007 Gordon Willem Klok <gwk@openbsd,org> * @@ -27,6 +27,7 @@ #include <machine/autoconf.h> #include <macppc/dev/dbdma.h> #include <macppc/dev/i2sreg.h> +#include <macppc/pci/macobio.h> struct xlights_softc { struct device sc_dev; @@ -55,8 +56,6 @@ void xlights_startdma(struct xlights_softc *); void xlights_deferred(void *); void xlights_theosDOT(void *); void xlights_timeout(void *); -extern void keylargo_fcr_enable(int, u_int32_t); -extern void keylargo_fcr_disable(int, u_int32_t); struct cfattach xlights_ca = { sizeof(struct xlights_softc), xlights_match, @@ -170,9 +169,9 @@ xlights_attach(struct device *parent, struct device *self, void *aux) printf(": irq %d\n", sc->sc_intr); - keylargo_fcr_enable(I2SClockOffset, I2S0EN); + macobio_enable(I2SClockOffset, I2S0EN); out32rb(sc->sc_reg + I2S_INT, I2S_INT_CLKSTOPPEND); - keylargo_fcr_disable(I2SClockOffset, I2S0CLKEN); + macobio_disable(I2SClockOffset, I2S0CLKEN); for (error = 0; error < 1000; error++) { if (in32rb(sc->sc_reg + I2S_INT) & I2S_INT_CLKSTOPPEND) { error = 0; @@ -189,7 +188,7 @@ xlights_attach(struct device *parent, struct device *self, void *aux) type, IPL_AUDIO, xlights_intr, sc, sc->sc_dev.dv_xname); out32rb(sc->sc_reg + I2S_FORMAT, CLKSRC_VS); - keylargo_fcr_enable(I2SClockOffset, I2S0CLKEN); + macobio_enable(I2SClockOffset, I2S0CLKEN); kthread_create_deferred(xlights_deferred, sc); timeout_set(&sc->sc_tmo, xlights_timeout, sc); diff --git a/sys/arch/macppc/pci/macobio.c b/sys/arch/macppc/pci/macobio.c index b335c558866..a4656a65506 100644 --- a/sys/arch/macppc/pci/macobio.c +++ b/sys/arch/macppc/pci/macobio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: macobio.c,v 1.18 2009/08/22 02:54:50 mk Exp $ */ +/* $OpenBSD: macobio.c,v 1.19 2011/05/15 09:10:26 mpi Exp $ */ /* $NetBSD: obio.c,v 1.6 1999/05/01 10:36:08 tsubai Exp $ */ /*- @@ -45,6 +45,7 @@ #include <machine/bus.h> #include <machine/autoconf.h> +#include <macppc/pci/macobio.h> void macobio_attach(struct device *, struct device *, void *); int macobio_match(struct device *, void *, void *); @@ -257,12 +258,8 @@ mac_intr_disestablish(void *lcp, void *arg) (*mac_intr_disestablish_func)(lcp, arg); } -void keylargo_fcr_enable(int offset, u_int32_t bits); -void keylargo_fcr_disable(int offset, u_int32_t bits); -u_int32_t keylargo_fcr_read(int offset); - void -keylargo_fcr_enable(int offset, u_int32_t bits) +macobio_enable(int offset, u_int32_t bits) { struct macobio_softc *sc = macobio_cd.cd_devs[0]; if (sc->obiomem == 0) @@ -272,7 +269,7 @@ keylargo_fcr_enable(int offset, u_int32_t bits) out32rb(sc->obiomem + offset, bits); } void -keylargo_fcr_disable(int offset, u_int32_t bits) +macobio_disable(int offset, u_int32_t bits) { struct macobio_softc *sc = macobio_cd.cd_devs[0]; if (sc->obiomem == 0) @@ -283,7 +280,7 @@ keylargo_fcr_disable(int offset, u_int32_t bits) } u_int32_t -keylargo_fcr_read(int offset) +macobio_read(int offset) { struct macobio_softc *sc = macobio_cd.cd_devs[0]; if (sc->obiomem == 0) @@ -293,6 +290,16 @@ keylargo_fcr_read(int offset) } void +macobio_write(int offset, u_int32_t bits) +{ + struct macobio_softc *sc = macobio_cd.cd_devs[0]; + if (sc->obiomem == 0) + return; + + out32rb(sc->obiomem + offset, bits); +} + +void macobio_modem_power(int enable) { u_int32_t val; diff --git a/sys/arch/macppc/pci/macobio.h b/sys/arch/macppc/pci/macobio.h new file mode 100644 index 00000000000..a87b08a3480 --- /dev/null +++ b/sys/arch/macppc/pci/macobio.h @@ -0,0 +1,33 @@ +/* $OpenBSD: macobio.h,v 1.1 2011/05/15 09:10:26 mpi Exp $ */ +/* + * Copyright (c) 2011 Martin Pieuchot <mp@nolizard.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACOBIO_H_ +#define _MACOBIO_H_ + +#define GPIO_DDR_INPUT 0x00 +#define GPIO_DDR_OUTPUT 0x04 + +#define GPIO_DATA 0x01 /* Data */ +#define GPIO_LEVEL 0x02 /* Pin level (RO) */ + +void macobio_enable(int, u_int32_t); +void macobio_disable(int, u_int32_t); +u_int32_t macobio_read(int); +void macobio_write(int, u_int32_t); + + +#endif /* _MACOBIO_H_ */ |