linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Anton Glukhov <anton.a.glukhov@gmail.com>,
	linux-can@vger.kernel.org, bcousson@baylibre.com
Subject: Re: [PATCH 1/3] can: ti_hecc: Add DT support for TI HECC module
Date: Wed, 16 Mar 2016 11:53:22 +0100	[thread overview]
Message-ID: <56E93B22.8010602@pengutronix.de> (raw)
In-Reply-To: <1443988779-19935-1-git-send-email-anton.a.glukhov@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3677 bytes --]

Hello,

just stumbled over these patches.

On 10/04/2015 09:59 PM, Anton Glukhov wrote:
> These patch set adds device tree support for TI HECC module.


> Signed-off-by: Anton Glukhov <anton.a.glukhov@gmail.com>
> ---
>  drivers/net/can/ti_hecc.c | 56 +++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 52 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
> index cf345cb..c1a89fd 100644
> --- a/drivers/net/can/ti_hecc.c
> +++ b/drivers/net/can/ti_hecc.c
> @@ -46,6 +46,8 @@
>  #include <linux/platform_device.h>
>  #include <linux/clk.h>
>  #include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
>  
>  #include <linux/can/dev.h>
>  #include <linux/can/error.h>
> @@ -875,19 +877,64 @@ static const struct net_device_ops ti_hecc_netdev_ops = {
>  	.ndo_change_mtu		= can_change_mtu,
>  };
>  
> +#if defined(CONFIG_OF)

please remove the ifdef

> +static const struct of_device_id ti_hecc_dt_ids[] = {
> +	{
> +		.compatible = "ti,am35x-hecc",
> +	},
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, ti_hecc_dt_ids);
> +#endif
> +
> +static struct ti_hecc_platform_data *hecc_parse_dt(struct device *dev)
> +{
> +	struct ti_hecc_platform_data *pdata;
> +	struct device_node *np = dev->of_node;
> +
> +	pdata = devm_kzalloc(dev, sizeof(struct ti_hecc_platform_data), GFP_KERNEL);

Please don't allocate pdata - better create two functions, one parsing
the pdata and one parse the dt.

> +	if (!pdata)
> +		return ERR_PTR(-ENOMEM);
> +
> +	if (of_property_read_u32(np, "ti,scc-ram-offset", &pdata->scc_ram_offset)) {
> +		dev_err(dev, "Missing scc-ram-offset property in the DT.\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	if (of_property_read_u32(np, "ti,hecc-ram-offset", &pdata->hecc_ram_offset)) {
> +		dev_err(dev, "Missing hecc-ram-offset property in the DT.\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +	if (of_property_read_u32(np, "ti,mbx-offset", &pdata->mbx_offset)) {
> +		dev_err(dev, "Missing mbx-offset property in the DT.\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +	if (of_property_read_u32(dev->of_node, "ti,int-line", &pdata->int_line)) {
> +		pdata->int_line = 0;
> +	}
> +
> +	return pdata;
> +}
> +
>  static int ti_hecc_probe(struct platform_device *pdev)
>  {
>  	struct net_device *ndev = (struct net_device *)0;
>  	struct ti_hecc_priv *priv;
> -	struct ti_hecc_platform_data *pdata;
> +	struct ti_hecc_platform_data *pdata = dev_get_platdata(&pdev->dev);
> +	struct device_node *np = pdev->dev.of_node;
>  	struct resource *mem, *irq;
>  	void __iomem *addr;
>  	int err = -ENODEV;
>  
> -	pdata = dev_get_platdata(&pdev->dev);
> +	if (!pdata && np) {
> +		pdata = hecc_parse_dt(&pdev->dev);
> +		if (IS_ERR(pdata))
> +			return PTR_ERR(pdata);
> +	}
> +
>  	if (!pdata) {
> -		dev_err(&pdev->dev, "No platform data\n");
> -		goto probe_exit;
> +		dev_err(&pdev->dev, "Platform data missing\n");
> +		return -EINVAL;
>  	}
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -1040,6 +1087,7 @@ static int ti_hecc_resume(struct platform_device *pdev)
>  static struct platform_driver ti_hecc_driver = {
>  	.driver = {
>  		.name    = DRV_NAME,
> +		.of_match_table = ti_hecc_dt_ids,
>  	},
>  	.probe = ti_hecc_probe,
>  	.remove = ti_hecc_remove,
> 

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

      parent reply	other threads:[~2016-03-16 10:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-04 19:59 [PATCH 1/3] can: ti_hecc: Add DT support for TI HECC module Anton Glukhov
2015-10-04 19:59 ` [PATCH 2/3] can: ti_hecc: Add TI HECC DT binding documentation Anton Glukhov
2015-10-12  9:50   ` Marc Kleine-Budde
2015-10-04 19:59 ` [PATCH 3/3] ARM: dts: AM35x: Add hecc node Anton Glukhov
2015-10-12  9:42 ` [PATCH 1/3] can: ti_hecc: Add DT support for TI HECC module Marc Kleine-Budde
2016-03-16 10:53 ` Marc Kleine-Budde [this message]

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=56E93B22.8010602@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=anton.a.glukhov@gmail.com \
    --cc=bcousson@baylibre.com \
    --cc=linux-can@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).