1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for the Airoha EN8811H 2.5 Gigabit PHY.
5 * Limitations of the EN8811H:
6 * - Only full duplex supported
7 * - Forced speed (AN off) is not supported by hardware (100Mbps)
9 * Source originated from airoha's en8811h.c and en8811h.h v1.2.1
11 * Copyright (C) 2023 Airoha Technology Corp.
14 #include <linux/phy.h>
15 #include <linux/firmware.h>
16 #include <linux/property.h>
17 #include <linux/wordpart.h>
18 #include <linux/unaligned.h>
20 #define EN8811H_PHY_ID 0x03a2a411
22 #define EN8811H_MD32_DM "airoha/EthMD32.dm.bin"
23 #define EN8811H_MD32_DSP "airoha/EthMD32.DSP.bin"
25 #define AIR_FW_ADDR_DM 0x00000000
26 #define AIR_FW_ADDR_DSP 0x00100000
29 #define AIR_AUX_CTRL_STATUS 0x1d
30 #define AIR_AUX_CTRL_STATUS_SPEED_MASK GENMASK(4, 2)
31 #define AIR_AUX_CTRL_STATUS_SPEED_100 0x4
32 #define AIR_AUX_CTRL_STATUS_SPEED_1000 0x8
33 #define AIR_AUX_CTRL_STATUS_SPEED_2500 0xc
35 #define AIR_EXT_PAGE_ACCESS 0x1f
36 #define AIR_PHY_PAGE_STANDARD 0x0000
37 #define AIR_PHY_PAGE_EXTENDED_4 0x0004
39 /* MII Registers Page 4*/
40 #define AIR_BPBUS_MODE 0x10
41 #define AIR_BPBUS_MODE_ADDR_FIXED 0x0000
42 #define AIR_BPBUS_MODE_ADDR_INCR BIT(15)
43 #define AIR_BPBUS_WR_ADDR_HIGH 0x11
44 #define AIR_BPBUS_WR_ADDR_LOW 0x12
45 #define AIR_BPBUS_WR_DATA_HIGH 0x13
46 #define AIR_BPBUS_WR_DATA_LOW 0x14
47 #define AIR_BPBUS_RD_ADDR_HIGH 0x15
48 #define AIR_BPBUS_RD_ADDR_LOW 0x16
49 #define AIR_BPBUS_RD_DATA_HIGH 0x17
50 #define AIR_BPBUS_RD_DATA_LOW 0x18
52 /* Registers on MDIO_MMD_VEND1 */
53 #define EN8811H_PHY_FW_STATUS 0x8009
54 #define EN8811H_PHY_READY 0x02
56 #define AIR_PHY_MCU_CMD_1 0x800c
57 #define AIR_PHY_MCU_CMD_1_MODE1 0x0
58 #define AIR_PHY_MCU_CMD_2 0x800d
59 #define AIR_PHY_MCU_CMD_2_MODE1 0x0
60 #define AIR_PHY_MCU_CMD_3 0x800e
61 #define AIR_PHY_MCU_CMD_3_MODE1 0x1101
62 #define AIR_PHY_MCU_CMD_3_DOCMD 0x1100
63 #define AIR_PHY_MCU_CMD_4 0x800f
64 #define AIR_PHY_MCU_CMD_4_MODE1 0x0002
65 #define AIR_PHY_MCU_CMD_4_INTCLR 0x00e4
67 /* Registers on MDIO_MMD_VEND2 */
68 #define AIR_PHY_LED_BCR 0x021
69 #define AIR_PHY_LED_BCR_MODE_MASK GENMASK(1, 0)
70 #define AIR_PHY_LED_BCR_TIME_TEST BIT(2)
71 #define AIR_PHY_LED_BCR_CLK_EN BIT(3)
72 #define AIR_PHY_LED_BCR_EXT_CTRL BIT(15)
74 #define AIR_PHY_LED_DUR_ON 0x022
76 #define AIR_PHY_LED_DUR_BLINK 0x023
78 #define AIR_PHY_LED_ON(i) (0x024 + ((i) * 2))
79 #define AIR_PHY_LED_ON_MASK (GENMASK(6, 0) | BIT(8))
80 #define AIR_PHY_LED_ON_LINK1000 BIT(0)
81 #define AIR_PHY_LED_ON_LINK100 BIT(1)
82 #define AIR_PHY_LED_ON_LINK10 BIT(2)
83 #define AIR_PHY_LED_ON_LINKDOWN BIT(3)
84 #define AIR_PHY_LED_ON_FDX BIT(4) /* Full duplex */
85 #define AIR_PHY_LED_ON_HDX BIT(5) /* Half duplex */
86 #define AIR_PHY_LED_ON_FORCE_ON BIT(6)
87 #define AIR_PHY_LED_ON_LINK2500 BIT(8)
88 #define AIR_PHY_LED_ON_POLARITY BIT(14)
89 #define AIR_PHY_LED_ON_ENABLE BIT(15)
91 #define AIR_PHY_LED_BLINK(i) (0x025 + ((i) * 2))
92 #define AIR_PHY_LED_BLINK_1000TX BIT(0)
93 #define AIR_PHY_LED_BLINK_1000RX BIT(1)
94 #define AIR_PHY_LED_BLINK_100TX BIT(2)
95 #define AIR_PHY_LED_BLINK_100RX BIT(3)
96 #define AIR_PHY_LED_BLINK_10TX BIT(4)
97 #define AIR_PHY_LED_BLINK_10RX BIT(5)
98 #define AIR_PHY_LED_BLINK_COLLISION BIT(6)
99 #define AIR_PHY_LED_BLINK_RX_CRC_ERR BIT(7)
100 #define AIR_PHY_LED_BLINK_RX_IDLE_ERR BIT(8)
101 #define AIR_PHY_LED_BLINK_FORCE_BLINK BIT(9)
102 #define AIR_PHY_LED_BLINK_2500TX BIT(10)
103 #define AIR_PHY_LED_BLINK_2500RX BIT(11)
105 /* Registers on BUCKPBUS */
106 #define EN8811H_2P5G_LPA 0x3b30
107 #define EN8811H_2P5G_LPA_2P5G BIT(0)
109 #define EN8811H_FW_VERSION 0x3b3c
111 #define EN8811H_POLARITY 0xca0f8
112 #define EN8811H_POLARITY_TX_NORMAL BIT(0)
113 #define EN8811H_POLARITY_RX_REVERSE BIT(1)
115 #define EN8811H_GPIO_OUTPUT 0xcf8b8
116 #define EN8811H_GPIO_OUTPUT_345 (BIT(3) | BIT(4) | BIT(5))
118 #define EN8811H_FW_CTRL_1 0x0f0018
119 #define EN8811H_FW_CTRL_1_START 0x0
120 #define EN8811H_FW_CTRL_1_FINISH 0x1
121 #define EN8811H_FW_CTRL_2 0x800000
122 #define EN8811H_FW_CTRL_2_LOADING BIT(11)
124 /* Led definitions */
125 #define EN8811H_LED_COUNT 3
127 /* Default LED setup:
128 * GPIO5 <-> LED0 On: Link detected, blink Rx/Tx
129 * GPIO4 <-> LED1 On: Link detected at 2500 or 1000 Mbps
130 * GPIO3 <-> LED2 On: Link detected at 2500 or 100 Mbps
132 #define AIR_DEFAULT_TRIGGER_LED0 (BIT(TRIGGER_NETDEV_LINK) | \
133 BIT(TRIGGER_NETDEV_RX) | \
134 BIT(TRIGGER_NETDEV_TX))
135 #define AIR_DEFAULT_TRIGGER_LED1 (BIT(TRIGGER_NETDEV_LINK_2500) | \
136 BIT(TRIGGER_NETDEV_LINK_1000))
137 #define AIR_DEFAULT_TRIGGER_LED2 (BIT(TRIGGER_NETDEV_LINK_2500) | \
138 BIT(TRIGGER_NETDEV_LINK_100))
145 struct en8811h_priv
{
146 u32 firmware_version
;
147 bool mcu_needs_restart
;
148 struct led led
[EN8811H_LED_COUNT
];
152 AIR_PHY_LED_STATE_FORCE_ON
,
153 AIR_PHY_LED_STATE_FORCE_BLINK
,
157 AIR_PHY_LED_DUR_BLINK_32MS
,
158 AIR_PHY_LED_DUR_BLINK_64MS
,
159 AIR_PHY_LED_DUR_BLINK_128MS
,
160 AIR_PHY_LED_DUR_BLINK_256MS
,
161 AIR_PHY_LED_DUR_BLINK_512MS
,
162 AIR_PHY_LED_DUR_BLINK_1024MS
,
176 AIR_LED_MODE_DISABLE
,
177 AIR_LED_MODE_USER_DEFINE
,
180 #define AIR_PHY_LED_DUR_UNIT 1024
181 #define AIR_PHY_LED_DUR (AIR_PHY_LED_DUR_UNIT << AIR_PHY_LED_DUR_BLINK_64MS)
183 static const unsigned long en8811h_led_trig
= BIT(TRIGGER_NETDEV_FULL_DUPLEX
) |
184 BIT(TRIGGER_NETDEV_LINK
) |
185 BIT(TRIGGER_NETDEV_LINK_10
) |
186 BIT(TRIGGER_NETDEV_LINK_100
) |
187 BIT(TRIGGER_NETDEV_LINK_1000
) |
188 BIT(TRIGGER_NETDEV_LINK_2500
) |
189 BIT(TRIGGER_NETDEV_RX
) |
190 BIT(TRIGGER_NETDEV_TX
);
192 static int air_phy_read_page(struct phy_device
*phydev
)
194 return __phy_read(phydev
, AIR_EXT_PAGE_ACCESS
);
197 static int air_phy_write_page(struct phy_device
*phydev
, int page
)
199 return __phy_write(phydev
, AIR_EXT_PAGE_ACCESS
, page
);
202 static int __air_buckpbus_reg_write(struct phy_device
*phydev
,
203 u32 pbus_address
, u32 pbus_data
)
207 ret
= __phy_write(phydev
, AIR_BPBUS_MODE
, AIR_BPBUS_MODE_ADDR_FIXED
);
211 ret
= __phy_write(phydev
, AIR_BPBUS_WR_ADDR_HIGH
,
212 upper_16_bits(pbus_address
));
216 ret
= __phy_write(phydev
, AIR_BPBUS_WR_ADDR_LOW
,
217 lower_16_bits(pbus_address
));
221 ret
= __phy_write(phydev
, AIR_BPBUS_WR_DATA_HIGH
,
222 upper_16_bits(pbus_data
));
226 ret
= __phy_write(phydev
, AIR_BPBUS_WR_DATA_LOW
,
227 lower_16_bits(pbus_data
));
234 static int air_buckpbus_reg_write(struct phy_device
*phydev
,
235 u32 pbus_address
, u32 pbus_data
)
240 saved_page
= phy_select_page(phydev
, AIR_PHY_PAGE_EXTENDED_4
);
242 if (saved_page
>= 0) {
243 ret
= __air_buckpbus_reg_write(phydev
, pbus_address
,
246 phydev_err(phydev
, "%s 0x%08x failed: %d\n", __func__
,
250 return phy_restore_page(phydev
, saved_page
, ret
);
253 static int __air_buckpbus_reg_read(struct phy_device
*phydev
,
254 u32 pbus_address
, u32
*pbus_data
)
256 int pbus_data_low
, pbus_data_high
;
259 ret
= __phy_write(phydev
, AIR_BPBUS_MODE
, AIR_BPBUS_MODE_ADDR_FIXED
);
263 ret
= __phy_write(phydev
, AIR_BPBUS_RD_ADDR_HIGH
,
264 upper_16_bits(pbus_address
));
268 ret
= __phy_write(phydev
, AIR_BPBUS_RD_ADDR_LOW
,
269 lower_16_bits(pbus_address
));
273 pbus_data_high
= __phy_read(phydev
, AIR_BPBUS_RD_DATA_HIGH
);
274 if (pbus_data_high
< 0)
275 return pbus_data_high
;
277 pbus_data_low
= __phy_read(phydev
, AIR_BPBUS_RD_DATA_LOW
);
278 if (pbus_data_low
< 0)
279 return pbus_data_low
;
281 *pbus_data
= pbus_data_low
| (pbus_data_high
<< 16);
285 static int air_buckpbus_reg_read(struct phy_device
*phydev
,
286 u32 pbus_address
, u32
*pbus_data
)
291 saved_page
= phy_select_page(phydev
, AIR_PHY_PAGE_EXTENDED_4
);
293 if (saved_page
>= 0) {
294 ret
= __air_buckpbus_reg_read(phydev
, pbus_address
, pbus_data
);
296 phydev_err(phydev
, "%s 0x%08x failed: %d\n", __func__
,
300 return phy_restore_page(phydev
, saved_page
, ret
);
303 static int __air_buckpbus_reg_modify(struct phy_device
*phydev
,
304 u32 pbus_address
, u32 mask
, u32 set
)
306 int pbus_data_low
, pbus_data_high
;
307 u32 pbus_data_old
, pbus_data_new
;
310 ret
= __phy_write(phydev
, AIR_BPBUS_MODE
, AIR_BPBUS_MODE_ADDR_FIXED
);
314 ret
= __phy_write(phydev
, AIR_BPBUS_RD_ADDR_HIGH
,
315 upper_16_bits(pbus_address
));
319 ret
= __phy_write(phydev
, AIR_BPBUS_RD_ADDR_LOW
,
320 lower_16_bits(pbus_address
));
324 pbus_data_high
= __phy_read(phydev
, AIR_BPBUS_RD_DATA_HIGH
);
325 if (pbus_data_high
< 0)
326 return pbus_data_high
;
328 pbus_data_low
= __phy_read(phydev
, AIR_BPBUS_RD_DATA_LOW
);
329 if (pbus_data_low
< 0)
330 return pbus_data_low
;
332 pbus_data_old
= pbus_data_low
| (pbus_data_high
<< 16);
333 pbus_data_new
= (pbus_data_old
& ~mask
) | set
;
334 if (pbus_data_new
== pbus_data_old
)
337 ret
= __phy_write(phydev
, AIR_BPBUS_WR_ADDR_HIGH
,
338 upper_16_bits(pbus_address
));
342 ret
= __phy_write(phydev
, AIR_BPBUS_WR_ADDR_LOW
,
343 lower_16_bits(pbus_address
));
347 ret
= __phy_write(phydev
, AIR_BPBUS_WR_DATA_HIGH
,
348 upper_16_bits(pbus_data_new
));
352 ret
= __phy_write(phydev
, AIR_BPBUS_WR_DATA_LOW
,
353 lower_16_bits(pbus_data_new
));
360 static int air_buckpbus_reg_modify(struct phy_device
*phydev
,
361 u32 pbus_address
, u32 mask
, u32 set
)
366 saved_page
= phy_select_page(phydev
, AIR_PHY_PAGE_EXTENDED_4
);
368 if (saved_page
>= 0) {
369 ret
= __air_buckpbus_reg_modify(phydev
, pbus_address
, mask
,
372 phydev_err(phydev
, "%s 0x%08x failed: %d\n", __func__
,
376 return phy_restore_page(phydev
, saved_page
, ret
);
379 static int __air_write_buf(struct phy_device
*phydev
, u32 address
,
380 const struct firmware
*fw
)
386 ret
= __phy_write(phydev
, AIR_BPBUS_MODE
, AIR_BPBUS_MODE_ADDR_INCR
);
390 ret
= __phy_write(phydev
, AIR_BPBUS_WR_ADDR_HIGH
,
391 upper_16_bits(address
));
395 ret
= __phy_write(phydev
, AIR_BPBUS_WR_ADDR_LOW
,
396 lower_16_bits(address
));
400 for (offset
= 0; offset
< fw
->size
; offset
+= 4) {
401 val
= get_unaligned_le16(&fw
->data
[offset
+ 2]);
402 ret
= __phy_write(phydev
, AIR_BPBUS_WR_DATA_HIGH
, val
);
406 val
= get_unaligned_le16(&fw
->data
[offset
]);
407 ret
= __phy_write(phydev
, AIR_BPBUS_WR_DATA_LOW
, val
);
415 static int air_write_buf(struct phy_device
*phydev
, u32 address
,
416 const struct firmware
*fw
)
421 saved_page
= phy_select_page(phydev
, AIR_PHY_PAGE_EXTENDED_4
);
423 if (saved_page
>= 0) {
424 ret
= __air_write_buf(phydev
, address
, fw
);
426 phydev_err(phydev
, "%s 0x%08x failed: %d\n", __func__
,
430 return phy_restore_page(phydev
, saved_page
, ret
);
433 static int en8811h_wait_mcu_ready(struct phy_device
*phydev
)
437 /* Because of mdio-lock, may have to wait for multiple loads */
438 ret
= phy_read_mmd_poll_timeout(phydev
, MDIO_MMD_VEND1
,
439 EN8811H_PHY_FW_STATUS
, reg_value
,
440 reg_value
== EN8811H_PHY_READY
,
441 20000, 7500000, true);
443 phydev_err(phydev
, "MCU not ready: 0x%x\n", reg_value
);
450 static int en8811h_load_firmware(struct phy_device
*phydev
)
452 struct en8811h_priv
*priv
= phydev
->priv
;
453 struct device
*dev
= &phydev
->mdio
.dev
;
454 const struct firmware
*fw1
, *fw2
;
457 ret
= request_firmware_direct(&fw1
, EN8811H_MD32_DM
, dev
);
461 ret
= request_firmware_direct(&fw2
, EN8811H_MD32_DSP
, dev
);
463 goto en8811h_load_firmware_rel1
;
465 ret
= air_buckpbus_reg_write(phydev
, EN8811H_FW_CTRL_1
,
466 EN8811H_FW_CTRL_1_START
);
468 goto en8811h_load_firmware_out
;
470 ret
= air_buckpbus_reg_modify(phydev
, EN8811H_FW_CTRL_2
,
471 EN8811H_FW_CTRL_2_LOADING
,
472 EN8811H_FW_CTRL_2_LOADING
);
474 goto en8811h_load_firmware_out
;
476 ret
= air_write_buf(phydev
, AIR_FW_ADDR_DM
, fw1
);
478 goto en8811h_load_firmware_out
;
480 ret
= air_write_buf(phydev
, AIR_FW_ADDR_DSP
, fw2
);
482 goto en8811h_load_firmware_out
;
484 ret
= air_buckpbus_reg_modify(phydev
, EN8811H_FW_CTRL_2
,
485 EN8811H_FW_CTRL_2_LOADING
, 0);
487 goto en8811h_load_firmware_out
;
489 ret
= air_buckpbus_reg_write(phydev
, EN8811H_FW_CTRL_1
,
490 EN8811H_FW_CTRL_1_FINISH
);
492 goto en8811h_load_firmware_out
;
494 ret
= en8811h_wait_mcu_ready(phydev
);
496 air_buckpbus_reg_read(phydev
, EN8811H_FW_VERSION
,
497 &priv
->firmware_version
);
498 phydev_info(phydev
, "MD32 firmware version: %08x\n",
499 priv
->firmware_version
);
501 en8811h_load_firmware_out
:
502 release_firmware(fw2
);
504 en8811h_load_firmware_rel1
:
505 release_firmware(fw1
);
508 phydev_err(phydev
, "Load firmware failed: %d\n", ret
);
513 static int en8811h_restart_mcu(struct phy_device
*phydev
)
517 ret
= air_buckpbus_reg_write(phydev
, EN8811H_FW_CTRL_1
,
518 EN8811H_FW_CTRL_1_START
);
522 ret
= air_buckpbus_reg_write(phydev
, EN8811H_FW_CTRL_1
,
523 EN8811H_FW_CTRL_1_FINISH
);
527 return en8811h_wait_mcu_ready(phydev
);
530 static int air_hw_led_on_set(struct phy_device
*phydev
, u8 index
, bool on
)
532 struct en8811h_priv
*priv
= phydev
->priv
;
535 if (index
>= EN8811H_LED_COUNT
)
539 changed
= !test_and_set_bit(AIR_PHY_LED_STATE_FORCE_ON
,
540 &priv
->led
[index
].state
);
542 changed
= !!test_and_clear_bit(AIR_PHY_LED_STATE_FORCE_ON
,
543 &priv
->led
[index
].state
);
545 changed
|= (priv
->led
[index
].rules
!= 0);
547 /* clear netdev trigger rules in case LED_OFF has been set */
549 priv
->led
[index
].rules
= 0;
552 return phy_modify_mmd(phydev
, MDIO_MMD_VEND2
,
553 AIR_PHY_LED_ON(index
),
555 on
? AIR_PHY_LED_ON_FORCE_ON
: 0);
560 static int air_hw_led_blink_set(struct phy_device
*phydev
, u8 index
,
563 struct en8811h_priv
*priv
= phydev
->priv
;
566 if (index
>= EN8811H_LED_COUNT
)
570 changed
= !test_and_set_bit(AIR_PHY_LED_STATE_FORCE_BLINK
,
571 &priv
->led
[index
].state
);
573 changed
= !!test_and_clear_bit(AIR_PHY_LED_STATE_FORCE_BLINK
,
574 &priv
->led
[index
].state
);
576 changed
|= (priv
->led
[index
].rules
!= 0);
579 return phy_write_mmd(phydev
, MDIO_MMD_VEND2
,
580 AIR_PHY_LED_BLINK(index
),
582 AIR_PHY_LED_BLINK_FORCE_BLINK
: 0);
587 static int air_led_blink_set(struct phy_device
*phydev
, u8 index
,
588 unsigned long *delay_on
,
589 unsigned long *delay_off
)
591 struct en8811h_priv
*priv
= phydev
->priv
;
592 bool blinking
= false;
595 if (index
>= EN8811H_LED_COUNT
)
598 if (delay_on
&& delay_off
&& (*delay_on
> 0) && (*delay_off
> 0)) {
604 err
= air_hw_led_blink_set(phydev
, index
, blinking
);
608 /* led-blink set, so switch led-on off */
609 err
= air_hw_led_on_set(phydev
, index
, false);
613 /* hw-control is off*/
614 if (!!test_bit(AIR_PHY_LED_STATE_FORCE_BLINK
, &priv
->led
[index
].state
))
615 priv
->led
[index
].rules
= 0;
620 static int air_led_brightness_set(struct phy_device
*phydev
, u8 index
,
621 enum led_brightness value
)
623 struct en8811h_priv
*priv
= phydev
->priv
;
626 if (index
>= EN8811H_LED_COUNT
)
629 /* led-on set, so switch led-blink off */
630 err
= air_hw_led_blink_set(phydev
, index
, false);
634 err
= air_hw_led_on_set(phydev
, index
, (value
!= LED_OFF
));
638 /* hw-control is off */
639 if (!!test_bit(AIR_PHY_LED_STATE_FORCE_ON
, &priv
->led
[index
].state
))
640 priv
->led
[index
].rules
= 0;
645 static int air_led_hw_control_get(struct phy_device
*phydev
, u8 index
,
646 unsigned long *rules
)
648 struct en8811h_priv
*priv
= phydev
->priv
;
650 if (index
>= EN8811H_LED_COUNT
)
653 *rules
= priv
->led
[index
].rules
;
658 static int air_led_hw_control_set(struct phy_device
*phydev
, u8 index
,
661 struct en8811h_priv
*priv
= phydev
->priv
;
662 u16 on
= 0, blink
= 0;
665 if (index
>= EN8811H_LED_COUNT
)
668 priv
->led
[index
].rules
= rules
;
670 if (rules
& BIT(TRIGGER_NETDEV_FULL_DUPLEX
))
671 on
|= AIR_PHY_LED_ON_FDX
;
673 if (rules
& (BIT(TRIGGER_NETDEV_LINK_10
) | BIT(TRIGGER_NETDEV_LINK
)))
674 on
|= AIR_PHY_LED_ON_LINK10
;
676 if (rules
& (BIT(TRIGGER_NETDEV_LINK_100
) | BIT(TRIGGER_NETDEV_LINK
)))
677 on
|= AIR_PHY_LED_ON_LINK100
;
679 if (rules
& (BIT(TRIGGER_NETDEV_LINK_1000
) | BIT(TRIGGER_NETDEV_LINK
)))
680 on
|= AIR_PHY_LED_ON_LINK1000
;
682 if (rules
& (BIT(TRIGGER_NETDEV_LINK_2500
) | BIT(TRIGGER_NETDEV_LINK
)))
683 on
|= AIR_PHY_LED_ON_LINK2500
;
685 if (rules
& BIT(TRIGGER_NETDEV_RX
)) {
686 blink
|= AIR_PHY_LED_BLINK_10RX
|
687 AIR_PHY_LED_BLINK_100RX
|
688 AIR_PHY_LED_BLINK_1000RX
|
689 AIR_PHY_LED_BLINK_2500RX
;
692 if (rules
& BIT(TRIGGER_NETDEV_TX
)) {
693 blink
|= AIR_PHY_LED_BLINK_10TX
|
694 AIR_PHY_LED_BLINK_100TX
|
695 AIR_PHY_LED_BLINK_1000TX
|
696 AIR_PHY_LED_BLINK_2500TX
;
700 /* switch hw-control on, so led-on and led-blink are off */
701 clear_bit(AIR_PHY_LED_STATE_FORCE_ON
,
702 &priv
->led
[index
].state
);
703 clear_bit(AIR_PHY_LED_STATE_FORCE_BLINK
,
704 &priv
->led
[index
].state
);
706 priv
->led
[index
].rules
= 0;
709 ret
= phy_modify_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_ON(index
),
710 AIR_PHY_LED_ON_MASK
, on
);
715 return phy_write_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_BLINK(index
),
719 static int air_led_init(struct phy_device
*phydev
, u8 index
, u8 state
, u8 pol
)
724 if (index
>= EN8811H_LED_COUNT
)
727 if (state
== AIR_LED_ENABLE
)
728 val
|= AIR_PHY_LED_ON_ENABLE
;
730 val
&= ~AIR_PHY_LED_ON_ENABLE
;
732 if (pol
== AIR_ACTIVE_HIGH
)
733 val
|= AIR_PHY_LED_ON_POLARITY
;
735 val
&= ~AIR_PHY_LED_ON_POLARITY
;
737 err
= phy_modify_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_ON(index
),
738 AIR_PHY_LED_ON_ENABLE
|
739 AIR_PHY_LED_ON_POLARITY
, val
);
747 static int air_leds_init(struct phy_device
*phydev
, int num
, int dur
, int mode
)
749 struct en8811h_priv
*priv
= phydev
->priv
;
752 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_DUR_BLINK
,
757 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_DUR_ON
,
763 case AIR_LED_MODE_DISABLE
:
764 ret
= phy_modify_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_BCR
,
765 AIR_PHY_LED_BCR_EXT_CTRL
|
766 AIR_PHY_LED_BCR_MODE_MASK
, 0);
770 case AIR_LED_MODE_USER_DEFINE
:
771 ret
= phy_modify_mmd(phydev
, MDIO_MMD_VEND2
, AIR_PHY_LED_BCR
,
772 AIR_PHY_LED_BCR_EXT_CTRL
|
773 AIR_PHY_LED_BCR_CLK_EN
,
774 AIR_PHY_LED_BCR_EXT_CTRL
|
775 AIR_PHY_LED_BCR_CLK_EN
);
780 phydev_err(phydev
, "LED mode %d is not supported\n", mode
);
784 for (i
= 0; i
< num
; ++i
) {
785 ret
= air_led_init(phydev
, i
, AIR_LED_ENABLE
, AIR_ACTIVE_HIGH
);
787 phydev_err(phydev
, "LED%d init failed: %d\n", i
, ret
);
790 air_led_hw_control_set(phydev
, i
, priv
->led
[i
].rules
);
796 static int en8811h_led_hw_is_supported(struct phy_device
*phydev
, u8 index
,
799 if (index
>= EN8811H_LED_COUNT
)
802 /* All combinations of the supported triggers are allowed */
803 if (rules
& ~en8811h_led_trig
)
809 static int en8811h_probe(struct phy_device
*phydev
)
811 struct en8811h_priv
*priv
;
814 priv
= devm_kzalloc(&phydev
->mdio
.dev
, sizeof(struct en8811h_priv
),
820 ret
= en8811h_load_firmware(phydev
);
824 /* mcu has just restarted after firmware load */
825 priv
->mcu_needs_restart
= false;
827 priv
->led
[0].rules
= AIR_DEFAULT_TRIGGER_LED0
;
828 priv
->led
[1].rules
= AIR_DEFAULT_TRIGGER_LED1
;
829 priv
->led
[2].rules
= AIR_DEFAULT_TRIGGER_LED2
;
831 /* MDIO_DEVS1/2 empty, so set mmds_present bits here */
832 phydev
->c45_ids
.mmds_present
|= MDIO_DEVS_PMAPMD
| MDIO_DEVS_AN
;
834 ret
= air_leds_init(phydev
, EN8811H_LED_COUNT
, AIR_PHY_LED_DUR
,
835 AIR_LED_MODE_DISABLE
);
837 phydev_err(phydev
, "Failed to disable leds: %d\n", ret
);
841 /* Configure led gpio pins as output */
842 ret
= air_buckpbus_reg_modify(phydev
, EN8811H_GPIO_OUTPUT
,
843 EN8811H_GPIO_OUTPUT_345
,
844 EN8811H_GPIO_OUTPUT_345
);
851 static int en8811h_config_init(struct phy_device
*phydev
)
853 struct en8811h_priv
*priv
= phydev
->priv
;
854 struct device
*dev
= &phydev
->mdio
.dev
;
858 /* If restart happened in .probe(), no need to restart now */
859 if (priv
->mcu_needs_restart
) {
860 ret
= en8811h_restart_mcu(phydev
);
864 /* Next calls to .config_init() mcu needs to restart */
865 priv
->mcu_needs_restart
= true;
868 /* Select mode 1, the only mode supported.
869 * Configures the SerDes for 2500Base-X with rate adaptation
871 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, AIR_PHY_MCU_CMD_1
,
872 AIR_PHY_MCU_CMD_1_MODE1
);
875 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, AIR_PHY_MCU_CMD_2
,
876 AIR_PHY_MCU_CMD_2_MODE1
);
879 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, AIR_PHY_MCU_CMD_3
,
880 AIR_PHY_MCU_CMD_3_MODE1
);
883 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, AIR_PHY_MCU_CMD_4
,
884 AIR_PHY_MCU_CMD_4_MODE1
);
888 /* Serdes polarity */
890 if (device_property_read_bool(dev
, "airoha,pnswap-rx"))
891 pbus_value
|= EN8811H_POLARITY_RX_REVERSE
;
893 pbus_value
&= ~EN8811H_POLARITY_RX_REVERSE
;
894 if (device_property_read_bool(dev
, "airoha,pnswap-tx"))
895 pbus_value
&= ~EN8811H_POLARITY_TX_NORMAL
;
897 pbus_value
|= EN8811H_POLARITY_TX_NORMAL
;
898 ret
= air_buckpbus_reg_modify(phydev
, EN8811H_POLARITY
,
899 EN8811H_POLARITY_RX_REVERSE
|
900 EN8811H_POLARITY_TX_NORMAL
, pbus_value
);
904 ret
= air_leds_init(phydev
, EN8811H_LED_COUNT
, AIR_PHY_LED_DUR
,
905 AIR_LED_MODE_USER_DEFINE
);
907 phydev_err(phydev
, "Failed to initialize leds: %d\n", ret
);
914 static int en8811h_get_features(struct phy_device
*phydev
)
916 linkmode_set_bit_array(phy_basic_ports_array
,
917 ARRAY_SIZE(phy_basic_ports_array
),
920 return genphy_c45_pma_read_abilities(phydev
);
923 static int en8811h_get_rate_matching(struct phy_device
*phydev
,
924 phy_interface_t iface
)
926 return RATE_MATCH_PAUSE
;
929 static int en8811h_config_aneg(struct phy_device
*phydev
)
931 bool changed
= false;
935 if (phydev
->autoneg
== AUTONEG_DISABLE
) {
936 phydev_warn(phydev
, "Disabling autoneg is not supported\n");
940 adv
= linkmode_adv_to_mii_10gbt_adv_t(phydev
->advertising
);
942 ret
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
, MDIO_AN_10GBT_CTRL
,
943 MDIO_AN_10GBT_CTRL_ADV2_5G
, adv
);
949 return __genphy_config_aneg(phydev
, changed
);
952 static int en8811h_read_status(struct phy_device
*phydev
)
954 struct en8811h_priv
*priv
= phydev
->priv
;
958 ret
= genphy_update_link(phydev
);
962 phydev
->master_slave_get
= MASTER_SLAVE_CFG_UNSUPPORTED
;
963 phydev
->master_slave_state
= MASTER_SLAVE_STATE_UNSUPPORTED
;
964 phydev
->speed
= SPEED_UNKNOWN
;
965 phydev
->duplex
= DUPLEX_UNKNOWN
;
967 phydev
->asym_pause
= 0;
968 phydev
->rate_matching
= RATE_MATCH_PAUSE
;
970 ret
= genphy_read_master_slave(phydev
);
974 ret
= genphy_read_lpa(phydev
);
978 /* Get link partner 2.5GBASE-T ability from vendor register */
979 ret
= air_buckpbus_reg_read(phydev
, EN8811H_2P5G_LPA
, &pbus_value
);
982 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT
,
983 phydev
->lp_advertising
,
984 pbus_value
& EN8811H_2P5G_LPA_2P5G
);
986 if (phydev
->autoneg_complete
)
987 phy_resolve_aneg_pause(phydev
);
992 /* Get real speed from vendor register */
993 val
= phy_read(phydev
, AIR_AUX_CTRL_STATUS
);
996 switch (val
& AIR_AUX_CTRL_STATUS_SPEED_MASK
) {
997 case AIR_AUX_CTRL_STATUS_SPEED_2500
:
998 phydev
->speed
= SPEED_2500
;
1000 case AIR_AUX_CTRL_STATUS_SPEED_1000
:
1001 phydev
->speed
= SPEED_1000
;
1003 case AIR_AUX_CTRL_STATUS_SPEED_100
:
1004 phydev
->speed
= SPEED_100
;
1008 /* Firmware before version 24011202 has no vendor register 2P5G_LPA.
1009 * Assume link partner advertised it if connected at 2500Mbps.
1011 if (priv
->firmware_version
< 0x24011202) {
1012 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT
,
1013 phydev
->lp_advertising
,
1014 phydev
->speed
== SPEED_2500
);
1017 /* Only supports full duplex */
1018 phydev
->duplex
= DUPLEX_FULL
;
1023 static int en8811h_clear_intr(struct phy_device
*phydev
)
1027 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, AIR_PHY_MCU_CMD_3
,
1028 AIR_PHY_MCU_CMD_3_DOCMD
);
1032 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, AIR_PHY_MCU_CMD_4
,
1033 AIR_PHY_MCU_CMD_4_INTCLR
);
1040 static irqreturn_t
en8811h_handle_interrupt(struct phy_device
*phydev
)
1044 ret
= en8811h_clear_intr(phydev
);
1050 phy_trigger_machine(phydev
);
1055 static struct phy_driver en8811h_driver
[] = {
1057 PHY_ID_MATCH_MODEL(EN8811H_PHY_ID
),
1058 .name
= "Airoha EN8811H",
1059 .probe
= en8811h_probe
,
1060 .get_features
= en8811h_get_features
,
1061 .config_init
= en8811h_config_init
,
1062 .get_rate_matching
= en8811h_get_rate_matching
,
1063 .config_aneg
= en8811h_config_aneg
,
1064 .read_status
= en8811h_read_status
,
1065 .config_intr
= en8811h_clear_intr
,
1066 .handle_interrupt
= en8811h_handle_interrupt
,
1067 .led_hw_is_supported
= en8811h_led_hw_is_supported
,
1068 .read_page
= air_phy_read_page
,
1069 .write_page
= air_phy_write_page
,
1070 .led_blink_set
= air_led_blink_set
,
1071 .led_brightness_set
= air_led_brightness_set
,
1072 .led_hw_control_set
= air_led_hw_control_set
,
1073 .led_hw_control_get
= air_led_hw_control_get
,
1076 module_phy_driver(en8811h_driver
);
1078 static struct mdio_device_id __maybe_unused en8811h_tbl
[] = {
1079 { PHY_ID_MATCH_MODEL(EN8811H_PHY_ID
) },
1083 MODULE_DEVICE_TABLE(mdio
, en8811h_tbl
);
1084 MODULE_FIRMWARE(EN8811H_MD32_DM
);
1085 MODULE_FIRMWARE(EN8811H_MD32_DSP
);
1087 MODULE_DESCRIPTION("Airoha EN8811H PHY drivers");
1088 MODULE_AUTHOR("Airoha");
1089 MODULE_AUTHOR("Eric Woudstra <ericwouds@gmail.com>");
1090 MODULE_LICENSE("GPL");