aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2010-05-16 16:11:38 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-18 17:42:57 -0400
commit9a3af585e7fe3df35b233977579b5ab6e4c7005f (patch)
tree5b0be0c5b24a71dd27616e2652a6283b539ea6a3 /drivers/staging
parent06f1962ab475bdee3ae17afbaecee5b23f3cd5f0 (diff)
Staging: iio: adis16220 extract bin_attribute structures from state
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/iio/accel/adis16220.h3
-rw-r--r--drivers/staging/iio/accel/adis16220_core.c106
2 files changed, 56 insertions, 53 deletions
diff --git a/drivers/staging/iio/accel/adis16220.h b/drivers/staging/iio/accel/adis16220.h
index 6b49f70eff47..2abf4850b373 100644
--- a/drivers/staging/iio/accel/adis16220.h
+++ b/drivers/staging/iio/accel/adis16220.h
@@ -141,9 +141,6 @@ struct adis16220_state {
141 struct iio_dev *indio_dev; 141 struct iio_dev *indio_dev;
142 u8 *tx; 142 u8 *tx;
143 u8 *rx; 143 u8 *rx;
144 struct bin_attribute accel_bin;
145 struct bin_attribute adc1_bin;
146 struct bin_attribute adc2_bin;
147 struct mutex buf_lock; 144 struct mutex buf_lock;
148}; 145};
149 146
diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c
index 8b845d9b7b9e..6de439fd1675 100644
--- a/drivers/staging/iio/accel/adis16220_core.c
+++ b/drivers/staging/iio/accel/adis16220_core.c
@@ -27,8 +27,6 @@
27 27
28#define DRIVER_NAME "adis16220" 28#define DRIVER_NAME "adis16220"
29 29
30static int adis16220_check_status(struct device *dev);
31
32/** 30/**
33 * adis16220_spi_write_reg_8() - write single byte to a register 31 * adis16220_spi_write_reg_8() - write single byte to a register
34 * @dev: device associated with child of actual device (iio_dev or iio_trig) 32 * @dev: device associated with child of actual device (iio_dev or iio_trig)
@@ -133,8 +131,6 @@ static int adis16220_spi_read_reg_16(struct device *dev,
133 mutex_lock(&st->buf_lock); 131 mutex_lock(&st->buf_lock);
134 st->tx[0] = ADIS16220_READ_REG(lower_reg_address); 132 st->tx[0] = ADIS16220_READ_REG(lower_reg_address);
135 st->tx[1] = 0; 133 st->tx[1] = 0;
136 st->tx[2] = 0;
137 st->tx[3] = 0;
138 134
139 spi_message_init(&msg); 135 spi_message_init(&msg);
140 spi_message_add_tail(&xfers[0], &msg); 136 spi_message_add_tail(&xfers[0], &msg);
@@ -275,23 +271,6 @@ static ssize_t adis16220_write_capture(struct device *dev,
275 return -1; 271 return -1;
276} 272}
277 273
278static int adis16220_self_test(struct device *dev)
279{
280 int ret;
281 ret = adis16220_spi_write_reg_16(dev,
282 ADIS16220_MSC_CTRL,
283 ADIS16220_MSC_CTRL_SELF_TEST_EN);
284 if (ret) {
285 dev_err(dev, "problem starting self test");
286 goto err_ret;
287 }
288
289 adis16220_check_status(dev);
290
291err_ret:
292 return ret;
293}
294
295static int adis16220_check_status(struct device *dev) 274static int adis16220_check_status(struct device *dev)
296{ 275{
297 u16 status; 276 u16 status;
@@ -320,6 +299,23 @@ error_ret:
320 return ret; 299 return ret;
321} 300}
322 301
302static int adis16220_self_test(struct device *dev)
303{
304 int ret;
305 ret = adis16220_spi_write_reg_16(dev,
306 ADIS16220_MSC_CTRL,
307 ADIS16220_MSC_CTRL_SELF_TEST_EN);
308 if (ret) {
309 dev_err(dev, "problem starting self test");
310 goto err_ret;
311 }
312
313 adis16220_check_status(dev);
314
315err_ret:
316 return ret;
317}
318
323static int adis16220_initial_setup(struct adis16220_state *st) 319static int adis16220_initial_setup(struct adis16220_state *st)
324{ 320{
325 int ret; 321 int ret;
@@ -433,6 +429,15 @@ static ssize_t adis16220_accel_bin_read(struct kobject *kobj,
433 ADIS16220_CAPT_BUFA); 429 ADIS16220_CAPT_BUFA);
434} 430}
435 431
432static struct bin_attribute accel_bin = {
433 .attr = {
434 .name = "accel_bin",
435 .mode = S_IRUGO,
436 },
437 .read = adis16220_accel_bin_read,
438 .size = ADIS16220_CAPTURE_SIZE,
439};
440
436static ssize_t adis16220_adc1_bin_read(struct kobject *kobj, 441static ssize_t adis16220_adc1_bin_read(struct kobject *kobj,
437 struct bin_attribute *attr, 442 struct bin_attribute *attr,
438 char *buf, loff_t off, 443 char *buf, loff_t off,
@@ -447,6 +452,15 @@ static ssize_t adis16220_adc1_bin_read(struct kobject *kobj,
447 ADIS16220_CAPT_BUF1); 452 ADIS16220_CAPT_BUF1);
448} 453}
449 454
455static struct bin_attribute adc1_bin = {
456 .attr = {
457 .name = "in0_bin",
458 .mode = S_IRUGO,
459 },
460 .read = adis16220_adc1_bin_read,
461 .size = ADIS16220_CAPTURE_SIZE,
462};
463
450static ssize_t adis16220_adc2_bin_read(struct kobject *kobj, 464static ssize_t adis16220_adc2_bin_read(struct kobject *kobj,
451 struct bin_attribute *attr, 465 struct bin_attribute *attr,
452 char *buf, loff_t off, 466 char *buf, loff_t off,
@@ -461,6 +475,16 @@ static ssize_t adis16220_adc2_bin_read(struct kobject *kobj,
461 ADIS16220_CAPT_BUF2); 475 ADIS16220_CAPT_BUF2);
462} 476}
463 477
478
479static struct bin_attribute adc2_bin = {
480 .attr = {
481 .name = "in1_bin",
482 .mode = S_IRUGO,
483 },
484 .read = adis16220_adc2_bin_read,
485 .size = ADIS16220_CAPTURE_SIZE,
486};
487
464static IIO_DEV_ATTR_IN_NAMED_RAW(supply, adis16220_read_12bit_unsigned, 488static IIO_DEV_ATTR_IN_NAMED_RAW(supply, adis16220_read_12bit_unsigned,
465 ADIS16220_CAPT_SUPPLY); 489 ADIS16220_CAPT_SUPPLY);
466static IIO_CONST_ATTR(in_supply_scale, "0.0012207"); 490static IIO_CONST_ATTR(in_supply_scale, "0.0012207");
@@ -481,12 +505,12 @@ static IIO_DEV_ATTR_IN_RAW(1, adis16220_read_16bit, ADIS16220_CAPT_BUF2);
481static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, 505static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL,
482 adis16220_write_reset, 0); 506 adis16220_write_reset, 0);
483 507
484#define IIO_DEV_ATTR_CAPTURE(_store) \ 508#define IIO_DEV_ATTR_CAPTURE(_store) \
485 IIO_DEVICE_ATTR(capture, S_IWUGO, NULL, _store, 0) 509 IIO_DEVICE_ATTR(capture, S_IWUGO, NULL, _store, 0)
486 510
487static IIO_DEV_ATTR_CAPTURE(adis16220_write_capture); 511static IIO_DEV_ATTR_CAPTURE(adis16220_write_capture);
488 512
489#define IIO_DEV_ATTR_CAPTURE_COUNT(_mode, _show, _store, _addr) \ 513#define IIO_DEV_ATTR_CAPTURE_COUNT(_mode, _show, _store, _addr) \
490 IIO_DEVICE_ATTR(capture_count, _mode, _show, _store, _addr) 514 IIO_DEVICE_ATTR(capture_count, _mode, _show, _store, _addr)
491 515
492static IIO_DEV_ATTR_CAPTURE_COUNT(S_IWUSR | S_IRUGO, 516static IIO_DEV_ATTR_CAPTURE_COUNT(S_IWUSR | S_IRUGO,
@@ -563,33 +587,15 @@ static int __devinit adis16220_probe(struct spi_device *spi)
563 goto error_free_dev; 587 goto error_free_dev;
564 regdone = 1; 588 regdone = 1;
565 589
566 st->accel_bin.attr.name = "accel_bin"; 590 ret = sysfs_create_bin_file(&st->indio_dev->dev.kobj, &accel_bin);
567 st->accel_bin.attr.mode = S_IRUGO;
568 st->accel_bin.attr.owner = THIS_MODULE;
569 st->accel_bin.read = adis16220_accel_bin_read;
570 st->accel_bin.size = ADIS16220_CAPTURE_SIZE;
571
572 ret = sysfs_create_bin_file(&st->indio_dev->dev.kobj, &st->accel_bin);
573 if (ret) 591 if (ret)
574 goto error_free_dev; 592 goto error_free_dev;
575 593
576 st->adc1_bin.attr.name = "adc1_bin"; 594 ret = sysfs_create_bin_file(&st->indio_dev->dev.kobj, &adc1_bin);
577 st->adc1_bin.attr.mode = S_IRUGO;
578 st->adc1_bin.attr.owner = THIS_MODULE;
579 st->adc1_bin.read = adis16220_adc1_bin_read;
580 st->adc1_bin.size = ADIS16220_CAPTURE_SIZE;
581
582 ret = sysfs_create_bin_file(&st->indio_dev->dev.kobj, &st->adc1_bin);
583 if (ret) 595 if (ret)
584 goto error_rm_accel_bin; 596 goto error_rm_accel_bin;
585 597
586 st->adc2_bin.attr.name = "adc2_bin"; 598 ret = sysfs_create_bin_file(&st->indio_dev->dev.kobj, &adc2_bin);
587 st->adc2_bin.attr.mode = S_IRUGO;
588 st->adc2_bin.attr.owner = THIS_MODULE;
589 st->adc2_bin.read = adis16220_adc2_bin_read;
590 st->adc2_bin.size = ADIS16220_CAPTURE_SIZE;
591
592 ret = sysfs_create_bin_file(&st->indio_dev->dev.kobj, &st->adc2_bin);
593 if (ret) 599 if (ret)
594 goto error_rm_adc1_bin; 600 goto error_rm_adc1_bin;
595 601
@@ -600,11 +606,11 @@ static int __devinit adis16220_probe(struct spi_device *spi)
600 return 0; 606 return 0;
601 607
602error_rm_adc2_bin: 608error_rm_adc2_bin:
603 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &st->adc2_bin); 609 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &adc2_bin);
604error_rm_adc1_bin: 610error_rm_adc1_bin:
605 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &st->adc1_bin); 611 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &adc1_bin);
606error_rm_accel_bin: 612error_rm_accel_bin:
607 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &st->accel_bin); 613 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &accel_bin);
608error_free_dev: 614error_free_dev:
609 if (regdone) 615 if (regdone)
610 iio_device_unregister(st->indio_dev); 616 iio_device_unregister(st->indio_dev);
@@ -627,9 +633,9 @@ static int adis16220_remove(struct spi_device *spi)
627 633
628 flush_scheduled_work(); 634 flush_scheduled_work();
629 635
630 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &st->adc2_bin); 636 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &adc2_bin);
631 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &st->adc1_bin); 637 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &adc1_bin);
632 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &st->accel_bin); 638 sysfs_remove_bin_file(&st->indio_dev->dev.kobj, &accel_bin);
633 iio_device_unregister(indio_dev); 639 iio_device_unregister(indio_dev);
634 kfree(st->tx); 640 kfree(st->tx);
635 kfree(st->rx); 641 kfree(st->rx);