From patchwork Thu Aug 10 13:25:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Purski X-Patchwork-Id: 9893735 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 8F3DF60325 for ; Thu, 10 Aug 2017 13:26:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 805BC288EB for ; Thu, 10 Aug 2017 13:26:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74C662891A; Thu, 10 Aug 2017 13:26:04 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 953F828841 for ; Thu, 10 Aug 2017 13:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752389AbdHJN0C (ORCPT ); Thu, 10 Aug 2017 09:26:02 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:45009 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752374AbdHJN0A (ORCPT ); Thu, 10 Aug 2017 09:26:00 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20170810132557euoutp02f7263ea1de5f66e6d056fa740ff7a37e~ZfvjTYU370141901419euoutp02v; Thu, 10 Aug 2017 13:25:57 +0000 (GMT) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170810132557eucas1p289d1ce173e2e38c1f295459d52edab01~ZfvilWPOC1822718227eucas1p2R; Thu, 10 Aug 2017 13:25:57 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges4.samsung.com (EUCPMTA) with SMTP id 8F.4E.12944.4EE5C895; Thu, 10 Aug 2017 14:25:56 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170810132556eucas1p2413e372ac3494e73dd07cb941a1baa3f~Zfvh9Gxr02411924119eucas1p2X; Thu, 10 Aug 2017 13:25:56 +0000 (GMT) X-AuditID: cbfec7f4-f79ab6d000003290-0a-598c5ee4179c Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A0.E3.18832.4EE5C895; Thu, 10 Aug 2017 14:25:56 +0100 (BST) Received: from AMDC2075.DIGITAL.local ([106.120.51.25]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OUH006WL1AWWU90@eusync1.samsung.com>; Thu, 10 Aug 2017 14:25:56 +0100 (BST) From: Maciej Purski To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: airlied@linux.ie, robh+dt@kernel.org, mark.rutland@arm.com, m.szyprowski@samsung.com, architt@codeaurora.org, will.deacon@arm.com, catalin.marinas@arm.com, a.hajda@samsung.com, Laurent.pinchart@ideasonboard.com, b.zolnierkie@samsung.com, krzk@kernel.org, Maciej Purski Subject: [PATCH 1/2] drm/bridge/sii8620: add external connector handle Date: Thu, 10 Aug 2017 15:25:29 +0200 Message-id: <1502371530-32260-2-git-send-email-m.purski@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1502371530-32260-1-git-send-email-m.purski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgF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2rxflkPo8X8I0CJK1/fs1mcP7+B3aJz4hJ2i02Pr7FazDi/j8liwctbLBZr j9xlt1h6/SKTReveI+wWLz+eYHEQ8Fgzbw2jx+W+XiaP2R0zWT02repk89j+7QGrx/3u40we m5fUe/RtWcXo8XmTXABnlJtNRmpiSmqRQmpecn5KZl66rVJoiJuuhZJCXmJuqq1ShK5vSJCS QlliTimQZ2SABhycA9yDlfTtEtwyLs99zVrwQrVi48wNbA2M6+S7GDk5JARMJD7+XssKYYtJ XLi3nq2LkYtDSGAJo8T0vy2MEE4jk8TbIw+Aqjg42AS0JNa0x4PERQS6GCVuNawDK2IWWM8k 8bTzPDvIKGEBN4mzB5cxgtgsAqoSHRuusoHYvAIuEluaTzJCrJOTuHmukxnE5hRwlZg7dy3Y AiGgmjk9EhMYeRcwMqxiFEktLc5Nzy021CtOzC0uzUvXS87P3cQIjKZtx35u3sF4aWPwIUYB DkYlHt4E0e5IIdbEsuLK3EOMEhzMSiK8erE9kUK8KYmVValF+fFFpTmpxYcYTYFumsgsJZqc D4z0vJJ4QxNDc0tDI2MLC3MjIyVxXvXLTZFCAumJJanZqakFqUUwfUwcnFINjHJ70s4+emVp VBbHuuVtMfuCez1R73w37ld/v3guT5fncZ7fZ87M2N+6blb0/TiXCUKT5xy3mKct5D2tRPqN fNuijJa1qqsmCMZ+2eAl1vVRZl3Vyoap+R0Xc880uwaJzY1ZOumWfIxS+MMl/0tfnmdhk9kg UnNgykfxEu19ItrhXRPZH1Q0+CixFGckGmoxFxUnAgABLaKavAIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170810132556eucas1p2413e372ac3494e73dd07cb941a1baa3f X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Global-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTU=?= CMS-TYPE: 201P X-CMS-RootMailID: 20170810132556eucas1p2413e372ac3494e73dd07cb941a1baa3f X-RootMTR: 20170810132556eucas1p2413e372ac3494e73dd07cb941a1baa3f References: <1502371530-32260-1-git-send-email-m.purski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver should be switched on if an external connector is plugged and switched off if it is unplugged. Extcon is optional. If it is not found, the driver stays in "always-on" mode. Signed-off-by: Maciej Purski --- .../bindings/display/bridge/sil-sii8620.txt | 4 ++ drivers/gpu/drm/bridge/sil-sii8620.c | 83 +++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/display/bridge/sil-sii8620.txt b/Documentation/devicetree/bindings/display/bridge/sil-sii8620.txt index 9409d9c..1f230bf 100644 --- a/Documentation/devicetree/bindings/display/bridge/sil-sii8620.txt +++ b/Documentation/devicetree/bindings/display/bridge/sil-sii8620.txt @@ -10,6 +10,9 @@ Required properties: - clocks, clock-names: specification and name of "xtal" clock - video interfaces: Device node can contain video interface port node for HDMI encoder according to [1]. +Optional properties: + - extcon: phandle to external connector for MHL cable changes + detection [1]: Documentation/devicetree/bindings/media/video-interfaces.txt @@ -24,6 +27,7 @@ Example: reset-gpio = <&gpv7 0 0>; clocks = <&pmu_system_controller 0>; clock-names = "xtal"; + extcon = <&muic>; port { mhl_to_hdmi: endpoint { diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/sil-sii8620.c index 2d51a22..5002654 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 @@ -78,6 +79,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; + bool extcon_attached; struct list_head mt_queue; struct { int r_size; @@ -2102,6 +2107,72 @@ 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); + + if (ctx->extcon_attached) + 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); + + ctx->extcon_attached = event; + schedule_work(&ctx->extcon_wq); + + return NOTIFY_DONE; +} + +static int sii8620_extcon_init(struct sii8620 *ctx) +{ + struct extcon_dev *edev; + int ret; + + INIT_WORK(&ctx->extcon_wq, sii8620_extcon_work); + + if (!of_property_read_bool(ctx->dev->of_node, "extcon")) { + dev_info(ctx->dev, "no extcon found, switching to 'always on' mode\n"); + ctx->extcon_attached = true; + return 0; + } + + edev = extcon_get_edev_by_phandle(ctx->dev, 0); + 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_attached = extcon_get_cable_state_(edev, EXTCON_DISP_MHL); + dev_info(ctx->dev, "extcon(MHL) = %d\n", ctx->extcon_attached); + + ctx->extcon = edev; + ctx->extcon_nb.notifier_call = sii8620_extcon_notifier; + ret = devm_extcon_register_notifier(ctx->dev, 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 +2272,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_attached) + sii8620_cable_in(ctx); return 0; } @@ -2216,7 +2294,8 @@ 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_attached) + sii8620_cable_out(ctx); drm_bridge_remove(&ctx->bridge); sii8620_hw_off(ctx);