boards/esp32s3_lan9250: deinitialize the ethernet device lan9250 for esp32s3.

This commit is contained in:
nuttxs 2024-08-23 15:38:27 +08:00 committed by Xiang Xiao
parent 9e388d1d00
commit fbb2e5f781
2 changed files with 80 additions and 11 deletions

View File

@ -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;
}

View File

@ -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__ */