Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: ucsi: ccg: enable runtime pm support

The change enables runtime pm support to UCSI CCG driver.
Added ucsi_resume() function to enable notification after
system reusme. Exported both ucsi_resume() and ucsi_send_command()
symbols in ucsi.c for modular build.

Signed-off-by: Ajay Gupta <ajayg@nvidia.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Ajay Gupta and committed by
Wolfram Sang
a94ecde4 d4a4f927

+49
+10
drivers/usb/typec/ucsi/ucsi.c
··· 206 206 207 207 return ret; 208 208 } 209 + EXPORT_SYMBOL_GPL(ucsi_send_command); 209 210 211 + int ucsi_resume(struct ucsi *ucsi) 212 + { 213 + struct ucsi_control ctrl; 214 + 215 + /* Restore UCSI notification enable mask after system resume */ 216 + UCSI_CMD_SET_NTFY_ENABLE(ctrl, UCSI_ENABLE_NTFY_ALL); 217 + return ucsi_send_command(ucsi, &ctrl, NULL, 0); 218 + } 219 + EXPORT_SYMBOL_GPL(ucsi_resume); 210 220 /* -------------------------------------------------------------------------- */ 211 221 212 222 void ucsi_altmode_update_active(struct ucsi_connector *con)
+1
drivers/usb/typec/ucsi/ucsi.h
··· 430 430 void *retval, size_t size); 431 431 432 432 void ucsi_altmode_update_active(struct ucsi_connector *con); 433 + int ucsi_resume(struct ucsi *ucsi); 433 434 434 435 #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) 435 436 struct typec_altmode *
+38
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/pci.h> 16 16 #include <linux/platform_device.h> 17 + #include <linux/pm.h> 18 + #include <linux/pm_runtime.h> 17 19 18 20 #include <asm/unaligned.h> 19 21 #include "ucsi.h" ··· 212 210 if (quirks && quirks->max_read_len) 213 211 max_read_len = quirks->max_read_len; 214 212 213 + pm_runtime_get_sync(uc->dev); 215 214 while (rem_len > 0) { 216 215 msgs[1].buf = &data[len - rem_len]; 217 216 rlen = min_t(u16, rem_len, max_read_len); ··· 221 218 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 222 219 if (status < 0) { 223 220 dev_err(uc->dev, "i2c_transfer failed %d\n", status); 221 + pm_runtime_put_sync(uc->dev); 224 222 return status; 225 223 } 226 224 rab += rlen; 227 225 rem_len -= rlen; 228 226 } 229 227 228 + pm_runtime_put_sync(uc->dev); 230 229 return 0; 231 230 } 232 231 ··· 254 249 msgs[0].len = len + sizeof(rab); 255 250 msgs[0].buf = buf; 256 251 252 + pm_runtime_get_sync(uc->dev); 257 253 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 258 254 if (status < 0) { 259 255 dev_err(uc->dev, "i2c_transfer failed %d\n", status); 256 + pm_runtime_put_sync(uc->dev); 260 257 kfree(buf); 261 258 return status; 262 259 } 263 260 261 + pm_runtime_put_sync(uc->dev); 264 262 kfree(buf); 265 263 return 0; 266 264 } ··· 1142 1134 if (status) 1143 1135 dev_err(uc->dev, "cannot create sysfs group: %d\n", status); 1144 1136 1137 + pm_runtime_set_active(uc->dev); 1138 + pm_runtime_enable(uc->dev); 1139 + pm_runtime_idle(uc->dev); 1140 + 1145 1141 return 0; 1146 1142 } 1147 1143 ··· 1155 1143 1156 1144 cancel_work_sync(&uc->work); 1157 1145 ucsi_unregister_ppm(uc->ucsi); 1146 + pm_runtime_disable(uc->dev); 1158 1147 free_irq(uc->irq, uc); 1159 1148 sysfs_remove_group(&uc->dev->kobj, &ucsi_ccg_attr_group); 1160 1149 ··· 1168 1155 }; 1169 1156 MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id); 1170 1157 1158 + static int ucsi_ccg_resume(struct device *dev) 1159 + { 1160 + struct i2c_client *client = to_i2c_client(dev); 1161 + struct ucsi_ccg *uc = i2c_get_clientdata(client); 1162 + 1163 + return ucsi_resume(uc->ucsi); 1164 + } 1165 + 1166 + static int ucsi_ccg_runtime_suspend(struct device *dev) 1167 + { 1168 + return 0; 1169 + } 1170 + 1171 + static int ucsi_ccg_runtime_resume(struct device *dev) 1172 + { 1173 + return 0; 1174 + } 1175 + 1176 + static const struct dev_pm_ops ucsi_ccg_pm = { 1177 + .resume = ucsi_ccg_resume, 1178 + .runtime_suspend = ucsi_ccg_runtime_suspend, 1179 + .runtime_resume = ucsi_ccg_runtime_resume, 1180 + }; 1181 + 1171 1182 static struct i2c_driver ucsi_ccg_driver = { 1172 1183 .driver = { 1173 1184 .name = "ucsi_ccg", 1185 + .pm = &ucsi_ccg_pm, 1174 1186 }, 1175 1187 .probe = ucsi_ccg_probe, 1176 1188 .remove = ucsi_ccg_remove,