From 9730ca1852546cac84e862e5a3f6df97cbce304a Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Tue, 6 Nov 2018 16:50:28 -0600 Subject: [PATCH] wifi: winc1500: Add Device Tree support Add a dts binding for the Atmel WINC1500 WIFI chip. Update the quark_se_c1000_devboard to utilize this binding as well as the wifi sample app. We now get all the GPIOs related to the Atmel WINC1500 from the device tree. Signed-off-by: Kumar Gala --- drivers/wifi/winc1500/Kconfig.winc1500 | 36 ------------------- .../winc1500/wifi_winc1500_nm_bus_wrapper.c | 14 ++++---- dts/bindings/wifi/atmel,winc1500.yaml | 35 ++++++++++++++++++ samples/net/wifi/Kconfig | 20 ----------- .../wifi/boards/quark_se_c1000_devboard.conf | 7 ---- samples/net/wifi/dts_fixup.h | 28 +++++++++++++++ .../net/wifi/quark_se_c1000_devboard.overlay | 18 ++++++++++ samples/net/wifi/src/wifi_test.c | 8 ++--- 8 files changed, 92 insertions(+), 74 deletions(-) create mode 100644 dts/bindings/wifi/atmel,winc1500.yaml delete mode 100644 samples/net/wifi/Kconfig create mode 100644 samples/net/wifi/dts_fixup.h create mode 100644 samples/net/wifi/quark_se_c1000_devboard.overlay diff --git a/drivers/wifi/winc1500/Kconfig.winc1500 b/drivers/wifi/winc1500/Kconfig.winc1500 index 83e05a2d27e..d21ee91d074 100644 --- a/drivers/wifi/winc1500/Kconfig.winc1500 +++ b/drivers/wifi/winc1500/Kconfig.winc1500 @@ -18,48 +18,12 @@ config WIFI_WINC1500_NAME string "Driver name" default "WINC1500" -config WIFI_WINC1500_SPI_DRV_NAME - string "SPI device where WINC1500 is connected" - default "SPI_1" - help - Specify the device name of the SPI device to which WINC1500 is - connected. - -config WIFI_WINC1500_SPI_SLAVE - int "SPI Slave Select where WINC1500 is connected" - default 1 - help - Specify the slave select pin of the SPI to which WINC1500 is - connected. - -config WIFI_WINC1500_SPI_FREQ - int "SPI frequency to use with WINC1500" - default 8000000 - help - SPI frequency to use with WINC1500 - config WIFI_WINC1500_GPIO_SPI_CS bool "Manage SPI CS through a GPIO pin" help This option is useful if one needs to manage SPI CS through a GPIO pin to by-pass the SPI controller's CS logic. -config WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME - string "GPIO driver's name to use to drive SPI CS through" - default "" - depends on WIFI_WINC1500_GPIO_SPI_CS - help - This option is mandatory to set which GPIO controller to use in - order to actually emulate the SPI CS. - -config WIFI_WINC1500_GPIO_SPI_CS_PIN - int "GPIO PIN to use to drive SPI CS through" - default 0 - depends on WIFI_WINC1500_GPIO_SPI_CS - help - This option is mandatory to set which GPIO pin to use in order - to actually emulate the SPI CS. - config WIFI_WINC1500_THREAD_STACK_SIZE int "HAL callback handler thread stack size" default 2048 diff --git a/drivers/wifi/winc1500/wifi_winc1500_nm_bus_wrapper.c b/drivers/wifi/winc1500/wifi_winc1500_nm_bus_wrapper.c index 431705ce858..7a4ac88d211 100644 --- a/drivers/wifi/winc1500/wifi_winc1500_nm_bus_wrapper.c +++ b/drivers/wifi/winc1500/wifi_winc1500_nm_bus_wrapper.c @@ -96,32 +96,32 @@ s8_t nm_bus_init(void *pvinit) /* Not implemented */ #elif defined CONF_WINC_USE_SPI /* setup SPI device */ - winc1500.spi = device_get_binding(CONFIG_WIFI_WINC1500_SPI_DRV_NAME); + winc1500.spi = device_get_binding(DT_WIFI_WINC1500_SPI_DRV_NAME); if (!winc1500.spi) { LOG_ERR("spi device binding"); return -1; } winc1500.spi_cfg.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB; - winc1500.spi_cfg.frequency = CONFIG_WIFI_WINC1500_SPI_FREQ; - winc1500.spi_cfg.slave = CONFIG_WIFI_WINC1500_SPI_SLAVE; + winc1500.spi_cfg.frequency = DT_WIFI_WINC1500_SPI_FREQ; + winc1500.spi_cfg.slave = DT_WIFI_WINC1500_SPI_SLAVE; #ifdef CONFIG_WIFI_WINC1500_GPIO_SPI_CS cs_ctrl.gpio_dev = device_get_binding( - CONFIG_WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME); + DT_WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME); if (!cs_ctrl.gpio_dev) { LOG_ERR("Unable to get GPIO SPI CS device"); return -ENODEV; } - cs_ctrl.gpio_pin = CONFIG_WIFI_WINC1500_GPIO_SPI_CS_PIN; + cs_ctrl.gpio_pin = DT_WIFI_WINC1500_GPIO_SPI_CS_PIN; cs_ctrl.delay = 0; winc1500.spi_cfg.cs = &cs_ctrl; LOG_DBG("SPI GPIO CS configured on %s:%u", - CONFIG_WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME, - CONFIG_WIFI_WINC1500_GPIO_SPI_CS_PIN); + DT_WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME, + DT_WIFI_WINC1500_GPIO_SPI_CS_PIN); #endif /* CONFIG_WIFI_WINC1500_GPIO_SPI_CS */ nm_bsp_reset(); diff --git a/dts/bindings/wifi/atmel,winc1500.yaml b/dts/bindings/wifi/atmel,winc1500.yaml new file mode 100644 index 00000000000..55e354c6a7d --- /dev/null +++ b/dts/bindings/wifi/atmel,winc1500.yaml @@ -0,0 +1,35 @@ +# +# Copyright (c) 2018, Linaro Limited +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +title: Atmel WINC1500 Wifi module +version: 0.1 + +description: > + This binding gives the base representation of the Atmel WINC1500 Wifi module + +inherits: + !include spi-device.yaml + +properties: + compatible: + constraint: "atmel,winc1500" + + irq-gpios: + type: compound + category: required + generation: define, use-prop-name + + reset-gpios: + type: compound + category: required + generation: define, use-prop-name + + enable-gpios: + type: compound + category: required + generation: define, use-prop-name + +... diff --git a/samples/net/wifi/Kconfig b/samples/net/wifi/Kconfig deleted file mode 100644 index d418fec39b6..00000000000 --- a/samples/net/wifi/Kconfig +++ /dev/null @@ -1,20 +0,0 @@ -mainmenu "Wi-Fi sample" - -if WIFI_WINC1500 - -config WINC1500_GPIO_DRV_NAME - string "GPIO device name" - -config WINC1500_GPIO_CHIP_EN - int "Pin number for Winc1500 CHIP_EN signal" - -config WINC1500_GPIO_IRQN - int "Pin number for Winc1500 IRQn signal" - -config WINC1500_GPIO_RESET_N - int "Pin number for Winc1500 RESET_N signal" - -endif # WIFI_WINC1500 - - -source "Kconfig.zephyr" diff --git a/samples/net/wifi/boards/quark_se_c1000_devboard.conf b/samples/net/wifi/boards/quark_se_c1000_devboard.conf index 019aa2d75f1..731ac719052 100644 --- a/samples/net/wifi/boards/quark_se_c1000_devboard.conf +++ b/samples/net/wifi/boards/quark_se_c1000_devboard.conf @@ -6,10 +6,3 @@ CONFIG_SPI_DW=y CONFIG_WIFI_WINC1500=y CONFIG_WIFI_WINC1500_REGION_EUROPE=y CONFIG_WIFI_WINC1500_GPIO_SPI_CS=y -CONFIG_WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME="GPIO_0" -CONFIG_WIFI_WINC1500_GPIO_SPI_CS_PIN=13 - -CONFIG_WINC1500_GPIO_DRV_NAME="GPIO_0" -CONFIG_WINC1500_GPIO_CHIP_EN=19 -CONFIG_WINC1500_GPIO_IRQN=18 -CONFIG_WINC1500_GPIO_RESET_N=26 diff --git a/samples/net/wifi/dts_fixup.h b/samples/net/wifi/dts_fixup.h new file mode 100644 index 00000000000..fdca225eb58 --- /dev/null +++ b/samples/net/wifi/dts_fixup.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Board level DTS fixup file */ + +#if defined(CONFIG_BOARD_QUARK_SE_C1000_DEVBOARD) + +#define DT_WIFI_WINC1500_SPI_DRV_NAME DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_BUS_NAME +#define DT_WIFI_WINC1500_SPI_SLAVE DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_BASE_ADDRESS +#define DT_WIFI_WINC1500_SPI_FREQ DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_SPI_MAX_FREQUENCY + +#define DT_WIFI_WINC1500_GPIO_SPI_CS_DRV_NAME DT_SNPS_DESIGNWARE_SPI_B0001400_CS_GPIOS_CONTROLLER +#define DT_WIFI_WINC1500_GPIO_SPI_CS_PIN DT_SNPS_DESIGNWARE_SPI_B0001400_CS_GPIOS_PIN + +#define DT_WINC1500_GPIO_CHIP_EN_DRV_NAME DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_ENABLE_GPIOS_CONTROLLER +#define DT_WINC1500_GPIO_CHIP_EN DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_ENABLE_GPIOS_PIN +#define DT_WINC1500_GPIO_IRQN_DRV_NAME DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_IRQ_GPIOS_CONTROLLER +#define DT_WINC1500_GPIO_IRQN DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_IRQ_GPIOS_PIN +#define DT_WINC1500_GPIO_RESET_N_DRV_NAME DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_RESET_GPIOS_CONTROLLER +#define DT_WINC1500_GPIO_RESET_N DT_SNPS_DESIGNWARE_SPI_B0001400_ATMEL_WINC1500_0_RESET_GPIOS_PIN + +/* For now we assume that all the GPIOs are on the same controller */ +#define DT_WINC1500_GPIO_DRV_NAME DT_WINC1500_GPIO_CHIP_EN_DRV_NAME + +#endif /* CONFIG_BOARD_QUARK_SE_C1000_DEVBOARD */ diff --git a/samples/net/wifi/quark_se_c1000_devboard.overlay b/samples/net/wifi/quark_se_c1000_devboard.overlay new file mode 100644 index 00000000000..b59d7383b58 --- /dev/null +++ b/samples/net/wifi/quark_se_c1000_devboard.overlay @@ -0,0 +1,18 @@ + +&spi1 { + status = "ok"; + + cs-gpios = <&gpio0 13 0>; + + winc1500@0 { + status = "ok"; + compatible = "atmel,winc1500"; + reg = <0x0>; + label = "winc1500"; + spi-max-frequency = <8000000>; + irq-gpios = <&gpio0 18 0>; + reset-gpios = <&gpio0 26 0>; + enable-gpios = <&gpio0 19 0>; + + }; +}; diff --git a/samples/net/wifi/src/wifi_test.c b/samples/net/wifi/src/wifi_test.c index 600974fd22f..7661d517944 100644 --- a/samples/net/wifi/src/wifi_test.c +++ b/samples/net/wifi/src/wifi_test.c @@ -15,9 +15,9 @@ static struct winc1500_gpio_configuration winc1500_gpios[WINC1500_GPIO_IDX_MAX] = { - { .dev = NULL, .pin = CONFIG_WINC1500_GPIO_CHIP_EN }, - { .dev = NULL, .pin = CONFIG_WINC1500_GPIO_IRQN }, - { .dev = NULL, .pin = CONFIG_WINC1500_GPIO_RESET_N }, + { .dev = NULL, .pin = DT_WINC1500_GPIO_CHIP_EN }, + { .dev = NULL, .pin = DT_WINC1500_GPIO_IRQN }, + { .dev = NULL, .pin = DT_WINC1500_GPIO_RESET_N }, }; struct winc1500_gpio_configuration *winc1500_configure_gpios(void) @@ -28,7 +28,7 @@ struct winc1500_gpio_configuration *winc1500_configure_gpios(void) const int flags_noint_out = GPIO_DIR_OUT; struct device *gpio; - gpio = device_get_binding(CONFIG_WINC1500_GPIO_DRV_NAME); + gpio = device_get_binding(DT_WINC1500_GPIO_DRV_NAME); gpio_pin_configure(gpio, winc1500_gpios[WINC1500_GPIO_IDX_CHIP_EN].pin, flags_noint_out);