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

phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

Start by reading the content of the VENDOR_SPECIFIC2 register and update
each bit field based on device properties when defined.

The use of bit masks prevents fields from overriding each other and
enables users to clear bits which are set by default, like datapolarity
in this instance.

Signed-off-by: Liam Beguin <lvb@xiphos.com>
Link: https://lore.kernel.org/r/20201211191241.21306-1-liambeguin@gmail.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Liam Beguin and committed by
Vinod Koul
eb445a15 015acd5d

+14 -13
+14 -13
drivers/phy/ti/phy-tusb1210.c
··· 7 7 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com> 8 8 */ 9 9 #include <linux/module.h> 10 + #include <linux/bitfield.h> 10 11 #include <linux/ulpi/driver.h> 11 12 #include <linux/ulpi/regs.h> 12 13 #include <linux/gpio/consumer.h> 13 14 #include <linux/phy/ulpi_phy.h> 14 15 15 16 #define TUSB1210_VENDOR_SPECIFIC2 0x80 16 - #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0 17 - #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4 18 - #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6 17 + #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK GENMASK(3, 0) 18 + #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK GENMASK(5, 4) 19 + #define TUSB1210_VENDOR_SPECIFIC2_DP_MASK BIT(6) 19 20 20 21 struct tusb1210 { 21 22 struct ulpi *ulpi; ··· 119 118 * diagram optimization and DP/DM swap. 120 119 */ 121 120 121 + reg = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2); 122 + 122 123 /* High speed output drive strength configuration */ 123 - device_property_read_u8(&ulpi->dev, "ihstx", &val); 124 - reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT; 124 + if (!device_property_read_u8(&ulpi->dev, "ihstx", &val)) 125 + u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK); 125 126 126 127 /* High speed output impedance configuration */ 127 - device_property_read_u8(&ulpi->dev, "zhsdrv", &val); 128 - reg |= val << TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT; 128 + if (!device_property_read_u8(&ulpi->dev, "zhsdrv", &val)) 129 + u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK); 129 130 130 131 /* DP/DM swap control */ 131 - device_property_read_u8(&ulpi->dev, "datapolarity", &val); 132 - reg |= val << TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT; 132 + if (!device_property_read_u8(&ulpi->dev, "datapolarity", &val)) 133 + u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_DP_MASK); 133 134 134 - if (reg) { 135 - ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg); 136 - tusb->vendor_specific2 = reg; 137 - } 135 + ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg); 136 + tusb->vendor_specific2 = reg; 138 137 139 138 tusb->phy = ulpi_phy_create(ulpi, &phy_ops); 140 139 if (IS_ERR(tusb->phy))