Re: macppc: GPIO & macobio(4) cleanup

2011-05-12 Thread Martin Pieuchot
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 -  1.18
> +++ dev/i2s.c 26 Apr 2011 12:15:37 -
> @@ -46,6 +46,7 @@
>  
>  #include 
>  #include 
> +#include 
>  
>  #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 */
> - /*  0x00GPIO bit0 is output
> - 0x10media-bay power
> - 0x20reserved
> - 0x30MPIC */
> -
> -#define GPIO_ALTOE   0x08/* Alternate output enable */
> - /*  0x00Use DDR
> - 0x08Use 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 -  1.4
> +++ dev/xlights.c 26 Apr 2011 12:15:37 -
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  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 -  1.18
> +++ pci/macobio.c 26 Apr 2011 12:15:37 -
> @@ -45,6 +45,7 @@
>  
>  #include 
>  #include 
> +#include 
>  
>  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 = mac

macppc: GPIO & macobio(4) cleanup

2011-04-26 Thread Martin Pieuchot
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.

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 -  1.18
+++ dev/i2s.c   26 Apr 2011 12:15:37 -
@@ -46,6 +46,7 @@
 
 #include 
 #include 
+#include 
 
 #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_OUTSEL0xf0/* Output select */
-   /*  0x00GPIO bit0 is output
-   0x10media-bay power
-   0x20reserved
-   0x30MPIC */
-
-#define GPIO_ALTOE 0x08/* Alternate output enable */
-   /*  0x00Use DDR
-   0x08Use output select */
-
-#define GPIO_DDR   0x04/* Data direction */
-#define GPIO_DDR_OUTPUT0x04/* Output */
-#define GPIO_DDR_INPUT 0x00/* Input */
-
-#define GPIO_LEVEL 0x02/* Pin level (RO) */
-
-#defineGPIO_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 -  1.4
+++ dev/xlights.c   26 Apr 2011 12:15:37 -
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 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 -  1.18
+++ pci/macobio.c   26 Apr 2011 12:15:37 -
@@ -45,6 +45,7 @@
 
 #include 
 #include 
+#include 
 
 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 + off