ath9k: Add airtime fairness scheduler
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 549-ath9k_enable_gpio_buttons.patch
1 From: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
2 Subject: [PATCH v5 5/8] mac80211: ath9k: enable GPIO buttons
3
4 Enable platform-defined GPIO button support for ath9k device.
5 Key poller is activated for attached platform buttons.
6 Requires ath9k GPIO chip access.
7
8 Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
10 ---
11 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
12 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
13 @@ -1048,6 +1048,7 @@ struct ath_softc {
14         struct list_head leds;
15  #ifdef CONFIG_GPIOLIB
16         struct ath9k_gpio_chip *gpiochip;
17 +       struct platform_device *btnpdev;        /* gpio-keys-polled */
18  #endif
19  #endif
20  
21 --- a/drivers/net/wireless/ath/ath9k/gpio.c
22 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
23 @@ -17,6 +17,8 @@
24  #include "ath9k.h"
25  #include <linux/ath9k_platform.h>
26  #include <linux/gpio.h>
27 +#include <linux/platform_device.h>
28 +#include <linux/gpio_keys.h>
29  
30  #ifdef CPTCFG_MAC80211_LEDS
31  
32 @@ -129,6 +131,64 @@ static void ath9k_unregister_gpio_chip(s
33         sc->gpiochip = NULL;
34  }
35  
36 +/******************/
37 +/*  GPIO Buttons  */
38 +/******************/
39 +
40 +/* add GPIO buttons */
41 +static void ath9k_init_buttons(struct ath_softc *sc)
42 +{
43 +       struct ath9k_platform_data *pdata = sc->dev->platform_data;
44 +       struct platform_device *pdev;
45 +       struct gpio_keys_platform_data gkpdata;
46 +       struct gpio_keys_button *bt;
47 +       int i;
48 +
49 +       if (!sc->gpiochip)
50 +               return;
51 +
52 +       if (!pdata || !pdata->btns || !pdata->num_btns)
53 +               return;
54 +
55 +       bt = devm_kmemdup(sc->dev, pdata->btns,
56 +                         pdata->num_btns * sizeof(struct gpio_keys_button),
57 +                         GFP_KERNEL);
58 +       if (!bt)
59 +               return;
60 +
61 +       for (i = 0; i < pdata->num_btns; i++) {
62 +               ath9k_hw_gpio_request_in(sc->sc_ah, pdata->btns[i].gpio,
63 +                                        "ath9k-gpio");
64 +               bt[i].gpio = sc->gpiochip->gchip.base + pdata->btns[i].gpio;
65 +       }
66 +
67 +       memset(&gkpdata, 0, sizeof(struct gpio_keys_platform_data));
68 +       gkpdata.buttons = bt;
69 +       gkpdata.nbuttons = pdata->num_btns;
70 +       gkpdata.poll_interval = pdata->btn_poll_interval;
71 +
72 +       pdev = platform_device_register_data(sc->dev, "gpio-keys-polled",
73 +                                            PLATFORM_DEVID_AUTO, &gkpdata,
74 +                                            sizeof(gkpdata));
75 +       if (!IS_ERR_OR_NULL(pdev))
76 +               sc->btnpdev = pdev;
77 +       else {
78 +               sc->btnpdev = NULL;
79 +               devm_kfree(sc->dev, bt);
80 +       }
81 +}
82 +
83 +/* remove GPIO buttons */
84 +static void ath9k_deinit_buttons(struct ath_softc *sc)
85 +{
86 +       if (!sc->gpiochip || !sc->btnpdev)
87 +               return;
88 +
89 +       platform_device_unregister(sc->btnpdev);
90 +
91 +       sc->btnpdev = NULL;
92 +}
93 +
94  #else /* CONFIG_GPIOLIB */
95  
96  static inline void ath9k_register_gpio_chip(struct ath_softc *sc)
97 @@ -139,6 +199,14 @@ static inline void ath9k_unregister_gpio
98  {
99  }
100  
101 +static inline void ath9k_init_buttons(struct ath_softc *sc)
102 +{
103 +}
104 +
105 +static inline void ath9k_deinit_buttons(struct ath_softc *sc)
106 +{
107 +}
108 +
109  #endif /* CONFIG_GPIOLIB */
110  
111  /********************************/
112 @@ -262,6 +330,7 @@ void ath_deinit_leds(struct ath_softc *s
113  {
114         struct ath_led *led;
115  
116 +       ath9k_deinit_buttons(sc);
117         while (!list_empty(&sc->leds)) {
118                 led = list_first_entry(&sc->leds, struct ath_led, list);
119  #ifdef CONFIG_GPIOLIB
120 @@ -293,6 +362,7 @@ void ath_init_leds(struct ath_softc *sc)
121         ath_fill_led_pin(sc);
122  
123         ath9k_register_gpio_chip(sc);
124 +       ath9k_init_buttons(sc);
125  
126         if (pdata && pdata->led_name)
127                 strncpy(led_name, pdata->led_name, sizeof(led_name));
128 @@ -308,7 +378,7 @@ void ath_init_leds(struct ath_softc *sc)
129         ath_create_gpio_led(sc, sc->sc_ah->led_pin, led_name, trigger,
130                            !sc->sc_ah->config.led_active_high);
131  
132 -       if (!pdata)
133 +       if (!pdata || !pdata->leds || !pdata->num_leds)
134                 return;
135  
136         for (i = 0; i < pdata->num_leds; i++)
137 --- a/include/linux/ath9k_platform.h
138 +++ b/include/linux/ath9k_platform.h
139 @@ -50,6 +50,10 @@ struct ath9k_platform_data {
140         int num_leds;
141         const struct gpio_led *leds;
142         const char *led_name;
143 +
144 +       unsigned num_btns;
145 +       const struct gpio_keys_button *btns;
146 +       unsigned btn_poll_interval;
147  };
148  
149  #endif /* _LINUX_ATH9K_PLATFORM_H */