On Mon, 30 May 2011 18:14:48 +0800
Mark Brown <broo...@opensource.wolfsonmicro.com> wrote:

> On Mon, May 30, 2011 at 11:07:49AM +0200, Antonio Ospite wrote:
> > On Mon, 23 May 2011 17:10:23 +0200
> 
> > > +#define STRUCT_FIELD(s, f) ((s) && (s)->f ? (s)->f : NULL )
> 
> > Any opinion on this macro? See its use below. It is meant to deal with
> > driver specific struct fields, which can have arbitrary names, I though
> > that using some syntactic sugar to deal with those as arguments when
> > calling the function was not that horrible.
> 
> > If that looks acceptable to you too I will submit the
> > mmc_regulator_set_power () patch, otherwise I would ask to consider the
> > simple patch to mmc_spi.c for now.
> 
> Would it not be simpler just to provide a standard generic struct that
> people can embed into their pdata?
> 

I thought to something like:

struct mmc_driver_ops {
        int (*setpower)(struct device *, unsigned int);
};

struct pxamci_platform_data {
        [...]
        struct mmc_driver_ops *ops;
};

static inline int mmc_regulator_set_power(struct mmc_host *mmc,
                                 unsigned char  power_mode,
                                 struct regulator *supply,
                                 unsigned short vdd_bit,
                                 struct device *device,
                                 struct mmc_driver_ops ops)
{
        [...]
                if (ops->setpower)
                        ops->setpower(device, vdd_bit);
        [...]
}

static inline int pxamci_set_power(struct pxamci_host *host,
                                    unsigned char power_mode,
                                    unsigned int vdd)
{
        [...]
        ret = mmc_regulator_set_power(host->mmc, power_mode, host->vcc,
                                      vdd, mmc_dev(host->mmc),
                                      host->pdata->ops);
        [...]
}

It is cleaner and more uniform indeed, but it does not solve the problem
I am seeing, the issue is still there when pdata is NULL, we are at the
same point as before (the current code checks for (pdata &&
pdata->field)), and we cannot pass pdata directly as a function argument
(can we?) as it is driver specific as well.

I would be glad to discover than I am still missing something :)

Thanks,
   Antonio

-- 
Antonio Ospite
http://ao2.it

PGP public key ID: 0x4553B001

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?

Attachment: pgpCkWFjUt1LC.pgp
Description: PGP signature

Reply via email to