// SPDX-License-Identifier: GPL-2.0 /* * Bus for USB Type-C Alternate Modes * * Copyright (C) 2018 Intel Corporation * Author: Heikki Krogerus <[email protected]> */ #include <linux/usb/pd_vdo.h> #include "bus.h" #include "class.h" #include "mux.h" #include "retimer.h" static inline int typec_altmode_set_retimer(struct altmode *alt, unsigned long conf, void *data) { … } static inline int typec_altmode_set_mux(struct altmode *alt, unsigned long conf, void *data) { … } /* Wrapper to set various Type-C port switches together. */ static inline int typec_altmode_set_switches(struct altmode *alt, unsigned long conf, void *data) { … } static int typec_altmode_set_state(struct typec_altmode *adev, unsigned long conf, void *data) { … } /* -------------------------------------------------------------------------- */ /* Common API */ /** * typec_altmode_notify - Communication between the OS and alternate mode driver * @adev: Handle to the alternate mode * @conf: Alternate mode specific configuration value * @data: Alternate mode specific data * * The primary purpose for this function is to allow the alternate mode drivers * to tell which pin configuration has been negotiated with the partner. That * information will then be used for example to configure the muxes. * Communication to the other direction is also possible, and low level device * drivers can also send notifications to the alternate mode drivers. The actual * communication will be specific for every SVID. */ int typec_altmode_notify(struct typec_altmode *adev, unsigned long conf, void *data) { … } EXPORT_SYMBOL_GPL(…); /** * typec_altmode_enter - Enter Mode * @adev: The alternate mode * @vdo: VDO for the Enter Mode command * * The alternate mode drivers use this function to enter mode. The port drivers * use this to inform the alternate mode drivers that the partner has initiated * Enter Mode command. If the alternate mode does not require VDO, @vdo must be * NULL. */ int typec_altmode_enter(struct typec_altmode *adev, u32 *vdo) { … } EXPORT_SYMBOL_GPL(…); /** * typec_altmode_exit - Exit Mode * @adev: The alternate mode * * The partner of @adev has initiated Exit Mode command. */ int typec_altmode_exit(struct typec_altmode *adev) { … } EXPORT_SYMBOL_GPL(…); /** * typec_altmode_attention - Attention command * @adev: The alternate mode * @vdo: VDO for the Attention command * * Notifies the partner of @adev about Attention command. */ int typec_altmode_attention(struct typec_altmode *adev, u32 vdo) { … } EXPORT_SYMBOL_GPL(…); /** * typec_altmode_vdm - Send Vendor Defined Messages (VDM) to the partner * @adev: Alternate mode handle * @header: VDM Header * @vdo: Array of Vendor Defined Data Objects * @count: Number of Data Objects * * The alternate mode drivers use this function for SVID specific communication * with the partner. The port drivers use it to deliver the Structured VDMs * received from the partners to the alternate mode drivers. */ int typec_altmode_vdm(struct typec_altmode *adev, const u32 header, const u32 *vdo, int count) { … } EXPORT_SYMBOL_GPL(…); const struct typec_altmode * typec_altmode_get_partner(struct typec_altmode *adev) { … } EXPORT_SYMBOL_GPL(…); /* -------------------------------------------------------------------------- */ /* API for cable alternate modes */ /** * typec_cable_altmode_enter - Enter Mode * @adev: The alternate mode * @sop: Cable plug target for Enter Mode command * @vdo: VDO for the Enter Mode command * * Alternate mode drivers use this function to enter mode on the cable plug. * If the alternate mode does not require VDO, @vdo must be NULL. */ int typec_cable_altmode_enter(struct typec_altmode *adev, enum typec_plug_index sop, u32 *vdo) { … } EXPORT_SYMBOL_GPL(…); /** * typec_cable_altmode_exit - Exit Mode * @adev: The alternate mode * @sop: Cable plug target for Exit Mode command * * The alternate mode drivers use this function to exit mode on the cable plug. */ int typec_cable_altmode_exit(struct typec_altmode *adev, enum typec_plug_index sop) { … } EXPORT_SYMBOL_GPL(…); /** * typec_cable_altmode_vdm - Send Vendor Defined Messages (VDM) between the cable plug and port. * @adev: Alternate mode handle * @sop: Cable plug target for VDM * @header: VDM Header * @vdo: Array of Vendor Defined Data Objects * @count: Number of Data Objects * * The alternate mode drivers use this function for SVID specific communication * with the cable plugs. The port drivers use it to deliver the Structured VDMs * received from the cable plugs to the alternate mode drivers. */ int typec_cable_altmode_vdm(struct typec_altmode *adev, enum typec_plug_index sop, const u32 header, const u32 *vdo, int count) { … } EXPORT_SYMBOL_GPL(…); /* -------------------------------------------------------------------------- */ /* API for the alternate mode drivers */ /** * typec_altmode_get_plug - Find cable plug alternate mode * @adev: Handle to partner alternate mode * @index: Cable plug index * * Increment reference count for cable plug alternate mode device. Returns * handle to the cable plug alternate mode, or NULL if none is found. */ struct typec_altmode *typec_altmode_get_plug(struct typec_altmode *adev, enum typec_plug_index index) { … } EXPORT_SYMBOL_GPL(…); /** * typec_altmode_put_plug - Decrement cable plug alternate mode reference count * @plug: Handle to the cable plug alternate mode */ void typec_altmode_put_plug(struct typec_altmode *plug) { … } EXPORT_SYMBOL_GPL(…); int __typec_altmode_register_driver(struct typec_altmode_driver *drv, struct module *module) { … } EXPORT_SYMBOL_GPL(…); void typec_altmode_unregister_driver(struct typec_altmode_driver *drv) { … } EXPORT_SYMBOL_GPL(…); /* -------------------------------------------------------------------------- */ /* API for the port drivers */ /** * typec_match_altmode - Match SVID and mode to an array of alternate modes * @altmodes: Array of alternate modes * @n: Number of elements in the array, or -1 for NULL terminated arrays * @svid: Standard or Vendor ID to match with * @mode: Mode to match with * * Return pointer to an alternate mode with SVID matching @svid, or NULL when no * match is found. */ struct typec_altmode *typec_match_altmode(struct typec_altmode **altmodes, size_t n, u16 svid, u8 mode) { … } EXPORT_SYMBOL_GPL(…); /* -------------------------------------------------------------------------- */ static ssize_t description_show(struct device *dev, struct device_attribute *attr, char *buf) { … } static DEVICE_ATTR_RO(description); static struct attribute *typec_attrs[] = …; ATTRIBUTE_GROUPS(…); static int typec_match(struct device *dev, const struct device_driver *driver) { … } static int typec_uevent(const struct device *dev, struct kobj_uevent_env *env) { … } static int typec_altmode_create_links(struct altmode *alt) { … } static void typec_altmode_remove_links(struct altmode *alt) { … } static int typec_probe(struct device *dev) { … } static void typec_remove(struct device *dev) { … } const struct bus_type typec_bus = …;