2020-12-11 19:28:56

by Liam Beguin

[permalink] [raw]
Subject: [PATCH v5 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

From: Liam Beguin <[email protected]>

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 <[email protected]>
---
Changes since v1:
- use set_mask_bits

Changes since v2:
- fix missing bit shift dropped in v2
- rebase on 5.9-rc1

Changes since v3:
- switch to u8p_replace_bits() since there's little reason to protect
against concurrent access

Changes since v4:
- rebase on latest master

drivers/phy/ti/phy-tusb1210.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/phy/ti/phy-tusb1210.c b/drivers/phy/ti/phy-tusb1210.c
index d8d0cc11d187..a63213f5972a 100644
--- a/drivers/phy/ti/phy-tusb1210.c
+++ b/drivers/phy/ti/phy-tusb1210.c
@@ -7,15 +7,16 @@
* Author: Heikki Krogerus <[email protected]>
*/
#include <linux/module.h>
+#include <linux/bitfield.h>
#include <linux/ulpi/driver.h>
#include <linux/ulpi/regs.h>
#include <linux/gpio/consumer.h>
#include <linux/phy/ulpi_phy.h>

#define TUSB1210_VENDOR_SPECIFIC2 0x80
-#define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0
-#define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
-#define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6
+#define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK GENMASK(3, 0)
+#define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK GENMASK(5, 4)
+#define TUSB1210_VENDOR_SPECIFIC2_DP_MASK BIT(6)

struct tusb1210 {
struct ulpi *ulpi;
@@ -118,22 +119,22 @@ static int tusb1210_probe(struct ulpi *ulpi)
* diagram optimization and DP/DM swap.
*/

+ reg = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);
+
/* High speed output drive strength configuration */
- device_property_read_u8(&ulpi->dev, "ihstx", &val);
- reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT;
+ if (!device_property_read_u8(&ulpi->dev, "ihstx", &val))
+ u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK);

/* High speed output impedance configuration */
- device_property_read_u8(&ulpi->dev, "zhsdrv", &val);
- reg |= val << TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT;
+ if (!device_property_read_u8(&ulpi->dev, "zhsdrv", &val))
+ u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK);

/* DP/DM swap control */
- device_property_read_u8(&ulpi->dev, "datapolarity", &val);
- reg |= val << TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT;
+ if (!device_property_read_u8(&ulpi->dev, "datapolarity", &val))
+ u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_DP_MASK);

- if (reg) {
- ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg);
- tusb->vendor_specific2 = reg;
- }
+ ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg);
+ tusb->vendor_specific2 = reg;

tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
if (IS_ERR(tusb->phy))

base-commit: 33dc9614dc208291d0c4bcdeb5d30d481dcd2c4c
--
2.27.0


2021-01-13 11:53:15

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH v5 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

On 11-12-20, 14:12, Liam Beguin wrote:
> From: Liam Beguin <[email protected]>
>
> 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.

Applied, thanks

--
~Vinod

2021-02-17 15:33:58

by Liam Beguin

[permalink] [raw]
Subject: Re: [PATCH v5 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

Hi Vinod,

On Wed Jan 13, 2021 at 6:49 AM EST, Vinod Koul wrote:
> Applied, thanks
>

I can't seem to find where this was applied, could you point me to the
right repository?

> --
> ~Vinod

Thanks,
Liam

2021-02-19 08:00:15

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH v5 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

On 17-02-21, 10:22, Liam Beguin wrote:
> Hi Vinod,
>
> On Wed Jan 13, 2021 at 6:49 AM EST, Vinod Koul wrote:
> > Applied, thanks
> >
>
> I can't seem to find where this was applied, could you point me to the
> right repository?

Yeah I cant find the commit in phy-next. I will apply this after merge
window opens.. sorry for the miss

--
~Vinod

2021-03-04 06:35:49

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH v5 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

On 19-02-21, 13:28, Vinod Koul wrote:
> On 17-02-21, 10:22, Liam Beguin wrote:
> > Hi Vinod,
> >
> > On Wed Jan 13, 2021 at 6:49 AM EST, Vinod Koul wrote:
> > > Applied, thanks
> > >
> >
> > I can't seem to find where this was applied, could you point me to the
> > right repository?
>
> Yeah I cant find the commit in phy-next. I will apply this after merge
> window opens.. sorry for the miss

Done now, it should be in linux-next for tomorrow

--
~Vinod

2021-03-04 06:37:04

by Liam Beguin

[permalink] [raw]
Subject: Re: [PATCH v5 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

On Tue Mar 2, 2021 at 11:37 AM EST, Vinod Koul wrote:
> On 19-02-21, 13:28, Vinod Koul wrote:
> > On 17-02-21, 10:22, Liam Beguin wrote:
> > > Hi Vinod,
> > >
> > > On Wed Jan 13, 2021 at 6:49 AM EST, Vinod Koul wrote:
> > > > Applied, thanks
> > > >
> > >
> > > I can't seem to find where this was applied, could you point me to the
> > > right repository?
> >
> > Yeah I cant find the commit in phy-next. I will apply this after merge
> > window opens.. sorry for the miss
>
> Done now, it should be in linux-next for tomorrow

Perfect! Thanks again for your time,

>
> --
> ~Vinod

Liam