Re: [OpenWrt-Devel] [PATCH 1/6] [kernel] ath9k: enable GPIO access for ar9287 and ar9285

2016-01-26 Thread Michal

Hello,

Hartmut, thanks for your input and help, it is always welcome.

> 
> [...] Why not create the gpio_chip just
> based on the fact, if a supported AR928x device is present or not?
> The support code will be there, already. So, the additional footprint
> of the gpio_chip is pretty small.
> 

I agree that ath9k GPIO chip should be visible regardless of
LED and/or button presence, I wanted to implement this later,
but it seems quite stable now so here it is - changed as requested.

I spent some time reorganizing patches to form more logical
entities - at least IMHO each of them is now providing complete
functionality, enhancement or fix. Due to changed structure, I
decided to attach all new patches to this thread, not to old ones.

I have also adjusted text formatting. Everything fits 80 cols.

Applied to r48508, compiled, it works. The only thing that has changed
from last trunk build is minor issue - it appears that empty PACKAGES
line in netgear.mk is not working anymore. USB modules sneaked
somehow into build image for my WNR2000v3 so for now there is only 108K
left in /overlay.

Best regards
Michal
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH 1/6] [kernel] ath9k: enable GPIO access for ar9287 and ar9285

2016-01-22 Thread Hartmut Knaack
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Michal Cieslakiewicz schrieb am 21.01.2016 um 00:11:
> From: Michal Cieslakiewicz 
> 
> Patch enables GPIO access for wireless chips ar9287 and ar9285.
> Key poller driver is activated when platform buttons are 
> defined. It also makes LEDs connected honour initial
> default_state and allows platform-supplied WLAN LED name.
> 
> Signed-off-by: Michal Cieslakiewicz 
> 

Looking pretty good over all. One problem throughout the whole set
however is, that you should diff from within your openwrt directory.
But the better way would be to use git format-patch.
Also, it might be a good idea to even split up this patch into the
topics that it covers: WLAN LED name and default state, registering
the gpio_chip and GPIO buttons. So that one patch addresses one issue.
Additional thoughts are inline.

> ---
> 
> This patch exports GPIOs connected to wireless chip. In some routers
> (for example Netgear WNR2000v3 which was used by me for development)
> certain buttons and LEDs are not connected to main SoC but to
> wifi chip instead.
> 
> Patch does the following:
> 
> * when CPTCFG_MAC80211_LEDS option is set and there are LEDs and/or 
>   buttons provided by device platform, ath9k module registers GPIO
>   chip, reserves GPIO pins and starts polling on keys using
>   'gpio-keys-polled' driver
> 
> * LED default_state is now honoured
> 
> * platform-supplied name for WLAN LED is supported (instead of
>   'ath9k-phy*' default)
> 
> GPIO chip base is auto-registered (as advised by kernel developers),
> so on my router pin numbers do not directly follow SoC GPIOs (0-19)
> but occupy numbers 53-63.
> 
> Due to nature of key polling, once started, module ath9k is locked
> and cannot be unloaded.
> 
> 
>  package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch |  368 
> 
>  target/linux/generic/files/include/linux/ath9k_platform.h   |5 
>  2 files changed, 373 insertions(+)
> 
> 
> diff -pruN 
> a/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch 
> b/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch
> --- a/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch 
> 1970-01-01 01:00:00.0 +0100
> +++ b/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch 
> 2016-01-20 19:56:46.681693574 +0100
> @@ -0,0 +1,368 @@
> +diff -pruN a/drivers/net/wireless/ath/ath9k/ath9k.h 
> b/drivers/net/wireless/ath/ath9k/ath9k.h
> +--- a/drivers/net/wireless/ath/ath9k/ath9k.h 2016-01-20 19:52:13.849779144 
> +0100
>  b/drivers/net/wireless/ath/ath9k/ath9k.h 2016-01-20 19:52:13.752784871 
> +0100
> +@@ -24,6 +24,7 @@
> + #include 
> + #include 
> + #include 
> ++#include 
> + 
> + #include "common.h"
> + #include "debug.h"
> +@@ -817,6 +818,15 @@ void ath_fill_led_pin(struct ath_softc *
> + int ath_create_gpio_led(struct ath_softc *sc, int gpio, const char *name,
> + const char *trigger, bool active_low);
> + 
> ++//
> ++/*GPIO & Buttons*/
> ++//
> ++
> ++void ath9k_register_gpio_chip(struct ath_softc *sc);
> ++void ath9k_unregister_gpio_chip(struct ath_softc *sc);
> ++void ath9k_init_buttons(struct ath_softc *sc);
> ++void ath9k_deinit_buttons(struct ath_softc *sc);
> ++
> + #else
> + static inline void ath_init_leds(struct ath_softc *sc)
> + {
> +@@ -828,6 +838,20 @@ static inline void ath_deinit_leds(struc
> + static inline void ath_fill_led_pin(struct ath_softc *sc)
> + {
> + }
> ++
> ++static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
> ++{
> ++}
> ++static inline void ath9k_unregister_gpio_chip(struct ath_softc *sc)
> ++{
> ++}
> ++
> ++void ath9k_init_buttons(struct ath_softc *sc)
> ++{
> ++}
> ++void ath9k_deinit_buttons(struct ath_softc *sc)
> ++{
> ++}
> + #endif
> + 
> + //
> +@@ -963,6 +987,12 @@ struct ath_led {
> + struct led_classdev cdev;
> + };
> + 
> ++struct ath9k_gpio_chip {
> ++struct ath_softc *sc;
> ++char label[32];
> ++struct gpio_chip gchip;
> ++};
> ++
> + struct ath_softc {
> + struct ieee80211_hw *hw;
> + struct device *dev;
> +@@ -1017,6 +1047,10 @@ struct ath_softc {
> + #ifdef CPTCFG_MAC80211_LEDS
> + const char *led_default_trigger;
> + struct list_head leds;
> ++
> ++struct ath9k_gpio_chip *gpiochip;
> ++
> ++struct platform_device *btnpdev;/* gpio-keys-polled */
> + #endif
> + 
> + #ifdef CPTCFG_ATH9K_DEBUGFS
> +diff -pruN a/drivers/net/wireless/ath/ath9k/gpio.c 
> b/drivers/net/wireless/ath/ath9k/gpio.c
> +--- a/drivers/net/wireless/ath/ath9k/gpio.c  2016-01-20 19:52:13.859778553 
> +0100
>  b/drivers/net/wireless/ath/ath9k/gpio.c  2016-01-20 19:52:13.761784340 
> +0100
> +@@ -22,6 +22,11 @@
> + //
> + 
> + #ifdef CPTCFG_MAC80211_LEDS
> ++
> ++#include 
> ++#include 
> ++#include 
> ++
> + static void ath_led_brightness(struct led_classdev *led_cdev,
> +   

[OpenWrt-Devel] [PATCH 1/6] [kernel] ath9k: enable GPIO access for ar9287 and ar9285

2016-01-20 Thread Michal Cieslakiewicz
From: Michal Cieslakiewicz 

Patch enables GPIO access for wireless chips ar9287 and ar9285.
Key poller driver is activated when platform buttons are 
defined. It also makes LEDs connected honour initial
default_state and allows platform-supplied WLAN LED name.

Signed-off-by: Michal Cieslakiewicz 

---

This patch exports GPIOs connected to wireless chip. In some routers
(for example Netgear WNR2000v3 which was used by me for development)
certain buttons and LEDs are not connected to main SoC but to
wifi chip instead.

Patch does the following:

* when CPTCFG_MAC80211_LEDS option is set and there are LEDs and/or 
  buttons provided by device platform, ath9k module registers GPIO
  chip, reserves GPIO pins and starts polling on keys using
  'gpio-keys-polled' driver

* LED default_state is now honoured

* platform-supplied name for WLAN LED is supported (instead of
  'ath9k-phy*' default)

GPIO chip base is auto-registered (as advised by kernel developers),
so on my router pin numbers do not directly follow SoC GPIOs (0-19)
but occupy numbers 53-63.

Due to nature of key polling, once started, module ath9k is locked
and cannot be unloaded.


 package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch |  368 
 target/linux/generic/files/include/linux/ath9k_platform.h   |5 
 2 files changed, 373 insertions(+)


diff -pruN 
a/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch 
b/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch
--- a/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch   
1970-01-01 01:00:00.0 +0100
+++ b/openwrt/package/kernel/mac80211/patches/546-ath9k-gpio-enable.patch   
2016-01-20 19:56:46.681693574 +0100
@@ -0,0 +1,368 @@
+diff -pruN a/drivers/net/wireless/ath/ath9k/ath9k.h 
b/drivers/net/wireless/ath/ath9k/ath9k.h
+--- a/drivers/net/wireless/ath/ath9k/ath9k.h   2016-01-20 19:52:13.849779144 
+0100
 b/drivers/net/wireless/ath/ath9k/ath9k.h   2016-01-20 19:52:13.752784871 
+0100
+@@ -24,6 +24,7 @@
+ #include 
+ #include 
+ #include 
++#include 
+ 
+ #include "common.h"
+ #include "debug.h"
+@@ -817,6 +818,15 @@ void ath_fill_led_pin(struct ath_softc *
+ int ath_create_gpio_led(struct ath_softc *sc, int gpio, const char *name,
+ const char *trigger, bool active_low);
+ 
++//
++/*GPIO & Buttons*/
++//
++
++void ath9k_register_gpio_chip(struct ath_softc *sc);
++void ath9k_unregister_gpio_chip(struct ath_softc *sc);
++void ath9k_init_buttons(struct ath_softc *sc);
++void ath9k_deinit_buttons(struct ath_softc *sc);
++
+ #else
+ static inline void ath_init_leds(struct ath_softc *sc)
+ {
+@@ -828,6 +838,20 @@ static inline void ath_deinit_leds(struc
+ static inline void ath_fill_led_pin(struct ath_softc *sc)
+ {
+ }
++
++static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
++{
++}
++static inline void ath9k_unregister_gpio_chip(struct ath_softc *sc)
++{
++}
++
++void ath9k_init_buttons(struct ath_softc *sc)
++{
++}
++void ath9k_deinit_buttons(struct ath_softc *sc)
++{
++}
+ #endif
+ 
+ //
+@@ -963,6 +987,12 @@ struct ath_led {
+   struct led_classdev cdev;
+ };
+ 
++struct ath9k_gpio_chip {
++  struct ath_softc *sc;
++  char label[32];
++  struct gpio_chip gchip;
++};
++
+ struct ath_softc {
+   struct ieee80211_hw *hw;
+   struct device *dev;
+@@ -1017,6 +1047,10 @@ struct ath_softc {
+ #ifdef CPTCFG_MAC80211_LEDS
+   const char *led_default_trigger;
+   struct list_head leds;
++
++  struct ath9k_gpio_chip *gpiochip;
++
++  struct platform_device *btnpdev;/* gpio-keys-polled */
+ #endif
+ 
+ #ifdef CPTCFG_ATH9K_DEBUGFS
+diff -pruN a/drivers/net/wireless/ath/ath9k/gpio.c 
b/drivers/net/wireless/ath/ath9k/gpio.c
+--- a/drivers/net/wireless/ath/ath9k/gpio.c2016-01-20 19:52:13.859778553 
+0100
 b/drivers/net/wireless/ath/ath9k/gpio.c2016-01-20 19:52:13.761784340 
+0100
+@@ -22,6 +22,11 @@
+ //
+ 
+ #ifdef CPTCFG_MAC80211_LEDS
++
++#include 
++#include 
++#include 
++
+ static void ath_led_brightness(struct led_classdev *led_cdev,
+  enum led_brightness brightness)
+ {
+@@ -54,8 +59,15 @@ static int ath_add_led(struct ath_softc
+   ath9k_hw_cfg_output(sc->sc_ah, gpio->gpio,
+   AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
+ 
+-  /* LED off */
+-  ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
++  /* set default LED state */
++  if (gpio->default_state == LEDS_GPIO_DEFSTATE_ON)
++  ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, !gpio->active_low);
++  else
++  ath9k_hw_set_gpio(sc->sc_ah, gpio->gpio, gpio->active_low);
++
++  /* if there is GPIO chip configured, reserve LED pin */
++  if (sc->gpiochip)
++  gpio_request(sc->gpiochip->gchip.base + gpio->gpio, gpio->name);
+ 
+   return 0;
+ }