Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4003725imj; Tue, 19 Feb 2019 13:26:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IYiL9B/GLIEosAEbirkdM6BGvW5R4YLXRJekeJAbwATrnd2bTyRB0MNiDcnAhXBXhcEfd2l X-Received: by 2002:a17:902:7405:: with SMTP id g5mr23415642pll.230.1550611567486; Tue, 19 Feb 2019 13:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550611567; cv=none; d=google.com; s=arc-20160816; b=N59+DypgZcywmJT+/eRvnI4Wf9p8jOZIPylhRCJ2DXd9XFQiWrIErXMSsk4ydiY3jX Y2UJIhj+IHVCtT2P5hVzOWELImdE4t1Cfs1mIGVEbSbWsTDn+fUOaJl+K2SRlW+wpsXN 0VRu1UyeOHla7OXOFMRIISkEYCexpP2lg0vl++BuhupC58hQ6pu/l1wj3Q6NHJMaIh13 jpD0CqF1IR+vbKo6PjqeN1Gv0eJbfcYl0mIl3L2qq3C5MYLMr0IhVJQkBOZbguknipRe +iPHqaf8XTSozIZ7e8RVDmjgjBIg0PPgMNkjKmLw6aJjDKRcXzcKcyuJk/H4hOt92Ewn oNHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ms2tRmhgh7YfcmvnmAX6PNIwDOg54reqN7wxeDE3+AA=; b=geLnrbgYzPFnOQJY08dlUuMSMvzvPyzjuxfQZ5DtGS+Q8hwNy3xq6lkNWxQOL+ig7+ JEQyT70TcHPEw9a75N+v1ziYlQMn8LWGIYJbunJElFpbUdWQnGF/1MbfIGi7PgIgTdRi x3yHhUSN/FiIyMNQInHyHmaIL1Ulygnz2c2Eg7yS0kPKUAW2TCrUdER8sA+bYfc4bVlf Wx+wi5baZ7yFh1SZXsW144Ed+vVoDe0JFrgBjQ5aK6k84s8NFBRSFhP270+mmkqjdAuQ /BcWjD9+KMKQEyBDGfbrNmwGc778f50Vth7EkR+TjBvE9G21l8ylAKLPxcwsEe46Jx2O Benw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nIZgUdQ6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k74si11127010pfb.32.2019.02.19.13.25.51; Tue, 19 Feb 2019 13:26:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nIZgUdQ6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbfBSVYv (ORCPT + 99 others); Tue, 19 Feb 2019 16:24:51 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36453 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbfBSVYv (ORCPT ); Tue, 19 Feb 2019 16:24:51 -0500 Received: by mail-wr1-f66.google.com with SMTP id o17so23607786wrw.3 for ; Tue, 19 Feb 2019 13:24:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ms2tRmhgh7YfcmvnmAX6PNIwDOg54reqN7wxeDE3+AA=; b=nIZgUdQ6ogeKoCSTVws8IMHkQXW2ifFvlnVAg7lALMhMGlxMK1afCZJ03AvrknLMsi sESlJACPQfmV9x3crfCrkahfg7m9BFURdjbev8UkyoC3uWEwJ21vwV1yxIuQ5fsmSIzQ 3gsGAWgar6lPar6U3svBUF7bl12RKdGyprsEpUx9I136SguT5NLKAN+g6KmafhBAIRxC ikezTdZFyk4JQk7OGgOE8sl5cv30FVAQB1JxKITavIwY9szgGaPNPw0IMeMqvd6nJTl2 elTb4iQdy+BBZuxcO9CwRGHRB+YCdQwYViwON+3sVFF/jrNFEluf8JydzTgCxokDU93E GjVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ms2tRmhgh7YfcmvnmAX6PNIwDOg54reqN7wxeDE3+AA=; b=WHqnryOlr0CRaF4r3UThhDJKgBDbwJ2nC5D9dHaAuuCCQjciGOxWzDGfKd0iELkM7a k1jmpqRbsa/4454hZUOVHbxMjm6quUIvmVBUqKqfxlqsB9sZxTb88GTDpHlwffwJlhDP QfR9wZDCtQKnNNFZrkwIb7BFXB67ezcuJXYzJru1eWXwTS6AIX2uU38AmZhZ+bRyfgL8 1NE3it5sQ91m8ufsSpbZoV5AzDtcfZ6eOLlidL32xJbv6QagEyxT4Gfez+Vnnbf1Njih Jt2sP7Ar5/T+7BhyIcuwX1MdjUOlSSSp2BLgfgrsss+Ag648pVORamaluuPg0bOhJM/j Tblg== X-Gm-Message-State: AHQUAuYTYW6vYfLV4giB7gHJfKVznoxqRyR0tMh/YnTIETcFVzdrzmsj 8Zswf3ZTnaqL9+egRU9oyqbqH2+q X-Received: by 2002:a5d:550f:: with SMTP id b15mr23409869wrv.251.1550611488595; Tue, 19 Feb 2019 13:24:48 -0800 (PST) Received: from localhost.localdomain ([46.216.153.243]) by smtp.gmail.com with ESMTPSA id n11sm12311758wrw.60.2019.02.19.13.24.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Feb 2019 13:24:47 -0800 (PST) Received: from jek by localhost.localdomain with local (Exim 4.92-RC4) (envelope-from ) id 1gwCsf-00053Z-9W; Wed, 20 Feb 2019 00:24:45 +0300 From: Yauhen Kharuzhy To: linux-kernel@vger.kernel.org Cc: MyungJoo Ham , Chanwoo Choi , Hans de Goede , Andy Shevchenko , Yauhen Kharuzhy Subject: [PATCH v2 1/2] extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode Date: Wed, 20 Feb 2019 00:24:40 +0300 Message-Id: <20190219212441.19391-2-jekhor@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219212441.19391-1-jekhor@gmail.com> References: <20190219212441.19391-1-jekhor@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whiskey Cove Cherry Trail PMIC requires disabling OTG host mode before of charger detection procedure. Do this by manipulationg of CHGRCTRL1 register. Source: APCI DSDT code of Lenovo Yoga Book YB1-X91L and open-sourced Intel's drivers. Signed-off-by: Yauhen Kharuzhy Reviewed-by: Hans de Goede --- drivers/extcon/extcon-intel-cht-wc.c | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index 5ef215297101..4f6ba249bc30 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -29,7 +29,16 @@ #define CHT_WC_CHGRCTRL0_DBPOFF BIT(6) #define CHT_WC_CHGRCTRL0_CHR_WDT_NOKICK BIT(7) -#define CHT_WC_CHGRCTRL1 0x5e17 +#define CHT_WC_CHGRCTRL1 0x5e17 +#define CHT_WC_CHGRCTRL1_DBPEN_MASK BIT(7) +#define CHT_WC_CHGRCTRL1_OTGMODE BIT(6) +#define CHT_WC_CHGRCTRL1_FTEMP_EVENT BIT(5) +#define CHT_WC_CHGRCTRL1_FUSB_INLMT_1500 BIT(4) +#define CHT_WC_CHGRCTRL1_FUSB_INLMT_900 BIT(3) +#define CHT_WC_CHGRCTRL1_FUSB_INLMT_500 BIT(2) +#define CHT_WC_CHGRCTRL1_FUSB_INLMT_150 BIT(1) +#define CHT_WC_CHGRCTRL1_FUSB_INLMT_100 BIT(0) + #define CHT_WC_USBSRC 0x5e29 #define CHT_WC_USBSRC_STS_MASK GENMASK(1, 0) @@ -198,6 +207,29 @@ static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext, dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret); } +static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext, + bool enable) +{ + unsigned int chgrctrl1; + int ret; + + ret = regmap_read(ext->regmap, CHT_WC_CHGRCTRL1, &chgrctrl1); + if (ret) { + dev_err(ext->dev, "Error reading CHGRCTRL1 reg: %d\n", ret); + return; + } + + if (enable) + chgrctrl1 |= CHT_WC_CHGRCTRL1_OTGMODE; + else + chgrctrl1 &= ~(CHT_WC_CHGRCTRL1_OTGMODE); + + ret = regmap_write(ext->regmap, CHT_WC_CHGRCTRL1, chgrctrl1); + if (ret) + dev_err(ext->dev, + "Error writing CHGRCTRL1 OTG mode bit: %d\n", ret); +} + /* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */ static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext, unsigned int cable, bool state) @@ -222,10 +254,14 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) id = cht_wc_extcon_get_id(ext, pwrsrc_sts); if (id == USB_ID_GND) { + cht_wc_extcon_set_otgmode(ext, true); + /* The 5v boost causes a false VBUS / SDP detect, skip */ goto charger_det_done; } + cht_wc_extcon_set_otgmode(ext, false); + /* Plugged into a host/charger or not connected? */ if (!(pwrsrc_sts & CHT_WC_PWRSRC_VBUS)) { /* Route D+ and D- to PMIC for future charger detection */ -- 2.20.1