Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nicolas Frattaroli and committed by
Yury Norov
a104de64 6fd524c3

+20 -31
+20 -31
drivers/phy/rockchip/phy-rockchip-usb.c
··· 8 8 9 9 #include <linux/clk.h> 10 10 #include <linux/clk-provider.h> 11 + #include <linux/hw_bitfield.h> 11 12 #include <linux/io.h> 12 13 #include <linux/kernel.h> 13 14 #include <linux/module.h> ··· 25 24 26 25 static int enable_usb_uart; 27 26 28 - #define HIWORD_UPDATE(val, mask) \ 29 - ((val) | (mask) << 16) 30 - 31 27 #define UOC_CON0 0x00 32 28 #define UOC_CON0_SIDDQ BIT(13) 33 29 #define UOC_CON0_DISABLE BIT(4) ··· 36 38 #define UOC_CON3 0x0c 37 39 /* bits present on rk3188 and rk3288 phys */ 38 40 #define UOC_CON3_UTMI_TERMSEL_FULLSPEED BIT(5) 39 - #define UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC (1 << 3) 40 - #define UOC_CON3_UTMI_XCVRSEELCT_MASK (3 << 3) 41 - #define UOC_CON3_UTMI_OPMODE_NODRIVING (1 << 1) 42 - #define UOC_CON3_UTMI_OPMODE_MASK (3 << 1) 41 + #define UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC 1UL 42 + #define UOC_CON3_UTMI_XCVRSEELCT_MASK GENMASK(4, 3) 43 + #define UOC_CON3_UTMI_OPMODE_NODRIVING 1UL 44 + #define UOC_CON3_UTMI_OPMODE_MASK GENMASK(2, 1) 43 45 #define UOC_CON3_UTMI_SUSPENDN BIT(0) 44 46 45 47 struct rockchip_usb_phys { ··· 77 79 static int rockchip_usb_phy_power(struct rockchip_usb_phy *phy, 78 80 bool siddq) 79 81 { 80 - u32 val = HIWORD_UPDATE(siddq ? UOC_CON0_SIDDQ : 0, UOC_CON0_SIDDQ); 82 + u32 val = FIELD_PREP_WM16(UOC_CON0_SIDDQ, siddq); 81 83 82 84 return regmap_write(phy->base->reg_base, phy->reg_offset, val); 83 85 } ··· 330 332 * but were not present in the original code. 331 333 * Also disable the analog phy components to save power. 332 334 */ 333 - val = HIWORD_UPDATE(UOC_CON0_COMMON_ON_N 334 - | UOC_CON0_DISABLE 335 - | UOC_CON0_SIDDQ, 336 - UOC_CON0_COMMON_ON_N 337 - | UOC_CON0_DISABLE 338 - | UOC_CON0_SIDDQ); 335 + val = FIELD_PREP_WM16(UOC_CON0_COMMON_ON_N, 1) | 336 + FIELD_PREP_WM16(UOC_CON0_DISABLE, 1) | 337 + FIELD_PREP_WM16(UOC_CON0_SIDDQ, 1); 339 338 ret = regmap_write(grf, regoffs + UOC_CON0, val); 340 339 if (ret) 341 340 return ret; 342 341 343 - val = HIWORD_UPDATE(UOC_CON2_SOFT_CON_SEL, 344 - UOC_CON2_SOFT_CON_SEL); 342 + val = FIELD_PREP_WM16(UOC_CON2_SOFT_CON_SEL, 1); 345 343 ret = regmap_write(grf, regoffs + UOC_CON2, val); 346 344 if (ret) 347 345 return ret; 348 346 349 - val = HIWORD_UPDATE(UOC_CON3_UTMI_OPMODE_NODRIVING 350 - | UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC 351 - | UOC_CON3_UTMI_TERMSEL_FULLSPEED, 352 - UOC_CON3_UTMI_SUSPENDN 353 - | UOC_CON3_UTMI_OPMODE_MASK 354 - | UOC_CON3_UTMI_XCVRSEELCT_MASK 355 - | UOC_CON3_UTMI_TERMSEL_FULLSPEED); 347 + val = FIELD_PREP_WM16(UOC_CON3_UTMI_SUSPENDN, 0) | 348 + FIELD_PREP_WM16(UOC_CON3_UTMI_OPMODE_MASK, 349 + UOC_CON3_UTMI_OPMODE_NODRIVING) | 350 + FIELD_PREP_WM16(UOC_CON3_UTMI_XCVRSEELCT_MASK, 351 + UOC_CON3_UTMI_XCVRSEELCT_FSTRANSC) | 352 + FIELD_PREP_WM16(UOC_CON3_UTMI_TERMSEL_FULLSPEED, 1); 356 353 ret = regmap_write(grf, UOC_CON3, val); 357 354 if (ret) 358 355 return ret; ··· 373 380 if (ret) 374 381 return ret; 375 382 376 - val = HIWORD_UPDATE(RK3188_UOC0_CON0_BYPASSSEL 377 - | RK3188_UOC0_CON0_BYPASSDMEN, 378 - RK3188_UOC0_CON0_BYPASSSEL 379 - | RK3188_UOC0_CON0_BYPASSDMEN); 383 + val = FIELD_PREP_WM16(RK3188_UOC0_CON0_BYPASSSEL, 1) | 384 + FIELD_PREP_WM16(RK3188_UOC0_CON0_BYPASSDMEN, 1); 380 385 ret = regmap_write(grf, RK3188_UOC0_CON0, val); 381 386 if (ret) 382 387 return ret; ··· 421 430 if (ret) 422 431 return ret; 423 432 424 - val = HIWORD_UPDATE(RK3288_UOC0_CON3_BYPASSSEL 425 - | RK3288_UOC0_CON3_BYPASSDMEN, 426 - RK3288_UOC0_CON3_BYPASSSEL 427 - | RK3288_UOC0_CON3_BYPASSDMEN); 433 + val = FIELD_PREP_WM16(RK3288_UOC0_CON3_BYPASSSEL, 1) | 434 + FIELD_PREP_WM16(RK3288_UOC0_CON3_BYPASSDMEN, 1); 428 435 ret = regmap_write(grf, RK3288_UOC0_CON3, val); 429 436 if (ret) 430 437 return ret;