Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 259638
b: refs/heads/master
c: afc2ff0
h: refs/heads/master
v: v3
  • Loading branch information
Jonathan Cameron authored and Greg Kroah-Hartman committed Jun 28, 2011
1 parent 50dbffd commit 6441178
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 61 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 338473c8194b45eb28bae737fc7aa8e7f4fe7330
refs/heads/master: afc2ff0afaf395042854172994825439d9961e2c
80 changes: 27 additions & 53 deletions trunk/drivers/staging/iio/meter/ade7759.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static int ade7759_spi_write_reg_8(struct device *dev,
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
struct ade7759_state *st = iio_priv(indio_dev);

mutex_lock(&st->buf_lock);
st->tx[0] = ADE7759_WRITE_REG(reg_address);
Expand All @@ -47,7 +47,7 @@ static int ade7759_spi_write_reg_16(struct device *dev,
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
struct ade7759_state *st = iio_priv(indio_dev);

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

ret = spi_w8r8(st->us, ADE7759_READ_REG(reg_address));
Expand All @@ -83,7 +83,7 @@ static int ade7759_spi_read_reg_16(struct device *dev,
u16 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
struct ade7759_state *st = iio_priv(indio_dev);
int ret;

ret = spi_w8r16(st->us, ADE7759_READ_REG(reg_address));
Expand All @@ -105,7 +105,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
struct ade7759_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
Expand Down Expand Up @@ -328,10 +328,11 @@ static int ade7759_stop_device(struct device *dev)
return ade7759_spi_write_reg_16(dev, ADE7759_MODE, val);
}

static int ade7759_initial_setup(struct ade7759_state *st)
static int ade7759_initial_setup(struct iio_dev *indio_dev)
{
int ret;
struct device *dev = &st->indio_dev->dev;
struct ade7759_state *st = iio_priv(indio_dev);
struct device *dev = &indio_dev->dev;

/* use low spi speed for init */
st->us->mode = SPI_MODE_3;
Expand Down Expand Up @@ -376,7 +377,7 @@ static ssize_t ade7759_write_frequency(struct device *dev,
size_t len)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
struct ade7759_state *st = iio_priv(indio_dev);
unsigned long val;
int ret;
u16 reg, t;
Expand Down Expand Up @@ -458,62 +459,41 @@ static const struct iio_info ade7759_info = {
static int __devinit ade7759_probe(struct spi_device *spi)
{
int ret;
struct ade7759_state *st = kzalloc(sizeof *st, GFP_KERNEL);
if (!st) {
ret = -ENOMEM;
struct ade7759_state *st;
struct iio_dev *indio_dev;

/* setup the industrialio driver allocated elements */
indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret;
}
/* this is only used for removal purposes */
spi_set_drvdata(spi, st);
spi_set_drvdata(spi, indio_dev);

/* Allocate the comms buffers */
st->rx = kzalloc(sizeof(*st->rx)*ADE7759_MAX_RX, GFP_KERNEL);
if (st->rx == NULL) {
ret = -ENOMEM;
goto error_free_st;
}
st->tx = kzalloc(sizeof(*st->tx)*ADE7759_MAX_TX, GFP_KERNEL);
if (st->tx == NULL) {
ret = -ENOMEM;
goto error_free_rx;
}
st = iio_priv(indio_dev);
st->us = spi;
mutex_init(&st->buf_lock);
/* setup the industrialio driver allocated elements */
st->indio_dev = iio_allocate_device(0);
if (st->indio_dev == NULL) {
ret = -ENOMEM;
goto error_free_tx;
}

st->indio_dev->name = spi->dev.driver->name;
st->indio_dev->dev.parent = &spi->dev;

st->indio_dev->info = &ade7759_info;
st->indio_dev->dev_data = (void *)(st);
st->indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &ade7759_info;
indio_dev->modes = INDIO_DIRECT_MODE;

ret = iio_device_register(st->indio_dev);
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;

/* Get the device into a sane initial state */
ret = ade7759_initial_setup(st);
ret = ade7759_initial_setup(indio_dev);
if (ret)
goto error_unreg_dev;
return 0;


error_unreg_dev:
iio_device_unregister(st->indio_dev);
iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(st->indio_dev);
error_free_tx:
kfree(st->tx);
error_free_rx:
kfree(st->rx);
error_free_st:
kfree(st);
iio_free_device(indio_dev);
error_ret:
return ret;
}
Expand All @@ -522,19 +502,13 @@ static int __devinit ade7759_probe(struct spi_device *spi)
static int ade7759_remove(struct spi_device *spi)
{
int ret;
struct ade7759_state *st = spi_get_drvdata(spi);
struct iio_dev *indio_dev = st->indio_dev;
struct iio_dev *indio_dev = spi_get_drvdata(spi);

ret = ade7759_stop_device(&(indio_dev->dev));
if (ret)
goto err_ret;

iio_device_unregister(indio_dev);
kfree(st->tx);
kfree(st->rx);
kfree(st);

return 0;

err_ret:
return ret;
Expand Down
12 changes: 5 additions & 7 deletions trunk/drivers/staging/iio/meter/ade7759.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@
/**
* struct ade7759_state - device instance specific data
* @us: actual spi_device
* @indio_dev: industrial I/O device structure
* @buf_lock: mutex to protect tx and rx
* @tx: transmit buffer
* @rx: receive buffer
* @buf_lock: mutex to protect tx and rx
**/
struct ade7759_state {
struct spi_device *us;
struct iio_dev *indio_dev;
u8 *tx;
u8 *rx;
struct mutex buf_lock;
struct spi_device *us;
struct mutex buf_lock;
u8 tx[ADE7759_MAX_TX] ____cacheline_aligned;
u8 rx[ADE7759_MAX_RX];
};

#endif

0 comments on commit 6441178

Please sign in to comment.