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

Configure Feed

Select the types of activity you want to include in your feed.

usb: typec: ucsi: glink: move GPIO reading into connector_status callback

To simplify the platform code move Type-C orientation handling into the
connector_status callback. As it is called both during connector
registration and on connector change events, duplicated code from
pmic_glink_ucsi_register() can be dropped.

Also this moves operations that can sleep into a worker thread,
removing the only sleeping operation from pmic_glink_ucsi_notify().

Tested-by: Krishna Kurapati <quic_kriskura@quicinc.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogeurs@linux.intel.com>
Link: https://lore.kernel.org/r/20240411-ucsi-orient-aware-v2-2-d4b1cb22a33f@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dmitry Baryshkov and committed by
Greg Kroah-Hartman
76716fd5 24bce22d

+20 -28
+20 -28
drivers/usb/typec/ucsi/ucsi_glink.c
··· 187 187 return ret; 188 188 } 189 189 190 + static void pmic_glink_ucsi_connector_status(struct ucsi_connector *con) 191 + { 192 + struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(con->ucsi); 193 + int orientation; 194 + 195 + if (con->num >= PMIC_GLINK_MAX_PORTS || 196 + !ucsi->port_orientation[con->num - 1]) 197 + return; 198 + 199 + orientation = gpiod_get_value(ucsi->port_orientation[con->num - 1]); 200 + if (orientation >= 0) { 201 + typec_switch_set(ucsi->port_switch[con->num - 1], 202 + orientation ? TYPEC_ORIENTATION_REVERSE 203 + : TYPEC_ORIENTATION_NORMAL); 204 + } 205 + } 206 + 190 207 static const struct ucsi_operations pmic_glink_ucsi_ops = { 191 208 .read = pmic_glink_ucsi_read, 192 209 .sync_write = pmic_glink_ucsi_sync_write, 193 - .async_write = pmic_glink_ucsi_async_write 210 + .async_write = pmic_glink_ucsi_async_write, 211 + .connector_status = pmic_glink_ucsi_connector_status, 194 212 }; 195 213 196 214 static void pmic_glink_ucsi_read_ack(struct pmic_glink_ucsi *ucsi, const void *data, int len) ··· 247 229 } 248 230 249 231 con_num = UCSI_CCI_CONNECTOR(cci); 250 - if (con_num) { 251 - if (con_num <= PMIC_GLINK_MAX_PORTS && 252 - ucsi->port_orientation[con_num - 1]) { 253 - int orientation = gpiod_get_value(ucsi->port_orientation[con_num - 1]); 254 - 255 - if (orientation >= 0) { 256 - typec_switch_set(ucsi->port_switch[con_num - 1], 257 - orientation ? TYPEC_ORIENTATION_REVERSE 258 - : TYPEC_ORIENTATION_NORMAL); 259 - } 260 - } 261 - 232 + if (con_num) 262 233 ucsi_connector_change(ucsi->ucsi, con_num); 263 - } 264 234 265 235 if (ucsi->sync_pending && 266 236 (cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE))) { ··· 259 253 static void pmic_glink_ucsi_register(struct work_struct *work) 260 254 { 261 255 struct pmic_glink_ucsi *ucsi = container_of(work, struct pmic_glink_ucsi, register_work); 262 - int orientation; 263 - int i; 264 - 265 - for (i = 0; i < PMIC_GLINK_MAX_PORTS; i++) { 266 - if (!ucsi->port_orientation[i]) 267 - continue; 268 - orientation = gpiod_get_value(ucsi->port_orientation[i]); 269 - 270 - if (orientation >= 0) { 271 - typec_switch_set(ucsi->port_switch[i], 272 - orientation ? TYPEC_ORIENTATION_REVERSE 273 - : TYPEC_ORIENTATION_NORMAL); 274 - } 275 - } 276 256 277 257 ucsi_register(ucsi->ucsi); 278 258 }