From fbb2e5f781c024a15ac4f826b3679bf9eadce0a1 Mon Sep 17 00:00:00 2001 From: nuttxs Date: Fri, 23 Aug 2024 15:38:27 +0800 Subject: [PATCH] boards/esp32s3_lan9250: deinitialize the ethernet device lan9250 for esp32s3. --- .../esp32s3/common/src/esp32s3_lan9250.c | 71 ++++++++++++++++--- .../esp32s3-devkit/src/esp32s3-devkit.h | 20 +++++- 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/boards/xtensa/esp32s3/common/src/esp32s3_lan9250.c b/boards/xtensa/esp32s3/common/src/esp32s3_lan9250.c index 707e712a58..6e1ca11049 100644 --- a/boards/xtensa/esp32s3/common/src/esp32s3_lan9250.c +++ b/boards/xtensa/esp32s3/common/src/esp32s3_lan9250.c @@ -62,6 +62,12 @@ static void lan9250_getmac(const struct lan9250_lower_s *lower, * Private Data ****************************************************************************/ +#ifdef CONFIG_LAN9250_SPI + static struct spi_dev_s *g_dev; +#else + static struct qspi_dev_s *g_dev; +#endif + static struct lan9250_lower_s g_lan9250_lower = { .attach = lan9250_attach, @@ -207,32 +213,27 @@ static void lan9250_getmac(const struct lan9250_lower_s *lower, uint8_t *mac) int esp32s3_lan9250_initialize(int port) { int ret; -#ifdef CONFIG_LAN9250_SPI - struct spi_dev_s *dev; -#else - struct qspi_dev_s *dev; -#endif esp32s3_configgpio(LAN9250_IRQ, INPUT_FUNCTION_2 | PULLUP); esp32s3_configgpio(LAN9250_RST, OUTPUT_FUNCTION_2 | PULLUP); #ifdef CONFIG_LAN9250_SPI - dev = esp32s3_spibus_initialize(port); - if (!dev) + g_dev = esp32s3_spibus_initialize(port); + if (!g_dev) { nerr("ERROR: Failed to initialize SPI port %d\n", port); return -ENODEV; } #else - dev = esp32s3_qspibus_initialize(port); - if (!dev) + g_dev = esp32s3_qspibus_initialize(port); + if (!g_dev) { nerr("ERROR: Failed to initialize QSPI port %d\n", port); return -ENODEV; } #endif - ret = lan9250_initialize(dev, &g_lan9250_lower); + ret = lan9250_initialize(g_dev, &g_lan9250_lower); if (ret != 0) { nerr("ERROR: Failed to initialize LAN9250 ret=%d\n", ret); @@ -242,3 +243,53 @@ int esp32s3_lan9250_initialize(int port) return 0; } +/**************************************************************************** + * Name: esp32s3_lan9250_uninitialize + * + * Description: + * This function is called by platform-specific setup logic to uninitialize + * the LAN9250 device. This function will unregister the network device. + * + * Input Parameters: + * port - The SPI port used for the device + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32s3_lan9250_uninitialize(int port) +{ + int ret; + int irq; + + irq = ESP32S3_PIN2IRQ(LAN9250_IRQ); + esp32s3_gpioirqdisable(irq); + +#ifdef CONFIG_LAN9250_SPI + ret = esp32s3_spibus_uninitialize((struct spi_dev_s *)g_dev); + if (ret != OK) + { + nerr("ERROR: Failed to uninitialize SPI port %d\n", port); + return ret; + } +#else + ret = esp32s3_qspibus_uninitialize((struct qspi_dev_s *)g_dev); + if (ret != OK) + { + nerr("ERROR: Failed to uninitialize QSPI port %d\n", port); + return ret; + } +#endif + + ret = lan9250_uninitialize(&g_lan9250_lower); + if (ret != OK) + { + nerr("ERROR: Failed to initialize LAN9250 ret=%d\n", ret); + return ret; + } + + return 0; +} + diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h index 5284a52faf..cafb03f6fd 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h @@ -230,6 +230,7 @@ int esp32s3_pwm_setup(void); int esp32s3_twai_setup(void); #endif +#ifdef CONFIG_NET_LAN9250 /**************************************************************************** * Name: esp32s3_lan9250_initialize * @@ -247,8 +248,25 @@ int esp32s3_twai_setup(void); * ****************************************************************************/ -#ifdef CONFIG_NET_LAN9250 int esp32s3_lan9250_initialize(int port); + +/**************************************************************************** + * Name: esp32s3_lan9250_uninitialize + * + * Description: + * This function is called by platform-specific setup logic to uninitialize + * the LAN9250 device. This function will unregister the network device. + * + * Input Parameters: + * port - The SPI port used for the device + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32s3_lan9250_uninitialize(int port); #endif #endif /* __ASSEMBLY__ */