2012-05-31 16:08:43

by Krystian Garbaciak

[permalink] [raw]
Subject: [PATCH 1/4] regmap: Reorganise internal read/write functions.

Extract from _regmap_raw_write() and _regmap_raw_read() code responsible
for data formatting and bus access and place it in separate functions:
_regmap_bus_write() and _regmap_bus_read().

Signed-off-by: Krystian Garbaciak <[email protected]>
---
drivers/base/regmap/regmap.c | 80 +++++++++++++++++++++++++-----------------
1 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index bb80853..a365aa8 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -396,40 +396,11 @@ void regmap_exit(struct regmap *map)
}
EXPORT_SYMBOL_GPL(regmap_exit);

-static int _regmap_raw_write(struct regmap *map, unsigned int reg,
- const void *val, size_t val_len)
+static int _regmap_bus_write(struct regmap *map, unsigned int reg,
+ void *val, size_t val_len)
{
u8 *u8 = map->work_buf;
- void *buf;
int ret = -ENOTSUPP;
- size_t len;
- int i;
-
- /* Check for unwritable registers before we start */
- if (map->writeable_reg)
- for (i = 0; i < val_len / map->format.val_bytes; i++)
- if (!map->writeable_reg(map->dev, reg + i))
- return -EINVAL;
-
- if (!map->cache_bypass && map->format.parse_val) {
- unsigned int ival;
- int val_bytes = map->format.val_bytes;
- for (i = 0; i < val_len / val_bytes; i++) {
- memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
- ival = map->format.parse_val(map->work_buf);
- ret = regcache_write(map, reg + i, ival);
- if (ret) {
- dev_err(map->dev,
- "Error in caching of register: %u ret: %d\n",
- reg + i, ret);
- return ret;
- }
- }
- if (map->cache_only) {
- map->cache_dirty = true;
- return 0;
- }
- }

map->format.format_reg(map->work_buf, reg);

@@ -456,6 +427,9 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,

/* If that didn't work fall back on linearising by hand. */
if (ret == -ENOTSUPP) {
+ void *buf;
+ size_t len;
+
len = map->format.reg_bytes + map->format.pad_bytes + val_len;
buf = kzalloc(len, GFP_KERNEL);
if (!buf)
@@ -475,6 +449,42 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
return ret;
}

+static int _regmap_raw_write(struct regmap *map, unsigned int reg,
+ const void *val, size_t val_len)
+{
+ void *_val = (void *)val;
+ int i;
+ int ret;
+
+ /* Check for unwritable registers before we start */
+ if (map->writeable_reg)
+ for (i = 0; i < val_len / map->format.val_bytes; i++)
+ if (!map->writeable_reg(map->dev, reg + i))
+ return -EINVAL;
+
+ if (!map->cache_bypass && map->format.parse_val) {
+ unsigned int ival;
+ int val_bytes = map->format.val_bytes;
+ for (i = 0; i < val_len / map->format.val_bytes; i++) {
+ memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
+ ival = map->format.parse_val(map->work_buf);
+ ret = regcache_write(map, reg + i, ival);
+ if (ret) {
+ dev_err(map->dev,
+ "Error in caching of register: %u ret: %d\n",
+ reg + i, ret);
+ return ret;
+ }
+ }
+ if (map->cache_only) {
+ map->cache_dirty = true;
+ return 0;
+ }
+ }
+
+ return _regmap_bus_write(map, reg, _val, val_len);
+}
+
int _regmap_write(struct regmap *map, unsigned int reg,
unsigned int val)
{
@@ -620,7 +630,7 @@ out:
}
EXPORT_SYMBOL_GPL(regmap_bulk_write);

-static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
+static int _regmap_bus_read(struct regmap *map, unsigned int reg, void *val,
unsigned int val_len)
{
u8 *u8 = map->work_buf;
@@ -649,6 +659,12 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
return ret;
}

+static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
+ unsigned int val_len)
+{
+ return _regmap_bus_read(map, reg, val, val_len);
+}
+
static int _regmap_read(struct regmap *map, unsigned int reg,
unsigned int *val)
{
--
1.7.0.4


2012-05-31 16:41:51

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 1/4] regmap: Reorganise internal read/write functions.

On Thu, May 31, 2012 at 04:11:12PM +0200, Krystian Garbaciak wrote:

> +static int _regmap_raw_write(struct regmap *map, unsigned int reg,
> + const void *val, size_t val_len)
> +{
> + void *_val = (void *)val;

This is scary... why are we casting away const here?


Attachments:
(No filename) (273.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2012-05-31 17:55:22

by Krystian Garbaciak

[permalink] [raw]
Subject: RE: [PATCH 1/4] regmap: Reorganise internal read/write functions.

> On Thu, May 31, 2012 at 04:11:12PM +0200, Krystian Garbaciak wrote:
>
> > +static int _regmap_raw_write(struct regmap *map, unsigned int reg,
> > + const void *val, size_t val_len) {
> > + void *_val = (void *)val;
>
> This is scary... why are we casting away const here?

I will remove it from here.
However, on next patch I need to pass *val for reading and writing to the same function. I will put casting there and comment it.

Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and contains proprietary information,
some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it
is addressed. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure,
copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.

Please consider the environment before printing this e-mail

2012-05-31 17:57:54

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 1/4] regmap: Reorganise internal read/write functions.

On Thu, May 31, 2012 at 05:53:16PM +0000, Krystian Garbaciak wrote:

> However, on next patch I need to pass *val for reading and writing to
> the same function. I will put casting there and comment it.

No, let's do something type safe for this.


Attachments:
(No filename) (247.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments