On 26/04/11(Tue) 18:22, Martin Pieuchot wrote:
> On macppc there are many way to get the gpio addresses of the devices 
> through the openfirmware.
> 
> Depending of the model you can read that address directly (property
> AAPL,address), read an offset (in reg) sometimes relative to the gpio
> controllers address sometimes relative to the base address of the I/O
> bus. And sometimes the address/offset is not even read but hardcoded in
> the drivers.
> 
> The following diff is a first step to unify this and exposes 4 methods,
> 3 of which already existed, to manage gpios with an offset from the I/O
> bus base address.

I didn't get any comment on this independently from the DFS diff. Any
thought?

> Index: dev/i2s.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/macppc/dev/i2s.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 i2s.c
> --- dev/i2s.c 15 Jul 2010 03:43:11 -0000      1.18
> +++ dev/i2s.c 26 Apr 2011 12:15:37 -0000
> @@ -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)
>  {
> @@ -951,7 +929,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--) {
> @@ -967,7 +945,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;
>  
> Index: dev/xlights.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/macppc/dev/xlights.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 xlights.c
> --- dev/xlights.c     30 Sep 2008 04:54:00 -0000      1.4
> +++ dev/xlights.c     26 Apr 2011 12:15:37 -0000
> @@ -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_sof
>  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,
> Index: pci/macobio.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/macppc/pci/macobio.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 macobio.c
> --- pci/macobio.c     22 Aug 2009 02:54:50 -0000      1.18
> +++ pci/macobio.c     26 Apr 2011 12:15:37 -0000
> @@ -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 *a
>       (*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_
>       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,13 +280,23 @@ keylargo_fcr_disable(int offset, u_int32
>  }
>  
>  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)
>               return -1;
>  
>       return in32rb(sc->obiomem + 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
> Index: pci/macobio.h
> ===================================================================
> RCS file: pci/macobio.h
> diff -N pci/macobio.h
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ pci/macobio.h     26 Apr 2011 12:15:37 -0000
> @@ -0,0 +1,33 @@
> +/*   $OpenBSD$       */
> +/*
> + * Copyright (c) 2011 Martin Pieuchot <[email protected]>
> + *
> + * 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_ */

Reply via email to