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

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

Jonathan writes:

Third set of IIO new device support, features and cleanups for the 4.6 cycle.

Good to see several new contributors in this set - and more generally a
number of new 'faces' over this whole cycle.

Staging movements
* hmc5843
- out of staging.
* periodic RTC trigger
- driver dropped. This is an ancient driver (brings back some memories ;)
that was always somewhat of a bodge. Originally there was a driver that
never went into mainline that supported large numbers of periodict timers
on the PXA270 via this route. Discussions to have a generic periodic
timer subsystem never went anywhere. At the time RTC periodic
interrupts were real - now they are emulated using high resolution
timers so with the HRT driver this has become pointless.

New device support
* mpu6050 driver
- Add support for the mpu6500.
* TI tpl0102 potentiometer
- new driver.
* Vybrid SoC DAC
- new driver. The ADC on this SoC has been supported for a while, this
adds a separate driver for the DAC.

New Features
* hmc5844
- Attributes to configure the bias current (typically part of a self test)
This could be done before via a somewhat obscure custom interface.
This at least makes it easy to tell what is going on.
- Document all custom attributes.
* mpu6050
- Add support for calibration offset control and readback.
* ms5611
- power regulator support. This is always one that gets added the
first time someone has a board that needs it. Here it was needed,
hence it was added.

Cleanups / minor fixes
* tree wide
- clean up all the myriad different return values in response to a
failure of i2c_check_functionality. After discussions everyone seemed
happy wiht -EOPNOTSUPP which seems to describe the situation well.
I encouraged a tree wide cleanup to set a good example in future for
this.
* core
- Typos in the iio_event_spec documentation in iio.h
* afe4403
- select REGMAP_SPI to avoid dependency issues
- mark suspend/resume as __maybe_unused to avoid warnings
* afe4404
- mark suspend/resume as __maybe_unused to avoid warnings
* atlas-ph-sensor
- switch the regmap cache type from linear to rbtree to gain reading of
registers on initial startup. It's not immediately obvious, but
regmap flat is meant for high performances cases so doesn't read these
registers.
- use regmap_bulk_read in one case where it was using
i2c_smbus_read_i2c_block_data directly (unlike everything else that was
through regmap).
* ina2xx
- stype cleanups (lots of them!)
* isl29018
- Get the struct device back from regmap rather than storing another
copy of it in the private data. This cleanup makes sense in a number
of other drivers so patches may well follow.
* mpu6050
- style cleanups (lots of them!)
- improved return value handling
- use usleep_range to avoid the usual issues with very short msleeps.
- add some missing documentation.
* ms5611
- use the probed device name for the device rather than the driver name.
- select IIO_BUFFER to avoid dependency issues
* palmas
- drop IRQF_EARLY_RESUME as no longer needed after genirq changes.

+1001 -567
+15
Documentation/ABI/testing/sysfs-bus-iio-magnetometer-hmc5843
··· 1 + What: /sys/bus/iio/devices/iio:deviceX/meas_conf 2 + What: /sys/bus/iio/devices/iio:deviceX/meas_conf_available 3 + KernelVersion: 4.5 4 + Contact: linux-iio@vger.kernel.org 5 + Description: 6 + Current configuration and available configurations 7 + for the bias current. 8 + normal - Normal measurement configurations (default) 9 + positivebias - Positive bias configuration 10 + negativebias - Negative bias configuration 11 + disabled - Only available on HMC5983. Disables magnetic 12 + sensor and enables temperature sensor. 13 + Note: The effect of this configuration may vary 14 + according to the device. For exact documentation 15 + check the device's datasheet.
+9
Documentation/ABI/testing/sysfs-bus-iio-vf610
··· 5 5 Specifies the hardware conversion mode used. The three 6 6 available modes are "normal", "high-speed" and "low-power", 7 7 where the last is the default mode. 8 + 9 + 10 + What: /sys/bus/iio/devices/iio:deviceX/out_conversion_mode 11 + KernelVersion: 4.6 12 + Contact: linux-iio@vger.kernel.org 13 + Description: 14 + Specifies the hardware conversion mode used within DAC. 15 + The two available modes are "high-power" and "low-power", 16 + where "low-power" mode is the default mode.
+20
Documentation/devicetree/bindings/iio/dac/vf610-dac.txt
··· 1 + Freescale vf610 Digital to Analog Converter bindings 2 + 3 + The devicetree bindings are for the new DAC driver written for 4 + vf610 SoCs from Freescale. 5 + 6 + Required properties: 7 + - compatible: Should contain "fsl,vf610-dac" 8 + - reg: Offset and length of the register set for the device 9 + - interrupts: Should contain the interrupt for the device 10 + - clocks: The clock is needed by the DAC controller 11 + - clock-names: Must contain "dac" matching entry in the clocks property. 12 + 13 + Example: 14 + dac0: dac@400cc000 { 15 + compatible = "fsl,vf610-dac"; 16 + reg = <0x400cc000 0x1000>; 17 + interrupts = <55 IRQ_TYPE_LEVEL_HIGH>; 18 + clock-names = "dac"; 19 + clocks = <&clks VF610_CLK_DAC0>; 20 + };
+72 -83
drivers/iio/adc/ina2xx-adc.c
··· 19 19 * 20 20 * Configurable 7-bit I2C slave address from 0x40 to 0x4F 21 21 */ 22 - #include <linux/module.h> 23 - #include <linux/kthread.h> 22 + 24 23 #include <linux/delay.h> 24 + #include <linux/i2c.h> 25 25 #include <linux/iio/kfifo_buf.h> 26 26 #include <linux/iio/sysfs.h> 27 - #include <linux/i2c.h> 27 + #include <linux/kthread.h> 28 + #include <linux/module.h> 28 29 #include <linux/regmap.h> 29 - #include <linux/platform_data/ina2xx.h> 30 - 31 30 #include <linux/util_macros.h> 31 + 32 + #include <linux/platform_data/ina2xx.h> 32 33 33 34 /* INA2XX registers definition */ 34 35 #define INA2XX_CONFIG 0x00 ··· 39 38 #define INA2XX_CURRENT 0x04 /* readonly */ 40 39 #define INA2XX_CALIBRATION 0x05 41 40 42 - #define INA226_ALERT_MASK 0x06 41 + #define INA226_ALERT_MASK GENMASK(2, 1) 43 42 #define INA266_CVRF BIT(3) 44 43 45 44 #define INA2XX_MAX_REGISTERS 8 ··· 114 113 struct mutex state_lock; 115 114 unsigned int shunt_resistor; 116 115 int avg; 117 - s64 prev_ns; /* track buffer capture time, check for underruns*/ 116 + s64 prev_ns; /* track buffer capture time, check for underruns */ 118 117 int int_time_vbus; /* Bus voltage integration time uS */ 119 118 int int_time_vshunt; /* Shunt voltage integration time uS */ 120 119 bool allow_async_readout; ··· 122 121 123 122 static const struct ina2xx_config ina2xx_config[] = { 124 123 [ina219] = { 125 - .config_default = INA219_CONFIG_DEFAULT, 126 - .calibration_factor = 40960000, 127 - .shunt_div = 100, 128 - .bus_voltage_shift = 3, 129 - .bus_voltage_lsb = 4000, 130 - .power_lsb = 20000, 131 - }, 124 + .config_default = INA219_CONFIG_DEFAULT, 125 + .calibration_factor = 40960000, 126 + .shunt_div = 100, 127 + .bus_voltage_shift = 3, 128 + .bus_voltage_lsb = 4000, 129 + .power_lsb = 20000, 130 + }, 132 131 [ina226] = { 133 - .config_default = INA226_CONFIG_DEFAULT, 134 - .calibration_factor = 5120000, 135 - .shunt_div = 400, 136 - .bus_voltage_shift = 0, 137 - .bus_voltage_lsb = 1250, 138 - .power_lsb = 25000, 139 - }, 132 + .config_default = INA226_CONFIG_DEFAULT, 133 + .calibration_factor = 5120000, 134 + .shunt_div = 400, 135 + .bus_voltage_shift = 0, 136 + .bus_voltage_lsb = 1250, 137 + .power_lsb = 25000, 138 + }, 140 139 }; 141 140 142 141 static int ina2xx_read_raw(struct iio_dev *indio_dev, ··· 150 149 switch (mask) { 151 150 case IIO_CHAN_INFO_RAW: 152 151 ret = regmap_read(chip->regmap, chan->address, &regval); 153 - if (ret < 0) 152 + if (ret) 154 153 return ret; 155 154 156 155 if (is_signed_reg(chan->address)) ··· 252 251 return -EINVAL; 253 252 254 253 bits = find_closest(val_us, ina226_conv_time_tab, 255 - ARRAY_SIZE(ina226_conv_time_tab)); 254 + ARRAY_SIZE(ina226_conv_time_tab)); 256 255 257 256 chip->int_time_vbus = ina226_conv_time_tab[bits]; 258 257 ··· 271 270 return -EINVAL; 272 271 273 272 bits = find_closest(val_us, ina226_conv_time_tab, 274 - ARRAY_SIZE(ina226_conv_time_tab)); 273 + ARRAY_SIZE(ina226_conv_time_tab)); 275 274 276 275 chip->int_time_vshunt = ina226_conv_time_tab[bits]; 277 276 ··· 286 285 int val, int val2, long mask) 287 286 { 288 287 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 289 - int ret; 290 288 unsigned int config, tmp; 289 + int ret; 291 290 292 291 if (iio_buffer_enabled(indio_dev)) 293 292 return -EBUSY; ··· 295 294 mutex_lock(&chip->state_lock); 296 295 297 296 ret = regmap_read(chip->regmap, INA2XX_CONFIG, &config); 298 - if (ret < 0) 299 - goto _err; 297 + if (ret) 298 + goto err; 300 299 301 300 tmp = config; 302 301 ··· 311 310 else 312 311 ret = ina226_set_int_time_vbus(chip, val2, &tmp); 313 312 break; 313 + 314 314 default: 315 315 ret = -EINVAL; 316 316 } 317 317 318 318 if (!ret && (tmp != config)) 319 319 ret = regmap_write(chip->regmap, INA2XX_CONFIG, tmp); 320 - _err: 320 + err: 321 321 mutex_unlock(&chip->state_lock); 322 322 323 323 return ret; 324 324 } 325 - 326 325 327 326 static ssize_t ina2xx_allow_async_readout_show(struct device *dev, 328 327 struct device_attribute *attr, ··· 356 355 return -EINVAL; 357 356 358 357 chip->shunt_resistor = val; 358 + 359 359 return 0; 360 360 } 361 361 ··· 440 438 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 441 439 unsigned short data[8]; 442 440 int bit, ret, i = 0; 443 - unsigned long buffer_us, elapsed_us; 444 441 s64 time_a, time_b; 445 442 unsigned int alert; 446 443 ··· 463 462 return ret; 464 463 465 464 alert &= INA266_CVRF; 466 - trace_printk("Conversion ready: %d\n", !!alert); 467 - 468 465 } while (!alert); 469 466 470 467 /* ··· 487 488 iio_push_to_buffers_with_timestamp(indio_dev, 488 489 (unsigned int *)data, time_a); 489 490 490 - buffer_us = (unsigned long)(time_b - time_a) / 1000; 491 - elapsed_us = (unsigned long)(time_a - chip->prev_ns) / 1000; 492 - 493 - trace_printk("uS: elapsed: %lu, buf: %lu\n", elapsed_us, buffer_us); 494 - 495 491 chip->prev_ns = time_a; 496 492 497 - return buffer_us; 493 + return (unsigned long)(time_b - time_a) / 1000; 498 494 }; 499 495 500 496 static int ina2xx_capture_thread(void *data) 501 497 { 502 - struct iio_dev *indio_dev = (struct iio_dev *)data; 498 + struct iio_dev *indio_dev = data; 503 499 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 504 500 unsigned int sampling_us = SAMPLING_PERIOD(chip); 505 501 int buffer_us; ··· 524 530 struct ina2xx_chip_info *chip = iio_priv(indio_dev); 525 531 unsigned int sampling_us = SAMPLING_PERIOD(chip); 526 532 527 - trace_printk("Enabling buffer w/ scan_mask %02x, freq = %d, avg =%u\n", 528 - (unsigned int)(*indio_dev->active_scan_mask), 529 - 1000000/sampling_us, chip->avg); 533 + dev_dbg(&indio_dev->dev, "Enabling buffer w/ scan_mask %02x, freq = %d, avg =%u\n", 534 + (unsigned int)(*indio_dev->active_scan_mask), 535 + 1000000 / sampling_us, chip->avg); 530 536 531 - trace_printk("Expected work period: %u us\n", sampling_us); 532 - trace_printk("Async readout mode: %d\n", chip->allow_async_readout); 537 + dev_dbg(&indio_dev->dev, "Expected work period: %u us\n", sampling_us); 538 + dev_dbg(&indio_dev->dev, "Async readout mode: %d\n", 539 + chip->allow_async_readout); 533 540 534 541 chip->prev_ns = iio_get_time_ns(); 535 542 ··· 570 575 } 571 576 572 577 /* Possible integration times for vshunt and vbus */ 573 - static IIO_CONST_ATTR_INT_TIME_AVAIL \ 574 - ("0.000140 0.000204 0.000332 0.000588 0.001100 0.002116 0.004156 0.008244"); 578 + static IIO_CONST_ATTR_INT_TIME_AVAIL("0.000140 0.000204 0.000332 0.000588 0.001100 0.002116 0.004156 0.008244"); 575 579 576 580 static IIO_DEVICE_ATTR(in_allow_async_readout, S_IRUGO | S_IWUSR, 577 581 ina2xx_allow_async_readout_show, ··· 592 598 }; 593 599 594 600 static const struct iio_info ina2xx_info = { 595 - .debugfs_reg_access = &ina2xx_debug_reg, 596 - .read_raw = &ina2xx_read_raw, 597 - .write_raw = &ina2xx_write_raw, 598 - .attrs = &ina2xx_attribute_group, 599 601 .driver_module = THIS_MODULE, 602 + .attrs = &ina2xx_attribute_group, 603 + .read_raw = ina2xx_read_raw, 604 + .write_raw = ina2xx_write_raw, 605 + .debugfs_reg_access = ina2xx_debug_reg, 600 606 }; 601 607 602 608 /* Initialize the configuration and calibration registers. */ 603 609 static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) 604 610 { 605 611 u16 regval; 606 - int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); 612 + int ret; 607 613 608 - if (ret < 0) 614 + ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); 615 + if (ret) 609 616 return ret; 617 + 610 618 /* 611 619 * Set current LSB to 1mA, shunt is in uOhms 612 620 * (equation 13 in datasheet). We hardcode a Current_LSB ··· 617 621 * to the user for now. 618 622 */ 619 623 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, 620 - chip->shunt_resistor); 624 + chip->shunt_resistor); 621 625 622 626 return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); 623 627 } ··· 628 632 struct ina2xx_chip_info *chip; 629 633 struct iio_dev *indio_dev; 630 634 struct iio_buffer *buffer; 631 - int ret; 632 635 unsigned int val; 636 + int ret; 633 637 634 638 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 635 639 if (!indio_dev) ··· 637 641 638 642 chip = iio_priv(indio_dev); 639 643 644 + /* This is only used for device removal purposes. */ 645 + i2c_set_clientdata(client, indio_dev); 646 + 647 + chip->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config); 648 + if (IS_ERR(chip->regmap)) { 649 + dev_err(&client->dev, "failed to allocate register map\n"); 650 + return PTR_ERR(chip->regmap); 651 + } 652 + 640 653 chip->config = &ina2xx_config[id->driver_data]; 654 + 655 + mutex_init(&chip->state_lock); 641 656 642 657 if (of_property_read_u32(client->dev.of_node, 643 658 "shunt-resistor", &val) < 0) { ··· 665 658 if (ret) 666 659 return ret; 667 660 668 - mutex_init(&chip->state_lock); 669 - 670 - /* This is only used for device removal purposes. */ 671 - i2c_set_clientdata(client, indio_dev); 672 - 673 - indio_dev->name = id->name; 674 - indio_dev->channels = ina2xx_channels; 675 - indio_dev->num_channels = ARRAY_SIZE(ina2xx_channels); 676 - 677 - indio_dev->dev.parent = &client->dev; 678 - indio_dev->info = &ina2xx_info; 679 - indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 680 - 681 - chip->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config); 682 - if (IS_ERR(chip->regmap)) { 683 - dev_err(&client->dev, "failed to allocate register map\n"); 684 - return PTR_ERR(chip->regmap); 685 - } 686 - 687 661 /* Patch the current config register with default. */ 688 662 val = chip->config->config_default; 689 663 ··· 675 687 } 676 688 677 689 ret = ina2xx_init(chip, val); 678 - if (ret < 0) { 679 - dev_err(&client->dev, "error configuring the device: %d\n", 680 - ret); 681 - return -ENODEV; 690 + if (ret) { 691 + dev_err(&client->dev, "error configuring the device\n"); 692 + return ret; 682 693 } 694 + 695 + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 696 + indio_dev->dev.parent = &client->dev; 697 + indio_dev->channels = ina2xx_channels; 698 + indio_dev->num_channels = ARRAY_SIZE(ina2xx_channels); 699 + indio_dev->name = id->name; 700 + indio_dev->info = &ina2xx_info; 701 + indio_dev->setup_ops = &ina2xx_setup_ops; 683 702 684 703 buffer = devm_iio_kfifo_allocate(&indio_dev->dev); 685 704 if (!buffer) 686 705 return -ENOMEM; 687 706 688 - indio_dev->setup_ops = &ina2xx_setup_ops; 689 - 690 707 iio_device_attach_buffer(indio_dev, buffer); 691 708 692 709 return iio_device_register(indio_dev); 693 710 } 694 - 695 711 696 712 static int ina2xx_remove(struct i2c_client *client) 697 713 { ··· 709 717 INA2XX_MODE_MASK, 0); 710 718 } 711 719 712 - 713 720 static const struct i2c_device_id ina2xx_id[] = { 714 721 {"ina219", ina219}, 715 722 {"ina220", ina219}, ··· 717 726 {"ina231", ina226}, 718 727 {} 719 728 }; 720 - 721 729 MODULE_DEVICE_TABLE(i2c, ina2xx_id); 722 730 723 731 static struct i2c_driver ina2xx_driver = { ··· 727 737 .remove = ina2xx_remove, 728 738 .id_table = ina2xx_id, 729 739 }; 730 - 731 740 module_i2c_driver(ina2xx_driver); 732 741 733 742 MODULE_AUTHOR("Marc Titinger <marc.titinger@baylibre.com>");
+1 -1
drivers/iio/adc/mcp3422.c
··· 339 339 u8 config; 340 340 341 341 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 342 - return -ENODEV; 342 + return -EOPNOTSUPP; 343 343 344 344 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adc)); 345 345 if (!indio_dev)
+3 -3
drivers/iio/adc/palmas_gpadc.c
··· 534 534 } 535 535 ret = request_threaded_irq(adc->irq, NULL, 536 536 palmas_gpadc_irq, 537 - IRQF_ONESHOT | IRQF_EARLY_RESUME, dev_name(adc->dev), 537 + IRQF_ONESHOT, dev_name(adc->dev), 538 538 adc); 539 539 if (ret < 0) { 540 540 dev_err(adc->dev, ··· 549 549 adc->irq_auto_0 = platform_get_irq(pdev, 1); 550 550 ret = request_threaded_irq(adc->irq_auto_0, NULL, 551 551 palmas_gpadc_irq_auto, 552 - IRQF_ONESHOT | IRQF_EARLY_RESUME, 552 + IRQF_ONESHOT, 553 553 "palmas-adc-auto-0", adc); 554 554 if (ret < 0) { 555 555 dev_err(adc->dev, "request auto0 irq %d failed: %d\n", ··· 565 565 adc->irq_auto_1 = platform_get_irq(pdev, 2); 566 566 ret = request_threaded_irq(adc->irq_auto_1, NULL, 567 567 palmas_gpadc_irq_auto, 568 - IRQF_ONESHOT | IRQF_EARLY_RESUME, 568 + IRQF_ONESHOT, 569 569 "palmas-adc-auto-1", adc); 570 570 if (ret < 0) { 571 571 dev_err(adc->dev, "request auto1 irq %d failed: %d\n",
+1 -1
drivers/iio/adc/ti-adc081c.c
··· 73 73 int err; 74 74 75 75 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 76 - return -ENODEV; 76 + return -EOPNOTSUPP; 77 77 78 78 iio = devm_iio_device_alloc(&client->dev, sizeof(*adc)); 79 79 if (!iio)
+4 -6
drivers/iio/chemical/atlas-ph-sensor.c
··· 65 65 66 66 static const struct regmap_range atlas_volatile_ranges[] = { 67 67 regmap_reg_range(ATLAS_REG_INT_CONTROL, ATLAS_REG_INT_CONTROL), 68 - regmap_reg_range(ATLAS_REG_CALIB_STATUS, ATLAS_REG_CALIB_STATUS), 69 - regmap_reg_range(ATLAS_REG_TEMP_DATA, ATLAS_REG_TEMP_DATA + 4), 70 68 regmap_reg_range(ATLAS_REG_PH_DATA, ATLAS_REG_PH_DATA + 4), 71 69 }; 72 70 ··· 81 83 82 84 .volatile_table = &atlas_volatile_table, 83 85 .max_register = ATLAS_REG_PH_DATA + 4, 84 - .cache_type = REGCACHE_FLAT, 86 + .cache_type = REGCACHE_RBTREE, 85 87 }; 86 88 87 89 static const struct iio_chan_spec atlas_channels[] = { ··· 178 180 struct atlas_data *data = iio_priv(indio_dev); 179 181 int ret; 180 182 181 - ret = i2c_smbus_read_i2c_block_data(data->client, ATLAS_REG_PH_DATA, 182 - sizeof(data->buffer[0]), (u8 *) &data->buffer); 183 + ret = regmap_bulk_read(data->regmap, ATLAS_REG_PH_DATA, 184 + (u8 *) &data->buffer, sizeof(data->buffer[0])); 183 185 184 - if (ret > 0) 186 + if (!ret) 185 187 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 186 188 iio_get_time_ns()); 187 189
+1 -1
drivers/iio/chemical/vz89x.c
··· 249 249 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) 250 250 data->xfer = vz89x_smbus_xfer; 251 251 else 252 - return -ENOTSUPP; 252 + return -EOPNOTSUPP; 253 253 254 254 i2c_set_clientdata(client, indio_dev); 255 255 data->client = client;
+10
drivers/iio/dac/Kconfig
··· 217 217 addresses for the devices may be configured via the "base" module 218 218 parameter array. 219 219 220 + config VF610_DAC 221 + tristate "Vybrid vf610 DAC driver" 222 + depends on OF 223 + depends on HAS_IOMEM 224 + help 225 + Say yes here to support Vybrid board digital-to-analog converter. 226 + 227 + This driver can also be built as a module. If so, the module will 228 + be called vf610_dac. 229 + 220 230 endmenu
+1
drivers/iio/dac/Makefile
··· 23 23 obj-$(CONFIG_MCP4725) += mcp4725.o 24 24 obj-$(CONFIG_MCP4922) += mcp4922.o 25 25 obj-$(CONFIG_STX104) += stx104.o 26 + obj-$(CONFIG_VF610_DAC) += vf610_dac.o
+298
drivers/iio/dac/vf610_dac.c
··· 1 + /* 2 + * Freescale Vybrid vf610 DAC driver 3 + * 4 + * Copyright 2016 Toradex AG 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/err.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/io.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/regulator/consumer.h> 25 + #include <linux/slab.h> 26 + 27 + #include <linux/iio/iio.h> 28 + #include <linux/iio/sysfs.h> 29 + 30 + #define VF610_DACx_STATCTRL 0x20 31 + 32 + #define VF610_DAC_DACEN BIT(15) 33 + #define VF610_DAC_DACRFS BIT(14) 34 + #define VF610_DAC_LPEN BIT(11) 35 + 36 + #define VF610_DAC_DAT0(x) ((x) & 0xFFF) 37 + 38 + enum vf610_conversion_mode_sel { 39 + VF610_DAC_CONV_HIGH_POWER, 40 + VF610_DAC_CONV_LOW_POWER, 41 + }; 42 + 43 + struct vf610_dac { 44 + struct clk *clk; 45 + struct device *dev; 46 + enum vf610_conversion_mode_sel conv_mode; 47 + void __iomem *regs; 48 + }; 49 + 50 + static void vf610_dac_init(struct vf610_dac *info) 51 + { 52 + int val; 53 + 54 + info->conv_mode = VF610_DAC_CONV_LOW_POWER; 55 + val = VF610_DAC_DACEN | VF610_DAC_DACRFS | 56 + VF610_DAC_LPEN; 57 + writel(val, info->regs + VF610_DACx_STATCTRL); 58 + } 59 + 60 + static void vf610_dac_exit(struct vf610_dac *info) 61 + { 62 + int val; 63 + 64 + val = readl(info->regs + VF610_DACx_STATCTRL); 65 + val &= ~VF610_DAC_DACEN; 66 + writel(val, info->regs + VF610_DACx_STATCTRL); 67 + } 68 + 69 + static int vf610_set_conversion_mode(struct iio_dev *indio_dev, 70 + const struct iio_chan_spec *chan, 71 + unsigned int mode) 72 + { 73 + struct vf610_dac *info = iio_priv(indio_dev); 74 + int val; 75 + 76 + mutex_lock(&indio_dev->mlock); 77 + info->conv_mode = mode; 78 + val = readl(info->regs + VF610_DACx_STATCTRL); 79 + if (mode) 80 + val |= VF610_DAC_LPEN; 81 + else 82 + val &= ~VF610_DAC_LPEN; 83 + writel(val, info->regs + VF610_DACx_STATCTRL); 84 + mutex_unlock(&indio_dev->mlock); 85 + 86 + return 0; 87 + } 88 + 89 + static int vf610_get_conversion_mode(struct iio_dev *indio_dev, 90 + const struct iio_chan_spec *chan) 91 + { 92 + struct vf610_dac *info = iio_priv(indio_dev); 93 + 94 + return info->conv_mode; 95 + } 96 + 97 + static const char * const vf610_conv_modes[] = { "high-power", "low-power" }; 98 + 99 + static const struct iio_enum vf610_conversion_mode = { 100 + .items = vf610_conv_modes, 101 + .num_items = ARRAY_SIZE(vf610_conv_modes), 102 + .get = vf610_get_conversion_mode, 103 + .set = vf610_set_conversion_mode, 104 + }; 105 + 106 + static const struct iio_chan_spec_ext_info vf610_ext_info[] = { 107 + IIO_ENUM("conversion_mode", IIO_SHARED_BY_DIR, 108 + &vf610_conversion_mode), 109 + {}, 110 + }; 111 + 112 + #define VF610_DAC_CHAN(_chan_type) { \ 113 + .type = (_chan_type), \ 114 + .output = 1, \ 115 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 116 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 117 + .ext_info = vf610_ext_info, \ 118 + } 119 + 120 + static const struct iio_chan_spec vf610_dac_iio_channels[] = { 121 + VF610_DAC_CHAN(IIO_VOLTAGE), 122 + }; 123 + 124 + static int vf610_read_raw(struct iio_dev *indio_dev, 125 + struct iio_chan_spec const *chan, 126 + int *val, int *val2, 127 + long mask) 128 + { 129 + struct vf610_dac *info = iio_priv(indio_dev); 130 + 131 + switch (mask) { 132 + case IIO_CHAN_INFO_RAW: 133 + *val = VF610_DAC_DAT0(readl(info->regs)); 134 + return IIO_VAL_INT; 135 + case IIO_CHAN_INFO_SCALE: 136 + /* 137 + * DACRFS is always 1 for valid reference and typical 138 + * reference voltage as per Vybrid datasheet is 3.3V 139 + * from section 9.1.2.1 of Vybrid datasheet 140 + */ 141 + *val = 3300 /* mV */; 142 + *val2 = 12; 143 + return IIO_VAL_FRACTIONAL_LOG2; 144 + 145 + default: 146 + return -EINVAL; 147 + } 148 + } 149 + 150 + static int vf610_write_raw(struct iio_dev *indio_dev, 151 + struct iio_chan_spec const *chan, 152 + int val, int val2, 153 + long mask) 154 + { 155 + struct vf610_dac *info = iio_priv(indio_dev); 156 + 157 + switch (mask) { 158 + case IIO_CHAN_INFO_RAW: 159 + mutex_lock(&indio_dev->mlock); 160 + writel(VF610_DAC_DAT0(val), info->regs); 161 + mutex_unlock(&indio_dev->mlock); 162 + return 0; 163 + 164 + default: 165 + return -EINVAL; 166 + } 167 + } 168 + 169 + static const struct iio_info vf610_dac_iio_info = { 170 + .driver_module = THIS_MODULE, 171 + .read_raw = &vf610_read_raw, 172 + .write_raw = &vf610_write_raw, 173 + }; 174 + 175 + static const struct of_device_id vf610_dac_match[] = { 176 + { .compatible = "fsl,vf610-dac", }, 177 + { /* sentinel */ } 178 + }; 179 + MODULE_DEVICE_TABLE(of, vf610_dac_match); 180 + 181 + static int vf610_dac_probe(struct platform_device *pdev) 182 + { 183 + struct iio_dev *indio_dev; 184 + struct vf610_dac *info; 185 + struct resource *mem; 186 + int ret; 187 + 188 + indio_dev = devm_iio_device_alloc(&pdev->dev, 189 + sizeof(struct vf610_dac)); 190 + if (!indio_dev) { 191 + dev_err(&pdev->dev, "Failed allocating iio device\n"); 192 + return -ENOMEM; 193 + } 194 + 195 + info = iio_priv(indio_dev); 196 + info->dev = &pdev->dev; 197 + 198 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 199 + info->regs = devm_ioremap_resource(&pdev->dev, mem); 200 + if (IS_ERR(info->regs)) 201 + return PTR_ERR(info->regs); 202 + 203 + info->clk = devm_clk_get(&pdev->dev, "dac"); 204 + if (IS_ERR(info->clk)) { 205 + dev_err(&pdev->dev, "Failed getting clock, err = %ld\n", 206 + PTR_ERR(info->clk)); 207 + return PTR_ERR(info->clk); 208 + } 209 + 210 + platform_set_drvdata(pdev, indio_dev); 211 + 212 + indio_dev->name = dev_name(&pdev->dev); 213 + indio_dev->dev.parent = &pdev->dev; 214 + indio_dev->dev.of_node = pdev->dev.of_node; 215 + indio_dev->info = &vf610_dac_iio_info; 216 + indio_dev->modes = INDIO_DIRECT_MODE; 217 + indio_dev->channels = vf610_dac_iio_channels; 218 + indio_dev->num_channels = ARRAY_SIZE(vf610_dac_iio_channels); 219 + 220 + ret = clk_prepare_enable(info->clk); 221 + if (ret) { 222 + dev_err(&pdev->dev, 223 + "Could not prepare or enable the clock\n"); 224 + return ret; 225 + } 226 + 227 + vf610_dac_init(info); 228 + 229 + ret = iio_device_register(indio_dev); 230 + if (ret) { 231 + dev_err(&pdev->dev, "Couldn't register the device\n"); 232 + goto error_iio_device_register; 233 + } 234 + 235 + return 0; 236 + 237 + error_iio_device_register: 238 + clk_disable_unprepare(info->clk); 239 + 240 + return ret; 241 + } 242 + 243 + static int vf610_dac_remove(struct platform_device *pdev) 244 + { 245 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 246 + struct vf610_dac *info = iio_priv(indio_dev); 247 + 248 + iio_device_unregister(indio_dev); 249 + vf610_dac_exit(info); 250 + clk_disable_unprepare(info->clk); 251 + 252 + return 0; 253 + } 254 + 255 + #ifdef CONFIG_PM_SLEEP 256 + static int vf610_dac_suspend(struct device *dev) 257 + { 258 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 259 + struct vf610_dac *info = iio_priv(indio_dev); 260 + 261 + vf610_dac_exit(info); 262 + clk_disable_unprepare(info->clk); 263 + 264 + return 0; 265 + } 266 + 267 + static int vf610_dac_resume(struct device *dev) 268 + { 269 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 270 + struct vf610_dac *info = iio_priv(indio_dev); 271 + int ret; 272 + 273 + ret = clk_prepare_enable(info->clk); 274 + if (ret) 275 + return ret; 276 + 277 + vf610_dac_init(info); 278 + 279 + return 0; 280 + } 281 + #endif 282 + 283 + static SIMPLE_DEV_PM_OPS(vf610_dac_pm_ops, vf610_dac_suspend, vf610_dac_resume); 284 + 285 + static struct platform_driver vf610_dac_driver = { 286 + .probe = vf610_dac_probe, 287 + .remove = vf610_dac_remove, 288 + .driver = { 289 + .name = "vf610-dac", 290 + .of_match_table = vf610_dac_match, 291 + .pm = &vf610_dac_pm_ops, 292 + }, 293 + }; 294 + module_platform_driver(vf610_dac_driver); 295 + 296 + MODULE_AUTHOR("Sanchayan Maity <sanchayan.maity@toradex.com>"); 297 + MODULE_DESCRIPTION("Freescale VF610 DAC driver"); 298 + MODULE_LICENSE("GPL v2");
+1
drivers/iio/health/Kconfig
··· 10 10 config AFE4403 11 11 tristate "TI AFE4403 Heart Rate Monitor" 12 12 depends on SPI_MASTER 13 + select REGMAP_SPI 13 14 select IIO_BUFFER 14 15 select IIO_TRIGGERED_BUFFER 15 16 help
+2 -2
drivers/iio/health/afe4403.c
··· 506 506 MODULE_DEVICE_TABLE(of, afe4403_of_match); 507 507 #endif 508 508 509 - static int afe4403_suspend(struct device *dev) 509 + static int __maybe_unused afe4403_suspend(struct device *dev) 510 510 { 511 511 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 512 512 struct afe4403_data *afe = iio_priv(indio_dev); ··· 527 527 return 0; 528 528 } 529 529 530 - static int afe4403_resume(struct device *dev) 530 + static int __maybe_unused afe4403_resume(struct device *dev) 531 531 { 532 532 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 533 533 struct afe4403_data *afe = iio_priv(indio_dev);
+2 -2
drivers/iio/health/afe4404.c
··· 477 477 MODULE_DEVICE_TABLE(of, afe4404_of_match); 478 478 #endif 479 479 480 - static int afe4404_suspend(struct device *dev) 480 + static int __maybe_unused afe4404_suspend(struct device *dev) 481 481 { 482 482 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 483 483 struct afe4404_data *afe = iio_priv(indio_dev); ··· 498 498 return 0; 499 499 } 500 500 501 - static int afe4404_resume(struct device *dev) 501 + static int __maybe_unused afe4404_resume(struct device *dev) 502 502 { 503 503 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 504 504 struct afe4404_data *afe = iio_priv(indio_dev);
+1 -1
drivers/iio/humidity/hdc100x.c
··· 274 274 275 275 if (!i2c_check_functionality(client->adapter, 276 276 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) 277 - return -ENODEV; 277 + return -EOPNOTSUPP; 278 278 279 279 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 280 280 if (!indio_dev)
+1 -1
drivers/iio/humidity/htu21.c
··· 192 192 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 193 193 dev_err(&client->dev, 194 194 "Adapter does not support some i2c transaction\n"); 195 - return -ENODEV; 195 + return -EOPNOTSUPP; 196 196 } 197 197 198 198 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+1 -1
drivers/iio/humidity/si7005.c
··· 135 135 int ret; 136 136 137 137 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 138 - return -ENODEV; 138 + return -EOPNOTSUPP; 139 139 140 140 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 141 141 if (!indio_dev)
+1 -1
drivers/iio/humidity/si7020.c
··· 121 121 if (!i2c_check_functionality(client->adapter, 122 122 I2C_FUNC_SMBUS_WRITE_BYTE | 123 123 I2C_FUNC_SMBUS_READ_WORD_DATA)) 124 - return -ENODEV; 124 + return -EOPNOTSUPP; 125 125 126 126 /* Reset device, loads default settings. */ 127 127 ret = i2c_smbus_write_byte(client, SI7020CMD_RESET);
+3 -3
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
··· 66 66 union acpi_object *elem; 67 67 int j; 68 68 69 - elem = &(cpm->package.elements[i]); 69 + elem = &cpm->package.elements[i]; 70 70 for (j = 0; j < elem->package.count; ++j) { 71 71 union acpi_object *sub_elem; 72 72 73 - sub_elem = &(elem->package.elements[j]); 73 + sub_elem = &elem->package.elements[j]; 74 74 if (sub_elem->type == ACPI_TYPE_STRING) 75 75 strlcpy(info->type, sub_elem->string.pointer, 76 76 sizeof(info->type)); ··· 186 186 st->mux_client = i2c_new_device(st->mux_adapter, &info); 187 187 if (!st->mux_client) 188 188 return -ENODEV; 189 - 190 189 } 191 190 192 191 return 0; ··· 194 195 void inv_mpu_acpi_delete_mux_client(struct i2c_client *client) 195 196 { 196 197 struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(&client->dev)); 198 + 197 199 if (st->mux_client) 198 200 i2c_unregister_device(st->mux_client); 199 201 }
+141 -56
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 39 39 */ 40 40 static const int accel_scale[] = {598, 1196, 2392, 4785}; 41 41 42 + static const struct inv_mpu6050_reg_map reg_set_6500 = { 43 + .sample_rate_div = INV_MPU6050_REG_SAMPLE_RATE_DIV, 44 + .lpf = INV_MPU6050_REG_CONFIG, 45 + .user_ctrl = INV_MPU6050_REG_USER_CTRL, 46 + .fifo_en = INV_MPU6050_REG_FIFO_EN, 47 + .gyro_config = INV_MPU6050_REG_GYRO_CONFIG, 48 + .accl_config = INV_MPU6050_REG_ACCEL_CONFIG, 49 + .fifo_count_h = INV_MPU6050_REG_FIFO_COUNT_H, 50 + .fifo_r_w = INV_MPU6050_REG_FIFO_R_W, 51 + .raw_gyro = INV_MPU6050_REG_RAW_GYRO, 52 + .raw_accl = INV_MPU6050_REG_RAW_ACCEL, 53 + .temperature = INV_MPU6050_REG_TEMPERATURE, 54 + .int_enable = INV_MPU6050_REG_INT_ENABLE, 55 + .pwr_mgmt_1 = INV_MPU6050_REG_PWR_MGMT_1, 56 + .pwr_mgmt_2 = INV_MPU6050_REG_PWR_MGMT_2, 57 + .int_pin_cfg = INV_MPU6050_REG_INT_PIN_CFG, 58 + .accl_offset = INV_MPU6500_REG_ACCEL_OFFSET, 59 + .gyro_offset = INV_MPU6050_REG_GYRO_OFFSET, 60 + }; 61 + 42 62 static const struct inv_mpu6050_reg_map reg_set_6050 = { 43 63 .sample_rate_div = INV_MPU6050_REG_SAMPLE_RATE_DIV, 44 64 .lpf = INV_MPU6050_REG_CONFIG, ··· 75 55 .pwr_mgmt_1 = INV_MPU6050_REG_PWR_MGMT_1, 76 56 .pwr_mgmt_2 = INV_MPU6050_REG_PWR_MGMT_2, 77 57 .int_pin_cfg = INV_MPU6050_REG_INT_PIN_CFG, 58 + .accl_offset = INV_MPU6050_REG_ACCEL_OFFSET, 59 + .gyro_offset = INV_MPU6050_REG_GYRO_OFFSET, 78 60 }; 79 61 80 62 static const struct inv_mpu6050_chip_config chip_config_6050 = { ··· 88 66 .accl_fs = INV_MPU6050_FS_02G, 89 67 }; 90 68 91 - static const struct inv_mpu6050_hw hw_info[INV_NUM_PARTS] = { 69 + static const struct inv_mpu6050_hw hw_info[] = { 70 + { 71 + .num_reg = 117, 72 + .name = "MPU6500", 73 + .reg = &reg_set_6500, 74 + .config = &chip_config_6050, 75 + }, 92 76 { 93 77 .num_reg = 117, 94 78 .name = "MPU6050", ··· 107 79 { 108 80 unsigned int d, mgmt_1; 109 81 int result; 110 - 111 - /* switch clock needs to be careful. Only when gyro is on, can 112 - clock source be switched to gyro. Otherwise, it must be set to 113 - internal clock */ 114 - if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { 82 + /* 83 + * switch clock needs to be careful. Only when gyro is on, can 84 + * clock source be switched to gyro. Otherwise, it must be set to 85 + * internal clock 86 + */ 87 + if (mask == INV_MPU6050_BIT_PWR_GYRO_STBY) { 115 88 result = regmap_read(st->map, st->reg->pwr_mgmt_1, &mgmt_1); 116 89 if (result) 117 90 return result; ··· 120 91 mgmt_1 &= ~INV_MPU6050_BIT_CLK_MASK; 121 92 } 122 93 123 - if ((INV_MPU6050_BIT_PWR_GYRO_STBY == mask) && (!en)) { 124 - /* turning off gyro requires switch to internal clock first. 125 - Then turn off gyro engine */ 94 + if ((mask == INV_MPU6050_BIT_PWR_GYRO_STBY) && (!en)) { 95 + /* 96 + * turning off gyro requires switch to internal clock first. 97 + * Then turn off gyro engine 98 + */ 126 99 mgmt_1 |= INV_CLK_INTERNAL; 127 100 result = regmap_write(st->map, st->reg->pwr_mgmt_1, mgmt_1); 128 101 if (result) ··· 145 114 if (en) { 146 115 /* Wait for output stabilize */ 147 116 msleep(INV_MPU6050_TEMP_UP_TIME); 148 - if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { 117 + if (mask == INV_MPU6050_BIT_PWR_GYRO_STBY) { 149 118 /* switch internal clock to PLL */ 150 119 mgmt_1 |= INV_CLK_PLL; 151 120 result = regmap_write(st->map, 152 - st->reg->pwr_mgmt_1, mgmt_1); 121 + st->reg->pwr_mgmt_1, mgmt_1); 153 122 if (result) 154 123 return result; 155 124 } ··· 179 148 return result; 180 149 181 150 if (power_on) 182 - msleep(INV_MPU6050_REG_UP_TIME); 151 + usleep_range(INV_MPU6050_REG_UP_TIME_MIN, 152 + INV_MPU6050_REG_UP_TIME_MAX); 183 153 184 154 return 0; 185 155 } ··· 225 193 return result; 226 194 227 195 memcpy(&st->chip_config, hw_info[st->chip_type].config, 228 - sizeof(struct inv_mpu6050_chip_config)); 196 + sizeof(struct inv_mpu6050_chip_config)); 229 197 result = inv_mpu6050_set_power_itg(st, false); 230 198 231 199 return result; 232 200 } 233 201 202 + static int inv_mpu6050_sensor_set(struct inv_mpu6050_state *st, int reg, 203 + int axis, int val) 204 + { 205 + int ind, result; 206 + __be16 d = cpu_to_be16(val); 207 + 208 + ind = (axis - IIO_MOD_X) * 2; 209 + result = regmap_bulk_write(st->map, reg + ind, (u8 *)&d, 2); 210 + if (result) 211 + return -EINVAL; 212 + 213 + return 0; 214 + } 215 + 234 216 static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg, 235 - int axis, int *val) 217 + int axis, int *val) 236 218 { 237 219 int ind, result; 238 220 __be16 d; ··· 260 214 return IIO_VAL_INT; 261 215 } 262 216 263 - static int inv_mpu6050_read_raw(struct iio_dev *indio_dev, 264 - struct iio_chan_spec const *chan, 265 - int *val, 266 - int *val2, 267 - long mask) { 217 + static int 218 + inv_mpu6050_read_raw(struct iio_dev *indio_dev, 219 + struct iio_chan_spec const *chan, 220 + int *val, int *val2, long mask) 221 + { 268 222 struct inv_mpu6050_state *st = iio_priv(indio_dev); 223 + int ret = 0; 269 224 270 225 switch (mask) { 271 226 case IIO_CHAN_INFO_RAW: 272 227 { 273 - int ret, result; 228 + int result; 274 229 275 230 ret = IIO_VAL_INT; 276 231 result = 0; ··· 285 238 switch (chan->type) { 286 239 case IIO_ANGL_VEL: 287 240 if (!st->chip_config.gyro_fifo_enable || 288 - !st->chip_config.enable) { 241 + !st->chip_config.enable) { 289 242 result = inv_mpu6050_switch_engine(st, true, 290 243 INV_MPU6050_BIT_PWR_GYRO_STBY); 291 244 if (result) 292 245 goto error_read_raw; 293 246 } 294 - ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, 295 - chan->channel2, val); 247 + ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, 248 + chan->channel2, val); 296 249 if (!st->chip_config.gyro_fifo_enable || 297 - !st->chip_config.enable) { 250 + !st->chip_config.enable) { 298 251 result = inv_mpu6050_switch_engine(st, false, 299 252 INV_MPU6050_BIT_PWR_GYRO_STBY); 300 253 if (result) ··· 303 256 break; 304 257 case IIO_ACCEL: 305 258 if (!st->chip_config.accl_fifo_enable || 306 - !st->chip_config.enable) { 259 + !st->chip_config.enable) { 307 260 result = inv_mpu6050_switch_engine(st, true, 308 261 INV_MPU6050_BIT_PWR_ACCL_STBY); 309 262 if (result) 310 263 goto error_read_raw; 311 264 } 312 265 ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, 313 - chan->channel2, val); 266 + chan->channel2, val); 314 267 if (!st->chip_config.accl_fifo_enable || 315 - !st->chip_config.enable) { 268 + !st->chip_config.enable) { 316 269 result = inv_mpu6050_switch_engine(st, false, 317 270 INV_MPU6050_BIT_PWR_ACCL_STBY); 318 271 if (result) ··· 322 275 case IIO_TEMP: 323 276 /* wait for stablization */ 324 277 msleep(INV_MPU6050_SENSOR_UP_TIME); 325 - inv_mpu6050_sensor_show(st, st->reg->temperature, 326 - IIO_MOD_X, val); 278 + ret = inv_mpu6050_sensor_show(st, st->reg->temperature, 279 + IIO_MOD_X, val); 327 280 break; 328 281 default: 329 282 ret = -EINVAL; ··· 364 317 *val = INV_MPU6050_TEMP_OFFSET; 365 318 366 319 return IIO_VAL_INT; 320 + default: 321 + return -EINVAL; 322 + } 323 + case IIO_CHAN_INFO_CALIBBIAS: 324 + switch (chan->type) { 325 + case IIO_ANGL_VEL: 326 + ret = inv_mpu6050_sensor_show(st, st->reg->gyro_offset, 327 + chan->channel2, val); 328 + return IIO_VAL_INT; 329 + case IIO_ACCEL: 330 + ret = inv_mpu6050_sensor_show(st, st->reg->accl_offset, 331 + chan->channel2, val); 332 + return IIO_VAL_INT; 333 + 367 334 default: 368 335 return -EINVAL; 369 336 } ··· 423 362 424 363 return -EINVAL; 425 364 } 365 + 426 366 static int inv_mpu6050_write_accel_scale(struct inv_mpu6050_state *st, int val) 427 367 { 428 368 int result, i; ··· 445 383 } 446 384 447 385 static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, 448 - struct iio_chan_spec const *chan, 449 - int val, 450 - int val2, 451 - long mask) { 386 + struct iio_chan_spec const *chan, 387 + int val, int val2, long mask) 388 + { 452 389 struct inv_mpu6050_state *st = iio_priv(indio_dev); 453 390 int result; 454 391 455 392 mutex_lock(&indio_dev->mlock); 456 - /* we should only update scale when the chip is disabled, i.e., 457 - not running */ 393 + /* 394 + * we should only update scale when the chip is disabled, i.e. 395 + * not running 396 + */ 458 397 if (st->chip_config.enable) { 459 398 result = -EBUSY; 460 399 goto error_write_raw; ··· 478 415 break; 479 416 } 480 417 break; 418 + case IIO_CHAN_INFO_CALIBBIAS: 419 + switch (chan->type) { 420 + case IIO_ANGL_VEL: 421 + result = inv_mpu6050_sensor_set(st, 422 + st->reg->gyro_offset, 423 + chan->channel2, val); 424 + break; 425 + case IIO_ACCEL: 426 + result = inv_mpu6050_sensor_set(st, 427 + st->reg->accl_offset, 428 + chan->channel2, val); 429 + break; 430 + default: 431 + result = -EINVAL; 432 + } 481 433 default: 482 434 result = -EINVAL; 483 435 break; ··· 539 461 /** 540 462 * inv_mpu6050_fifo_rate_store() - Set fifo rate. 541 463 */ 542 - static ssize_t inv_mpu6050_fifo_rate_store(struct device *dev, 543 - struct device_attribute *attr, const char *buf, size_t count) 464 + static ssize_t 465 + inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, 466 + const char *buf, size_t count) 544 467 { 545 468 s32 fifo_rate; 546 469 u8 d; ··· 552 473 if (kstrtoint(buf, 10, &fifo_rate)) 553 474 return -EINVAL; 554 475 if (fifo_rate < INV_MPU6050_MIN_FIFO_RATE || 555 - fifo_rate > INV_MPU6050_MAX_FIFO_RATE) 476 + fifo_rate > INV_MPU6050_MAX_FIFO_RATE) 556 477 return -EINVAL; 557 478 if (fifo_rate == st->chip_config.fifo_rate) 558 479 return count; ··· 588 509 /** 589 510 * inv_fifo_rate_show() - Get the current sampling rate. 590 511 */ 591 - static ssize_t inv_fifo_rate_show(struct device *dev, 592 - struct device_attribute *attr, char *buf) 512 + static ssize_t 513 + inv_fifo_rate_show(struct device *dev, struct device_attribute *attr, 514 + char *buf) 593 515 { 594 516 struct inv_mpu6050_state *st = iio_priv(dev_to_iio_dev(dev)); 595 517 ··· 601 521 * inv_attr_show() - calling this function will show current 602 522 * parameters. 603 523 */ 604 - static ssize_t inv_attr_show(struct device *dev, 605 - struct device_attribute *attr, char *buf) 524 + static ssize_t inv_attr_show(struct device *dev, struct device_attribute *attr, 525 + char *buf) 606 526 { 607 527 struct inv_mpu6050_state *st = iio_priv(dev_to_iio_dev(dev)); 608 528 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 609 529 s8 *m; 610 530 611 531 switch (this_attr->address) { 612 - /* In MPU6050, the two matrix are the same because gyro and accel 613 - are integrated in one chip */ 532 + /* 533 + * In MPU6050, the two matrix are the same because gyro and accel 534 + * are integrated in one chip 535 + */ 614 536 case ATTR_GYRO_MATRIX: 615 537 case ATTR_ACCL_MATRIX: 616 538 m = st->plat_data.orientation; ··· 649 567 .type = _type, \ 650 568 .modified = 1, \ 651 569 .channel2 = _channel2, \ 652 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 653 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 570 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 571 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 572 + BIT(IIO_CHAN_INFO_CALIBBIAS), \ 654 573 .scan_index = _index, \ 655 574 .scan_type = { \ 656 575 .sign = 's', \ 657 576 .realbits = 16, \ 658 577 .storagebits = 16, \ 659 - .shift = 0 , \ 578 + .shift = 0, \ 660 579 .endianness = IIO_BE, \ 661 580 }, \ 662 581 } ··· 670 587 */ 671 588 { 672 589 .type = IIO_TEMP, 673 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) 590 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) 674 591 | BIT(IIO_CHAN_INFO_OFFSET) 675 592 | BIT(IIO_CHAN_INFO_SCALE), 676 593 .scan_index = -1, ··· 727 644 { 728 645 int result; 729 646 730 - st->chip_type = INV_MPU6050; 731 647 st->hw = &hw_info[st->chip_type]; 732 648 st->reg = hw_info[st->chip_type].reg; 733 649 ··· 736 654 if (result) 737 655 return result; 738 656 msleep(INV_MPU6050_POWER_UP_TIME); 739 - /* toggle power state. After reset, the sleep bit could be on 740 - or off depending on the OTP settings. Toggling power would 741 - make it in a definite state as well as making the hardware 742 - state align with the software state */ 657 + /* 658 + * toggle power state. After reset, the sleep bit could be on 659 + * or off depending on the OTP settings. Toggling power would 660 + * make it in a definite state as well as making the hardware 661 + * state align with the software state 662 + */ 743 663 result = inv_mpu6050_set_power_itg(st, false); 744 664 if (result) 745 665 return result; ··· 750 666 return result; 751 667 752 668 result = inv_mpu6050_switch_engine(st, false, 753 - INV_MPU6050_BIT_PWR_ACCL_STBY); 669 + INV_MPU6050_BIT_PWR_ACCL_STBY); 754 670 if (result) 755 671 return result; 756 672 result = inv_mpu6050_switch_engine(st, false, 757 - INV_MPU6050_BIT_PWR_GYRO_STBY); 673 + INV_MPU6050_BIT_PWR_GYRO_STBY); 758 674 if (result) 759 675 return result; 760 676 ··· 762 678 } 763 679 764 680 int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, 765 - int (*inv_mpu_bus_setup)(struct iio_dev *)) 681 + int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type) 766 682 { 767 683 struct inv_mpu6050_state *st; 768 684 struct iio_dev *indio_dev; ··· 775 691 return -ENOMEM; 776 692 777 693 st = iio_priv(indio_dev); 694 + st->chip_type = chip_type; 778 695 st->powerup_count = 0; 779 696 st->irq = irq; 780 697 st->map = regmap;
+6 -4
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 68 68 if (ret) 69 69 goto write_error; 70 70 71 - msleep(INV_MPU6050_REG_UP_TIME); 71 + usleep_range(INV_MPU6050_REG_UP_TIME_MIN, 72 + INV_MPU6050_REG_UP_TIME_MAX); 72 73 } 73 74 if (!ret) { 74 75 st->powerup_count++; ··· 112 111 * Returns 0 on success, a negative error code otherwise. 113 112 */ 114 113 static int inv_mpu_probe(struct i2c_client *client, 115 - const struct i2c_device_id *id) 114 + const struct i2c_device_id *id) 116 115 { 117 116 struct inv_mpu6050_state *st; 118 117 int result; ··· 121 120 122 121 if (!i2c_check_functionality(client->adapter, 123 122 I2C_FUNC_SMBUS_I2C_BLOCK)) 124 - return -ENOSYS; 123 + return -EOPNOTSUPP; 125 124 126 125 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); 127 126 if (IS_ERR(regmap)) { ··· 130 129 return PTR_ERR(regmap); 131 130 } 132 131 133 - result = inv_mpu_core_probe(regmap, client->irq, name, NULL); 132 + result = inv_mpu_core_probe(regmap, client->irq, name, 133 + NULL, id->driver_data); 134 134 if (result < 0) 135 135 return result; 136 136
+18 -2
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 39 39 * @int_enable: Interrupt enable register. 40 40 * @pwr_mgmt_1: Controls chip's power state and clock source. 41 41 * @pwr_mgmt_2: Controls power state of individual sensors. 42 + * @int_pin_cfg; Controls interrupt pin configuration. 43 + * @accl_offset: Controls the accelerometer calibration offset. 44 + * @gyro_offset: Controls the gyroscope calibration offset. 42 45 */ 43 46 struct inv_mpu6050_reg_map { 44 47 u8 sample_rate_div; ··· 59 56 u8 pwr_mgmt_1; 60 57 u8 pwr_mgmt_2; 61 58 u8 int_pin_cfg; 59 + u8 accl_offset; 60 + u8 gyro_offset; 62 61 }; 63 62 64 63 /*device enum */ ··· 137 132 }; 138 133 139 134 /*register and associated bit definition*/ 135 + #define INV_MPU6050_REG_ACCEL_OFFSET 0x06 136 + #define INV_MPU6050_REG_GYRO_OFFSET 0x13 137 + 140 138 #define INV_MPU6050_REG_SAMPLE_RATE_DIV 0x19 141 139 #define INV_MPU6050_REG_CONFIG 0x1A 142 140 #define INV_MPU6050_REG_GYRO_CONFIG 0x1B ··· 180 172 #define INV_MPU6050_BYTES_PER_3AXIS_SENSOR 6 181 173 #define INV_MPU6050_FIFO_COUNT_BYTE 2 182 174 #define INV_MPU6050_FIFO_THRESHOLD 500 175 + 176 + /* mpu6500 registers */ 177 + #define INV_MPU6500_REG_ACCEL_OFFSET 0x77 178 + 179 + /* delay time in milliseconds */ 183 180 #define INV_MPU6050_POWER_UP_TIME 100 184 181 #define INV_MPU6050_TEMP_UP_TIME 100 185 182 #define INV_MPU6050_SENSOR_UP_TIME 30 186 - #define INV_MPU6050_REG_UP_TIME 5 183 + 184 + /* delay time in microseconds */ 185 + #define INV_MPU6050_REG_UP_TIME_MIN 5000 186 + #define INV_MPU6050_REG_UP_TIME_MAX 10000 187 187 188 188 #define INV_MPU6050_TEMP_OFFSET 12421 189 189 #define INV_MPU6050_TEMP_SCALE 2941 ··· 277 261 int inv_mpu_acpi_create_mux_client(struct i2c_client *client); 278 262 void inv_mpu_acpi_delete_mux_client(struct i2c_client *client); 279 263 int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, 280 - int (*inv_mpu_bus_setup)(struct iio_dev *)); 264 + int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type); 281 265 int inv_mpu_core_remove(struct device *dev); 282 266 int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on); 283 267 extern const struct dev_pm_ops inv_mpu_pmops;
+11 -12
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
··· 57 57 58 58 /* reset FIFO*/ 59 59 result = regmap_write(st->map, st->reg->user_ctrl, 60 - INV_MPU6050_BIT_FIFO_RST); 60 + INV_MPU6050_BIT_FIFO_RST); 61 61 if (result) 62 62 goto reset_fifo_fail; 63 63 ··· 68 68 if (st->chip_config.accl_fifo_enable || 69 69 st->chip_config.gyro_fifo_enable) { 70 70 result = regmap_write(st->map, st->reg->int_enable, 71 - INV_MPU6050_BIT_DATA_RDY_EN); 71 + INV_MPU6050_BIT_DATA_RDY_EN); 72 72 if (result) 73 73 return result; 74 74 } 75 75 /* enable FIFO reading and I2C master interface*/ 76 76 result = regmap_write(st->map, st->reg->user_ctrl, 77 - INV_MPU6050_BIT_FIFO_EN); 77 + INV_MPU6050_BIT_FIFO_EN); 78 78 if (result) 79 79 goto reset_fifo_fail; 80 80 /* enable sensor output to FIFO */ ··· 92 92 reset_fifo_fail: 93 93 dev_err(regmap_get_device(st->map), "reset fifo failed %d\n", result); 94 94 result = regmap_write(st->map, st->reg->int_enable, 95 - INV_MPU6050_BIT_DATA_RDY_EN); 95 + INV_MPU6050_BIT_DATA_RDY_EN); 96 96 97 97 return result; 98 98 } ··· 109 109 110 110 timestamp = iio_get_time_ns(); 111 111 kfifo_in_spinlocked(&st->timestamps, &timestamp, 1, 112 - &st->time_stamp_lock); 112 + &st->time_stamp_lock); 113 113 114 114 return IRQ_WAKE_THREAD; 115 115 } ··· 143 143 * read fifo_count register to know how many bytes inside FIFO 144 144 * right now 145 145 */ 146 - result = regmap_bulk_read(st->map, 147 - st->reg->fifo_count_h, 148 - data, INV_MPU6050_FIFO_COUNT_BYTE); 146 + result = regmap_bulk_read(st->map, st->reg->fifo_count_h, data, 147 + INV_MPU6050_FIFO_COUNT_BYTE); 149 148 if (result) 150 149 goto end_session; 151 150 fifo_count = be16_to_cpup((__be16 *)(&data[0])); ··· 157 158 goto flush_fifo; 158 159 /* Timestamp mismatch. */ 159 160 if (kfifo_len(&st->timestamps) > 160 - fifo_count / bytes_per_datum + INV_MPU6050_TIME_STAMP_TOR) 161 - goto flush_fifo; 161 + fifo_count / bytes_per_datum + INV_MPU6050_TIME_STAMP_TOR) 162 + goto flush_fifo; 162 163 while (fifo_count >= bytes_per_datum) { 163 164 result = regmap_bulk_read(st->map, st->reg->fifo_r_w, 164 165 data, bytes_per_datum); ··· 167 168 168 169 result = kfifo_out(&st->timestamps, &timestamp, 1); 169 170 /* when there is no timestamp, put timestamp as 0 */ 170 - if (0 == result) 171 + if (result == 0) 171 172 timestamp = 0; 172 173 173 174 result = iio_push_to_buffers_with_timestamp(indio_dev, data, 174 - timestamp); 175 + timestamp); 175 176 if (result) 176 177 goto flush_fifo; 177 178 fifo_count -= bytes_per_datum;
+2 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 54 54 return PTR_ERR(regmap); 55 55 } 56 56 57 - return inv_mpu_core_probe(regmap, spi->irq, name, inv_mpu_i2c_disable); 57 + return inv_mpu_core_probe(regmap, spi->irq, name, 58 + inv_mpu_i2c_disable, id->driver_data); 58 59 } 59 60 60 61 static int inv_mpu_remove(struct spi_device *spi)
+11 -11
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
··· 19 19 20 20 st->chip_config.gyro_fifo_enable = 21 21 test_bit(INV_MPU6050_SCAN_GYRO_X, 22 - indio_dev->active_scan_mask) || 23 - test_bit(INV_MPU6050_SCAN_GYRO_Y, 24 - indio_dev->active_scan_mask) || 25 - test_bit(INV_MPU6050_SCAN_GYRO_Z, 26 - indio_dev->active_scan_mask); 22 + indio_dev->active_scan_mask) || 23 + test_bit(INV_MPU6050_SCAN_GYRO_Y, 24 + indio_dev->active_scan_mask) || 25 + test_bit(INV_MPU6050_SCAN_GYRO_Z, 26 + indio_dev->active_scan_mask); 27 27 28 28 st->chip_config.accl_fifo_enable = 29 29 test_bit(INV_MPU6050_SCAN_ACCL_X, 30 - indio_dev->active_scan_mask) || 31 - test_bit(INV_MPU6050_SCAN_ACCL_Y, 32 - indio_dev->active_scan_mask) || 33 - test_bit(INV_MPU6050_SCAN_ACCL_Z, 34 - indio_dev->active_scan_mask); 30 + indio_dev->active_scan_mask) || 31 + test_bit(INV_MPU6050_SCAN_ACCL_Y, 32 + indio_dev->active_scan_mask) || 33 + test_bit(INV_MPU6050_SCAN_ACCL_Z, 34 + indio_dev->active_scan_mask); 35 35 } 36 36 37 37 /** ··· 101 101 * @state: Desired trigger state 102 102 */ 103 103 static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig, 104 - bool state) 104 + bool state) 105 105 { 106 106 return inv_mpu6050_set_enable(iio_trigger_get_drvdata(trig), state); 107 107 }
+1 -1
drivers/iio/light/bh1750.c
··· 241 241 242 242 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 243 243 I2C_FUNC_SMBUS_WRITE_BYTE)) 244 - return -ENODEV; 244 + return -EOPNOTSUPP; 245 245 246 246 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 247 247 if (!indio_dev)
+1 -1
drivers/iio/light/jsa1212.c
··· 326 326 int ret; 327 327 328 328 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 329 - return -ENODEV; 329 + return -EOPNOTSUPP; 330 330 331 331 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 332 332 if (!indio_dev)
+33
drivers/iio/magnetometer/Kconfig
··· 105 105 depends on IIO_ST_MAGN_3AXIS 106 106 depends on IIO_ST_SENSORS_SPI 107 107 108 + config SENSORS_HMC5843 109 + tristate 110 + select IIO_BUFFER 111 + select IIO_TRIGGERED_BUFFER 112 + 113 + config SENSORS_HMC5843_I2C 114 + tristate "Honeywell HMC5843/5883/5883L 3-Axis Magnetometer (I2C)" 115 + depends on I2C 116 + select SENSORS_HMC5843 117 + select REGMAP_I2C 118 + help 119 + Say Y here to add support for the Honeywell HMC5843, HMC5883 and 120 + HMC5883L 3-Axis Magnetometer (digital compass). 121 + 122 + This driver can also be compiled as a set of modules. 123 + If so, these modules will be created: 124 + - hmc5843_core (core functions) 125 + - hmc5843_i2c (support for HMC5843, HMC5883, HMC5883L and HMC5983) 126 + 127 + config SENSORS_HMC5843_SPI 128 + tristate "Honeywell HMC5983 3-Axis Magnetometer (SPI)" 129 + depends on SPI_MASTER 130 + select SENSORS_HMC5843 131 + select REGMAP_SPI 132 + help 133 + Say Y here to add support for the Honeywell HMC5983 3-Axis Magnetometer 134 + (digital compass). 135 + 136 + This driver can also be compiled as a set of modules. 137 + If so, these modules will be created: 138 + - hmc5843_core (core functions) 139 + - hmc5843_spi (support for HMC5983) 140 + 108 141 endmenu
+4
drivers/iio/magnetometer/Makefile
··· 15 15 16 16 obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o 17 17 obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o 18 + 19 + obj-$(CONFIG_SENSORS_HMC5843) += hmc5843_core.o 20 + obj-$(CONFIG_SENSORS_HMC5843_I2C) += hmc5843_i2c.o 21 + obj-$(CONFIG_SENSORS_HMC5843_SPI) += hmc5843_spi.o
+12
drivers/iio/potentiometer/Kconfig
··· 17 17 To compile this driver as a module, choose M here: the 18 18 module will be called mcp4531. 19 19 20 + config TPL0102 21 + tristate "Texas Instruments digital potentiometer driver" 22 + depends on I2C 23 + select REGMAP_I2C 24 + help 25 + Say yes here to build support for the Texas Instruments 26 + TPL0102, TPL0402 27 + digital potentiometer chips. 28 + 29 + To compile this driver as a module, choose M here: the 30 + module will be called tpl0102. 31 + 20 32 endmenu
+1
drivers/iio/potentiometer/Makefile
··· 4 4 5 5 # When adding new entries keep the list in alphabetical order 6 6 obj-$(CONFIG_MCP4531) += mcp4531.o 7 + obj-$(CONFIG_TPL0102) += tpl0102.o
+1 -1
drivers/iio/potentiometer/mcp4531.c
··· 159 159 if (!i2c_check_functionality(client->adapter, 160 160 I2C_FUNC_SMBUS_WORD_DATA)) { 161 161 dev_err(dev, "SMBUS Word Data not supported\n"); 162 - return -EIO; 162 + return -EOPNOTSUPP; 163 163 } 164 164 165 165 indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+166
drivers/iio/potentiometer/tpl0102.c
··· 1 + /* 2 + * tpl0102.c - Support for Texas Instruments digital potentiometers 3 + * 4 + * Copyright (C) 2016 Matt Ranostay <mranostay@gmail.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * TODO: enable/disable hi-z output control 17 + */ 18 + 19 + #include <linux/module.h> 20 + #include <linux/i2c.h> 21 + #include <linux/regmap.h> 22 + #include <linux/iio/iio.h> 23 + 24 + struct tpl0102_cfg { 25 + int wipers; 26 + int max_pos; 27 + int kohms; 28 + }; 29 + 30 + enum tpl0102_type { 31 + CAT5140_503, 32 + CAT5140_104, 33 + TPL0102_104, 34 + TPL0401_103, 35 + }; 36 + 37 + static const struct tpl0102_cfg tpl0102_cfg[] = { 38 + /* on-semiconductor parts */ 39 + [CAT5140_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, 40 + [CAT5140_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, 41 + /* ti parts */ 42 + [TPL0102_104] = { .wipers = 2, .max_pos = 256, .kohms = 100 }, 43 + [TPL0401_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, 44 + }; 45 + 46 + struct tpl0102_data { 47 + struct regmap *regmap; 48 + unsigned long devid; 49 + }; 50 + 51 + static const struct regmap_config tpl0102_regmap_config = { 52 + .reg_bits = 8, 53 + .val_bits = 8, 54 + }; 55 + 56 + #define TPL0102_CHANNEL(ch) { \ 57 + .type = IIO_RESISTANCE, \ 58 + .indexed = 1, \ 59 + .output = 1, \ 60 + .channel = (ch), \ 61 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 62 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 63 + } 64 + 65 + static const struct iio_chan_spec tpl0102_channels[] = { 66 + TPL0102_CHANNEL(0), 67 + TPL0102_CHANNEL(1), 68 + }; 69 + 70 + static int tpl0102_read_raw(struct iio_dev *indio_dev, 71 + struct iio_chan_spec const *chan, 72 + int *val, int *val2, long mask) 73 + { 74 + struct tpl0102_data *data = iio_priv(indio_dev); 75 + 76 + switch (mask) { 77 + case IIO_CHAN_INFO_RAW: { 78 + int ret = regmap_read(data->regmap, chan->channel, val); 79 + 80 + return ret ? ret : IIO_VAL_INT; 81 + } 82 + case IIO_CHAN_INFO_SCALE: 83 + *val = 1000 * tpl0102_cfg[data->devid].kohms; 84 + *val2 = tpl0102_cfg[data->devid].max_pos; 85 + return IIO_VAL_FRACTIONAL; 86 + } 87 + 88 + return -EINVAL; 89 + } 90 + 91 + static int tpl0102_write_raw(struct iio_dev *indio_dev, 92 + struct iio_chan_spec const *chan, 93 + int val, int val2, long mask) 94 + { 95 + struct tpl0102_data *data = iio_priv(indio_dev); 96 + 97 + if (mask != IIO_CHAN_INFO_RAW) 98 + return -EINVAL; 99 + 100 + if (val >= tpl0102_cfg[data->devid].max_pos || val < 0) 101 + return -EINVAL; 102 + 103 + return regmap_write(data->regmap, chan->channel, val); 104 + } 105 + 106 + static const struct iio_info tpl0102_info = { 107 + .read_raw = tpl0102_read_raw, 108 + .write_raw = tpl0102_write_raw, 109 + .driver_module = THIS_MODULE, 110 + }; 111 + 112 + static int tpl0102_probe(struct i2c_client *client, 113 + const struct i2c_device_id *id) 114 + { 115 + struct device *dev = &client->dev; 116 + struct tpl0102_data *data; 117 + struct iio_dev *indio_dev; 118 + 119 + if (!i2c_check_functionality(client->adapter, 120 + I2C_FUNC_SMBUS_WORD_DATA)) 121 + return -ENOTSUPP; 122 + 123 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 124 + if (!indio_dev) 125 + return -ENOMEM; 126 + data = iio_priv(indio_dev); 127 + i2c_set_clientdata(client, indio_dev); 128 + 129 + data->devid = id->driver_data; 130 + data->regmap = devm_regmap_init_i2c(client, &tpl0102_regmap_config); 131 + if (IS_ERR(data->regmap)) { 132 + dev_err(dev, "regmap initialization failed\n"); 133 + return PTR_ERR(data->regmap); 134 + } 135 + 136 + indio_dev->dev.parent = dev; 137 + indio_dev->info = &tpl0102_info; 138 + indio_dev->channels = tpl0102_channels; 139 + indio_dev->num_channels = tpl0102_cfg[data->devid].wipers; 140 + indio_dev->name = client->name; 141 + 142 + return devm_iio_device_register(dev, indio_dev); 143 + } 144 + 145 + static const struct i2c_device_id tpl0102_id[] = { 146 + { "cat5140-503", CAT5140_503 }, 147 + { "cat5140-104", CAT5140_104 }, 148 + { "tpl0102-104", TPL0102_104 }, 149 + { "tpl0401-103", TPL0401_103 }, 150 + {} 151 + }; 152 + MODULE_DEVICE_TABLE(i2c, tpl0102_id); 153 + 154 + static struct i2c_driver tpl0102_driver = { 155 + .driver = { 156 + .name = "tpl0102", 157 + }, 158 + .probe = tpl0102_probe, 159 + .id_table = tpl0102_id, 160 + }; 161 + 162 + module_i2c_driver(tpl0102_driver); 163 + 164 + MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); 165 + MODULE_DESCRIPTION("TPL0102 digital potentiometer"); 166 + MODULE_LICENSE("GPL");
+1
drivers/iio/pressure/Kconfig
··· 69 69 70 70 config MS5611 71 71 tristate "Measurement Specialties MS5611 pressure sensor driver" 72 + select IIO_BUFFER 72 73 select IIO_TRIGGERED_BUFFER 73 74 help 74 75 Say Y here to build support for the Measurement Specialties
+1 -1
drivers/iio/pressure/mpl115_i2c.c
··· 42 42 const struct i2c_device_id *id) 43 43 { 44 44 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 45 - return -ENODEV; 45 + return -EOPNOTSUPP; 46 46 47 47 return mpl115_probe(&client->dev, id->name, &mpl115_i2c_ops); 48 48 }
+2 -1
drivers/iio/pressure/ms5611.h
··· 51 51 struct ms5611_chip_info *chip_info; 52 52 }; 53 53 54 - int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type); 54 + int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, 55 + const char* name, int type); 55 56 int ms5611_remove(struct iio_dev *indio_dev); 56 57 57 58 #endif /* _MS5611_H */
+22 -8
drivers/iio/pressure/ms5611_core.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/iio/iio.h> 18 18 #include <linux/delay.h> 19 + #include <linux/regulator/consumer.h> 19 20 20 21 #include <linux/iio/buffer.h> 21 22 #include <linux/iio/triggered_buffer.h> ··· 137 136 138 137 t = 2000 + ((chip_info->prom[6] * dt) >> 23); 139 138 if (t < 2000) { 140 - s64 off2, sens2, t2; 139 + s64 off2, sens2, t2, tmp; 141 140 142 141 t2 = (dt * dt) >> 31; 143 - off2 = (61 * (t - 2000) * (t - 2000)) >> 4; 144 - sens2 = off2 << 1; 142 + tmp = (t - 2000) * (t - 2000); 143 + off2 = (61 * tmp) >> 4; 144 + sens2 = tmp << 1; 145 145 146 146 if (t < -1500) { 147 - s64 tmp = (t + 1500) * (t + 1500); 148 - 147 + tmp = (t + 1500) * (t + 1500); 149 148 off2 += 15 * tmp; 150 - sens2 += (8 * tmp); 149 + sens2 += 8 * tmp; 151 150 } 152 151 153 152 t -= t2; ··· 291 290 static int ms5611_init(struct iio_dev *indio_dev) 292 291 { 293 292 int ret; 293 + struct regulator *vdd = devm_regulator_get(indio_dev->dev.parent, 294 + "vdd"); 295 + 296 + /* Enable attached regulator if any. */ 297 + if (!IS_ERR(vdd)) { 298 + ret = regulator_enable(vdd); 299 + if (ret) { 300 + dev_err(indio_dev->dev.parent, 301 + "failed to enable Vdd supply: %d\n", ret); 302 + return ret; 303 + } 304 + } 294 305 295 306 ret = ms5611_reset(indio_dev); 296 307 if (ret < 0) ··· 311 298 return ms5611_read_prom(indio_dev); 312 299 } 313 300 314 - int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type) 301 + int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, 302 + const char *name, int type) 315 303 { 316 304 int ret; 317 305 struct ms5611_state *st = iio_priv(indio_dev); ··· 320 306 mutex_init(&st->lock); 321 307 st->chip_info = &chip_info_tbl[type]; 322 308 indio_dev->dev.parent = dev; 323 - indio_dev->name = dev->driver->name; 309 + indio_dev->name = name; 324 310 indio_dev->info = &ms5611_info; 325 311 indio_dev->channels = ms5611_channels; 326 312 indio_dev->num_channels = ARRAY_SIZE(ms5611_channels);
+2 -2
drivers/iio/pressure/ms5611_i2c.c
··· 92 92 I2C_FUNC_SMBUS_WRITE_BYTE | 93 93 I2C_FUNC_SMBUS_READ_WORD_DATA | 94 94 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) 95 - return -ENODEV; 95 + return -EOPNOTSUPP; 96 96 97 97 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 98 98 if (!indio_dev) ··· 105 105 st->read_adc_temp_and_pressure = ms5611_i2c_read_adc_temp_and_pressure; 106 106 st->client = client; 107 107 108 - return ms5611_probe(indio_dev, &client->dev, id->driver_data); 108 + return ms5611_probe(indio_dev, &client->dev, id->name, id->driver_data); 109 109 } 110 110 111 111 static int ms5611_i2c_remove(struct i2c_client *client)
+2 -2
drivers/iio/pressure/ms5611_spi.c
··· 105 105 st->read_adc_temp_and_pressure = ms5611_spi_read_adc_temp_and_pressure; 106 106 st->client = spi; 107 107 108 - return ms5611_probe(indio_dev, &spi->dev, 109 - spi_get_device_id(spi)->driver_data); 108 + return ms5611_probe(indio_dev, &spi->dev, spi_get_device_id(spi)->name, 109 + spi_get_device_id(spi)->driver_data); 110 110 } 111 111 112 112 static int ms5611_spi_remove(struct spi_device *spi)
+1 -1
drivers/iio/pressure/ms5637.c
··· 136 136 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 137 137 dev_err(&client->dev, 138 138 "Adapter does not support some i2c transaction\n"); 139 - return -ENODEV; 139 + return -EOPNOTSUPP; 140 140 } 141 141 142 142 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+1 -1
drivers/iio/pressure/t5403.c
··· 221 221 222 222 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA | 223 223 I2C_FUNC_SMBUS_I2C_BLOCK)) 224 - return -ENODEV; 224 + return -EOPNOTSUPP; 225 225 226 226 ret = i2c_smbus_read_byte_data(client, T5403_SLAVE_ADDR); 227 227 if (ret < 0)
+1 -1
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
··· 278 278 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) 279 279 data->xfer = lidar_smbus_xfer; 280 280 else 281 - return -ENOTSUPP; 281 + return -EOPNOTSUPP; 282 282 283 283 indio_dev->info = &lidar_info; 284 284 indio_dev->name = LIDAR_DRV_NAME;
+1 -1
drivers/iio/temperature/mlx90614.c
··· 516 516 int ret; 517 517 518 518 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 519 - return -ENODEV; 519 + return -EOPNOTSUPP; 520 520 521 521 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 522 522 if (!indio_dev)
+1 -1
drivers/iio/temperature/tmp006.c
··· 205 205 int ret; 206 206 207 207 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 208 - return -ENODEV; 208 + return -EOPNOTSUPP; 209 209 210 210 if (!tmp006_check_identification(client)) { 211 211 dev_err(&client->dev, "no TMP006 sensor\n");
+1 -1
drivers/iio/temperature/tsys01.c
··· 190 190 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 191 191 dev_err(&client->dev, 192 192 "Adapter does not support some i2c transaction\n"); 193 - return -ENODEV; 193 + return -EOPNOTSUPP; 194 194 } 195 195 196 196 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+1 -1
drivers/iio/temperature/tsys02d.c
··· 137 137 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 138 138 dev_err(&client->dev, 139 139 "Adapter does not support some i2c transaction\n"); 140 - return -ENODEV; 140 + return -EOPNOTSUPP; 141 141 } 142 142 143 143 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
-1
drivers/staging/iio/Kconfig
··· 12 12 source "drivers/staging/iio/gyro/Kconfig" 13 13 source "drivers/staging/iio/impedance-analyzer/Kconfig" 14 14 source "drivers/staging/iio/light/Kconfig" 15 - source "drivers/staging/iio/magnetometer/Kconfig" 16 15 source "drivers/staging/iio/meter/Kconfig" 17 16 source "drivers/staging/iio/resolver/Kconfig" 18 17 source "drivers/staging/iio/trigger/Kconfig"
-1
drivers/staging/iio/Makefile
··· 10 10 obj-y += gyro/ 11 11 obj-y += impedance-analyzer/ 12 12 obj-y += light/ 13 - obj-y += magnetometer/ 14 13 obj-y += meter/ 15 14 obj-y += resolver/ 16 15 obj-y += trigger/
-8
drivers/staging/iio/TODO
··· 58 58 frequencies (100Hz - 4kHz). 59 59 2) Lots of testing 60 60 61 - Periodic Timer trigger 62 - 1) Move to a more general hardware periodic timer request 63 - subsystem. Current approach is abusing purpose of RTC. 64 - Initial discussions have taken place, but no actual code 65 - is in place as yet. This topic will be reopened on lkml 66 - shortly. I don't really envision this patch being merged 67 - in anything like its current form. 68 - 69 61 GPIO trigger 70 62 1) Add control over the type of interrupt etc. This will 71 63 necessitate a header that is also visible from arch board
+15 -13
drivers/staging/iio/light/isl29018.c
··· 100 100 }; 101 101 102 102 struct isl29018_chip { 103 - struct device *dev; 104 103 struct regmap *regmap; 105 104 struct mutex lock; 106 105 int type; ··· 179 180 int status; 180 181 unsigned int lsb; 181 182 unsigned int msb; 183 + struct device *dev = regmap_get_device(chip->regmap); 182 184 183 185 /* Set mode */ 184 186 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, 185 187 mode << COMMMAND1_OPMODE_SHIFT); 186 188 if (status) { 187 - dev_err(chip->dev, 189 + dev_err(dev, 188 190 "Error in setting operating mode err %d\n", status); 189 191 return status; 190 192 } 191 193 msleep(CONVERSION_TIME_MS); 192 194 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_LSB, &lsb); 193 195 if (status < 0) { 194 - dev_err(chip->dev, 196 + dev_err(dev, 195 197 "Error in reading LSB DATA with err %d\n", status); 196 198 return status; 197 199 } 198 200 199 201 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_MSB, &msb); 200 202 if (status < 0) { 201 - dev_err(chip->dev, 203 + dev_err(dev, 202 204 "Error in reading MSB DATA with error %d\n", status); 203 205 return status; 204 206 } 205 - dev_vdbg(chip->dev, "MSB 0x%x and LSB 0x%x\n", msb, lsb); 207 + dev_vdbg(dev, "MSB 0x%x and LSB 0x%x\n", msb, lsb); 206 208 207 209 return (msb << 8) | lsb; 208 210 } ··· 246 246 int status; 247 247 int prox_data = -1; 248 248 int ir_data = -1; 249 + struct device *dev = regmap_get_device(chip->regmap); 249 250 250 251 /* Do proximity sensing with required scheme */ 251 252 status = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII, 252 253 COMMANDII_SCHEME_MASK, 253 254 scheme << COMMANDII_SCHEME_SHIFT); 254 255 if (status) { 255 - dev_err(chip->dev, "Error in setting operating mode\n"); 256 + dev_err(dev, "Error in setting operating mode\n"); 256 257 return status; 257 258 } 258 259 ··· 526 525 { 527 526 int status; 528 527 unsigned int id; 528 + struct device *dev = regmap_get_device(chip->regmap); 529 529 530 530 status = regmap_read(chip->regmap, ISL29035_REG_DEVICE_ID, &id); 531 531 if (status < 0) { 532 - dev_err(chip->dev, 532 + dev_err(dev, 533 533 "Error reading ID register with error %d\n", 534 534 status); 535 535 return status; ··· 555 553 static int isl29018_chip_init(struct isl29018_chip *chip) 556 554 { 557 555 int status; 556 + struct device *dev = regmap_get_device(chip->regmap); 558 557 559 558 if (chip->type == isl29035) { 560 559 status = isl29035_detect(chip); ··· 585 582 */ 586 583 status = regmap_write(chip->regmap, ISL29018_REG_TEST, 0x0); 587 584 if (status < 0) { 588 - dev_err(chip->dev, "Failed to clear isl29018 TEST reg.(%d)\n", 585 + dev_err(dev, "Failed to clear isl29018 TEST reg.(%d)\n", 589 586 status); 590 587 return status; 591 588 } ··· 596 593 */ 597 594 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, 0); 598 595 if (status < 0) { 599 - dev_err(chip->dev, "Failed to clear isl29018 CMD1 reg.(%d)\n", 596 + dev_err(dev, "Failed to clear isl29018 CMD1 reg.(%d)\n", 600 597 status); 601 598 return status; 602 599 } ··· 607 604 status = isl29018_set_scale(chip, chip->scale.scale, 608 605 chip->scale.uscale); 609 606 if (status < 0) { 610 - dev_err(chip->dev, "Init of isl29018 fails\n"); 607 + dev_err(dev, "Init of isl29018 fails\n"); 611 608 return status; 612 609 } 613 610 614 611 status = isl29018_set_integration_time(chip, 615 612 isl29018_int_utimes[chip->type][chip->int_time]); 616 613 if (status < 0) { 617 - dev_err(chip->dev, "Init of isl29018 fails\n"); 614 + dev_err(dev, "Init of isl29018 fails\n"); 618 615 return status; 619 616 } 620 617 ··· 731 728 chip = iio_priv(indio_dev); 732 729 733 730 i2c_set_clientdata(client, indio_dev); 734 - chip->dev = &client->dev; 735 731 736 732 if (id) { 737 733 name = id->name; ··· 753 751 chip_info_tbl[dev_id].regmap_cfg); 754 752 if (IS_ERR(chip->regmap)) { 755 753 err = PTR_ERR(chip->regmap); 756 - dev_err(chip->dev, "regmap initialization failed: %d\n", err); 754 + dev_err(&client->dev, "regmap initialization fails: %d\n", err); 757 755 return err; 758 756 } 759 757
-40
drivers/staging/iio/magnetometer/Kconfig
··· 1 - # 2 - # Magnetometer sensors 3 - # 4 - menu "Magnetometer sensors" 5 - 6 - config SENSORS_HMC5843 7 - tristate 8 - select IIO_BUFFER 9 - select IIO_TRIGGERED_BUFFER 10 - 11 - config SENSORS_HMC5843_I2C 12 - tristate "Honeywell HMC5843/5883/5883L 3-Axis Magnetometer (I2C)" 13 - depends on I2C 14 - select SENSORS_HMC5843 15 - select REGMAP_I2C 16 - help 17 - Say Y here to add support for the Honeywell HMC5843, HMC5883 and 18 - HMC5883L 3-Axis Magnetometer (digital compass). 19 - 20 - This driver can also be compiled as a set of modules. 21 - If so, these modules will be created: 22 - - hmc5843_core (core functions) 23 - - hmc5843_i2c (support for HMC5843, HMC5883, HMC5883L and HMC5983) 24 - 25 - config SENSORS_HMC5843_SPI 26 - tristate "Honeywell HMC5983 3-Axis Magnetometer (SPI)" 27 - depends on SPI_MASTER 28 - select SENSORS_HMC5843 29 - select REGMAP_SPI 30 - help 31 - Say Y here to add support for the Honeywell HMC5983 3-Axis Magnetometer 32 - (digital compass). 33 - 34 - This driver can also be compiled as a set of modules. 35 - If so, these modules will be created: 36 - - hmc5843_core (core functions) 37 - - hmc5843_spi (support for HMC5983) 38 - 39 - 40 - endmenu
-7
drivers/staging/iio/magnetometer/Makefile
··· 1 - # 2 - # Makefile for industrial I/O Magnetometer sensors 3 - # 4 - 5 - obj-$(CONFIG_SENSORS_HMC5843) += hmc5843_core.o 6 - obj-$(CONFIG_SENSORS_HMC5843_I2C) += hmc5843_i2c.o 7 - obj-$(CONFIG_SENSORS_HMC5843_SPI) += hmc5843_spi.o
drivers/staging/iio/magnetometer/hmc5843.h drivers/iio/magnetometer/hmc5843.h
+91 -51
drivers/staging/iio/magnetometer/hmc5843_core.c drivers/iio/magnetometer/hmc5843_core.c
··· 18 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 20 * GNU General Public License for more details. 21 - * 22 21 */ 23 22 24 23 #include <linux/module.h> ··· 65 66 #define HMC5843_MEAS_CONF_NEGATIVE_BIAS 0x02 66 67 #define HMC5843_MEAS_CONF_MASK 0x03 67 68 69 + /* 70 + * API for setting the measurement configuration to 71 + * Normal, Positive bias and Negative bias 72 + * 73 + * From the datasheet: 74 + * 0 - Normal measurement configuration (default): In normal measurement 75 + * configuration the device follows normal measurement flow. Pins BP 76 + * and BN are left floating and high impedance. 77 + * 78 + * 1 - Positive bias configuration: In positive bias configuration, a 79 + * positive current is forced across the resistive load on pins BP 80 + * and BN. 81 + * 82 + * 2 - Negative bias configuration. In negative bias configuration, a 83 + * negative current is forced across the resistive load on pins BP 84 + * and BN. 85 + * 86 + * 3 - Only available on HMC5983. Magnetic sensor is disabled. 87 + * Temperature sensor is enabled. 88 + */ 89 + 90 + static const char *const hmc5843_meas_conf_modes[] = {"normal", "positivebias", 91 + "negativebias"}; 92 + 93 + static const char *const hmc5983_meas_conf_modes[] = {"normal", "positivebias", 94 + "negativebias", 95 + "disabled"}; 68 96 /* Scaling factors: 10000000/Gain */ 69 97 static const int hmc5843_regval_to_nanoscale[] = { 70 98 6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714 ··· 200 174 return IIO_VAL_INT; 201 175 } 202 176 203 - /* 204 - * API for setting the measurement configuration to 205 - * Normal, Positive bias and Negative bias 206 - * 207 - * From the datasheet: 208 - * 0 - Normal measurement configuration (default): In normal measurement 209 - * configuration the device follows normal measurement flow. Pins BP 210 - * and BN are left floating and high impedance. 211 - * 212 - * 1 - Positive bias configuration: In positive bias configuration, a 213 - * positive current is forced across the resistive load on pins BP 214 - * and BN. 215 - * 216 - * 2 - Negative bias configuration. In negative bias configuration, a 217 - * negative current is forced across the resistive load on pins BP 218 - * and BN. 219 - * 220 - */ 221 177 static int hmc5843_set_meas_conf(struct hmc5843_data *data, u8 meas_conf) 222 178 { 223 179 int ret; ··· 213 205 } 214 206 215 207 static 216 - ssize_t hmc5843_show_measurement_configuration(struct device *dev, 217 - struct device_attribute *attr, 218 - char *buf) 208 + int hmc5843_show_measurement_configuration(struct iio_dev *indio_dev, 209 + const struct iio_chan_spec *chan) 219 210 { 220 - struct hmc5843_data *data = iio_priv(dev_to_iio_dev(dev)); 211 + struct hmc5843_data *data = iio_priv(indio_dev); 221 212 unsigned int val; 222 213 int ret; 223 214 224 215 ret = regmap_read(data->regmap, HMC5843_CONFIG_REG_A, &val); 225 216 if (ret) 226 217 return ret; 227 - val &= HMC5843_MEAS_CONF_MASK; 228 218 229 - return sprintf(buf, "%d\n", val); 219 + return val & HMC5843_MEAS_CONF_MASK; 230 220 } 231 221 232 222 static 233 - ssize_t hmc5843_set_measurement_configuration(struct device *dev, 234 - struct device_attribute *attr, 235 - const char *buf, 236 - size_t count) 223 + int hmc5843_set_measurement_configuration(struct iio_dev *indio_dev, 224 + const struct iio_chan_spec *chan, 225 + unsigned int meas_conf) 237 226 { 238 - struct hmc5843_data *data = iio_priv(dev_to_iio_dev(dev)); 239 - unsigned long meas_conf = 0; 240 - int ret; 227 + struct hmc5843_data *data = iio_priv(indio_dev); 241 228 242 - ret = kstrtoul(buf, 10, &meas_conf); 243 - if (ret) 244 - return ret; 245 - if (meas_conf >= HMC5843_MEAS_CONF_MASK) 246 - return -EINVAL; 247 - 248 - ret = hmc5843_set_meas_conf(data, meas_conf); 249 - 250 - return (ret < 0) ? ret : count; 229 + return hmc5843_set_meas_conf(data, meas_conf); 251 230 } 252 231 253 - static IIO_DEVICE_ATTR(meas_conf, 254 - S_IWUSR | S_IRUGO, 255 - hmc5843_show_measurement_configuration, 256 - hmc5843_set_measurement_configuration, 257 - 0); 232 + static const struct iio_enum hmc5843_meas_conf_enum = { 233 + .items = hmc5843_meas_conf_modes, 234 + .num_items = ARRAY_SIZE(hmc5843_meas_conf_modes), 235 + .get = hmc5843_show_measurement_configuration, 236 + .set = hmc5843_set_measurement_configuration, 237 + }; 238 + 239 + static const struct iio_chan_spec_ext_info hmc5843_ext_info[] = { 240 + IIO_ENUM("meas_conf", true, &hmc5843_meas_conf_enum), 241 + IIO_ENUM_AVAILABLE("meas_conf", &hmc5843_meas_conf_enum), 242 + { }, 243 + }; 244 + 245 + static const struct iio_enum hmc5983_meas_conf_enum = { 246 + .items = hmc5983_meas_conf_modes, 247 + .num_items = ARRAY_SIZE(hmc5983_meas_conf_modes), 248 + .get = hmc5843_show_measurement_configuration, 249 + .set = hmc5843_set_measurement_configuration, 250 + }; 251 + 252 + static const struct iio_chan_spec_ext_info hmc5983_ext_info[] = { 253 + IIO_ENUM("meas_conf", true, &hmc5983_meas_conf_enum), 254 + IIO_ENUM_AVAILABLE("meas_conf", &hmc5983_meas_conf_enum), 255 + { }, 256 + }; 258 257 259 258 static 260 259 ssize_t hmc5843_show_samp_freq_avail(struct device *dev, ··· 474 459 .storagebits = 16, \ 475 460 .endianness = IIO_BE, \ 476 461 }, \ 462 + .ext_info = hmc5843_ext_info, \ 463 + } 464 + 465 + #define HMC5983_CHANNEL(axis, idx) \ 466 + { \ 467 + .type = IIO_MAGN, \ 468 + .modified = 1, \ 469 + .channel2 = IIO_MOD_##axis, \ 470 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 471 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 472 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 473 + .scan_index = idx, \ 474 + .scan_type = { \ 475 + .sign = 's', \ 476 + .realbits = 16, \ 477 + .storagebits = 16, \ 478 + .endianness = IIO_BE, \ 479 + }, \ 480 + .ext_info = hmc5983_ext_info, \ 477 481 } 478 482 479 483 static const struct iio_chan_spec hmc5843_channels[] = { ··· 510 476 IIO_CHAN_SOFT_TIMESTAMP(3), 511 477 }; 512 478 479 + static const struct iio_chan_spec hmc5983_channels[] = { 480 + HMC5983_CHANNEL(X, 0), 481 + HMC5983_CHANNEL(Z, 1), 482 + HMC5983_CHANNEL(Y, 2), 483 + IIO_CHAN_SOFT_TIMESTAMP(3), 484 + }; 485 + 513 486 static struct attribute *hmc5843_attributes[] = { 514 - &iio_dev_attr_meas_conf.dev_attr.attr, 515 487 &iio_dev_attr_scale_available.dev_attr.attr, 516 488 &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 517 489 NULL ··· 556 516 ARRAY_SIZE(hmc5883l_regval_to_nanoscale), 557 517 }, 558 518 [HMC5983_ID] = { 559 - .channels = hmc5883_channels, 519 + .channels = hmc5983_channels, 560 520 .regval_to_samp_freq = hmc5983_regval_to_samp_freq, 561 521 .n_regval_to_samp_freq = 562 522 ARRAY_SIZE(hmc5983_regval_to_samp_freq), ··· 594 554 595 555 static const struct iio_info hmc5843_info = { 596 556 .attrs = &hmc5843_group, 597 - .read_raw = hmc5843_read_raw, 598 - .write_raw = hmc5843_write_raw, 599 - .write_raw_get_fmt = hmc5843_write_raw_get_fmt, 557 + .read_raw = &hmc5843_read_raw, 558 + .write_raw = &hmc5843_write_raw, 559 + .write_raw_get_fmt = &hmc5843_write_raw_get_fmt, 600 560 .driver_module = THIS_MODULE, 601 561 }; 602 562
drivers/staging/iio/magnetometer/hmc5843_i2c.c drivers/iio/magnetometer/hmc5843_i2c.c
drivers/staging/iio/magnetometer/hmc5843_spi.c drivers/iio/magnetometer/hmc5843_spi.c
-10
drivers/staging/iio/trigger/Kconfig
··· 5 5 6 6 if IIO_TRIGGER 7 7 8 - config IIO_PERIODIC_RTC_TRIGGER 9 - tristate "Periodic RTC triggers" 10 - depends on RTC_CLASS 11 - help 12 - Provides support for using periodic capable real time 13 - clocks as IIO triggers. 14 - 15 - To compile this driver as a module, choose M here: the 16 - module will be called iio-trig-periodic-rtc. 17 - 18 8 config IIO_BFIN_TMR_TRIGGER 19 9 tristate "Blackfin TIMER trigger" 20 10 depends on BLACKFIN
-1
drivers/staging/iio/trigger/Makefile
··· 2 2 # Makefile for triggers not associated with iio-devices 3 3 # 4 4 5 - obj-$(CONFIG_IIO_PERIODIC_RTC_TRIGGER) += iio-trig-periodic-rtc.o 6 5 obj-$(CONFIG_IIO_BFIN_TMR_TRIGGER) += iio-trig-bfin-timer.o
-216
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
··· 1 - /* The industrial I/O periodic RTC trigger driver 2 - * 3 - * Copyright (c) 2008 Jonathan Cameron 4 - * 5 - * This program is free software; you can redistribute it and/or modify it 6 - * under the terms of the GNU General Public License version 2 as published by 7 - * the Free Software Foundation. 8 - * 9 - * This is a heavily rewritten version of the periodic timer system in 10 - * earlier version of industrialio. It supplies the same functionality 11 - * but via a trigger rather than a specific periodic timer system. 12 - */ 13 - 14 - #include <linux/platform_device.h> 15 - #include <linux/kernel.h> 16 - #include <linux/module.h> 17 - #include <linux/slab.h> 18 - #include <linux/rtc.h> 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/trigger.h> 21 - 22 - static LIST_HEAD(iio_prtc_trigger_list); 23 - static DEFINE_MUTEX(iio_prtc_trigger_list_lock); 24 - 25 - struct iio_prtc_trigger_info { 26 - struct rtc_device *rtc; 27 - unsigned int frequency; 28 - struct rtc_task task; 29 - bool state; 30 - }; 31 - 32 - static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state) 33 - { 34 - struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); 35 - int ret; 36 - 37 - if (trig_info->frequency == 0 && state) 38 - return -EINVAL; 39 - dev_dbg(&trig_info->rtc->dev, "trigger frequency is %u\n", 40 - trig_info->frequency); 41 - ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, state); 42 - if (!ret) 43 - trig_info->state = state; 44 - 45 - return ret; 46 - } 47 - 48 - static ssize_t iio_trig_periodic_read_freq(struct device *dev, 49 - struct device_attribute *attr, 50 - char *buf) 51 - { 52 - struct iio_trigger *trig = to_iio_trigger(dev); 53 - struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); 54 - 55 - return sprintf(buf, "%u\n", trig_info->frequency); 56 - } 57 - 58 - static ssize_t iio_trig_periodic_write_freq(struct device *dev, 59 - struct device_attribute *attr, 60 - const char *buf, 61 - size_t len) 62 - { 63 - struct iio_trigger *trig = to_iio_trigger(dev); 64 - struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); 65 - unsigned int val; 66 - int ret; 67 - 68 - ret = kstrtouint(buf, 10, &val); 69 - if (ret) 70 - goto error_ret; 71 - 72 - if (val > 0) { 73 - ret = rtc_irq_set_freq(trig_info->rtc, &trig_info->task, val); 74 - if (ret == 0 && trig_info->state && trig_info->frequency == 0) 75 - ret = rtc_irq_set_state(trig_info->rtc, 76 - &trig_info->task, 1); 77 - } else { 78 - ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, 0); 79 - } 80 - if (ret) 81 - goto error_ret; 82 - 83 - trig_info->frequency = val; 84 - 85 - return len; 86 - 87 - error_ret: 88 - return ret; 89 - } 90 - 91 - static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR, 92 - iio_trig_periodic_read_freq, 93 - iio_trig_periodic_write_freq); 94 - 95 - static struct attribute *iio_trig_prtc_attrs[] = { 96 - &dev_attr_frequency.attr, 97 - NULL, 98 - }; 99 - 100 - static const struct attribute_group iio_trig_prtc_attr_group = { 101 - .attrs = iio_trig_prtc_attrs, 102 - }; 103 - 104 - static const struct attribute_group *iio_trig_prtc_attr_groups[] = { 105 - &iio_trig_prtc_attr_group, 106 - NULL 107 - }; 108 - 109 - static void iio_prtc_trigger_poll(void *private_data) 110 - { 111 - iio_trigger_poll(private_data); 112 - } 113 - 114 - static const struct iio_trigger_ops iio_prtc_trigger_ops = { 115 - .owner = THIS_MODULE, 116 - .set_trigger_state = &iio_trig_periodic_rtc_set_state, 117 - }; 118 - 119 - static int iio_trig_periodic_rtc_probe(struct platform_device *dev) 120 - { 121 - char **pdata = dev->dev.platform_data; 122 - struct iio_prtc_trigger_info *trig_info; 123 - struct iio_trigger *trig, *trig2; 124 - 125 - int i, ret; 126 - 127 - for (i = 0;; i++) { 128 - if (!pdata[i]) 129 - break; 130 - trig = iio_trigger_alloc("periodic%s", pdata[i]); 131 - if (!trig) { 132 - ret = -ENOMEM; 133 - goto error_free_completed_registrations; 134 - } 135 - list_add(&trig->alloc_list, &iio_prtc_trigger_list); 136 - 137 - trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); 138 - if (!trig_info) { 139 - ret = -ENOMEM; 140 - goto error_put_trigger_and_remove_from_list; 141 - } 142 - iio_trigger_set_drvdata(trig, trig_info); 143 - trig->ops = &iio_prtc_trigger_ops; 144 - /* RTC access */ 145 - trig_info->rtc = rtc_class_open(pdata[i]); 146 - if (!trig_info->rtc) { 147 - ret = -EINVAL; 148 - goto error_free_trig_info; 149 - } 150 - trig_info->task.func = iio_prtc_trigger_poll; 151 - trig_info->task.private_data = trig; 152 - ret = rtc_irq_register(trig_info->rtc, &trig_info->task); 153 - if (ret) 154 - goto error_close_rtc; 155 - trig->dev.groups = iio_trig_prtc_attr_groups; 156 - ret = iio_trigger_register(trig); 157 - if (ret) 158 - goto error_unregister_rtc_irq; 159 - } 160 - return 0; 161 - error_unregister_rtc_irq: 162 - rtc_irq_unregister(trig_info->rtc, &trig_info->task); 163 - error_close_rtc: 164 - rtc_class_close(trig_info->rtc); 165 - error_free_trig_info: 166 - kfree(trig_info); 167 - error_put_trigger_and_remove_from_list: 168 - list_del(&trig->alloc_list); 169 - iio_trigger_put(trig); 170 - error_free_completed_registrations: 171 - list_for_each_entry_safe(trig, 172 - trig2, 173 - &iio_prtc_trigger_list, 174 - alloc_list) { 175 - trig_info = iio_trigger_get_drvdata(trig); 176 - rtc_irq_unregister(trig_info->rtc, &trig_info->task); 177 - rtc_class_close(trig_info->rtc); 178 - kfree(trig_info); 179 - iio_trigger_unregister(trig); 180 - } 181 - return ret; 182 - } 183 - 184 - static int iio_trig_periodic_rtc_remove(struct platform_device *dev) 185 - { 186 - struct iio_trigger *trig, *trig2; 187 - struct iio_prtc_trigger_info *trig_info; 188 - 189 - mutex_lock(&iio_prtc_trigger_list_lock); 190 - list_for_each_entry_safe(trig, 191 - trig2, 192 - &iio_prtc_trigger_list, 193 - alloc_list) { 194 - trig_info = iio_trigger_get_drvdata(trig); 195 - rtc_irq_unregister(trig_info->rtc, &trig_info->task); 196 - rtc_class_close(trig_info->rtc); 197 - kfree(trig_info); 198 - iio_trigger_unregister(trig); 199 - } 200 - mutex_unlock(&iio_prtc_trigger_list_lock); 201 - return 0; 202 - } 203 - 204 - static struct platform_driver iio_trig_periodic_rtc_driver = { 205 - .probe = iio_trig_periodic_rtc_probe, 206 - .remove = iio_trig_periodic_rtc_remove, 207 - .driver = { 208 - .name = "iio_prtc_trigger", 209 - }, 210 - }; 211 - 212 - module_platform_driver(iio_trig_periodic_rtc_driver); 213 - 214 - MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 215 - MODULE_DESCRIPTION("Periodic realtime clock trigger for the iio subsystem"); 216 - MODULE_LICENSE("GPL v2");
+3 -3
include/linux/iio/iio.h
··· 180 180 * @address: Driver specific identifier. 181 181 * @scan_index: Monotonic index to give ordering in scans when read 182 182 * from a buffer. 183 - * @scan_type: Sign: 's' or 'u' to specify signed or unsigned 183 + * @scan_type: sign: 's' or 'u' to specify signed or unsigned 184 184 * realbits: Number of valid bits of data 185 - * storage_bits: Realbits + padding 185 + * storagebits: Realbits + padding 186 186 * shift: Shift right by this before masking out 187 187 * realbits. 188 - * endianness: little or big endian 189 188 * repeat: Number of times real/storage bits 190 189 * repeats. When the repeat element is 191 190 * more than 1, then the type element in 192 191 * sysfs will show a repeat value. 193 192 * Otherwise, the number of repetitions is 194 193 * omitted. 194 + * endianness: little or big endian 195 195 * @info_mask_separate: What information is to be exported that is specific to 196 196 * this channel. 197 197 * @info_mask_shared_by_type: What information is to be exported that is shared