From: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org,
peter.chen-3arQi8VN3Tc@public.gmane.org,
aisheng.dong-3arQi8VN3Tc@public.gmane.org,
jun.li-3arQi8VN3Tc@public.gmane.org,
linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 04/12] staging: typec: tcpci: support port config passed via dt
Date: Tue, 26 Sep 2017 08:45:19 +0800 [thread overview]
Message-ID: <1506386727-16370-5-git-send-email-jun.li@nxp.com> (raw)
In-Reply-To: <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
User can define the typec port properties in tcpci node to setup
the port config.
Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
drivers/staging/typec/tcpci.c | 89 +++++++++++++++++++++++++++++++++++++++----
include/linux/usb/tcpm.h | 6 +--
2 files changed, 85 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 4636804..0119453 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -425,17 +425,92 @@ static const struct regmap_config tcpci_regmap_config = {
.max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */
};
-static const struct tcpc_config tcpci_tcpc_config = {
- .type = TYPEC_PORT_DFP,
- .default_role = TYPEC_SINK,
-};
-
+/* Populate struct tcpc_config from device-tree */
static int tcpci_parse_config(struct tcpci *tcpci)
{
+ struct tcpc_config *tcfg;
+ int ret = -EINVAL;
+
tcpci->controls_vbus = true; /* XXX */
- /* TODO: Populate struct tcpc_config from ACPI/device-tree */
- tcpci->tcpc.config = &tcpci_tcpc_config;
+ tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
+ GFP_KERNEL);
+ if (!tcpci->tcpc.config)
+ return -ENOMEM;
+
+ tcfg = tcpci->tcpc.config;
+
+ /* Get port-type */
+ ret = typec_get_port_type(tcpci->dev);
+ if (ret < 0) {
+ dev_err(tcpci->dev, "typec port type is NOT correct!\n");
+ return ret;
+ }
+ tcfg->type = ret;
+
+ if (tcfg->type == TYPEC_PORT_UFP)
+ goto sink;
+
+ /* Get source PDO */
+ tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev,
+ "src-pdos", NULL, 0);
+ if (tcfg->nr_src_pdo <= 0) {
+ dev_err(tcpci->dev, "typec source pdo is missing!\n");
+ return -EINVAL;
+ }
+
+ tcfg->src_pdo = devm_kzalloc(tcpci->dev,
+ sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL);
+ if (!tcfg->src_pdo)
+ return -ENOMEM;
+
+ ret = device_property_read_u32_array(tcpci->dev, "src-pdos",
+ tcfg->src_pdo, tcfg->nr_src_pdo);
+ if (ret) {
+ dev_err(tcpci->dev, "Failed to read src pdo!\n");
+ return -EINVAL;
+ }
+
+ if (tcfg->type == TYPEC_PORT_DFP)
+ return 0;
+
+ /* Get the preferred power role for drp */
+ ret = typec_get_power_role(tcpci->dev);
+ if (ret < 0) {
+ dev_err(tcpci->dev, "typec preferred role is wrong!\n");
+ return ret;
+ }
+ tcfg->default_role = ret;
+sink:
+ /* Get sink power capability */
+ tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev,
+ "snk-pdos", NULL, 0);
+ if (tcfg->nr_snk_pdo <= 0) {
+ dev_err(tcpci->dev, "typec sink pdo is missing!\n");
+ return -EINVAL;
+ }
+
+ tcfg->snk_pdo = devm_kzalloc(tcpci->dev,
+ sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);
+ if (!tcfg->snk_pdo)
+ return -ENOMEM;
+
+ ret = device_property_read_u32_array(tcpci->dev, "snk-pdos",
+ tcfg->snk_pdo, tcfg->nr_snk_pdo);
+ if (ret) {
+ dev_err(tcpci->dev, "Failed to read sink pdo!\n");
+ return -EINVAL;
+ }
+
+ if (device_property_read_u32(tcpci->dev, "max-snk-mv",
+ &tcfg->max_snk_mv) ||
+ device_property_read_u32(tcpci->dev, "max-snk-ma",
+ &tcfg->max_snk_ma) ||
+ device_property_read_u32(tcpci->dev, "op-snk-mw",
+ &tcfg->operating_snk_mw)) {
+ dev_err(tcpci->dev, "Failed to read sink capability!\n");
+ return -EINVAL;
+ }
return 0;
}
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index 073197f..a67cf77 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -76,10 +76,10 @@ enum tcpm_transmit_type {
* @alt_modes: List of supported alternate modes
*/
struct tcpc_config {
- const u32 *src_pdo;
+ u32 *src_pdo;
unsigned int nr_src_pdo;
- const u32 *snk_pdo;
+ u32 *snk_pdo;
unsigned int nr_snk_pdo;
const u32 *snk_vdo;
@@ -154,7 +154,7 @@ struct tcpc_mux_dev {
* @mux: Pointer to multiplexer data
*/
struct tcpc_dev {
- const struct tcpc_config *config;
+ struct tcpc_config *config;
int (*init)(struct tcpc_dev *dev);
int (*get_vbus)(struct tcpc_dev *dev);
--
2.6.6
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-09-26 0:45 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-26 0:45 [PATCH 00/12] staging: typec: tcpci: move out of staging Li Jun
[not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 0:45 ` [PATCH 01/12] usb: typec: add API to get port type and preferred role Li Jun
[not found] ` <1506386727-16370-2-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 8:02 ` Heikki Krogerus
[not found] ` <20170926080231.GB14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
2017-09-26 9:55 ` Jun Li
2017-09-26 13:20 ` Guenter Roeck
2017-09-26 0:45 ` [PATCH 02/12] usb: typec: add basic typec properties Li Jun
[not found] ` <1506386727-16370-3-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 8:23 ` Heikki Krogerus
[not found] ` <20170926082300.GC14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
2017-09-26 10:09 ` Jun Li
2017-09-26 0:45 ` [PATCH 03/12] staging: typec: tcpci: add documentation for tcpci Li Jun
2017-09-26 0:45 ` Li Jun [this message]
[not found] ` <1506386727-16370-5-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:32 ` [PATCH 04/12] staging: typec: tcpci: support port config passed via dt Guenter Roeck
[not found] ` <bb854ecf-fad7-2c2a-1972-5c4cabb970f2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:14 ` Jun Li
2017-09-26 0:45 ` [PATCH 05/12] staging: typec: tcpci: register port before request irq Li Jun
[not found] ` <1506386727-16370-6-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:33 ` Guenter Roeck
[not found] ` <da64a379-f9bc-5ad8-44a5-f61c4419e1e7-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:16 ` Jun Li
2017-09-26 0:45 ` [PATCH 06/12] staging: typec: tcpci: enable vbus detection Li Jun
[not found] ` <1506386727-16370-7-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:37 ` Guenter Roeck
[not found] ` <6cbb9cb2-206d-64e3-9e91-77edce855fdd-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:17 ` Jun Li
2017-09-26 0:45 ` [PATCH 07/12] typec: tcpm: add starting value for drp toggling Li Jun
[not found] ` <1506386727-16370-8-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:42 ` Guenter Roeck
[not found] ` <ceae0f45-5d14-8e7f-3258-aa2e28fcf9bc-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:25 ` Jun Li
2017-09-26 0:45 ` [PATCH 08/12] staging: typec: tcpci: correct " Li Jun
2017-09-26 0:45 ` [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached Li Jun
[not found] ` <1506386727-16370-10-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 7:16 ` Guenter Roeck
[not found] ` <9c461105-fa96-3989-5a95-b9f82b154ea2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 9:53 ` Jun Li
[not found] ` <DB4PR04MB07689A95430FA6F4AA219539897B0-tLF+feb1Bz6HC8XOQgzeLs9NdZoXdze2vxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-26 13:20 ` Guenter Roeck
[not found] ` <e79d8143-1187-f3c4-6030-ecf28e3d2fff-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 13:57 ` Jun Li
2017-09-26 0:45 ` [PATCH 10/12] staging: typec: tcpci: update set_cc for different state Li Jun
[not found] ` <1506386727-16370-11-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:49 ` Guenter Roeck
[not found] ` <8ef676a1-4c2b-cea7-ad79-c50fb8d091fb-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:39 ` Jun Li
2017-09-26 0:45 ` [PATCH 11/12] staging: typec: tcpci: Only touch target bit when enable vconn Li Jun
2017-09-26 0:45 ` [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging Li Jun
[not found] ` <1506386727-16370-13-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 6:57 ` Greg KH
[not found] ` <20170926065749.GE6250-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-09-26 7:16 ` 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=1506386727-16370-5-git-send-email-jun.li@nxp.com \
--to=jun.li-3arqi8vn3tc@public.gmane.org \
--cc=aisheng.dong-3arQi8VN3Tc@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org \
--cc=peter.chen-3arQi8VN3Tc@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
/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).