Commit f5fc8790 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regulator: Convert tps65023 to use regmap API
  regmap: Add SPI bus support
  regmap: Add I2C bus support
  regmap: Add generic non-memory mapped register access API
parents d4e06701 90923351
...@@ -5327,6 +5327,13 @@ L: reiserfs-devel@vger.kernel.org ...@@ -5327,6 +5327,13 @@ L: reiserfs-devel@vger.kernel.org
S: Supported S: Supported
F: fs/reiserfs/ F: fs/reiserfs/
REGISTER MAP ABSTRACTION
M: Mark Brown <broonie@opensource.wolfsonmicro.com>
T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git
S: Supported
F: drivers/base/regmap/
F: include/linux/regmap.h
RFKILL RFKILL
M: Johannes Berg <johannes@sipsolutions.net> M: Johannes Berg <johannes@sipsolutions.net>
L: linux-wireless@vger.kernel.org L: linux-wireless@vger.kernel.org
......
...@@ -168,4 +168,6 @@ config SYS_HYPERVISOR ...@@ -168,4 +168,6 @@ config SYS_HYPERVISOR
bool bool
default n default n
source "drivers/base/regmap/Kconfig"
endmenu endmenu
...@@ -17,6 +17,7 @@ ifeq ($(CONFIG_SYSFS),y) ...@@ -17,6 +17,7 @@ ifeq ($(CONFIG_SYSFS),y)
obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_MODULES) += module.o
endif endif
obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
obj-$(CONFIG_REGMAP) += regmap/
ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
# Generic register map support. There are no user servicable options here,
# this is an API intended to be used by other kernel subsystems. These
# subsystems should select the appropriate symbols.
config REGMAP
default y if (REGMAP_I2C || REGMAP_SPI)
bool
config REGMAP_I2C
tristate
config REGMAP_SPI
tristate
obj-$(CONFIG_REGMAP) += regmap.o
obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
/*
* Register map access API - I2C support
*
* Copyright 2011 Wolfson Microelectronics plc
*
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/regmap.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/init.h>
static int regmap_i2c_write(struct device *dev, const void *data, size_t count)
{
struct i2c_client *i2c = to_i2c_client(dev);
int ret;
ret = i2c_master_send(i2c, data, count);
if (ret == count)
return 0;
else if (ret < 0)
return ret;
else
return -EIO;
}
static int regmap_i2c_gather_write(struct device *dev,
const void *reg, size_t reg_size,
const void *val, size_t val_size)
{
struct i2c_client *i2c = to_i2c_client(dev);
struct i2c_msg xfer[2];
int ret;
/* If the I2C controller can't do a gather tell the core, it
* will substitute in a linear write for us.
*/
if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_PROTOCOL_MANGLING))
return -ENOTSUPP;
xfer[0].addr = i2c->addr;
xfer[0].flags = 0;
xfer[0].len = reg_size;
xfer[0].buf = (void *)reg;
xfer[1].addr = i2c->addr;
xfer[1].flags = I2C_M_NOSTART;
xfer[1].len = val_size;
xfer[1].buf = (void *)val;
ret = i2c_transfer(i2c->adapter, xfer, 2);
if (ret == 2)
return 0;
if (ret < 0)
return ret;
else
return -EIO;
}
static int regmap_i2c_read(struct device *dev,
const void *reg, size_t reg_size,
void *val, size_t val_size)
{
struct i2c_client *i2c = to_i2c_client(dev);
struct i2c_msg xfer[2];
int ret;
xfer[0].addr = i2c->addr;
xfer[0].flags = 0;
xfer[0].len = reg_size;
xfer[0].buf = (void *)reg;
xfer[1].addr = i2c->addr;
xfer[1].flags = I2C_M_RD;
xfer[1].len = val_size;
xfer[1].buf = val;
ret = i2c_transfer(i2c->adapter, xfer, 2);
if (ret == 2)
return 0;
else if (ret < 0)
return ret;
else
return -EIO;
}
static struct regmap_bus regmap_i2c = {
.type = &i2c_bus_type,
.write = regmap_i2c_write,
.gather_write = regmap_i2c_gather_write,
.read = regmap_i2c_read,
.owner = THIS_MODULE,
};
/**
* regmap_init_i2c(): Initialise register map
*
* @i2c: Device that will be interacted with
* @config: Configuration for register map
*
* The return value will be an ERR_PTR() on error or a valid pointer to
* a struct regmap.
*/
struct regmap *regmap_init_i2c(struct i2c_client *i2c,
const struct regmap_config *config)
{
return regmap_init(&i2c->dev, &regmap_i2c, config);
}
EXPORT_SYMBOL_GPL(regmap_init_i2c);
/*
* Register map access API - SPI support
*
* Copyright 2011 Wolfson Microelectronics plc
*
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include <linux/init.h>
static int regmap_spi_write(struct device *dev, const void *data, size_t count)
{
struct spi_device *spi = to_spi_device(dev);
return spi_write(spi, data, count);
}
static int regmap_spi_gather_write(struct device *dev,
const void *reg, size_t reg_len,
const void *val, size_t val_len)
{
struct spi_device *spi = to_spi_device(dev);
struct spi_message m;
struct spi_transfer t[2] = { { .tx_buf = reg, .len = reg_len, },
{ .tx_buf = val, .len = val_len, }, };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
return spi_sync(spi, &m);
}
static int regmap_spi_read(struct device *dev,
const void *reg, size_t reg_size,
void *val, size_t val_size)
{
struct spi_device *spi = to_spi_device(dev);
return spi_write_then_read(spi, reg, reg_size, val, val_size);
}
static struct regmap_bus regmap_spi = {
.type = &spi_bus_type,
.write = regmap_spi_write,
.gather_write = regmap_spi_gather_write,
.read = regmap_spi_read,
.owner = THIS_MODULE,
.read_flag_mask = 0x80,
};
/**
* regmap_init_spi(): Initialise register map
*
* @spi: Device that will be interacted with
* @config: Configuration for register map
*
* The return value will be an ERR_PTR() on error or a valid pointer to
* a struct regmap.
*/
struct regmap *regmap_init_spi(struct spi_device *spi,
const struct regmap_config *config)
{
return regmap_init(&spi->dev, &regmap_spi, config);
}
EXPORT_SYMBOL_GPL(regmap_init_spi);
This diff is collapsed.
...@@ -235,6 +235,7 @@ config REGULATOR_TPS6105X ...@@ -235,6 +235,7 @@ config REGULATOR_TPS6105X
config REGULATOR_TPS65023 config REGULATOR_TPS65023
tristate "TI TPS65023 Power regulators" tristate "TI TPS65023 Power regulators"
depends on I2C depends on I2C
select REGMAP_I2C
help help
This driver supports TPS65023 voltage regulator chips. TPS65023 provides This driver supports TPS65023 voltage regulator chips. TPS65023 provides
three step-down converters and two general-purpose LDO voltage regulators. three step-down converters and two general-purpose LDO voltage regulators.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/regmap.h>
/* Register definitions */ /* Register definitions */
#define TPS65023_REG_VERSION 0 #define TPS65023_REG_VERSION 0
...@@ -125,93 +126,35 @@ struct tps_pmic { ...@@ -125,93 +126,35 @@ struct tps_pmic {
struct i2c_client *client; struct i2c_client *client;
struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; struct regulator_dev *rdev[TPS65023_NUM_REGULATOR];
const struct tps_info *info[TPS65023_NUM_REGULATOR]; const struct tps_info *info[TPS65023_NUM_REGULATOR];
struct mutex io_lock; struct regmap *regmap;
}; };
static inline int tps_65023_read(struct tps_pmic *tps, u8 reg)
{
return i2c_smbus_read_byte_data(tps->client, reg);
}
static inline int tps_65023_write(struct tps_pmic *tps, u8 reg, u8 val)
{
return i2c_smbus_write_byte_data(tps->client, reg, val);
}
static int tps_65023_set_bits(struct tps_pmic *tps, u8 reg, u8 mask) static int tps_65023_set_bits(struct tps_pmic *tps, u8 reg, u8 mask)
{ {
int err, data; return regmap_update_bits(tps->regmap, reg, mask, mask);
mutex_lock(&tps->io_lock);
data = tps_65023_read(tps, reg);
if (data < 0) {
dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
err = data;
goto out;
}
data |= mask;
err = tps_65023_write(tps, reg, data);
if (err)
dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
out:
mutex_unlock(&tps->io_lock);
return err;
} }
static int tps_65023_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask) static int tps_65023_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask)
{ {
int err, data; return regmap_update_bits(tps->regmap, reg, mask, 0);
mutex_lock(&tps->io_lock);
data = tps_65023_read(tps, reg);
if (data < 0) {
dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
err = data;
goto out;
}
data &= ~mask;
err = tps_65023_write(tps, reg, data);
if (err)
dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
out:
mutex_unlock(&tps->io_lock);
return err;
} }
static int tps_65023_reg_read(struct tps_pmic *tps, u8 reg) static int tps_65023_reg_read(struct tps_pmic *tps, u8 reg)
{ {
int data; unsigned int val;
int ret;
mutex_lock(&tps->io_lock); ret = regmap_read(tps->regmap, reg, &val);
data = tps_65023_read(tps, reg); if (ret != 0)
if (data < 0) return ret;
dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); else
return val;
mutex_unlock(&tps->io_lock);
return data;
} }
static int tps_65023_reg_write(struct tps_pmic *tps, u8 reg, u8 val) static int tps_65023_reg_write(struct tps_pmic *tps, u8 reg, u8 val)
{ {
int err; return regmap_write(tps->regmap, reg, val);
mutex_lock(&tps->io_lock);
err = tps_65023_write(tps, reg, val);
if (err < 0)
dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
mutex_unlock(&tps->io_lock);
return err;
} }
static int tps65023_dcdc_is_enabled(struct regulator_dev *dev) static int tps65023_dcdc_is_enabled(struct regulator_dev *dev)
...@@ -463,6 +406,11 @@ static struct regulator_ops tps65023_ldo_ops = { ...@@ -463,6 +406,11 @@ static struct regulator_ops tps65023_ldo_ops = {
.list_voltage = tps65023_ldo_list_voltage, .list_voltage = tps65023_ldo_list_voltage,
}; };
static struct regmap_config tps65023_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
};
static int __devinit tps_65023_probe(struct i2c_client *client, static int __devinit tps_65023_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -488,7 +436,13 @@ static int __devinit tps_65023_probe(struct i2c_client *client, ...@@ -488,7 +436,13 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
if (!tps) if (!tps)
return -ENOMEM; return -ENOMEM;
mutex_init(&tps->io_lock); tps->regmap = regmap_init_i2c(client, &tps65023_regmap_config);
if (IS_ERR(tps->regmap)) {
error = PTR_ERR(tps->regmap);
dev_err(&client->dev, "Failed to allocate register map: %d\n",
error);
goto fail_alloc;
}
/* common for all regulators */ /* common for all regulators */
tps->client = client; tps->client = client;
...@@ -527,6 +481,8 @@ static int __devinit tps_65023_probe(struct i2c_client *client, ...@@ -527,6 +481,8 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
while (--i >= 0) while (--i >= 0)
regulator_unregister(tps->rdev[i]); regulator_unregister(tps->rdev[i]);
regmap_exit(tps->regmap);
fail_alloc:
kfree(tps); kfree(tps);
return error; return error;
} }
...@@ -545,6 +501,7 @@ static int __devexit tps_65023_remove(struct i2c_client *client) ...@@ -545,6 +501,7 @@ static int __devexit tps_65023_remove(struct i2c_client *client)
for (i = 0; i < TPS65023_NUM_REGULATOR; i++) for (i = 0; i < TPS65023_NUM_REGULATOR; i++)
regulator_unregister(tps->rdev[i]); regulator_unregister(tps->rdev[i]);
regmap_exit(tps->regmap);
kfree(tps); kfree(tps);
return 0; return 0;
......
#ifndef __LINUX_REGMAP_H
#define __LINUX_REGMAP_H
/*
* Register map access API
*
* Copyright 2011 Wolfson Microelectronics plc
*
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/device.h>
#include <linux/list.h>
#include <linux/module.h>
struct i2c_client;
struct spi_device;
struct regmap_config {
int reg_bits;
int val_bits;
};
typedef int (*regmap_hw_write)(struct device *dev, const void *data,
size_t count);
typedef int (*regmap_hw_gather_write)(struct device *dev,
const void *reg, size_t reg_len,
const void *val, size_t val_len);
typedef int (*regmap_hw_read)(struct device *dev,
const void *reg_buf, size_t reg_size,
void *val_buf, size_t val_size);
/**
* Description of a hardware bus for the register map infrastructure.
*
* @list: Internal use.
* @type: Bus type, used to identify bus to be used for a device.
* @write: Write operation.
* @gather_write: Write operation with split register/value, return -ENOTSUPP
* if not implemented on a given device.
* @read: Read operation. Data is returned in the buffer used to transmit
* data.
* @owner: Module with the bus implementation, used to pin the implementation
* in memory.
* @read_flag_mask: Mask to be set in the top byte of the register when doing
* a read.
*/
struct regmap_bus {
struct list_head list;
struct bus_type *type;
regmap_hw_write write;
regmap_hw_gather_write gather_write;
regmap_hw_read read;
struct module *owner;
u8 read_flag_mask;
};
struct regmap *regmap_init(struct device *dev,
const struct regmap_bus *bus,
const struct regmap_config *config);
struct regmap *regmap_init_i2c(struct i2c_client *i2c,
const struct regmap_config *config);
struct regmap *regmap_init_spi(struct spi_device *dev,
const struct regmap_config *config);
void regmap_exit(struct regmap *map);
int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
int regmap_raw_write(struct regmap *map, unsigned int reg,
const void *val, size_t val_len);
int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
int regmap_raw_read(struct regmap *map, unsigned int reg,
void *val, size_t val_len);
int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
size_t val_count);
int regmap_update_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment