mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-28 07:13:34 +00:00
HID: mcp2221: switch i2c registration to devm functions
Switch from i2c_add_adapter() to resource managed devm_i2c_add_adapter() for matching rest of driver initialization, and more concise code. Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
79d11de963
commit
deb3b88bbb
1 changed files with 25 additions and 25 deletions
|
@ -824,6 +824,20 @@ static int mcp2221_raw_event(struct hid_device *hdev,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Device resource managed function for HID unregistration */
|
||||||
|
static void mcp2221_hid_unregister(void *ptr)
|
||||||
|
{
|
||||||
|
struct hid_device *hdev = ptr;
|
||||||
|
|
||||||
|
hid_hw_close(hdev);
|
||||||
|
hid_hw_stop(hdev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is needed to be sure hid_hw_stop() isn't called twice by the subsystem */
|
||||||
|
static void mcp2221_remove(struct hid_device *hdev)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static int mcp2221_probe(struct hid_device *hdev,
|
static int mcp2221_probe(struct hid_device *hdev,
|
||||||
const struct hid_device_id *id)
|
const struct hid_device_id *id)
|
||||||
{
|
{
|
||||||
|
@ -849,7 +863,8 @@ static int mcp2221_probe(struct hid_device *hdev,
|
||||||
ret = hid_hw_open(hdev);
|
ret = hid_hw_open(hdev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
hid_err(hdev, "can't open device\n");
|
hid_err(hdev, "can't open device\n");
|
||||||
goto err_hstop;
|
hid_hw_stop(hdev);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_init(&mcp->lock);
|
mutex_init(&mcp->lock);
|
||||||
|
@ -857,6 +872,10 @@ static int mcp2221_probe(struct hid_device *hdev,
|
||||||
hid_set_drvdata(hdev, mcp);
|
hid_set_drvdata(hdev, mcp);
|
||||||
mcp->hdev = hdev;
|
mcp->hdev = hdev;
|
||||||
|
|
||||||
|
ret = devm_add_action_or_reset(&hdev->dev, mcp2221_hid_unregister, hdev);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* Set I2C bus clock diviser */
|
/* Set I2C bus clock diviser */
|
||||||
if (i2c_clk_freq > 400)
|
if (i2c_clk_freq > 400)
|
||||||
i2c_clk_freq = 400;
|
i2c_clk_freq = 400;
|
||||||
|
@ -873,19 +892,17 @@ static int mcp2221_probe(struct hid_device *hdev,
|
||||||
"MCP2221 usb-i2c bridge on hidraw%d",
|
"MCP2221 usb-i2c bridge on hidraw%d",
|
||||||
((struct hidraw *)hdev->hidraw)->minor);
|
((struct hidraw *)hdev->hidraw)->minor);
|
||||||
|
|
||||||
ret = i2c_add_adapter(&mcp->adapter);
|
ret = devm_i2c_add_adapter(&hdev->dev, &mcp->adapter);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret);
|
hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret);
|
||||||
goto err_i2c;
|
return ret;
|
||||||
}
|
}
|
||||||
i2c_set_adapdata(&mcp->adapter, mcp);
|
i2c_set_adapdata(&mcp->adapter, mcp);
|
||||||
|
|
||||||
/* Setup GPIO chip */
|
/* Setup GPIO chip */
|
||||||
mcp->gc = devm_kzalloc(&hdev->dev, sizeof(*mcp->gc), GFP_KERNEL);
|
mcp->gc = devm_kzalloc(&hdev->dev, sizeof(*mcp->gc), GFP_KERNEL);
|
||||||
if (!mcp->gc) {
|
if (!mcp->gc)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_gc;
|
|
||||||
}
|
|
||||||
|
|
||||||
mcp->gc->label = "mcp2221_gpio";
|
mcp->gc->label = "mcp2221_gpio";
|
||||||
mcp->gc->direction_input = mcp_gpio_direction_input;
|
mcp->gc->direction_input = mcp_gpio_direction_input;
|
||||||
|
@ -900,26 +917,9 @@ static int mcp2221_probe(struct hid_device *hdev,
|
||||||
|
|
||||||
ret = devm_gpiochip_add_data(&hdev->dev, mcp->gc, mcp);
|
ret = devm_gpiochip_add_data(&hdev->dev, mcp->gc, mcp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_gc;
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_gc:
|
|
||||||
i2c_del_adapter(&mcp->adapter);
|
|
||||||
err_i2c:
|
|
||||||
hid_hw_close(mcp->hdev);
|
|
||||||
err_hstop:
|
|
||||||
hid_hw_stop(mcp->hdev);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mcp2221_remove(struct hid_device *hdev)
|
|
||||||
{
|
|
||||||
struct mcp2221 *mcp = hid_get_drvdata(hdev);
|
|
||||||
|
|
||||||
i2c_del_adapter(&mcp->adapter);
|
|
||||||
hid_hw_close(mcp->hdev);
|
|
||||||
hid_hw_stop(mcp->hdev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct hid_device_id mcp2221_devices[] = {
|
static const struct hid_device_id mcp2221_devices[] = {
|
||||||
|
|
Loading…
Reference in a new issue