mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Konrad Dybcio <konradybcio@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Marijn Suijten <marijn.suijten@somainline.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Subject: Re: [PATCH v3] usb: typec: fsa4480: Check if the chip is really there
Date: Thu, 1 Aug 2024 11:42:31 +0300	[thread overview]
Message-ID: <ZqtKd8Cin4TvcVH+@kuha.fi.intel.com> (raw)
In-Reply-To: <20240729-topic-fs4480_check-v3-1-f5bf732d3424@kernel.org>

On Mon, Jul 29, 2024 at 10:42:58AM +0200, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@linaro.org>
> 
> 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")
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> Changes in v3:
> - Don't sign off twice
> - Pick up Dmitry's rb
> - Link to v2: https://lore.kernel.org/r/20240726-topic-fs4480_check-v2-1-901ca449db15@kernel.org
> 
> Changes in v2:
> - Prepend the new defines with FSA4480_ to make them more obvious
> - Link to v1: https://lore.kernel.org/r/20240212-topic-fs4480_check-v1-1-d9969e4d6f9a@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..cd235339834b 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 FSA4480_DEVICE_ID_VENDOR_ID	GENMASK(7, 6)
> + #define FSA4480_DEVICE_ID_VERSION_ID	GENMASK(5, 3)
> + #define FSA4480_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(FSA4480_DEVICE_ID_VERSION_ID, val),
> +		FIELD_GET(FSA4480_DEVICE_ID_REV_ID, val),
> +		FIELD_GET(FSA4480_DEVICE_ID_VENDOR_ID, val));
> +
>  	/* Safe mode */
>  	fsa->cur_enable = FSA4480_ENABLE_DEVICE | FSA4480_ENABLE_USB;
>  	fsa->mode = TYPEC_STATE_SAFE;

thanks,

-- 
heikki

      reply	other threads:[~2024-08-01  8:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29  8:42 Konrad Dybcio
2024-08-01  8:42 ` Heikki Krogerus [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZqtKd8Cin4TvcVH+@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=andersson@kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=konradybcio@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=marijn.suijten@somainline.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®