All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Oliver Neukum <oneukum@suse.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@kernel.org>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/3] usb: type-c: USB Type-C Connector System Software Interface
Date: Wed, 10 Feb 2016 14:04:44 +0200	[thread overview]
Message-ID: <20160210120444.GH5270@kuha.fi.intel.com> (raw)
In-Reply-To: <1455103193.8878.10.camel@suse.com>

On Wed, Feb 10, 2016 at 12:19:53PM +0100, Oliver Neukum wrote:
> 
> > +static int ucsi_run_cmd(struct ucsi *ucsi, void *data, size_t size)
> > +{
> > +	int status;
> > +	int ret;
> > +
> > +	dev_vdbg(ucsi->dev, "%s control 0x%llx\n", __func__,
> > +		 ucsi->ppm->data->control);
> > +
> > +	ret = ucsi->ppm->cmd(ucsi->ppm);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* REVISIT: We may need to set UCSI_CCI_CMD_COMPLETE flag here */
> > +	wait_for_completion(&ucsi->complete);
> > +
> > +	status = ucsi->status;
> > +	if (status != UCSI_ERROR && size)
> > +		memcpy(data, ucsi->ppm->data->message_in, size);
> > +
> > +	ret = ucsi_ack(ucsi, UCSI_ACK_CMD);
> > +	if (ret)
> > +		goto out;
> > +
> > +	if (status == UCSI_ERROR) {
> > +		u16 error;
> > +
> > +		ucsi->ppm->data->control = UCSI_GET_ERROR_STATUS;
> > +		ret = ucsi->ppm->cmd(ucsi->ppm);
> > +		if (ret)
> > +			goto out;
> > +
> > +		wait_for_completion(&ucsi->complete);
> > +
> > +		/* Something has really gone wrong */
> > +		if (ucsi->status == UCSI_ERROR) {
> > +			ret = -ENODEV;
> > +			goto out;
> > +		}
> > +
> > +		memcpy(&error, ucsi->ppm->data->message_in, sizeof(error));
> > +
> > +		ret = ucsi_ack(ucsi, UCSI_ACK_CMD);
> > +		if (ret)
> > +			goto out;
> > +
> > +		switch (error) {
> > +		case UCSI_ERROR_INVALID_CON_NUM:
> > +			ret = -ENXIO;
> > +			break;
> > +		case UCSI_ERROR_INCOMPATIBLE_PARTNER:
> > +		case UCSI_ERROR_CC_COMMUNICATION_ERR:
> > +		case UCSI_ERROR_CONTRACT_NEGOTIATION_FAIL:
> > +			ret = -EIO;
> > +			break;
> 
> This looks like you mapped all the interesting error condition
> on a single error code and gave out other error codes to
> conditions of lesser importance.

OK, I'll fix those.

> > +		case UCSI_ERROR_DEAD_BATTERY:
> > +			dev_warn(ucsi->dev, "Dead Battery Condition!\n");
> > +			ret = -EPERM;
> > +			break;
> > +		case UCSI_ERROR_UNREGONIZED_CMD:
> > +		case UCSI_ERROR_INVALID_CMD_ARGUMENT:
> > +		default:
> > +			ret = -EINVAL;
> > +			break;
> > +		}
> > +	}
> > +out:
> > +	ucsi->ppm->data->control = 0;
> > +	return ret;
> > +}
> 
> [..]
> 
> > +/**
> > + * ucsi_init - Initialize an UCSI Interface
> > + * @ucsi: The UCSI Interface
> > + *
> > + * Registers all the USB Type-C ports governed by the PPM of @ucsi and enables
> > + * all the notifications from the PPM.
> > + */
> > +int ucsi_init(struct ucsi *ucsi)
> > +{
> > +	struct ucsi_control *ctrl = (void *)&ucsi->ppm->data->control;
> > +	struct ucsi_connector *con;
> > +	int ret;
> > +	int i;
> > +
> > +	/* Enable basic notifications */
> > +	ctrl->cmd = UCSI_SET_NOTIFICATION_ENABLE;
> > +	ctrl->data = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;
> > +	ret = ucsi_run_cmd(ucsi, NULL, 0);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* Get PPM capabilities */
> > +	ctrl->cmd = UCSI_GET_CAPABILITY;
> > +	ret = ucsi_run_cmd(ucsi, &ucsi->cap, sizeof(ucsi->cap));
> > +	if (ret)
> > +		return ret;
> > +
> > +	ucsi->connector = kcalloc(ucsi->cap.num_connectors,
> > +				  sizeof(struct ucsi_connector), GFP_KERNEL);
> > +	if (!ucsi->connector)
> > +		return -ENOMEM;
> > +
> > +	for (i = 0, con = ucsi->connector; i < ucsi->cap.num_connectors;
> > +	     i++, con++) {
> > +		struct typec_capability *cap = &con->typec_cap;
> > +		struct ucsi_connector_status constat;
> > +
> > +		/* Get connector capability */
> > +		ctrl->cmd = UCSI_GET_CONNECTOR_CAPABILITY;
> > +		ctrl->data = i + 1;
> > +		ret = ucsi_run_cmd(ucsi, &con->cap, sizeof(con->cap));
> > +		if (ret)
> > +			goto err;
> > +
> > +		/* Register the connector */
> > +
> > +		if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DRP)
> > +			cap->type = TYPEC_PORT_DRP;
> > +		else if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DFP)
> > +			cap->type = TYPEC_PORT_DFP;
> > +		else if (con->cap.op_mode & UCSI_CONCAP_OPMODE_UFP)
> > +			cap->type = TYPEC_PORT_UFP;
> > +
> > +		cap->usb_pd = !!(ucsi->cap.attributes &
> > +				       UCSI_CAP_ATTR_USB_PD);
> > +		cap->audio_accessory = !!(con->cap.op_mode &
> > +					  UCSI_CONCAP_OPMODE_AUDIO_ACCESSORY);
> > +		cap->debug_accessory = !!(con->cap.op_mode &
> > +					  UCSI_CONCAP_OPMODE_DEBUG_ACCESSORY);
> > +
> > +		/* TODO: Alt modes */
> > +
> > +		cap->dr_swap = ucsi_dr_swap;
> > +		cap->pr_swap = ucsi_pr_swap;
> > +
> > +		con->port = typec_register_port(ucsi->dev, cap);
> > +		if (IS_ERR(con->port)) {
> > +			ret = PTR_ERR(con->port);
> > +			goto err;
> > +		}
> > +
> > +		con->num = i + 1;
> > +		con->ucsi = ucsi;
> > +		INIT_WORK(&con->work, ucsi_connector_change);
> 
> You init the work later. Does this depend on the firmware
> generating no events before they are enabled? Depending on firmware
> is a bad idea.

If there is a real risk of getting connector change events before we
have enabled them, I think the only thing we can do is add checks to
ucsi_interrupt() to make sure that we don't try to handle events from
connectors that are not yet initialized.


Thanks,

-- 
heikki

  reply	other threads:[~2016-02-10 12:04 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 [this message]
2016-02-10 11:56   ` Andy Shevchenko
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=20160210120444.GH5270@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=oneukum@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.