From 3e29e9306f1cf01a3d762c8749c7fec0bbdeeadc Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Tue, 18 Jun 2019 21:21:19 +0000 Subject: [PATCH] Merged in masayuki2009/nuttx.nuttx/spresense_with_gs2200m (pull request #910) configs/spresense: Add support for Tilt GS2200M Wi-Fi module Signed-off-by: Masayuki Ishikawa Approved-by: Gregory Nutt --- configs/spresense/include/board.h | 1 + configs/spresense/include/cxd56_gs2200m.h | 87 ++++++++ configs/spresense/src/Makefile | 4 + configs/spresense/src/cxd56_bringup.c | 8 + configs/spresense/src/cxd56_gs2200m.c | 248 ++++++++++++++++++++++ configs/spresense/wifi/defconfig | 95 +++++++++ 6 files changed, 443 insertions(+) create mode 100644 configs/spresense/include/cxd56_gs2200m.h create mode 100644 configs/spresense/src/cxd56_gs2200m.c create mode 100644 configs/spresense/wifi/defconfig diff --git a/configs/spresense/include/board.h b/configs/spresense/include/board.h index 806905cee9..17f66c86a9 100644 --- a/configs/spresense/include/board.h +++ b/configs/spresense/include/board.h @@ -48,6 +48,7 @@ #include "cxd56_clock.h" #include "cxd56_power.h" #include "cxd56_flash.h" +#include "cxd56_gs2200m.h" #include "cxd56_sdcard.h" #include "cxd56_wdt.h" diff --git a/configs/spresense/include/cxd56_gs2200m.h b/configs/spresense/include/cxd56_gs2200m.h new file mode 100644 index 0000000000..c1fabc86c9 --- /dev/null +++ b/configs/spresense/include/cxd56_gs2200m.h @@ -0,0 +1,87 @@ +/**************************************************************************** + * configs/spresense/include/cxd56_gs2200m.h + * + * Copyright 2019 Sony Home Entertainment & Sound Products Inc. + * Author: Masayuki Ishikawa + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Sony Semiconductor Solutions Corporation nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __CONFIGS_SPRESENSE_INCLUDE_CXD56_GS2200M_H +#define __CONFIGS_SPRESENSE_INCLUDE_CXD56_GS2200M_H + + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_gs2200m_initialize + * + * Description: + * Initialize Tilt GS2200M board + * + ****************************************************************************/ + +int board_gs2200m_initialize(FAR const char *devpath, int bus); + + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __CONFIGS_SPRESENSE_INCLUDE_CXD56_GS2200M_H */ diff --git a/configs/spresense/src/Makefile b/configs/spresense/src/Makefile index e1fd83c38d..c4eed3beb9 100644 --- a/configs/spresense/src/Makefile +++ b/configs/spresense/src/Makefile @@ -88,4 +88,8 @@ ifeq ($(CONFIG_NETDEVICES),y) CSRCS += cxd56_netinit.c endif +ifeq ($(CONFIG_WL_GS2200M),y) +CSRCS += cxd56_gs2200m.c +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/spresense/src/cxd56_bringup.c b/configs/spresense/src/cxd56_bringup.c index b0776bd1cc..0c39a6a827 100644 --- a/configs/spresense/src/cxd56_bringup.c +++ b/configs/spresense/src/cxd56_bringup.c @@ -338,5 +338,13 @@ int cxd56_bringup(void) usbdev_rndis_initialize(mac); #endif +#ifdef CONFIG_WL_GS2200M + ret = board_gs2200m_initialize("/dev/gs2200m", 5); + if (ret < 0) + { + _err("ERROR: Failed to initialze GS2200M. \n"); + } +#endif + return 0; } diff --git a/configs/spresense/src/cxd56_gs2200m.c b/configs/spresense/src/cxd56_gs2200m.c new file mode 100644 index 0000000000..e51cf65126 --- /dev/null +++ b/configs/spresense/src/cxd56_gs2200m.c @@ -0,0 +1,248 @@ +/**************************************************************************** + * configs/spresense/src/cxd56_gs2200m.c + * + * Copyright 2019 Sony Home Entertainment & Sound Products Inc. + * Author: Masayuki Ishikawa + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Sony Semiconductor Solutions Corporation nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "cxd56_pinconfig.h" +#include "cxd56_spi.h" +#include "cxd56_gpio.h" +#include "cxd56_gpioint.h" + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int gs2200m_irq_attach(xcpt_t, FAR void *); +static void gs2200m_irq_enable(void); +static void gs2200m_irq_disable(void); +static uint32_t gs2200m_dready(int *); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct gs2200m_lower_s g_wifi_lower = +{ + .attach = gs2200m_irq_attach, + .enable = gs2200m_irq_enable, + .disable = gs2200m_irq_disable, + .dready = gs2200m_dready, +}; + +static FAR void *g_devhandle = NULL; +static volatile int32_t _enable_count = 0; +static volatile uint32_t _n_called; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gs2200m_irq_attach + ****************************************************************************/ + +static int gs2200m_irq_attach(xcpt_t handler, FAR void *arg) +{ + (void)cxd56_gpioint_config(PIN_UART2_CTS, + GPIOINT_LEVEL_HIGH, + handler, + arg); + return 0; +} + +/**************************************************************************** + * Name: gs2200m_irq_enable + ****************************************************************************/ + +static void gs2200m_irq_enable(void) +{ + irqstate_t flags = spin_lock_irqsave(); + + wlinfo("== ec:%d called=%d \n", _enable_count, _n_called++); + + if (1 == _enable_count) + { + /* NOTE: This would happen if we received an event */ + return; + } + + _enable_count++; + + if (1 == _enable_count) + { + cxd56_gpioint_enable(PIN_UART2_CTS); + } + + spin_unlock_irqrestore(flags); +} + +/**************************************************************************** + * Name: gs2200m_irq_disable + ****************************************************************************/ + +static void gs2200m_irq_disable(void) +{ + irqstate_t flags = spin_lock_irqsave(); + + wlinfo("== ec:%d called=%d \n", _enable_count, _n_called++); + + _enable_count--; + + if (0 == _enable_count) + { + cxd56_gpioint_disable(PIN_UART2_CTS); + } + + spin_unlock_irqrestore(flags); +} + +/**************************************************************************** + * Name: gs2200m_disable + ****************************************************************************/ + +static uint32_t gs2200m_dready(int *ec) +{ + irqstate_t flags = spin_lock_irqsave(); + + uint32_t r = cxd56_gpio_read(PIN_UART2_CTS); + + if (ec) + { + /* Copy enable count (just for debug) */ + + *ec = _enable_count; + } + + spin_unlock_irqrestore(flags); + return r; +} + +/**************************************************************************** + * Name: spi_pincontrol + * + * Description: + * Configure the SPI pin + * + * Input Parameter: + * on - true: enable pin, false: disable pin + ****************************************************************************/ + +static void spi_pincontrol(int bus, bool on) +{ + if (bus == 5) + { +#ifdef CONFIG_CXD56_SPI5_PINMAP_EMMC + if (on) + { + CXD56_PIN_CONFIGS(PINCONFS_EMMCA_SPI5); + } + else + { + CXD56_PIN_CONFIGS(PINCONFS_EMMCA_GPIO); + } +#endif +#ifdef CONFIG_CXD56_SPI5_PINMAP_SDIO + if (on) + { + CXD56_PIN_CONFIGS(PINCONFS_SDIOA_SPI5); + } + else + { + CXD56_PIN_CONFIGS(PINCONFS_SDIOA_GPIO); + } +#endif + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_gs2200m_initialize + ****************************************************************************/ + +int board_gs2200m_initialize(FAR const char *devpath, int bus) +{ + FAR struct spi_dev_s *spi; + + wlinfo("Initializing GS2200M..\n"); + + if (!g_devhandle) + { + /* Change UART2 to GPIO */ + + CXD56_PIN_CONFIGS(PINCONFS_UART2_GPIO); + (void)cxd56_gpio_config(PIN_UART2_CTS, true); + + /* Initialize spi deivce */ + + spi = cxd56_spibus_initialize(bus); + + if (!spi) + { + wlerr("ERROR: Failed to initialize spi%d.\n", bus); + return -ENODEV; + } + + /* Enable SPI5 */ + + spi_pincontrol(5, true); + + g_devhandle = gs2200m_register(devpath, spi, &g_wifi_lower); + + if (!g_devhandle) + { + wlerr("ERROR: Failed to register gs2200m driver.\n"); + return -ENODEV; + } + } + + return OK; +} diff --git a/configs/spresense/wifi/defconfig b/configs/spresense/wifi/defconfig new file mode 100644 index 0000000000..8b3c23de20 --- /dev/null +++ b/configs/spresense/wifi/defconfig @@ -0,0 +1,95 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set +# CONFIG_MMCSD_SPI is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="spresense" +CONFIG_ARCH_BOARD_SPRESENSE=y +CONFIG_ARCH_CHIP_CXD56XX=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV7M_USEBASEPRI=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_LOOPSPERMSEC=5434 +CONFIG_BOOT_RUNFROMISRAM=y +CONFIG_BUILTIN=y +CONFIG_CLOCK_MONOTONIC=y +CONFIG_CODECS_HASH_MD5=y +CONFIG_CXD56_SDIO=y +CONFIG_CXD56_SPI5=y +CONFIG_CXD56_SPI=y +CONFIG_CXD56_USBDEV=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DRIVERS_WIRELESS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_WEBSERVER=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FAT_MAXFNAME=64 +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2C=y +CONFIG_MAX_WDOGPARMS=2 +CONFIG_MMCSD=y +CONFIG_MMCSD_SDIO=y +CONFIG_NET=y +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETDEVICES=y +CONFIG_NETINIT_NETLOCAL=y +CONFIG_NETUTILS_CODECS=y +CONFIG_NETUTILS_FTPC=y +CONFIG_NETUTILS_TELNETD=y +CONFIG_NETUTILS_WEBCLIENT=y +CONFIG_NETUTILS_WEBSERVER=y +CONFIG_NET_ICMP=y +CONFIG_NET_LOCAL=y +CONFIG_NET_TCP_NO_STACK=y +CONFIG_NET_UDP_NO_STACK=y +CONFIG_NET_USRSOCK=y +CONFIG_NET_USRSOCK_CONNS=16 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_ARP=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_DISABLE_NSLOOKUP=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_WGET_USERAGENT="NuttX/7.2x.x (; http://www.nuttx.org/)" +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=16 +CONFIG_RAM_SIZE=1572864 +CONFIG_RAM_START=0x0d000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_LPWORKPRIORITY=30 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_GS2200M=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_CXXINITIALIZE=y +CONFIG_SYSTEM_USBMSC=y +CONFIG_UART1_SERIAL_CONSOLE=y +CONFIG_USBDEV=y +CONFIG_USBDEV_DMA=y +CONFIG_USBDEV_DUALSPEED=y +CONFIG_USBMSC=y +CONFIG_USBMSC_EPBULKIN=1 +CONFIG_USBMSC_REMOVABLE=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WL_GS2200M=y