linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Grant Likely" <grant.likely@secretlab.ca>
To: benh@kernel.crashing.org
Cc: linuxppc-dev@ozlabs.org
Subject: Re: [PATCH 2 6/7] Uartlite: Add of-platform-bus binding
Date: Tue, 2 Oct 2007 08:26:42 -0600	[thread overview]
Message-ID: <fa686aa40710020726s330d586p6ece70ae378f1206@mail.gmail.com> (raw)
In-Reply-To: <1191304386.6310.92.camel@pasglop>

On 10/1/07, Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>
> On Sun, 2007-09-30 at 16:42 -0600, Grant Likely wrote:
> > From: Grant Likely <grant.likely@secretlab.ca>
> >
> > Add of_platform bus binding so this driver can be used with arch/powerpc
>
> Another option is to have a "constructor" in the platform code that
> generates the platform device from the DT. It might even become the
> preferred way one of these days, I'm not too sure at this stage. Anyway,
> do what you prefer.

I've looked at both, and I'm not to fond of the 'constructor'
approach.  Here are my reasons:

- Separate constructor code must be written for each driver anyway
(except perhaps for very simple cases which only require 'regs' and
'interrupts' properties).  The device tree data must then be mapped
onto a pdata structure; which the driver immediately turns around and
unmaps from pdata to populate it's driver state structure.  It ends up
being a lot of indirection to follow.
- Many (but perhaps not all) of these devices will be registered as an
of_device anyway.  By having a constructor to generate a
platform_device from that means each device will get probed twice;
once by the of_platform bus and once by the platform bus.
- Writing device drivers with multiple binding is easy and probable
results in smaller simpler code than the two step process of using a
constructor.

For example, here is my of_device binding for the systemace driver:

static int __devinit
ulite_of_probe(struct of_device *op, const struct of_device_id *match)
{
        struct resource res;
        const unsigned int *id;
        int irq, rc;
        dev_dbg(&op->dev, "%s(%p, %p)\n", __FUNCTION__, op, match);
        rc = of_address_to_resource(op->node, 0, &res);
        if (rc) {
                dev_err(&op->dev, "invalide address\n");
                return rc;
        }
        irq = irq_of_parse_and_map(op->node, 0);
        id = of_get_property(op->node, "port-number", NULL);
        return ulite_assign(&op->dev, id ? *id : -1, res.start, irq);
}

That's 3 calls to get data out of the device tree and one call to
setup the device.  The final 'ulite_assign()' call is called by both
the of_device and platform_device bindings.

To do the same thing with a constructor requires an additional
allocation and registration of a platform device structure and a pdata
structure.  Plus it requires the platform code to explicitly call a
set of helper functions to find and create platform devices for nodes
in the device tree.  (Unless you're thinking about leveraging the
of_platform probe code and have the .probe hook to the 'constructor'
bit)

What advantages do you see with the constructor approach?

Cheers,
g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely@secretlab.ca
(403) 399-0195

  reply	other threads:[~2007-10-02 14:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-30 22:41 [PATCH 2 1/7] Uartlite: Fix reg io to access documented register size Grant Likely
2007-09-30 22:41 ` [PATCH 2 2/7] Uartlite: change name of ports to ulite_ports Grant Likely
2007-10-02 18:46   ` Peter Korsgaard
2007-09-30 22:41 ` [PATCH 2 3/7] Uartlite: Add macro for uartlite device name Grant Likely
2007-10-02 18:45   ` Peter Korsgaard
2007-09-30 22:41 ` [PATCH 2 4/7] Uartlite: Separate the bus binding from the driver proper Grant Likely
2007-09-30 22:42 ` [PATCH 2 5/7] Uartlite: Comment block tidy Grant Likely
2007-10-02 18:46   ` Peter Korsgaard
2007-09-30 22:42 ` [PATCH 2 6/7] Uartlite: Add of-platform-bus binding Grant Likely
2007-10-02  5:53   ` Benjamin Herrenschmidt
2007-10-02 14:26     ` Grant Likely [this message]
2007-10-02 15:58       ` Peter Korsgaard
2007-10-02 16:10         ` Scott Wood
2007-10-02 16:23           ` Grant Likely
2007-10-02 16:10         ` Grant Likely
2007-10-02 22:43           ` Benjamin Herrenschmidt
2007-10-03  4:18             ` Grant Likely
2007-10-03  4:24               ` Benjamin Herrenschmidt
2007-10-03 14:39                 ` Grant Likely
2007-10-03 21:21                   ` Benjamin Herrenschmidt
2007-10-02 18:49   ` Peter Korsgaard
2007-09-30 22:42 ` [PATCH 2 7/7] Uartlite: Let the console be initialized earlier Grant Likely
2007-10-02 18:48   ` Peter Korsgaard

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=fa686aa40710020726s330d586p6ece70ae378f1206@mail.gmail.com \
    --to=grant.likely@secretlab.ca \
    --cc=benh@kernel.crashing.org \
    --cc=linuxppc-dev@ozlabs.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).