diff mbox series

usb: typec: fsa4480: Check if the chip is really there

Message ID 20240212-topic-fs4480_check-v1-1-d9969e4d6f9a@linaro.org (mailing list archive)
State New
Headers show
Series usb: typec: fsa4480: Check if the chip is really there | expand

Commit Message

Konrad Dybcio Feb. 12, 2024, 12:01 p.m. UTC
Currently, the driver will happily register the switch/mux devices, and
so long as the i2c master doesn't complain, the user would never know
there's something wrong.

Add a device id check (based on [1]) and return -ENODEV if the read
fails or returns nonsense.

Checking the value on a Qualcomm SM6115P-based Lenovo Tab P11 tablet,
the ID mentioned in the datasheet does indeed show up:
 fsa4480 1-0042: Found FSA4480 v1.1 (Vendor ID = 0)

[1] https://www.onsemi.com/pdf/datasheet/fsa4480-d.pdf

Fixes: 1dc246320c6b ("usb: typec: mux: Add On Semi fsa4480 driver")
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
---
 drivers/usb/typec/mux/fsa4480.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)


---
base-commit: ae00c445390b349e070a64dc62f08aa878db7248
change-id: 20240212-topic-fs4480_check-caa0160fb101

Best regards,

Comments

Greg KH Feb. 12, 2024, 12:48 p.m. UTC | #1
On Mon, Feb 12, 2024 at 01:01:30PM +0100, Konrad Dybcio wrote:
> Currently, the driver will happily register the switch/mux devices, and
> so long as the i2c master doesn't complain, the user would never know
> there's something wrong.
> 
> Add a device id check (based on [1]) and return -ENODEV if the read
> fails or returns nonsense.
> 
> Checking the value on a Qualcomm SM6115P-based Lenovo Tab P11 tablet,
> the ID mentioned in the datasheet does indeed show up:
>  fsa4480 1-0042: Found FSA4480 v1.1 (Vendor ID = 0)
> 
> [1] https://www.onsemi.com/pdf/datasheet/fsa4480-d.pdf
> 
> Fixes: 1dc246320c6b ("usb: typec: mux: Add On Semi fsa4480 driver")
> Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
> ---
>  drivers/usb/typec/mux/fsa4480.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c
> index cb7cdf90cb0a..d622f4f3bd54 100644
> --- a/drivers/usb/typec/mux/fsa4480.c
> +++ b/drivers/usb/typec/mux/fsa4480.c
> @@ -13,6 +13,10 @@
>  #include <linux/usb/typec_dp.h>
>  #include <linux/usb/typec_mux.h>
>  
> +#define FSA4480_DEVICE_ID	0x00
> + #define DEVICE_ID_VENDOR_ID	GENMASK(7, 6)
> + #define DEVICE_ID_VERSION_ID	GENMASK(5, 3)
> + #define DEVICE_ID_REV_ID	GENMASK(2, 0)

Why the indent?

And those are _VERY_ generic #defines, please give a better name for
these so you don't conflict with other stuff in the kernel accidentally.

thanks,

greg k-h
Greg KH Feb. 12, 2024, 12:48 p.m. UTC | #2
On Mon, Feb 12, 2024 at 01:01:30PM +0100, Konrad Dybcio wrote:
> Currently, the driver will happily register the switch/mux devices, and
> so long as the i2c master doesn't complain, the user would never know
> there's something wrong.
> 
> Add a device id check (based on [1]) and return -ENODEV if the read
> fails or returns nonsense.
> 
> Checking the value on a Qualcomm SM6115P-based Lenovo Tab P11 tablet,
> the ID mentioned in the datasheet does indeed show up:
>  fsa4480 1-0042: Found FSA4480 v1.1 (Vendor ID = 0)
> 
> [1] https://www.onsemi.com/pdf/datasheet/fsa4480-d.pdf
> 
> Fixes: 1dc246320c6b ("usb: typec: mux: Add On Semi fsa4480 driver")
> Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
> ---
>  drivers/usb/typec/mux/fsa4480.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an
  older released kernel, yet you do not have a cc: stable line in the
  signed-off-by area at all, which means that the patch will not be
  applied to any older kernel releases.  To properly fix this, please
  follow the documented rules in the
  Documentation/process/stable-kernel-rules.rst file for how to resolve
  this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot
Konrad Dybcio Feb. 12, 2024, 12:59 p.m. UTC | #3
On 12.02.2024 13:48, Greg Kroah-Hartman wrote:
> On Mon, Feb 12, 2024 at 01:01:30PM +0100, Konrad Dybcio wrote:
>> Currently, the driver will happily register the switch/mux devices, and
>> so long as the i2c master doesn't complain, the user would never know
>> there's something wrong.
>>
>> Add a device id check (based on [1]) and return -ENODEV if the read
>> fails or returns nonsense.
>>
>> Checking the value on a Qualcomm SM6115P-based Lenovo Tab P11 tablet,
>> the ID mentioned in the datasheet does indeed show up:
>>  fsa4480 1-0042: Found FSA4480 v1.1 (Vendor ID = 0)
>>
>> [1] https://www.onsemi.com/pdf/datasheet/fsa4480-d.pdf
>>
>> Fixes: 1dc246320c6b ("usb: typec: mux: Add On Semi fsa4480 driver")
>> Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>> ---
>>  drivers/usb/typec/mux/fsa4480.c | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c
>> index cb7cdf90cb0a..d622f4f3bd54 100644
>> --- a/drivers/usb/typec/mux/fsa4480.c
>> +++ b/drivers/usb/typec/mux/fsa4480.c
>> @@ -13,6 +13,10 @@
>>  #include <linux/usb/typec_dp.h>
>>  #include <linux/usb/typec_mux.h>
>>  
>> +#define FSA4480_DEVICE_ID	0x00
>> + #define DEVICE_ID_VENDOR_ID	GENMASK(7, 6)
>> + #define DEVICE_ID_VERSION_ID	GENMASK(5, 3)
>> + #define DEVICE_ID_REV_ID	GENMASK(2, 0)
> 
> Why the indent?

In many places across the kernel, bitfields or possible values of a
register are defined with an indentation to emphasize the relation between
the defines

> 
> And those are _VERY_ generic #defines, please give a better name for
> these so you don't conflict with other stuff in the kernel accidentally.

If you don't mind them becoming very long, I can prepend them with FSA4480_,
and I suppose shrink 'VENDOR' to "VEN" and "VERSION" to "VER" to compensate

Konrad
Greg KH Feb. 13, 2024, 9:45 a.m. UTC | #4
On Mon, Feb 12, 2024 at 01:59:42PM +0100, Konrad Dybcio wrote:
> On 12.02.2024 13:48, Greg Kroah-Hartman wrote:
> > On Mon, Feb 12, 2024 at 01:01:30PM +0100, Konrad Dybcio wrote:
> >> Currently, the driver will happily register the switch/mux devices, and
> >> so long as the i2c master doesn't complain, the user would never know
> >> there's something wrong.
> >>
> >> Add a device id check (based on [1]) and return -ENODEV if the read
> >> fails or returns nonsense.
> >>
> >> Checking the value on a Qualcomm SM6115P-based Lenovo Tab P11 tablet,
> >> the ID mentioned in the datasheet does indeed show up:
> >>  fsa4480 1-0042: Found FSA4480 v1.1 (Vendor ID = 0)
> >>
> >> [1] https://www.onsemi.com/pdf/datasheet/fsa4480-d.pdf
> >>
> >> Fixes: 1dc246320c6b ("usb: typec: mux: Add On Semi fsa4480 driver")
> >> Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
> >> ---
> >>  drivers/usb/typec/mux/fsa4480.c | 14 ++++++++++++++
> >>  1 file changed, 14 insertions(+)
> >>
> >> diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c
> >> index cb7cdf90cb0a..d622f4f3bd54 100644
> >> --- a/drivers/usb/typec/mux/fsa4480.c
> >> +++ b/drivers/usb/typec/mux/fsa4480.c
> >> @@ -13,6 +13,10 @@
> >>  #include <linux/usb/typec_dp.h>
> >>  #include <linux/usb/typec_mux.h>
> >>  
> >> +#define FSA4480_DEVICE_ID	0x00
> >> + #define DEVICE_ID_VENDOR_ID	GENMASK(7, 6)
> >> + #define DEVICE_ID_VERSION_ID	GENMASK(5, 3)
> >> + #define DEVICE_ID_REV_ID	GENMASK(2, 0)
> > 
> > Why the indent?
> 
> In many places across the kernel, bitfields or possible values of a
> register are defined with an indentation to emphasize the relation between
> the defines

Ah, that wasn't obvious here because:

> > And those are _VERY_ generic #defines, please give a better name for
> > these so you don't conflict with other stuff in the kernel accidentally.
> 
> If you don't mind them becoming very long, I can prepend them with FSA4480_,
> and I suppose shrink 'VENDOR' to "VEN" and "VERSION" to "VER" to compensate

Yes, prepend them pleaase.  And no need to shorten the word, we have
plenty of space.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c
index cb7cdf90cb0a..d622f4f3bd54 100644
--- a/drivers/usb/typec/mux/fsa4480.c
+++ b/drivers/usb/typec/mux/fsa4480.c
@@ -13,6 +13,10 @@ 
 #include <linux/usb/typec_dp.h>
 #include <linux/usb/typec_mux.h>
 
+#define FSA4480_DEVICE_ID	0x00
+ #define DEVICE_ID_VENDOR_ID	GENMASK(7, 6)
+ #define DEVICE_ID_VERSION_ID	GENMASK(5, 3)
+ #define DEVICE_ID_REV_ID	GENMASK(2, 0)
 #define FSA4480_SWITCH_ENABLE	0x04
 #define FSA4480_SWITCH_SELECT	0x05
 #define FSA4480_SWITCH_STATUS1	0x07
@@ -251,6 +255,7 @@  static int fsa4480_probe(struct i2c_client *client)
 	struct typec_switch_desc sw_desc = { };
 	struct typec_mux_desc mux_desc = { };
 	struct fsa4480 *fsa;
+	int val = 0;
 	int ret;
 
 	fsa = devm_kzalloc(dev, sizeof(*fsa), GFP_KERNEL);
@@ -268,6 +273,15 @@  static int fsa4480_probe(struct i2c_client *client)
 	if (IS_ERR(fsa->regmap))
 		return dev_err_probe(dev, PTR_ERR(fsa->regmap), "failed to initialize regmap\n");
 
+	ret = regmap_read(fsa->regmap, FSA4480_DEVICE_ID, &val);
+	if (ret || !val)
+		return dev_err_probe(dev, -ENODEV, "FSA4480 not found\n");
+
+	dev_dbg(dev, "Found FSA4480 v%lu.%lu (Vendor ID = %lu)\n",
+		FIELD_GET(DEVICE_ID_VERSION_ID, val),
+		FIELD_GET(DEVICE_ID_REV_ID, val),
+		FIELD_GET(DEVICE_ID_VENDOR_ID, val));
+
 	/* Safe mode */
 	fsa->cur_enable = FSA4480_ENABLE_DEVICE | FSA4480_ENABLE_USB;
 	fsa->mode = TYPEC_STATE_SAFE;