Skip to content

Commit

Permalink
boards/esp32s3_lan9250: deinitialize the ethernet device lan9250 for …
Browse files Browse the repository at this point in the history
…esp32s3.
  • Loading branch information
nuttxs committed Aug 23, 2024
1 parent 93b520f commit b8cb08d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
71 changes: 61 additions & 10 deletions boards/xtensa/esp32s3/common/src/esp32s3_lan9250.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

20 changes: 19 additions & 1 deletion boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ int esp32s3_pwm_setup(void);
int esp32s3_twai_setup(void);
#endif

#ifdef CONFIG_NET_LAN9250
/****************************************************************************
* Name: esp32s3_lan9250_initialize
*
Expand All @@ -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__ */
Expand Down

0 comments on commit b8cb08d

Please sign in to comment.