From patchwork Tue Jan 19 14:51:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 8063181 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AF398BEEE5 for ; Tue, 19 Jan 2016 14:54:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 99BAE20434 for ; Tue, 19 Jan 2016 14:54:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B147A20411 for ; Tue, 19 Jan 2016 14:54:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLXeK-0007Xh-Pt; Tue, 19 Jan 2016 14:52:48 +0000 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163] helo=cgate.sperl.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLXdz-0007IH-7C; Tue, 19 Jan 2016 14:52:28 +0000 Received: from raspcm.intern.sperl.org (account martin@sperl.org [10.10.10.41] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6392115; Tue, 19 Jan 2016 14:51:48 +0000 From: kernel@martin.sperl.org To: Rob Herring , Stephen Warren , Lee Jones , Eric Anholt , Michael Turquette , Stephen Boyd , Remi Pommarel , devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [RFC 1/9] clk: bcm2835: add basic device tree support for per clock settings Date: Tue, 19 Jan 2016 14:51:32 +0000 Message-Id: <1453215100-2382-2-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1453215100-2382-1-git-send-email-kernel@martin.sperl.org> References: <1453215100-2382-1-git-send-email-kernel@martin.sperl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160119_065227_737456_8DE465C2 X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: -0.9 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Sperl MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Sperl Add basic device tree support for per clock settings taken from the device tree. Signed-off-by: Martin Sperl --- drivers/clk/bcm/clk-bcm2835.c | 72 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index 637f8ae..1c714d0 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -1757,8 +1757,38 @@ static const struct clk_ops bcm2835_vpu_clock_clk_ops = { .get_parent = bcm2835_clock_get_parent, }; +static struct device_node *bcm2835_find_dt_node( + struct bcm2835_cprman *cprman, int id) +{ + struct device *dev = cprman->dev; + struct device_node *nc, *ncp = dev->of_node; + u32 value; + int err; + + /* if no dt, then use the constant version */ + if (!ncp) + return NULL; + + /* try to find the devicetree with the id */ + for_each_available_child_of_node(ncp, nc) { + /* get reg value */ + err = of_property_read_u32(nc, "reg", &value); + if (err) { + dev_err(dev, "%s has no valid 'reg' property (%d)\n", + nc->full_name, err); + } else { + if (value == id) + return nc; + } + } + + /* not found */ + return NULL; +} + static struct clk *bcm2835_register_pll(struct bcm2835_cprman *cprman, - const struct bcm2835_pll_data *data) + const struct bcm2835_pll_data *data, + size_t id) { struct bcm2835_pll *pll; struct clk_init_data init; @@ -1785,7 +1815,8 @@ static struct clk *bcm2835_register_pll(struct bcm2835_cprman *cprman, static struct clk * bcm2835_register_pll_divider(struct bcm2835_cprman *cprman, - const struct bcm2835_pll_divider_data *data) + const struct bcm2835_pll_divider_data *data, + size_t id) { struct bcm2835_pll_divider *divider; struct clk_init_data init; @@ -1843,14 +1874,42 @@ bcm2835_register_pll_divider(struct bcm2835_cprman *cprman, return clk; } +static const struct bcm2835_clock_data *bcm2835_register_clock_of( + struct bcm2835_cprman *cprman, + const struct bcm2835_clock_data *data_orig, + size_t id) +{ + struct device *dev = cprman->dev; + struct device_node *nc; + struct bcm2835_clock_data *data; + + /* find the corresponding dt-node */ + nc = bcm2835_find_dt_node(cprman, id); + if (!nc) + return data_orig; + + /* create a copy of data */ + data = devm_kmalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return data_orig; + memcpy(data, data_orig, sizeof(*data)); + + /* and return the result */ + return data; +} + static struct clk *bcm2835_register_clock(struct bcm2835_cprman *cprman, - const struct bcm2835_clock_data *data) + const struct bcm2835_clock_data *data, + size_t id) { struct bcm2835_clock *clock; struct clk_init_data init; const char *parents[1 << CM_SRC_BITS]; size_t i; + /* update default values from the device_tree */ + data = bcm2835_register_clock_of(cprman, data, id); + /* * Replace our "xosc" references with the oscillator's * actual name. @@ -1887,7 +1946,8 @@ static struct clk *bcm2835_register_clock(struct bcm2835_cprman *cprman, } static struct clk *bcm2835_register_gate(struct bcm2835_cprman *cprman, - const struct bcm2835_gate_data *data) + const struct bcm2835_gate_data *data, + size_t id) { return clk_register_gate(cprman->dev, data->name, data->parent, CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE, @@ -1896,7 +1956,7 @@ static struct clk *bcm2835_register_gate(struct bcm2835_cprman *cprman, } typedef struct clk *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman, - const void *data); + const void *data, size_t id); struct bcm2835_clk_desc { bcm2835_clk_register clk_register; const void *data; @@ -2007,7 +2067,7 @@ static int bcm2835_clk_probe(struct platform_device *pdev) for (i = 0; i < asize; i++) { desc = &clk_desc_array[i]; if (desc->clk_register && desc->data) - clks[i] = desc->clk_register(cprman, desc->data); + clks[i] = desc->clk_register(cprman, desc->data, i); } return of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,