From patchwork Thu Sep 28 13:07:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 9976045 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 CA95C6037E for ; Thu, 28 Sep 2017 13:08:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB4FA295B9 for ; Thu, 28 Sep 2017 13:08:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFB93295C5; Thu, 28 Sep 2017 13:08:32 +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 2A17A295B9 for ; Thu, 28 Sep 2017 13:08:31 +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=E34SENkNyAQTFsE8WrzC+skkb0YJudDQIRbAsy60xgg=; b=DNdAyVP4E2gQEs2ObYww/pdN1J v4TIxy+RfsMK/YhuBlUh3Emlx/MqGX4DlqfQCzIsuPXm3VMg0Eb6KRCHxqxXZvY0GZBOERuymckJn bRrOhU/ReVQBYfmKyJXXyccFsoI5j9adMrLqyI9ocm0HBMLYxj/tP9Tk607I7FFvi3bn3oJEh0bSm i3wyALtL0hIKSRHAulp1wbunuIBX3SMAkI58FdJsmDwnc+HCwI+X+3svgmDES5OcgLymk4NhKjLzy H23LyqHIYIKwEpMp48JKb8ZOuXOGvczB7XnBYYuUfyCsLQ+XscF0714r804RLqJPKTlZIAW++Dzoy VQNLirpA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dxYYF-00034c-6e; Thu, 28 Sep 2017 13:08:27 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dxYXp-0002kd-4t for linux-arm-kernel@lists.infradead.org; Thu, 28 Sep 2017 13:08:04 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20170928130738euoutp0230efafb244a5a5cb84fd0d4a6c61a2d7~oiGi3Acp50569405694euoutp02t; Thu, 28 Sep 2017 13:07:38 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170928130737eucas1p1a3448de7254c71238357ab773d893c80~oiGiJOfM42014820148eucas1p1n; Thu, 28 Sep 2017 13:07:37 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges5.samsung.com (EUCPMTA) with SMTP id 3C.F8.12743.914FCC95; Thu, 28 Sep 2017 14:07:37 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170928130737eucas1p15a82a6fd0f9175075249e02c072e6b0d~oiGhgn98x0806408064eucas1p1O; Thu, 28 Sep 2017 13:07:37 +0000 (GMT) X-AuditID: cbfec7f5-f79d06d0000031c7-bf-59ccf41963b0 Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D2.BD.18832.914FCC95; Thu, 28 Sep 2017 14:07:37 +0100 (BST) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OWZ004HER4LMZ40@eusync2.samsung.com>; Thu, 28 Sep 2017 14:07:37 +0100 (BST) From: Andrzej Hajda To: devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) Subject: [RFC PATCH 4/4] drm/bridge/sii8620: use micro-USB cable detection logic to detect MHL Date: Thu, 28 Sep 2017 15:07:30 +0200 Message-id: <20170928130730.8747-5-a.hajda@samsung.com> X-Mailer: git-send-email 2.14.1 In-reply-to: <20170928130730.8747-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgleLIzCtJLcpLzFFi42LZduzneV3JL2ciDZr+q1ncWneO1aKp4y2r xcYZ61ktrn95zmox/whQ7MrX92wWk+5PYLE4f34Du0XnxCXsFpseX2O1uLxrDpvFjPP7mCwW LWtltljw8haLxdojd9ktll6/yGTRuvcIu4Ogx5p5axg9Lvf1MnnM7pjJ6rFpVSebx/3u40we m5fUe/RtWcXo8XmTXABHFJdNSmpOZllqkb5dAlfGhMXLWAsWqFdMOnGRqYFxh0IXIyeHhICJ xKbNZxghbDGJC/fWs3UxcnEICSxllGhtfsoGkhAS+MwocWtdPEzDgZdLoIqWMUqc2vgVyvnP KHGl6QLYKDYBTYm/m2+CdYsIxEq8u7SLGaSIWeAbi8S8WfOZQBLCAgkSs+ctZQaxWQRUJdbO vgwW5xUwl5jXepkFYp28xLkHt8FqOAUsJLYsPMUEMkhC4DWbxP9pB1ghilwkXj/cygZhC0u8 Or6FHcKWkejsO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Rmp6YWpBbBZJk4OKUaGGX/W5j/vtLpf0zje1Tjs4V7Ckx4MheFfrV7 KtXZZppWaLsixMrv+Yq3q+ODptnW983yy1uw8eAb81VS6SzzpyfGTr9rfZ7R/EG1YqX9A8Zv 0ktubjsXcOZlt5DwmTO5U59ciucIu6r7ztCvXDduecatX+YGTLu1+dbX/hGKb1j82Pi3Yd41 HyWW4oxEQy3mouJEAB9RNVdmAgAA X-CMS-MailID: 20170928130737eucas1p15a82a6fd0f9175075249e02c072e6b0d X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRvsgrw=?= =?UTF-8?B?7ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRtTYW1z?= =?UTF-8?B?dW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-CMS-RootMailID: 20170928130737eucas1p15a82a6fd0f9175075249e02c072e6b0d X-RootMTR: 20170928130737eucas1p15a82a6fd0f9175075249e02c072e6b0d References: <20170928130730.8747-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170928_060801_357542_3FB8F63D X-CRM114-Status: GOOD ( 19.64 ) 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 | 98 ++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/sil-sii8620.c index 5131bfb94f06..6f40cbc2445e 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 @@ -78,6 +80,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; @@ -2102,6 +2108,78 @@ static void sii8620_cable_in(struct sii8620 *ctx) enable_irq(to_i2c_client(ctx->dev)->irq); } +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_graph_get_remote_node(musb, -1, 0); + of_node_put(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); @@ -2201,13 +2279,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; } @@ -2216,9 +2301,16 @@ static int sii8620_remove(struct i2c_client *client) { struct sii8620 *ctx = i2c_get_clientdata(client); - disable_irq(to_i2c_client(ctx->dev)->irq); + 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); - sii8620_hw_off(ctx); return 0; }