From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
USB <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>,
Felipe Balbi <balbi@kernel.org>
Subject: Re: [PATCH 2/3] usb: type-c: USB Type-C Connector System Software Interface
Date: Wed, 10 Feb 2016 13:56:03 +0200 [thread overview]
Message-ID: <CAHp75VeUt_uRgxQDxzMw3uoqaRC3TDEyVt1xDSGUicACf4H-_A@mail.gmail.com> (raw)
In-Reply-To: <1455037283-106479-3-git-send-email-heikki.krogerus@linux.intel.com>
On Tue, Feb 9, 2016 at 7:01 PM, Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
> USB Type-C Connector System Software Interface (UCSI) is a
> specification that defines registers and data structures
> used to interface with the USB Type-C connectors on a system.
>
> The specification is public and available at:
> http://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
+#define to_ucsi_connector(_port_) container_of(_port_->cap,
\
+ struct ucsi_connector, \
+ typec_cap)
Perhaps
static inline ...
+
+#define cci_to_connector(_ucsi_, cci) (_ucsi_->connector + \
+ UCSI_CCI_CONNECTOR_CHANGE(cci) - 1)
+
If you start you macro on the next line it will look better.
> +static int
> +ucsi_connect(struct ucsi_connector *con, struct ucsi_connector_status *constat)
> +{
> + struct typec_port *port = con->port;
> +
> + port->connected = true;
> +
> + if (constat->partner_flags & UCSI_CONSTAT_PARTNER_FLAG_ALT_MODE)
> + port->partner_type = TYPEC_PARTNER_ALTMODE;
> + else
> + port->partner_type = TYPEC_PARTNER_USB;
> +
> + switch (constat->partner_type) {
> + case UCSI_CONSTAT_PARTNER_TYPE_CABLE_NO_UFP:
> + /* REVISIT: We don't care about just the cable for now */
> + return 0;
> + case UCSI_CONSTAT_PARTNER_TYPE_DFP:
> + case UCSI_CONSTAT_PARTNER_TYPE_CABLE_AND_UFP:
> + port->pwr_role = TYPEC_PWR_SINK;
> + port->data_role = TYPEC_DEVICE;
> + break;
> + case UCSI_CONSTAT_PARTNER_TYPE_UFP:
> + port->pwr_role = TYPEC_PWR_SOURCE;
> + port->data_role = TYPEC_HOST;
> + break;
> + case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
> + port->partner_type = TYPEC_PARTNER_DEBUG;
> + goto out;
> + case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
> + port->partner_type = TYPEC_PARTNER_AUDIO;
> + goto out;
> + }
> +
> + switch (constat->pwr_op_mode) {
> + case UCSI_CONSTAT_PWR_OPMODE_NONE:
> + case UCSI_CONSTAT_PWR_OPMODE_DEFAULT:
> + port->pwr_opmode = TYPEC_PWR_MODE_USB;
> + break;
> + case UCSI_CONSTAT_PWR_OPMODE_BC:
> + port->partner_type = TYPEC_PARTNER_CHARGER;
> + port->pwr_opmode = TYPEC_PWR_MODE_BC1_2;
> + break;
> + case UCSI_CONSTAT_PWR_OPMODE_PD:
> + port->pwr_opmode = TYPEC_PWR_MODE_PD;
> + break;
> + case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_3:
> + port->pwr_opmode = TYPEC_PWR_MODE_1_5A;
> + break;
> + case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
> + port->pwr_opmode = TYPEC_PWR_MODE_3_0A;
> + break;
> + default:
> + break;
> + }
> +out:
CodingStyle suggests to do a better label naming.
> + return typec_connect(port);
> +}
> +static void ucsi_connector_change(struct work_struct *work)
> +{
> + struct ucsi_connector *con = container_of(work, struct ucsi_connector,
> + work);
> +}
> +int ucsi_init(struct ucsi *ucsi)
> +{
> + struct ucsi_control *ctrl = (void *)&ucsi->ppm->data->control;
> + struct ucsi_connector *con;
> + int ret;
> + int i;
> + for (i = 0, con = ucsi->connector; i < ucsi->cap.num_connectors;
> + i++, con++) {
> +err:
> + if (i > 0)
> + for (; i >= 0; i--, con--)
> + typec_unregister_port(con->port);
Perhaps
while (--i >= 0) {
...
}
But...
> +
> + kfree(ucsi->connector);
> + return ret;
> +}
> +struct ucsi *ucsi_register_ppm(struct device *dev, struct ucsi_ppm *ppm)
> +{
> + struct ucsi *ucsi;
> +
> + ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL);
> + if (!ucsi)
> + return ERR_PTR(-ENOMEM);
> +
> + init_completion(&ucsi->complete);
> + ucsi->dev = dev;
> + ucsi->ppm = ppm;
> +
> + return ucsi;
> +}
> +EXPORT_SYMBOL_GPL(ucsi_register_ppm);
> +
> +/**
> + * ucsi_unregister_ppm - Unregister UCSI PPM Interface
> + * @ucsi: struct ucsi associated with the PPM
> + *
> + * Unregister an UCSI PPM that was created with ucsi_register().
> + */
> +void ucsi_unregister_ppm(struct ucsi *ucsi)
> +{
> + struct ucsi_connector *con;
> + int i;
> +
> + /* Disable all notifications */
> + ucsi->ppm->data->control = UCSI_SET_NOTIFICATION_ENABLE;
> + ucsi->ppm->cmd(ucsi->ppm);
> +
> + for (i = 0, con = ucsi->connector; i < ucsi->cap.num_connectors;
> + i++, con++)
> + typec_unregister_port(con->port);
...looks a code duplication.
> +
> + kfree(ucsi->connector);
> + kfree(ucsi);
> +}
> +EXPORT_SYMBOL_GPL(ucsi_unregister_ppm);
> +#include <linux/types.h>
> +
> +/* -------------------------------------------------------------------------- */
> +
> +struct ucsi_data {
> + __u16 version;
> + __u16 RESERVED;
Small letters?
> + __u32 cci;
> + __u64 control;
> + __u32 message_in[4];
> + __u32 message_out[4];
> +} __packed;
> +/* Bits for SET_NOTIFICATION_ENABLE command */
> +#define UCSI_ENABLE_NTFY_CMD_COMPLETE BIT(0)
> +#define UCSI_ENABLE_NTFY_EXT_PWR_SRC_CHANGE BIT(1)
> +#define UCSI_ENABLE_NTFY_PWR_OPMODE_CHANGE BIT(2)
> +#define UCSI_ENABLE_NTFY_CAP_CHANGE BIT(5)
> +#define UCSI_ENABLE_NTFY_PWR_LEVEL_CHANGE BIT(6)
> +#define UCSI_ENABLE_NTFY_PD_RESET_COMPLETE BIT(7)
> +#define UCSI_ENABLE_NTFY_CAM_CHANGE BIT(8)
> +#define UCSI_ENABLE_NTFY_BAT_STATUS_CHANGE BIT(9)
> +#define UCSI_ENABLE_NTFY_PARTNER_CHANGE BIT(11)
> +#define UCSI_ENABLE_NTFY_PWR_DIR_CHANGE BIT(12)
> +#define UCSI_ENABLE_NTFY_CONNECTOR_CHANGE BIT(14)
> +#define UCSI_ENABLE_NTFY_ERROR BIT(15)
> +#define UCSI_ENABLE_NTFY_ALL 0xdbf3
Hmm... I would add the decode part of this, i.e. what kind of
notifications are excluded (and maybe why), e.g. BIT(2).
> + __u8 num_alt_modes;
> + __u8 RESERVED;
Small letters?
> + __u16 bc_version;
> + __u16 pd_version;
> + __u16 typec_version;
> +} __packed;
> + __u8 mode_support:1;
> + __u8 RESERVED_2:2;
> + __u8 latency:4;
> + __u8 RESERVED_4:4;
> +} __packed;
Ditto.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2016-02-10 11:56 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-09 17:01 [PATCH 0/3] usb: USB Type-C Class and driver for UCSI Heikki Krogerus
2016-02-09 17:01 ` [PATCH 1/3] usb: USB Type-C Connector Class Heikki Krogerus
2016-02-09 18:20 ` Greg KH
2016-02-10 10:38 ` Heikki Krogerus
2016-02-10 17:26 ` Greg KH
2016-02-11 14:07 ` Heikki Krogerus
2016-02-10 10:49 ` Oliver Neukum
2016-02-10 11:05 ` Andy Shevchenko
2016-02-10 11:11 ` Heikki Krogerus
2016-02-10 11:14 ` Andy Shevchenko
2016-02-10 11:23 ` Heikki Krogerus
2016-02-15 15:16 ` Oliver Neukum
2016-02-11 8:55 ` Felipe Balbi
2016-02-11 9:08 ` Oliver Neukum
2016-02-11 14:51 ` Heikki Krogerus
2016-02-11 14:36 ` Heikki Krogerus
2016-02-11 14:56 ` Oliver Neukum
2016-02-17 14:07 ` Oliver Neukum
2016-02-18 8:47 ` Heikki Krogerus
2016-02-18 9:21 ` Oliver Neukum
2016-02-18 13:09 ` Heikki Krogerus
2016-02-18 9:35 ` Oliver Neukum
2016-02-18 13:25 ` Heikki Krogerus
2016-02-18 13:44 ` Oliver Neukum
2016-02-18 15:13 ` Heikki Krogerus
2016-02-26 13:09 ` Heikki Krogerus
2016-02-09 17:01 ` [PATCH 2/3] usb: type-c: USB Type-C Connector System Software Interface Heikki Krogerus
2016-02-09 18:21 ` Greg KH
2016-02-10 10:30 ` Heikki Krogerus
2016-02-10 17:20 ` Greg KH
2016-02-11 13:50 ` Heikki Krogerus
2016-02-15 15:30 ` Oliver Neukum
2016-02-16 9:22 ` Heikki Krogerus
2016-02-16 13:39 ` Oliver Neukum
2016-02-17 7:58 ` Heikki Krogerus
2016-02-17 9:03 ` Oliver Neukum
2016-02-17 10:29 ` Felipe Balbi
2016-02-17 10:36 ` Oliver Neukum
2016-02-17 11:11 ` Heikki Krogerus
2016-02-17 13:36 ` Felipe Balbi
2016-02-17 14:28 ` Heikki Krogerus
2016-02-18 9:07 ` Peter Chen
2016-02-18 10:44 ` Heikki Krogerus
2016-02-18 10:37 ` Rajaram R
2016-02-18 10:47 ` Heikki Krogerus
2016-02-18 11:06 ` Rajaram R
2016-02-17 13:34 ` Felipe Balbi
2016-02-17 13:51 ` Oliver Neukum
2016-02-18 7:08 ` Felipe Balbi
2016-02-18 10:18 ` Oliver Neukum
2016-02-18 10:30 ` Felipe Balbi
2016-02-18 10:40 ` Oliver Neukum
2016-02-18 9:29 ` Peter Chen
2016-02-18 9:44 ` Oliver Neukum
2016-02-10 11:19 ` Oliver Neukum
2016-02-10 12:04 ` Heikki Krogerus
2016-02-10 11:56 ` Andy Shevchenko [this message]
2016-02-10 13:21 ` Oliver Neukum
2016-02-10 14:02 ` Andy Shevchenko
2016-02-10 15:11 ` Bjørn Mork
2016-02-11 8:26 ` Andy Shevchenko
2016-02-11 8:59 ` Bjørn Mork
2016-02-10 14:15 ` Oliver Neukum
2016-02-10 14:24 ` Andy Shevchenko
2016-02-10 15:08 ` Oliver Neukum
[not found] ` <CAHp75VfmGsskf7Cmni3b4=tCbkPsR8d3jPYiv93Lm6DM9gq1-g@mail.gmail.com>
2016-02-11 8:13 ` Fwd: " Andy Shevchenko
2016-02-11 14:10 ` Heikki Krogerus
2016-02-10 13:04 ` Oliver Neukum
2016-02-11 14:08 ` Heikki Krogerus
2016-02-09 17:01 ` [PATCH 3/3] usb: type-c: UCSI ACPI driver Heikki Krogerus
2016-02-09 18:22 ` Greg KH
2016-02-10 10:23 ` Heikki Krogerus
2016-02-17 18:53 ` [PATCH 0/3] usb: USB Type-C Class and driver for UCSI Oliver Neukum
2016-02-18 9:21 ` Heikki Krogerus
2016-02-17 19:34 ` Rajaram R
2016-02-18 11:05 ` Heikki Krogerus
2016-02-18 11:15 ` Oliver Neukum
2016-05-05 3:05 ` Guenter Roeck
2016-05-06 6:50 ` Felipe Balbi
2016-05-06 8:05 ` Guenter Roeck
2016-05-06 8:29 ` Heikki Krogerus
2016-05-06 14:10 ` Guenter Roeck
2016-05-06 8:23 ` Heikki Krogerus
2016-05-06 8:08 ` Heikki Krogerus
2016-05-06 14:08 ` Guenter Roeck
2016-05-11 3:14 ` Guenter Roeck
2016-05-11 9:40 ` Heikki Krogerus
2016-05-11 14:47 ` Guenter Roeck
2016-05-13 14:23 ` Heikki Krogerus
2016-05-13 17:48 ` Guenter Roeck
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=CAHp75VeUt_uRgxQDxzMw3uoqaRC3TDEyVt1xDSGUicACf4H-_A@mail.gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.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;
as well as URLs for NNTP newsgroup(s).