phy: realtek: usb2: support for RTL9607C USB2 PHY
Subsystems (2)
v7 cover phy: realtek: usb2: support for RTL9607C USB2 PHY
This patch series for Realtek USB2 PHY driver adds support for RTL9607C USB2 PHY.
RTL9607C is a big endian MIPS CPU which is quite far from RTD series SoCs supported by realtek usb2 phy driver, but the phy initilization is found to be very indentical in most areas.
Most of the code was based on the Realtek's usb driver from the GPL tarball in [1] and adjusted to fit into the realtek usb2 phy driver code format.
The patch series was split into smaller patches that add/change something in the driver that are not exactly related to RTL9607C and that also helps for easier review. That also means, patch 5 depends on all the prior patches that come before it.
USB2 PHY on RTL9607C is primarly used for its internal OHCI/EHCI controllers.
Tested on my RTL9607C based machine as a backport to 6.18 linux in OpenWrt.
[1] - https://github.com/jameywine/GPL-for-GP3000/blob/main/linux-5.10.x/arch/mips/rtl9607c/usb.c
---
Changelog in v7:
- Patch 1
- created a phy_reg_desc struct to get rid of duplicated fields across phy_cfg and phy_reg.
- added a default rtd_phy_reg_desc for all existing SoC phy configs.
- Patch 2
- moved the read/write to a newly added phy_reg_desc struct.
- Patch 3
- added an Acked-by tag from Manivannan Sadhasivam.
- Patch 4
- replaced devm_reset_control_array_get*() with devm_reset_control_get*()
- Patch 5
- added the read operation after write to FORCE_DISCONNECT_REG.
- Patch 6
- added a Reviewed-by tag from Manivannan Sadhasivam.
- Link to v6: https://lore.kernel.org/linux-phy/[email protected]/
Changelog in v6:
Driver has been refactored with enabled SWAP_IO_SPACE config in mind.
- Patch 1
- fixed one line exceeding 80 columns.
- Patch 2
- changed to use the introduced read/write functions for reg_wrap_vstatus instead of reg_gusb2phyacc0.
- Patch 3
- properly added the review tag from v4 of patch series.
- Patch 5
- fixed the lines exceeding 80 columns.
- changed msleep(10) to usleep_range(10000, 11000).
- changed the read and write functions to use ioread32be instead of __le32 now that we are using them for reg_wrap_vstatus.
- Link to v5: https://lore.kernel.org/linux-phy/[email protected]/
Changelog in v5:
Mostly addressing LLM review
- Patch 1
- changed int to u32 type for new_reg_req and vstatus_busy data fields.
- changed comments in rtk_phy_read/write from PHY_NEW_REG_REQ to phy_reg->new_reg_req.
- Patch 2
- explained readl/writel native endianess issue in more detail.
- explained why vstatus register doesn't need byte swapping.
- Patch 4
- moved reset_control_deassert to rtk_phy_init function to keep it outside of for loop.
- changed msleep(5) to usleep_range(5000, 6000).
- explained why reset_control_assert is not needed.
- Patch 5
- explained readl/writel native endianess issue here as well.
- explained why FORCE_DISCONNECT_REG doesn't need byte swapping.
- Link to v4: https://lore.kernel.org/linux-phy/[email protected]/
Changelog in v4:
- Patch 2
- moved the le variations of read/write functions to Patch 5 where it is actually used because otherwise, it results in unused errors when only Patch 2 is applied.
- updated the commit message to to point the reason for le32 wrappers around readl/writel.
- Patch 3
- added "Reviewed by Krzysztof Kozlowski"
- Patch 5
- updated the commit message to include the addition of little endian read/write functions from Patch 2.
- Link to v3: https://lore.kernel.org/linux-phy/[email protected]/
Changelog in v3:
- Patch 2
- renamed phy read and functions to "rtk_usb2phy" to not collide with networking API functions
- fixed the sparse warnings by creating intermidiate "tmp" variable and then pass it to writel
- sligtly adjusted commit message to instead use "default read" not "default phy_read"
- Patch 4
- added the check for reset_control_deassert() just in case
- changed mdelay(5) to msleep(5)
- changed dev_err and return combo with one dev_err_probe for phy_rst
- Patch 5
- changed mdelay(10) under force_host_disconnect to msleep(10)
- removed struct fields with false like force_host_disconnect and more in rtl9607_phy_cfg
- Patch 6
- updated the #endif commend to now include MACH_REALTEK_RTL to reflect if on top
- Link to v2: https://lore.kernel.org/linux-phy/[email protected]/
Changelog in v2:
- Patch 3
- removed the line about OHCI/EHCI controllers from description.
- set the resets to false for RTD SoC devices and changed the
commit message to reflect that.
- Link to v1: https://lore.kernel.org/linux-phy/[email protected]/
Rustam Adilov (6):
phy: realtek: usb2: introduce phy_reg_desc struct to the driver
phy: realtek: usb2: introduce read and write functions to phy_reg_desc
struct
dt-bindings: phy: realtek,usb2phy.yaml: extend for resets and RTL9607C
support
phy: realtek: usb2: introduce reset controller struct
phy: realtek: usb2: add support for RTL9607C USB2 PHY
phy: realtek: Make configs available for MACH_REALTEK_RTL
.../bindings/phy/realtek,usb2phy.yaml | 25 ++- drivers/phy/realtek/Kconfig | 4 +- drivers/phy/realtek/phy-rtk-usb2.c | 154 ++++++++++++++++-- 3 files changed, 165 insertions(+), 18 deletions(-)
Signature · 1 line
2.55.0
PATCH v7 1/6 phy: realtek: usb2: introduce phy_reg_desc struct to the driver
In RTL9607C SoC, there are a few differences in usb2 phy compared to existing RTD SoCs, like vstatus register is at certain offset from the base, busy bit and new_reg_req bit are at different bits of the register.
To avoid duplicating these variables across phy cfg and driver data, create a per-SoC struct that would hold them and with that add the default rtd_phy_reg_desc to which all RTD SoCs driver data will point towards.
--- drivers/phy/realtek/phy-rtk-usb2.c | 59 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/phy/realtek/phy-rtk-usb2.c +44 -15
@@ -60,10 +60,17 @@#define DEFAULT_DC_DISCONNECTION_VALUE (0x6)#define HS_CLK_SELECT BIT(6) +struct phy_reg_desc { +int vstatus_offset; +u32 vstatus_busy; +u32 new_reg_req; +}; +struct phy_reg {void __iomem *reg_wrap_vstatus;void __iomem *reg_gusb2phyacc0;int vstatus_index; +const struct phy_reg_desc *desc; };struct phy_data {
@@ -96,6 +103,7 @@ struct phy_cfg {bool do_toggle_driving;bool use_default_parameter;bool is_double_sensitivity_mode; +const struct phy_reg_desc *reg_desc; };struct phy_parameter {
@@ -156,27 +164,28 @@ static inline int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)static char rtk_phy_read (struct phy_reg *phy_reg,char addr) {void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; +const struct phy_reg_desc *reg_desc = phy_reg->desc;unsigned int val;int ret =0 ; addr -=OFFEST_PHY_READ ;/* polling until VBusy == 0 */ - ret =utmi_wait_register (reg_gusb2phyacc0,PHY_VSTS_BUSY ,0 ); + ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)return (char )ret; -/* VCtrl = low nibble of addr, and set PHY_NEW_REG_REQ */ - val =PHY_NEW_REG_REQ | (GET_LOW_NIBBLE (addr) <<PHY_VCTRL_SHIFT ); +/* VCtrl = low nibble of addr, and set reg_desc->new_reg_req */ + val = reg_desc->new_reg_req | (GET_LOW_NIBBLE (addr) <<PHY_VCTRL_SHIFT );writel (val, reg_gusb2phyacc0); - ret =utmi_wait_register (reg_gusb2phyacc0,PHY_VSTS_BUSY ,0 ); + ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)return (char )ret; -/* VCtrl = high nibble of addr, and set PHY_NEW_REG_REQ */ - val =PHY_NEW_REG_REQ | (GET_HIGH_NIBBLE (addr) <<PHY_VCTRL_SHIFT ); +/* VCtrl = high nibble of addr, and set reg_desc->new_reg_req */ + val = reg_desc->new_reg_req | (GET_HIGH_NIBBLE (addr) <<PHY_VCTRL_SHIFT );writel (val, reg_gusb2phyacc0); - ret =utmi_wait_register (reg_gusb2phyacc0,PHY_VSTS_BUSY ,0 ); + ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)return (char )ret;
@@ -190,29 +199,31 @@ static int rtk_phy_write(struct phy_reg *phy_reg, char addr, char data)unsigned int val;void __iomem *reg_wrap_vstatus = phy_reg->reg_wrap_vstatus;void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; +const struct phy_reg_desc *reg_desc = phy_reg->desc;int shift_bits = phy_reg->vstatus_index *8 ;int ret =0 ;/* write data to VStatusOut2 (data output to phy) */ -writel ((u32 )data << shift_bits, reg_wrap_vstatus); +writel ((u32 )data << shift_bits, + reg_wrap_vstatus + reg_desc->vstatus_offset); - ret =utmi_wait_register (reg_gusb2phyacc0,PHY_VSTS_BUSY ,0 ); + ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)return ret; -/* VCtrl = low nibble of addr, set PHY_NEW_REG_REQ */ - val =PHY_NEW_REG_REQ | (GET_LOW_NIBBLE (addr) <<PHY_VCTRL_SHIFT ); +/* VCtrl = low nibble of addr, set reg_desc->new_reg_req */ + val = reg_desc->new_reg_req | (GET_LOW_NIBBLE (addr) <<PHY_VCTRL_SHIFT );writel (val, reg_gusb2phyacc0); - ret =utmi_wait_register (reg_gusb2phyacc0,PHY_VSTS_BUSY ,0 ); + ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)return ret; -/* VCtrl = high nibble of addr, set PHY_NEW_REG_REQ */ - val =PHY_NEW_REG_REQ | (GET_HIGH_NIBBLE (addr) <<PHY_VCTRL_SHIFT ); +/* VCtrl = high nibble of addr, set reg_desc->new_reg_req */ + val = reg_desc->new_reg_req | (GET_HIGH_NIBBLE (addr) <<PHY_VCTRL_SHIFT );writel (val, reg_gusb2phyacc0); - ret =utmi_wait_register (reg_gusb2phyacc0,PHY_VSTS_BUSY ,0 ); + ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)return ret;
@@ -957,6 +968,7 @@ static int get_phy_data_by_efuse(struct rtk_phy *rtk_phy,static int parse_phy_data (struct rtk_phy *rtk_phy) { +struct phy_cfg *phy_cfg = rtk_phy->phy_cfg;struct device *dev = rtk_phy->dev;struct device_node *np = dev->of_node;struct phy_parameter *phy_parameter;
@@ -974,6 +986,8 @@ static int parse_phy_data(struct rtk_phy *rtk_phy) phy_parameter->phy_reg.reg_wrap_vstatus =of_iomap (np,0 ); phy_parameter->phy_reg.reg_gusb2phyacc0 =of_iomap (np,1 ) + index; phy_parameter->phy_reg.vstatus_index = index; + phy_parameter->phy_reg.desc = phy_cfg->reg_desc; +if (of_property_read_bool (np,"realtek,inverse-hstx-sync-clock" )) phy_parameter->inverse_hstx_sync_clock = true;
@@ -1060,6 +1074,12 @@ static void rtk_usb2phy_remove(struct platform_device *pdev)remove_debug_files (rtk_phy); } +static const struct phy_reg_desc rtd_phy_reg_desc = { + .vstatus_offset =0 , + .vstatus_busy =PHY_VSTS_BUSY , + .new_reg_req =PHY_NEW_REG_REQ , +}; +static const struct phy_cfg rtd1295_phy_cfg = { .page0_size =MAX_USB_PHY_PAGE0_DATA_SIZE , .page0 = { [0 ] = {0xe0 ,0x90 },
@@ -1085,6 +1105,7 @@ static const struct phy_cfg rtd1295_phy_cfg = { .driving_updated_for_dev_dis = 0xf, .use_default_parameter = false, .is_double_sensitivity_mode = false, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1395_phy_cfg = {
@@ -1109,6 +1130,7 @@ static const struct phy_cfg rtd1395_phy_cfg = { .driving_updated_for_dev_dis = 0xf, .use_default_parameter = false, .is_double_sensitivity_mode = false, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1395_phy_cfg_2port = {
@@ -1133,6 +1155,7 @@ static const struct phy_cfg rtd1395_phy_cfg_2port = { .driving_updated_for_dev_dis = 0xf, .use_default_parameter = false, .is_double_sensitivity_mode = false, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1619_phy_cfg = {
@@ -1155,6 +1178,7 @@ static const struct phy_cfg rtd1619_phy_cfg = { .driving_updated_for_dev_dis = 0xf, .use_default_parameter = false, .is_double_sensitivity_mode = false, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1319_phy_cfg = {
@@ -1181,6 +1205,7 @@ static const struct phy_cfg rtd1319_phy_cfg = { .driving_updated_for_dev_dis = 0xf, .use_default_parameter = false, .is_double_sensitivity_mode = true, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1312c_phy_cfg = {
@@ -1206,6 +1231,7 @@ static const struct phy_cfg rtd1312c_phy_cfg = { .driving_updated_for_dev_dis = 0xf, .use_default_parameter = false, .is_double_sensitivity_mode = true, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1619b_phy_cfg = {
@@ -1231,6 +1257,7 @@ static const struct phy_cfg rtd1619b_phy_cfg = { .driving_updated_for_dev_dis = 0x8, .use_default_parameter = false, .is_double_sensitivity_mode = true, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1319d_phy_cfg = {
@@ -1256,6 +1283,7 @@ static const struct phy_cfg rtd1319d_phy_cfg = { .driving_updated_for_dev_dis = 0x8, .use_default_parameter = false, .is_double_sensitivity_mode = true, + .reg_desc = &rtd_phy_reg_desc, };static const struct phy_cfg rtd1315e_phy_cfg = {
@@ -1282,6 +1310,7 @@ static const struct phy_cfg rtd1315e_phy_cfg = { .driving_updated_for_dev_dis = 0x8, .use_default_parameter = false, .is_double_sensitivity_mode = true, + .reg_desc = &rtd_phy_reg_desc, };static const struct of_device_id usbphy_rtk_dt_match[] = {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v7 1/6] phy: realtek: usb2: introduce phy_reg_desc struct to the driver
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Repeated of_iomap() calls inside a loop redundantly map hardware registers without corresponding iounmap() calls, causing permanent memory leaks.
- [High] Incorrect pointer arithmetic on void __iomem * creates unaligned I/O pointers for subsequent PHYs, leading to unaligned 32-bit accesses.
- [High] The return values of of_iomap() are not checked for NULL, leading to potential NULL pointer dereferences during MMIO operations.
- [High] rtk_phy_write() overwrites the entire shared VStatusOut2 register, clobbering the configuration of other PHY ports.
- [High] The driver accumulates per-port PHY calibration values into a single shared phy_cfg structure, causing all ports to be initialized with corrupted data. --
--- Patch [1]: [PATCH v7 1/6] phy: realtek: usb2: introduce phy_reg_desc struct to the driver --- commit 9a2c62ecf6aef3b339ebeb8b5606b980417dd955
Author: Rustam Adilov <[email protected]>
phy: realtek: usb2: introduce phy_reg_desc struct to the driver
This commit creates a per-SoC phy_reg_desc struct to hold register offsets and bits that vary across different SoCs. It adds a default rtd_phy_reg_desc and updates the driver data to point towards it.
Quoted 4 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c static int rtk_phy_write(struct phy_reg *phy_reg, char addr, char data) · line 208
Quoted 12 lines
drivers/phy/realtek/phy-rtk-usb2.c +3
-1@@ -190,29 +199,31 @@ static int rtk_phy_write(struct phy_reg *phy_reg, char addr, char data)unsigned int val;void __iomem *reg_wrap_vstatus = phy_reg->reg_wrap_vstatus;void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; +const struct phy_reg_desc *reg_desc = phy_reg->desc;int shift_bits = phy_reg->vstatus_index *8 ;int ret =0 ;/* write data to VStatusOut2 (data output to phy) */ -writel ((u32 )data << shift_bits, reg_wrap_vstatus); +writel ((u32 )data << shift_bits, + reg_wrap_vstatus + reg_desc->vstatus_offset);
[Severity: High]
This is a pre-existing issue, but does this unconditional 32-bit writel() clobber the shared register's other byte lanes without a read-modify-write?
In multi-port setups, all ports map the exact same physical reg_wrap_vstatus register. When configuring port 1 (where shift_bits = 8), writing (u32)data << shift_bits will correctly position port 1's byte, but write zeroes to all other bytes, entirely erasing the configuration just applied to port 0.
[Severity: High]
This isn't a bug introduced by this patch, but is it possible for reg_wrap_vstatus to be NULL here?
The pointer is acquired via of_iomap() in parse_phy_data(), which doesn't appear to be checked for NULL before being dereferenced in this writel().
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c static int parse_phy_data(struct rtk_phy *rtk_phy) · line 987
Quoted 3 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0@@ -974,6 +986,8 @@ static int parse_phy_data(struct rtk_phy *rtk_phy) phy_parameter->phy_reg.reg_wrap_vstatus =of_iomap (np,0 ); phy_parameter->phy_reg.reg_gusb2phyacc0 =of_iomap (np,1 ) + index;
[Severity: High]
This is a pre-existing issue, but do these redundant of_iomap() calls create a memory leak?
They occur inside the loop iterating over num_phy, repeatedly mapping the same physical region without storing all mapped pointers or unmapping them.
[Severity: High]
This isn't a bug introduced by this patch, but does the pointer arithmetic on of_iomap(np, 1) + index create unaligned I/O pointers for subsequent PHYs?
The return type of of_iomap() is void __iomem *. By GCC extension, adding index advances the pointer by index bytes. For num_phy > 1, index becomes 1 or higher, creating a misaligned pointer. Subsequent calls to readl() or writel() on this pointer will perform 32-bit accesses misaligned by 1 byte.
[Severity: High]
This isn't a bug introduced by this patch, but does the driver accumulate per-port PHY calibration values into a single shared phy_cfg structure?
In parse_phy_data(), it iterates over all ports and calls update_dc_driving_level(), which modifies phy_cfg->page0[4].data:
drivers/phy/realtek/phy-rtk-usb2.c:update_dc_driving_level() {
...
phy_cfg->page0[4].data = __update_dc_driving_page0_0xe4(phy_cfg,
phy_parameter,
phy_cfg->page0[4].data);
...
}Because phy_cfg is shared globally for the entire driver instance, it seems the calibration math meant for port 1 is added cumulatively on top of the results of port 0. Later, do_rtk_phy_init() pushes this heavily corrupted array to all ports.
Quoted 5 lines
drivers/phy/realtek/phy-rtk-usb2.c +2
-0phy_parameter->phy_reg.vstatus_index = index; + phy_parameter->phy_reg.desc = phy_cfg->reg_desc; +if (of_property_read_bool (np,"realtek,inverse-hstx-sync-clock" ))
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c static void rtk_usb2phy_remove(struct platform_device *pdev) · line 1075
Quoted 3 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0@@ -1060,6 +1074,12 @@ static void rtk_usb2phy_remove(struct platform_device *pdev)remove_debug_files (rtk_phy); }
[Severity: High]
This is a pre-existing issue, but does rtk_usb2phy_remove() fail to call iounmap() to clean up the mappings created by of_iomap() during probe?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v7 2/6 phy: realtek: usb2: introduce read and write functions to phy_reg_desc struct
In reply to Rustam AdilovRTL9607C is a big endian SoC with little endian USB host controller but vstatus register is from big endian memory region and thus existing writel doesn't work. It needs either __raw_writel or iowrite32be instead.
To handle this situation, introduce read and write function to the phy_reg_desc struct and add a default variation that is going to be ponted by the existing rtd_phy_reg_desc.
--- drivers/phy/realtek/phy-rtk-usb2.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/phy/realtek/phy-rtk-usb2.c +16 -3
@@ -64,6 +64,8 @@ struct phy_reg_desc {int vstatus_offset;u32 vstatus_busy;u32 new_reg_req; +u32 (*read)(void__iomem *reg); +void (*write)(u32 val,void __iomem *reg); };struct phy_reg {
@@ -130,6 +132,16 @@ struct rtk_phy {struct dentry *debug_dir; }; +static u32 rtk_usb2phy_read (void __iomem *reg) +{ +return readl (reg); +} + +static void rtk_usb2phy_write (u32 val,void __iomem *reg) +{ +writel (val, reg); +} +/* mapping 0xE0 to 0 ... 0xE7 to 7, 0xF0 to 8 ,,, 0xF7 to 15 */ static inline int page_addr_to_array_index (u8 addr) {
@@ -204,8 +216,8 @@ static int rtk_phy_write(struct phy_reg *phy_reg, char addr, char data)int ret =0 ;/* write data to VStatusOut2 (data output to phy) */ -writel ((u32 )data << shift_bits, - reg_wrap_vstatus + reg_desc->vstatus_offset); + reg_desc->write ((u32 )data << shift_bits, + reg_wrap_vstatus + reg_desc->vstatus_offset); ret =utmi_wait_register (reg_gusb2phyacc0, reg_desc->vstatus_busy,0 );if (ret)
@@ -988,7 +1000,6 @@ static int parse_phy_data(struct rtk_phy *rtk_phy) phy_parameter->phy_reg.vstatus_index = index; phy_parameter->phy_reg.desc = phy_cfg->reg_desc; -if (of_property_read_bool (np,"realtek,inverse-hstx-sync-clock" )) phy_parameter->inverse_hstx_sync_clock = true;else
@@ -1078,6 +1089,8 @@ static const struct phy_reg_desc rtd_phy_reg_desc = { .vstatus_offset = 0, .vstatus_busy = PHY_VSTS_BUSY, .new_reg_req = PHY_NEW_REG_REQ, + .read = rtk_usb2phy_read, + .write = rtk_usb2phy_write, };static const struct phy_cfg rtd1295_phy_cfg = {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v7 2/6] phy: realtek: usb2: introduce read and write functions to phy_reg_desc struct
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] The .read callback in struct phy_reg_desc and its default implementation rtk_usb2phy_read() are introduced but never used.
Pre-existing issues:
- [High] Unaligned MMIO access due to incorrect pointer arithmetic on void __iomem * when mapping multiple PHYs. --
--- Patch [2]: [PATCH v7 2/6] phy: realtek: usb2: introduce read and write functions to phy_reg_desc struct --- commit 8dc103211b6a1af9aae2648b712feaff2df2fd7f
Author: Rustam Adilov <[email protected]>
phy: realtek: usb2: introduce read and write functions to phy_reg_desc struct
This commit introduces read and write function pointers to the phy_reg_desc struct to support platforms where the vstatus register resides in a big-endian memory region. It also provides default implementations for existing PHYs.
drivers/phy/realtek/phy-rtk-usb2.c struct rtk_phy { · line 139
Quoted 13 lines
drivers/phy/realtek/phy-rtk-usb2.c +5
-0@@ -130,6 +132,16 @@ struct rtk_phy {struct dentry *debug_dir; }; +static u32 rtk_usb2phy_read (void __iomem *reg) +{ +return readl (reg); +} +
[Severity: Low]
Does this driver actually use the new read callback?
The vstatus register mentioned in the commit message is write-only in this driver, and all existing reads appear to continue using readl() directly. Is this read function needed, or is it dead code?
Quoted 5 lines
drivers/phy/realtek/phy-rtk-usb2.c +5
-0+static void rtk_usb2phy_write (u32 val,void __iomem *reg) +{ +writel (val, reg); +} +
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c static int parse_phy_data(struct rtk_phy *rtk_phy) · line 1002
Quoted 4 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0@@ -988,7 +1000,6 @@ static int parse_phy_data(struct rtk_phy *rtk_phy) phy_parameter->phy_reg.vstatus_index = index; phy_parameter->phy_reg.desc = phy_cfg->reg_desc;
[Severity: High]
This is a pre-existing issue, but does this pointer arithmetic cause unaligned MMIO accesses when configuring multiple PHYs?
In parse_phy_data():
phy_parameter->phy_reg.reg_gusb2phyacc0 = of_iomap(np, 1) + index;
When num_phy > 1, the loop increments index. Since of_iomap() returns a void __iomem *, adding index directly increments the address by exactly index bytes rather than the register stride. Could this cause an alignment fault during device probe on systems with multi-port PHY configurations?
Quoted 4 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-1-if (of_property_read_bool (np,"realtek,inverse-hstx-sync-clock" )) phy_parameter->inverse_hstx_sync_clock = true;else
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v7 3/6 dt-bindings: phy: realtek,usb2phy.yaml: extend for resets and RTL9607C support
In reply to Rustam AdilovAdd the "realtek,rtl9607-usb2phy" compatible for USB2 PHY on the RTL9607C SoC series.
Add a resets property to properties to describe the usb2phy reset line.
In RTL9607C, USB2 PHY reset line is from "IP Enable controller" which is multipurpose and handle activating various SoC peripherals.
It is unclear whether RTD SoCs have something similar to that so set the resets to false for these devices.
RTL9607C requires the "resets" to be specified so add the corresponding if check for the "realtek,rtl9607-usb2phy" compatible.
--- .../bindings/phy/realtek,usb2phy.yaml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/phy/realtek,usb2phy.yaml +24 -1
@@ -11,7 +11,8 @@ maintainers: - Stanley Chang <[email protected]> description: | - Realtek USB 2.0 PHY support the digital home center (DHC) RTD series SoCs. + Realtek USB 2.0 PHY support the digital home center (DHC) RTD and + RTL9607C series SoCs. The USB 2.0 PHY driver is designed to support the XHCI controller. The SoCs support multiple XHCI controllers. One PHY device node maps to one XHCI controller.
@@ -57,6 +58,12 @@ description: | XHCI controller#1 -- usb2phy -- phy#0 XHCI controller#2 -- usb2phy -- phy#0 + RTL9607C SoCs USB + The USB architecture includes OHCI and EHCI controllers. + Both of them map to one USB2.0 PHY. + OHCI controller#0 -- usb2phy -- phy#0 + EHCI controller#0 -- usb2phy -- phy#0 + properties: compatible: enum:
@@ -69,6 +76,7 @@ properties: - realtek,rtd1395-usb2phy-2port - realtek,rtd1619-usb2phy - realtek,rtd1619b-usb2phy + - realtek,rtl9607-usb2phy reg: items:
@@ -130,6 +138,9 @@ properties: minimum: -8 maximum: 8 + resets: + maxItems: 1 + required: - compatible - reg
@@ -157,6 +168,18 @@ allOf: then: properties: realtek,driving-level-compensate: false + - if: + properties: + compatible: + contains: + enum: + - realtek,rtl9607-usb2phy + then: + required: + - resets + else: + properties: + resets: false additionalProperties: false
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v7 3/6] dt-bindings: phy: realtek,usb2phy.yaml: extend for resets and RTL9607C support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Unused `read` function pointer in `struct phy_reg_desc`. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Unused read function pointer in struct phy_reg_desc.
--
--- Patch [3]: [PATCH v7 3/6] dt-bindings: phy: realtek,usb2phy.yaml: extend for resets and RTL9607C support --- commit 16f65d15255be7042c02dfe746526c8bd6b0efc9
Author: Rustam Adilov <[email protected]>
dt-bindings: phy: realtek,usb2phy.yaml: extend for resets and RTL9607C support
This commit adds the realtek,rtl9607-usb2phy compatible for the USB2 PHY on the RTL9607C SoC series. It also introduces a resets property to describe the multipurpose USB2 PHY reset line, making it required for the RTL9607C SoC while explicitly disabling it for other RTD devices.
drivers/phy/realtek/phy-rtk-usb2.c struct phy_reg_desc { · line 67
Quoted 9 lines
drivers/phy/realtek/phy-rtk-usb2.c +1
-0@@ -64,6 +64,8 @@ struct phy_reg_desc {int vstatus_offset;u32 vstatus_busy;u32 new_reg_req; +u32 (*read)(void__iomem *reg);
[Severity: Low]
Is this read function pointer ever consumed?
It appears to be added to the descriptor struct but is never called anywhere in the driver.
Quoted 2 lines
drivers/phy/realtek/phy-rtk-usb2.c +1
-0+void (*write)(u32 val,void __iomem *reg); };
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c struct rtk_phy { · line 138
Quoted 8 lines
drivers/phy/realtek/phy-rtk-usb2.c +4
-0@@ -130,6 +132,16 @@ struct rtk_phy {struct dentry *debug_dir; }; +static u32 rtk_usb2phy_read (void __iomem *reg) +{ +return readl (reg); +}
[Severity: Low]
Is it necessary to implement this default read function?
Since the read function pointer in struct phy_reg_desc is unused, this implementation might be dead code.
Quoted 5 lines
drivers/phy/realtek/phy-rtk-usb2.c +5
-0+ +static void rtk_usb2phy_write (u32 val,void __iomem *reg) +{ +writel (val, reg); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v7 4/6 phy: realtek: usb2: introduce reset controller struct
In reply to Rustam AdilovIn RTL9607C, there is so called "IP Enable Controller" which resemble reset controller with reset lines and is used for various things like USB, PCIE, GMAC and such.
Introduce the reset_control struct to this driver to handle deasserting usb2 phy reset line.
Make use of the function devm_reset_control_get_optional_exclusive() function to get the reset controller and since existing RTD SoCs don't specify the resets we can have a cleaner code.
Since the vendor usb driver developed by Realtek doesn't assert the reset line (or in their case clear the register bit), we can reasonably assume reset_control_assert is not needed here.
--- drivers/phy/realtek/phy-rtk-usb2.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/phy/realtek/phy-rtk-usb2.c +16 -0
@@ -17,6 +17,7 @@#include <linux/sys_soc.h> #include <linux/mfd/syscon.h> #include <linux/phy/phy.h> +#include <linux/reset.h> #include <linux/usb.h> /* GUSB2PHYACCn register */
@@ -128,6 +129,7 @@ struct rtk_phy {struct phy_cfg *phy_cfg;int num_phy;struct phy_parameter *phy_parameter; +struct reset_control *phy_rst;struct dentry *debug_dir; };
@@ -676,6 +678,15 @@ static int rtk_phy_init(struct phy *phy)if (!rtk_phy)return -EINVAL ; +if (rtk_phy->phy_rst) { + ret =reset_control_deassert (rtk_phy->phy_rst); + +if (ret) +return ret; + +usleep_range (5000 ,6000 ); + } +for (i =0 ; i < rtk_phy->num_phy; i++) ret =do_rtk_phy_init (rtk_phy, i);
@@ -1055,6 +1066,11 @@ static int rtk_usb2phy_probe(struct platform_device *pdev) rtk_phy->num_phy = phy_cfg->num_phy; + rtk_phy->phy_rst =devm_reset_control_get_optional_exclusive (dev,NULL ); +if (IS_ERR (rtk_phy->phy_rst)) +return dev_err_probe (dev,PTR_ERR (rtk_phy->phy_rst), +"usb2 phy reset is not working\n" ); + ret =parse_phy_data (rtk_phy);if (ret) goto err;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v7 4/6] phy: realtek: usb2: introduce reset controller struct
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The newly introduced PHY reset is deasserted too late (in `rtk_phy_init()`), causing fatal MMIO…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The newly introduced PHY reset is deasserted too late (in rtk_phy_init()), causing fatal MMIO register accesses during probe() if the static configuration omits explicit initializers. --
--- Patch [4]: [PATCH v7 4/6] phy: realtek: usb2: introduce reset controller struct --- commit f14473a9b55e70977d451ec39af7f337818751bd
Author: Rustam Adilov <[email protected]>
phy: realtek: usb2: introduce reset controller struct
This commit introduces a reset_control struct to the driver to handle deasserting the usb2 phy reset line using devm_reset_control_get_optional_exclusive().
Quoted 4 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0
[ ... ]
Quoted 13 lines
drivers/phy/realtek/phy-rtk-usb2.c +9
-0@@ -676,6 +678,15 @@ static int rtk_phy_init(struct phy *phy)if (!rtk_phy)return -EINVAL ; +if (rtk_phy->phy_rst) { + ret =reset_control_deassert (rtk_phy->phy_rst); + +if (ret) +return ret; + +usleep_range (5000 ,6000 ); + } +
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c static int rtk_usb2phy_probe(struct platform_device *pdev) · line 1074
Quoted 10 lines
drivers/phy/realtek/phy-rtk-usb2.c +5
-0@@ -1055,6 +1066,11 @@ static int rtk_usb2phy_probe(struct platform_device *pdev) rtk_phy->num_phy = phy_cfg->num_phy; + rtk_phy->phy_rst =devm_reset_control_get_optional_exclusive (dev,NULL ); +if (IS_ERR (rtk_phy->phy_rst)) +return dev_err_probe (dev,PTR_ERR (rtk_phy->phy_rst), +"usb2 phy reset is not working\n" ); + ret =parse_phy_data (rtk_phy);
[Severity: High]
Can this cause a bus hang or read timeout during probe()?
Since the newly introduced reset is only deasserted later when consumers call rtk_phy_init(), the IP is still held in reset here.
However, parse_phy_data() can perform direct MMIO reads against the PHY to cache default values if the static configuration lacks explicit initializers:
drivers/phy/realtek/phy-rtk-usb2.c:update_dc_driving_level() {
...
if (!phy_cfg->page0[4].addr) {
rtk_phy_set_page(phy_reg, 0);
phy_cfg->page0[4].addr = PAGE0_0XE4;
phy_cfg->page0[4].data = rtk_phy_read(phy_reg, PAGE0_0XE4);
}
...
}Will this cause issues when interacting with the PHY registers while the device is still in reset?
Quoted 2 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0if (ret) goto err;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v7 5/6 phy: realtek: usb2: add support for RTL9607C USB2 PHY
In reply to Rustam AdilovAdd support for the usb2 phy of RTL9607C series based SoCs. Add the macros and phy config struct for rtl9607.
RTL9607C requires to clear a "force host disconnect" bit in the specific register (which is at an offset from reg_wrap_vstatus) before proceeding with phy parameter writes. Since it belongs into the vstatus register region, it requires the use of added read and write helper functions.
Add the bool variable to the driver data struct and hide this whole procedure under the if statement that checks this new variable.
Add the appropriate big endian read and write functions for rtl9607 and assign them to its rtl9607_phy_reg_desc struct.
--- drivers/phy/realtek/phy-rtk-usb2.c | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
drivers/phy/realtek/phy-rtk-usb2.c +66 -0
@@ -26,6 +26,12 @@#define PHY_VCTRL_SHIFT 8#define PHY_REG_DATA_MASK 0xff +#define PHY_9607_VSTS_BUSY BIT(17) +#define PHY_9607_NEW_REG_REQ BIT(13) + +#define PHY_9607_FORCE_DISCONNECT_REG 0x10 +#define PHY_9607_FORCE_DISCONNECT_BIT BIT(5) +#define GET_LOW_NIBBLE (addr) ((addr) & 0x0f)#define GET_HIGH_NIBBLE (addr) (((addr) & 0xf0) >> 4)
@@ -107,6 +113,7 @@ struct phy_cfg {bool use_default_parameter;bool is_double_sensitivity_mode;const struct phy_reg_desc *reg_desc; +bool force_host_disconnect; };struct phy_parameter {
@@ -144,6 +151,16 @@ static void rtk_usb2phy_write(u32 val, void __iomem *reg)writel (val, reg); } +static u32 rtk_usb2phy_read_be (void __iomem *reg) +{ +return ioread32be (reg); +} + +static void rtk_usb2phy_write_be (u32 val,void __iomem *reg) +{ +iowrite32be (val, reg); +} +/* mapping 0xE0 to 0 ... 0xE7 to 7, 0xF0 to 8 ,,, 0xF7 to 15 */ static inline int page_addr_to_array_index (u8 addr) {
@@ -600,6 +617,23 @@ static int do_rtk_phy_init(struct rtk_phy *rtk_phy, int index) goto do_toggle; } +if (phy_cfg->force_host_disconnect) { +const struct phy_reg_desc *reg_desc = phy_reg->desc; +void __iomem *vstatus = phy_reg->reg_wrap_vstatus; +u32 temp; + + temp = reg_desc->read (vstatus +PHY_9607_FORCE_DISCONNECT_REG ); + +/* disable force-host-disconnect */ + temp &= ~PHY_9607_FORCE_DISCONNECT_BIT ; + + reg_desc->write (temp, vstatus +PHY_9607_FORCE_DISCONNECT_REG ); + temp = reg_desc->read (vstatus +PHY_9607_FORCE_DISCONNECT_REG ); + +/* allow IP to startup */ +usleep_range (10000 ,11000 ); + } +/* Set page 0 */ phy_data_page = phy_cfg->page0;rtk_phy_set_page (phy_reg,0 );
@@ -1109,6 +1143,14 @@ static const struct phy_reg_desc rtd_phy_reg_desc = { .write = rtk_usb2phy_write, }; +static const struct phy_reg_desc rtl9607_phy_reg_desc = { + .vstatus_offset =0xc , + .vstatus_busy =PHY_9607_VSTS_BUSY , + .new_reg_req =PHY_9607_NEW_REG_REQ , + .read = rtk_usb2phy_read_be, + .write = rtk_usb2phy_write_be, +}; +static const struct phy_cfg rtd1295_phy_cfg = { .page0_size =MAX_USB_PHY_PAGE0_DATA_SIZE , .page0 = { [0 ] = {0xe0 ,0x90 },
@@ -1342,6 +1384,29 @@ static const struct phy_cfg rtd1315e_phy_cfg = { .reg_desc = &rtd_phy_reg_desc, }; +static const struct phy_cfg rtl9607_phy_cfg = { + .page0_size =MAX_USB_PHY_PAGE0_DATA_SIZE , + .page0 = { [0 ] = {0xe0 ,0x95 }, + [4 ] = {0xe4 ,0x6a }, + [12 ] = {0xf3 ,0x31 }, }, + .page1_size =MAX_USB_PHY_PAGE1_DATA_SIZE , + .page1 = { [0 ] = {0xe0 ,0x26 }, }, + .page2_size =MAX_USB_PHY_PAGE2_DATA_SIZE , + .page2 = { [7 ] = {0xe7 ,0x33 }, }, + .num_phy =1 , + .check_efuse_version =CHECK_EFUSE_V2 , + .efuse_dc_driving_rate =EFUS_USB_DC_CAL_RATE , + .dc_driving_mask =0x1f , + .efuse_dc_disconnect_rate =EFUS_USB_DC_DIS_RATE , + .dc_disconnect_mask =0xf , + .usb_dc_disconnect_at_page0 = true, + .do_toggle = true, + .driving_updated_for_dev_dis =0x8 , + .is_double_sensitivity_mode = true, + .reg_desc = &rtl9607_phy_reg_desc, + .force_host_disconnect = true, +}; +static const struct of_device_id usbphy_rtk_dt_match[] = { { .compatible ="realtek,rtd1295-usb2phy" , .data = &rtd1295_phy_cfg }, { .compatible ="realtek,rtd1312c-usb2phy" , .data = &rtd1312c_phy_cfg },
@@ -1352,6 +1417,7 @@ static const struct of_device_id usbphy_rtk_dt_match[] = { { .compatible = "realtek,rtd1395-usb2phy-2port", .data = &rtd1395_phy_cfg_2port }, { .compatible = "realtek,rtd1619-usb2phy", .data = &rtd1619_phy_cfg }, { .compatible = "realtek,rtd1619b-usb2phy", .data = &rtd1619b_phy_cfg }, + { .compatible = "realtek,rtl9607-usb2phy", .data = &rtl9607_phy_cfg }, {}, };MODULE_DEVICE_TABLE (of, usbphy_rtk_dt_match);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v7 5/6] phy: realtek: usb2: add support for RTL9607C USB2 PHY
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
New issues:
- [Medium] The rtl9607_phy_cfg structure omits the .check_efuse flag, causing eFuse parameters to be ignored.
- [Medium] The page0 register configuration stores address 0xf3 at the wrong index, corrupting debugfs output.
Pre-existing issues:
- [High] Unchecked return value from of_iomap() leads to a NULL pointer dereference.
- [High] Pointer arithmetic on void __iomem * causes unaligned device register accesses.
- [High] Signed char integer promotion corrupts register writes on architectures with signed chars (e.g., MIPS).
- [High] Silent failure when do_rtk_phy_init() fails for multi-port SoCs.
--
--- Patch [5]: [PATCH v7 5/6] phy: realtek: usb2: add support for RTL9607C USB2 PHY --- commit 6a5b4e2235314d4730ccd147be12148b19afc984
Author: Rustam Adilov <[email protected]>
phy: realtek: usb2: add support for RTL9607C USB2 PHY
Add support for the usb2 phy of RTL9607C series based SoCs. Add the macros and phy config struct for rtl9607.
Quoted 4 lines
drivers/phy/realtek/phy-rtk-usb2.c +0
-0
[ ... ]
drivers/phy/realtek/phy-rtk-usb2.c static const struct phy_cfg rtd1315e_phy_cfg = { · line 1389
Quoted 7 lines
drivers/phy/realtek/phy-rtk-usb2.c +3
-0@@ -1342,6 +1384,29 @@ static const struct phy_cfg rtd1315e_phy_cfg = { .reg_desc = &rtd_phy_reg_desc, }; +static const struct phy_cfg rtl9607_phy_cfg = { + .page0_size =MAX_USB_PHY_PAGE0_DATA_SIZE , + .page0 = { [0 ] = {0xe0 ,0x95 },
[Severity: High]
This is a pre-existing issue, but does writing 0x95 here corrupt the register on architectures like MIPS?
rtk_phy_write() takes data as a signed char:
drivers/phy/realtek/phy-rtk-usb2.c:rtk_phy_write() {
...
reg_desc->write((u32)data << shift_bits,
...
}
On architectures where char is signed by default, a value of 0x95 is interpreted as a negative number (-107). When cast to u32, it undergoes sign extension to 0xFFFFFF95, and after shifting, it can clobber the upper bits of the shared reg_wrap_vstatus register.
drivers/phy/realtek/phy-rtk-usb2.c static const struct phy_cfg rtd1315e_phy_cfg = { · line 1391
Quoted 2 lines
drivers/phy/realtek/phy-rtk-usb2.c +2
-0+ [4] = {0xe4, 0x6a}, + [12] = {0xf3, 0x31}, },
[Severity: Medium]
Will this map to the correct debugfs output?
Address 0xf3 mathematically maps to array index 11 via the strict mapping formula in page_addr_to_array_index(). Because it is placed at index 12 here, when rtk_usb2_parameter_show() computes the target read address dynamically, it will read from 0xf4 and display it alongside the expected 0xf3 data.
drivers/phy/realtek/phy-rtk-usb2.c static const struct phy_cfg rtd1315e_phy_cfg = { · line 1397
Quoted 6 lines
drivers/phy/realtek/phy-rtk-usb2.c +6
-0+ .page1_size = MAX_USB_PHY_PAGE1_DATA_SIZE, + .page1 = { [0] = {0xe0, 0x26}, }, + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, + .page2 = { [7] = {0xe7, 0x33}, }, + .num_phy = 1, + .check_efuse_version = CHECK_EFUSE_V2,
[Severity: Medium]
Is the .check_efuse flag missing here?
Without .check_efuse = true, the eFuse parameters like check_efuse_version and efuse_dc_driving_rate specified in this structure appear to be ignored by get_phy_data_by_efuse(), leaving the hardware uncalibrated.
drivers/phy/realtek/phy-rtk-usb2.c static const struct phy_cfg rtd1315e_phy_cfg = { · line 1409
Quoted 12 lines
drivers/phy/realtek/phy-rtk-usb2.c +12
-0+ .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, + .dc_driving_mask = 0x1f, + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, + .dc_disconnect_mask = 0xf, + .usb_dc_disconnect_at_page0 = true, + .do_toggle = true, + .driving_updated_for_dev_dis = 0x8, + .is_double_sensitivity_mode = true, + .reg_desc = &rtl9607_phy_reg_desc, + .force_host_disconnect = true, +}; +
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but looking at the existing parse_phy_data() function:
drivers/phy/realtek/phy-rtk-usb2.c:parse_phy_data() {
...
phy_parameter->phy_reg.reg_wrap_vstatus = of_iomap(np, 0);
...
}
Does this code dereference a NULL pointer during device probe if the device tree lacks the required reg properties?
The return values from of_iomap() are assigned and subsequently dereferenced without any validation.
[Severity: High]
This is a pre-existing issue, but does adding index to the of_iomap() result cause unaligned device register accesses?
Looking at the existing parse_phy_data() function:
drivers/phy/realtek/phy-rtk-usb2.c:parse_phy_data() {
...
phy_parameter->phy_reg.reg_gusb2phyacc0 = of_iomap(np, 1) + index;
...
}
Since of_iomap() returns void __iomem *, GCC treats the pointer arithmetic as 1-byte elements. For multi-port PHYs where index > 0, this adds exactly 1 byte to the base address, which will trigger alignment exceptions during subsequent 32-bit writel() calls on architectures like ARM64.
[Severity: High]
This is a pre-existing issue, but does the initialization loop mask errors for multi-port SoCs?
Looking at the existing rtk_phy_init() function:
drivers/phy/realtek/phy-rtk-usb2.c:rtk_phy_init() {
...
for (i = 0; i < rtk_phy->num_phy; i++) ret = do_rtk_phy_init(rtk_phy, i);
...
}
If do_rtk_phy_init() fails for any port except the last one, ret is overwritten by the result of the subsequent PHY's initialization, silently ignoring earlier failures while incorrectly reporting probe success.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v7 6/6 phy: realtek: Make configs available for MACH_REALTEK_RTL
In reply to Rustam AdilovAdd the MACH_REALTEK_RTL to the if statement to make the config options available for Realtek RTL SoCs as well.
--- drivers/phy/realtek/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/realtek/Kconfig +2 -2
@@ -3,7 +3,7 @@ # Phy drivers for Realtek platforms # -if ARCH_REALTEK || COMPILE_TEST +if ARCH_REALTEK || MACH_REALTEK_RTL || COMPILE_TEST config PHY_RTK_RTD_USB2PHY tristate "Realtek RTD USB2 PHY Transceiver Driver"
@@ -29,4 +29,4 @@ config PHY_RTK_RTD_USB3PHY DWC3 USB IP. This driver will do the PHY initialization of the parameters. -endif # ARCH_REALTEK || COMPILE_TEST +endif # ARCH_REALTEK || MACH_REALTEK_RTL || COMPILE_TEST
Signature · 1 line
2.55.0