Skip to content

Commit e885f5f

Browse files
konradybciogregkh
authored andcommitted
usb: typec: fsa4480: Check if the chip is really there
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 <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Signed-off-by: Konrad Dybcio <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 973a578 commit e885f5f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/usb/typec/mux/fsa4480.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include <linux/usb/typec_dp.h>
1414
#include <linux/usb/typec_mux.h>
1515

16+
#define FSA4480_DEVICE_ID 0x00
17+
#define FSA4480_DEVICE_ID_VENDOR_ID GENMASK(7, 6)
18+
#define FSA4480_DEVICE_ID_VERSION_ID GENMASK(5, 3)
19+
#define FSA4480_DEVICE_ID_REV_ID GENMASK(2, 0)
1620
#define FSA4480_SWITCH_ENABLE 0x04
1721
#define FSA4480_SWITCH_SELECT 0x05
1822
#define FSA4480_SWITCH_STATUS1 0x07
@@ -251,6 +255,7 @@ static int fsa4480_probe(struct i2c_client *client)
251255
struct typec_switch_desc sw_desc = { };
252256
struct typec_mux_desc mux_desc = { };
253257
struct fsa4480 *fsa;
258+
int val = 0;
254259
int ret;
255260

256261
fsa = devm_kzalloc(dev, sizeof(*fsa), GFP_KERNEL);
@@ -268,6 +273,15 @@ static int fsa4480_probe(struct i2c_client *client)
268273
if (IS_ERR(fsa->regmap))
269274
return dev_err_probe(dev, PTR_ERR(fsa->regmap), "failed to initialize regmap\n");
270275

276+
ret = regmap_read(fsa->regmap, FSA4480_DEVICE_ID, &val);
277+
if (ret || !val)
278+
return dev_err_probe(dev, -ENODEV, "FSA4480 not found\n");
279+
280+
dev_dbg(dev, "Found FSA4480 v%lu.%lu (Vendor ID = %lu)\n",
281+
FIELD_GET(FSA4480_DEVICE_ID_VERSION_ID, val),
282+
FIELD_GET(FSA4480_DEVICE_ID_REV_ID, val),
283+
FIELD_GET(FSA4480_DEVICE_ID_VENDOR_ID, val));
284+
271285
/* Safe mode */
272286
fsa->cur_enable = FSA4480_ENABLE_DEVICE | FSA4480_ENABLE_USB;
273287
fsa->mode = TYPEC_STATE_SAFE;

0 commit comments

Comments
 (0)