All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@codeaurora.org>
To: Erin Lo <erin.lo@mediatek.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>,
	Mike Turquette <mturquette@baylibre.com>,
	Rob Herring <robh@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Sascha Hauer <kernel@pengutronix.de>,
	Daniel Kurtz <djkurtz@chromium.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	linux-clk@vger.kernel.org, srv_heupstream@mediatek.com,
	Shunli Wang <shunli.wang@mediatek.com>,
	James Liao <jamesjj.liao@mediatek.com>
Subject: Re: [PATCH v11 5/9] clk: mediatek: Add MT2701 clock support
Date: Fri, 19 Aug 2016 12:46:08 -0700	[thread overview]
Message-ID: <20160819194608.GA6502@codeaurora.org> (raw)
In-Reply-To: <1471584896-9986-6-git-send-email-erin.lo@mediatek.com>

On 08/19, Erin Lo wrote:
> diff --git a/drivers/clk/mediatek/clk-mt2701-vdec.c b/drivers/clk/mediatek/clk-mt2701-vdec.c
> new file mode 100644
> index 0000000..45a102e
> --- /dev/null
> +++ b/drivers/clk/mediatek/clk-mt2701-vdec.c
> +
> +static const struct mtk_gate vdec_clks[] = {
> +	GATE_VDEC0(CLK_VDEC_CKGEN, "vdec_cken", "vdec_sel", 0),
> +	GATE_VDEC1(CLK_VDEC_LARB, "vdec_larb_cken", "mm_sel", 0),
> +};
> +
> +static void mtk_vdecsys_init(struct device_node *node)

Please return errors to driver probe.

> +{
> +	struct clk_onecell_data *clk_data;
> +	int r;
> +
> +	clk_data = mtk_alloc_clk_data(CLK_VDEC_NR);
> +
> +	mtk_clk_register_gates(node, vdec_clks, ARRAY_SIZE(vdec_clks),
> +						clk_data);
> +
> +	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
> +	if (r)
> +		pr_err("%s(): could not register clock provider: %d\n",
> +			__func__, r);
> +}
> +
> +static const struct of_device_id of_match_clk_mt2701_vdec[] = {
> +	{ .compatible = "mediatek,mt2701-vdecsys", },
> +	{}
> +};
> +
> +static int clk_mt2701_vdec_probe(struct platform_device *pdev)
> +{
> +	mtk_vdecsys_init(pdev->dev.of_node);
> +	return 0;

	return mtk_vdecsys_init()?

> +}
> +
> diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
> new file mode 100644
> index 0000000..f64dc4e
> --- /dev/null
> +++ b/drivers/clk/mediatek/clk-mt2701.c
> @@ -0,0 +1,1033 @@
> +/*
> + * Copyright (c) 2014 MediaTek Inc.
> + * Author: Shunli Wang <shunli.wang@mediatek.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +
> +#include "clk-mtk.h"
> +#include "clk-gate.h"
> +
> +#include <dt-bindings/clock/mt2701-clk.h>
> +
> +/*
> + * For some clocks, we don't care what their actual rates are. And these
> + * clocks may change their rate on different products or different scenarios.
> + * So we model these clocks' rate as 0, to denote it's not an actual rate.
> + */
> +#define DUMMY_RATE		0

This doesn't sound great... Wouldn't we want to get those rates
from the dts files then?

> +
> +static DEFINE_SPINLOCK(lock);

Please use a better name than lock. mtk2701_clk_lock?

> +
> +static int clk_mt2701_probe(struct platform_device *pdev)
> +{
> +	void (*clk_init)(struct device_node *);

Please return errors from clk_init() callbacks.

> +	const struct of_device_id *of_id;
> +
> +	pr_warn("%s():%d: %s\n", __func__, __LINE__, pdev->name);
> +

This is noise, please remove.

> +	of_id = of_match_node(of_match_clk_mt2701, pdev->dev.of_node);
> +	if (!of_id || !of_id->data)
> +		return -EINVAL;

We can use of_device_get_match_data() here to simplify things.

> +
> +	clk_init = of_id->data;
> +	clk_init(pdev->dev.of_node);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver clk_mt2701_drv = {
> +	.probe = clk_mt2701_probe,
> +	.driver = {
> +		.name = "clk-mt2701",
> +		.owner = THIS_MODULE,

This isn't needed because of how platform_driver_register() works.

> +		.of_match_table = of_match_clk_mt2701,
> +	},
> +};
> +
> +static int __init clk_mt2701_init(void)
> +{
> +	return platform_driver_register(&clk_mt2701_drv);
> +}
> +
> +arch_initcall(clk_mt2701_init);
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index bb30f70..6a015a8 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
> @@ -244,3 +256,31 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs,
>  			clk_data->clks[mc->id] = clk;
>  	}
>  }
> +
> +void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
> +			int num, void __iomem *base, spinlock_t *lock,
> +				struct clk_onecell_data *clk_data)
> +{
> +	struct clk *clk;
> +	int i;
> +
> +	for (i = 0; i <  num; i++) {
> +		const struct mtk_clk_divider *mcd = &mcds[i];
> +
> +		if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id]))
> +			continue;

We dereference clk_data here...

> +
> +		clk = clk_register_divider(NULL, mcd->name, mcd->parent_name,
> +			mcd->flags, base +  mcd->div_reg, mcd->div_shift,
> +			mcd->div_width, mcd->clk_divider_flags, lock);
> +
> +		if (IS_ERR(clk)) {
> +			pr_err("Failed to register clk %s: %ld\n",
> +				mcd->name, PTR_ERR(clk));
> +			continue;
> +		}
> +
> +		if (clk_data)

But then we check it for NULL here? This happens quite often now
after this patch.

> +			clk_data->clks[mcd->id] = clk;
> +	}
> +}

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

WARNING: multiple messages have this Message-ID (diff)
From: sboyd@codeaurora.org (Stephen Boyd)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v11 5/9] clk: mediatek: Add MT2701 clock support
Date: Fri, 19 Aug 2016 12:46:08 -0700	[thread overview]
Message-ID: <20160819194608.GA6502@codeaurora.org> (raw)
In-Reply-To: <1471584896-9986-6-git-send-email-erin.lo@mediatek.com>

On 08/19, Erin Lo wrote:
> diff --git a/drivers/clk/mediatek/clk-mt2701-vdec.c b/drivers/clk/mediatek/clk-mt2701-vdec.c
> new file mode 100644
> index 0000000..45a102e
> --- /dev/null
> +++ b/drivers/clk/mediatek/clk-mt2701-vdec.c
> +
> +static const struct mtk_gate vdec_clks[] = {
> +	GATE_VDEC0(CLK_VDEC_CKGEN, "vdec_cken", "vdec_sel", 0),
> +	GATE_VDEC1(CLK_VDEC_LARB, "vdec_larb_cken", "mm_sel", 0),
> +};
> +
> +static void mtk_vdecsys_init(struct device_node *node)

Please return errors to driver probe.

> +{
> +	struct clk_onecell_data *clk_data;
> +	int r;
> +
> +	clk_data = mtk_alloc_clk_data(CLK_VDEC_NR);
> +
> +	mtk_clk_register_gates(node, vdec_clks, ARRAY_SIZE(vdec_clks),
> +						clk_data);
> +
> +	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
> +	if (r)
> +		pr_err("%s(): could not register clock provider: %d\n",
> +			__func__, r);
> +}
> +
> +static const struct of_device_id of_match_clk_mt2701_vdec[] = {
> +	{ .compatible = "mediatek,mt2701-vdecsys", },
> +	{}
> +};
> +
> +static int clk_mt2701_vdec_probe(struct platform_device *pdev)
> +{
> +	mtk_vdecsys_init(pdev->dev.of_node);
> +	return 0;

	return mtk_vdecsys_init()?

> +}
> +
> diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
> new file mode 100644
> index 0000000..f64dc4e
> --- /dev/null
> +++ b/drivers/clk/mediatek/clk-mt2701.c
> @@ -0,0 +1,1033 @@
> +/*
> + * Copyright (c) 2014 MediaTek Inc.
> + * Author: Shunli Wang <shunli.wang@mediatek.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +
> +#include "clk-mtk.h"
> +#include "clk-gate.h"
> +
> +#include <dt-bindings/clock/mt2701-clk.h>
> +
> +/*
> + * For some clocks, we don't care what their actual rates are. And these
> + * clocks may change their rate on different products or different scenarios.
> + * So we model these clocks' rate as 0, to denote it's not an actual rate.
> + */
> +#define DUMMY_RATE		0

This doesn't sound great... Wouldn't we want to get those rates
from the dts files then?

> +
> +static DEFINE_SPINLOCK(lock);

Please use a better name than lock. mtk2701_clk_lock?

> +
> +static int clk_mt2701_probe(struct platform_device *pdev)
> +{
> +	void (*clk_init)(struct device_node *);

Please return errors from clk_init() callbacks.

> +	const struct of_device_id *of_id;
> +
> +	pr_warn("%s():%d: %s\n", __func__, __LINE__, pdev->name);
> +

This is noise, please remove.

> +	of_id = of_match_node(of_match_clk_mt2701, pdev->dev.of_node);
> +	if (!of_id || !of_id->data)
> +		return -EINVAL;

We can use of_device_get_match_data() here to simplify things.

> +
> +	clk_init = of_id->data;
> +	clk_init(pdev->dev.of_node);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver clk_mt2701_drv = {
> +	.probe = clk_mt2701_probe,
> +	.driver = {
> +		.name = "clk-mt2701",
> +		.owner = THIS_MODULE,

This isn't needed because of how platform_driver_register() works.

> +		.of_match_table = of_match_clk_mt2701,
> +	},
> +};
> +
> +static int __init clk_mt2701_init(void)
> +{
> +	return platform_driver_register(&clk_mt2701_drv);
> +}
> +
> +arch_initcall(clk_mt2701_init);
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index bb30f70..6a015a8 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
> @@ -244,3 +256,31 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs,
>  			clk_data->clks[mc->id] = clk;
>  	}
>  }
> +
> +void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
> +			int num, void __iomem *base, spinlock_t *lock,
> +				struct clk_onecell_data *clk_data)
> +{
> +	struct clk *clk;
> +	int i;
> +
> +	for (i = 0; i <  num; i++) {
> +		const struct mtk_clk_divider *mcd = &mcds[i];
> +
> +		if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id]))
> +			continue;

We dereference clk_data here...

> +
> +		clk = clk_register_divider(NULL, mcd->name, mcd->parent_name,
> +			mcd->flags, base +  mcd->div_reg, mcd->div_shift,
> +			mcd->div_width, mcd->clk_divider_flags, lock);
> +
> +		if (IS_ERR(clk)) {
> +			pr_err("Failed to register clk %s: %ld\n",
> +				mcd->name, PTR_ERR(clk));
> +			continue;
> +		}
> +
> +		if (clk_data)

But then we check it for NULL here? This happens quite often now
after this patch.

> +			clk_data->clks[mcd->id] = clk;
> +	}
> +}

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2016-08-19 19:46 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19  5:34 [PATCH v11 0/9] Add clock support for Mediatek MT2701 Erin Lo
2016-08-19  5:34 ` Erin Lo
2016-08-19  5:34 ` Erin Lo
2016-08-19  5:34 ` [PATCH v11 1/9] clk: mediatek: remove __init from clk registration functions Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34 ` [PATCH v11 2/9] clk: mediatek: Refine the makefile to support multiple clock drivers Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19 19:46   ` Stephen Boyd
2016-08-19 19:46     ` Stephen Boyd
2016-08-19  5:34 ` [PATCH v11 3/9] dt-bindings: ARM: Mediatek: Document bindings for MT2701 Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19 19:46   ` Stephen Boyd
2016-08-19 19:46     ` Stephen Boyd
2016-08-19  5:34 ` [PATCH v11 4/9] clk: mediatek: Add dt-bindings for MT2701 clocks Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19 19:46   ` Stephen Boyd
2016-08-19 19:46     ` Stephen Boyd
2016-08-19  5:34 ` [PATCH v11 5/9] clk: mediatek: Add MT2701 clock support Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19 19:46   ` Stephen Boyd [this message]
2016-08-19 19:46     ` Stephen Boyd
2016-08-19  5:34 ` [PATCH v11 6/9] reset: mediatek: Add MT2701 reset controller dt-binding file Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19 19:46   ` Stephen Boyd
2016-08-19 19:46     ` Stephen Boyd
2016-08-19  5:34 ` [PATCH v11 7/9] reset: mediatek: Add MT2701 reset driver Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34 ` [PATCH v11 8/9] arm: dts: mt2701: Add clock controller device nodes Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34 ` [PATCH v11 9/9] arm: dts: mt2701: Use real clock for UARTs Erin Lo
2016-08-19  5:34   ` Erin Lo
2016-08-19  5:34   ` Erin Lo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160819194608.GA6502@codeaurora.org \
    --to=sboyd@codeaurora.org \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=djkurtz@chromium.org \
    --cc=erin.lo@mediatek.com \
    --cc=jamesjj.liao@mediatek.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mturquette@baylibre.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=shunli.wang@mediatek.com \
    --cc=srv_heupstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.