linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Li Jun <jun.li@nxp.com>
Cc: robh+dt@kernel.org, mark.rutland@arm.com,
	gregkh@linuxfoundation.org, a.hajda@samsung.com,
	linux@roeck-us.net, yueyao@google.com, shufan_lee@richtek.com,
	o_leveque@orange.fr, linux-usb@vger.kernel.org,
	linux-imx@nxp.com
Subject: [v3,04/12] usb: typec: add API to get typec basic port power and data config
Date: Wed, 14 Mar 2018 11:59:02 +0200	[thread overview]
Message-ID: <20180314095902.GF30868@kuha.fi.intel.com> (raw)

Hi,

On Tue, Mar 13, 2018 at 05:34:30PM +0800, Li Jun wrote:
> +/**
> + * typec_get_power_type - Get the typec port power type
> + * @fwnode: Firmware node to get the property of
> + *
> + * This routine is used by typec hardware driver to read property
> + * port power type from the device firmware description.
> + *
> + * Returns typec_port_type if success, otherwise negative error code.
> + */
> +int typec_get_power_type(struct fwnode_handle *fwnode)
> +{
> +	const char *type_str;
> +	int ret;
> +
> +	if (!fwnode)
> +		return -EINVAL;
> +
> +	ret = fwnode_property_read_string(fwnode, "power-type", &type_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_port_types, ARRAY_SIZE(typec_port_types),
> +			    type_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_power_type);
> 
> +/**
> + * typec_get_preferred_role - Get the typec preferred power role
> + * @fwnode: Firmware node to get the property of
> + *
> + * This routine is used by typec hardware driver to read property
> + * try-power-role from the device firmware description to decide
> + * if the port can support Try.SRC or Try.SNK.
> + *
> + * Returns typec_role if success, otherwise negative error code.
> + */
> +int typec_get_preferred_role(struct fwnode_handle *fwnode)
> +{
> +	const char *type_str;
> +	int ret;
> +
> +	if (!fwnode)
> +		return -EINVAL;
> +
> +	ret = fwnode_property_read_string(fwnode, "try-power-role", &type_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_roles, ARRAY_SIZE(typec_roles), type_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_preferred_role);
> +
> +/**
> + * typec_get_data_type - Get the typec port data type
> + * @fwnode: Firmware node to get the property of
> + *
> + * This routine is used by typec hardware driver to read property
> + * port data type from the device firmware description.
> + *
> + * Returns typec_data_type if success, otherwise negative error code.
> + */
> +int typec_get_data_type(struct fwnode_handle *fwnode)
> +{
> +	const char *type_str;
> +	int ret;
> +
> +	if (!fwnode)
> +		return -EINVAL;
> +
> +	ret = fwnode_property_read_string(fwnode, "data-type", &type_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_data_types, ARRAY_SIZE(typec_data_types),
> +			    type_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_data_type);

I been thinking about this. Perhaps it's better that we don't read
any properties in these helpers. These helpers become more useful that
way, and we can use the in other places as well if needed.

So my proposal is that the callers of these functions are responsible
of reading the property values. Here we just convert the strings to
values:

int typec_find_preferred_role(const char *name)
{
	return match_string(typec_roles, ARRAY_SIZE(typec_roles), name);
}
EXPORT_SYMBOL_GPL(typec_find_preferred_role);

int typec_find_power_role(const char *name)
{
	return match_string(typec_port_types, ARRAY_SIZE(typec_data_types),
			    name);
}
EXPORT_SYMBOL_GPL(typec_find_data_role);

int typec_find_data_role(const char *name)
{
	return match_string(typec_data_types, ARRAY_SIZE(typec_data_types),
			    name);
}
EXPORT_SYMBOL_GPL(typec_find_data_role);


Thanks,

             reply	other threads:[~2018-03-14  9:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-14  9:59 Heikki Krogerus [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-03-19  9:28 [v3,04/12] usb: typec: add API to get typec basic port power and data config Jun Li
2018-03-13  9:34 Jun Li

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=20180314095902.GF30868@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=a.hajda@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jun.li@nxp.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    --cc=o_leveque@orange.fr \
    --cc=robh+dt@kernel.org \
    --cc=shufan_lee@richtek.com \
    --cc=yueyao@google.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).