Skip to content

Commit

Permalink
staging:iio:meter:ade7854: Allocate buffers in state and state with i…
Browse files Browse the repository at this point in the history
…io_dev.

Requires moving a few things around, but should be no functional changes.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jonathan Cameron authored and gregkh committed Jun 28, 2011
1 parent 57157d1 commit 937a960
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 110 deletions.
39 changes: 19 additions & 20 deletions drivers/staging/iio/meter/ade7854-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int ade7854_i2c_write_reg_8(struct device *dev,
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);

mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
Expand All @@ -39,7 +39,7 @@ static int ade7854_i2c_write_reg_16(struct device *dev,
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);

mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
Expand All @@ -59,7 +59,7 @@ static int ade7854_i2c_write_reg_24(struct device *dev,
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);

mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
Expand All @@ -80,7 +80,7 @@ static int ade7854_i2c_write_reg_32(struct device *dev,
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);

mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
Expand All @@ -101,7 +101,7 @@ static int ade7854_i2c_read_reg_8(struct device *dev,
u8 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;

mutex_lock(&st->buf_lock);
Expand All @@ -127,7 +127,7 @@ static int ade7854_i2c_read_reg_16(struct device *dev,
u16 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;

mutex_lock(&st->buf_lock);
Expand All @@ -153,7 +153,7 @@ static int ade7854_i2c_read_reg_24(struct device *dev,
u32 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;

mutex_lock(&st->buf_lock);
Expand All @@ -179,7 +179,7 @@ static int ade7854_i2c_read_reg_32(struct device *dev,
u32 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;

mutex_lock(&st->buf_lock);
Expand All @@ -204,13 +204,14 @@ static int __devinit ade7854_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int ret;
struct ade7854_state *st = kzalloc(sizeof *st, GFP_KERNEL);
if (!st) {
ret = -ENOMEM;
return ret;
}

i2c_set_clientdata(client, st);
struct ade7854_state *st;
struct iio_dev *indio_dev;

indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL)
return -ENOMEM;
st = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
st->read_reg_8 = ade7854_i2c_read_reg_8;
st->read_reg_16 = ade7854_i2c_read_reg_16;
st->read_reg_24 = ade7854_i2c_read_reg_24;
Expand All @@ -222,11 +223,9 @@ static int __devinit ade7854_i2c_probe(struct i2c_client *client,
st->i2c = client;
st->irq = client->irq;

ret = ade7854_probe(st, &client->dev);
if (ret) {
kfree(st);
return ret;
}
ret = ade7854_probe(indio_dev, &client->dev);
if (ret)
iio_free_device(indio_dev);

return ret;
}
Expand Down
40 changes: 20 additions & 20 deletions drivers/staging/iio/meter/ade7854-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static int ade7854_spi_write_reg_8(struct device *dev,
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
struct spi_transfer xfer = {
.tx_buf = st->tx,
.bits_per_word = 8,
Expand Down Expand Up @@ -49,7 +49,7 @@ static int ade7854_spi_write_reg_16(struct device *dev,
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
struct spi_transfer xfer = {
.tx_buf = st->tx,
.bits_per_word = 8,
Expand Down Expand Up @@ -78,7 +78,7 @@ static int ade7854_spi_write_reg_24(struct device *dev,
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
struct spi_transfer xfer = {
.tx_buf = st->tx,
.bits_per_word = 8,
Expand Down Expand Up @@ -108,7 +108,7 @@ static int ade7854_spi_write_reg_32(struct device *dev,
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
struct spi_transfer xfer = {
.tx_buf = st->tx,
.bits_per_word = 8,
Expand Down Expand Up @@ -138,7 +138,7 @@ static int ade7854_spi_read_reg_8(struct device *dev,
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
Expand Down Expand Up @@ -180,7 +180,7 @@ static int ade7854_spi_read_reg_16(struct device *dev,
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
Expand Down Expand Up @@ -221,7 +221,7 @@ static int ade7854_spi_read_reg_24(struct device *dev,
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
Expand Down Expand Up @@ -263,7 +263,7 @@ static int ade7854_spi_read_reg_32(struct device *dev,
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
Expand Down Expand Up @@ -302,13 +302,14 @@ static int ade7854_spi_read_reg_32(struct device *dev,
static int __devinit ade7854_spi_probe(struct spi_device *spi)
{
int ret;
struct ade7854_state *st = kzalloc(sizeof *st, GFP_KERNEL);
if (!st) {
ret = -ENOMEM;
return ret;
}

spi_set_drvdata(spi, st);
struct ade7854_state *st;
struct iio_dev *indio_dev;

indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL)
return -ENOMEM;
st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
st->read_reg_8 = ade7854_spi_read_reg_8;
st->read_reg_16 = ade7854_spi_read_reg_16;
st->read_reg_24 = ade7854_spi_read_reg_24;
Expand All @@ -320,11 +321,10 @@ static int __devinit ade7854_spi_probe(struct spi_device *spi)
st->irq = spi->irq;
st->spi = spi;

ret = ade7854_probe(st, &spi->dev);
if (ret) {
kfree(st);
return ret;
}

ret = ade7854_probe(indio_dev, &spi->dev);
if (ret)
iio_free_device(indio_dev);

return 0;
}
Expand Down
Loading

0 comments on commit 937a960

Please sign in to comment.