Skip to content

Commit

Permalink
mediatek: add support for OpenEmbed SOM7981 (#12524)
Browse files Browse the repository at this point in the history
* kernel: crypto: add atmel i2c hw accelerator support

Signed-off-by: Tianling Shen <[email protected]>

* kernel: add led act/polarity select for rtl8221 phy

Signed-off-by: Tianling Shen <[email protected]>

* mediatek: add support for OpenEmbed SOM7981

Hardware specification:
  SoC: MediaTek MT7981B 2x A53
  Flash: 256 MiB SPI-NAND
  RAM: 0.5/1 GB DDR4
  Ethernet: 1x 1GbE, 1x 2.5GbE (RTL8221B)
  WiFi: MediaTek MT7976C
  USB: 1x M.2 B-Key
  GPIO: 26-Pin header
  UART: 6 GND, 8 TX, 10 RX (in Pin header)
  Button: Reset

Installation:
The board comes with a third-party custom OpenWrt image, you can upload
sysupgrade image via LuCI directly WITHOUT keeping configurations.

Or power on the board with pressing reset button for 5 second, then visit
http://192.168.1.1 and upload -factory.bin firmware.

Signed-off-by: Tianling Shen <[email protected]>

---------

Signed-off-by: Tianling Shen <[email protected]>
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 authored Oct 8, 2024
1 parent 9a4a925 commit 8061c8b
Show file tree
Hide file tree
Showing 17 changed files with 444 additions and 45 deletions.
4 changes: 4 additions & 0 deletions package/boot/uboot-envtools/files/mediatek_filogic
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ glinet,gl-mt6000)
glinet,gl-mt3000)
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x20000"
;;
openembed,som7981)
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x80000"
ubootenv_add_uci_sys_config "/dev/mtd3" "0x0" "0x100000" "0x100000"
;;
xiaomi,mi-router-wr30u|\
xiaomi,mi-router-ax3000t|\
xiaomi,redmi-router-ax6000)
Expand Down
20 changes: 20 additions & 0 deletions package/kernel/linux/modules/crypto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,26 @@ endef
$(eval $(call KernelPackage,crypto-hmac))


define KernelPackage/crypto-hw-atmel
TITLE:=Microchip / Atmel ECC/SHA/RNG hw accelerator
DEPENDS:=+kmod-i2c-core +kmod-crypto-ecdh +kmod-crypto-sha1 \
+kmod-crypto-sha256 +kmod-lib-crc16 +kmod-random-core
KCONFIG:= \
CONFIG_CRYPTO_HW=y \
CONFIG_CRYPTO_DEV_ATMEL_I2C \
CONFIG_CRYPTO_DEV_ATMEL_ECC \
CONFIG_CRYPTO_DEV_ATMEL_SHA204A
FILES:= \
$(LINUX_DIR)/drivers/crypto/atmel-i2c.ko \
$(LINUX_DIR)/drivers/crypto/atmel-ecc.ko \
$(LINUX_DIR)/drivers/crypto/atmel-sha204a.ko
AUTOLOAD:=$(call AutoLoad,09,atmel-i2c atmel-ecc atmel-sha204a)
$(call AddDepends/crypto)
endef

$(eval $(call KernelPackage,crypto-hw-atmel))


define KernelPackage/crypto-hw-ccp
TITLE:=AMD Cryptographic Coprocessor
DEPENDS:= \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Signed-off-by: David S. Miller <[email protected]>

--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -1941,11 +1941,11 @@ static int mtk_poll_rx(struct napi_struc
@@ -1940,11 +1940,11 @@ static int mtk_poll_rx(struct napi_struc
u8 *data, *new_data;
struct mtk_rx_dma_v2 *rxd, trxd;
int done = 0, bytes = 0;
Expand All @@ -32,7 +32,7 @@ Signed-off-by: David S. Miller <[email protected]>
u32 hash, reason;
int mac = 0;

@@ -2122,7 +2122,8 @@ release_desc:
@@ -2121,7 +2121,8 @@ release_desc:
else
rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,55 @@ Signed-off-by: Yangyu Chen <[email protected]>

--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -66,6 +66,10 @@
@@ -66,6 +66,12 @@
#define RTL8221B_PHYCR1_ALDPS_EN BIT(2)
#define RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN BIT(12)

+#define RTL8221B_NR_LEDS 3
+#define RTL8221B_LED_LINK_SELECT 0xd032
+#define RTL8221B_LED_LINK_SELECT_OFFSET 0x2
+#define RTL8221B_LED_ACT_SELECT 0xd040
+#define RTL8221B_LED_POLARITY_SELECT 0xd044
+
#define RTL8366RB_POWER_SAVE 0x15
#define RTL8366RB_POWER_SAVE_ON BIT(12)

@@ -921,6 +925,28 @@ static irqreturn_t rtl9000a_handle_inter
@@ -921,6 +927,45 @@ static irqreturn_t rtl9000a_handle_inter
return IRQ_HANDLED;
}

+static int rtl8221b_config_led(struct phy_device *phydev) {
+ struct device_node *node = phydev->mdio.dev.of_node;
+ u32 link_select[RTL8221B_NR_LEDS];
+ u32 act_select, polarity_select;
+ int i, val;
+
+ val = of_property_read_u32_array(node, "realtek,led-link-select",
+ val = of_property_read_u32_array(node, "realtek,led-link-select",
+ link_select, RTL8221B_NR_LEDS);
+ if (!val) {
+ for (i = 0; i < RTL8221B_NR_LEDS; i++) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_LINK_SELECT + i * RTL8221B_LED_LINK_SELECT_OFFSET,
+ link_select[i]);
+ if (val < 0)
+ return val;
+ }
+ }
+
+ if (val)
+ return 0;
+ val = of_property_read_u32(node, "realtek,led-act-select",
+ &act_select);
+ if (!val) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_ACT_SELECT, act_select);
+ if (val < 0)
+ return val;
+ }
+
+ for (i = 0; i < RTL8221B_NR_LEDS; i++) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_LINK_SELECT + i * RTL8221B_LED_LINK_SELECT_OFFSET,
+ link_select[i]);
+ val = of_property_read_u32(node, "realtek,led-polarity-select",
+ &polarity_select);
+ if (!val) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_POLARITY_SELECT, polarity_select);
+ if (val < 0)
+ return val;
+ }
Expand All @@ -58,7 +77,7 @@ Signed-off-by: Yangyu Chen <[email protected]>
static int rtl8221b_config_init(struct phy_device *phydev)
{
u16 option_mode;
@@ -968,7 +994,7 @@ static int rtl8221b_config_init(struct p
@@ -968,7 +1013,7 @@ static int rtl8221b_config_init(struct p
phy_read_mmd_poll_timeout(phydev, RTL8221B_MMD_SERDES_CTRL, 0x7587,
val, !(val & BIT(0)), 500, 100000, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,55 @@ Signed-off-by: Yangyu Chen <[email protected]>

--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -66,6 +66,10 @@
@@ -66,6 +66,12 @@
#define RTL8221B_PHYCR1_ALDPS_EN BIT(2)
#define RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN BIT(12)

+#define RTL8221B_NR_LEDS 3
+#define RTL8221B_LED_LINK_SELECT 0xd032
+#define RTL8221B_LED_LINK_SELECT_OFFSET 0x2
+#define RTL8221B_LED_ACT_SELECT 0xd040
+#define RTL8221B_LED_POLARITY_SELECT 0xd044
+
#define RTL8366RB_POWER_SAVE 0x15
#define RTL8366RB_POWER_SAVE_ON BIT(12)

@@ -932,6 +936,28 @@ static irqreturn_t rtl9000a_handle_inter
@@ -932,6 +938,45 @@ static irqreturn_t rtl9000a_handle_inter
return IRQ_HANDLED;
}

+static int rtl8221b_config_led(struct phy_device *phydev) {
+ struct device_node *node = phydev->mdio.dev.of_node;
+ u32 link_select[RTL8221B_NR_LEDS];
+ u32 act_select, polarity_select;
+ int i, val;
+
+ val = of_property_read_u32_array(node, "realtek,led-link-select",
+ val = of_property_read_u32_array(node, "realtek,led-link-select",
+ link_select, RTL8221B_NR_LEDS);
+ if (!val) {
+ for (i = 0; i < RTL8221B_NR_LEDS; i++) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_LINK_SELECT + i * RTL8221B_LED_LINK_SELECT_OFFSET,
+ link_select[i]);
+ if (val < 0)
+ return val;
+ }
+ }
+
+ if (val)
+ return 0;
+ val = of_property_read_u32(node, "realtek,led-act-select",
+ &act_select);
+ if (!val) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_ACT_SELECT, act_select);
+ if (val < 0)
+ return val;
+ }
+
+ for (i = 0; i < RTL8221B_NR_LEDS; i++) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_LINK_SELECT + i * RTL8221B_LED_LINK_SELECT_OFFSET,
+ link_select[i]);
+ val = of_property_read_u32(node, "realtek,led-polarity-select",
+ &polarity_select);
+ if (!val) {
+ val = phy_write_mmd(phydev, RTL8221B_MMD_PHY_CTRL,
+ RTL8221B_LED_POLARITY_SELECT, polarity_select);
+ if (val < 0)
+ return val;
+ }
Expand All @@ -58,7 +77,7 @@ Signed-off-by: Yangyu Chen <[email protected]>
static int rtl8221b_config_init(struct phy_device *phydev)
{
u16 option_mode;
@@ -979,7 +1005,7 @@ static int rtl8221b_config_init(struct p
@@ -979,7 +1024,7 @@ static int rtl8221b_config_init(struct p
phy_read_mmd_poll_timeout(phydev, RTL8221B_MMD_SERDES_CTRL, 0x7587,
val, !(val & BIT(0)), 500, 100000, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,55 @@ Signed-off-by: Yangyu Chen <[email protected]>

--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -86,6 +86,10 @@
@@ -86,6 +86,12 @@
#define RTL8221B_PHYCR1_ALDPS_EN BIT(2)
#define RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN BIT(12)

+#define RTL8221B_NR_LEDS 3
+#define RTL8221B_LED_LINK_SELECT 0xd032
+#define RTL8221B_LED_LINK_SELECT_OFFSET 0x2
+#define RTL8221B_LED_ACT_SELECT 0xd040
+#define RTL8221B_LED_POLARITY_SELECT 0xd044
+
#define RTL8366RB_POWER_SAVE 0x15
#define RTL8366RB_POWER_SAVE_ON BIT(12)

@@ -787,6 +791,28 @@ static int rtl822x_write_mmd(struct phy_
@@ -787,6 +793,45 @@ static int rtl822x_write_mmd(struct phy_
return ret;
}

+static int rtl822xb_config_led(struct phy_device *phydev) {
+ struct device_node *node = phydev->mdio.dev.of_node;
+ u32 link_select[RTL8221B_NR_LEDS];
+ u32 act_select, polarity_select;
+ int i, val;
+
+ val = of_property_read_u32_array(node, "realtek,led-link-select",
+ val = of_property_read_u32_array(node, "realtek,led-link-select",
+ link_select, RTL8221B_NR_LEDS);
+ if (!val) {
+ for (i = 0; i < RTL8221B_NR_LEDS; i++) {
+ val = phy_write_mmd(phydev, MDIO_MMD_VEND2,
+ RTL8221B_LED_LINK_SELECT + i * RTL8221B_LED_LINK_SELECT_OFFSET,
+ link_select[i]);
+ if (val < 0)
+ return val;
+ }
+ }
+
+ if (val)
+ return 0;
+ val = of_property_read_u32(node, "realtek,led-act-select",
+ &act_select);
+ if (!val) {
+ val = phy_write_mmd(phydev, MDIO_MMD_VEND2,
+ RTL8221B_LED_ACT_SELECT, act_select);
+ if (val < 0)
+ return val;
+ }
+
+ for (i = 0; i < RTL8221B_NR_LEDS; i++) {
+ val = phy_write_mmd(phydev, MDIO_MMD_VEND2,
+ RTL8221B_LED_LINK_SELECT + i * RTL8221B_LED_LINK_SELECT_OFFSET,
+ link_select[i]);
+ val = of_property_read_u32(node, "realtek,led-polarity-select",
+ &polarity_select);
+ if (!val) {
+ val = phy_write_mmd(phydev, MDIO_MMD_VEND2,
+ RTL8221B_LED_POLARITY_SELECT, polarity_select);
+ if (val < 0)
+ return val;
+ }
Expand All @@ -58,7 +77,7 @@ Signed-off-by: Yangyu Chen <[email protected]>
static int rtl822xb_config_init(struct phy_device *phydev)
{
bool has_2500, has_sgmii;
@@ -863,7 +889,7 @@ static int rtl822xb_config_init(struct p
@@ -863,7 +908,7 @@ static int rtl822xb_config_init(struct p
if (ret < 0)
return ret;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Signed-off-by: Felix Fietkau <[email protected]>

--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -253,6 +253,9 @@ mtk_flow_offload_replace(struct mtk_eth
@@ -255,6 +255,9 @@ mtk_flow_offload_replace(struct mtk_eth
if (rhashtable_lookup(&eth->flow_table, &f->cookie, mtk_flow_ht_params))
return -EEXIST;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Signed-off-by: Felix Fietkau <[email protected]>

--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -3097,8 +3097,8 @@ static irqreturn_t mtk_handle_irq_rx(int
@@ -3098,8 +3098,8 @@ static irqreturn_t mtk_handle_irq_rx(int

eth->rx_events++;
if (likely(napi_schedule_prep(&eth->rx_napi))) {
Expand All @@ -20,7 +20,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
}

return IRQ_HANDLED;
@@ -3110,8 +3110,8 @@ static irqreturn_t mtk_handle_irq_tx(int
@@ -3111,8 +3111,8 @@ static irqreturn_t mtk_handle_irq_tx(int

eth->tx_events++;
if (likely(napi_schedule_prep(&eth->tx_napi))) {
Expand All @@ -30,7 +30,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
}

return IRQ_HANDLED;
@@ -4885,6 +4885,8 @@ static int mtk_probe(struct platform_dev
@@ -4886,6 +4886,8 @@ static int mtk_probe(struct platform_dev
* for NAPI to work
*/
init_dummy_netdev(&eth->dummy_dev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
switch (speed) {
case SPEED_2500:
case SPEED_1000:
@@ -3290,6 +3291,9 @@ found:
@@ -3291,6 +3292,9 @@ found:
if (dp->index >= MTK_QDMA_NUM_QUEUES)
return NOTIFY_DONE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Signed-off-by: Felix Fietkau <[email protected]>

--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -235,7 +235,8 @@ out:
@@ -237,7 +237,8 @@ out:
}

static int
Expand All @@ -36,15 +36,15 @@ Signed-off-by: Felix Fietkau <[email protected]>
{
struct flow_rule *rule = flow_cls_offload_flow_rule(f);
struct flow_action_entry *act;
@@ -455,6 +456,7 @@ mtk_flow_offload_replace(struct mtk_eth
@@ -457,6 +458,7 @@ mtk_flow_offload_replace(struct mtk_eth
entry->cookie = f->cookie;
memcpy(&entry->data, &foe, sizeof(entry->data));
entry->wed_index = wed_index;
+ entry->ppe_index = ppe_index;

err = mtk_foe_entry_commit(eth->ppe[entry->ppe_index], entry);
if (err < 0)
@@ -523,25 +525,15 @@ mtk_flow_offload_stats(struct mtk_eth *e
@@ -525,25 +527,15 @@ mtk_flow_offload_stats(struct mtk_eth *e

static DEFINE_MUTEX(mtk_flow_offload_mutex);

Expand Down Expand Up @@ -73,7 +73,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
break;
case FLOW_CLS_DESTROY:
err = mtk_flow_offload_destroy(eth, cls);
@@ -559,6 +551,23 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_
@@ -561,6 +553,23 @@ mtk_eth_setup_tc_block_cb(enum tc_setup_
}

static int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
seq_printf(m, "%05x %s %7s", i,
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -502,24 +502,21 @@ static int
@@ -504,24 +504,21 @@ static int
mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
{
struct mtk_flow_entry *entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ Signed-off-by: Daniel Golle <[email protected]>
static const struct phylink_mac_ops mtk_phylink_ops = {
.validate = phylink_generic_validate,
.mac_select_pcs = mtk_mac_select_pcs,
@@ -4560,8 +4674,21 @@ static int mtk_add_mac(struct mtk_eth *e
@@ -4561,8 +4675,21 @@ static int mtk_add_mac(struct mtk_eth *e
phy_interface_zero(mac->phylink_config.supported_interfaces);
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
mac->phylink_config.supported_interfaces);
Expand All @@ -500,7 +500,7 @@ Signed-off-by: Daniel Golle <[email protected]>
phylink = phylink_create(&mac->phylink_config,
of_fwnode_handle(mac->of_node),
phy_mode, &mtk_phylink_ops);
@@ -4754,6 +4881,13 @@ static int mtk_probe(struct platform_dev
@@ -4755,6 +4882,13 @@ static int mtk_probe(struct platform_dev

if (err)
return err;
Expand Down
Loading

0 comments on commit 8061c8b

Please sign in to comment.