Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'iio-for-v3.7a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

First set of IIO rework and new drivers for 3.7 cycle.

New MXS adc driver form Marek Vasut with a minor addition
to the example code to support 4 byte reads.

First of I suspect many devm conversion patches form Julia Lawall
Some module_platform_driver uses that somehow got missed the
first time around.

Couple of other useful cleanups.

+678 -89
+15
Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
··· 1 + * Freescale i.MX28 LRADC device driver 2 + 3 + Required properties: 4 + - compatible: Should be "fsl,imx28-lradc" 5 + - reg: Address and length of the register set for the device 6 + - interrupts: Should contain the LRADC interrupts 7 + 8 + Examples: 9 + 10 + lradc@80050000 { 11 + compatible = "fsl,imx28-lradc"; 12 + reg = <0x80050000 0x2000>; 13 + interrupts = <10 14 15 16 17 18 19 14 + 20 21 22 23 24 25>; 15 + };
+8 -34
drivers/iio/adc/at91_adc.c
··· 545 545 goto error_free_device; 546 546 } 547 547 548 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 549 - if (!res) { 550 - dev_err(&pdev->dev, "No resource defined\n"); 551 - ret = -ENXIO; 552 - goto error_ret; 553 - } 554 - 555 548 platform_set_drvdata(pdev, idev); 556 549 557 550 idev->dev.parent = &pdev->dev; ··· 559 566 goto error_free_device; 560 567 } 561 568 562 - if (!request_mem_region(res->start, resource_size(res), 563 - "AT91 adc registers")) { 564 - dev_err(&pdev->dev, "Resources are unavailable.\n"); 565 - ret = -EBUSY; 566 - goto error_free_device; 567 - } 569 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 568 570 569 - st->reg_base = ioremap(res->start, resource_size(res)); 571 + st->reg_base = devm_request_and_ioremap(&pdev->dev, res); 570 572 if (!st->reg_base) { 571 - dev_err(&pdev->dev, "Failed to map registers.\n"); 572 573 ret = -ENOMEM; 573 - goto error_release_mem; 574 + goto error_free_device; 574 575 } 575 576 576 577 /* ··· 579 592 idev); 580 593 if (ret) { 581 594 dev_err(&pdev->dev, "Failed to allocate IRQ.\n"); 582 - goto error_unmap_reg; 595 + goto error_free_device; 583 596 } 584 597 585 - st->clk = clk_get(&pdev->dev, "adc_clk"); 598 + st->clk = devm_clk_get(&pdev->dev, "adc_clk"); 586 599 if (IS_ERR(st->clk)) { 587 600 dev_err(&pdev->dev, "Failed to get the clock.\n"); 588 601 ret = PTR_ERR(st->clk); ··· 592 605 ret = clk_prepare(st->clk); 593 606 if (ret) { 594 607 dev_err(&pdev->dev, "Could not prepare the clock.\n"); 595 - goto error_free_clk; 608 + goto error_free_irq; 596 609 } 597 610 598 611 ret = clk_enable(st->clk); ··· 601 614 goto error_unprepare_clk; 602 615 } 603 616 604 - st->adc_clk = clk_get(&pdev->dev, "adc_op_clk"); 617 + st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk"); 605 618 if (IS_ERR(st->adc_clk)) { 606 619 dev_err(&pdev->dev, "Failed to get the ADC clock.\n"); 607 620 ret = PTR_ERR(st->clk); ··· 611 624 ret = clk_prepare(st->adc_clk); 612 625 if (ret) { 613 626 dev_err(&pdev->dev, "Could not prepare the ADC clock.\n"); 614 - goto error_free_adc_clk; 627 + goto error_disable_clk; 615 628 } 616 629 617 630 ret = clk_enable(st->adc_clk); ··· 684 697 clk_disable(st->adc_clk); 685 698 error_unprepare_adc_clk: 686 699 clk_unprepare(st->adc_clk); 687 - error_free_adc_clk: 688 - clk_put(st->adc_clk); 689 700 error_disable_clk: 690 701 clk_disable(st->clk); 691 702 error_unprepare_clk: 692 703 clk_unprepare(st->clk); 693 - error_free_clk: 694 - clk_put(st->clk); 695 704 error_free_irq: 696 705 free_irq(st->irq, idev); 697 - error_unmap_reg: 698 - iounmap(st->reg_base); 699 - error_release_mem: 700 - release_mem_region(res->start, resource_size(res)); 701 706 error_free_device: 702 707 iio_device_free(idev); 703 708 error_ret: ··· 699 720 static int __devexit at91_adc_remove(struct platform_device *pdev) 700 721 { 701 722 struct iio_dev *idev = platform_get_drvdata(pdev); 702 - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 703 723 struct at91_adc_state *st = iio_priv(idev); 704 724 705 725 iio_device_unregister(idev); 706 726 at91_adc_trigger_remove(idev); 707 727 at91_adc_buffer_remove(idev); 708 728 clk_disable_unprepare(st->adc_clk); 709 - clk_put(st->adc_clk); 710 729 clk_disable(st->clk); 711 730 clk_unprepare(st->clk); 712 - clk_put(st->clk); 713 731 free_irq(st->irq, idev); 714 - iounmap(st->reg_base); 715 - release_mem_region(res->start, resource_size(res)); 716 732 iio_device_free(idev); 717 733 718 734 return 0;
+10
drivers/staging/iio/Documentation/generic_buffer.c
··· 104 104 print2byte(*(uint16_t *)(data + channels[k].location), 105 105 &channels[k]); 106 106 break; 107 + case 4: 108 + if (!channels[k].is_signed) { 109 + uint32_t val = *(uint32_t *) 110 + (data + channels[k].location); 111 + printf("%05f ", ((float)val + 112 + channels[k].offset)* 113 + channels[k].scale); 114 + 115 + } 116 + break; 107 117 case 8: 108 118 if (channels[k].is_signed) { 109 119 int64_t val = *(int64_t *)
+1 -1
drivers/staging/iio/accel/adis16201_core.c
··· 390 390 return -EINVAL; 391 391 } 392 392 393 - static struct iio_chan_spec adis16201_channels[] = { 393 + static const struct iio_chan_spec adis16201_channels[] = { 394 394 { 395 395 .type = IIO_VOLTAGE, 396 396 .indexed = 1,
+1 -1
drivers/staging/iio/accel/adis16203_core.c
··· 355 355 } 356 356 } 357 357 358 - static struct iio_chan_spec adis16203_channels[] = { 358 + static const struct iio_chan_spec adis16203_channels[] = { 359 359 { 360 360 .type = IIO_VOLTAGE, 361 361 .indexed = 1,
+1 -1
drivers/staging/iio/accel/adis16204_core.c
··· 397 397 return -EINVAL; 398 398 } 399 399 400 - static struct iio_chan_spec adis16204_channels[] = { 400 + static const struct iio_chan_spec adis16204_channels[] = { 401 401 { 402 402 .type = IIO_VOLTAGE, 403 403 .indexed = 1, /* Note was not previously indexed */
+1 -1
drivers/staging/iio/accel/adis16209_core.c
··· 390 390 return -EINVAL; 391 391 } 392 392 393 - static struct iio_chan_spec adis16209_channels[] = { 393 + static const struct iio_chan_spec adis16209_channels[] = { 394 394 { 395 395 .type = IIO_VOLTAGE, 396 396 .indexed = 1,
+3 -6
drivers/staging/iio/accel/adis16220_core.c
··· 372 372 loff_t off, 373 373 size_t count) 374 374 { 375 - struct device *dev = container_of(kobj, struct device, kobj); 376 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 375 + struct iio_dev *indio_dev = dev_to_iio_dev(kobj_to_dev(kobj)); 377 376 378 377 return adis16220_capture_buffer_read(indio_dev, buf, 379 378 off, count, ··· 393 394 char *buf, loff_t off, 394 395 size_t count) 395 396 { 396 - struct device *dev = container_of(kobj, struct device, kobj); 397 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 397 + struct iio_dev *indio_dev = dev_to_iio_dev(kobj_to_dev(kobj)); 398 398 399 399 return adis16220_capture_buffer_read(indio_dev, buf, 400 400 off, count, ··· 414 416 char *buf, loff_t off, 415 417 size_t count) 416 418 { 417 - struct device *dev = container_of(kobj, struct device, kobj); 418 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 419 + struct iio_dev *indio_dev = dev_to_iio_dev(kobj_to_dev(kobj)); 419 420 420 421 return adis16220_capture_buffer_read(indio_dev, buf, 421 422 off, count,
+1 -1
drivers/staging/iio/accel/adis16240_core.c
··· 448 448 return -EINVAL; 449 449 } 450 450 451 - static struct iio_chan_spec adis16240_channels[] = { 451 + static const struct iio_chan_spec adis16240_channels[] = { 452 452 { 453 453 .type = IIO_VOLTAGE, 454 454 .indexed = 1,
+1 -1
drivers/staging/iio/accel/kxsd9.c
··· 186 186 .address = KXSD9_REG_##axis, \ 187 187 } 188 188 189 - static struct iio_chan_spec kxsd9_channels[] = { 189 + static const struct iio_chan_spec kxsd9_channels[] = { 190 190 KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z), 191 191 { 192 192 .type = IIO_VOLTAGE,
+1 -1
drivers/staging/iio/accel/lis3l02dq_core.c
··· 538 538 .event_mask = LIS3L02DQ_EVENT_MASK, \ 539 539 } 540 540 541 - static struct iio_chan_spec lis3l02dq_channels[] = { 541 + static const struct iio_chan_spec lis3l02dq_channels[] = { 542 542 LIS3L02DQ_CHAN(0, IIO_MOD_X), 543 543 LIS3L02DQ_CHAN(1, IIO_MOD_Y), 544 544 LIS3L02DQ_CHAN(2, IIO_MOD_Z),
+1 -1
drivers/staging/iio/accel/sca3000_core.c
··· 450 450 .event_mask = SCA3000_EVENT_MASK, \ 451 451 } 452 452 453 - static struct iio_chan_spec sca3000_channels[] = { 453 + static const struct iio_chan_spec sca3000_channels[] = { 454 454 SCA3000_CHAN(0, IIO_MOD_X), 455 455 SCA3000_CHAN(1, IIO_MOD_Y), 456 456 SCA3000_CHAN(2, IIO_MOD_Z),
+12
drivers/staging/iio/adc/Kconfig
··· 200 200 activate only one via device tree selection. Provides direct access 201 201 via sysfs. 202 202 203 + config MXS_LRADC 204 + tristate "Freescale i.MX28 LRADC" 205 + depends on ARCH_MXS 206 + select IIO_BUFFER 207 + select IIO_TRIGGERED_BUFFER 208 + help 209 + Say yes here to build support for i.MX28 LRADC convertor 210 + built into these chips. 211 + 212 + To compile this driver as a module, choose M here: the 213 + module will be called mxs-lradc. 214 + 203 215 config SPEAR_ADC 204 216 tristate "ST SPEAr ADC" 205 217 depends on PLAT_SPEAR
+1
drivers/staging/iio/adc/Makefile
··· 38 38 obj-$(CONFIG_ADT7410) += adt7410.o 39 39 obj-$(CONFIG_AD7280) += ad7280a.o 40 40 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 41 + obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o 41 42 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
+1 -1
drivers/staging/iio/adc/ad7192.c
··· 967 967 .scan_index = _si, \ 968 968 .scan_type = IIO_ST('s', 24, 32, 0)} 969 969 970 - static struct iio_chan_spec ad7192_channels[] = { 970 + static const struct iio_chan_spec ad7192_channels[] = { 971 971 AD7192_CHAN_DIFF(1, 2, NULL, AD7192_CH_AIN1P_AIN2M, 0), 972 972 AD7192_CHAN_DIFF(3, 4, NULL, AD7192_CH_AIN3P_AIN4M, 1), 973 973 AD7192_CHAN_TEMP(0, AD7192_CH_TEMP, 2),
+1 -1
drivers/staging/iio/adc/ad7298_core.c
··· 38 38 }, \ 39 39 } 40 40 41 - static struct iio_chan_spec ad7298_channels[] = { 41 + static const struct iio_chan_spec ad7298_channels[] = { 42 42 { 43 43 .type = IIO_TEMP, 44 44 .indexed = 1,
+1 -1
drivers/staging/iio/adc/ad7606.h
··· 51 51 struct ad7606_chip_info { 52 52 const char *name; 53 53 u16 int_vref_mv; 54 - struct iio_chan_spec *channels; 54 + const struct iio_chan_spec *channels; 55 55 unsigned num_channels; 56 56 }; 57 57
+3 -3
drivers/staging/iio/adc/ad7606_core.c
··· 241 241 .scan_type = IIO_ST('s', 16, 16, 0), \ 242 242 } 243 243 244 - static struct iio_chan_spec ad7606_8_channels[] = { 244 + static const struct iio_chan_spec ad7606_8_channels[] = { 245 245 AD7606_CHANNEL(0), 246 246 AD7606_CHANNEL(1), 247 247 AD7606_CHANNEL(2), ··· 253 253 IIO_CHAN_SOFT_TIMESTAMP(8), 254 254 }; 255 255 256 - static struct iio_chan_spec ad7606_6_channels[] = { 256 + static const struct iio_chan_spec ad7606_6_channels[] = { 257 257 AD7606_CHANNEL(0), 258 258 AD7606_CHANNEL(1), 259 259 AD7606_CHANNEL(2), ··· 263 263 IIO_CHAN_SOFT_TIMESTAMP(6), 264 264 }; 265 265 266 - static struct iio_chan_spec ad7606_4_channels[] = { 266 + static const struct iio_chan_spec ad7606_4_channels[] = { 267 267 AD7606_CHANNEL(0), 268 268 AD7606_CHANNEL(1), 269 269 AD7606_CHANNEL(2),
+1 -1
drivers/staging/iio/adc/lpc32xx_adc.c
··· 108 108 .scan_index = _index, \ 109 109 } 110 110 111 - static struct iio_chan_spec lpc32xx_adc_iio_channels[] = { 111 + static const struct iio_chan_spec lpc32xx_adc_iio_channels[] = { 112 112 LPC32XX_ADC_CHANNEL(0), 113 113 LPC32XX_ADC_CHANNEL(1), 114 114 LPC32XX_ADC_CHANNEL(2),
+1 -1
drivers/staging/iio/adc/max1363.h
··· 100 100 */ 101 101 struct max1363_chip_info { 102 102 const struct iio_info *info; 103 - struct iio_chan_spec *channels; 103 + const struct iio_chan_spec *channels; 104 104 int num_channels; 105 105 const enum max1363_modes *mode_list; 106 106 enum max1363_modes default_mode;
+13 -13
drivers/staging/iio/adc/max1363_core.c
··· 335 335 IIO_CHAN_SOFT_TIMESTAMP(8) \ 336 336 } 337 337 338 - static struct iio_chan_spec max1036_channels[] = MAX1363_4X_CHANS(8, 0); 339 - static struct iio_chan_spec max1136_channels[] = MAX1363_4X_CHANS(10, 0); 340 - static struct iio_chan_spec max1236_channels[] = MAX1363_4X_CHANS(12, 0); 341 - static struct iio_chan_spec max1361_channels[] = 338 + static const struct iio_chan_spec max1036_channels[] = MAX1363_4X_CHANS(8, 0); 339 + static const struct iio_chan_spec max1136_channels[] = MAX1363_4X_CHANS(10, 0); 340 + static const struct iio_chan_spec max1236_channels[] = MAX1363_4X_CHANS(12, 0); 341 + static const struct iio_chan_spec max1361_channels[] = 342 342 MAX1363_4X_CHANS(10, MAX1363_EV_M); 343 - static struct iio_chan_spec max1363_channels[] = 343 + static const struct iio_chan_spec max1363_channels[] = 344 344 MAX1363_4X_CHANS(12, MAX1363_EV_M); 345 345 346 346 /* Applies to max1236, max1237 */ ··· 392 392 MAX1363_CHAN_B(11, 10, d11m10, 23, bits, 0), \ 393 393 IIO_CHAN_SOFT_TIMESTAMP(24) \ 394 394 } 395 - static struct iio_chan_spec max1038_channels[] = MAX1363_12X_CHANS(8); 396 - static struct iio_chan_spec max1138_channels[] = MAX1363_12X_CHANS(10); 397 - static struct iio_chan_spec max1238_channels[] = MAX1363_12X_CHANS(12); 395 + static const struct iio_chan_spec max1038_channels[] = MAX1363_12X_CHANS(8); 396 + static const struct iio_chan_spec max1138_channels[] = MAX1363_12X_CHANS(10); 397 + static const struct iio_chan_spec max1238_channels[] = MAX1363_12X_CHANS(12); 398 398 399 399 static const enum max1363_modes max11607_mode_list[] = { 400 400 _s0, _s1, _s2, _s3, ··· 433 433 MAX1363_CHAN_B(7, 6, d7m6, 15, bits, 0), \ 434 434 IIO_CHAN_SOFT_TIMESTAMP(16) \ 435 435 } 436 - static struct iio_chan_spec max11602_channels[] = MAX1363_8X_CHANS(8); 437 - static struct iio_chan_spec max11608_channels[] = MAX1363_8X_CHANS(10); 438 - static struct iio_chan_spec max11614_channels[] = MAX1363_8X_CHANS(12); 436 + static const struct iio_chan_spec max11602_channels[] = MAX1363_8X_CHANS(8); 437 + static const struct iio_chan_spec max11608_channels[] = MAX1363_8X_CHANS(10); 438 + static const struct iio_chan_spec max11614_channels[] = MAX1363_8X_CHANS(12); 439 439 440 440 static const enum max1363_modes max11644_mode_list[] = { 441 441 _s0, _s1, s0to1, d0m1, d1m0, ··· 449 449 IIO_CHAN_SOFT_TIMESTAMP(4) \ 450 450 } 451 451 452 - static struct iio_chan_spec max11646_channels[] = MAX1363_2X_CHANS(10); 453 - static struct iio_chan_spec max11644_channels[] = MAX1363_2X_CHANS(12); 452 + static const struct iio_chan_spec max11646_channels[] = MAX1363_2X_CHANS(10); 453 + static const struct iio_chan_spec max11644_channels[] = MAX1363_2X_CHANS(12); 454 454 455 455 enum { max1361, 456 456 max1362,
+590
drivers/staging/iio/adc/mxs-lradc.c
··· 1 + /* 2 + * Freescale i.MX28 LRADC driver 3 + * 4 + * Copyright (c) 2012 DENX Software Engineering, GmbH. 5 + * Marek Vasut <marex@denx.de> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/interrupt.h> 19 + #include <linux/device.h> 20 + #include <linux/kernel.h> 21 + #include <linux/slab.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 24 + #include <linux/sysfs.h> 25 + #include <linux/list.h> 26 + #include <linux/io.h> 27 + #include <linux/module.h> 28 + #include <linux/platform_device.h> 29 + #include <linux/spinlock.h> 30 + #include <linux/wait.h> 31 + #include <linux/sched.h> 32 + #include <linux/stmp_device.h> 33 + #include <linux/bitops.h> 34 + #include <linux/completion.h> 35 + 36 + #include <mach/mxs.h> 37 + #include <mach/common.h> 38 + 39 + #include <linux/iio/iio.h> 40 + #include <linux/iio/buffer.h> 41 + #include <linux/iio/trigger.h> 42 + #include <linux/iio/trigger_consumer.h> 43 + #include <linux/iio/triggered_buffer.h> 44 + 45 + #define DRIVER_NAME "mxs-lradc" 46 + 47 + #define LRADC_MAX_DELAY_CHANS 4 48 + #define LRADC_MAX_MAPPED_CHANS 8 49 + #define LRADC_MAX_TOTAL_CHANS 16 50 + 51 + #define LRADC_DELAY_TIMER_HZ 2000 52 + 53 + /* 54 + * Make this runtime configurable if necessary. Currently, if the buffered mode 55 + * is enabled, the LRADC takes LRADC_DELAY_TIMER_LOOP samples of data before 56 + * triggering IRQ. The sampling happens every (LRADC_DELAY_TIMER_PER / 2000) 57 + * seconds. The result is that the samples arrive every 500mS. 58 + */ 59 + #define LRADC_DELAY_TIMER_PER 200 60 + #define LRADC_DELAY_TIMER_LOOP 5 61 + 62 + static const char * const mxs_lradc_irq_name[] = { 63 + "mxs-lradc-touchscreen", 64 + "mxs-lradc-thresh0", 65 + "mxs-lradc-thresh1", 66 + "mxs-lradc-channel0", 67 + "mxs-lradc-channel1", 68 + "mxs-lradc-channel2", 69 + "mxs-lradc-channel3", 70 + "mxs-lradc-channel4", 71 + "mxs-lradc-channel5", 72 + "mxs-lradc-channel6", 73 + "mxs-lradc-channel7", 74 + "mxs-lradc-button0", 75 + "mxs-lradc-button1", 76 + }; 77 + 78 + struct mxs_lradc_chan { 79 + uint8_t slot; 80 + uint8_t flags; 81 + }; 82 + 83 + struct mxs_lradc { 84 + struct device *dev; 85 + void __iomem *base; 86 + int irq[13]; 87 + 88 + uint32_t *buffer; 89 + struct iio_trigger *trig; 90 + 91 + struct mutex lock; 92 + 93 + uint8_t enable; 94 + 95 + struct completion completion; 96 + }; 97 + 98 + #define LRADC_CTRL0 0x00 99 + #define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23) 100 + #define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22) 101 + 102 + #define LRADC_CTRL1 0x10 103 + #define LRADC_CTRL1_LRADC_IRQ(n) (1 << (n)) 104 + #define LRADC_CTRL1_LRADC_IRQ_MASK 0x1fff 105 + #define LRADC_CTRL1_LRADC_IRQ_EN(n) (1 << ((n) + 16)) 106 + #define LRADC_CTRL1_LRADC_IRQ_EN_MASK (0x1fff << 16) 107 + 108 + #define LRADC_CTRL2 0x20 109 + #define LRADC_CTRL2_TEMPSENSE_PWD (1 << 15) 110 + 111 + #define LRADC_CH(n) (0x50 + (0x10 * (n))) 112 + #define LRADC_CH_ACCUMULATE (1 << 29) 113 + #define LRADC_CH_NUM_SAMPLES_MASK (0x1f << 24) 114 + #define LRADC_CH_NUM_SAMPLES_OFFSET 24 115 + #define LRADC_CH_VALUE_MASK 0x3ffff 116 + #define LRADC_CH_VALUE_OFFSET 0 117 + 118 + #define LRADC_DELAY(n) (0xd0 + (0x10 * (n))) 119 + #define LRADC_DELAY_TRIGGER_LRADCS_MASK (0xff << 24) 120 + #define LRADC_DELAY_TRIGGER_LRADCS_OFFSET 24 121 + #define LRADC_DELAY_KICK (1 << 20) 122 + #define LRADC_DELAY_TRIGGER_DELAYS_MASK (0xf << 16) 123 + #define LRADC_DELAY_TRIGGER_DELAYS_OFFSET 16 124 + #define LRADC_DELAY_LOOP_COUNT_MASK (0x1f << 11) 125 + #define LRADC_DELAY_LOOP_COUNT_OFFSET 11 126 + #define LRADC_DELAY_DELAY_MASK 0x7ff 127 + #define LRADC_DELAY_DELAY_OFFSET 0 128 + 129 + #define LRADC_CTRL4 0x140 130 + #define LRADC_CTRL4_LRADCSELECT_MASK(n) (0xf << ((n) * 4)) 131 + #define LRADC_CTRL4_LRADCSELECT_OFFSET(n) ((n) * 4) 132 + 133 + /* 134 + * Raw I/O operations 135 + */ 136 + static int mxs_lradc_read_raw(struct iio_dev *iio_dev, 137 + const struct iio_chan_spec *chan, 138 + int *val, int *val2, long m) 139 + { 140 + struct mxs_lradc *lradc = iio_priv(iio_dev); 141 + int ret; 142 + 143 + if (m != IIO_CHAN_INFO_RAW) 144 + return -EINVAL; 145 + 146 + /* Check for invalid channel */ 147 + if (chan->channel > LRADC_MAX_TOTAL_CHANS) 148 + return -EINVAL; 149 + 150 + /* 151 + * See if there is no buffered operation in progess. If there is, simply 152 + * bail out. This can be improved to support both buffered and raw IO at 153 + * the same time, yet the code becomes horribly complicated. Therefore I 154 + * applied KISS principle here. 155 + */ 156 + ret = mutex_trylock(&lradc->lock); 157 + if (!ret) 158 + return -EBUSY; 159 + 160 + INIT_COMPLETION(lradc->completion); 161 + 162 + /* 163 + * No buffered operation in progress, map the channel and trigger it. 164 + * Virtual channel 0 is always used here as the others are always not 165 + * used if doing raw sampling. 166 + */ 167 + writel(LRADC_CTRL1_LRADC_IRQ_EN_MASK, 168 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 169 + writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 170 + 171 + writel(chan->channel, lradc->base + LRADC_CTRL4); 172 + writel(0, lradc->base + LRADC_CH(0)); 173 + 174 + /* Enable the IRQ and start sampling the channel. */ 175 + writel(LRADC_CTRL1_LRADC_IRQ_EN(0), 176 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); 177 + writel(1 << 0, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); 178 + 179 + /* Wait for completion on the channel, 1 second max. */ 180 + ret = wait_for_completion_killable_timeout(&lradc->completion, HZ); 181 + if (!ret) 182 + ret = -ETIMEDOUT; 183 + if (ret < 0) 184 + goto err; 185 + 186 + /* Read the data. */ 187 + *val = readl(lradc->base + LRADC_CH(0)) & LRADC_CH_VALUE_MASK; 188 + ret = IIO_VAL_INT; 189 + 190 + err: 191 + writel(LRADC_CTRL1_LRADC_IRQ_EN(0), 192 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 193 + 194 + mutex_unlock(&lradc->lock); 195 + 196 + return ret; 197 + } 198 + 199 + static const struct iio_info mxs_lradc_iio_info = { 200 + .driver_module = THIS_MODULE, 201 + .read_raw = mxs_lradc_read_raw, 202 + }; 203 + 204 + /* 205 + * IRQ Handling 206 + */ 207 + static irqreturn_t mxs_lradc_handle_irq(int irq, void *data) 208 + { 209 + struct iio_dev *iio = data; 210 + struct mxs_lradc *lradc = iio_priv(iio); 211 + unsigned long reg = readl(lradc->base + LRADC_CTRL1); 212 + 213 + if (!(reg & LRADC_CTRL1_LRADC_IRQ_MASK)) 214 + return IRQ_NONE; 215 + 216 + /* 217 + * Touchscreen IRQ handling code shall probably have priority 218 + * and therefore shall be placed here. 219 + */ 220 + 221 + if (iio_buffer_enabled(iio)) 222 + iio_trigger_poll(iio->trig, iio_get_time_ns()); 223 + else if (reg & LRADC_CTRL1_LRADC_IRQ(0)) 224 + complete(&lradc->completion); 225 + 226 + writel(reg & LRADC_CTRL1_LRADC_IRQ_MASK, 227 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 228 + 229 + return IRQ_HANDLED; 230 + } 231 + 232 + /* 233 + * Trigger handling 234 + */ 235 + static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p) 236 + { 237 + struct iio_poll_func *pf = p; 238 + struct iio_dev *iio = pf->indio_dev; 239 + struct mxs_lradc *lradc = iio_priv(iio); 240 + struct iio_buffer *buffer = iio->buffer; 241 + const uint32_t chan_value = LRADC_CH_ACCUMULATE | 242 + ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET); 243 + int i, j = 0; 244 + 245 + for_each_set_bit(i, iio->active_scan_mask, iio->masklength) { 246 + lradc->buffer[j] = readl(lradc->base + LRADC_CH(j)); 247 + writel(chan_value, lradc->base + LRADC_CH(j)); 248 + lradc->buffer[j] &= LRADC_CH_VALUE_MASK; 249 + lradc->buffer[j] /= LRADC_DELAY_TIMER_LOOP; 250 + j++; 251 + } 252 + 253 + if (iio->scan_timestamp) { 254 + s64 *timestamp = (s64 *)((u8 *)lradc->buffer + 255 + ALIGN(j, sizeof(s64))); 256 + *timestamp = pf->timestamp; 257 + } 258 + 259 + iio_push_to_buffer(buffer, (u8 *)lradc->buffer, pf->timestamp); 260 + 261 + iio_trigger_notify_done(iio->trig); 262 + 263 + return IRQ_HANDLED; 264 + } 265 + 266 + static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool state) 267 + { 268 + struct iio_dev *iio = trig->private_data; 269 + struct mxs_lradc *lradc = iio_priv(iio); 270 + const uint32_t st = state ? STMP_OFFSET_REG_SET : STMP_OFFSET_REG_CLR; 271 + 272 + writel(LRADC_DELAY_KICK, lradc->base + LRADC_DELAY(0) + st); 273 + 274 + return 0; 275 + } 276 + 277 + static const struct iio_trigger_ops mxs_lradc_trigger_ops = { 278 + .owner = THIS_MODULE, 279 + .set_trigger_state = &mxs_lradc_configure_trigger, 280 + }; 281 + 282 + static int mxs_lradc_trigger_init(struct iio_dev *iio) 283 + { 284 + int ret; 285 + struct iio_trigger *trig; 286 + 287 + trig = iio_trigger_alloc("%s-dev%i", iio->name, iio->id); 288 + if (trig == NULL) 289 + return -ENOMEM; 290 + 291 + trig->dev.parent = iio->dev.parent; 292 + trig->private_data = iio; 293 + trig->ops = &mxs_lradc_trigger_ops; 294 + 295 + ret = iio_trigger_register(trig); 296 + if (ret) { 297 + iio_trigger_free(trig); 298 + return ret; 299 + } 300 + 301 + iio->trig = trig; 302 + 303 + return 0; 304 + } 305 + 306 + static void mxs_lradc_trigger_remove(struct iio_dev *iio) 307 + { 308 + iio_trigger_unregister(iio->trig); 309 + iio_trigger_free(iio->trig); 310 + } 311 + 312 + static int mxs_lradc_buffer_preenable(struct iio_dev *iio) 313 + { 314 + struct mxs_lradc *lradc = iio_priv(iio); 315 + struct iio_buffer *buffer = iio->buffer; 316 + int ret = 0, chan, ofs = 0, enable = 0; 317 + uint32_t ctrl4 = 0; 318 + uint32_t ctrl1_irq = 0; 319 + const uint32_t chan_value = LRADC_CH_ACCUMULATE | 320 + ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET); 321 + const int len = bitmap_weight(buffer->scan_mask, LRADC_MAX_TOTAL_CHANS); 322 + 323 + if (!len) 324 + return -EINVAL; 325 + 326 + /* 327 + * Lock the driver so raw access can not be done during buffered 328 + * operation. This simplifies the code a lot. 329 + */ 330 + ret = mutex_trylock(&lradc->lock); 331 + if (!ret) 332 + return -EBUSY; 333 + 334 + lradc->buffer = kmalloc(len * sizeof(*lradc->buffer), GFP_KERNEL); 335 + if (!lradc->buffer) { 336 + ret = -ENOMEM; 337 + goto err_mem; 338 + } 339 + 340 + ret = iio_sw_buffer_preenable(iio); 341 + if (ret < 0) 342 + goto err_buf; 343 + 344 + writel(LRADC_CTRL1_LRADC_IRQ_EN_MASK, 345 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 346 + writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 347 + 348 + for_each_set_bit(chan, buffer->scan_mask, LRADC_MAX_TOTAL_CHANS) { 349 + ctrl4 |= chan << LRADC_CTRL4_LRADCSELECT_OFFSET(ofs); 350 + ctrl1_irq |= LRADC_CTRL1_LRADC_IRQ_EN(ofs); 351 + writel(chan_value, lradc->base + LRADC_CH(ofs)); 352 + enable |= 1 << ofs; 353 + ofs++; 354 + }; 355 + 356 + writel(LRADC_DELAY_TRIGGER_LRADCS_MASK | LRADC_DELAY_KICK, 357 + lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_CLR); 358 + 359 + writel(ctrl4, lradc->base + LRADC_CTRL4); 360 + writel(ctrl1_irq, lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); 361 + 362 + writel(enable << LRADC_DELAY_TRIGGER_LRADCS_OFFSET, 363 + lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_SET); 364 + 365 + return 0; 366 + 367 + err_buf: 368 + kfree(lradc->buffer); 369 + err_mem: 370 + mutex_unlock(&lradc->lock); 371 + return ret; 372 + } 373 + 374 + static int mxs_lradc_buffer_postdisable(struct iio_dev *iio) 375 + { 376 + struct mxs_lradc *lradc = iio_priv(iio); 377 + 378 + writel(LRADC_DELAY_TRIGGER_LRADCS_MASK | LRADC_DELAY_KICK, 379 + lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_CLR); 380 + 381 + writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 382 + writel(LRADC_CTRL1_LRADC_IRQ_EN_MASK, 383 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 384 + 385 + kfree(lradc->buffer); 386 + mutex_unlock(&lradc->lock); 387 + 388 + return 0; 389 + } 390 + 391 + static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio, 392 + const unsigned long *mask) 393 + { 394 + const int mw = bitmap_weight(mask, iio->masklength); 395 + 396 + return mw <= LRADC_MAX_MAPPED_CHANS; 397 + } 398 + 399 + static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = { 400 + .preenable = &mxs_lradc_buffer_preenable, 401 + .postenable = &iio_triggered_buffer_postenable, 402 + .predisable = &iio_triggered_buffer_predisable, 403 + .postdisable = &mxs_lradc_buffer_postdisable, 404 + .validate_scan_mask = &mxs_lradc_validate_scan_mask, 405 + }; 406 + 407 + /* 408 + * Driver initialization 409 + */ 410 + 411 + #define MXS_ADC_CHAN(idx, chan_type) { \ 412 + .type = (chan_type), \ 413 + .indexed = 1, \ 414 + .scan_index = (idx), \ 415 + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \ 416 + .channel = (idx), \ 417 + .scan_type = { \ 418 + .sign = 'u', \ 419 + .realbits = 18, \ 420 + .storagebits = 32, \ 421 + }, \ 422 + } 423 + 424 + static const struct iio_chan_spec mxs_lradc_chan_spec[] = { 425 + MXS_ADC_CHAN(0, IIO_VOLTAGE), 426 + MXS_ADC_CHAN(1, IIO_VOLTAGE), 427 + MXS_ADC_CHAN(2, IIO_VOLTAGE), 428 + MXS_ADC_CHAN(3, IIO_VOLTAGE), 429 + MXS_ADC_CHAN(4, IIO_VOLTAGE), 430 + MXS_ADC_CHAN(5, IIO_VOLTAGE), 431 + MXS_ADC_CHAN(6, IIO_VOLTAGE), 432 + MXS_ADC_CHAN(7, IIO_VOLTAGE), /* VBATT */ 433 + MXS_ADC_CHAN(8, IIO_TEMP), /* Temp sense 0 */ 434 + MXS_ADC_CHAN(9, IIO_TEMP), /* Temp sense 1 */ 435 + MXS_ADC_CHAN(10, IIO_VOLTAGE), /* VDDIO */ 436 + MXS_ADC_CHAN(11, IIO_VOLTAGE), /* VTH */ 437 + MXS_ADC_CHAN(12, IIO_VOLTAGE), /* VDDA */ 438 + MXS_ADC_CHAN(13, IIO_VOLTAGE), /* VDDD */ 439 + MXS_ADC_CHAN(14, IIO_VOLTAGE), /* VBG */ 440 + MXS_ADC_CHAN(15, IIO_VOLTAGE), /* VDD5V */ 441 + }; 442 + 443 + static void mxs_lradc_hw_init(struct mxs_lradc *lradc) 444 + { 445 + int i; 446 + const uint32_t cfg = 447 + (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET); 448 + 449 + stmp_reset_block(lradc->base); 450 + 451 + for (i = 0; i < LRADC_MAX_DELAY_CHANS; i++) 452 + writel(cfg | (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + i)), 453 + lradc->base + LRADC_DELAY(i)); 454 + 455 + /* Start internal temperature sensing. */ 456 + writel(0, lradc->base + LRADC_CTRL2); 457 + } 458 + 459 + static void mxs_lradc_hw_stop(struct mxs_lradc *lradc) 460 + { 461 + int i; 462 + 463 + writel(LRADC_CTRL1_LRADC_IRQ_EN_MASK, 464 + lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 465 + 466 + for (i = 0; i < LRADC_MAX_DELAY_CHANS; i++) 467 + writel(0, lradc->base + LRADC_DELAY(i)); 468 + } 469 + 470 + static int __devinit mxs_lradc_probe(struct platform_device *pdev) 471 + { 472 + struct device *dev = &pdev->dev; 473 + struct mxs_lradc *lradc; 474 + struct iio_dev *iio; 475 + struct resource *iores; 476 + int ret = 0; 477 + int i; 478 + 479 + /* Allocate the IIO device. */ 480 + iio = iio_device_alloc(sizeof(*lradc)); 481 + if (!iio) { 482 + dev_err(dev, "Failed to allocate IIO device\n"); 483 + return -ENOMEM; 484 + } 485 + 486 + lradc = iio_priv(iio); 487 + 488 + /* Grab the memory area */ 489 + iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 490 + lradc->dev = &pdev->dev; 491 + lradc->base = devm_request_and_ioremap(dev, iores); 492 + if (!lradc->base) { 493 + ret = -EADDRNOTAVAIL; 494 + goto err_addr; 495 + } 496 + 497 + /* Grab all IRQ sources */ 498 + for (i = 0; i < 13; i++) { 499 + lradc->irq[i] = platform_get_irq(pdev, i); 500 + if (lradc->irq[i] < 0) { 501 + ret = -EINVAL; 502 + goto err_addr; 503 + } 504 + 505 + ret = devm_request_irq(dev, lradc->irq[i], 506 + mxs_lradc_handle_irq, 0, 507 + mxs_lradc_irq_name[i], iio); 508 + if (ret) 509 + goto err_addr; 510 + } 511 + 512 + platform_set_drvdata(pdev, iio); 513 + 514 + init_completion(&lradc->completion); 515 + mutex_init(&lradc->lock); 516 + 517 + iio->name = pdev->name; 518 + iio->dev.parent = &pdev->dev; 519 + iio->info = &mxs_lradc_iio_info; 520 + iio->modes = INDIO_DIRECT_MODE; 521 + iio->channels = mxs_lradc_chan_spec; 522 + iio->num_channels = ARRAY_SIZE(mxs_lradc_chan_spec); 523 + 524 + ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, 525 + &mxs_lradc_trigger_handler, 526 + &mxs_lradc_buffer_ops); 527 + if (ret) 528 + goto err_addr; 529 + 530 + ret = mxs_lradc_trigger_init(iio); 531 + if (ret) 532 + goto err_trig; 533 + 534 + /* Register IIO device. */ 535 + ret = iio_device_register(iio); 536 + if (ret) { 537 + dev_err(dev, "Failed to register IIO device\n"); 538 + goto err_dev; 539 + } 540 + 541 + /* Configure the hardware. */ 542 + mxs_lradc_hw_init(lradc); 543 + 544 + return 0; 545 + 546 + err_dev: 547 + mxs_lradc_trigger_remove(iio); 548 + err_trig: 549 + iio_triggered_buffer_cleanup(iio); 550 + err_addr: 551 + iio_device_free(iio); 552 + return ret; 553 + } 554 + 555 + static int __devexit mxs_lradc_remove(struct platform_device *pdev) 556 + { 557 + struct iio_dev *iio = platform_get_drvdata(pdev); 558 + struct mxs_lradc *lradc = iio_priv(iio); 559 + 560 + mxs_lradc_hw_stop(lradc); 561 + 562 + iio_device_unregister(iio); 563 + iio_triggered_buffer_cleanup(iio); 564 + mxs_lradc_trigger_remove(iio); 565 + iio_device_free(iio); 566 + 567 + return 0; 568 + } 569 + 570 + static const struct of_device_id mxs_lradc_dt_ids[] = { 571 + { .compatible = "fsl,imx28-lradc", }, 572 + { /* sentinel */ } 573 + }; 574 + MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids); 575 + 576 + static struct platform_driver mxs_lradc_driver = { 577 + .driver = { 578 + .name = DRIVER_NAME, 579 + .owner = THIS_MODULE, 580 + .of_match_table = mxs_lradc_dt_ids, 581 + }, 582 + .probe = mxs_lradc_probe, 583 + .remove = __devexit_p(mxs_lradc_remove), 584 + }; 585 + 586 + module_platform_driver(mxs_lradc_driver); 587 + 588 + MODULE_AUTHOR("Marek Vasut <marex@denx.de>"); 589 + MODULE_DESCRIPTION("Freescale i.MX28 LRADC driver"); 590 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/staging/iio/adc/spear_adc.c
··· 189 189 }, \ 190 190 } 191 191 192 - static struct iio_chan_spec spear_adc_iio_channels[] = { 192 + static const struct iio_chan_spec spear_adc_iio_channels[] = { 193 193 SPEAR_ADC_CHAN(0), 194 194 SPEAR_ADC_CHAN(1), 195 195 SPEAR_ADC_CHAN(2),
+1 -11
drivers/staging/iio/iio_hwmon.c
··· 215 215 .remove = __devexit_p(iio_hwmon_remove), 216 216 }; 217 217 218 - static int iio_inkern_init(void) 219 - { 220 - return platform_driver_register(&iio_hwmon_driver); 221 - } 222 - module_init(iio_inkern_init); 223 - 224 - static void iio_inkern_exit(void) 225 - { 226 - platform_driver_unregister(&iio_hwmon_driver); 227 - } 228 - module_exit(iio_inkern_exit); 218 + module_platform_driver(iio_hwmon_driver); 229 219 230 220 MODULE_AUTHOR("Jonathan Cameron <jic23@cam.ac.uk>"); 231 221 MODULE_DESCRIPTION("IIO to hwmon driver");
+1 -1
drivers/staging/iio/iio_simple_dummy.c
··· 63 63 * This array of structures tells the IIO core about what the device 64 64 * actually provides for a given channel. 65 65 */ 66 - static struct iio_chan_spec iio_dummy_channels[] = { 66 + static const struct iio_chan_spec iio_dummy_channels[] = { 67 67 /* indexed ADC channel in_voltage0_raw etc */ 68 68 { 69 69 .type = IIO_VOLTAGE,
+1 -1
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 108 108 .vref_mv = 3300, 109 109 }; 110 110 111 - static struct iio_chan_spec ad5933_channels[] = { 111 + static const struct iio_chan_spec ad5933_channels[] = { 112 112 { 113 113 .type = IIO_TEMP, 114 114 .indexed = 1,
+3 -3
drivers/staging/iio/imu/adis16400_core.c
··· 610 610 } 611 611 } 612 612 613 - static struct iio_chan_spec adis16400_channels[] = { 613 + static const struct iio_chan_spec adis16400_channels[] = { 614 614 { 615 615 .type = IIO_VOLTAGE, 616 616 .indexed = 1, ··· 740 740 IIO_CHAN_SOFT_TIMESTAMP(12) 741 741 }; 742 742 743 - static struct iio_chan_spec adis16350_channels[] = { 743 + static const struct iio_chan_spec adis16350_channels[] = { 744 744 { 745 745 .type = IIO_VOLTAGE, 746 746 .indexed = 1, ··· 865 865 IIO_CHAN_SOFT_TIMESTAMP(11) 866 866 }; 867 867 868 - static struct iio_chan_spec adis16300_channels[] = { 868 + static const struct iio_chan_spec adis16300_channels[] = { 869 869 { 870 870 .type = IIO_VOLTAGE, 871 871 .indexed = 1,
+1 -1
drivers/staging/iio/meter/ade7758.h
··· 122 122 u8 *tx; 123 123 u8 *rx; 124 124 struct mutex buf_lock; 125 - struct iio_chan_spec *ade7758_ring_channels; 125 + const struct iio_chan_spec *ade7758_ring_channels; 126 126 struct spi_transfer ring_xfer[4]; 127 127 struct spi_message ring_msg; 128 128 /*
+1 -1
drivers/staging/iio/meter/ade7758_core.c
··· 661 661 .attrs = ade7758_attributes, 662 662 }; 663 663 664 - static struct iio_chan_spec ade7758_channels[] = { 664 + static const struct iio_chan_spec ade7758_channels[] = { 665 665 { 666 666 .type = IIO_VOLTAGE, 667 667 .indexed = 1,
+1 -1
drivers/staging/iio/resolver/ad2s1210.c
··· 575 575 AD2S1210_REG_LOT_LOW_THRD); 576 576 577 577 578 - static struct iio_chan_spec ad2s1210_channels[] = { 578 + static const struct iio_chan_spec ad2s1210_channels[] = { 579 579 { 580 580 .type = IIO_ANGL, 581 581 .indexed = 1,