public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: Greg KH <greg@kroah.com>,
	Dimitris Papastamos <dp@opensource.wolfsonmicro.com>,
	Liam Girdwood <lrg@ti.com>, Samuel Oritz <sameo@linux.intel.com>,
	Graeme Gregory <gg@slimlogic.co.uk>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] regmap: Add generic non-memory mapped register access API
Date: Fri, 15 Jul 2011 12:25:05 +0900	[thread overview]
Message-ID: <20110715032503.GH32716@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <20110715025326.GH2927@ponder.secretlab.ca>

On Thu, Jul 14, 2011 at 08:53:26PM -0600, Grant Likely wrote:

Please delete unneeded context, I may have missed some of your comments
due to skimming.

> > +struct regmap {
> > +	struct mutex lock;
> > +
> > +	struct device *dev; /* Device we do I/O on */
> > +	void *work_buf;     /* Scratch buffer used to format I/O */
> > +	struct regmap_format format;  /* Buffer format */
> > +	const struct regmap_bus *bus;
> > +};

> Some /** kerneldoc on these structures would be helpful.

I didn't kerneldoc it because it's internal only and shouldn't appear in
the API reference for the API.

> > +/**
> > + * remap_init: Initialise register map

> nit: "remap_init() - Initialise reigster map"

> > +struct regmap *regmap_init(struct device *dev,
> > +			   const struct regmap_config *config)
> > +{
> > +	struct regmap *map;
> > +	int ret = -EINVAL;
> > +
> > +	map = kzalloc(sizeof(*map), GFP_KERNEL);
> > +	if (map == NULL) {
> > +		ret = -ENOMEM;
> > +		goto err;
> > +	}

> Wouldn't it be appropriate to allow drivers to embed the regmap in a
> private data structure?

Not until we're more confident of the internals, I'd rather not have to
worry about what people are doing with them until they seem more stable.

> Rather than a big case statement, could this be cleaner with a lookup
> table?

Yeah, I did it that way initially but it got annoying to write.  I'm
swithering about going back to that, though.  The problem was the 4x12
and 7x9 cases.  I don't really like either way and this just happened to
be the last one that got implemented.

> I'm a bit concerned that the overall structure of the init function
> will be inflexible in the long run.  Specifically, the way the

That's fine, we can rewrite it.  Like I said I'm not

> instance structure is hidden from the caller, there isn't any way for
> a device driver to explicitly override the accessor functions if it
> needs to.  One of the things I like about the generic irq_chip work
> that tglx did was that it set up a lot of things for the irq
> controller, but the controller could still provide its own hooks when
> necessary.

This is mostly the API internals thing again.

For overrides my plan was to let drivers set the hooks in the
regmap_config they pass in, but I'd like to try to get as far as we can
without needing to do that.  Specifically I'd like to get the cache
stuff in before exposing the internals as I think that that may suggest
some refactorings.

> > +	/* Figure out which bus to use, and also grab a lock on the
> > +	 * module supplying it. */
> > +	mutex_lock(&regmap_bus_lock);
> > +	list_for_each_entry(map->bus, &regmap_bus_list, list)
> > +		if (map->bus->type == dev->bus &&
> > +		    try_module_get(map->bus->owner))
> > +			break;
> > +	mutex_unlock(&regmap_bus_lock);

> Hmmmm.  Two things here.  First, grabbing a reference to the module
> mostly works, but it highlights a deficiency in the driver model.
> Really what we want here is a refcount on the /bound/ instance of the
> driver+device.  The driver model does actually support unbinding a
> device without removing the module.

I know, but all the other subsystems are doing it :)

> Second, combining a device reference with the register access library
> conflates two things which seem to me to be separate.  Actually, which
> it seems odd, it doesn't bother me too much, but it looks completely
> wrong for this library to need specific bus-type knowledge.  Why does
> the bus type need to be known (other than to choose the appropriate IO
> routines)?  If it is only for setting up the io accessors, I'd rather
> see the caller use a bus-specific setup funtion and pass the
> appropriate {i2c,spi,...}_device which will take care of type
> checking.

It's for the I/O accessors at present, though it will also get used for
trace and diagnostics - experience with ASoC has been that it's very
useful to have an off the shelf set of register I/O trace and dump
facilities that you can turn on easily.  For example, once we get the
drivers telling us more about their register maps I'd expect to
replicate the ASoC debugfs dump access.  For that stuff being able to
say what device we're talking about is obviously helpful.

The reasoning behind the I/O is that for all the I2C/SPI devices you
usually end up with a common probe()/exit() function which gets called
by the bus-specific ones and doing things this way means that for most
devices we move an extra call and check block from the bus specific code
into the common code.

> > +err:
> > +	return ERR_PTR(ret);

> Personal soapbox: I'm not at all a fan of the ERR_PTR() pattern
> because it provides no clues to the caller (gcc) if a failure is
> returned as a NULL or as a 0.  Unless there is a really strong
> argument for needing to differentiate between "no data" and "things
> went bad", I'd rather see APIs that return NULL on failure.

We should just switch to C++ and use exceptions :)

  reply	other threads:[~2011-07-15  3:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-09  4:49 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-09  4:50 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-09  4:50   ` [PATCH 2/4] regmap: Add I2C bus support Mark Brown
2011-07-09 11:53     ` Wolfram Sang
2011-07-09 14:08       ` Mark Brown
2011-07-09 14:57         ` Wolfram Sang
2011-07-10  2:59           ` Mark Brown
2011-07-10  9:03             ` Wolfram Sang
2011-07-09  4:50   ` [PATCH 3/4] regmap: Add SPI " Mark Brown
2011-07-15  2:53     ` Grant Likely
2011-07-15  4:39       ` Mark Brown
2011-07-15  5:04         ` Grant Likely
2011-07-15  5:09           ` Mark Brown
2011-07-15  9:01             ` Jonathan Cameron
2011-07-15 18:30               ` Grant Likely
2011-07-09  4:50   ` [PATCH 4/4] regulator: Convert tps65023 to use regmap API Mark Brown
2011-07-15  2:53     ` Grant Likely
2011-07-15  4:48       ` Mark Brown
2011-07-15 18:29         ` Grant Likely
2011-07-16  1:47           ` Mark Brown
2011-07-16  2:06             ` Grant Likely
2011-07-16  2:13               ` Mark Brown
2011-07-09  5:44   ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Greg KH
2011-07-15  2:53   ` Grant Likely
2011-07-15  3:25     ` Mark Brown [this message]
2011-07-15  3:30       ` Grant Likely
  -- strict thread matches above, loose matches on Subject: below --
2011-07-15  6:22 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-15  6:23 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-16  2:48 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-16  2:48 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-18 10:04 [PATCH 0/4] regmap: Generic I2C and SPI register map library Mark Brown
2011-07-18 10:07 ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
2011-07-18 10:38   ` Takashi Iwai
2011-07-18 10:50     ` Mark Brown

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=20110715032503.GH32716@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=dp@opensource.wolfsonmicro.com \
    --cc=gg@slimlogic.co.uk \
    --cc=grant.likely@secretlab.ca \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=sameo@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox