driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: wfx: Get descriptors for GPIOs
@ 2020-06-27 11:59 Linus Walleij
  2020-06-27 17:55 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-06-27 11:59 UTC (permalink / raw)
  To: gregkh; +Cc: devel, Linus Walleij

The code has the functionality to insert the GPIO lines using
the global GPIO numbers through module parameters.

As we are clearly deprecating the use of global GPIO numbers
look up the GPIO descriptors from the device instead. This
usually falls back to device hardware descriptions using e.g.
device tree or ACPI. This device clearly supports device
tree when used over SPI for example.

For example, this can be supplied in the device tree like so:

  wfx@0x01 {
      compatible = "silabs,wf200";
      reset-gpios = <&gpio0 1>;
      wakeup-gpios = <&gpio0 2>;
  };

Cc: Jérôme Pouiller <jerome.pouiller@silabs.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/staging/wfx/bus_spi.c | 11 +++++----
 drivers/staging/wfx/main.c    | 42 ++++-------------------------------
 drivers/staging/wfx/main.h    |  2 --
 3 files changed, 9 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/wfx/bus_spi.c b/drivers/staging/wfx/bus_spi.c
index e8da61fb096b..88ca5d453e83 100644
--- a/drivers/staging/wfx/bus_spi.c
+++ b/drivers/staging/wfx/bus_spi.c
@@ -8,7 +8,6 @@
  */
 #include <linux/module.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
 #include <linux/spi/spi.h>
 #include <linux/interrupt.h>
@@ -21,10 +20,6 @@
 #include "main.h"
 #include "bh.h"
 
-static int gpio_reset = -2;
-module_param(gpio_reset, int, 0644);
-MODULE_PARM_DESC(gpio_reset, "gpio number for reset. -1 for none.");
-
 #define SET_WRITE 0x7FFF        /* usage: and operation */
 #define SET_READ 0x8000         /* usage: or operation */
 
@@ -211,10 +206,14 @@ static int wfx_spi_probe(struct spi_device *func)
 		bus->need_swab = true;
 	spi_set_drvdata(func, bus);
 
-	bus->gpio_reset = wfx_get_gpio(&func->dev, gpio_reset, "reset");
+	bus->gpio_reset = devm_gpiod_get_optional(&func->dev, "reset"
+						  GPIOD_OUT_HIGH);
+	if (IS_ERR(bus->gpio_reset))
+		return PTR_ERR(bus->gpio_reset);
 	if (!bus->gpio_reset) {
 		dev_warn(&func->dev, "try to load firmware anyway\n");
 	} else {
+		gpiod_set_consumer_name(bus->gpio_reset, "wfx reset");
 		if (spi_get_device_id(func)->driver_data & WFX_RESET_INVERTED)
 			gpiod_toggle_active_low(bus->gpio_reset);
 		gpiod_set_value_cansleep(bus->gpio_reset, 1);
diff --git a/drivers/staging/wfx/main.c b/drivers/staging/wfx/main.c
index 6bd96f476388..cd58173f7294 100644
--- a/drivers/staging/wfx/main.c
+++ b/drivers/staging/wfx/main.c
@@ -13,7 +13,6 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_net.h>
-#include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
 #include <linux/mmc/sdio_func.h>
 #include <linux/spi/spi.h>
@@ -41,10 +40,6 @@ MODULE_DESCRIPTION("Silicon Labs 802.11 Wireless LAN driver for WFx");
 MODULE_AUTHOR("Jérôme Pouiller <jerome.pouiller@silabs.com>");
 MODULE_LICENSE("GPL");
 
-static int gpio_wakeup = -2;
-module_param(gpio_wakeup, int, 0644);
-MODULE_PARM_DESC(gpio_wakeup, "gpio number for wakeup. -1 for none.");
-
 #define RATETAB_ENT(_rate, _rateid, _flags) { \
 	.bitrate  = (_rate),   \
 	.hw_value = (_rateid), \
@@ -170,38 +165,6 @@ bool wfx_api_older_than(struct wfx_dev *wdev, int major, int minor)
 	return false;
 }
 
-struct gpio_desc *wfx_get_gpio(struct device *dev,
-			       int override, const char *label)
-{
-	struct gpio_desc *ret;
-	char label_buf[256];
-
-	if (override >= 0) {
-		snprintf(label_buf, sizeof(label_buf), "wfx_%s", label);
-		ret = ERR_PTR(devm_gpio_request_one(dev, override,
-						    GPIOF_OUT_INIT_LOW,
-						    label_buf));
-		if (!ret)
-			ret = gpio_to_desc(override);
-	} else if (override == -1) {
-		ret = NULL;
-	} else {
-		ret = devm_gpiod_get(dev, label, GPIOD_OUT_LOW);
-	}
-	if (IS_ERR_OR_NULL(ret)) {
-		if (!ret || PTR_ERR(ret) == -ENOENT)
-			dev_warn(dev, "gpio %s is not defined\n", label);
-		else
-			dev_warn(dev, "error while requesting gpio %s\n",
-				 label);
-		ret = NULL;
-	} else {
-		dev_dbg(dev, "using gpio %d for %s\n",
-			desc_to_gpio(ret), label);
-	}
-	return ret;
-}
-
 /* NOTE: wfx_send_pds() destroy buf */
 int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len)
 {
@@ -340,7 +303,10 @@ struct wfx_dev *wfx_init_common(struct device *dev,
 	memcpy(&wdev->pdata, pdata, sizeof(*pdata));
 	of_property_read_string(dev->of_node, "config-file",
 				&wdev->pdata.file_pds);
-	wdev->pdata.gpio_wakeup = wfx_get_gpio(dev, gpio_wakeup, "wakeup");
+	wdev->pdata.gpio_wakeup = devm_gpiod_get(dev, "wakeup", GPIOD_IN);
+	if (IS_ERR(wdev->pdata.gpio_wakeup))
+		return PTR_ERR(wdev->pdata.gpio_wakeup);
+	gpiod_set_consumer_name(wdev->pdata.gpio_wakep, "wfx wakeup");
 	wfx_sl_fill_pdata(dev, &wdev->pdata);
 
 	mutex_init(&wdev->conf_mutex);
diff --git a/drivers/staging/wfx/main.h b/drivers/staging/wfx/main.h
index f832ce409fda..c59d375dd3ad 100644
--- a/drivers/staging/wfx/main.h
+++ b/drivers/staging/wfx/main.h
@@ -38,8 +38,6 @@ struct wfx_dev *wfx_init_common(struct device *dev,
 int wfx_probe(struct wfx_dev *wdev);
 void wfx_release(struct wfx_dev *wdev);
 
-struct gpio_desc *wfx_get_gpio(struct device *dev, int override,
-			       const char *label);
 bool wfx_api_older_than(struct wfx_dev *wdev, int major, int minor);
 int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len);
 
-- 
2.25.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: wfx: Get descriptors for GPIOs
  2020-06-27 11:59 [PATCH] staging: wfx: Get descriptors for GPIOs Linus Walleij
@ 2020-06-27 17:55 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-06-27 17:55 UTC (permalink / raw)
  To: Linus Walleij, gregkh; +Cc: devel, clang-built-linux, Linus Walleij, kbuild-all

[-- Attachment #1: Type: text/plain, Size: 5861 bytes --]

Hi Linus,

I love your patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]

url:    https://github.com/0day-ci/linux/commits/Linus-Walleij/staging-wfx-Get-descriptors-for-GPIOs/20200627-200038
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git a8e773132f131511357d9529c289ed52330e232a
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project ee3620643dfc88a178fa4ca116cf83014e4ee547)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

>> drivers/staging/wfx/main.c:308:10: warning: incompatible integer to pointer conversion returning 'long' from a function with result type 'struct wfx_dev *' [-Wint-conversion]
                   return PTR_ERR(wdev->pdata.gpio_wakeup);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/staging/wfx/main.c:309:38: error: no member named 'gpio_wakep' in 'struct wfx_platform_data'; did you mean 'gpio_wakeup'?
           gpiod_set_consumer_name(wdev->pdata.gpio_wakep, "wfx wakeup");
                                               ^~~~~~~~~~
                                               gpio_wakeup
   drivers/staging/wfx/main.h:25:20: note: 'gpio_wakeup' declared here
           struct gpio_desc *gpio_wakeup;
                             ^
   1 warning and 1 error generated.
--
>> drivers/staging/wfx/bus_spi.c:210:9: error: expected ')'
                                                     GPIOD_OUT_HIGH);
                                                     ^
   drivers/staging/wfx/bus_spi.c:209:43: note: to match this '('
           bus->gpio_reset = devm_gpiod_get_optional(&func->dev, "reset"
                                                    ^
   1 error generated.

vim +309 drivers/staging/wfx/main.c

   245	
   246	struct wfx_dev *wfx_init_common(struct device *dev,
   247					const struct wfx_platform_data *pdata,
   248					const struct hwbus_ops *hwbus_ops,
   249					void *hwbus_priv)
   250	{
   251		struct ieee80211_hw *hw;
   252		struct wfx_dev *wdev;
   253	
   254		hw = ieee80211_alloc_hw(sizeof(struct wfx_dev), &wfx_ops);
   255		if (!hw)
   256			return NULL;
   257	
   258		SET_IEEE80211_DEV(hw, dev);
   259	
   260		ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
   261		ieee80211_hw_set(hw, AMPDU_AGGREGATION);
   262		ieee80211_hw_set(hw, CONNECTION_MONITOR);
   263		ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
   264		ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
   265		ieee80211_hw_set(hw, SIGNAL_DBM);
   266		ieee80211_hw_set(hw, SUPPORTS_PS);
   267		ieee80211_hw_set(hw, MFP_CAPABLE);
   268	
   269		hw->vif_data_size = sizeof(struct wfx_vif);
   270		hw->sta_data_size = sizeof(struct wfx_sta_priv);
   271		hw->queues = 4;
   272		hw->max_rates = 8;
   273		hw->max_rate_tries = 8;
   274		hw->extra_tx_headroom = sizeof(struct hif_sl_msg_hdr) +
   275					sizeof(struct hif_msg)
   276					+ sizeof(struct hif_req_tx)
   277					+ 4 /* alignment */ + 8 /* TKIP IV */;
   278		hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
   279					     BIT(NL80211_IFTYPE_ADHOC) |
   280					     BIT(NL80211_IFTYPE_AP);
   281		hw->wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
   282						NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
   283						NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
   284						NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
   285		hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
   286		hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
   287		hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
   288		hw->wiphy->max_ap_assoc_sta = HIF_LINK_ID_MAX;
   289		hw->wiphy->max_scan_ssids = 2;
   290		hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
   291		hw->wiphy->n_iface_combinations = ARRAY_SIZE(wfx_iface_combinations);
   292		hw->wiphy->iface_combinations = wfx_iface_combinations;
   293		hw->wiphy->bands[NL80211_BAND_2GHZ] = devm_kmalloc(dev, sizeof(wfx_band_2ghz), GFP_KERNEL);
   294		// FIXME: also copy wfx_rates and wfx_2ghz_chantable
   295		memcpy(hw->wiphy->bands[NL80211_BAND_2GHZ], &wfx_band_2ghz,
   296		       sizeof(wfx_band_2ghz));
   297	
   298		wdev = hw->priv;
   299		wdev->hw = hw;
   300		wdev->dev = dev;
   301		wdev->hwbus_ops = hwbus_ops;
   302		wdev->hwbus_priv = hwbus_priv;
   303		memcpy(&wdev->pdata, pdata, sizeof(*pdata));
   304		of_property_read_string(dev->of_node, "config-file",
   305					&wdev->pdata.file_pds);
   306		wdev->pdata.gpio_wakeup = devm_gpiod_get(dev, "wakeup", GPIOD_IN);
   307		if (IS_ERR(wdev->pdata.gpio_wakeup))
 > 308			return PTR_ERR(wdev->pdata.gpio_wakeup);
 > 309		gpiod_set_consumer_name(wdev->pdata.gpio_wakep, "wfx wakeup");
   310		wfx_sl_fill_pdata(dev, &wdev->pdata);
   311	
   312		mutex_init(&wdev->conf_mutex);
   313		mutex_init(&wdev->rx_stats_lock);
   314		mutex_init(&wdev->tx_power_loop_info_lock);
   315		init_completion(&wdev->firmware_ready);
   316		INIT_DELAYED_WORK(&wdev->cooling_timeout_work,
   317				  wfx_cooling_timeout_work);
   318		wfx_init_hif_cmd(&wdev->hif_cmd);
   319		wfx_tx_queues_init(wdev);
   320	
   321		if (devm_add_action_or_reset(dev, wfx_free_common, wdev))
   322			return NULL;
   323	
   324		return wdev;
   325	}
   326	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 75333 bytes --]

[-- Attachment #3: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-27 17:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 11:59 [PATCH] staging: wfx: Get descriptors for GPIOs Linus Walleij
2020-06-27 17:55 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).