diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-25 23:26:34 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-25 23:26:34 -0700 |
commit | 138051659902da7e6a09d379fee5dade2a80fcfd (patch) | |
tree | e0a90e27451b1fcd812675092d30c1059369cb87 /drivers/staging/iio/meter | |
parent | d5ef642355bdd9b383ff5c18cbc6102a06eecbaf (diff) | |
parent | e1703b329f7c7ea82ea181dc4c50020f25061a2c (diff) | |
download | op-kernel-dev-138051659902da7e6a09d379fee5dade2a80fcfd.zip op-kernel-dev-138051659902da7e6a09d379fee5dade2a80fcfd.tar.gz |
Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
* 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (741 commits)
staging:iio:meter:ade7753 should be 16 bit read not 8 bit for mode register.
staging:iio:kfifo_buf fix double initialization of the ring device structure.
staging:iio:accel:lis3l02dq: fix incorrect pointer passed to spi_set_drvdata.
staging:iio:imu fix missing register table index for some channels
spectra: enable device before poking it
staging: rts_pstor: Fix a miswriting
staging/lirc_bt829: Return -ENODEV when no hardware is found.
staging/lirc_parallel: remove pointless prototypes.
staging/lirc_parallel: fix panic on rmmod
staging:iio:adc:ad7476: Incorrect pointer into spi_set_drvdata.
Staging: zram: Fix kunmapping order
Revert "gma500: Fix dependencies"
gma500: Add medfield header
gma500: wire up the mrst i2c bus from chip_info
gma500: Fix DPU build
gma500: Clean up the DPU config and make it runtime
gma500: resync with Medfield progress
gma500: Use the mrst helpers and power control for mode commit
gma500@ Fix backlight range error
gma500: More Moorestown muddle meddling means MM maybe might modeset
...
Fix up fairly trivial conflicts all over, mostly due to header file
cleanup conflicts, but some deleted files and some just context changes:
- Documentation/feature-removal-schedule.txt
- drivers/staging/bcm/headers.h
- drivers/staging/brcm80211/brcmfmac/dhd_linux.c
- drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
- drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
- drivers/staging/brcm80211/brcmfmac/wl_iw.c
- drivers/staging/et131x/et131x_netdev.c
- drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
- drivers/staging/rtl8192e/r8192E.h
- drivers/staging/usbip/userspace/src/utils.h
Diffstat (limited to 'drivers/staging/iio/meter')
-rw-r--r-- | drivers/staging/iio/meter/ade7753.c | 83 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7753.h | 10 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7754.c | 80 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7754.h | 12 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7759.c | 80 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7759.h | 12 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7854-i2c.c | 39 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7854-spi.c | 40 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7854.c | 76 | ||||
-rw-r--r-- | drivers/staging/iio/meter/ade7854.h | 36 |
10 files changed, 181 insertions, 287 deletions
diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c index 6c9c23f..4d1bd42 100644 --- a/drivers/staging/iio/meter/ade7753.c +++ b/drivers/staging/iio/meter/ade7753.c @@ -29,7 +29,7 @@ static int ade7753_spi_write_reg_8(struct device *dev, { int ret; struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7753_state *st = iio_dev_get_devdata(indio_dev); + struct ade7753_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); st->tx[0] = ADE7753_WRITE_REG(reg_address); @@ -47,7 +47,7 @@ static int ade7753_spi_write_reg_16(struct device *dev, { int ret; struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7753_state *st = iio_dev_get_devdata(indio_dev); + struct ade7753_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); st->tx[0] = ADE7753_WRITE_REG(reg_address); @@ -64,7 +64,7 @@ static int ade7753_spi_read_reg_8(struct device *dev, u8 *val) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7753_state *st = iio_dev_get_devdata(indio_dev); + struct ade7753_state *st = iio_priv(indio_dev); ssize_t ret; ret = spi_w8r8(st->us, ADE7753_READ_REG(reg_address)); @@ -83,7 +83,7 @@ static int ade7753_spi_read_reg_16(struct device *dev, u16 *val) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7753_state *st = iio_dev_get_devdata(indio_dev); + struct ade7753_state *st = iio_priv(indio_dev); ssize_t ret; ret = spi_w8r16(st->us, ADE7753_READ_REG(reg_address)); @@ -105,7 +105,7 @@ static int ade7753_spi_read_reg_24(struct device *dev, { struct spi_message msg; struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7753_state *st = iio_dev_get_devdata(indio_dev); + struct ade7753_state *st = iio_priv(indio_dev); int ret; struct spi_transfer xfers[] = { { @@ -369,10 +369,11 @@ static int ade7753_stop_device(struct device *dev) return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val); } -static int ade7753_initial_setup(struct ade7753_state *st) +static int ade7753_initial_setup(struct iio_dev *indio_dev) { int ret; - struct device *dev = &st->indio_dev->dev; + struct device *dev = &indio_dev->dev; + struct ade7753_state *st = iio_priv(indio_dev); /* use low spi speed for init */ st->us->mode = SPI_MODE_3; @@ -397,9 +398,9 @@ static ssize_t ade7753_read_frequency(struct device *dev, char *buf) { int ret, len = 0; - u8 t; + u16 t; int sps; - ret = ade7753_spi_read_reg_8(dev, ADE7753_MODE, &t); + ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &t); if (ret) return ret; @@ -416,7 +417,7 @@ static ssize_t ade7753_write_frequency(struct device *dev, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7753_state *st = iio_dev_get_devdata(indio_dev); + struct ade7753_state *st = iio_priv(indio_dev); unsigned long val; int ret; u16 reg, t; @@ -512,62 +513,44 @@ static const struct iio_info ade7753_info = { static int __devinit ade7753_probe(struct spi_device *spi) { int ret, regdone = 0; - struct ade7753_state *st = kzalloc(sizeof *st, GFP_KERNEL); - if (!st) { - ret = -ENOMEM; + struct ade7753_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)*ADE7753_MAX_RX, GFP_KERNEL); - if (st->rx == NULL) { - ret = -ENOMEM; - goto error_free_st; - } - st->tx = kzalloc(sizeof(*st->tx)*ADE7753_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 = &ade7753_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 = &ade7753_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; regdone = 1; /* Get the device into a sane initial state */ - ret = ade7753_initial_setup(st); + ret = ade7753_initial_setup(indio_dev); if (ret) goto error_free_dev; return 0; error_free_dev: if (regdone) - iio_device_unregister(st->indio_dev); + iio_device_unregister(indio_dev); else - 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; } @@ -576,19 +559,13 @@ error_ret: static int ade7753_remove(struct spi_device *spi) { int ret; - struct ade7753_state *st = spi_get_drvdata(spi); - struct iio_dev *indio_dev = st->indio_dev; + struct iio_dev *indio_dev = spi_get_drvdata(spi); ret = ade7753_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; diff --git a/drivers/staging/iio/meter/ade7753.h b/drivers/staging/iio/meter/ade7753.h index 3b9c7f6..3f059d3 100644 --- a/drivers/staging/iio/meter/ade7753.h +++ b/drivers/staging/iio/meter/ade7753.h @@ -60,17 +60,15 @@ /** * struct ade7753_state - device instance specific data * @us: actual spi_device - * @indio_dev: industrial I/O device structure * @tx: transmit buffer * @rx: receive buffer * @buf_lock: mutex to protect tx and rx **/ struct ade7753_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[ADE7753_MAX_TX] ____cacheline_aligned; + u8 rx[ADE7753_MAX_RX]; }; #endif diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c index 378f2c8..f4f85fd 100644 --- a/drivers/staging/iio/meter/ade7754.c +++ b/drivers/staging/iio/meter/ade7754.c @@ -29,7 +29,7 @@ static int ade7754_spi_write_reg_8(struct device *dev, { int ret; struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7754_state *st = iio_dev_get_devdata(indio_dev); + struct ade7754_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); st->tx[0] = ADE7754_WRITE_REG(reg_address); @@ -47,7 +47,7 @@ static int ade7754_spi_write_reg_16(struct device *dev, { int ret; struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7754_state *st = iio_dev_get_devdata(indio_dev); + struct ade7754_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); st->tx[0] = ADE7754_WRITE_REG(reg_address); @@ -64,7 +64,7 @@ static int ade7754_spi_read_reg_8(struct device *dev, u8 *val) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7754_state *st = iio_dev_get_devdata(indio_dev); + struct ade7754_state *st = iio_priv(indio_dev); int ret; ret = spi_w8r8(st->us, ADE7754_READ_REG(reg_address)); @@ -83,7 +83,7 @@ static int ade7754_spi_read_reg_16(struct device *dev, u16 *val) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7754_state *st = iio_dev_get_devdata(indio_dev); + struct ade7754_state *st = iio_priv(indio_dev); int ret; ret = spi_w8r16(st->us, ADE7754_READ_REG(reg_address)); @@ -105,7 +105,7 @@ static int ade7754_spi_read_reg_24(struct device *dev, { struct spi_message msg; struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7754_state *st = iio_dev_get_devdata(indio_dev); + struct ade7754_state *st = iio_priv(indio_dev); int ret; struct spi_transfer xfers[] = { { @@ -388,10 +388,11 @@ static int ade7754_stop_device(struct device *dev) return ade7754_spi_write_reg_8(dev, ADE7754_OPMODE, val); } -static int ade7754_initial_setup(struct ade7754_state *st) +static int ade7754_initial_setup(struct iio_dev *indio_dev) { int ret; - struct device *dev = &st->indio_dev->dev; + struct ade7754_state *st = iio_priv(indio_dev); + struct device *dev = &indio_dev->dev; /* use low spi speed for init */ st->us->mode = SPI_MODE_3; @@ -436,7 +437,7 @@ static ssize_t ade7754_write_frequency(struct device *dev, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ade7754_state *st = iio_dev_get_devdata(indio_dev); + struct ade7754_state *st = iio_priv(indio_dev); unsigned long val; int ret; u8 reg, t; @@ -535,62 +536,44 @@ static const struct iio_info ade7754_info = { static int __devinit ade7754_probe(struct spi_device *spi) { int ret, regdone = 0; - struct ade7754_state *st = kzalloc(sizeof *st, GFP_KERNEL); - if (!st) { - ret = -ENOMEM; + struct ade7754_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)*ADE7754_MAX_RX, GFP_KERNEL); - if (st->rx == NULL) { - ret = -ENOMEM; - goto error_free_st; - } - st->tx = kzalloc(sizeof(*st->tx)*ADE7754_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 = &ade7754_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 = &ade7754_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; regdone = 1; /* Get the device into a sane initial state */ - ret = ade7754_initial_setup(st); + ret = ade7754_initial_setup(indio_dev); if (ret) goto error_free_dev; return 0; error_free_dev: if (regdone) - iio_device_unregister(st->indio_dev); + iio_device_unregister(indio_dev); else - 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; } @@ -599,22 +582,17 @@ error_ret: static int ade7754_remove(struct spi_device *spi) { int ret; - struct ade7754_state *st = spi_get_drvdata(spi); - struct iio_dev *indio_dev = st->indio_dev; + struct iio_dev *indio_dev = spi_get_drvdata(spi); ret = ade7754_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; + } static struct spi_driver ade7754_driver = { diff --git a/drivers/staging/iio/meter/ade7754.h b/drivers/staging/iio/meter/ade7754.h index 0aa0522..6121125 100644 --- a/drivers/staging/iio/meter/ade7754.h +++ b/drivers/staging/iio/meter/ade7754.h @@ -78,17 +78,15 @@ /** * struct ade7754_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 ade7754_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[ADE7754_MAX_TX] ____cacheline_aligned; + u8 rx[ADE7754_MAX_RX]; }; #endif diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c index 730f6d9..a51a64c 100644 --- a/drivers/staging/iio/meter/ade7759.c +++ b/drivers/staging/iio/meter/ade7759.c @@ -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); @@ -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); @@ -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)); @@ -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)); @@ -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[] = { { @@ -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; @@ -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; @@ -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; } @@ -522,19 +502,13 @@ error_ret: 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; diff --git a/drivers/staging/iio/meter/ade7759.h b/drivers/staging/iio/meter/ade7759.h index cc76c2c..c81d23d 100644 --- a/drivers/staging/iio/meter/ade7759.h +++ b/drivers/staging/iio/meter/ade7759.h @@ -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 diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c index 4578e7b..dd72343 100644 --- a/drivers/staging/iio/meter/ade7854-i2c.c +++ b/drivers/staging/iio/meter/ade7854-i2c.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; @@ -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; } diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c index 84da8fb..e0d1086 100644 --- a/drivers/staging/iio/meter/ade7854-spi.c +++ b/drivers/staging/iio/meter/ade7854-spi.c @@ -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, @@ -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, @@ -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, @@ -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, @@ -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[] = { { @@ -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[] = { { @@ -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[] = { { @@ -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[] = { { @@ -302,13 +302,14 @@ error_ret: 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; @@ -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; } diff --git a/drivers/staging/iio/meter/ade7854.c b/drivers/staging/iio/meter/ade7854.c index 44cd3ec..b82659f 100644 --- a/drivers/staging/iio/meter/ade7854.c +++ b/drivers/staging/iio/meter/ade7854.c @@ -29,7 +29,7 @@ static ssize_t ade7854_read_8bit(struct device *dev, int ret; u8 val = 0; 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 iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = st->read_reg_8(dev, this_attr->address, &val); @@ -46,7 +46,7 @@ static ssize_t ade7854_read_16bit(struct device *dev, int ret; u16 val = 0; 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 iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = st->read_reg_16(dev, this_attr->address, &val); @@ -63,7 +63,7 @@ static ssize_t ade7854_read_24bit(struct device *dev, int ret; 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); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = st->read_reg_24(dev, this_attr->address, &val); @@ -81,7 +81,7 @@ static ssize_t ade7854_read_32bit(struct device *dev, u32 val = 0; struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 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); ret = st->read_reg_32(dev, this_attr->address, &val); if (ret) @@ -97,7 +97,7 @@ static ssize_t ade7854_write_8bit(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 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; long val; @@ -118,7 +118,7 @@ static ssize_t ade7854_write_16bit(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 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; long val; @@ -139,7 +139,7 @@ static ssize_t ade7854_write_24bit(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 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; long val; @@ -160,7 +160,7 @@ static ssize_t ade7854_write_32bit(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 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; long val; @@ -177,7 +177,7 @@ error_ret: static int ade7854_reset(struct device *dev) { 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); u16 val; st->read_reg_16(dev, ADE7854_CONFIG, &val); @@ -426,7 +426,7 @@ static IIO_DEV_ATTR_CVAHR(ade7854_read_32bit, static int ade7854_set_irq(struct device *dev, bool enable) { 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; u32 irqen; @@ -449,10 +449,10 @@ error_ret: return ret; } -static int ade7854_initial_setup(struct ade7854_state *st) +static int ade7854_initial_setup(struct iio_dev *indio_dev) { int ret; - struct device *dev = &st->indio_dev->dev; + struct device *dev = &indio_dev->dev; /* Disable IRQ */ ret = ade7854_set_irq(dev, false); @@ -556,68 +556,40 @@ static const struct iio_info ade7854_info = { .driver_module = THIS_MODULE, }; -int ade7854_probe(struct ade7854_state *st, struct device *dev) +int ade7854_probe(struct iio_dev *indio_dev, struct device *dev) { int ret; - - /* Allocate the comms buffers */ - st->rx = kzalloc(sizeof(*st->rx)*ADE7854_MAX_RX, GFP_KERNEL); - if (st->rx == NULL) { - ret = -ENOMEM; - goto error_free_st; - } - st->tx = kzalloc(sizeof(*st->tx)*ADE7854_MAX_TX, GFP_KERNEL); - if (st->tx == NULL) { - ret = -ENOMEM; - goto error_free_rx; - } - mutex_init(&st->buf_lock); + struct ade7854_state *st = iio_priv(indio_dev); /* setup the industrialio driver allocated elements */ - st->indio_dev = iio_allocate_device(0); - if (st->indio_dev == NULL) { - ret = -ENOMEM; - goto error_free_tx; - } + mutex_init(&st->buf_lock); - st->indio_dev->dev.parent = dev; - st->indio_dev->info = &ade7854_info; - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->dev.parent = dev; + indio_dev->info = &ade7854_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 = ade7854_initial_setup(st); + ret = ade7854_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; } EXPORT_SYMBOL(ade7854_probe); -int ade7854_remove(struct ade7854_state *st) +int ade7854_remove(struct iio_dev *indio_dev) { - struct iio_dev *indio_dev = st->indio_dev; - iio_device_unregister(indio_dev); - kfree(st->tx); - kfree(st->rx); - kfree(st); return 0; } diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h index 79a2110..2c96e86 100644 --- a/drivers/staging/iio/meter/ade7854.h +++ b/drivers/staging/iio/meter/ade7854.h @@ -148,29 +148,29 @@ * struct ade7854_state - device instance specific data * @spi: 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 ade7854_state { - struct spi_device *spi; - struct i2c_client *i2c; - struct iio_dev *indio_dev; - u8 *tx; - u8 *rx; - int (*read_reg_8) (struct device *, u16, u8 *); - int (*read_reg_16) (struct device *, u16, u16 *); - int (*read_reg_24) (struct device *, u16, u32 *); - int (*read_reg_32) (struct device *, u16, u32 *); - int (*write_reg_8) (struct device *, u16, u8); - int (*write_reg_16) (struct device *, u16, u16); - int (*write_reg_24) (struct device *, u16, u32); - int (*write_reg_32) (struct device *, u16, u32); - int irq; - struct mutex buf_lock; + struct spi_device *spi; + struct i2c_client *i2c; + int (*read_reg_8) (struct device *, u16, u8 *); + int (*read_reg_16) (struct device *, u16, u16 *); + int (*read_reg_24) (struct device *, u16, u32 *); + int (*read_reg_32) (struct device *, u16, u32 *); + int (*write_reg_8) (struct device *, u16, u8); + int (*write_reg_16) (struct device *, u16, u16); + int (*write_reg_24) (struct device *, u16, u32); + int (*write_reg_32) (struct device *, u16, u32); + int irq; + struct mutex buf_lock; + u8 tx[ADE7854_MAX_TX] ____cacheline_aligned; + u8 rx[ADE7854_MAX_RX]; + }; -extern int ade7854_probe(struct ade7854_state *st, struct device *dev); -extern int ade7854_remove(struct ade7854_state *st); +extern int ade7854_probe(struct iio_dev *indio_dev, struct device *dev); +extern int ade7854_remove(struct iio_dev *indio_dev); #endif |