Skip to content

Commit ea1129e

Browse files
cyliangtwkartben
authored andcommitted
drivers: ethernet: support for numaker m55m1x series
Add support for Nuvoton numaker m55m1x series EMAC controller. Also include NOCACHE_MEMORY allocation. Support to generate random mac address and remove emac data flash. Signed-off-by: cyliang tw <cyliang@nuvoton.com>
1 parent 8b49c63 commit ea1129e

File tree

9 files changed

+91
-24
lines changed

9 files changed

+91
-24
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Nuvoton NuMaker M55M1 board configuration
4+
#
5+
# Copyright (c) 2025 Nuvoton Technology Corporation.
6+
7+
if BOARD_NUMAKER_M55M1
8+
9+
if NETWORKING
10+
11+
config NET_L2_ETHERNET
12+
default y if !MODEM
13+
14+
endif # NETWORKING
15+
16+
endif # BOARD_NUMAKER_M55M1

boards/nuvoton/numaker_m55m1/numaker_m55m1-pinctrl.dtsi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@
2424
<PC9MFP_GPIO>;
2525
};
2626
};
27+
28+
/* EMAC multi-function pins for MDIO, TX, REFCLK, RX pins */
29+
emac_default: emac_default {
30+
group0 {
31+
pinmux = <PE8MFP_EMAC0_RMII_MDC>,
32+
<PE9MFP_EMAC0_RMII_MDIO>,
33+
<PC8MFP_EMAC0_RMII_REFCLK>,
34+
<PC7MFP_EMAC0_RMII_RXD0>,
35+
<PC6MFP_EMAC0_RMII_RXD1>,
36+
<PA7MFP_EMAC0_RMII_CRSDV>,
37+
<PA6MFP_EMAC0_RMII_RXERR>;
38+
};
39+
group1 {
40+
pinmux = <PE10MFP_EMAC0_RMII_TXD0>,
41+
<PE11MFP_EMAC0_RMII_TXD1>,
42+
<PE12MFP_EMAC0_RMII_TXEN>;
43+
slew-rate = "fast";
44+
};
45+
};
2746
};

boards/nuvoton/numaker_m55m1/numaker_m55m1.dts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@
8686
pinctrl-names = "default";
8787
status = "okay";
8888
};
89+
90+
&emac {
91+
pinctrl-0 = <&emac_default>;
92+
pinctrl-names = "default";
93+
status = "okay";
94+
};

doc/releases/migration-guide-4.2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ Ethernet
133133
kconfig options: :kconfig:option:`CONFIG_ETH_NATIVE_POSIX` and its related options have been
134134
deprecated in favor of :kconfig:option:`CONFIG_ETH_NATIVE_TAP` (:github:`86578`).
135135

136+
* NuMaker Ethernet driver ``eth_numaker.c`` now supports ``gen_random_mac``,
137+
and the EMAC data flash feature has been removed (:github:`87953`).
138+
136139
Enhanced Serial Peripheral Interface (eSPI)
137140
===========================================
138141

drivers/ethernet/Kconfig.numaker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config ETH_NUMAKER
99
select HAS_NUMAKER_ETH
1010
select PINCTRL
1111
depends on DT_HAS_NUVOTON_NUMAKER_ETHERNET_ENABLED
12+
select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
1213
help
1314
This option enables the Ethernet driver for Nuvoton NuMaker family of
1415
processors.

drivers/ethernet/eth_numaker.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,31 @@
2121

2222
#ifdef CONFIG_SOC_M467
2323
#include <m460_eth.h>
24+
#else
25+
#include <numaker_eth.h>
2426
#endif
2527

2628
LOG_MODULE_REGISTER(eth_numaker, CONFIG_ETHERNET_LOG_LEVEL);
2729

2830
/* Device EMAC Interface port */
2931
#define NUMAKER_GMAC_INTF 0
30-
/* 2KB Data Flash at 0xFF800 */
31-
#define NUMAKER_DATA_FLASH (0xFF800U)
32+
3233
#define NUMAKER_MASK_32 (0xFFFFFFFFU)
3334
#define NUMAKER_MII_CONFIG (ADVERTISE_CSMA | ADVERTISE_10HALF | ADVERTISE_10FULL | \
3435
ADVERTISE_100HALF | ADVERTISE_100FULL)
3536
#define NUMAKER_MII_LINKED (BMSR_ANEGCOMPLETE | BMSR_LSTATUS)
3637

3738
extern synopGMACdevice GMACdev[GMAC_CNT];
39+
40+
#ifdef CONFIG_NOCACHE_MEMORY
41+
DmaDesc tx_desc[GMAC_CNT][TRANSMIT_DESC_SIZE] __nocache __aligned(64);
42+
DmaDesc rx_desc[GMAC_CNT][RECEIVE_DESC_SIZE] __nocache __aligned(64);
43+
struct sk_buff tx_buf[GMAC_CNT][TRANSMIT_DESC_SIZE] __nocache __aligned(64);
44+
struct sk_buff rx_buf[GMAC_CNT][RECEIVE_DESC_SIZE] __nocache __aligned(64);
45+
#else
3846
extern struct sk_buff tx_buf[GMAC_CNT][TRANSMIT_DESC_SIZE];
3947
extern struct sk_buff rx_buf[GMAC_CNT][RECEIVE_DESC_SIZE];
48+
#endif
4049

4150
static uint32_t eth_phy_addr;
4251

@@ -167,33 +176,31 @@ static int reset_phy(synopGMACdevice *gmacdev)
167176

168177
static void m_numaker_read_mac_addr(char *mac)
169178
{
179+
#if DT_INST_PROP(0, zephyr_random_mac_address)
180+
gen_random_mac(mac, NUMAKER_OUI_B0, NUMAKER_OUI_B1, NUMAKER_OUI_B2);
181+
#else
170182
uint32_t uid1;
171-
/* Fetch word 0 of data flash */
172-
uint32_t word0 = *(uint32_t *)(NUMAKER_DATA_FLASH + 0x04U);
183+
uint32_t word0;
173184
/*
174-
* Fetch word 1 of data flash
175185
* we only want bottom 16 bits of word1 (MAC bits 32-47)
176186
* and bit 9 forced to 1, bit 8 forced to 0
177187
* Locally administered MAC, reduced conflicts
178188
* http://en.wikipedia.org/wiki/MAC_address
179189
*/
180-
uint32_t word1 = *(uint32_t *)NUMAKER_DATA_FLASH;
181-
182-
/* Not burn any mac address at the beginning of data flash */
183-
if (word0 == NUMAKER_MASK_32) {
184-
/* Generate a semi-unique MAC address from the UUID */
185-
SYS_UnlockReg();
186-
/* Enable FMC ISP function */
187-
FMC_Open();
188-
uid1 = FMC_ReadUID(1);
189-
word1 = (uid1 & 0x003FFFFF) | ((uid1 & 0x030000) << 6) >> 8;
190-
word0 = ((FMC_ReadUID(0) >> 4) << 20) | ((uid1 & 0xFF) << 12) |
191-
(FMC_ReadUID(2) & 0xFFF);
192-
/* Disable FMC ISP function */
193-
FMC_Close();
194-
/* Lock protected registers */
195-
SYS_LockReg();
196-
}
190+
uint32_t word1;
191+
192+
/* Generate a semi-unique MAC address from the UUID */
193+
SYS_UnlockReg();
194+
/* Enable FMC ISP function */
195+
FMC_Open();
196+
uid1 = FMC_ReadUID(1);
197+
word1 = (uid1 & 0x003FFFFF) | ((uid1 & 0x030000) << 6) >> 8;
198+
word0 = ((FMC_ReadUID(0) >> 4) << 20) | ((uid1 & 0xFF) << 12) |
199+
(FMC_ReadUID(2) & 0xFFF);
200+
/* Disable FMC ISP function */
201+
FMC_Close();
202+
/* Lock protected registers */
203+
SYS_LockReg();
197204

198205
word1 |= 0x00000200;
199206
word1 &= 0x0000FEFF;
@@ -204,7 +211,7 @@ static void m_numaker_read_mac_addr(char *mac)
204211
mac[3] = (word0 & 0x00ff0000) >> 16;
205212
mac[4] = (word0 & 0x0000ff00) >> 8;
206213
mac[5] = (word0 & 0x000000ff);
207-
214+
#endif
208215
LOG_INF("mac address %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3],
209216
mac[4], mac[5]);
210217
}

drivers/ethernet/eth_numaker_priv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515

1616
#define NU_ETH_MTU_SIZE 1500
1717

18+
/* NuMaker chip's OUI*/
19+
#define NUMAKER_OUI_B0 0xDA
20+
#define NUMAKER_OUI_B1 0x00
21+
#define NUMAKER_OUI_B2 0x53
22+
1823
#endif /* ZEPHYR_DRIVERS_ETHERNET_ETH_NUMAKER_PRIV_H_ */

dts/arm/nuvoton/m55m1x.dtsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@
335335
#size-cells = <0>;
336336
status = "disabled";
337337
};
338+
339+
emac: ethernet@40208000 {
340+
compatible = "nuvoton,numaker-ethernet";
341+
reg = <0x40208000 0x2000>;
342+
interrupts = <63 0>;
343+
resets = <&rst NUMAKER_SYS_EMAC0RST>;
344+
phy-addr = <0>;
345+
clocks = <&pcc NUMAKER_EMAC0_MODULE 0 0>;
346+
status = "disabled";
347+
};
338348
};
339349
};
340350

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ manifest:
198198
groups:
199199
- hal
200200
- name: hal_nuvoton
201-
revision: 8eec051270fe45c3f9a1a12de60220e1ab26b579
201+
revision: be1042dc8a96ebe9ea4c5d714f07c617539106d6
202202
path: modules/hal/nuvoton
203203
groups:
204204
- hal

0 commit comments

Comments
 (0)