Skip to content

Commit edf9acf

Browse files
committed
Merge branch 'r8152-serial-fixes'
Hayes Wang says: ==================== r8152: serial fixes v3: 1. Fix the typos for patch #5 and #6. 2. Modify the commit message of patch #9. v2: For patch #2, move declaring the variable "ocp_data". v1: These patches are used to fix some issues for RTL8153. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 940ba14 + aa475d9 commit edf9acf

File tree

1 file changed

+114
-11
lines changed

1 file changed

+114
-11
lines changed

drivers/net/usb/r8152.c

+114-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define NETNEXT_VERSION "11"
3232

3333
/* Information for net */
34-
#define NET_VERSION "10"
34+
#define NET_VERSION "11"
3535

3636
#define DRIVER_VERSION "v1." NETNEXT_VERSION "." NET_VERSION
3737
#define DRIVER_AUTHOR "Realtek linux nic maintainers <[email protected]>"
@@ -68,6 +68,7 @@
6868
#define PLA_LED_FEATURE 0xdd92
6969
#define PLA_PHYAR 0xde00
7070
#define PLA_BOOT_CTRL 0xe004
71+
#define PLA_LWAKE_CTRL_REG 0xe007
7172
#define PLA_GPHY_INTR_IMR 0xe022
7273
#define PLA_EEE_CR 0xe040
7374
#define PLA_EEEP_CR 0xe080
@@ -95,6 +96,7 @@
9596
#define PLA_TALLYCNT 0xe890
9697
#define PLA_SFF_STS_7 0xe8de
9798
#define PLA_PHYSTATUS 0xe908
99+
#define PLA_CONFIG6 0xe90a /* CONFIG6 */
98100
#define PLA_BP_BA 0xfc26
99101
#define PLA_BP_0 0xfc28
100102
#define PLA_BP_1 0xfc2a
@@ -107,6 +109,7 @@
107109
#define PLA_BP_EN 0xfc38
108110

109111
#define USB_USB2PHY 0xb41e
112+
#define USB_SSPHYLINK1 0xb426
110113
#define USB_SSPHYLINK2 0xb428
111114
#define USB_U2P3_CTRL 0xb460
112115
#define USB_CSR_DUMMY1 0xb464
@@ -300,6 +303,9 @@
300303
#define LINK_ON_WAKE_EN 0x0010
301304
#define LINK_OFF_WAKE_EN 0x0008
302305

306+
/* PLA_CONFIG6 */
307+
#define LANWAKE_CLR_EN BIT(0)
308+
303309
/* PLA_CONFIG5 */
304310
#define BWF_EN 0x0040
305311
#define MWF_EN 0x0020
@@ -312,6 +318,7 @@
312318
/* PLA_PHY_PWR */
313319
#define TX_10M_IDLE_EN 0x0080
314320
#define PFM_PWM_SWITCH 0x0040
321+
#define TEST_IO_OFF BIT(4)
315322

316323
/* PLA_MAC_PWR_CTRL */
317324
#define D3_CLK_GATED_EN 0x00004000
@@ -324,6 +331,7 @@
324331
#define MAC_CLK_SPDWN_EN BIT(15)
325332

326333
/* PLA_MAC_PWR_CTRL3 */
334+
#define PLA_MCU_SPDWN_EN BIT(14)
327335
#define PKT_AVAIL_SPDWN_EN 0x0100
328336
#define SUSPEND_SPDWN_EN 0x0004
329337
#define U1U2_SPDWN_EN 0x0002
@@ -354,6 +362,9 @@
354362
/* PLA_BOOT_CTRL */
355363
#define AUTOLOAD_DONE 0x0002
356364

365+
/* PLA_LWAKE_CTRL_REG */
366+
#define LANWAKE_PIN BIT(7)
367+
357368
/* PLA_SUSPEND_FLAG */
358369
#define LINK_CHG_EVENT BIT(0)
359370

@@ -365,13 +376,18 @@
365376
#define DEBUG_LTSSM 0x0082
366377

367378
/* PLA_EXTRA_STATUS */
379+
#define CUR_LINK_OK BIT(15)
368380
#define U3P3_CHECK_EN BIT(7) /* RTL_VER_05 only */
369381
#define LINK_CHANGE_FLAG BIT(8)
382+
#define POLL_LINK_CHG BIT(0)
370383

371384
/* USB_USB2PHY */
372385
#define USB2PHY_SUSPEND 0x0001
373386
#define USB2PHY_L1 0x0002
374387

388+
/* USB_SSPHYLINK1 */
389+
#define DELAY_PHY_PWR_CHG BIT(1)
390+
375391
/* USB_SSPHYLINK2 */
376392
#define pwd_dn_scale_mask 0x3ffe
377393
#define pwd_dn_scale(x) ((x) << 1)
@@ -2863,6 +2879,17 @@ static int rtl8153_enable(struct r8152 *tp)
28632879
r8153_set_rx_early_timeout(tp);
28642880
r8153_set_rx_early_size(tp);
28652881

2882+
if (tp->version == RTL_VER_09) {
2883+
u32 ocp_data;
2884+
2885+
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK);
2886+
ocp_data &= ~FC_PATCH_TASK;
2887+
ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
2888+
usleep_range(1000, 2000);
2889+
ocp_data |= FC_PATCH_TASK;
2890+
ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
2891+
}
2892+
28662893
return rtl_enable(tp);
28672894
}
28682895

@@ -3376,8 +3403,8 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
33763403
r8153b_ups_en(tp, false);
33773404
r8153_queue_wake(tp, false);
33783405
rtl_runtime_suspend_enable(tp, false);
3379-
r8153_u2p3en(tp, true);
3380-
r8153b_u1u2en(tp, true);
3406+
if (tp->udev->speed != USB_SPEED_HIGH)
3407+
r8153b_u1u2en(tp, true);
33813408
}
33823409
}
33833410

@@ -4675,7 +4702,6 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
46754702

46764703
r8153_aldps_en(tp, true);
46774704
r8152b_enable_fc(tp);
4678-
r8153_u2p3en(tp, true);
46794705

46804706
set_bit(PHY_RESET, &tp->flags);
46814707
}
@@ -4954,13 +4980,28 @@ static void rtl8152_down(struct r8152 *tp)
49544980

49554981
static void rtl8153_up(struct r8152 *tp)
49564982
{
4983+
u32 ocp_data;
4984+
49574985
if (test_bit(RTL8152_UNPLUG, &tp->flags))
49584986
return;
49594987

49604988
r8153_u1u2en(tp, false);
49614989
r8153_u2p3en(tp, false);
49624990
r8153_aldps_en(tp, false);
49634991
r8153_first_init(tp);
4992+
4993+
ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
4994+
ocp_data |= LANWAKE_CLR_EN;
4995+
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
4996+
4997+
ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
4998+
ocp_data &= ~LANWAKE_PIN;
4999+
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
5000+
5001+
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1);
5002+
ocp_data &= ~DELAY_PHY_PWR_CHG;
5003+
ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data);
5004+
49645005
r8153_aldps_en(tp, true);
49655006

49665007
switch (tp->version) {
@@ -4979,11 +5020,17 @@ static void rtl8153_up(struct r8152 *tp)
49795020

49805021
static void rtl8153_down(struct r8152 *tp)
49815022
{
5023+
u32 ocp_data;
5024+
49825025
if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
49835026
rtl_drop_queued_tx(tp);
49845027
return;
49855028
}
49865029

5030+
ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
5031+
ocp_data &= ~LANWAKE_CLR_EN;
5032+
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
5033+
49875034
r8153_u1u2en(tp, false);
49885035
r8153_u2p3en(tp, false);
49895036
r8153_power_cut_en(tp, false);
@@ -4994,6 +5041,8 @@ static void rtl8153_down(struct r8152 *tp)
49945041

49955042
static void rtl8153b_up(struct r8152 *tp)
49965043
{
5044+
u32 ocp_data;
5045+
49975046
if (test_bit(RTL8152_UNPLUG, &tp->flags))
49985047
return;
49995048

@@ -5004,18 +5053,29 @@ static void rtl8153b_up(struct r8152 *tp)
50045053
r8153_first_init(tp);
50055054
ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
50065055

5056+
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
5057+
ocp_data &= ~PLA_MCU_SPDWN_EN;
5058+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
5059+
50075060
r8153_aldps_en(tp, true);
5008-
r8153_u2p3en(tp, true);
5009-
r8153b_u1u2en(tp, true);
5061+
5062+
if (tp->udev->speed != USB_SPEED_HIGH)
5063+
r8153b_u1u2en(tp, true);
50105064
}
50115065

50125066
static void rtl8153b_down(struct r8152 *tp)
50135067
{
5068+
u32 ocp_data;
5069+
50145070
if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
50155071
rtl_drop_queued_tx(tp);
50165072
return;
50175073
}
50185074

5075+
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
5076+
ocp_data |= PLA_MCU_SPDWN_EN;
5077+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
5078+
50195079
r8153b_u1u2en(tp, false);
50205080
r8153_u2p3en(tp, false);
50215081
r8153b_power_cut_en(tp, false);
@@ -5387,6 +5447,16 @@ static void r8153_init(struct r8152 *tp)
53875447
else
53885448
ocp_data |= DYNAMIC_BURST;
53895449
ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
5450+
5451+
r8153_queue_wake(tp, false);
5452+
5453+
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
5454+
if (rtl8152_get_speed(tp) & LINK_STATUS)
5455+
ocp_data |= CUR_LINK_OK;
5456+
else
5457+
ocp_data &= ~CUR_LINK_OK;
5458+
ocp_data |= POLL_LINK_CHG;
5459+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
53905460
}
53915461

53925462
ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
@@ -5416,10 +5486,19 @@ static void r8153_init(struct r8152 *tp)
54165486
ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001);
54175487

54185488
r8153_power_cut_en(tp, false);
5489+
rtl_runtime_suspend_enable(tp, false);
54195490
r8153_u1u2en(tp, true);
54205491
r8153_mac_clk_spd(tp, false);
54215492
usb_enable_lpm(tp->udev);
54225493

5494+
ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
5495+
ocp_data |= LANWAKE_CLR_EN;
5496+
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
5497+
5498+
ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
5499+
ocp_data &= ~LANWAKE_PIN;
5500+
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
5501+
54235502
/* rx aggregation */
54245503
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
54255504
ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
@@ -5484,14 +5563,37 @@ static void r8153b_init(struct r8152 *tp)
54845563
r8153b_ups_en(tp, false);
54855564
r8153_queue_wake(tp, false);
54865565
rtl_runtime_suspend_enable(tp, false);
5487-
r8153b_u1u2en(tp, true);
5566+
5567+
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
5568+
if (rtl8152_get_speed(tp) & LINK_STATUS)
5569+
ocp_data |= CUR_LINK_OK;
5570+
else
5571+
ocp_data &= ~CUR_LINK_OK;
5572+
ocp_data |= POLL_LINK_CHG;
5573+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
5574+
5575+
if (tp->udev->speed != USB_SPEED_HIGH)
5576+
r8153b_u1u2en(tp, true);
54885577
usb_enable_lpm(tp->udev);
54895578

54905579
/* MAC clock speed down */
54915580
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2);
54925581
ocp_data |= MAC_CLK_SPDWN_EN;
54935582
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data);
54945583

5584+
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
5585+
ocp_data &= ~PLA_MCU_SPDWN_EN;
5586+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
5587+
5588+
if (tp->version == RTL_VER_09) {
5589+
/* Disable Test IO for 32QFN */
5590+
if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) {
5591+
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
5592+
ocp_data |= TEST_IO_OFF;
5593+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
5594+
}
5595+
}
5596+
54955597
set_bit(GREEN_ETHERNET, &tp->flags);
54965598

54975599
/* rx aggregation */
@@ -6707,6 +6809,11 @@ static int rtl8152_probe(struct usb_interface *intf,
67076809

67086810
intf->needs_remote_wakeup = 1;
67096811

6812+
if (!rtl_can_wakeup(tp))
6813+
__rtl_set_wol(tp, 0);
6814+
else
6815+
tp->saved_wolopts = __rtl_get_wol(tp);
6816+
67106817
tp->rtl_ops.init(tp);
67116818
#if IS_BUILTIN(CONFIG_USB_RTL8152)
67126819
/* Retry in case request_firmware() is not ready yet. */
@@ -6724,10 +6831,6 @@ static int rtl8152_probe(struct usb_interface *intf,
67246831
goto out1;
67256832
}
67266833

6727-
if (!rtl_can_wakeup(tp))
6728-
__rtl_set_wol(tp, 0);
6729-
6730-
tp->saved_wolopts = __rtl_get_wol(tp);
67316834
if (tp->saved_wolopts)
67326835
device_set_wakeup_enable(&udev->dev, true);
67336836
else

0 commit comments

Comments
 (0)