From patchwork Wed Jan 31 13:44:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10194021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D72B60380 for ; Wed, 31 Jan 2018 13:45:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59BCC285E8 for ; Wed, 31 Jan 2018 13:45:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E0DA2861D; Wed, 31 Jan 2018 13:45:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A8226285E8 for ; Wed, 31 Jan 2018 13:45:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-reply-to:Message-id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Nz1XtfsiOQitqsh+f3ZzQsExEPazsiT3syfQz3Q37HI=; b=PgGgqm15UcuhRIVS+96q0PUjTk 4aQjWklqnyw3fttqtw0TeIvt/0KnrA3YkDMb8dlUX01OLOCCsVJr36u0XBORx1JFG3N7BpVqXVg+v yxbJxhBiM3SuodmejCzW7677huaCvhvnugsTkj4I0t8njgY/ob2LkZVTuy+eLrUyuiDqoFrtoXu8Q 502xGzjf3L+5K6I7zJTH07g+qZbTQz7OZb3PoYiuddknl1bPUsC6WQufjofrDvXezGO8PDhpXVAFl W4E2zEY9LDQ1WE8WP+Ycq3uDDvkRIoQd+mBldYdf8HmmXMElFWMVu3mTnkjTYrqY0CDswZW5p/vrU A0X5X6Tw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egshg-00078h-6u; Wed, 31 Jan 2018 13:45:32 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1egshR-0005yq-7e for linux-arm-kernel@lists.infradead.org; Wed, 31 Jan 2018 13:45:19 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180131134502euoutp010d3b7abfcb3a25e147b22a277cbb85c7~O6P37xcFl2415124151euoutp01E; Wed, 31 Jan 2018 13:45:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180131134502euoutp010d3b7abfcb3a25e147b22a277cbb85c7~O6P37xcFl2415124151euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1517406302; bh=rSoY+eBtc97H0Xhaq9dKN4qM33oA8HyZfl9HjMFVbdQ=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=PWm8S5OPmAFUfdDxvrQ2/rmX+PSTZKrRHMHHii5nn/oDsiQnHQQrYc2KMXrgWMhiE VsW7Mhazw3fol7JSUOfuBmbpaiAe7puLhlO+hWJOT/1bEl8Yrj7gqdVAvKomxZ1+IV Q75FHCAWrThWs7LlgKPWGOb/3GpGOpJBswMvIHGY= Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180131134501eucas1p164e38ee7cebd9bb11d198c6530612bf1~O6P3DgRla2975129751eucas1p1f; Wed, 31 Jan 2018 13:45:01 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3.samsung.com (EUCPMTA) with SMTP id 1D.94.12867.C58C17A5; Wed, 31 Jan 2018 13:45:00 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180131134500eucas1p1bb313876bc8ea81a46113f29c1d4ce54~O6P2IBdzW1268512685eucas1p1T; Wed, 31 Jan 2018 13:45:00 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-b2-5a71c85cfe8d Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 40.B2.20118.C58C17A5; Wed, 31 Jan 2018 13:45:00 +0000 (GMT) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P3F00KEJA6V2O00@eusync1.samsung.com>; Wed, 31 Jan 2018 13:44:59 +0000 (GMT) From: Andrzej Hajda To: devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) Subject: [RFC PATCH v2 5/5] drm/bridge/sii8620: use micro-USB cable detection logic to detect MHL Date: Wed, 31 Jan 2018 14:44:35 +0100 Message-id: <20180131134435.12216-6-a.hajda@samsung.com> X-Mailer: git-send-email 2.15.1 In-reply-to: <20180131134435.12216-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0gUYRSG/XYuO4oj07jUh0bKgoWKWljyVRYFBkP1o8sPcTFy1ElF18uu K2lgJmnrbTXbyC1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tbKbLHg5S0Wi7VH7rJbLL1+kcmide8RdgdBjzXz1jB6XO7rZfKY3TGT1WPTqk42j/vdx5k8 Ni+p9+jbsorR4/MmuQCOKC6blNSczLLUIn27BK6MSytmsha8V6u4teQTewNjr0IXIyeHhICJ xPF1qxkhbDGJC/fWs3UxcnEICSxhlFhy8gsThNPIJHH51G5WkCo2AU2Jv5tvsoHYIgKxEm9P fWYGKWIW+MEicf3kTrCEsECyxMVPfWANLAKqEkdbnzCB2LwCFhK/F89kgVgnLzFhSxOYzSlg KXFvxR6wXiGgmn+bGtgmMPIuYGRYxSiSWlqcm55bbKRXnJhbXJqXrpecn7uJERjW24793LKD setd8CFGAQ5GJR5ezoqCKCHWxLLiytxDjBIczEoivN9iCqOEeFMSK6tSi/Lji0pzUosPMUpz sCiJ8/buWR0pJJCeWJKanZpakFoEk2Xi4JRqYNzM/FMtY21Z+NWb0Up3Zkkr6MdPV+vctaN3 0k0htmuv/58/XinU53tUoyBw+xLdGJOl5kdc/QuCp52RbAvn9OOQCny77PmS09OaF3oIu3yI LZhYlbsqrPzGUc/FM3Mt1s9zfBxy2qbxstjjlx/dt0gd9Ttcz8a0xaHiiyfzBf31zeznrtdN XKXEUpyRaKjFXFScCAB1f6obZwIAAA== X-CMS-MailID: 20180131134500eucas1p1bb313876bc8ea81a46113f29c1d4ce54 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180131134500eucas1p1bb313876bc8ea81a46113f29c1d4ce54 X-RootMTR: 20180131134500eucas1p1bb313876bc8ea81a46113f29c1d4ce54 References: <20180131134435.12216-1-a.hajda@samsung.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Inki Dae , Archit Taneja , linux-samsung-soc@vger.kernel.org, Laurent Pinchart , Chanwoo Choi , Bartlomiej Zolnierkiewicz , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Maciej Purski , Andrzej Hajda , Rob Herring , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Maciej Purski Currently MHL chip must be turned on permanently to detect MHL cable. It duplicates micro-USB controller's (MUIC) functionality and consumes unnecessary power. Lets use extcon attached to MUIC to enable MHL chip only if it detects MHL cable. Signed-off-by: Maciej Purski Signed-off-by: Andrzej Hajda --- This is rework of the patch by Maciej with following changes: - use micro-USB port bindings to get extcon, instead of extcon property, - fixed remove sequence, - fixed extcon get state logic. Code finding extcon node is hacky IMO, I guess ultimately it should be done via some framework (maybe even extcon), or at least via helper, I hope it can stay as is until the proper solution will be merged. Signed-off-by: Andrzej Hajda --- drivers/gpu/drm/bridge/sil-sii8620.c | 97 ++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/sil-sii8620.c index 9e785b8e0ea2..565cc352ca81 100644 --- a/drivers/gpu/drm/bridge/sil-sii8620.c +++ b/drivers/gpu/drm/bridge/sil-sii8620.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include #include @@ -81,6 +83,10 @@ struct sii8620 { struct edid *edid; unsigned int gen2_write_burst:1; enum sii8620_mt_state mt_state; + struct extcon_dev *extcon; + struct notifier_block extcon_nb; + struct work_struct extcon_wq; + int cable_state; struct list_head mt_queue; struct { int r_size; @@ -2175,6 +2181,77 @@ static void sii8620_init_rcp_input_dev(struct sii8620 *ctx) ctx->rc_dev = rc_dev; } +static void sii8620_cable_out(struct sii8620 *ctx) +{ + disable_irq(to_i2c_client(ctx->dev)->irq); + sii8620_hw_off(ctx); +} + +static void sii8620_extcon_work(struct work_struct *work) +{ + struct sii8620 *ctx = + container_of(work, struct sii8620, extcon_wq); + int state = extcon_get_state(ctx->extcon, EXTCON_DISP_MHL); + + if (state == ctx->cable_state) + return; + + ctx->cable_state = state; + + if (state > 0) + sii8620_cable_in(ctx); + else + sii8620_cable_out(ctx); +} + +static int sii8620_extcon_notifier(struct notifier_block *self, + unsigned long event, void *ptr) +{ + struct sii8620 *ctx = + container_of(self, struct sii8620, extcon_nb); + + schedule_work(&ctx->extcon_wq); + + return NOTIFY_DONE; +} + +static int sii8620_extcon_init(struct sii8620 *ctx) +{ + struct extcon_dev *edev; + struct device_node *musb, *muic; + int ret; + + /* get micro-USB connector node */ + musb = of_graph_get_remote_node(ctx->dev->of_node, 1, -1); + /* next get micro-USB Interface Controller node */ + muic = of_get_next_parent(musb); + + if (!muic) { + dev_info(ctx->dev, "no extcon found, switching to 'always on' mode\n"); + return 0; + } + + edev = extcon_get_edev_by_of_node(muic); + of_node_put(muic); + if (IS_ERR(edev)) { + if (PTR_ERR(edev) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_err(ctx->dev, "Invalid or missing extcon\n"); + return PTR_ERR(edev); + } + + ctx->extcon = edev; + ctx->extcon_nb.notifier_call = sii8620_extcon_notifier; + INIT_WORK(&ctx->extcon_wq, sii8620_extcon_work); + ret = extcon_register_notifier(edev, EXTCON_DISP_MHL, &ctx->extcon_nb); + if (ret) { + dev_err(ctx->dev, "failed to register notifier for MHL\n"); + return ret; + } + + return 0; +} + static inline struct sii8620 *bridge_to_sii8620(struct drm_bridge *bridge) { return container_of(bridge, struct sii8620, bridge); @@ -2307,13 +2384,20 @@ static int sii8620_probe(struct i2c_client *client, if (ret) return ret; + ret = sii8620_extcon_init(ctx); + if (ret < 0) { + dev_err(ctx->dev, "failed to initialize EXTCON\n"); + return ret; + } + i2c_set_clientdata(client, ctx); ctx->bridge.funcs = &sii8620_bridge_funcs; ctx->bridge.of_node = dev->of_node; drm_bridge_add(&ctx->bridge); - sii8620_cable_in(ctx); + if (!ctx->extcon) + sii8620_cable_in(ctx); return 0; } @@ -2322,8 +2406,15 @@ static int sii8620_remove(struct i2c_client *client) { struct sii8620 *ctx = i2c_get_clientdata(client); - disable_irq(to_i2c_client(ctx->dev)->irq); - sii8620_hw_off(ctx); + if (ctx->extcon) { + extcon_unregister_notifier(ctx->extcon, EXTCON_DISP_MHL, + &ctx->extcon_nb); + flush_work(&ctx->extcon_wq); + if (ctx->cable_state > 0) + sii8620_cable_out(ctx); + } else { + sii8620_cable_out(ctx); + } drm_bridge_remove(&ctx->bridge); return 0;