From patchwork Tue Feb 27 07:11:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10244435 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 5F12A602DC for ; Tue, 27 Feb 2018 07:15:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47A582A2E7 for ; Tue, 27 Feb 2018 07:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AAD12A321; Tue, 27 Feb 2018 07:15:31 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 A30F12A2E7 for ; Tue, 27 Feb 2018 07:15:30 +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=pgnblTA+T7mNi5Q2KhS1NzBl0DS77IHxTuKo3zTWRbE=; b=FN6JPvuxREeOdu5iX7oCeZ7dbn A0P+o2i/bRVy5ODb+f/vnIhqBMYMXMoN6Ci6fcs9rMUNK60khrhwR92FIlvXAx0i8qFk7yFwW2NrN dGyM9lJnhhV/Sx5yFFiOdh8uxh/ESG7JcPkE9NMg1A0oaXj/MckNG8nMFdVDtiSIlN/DgoO/RH4sW HaQbmZ6bKGYprdl7BVxRnhpXC7D3oXIr/Q6bqZDJgFcOIVG+ZkwgiQz7/oNkEmNoNt7N96tWUoCyE wutRHzsAGz74ryl94XUnyWT9hKJWYhcKet+NiT2+lhTZ0n91ecZqNoe7sCyFzPxqjVxEaUsi/X90E 2pWaXvzQ==; 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 1eqZTt-0003lP-F6; Tue, 27 Feb 2018 07:15:21 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqZQZ-0001AT-0Y for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 07:12:00 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180227071143euoutp0226ccdca888e87c6e04841bf87e98ef17~XHTLpKdCh2547425474euoutp020; Tue, 27 Feb 2018 07:11:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180227071143euoutp0226ccdca888e87c6e04841bf87e98ef17~XHTLpKdCh2547425474euoutp020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1519715503; bh=sl+Z3IvAwbq5YUxXIli0d9uh4s0GnT1JQ6gINSbqPoI=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=VEzlrA/oTQH96DuEPhf+H4vQQeTc37GNmtdeGr+yc53MLkEQ5r9K1XCjlcWhILKiJ jX1C+7HVCqVC+X8cM6H3V0rNGeACw6jhXTc/nSEKAsBwRGy31sqlke+WaecKWnFi9h fln7aj8eP5v2zKHjF2K78gnsFIch4vIBTNf42N/Y= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180227071142eucas1p250cccd2e4786a293042c8f73a174dd37~XHTKzLn3n1944919449eucas1p29; Tue, 27 Feb 2018 07:11:42 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id F2.98.17380.EA4059A5; Tue, 27 Feb 2018 07:11:42 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180227071142eucas1p10203dac2558db034a4a3287220213601~XHTKGVMAK2996729967eucas1p1S; Tue, 27 Feb 2018 07:11:42 +0000 (GMT) X-AuditID: cbfec7f4-6f9ff700000043e4-85-5a9504ae17ac Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D6.BC.04178.DA4059A5; Tue, 27 Feb 2018 07:11:41 +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 <0P4S00AJMRZD4P00@eusync1.samsung.com>; Tue, 27 Feb 2018 07:11:41 +0000 (GMT) From: Andrzej Hajda To: devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) Subject: [PATCH v5 6/6] drm/bridge/sii8620: use micro-USB cable detection logic to detect MHL Date: Tue, 27 Feb 2018 08:11:34 +0100 Message-id: <20180227071134.28063-7-a.hajda@samsung.com> X-Mailer: git-send-email 2.16.2 In-reply-to: <20180227071134.28063-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGIsWRmVeSWpSXmKPExsWy7djPc7rrWKZGGVzfpWRxa905Voumjres FhtnrGe1uP7lOavF/CNAsStf37NZTLo/g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mq8emVZ1sHve7jzN5 bF5S79G3ZRWjx+dNcgEcUVw2Kak5mWWpRfp2CVwZR9buYC5oV694MvEOSwPjPIUuRk4OCQET iTfHLrOB2EICSxglLv9U7GLkArIbmSTetc1nBEmwCWhK/N18E6xIRCBW4u2pz8wgRcwCP1gk rp/cCZTg4BAWiJe41OgOUsMioCqx6VIDWD2vgIXEuatzmCGWyUssPHsVzOYUsJTYP+0M1GIL ifudx1gnMPIsYGRYxSiSWlqcm55bbKhXnJhbXJqXrpecn7uJERi624793LyD8dLG4EOMAhyM Sjy8M+SmRAmxJpYVV+YeYpTgYFYS4V25eHKUEG9KYmVValF+fFFpTmrxIUZpDhYlcd7zBpVR QgLpiSWp2ampBalFMFkmDk6pBsaShstzDqh7GH3gC5XXeHNb7K7Y1Qyh/hf9f70kNn17GfEr 3qDyYbhA5MP8I5f8eTK75h/8kMyq6tzg/eWJeV+129XZ+xkOnbF5qpgodZv7UT6j0dKtGTtO POhcfJfP8P62rvrJ5t4vJmR2Pdi1PbTBKe718wk3bW9fvLIz+vDkogmswp9PydxRYinOSDTU Yi4qTgQAEoG0sFkCAAA= X-CMS-MailID: 20180227071142eucas1p10203dac2558db034a4a3287220213601 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180227071142eucas1p10203dac2558db034a4a3287220213601 X-RootMTR: 20180227071142eucas1p10203dac2558db034a4a3287220213601 References: <20180227071134.28063-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_231155_333913_CCA19417 X-CRM114-Status: GOOD ( 18.97 ) 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 Reviewed-by: Chanwoo Choi Reviewed-by: Chanwoo Choi --- v5: updated extcon API 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..62b0adabcac2 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_find_edev_by_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;