From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753974AbcG0IP2 (ORCPT ); Wed, 27 Jul 2016 04:15:28 -0400 Received: from mga14.intel.com ([192.55.52.115]:30437 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752379AbcG0IPW (ORCPT ); Wed, 27 Jul 2016 04:15:22 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,428,1464678000"; d="asc'?scan'208";a="740347232" From: Felipe Balbi To: Bin Gao , Heikki Krogerus , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Bin Gao , Chandra Sekhar Anagani , Pranav Tipnis Subject: Re: [PATCH v2 1/2] usb: typec: Add USB Power Delivery sink port support In-Reply-To: <20160726183722.GE211765@worksta> References: <20160726183722.GE211765@worksta> User-Agent: Notmuch/0.22+58~g3a45d29 (https://notmuchmail.org) Emacs/25.0.95.2 (x86_64-pc-linux-gnu) Date: Wed, 27 Jul 2016 11:13:43 +0300 Message-ID: <87wpk7fqh4.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Bin Gao writes: > This patch implements a simple USB Power Delivery sink port state machine. > It assumes the hardware only handles PD packet transmitting and receiving > over the CC line of the USB Type-C connector. The state transition is > completely controlled by software. This patch only implement the sink port > function and it doesn't support source port and port swap yet. > > This patch depends on these two patches: > https://lkml.org/lkml/2016/6/29/349 > https://lkml.org/lkml/2016/6/29/350 > > Signed-off-by: Bin Gao > Changes in v2: > - Removed work queue so messages are directly handled in phy driver's in= terrupt context > - used pr_debug instead of pr_info for message dump > - Converted PD driver to tristate and typec driver is independent of it this should be after the tearline (---) below. We don't want this in changelog ;-) > +static void handle_source_cap(struct pd_sink_port *port, u8 msg_revision, > + u8 nr_objs, u8 *buf) > +{ > + int i; > + u32 *obj; > + u8 type; > + struct pd_source_cap *cap =3D port->source_caps; > + > + /* > + * The PD spec revision included in SOURCE_CAPABILITY message is the > + * highest revision that the Source supports. > + */ > + port->pd_rev =3D msg_revision; > + > + /* > + * First we need to save all PDOs - they may be used in the future. > + * USB PD spec says we must use PDOs in the most recent > + * SOURCE_CAPABILITY message. Here we replace old PDOs with new ones. > + */ > + port->nr_source_caps =3D 0; > + for (i =3D 0; i < nr_objs; i++) { > + obj =3D (u32 *)(buf + i * PD_OBJ_SIZE); > + type =3D (*obj >> SOURCE_CAP_TYPE_BIT) & SOURCE_CAP_TYPE_MASK; > + switch (type) { > + case PS_TYPE_FIXED: > + cap->ps_type =3D PS_TYPE_FIXED; > + cap->fixed =3D *(struct pd_pdo_src_fixed *)obj; > + break; > + case PS_TYPE_VARIABLE: > + cap->ps_type =3D PS_TYPE_VARIABLE; > + cap->variable =3D *(struct pd_pdo_variable *)obj; > + break; > + case PS_TYPE_BATTERY: > + cap->ps_type =3D PS_TYPE_BATTERY; > + cap->battery =3D *(struct pd_pdo_battery *)obj; > + break; > + default: /* shouldn't come here */ > + pr_err("Invalid Source Capability type: %u.\n", type); > + continue; > + } > + port->nr_source_caps++; > + cap++; > + } > + > + if (port->nr_source_caps =3D=3D 0) { > + pr_err("There is no valid PDOs in SOURCE_CAPABILITY message\n"); > + return; > + } > + > + /* If a contract is not established, we need send a REQUEST message */ > + if (port->state =3D=3D PD_SINK_STATE_WAIT_FOR_SRC_CAP) { this is wrong. Read the fluxchart in figure 8-42. Source can decide to send another Source Capability before receiving our Good CRC and we need to work with that. This state check is, at a minimum, wrong. I'd actually just go ahead and remove it. > + if (!send_request(port)) > + port->state =3D PD_SINK_STATE_REQUEST_SENT; > + } > +} =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXmG03AAoJEIaOsuA1yqREyLkP/2xje7Cx8ecMTBY1eudZsdWK W5Hh4az7XnEQGsYSt8wptm4VYcEfG6xnpkRt/tzPM3WTvoxE/jTnohrDNgoZIyWG 3Omt0agbM4bDwOv+V2nXck2IMTvrqwJfSvAW1rDco6vk95epg/X2hqGbJtylMxDN rG8A0LNFfyuwvLGOdISPe4BEnCIaWJq8xv7NHjQ/WUtmqwiX5fR/asOiE45r/dIC zt9K7M/3bhyb0RaWP6HmxzITvPEArRGBnCgF8IIdI9fx2qZbv1pcVbhn9EvPTgVf o+NklTTInmEmXgXn8POw8k3bZ5OkbLWEmsuiTI4gfRKVEy3O4uMybU0YMxRTopHL jRhbFP+UGTJ245NVRE5HYXgp0+B/fn9Rmx/29OGjqWNgwEOxwQPt+WQn4KV04v2s GTNe19oz0gSWOQ88wBWpjXheE+YlXwdR49vuhL+9omDbflyBHuZZEzF7zjhCJ0xm lM8xfSFndxpd9r+E/6Y7rmfKrnNstNwKX/uvG4nG863U5Cor9GN0CMExYFU3tN40 KGZkbdtzLrQLfiAxrModPKzttkohvizc4eqsn4yaMKZj7BT+lVVYlh6tnbAJbf1N RoOa3SZPT/i5sBX6uSGtgW2I0K0X4Ff7ZlQM4sf9BgP4Xgs1tZYvPqgLBNFFKY18 SNfLnuiS+tWdMNDVdmtP =W6cb -----END PGP SIGNATURE----- --=-=-=--