Skip to content

Commit

Permalink
usb: typec: fsa4480: Check if the chip is really there
Browse files Browse the repository at this point in the history
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: 1dc2463 ("usb: typec: mux: Add On Semi fsa4480 driver")
Cc: stable <stable@kernel.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Link: https://lore.kernel.org/r/20240729-topic-fs4480_check-v3-1-f5bf732d3424@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Konrad Dybcio authored and Greg Kroah-Hartman committed Jul 31, 2024
1 parent 973a578 commit e885f5f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/usb/typec/mux/fsa4480.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit e885f5f

Please sign in to comment.