From: Hans de Goede <hdegoede@redhat.com>
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>
Cc: Hans de Goede <hdegoede@redhat.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] extcon: intel-cht-wc: Add support for monitoring external USB Type-C controller
Date: Fri, 21 Apr 2017 15:01:19 +0200 [thread overview]
Message-ID: <20170421130119.6187-5-hdegoede@redhat.com> (raw)
In-Reply-To: <20170421130119.6187-1-hdegoede@redhat.com>
On some boards the Whiskey Cove PMIC is combined with an external USB
Type-C controller, in this case extcon consumers should use the Type-C
extcon state, except when the USB Type-C controller detects a current
limit of 500 mA which may indicate USB-C to USB-A cable at which point
the extcon consumer should use the Whiskey Cove's BC-1.2 detection's
state.
Since the Type-C controller info is incomplete and needs to be
supplemented with the BC1.2 detection result in some cases, this
commit makes the intel-cht-wc extcon driver monitor the extcon device
registered by the Type-C controller and report that as our extcon state
except when BC-1.2 detection should be used. This allows extcon
consumers on these boards to keep monitoring only the intel-cht-wc extcon
and then get complete extcon info from that, which combines the Type-C
and BC-1.2 info.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/extcon/extcon-intel-cht-wc.c | 96 ++++++++++++++++++++++++++++++------
1 file changed, 80 insertions(+), 16 deletions(-)
diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
index 684f6b2..e510188 100644
--- a/drivers/extcon/extcon-intel-cht-wc.c
+++ b/drivers/extcon/extcon-intel-cht-wc.c
@@ -15,6 +15,7 @@
* more details.
*/
+#include <linux/acpi.h>
#include <linux/extcon.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
@@ -88,6 +89,7 @@ static const unsigned int cht_wc_extcon_cables[] = {
EXTCON_CHG_USB_CDP,
EXTCON_CHG_USB_DCP,
EXTCON_CHG_USB_ACA,
+ EXTCON_CHG_USB_FAST,
EXTCON_NONE,
};
@@ -95,6 +97,9 @@ struct cht_wc_extcon_data {
struct device *dev;
struct regmap *regmap;
struct extcon_dev *edev;
+ struct extcon_dev *usbc;
+ struct notifier_block usbc_nb;
+ struct work_struct work;
unsigned int previous_cable;
bool usb_host;
};
@@ -224,8 +229,32 @@ static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext,
extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host);
}
-static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
+static void cht_wc_extcon_usb_c_event(struct work_struct *work)
{
+ struct cht_wc_extcon_data *ext =
+ container_of(work, struct cht_wc_extcon_data, work);
+ unsigned int cable = EXTCON_NONE;
+
+ if (extcon_get_state(ext->usbc, EXTCON_CHG_USB_SDP) > 0) {
+ /*
+ * USB-C to USB-A cable ? Try BC1.2 charger detection from
+ * WC PMIC, ignore charger detection errors.
+ */
+ cable = cht_wc_extcon_get_charger(ext, true);
+ } else if (extcon_get_state(ext->usbc, EXTCON_CHG_USB_CDP) > 0) {
+ cable = EXTCON_CHG_USB_CDP;
+ } else if (extcon_get_state(ext->usbc, EXTCON_CHG_USB_FAST) > 0) {
+ cable = EXTCON_CHG_USB_FAST;
+ }
+
+ ext->usb_host = (extcon_get_state(ext->usbc, EXTCON_USB_HOST) > 0);
+ cht_wc_extcon_set_state(ext, cable);
+}
+
+static void cht_wc_extcon_pwrsrc_event(struct work_struct *work)
+{
+ struct cht_wc_extcon_data *ext =
+ container_of(work, struct cht_wc_extcon_data, work);
int ret, pwrsrc_sts, id;
unsigned int cable = EXTCON_NONE;
/* Ignore errors in host mode, as the 5v boost converter is on then */
@@ -258,7 +287,7 @@ static irqreturn_t cht_wc_extcon_isr(int irq, void *data)
return IRQ_NONE;
}
- cht_wc_extcon_pwrsrc_event(ext);
+ schedule_work(&ext->work);
ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ, irqs);
if (ret) {
@@ -269,6 +298,17 @@ static irqreturn_t cht_wc_extcon_isr(int irq, void *data)
return IRQ_HANDLED;
}
+static int cht_wc_extcon_usbc_evt(struct notifier_block *nb,
+ unsigned long event, void *param)
+{
+ struct cht_wc_extcon_data *ext =
+ container_of(nb, struct cht_wc_extcon_data, usbc_nb);
+
+ schedule_work(&ext->work);
+
+ return NOTIFY_OK;
+}
+
static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable)
{
int ret, mask, val;
@@ -300,6 +340,15 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
ext->regmap = pmic->regmap;
ext->previous_cable = EXTCON_NONE;
+ if (acpi_dev_present("INT33FE", NULL, -1)) {
+ ext->usbc = extcon_get_extcon_dev("fusb302");
+ if (!ext->usbc)
+ return -EPROBE_DEFER;
+
+ dev_info(&pdev->dev,
+ "Using FUSB302 extcon for USB Type-C cable info\n");
+ }
+
/* Initialize extcon device */
ext->edev = devm_extcon_dev_allocate(ext->dev, cht_wc_extcon_cables);
if (IS_ERR(ext->edev))
@@ -335,25 +384,40 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
/* Route D+ and D- to PMIC for initial charger detection */
cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
- /* Get initial state */
- cht_wc_extcon_pwrsrc_event(ext);
-
- ret = devm_request_threaded_irq(ext->dev, irq, NULL, cht_wc_extcon_isr,
- IRQF_ONESHOT, pdev->name, ext);
- if (ret) {
- dev_err(ext->dev, "Error requesting interrupt: %d\n", ret);
- goto disable_sw_control;
- }
+ if (ext->usbc) {
+ INIT_WORK(&ext->work, cht_wc_extcon_usb_c_event);
+ ext->usbc_nb.notifier_call = cht_wc_extcon_usbc_evt;
+ ret = devm_extcon_register_notifier_all(&pdev->dev, ext->usbc,
+ &ext->usbc_nb);
+ if (ret) {
+ dev_err(&pdev->dev,
+ "Error registering usbc extcon notifier: %d\n",
+ ret);
+ goto disable_sw_control;
+ }
+ } else {
+ INIT_WORK(&ext->work, cht_wc_extcon_pwrsrc_event);
+ ret = devm_request_threaded_irq(ext->dev, irq, NULL,
+ cht_wc_extcon_isr, IRQF_ONESHOT,
+ pdev->name, ext);
+ if (ret) {
+ dev_err(ext->dev, "Error requesting irq: %d\n", ret);
+ goto disable_sw_control;
+ }
- /* Unmask irqs */
- ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ_MASK,
+ /* Unmask irqs */
+ ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ_MASK,
(int)~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_ID_GND |
CHT_WC_PWRSRC_ID_FLOAT));
- if (ret) {
- dev_err(ext->dev, "Error writing irq-mask: %d\n", ret);
- goto disable_sw_control;
+ if (ret) {
+ dev_err(ext->dev, "Error writing irq-mask: %d\n", ret);
+ goto disable_sw_control;
+ }
}
+ /* Get initial state */
+ schedule_work(&ext->work);
+
platform_set_drvdata(pdev, ext);
return 0;
--
2.9.3
next prev parent reply other threads:[~2017-04-21 13:01 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170421130123epcas4p12e891d305aa2b4126089e691d15c6659@epcas4p1.samsung.com>
2017-04-21 13:01 ` [PATCH 1/5] extcon: Allow extcon drivers to specify the extcon name Hans de Goede
2017-04-21 13:01 ` [PATCH 2/5] extcon: Add FUSB302 USB TYPE-C controller support Hans de Goede
2017-04-21 18:51 ` Andy Shevchenko
2017-04-24 11:02 ` Heikki Krogerus
2017-04-24 13:12 ` Guenter Roeck
2017-05-12 21:22 ` Hans de Goede
2017-05-16 12:07 ` Heikki Krogerus
2017-05-16 22:24 ` Hans de Goede
2017-05-17 11:45 ` Heikki Krogerus
2017-05-17 14:47 ` USB TYPE-C support and the power-supply subsys (was Re: [PATCH 2/5] extcon: Add FUSB302 USB TYPE-C controller support) Hans de Goede
2017-05-18 8:37 ` Heikki Krogerus
2017-05-18 11:50 ` Heikki Krogerus
2017-05-19 20:12 ` Hans de Goede
2017-05-19 20:15 ` Hans de Goede
2017-05-22 14:56 ` Heikki Krogerus
2017-05-16 22:52 ` [PATCH 2/5] extcon: Add FUSB302 USB TYPE-C controller support Guenter Roeck
2017-04-21 23:23 ` kbuild test robot
2017-05-23 9:27 ` Chanwoo Choi
2017-05-24 12:23 ` Andy Shevchenko
2017-04-21 13:01 ` [PATCH 3/5] extcon: intel-cht-wc: Default to SDP on regmap io errors Hans de Goede
2017-04-21 13:01 ` [PATCH 4/5] extcon: intel-cht-wc: Add new cht_wc_extcon_set_state helper Hans de Goede
2017-04-21 18:54 ` Andy Shevchenko
2017-04-21 13:01 ` Hans de Goede [this message]
2017-04-21 18:55 ` [PATCH 5/5] extcon: intel-cht-wc: Add support for monitoring external USB Type-C controller Andy Shevchenko
2017-04-24 14:25 ` Heikki Krogerus
2017-05-23 9:26 ` [PATCH 1/5] extcon: Allow extcon drivers to specify the extcon name Chanwoo Choi
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=20170421130119.6187-5-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=cw00.choi@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=myungjoo.ham@samsung.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
all inboxes | Powered by JetHome®