|
|
|
@ -9,6 +9,8 @@
@@ -9,6 +9,8 @@
|
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <zephyr/device.h> |
|
|
|
|
#include <zephyr/kernel.h> |
|
|
|
|
#include <zephyr/drivers/clock_control.h> |
|
|
|
|
#include <zephyr/drivers/clock_control/stm32_clock_control.h> |
|
|
|
|
#include <zephyr/drivers/pinctrl.h> |
|
|
|
|
#include <zephyr/drivers/mdio.h> |
|
|
|
|
#include <zephyr/net/ethernet.h> |
|
|
|
@ -28,6 +30,7 @@ struct mdio_stm32_data {
@@ -28,6 +30,7 @@ struct mdio_stm32_data {
|
|
|
|
|
|
|
|
|
|
struct mdio_stm32_config { |
|
|
|
|
const struct pinctrl_dev_config *pincfg; |
|
|
|
|
struct stm32_pclken pclken; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static int mdio_stm32_read(const struct device *dev, uint8_t prtad, |
|
|
|
@ -91,6 +94,14 @@ static int mdio_stm32_init(const struct device *dev)
@@ -91,6 +94,14 @@ static int mdio_stm32_init(const struct device *dev)
|
|
|
|
|
const struct mdio_stm32_config *const config = dev->config; |
|
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
/* enable clock */ |
|
|
|
|
ret = clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE), |
|
|
|
|
(clock_control_subsys_t)&config->pclken); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
LOG_ERR("Failed to enable ethernet clock needed for MDIO (%d)", ret); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
return ret; |
|
|
|
@ -106,18 +117,19 @@ static DEVICE_API(mdio, mdio_stm32_api) = {
@@ -106,18 +117,19 @@ static DEVICE_API(mdio, mdio_stm32_api) = {
|
|
|
|
|
.write = mdio_stm32_write, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#define MDIO_STM32_HAL_DEVICE(inst) \ |
|
|
|
|
PINCTRL_DT_INST_DEFINE(inst); \ |
|
|
|
|
\ |
|
|
|
|
static struct mdio_stm32_data mdio_stm32_data_##inst = { \ |
|
|
|
|
.heth = {.Instance = (ETH_TypeDef *)DT_REG_ADDR(DT_INST_PARENT(inst))}, \ |
|
|
|
|
}; \ |
|
|
|
|
static struct mdio_stm32_config mdio_stm32_config_##inst = { \ |
|
|
|
|
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ |
|
|
|
|
}; \ |
|
|
|
|
DEVICE_DT_INST_DEFINE(inst, &mdio_stm32_init, NULL, \ |
|
|
|
|
&mdio_stm32_data_##inst, &mdio_stm32_config_##inst, \ |
|
|
|
|
POST_KERNEL, CONFIG_ETH_INIT_PRIORITY, \ |
|
|
|
|
&mdio_stm32_api); |
|
|
|
|
#define MDIO_STM32_HAL_DEVICE(inst) \ |
|
|
|
|
PINCTRL_DT_INST_DEFINE(inst); \ |
|
|
|
|
\ |
|
|
|
|
static struct mdio_stm32_data mdio_stm32_data_##inst = { \ |
|
|
|
|
.heth = {.Instance = (ETH_TypeDef *)DT_REG_ADDR(DT_INST_PARENT(inst))}, \ |
|
|
|
|
}; \ |
|
|
|
|
static struct mdio_stm32_config mdio_stm32_config_##inst = { \ |
|
|
|
|
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ |
|
|
|
|
.pclken = {.bus = DT_CLOCKS_CELL_BY_NAME(DT_INST_PARENT(inst), stm_eth, bus), \ |
|
|
|
|
.enr = DT_CLOCKS_CELL_BY_NAME(DT_INST_PARENT(inst), stm_eth, bits)}, \ |
|
|
|
|
}; \ |
|
|
|
|
DEVICE_DT_INST_DEFINE(inst, &mdio_stm32_init, NULL, &mdio_stm32_data_##inst, \ |
|
|
|
|
&mdio_stm32_config_##inst, POST_KERNEL, CONFIG_MDIO_INIT_PRIORITY, \ |
|
|
|
|
&mdio_stm32_api); |
|
|
|
|
|
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(MDIO_STM32_HAL_DEVICE) |
|
|
|
|