devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Vaussard <florian.vaussard@epfl.ch>
To: Alexander Shiyan <shc_work@mail.ru>
Cc: linux-leds@vger.kernel.org, "Bryan Wu" <cooloney@gmail.com>,
	"Richard Purdie" <rpurdie@rpsys.net>,
	devicetree@vger.kernel.org,
	"Philippe Rétornaz" <philippe.retornaz@epfl.ch>
Subject: Re: [PATCH v2 5/5] leds: leds-mc13783: Add devicetree support
Date: Mon, 23 Dec 2013 10:10:08 +0100	[thread overview]
Message-ID: <52B7FDF0.9000404@epfl.ch> (raw)
In-Reply-To: <1387788147.985598723@f413.i.mail.ru>



On 12/23/2013 09:42 AM, Alexander Shiyan wrote:
>>>> On 12/21/2013 05:32 AM, Alexander Shiyan wrote:
>>>>> This patch adds devicetree support for the MC13XXX LED driver.
> ...
>>>>> +	ret = of_property_read_u32_array(parent, "led-control", ctrls,
>>>>> +					 leds->devtype->num_regs);
>>>>> +	if (ret)
>>>>> +		goto out_node_put;
>>>>> +
>>>>> +	for (i = 0; i < leds->devtype->num_regs; i++) {
>>>>> +		ret = mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i,
>>>>> +					ctrls[i]);
>>>>
>>>> Code duplicated from the regular probe.
>>>
>>> Yes. This was done based on the comments to the previous version:
>>> http://www.spinics.net/lists/devicetree/msg14933.html
>>>
>>
>> From what I understand, Tomasz is suggesting exactly the same as
>> what I am saying:
>>
>> "what about making
>> mc13xxx_led_setup_of() allocate a platform data structure and fill it
>> in with data parsed from DT, so the driver would then proceed normally as
>> if the platform data were available? IMHO this should make the code much
>> simpler and more readable."
>>
>> This is not what you have done IMHO, you are cloning the probe
>> into a separate DT-only function.
> 
> I do not fully understand what you mean. When we had an universal procedure,
> I was told to divide them into DT and non-DT. I separated it - now we have duplicate code.
> Merge back?
> 

No, do in-between. Look at leds-lp5521.c for example. What you have to
do is roughly:

mc13xxx_led_probe
{
	struct mc13xxx_leds_platform_data *pdata = NULL;

	if (devicetree)
		mc13xxx_of_populate_pdata(pdev->dev.of_node, &pdata);
	else
		pdata = dev_get_platdata(&pdev->dev);

	if (!pdata)
		oops...

	-> regular probe here <-
}

Your function mc13xxx_of_populate_pdata() will look for DT properties,
and only fill the platform data. All the rest is done as usual by your probe
function. No code is duplicated, but the DT logic is encapsulated inside its
own function.

Look at other drivers if you are not familiar with such an approach, it
is pretty common.

Regards,

Florian

      reply	other threads:[~2013-12-23  9:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-21  4:32 [PATCH v2 5/5] leds: leds-mc13783: Add devicetree support Alexander Shiyan
     [not found] ` <1387600347-22673-1-git-send-email-shc_work-JGs/UdohzUI@public.gmane.org>
2013-12-23  7:58   ` Florian Vaussard
2013-12-23  8:18     ` Alexander Shiyan
2013-12-23  8:31       ` Florian Vaussard
     [not found]         ` <52B7F4F8.3050907-p8DiymsW2f8@public.gmane.org>
2013-12-23  8:42           ` Alexander Shiyan
2013-12-23  9:10             ` Florian Vaussard [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=52B7FDF0.9000404@epfl.ch \
    --to=florian.vaussard@epfl.ch \
    --cc=cooloney@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=philippe.retornaz@epfl.ch \
    --cc=rpurdie@rpsys.net \
    --cc=shc_work@mail.ru \
    /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).