Skip to content

Commit 3510fda

Browse files
PetervdPerk-NXPfabiobaltieri
authored andcommitted
boards: nxp: vmu_rt1170: Fix TJA1103 phy config
Also increase regulator init priority so that ethernet vdd is turned before PHY initialization Signed-off-by: Peter van der Perk <[email protected]>
1 parent 7fbf146 commit 3510fda

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

boards/nxp/vmu_rt1170/vmu_rt1170.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
&enet1g_mdio {
110110
pinctrl-0 = <&pinmux_enet1g_mdio>;
111111
pinctrl-names = "default";
112-
enet1g_phy: phy@1 {
112+
enet1g_phy: phy@f {
113113
compatible = "nxp,tja1103";
114-
reg = <1>;
114+
reg = <0xf>;
115115
master-slave = "master";
116116
};
117117
};

boards/nxp/vmu_rt1170/vmu_rt1170_mimxrt1176_cm7.dts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,11 @@
506506

507507
&enet1g_mdio {
508508
status = "okay";
509-
enet1g_phy: phy@1 {
510-
status = "okay";
511-
int-gpios = <&gpio5 10 GPIO_ACTIVE_HIGH>;
512-
};
509+
};
510+
511+
&enet1g_phy {
512+
status = "okay";
513+
int-gpios = <&gpio5 10 GPIO_ACTIVE_HIGH>;
513514
};
514515

515516
zephyr_udc0: &usb1 {

boards/nxp/vmu_rt1170/vmu_rt1170_mimxrt1176_cm7_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ CONFIG_FLEXSPI_CONFIG_BLOCK_OFFSET=0x400
1515

1616
# Enable Regulators
1717
CONFIG_REGULATOR=y
18-
CONFIG_REGULATOR_FIXED_INIT_PRIORITY=75
18+
CONFIG_REGULATOR_FIXED_INIT_PRIORITY=65
1919

2020
CONFIG_TICKLESS_KERNEL=n

drivers/ethernet/phy/phy_tja1103.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ LOG_MODULE_REGISTER(phy_tja1103, CONFIG_PHY_LOG_LEVEL);
5555
#define TJA1103_ALWAYS_ACCESSIBLE (0x801F)
5656
#define TJA1103_ALWAYS_ACCESSIBLE_FUSA_PASS_IRQ BIT(4)
5757

58+
#define MASTER_SLAVE_DEFAULT 0
59+
#define MASTER_SLAVE_MASTER 1
60+
#define MASTER_SLAVE_SLAVE 2
61+
#define MASTER_SLAVE_AUTO 3
62+
63+
#define SWITCH_WAIT_RANGE(min, max) ((min) + (sys_rand16_get() % ((max) - (min))))
64+
5865
struct phy_tja1103_config {
5966
const struct device *mdio;
6067
struct gpio_dt_spec gpio_interrupt;
@@ -70,8 +77,7 @@ struct phy_tja1103_data {
7077
struct gpio_callback phy_tja1103_int_callback;
7178
void *cb_data;
7279
struct k_work_delayable phy_work;
73-
uint64_t start_time;
74-
uint32_t wait_time;
80+
k_timepoint_t timeout;
7581
};
7682

7783
static inline int phy_tja1103_c22_read(const struct device *dev, uint16_t reg, uint16_t *val)
@@ -152,23 +158,33 @@ static int phy_tja1103_id(const struct device *dev, uint32_t *phy_id)
152158
}
153159

154160
static int phy_tja1103_get_link_state(const struct device *dev, struct phy_link_state *state)
161+
{
162+
struct phy_tja1103_data *const data = dev->data;
163+
164+
state->speed = data->state.speed;
165+
state->is_up = data->state.is_up;
166+
167+
return 0;
168+
}
169+
170+
static int phy_tja1103_update_link_state(const struct device *dev, struct phy_link_state *state)
155171
{
156172
struct phy_tja1103_data *const data = dev->data;
157173
uint16_t val;
158174
int rc = 0;
159175

160-
k_sem_take(&data->sem, K_FOREVER);
161-
162176
if (phy_tja1103_c45_read(dev, MDIO_MMD_VENDOR_SPECIFIC1, TJA1103_PHY_STATUS, &val) < 0) {
163177
return -EIO;
164178
}
165179

166-
k_sem_give(&data->sem);
180+
k_sem_take(&data->sem, K_FOREVER);
167181

168182
/* TJA1103 Only supports 100BASE Full-duplex */
169183
state->speed = LINK_FULL_100BASE;
170184
state->is_up = (val & TJA1103_PHY_STATUS_LINK_STAT) != 0;
171185

186+
k_sem_give(&data->sem);
187+
172188
LOG_DBG("TJA1103 Link state %i", state->is_up);
173189

174190
return rc;
@@ -216,22 +232,21 @@ static void phy_work_handler(struct k_work *work)
216232
int rc;
217233
const struct phy_tja1103_config *const cfg = dev->config;
218234

219-
rc = phy_tja1103_get_link_state(dev, &state);
235+
rc = phy_tja1103_update_link_state(dev, &state);
220236

221237
/* Update link state and trigger callback if changed */
222-
if (rc == 0 && (state.speed != data->state.speed || state.is_up != data->state.is_up)) {
238+
if (rc == 0 && state.is_up != data->state.is_up) {
223239
memcpy(&data->state, &state, sizeof(struct phy_link_state));
224240
if (data->cb) {
225241
data->cb(dev, &data->state, data->cb_data);
226242
}
227243
}
228244

229-
if (cfg->master_slave == 3 && !data->state.is_up &&
230-
k_uptime_delta(&data->start_time) > data->wait_time) {
245+
if (cfg->master_slave == MASTER_SLAVE_AUTO && !data->state.is_up &&
246+
sys_timepoint_expired(data->timeout)) {
231247
uint16_t val;
232248

233-
data->start_time = k_uptime_get();
234-
data->wait_time = 1000 + (sys_rand32_get() % 2001);
249+
data->timeout = sys_timepoint_calc(K_MSEC(SWITCH_WAIT_RANGE(1000, 3000)));
235250

236251
phy_tja1103_c45_read(dev, MDIO_MMD_PMAPMD, MDIO_PMA_PMD_BT1_CTRL, &val);
237252

@@ -244,8 +259,8 @@ static void phy_work_handler(struct k_work *work)
244259
if (cfg->gpio_interrupt.port) {
245260
phy_tja1103_ack_irq(dev);
246261

247-
if (cfg->master_slave == 3 && !data->state.is_up) {
248-
k_work_reschedule(&data->phy_work, K_MSEC(data->wait_time + 10));
262+
if (cfg->master_slave == MASTER_SLAVE_AUTO && !data->state.is_up) {
263+
k_work_reschedule(&data->phy_work, sys_timepoint_timeout(data->timeout));
249264
}
250265

251266
return;
@@ -301,8 +316,7 @@ static void phy_tja1103_cfg_irq_poll(const struct device *dev)
301316
}
302317
#endif
303318

304-
data->start_time = k_uptime_get();
305-
data->wait_time = 1000 + (sys_rand32_get() % 4001);
319+
data->timeout = sys_timepoint_calc(K_MSEC(SWITCH_WAIT_RANGE(1000, 3000)));
306320

307321
k_work_init_delayable(&data->phy_work, phy_work_handler);
308322

@@ -350,9 +364,9 @@ static int phy_tja1103_init(const struct device *dev)
350364
}
351365

352366
/* Change master/slave mode if need */
353-
if (cfg->master_slave == 1) {
367+
if (cfg->master_slave == MASTER_SLAVE_MASTER) {
354368
val |= MDIO_PMA_PMD_BT1_CTRL_CFG_MST;
355-
} else if (cfg->master_slave == 2) {
369+
} else if (cfg->master_slave == MASTER_SLAVE_SLAVE) {
356370
val &= ~MDIO_PMA_PMD_BT1_CTRL_CFG_MST;
357371
}
358372

@@ -388,11 +402,7 @@ static int phy_tja1103_link_cb_set(const struct device *dev, phy_callback_t cb,
388402
data->cb = cb;
389403
data->cb_data = user_data;
390404

391-
rc = phy_tja1103_get_link_state(dev, &data->state);
392-
393-
if (rc == 0) {
394-
data->cb(dev, &data->state, data->cb_data);
395-
}
405+
data->cb(dev, &data->state, data->cb_data);
396406

397407
return rc;
398408
}

0 commit comments

Comments
 (0)