From: Bin Gao <bin.gao@linux.intel.com>
To: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
Bin Gao <bin.gao@intel.com>,
Chandra Sekhar Anagani <chandra.sekhar.anagani@intel.com>,
Pranav Tipnis <pranav.tipnis@intel.com>
Subject: Re: [PATCH v2 1/2] usb: typec: Add USB Power Delivery sink port support
Date: Wed, 27 Jul 2016 10:31:32 -0700 [thread overview]
Message-ID: <20160727173132.GA169011@worksta> (raw)
In-Reply-To: <1469611273.2408.2.camel@suse.com>
On Wed, Jul 27, 2016 at 11:21:13AM +0200, Oliver Neukum wrote:
> On Tue, 2016-07-26 at 11:37 -0700, Bin Gao wrote:
> > +#define MAKE_HEADER(port, header, msg, objs) \
> > +do { \
> > + header->type = msg; \
> > + header->data_role = PD_DATA_ROLE_UFP; \
> > + header->revision = port->pd_rev; \
> > + header->power_role = PD_POWER_ROLE_SINK; \
> > + header->id = roll_msg_id(port); \
> > + header->nr_objs = objs; \
> > + header->extended = PD_MSG_NOT_EXTENDED; \
> > +} while (0)
> > +
> > +static struct pd_sink_port *sink_ports[MAX_NR_SINK_PORTS];
> > +static int nr_ports;
> > +
> > +BLOCKING_NOTIFIER_HEAD(pd_sink_notifier_list);
> > +
> > +static char *state_strings[] = {
> > + "WAIT_FOR_SOURCE_CAPABILITY",
> > + "REQUEST_SENT",
> > + "ACCEPT_RECEIVED",
> > + "POWER_SUPPLY_READY",
> > +};
> > +
> > +/* Control messages */
> > +static char *cmsg_strings[] = {
> > + "GOODCRC", /* 1 */
> > + "GOTOMIN", /* 2 */
> > + "ACCEPT", /* 3 */
> > + "REJECT", /* 4 */
> > + "PING", /* 5 */
> > + "PS_RDY", /* 6 */
> > + "GET_SRC_CAP", /* 7 */
> > + "GET_SINK_CAP", /* 8 */
> > + "DR_SWAP", /* 9 */
> > + "PR_SWAP", /* 10 */
> > + "VCONN_SWAP", /* 11 */
> > + "WAIT", /* 12 */
> > + "SOFT_RESET", /* 13 */
> > + "RESERVED", /* 14 */
> > + "RESERVED", /* 15 */
> > + "NOT_SUPPORTED", /* 16 */
> > + "GET_SOURCE_CAP_EXTENDED", /* 17 */
> > + "GET_STATUS", /* 18 */
> > + "FR_SWAP", /* 19 */
> > + /* RESERVED 20 - 31 */
> > +};
> > +
> > +/* Data messages */
> > +static char *dmsg_strings[] = {
> > + "SOURCE_CAP", /* 1 */
> > + "REQUEST", /* 2 */
> > + "BIST", /* 3 */
> > + "SINK_CAP", /* 4 */
> > + "BATTERY_STATUS", /* 5 */
> > + "ALERT", /* 6 */
> > + "RESERVED", /* 7 */
> > + "RESERVED", /* 8 */
> > + "RESERVED", /* 9 */
> > + "RESERVED", /* 10 */
> > + "RESERVED", /* 11 */
> > + "RESERVED", /* 12 */
> > + "RESERVED", /* 13 */
> > + "RESERVED", /* 14 */
> > + "VENDOR_DEFINED", /* 15 */
> > + /* RESERVED 16 - 31 */
> > +};
> > +
> > +static char *state_to_string(enum pd_sink_state state)
> > +{
> > + if (state < ARRAY_SIZE(state_strings))
> > + return state_strings[state];
> > + else
> > + return NULL;
> > +}
> > +
> > +static char *msg_to_string(bool is_cmsg, u8 msg)
> > +{
> > + int nr = is_cmsg ? ARRAY_SIZE(cmsg_strings) :
> > ARRAY_SIZE(dmsg_strings);
> > +
> > + if (msg <= nr)
> > + return is_cmsg ? cmsg_strings[msg - 1] :
> > dmsg_strings[msg - 1];
> > + else
> > + return "RESERVED";
> > +}
> > +
> > +static void print_message(int port, bool is_cmsg, u8 msg, bool recv)
> > +{
> > + pr_debug("sink port %d: %s message %s %s\n", port,
> > + is_cmsg ? "Control" : "Data",
> > + msg_to_string(is_cmsg, msg),
> > + recv ? "received" : "sent)");
> > +}
> > +
> > +static inline bool fixed_ps_equal(struct sink_ps *p1,
> > + struct sink_ps *p2)
> > +{
> > + return p1->ps_type == p2->ps_type &&
> > + p1->ps_fixed.voltage_fixed ==
> > p2->ps_fixed.voltage_fixed &&
> > + p1->ps_fixed.current_default ==
> > p2->ps_fixed.current_default;
> > +}
> > +
> > +/* The message ID increments each time we send out a new message */
> > +static u8 roll_msg_id(struct pd_sink_port *port)
> > +{
> > + u8 msg_id = port->msg_id;
> > +
> > + if (msg_id == PD_MSG_ID_MAX)
> > + msg_id = PD_MSG_ID_MIN;
> > + else
> > + msg_id++;
> > +
> > + port->msg_id = msg_id;
> > + return msg_id;
> > +}
> > +
>
> These pieces of code are completely generic. They should be shared
> among drivers. Please move them into the include files.
>
> Regards
> Oliver
>
>
They are only internally used by this driver (USB PD state machine driver).
And they are not used by drivers (typicall USB Type-C phy drivers) which
use APIs exposed by this driver. So I think it's not appropriate to move
to include files.
prev parent reply other threads:[~2016-07-27 17:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-26 18:37 [PATCH v2 1/2] usb: typec: Add USB Power Delivery sink port support Bin Gao
2016-07-27 8:13 ` Felipe Balbi
2016-07-27 17:32 ` Bin Gao
2016-07-27 9:21 ` Oliver Neukum
2016-07-27 17:31 ` Bin Gao [this message]
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=20160727173132.GA169011@worksta \
--to=bin.gao@linux.intel.com \
--cc=bin.gao@intel.com \
--cc=chandra.sekhar.anagani@intel.com \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oneukum@suse.com \
--cc=pranav.tipnis@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 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.