mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Greg KH <greg@kroah.com>, Grant Likely <grant@secretlab.ca>,
	Jean Delvare <khali@linux-fr.org>,
	Ben Dooks <ben-linux@fluff.org>,
	Dimitris Papastamos <dp@opensource.wolfsonmicro.com>,
	Liam Girdwood <lrg@ti.com>, Samuel Oritz <sameo@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] regmap: Add generic non-memory mapped register access API
Date: Mon, 18 Jul 2011 12:38:14 +0200	[thread overview]
Message-ID: <s5hsjq3kh61.wl%tiwai@suse.de> (raw)
In-Reply-To: <1310983663-6404-1-git-send-email-broonie@opensource.wolfsonmicro.com>

At Mon, 18 Jul 2011 19:07:40 +0900,
Mark Brown wrote:
> 
> +static int _regmap_raw_write(struct regmap *map, unsigned int reg,
> +			     const void *val, size_t val_len)
> +{
> +	void *buf;
> +	int ret = -ENOTSUPP;
> +	size_t len;
> +
> +	map->format.format_reg(map->work_buf, reg);
> +
> +	/* Try to do a gather write if we can */
> +	if (map->bus->gather_write)
> +		ret = map->bus->gather_write(map->dev, map->work_buf,
> +					     map->format.reg_bytes,
> +					     val, val_len);
> +
> +	/* Otherwise fall back on linearising by hand. */
> +	if (ret == -ENOTSUPP) {
> +		len = map->format.reg_bytes + val_len;
> +		buf = kmalloc(len, GFP_KERNEL);
> +		if (!buf)
> +			return -ENOMEM;
> +
> +		memcpy(buf, map->work_buf, map->format.reg_bytes);
> +		memcpy(buf + map->format.reg_bytes, val, val_len);
> +		ret = map->bus->write(map->dev, buf, len);
> +
> +		kfree(buf);

In most cases, val = map->work_buf + map->format.reg_bytes.
How about a bit optimization?

	if (ret == -ENOTSUPP) {
		len = map->format.reg_bytes + val_len;
		if (val == map->work_buf + map->format.reg_bytes)
			ret = map->bus->write(map->dev, map->work_buf, len);
		else {
			buf = kmalloc(len, GFP_KERNEL);
			if (!buf)
				return -ENOMEM;

			memcpy(buf, map->work_buf, map->format.reg_bytes);
			memcpy(buf + map->format.reg_bytes, val, val_len);
			ret = map->bus->write(map->dev, buf, len);

			kfree(buf);
		}
	}


thanks,

Takashi

  parent reply	other threads:[~2011-07-18 10:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:07   ` [PATCH 2/4] regmap: Add I2C bus support Mark Brown
2011-07-18 10:07   ` [PATCH 3/4] regmap: Add SPI " Mark Brown
2011-07-19 21:51     ` Grant Likely
2011-07-20 10:33       ` Mark Brown
2011-07-18 10:07   ` [PATCH 4/4] regulator: Convert tps65023 to use regmap API Mark Brown
2011-07-18 10:38   ` Takashi Iwai [this message]
2011-07-18 10:50     ` [PATCH 1/4] regmap: Add generic non-memory mapped register access API Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
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-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-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  5:44   ` Greg KH
2011-07-15  2:53   ` Grant Likely
2011-07-15  3:25     ` Mark Brown
2011-07-15  3:30       ` Grant Likely

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=s5hsjq3kh61.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=ben-linux@fluff.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=dp@opensource.wolfsonmicro.com \
    --cc=grant@secretlab.ca \
    --cc=greg@kroah.com \
    --cc=khali@linux-fr.org \
    --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

Powered by JetHome