From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 2/2] usb: eth: add Realtek RTL8152B/RTL8153 DRIVER
Date: Thu, 14 Jan 2016 06:37:06 +0100 [thread overview]
Message-ID: <201601140637.06983.marex@denx.de> (raw)
In-Reply-To: <1452748927-60186-1-git-send-email-tedchen@realtek.com>
On Thursday, January 14, 2016 at 06:22:07 AM, Ted Chen wrote:
> This patch adds driver support for the Realtek RTL8152B/RTL8153 USB
> network adapters.
[...]
> +static void rtl8152_wait_fifo_empty(struct r8152 *tp)
> +{
> + int i;
> + u32 ocp_data;
> +
> + for (i = 0; i < FIFO_EMPTY_TIMEOUT; i++) {
> + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
> + if ((ocp_data & FIFO_EMPTY) == FIFO_EMPTY)
> + break;
> +
> + mdelay(1);
> + }
> +
> + if (i == FIFO_EMPTY_TIMEOUT)
> + debug("Timeout waiting for FIFO empty\n");
> +
> + for (i = 0; i < FIFO_EMPTY_TIMEOUT; i++) {
> + if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0) & TCR0_TX_EMPTY)
> + break;
> + mdelay(1);
You can implement something like wait_for_bit() here to avoid having multiple
copies of the same code.
> + }
> +
> + if (i == FIFO_EMPTY_TIMEOUT)
> + debug("Timeout waiting for TX empty\n");
> +}
> +
> +static void rtl8152_nic_reset(struct r8152 *tp)
> +{
> + int i;
> +
> + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, PLA_CR_RST);
> +
> + for (i = 0; i < NIC_RESET_TIMEOUT; i++) {
> + if (!(ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR) & PLA_CR_RST))
> + break;
> +
> + mdelay(1);
> + }
DTTO here.
> + if (i == NIC_RESET_TIMEOUT)
> + debug("Timeout waiting for NIC reset\n");
> +}
> +
> +static u8 rtl8152_get_speed(struct r8152 *tp)
> +{
> + return ocp_read_byte(tp, MCU_TYPE_PLA, PLA_PHYSTATUS);
> +}
[...]
> +static void r8152b_get_version(struct r8152 *tp)
> +{
> + u32 ocp_data;
> + u16 version;
> +
> + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1);
> + version = (u16)(ocp_data & VERSION_MASK);
> +
> + switch (version) {
> + case 0x4c00:
> + tp->version = RTL_VER_01;
I'd implement this as a lookup table, it might be more readable.
What do you think ?
> + break;
> + case 0x4c10:
> + tp->version = RTL_VER_02;
> + break;
> + case 0x5c00:
> + tp->version = RTL_VER_03;
> + tp->supports_gmii = 1;
> + break;
> + case 0x5c10:
> + tp->version = RTL_VER_04;
> + tp->supports_gmii = 1;
> + break;
> + case 0x5c20:
> + tp->version = RTL_VER_05;
> + tp->supports_gmii = 1;
> + break;
> + case 0x5c30:
> + tp->version = RTL_VER_06;
> + tp->supports_gmii = 1;
> + break;
> + case 0x4800:
> + tp->version = RTL_VER_07;
> + break;
> + default:
> + printf("Unknown version 0x%04x\n", version);
> + break;
> + }
> +}
> +
[...]
> +static void r8153_init(struct r8152 *tp)
> +{
> + u32 ocp_data;
> + int i;
> +
> + r8153_disable_aldps(tp);
> + r8153_u1u2en(tp, false);
> +
> + for (i = 0; i < 500; i++) {
> + if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
> + AUTOLOAD_DONE)
> + break;
> + mdelay(20);
Yet another ad-hoc wait_for_bit() implementation here.
> + }
> +
> + for (i = 0; i < 500; i++) {
> + ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
> + if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
> + break;
> + mdelay(20);
And here ...
> + }
> +
> + r8153_u2p3en(tp, false);
> +
> + if (tp->version == RTL_VER_04) {
> + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2);
> + ocp_data &= ~pwd_dn_scale_mask;
> + ocp_data |= pwd_dn_scale(96);
> + ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK2, ocp_data);
> +
> + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY);
> + ocp_data |= USB2PHY_L1 | USB2PHY_SUSPEND;
> + ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data);
> + } else if (tp->version == RTL_VER_05) {
> + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0);
> + ocp_data &= ~ECM_ALDPS;
> + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_DMY_REG0, ocp_data);
> +
> + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1);
> + if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0)
> + ocp_data &= ~DYNAMIC_BURST;
> + else
> + ocp_data |= DYNAMIC_BURST;
> + ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
> + } else if (tp->version == RTL_VER_06) {
> + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1);
> + if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0)
> + ocp_data &= ~DYNAMIC_BURST;
> + else
> + ocp_data |= DYNAMIC_BURST;
> + ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
> + }
> +
> + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
> + ocp_data |= EP4_FULL_FC;
> + ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2, ocp_data);
> +
> + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL);
> + ocp_data &= ~TIMER11_EN;
> + ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data);
> +
> + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
> + ocp_data &= ~LED_MODE_MASK;
> + ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
> +
> + ocp_data = FIFO_EMPTY_1FB | ROK_EXIT_LPM;
> + if (tp->version == RTL_VER_04 && tp->udev->speed != USB_SPEED_SUPER)
> + ocp_data |= LPM_TIMER_500MS;
> + else
> + ocp_data |= LPM_TIMER_500US;
> + ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data);
> +
> + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2);
> + ocp_data &= ~SEN_VAL_MASK;
> + ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE;
> + ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data);
> +
> + ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001);
> +
> + r8153_power_cut_en(tp, false);
> +
> + r8152b_enable_fc(tp);
> + rtl_tally_reset(tp);
> +}
> +
> +static void rtl8152_unload(struct r8152 *tp)
> +{
> + if (tp->version != RTL_VER_01)
> + r8152_power_cut_en(tp, true);
> +}
> +
> +static void rtl8153_unload(struct r8152 *tp)
> +{
> + r8153_power_cut_en(tp, false);
> +}
[...]
> diff --git a/drivers/usb/eth/r8152_fw.c b/drivers/usb/eth/r8152_fw.c
> new file mode 100644
> index 0000000..8dc8cad
> --- /dev/null
> +++ b/drivers/usb/eth/r8152_fw.c
[...]
> +static void patch4(struct r8152 *tp)
Please make this consistent and name it with r8153_ prefix. Some more
obvious name would help too, patch4 doesn't tell me anything about the
function or what it does.
> +{
> + u8 data;
> +
> + data = ocp_read_byte(tp, MCU_TYPE_USB, 0xd429);
> + data |= 0x80;
> + ocp_write_byte(tp, MCU_TYPE_USB, 0xd429, data);
> + ocp_write_word(tp, MCU_TYPE_USB, 0xc0ce, 0x0210);
> + data = ocp_read_byte(tp, MCU_TYPE_USB, 0xd429);
> + data &= ~0x80;
> + ocp_write_byte(tp, MCU_TYPE_USB, 0xd429, data);
> +}
[...]
> +static void r8153_wdt1_end(struct r8152 *tp)
> +{
This is, again, ad-hoc implementation of wait_for_bit() alike.
> + int i;
> +
> + for (i = 0; i < 104; i++) {
> + if (!(ocp_read_byte(tp, MCU_TYPE_USB, 0xe404) & 1))
> + break;
> + mdelay(2);
> + }
> +}
[...]
Thanks!
next prev parent reply other threads:[~2016-01-14 5:37 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-13 16:03 [U-Boot] [PATCH 1/2] checkpatch: ignore request to use ether_addr_copy() Stephen Warren
2015-11-13 16:03 ` [U-Boot] [PATCH 2/2] usb: eth: add Realtek RTL8152B/RTL8153 driver Stephen Warren
2015-11-14 1:13 ` Marek Vasut
2015-11-16 17:32 ` Stephen Warren
2015-11-17 7:18 ` Ted
2015-11-17 8:04 ` Marek Vasut
2015-11-19 6:07 ` Anand Moon
2015-11-19 16:51 ` Stephen Warren
2015-11-19 17:00 ` Lukasz Majewski
2015-11-19 17:00 ` Marek Vasut
2015-11-19 10:58 ` Anand Moon
2015-11-19 11:12 ` Marek Vasut
2015-11-19 12:49 ` Anand Moon
2015-11-19 13:12 ` Marek Vasut
2015-11-20 17:35 ` Simon Glass
2015-11-20 17:38 ` Marek Vasut
2015-11-21 4:10 ` Anand Moon
2015-11-22 17:12 ` Stephen Warren
2015-11-22 19:25 ` Anand Moon
2015-11-21 7:27 ` Stephen Warren
2015-11-21 16:50 ` Simon Glass
2015-11-22 17:09 ` Stephen Warren
2015-11-23 3:09 ` Simon Glass
2015-11-23 17:16 ` Stephen Warren
2015-11-25 5:30 ` [U-Boot] [PATCH v2 " Ted Chen
2015-11-25 9:09 ` Anand Moon
2015-11-26 16:58 ` Marek Vasut
2015-11-30 22:07 ` Joe Hershberger
2015-12-01 11:24 ` [U-Boot] [PATCH v3 " Ted Chen
2015-12-01 15:10 ` Marek Vasut
2015-12-01 16:31 ` Stephen Warren
2015-12-01 17:11 ` Marek Vasut
2015-12-01 16:32 ` Simon Glass
2016-01-13 18:27 ` Stephen Warren
2016-01-14 4:37 ` [U-Boot] [PATCH v4 2/2] usb: eth: add Realtek RTL8152B/RTL8153 DRIVER Ted Chen
2016-01-14 4:42 ` Marek Vasut
2016-01-14 5:22 ` Ted Chen
2016-01-14 5:37 ` Marek Vasut [this message]
2016-01-20 6:24 ` [U-Boot] [PATCH v5 " Ted Chen
2016-01-20 13:08 ` Marek Vasut
2016-01-20 16:52 ` Stephen Warren
2016-01-20 20:10 ` Anand Moon
2016-01-20 20:34 ` Marek Vasut
2016-01-21 8:55 ` Anand Moon
2016-01-21 10:12 ` Marek Vasut
2016-01-22 19:50 ` Joe Hershberger
2016-01-22 20:00 ` Marek Vasut
2016-01-22 20:41 ` Joe Hershberger
2016-01-23 0:42 ` Marek Vasut
2016-01-23 15:23 ` Marek Vasut
2016-01-23 18:55 ` Anand Moon
2016-01-23 19:38 ` Marek Vasut
2016-01-25 3:42 ` Ted
2016-01-25 3:47 ` Marek Vasut
2015-11-14 0:56 ` [U-Boot] [PATCH 1/2] checkpatch: ignore request to use ether_addr_copy() Marek Vasut
2015-11-23 23:36 ` Joe Hershberger
2015-12-15 23:34 ` Stephen Warren
2015-12-15 23:41 ` Joe Hershberger
[not found] ` <56969621.30204@wwwdotorg.org>
2016-01-20 20:47 ` Stephen Warren
2016-01-20 21:00 ` Tom Rini
2016-01-20 21:04 ` Stephen Warren
2016-01-21 1:22 ` Tom Rini
2016-01-21 4:09 ` Joe Hershberger
2016-01-25 21:28 ` [U-Boot] [U-Boot, " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201601140637.06983.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox