From patchwork Thu Feb 15 10:39:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10220859 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 D83FF60467 for ; Thu, 15 Feb 2018 10:40:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5D4429128 for ; Thu, 15 Feb 2018 10:40:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BACD62912D; Thu, 15 Feb 2018 10:40:29 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 322C729128 for ; Thu, 15 Feb 2018 10:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755390AbeBOKkN (ORCPT ); Thu, 15 Feb 2018 05:40:13 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:47570 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755446AbeBOKjh (ORCPT ); Thu, 15 Feb 2018 05:39:37 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180215103935euoutp01bf85612dd0d6225fb1b464347ffae589~TeZPxNUCf1203312033euoutp01P; Thu, 15 Feb 2018 10:39:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180215103935euoutp01bf85612dd0d6225fb1b464347ffae589~TeZPxNUCf1203312033euoutp01P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1518691175; bh=e6Hbjyhatxq5yAS7yLiRqxkDLvc1OnleS6HMUxpvsDU=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=VJZia74EHhBblrk2X+ei79/Y0asWBGmjsccAN1hR9G8eGDrHcwENbrjHyUiBr9k5O 9SQHlEq/FDu3KajEavrIogmTBt7DsZbqr7V6bY/JFTBmQo0zyIqKeZ0hrajjJqLLLL 1Y+24EFcjnhixYGBSjGKRBPrQMvWt8uW8m7nK/0I= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180215103933eucas1p112242b968c92d44ef5a7d31614926ced~TeZN8n-or1885518855eucas1p16; Thu, 15 Feb 2018 10:39:33 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 4C.AE.17380.263658A5; Thu, 15 Feb 2018 10:39:30 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180215103929eucas1p208a0b6b20e7b0c5ce1b99791b6707ab8~TeZJlbadH2723227232eucas1p2e; Thu, 15 Feb 2018 10:39:29 +0000 (GMT) X-AuditID: cbfec7f4-b4fc79c0000043e4-de-5a85636236d1 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DE.ED.04183.063658A5; Thu, 15 Feb 2018 10:39:29 +0000 (GMT) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P46006GJTLN2910@eusync3.samsung.com>; Thu, 15 Feb 2018 10:39:28 +0000 (GMT) From: Andrzej Hajda To: devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) Cc: Maciej Purski , Bartlomiej Zolnierkiewicz , Marek Szyprowski , Andrzej Hajda , dri-devel@lists.freedesktop.org, Inki Dae , Rob Herring , Mark Rutland , Krzysztof Kozlowski , Chanwoo Choi , Archit Taneja , Laurent Pinchart , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-usb@vger.kernel.org Subject: [RFC PATCH v2 6/6] drm/bridge/sii8620: use micro-USB cable detection logic to detect MHL Date: Thu, 15 Feb 2018 11:39:20 +0100 Message-id: <20180215103920.32017-7-a.hajda@samsung.com> X-Mailer: git-send-email 2.16.1 In-reply-to: <20180215103920.32017-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOIsWRmVeSWpSXmKPExsWy7djP87pJya1RBj/v61vcWneO1aKp4y2r xcYZ61ktrn95zmox/whQ7MrX92wWk+5PYLE4f34Du0XnxCXsFpseX2O1uLxrDpvFjPP7mCwW LWtltljw8haLxdojd9ktll6/yGTRuvcIu4Ogx5p5axg9Lvf1MnnM7pjJ6rFpVSebx/3u40we m5fUe/RtWcXo8XmTXABHFJdNSmpOZllqkb5dAlfG9/PT2Areq1U03v3E2MDYq9DFyMkhIWAi 0b64i6WLkYtDSGAFo8S9WZtYIZzPjBIHG7ewwlTN3XSNCSKxjFFi664PUM5/RolJb9exgVSx CWhK/N18E8wWEYiVeHdpFzNIEbPANxaJebPmM4EkhAWSJT4ub2AEsVkEVCUmHD/NAmLzClhI 9LzuZYZYJy9x+E0T0GoODk4BS4kp8y1A5kgIPGaT+PRgMRtEjYvEidO72SFsYYlXx7dA2TIS lyd3s0A0dDNKnNrXyQzhTGGUOP/qMhNElbXE4eMXwZ5jFuCTmLRtOjPINgkBXomONiGIEg+J ny2HoP53lLjY+ZMN4uUeRonp3fuYJjBKLWBkWMUonlpanJueWmy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Llz8rLjjtMK is+WKsxSX7onzFL12qap5Quyo14f8CmfL1ko6Xdo0Xmpz1N3Xz70442Zzuy85Op0JZbijERD Leai4kQA2SPhhFkCAAA= X-CMS-MailID: 20180215103929eucas1p208a0b6b20e7b0c5ce1b99791b6707ab8 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180215103929eucas1p208a0b6b20e7b0c5ce1b99791b6707ab8 X-RootMTR: 20180215103929eucas1p208a0b6b20e7b0c5ce1b99791b6707ab8 References: <20180215103920.32017-1-a.hajda@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 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;