From patchwork Fri May 29 12:49:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 11578505 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D2FF1392 for ; Fri, 29 May 2020 12:49:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F1F5208B8 for ; Fri, 29 May 2020 12:49:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="B/GOIXWC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725901AbgE2Mty (ORCPT ); Fri, 29 May 2020 08:49:54 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:54594 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbgE2Mtx (ORCPT ); Fri, 29 May 2020 08:49:53 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200529124952euoutp028e103d35a12cfc1a402793bee92134ad~TgLE5UxWk0941009410euoutp02X for ; Fri, 29 May 2020 12:49:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200529124952euoutp028e103d35a12cfc1a402793bee92134ad~TgLE5UxWk0941009410euoutp02X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1590756592; bh=vKKWXKKZb66zmci3zWOPhnbVvCuDMc0NgqWOz9mv0L0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B/GOIXWCzfxFJWcqgWt92wZLQ7QDwjbSdd9q6+dzA7IGFdBlF3UgZUHhBd8k+WpDR BuEclZUeWTvwT6NRzgCaHFOG1ZPUCseCXaYfLONSaTOaRfk54u9Jjtc4dMpY7bcg56 7TSPPW+gx8S0Js/mKmW/Ua4G12f5koksTkfeHspE= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200529124951eucas1p16fbbb10363ae6c91a4f31486602e7f78~TgLEY6YrO2815328153eucas1p1j; Fri, 29 May 2020 12:49:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 33.74.60698.FE401DE5; Fri, 29 May 2020 13:49:51 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200529124951eucas1p213c748fb481a37cf98918caae5e30fd2~TgLEGbgkg2891728917eucas1p2K; Fri, 29 May 2020 12:49:51 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200529124951eusmtrp185582db9a7f4f002a908e706edc6df9c~TgLEFnqxP1703417034eusmtrp1B; Fri, 29 May 2020 12:49:51 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-f2-5ed104ef29f1 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B4.80.08375.FE401DE5; Fri, 29 May 2020 13:49:51 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200529124950eusmtip135d1e103b2e67c978b9fc874ab56cba6~TgLDPzqUl1155411554eusmtip1J; Fri, 29 May 2020 12:49:50 +0000 (GMT) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mark Brown , Dmitry Osipenko Cc: Marek Szyprowski , Liam Girdwood , Lucas Stach , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Viresh Kumar , peron.clem@gmail.com, Nishanth Menon , Stephen Boyd , Vincent Guittot , Rafael Wysocki , linux-samsung-soc@vger.kernel.org, Chanwoo Choi Subject: [PATCH 1/2] regulator: extract voltage balancing code to the separate function Date: Fri, 29 May 2020 14:49:39 +0200 Message-Id: <20200529124940.10675-2-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529124940.10675-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSWUwTURT1dabTobE4VCMvLoglSCQqGNQ817gzX8TghxG1WmUEIi2mAyhE Da7URlAxKFQ0QDRIEYFSKhoXqA2NVNtStBSxBGLdIYoFXAFtB/Xv3HPuuefel0di4jv8aWSK Ip1RKmSpEkKIG1q+W+d/wtuk0QNtM1BdUQ0fFfZ6CNQx+JaPqgZeAWSz1QpQz5VOHhp+puKh 9rslBPLmmQAqsj3goWqTW4D6vj3loa6r7Th6YnHw0aizDkcq0zCG6obo1UH0HY1bQOu0pwn6 pfMeQZ8diab1z3NxOl+vBbTZdZtHe3Uhm8gE4YpEJjUlk1FGrdolTD75TLw/P+TgsTwblgNc UA0CSEgtgu+6mzA1EJJi6gaAnZ8e83yCmBoEsOZaPCd4AbyZc4lQA9Lv0JbLOb4CQI19lOCK P4a+smbgcxPUQqjuV/uFKdRRABtK7f6xGPUTg/fbZvvwZGorzP06hPkwToVDd6vNj0XUStja 6AXcfrNgVW2Tnw+gVkGnwwh8QyFlFcDm529wrmk99KrKxvFk+MGsF3B4BrRcOINzhuMA9lqr BVxxBsD2Y0XjEcvhS+sP/3EYNRfW3I3i6DXw8odfAu7mQOjqD+IOCIQFhksYR4ug6pSY654D NeZb/2Kb7Y7xFhqO5M/kHug8gG6biTgHZmn+Z5UCoAXBTAYrT2LYGAVzYAErk7MZiqQFe9Lk OvDnQ1lGzUON4MGv3UZAkUAyUVRbbJOK+bJMNktuBJDEJFNEa59apGJRoiwrm1Gm7VRmpDKs EUwncUmwKKb8/Q4xlSRLZ/YxzH5G+VflkQHTckDu7uxYjyVGcaTnYsJG0ViHRB66ZVlxcFj4 2Od1a187w760Nnw+HN1dGdpVjy/NeVFwSOdclodj2+PnbdjcpTkx4N7bWRjnYT/GeYwTFic3 VCse9smnioorS2Mj6o3SsYGVDjxL/yjSHlWRfL33oWuCYVLJt4AVISOZ2wyDsRFLWiQ4myxb GIkpWdlv5J2dukwDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDIsWRmVeSWpSXmKPExsVy+t/xu7rvWS7GGRx5zmmxccZ6VoupD5+w WVz/8pzVYvXHx4wW589vYLd4MPcmk8W3Kx1MFpd3zWGz+Nx7hNFixvl9TBZrj9xlt3jz4yyT xe15l1kszpy+xGrx79pGFouOI9+YLTZ+9XAQ9Ng56y67x6ZVnWwed67tYfPo/2vgseVqO4tH 35ZVjB7Hb2xn8vi8SS6AI0rPpii/tCRVISO/uMRWKdrQwkjP0NJCz8jEUs/Q2DzWyshUSd/O JiU1J7MstUjfLkEvo/WKUEGfXEVT73nmBsYbEl2MHBwSAiYSqxbldjFycQgJLGWUuHPxDnMX IydQXEbi5LQGVghbWOLPtS42iKJPjBJrN79jAkmwCRhKdL2FSIgItDJKnH+9ignEYRZoZZFY cGcV2ChhgXCJN39ms4HYLAKqEndPnQeL8wrYSpza8ZkRYoW8xOoNB8DinAJ2EtcuHQKLCwHV HNjRxDSBkW8BI8MqRpHU0uLc9NxiQ73ixNzi0rx0veT83E2MwJjZduzn5h2MlzYGH2IU4GBU 4uHdMPN8nBBrYllxZe4hRgkOZiURXqezp+OEeFMSK6tSi/Lji0pzUosPMZoCHTWRWUo0OR8Y z3kl8YamhuYWlobmxubGZhZK4rwdAgdjhATSE0tSs1NTC1KLYPqYODilGhj1284xsJo2NVrU nl+wMTUiYGPqaf0X/Om/ut9p93z9ItZ1MuKfU4D5zQmxjvkq83UdjvKuls/7qFrqn7Jf705G dmDavbZAzuUttx05z3LGHzs0M9m2YtK0A+wrvy8pXf1NOuvy5rtTOKTjneqOH5zpGbJ7yYn6 N7ffn2VyEF3pIzud53IVx28lluKMREMt5qLiRAD2Y4GtrwIAAA== X-CMS-MailID: 20200529124951eucas1p213c748fb481a37cf98918caae5e30fd2 X-Msg-Generator: CA X-RootMTR: 20200529124951eucas1p213c748fb481a37cf98918caae5e30fd2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200529124951eucas1p213c748fb481a37cf98918caae5e30fd2 References: <20200529124940.10675-1-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Move the coupled regulators voltage balancing code to the separate function and allow to call it from the custom regulator couplers. Signed-off-by: Marek Szyprowski --- drivers/regulator/core.c | 49 ++++++++++++++++++------------- include/linux/regulator/coupler.h | 8 +++++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 941783a14b45..370c655ad8f6 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3642,36 +3642,19 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev, return done; } -static int regulator_balance_voltage(struct regulator_dev *rdev, - suspend_state_t state) +int regulator_do_balance_voltage(struct regulator_dev *rdev, + suspend_state_t state, bool skip_coupled) { struct regulator_dev **c_rdevs; struct regulator_dev *best_rdev; struct coupling_desc *c_desc = &rdev->coupling_desc; - struct regulator_coupler *coupler = c_desc->coupler; int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev; unsigned int delta, best_delta; unsigned long c_rdev_done = 0; bool best_c_rdev_done; c_rdevs = c_desc->coupled_rdevs; - n_coupled = c_desc->n_coupled; - - /* - * If system is in a state other than PM_SUSPEND_ON, don't check - * other coupled regulators. - */ - if (state != PM_SUSPEND_ON) - n_coupled = 1; - - if (c_desc->n_resolved < n_coupled) { - rdev_err(rdev, "Not all coupled regulators registered\n"); - return -EPERM; - } - - /* Invoke custom balancer for customized couplers */ - if (coupler && coupler->balance_voltage) - return coupler->balance_voltage(coupler, rdev, state); + n_coupled = skip_coupled ? 1 : c_desc->n_coupled; /* * Find the best possible voltage change on each loop. Leave the loop @@ -3742,6 +3725,32 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, return ret; } +static int regulator_balance_voltage(struct regulator_dev *rdev, + suspend_state_t state) +{ + struct coupling_desc *c_desc = &rdev->coupling_desc; + struct regulator_coupler *coupler = c_desc->coupler; + bool skip_coupled = false; + + /* + * If system is in a state other than PM_SUSPEND_ON, don't check + * other coupled regulators. + */ + if (state != PM_SUSPEND_ON) + skip_coupled = true; + + if (c_desc->n_resolved < c_desc->n_coupled) { + rdev_err(rdev, "Not all coupled regulators registered\n"); + return -EPERM; + } + + /* Invoke custom balancer for customized couplers */ + if (coupler && coupler->balance_voltage) + return coupler->balance_voltage(coupler, rdev, state); + + return regulator_do_balance_voltage(rdev, state, skip_coupled); +} + /** * regulator_set_voltage - set regulator output voltage * @regulator: regulator source diff --git a/include/linux/regulator/coupler.h b/include/linux/regulator/coupler.h index 0212d6255e4e..5f86824bd117 100644 --- a/include/linux/regulator/coupler.h +++ b/include/linux/regulator/coupler.h @@ -62,6 +62,8 @@ int regulator_get_voltage_rdev(struct regulator_dev *rdev); int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, int max_uV, suspend_state_t state); +int regulator_do_balance_voltage(struct regulator_dev *rdev, + suspend_state_t state, bool skip_coupled); #else static inline int regulator_coupler_register(struct regulator_coupler *coupler) { @@ -92,6 +94,12 @@ static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev, { return -EINVAL; } +static inline int regulator_do_balance_voltage(struct regulator_dev *rdev, + suspend_state_t state, + bool skip_coupled) +{ + return -EINVAL; +} #endif #endif From patchwork Fri May 29 12:49:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 11578511 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DCE9139A for ; Fri, 29 May 2020 12:50:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4057A20721 for ; Fri, 29 May 2020 12:50:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="tev7GWgH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726459AbgE2Mt7 (ORCPT ); Fri, 29 May 2020 08:49:59 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:54609 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727019AbgE2Mty (ORCPT ); Fri, 29 May 2020 08:49:54 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200529124952euoutp02d5de79afe6f2b4f377402140875cf5ea~TgLFlC42s0958309583euoutp02G for ; Fri, 29 May 2020 12:49:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200529124952euoutp02d5de79afe6f2b4f377402140875cf5ea~TgLFlC42s0958309583euoutp02G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1590756592; bh=GrxDA5iIgAOI8Alt9JYWIyF3cW/T6tYVEoUzcSu9Wto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tev7GWgHS3EGdhrO9ydDAZJJS9P8Gzbx5y1Kxy8SW/8LmyyMxIKYAYEzxRHLHbqpO 06EjMPbPMubuzVV8EK1sKFWUvqKxS9Rbh6i2S6KxXcAvXvHR4UgahTmQJVbq8YnwSF HUA/+CNRziSsuKSeblM+4SsG+ks0Q88IGSEcBx0c= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200529124952eucas1p2e2ae4295379ed6c62ddb39ebaf7d139b~TgLFOpYvt1904919049eucas1p29; Fri, 29 May 2020 12:49:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 54.74.60698.0F401DE5; Fri, 29 May 2020 13:49:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200529124952eucas1p2565c598c3c0164b5dec6ed83e19148b8~TgLE21sBi1701917019eucas1p2J; Fri, 29 May 2020 12:49:52 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200529124951eusmtrp146027ea796376930b651005eb6fd9990~TgLE2I6V61722217222eusmtrp1I; Fri, 29 May 2020 12:49:51 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-f4-5ed104f03e4f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CB.CA.07950.FE401DE5; Fri, 29 May 2020 13:49:51 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200529124951eusmtip1002b54cd56840951beab382476cbf0bb~TgLEBYA4R1283312833eusmtip1v; Fri, 29 May 2020 12:49:51 +0000 (GMT) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mark Brown , Dmitry Osipenko Cc: Marek Szyprowski , Liam Girdwood , Lucas Stach , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Viresh Kumar , peron.clem@gmail.com, Nishanth Menon , Stephen Boyd , Vincent Guittot , Rafael Wysocki , linux-samsung-soc@vger.kernel.org, Chanwoo Choi Subject: [PATCH 2/2] soc: samsung: Add simple voltage coupler for Exynos5800 Date: Fri, 29 May 2020 14:49:40 +0200 Message-Id: <20200529124940.10675-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529124940.10675-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSaUhUURjlznvz5jk1+hyFuWlkDRQkuGXBbVGyBR6l0L9ESnvpQ821eWoq BGpRNlouYbmjIqRj7kvu5ahNYjouNSopppmaSxoumKbV+Mz+nfOdc+75+LgkJq0TmpG+gSGs IpDxlxNivObtT63VIt7rbtt+X4bKU0uFKGVsgkADy1NCVPTjC0BabZkIfc4aEqDVD7EC1F+f SaClx20ApWqbBai4bUSE5ta6BOhTdj+O3nf2CdGWrhxHsW2rGCpfoc8a03XpIyK6QvWIoId1 jQSdsGlLV318iNNPqlSA1gy+EtBLFQeukG7iM16sv28Yq7BxvCH2iZkdEgWPHwzf2mzBo4Da XAlIElLHYUaJsRKISSlVAKCuIwrjyTKAGSotzpMlAFM0ZQIlMNhOjFdqRXospV4AuBB9dzeR 1TAj1AsEZQeV80pCL5hS0QBW5/RspzFqA4NNvYf02IRyhoW5i4R+D5w6DNcHcP1YQjnA6aYK wJdZwKKyN5geG1COUNenBvo3IdUtgnE1aoI3XYCDzWNCHpvAGU2ViMf7YefTeJwP3ANwrLtY xJN4APtjUncqTsPh7vXtLTDqKCytt+HHTnB2uQvjj2QIB+eN+f0NYXLN852xBMY+kPLuIzBd U7Jb29LTt2Oh4USBmL9PEoB1KZOCRGCR/r8rBwAVkLGhXIA3y9kHsnesOSaACw30tvYMCqgA fz9U55ZmpRY0/7qpBhQJ5HslZWlad6mQCeMiAtQAkpjcVHKuq9NdKvFiIiJZRZCHItSf5dTA nMTlMol93rfrUsqbCWH9WDaYVfxTBaSBWRS4bTU86ddy0oWZbZL5vT5WHF2dpwvdsFSlcy/d XDamPBKNXDNGXBPyI8/bOL+7Gu0wmuaUHa+djEvbSlp5diu5dfqEYceer/ssHC6FR9Rubl4b X+vOdDqVP+fXKlsgzRSNFz080+h8o7GJwu/rbb8lMS7Ifm2UXsz1b69kSrGGy3Kc82HsLDEF x/wBdAECwUwDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRmVeSWpSXmKPExsVy+t/xu7rvWS7GGczqsrDYOGM9q8XUh0/Y LK5/ec5qsfrjY0aL8+c3sFs8mHuTyeLblQ4mi8u75rBZfO49wmgx4/w+Jou1R+6yW7z5cZbJ 4va8yywWZ05fYrX4d20ji0XHkW/MFhu/ejgIeuycdZfdY9OqTjaPO9f2sHn0/zXw2HK1ncWj b8sqRo/jN7YzeXzeJBfAEaVnU5RfWpKqkJFfXGKrFG1oYaRnaGmhZ2RiqWdobB5rZWSqpG9n k5Kak1mWWqRvl6CX0fT6JnvBI4WKf38PsjQwHpLuYuTkkBAwkXi0+Tx7FyMXh5DAUkaJJR+a GSESMhInpzWwQtjCEn+udbFBFH1ilJi3+TczSIJNwFCi6y1EQkSglVHi/OtVTCAOs0Ari8SC O6vAqoQFfCRWLvwAVMXBwSKgKvHrOgtImFfAVuLF3k1Q2+QlVm84AFbOKWAnce3SIbC4EFDN gR1NTBMY+RYwMqxiFEktLc5Nzy020itOzC0uzUvXS87P3cQIjJptx35u2cHY9S74EKMAB6MS D++GmefjhFgTy4orcw8xSnAwK4nwOp09HSfEm5JYWZValB9fVJqTWnyI0RToponMUqLJ+cCI ziuJNzQ1NLewNDQ3Njc2s1AS5+0QOBgjJJCeWJKanZpakFoE08fEwSnVwKi+ffmPvh0B32Lt lQReWy1Su7iA7ca+Dt6Vzjo753hnab98PtNE3GiXzJlz3dLlCYZcW+vMflsHh8lMmvn/p+/1 a1+NJPIDX8yIPvZY9snZHxvK/16MPuO9i3U/Z+iprW8EWoxFn3z6LbTXJTHE/sUCjctyP/qv 6Md0TF78/LDkpTW/tG7K7mxRYinOSDTUYi4qTgQAn1kQdrACAAA= X-CMS-MailID: 20200529124952eucas1p2565c598c3c0164b5dec6ed83e19148b8 X-Msg-Generator: CA X-RootMTR: 20200529124952eucas1p2565c598c3c0164b5dec6ed83e19148b8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200529124952eucas1p2565c598c3c0164b5dec6ed83e19148b8 References: <20200529124940.10675-1-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Add custom voltage regulator coupler for Exynos5800 SoCs, which require coupling between "vdd_arm" and "vdd_int" regulators. This coupler ensures that coupled regulators voltage balancing is done only when clients for each regulator (cpufreq for "vdd_arm" and devfreq for "vdd_int") apply their constraints, so the voltage values don't go beyond the bootloader-selected operation point during the boot process. This also ensures proper voltage balancing if any of those drivers is missing. Signed-off-by: Marek Szyprowski --- arch/arm/mach-exynos/Kconfig | 1 + drivers/soc/samsung/Kconfig | 3 + drivers/soc/samsung/Makefile | 1 + .../soc/samsung/exynos-regulator-coupler.c | 59 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 drivers/soc/samsung/exynos-regulator-coupler.c diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig index 76838255b5fa..f185cd3d4c62 100644 --- a/arch/arm/mach-exynos/Kconfig +++ b/arch/arm/mach-exynos/Kconfig @@ -118,6 +118,7 @@ config SOC_EXYNOS5800 bool "Samsung EXYNOS5800" default y depends on SOC_EXYNOS5420 + select EXYNOS_REGULATOR_COUPLER config EXYNOS_MCPM bool diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig index c7a2003687c7..264185664594 100644 --- a/drivers/soc/samsung/Kconfig +++ b/drivers/soc/samsung/Kconfig @@ -37,4 +37,7 @@ config EXYNOS_PM_DOMAINS bool "Exynos PM domains" if COMPILE_TEST depends on PM_GENERIC_DOMAINS || COMPILE_TEST +config EXYNOS_REGULATOR_COUPLER + bool "Exynos SoC Regulator Coupler" if COMPILE_TEST + depends on ARCH_EXYNOS || COMPILE_TEST endif diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile index edd1d6ea064d..ecc3a32f6406 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o obj-$(CONFIG_EXYNOS_PMU_ARM_DRIVERS) += exynos3250-pmu.o exynos4-pmu.o \ exynos5250-pmu.o exynos5420-pmu.o obj-$(CONFIG_EXYNOS_PM_DOMAINS) += pm_domains.o +obj-$(CONFIG_EXYNOS_REGULATOR_COUPLER) += exynos-regulator-coupler.o diff --git a/drivers/soc/samsung/exynos-regulator-coupler.c b/drivers/soc/samsung/exynos-regulator-coupler.c new file mode 100644 index 000000000000..54445918bd75 --- /dev/null +++ b/drivers/soc/samsung/exynos-regulator-coupler.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * Author: Marek Szyprowski + * + * Samsung Exynos SoC voltage coupler + */ + +#include +#include +#include +#include +#include + +static int exynos_coupler_balance_voltage(struct regulator_coupler *coupler, + struct regulator_dev *rdev, + suspend_state_t state) +{ + struct coupling_desc *c_desc = &rdev->coupling_desc; + int ret, cons_uV = 0, cons_max_uV = INT_MAX; + bool skip_coupled = false; + + /* get coupled regulator constraints */ + ret = regulator_check_consumers(c_desc->coupled_rdevs[1], &cons_uV, + &cons_max_uV, state); + if (ret < 0) + return ret; + + /* skip adjusting coupled regulator if it has no constraints set yet */ + if (cons_uV == 0) + skip_coupled = true; + + return regulator_do_balance_voltage(rdev, state, skip_coupled); +} + +static int exynos_coupler_attach(struct regulator_coupler *coupler, + struct regulator_dev *rdev) +{ + if (strcmp(rdev_get_name(rdev), "vdd_arm") == 0 || + strcmp(rdev_get_name(rdev), "vdd_int") == 0) + return 0; + + return -EINVAL; +} + +static struct regulator_coupler exynos_coupler = { + .attach_regulator = exynos_coupler_attach, + .balance_voltage = exynos_coupler_balance_voltage, +}; + +static int __init exynos_coupler_init(void) +{ + if (!of_machine_is_compatible("samsung,exynos5800")) + return 0; + + return regulator_coupler_register(&exynos_coupler); +} +arch_initcall(exynos_coupler_init);