From patchwork Mon Feb 19 15:43:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Purski X-Patchwork-Id: 10228077 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 9570A60467 for ; Mon, 19 Feb 2018 15:45:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8564727B81 for ; Mon, 19 Feb 2018 15:45:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 798F828987; Mon, 19 Feb 2018 15:45:17 +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=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 DC92427B81 for ; Mon, 19 Feb 2018 15:45:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753152AbeBSPpP (ORCPT ); Mon, 19 Feb 2018 10:45:15 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:59796 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753009AbeBSPpG (ORCPT ); Mon, 19 Feb 2018 10:45:06 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180219154503euoutp027caec951bbb542486dcc9b017d089762~UxJFsl3ba1439314393euoutp02Q; Mon, 19 Feb 2018 15:45:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180219154503euoutp027caec951bbb542486dcc9b017d089762~UxJFsl3ba1439314393euoutp02Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1519055103; bh=JmoOlIiZie6kufYkDZhVfayKpC3bQPVHmzZ8rJbiPQw=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=DAlaoqnMqIi33PPHl+0ZNL24usG8PaxGGzMipK6gopsLMC9aH+8WtpXFzhReUkH/0 a4s081xWPxZYciM8EX3aVa1Vy2uBsuyprKO8LTqHs6fkboFPYX4M1RYbweD2WmhRUF uNPUvQ9OuoGQrrDfS3g68ZtPU7vUcUymH3CaF2VM= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180219154500eucas1p2b2c8bdfe49ecb7ebad304c5390fd5edd~UxJDeyb5c0492204922eucas1p28; Mon, 19 Feb 2018 15:45:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 42.C8.05700.AF0FA8A5; Mon, 19 Feb 2018 15:44:58 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180219154456eucas1p15f4073beaf61312238f142f217a8bb3c~UxI-aXuil1792217922eucas1p1b; Mon, 19 Feb 2018 15:44:56 +0000 (GMT) X-AuditID: cbfec7f2-5ffe19c000011644-47-5a8af0faefb5 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 8D.CB.04178.8F0FA8A5; Mon, 19 Feb 2018 15:44:56 +0000 (GMT) Received: from AMDC2075.DIGITAL.local ([106.120.51.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P4E00C9VMEN0Z00@eusync4.samsung.com>; Mon, 19 Feb 2018 15:44:55 +0000 (GMT) From: Maciej Purski To: linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org Cc: Michael Turquette , Stephen Boyd , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , David Airlie , Kukjin Kim , Krzysztof Kozlowski , Mauro Carvalho Chehab , Andrzej Pietrasiewicz , Jacek Anaszewski , Kamil Debski , Jeongtae Park , Andrzej Hajda , Russell King , Sylwester Nawrocki , Thibault Saunier , Javier Martinez Canillas , Hans Verkuil , Hoegeun Kwon , Bartlomiej Zolnierkiewicz , Marek Szyprowski , Maciej Purski Subject: [PATCH 1/8] clk: Add clk_bulk_alloc functions Date: Mon, 19 Feb 2018 16:43:59 +0100 Message-id: <1519055046-2399-2-git-send-email-m.purski@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1519055046-2399-1-git-send-email-m.purski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0iTYRTHe977zMXrtHrQWDIKupCmdHmgC4YGb2jghz6ExGzVi0lq452z VlFZ1Ny8X8pLVkKiMbTm2qxWRi1zpeXSyuwyFeyipWiZhVquzVe//c/5/875nw+HwWVOMphJ TkvnhTRVioLyIxpbJlxrJkeNCWsnWyLR+xvtJMptf4ahikE9gRrKbpLo9fgIhUYLywEaqTVS qKi3gEAfbGYCDQ3XYai5/g2GBno6CFT+VE+i/P7vOHK5zDR6cWaIRpb+LhL9yOkh0St7JYVy zDYSlbkeYMhxoQmgqsH3BKpvdtOoxvIXQx2t29HjIe+S6a4GApUVD1Jo7GERHiXnXnV14NxI 9zmaK5lqILm7FW6as5gMFHf7dx/J9WY7Me5W9SnOmu/t51lNgBuzyLnXzZl0vH+C3+YDfEpy Bi+Eb93rdzDnvJlUZ68+Wun6g58GEwojkDCQXQcnHYWYEfgxMvY6gJ7KG0AsxgC0TbnJOUpv uEaIRg2At3PbaLHwA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BeXgFnia2PvSGWyUncPNfJDGJzCrhIPNi9lw3EFgIqOX//EtsERp4FjAyrGEVS S4tz03OLDfWKE3OLS/PS9ZLzczcxAmNs27Gfm3cwXtoYfIhRgINRiYdX4G5XlBBrYllxZe4h RgkOZiURXp8bQCHelMTKqtSi/Pii0pzU4kOM0hwsSuK85w0qo4QE0hNLUrNTUwtSi2CyTByc Ug2M7C3vfOZeD/yyesr21hWh/zdfWuAR3sJZ7WN4JFzD1zdFtl4n+6H/zeSdXFuXMwa5n3QN 6yn5E1VXrViq9I0t0/fmpt/761V9ErS3cep8C3J42Kkr6qH/f7Wl0e2d+jr6jx+vsJ4asVcv NqlBNkk8SjjtjeXFdHPpKb5XOgQsCqcH2nybqKnEUpyRaKjFXFScCAAV15HkrQIAAA== X-CMS-MailID: 20180219154456eucas1p15f4073beaf61312238f142f217a8bb3c X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180219154456eucas1p15f4073beaf61312238f142f217a8bb3c X-RootMTR: 20180219154456eucas1p15f4073beaf61312238f142f217a8bb3c References: <1519055046-2399-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 When a driver is going to use clk_bulk_get() function, it has to initialize an array of clk_bulk_data, by filling its id fields. Add a new function to the core, which dynamically allocates clk_bulk_data array and fills its id fields. Add clk_bulk_free() function, which frees the array allocated by clk_bulk_alloc() function. Add a managed version of clk_bulk_alloc(). Signed-off-by: Maciej Purski --- drivers/clk/clk-bulk.c | 16 ++++++++++++ drivers/clk/clk-devres.c | 37 +++++++++++++++++++++++++--- include/linux/clk.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c index 4c10456..2f16941 100644 --- a/drivers/clk/clk-bulk.c +++ b/drivers/clk/clk-bulk.c @@ -19,6 +19,22 @@ #include #include #include +#include + +struct clk_bulk_data *clk_bulk_alloc(int num_clocks, const char *const *clk_ids) +{ + struct clk_bulk_data *ptr; + int i; + + ptr = kcalloc(num_clocks, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + for (i = 0; i < num_clocks; i++) + ptr[i].id = clk_ids[i]; + + return ptr; +} void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) { diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index d854e26..2115b97 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -9,6 +9,39 @@ #include #include +struct clk_bulk_devres { + struct clk_bulk_data *clks; + int num_clks; +}; + +static void devm_clk_alloc_release(struct device *dev, void *res) +{ + struct clk_bulk_devres *devres = res; + + clk_bulk_free(devres->clks); +} + +struct clk_bulk_data *devm_clk_bulk_alloc(struct device *dev, int num_clks, + const char *const *clk_ids) +{ + struct clk_bulk_data **ptr, *clk_bulk; + + ptr = devres_alloc(devm_clk_alloc_release, + num_clks * sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + clk_bulk = clk_bulk_alloc(num_clks, clk_ids); + if (clk_bulk) { + *ptr = clk_bulk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return clk_bulk; +} + static void devm_clk_release(struct device *dev, void *res) { clk_put(*(struct clk **)res); @@ -34,10 +67,6 @@ struct clk *devm_clk_get(struct device *dev, const char *id) } EXPORT_SYMBOL(devm_clk_get); -struct clk_bulk_devres { - struct clk_bulk_data *clks; - int num_clks; -}; static void devm_clk_bulk_release(struct device *dev, void *res) { diff --git a/include/linux/clk.h b/include/linux/clk.h index 4c4ef9f..7d66f41 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -15,6 +15,7 @@ #include #include #include +#include struct device; struct clk; @@ -240,6 +241,52 @@ static inline void clk_bulk_unprepare(int num_clks, struct clk_bulk_data *clks) #endif #ifdef CONFIG_HAVE_CLK + +/** + * clk_bulk_alloc - allocates an array of clk_bulk_data and fills their + * id field + * @num_clks: number of clk_bulk_data + * @clk_ids: array of clock consumer ID's + * + * This function allows drivers to dynamically create an array of clk_bulk_data + * and fill their id field in one operation. If successful, it allows calling + * clk_bulk_get on the pointer returned by this function. + * + * Returns a pointer to a clk_bulk_data array, or valid IS_ERR() condition + * containing errno. + */ +struct clk_bulk_data *clk_bulk_alloc(int num_clks, const char *const *clk_ids); + +/** + * devm_clk_bulk_alloc - allocates an array of clk_bulk_data and fills their + * id field + * @dev: device for clock "consumer" + * @num_clks: number of clk_bulk_data + * @clk_ids: array of clock consumer ID's + * + * This function allows drivers to dynamically create an array of clk_bulk_data + * and fill their id field in one operation with management, the array will + * automatically be freed when the device is unbound. If successful, it allows + * calling clk_bulk_get on the pointer returned by this function. + * + * Returns a pointer to a clk_bulk_data array, or valid IS_ERR() condition + * containing errno. + */ +struct clk_bulk_data *devm_clk_bulk_alloc(struct device *dev, int num_clks, + const char * const *clk_ids); + +/** + * clk_bulk_free - frees the array of clk_bulk_data + * @clks: pointer to clk_bulk_data array + * + * This function frees the array allocated by clk_bulk_data. It must be called + * when all clks are freed. + */ +static inline void clk_bulk_free(struct clk_bulk_data *clks) +{ + kfree(clks); +} + /** * clk_get - lookup and obtain a reference to a clock producer. * @dev: device for clock "consumer" @@ -598,6 +645,23 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id); #else /* !CONFIG_HAVE_CLK */ +static inline struct clk_bulk_data *clk_bulk_alloc(int num_clks, + const char **clk_ids) +{ + return NULL; +} + +static inline struct clk_bulk_data *devm_clk_bulk_alloc(struct device *dev, + int num_clks, + const char **clk_ids) +{ + return NULL; +} + +static inline void clk_bulk_free(struct clk_bulk_data *clks) +{ +} + static inline struct clk *clk_get(struct device *dev, const char *id) { return NULL;