Skip to content

Commit d93d284

Browse files
committed
HID: i2c-hid: Make suspend and resume into helper functions
In a future patch we'd like to be able to call the current i2c-hid suspend and resume functions from times other than system suspend. Move the functions higher up in the file and have them take a "struct i2c_hid" to make this simpler. We'll then add tiny wrappers of the functions for use with system suspend. This change is expected to have no functional effect. Reviewed-by: Maxime Ripard <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Acked-by: Benjamin Tissoires <[email protected]> Signed-off-by: Douglas Anderson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20230727101636.v4.7.I5c9894789b8b02f029bf266ae9b4f43c7907a173@changeid
1 parent 675cd87 commit d93d284

File tree

1 file changed

+56
-42
lines changed

1 file changed

+56
-42
lines changed

drivers/hid/i2c-hid/i2c-hid-core.c

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,57 @@ static void i2c_hid_core_shutdown_tail(struct i2c_hid *ihid)
941941
ihid->ops->shutdown_tail(ihid->ops);
942942
}
943943

944+
static int i2c_hid_core_suspend(struct i2c_hid *ihid)
945+
{
946+
struct i2c_client *client = ihid->client;
947+
struct hid_device *hid = ihid->hid;
948+
int ret;
949+
950+
ret = hid_driver_suspend(hid, PMSG_SUSPEND);
951+
if (ret < 0)
952+
return ret;
953+
954+
/* Save some power */
955+
i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
956+
957+
disable_irq(client->irq);
958+
959+
if (!device_may_wakeup(&client->dev))
960+
i2c_hid_core_power_down(ihid);
961+
962+
return 0;
963+
}
964+
965+
static int i2c_hid_core_resume(struct i2c_hid *ihid)
966+
{
967+
struct i2c_client *client = ihid->client;
968+
struct hid_device *hid = ihid->hid;
969+
int ret;
970+
971+
if (!device_may_wakeup(&client->dev))
972+
i2c_hid_core_power_up(ihid);
973+
974+
enable_irq(client->irq);
975+
976+
/* Instead of resetting device, simply powers the device on. This
977+
* solves "incomplete reports" on Raydium devices 2386:3118 and
978+
* 2386:4B33 and fixes various SIS touchscreens no longer sending
979+
* data after a suspend/resume.
980+
*
981+
* However some ALPS touchpads generate IRQ storm without reset, so
982+
* let's still reset them here.
983+
*/
984+
if (ihid->quirks & I2C_HID_QUIRK_RESET_ON_RESUME)
985+
ret = i2c_hid_hwreset(ihid);
986+
else
987+
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
988+
989+
if (ret)
990+
return ret;
991+
992+
return hid_driver_reset_resume(hid);
993+
}
994+
944995
/**
945996
* i2c_hid_core_initial_power_up() - First time power up of the i2c-hid device.
946997
* @ihid: The ihid object created during probe.
@@ -1115,61 +1166,24 @@ void i2c_hid_core_shutdown(struct i2c_client *client)
11151166
}
11161167
EXPORT_SYMBOL_GPL(i2c_hid_core_shutdown);
11171168

1118-
static int i2c_hid_core_suspend(struct device *dev)
1169+
static int i2c_hid_core_pm_suspend(struct device *dev)
11191170
{
11201171
struct i2c_client *client = to_i2c_client(dev);
11211172
struct i2c_hid *ihid = i2c_get_clientdata(client);
1122-
struct hid_device *hid = ihid->hid;
1123-
int ret;
1124-
1125-
ret = hid_driver_suspend(hid, PMSG_SUSPEND);
1126-
if (ret < 0)
1127-
return ret;
11281173

1129-
/* Save some power */
1130-
i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
1131-
1132-
disable_irq(client->irq);
1133-
1134-
if (!device_may_wakeup(&client->dev))
1135-
i2c_hid_core_power_down(ihid);
1136-
1137-
return 0;
1174+
return i2c_hid_core_suspend(ihid);
11381175
}
11391176

1140-
static int i2c_hid_core_resume(struct device *dev)
1177+
static int i2c_hid_core_pm_resume(struct device *dev)
11411178
{
1142-
int ret;
11431179
struct i2c_client *client = to_i2c_client(dev);
11441180
struct i2c_hid *ihid = i2c_get_clientdata(client);
1145-
struct hid_device *hid = ihid->hid;
11461181

1147-
if (!device_may_wakeup(&client->dev))
1148-
i2c_hid_core_power_up(ihid);
1149-
1150-
enable_irq(client->irq);
1151-
1152-
/* Instead of resetting device, simply powers the device on. This
1153-
* solves "incomplete reports" on Raydium devices 2386:3118 and
1154-
* 2386:4B33 and fixes various SIS touchscreens no longer sending
1155-
* data after a suspend/resume.
1156-
*
1157-
* However some ALPS touchpads generate IRQ storm without reset, so
1158-
* let's still reset them here.
1159-
*/
1160-
if (ihid->quirks & I2C_HID_QUIRK_RESET_ON_RESUME)
1161-
ret = i2c_hid_hwreset(ihid);
1162-
else
1163-
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
1164-
1165-
if (ret)
1166-
return ret;
1167-
1168-
return hid_driver_reset_resume(hid);
1182+
return i2c_hid_core_resume(ihid);
11691183
}
11701184

11711185
const struct dev_pm_ops i2c_hid_core_pm = {
1172-
SYSTEM_SLEEP_PM_OPS(i2c_hid_core_suspend, i2c_hid_core_resume)
1186+
SYSTEM_SLEEP_PM_OPS(i2c_hid_core_pm_suspend, i2c_hid_core_pm_resume)
11731187
};
11741188
EXPORT_SYMBOL_GPL(i2c_hid_core_pm);
11751189

0 commit comments

Comments
 (0)