@@ -324,6 +324,9 @@ static int mcp_i2c_xfer(struct i2c_adapter *adapter,
int ret;
struct mcp2221 *mcp = i2c_get_adapdata(adapter);
+ if(!mcp)
+ return -ECONNREFUSED;
+
hid_hw_power(mcp->hdev, PM_HINT_FULLON);
mutex_lock(&mcp->lock);
@@ -433,6 +436,9 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
int ret;
struct mcp2221 *mcp = i2c_get_adapdata(adapter);
+ if(!mcp)
+ return -ECONNREFUSED;
+
hid_hw_power(mcp->hdev, PM_HINT_FULLON);
mutex_lock(&mcp->lock);
@@ -1148,12 +1154,14 @@ static int mcp2221_probe(struct hid_device *hdev,
"MCP2221 usb-i2c bridge on hidraw%d",
((struct hidraw *)hdev->hidraw)->minor);
+ i2c_set_adapdata(&mcp->adapter, mcp);
+ hid_device_io_start(hdev);
+
ret = devm_i2c_add_adapter(&hdev->dev, &mcp->adapter);
if (ret) {
hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret);
return ret;
}
- i2c_set_adapdata(&mcp->adapter, mcp);
#if IS_REACHABLE(CONFIG_GPIOLIB)
/* Setup GPIO chip */