Commit be61a0d7 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge tag 'iio-for-3.19a' of...

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

Jonathan writes:

First round of new drivers, features and cleanups for IIO in the 3.19 cycle.

New drivers / supported parts
* rockchip - rk3066-tsadc variant
* si7020 humidity and temperature sensor
* mcp320x - add mcp3001, mcp3002, mcp3004, mcp3008, mcp3201, mcp3202
* bmp280 pressure and temperature sensor
* Qualcomm SPMI PMIC current ADC driver
* Exynos_adc - support exynos7

New features
* vf610-adc - add temperature sensor support
* Documentation of current attributes, scaled pressure, offset and
  scaled humidity, RGBC intensity gain factor and scale applied to
  differential voltage channels.
* Bring iio_event_monitor up to date with newer modifiers.
* Add of_xlate function to allow for complex channel mappings from the
  device tree.
* Add -g parameter to generic_buffer example to allow for devices with
  directly fed (no trigger) buffers.
* Move exynos driver over to syscon for PMU register access.

Cleanups, fixes for new drivers
* lis3l02dq drop an unneeded else.
* st sensors - renam st_sensors to st_sensor_settings (for clarity)
* st sensors - drop an unused parameter from all the probe utility
  functions.
* vf610 better error handling and tidy up.
* si7020 - cleanups following merge
* as3935 - drop some unnecessary semicolons.
* bmp280 - fix the pressure calculation.
parents 7be921a2 4e4cd14e
...@@ -200,6 +200,13 @@ Description: ...@@ -200,6 +200,13 @@ Description:
Raw pressure measurement from channel Y. Units after Raw pressure measurement from channel Y. Units after
application of scale and offset are kilopascal. application of scale and offset are kilopascal.
What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_input
What: /sys/bus/iio/devices/iio:deviceX/in_pressure_input
KernelVersion: 3.8
Contact: linux-iio@vger.kernel.org
Description:
Scaled pressure measurement from channel Y, in kilopascal.
What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_raw What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_raw
KernelVersion: 3.14 KernelVersion: 3.14
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
...@@ -231,6 +238,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_tempY_offset ...@@ -231,6 +238,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_tempY_offset
What: /sys/bus/iio/devices/iio:deviceX/in_temp_offset What: /sys/bus/iio/devices/iio:deviceX/in_temp_offset
What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_offset What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_offset
What: /sys/bus/iio/devices/iio:deviceX/in_pressure_offset What: /sys/bus/iio/devices/iio:deviceX/in_pressure_offset
What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_offset
KernelVersion: 2.6.35 KernelVersion: 2.6.35
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
...@@ -251,6 +259,7 @@ Description: ...@@ -251,6 +259,7 @@ Description:
What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_scale What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_scale
What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_supply_scale What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_supply_scale
What: /sys/bus/iio/devices/iio:deviceX/in_voltage_scale What: /sys/bus/iio/devices/iio:deviceX/in_voltage_scale
What: /sys/bus/iio/devices/iio:deviceX/in_voltage-voltage_scale
What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_scale What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_scale
What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_scale What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_scale
What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale
...@@ -266,6 +275,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_magnetic_tilt_comp_sca ...@@ -266,6 +275,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_magnetic_tilt_comp_sca
What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_true_tilt_comp_scale What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_true_tilt_comp_scale
What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_scale What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_scale
What: /sys/bus/iio/devices/iio:deviceX/in_pressure_scale What: /sys/bus/iio/devices/iio:deviceX/in_pressure_scale
What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_scale
KernelVersion: 2.6.35 KernelVersion: 2.6.35
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
...@@ -328,6 +338,10 @@ Description: ...@@ -328,6 +338,10 @@ Description:
are listed in this attribute. are listed in this attribute.
What /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain What /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain
What: /sys/bus/iio/devices/iio:deviceX/in_intensity_red_hardwaregain
What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_hardwaregain
What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_hardwaregain
What: /sys/bus/iio/devices/iio:deviceX/in_intensity_clear_hardwaregain
KernelVersion: 2.6.35 KernelVersion: 2.6.35
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
...@@ -1028,3 +1042,12 @@ Contact: linux-iio@vger.kernel.org ...@@ -1028,3 +1042,12 @@ Contact: linux-iio@vger.kernel.org
Description: Description:
Raw value of rotation from true/magnetic north measured with Raw value of rotation from true/magnetic north measured with
or without compensation from tilt sensors. or without compensation from tilt sensors.
What: /sys/bus/iio/devices/iio:deviceX/in_currentX_raw
KernelVersion: 3.18
Contact: linux-iio@vger.kernel.org
Description:
Raw current measurement from channel X. Units are in milliamps
after application of scale and offset. If no offset or scale is
present, output should be considered as processed with the
unit in milliamps.
...@@ -16,6 +16,8 @@ Required properties: ...@@ -16,6 +16,8 @@ Required properties:
future controllers. future controllers.
Must be "samsung,exynos3250-adc" for Must be "samsung,exynos3250-adc" for
controllers compatible with ADC of Exynos3250. controllers compatible with ADC of Exynos3250.
Must be "samsung,exynos7-adc" for
the ADC in Exynos7 and compatibles
Must be "samsung,s3c2410-adc" for Must be "samsung,s3c2410-adc" for
the ADC in s3c2410 and compatibles the ADC in s3c2410 and compatibles
Must be "samsung,s3c2416-adc" for Must be "samsung,s3c2416-adc" for
...@@ -43,13 +45,16 @@ Required properties: ...@@ -43,13 +45,16 @@ Required properties:
compatible ADC block) compatible ADC block)
- vdd-supply VDD input supply. - vdd-supply VDD input supply.
- samsung,syscon-phandle Contains the PMU system controller node
(To access the ADC_PHY register on Exynos5250/5420/5800/3250)
Note: child nodes can be added for auto probing from device tree. Note: child nodes can be added for auto probing from device tree.
Example: adding device info in dtsi file Example: adding device info in dtsi file
adc: adc@12D10000 { adc: adc@12D10000 {
compatible = "samsung,exynos-adc-v1"; compatible = "samsung,exynos-adc-v1";
reg = <0x12D10000 0x100>, <0x10040718 0x4>; reg = <0x12D10000 0x100>;
interrupts = <0 106 0>; interrupts = <0 106 0>;
#io-channel-cells = <1>; #io-channel-cells = <1>;
io-channel-ranges; io-channel-ranges;
...@@ -58,13 +63,14 @@ adc: adc@12D10000 { ...@@ -58,13 +63,14 @@ adc: adc@12D10000 {
clock-names = "adc"; clock-names = "adc";
vdd-supply = <&buck5_reg>; vdd-supply = <&buck5_reg>;
samsung,syscon-phandle = <&pmu_system_controller>;
}; };
Example: adding device info in dtsi file for Exynos3250 with additional sclk Example: adding device info in dtsi file for Exynos3250 with additional sclk
adc: adc@126C0000 { adc: adc@126C0000 {
compatible = "samsung,exynos3250-adc", "samsung,exynos-adc-v2; compatible = "samsung,exynos3250-adc", "samsung,exynos-adc-v2;
reg = <0x126C0000 0x100>, <0x10020718 0x4>; reg = <0x126C0000 0x100>;
interrupts = <0 137 0>; interrupts = <0 137 0>;
#io-channel-cells = <1>; #io-channel-cells = <1>;
io-channel-ranges; io-channel-ranges;
...@@ -73,6 +79,7 @@ adc: adc@126C0000 { ...@@ -73,6 +79,7 @@ adc: adc@126C0000 {
clock-names = "adc", "sclk"; clock-names = "adc", "sclk";
vdd-supply = <&buck5_reg>; vdd-supply = <&buck5_reg>;
samsung,syscon-phandle = <&pmu_system_controller>;
}; };
Example: Adding child nodes in dts file Example: Adding child nodes in dts file
......
Qualcomm's SPMI PMIC current ADC
QPNP PMIC current ADC (IADC) provides interface to clients to read current.
A 16 bit ADC is used for current measurements. IADC can measure the current
through an external resistor (channel 1) or internal (built-in) resistor
(channel 0). When using an external resistor it is to be described by
qcom,external-resistor-micro-ohms property.
IADC node:
- compatible:
Usage: required
Value type: <string>
Definition: Should contain "qcom,spmi-iadc".
- reg:
Usage: required
Value type: <prop-encoded-array>
Definition: IADC base address and length in the SPMI PMIC register map
- interrupts:
Usage: optional
Value type: <prop-encoded-array>
Definition: End of ADC conversion.
- qcom,external-resistor-micro-ohms:
Usage: optional
Value type: <u32>
Definition: Sense resister value in micro Ohm.
If not defined value of 10000 micro Ohms will be used.
Example:
/* IADC node */
pmic_iadc: iadc@3600 {
compatible = "qcom,spmi-iadc";
reg = <0x3600 0x100>;
interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
qcom,external-resistor-micro-ohms = <10000>;
#io-channel-cells = <1>;
};
/* IIO client node */
bat {
io-channels = <&pmic_iadc 0>;
io-channel-names = "iadc";
};
Rockchip Successive Approximation Register (SAR) A/D Converter bindings Rockchip Successive Approximation Register (SAR) A/D Converter bindings
Required properties: Required properties:
- compatible: Should be "rockchip,saradc" - compatible: Should be "rockchip,saradc" or "rockchip,rk3066-tsadc"
- reg: physical base address of the controller and length of memory mapped - reg: physical base address of the controller and length of memory mapped
region. region.
- interrupts: The interrupt number to the cpu. The interrupt specifier format - interrupts: The interrupt number to the cpu. The interrupt specifier format
......
...@@ -311,12 +311,13 @@ pdma1: pdma@12690000 { ...@@ -311,12 +311,13 @@ pdma1: pdma@12690000 {
adc: adc@126C0000 { adc: adc@126C0000 {
compatible = "samsung,exynos3250-adc", compatible = "samsung,exynos3250-adc",
"samsung,exynos-adc-v2"; "samsung,exynos-adc-v2";
reg = <0x126C0000 0x100>, <0x10020718 0x4>; reg = <0x126C0000 0x100>;
interrupts = <0 137 0>; interrupts = <0 137 0>;
clock-names = "adc", "sclk"; clock-names = "adc", "sclk";
clocks = <&cmu CLK_TSADC>, <&cmu CLK_SCLK_TSADC>; clocks = <&cmu CLK_TSADC>, <&cmu CLK_SCLK_TSADC>;
#io-channel-cells = <1>; #io-channel-cells = <1>;
io-channel-ranges; io-channel-ranges;
samsung,syscon-phandle = <&pmu_system_controller>;
status = "disabled"; status = "disabled";
}; };
......
...@@ -108,13 +108,14 @@ wakup_eint: wakeup-interrupt-controller { ...@@ -108,13 +108,14 @@ wakup_eint: wakeup-interrupt-controller {
adc: adc@126C0000 { adc: adc@126C0000 {
compatible = "samsung,exynos-adc-v1"; compatible = "samsung,exynos-adc-v1";
reg = <0x126C0000 0x100>, <0x10020718 0x4>; reg = <0x126C0000 0x100>;
interrupt-parent = <&combiner>; interrupt-parent = <&combiner>;
interrupts = <10 3>; interrupts = <10 3>;
clocks = <&clock CLK_TSADC>; clocks = <&clock CLK_TSADC>;
clock-names = "adc"; clock-names = "adc";
#io-channel-cells = <1>; #io-channel-cells = <1>;
io-channel-ranges; io-channel-ranges;
samsung,syscon-phandle = <&pmu_system_controller>;
status = "disabled"; status = "disabled";
}; };
......
...@@ -750,12 +750,13 @@ fimd@14400000 { ...@@ -750,12 +750,13 @@ fimd@14400000 {
adc: adc@12D10000 { adc: adc@12D10000 {
compatible = "samsung,exynos-adc-v1"; compatible = "samsung,exynos-adc-v1";
reg = <0x12D10000 0x100>, <0x10040718 0x4>; reg = <0x12D10000 0x100>;
interrupts = <0 106 0>; interrupts = <0 106 0>;
clocks = <&clock CLK_ADC>; clocks = <&clock CLK_ADC>;
clock-names = "adc"; clock-names = "adc";
#io-channel-cells = <1>; #io-channel-cells = <1>;
io-channel-ranges; io-channel-ranges;
samsung,syscon-phandle = <&pmu_system_controller>;
status = "disabled"; status = "disabled";
}; };
......
...@@ -541,12 +541,13 @@ fimd: fimd@14400000 { ...@@ -541,12 +541,13 @@ fimd: fimd@14400000 {
adc: adc@12D10000 { adc: adc@12D10000 {
compatible = "samsung,exynos-adc-v2"; compatible = "samsung,exynos-adc-v2";
reg = <0x12D10000 0x100>, <0x10040720 0x4>; reg = <0x12D10000 0x100>;
interrupts = <0 106 0>; interrupts = <0 106 0>;
clocks = <&clock CLK_TSADC>; clocks = <&clock CLK_TSADC>;
clock-names = "adc"; clock-names = "adc";
#io-channel-cells = <1>; #io-channel-cells = <1>;
io-channel-ranges; io-channel-ranges;
samsung,syscon-phandle = <&pmu_system_controller>;
status = "disabled"; status = "disabled";
}; };
......
...@@ -33,8 +33,7 @@ static const struct st_sensors_platform_data default_accel_pdata = { ...@@ -33,8 +33,7 @@ static const struct st_sensors_platform_data default_accel_pdata = {
.drdy_int_pin = 1, .drdy_int_pin = 1,
}; };
int st_accel_common_probe(struct iio_dev *indio_dev, int st_accel_common_probe(struct iio_dev *indio_dev);
struct st_sensors_platform_data *pdata);
void st_accel_common_remove(struct iio_dev *indio_dev); void st_accel_common_remove(struct iio_dev *indio_dev);
#ifdef CONFIG_IIO_BUFFER #ifdef CONFIG_IIO_BUFFER
......
...@@ -161,7 +161,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = { ...@@ -161,7 +161,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(3) IIO_CHAN_SOFT_TIMESTAMP(3)
}; };
static const struct st_sensors st_accel_sensors[] = { static const struct st_sensor_settings st_accel_sensors_settings[] = {
{ {
.wai = ST_ACCEL_1_WAI_EXP, .wai = ST_ACCEL_1_WAI_EXP,
.sensors_supported = { .sensors_supported = {
...@@ -457,8 +457,7 @@ static const struct iio_trigger_ops st_accel_trigger_ops = { ...@@ -457,8 +457,7 @@ static const struct iio_trigger_ops st_accel_trigger_ops = {
#define ST_ACCEL_TRIGGER_OPS NULL #define ST_ACCEL_TRIGGER_OPS NULL
#endif #endif
int st_accel_common_probe(struct iio_dev *indio_dev, int st_accel_common_probe(struct iio_dev *indio_dev)
struct st_sensors_platform_data *plat_data)
{ {
struct st_sensor_data *adata = iio_priv(indio_dev); struct st_sensor_data *adata = iio_priv(indio_dev);
int irq = adata->get_irq_data_ready(indio_dev); int irq = adata->get_irq_data_ready(indio_dev);
...@@ -470,24 +469,25 @@ int st_accel_common_probe(struct iio_dev *indio_dev, ...@@ -470,24 +469,25 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
st_sensors_power_enable(indio_dev); st_sensors_power_enable(indio_dev);
err = st_sensors_check_device_support(indio_dev, err = st_sensors_check_device_support(indio_dev,
ARRAY_SIZE(st_accel_sensors), st_accel_sensors); ARRAY_SIZE(st_accel_sensors_settings),
st_accel_sensors_settings);
if (err < 0) if (err < 0)
return err; return err;
adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
adata->multiread_bit = adata->sensor->multi_read_bit; adata->multiread_bit = adata->sensor_settings->multi_read_bit;
indio_dev->channels = adata->sensor->ch; indio_dev->channels = adata->sensor_settings->ch;
indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
adata->current_fullscale = (struct st_sensor_fullscale_avl *) adata->current_fullscale = (struct st_sensor_fullscale_avl *)
&adata->sensor->fs.fs_avl[0]; &adata->sensor_settings->fs.fs_avl[0];
adata->odr = adata->sensor->odr.odr_avl[0].hz; adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
if (!plat_data) if (!adata->dev->platform_data)
plat_data = adata->dev->platform_data =
(struct st_sensors_platform_data *)&default_accel_pdata; (struct st_sensors_platform_data *)&default_accel_pdata;
err = st_sensors_init_sensor(indio_dev, plat_data); err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -79,12 +79,11 @@ static int st_accel_i2c_probe(struct i2c_client *client, ...@@ -79,12 +79,11 @@ static int st_accel_i2c_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
adata = iio_priv(indio_dev); adata = iio_priv(indio_dev);
adata->dev = &client->dev;
st_sensors_of_i2c_probe(client, st_accel_of_match); st_sensors_of_i2c_probe(client, st_accel_of_match);
st_sensors_i2c_configure(indio_dev, client, adata); st_sensors_i2c_configure(indio_dev, client, adata);
err = st_accel_common_probe(indio_dev, client->dev.platform_data); err = st_accel_common_probe(indio_dev);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -29,11 +29,10 @@ static int st_accel_spi_probe(struct spi_device *spi) ...@@ -29,11 +29,10 @@ static int st_accel_spi_probe(struct spi_device *spi)
return -ENOMEM; return -ENOMEM;
adata = iio_priv(indio_dev); adata = iio_priv(indio_dev);
adata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, adata); st_sensors_spi_configure(indio_dev, spi, adata);
err = st_accel_common_probe(indio_dev, spi->dev.platform_data); err = st_accel_common_probe(indio_dev);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -206,6 +206,20 @@ config NAU7802 ...@@ -206,6 +206,20 @@ config NAU7802
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called nau7802. module will be called nau7802.
config QCOM_SPMI_IADC
tristate "Qualcomm SPMI PMIC current ADC"
depends on SPMI
select REGMAP_SPMI
help
This is the IIO Current ADC driver for Qualcomm QPNP IADC Chip.
The driver supports single mode operation to read from one of two
channels (external or internal). Hardware have additional
channels internally used for gain and offset calibration.
To compile this driver as a module, choose M here: the module will
be called qcom-spmi-iadc.
config ROCKCHIP_SARADC config ROCKCHIP_SARADC
tristate "Rockchip SARADC driver" tristate "Rockchip SARADC driver"
depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST) depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST)
......
...@@ -22,6 +22,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o ...@@ -22,6 +22,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
obj-$(CONFIG_MCP3422) += mcp3422.o obj-$(CONFIG_MCP3422) += mcp3422.o
obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
obj-$(CONFIG_NAU7802) += nau7802.o obj-$(CONFIG_NAU7802) += nau7802.o
obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/machine.h> #include <linux/iio/machine.h>
#include <linux/iio/driver.h> #include <linux/iio/driver.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
/* S3C/EXYNOS4412/5250 ADC_V1 registers definitions */ /* S3C/EXYNOS4412/5250 ADC_V1 registers definitions */
#define ADC_V1_CON(x) ((x) + 0x00) #define ADC_V1_CON(x) ((x) + 0x00)
...@@ -90,11 +92,14 @@ ...@@ -90,11 +92,14 @@
#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100)) #define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
#define EXYNOS_ADCV1_PHY_OFFSET 0x0718
#define EXYNOS_ADCV2_PHY_OFFSET 0x0720
struct exynos_adc { struct exynos_adc {
struct exynos_adc_data *data; struct exynos_adc_data *data;
struct device *dev; struct device *dev;
void __iomem *regs; void __iomem *regs;
void __iomem *enable_reg; struct regmap *pmu_map;
struct clk *clk; struct clk *clk;
struct clk *sclk; struct clk *sclk;
unsigned int irq; unsigned int irq;
...@@ -110,6 +115,7 @@ struct exynos_adc_data { ...@@ -110,6 +115,7 @@ struct exynos_adc_data {
int num_channels; int num_channels;
bool needs_sclk; bool needs_sclk;
bool needs_adc_phy; bool needs_adc_phy;
int phy_offset;
u32 mask; u32 mask;
void (*init_hw)(struct exynos_adc *info); void (*init_hw)(struct exynos_adc *info);
...@@ -183,7 +189,7 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info) ...@@ -183,7 +189,7 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info)
u32 con1; u32 con1;
if (info->data->needs_adc_phy) if (info->data->needs_adc_phy)
writel(1, info->enable_reg); regmap_write(info->pmu_map, info->data->phy_offset, 1);
/* set default prescaler values and Enable prescaler */ /* set default prescaler values and Enable prescaler */
con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN; con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
...@@ -198,7 +204,7 @@ static void exynos_adc_v1_exit_hw(struct exynos_adc *info) ...@@ -198,7 +204,7 @@ static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
u32 con; u32 con;
if (info->data->needs_adc_phy) if (info->data->needs_adc_phy)
writel(0, info->enable_reg); regmap_write(info->pmu_map, info->data->phy_offset, 0);
con = readl(ADC_V1_CON(info->regs)); con = readl(ADC_V1_CON(info->regs));
con |= ADC_V1_CON_STANDBY; con |= ADC_V1_CON_STANDBY;
...@@ -225,6 +231,7 @@ static const struct exynos_adc_data exynos_adc_v1_data = { ...@@ -225,6 +231,7 @@ static const struct exynos_adc_data exynos_adc_v1_data = {
.num_channels = MAX_ADC_V1_CHANNELS, .num_channels = MAX_ADC_V1_CHANNELS,
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
.needs_adc_phy = true, .needs_adc_phy = true,
.phy_offset = EXYNOS_ADCV1_PHY_OFFSET,
.init_hw = exynos_adc_v1_init_hw, .init_hw = exynos_adc_v1_init_hw,
.exit_hw = exynos_adc_v1_exit_hw, .exit_hw = exynos_adc_v1_exit_hw,
...@@ -314,7 +321,7 @@ static void exynos_adc_v2_init_hw(struct exynos_adc *info) ...@@ -314,7 +321,7 @@ static void exynos_adc_v2_init_hw(struct exynos_adc *info)
u32 con1, con2; u32 con1, con2;
if (info->data->needs_adc_phy) if (info->data->needs_adc_phy)
writel(1, info->enable_reg); regmap_write(info->pmu_map, info->data->phy_offset, 1);
con1 = ADC_V2_CON1_SOFT_RESET; con1 = ADC_V2_CON1_SOFT_RESET;
writel(con1, ADC_V2_CON1(info->regs)); writel(con1, ADC_V2_CON1(info->regs));
...@@ -332,7 +339,7 @@ static void exynos_adc_v2_exit_hw(struct exynos_adc *info) ...@@ -332,7 +339,7 @@ static void exynos_adc_v2_exit_hw(struct exynos_adc *info)
u32 con; u32 con;
if (info->data->needs_adc_phy) if (info->data->needs_adc_phy)
writel(0, info->enable_reg); regmap_write(info->pmu_map, info->data->phy_offset, 0);
con = readl(ADC_V2_CON1(info->regs)); con = readl(ADC_V2_CON1(info->regs));
con &= ~ADC_CON_EN_START; con &= ~ADC_CON_EN_START;
...@@ -362,6 +369,7 @@ static const struct exynos_adc_data exynos_adc_v2_data = { ...@@ -362,6 +369,7 @@ static const struct exynos_adc_data exynos_adc_v2_data = {
.num_channels = MAX_ADC_V2_CHANNELS, .num_channels = MAX_ADC_V2_CHANNELS,
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
.needs_adc_phy = true, .needs_adc_phy = true,
.phy_offset = EXYNOS_ADCV2_PHY_OFFSET,
.init_hw = exynos_adc_v2_init_hw, .init_hw = exynos_adc_v2_init_hw,
.exit_hw = exynos_adc_v2_exit_hw, .exit_hw = exynos_adc_v2_exit_hw,
...@@ -374,6 +382,7 @@ static const struct exynos_adc_data exynos3250_adc_data = { ...@@ -374,6 +382,7 @@ static const struct exynos_adc_data exynos3250_adc_data = {
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
.needs_sclk = true, .needs_sclk = true,
.needs_adc_phy = true, .needs_adc_phy = true,
.phy_offset = EXYNOS_ADCV1_PHY_OFFSET,
.init_hw = exynos_adc_v2_init_hw, .init_hw = exynos_adc_v2_init_hw,
.exit_hw = exynos_adc_v2_exit_hw, .exit_hw = exynos_adc_v2_exit_hw,
...@@ -381,6 +390,35 @@ static const struct exynos_adc_data exynos3250_adc_data = { ...@@ -381,6 +390,35 @@ static const struct exynos_adc_data exynos3250_adc_data = {
.start_conv = exynos_adc_v2_start_conv, .start_conv = exynos_adc_v2_start_conv,
}; };
static void exynos_adc_exynos7_init_hw(struct exynos_adc *info)
{
u32 con1, con2;
if (info->data->needs_adc_phy)
regmap_write(info->pmu_map, info->data->phy_offset, 1);
con1 = ADC_V2_CON1_SOFT_RESET;
writel(con1, ADC_V2_CON1(info->regs));
con2 = readl(ADC_V2_CON2(info->regs));
con2 &= ~ADC_V2_CON2_C_TIME(7);
con2 |= ADC_V2_CON2_C_TIME(0);
writel(con2, ADC_V2_CON2(info->regs));
/* Enable interrupts */
writel(1, ADC_V2_INT_EN(info->regs));
}
static const struct exynos_adc_data exynos7_adc_data = {
.num_channels = MAX_ADC_V1_CHANNELS,
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
.init_hw = exynos_adc_exynos7_init_hw,
.exit_hw = exynos_adc_v2_exit_hw,
.clear_irq = exynos_adc_v2_clear_irq,
.start_conv = exynos_adc_v2_start_conv,
};
static const struct of_device_id exynos_adc_match[] = { static const struct of_device_id exynos_adc_match[] = {
{ {
.compatible = "samsung,s3c2410-adc", .compatible = "samsung,s3c2410-adc",
...@@ -406,6 +444,9 @@ static const struct of_device_id exynos_adc_match[] = { ...@@ -406,6 +444,9 @@ static const struct of_device_id exynos_adc_match[] = {
}, { }, {
.compatible = "samsung,exynos3250-adc", .compatible = "samsung,exynos3250-adc",
.data = &exynos3250_adc_data, .data = &exynos3250_adc_data,
}, {
.compatible = "samsung,exynos7-adc",
.data = &exynos7_adc_data,
}, },
{}, {},
}; };
...@@ -558,10 +599,13 @@ static int exynos_adc_probe(struct platform_device *pdev) ...@@ -558,10 +599,13 @@ static int exynos_adc_probe(struct platform_device *pdev)
if (info->data->needs_adc_phy) { if (info->data->needs_adc_phy) {
mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); info->pmu_map = syscon_regmap_lookup_by_phandle(
info->enable_reg = devm_ioremap_resource(&pdev->dev, mem); pdev->dev.of_node,
if (IS_ERR(info->enable_reg)) "samsung,syscon-phandle");
return PTR_ERR(info->enable_reg); if (IS_ERR(info->pmu_map)) {
dev_err(&pdev->dev, "syscon regmap lookup failed.\n");
return PTR_ERR(info->pmu_map);
}
} }
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
......
/* /*
* Copyright (C) 2013 Oskar Andero <oskar.andero@gmail.com> * Copyright (C) 2013 Oskar Andero <oskar.andero@gmail.com>
* Copyright (C) 2014 Rose Technology
* Allan Bendorff Jensen <abj@rosetechnology.dk>
* Soren Andersen <san@rosetechnology.dk>
*
* Driver for following ADC chips from Microchip Technology's:
* 10 Bit converter
* MCP3001
* MCP3002
* MCP3004
* MCP3008
* ------------
* 12 bit converter
* MCP3201
* MCP3202
* MCP3204
* MCP3208
* ------------
* *
* Driver for Microchip Technology's MCP3204 and MCP3208 ADC chips.
* Datasheet can be found here: * Datasheet can be found here:
* http://ww1.microchip.com/downloads/en/devicedoc/21298c.pdf * http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
* http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002
* http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08
* http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
* http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
* http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -11,19 +32,29 @@ ...@@ -11,19 +32,29 @@
*/ */
#include <linux/err.h> #include <linux/err.h>
#include <linux/delay.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#define MCP_SINGLE_ENDED (1 << 3)
#define MCP_START_BIT (1 << 4)
enum { enum {
mcp3001,
mcp3002,
mcp3004,
mcp3008,
mcp3201,
mcp3202,
mcp3204, mcp3204,
mcp3208, mcp3208,
}; };
struct mcp320x_chip_info {
const struct iio_chan_spec *channels;
unsigned int num_channels;
unsigned int resolution;
};
struct mcp320x { struct mcp320x {
struct spi_device *spi; struct spi_device *spi;
struct spi_message msg; struct spi_message msg;
...@@ -34,19 +65,69 @@ struct mcp320x { ...@@ -34,19 +65,69 @@ struct mcp320x {
struct regulator *reg; struct regulator *reg;
struct mutex lock; struct mutex lock;
const struct mcp320x_chip_info *chip_info;
}; };
static int mcp320x_adc_conversion(struct mcp320x *adc, u8 msg) static int mcp320x_channel_to_tx_data(int device_index,
const unsigned int channel, bool differential)
{
int start_bit = 1;
switch (device_index) {
case mcp3001:
case mcp3201:
return 0;
case mcp3002:
case mcp3202:
return ((start_bit << 4) | (!differential << 3) |
(channel << 2));
case mcp3004:
case mcp3204:
case mcp3008:
case mcp3208:
return ((start_bit << 6) | (!differential << 5) |
(channel << 2));
default:
return -EINVAL;
}
}
static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
bool differential, int device_index)
{ {
int ret; int ret;
adc->tx_buf = msg; adc->rx_buf[0] = 0;
ret = spi_sync(adc->spi, &adc->msg); adc->rx_buf[1] = 0;
if (ret < 0) adc->tx_buf = mcp320x_channel_to_tx_data(device_index,
return ret; channel, differential);
if (device_index != mcp3001 && device_index != mcp3201) {
ret = spi_sync(adc->spi, &adc->msg);
if (ret < 0)
return ret;
} else {
ret = spi_read(adc->spi, &adc->rx_buf, sizeof(adc->rx_buf));
if (ret < 0)
return ret;
}
return ((adc->rx_buf[0] & 0x3f) << 6) | switch (device_index) {
(adc->rx_buf[1] >> 2); case mcp3001:
return (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3);
case mcp3002:
case mcp3004:
case mcp3008:
return (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6);
case mcp3201:
return (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1);
case mcp3202:
case mcp3204:
case mcp3208:
return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
default:
return -EINVAL;
}
} }
static int mcp320x_read_raw(struct iio_dev *indio_dev, static int mcp320x_read_raw(struct iio_dev *indio_dev,
...@@ -55,18 +136,17 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev, ...@@ -55,18 +136,17 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
{ {
struct mcp320x *adc = iio_priv(indio_dev); struct mcp320x *adc = iio_priv(indio_dev);
int ret = -EINVAL; int ret = -EINVAL;
int device_index = 0;
mutex_lock(&adc->lock); mutex_lock(&adc->lock);
device_index = spi_get_device_id(adc->spi)->driver_data;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
if (channel->differential) ret = mcp320x_adc_conversion(adc, channel->address,
ret = mcp320x_adc_conversion(adc, channel->differential, device_index);
MCP_START_BIT | channel->address);
else
ret = mcp320x_adc_conversion(adc,
MCP_START_BIT | MCP_SINGLE_ENDED |
channel->address);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -75,18 +155,15 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev, ...@@ -75,18 +155,15 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
/* Digital output code = (4096 * Vin) / Vref */
ret = regulator_get_voltage(adc->reg); ret = regulator_get_voltage(adc->reg);
if (ret < 0) if (ret < 0)
goto out; goto out;
/* convert regulator output voltage to mV */
*val = ret / 1000; *val = ret / 1000;
*val2 = 12; *val2 = adc->chip_info->resolution;
ret = IIO_VAL_FRACTIONAL_LOG2; ret = IIO_VAL_FRACTIONAL_LOG2;
break; break;
default:
break;
} }
out: out:
...@@ -117,6 +194,16 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev, ...@@ -117,6 +194,16 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
} }
static const struct iio_chan_spec mcp3201_channels[] = {
MCP320X_VOLTAGE_CHANNEL_DIFF(0),
};
static const struct iio_chan_spec mcp3202_channels[] = {
MCP320X_VOLTAGE_CHANNEL(0),
MCP320X_VOLTAGE_CHANNEL(1),
MCP320X_VOLTAGE_CHANNEL_DIFF(0),
};
static const struct iio_chan_spec mcp3204_channels[] = { static const struct iio_chan_spec mcp3204_channels[] = {
MCP320X_VOLTAGE_CHANNEL(0), MCP320X_VOLTAGE_CHANNEL(0),
MCP320X_VOLTAGE_CHANNEL(1), MCP320X_VOLTAGE_CHANNEL(1),
...@@ -146,19 +233,46 @@ static const struct iio_info mcp320x_info = { ...@@ -146,19 +233,46 @@ static const struct iio_info mcp320x_info = {
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
}; };
struct mcp3208_chip_info { static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
const struct iio_chan_spec *channels; [mcp3001] = {
unsigned int num_channels; .channels = mcp3201_channels,
}; .num_channels = ARRAY_SIZE(mcp3201_channels),
.resolution = 10
static const struct mcp3208_chip_info mcp3208_chip_infos[] = { },
[mcp3002] = {
.channels = mcp3202_channels,
.num_channels = ARRAY_SIZE(mcp3202_channels),
.resolution = 10
},
[mcp3004] = {
.channels = mcp3204_channels,
.num_channels = ARRAY_SIZE(mcp3204_channels),
.resolution = 10
},
[mcp3008] = {
.channels = mcp3208_channels,
.num_channels = ARRAY_SIZE(mcp3208_channels),
.resolution = 10
},
[mcp3201] = {
.channels = mcp3201_channels,
.num_channels = ARRAY_SIZE(mcp3201_channels),
.resolution = 12
},
[mcp3202] = {
.channels = mcp3202_channels,
.num_channels = ARRAY_SIZE(mcp3202_channels),
.resolution = 12
},
[mcp3204] = { [mcp3204] = {
.channels = mcp3204_channels, .channels = mcp3204_channels,
.num_channels = ARRAY_SIZE(mcp3204_channels) .num_channels = ARRAY_SIZE(mcp3204_channels),
.resolution = 12
}, },
[mcp3208] = { [mcp3208] = {
.channels = mcp3208_channels, .channels = mcp3208_channels,
.num_channels = ARRAY_SIZE(mcp3208_channels) .num_channels = ARRAY_SIZE(mcp3208_channels),
.resolution = 12
}, },
}; };
...@@ -166,7 +280,7 @@ static int mcp320x_probe(struct spi_device *spi) ...@@ -166,7 +280,7 @@ static int mcp320x_probe(struct spi_device *spi)
{ {
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct mcp320x *adc; struct mcp320x *adc;
const struct mcp3208_chip_info *chip_info; const struct mcp320x_chip_info *chip_info;
int ret; int ret;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
...@@ -181,7 +295,7 @@ static int mcp320x_probe(struct spi_device *spi) ...@@ -181,7 +295,7 @@ static int mcp320x_probe(struct spi_device *spi)
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &mcp320x_info; indio_dev->info = &mcp320x_info;
chip_info = &mcp3208_chip_infos[spi_get_device_id(spi)->driver_data]; chip_info = &mcp320x_chip_infos[spi_get_device_id(spi)->driver_data];
indio_dev->channels = chip_info->channels; indio_dev->channels = chip_info->channels;
indio_dev->num_channels = chip_info->num_channels; indio_dev->num_channels = chip_info->num_channels;
...@@ -226,7 +340,45 @@ static int mcp320x_remove(struct spi_device *spi) ...@@ -226,7 +340,45 @@ static int mcp320x_remove(struct spi_device *spi)
return 0; return 0;
} }
#if defined(CONFIG_OF)
static const struct of_device_id mcp320x_dt_ids[] = {
{
.compatible = "mcp3001",
.data = &mcp320x_chip_infos[mcp3001],
}, {
.compatible = "mcp3002",
.data = &mcp320x_chip_infos[mcp3002],
}, {
.compatible = "mcp3004",
.data = &mcp320x_chip_infos[mcp3004],
}, {
.compatible = "mcp3008",
.data = &mcp320x_chip_infos[mcp3008],
}, {
.compatible = "mcp3201",
.data = &mcp320x_chip_infos[mcp3201],
}, {
.compatible = "mcp3202",
.data = &mcp320x_chip_infos[mcp3202],
}, {
.compatible = "mcp3204",
.data = &mcp320x_chip_infos[mcp3204],
}, {
.compatible = "mcp3208",
.data = &mcp320x_chip_infos[mcp3208],
}, {
}
};
MODULE_DEVICE_TABLE(of, mcp320x_dt_ids);
#endif
static const struct spi_device_id mcp320x_id[] = { static const struct spi_device_id mcp320x_id[] = {
{ "mcp3001", mcp3001 },
{ "mcp3002", mcp3002 },
{ "mcp3004", mcp3004 },
{ "mcp3008", mcp3008 },
{ "mcp3201", mcp3201 },
{ "mcp3202", mcp3202 },
{ "mcp3204", mcp3204 }, { "mcp3204", mcp3204 },
{ "mcp3208", mcp3208 }, { "mcp3208", mcp3208 },
{ } { }
...@@ -245,5 +397,5 @@ static struct spi_driver mcp320x_driver = { ...@@ -245,5 +397,5 @@ static struct spi_driver mcp320x_driver = {
module_spi_driver(mcp320x_driver); module_spi_driver(mcp320x_driver);
MODULE_AUTHOR("Oskar Andero <oskar.andero@gmail.com>"); MODULE_AUTHOR("Oskar Andero <oskar.andero@gmail.com>");
MODULE_DESCRIPTION("Microchip Technology MCP3204/08"); MODULE_DESCRIPTION("Microchip Technology MCP3x01/02/04/08");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
This diff is collapsed.
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#define SARADC_DATA 0x00 #define SARADC_DATA 0x00
#define SARADC_DATA_MASK 0x3ff
#define SARADC_STAS 0x04 #define SARADC_STAS 0x04
#define SARADC_STAS_BUSY BIT(0) #define SARADC_STAS_BUSY BIT(0)
...@@ -38,15 +38,22 @@ ...@@ -38,15 +38,22 @@
#define SARADC_DLY_PU_SOC 0x0c #define SARADC_DLY_PU_SOC 0x0c
#define SARADC_DLY_PU_SOC_MASK 0x3f #define SARADC_DLY_PU_SOC_MASK 0x3f
#define SARADC_BITS 10
#define SARADC_TIMEOUT msecs_to_jiffies(100) #define SARADC_TIMEOUT msecs_to_jiffies(100)
struct rockchip_saradc_data {
int num_bits;
const struct iio_chan_spec *channels;
int num_channels;
unsigned long clk_rate;
};
struct rockchip_saradc { struct rockchip_saradc {
void __iomem *regs; void __iomem *regs;
struct clk *pclk; struct clk *pclk;
struct clk *clk; struct clk *clk;
struct completion completion; struct completion completion;
struct regulator *vref; struct regulator *vref;
const struct rockchip_saradc_data *data;
u16 last_val; u16 last_val;
}; };
...@@ -90,7 +97,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev, ...@@ -90,7 +97,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
} }
*val = ret / 1000; *val = ret / 1000;
*val2 = SARADC_BITS; *val2 = info->data->num_bits;
return IIO_VAL_FRACTIONAL_LOG2; return IIO_VAL_FRACTIONAL_LOG2;
default: default:
return -EINVAL; return -EINVAL;
...@@ -103,7 +110,7 @@ static irqreturn_t rockchip_saradc_isr(int irq, void *dev_id) ...@@ -103,7 +110,7 @@ static irqreturn_t rockchip_saradc_isr(int irq, void *dev_id)
/* Read value */ /* Read value */
info->last_val = readl_relaxed(info->regs + SARADC_DATA); info->last_val = readl_relaxed(info->regs + SARADC_DATA);
info->last_val &= SARADC_DATA_MASK; info->last_val &= GENMASK(info->data->num_bits - 1, 0);
/* Clear irq & power down adc */ /* Clear irq & power down adc */
writel_relaxed(0, info->regs + SARADC_CTRL); writel_relaxed(0, info->regs + SARADC_CTRL);
...@@ -133,12 +140,44 @@ static const struct iio_chan_spec rockchip_saradc_iio_channels[] = { ...@@ -133,12 +140,44 @@ static const struct iio_chan_spec rockchip_saradc_iio_channels[] = {
ADC_CHANNEL(2, "adc2"), ADC_CHANNEL(2, "adc2"),
}; };
static const struct rockchip_saradc_data saradc_data = {
.num_bits = 10,
.channels = rockchip_saradc_iio_channels,
.num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels),
.clk_rate = 1000000,
};
static const struct iio_chan_spec rockchip_rk3066_tsadc_iio_channels[] = {
ADC_CHANNEL(0, "adc0"),
ADC_CHANNEL(1, "adc1"),
};
static const struct rockchip_saradc_data rk3066_tsadc_data = {
.num_bits = 12,
.channels = rockchip_rk3066_tsadc_iio_channels,
.num_channels = ARRAY_SIZE(rockchip_rk3066_tsadc_iio_channels),
.clk_rate = 50000,
};
static const struct of_device_id rockchip_saradc_match[] = {
{
.compatible = "rockchip,saradc",
.data = &saradc_data,
}, {
.compatible = "rockchip,rk3066-tsadc",
.data = &rk3066_tsadc_data,
},
{},
};
MODULE_DEVICE_TABLE(of, rockchip_saradc_match);
static int rockchip_saradc_probe(struct platform_device *pdev) static int rockchip_saradc_probe(struct platform_device *pdev)
{ {
struct rockchip_saradc *info = NULL; struct rockchip_saradc *info = NULL;
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct iio_dev *indio_dev = NULL; struct iio_dev *indio_dev = NULL;
struct resource *mem; struct resource *mem;
const struct of_device_id *match;
int ret; int ret;
int irq; int irq;
...@@ -152,6 +191,9 @@ static int rockchip_saradc_probe(struct platform_device *pdev) ...@@ -152,6 +191,9 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
} }
info = iio_priv(indio_dev); info = iio_priv(indio_dev);
match = of_match_device(rockchip_saradc_match, &pdev->dev);
info->data = match->data;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
info->regs = devm_ioremap_resource(&pdev->dev, mem); info->regs = devm_ioremap_resource(&pdev->dev, mem);
if (IS_ERR(info->regs)) if (IS_ERR(info->regs))
...@@ -192,10 +234,10 @@ static int rockchip_saradc_probe(struct platform_device *pdev) ...@@ -192,10 +234,10 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
} }
/* /*
* Use a default of 1MHz for the converter clock. * Use a default value for the converter clock.
* This may become user-configurable in the future. * This may become user-configurable in the future.
*/ */
ret = clk_set_rate(info->clk, 1000000); ret = clk_set_rate(info->clk, info->data->clk_rate);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to set adc clk rate, %d\n", ret); dev_err(&pdev->dev, "failed to set adc clk rate, %d\n", ret);
return ret; return ret;
...@@ -227,8 +269,8 @@ static int rockchip_saradc_probe(struct platform_device *pdev) ...@@ -227,8 +269,8 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
indio_dev->info = &rockchip_saradc_iio_info; indio_dev->info = &rockchip_saradc_iio_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = rockchip_saradc_iio_channels; indio_dev->channels = info->data->channels;
indio_dev->num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels); indio_dev->num_channels = info->data->num_channels;
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
...@@ -296,12 +338,6 @@ static int rockchip_saradc_resume(struct device *dev) ...@@ -296,12 +338,6 @@ static int rockchip_saradc_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops, static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops,
rockchip_saradc_suspend, rockchip_saradc_resume); rockchip_saradc_suspend, rockchip_saradc_resume);
static const struct of_device_id rockchip_saradc_match[] = {
{ .compatible = "rockchip,saradc" },
{},
};
MODULE_DEVICE_TABLE(of, rockchip_saradc_match);
static struct platform_driver rockchip_saradc_driver = { static struct platform_driver rockchip_saradc_driver = {
.probe = rockchip_saradc_probe, .probe = rockchip_saradc_probe,
.remove = rockchip_saradc_remove, .remove = rockchip_saradc_remove,
......
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
#define VF610_ADC_CAL 0x80 #define VF610_ADC_CAL 0x80
/* Other field define */ /* Other field define */
#define VF610_ADC_ADCHC(x) ((x) & 0xF) #define VF610_ADC_ADCHC(x) ((x) & 0x1F)
#define VF610_ADC_AIEN (0x1 << 7) #define VF610_ADC_AIEN (0x1 << 7)
#define VF610_ADC_CONV_DISABLE 0x1F #define VF610_ADC_CONV_DISABLE 0x1F
#define VF610_ADC_HS_COCO0 0x1 #define VF610_ADC_HS_COCO0 0x1
...@@ -153,6 +153,12 @@ struct vf610_adc { ...@@ -153,6 +153,12 @@ struct vf610_adc {
BIT(IIO_CHAN_INFO_SAMP_FREQ), \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
} }
#define VF610_ADC_TEMPERATURE_CHAN(_idx, _chan_type) { \
.type = (_chan_type), \
.channel = (_idx), \
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
}
static const struct iio_chan_spec vf610_adc_iio_channels[] = { static const struct iio_chan_spec vf610_adc_iio_channels[] = {
VF610_ADC_CHAN(0, IIO_VOLTAGE), VF610_ADC_CHAN(0, IIO_VOLTAGE),
VF610_ADC_CHAN(1, IIO_VOLTAGE), VF610_ADC_CHAN(1, IIO_VOLTAGE),
...@@ -170,6 +176,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = { ...@@ -170,6 +176,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = {
VF610_ADC_CHAN(13, IIO_VOLTAGE), VF610_ADC_CHAN(13, IIO_VOLTAGE),
VF610_ADC_CHAN(14, IIO_VOLTAGE), VF610_ADC_CHAN(14, IIO_VOLTAGE),
VF610_ADC_CHAN(15, IIO_VOLTAGE), VF610_ADC_CHAN(15, IIO_VOLTAGE),
VF610_ADC_TEMPERATURE_CHAN(26, IIO_TEMP),
/* sentinel */ /* sentinel */
}; };
...@@ -451,6 +458,7 @@ static int vf610_read_raw(struct iio_dev *indio_dev, ...@@ -451,6 +458,7 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
case IIO_CHAN_INFO_PROCESSED:
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
reinit_completion(&info->completion); reinit_completion(&info->completion);
...@@ -468,7 +476,23 @@ static int vf610_read_raw(struct iio_dev *indio_dev, ...@@ -468,7 +476,23 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
return ret; return ret;
} }
*val = info->value; switch (chan->type) {
case IIO_VOLTAGE:
*val = info->value;
break;
case IIO_TEMP:
/*
* Calculate in degree Celsius times 1000
* Using sensor slope of 1.84 mV/°C and
* V at 25°C of 696 mV
*/
*val = 25000 - ((int)info->value - 864) * 1000000 / 1840;
break;
default:
mutex_unlock(&indio_dev->mlock);
return -EINVAL;
}
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
return IIO_VAL_INT; return IIO_VAL_INT;
...@@ -569,9 +593,9 @@ static int vf610_adc_probe(struct platform_device *pdev) ...@@ -569,9 +593,9 @@ static int vf610_adc_probe(struct platform_device *pdev)
return PTR_ERR(info->regs); return PTR_ERR(info->regs);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq <= 0) { if (irq < 0) {
dev_err(&pdev->dev, "no irq resource?\n"); dev_err(&pdev->dev, "no irq resource?\n");
return -EINVAL; return irq;
} }
ret = devm_request_irq(info->dev, irq, ret = devm_request_irq(info->dev, irq,
...@@ -586,8 +610,7 @@ static int vf610_adc_probe(struct platform_device *pdev) ...@@ -586,8 +610,7 @@ static int vf610_adc_probe(struct platform_device *pdev)
if (IS_ERR(info->clk)) { if (IS_ERR(info->clk)) {
dev_err(&pdev->dev, "failed getting clock, err = %ld\n", dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
PTR_ERR(info->clk)); PTR_ERR(info->clk));
ret = PTR_ERR(info->clk); return PTR_ERR(info->clk);
return ret;
} }
info->vref = devm_regulator_get(&pdev->dev, "vref"); info->vref = devm_regulator_get(&pdev->dev, "vref");
...@@ -681,17 +704,19 @@ static int vf610_adc_resume(struct device *dev) ...@@ -681,17 +704,19 @@ static int vf610_adc_resume(struct device *dev)
ret = clk_prepare_enable(info->clk); ret = clk_prepare_enable(info->clk);
if (ret) if (ret)
return ret; goto disable_reg;
vf610_adc_hw_init(info); vf610_adc_hw_init(info);
return 0; return 0;
disable_reg:
regulator_disable(info->vref);
return ret;
} }
#endif #endif
static SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, static SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend, vf610_adc_resume);
vf610_adc_suspend,
vf610_adc_resume);
static struct platform_driver vf610_adc_driver = { static struct platform_driver vf610_adc_driver = {
.probe = vf610_adc_probe, .probe = vf610_adc_probe,
......
...@@ -72,6 +72,7 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev, ...@@ -72,6 +72,7 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
indio_dev->dev.parent = &client->dev; indio_dev->dev.parent = &client->dev;
indio_dev->name = client->name; indio_dev->name = client->name;
sdata->dev = &client->dev;
sdata->tf = &st_sensors_tf_i2c; sdata->tf = &st_sensors_tf_i2c;
sdata->get_irq_data_ready = st_sensors_i2c_get_irq; sdata->get_irq_data_ready = st_sensors_i2c_get_irq;
} }
......
...@@ -111,6 +111,7 @@ void st_sensors_spi_configure(struct iio_dev *indio_dev, ...@@ -111,6 +111,7 @@ void st_sensors_spi_configure(struct iio_dev *indio_dev,
indio_dev->dev.parent = &spi->dev; indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi->modalias; indio_dev->name = spi->modalias;
sdata->dev = &spi->dev;
sdata->tf = &st_sensors_tf_spi; sdata->tf = &st_sensors_tf_spi;
sdata->get_irq_data_ready = st_sensors_spi_get_irq; sdata->get_irq_data_ready = st_sensors_spi_get_irq;
} }
......
...@@ -30,8 +30,7 @@ static const struct st_sensors_platform_data gyro_pdata = { ...@@ -30,8 +30,7 @@ static const struct st_sensors_platform_data gyro_pdata = {
.drdy_int_pin = 2, .drdy_int_pin = 2,
}; };
int st_gyro_common_probe(struct iio_dev *indio_dev, int st_gyro_common_probe(struct iio_dev *indio_dev);
struct st_sensors_platform_data *pdata);
void st_gyro_common_remove(struct iio_dev *indio_dev); void st_gyro_common_remove(struct iio_dev *indio_dev);
#ifdef CONFIG_IIO_BUFFER #ifdef CONFIG_IIO_BUFFER
......
...@@ -103,7 +103,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = { ...@@ -103,7 +103,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(3) IIO_CHAN_SOFT_TIMESTAMP(3)
}; };
static const struct st_sensors st_gyro_sensors[] = { static const struct st_sensor_settings st_gyro_sensors_settings[] = {
{ {
.wai = ST_GYRO_1_WAI_EXP, .wai = ST_GYRO_1_WAI_EXP,
.sensors_supported = { .sensors_supported = {
...@@ -309,8 +309,7 @@ static const struct iio_trigger_ops st_gyro_trigger_ops = { ...@@ -309,8 +309,7 @@ static const struct iio_trigger_ops st_gyro_trigger_ops = {
#define ST_GYRO_TRIGGER_OPS NULL #define ST_GYRO_TRIGGER_OPS NULL
#endif #endif
int st_gyro_common_probe(struct iio_dev *indio_dev, int st_gyro_common_probe(struct iio_dev *indio_dev)
struct st_sensors_platform_data *pdata)
{ {
struct st_sensor_data *gdata = iio_priv(indio_dev); struct st_sensor_data *gdata = iio_priv(indio_dev);
int irq = gdata->get_irq_data_ready(indio_dev); int irq = gdata->get_irq_data_ready(indio_dev);
...@@ -322,20 +321,22 @@ int st_gyro_common_probe(struct iio_dev *indio_dev, ...@@ -322,20 +321,22 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
st_sensors_power_enable(indio_dev); st_sensors_power_enable(indio_dev);
err = st_sensors_check_device_support(indio_dev, err = st_sensors_check_device_support(indio_dev,
ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors); ARRAY_SIZE(st_gyro_sensors_settings),
st_gyro_sensors_settings);
if (err < 0) if (err < 0)
return err; return err;
gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
gdata->multiread_bit = gdata->sensor->multi_read_bit; gdata->multiread_bit = gdata->sensor_settings->multi_read_bit;
indio_dev->channels = gdata->sensor->ch; indio_dev->channels = gdata->sensor_settings->ch;
indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
gdata->current_fullscale = (struct st_sensor_fullscale_avl *) gdata->current_fullscale = (struct st_sensor_fullscale_avl *)
&gdata->sensor->fs.fs_avl[0]; &gdata->sensor_settings->fs.fs_avl[0];
gdata->odr = gdata->sensor->odr.odr_avl[0].hz; gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
err = st_sensors_init_sensor(indio_dev, pdata); err = st_sensors_init_sensor(indio_dev,
(struct st_sensors_platform_data *)&gyro_pdata);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -67,13 +67,11 @@ static int st_gyro_i2c_probe(struct i2c_client *client, ...@@ -67,13 +67,11 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
gdata = iio_priv(indio_dev); gdata = iio_priv(indio_dev);
gdata->dev = &client->dev;
st_sensors_of_i2c_probe(client, st_gyro_of_match); st_sensors_of_i2c_probe(client, st_gyro_of_match);
st_sensors_i2c_configure(indio_dev, client, gdata); st_sensors_i2c_configure(indio_dev, client, gdata);
err = st_gyro_common_probe(indio_dev, err = st_gyro_common_probe(indio_dev);
(struct st_sensors_platform_data *)&gyro_pdata);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -29,12 +29,10 @@ static int st_gyro_spi_probe(struct spi_device *spi) ...@@ -29,12 +29,10 @@ static int st_gyro_spi_probe(struct spi_device *spi)
return -ENOMEM; return -ENOMEM;
gdata = iio_priv(indio_dev); gdata = iio_priv(indio_dev);
gdata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, gdata); st_sensors_spi_configure(indio_dev, spi, gdata);
err = st_gyro_common_probe(indio_dev, err = st_gyro_common_probe(indio_dev);
(struct st_sensors_platform_data *)&gyro_pdata);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -22,4 +22,14 @@ config SI7005 ...@@ -22,4 +22,14 @@ config SI7005
To compile this driver as a module, choose M here: the module To compile this driver as a module, choose M here: the module
will be called si7005. will be called si7005.
config SI7020
tristate "Si7013/20/21 Relative Humidity and Temperature Sensors"
depends on I2C
help
Say yes here to build support for the Silicon Labs Si7013/20/21
Relative Humidity and Temperature Sensors.
To compile this driver as a module, choose M here: the module
will be called si7020.
endmenu endmenu
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
obj-$(CONFIG_DHT11) += dht11.o obj-$(CONFIG_DHT11) += dht11.o
obj-$(CONFIG_SI7005) += si7005.o obj-$(CONFIG_SI7005) += si7005.o
obj-$(CONFIG_SI7020) += si7020.o
/*
* si7020.c - Silicon Labs Si7013/20/21 Relative Humidity and Temp Sensors
* Copyright (c) 2013,2014 Uplogix, Inc.
* David Barksdale <dbarksdale@uplogix.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* The Silicon Labs Si7013/20/21 Relative Humidity and Temperature Sensors
* are i2c devices which have an identical programming interface for
* measuring relative humidity and temperature. The Si7013 has an additional
* temperature input which this driver does not support.
*
* Data Sheets:
* Si7013: http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7013.pdf
* Si7020: http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7020.pdf
* Si7021: http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7021.pdf
*/
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
/* Measure Relative Humidity, Hold Master Mode */
#define SI7020CMD_RH_HOLD 0xE5
/* Measure Temperature, Hold Master Mode */
#define SI7020CMD_TEMP_HOLD 0xE3
/* Software Reset */
#define SI7020CMD_RESET 0xFE
static int si7020_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
struct i2c_client *client = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = i2c_smbus_read_word_data(client,
chan->type == IIO_TEMP ?
SI7020CMD_TEMP_HOLD :
SI7020CMD_RH_HOLD);
if (ret < 0)
return ret;
*val = ret >> 2;
if (chan->type == IIO_HUMIDITYRELATIVE)
*val &= GENMASK(11, 0);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
if (chan->type == IIO_TEMP)
*val = 175720; /* = 175.72 * 1000 */
else
*val = 125 * 1000;
*val2 = 65536 >> 2;
return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_OFFSET:
/*
* Since iio_convert_raw_to_processed_unlocked assumes offset
* is an integer we have to round these values and lose
* accuracy.
* Relative humidity will be 0.0032959% too high and
* temperature will be 0.00277344 degrees too high.
* This is no big deal because it's within the accuracy of the
* sensor.
*/
if (chan->type == IIO_TEMP)
*val = -4368; /* = -46.85 * (65536 >> 2) / 175.72 */
else
*val = -786; /* = -6 * (65536 >> 2) / 125 */
return IIO_VAL_INT;
default:
break;
}
return -EINVAL;
}
static const struct iio_chan_spec si7020_channels[] = {
{
.type = IIO_HUMIDITYRELATIVE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
},
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
}
};
static const struct iio_info si7020_info = {
.read_raw = si7020_read_raw,
.driver_module = THIS_MODULE,
};
static int si7020_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct iio_dev *indio_dev;
struct i2c_client **data;
int ret;
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_BYTE |
I2C_FUNC_SMBUS_READ_WORD_DATA))
return -ENODEV;
/* Reset device, loads default settings. */
ret = i2c_smbus_write_byte(client, SI7020CMD_RESET);
if (ret < 0)
return ret;
/* Wait the maximum power-up time after software reset. */
msleep(15);
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*client));
if (!indio_dev)
return -ENOMEM;
data = iio_priv(indio_dev);
*data = client;
indio_dev->dev.parent = &client->dev;
indio_dev->name = dev_name(&client->dev);
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &si7020_info;
indio_dev->channels = si7020_channels;
indio_dev->num_channels = ARRAY_SIZE(si7020_channels);
return devm_iio_device_register(&client->dev, indio_dev);
}
static const struct i2c_device_id si7020_id[] = {
{ "si7020", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, si7020_id);
static struct i2c_driver si7020_driver = {
.driver.name = "si7020",
.probe = si7020_probe,
.id_table = si7020_id,
};
module_i2c_driver(si7020_driver);
MODULE_DESCRIPTION("Silicon Labs Si7013/20/21 Relative Humidity and Temperature Sensors");
MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>");
MODULE_LICENSE("GPL");
...@@ -100,6 +100,28 @@ static int iio_dev_node_match(struct device *dev, void *data) ...@@ -100,6 +100,28 @@ static int iio_dev_node_match(struct device *dev, void *data)
return dev->of_node == data && dev->type == &iio_device_type; return dev->of_node == data && dev->type == &iio_device_type;
} }
/**
* __of_iio_simple_xlate - translate iiospec to the IIO channel index
* @indio_dev: pointer to the iio_dev structure
* @iiospec: IIO specifier as found in the device tree
*
* This is simple translation function, suitable for the most 1:1 mapped
* channels in IIO chips. This function performs only one sanity check:
* whether IIO index is less than num_channels (that is specified in the
* iio_dev).
*/
static int __of_iio_simple_xlate(struct iio_dev *indio_dev,
const struct of_phandle_args *iiospec)
{
if (!iiospec->args_count)
return 0;
if (iiospec->args[0] >= indio_dev->num_channels)
return -EINVAL;
return iiospec->args[0];
}
static int __of_iio_channel_get(struct iio_channel *channel, static int __of_iio_channel_get(struct iio_channel *channel,
struct device_node *np, int index) struct device_node *np, int index)
{ {
...@@ -122,18 +144,19 @@ static int __of_iio_channel_get(struct iio_channel *channel, ...@@ -122,18 +144,19 @@ static int __of_iio_channel_get(struct iio_channel *channel,
indio_dev = dev_to_iio_dev(idev); indio_dev = dev_to_iio_dev(idev);
channel->indio_dev = indio_dev; channel->indio_dev = indio_dev;
index = iiospec.args_count ? iiospec.args[0] : 0; if (indio_dev->info->of_xlate)
if (index >= indio_dev->num_channels) { index = indio_dev->info->of_xlate(indio_dev, &iiospec);
err = -EINVAL; else
index = __of_iio_simple_xlate(indio_dev, &iiospec);
if (index < 0)
goto err_put; goto err_put;
}
channel->channel = &indio_dev->channels[index]; channel->channel = &indio_dev->channels[index];
return 0; return 0;
err_put: err_put:
iio_device_put(indio_dev); iio_device_put(indio_dev);
return err; return index;
} }
static struct iio_channel *of_iio_channel_get(struct device_node *np, int index) static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn" #define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn"
#define LIS3MDL_MAGN_DEV_NAME "lis3mdl" #define LIS3MDL_MAGN_DEV_NAME "lis3mdl"
int st_magn_common_probe(struct iio_dev *indio_dev, int st_magn_common_probe(struct iio_dev *indio_dev);
struct st_sensors_platform_data *pdata);
void st_magn_common_remove(struct iio_dev *indio_dev); void st_magn_common_remove(struct iio_dev *indio_dev);
#ifdef CONFIG_IIO_BUFFER #ifdef CONFIG_IIO_BUFFER
......
...@@ -149,7 +149,7 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = { ...@@ -149,7 +149,7 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(3) IIO_CHAN_SOFT_TIMESTAMP(3)
}; };
static const struct st_sensors st_magn_sensors[] = { static const struct st_sensor_settings st_magn_sensors_settings[] = {
{ {
.wai = ST_MAGN_1_WAI_EXP, .wai = ST_MAGN_1_WAI_EXP,
.sensors_supported = { .sensors_supported = {
...@@ -361,8 +361,7 @@ static const struct iio_info magn_info = { ...@@ -361,8 +361,7 @@ static const struct iio_info magn_info = {
.write_raw = &st_magn_write_raw, .write_raw = &st_magn_write_raw,
}; };
int st_magn_common_probe(struct iio_dev *indio_dev, int st_magn_common_probe(struct iio_dev *indio_dev)
struct st_sensors_platform_data *pdata)
{ {
struct st_sensor_data *mdata = iio_priv(indio_dev); struct st_sensor_data *mdata = iio_priv(indio_dev);
int irq = mdata->get_irq_data_ready(indio_dev); int irq = mdata->get_irq_data_ready(indio_dev);
...@@ -374,20 +373,21 @@ int st_magn_common_probe(struct iio_dev *indio_dev, ...@@ -374,20 +373,21 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
st_sensors_power_enable(indio_dev); st_sensors_power_enable(indio_dev);
err = st_sensors_check_device_support(indio_dev, err = st_sensors_check_device_support(indio_dev,
ARRAY_SIZE(st_magn_sensors), st_magn_sensors); ARRAY_SIZE(st_magn_sensors_settings),
st_magn_sensors_settings);
if (err < 0) if (err < 0)
return err; return err;
mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS;
mdata->multiread_bit = mdata->sensor->multi_read_bit; mdata->multiread_bit = mdata->sensor_settings->multi_read_bit;
indio_dev->channels = mdata->sensor->ch; indio_dev->channels = mdata->sensor_settings->ch;
indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
mdata->current_fullscale = (struct st_sensor_fullscale_avl *) mdata->current_fullscale = (struct st_sensor_fullscale_avl *)
&mdata->sensor->fs.fs_avl[0]; &mdata->sensor_settings->fs.fs_avl[0];
mdata->odr = mdata->sensor->odr.odr_avl[0].hz; mdata->odr = mdata->sensor_settings->odr.odr_avl[0].hz;
err = st_sensors_init_sensor(indio_dev, pdata); err = st_sensors_init_sensor(indio_dev, NULL);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -51,12 +51,11 @@ static int st_magn_i2c_probe(struct i2c_client *client, ...@@ -51,12 +51,11 @@ static int st_magn_i2c_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
mdata = iio_priv(indio_dev); mdata = iio_priv(indio_dev);
mdata->dev = &client->dev;
st_sensors_of_i2c_probe(client, st_magn_of_match); st_sensors_of_i2c_probe(client, st_magn_of_match);
st_sensors_i2c_configure(indio_dev, client, mdata); st_sensors_i2c_configure(indio_dev, client, mdata);
err = st_magn_common_probe(indio_dev, NULL); err = st_magn_common_probe(indio_dev);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -29,11 +29,10 @@ static int st_magn_spi_probe(struct spi_device *spi) ...@@ -29,11 +29,10 @@ static int st_magn_spi_probe(struct spi_device *spi)
return -ENOMEM; return -ENOMEM;
mdata = iio_priv(indio_dev); mdata = iio_priv(indio_dev);
mdata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, mdata); st_sensors_spi_configure(indio_dev, spi, mdata);
err = st_magn_common_probe(indio_dev, NULL); err = st_magn_common_probe(indio_dev);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -5,6 +5,17 @@ ...@@ -5,6 +5,17 @@
menu "Pressure sensors" menu "Pressure sensors"
config BMP280
tristate "Bosch Sensortec BMP280 pressure sensor driver"
depends on I2C
select REGMAP_I2C
help
Say yes here to build support for Bosch Sensortec BMP280
pressure and temperature sensor.
To compile this driver as a module, choose M here: the module
will be called bmp280.
config HID_SENSOR_PRESS config HID_SENSOR_PRESS
depends on HID_SENSOR_HUB depends on HID_SENSOR_HUB
select IIO_BUFFER select IIO_BUFFER
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# #
# When adding new entries keep the list in alphabetical order # When adding new entries keep the list in alphabetical order
obj-$(CONFIG_BMP280) += bmp280.o
obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o
obj-$(CONFIG_MPL115) += mpl115.o obj-$(CONFIG_MPL115) += mpl115.o
obj-$(CONFIG_MPL3115) += mpl3115.o obj-$(CONFIG_MPL3115) += mpl3115.o
......
This diff is collapsed.
...@@ -26,8 +26,7 @@ static const struct st_sensors_platform_data default_press_pdata = { ...@@ -26,8 +26,7 @@ static const struct st_sensors_platform_data default_press_pdata = {
.drdy_int_pin = 1, .drdy_int_pin = 1,
}; };
int st_press_common_probe(struct iio_dev *indio_dev, int st_press_common_probe(struct iio_dev *indio_dev);
struct st_sensors_platform_data *pdata);
void st_press_common_remove(struct iio_dev *indio_dev); void st_press_common_remove(struct iio_dev *indio_dev);
#ifdef CONFIG_IIO_BUFFER #ifdef CONFIG_IIO_BUFFER
......
...@@ -38,10 +38,10 @@ static int st_press_buffer_preenable(struct iio_dev *indio_dev) ...@@ -38,10 +38,10 @@ static int st_press_buffer_preenable(struct iio_dev *indio_dev)
static int st_press_buffer_postenable(struct iio_dev *indio_dev) static int st_press_buffer_postenable(struct iio_dev *indio_dev)
{ {
int err; int err;
struct st_sensor_data *pdata = iio_priv(indio_dev); struct st_sensor_data *press_data = iio_priv(indio_dev);
pdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); press_data->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (pdata->buffer_data == NULL) { if (press_data->buffer_data == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto allocate_memory_error; goto allocate_memory_error;
} }
...@@ -53,7 +53,7 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev) ...@@ -53,7 +53,7 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev)
return err; return err;
st_press_buffer_postenable_error: st_press_buffer_postenable_error:
kfree(pdata->buffer_data); kfree(press_data->buffer_data);
allocate_memory_error: allocate_memory_error:
return err; return err;
} }
...@@ -61,7 +61,7 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev) ...@@ -61,7 +61,7 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev)
static int st_press_buffer_predisable(struct iio_dev *indio_dev) static int st_press_buffer_predisable(struct iio_dev *indio_dev)
{ {
int err; int err;
struct st_sensor_data *pdata = iio_priv(indio_dev); struct st_sensor_data *press_data = iio_priv(indio_dev);
err = iio_triggered_buffer_predisable(indio_dev); err = iio_triggered_buffer_predisable(indio_dev);
if (err < 0) if (err < 0)
...@@ -70,7 +70,7 @@ static int st_press_buffer_predisable(struct iio_dev *indio_dev) ...@@ -70,7 +70,7 @@ static int st_press_buffer_predisable(struct iio_dev *indio_dev)
err = st_sensors_set_enable(indio_dev, false); err = st_sensors_set_enable(indio_dev, false);
st_press_buffer_predisable_error: st_press_buffer_predisable_error:
kfree(pdata->buffer_data); kfree(press_data->buffer_data);
return err; return err;
} }
......
...@@ -175,7 +175,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = { ...@@ -175,7 +175,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(1) IIO_CHAN_SOFT_TIMESTAMP(1)
}; };
static const struct st_sensors st_press_sensors[] = { static const struct st_sensor_settings st_press_sensors_settings[] = {
{ {
.wai = ST_PRESS_LPS331AP_WAI_EXP, .wai = ST_PRESS_LPS331AP_WAI_EXP,
.sensors_supported = { .sensors_supported = {
...@@ -333,7 +333,7 @@ static int st_press_read_raw(struct iio_dev *indio_dev, ...@@ -333,7 +333,7 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
int *val2, long mask) int *val2, long mask)
{ {
int err; int err;
struct st_sensor_data *pdata = iio_priv(indio_dev); struct st_sensor_data *press_data = iio_priv(indio_dev);
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
...@@ -347,10 +347,10 @@ static int st_press_read_raw(struct iio_dev *indio_dev, ...@@ -347,10 +347,10 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
switch (ch->type) { switch (ch->type) {
case IIO_PRESSURE: case IIO_PRESSURE:
*val2 = pdata->current_fullscale->gain; *val2 = press_data->current_fullscale->gain;
break; break;
case IIO_TEMP: case IIO_TEMP:
*val2 = pdata->current_fullscale->gain2; *val2 = press_data->current_fullscale->gain2;
break; break;
default: default:
err = -EINVAL; err = -EINVAL;
...@@ -371,7 +371,7 @@ static int st_press_read_raw(struct iio_dev *indio_dev, ...@@ -371,7 +371,7 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_FRACTIONAL; return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
*val = pdata->odr; *val = press_data->odr;
return IIO_VAL_INT; return IIO_VAL_INT;
default: default:
return -EINVAL; return -EINVAL;
...@@ -409,11 +409,10 @@ static const struct iio_trigger_ops st_press_trigger_ops = { ...@@ -409,11 +409,10 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
#define ST_PRESS_TRIGGER_OPS NULL #define ST_PRESS_TRIGGER_OPS NULL
#endif #endif
int st_press_common_probe(struct iio_dev *indio_dev, int st_press_common_probe(struct iio_dev *indio_dev)
struct st_sensors_platform_data *plat_data)
{ {
struct st_sensor_data *pdata = iio_priv(indio_dev); struct st_sensor_data *press_data = iio_priv(indio_dev);
int irq = pdata->get_irq_data_ready(indio_dev); int irq = press_data->get_irq_data_ready(indio_dev);
int err; int err;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
...@@ -422,28 +421,30 @@ int st_press_common_probe(struct iio_dev *indio_dev, ...@@ -422,28 +421,30 @@ int st_press_common_probe(struct iio_dev *indio_dev,
st_sensors_power_enable(indio_dev); st_sensors_power_enable(indio_dev);
err = st_sensors_check_device_support(indio_dev, err = st_sensors_check_device_support(indio_dev,
ARRAY_SIZE(st_press_sensors), ARRAY_SIZE(st_press_sensors_settings),
st_press_sensors); st_press_sensors_settings);
if (err < 0) if (err < 0)
return err; return err;
pdata->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS; press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS;
pdata->multiread_bit = pdata->sensor->multi_read_bit; press_data->multiread_bit = press_data->sensor_settings->multi_read_bit;
indio_dev->channels = pdata->sensor->ch; indio_dev->channels = press_data->sensor_settings->ch;
indio_dev->num_channels = pdata->sensor->num_ch; indio_dev->num_channels = press_data->sensor_settings->num_ch;
if (pdata->sensor->fs.addr != 0) if (press_data->sensor_settings->fs.addr != 0)
pdata->current_fullscale = (struct st_sensor_fullscale_avl *) press_data->current_fullscale =
&pdata->sensor->fs.fs_avl[0]; (struct st_sensor_fullscale_avl *)
&press_data->sensor_settings->fs.fs_avl[0];
pdata->odr = pdata->sensor->odr.odr_avl[0].hz; press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz;
/* Some devices don't support a data ready pin. */ /* Some devices don't support a data ready pin. */
if (!plat_data && pdata->sensor->drdy_irq.addr) if (!press_data->dev->platform_data &&
plat_data = press_data->sensor_settings->drdy_irq.addr)
press_data->dev->platform_data =
(struct st_sensors_platform_data *)&default_press_pdata; (struct st_sensors_platform_data *)&default_press_pdata;
err = st_sensors_init_sensor(indio_dev, plat_data); err = st_sensors_init_sensor(indio_dev, press_data->dev->platform_data);
if (err < 0) if (err < 0)
return err; return err;
...@@ -479,12 +480,12 @@ EXPORT_SYMBOL(st_press_common_probe); ...@@ -479,12 +480,12 @@ EXPORT_SYMBOL(st_press_common_probe);
void st_press_common_remove(struct iio_dev *indio_dev) void st_press_common_remove(struct iio_dev *indio_dev)
{ {
struct st_sensor_data *pdata = iio_priv(indio_dev); struct st_sensor_data *press_data = iio_priv(indio_dev);
st_sensors_power_disable(indio_dev); st_sensors_power_disable(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
if (pdata->get_irq_data_ready(indio_dev) > 0) if (press_data->get_irq_data_ready(indio_dev) > 0)
st_sensors_deallocate_trigger(indio_dev); st_sensors_deallocate_trigger(indio_dev);
st_press_deallocate_ring(indio_dev); st_press_deallocate_ring(indio_dev);
......
...@@ -43,20 +43,19 @@ static int st_press_i2c_probe(struct i2c_client *client, ...@@ -43,20 +43,19 @@ static int st_press_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct st_sensor_data *pdata; struct st_sensor_data *press_data;
int err; int err;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*pdata)); indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
pdata = iio_priv(indio_dev); press_data = iio_priv(indio_dev);
pdata->dev = &client->dev;
st_sensors_of_i2c_probe(client, st_press_of_match); st_sensors_of_i2c_probe(client, st_press_of_match);
st_sensors_i2c_configure(indio_dev, client, pdata); st_sensors_i2c_configure(indio_dev, client, press_data);
err = st_press_common_probe(indio_dev, client->dev.platform_data); err = st_press_common_probe(indio_dev);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -21,19 +21,18 @@ ...@@ -21,19 +21,18 @@
static int st_press_spi_probe(struct spi_device *spi) static int st_press_spi_probe(struct spi_device *spi)
{ {
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct st_sensor_data *pdata; struct st_sensor_data *press_data;
int err; int err;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*pdata)); indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
if (indio_dev == NULL) if (indio_dev == NULL)
return -ENOMEM; return -ENOMEM;
pdata = iio_priv(indio_dev); press_data = iio_priv(indio_dev);
pdata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, pdata); st_sensors_spi_configure(indio_dev, spi, press_data);
err = st_press_common_probe(indio_dev, spi->dev.platform_data); err = st_press_common_probe(indio_dev);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -95,7 +95,7 @@ static int as3935_read(struct as3935_state *st, unsigned int reg, int *val) ...@@ -95,7 +95,7 @@ static int as3935_read(struct as3935_state *st, unsigned int reg, int *val)
*val = ret; *val = ret;
return 0; return 0;
}; }
static int as3935_write(struct as3935_state *st, static int as3935_write(struct as3935_state *st,
unsigned int reg, unsigned int reg,
...@@ -107,7 +107,7 @@ static int as3935_write(struct as3935_state *st, ...@@ -107,7 +107,7 @@ static int as3935_write(struct as3935_state *st,
buf[1] = val; buf[1] = val;
return spi_write(st->spi, buf, 2); return spi_write(st->spi, buf, 2);
}; }
static ssize_t as3935_sensor_sensitivity_show(struct device *dev, static ssize_t as3935_sensor_sensitivity_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
...@@ -122,7 +122,7 @@ static ssize_t as3935_sensor_sensitivity_show(struct device *dev, ...@@ -122,7 +122,7 @@ static ssize_t as3935_sensor_sensitivity_show(struct device *dev,
val = (val & AS3935_AFE_MASK) >> 1; val = (val & AS3935_AFE_MASK) >> 1;
return sprintf(buf, "%d\n", val); return sprintf(buf, "%d\n", val);
}; }
static ssize_t as3935_sensor_sensitivity_store(struct device *dev, static ssize_t as3935_sensor_sensitivity_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
...@@ -142,7 +142,7 @@ static ssize_t as3935_sensor_sensitivity_store(struct device *dev, ...@@ -142,7 +142,7 @@ static ssize_t as3935_sensor_sensitivity_store(struct device *dev,
as3935_write(st, AS3935_AFE_GAIN, val << 1); as3935_write(st, AS3935_AFE_GAIN, val << 1);
return len; return len;
}; }
static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR, static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR,
as3935_sensor_sensitivity_show, as3935_sensor_sensitivity_store, 0); as3935_sensor_sensitivity_show, as3935_sensor_sensitivity_store, 0);
...@@ -214,7 +214,7 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private) ...@@ -214,7 +214,7 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
iio_trigger_notify_done(indio_dev->trig); iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED; return IRQ_HANDLED;
}; }
static const struct iio_trigger_ops iio_interrupt_trigger_ops = { static const struct iio_trigger_ops iio_interrupt_trigger_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -238,7 +238,7 @@ static void as3935_event_work(struct work_struct *work) ...@@ -238,7 +238,7 @@ static void as3935_event_work(struct work_struct *work)
dev_warn(&st->spi->dev, "noise level is too high"); dev_warn(&st->spi->dev, "noise level is too high");
break; break;
} }
}; }
static irqreturn_t as3935_interrupt_handler(int irq, void *private) static irqreturn_t as3935_interrupt_handler(int irq, void *private)
{ {
...@@ -417,7 +417,7 @@ static int as3935_probe(struct spi_device *spi) ...@@ -417,7 +417,7 @@ static int as3935_probe(struct spi_device *spi)
iio_trigger_unregister(st->trig); iio_trigger_unregister(st->trig);
return ret; return ret;
}; }
static int as3935_remove(struct spi_device *spi) static int as3935_remove(struct spi_device *spi)
{ {
...@@ -429,7 +429,7 @@ static int as3935_remove(struct spi_device *spi) ...@@ -429,7 +429,7 @@ static int as3935_remove(struct spi_device *spi)
iio_trigger_unregister(st->trig); iio_trigger_unregister(st->trig);
return 0; return 0;
}; }
static const struct spi_device_id as3935_id[] = { static const struct spi_device_id as3935_id[] = {
{"as3935", 0}, {"as3935", 0},
......
...@@ -162,11 +162,12 @@ int main(int argc, char **argv) ...@@ -162,11 +162,12 @@ int main(int argc, char **argv)
char *buffer_access; char *buffer_access;
int scan_size; int scan_size;
int noevents = 0; int noevents = 0;
int notrigger = 0;
char *dummy; char *dummy;
struct iio_channel_info *channels; struct iio_channel_info *channels;
while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) { while ((c = getopt(argc, argv, "l:w:c:et:n:g")) != -1) {
switch (c) { switch (c) {
case 'n': case 'n':
device_name = optarg; device_name = optarg;
...@@ -187,6 +188,9 @@ int main(int argc, char **argv) ...@@ -187,6 +188,9 @@ int main(int argc, char **argv)
case 'l': case 'l':
buf_len = strtoul(optarg, &dummy, 10); buf_len = strtoul(optarg, &dummy, 10);
break; break;
case 'g':
notrigger = 1;
break;
case '?': case '?':
return -1; return -1;
} }
...@@ -205,28 +209,32 @@ int main(int argc, char **argv) ...@@ -205,28 +209,32 @@ int main(int argc, char **argv)
printf("iio device number being used is %d\n", dev_num); printf("iio device number being used is %d\n", dev_num);
asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
if (trigger_name == NULL) {
/* if (!notrigger) {
* Build the trigger name. If it is device associated its if (trigger_name == NULL) {
* name is <device_name>_dev[n] where n matches the device /*
* number found above * Build the trigger name. If it is device associated
*/ * its name is <device_name>_dev[n] where n matches
ret = asprintf(&trigger_name, * the device number found above.
"%s-dev%d", device_name, dev_num); */
if (ret < 0) { ret = asprintf(&trigger_name,
ret = -ENOMEM; "%s-dev%d", device_name, dev_num);
goto error_ret; if (ret < 0) {
ret = -ENOMEM;
goto error_ret;
}
} }
}
/* Verify the trigger exists */ /* Verify the trigger exists */
trig_num = find_type_by_name(trigger_name, "trigger"); trig_num = find_type_by_name(trigger_name, "trigger");
if (trig_num < 0) { if (trig_num < 0) {
printf("Failed to find the trigger %s\n", trigger_name); printf("Failed to find the trigger %s\n", trigger_name);
ret = -ENODEV; ret = -ENODEV;
goto error_free_triggername; goto error_free_triggername;
} }
printf("iio trigger number being used is %d\n", trig_num); printf("iio trigger number being used is %d\n", trig_num);
} else
printf("trigger-less mode selected\n");
/* /*
* Parse the files in scan_elements to identify what channels are * Parse the files in scan_elements to identify what channels are
...@@ -250,14 +258,18 @@ int main(int argc, char **argv) ...@@ -250,14 +258,18 @@ int main(int argc, char **argv)
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_triggername; goto error_free_triggername;
} }
printf("%s %s\n", dev_dir_name, trigger_name);
/* Set the device trigger to be the data ready trigger found above */ if (!notrigger) {
ret = write_sysfs_string_and_verify("trigger/current_trigger", printf("%s %s\n", dev_dir_name, trigger_name);
dev_dir_name, /* Set the device trigger to be the data ready trigger found
trigger_name); * above */
if (ret < 0) { ret = write_sysfs_string_and_verify("trigger/current_trigger",
printf("Failed to write current_trigger file\n"); dev_dir_name,
goto error_free_buf_dir_name; trigger_name);
if (ret < 0) {
printf("Failed to write current_trigger file\n");
goto error_free_buf_dir_name;
}
} }
/* Setup ring buffer parameters */ /* Setup ring buffer parameters */
...@@ -327,9 +339,10 @@ int main(int argc, char **argv) ...@@ -327,9 +339,10 @@ int main(int argc, char **argv)
if (ret < 0) if (ret < 0)
goto error_close_buffer_access; goto error_close_buffer_access;
/* Disconnect the trigger - just write a dummy name. */ if (!notrigger)
write_sysfs_string("trigger/current_trigger", /* Disconnect the trigger - just write a dummy name. */
dev_dir_name, "NULL"); write_sysfs_string("trigger/current_trigger",
dev_dir_name, "NULL");
error_close_buffer_access: error_close_buffer_access:
close(fp); close(fp);
......
...@@ -35,6 +35,7 @@ irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private) ...@@ -35,6 +35,7 @@ irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private)
iio_trigger_poll(st->trig); iio_trigger_poll(st->trig);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
return IRQ_WAKE_THREAD; return IRQ_WAKE_THREAD;
} }
......
...@@ -164,7 +164,7 @@ struct st_sensor_transfer_function { ...@@ -164,7 +164,7 @@ struct st_sensor_transfer_function {
}; };
/** /**
* struct st_sensors - ST sensors list * struct st_sensor_settings - ST specific sensor settings
* @wai: Contents of WhoAmI register. * @wai: Contents of WhoAmI register.
* @sensors_supported: List of supported sensors by struct itself. * @sensors_supported: List of supported sensors by struct itself.
* @ch: IIO channels for the sensor. * @ch: IIO channels for the sensor.
...@@ -177,7 +177,7 @@ struct st_sensor_transfer_function { ...@@ -177,7 +177,7 @@ struct st_sensor_transfer_function {
* @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read. * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
* @bootime: samples to discard when sensor passing from power-down to power-up. * @bootime: samples to discard when sensor passing from power-down to power-up.
*/ */
struct st_sensors { struct st_sensor_settings {
u8 wai; u8 wai;
char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME]; char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
struct iio_chan_spec *ch; struct iio_chan_spec *ch;
...@@ -196,7 +196,7 @@ struct st_sensors { ...@@ -196,7 +196,7 @@ struct st_sensors {
* struct st_sensor_data - ST sensor device status * struct st_sensor_data - ST sensor device status
* @dev: Pointer to instance of struct device (I2C or SPI). * @dev: Pointer to instance of struct device (I2C or SPI).
* @trig: The trigger in use by the core driver. * @trig: The trigger in use by the core driver.
* @sensor: Pointer to the current sensor struct in use. * @sensor_settings: Pointer to the specific sensor settings in use.
* @current_fullscale: Maximum range of measure by the sensor. * @current_fullscale: Maximum range of measure by the sensor.
* @vdd: Pointer to sensor's Vdd power supply * @vdd: Pointer to sensor's Vdd power supply
* @vdd_io: Pointer to sensor's Vdd-IO power supply * @vdd_io: Pointer to sensor's Vdd-IO power supply
...@@ -213,7 +213,7 @@ struct st_sensors { ...@@ -213,7 +213,7 @@ struct st_sensors {
struct st_sensor_data { struct st_sensor_data {
struct device *dev; struct device *dev;
struct iio_trigger *trig; struct iio_trigger *trig;
struct st_sensors *sensor; struct st_sensor_settings *sensor_settings;
struct st_sensor_fullscale_avl *current_fullscale; struct st_sensor_fullscale_avl *current_fullscale;
struct regulator *vdd; struct regulator *vdd;
struct regulator *vdd_io; struct regulator *vdd_io;
...@@ -279,7 +279,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev, ...@@ -279,7 +279,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *ch, int *val); struct iio_chan_spec const *ch, int *val);
int st_sensors_check_device_support(struct iio_dev *indio_dev, int st_sensors_check_device_support(struct iio_dev *indio_dev,
int num_sensors_list, const struct st_sensors *sensors); int num_sensors_list, const struct st_sensor_settings *sensor_settings);
ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
struct device_attribute *attr, char *buf); struct device_attribute *attr, char *buf);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/iio/types.h> #include <linux/iio/types.h>
#include <linux/of.h>
/* IIO TODO LIST */ /* IIO TODO LIST */
/* /*
* Provide means of adjusting timer accuracy. * Provide means of adjusting timer accuracy.
...@@ -326,6 +327,11 @@ struct iio_dev; ...@@ -326,6 +327,11 @@ struct iio_dev;
* @update_scan_mode: function to configure device and scan buffer when * @update_scan_mode: function to configure device and scan buffer when
* channels have changed * channels have changed
* @debugfs_reg_access: function to read or write register value of device * @debugfs_reg_access: function to read or write register value of device
* @of_xlate: function pointer to obtain channel specifier index.
* When #iio-cells is greater than '0', the driver could
* provide a custom of_xlate function that reads the
* *args* and returns the appropriate index in registered
* IIO channels array.
**/ **/
struct iio_info { struct iio_info {
struct module *driver_module; struct module *driver_module;
...@@ -385,6 +391,8 @@ struct iio_info { ...@@ -385,6 +391,8 @@ struct iio_info {
int (*debugfs_reg_access)(struct iio_dev *indio_dev, int (*debugfs_reg_access)(struct iio_dev *indio_dev,
unsigned reg, unsigned writeval, unsigned reg, unsigned writeval,
unsigned *readval); unsigned *readval);
int (*of_xlate)(struct iio_dev *indio_dev,
const struct of_phandle_args *iiospec);
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment