1 |
From 12f649c6d241008017ddcc12a39d1b5e6053a336 Mon Sep 17 00:00:00 2001 |
2 |
From: Sasha Levin <sashal@kernel.org> |
3 |
Date: Fri, 17 Jun 2022 14:12:45 +0530 |
4 |
Subject: net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect |
5 |
|
6 |
From: Arun Ramadoss <arun.ramadoss@microchip.com> |
7 |
|
8 |
[ Upstream commit 27faa0aa85f6696d411bbbebaed9f0f723c2a175 ] |
9 |
|
10 |
The ksz9477_switch_detect performs the detecting the chip id from the |
11 |
location 0x00 and also check gigabit compatibility check & number of |
12 |
ports based on the register global_options0. To prepare the common ksz |
13 |
switch detect function, routine other than chip id read is moved to |
14 |
ksz9477_switch_init. |
15 |
|
16 |
Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com> |
17 |
Reviewed-by: Vladimir Oltean <olteanv@gmail.com> |
18 |
Signed-off-by: Paolo Abeni <pabeni@redhat.com> |
19 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
20 |
--- |
21 |
drivers/net/dsa/microchip/ksz9477.c | 48 +++++++++++++---------------- |
22 |
1 file changed, 22 insertions(+), 26 deletions(-) |
23 |
|
24 |
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c |
25 |
index ebad795e4e95f..876a801ac23a4 100644 |
26 |
--- a/drivers/net/dsa/microchip/ksz9477.c |
27 |
+++ b/drivers/net/dsa/microchip/ksz9477.c |
28 |
@@ -1365,12 +1365,30 @@ static u32 ksz9477_get_port_addr(int port, int offset) |
29 |
|
30 |
static int ksz9477_switch_detect(struct ksz_device *dev) |
31 |
{ |
32 |
- u8 data8; |
33 |
- u8 id_hi; |
34 |
- u8 id_lo; |
35 |
u32 id32; |
36 |
int ret; |
37 |
|
38 |
+ /* read chip id */ |
39 |
+ ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32); |
40 |
+ if (ret) |
41 |
+ return ret; |
42 |
+ |
43 |
+ dev_dbg(dev->dev, "Switch detect: ID=%08x\n", id32); |
44 |
+ |
45 |
+ dev->chip_id = id32 & 0x00FFFF00; |
46 |
+ |
47 |
+ return 0; |
48 |
+} |
49 |
+ |
50 |
+static int ksz9477_switch_init(struct ksz_device *dev) |
51 |
+{ |
52 |
+ u8 data8; |
53 |
+ int ret; |
54 |
+ |
55 |
+ dev->ds->ops = &ksz9477_switch_ops; |
56 |
+ |
57 |
+ dev->port_mask = (1 << dev->info->port_cnt) - 1; |
58 |
+ |
59 |
/* turn off SPI DO Edge select */ |
60 |
ret = ksz_read8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, &data8); |
61 |
if (ret) |
62 |
@@ -1381,10 +1399,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev) |
63 |
if (ret) |
64 |
return ret; |
65 |
|
66 |
- /* read chip id */ |
67 |
- ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32); |
68 |
- if (ret) |
69 |
- return ret; |
70 |
ret = ksz_read8(dev, REG_GLOBAL_OPTIONS, &data8); |
71 |
if (ret) |
72 |
return ret; |
73 |
@@ -1395,10 +1409,7 @@ static int ksz9477_switch_detect(struct ksz_device *dev) |
74 |
/* Default capability is gigabit capable. */ |
75 |
dev->features = GBIT_SUPPORT; |
76 |
|
77 |
- dev_dbg(dev->dev, "Switch detect: ID=%08x%02x\n", id32, data8); |
78 |
- id_hi = (u8)(id32 >> 16); |
79 |
- id_lo = (u8)(id32 >> 8); |
80 |
- if ((id_lo & 0xf) == 3) { |
81 |
+ if (dev->chip_id == KSZ9893_CHIP_ID) { |
82 |
/* Chip is from KSZ9893 design. */ |
83 |
dev_info(dev->dev, "Found KSZ9893\n"); |
84 |
dev->features |= IS_9893; |
85 |
@@ -1416,21 +1427,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev) |
86 |
if (!(data8 & SW_GIGABIT_ABLE)) |
87 |
dev->features &= ~GBIT_SUPPORT; |
88 |
} |
89 |
- |
90 |
- /* Change chip id to known ones so it can be matched against them. */ |
91 |
- id32 = (id_hi << 16) | (id_lo << 8); |
92 |
- |
93 |
- dev->chip_id = id32; |
94 |
- |
95 |
- return 0; |
96 |
-} |
97 |
- |
98 |
-static int ksz9477_switch_init(struct ksz_device *dev) |
99 |
-{ |
100 |
- dev->ds->ops = &ksz9477_switch_ops; |
101 |
- |
102 |
- dev->port_mask = (1 << dev->info->port_cnt) - 1; |
103 |
- |
104 |
return 0; |
105 |
} |
106 |
|
107 |
-- |
108 |
2.35.1 |
109 |
|