Skip to content

Commit a104de6

Browse files
Nicolas FrattaroliYuryNorov
authored andcommitted
phy: rockchip-usb: switch to FIELD_PREP_WM16 macro
The era of hand-rolled HIWORD_UPDATE macros is over, at least for those drivers that use constant masks. Remove this driver's HIWORD_UPDATE macro, and replace all instances of it with (hopefully) equivalent FIELD_PREP_WM16 instances. To do this, a few of the defines are being adjusted, as FIELD_PREP_WM16 shifts up the value for us. This gets rid of the icky update(mask, mask) shenanigans. The benefit of using FIELD_PREP_WM16 is that it does more checking of the input, hopefully catching errors. In practice, a shared definition makes code more readable than several different flavours of the same macro, and the shifted value helps as well. I do not have the hardware that uses this particular driver, so it's compile-tested only as far as my own testing goes. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
1 parent 6fd524c commit a104de6

1 file changed

Lines changed: 20 additions & 31 deletions

File tree

drivers/phy/rockchip/phy-rockchip-usb.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/clk.h>
1010
#include <linux/clk-provider.h>
11+
#include <linux/hw_bitfield.h>
1112
#include <linux/io.h>
1213
#include <linux/kernel.h>
1314
#include <linux/module.h>
@@ -24,9 +25,6 @@
2425

2526
static int enable_usb_uart;
2627

27-
#define HIWORD_UPDATE(val, mask) \
28-
((val) | (mask) << 16)
29-
3028
#define UOC_CON0 0x00
3129
#define UOC_CON0_SIDDQ BIT(13)
3230
#define UOC_CON0_DISABLE BIT(4)
@@ -38,10 +36,10 @@ static int enable_usb_uart;
3836
#define UOC_CON3 0x0c
3937
/* bits present on rk3188 and rk3288 phys */
4038
#define UOC_CON3_UTMI_TERMSEL_FULLSPEED BIT(5)
41-
#define UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC (1 << 3)
42-
#define UOC_CON3_UTMI_XCVRSEELCT_MASK (3 << 3)
43-
#define UOC_CON3_UTMI_OPMODE_NODRIVING (1 << 1)
44-
#define UOC_CON3_UTMI_OPMODE_MASK (3 << 1)
39+
#define UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC 1UL
40+
#define UOC_CON3_UTMI_XCVRSEELCT_MASK GENMASK(4, 3)
41+
#define UOC_CON3_UTMI_OPMODE_NODRIVING 1UL
42+
#define UOC_CON3_UTMI_OPMODE_MASK GENMASK(2, 1)
4543
#define UOC_CON3_UTMI_SUSPENDN BIT(0)
4644

4745
struct rockchip_usb_phys {
@@ -79,7 +77,7 @@ struct rockchip_usb_phy {
7977
static int rockchip_usb_phy_power(struct rockchip_usb_phy *phy,
8078
bool siddq)
8179
{
82-
u32 val = HIWORD_UPDATE(siddq ? UOC_CON0_SIDDQ : 0, UOC_CON0_SIDDQ);
80+
u32 val = FIELD_PREP_WM16(UOC_CON0_SIDDQ, siddq);
8381

8482
return regmap_write(phy->base->reg_base, phy->reg_offset, val);
8583
}
@@ -332,29 +330,24 @@ static int __init rockchip_init_usb_uart_common(struct regmap *grf,
332330
* but were not present in the original code.
333331
* Also disable the analog phy components to save power.
334332
*/
335-
val = HIWORD_UPDATE(UOC_CON0_COMMON_ON_N
336-
| UOC_CON0_DISABLE
337-
| UOC_CON0_SIDDQ,
338-
UOC_CON0_COMMON_ON_N
339-
| UOC_CON0_DISABLE
340-
| UOC_CON0_SIDDQ);
333+
val = FIELD_PREP_WM16(UOC_CON0_COMMON_ON_N, 1) |
334+
FIELD_PREP_WM16(UOC_CON0_DISABLE, 1) |
335+
FIELD_PREP_WM16(UOC_CON0_SIDDQ, 1);
341336
ret = regmap_write(grf, regoffs + UOC_CON0, val);
342337
if (ret)
343338
return ret;
344339

345-
val = HIWORD_UPDATE(UOC_CON2_SOFT_CON_SEL,
346-
UOC_CON2_SOFT_CON_SEL);
340+
val = FIELD_PREP_WM16(UOC_CON2_SOFT_CON_SEL, 1);
347341
ret = regmap_write(grf, regoffs + UOC_CON2, val);
348342
if (ret)
349343
return ret;
350344

351-
val = HIWORD_UPDATE(UOC_CON3_UTMI_OPMODE_NODRIVING
352-
| UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC
353-
| UOC_CON3_UTMI_TERMSEL_FULLSPEED,
354-
UOC_CON3_UTMI_SUSPENDN
355-
| UOC_CON3_UTMI_OPMODE_MASK
356-
| UOC_CON3_UTMI_XCVRSEELCT_MASK
357-
| UOC_CON3_UTMI_TERMSEL_FULLSPEED);
345+
val = FIELD_PREP_WM16(UOC_CON3_UTMI_SUSPENDN, 0) |
346+
FIELD_PREP_WM16(UOC_CON3_UTMI_OPMODE_MASK,
347+
UOC_CON3_UTMI_OPMODE_NODRIVING) |
348+
FIELD_PREP_WM16(UOC_CON3_UTMI_XCVRSEELCT_MASK,
349+
UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC) |
350+
FIELD_PREP_WM16(UOC_CON3_UTMI_TERMSEL_FULLSPEED, 1);
358351
ret = regmap_write(grf, UOC_CON3, val);
359352
if (ret)
360353
return ret;
@@ -380,10 +373,8 @@ static int __init rk3188_init_usb_uart(struct regmap *grf,
380373
if (ret)
381374
return ret;
382375

383-
val = HIWORD_UPDATE(RK3188_UOC0_CON0_BYPASSSEL
384-
| RK3188_UOC0_CON0_BYPASSDMEN,
385-
RK3188_UOC0_CON0_BYPASSSEL
386-
| RK3188_UOC0_CON0_BYPASSDMEN);
376+
val = FIELD_PREP_WM16(RK3188_UOC0_CON0_BYPASSSEL, 1) |
377+
FIELD_PREP_WM16(RK3188_UOC0_CON0_BYPASSDMEN, 1);
387378
ret = regmap_write(grf, RK3188_UOC0_CON0, val);
388379
if (ret)
389380
return ret;
@@ -430,10 +421,8 @@ static int __init rk3288_init_usb_uart(struct regmap *grf,
430421
if (ret)
431422
return ret;
432423

433-
val = HIWORD_UPDATE(RK3288_UOC0_CON3_BYPASSSEL
434-
| RK3288_UOC0_CON3_BYPASSDMEN,
435-
RK3288_UOC0_CON3_BYPASSSEL
436-
| RK3288_UOC0_CON3_BYPASSDMEN);
424+
val = FIELD_PREP_WM16(RK3288_UOC0_CON3_BYPASSSEL, 1) |
425+
FIELD_PREP_WM16(RK3288_UOC0_CON3_BYPASSDMEN, 1);
437426
ret = regmap_write(grf, RK3288_UOC0_CON3, val);
438427
if (ret)
439428
return ret;

0 commit comments

Comments
 (0)