Skip to content

Commit

Permalink
kernel: rtl8367b: store chip in smi->rtl8367b_chip
Browse files Browse the repository at this point in the history
Store the chip type in smi->rtl8367b_chip, fix #12537

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Hauke Mehrtens <[email protected]>
  • Loading branch information
namiltd committed Oct 14, 2024
1 parent 3f4efb6 commit 3396735
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
11 changes: 11 additions & 0 deletions target/linux/generic/files/drivers/net/phy/rtl8366_smi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ struct dentry;
struct inode;
struct file;

typedef enum rtl8367b_chip_e {
RTL8367B_CHIP_UNKNOWN,
/* Family B */
RTL8367B_CHIP_RTL8367RB,
RTL8367B_CHIP_RTL8367R_VB, /* chip with exception in extif assignment */
/* Family C */
RTL8367B_CHIP_RTL8367RB_VB,
RTL8367B_CHIP_RTL8367S
} rtl8367b_chip_t;

struct rtl8366_mib_counter {
unsigned base;
unsigned offset;
Expand Down Expand Up @@ -64,6 +74,7 @@ struct rtl8366_smi {
u8 dbg_vlan_4k_page;
#endif
u32 phy_id;
rtl8367b_chip_t rtl8367b_chip;
struct mii_bus *ext_mbus;
};

Expand Down
58 changes: 25 additions & 33 deletions target/linux/generic/files/drivers/net/phy/rtl8367b.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Platform driver for the Realtek RTL8367R-VB ethernet switches
* Platform driver for Realtek RTL8367B family chips, i.e. RTL8367RB and RTL8367R-VB
* extended with support for RTL8367C family chips, i.e. RTL8367RB-VB and RTL8367S
*
* Copyright (C) 2012 Gabor Juhos <[email protected]>
*
Expand Down Expand Up @@ -515,28 +516,19 @@ static int rtl8367b_write_phy_reg(struct rtl8366_smi *smi,
static int rtl8367b_init_regs(struct rtl8366_smi *smi)
{
const struct rtl8367b_initval *initvals;
u32 chip_num;
u32 chip_ver;
int count;
int err;

REG_WR(smi, RTL8367B_RTL_MAGIC_ID_REG, RTL8367B_RTL_MAGIC_ID_VAL);
REG_RD(smi, RTL8367B_CHIP_NUMBER_REG, &chip_num);
REG_RD(smi, RTL8367B_CHIP_VER_REG, &chip_ver);

switch (chip_ver) {
case 0x1000:
case 0x1010:
switch (smi->rtl8367b_chip) {
case RTL8367B_CHIP_RTL8367RB:
case RTL8367B_CHIP_RTL8367R_VB:
initvals = rtl8367b_initvals;
count = ARRAY_SIZE(rtl8367b_initvals);
break;
case 0x0020:
case 0x00A0:
if (chip_num == 0x6367) {
initvals = rtl8367c_initvals;
count = ARRAY_SIZE(rtl8367c_initvals);
} else return -ENODEV;
break
case RTL8367B_CHIP_RTL8367RB_VB:
case RTL8367B_CHIP_RTL8367S:
initvals = rtl8367c_initvals;
count = ARRAY_SIZE(rtl8367c_initvals);
break;
default:
return -ENODEV;
}
Expand Down Expand Up @@ -1308,10 +1300,10 @@ static int rtl8367b_detect(struct rtl8366_smi *smi)
const char *chip_name = NULL;
u32 chip_num;
u32 chip_ver;
u32 chip_mode;
int ret;

/* TODO: improve chip detection */
smi->rtl8367b_chip = RTL8367B_CHIP_UNKNOWN;

rtl8366_smi_write_reg(smi, RTL8367B_RTL_MAGIC_ID_REG,
RTL8367B_RTL_MAGIC_ID_VAL);

Expand All @@ -1329,41 +1321,41 @@ static int rtl8367b_detect(struct rtl8366_smi *smi)
return ret;
}

ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_MODE_REG, &chip_mode);
if (ret) {
dev_err(smi->parent, "unable to read %s register\n",
"chip mode");
return ret;
}

switch (chip_ver) {
case 0x0020:
if (chip_num == 0x6367)
if (chip_num == 0x6367) {
chip_name = "8367RB-VB";
smi->rtl8367b_chip = RTL8367B_CHIP_RTL8367RB_VB;
}
break;
case 0x00A0:
if (chip_num == 0x6367)
if (chip_num == 0x6367) {
chip_name = "8367S";
smi->rtl8367b_chip = RTL8367B_CHIP_RTL8367S;
}
break;
case 0x1000:
chip_name = "8367RB";
smi->rtl8367b_chip = RTL8367B_CHIP_RTL8367RB;
break;
case 0x1010:
chip_name = "8367R-VB";
smi->rtl8367b_chip = RTL8367B_CHIP_RTL8367R_VB;
}

if (!chip_name) {
dev_err(smi->parent,
"unknown chip num:%04x ver:%04x, mode:%04x\n",
chip_num, chip_ver, chip_mode);
"unknown chip (num:%04x ver:%04x)\n",
chip_num, chip_ver);
return -ENODEV;
}

dev_info(smi->parent, "RTL%s chip found\n", chip_name);
dev_info(smi->parent, "RTL%s chip found (num:%04x ver:%04x)\n", chip_name, chip_num, chip_ver);

/* for the RTL8367R-VB chip, extif1 corresponds to cpu_port 5 */
if (of_property_present(smi->parent->of_node, "realtek,extif2"))
smi->cpu_port = RTL8367B_CPU_PORT_NUM + 2;
else if (of_property_present(smi->parent->of_node, "realtek,extif1") && (chip_ver != 0x1010)) /* for the RTL8367R-VB chip, extif1 corresponds to cpu_port 5 */
else if (of_property_present(smi->parent->of_node, "realtek,extif1") && (smi->rtl8367b_chip != RTL8367B_CHIP_RTL8367R_VB))
smi->cpu_port = RTL8367B_CPU_PORT_NUM + 1;

dev_info(smi->parent, "CPU port: %u\n", smi->cpu_port);
Expand Down

0 comments on commit 3396735

Please sign in to comment.