From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Abhishek Pandit-Subedi <abhishekpandit@google.com>
Cc: linux-usb@vger.kernel.org, pmalani@chromium.org,
jthies@google.com,
Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
Bjorn Andersson <andersson@kernel.org>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Saranya Gopal <saranya.gopal@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/3] usb: typec: ucsi: Update connector cap and status
Date: Wed, 24 Jan 2024 16:14:10 +0200 [thread overview]
Message-ID: <ZbEbMvzSr4JR3s/9@kuha.fi.intel.com> (raw)
In-Reply-To: <20240123143026.v1.2.I3d909e3c9a200621e3034686f068a3307945fd87@changeid>
On Tue, Jan 23, 2024 at 02:30:35PM -0800, Abhishek Pandit-Subedi wrote:
> From: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
>
> Update the data structures for ucsi_connector_capability and
> ucsi_connector_status to UCSIv3.
>
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> ---
> Connector status has several unaligned bitfields (16-bit) that result in
> difficult to maintain macros. It may be better if we simply re-define
> these structs as u8[] and add bit range macros to access and cast these
> values.
>
> i.e.
> struct ucsi_connector_status {
> u8 raw_data[18];
>
> ...
> \#define UCSI_CONSTAT_CONNECTOR_STATUS FIELD(u16, 15, 0)
> \#define UCSI_CONSTAT_BCD_PD_VER_OPER_MODE FIELD(u16, 85, 70)
> }
>
> GET_UCSI_FIELD(con->status, UCSI_CONSTAT_CONNECTOR_STATUS);
> SET_UCSI_FIELD(con->status, UCSI_CONSTAT_CONNECTOR_STATUS, 0);
>
> I didn't find a clear example of an existing mechanism to do this. Would
> love some pointers here if it already exists and some feedback from the
> maintainer if this is a direction you want to go.
I'll ask around if anybody has any ideas on our side, but I think we
can go forward with this in any case. We can always fine tune these
later.
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> drivers/usb/typec/ucsi/ucsi.h | 50 ++++++++++++++++++++++++++++++++---
> 1 file changed, 46 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index bec920fa6b8a..94b373378f63 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -3,6 +3,7 @@
> #ifndef __DRIVER_USB_TYPEC_UCSI_H
> #define __DRIVER_USB_TYPEC_UCSI_H
>
> +#include <asm-generic/unaligned.h>
> #include <linux/bitops.h>
> #include <linux/device.h>
> #include <linux/power_supply.h>
> @@ -214,9 +215,29 @@ struct ucsi_connector_capability {
> #define UCSI_CONCAP_OPMODE_USB2 BIT(5)
> #define UCSI_CONCAP_OPMODE_USB3 BIT(6)
> #define UCSI_CONCAP_OPMODE_ALT_MODE BIT(7)
> - u8 flags;
> + u32 flags;
> #define UCSI_CONCAP_FLAG_PROVIDER BIT(0)
> #define UCSI_CONCAP_FLAG_CONSUMER BIT(1)
> +#define UCSI_CONCAP_FLAG_SWAP_TO_DFP BIT(2)
> +#define UCSI_CONCAP_FLAG_SWAP_TO_UFP BIT(3)
> +#define UCSI_CONCAP_FLAG_SWAP_TO_SRC BIT(4)
> +#define UCSI_CONCAP_FLAG_SWAP_TO_SINK BIT(5)
> +#define UCSI_CONCAP_FLAG_EX_OP_MODE(_f_) \
> + (((_f_) & GENMASK(13, 6)) >> 6)
> +#define UCSI_CONCAP_EX_OP_MODE_USB4_GEN2 BIT(0)
> +#define UCSI_CONCAP_EX_OP_MODE_EPR_SRC BIT(1)
> +#define UCSI_CONCAP_EX_OP_MODE_EPR_SINK BIT(2)
> +#define UCSI_CONCAP_EX_OP_MODE_USB4_GEN3 BIT(3)
> +#define UCSI_CONCAP_EX_OP_MODE_USB4_GEN4 BIT(4)
> +#define UCSI_CONCAP_FLAG_MISC_CAPS(_f_) \
> + (((_f_) & GENMASK(17, 14)) >> 14)
> +#define UCSI_CONCAP_MISC_CAP_FW_UPDATE BIT(0)
> +#define UCSI_CONCAP_MISC_CAP_SECURITY BIT(1)
> +#define UCSI_CONCAP_FLAG_REV_CURR_PROT_SUPPORT BIT(18)
> +#define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_) \
> + (((_f_) & GENMASK(20, 19)) >> 19)
> +#define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(_f_) \
> + (UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_) << 8)
> } __packed;
>
> struct ucsi_altmode {
> @@ -276,15 +297,36 @@ struct ucsi_connector_status {
> #define UCSI_CONSTAT_PARTNER_TYPE_DEBUG 5
> #define UCSI_CONSTAT_PARTNER_TYPE_AUDIO 6
> u32 request_data_obj;
> - u8 pwr_status;
> -#define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_) & GENMASK(2, 0))
> +
> + u8 pwr_status[3];
> +#define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_[0]) & GENMASK(1, 0))
> #define UCSI_CONSTAT_BC_NOT_CHARGING 0
> #define UCSI_CONSTAT_BC_NOMINAL_CHARGING 1
> #define UCSI_CONSTAT_BC_SLOW_CHARGING 2
> #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3
> -#define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_) & GENMASK(6, 3)) >> 3)
> +#define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_[0]) & GENMASK(5, 2)) >> 2)
> #define UCSI_CONSTAT_CAP_PWR_LOWERED 0
> #define UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT 1
> +#define UCSI_CONSTAT_PROVIDER_PD_VERSION_OPER_MODE(_p_) \
> + ((get_unaligned_le32(_p_) & GENMASK(21, 6)) >> 6)
> +#define UCSI_CONSTAT_ORIENTATION(_p_) (((_p_[2]) & GENMASK(6, 6)) >> 6)
> +#define UCSI_CONSTAT_ORIENTATION_DIRECT 0
> +#define UCSI_CONSTAT_ORIENTATION_FLIPPED 1
> +#define UCSI_CONSTAT_SINK_PATH_STATUS(_p_) (((_p_[2]) & GENMASK(7, 7)) >> 7)
> +#define UCSI_CONSTAT_SINK_PATH_DISABLED 0
> +#define UCSI_CONSTAT_SINK_PATH_ENABLED 1
> + u8 pwr_readings[9];
> +#define UCSI_CONSTAT_REV_CURR_PROT_STATUS(_p_) ((_p_[0]) & 0x1)
> +#define UCSI_CONSTAT_PWR_READING_VALID(_p_) (((_p_[0]) & GENMASK(1, 1)) >> 1)
> +#define UCSI_CONSTAT_CURRENT_SCALE(_p_) (((_p_[0]) & GENMASK(4, 2)) >> 2)
> +#define UCSI_CONSTAT_PEAK_CURRENT(_p_) \
> + ((get_unaligned_le32(_p_) & GENMASK(20, 5)) >> 5)
> +#define UCSI_CONSTAT_AVG_CURRENT(_p_) \
> + ((get_unaligned_le32(&(_p_)[2]) & GENMASK(20, 5)) >> 5)
> +#define UCSI_CONSTAT_VOLTAGE_SCALE(_p_) \
> + ((get_unaligned_le16(&(_p_)[4]) & GENMASK(8, 5)) >> 5)
> +#define UCSI_CONSTAT_VOLTAGE_READING(_p_) \
> + ((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1)
> } __packed;
>
> /* -------------------------------------------------------------------------- */
> --
> 2.43.0.429.g432eaa2c6b-goog
--
heikki
next prev parent reply other threads:[~2024-01-24 14:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 22:30 [PATCH v1 0/3] usb: typec: ucsi: Adding support for UCSI 3.0 Abhishek Pandit-Subedi
2024-01-23 22:30 ` [PATCH v1 1/3] usb: typec: ucsi: Limit read size on v1.2 Abhishek Pandit-Subedi
2024-01-24 8:12 ` Prashant Malani
2024-01-24 13:51 ` Heikki Krogerus
2024-01-24 14:17 ` Greg Kroah-Hartman
2024-01-24 18:59 ` Abhishek Pandit-Subedi
2024-01-25 23:16 ` Greg Kroah-Hartman
2024-01-25 23:37 ` Abhishek Pandit-Subedi
2024-01-23 22:30 ` [PATCH v1 2/3] usb: typec: ucsi: Update connector cap and status Abhishek Pandit-Subedi
2024-01-24 14:14 ` Heikki Krogerus [this message]
2024-01-24 18:50 ` Prashant Malani
2024-01-23 22:30 ` [PATCH v1 3/3] usb: typec: ucsi: Get PD revision for partner Abhishek Pandit-Subedi
2024-01-24 14:30 ` Heikki Krogerus
2024-01-24 18:48 ` Prashant Malani
2024-01-24 19:18 ` Abhishek Pandit-Subedi
2024-01-24 19:34 ` Prashant Malani
2024-01-24 22:57 ` Abhishek Pandit-Subedi
2024-01-24 12:44 ` [PATCH v1 0/3] usb: typec: ucsi: Adding support for UCSI 3.0 Neil Armstrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZbEbMvzSr4JR3s/9@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=abhishekpandit@chromium.org \
--cc=abhishekpandit@google.com \
--cc=andersson@kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=jthies@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pmalani@chromium.org \
--cc=saranya.gopal@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox