Third set of new functionality and cleanups for IIO in the 3.13 cycle.
Driver New Functionality * MXS - new interrupt driven touch screen support for i.MX23/28. Old polled implementation dropped. Driver Cleanups * Some spi_sync boilerplate dropped by using spi_sync_transfer * Some switching of drivers to the fractional type for scale reading. Moves the ugly calculation into one place. * Fix the documentation for *_voltage_scale which is never been correct or as implemented in any driver. * HID sensor hub and children : Open the sensor hub only when someone cares. * hmc5843 - various minor -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) iQIcBAABAgAGBQJSUarRAAoJEFSFNJnE9BaIFw4P/j5zve2C/I2v/00mzH2W/zvo clpQ7JKH4wQMmBisua9pHyaE40sErNjoX2XVan7alTr901HiUoxSLmik7Jvh05C6 uwtIFdu0oRNrU2T/kHWYj/xMPPFV3OxATAO7Nn/HNvxXPbGbRUkF7P1+bker+IjF zKMZSZCUrfG2Sqs9+jtvpB6lKXNG6ndkNXPAyaqlRaJuYd3ea6EvowOVvGBAoNnM bU4Y+juHcWW3MieVeBiuIMU7GEyXXDQRjIt4x7gkRWTn2tY0eeBT8yh3V+18vsNQ sp24yCUVR5/3hDb86izGMYo+3bv2XycqGOdvBdPa2QfNIkgdVjd+MvRhqcol1W6o MaNurmmvzYOORuo1dWu9M44uQuo9HxO5tf9c1vemxxFkiHAMKTiG2JRphl+aofrB xxbI6g8XypPO8DlVmIGPScHVtD8qf1c3kJtTXO634zwhKnftL4h9ROox0xajBRlg JPDXtkceIomky76zPjKq+9g68QRyd/TqIQl9l6EdTsAdcN2kiXkt3PDOM8FWh0sn 6dhxIVQ6WQHRZ0oWk0iaMpTwyekeRZY6dHVsnOld/Lw4v6B3yxEWb3TFBMeJ21m8 m/vC8e/Hw1DFtxjqDi4Nlkb4krlbaj1cR/xhIt8w4fU9Hdcj+3rdTZiDNBFn19EI AprCOdGOYunw8CrhRnXs =g8ZE -----END PGP SIGNATURE----- Merge tag 'iio-for-3.13c' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Third set of new functionality and cleanups for IIO in the 3.13 cycle. Driver New Functionality * MXS - new interrupt driven touch screen support for i.MX23/28. Old polled implementation dropped. Driver Cleanups * Some spi_sync boilerplate dropped by using spi_sync_transfer * Some switching of drivers to the fractional type for scale reading. Moves the ugly calculation into one place. * Fix the documentation for *_voltage_scale which is never been correct or as implemented in any driver. * HID sensor hub and children : Open the sensor hub only when someone cares. * hmc5843 - various minor
This commit is contained in:
commit
eb3e6ae960
@ -79,7 +79,7 @@ Description:
|
|||||||
correspond to externally available input one of the named
|
correspond to externally available input one of the named
|
||||||
versions may be used. The number must always be specified and
|
versions may be used. The number must always be specified and
|
||||||
unique to allow association with event codes. Units after
|
unique to allow association with event codes. Units after
|
||||||
application of scale and offset are microvolts.
|
application of scale and offset are millivolts.
|
||||||
|
|
||||||
What: /sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_raw
|
What: /sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_raw
|
||||||
KernelVersion: 2.6.35
|
KernelVersion: 2.6.35
|
||||||
@ -90,7 +90,7 @@ Description:
|
|||||||
physically equivalent inputs when non differential readings are
|
physically equivalent inputs when non differential readings are
|
||||||
separately available. In differential only parts, then all that
|
separately available. In differential only parts, then all that
|
||||||
is required is a consistent labeling. Units after application
|
is required is a consistent labeling. Units after application
|
||||||
of scale and offset are microvolts.
|
of scale and offset are millivolts.
|
||||||
|
|
||||||
What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw
|
What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw
|
||||||
KernelVersion: 3.2
|
KernelVersion: 3.2
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
* Freescale i.MX28 LRADC device driver
|
* Freescale i.MX28 LRADC device driver
|
||||||
|
|
||||||
Required properties:
|
Required properties:
|
||||||
- compatible: Should be "fsl,imx28-lradc"
|
- compatible: Should be "fsl,imx23-lradc" for i.MX23 SoC and "fsl,imx28-lradc"
|
||||||
|
for i.MX28 SoC
|
||||||
- reg: Address and length of the register set for the device
|
- reg: Address and length of the register set for the device
|
||||||
- interrupts: Should contain the LRADC interrupts
|
- interrupts: Should contain the LRADC interrupts
|
||||||
|
|
||||||
@ -9,13 +10,38 @@ Optional properties:
|
|||||||
- fsl,lradc-touchscreen-wires: Number of wires used to connect the touchscreen
|
- fsl,lradc-touchscreen-wires: Number of wires used to connect the touchscreen
|
||||||
to LRADC. Valid value is either 4 or 5. If this
|
to LRADC. Valid value is either 4 or 5. If this
|
||||||
property is not present, then the touchscreen is
|
property is not present, then the touchscreen is
|
||||||
disabled.
|
disabled. 5 wires is valid for i.MX28 SoC only.
|
||||||
|
- fsl,ave-ctrl: number of samples per direction to calculate an average value.
|
||||||
|
Allowed value is 1 ... 31, default is 4
|
||||||
|
- fsl,ave-delay: delay between consecutive samples. Allowed value is
|
||||||
|
1 ... 2047. It is used if 'fsl,ave-ctrl' > 1, counts at
|
||||||
|
2 kHz and its default is 2 (= 1 ms)
|
||||||
|
- fsl,settling: delay between plate switch to next sample. Allowed value is
|
||||||
|
1 ... 2047. It counts at 2 kHz and its default is
|
||||||
|
10 (= 5 ms)
|
||||||
|
|
||||||
Examples:
|
Example for i.MX23 SoC:
|
||||||
|
|
||||||
|
lradc@80050000 {
|
||||||
|
compatible = "fsl,imx23-lradc";
|
||||||
|
reg = <0x80050000 0x2000>;
|
||||||
|
interrupts = <36 37 38 39 40 41 42 43 44>;
|
||||||
|
status = "okay";
|
||||||
|
fsl,lradc-touchscreen-wires = <4>;
|
||||||
|
fsl,ave-ctrl = <4>;
|
||||||
|
fsl,ave-delay = <2>;
|
||||||
|
fsl,settling = <10>;
|
||||||
|
};
|
||||||
|
|
||||||
|
Example for i.MX28 SoC:
|
||||||
|
|
||||||
lradc@80050000 {
|
lradc@80050000 {
|
||||||
compatible = "fsl,imx28-lradc";
|
compatible = "fsl,imx28-lradc";
|
||||||
reg = <0x80050000 0x2000>;
|
reg = <0x80050000 0x2000>;
|
||||||
interrupts = <10 14 15 16 17 18 19
|
interrupts = <10 14 15 16 17 18 19 20 21 22 23 24 25>;
|
||||||
20 21 22 23 24 25>;
|
status = "okay";
|
||||||
|
fsl,lradc-touchscreen-wires = <5>;
|
||||||
|
fsl,ave-ctrl = <4>;
|
||||||
|
fsl,ave-delay = <2>;
|
||||||
|
fsl,settling = <10>;
|
||||||
};
|
};
|
||||||
|
@ -430,6 +430,7 @@
|
|||||||
reg = <0x80050000 0x2000>;
|
reg = <0x80050000 0x2000>;
|
||||||
interrupts = <36 37 38 39 40 41 42 43 44>;
|
interrupts = <36 37 38 39 40 41 42 43 44>;
|
||||||
status = "disabled";
|
status = "disabled";
|
||||||
|
clocks = <&clks 26>;
|
||||||
};
|
};
|
||||||
|
|
||||||
spdif@80054000 {
|
spdif@80054000 {
|
||||||
|
@ -183,6 +183,10 @@
|
|||||||
|
|
||||||
lradc@80050000 {
|
lradc@80050000 {
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
fsl,lradc-touchscreen-wires = <4>;
|
||||||
|
fsl,ave-ctrl = <4>;
|
||||||
|
fsl,ave-delay = <2>;
|
||||||
|
fsl,settling = <10>;
|
||||||
};
|
};
|
||||||
|
|
||||||
i2c0: i2c@80058000 {
|
i2c0: i2c@80058000 {
|
||||||
|
@ -902,6 +902,7 @@
|
|||||||
interrupts = <10 14 15 16 17 18 19
|
interrupts = <10 14 15 16 17 18 19
|
||||||
20 21 22 23 24 25>;
|
20 21 22 23 24 25>;
|
||||||
status = "disabled";
|
status = "disabled";
|
||||||
|
clocks = <&clks 41>;
|
||||||
};
|
};
|
||||||
|
|
||||||
spdif: spdif@80054000 {
|
spdif: spdif@80054000 {
|
||||||
|
@ -465,6 +465,39 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
|
||||||
|
|
||||||
|
mutex_lock(&data->mutex);
|
||||||
|
if (!hsdev->ref_cnt) {
|
||||||
|
ret = hid_hw_open(hsdev->hdev);
|
||||||
|
if (ret) {
|
||||||
|
hid_err(hsdev->hdev, "failed to open hid device\n");
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hsdev->ref_cnt++;
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(sensor_hub_device_open);
|
||||||
|
|
||||||
|
void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev)
|
||||||
|
{
|
||||||
|
struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
|
||||||
|
|
||||||
|
mutex_lock(&data->mutex);
|
||||||
|
hsdev->ref_cnt--;
|
||||||
|
if (!hsdev->ref_cnt)
|
||||||
|
hid_hw_close(hsdev->hdev);
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(sensor_hub_device_close);
|
||||||
|
|
||||||
static int sensor_hub_probe(struct hid_device *hdev,
|
static int sensor_hub_probe(struct hid_device *hdev,
|
||||||
const struct hid_device_id *id)
|
const struct hid_device_id *id)
|
||||||
{
|
{
|
||||||
@ -506,12 +539,6 @@ static int sensor_hub_probe(struct hid_device *hdev,
|
|||||||
hid_err(hdev, "hw start failed\n");
|
hid_err(hdev, "hw start failed\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = hid_hw_open(hdev);
|
|
||||||
if (ret) {
|
|
||||||
hid_err(hdev, "failed to open input interrupt pipe\n");
|
|
||||||
goto err_stop_hw;
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_LIST_HEAD(&sd->dyn_callback_list);
|
INIT_LIST_HEAD(&sd->dyn_callback_list);
|
||||||
sd->hid_sensor_client_cnt = 0;
|
sd->hid_sensor_client_cnt = 0;
|
||||||
report_enum = &hdev->report_enum[HID_INPUT_REPORT];
|
report_enum = &hdev->report_enum[HID_INPUT_REPORT];
|
||||||
@ -520,7 +547,7 @@ static int sensor_hub_probe(struct hid_device *hdev,
|
|||||||
if (dev_cnt > HID_MAX_PHY_DEVICES) {
|
if (dev_cnt > HID_MAX_PHY_DEVICES) {
|
||||||
hid_err(hdev, "Invalid Physical device count\n");
|
hid_err(hdev, "Invalid Physical device count\n");
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto err_close;
|
goto err_stop_hw;
|
||||||
}
|
}
|
||||||
sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt *
|
sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt *
|
||||||
sizeof(struct mfd_cell),
|
sizeof(struct mfd_cell),
|
||||||
@ -528,7 +555,7 @@ static int sensor_hub_probe(struct hid_device *hdev,
|
|||||||
if (sd->hid_sensor_hub_client_devs == NULL) {
|
if (sd->hid_sensor_hub_client_devs == NULL) {
|
||||||
hid_err(hdev, "Failed to allocate memory for mfd cells\n");
|
hid_err(hdev, "Failed to allocate memory for mfd cells\n");
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto err_close;
|
goto err_stop_hw;
|
||||||
}
|
}
|
||||||
list_for_each_entry(report, &report_enum->report_list, list) {
|
list_for_each_entry(report, &report_enum->report_list, list) {
|
||||||
hid_dbg(hdev, "Report id:%x\n", report->id);
|
hid_dbg(hdev, "Report id:%x\n", report->id);
|
||||||
@ -565,8 +592,6 @@ err_free_names:
|
|||||||
for (i = 0; i < sd->hid_sensor_client_cnt ; ++i)
|
for (i = 0; i < sd->hid_sensor_client_cnt ; ++i)
|
||||||
kfree(sd->hid_sensor_hub_client_devs[i].name);
|
kfree(sd->hid_sensor_hub_client_devs[i].name);
|
||||||
kfree(sd->hid_sensor_hub_client_devs);
|
kfree(sd->hid_sensor_hub_client_devs);
|
||||||
err_close:
|
|
||||||
hid_hw_close(hdev);
|
|
||||||
err_stop_hw:
|
err_stop_hw:
|
||||||
hid_hw_stop(hdev);
|
hid_hw_stop(hdev);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
struct ad7266_state {
|
struct ad7266_state {
|
||||||
struct spi_device *spi;
|
struct spi_device *spi;
|
||||||
struct regulator *reg;
|
struct regulator *reg;
|
||||||
unsigned long vref_uv;
|
unsigned long vref_mv;
|
||||||
|
|
||||||
struct spi_transfer single_xfer[3];
|
struct spi_transfer single_xfer[3];
|
||||||
struct spi_message single_msg;
|
struct spi_message single_msg;
|
||||||
@ -156,7 +156,7 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
|
|||||||
struct iio_chan_spec const *chan, int *val, int *val2, long m)
|
struct iio_chan_spec const *chan, int *val, int *val2, long m)
|
||||||
{
|
{
|
||||||
struct ad7266_state *st = iio_priv(indio_dev);
|
struct ad7266_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
unsigned long scale_mv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
@ -174,16 +174,15 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
|
|||||||
|
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->vref_uv * 100);
|
scale_mv = st->vref_mv;
|
||||||
if (st->mode == AD7266_MODE_DIFF)
|
if (st->mode == AD7266_MODE_DIFF)
|
||||||
scale_uv *= 2;
|
scale_mv *= 2;
|
||||||
if (st->range == AD7266_RANGE_2VREF)
|
if (st->range == AD7266_RANGE_2VREF)
|
||||||
scale_uv *= 2;
|
scale_mv *= 2;
|
||||||
|
|
||||||
scale_uv >>= chan->scan_type.realbits;
|
*val = scale_mv;
|
||||||
*val = scale_uv / 100000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
case IIO_CHAN_INFO_OFFSET:
|
case IIO_CHAN_INFO_OFFSET:
|
||||||
if (st->range == AD7266_RANGE_2VREF &&
|
if (st->range == AD7266_RANGE_2VREF &&
|
||||||
st->mode != AD7266_MODE_DIFF)
|
st->mode != AD7266_MODE_DIFF)
|
||||||
@ -414,10 +413,10 @@ static int ad7266_probe(struct spi_device *spi)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error_disable_reg;
|
goto error_disable_reg;
|
||||||
|
|
||||||
st->vref_uv = ret;
|
st->vref_mv = ret / 1000;
|
||||||
} else {
|
} else {
|
||||||
/* Use internal reference */
|
/* Use internal reference */
|
||||||
st->vref_uv = 2500000;
|
st->vref_mv = 2500;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdata) {
|
if (pdata) {
|
||||||
|
@ -127,10 +127,9 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
|
|||||||
} else {
|
} else {
|
||||||
scale_uv = st->chip_info->int_vref_uv;
|
scale_uv = st->chip_info->int_vref_uv;
|
||||||
}
|
}
|
||||||
scale_uv >>= chan->scan_type.realbits;
|
*val = scale_uv / 1000;
|
||||||
*val = scale_uv / 1000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,6 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
struct ad7791_state *st = iio_priv(indio_dev);
|
struct ad7791_state *st = iio_priv(indio_dev);
|
||||||
bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR);
|
bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR);
|
||||||
unsigned long long scale_pv;
|
|
||||||
|
|
||||||
switch (info) {
|
switch (info) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
@ -220,23 +219,26 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,
|
|||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
/* The monitor channel uses an internal reference. */
|
/* The monitor channel uses an internal reference. */
|
||||||
if (chan->address == AD7791_CH_AVDD_MONITOR) {
|
if (chan->address == AD7791_CH_AVDD_MONITOR) {
|
||||||
scale_pv = 5850000000000ULL;
|
/*
|
||||||
|
* The signal is attenuated by a factor of 5 and
|
||||||
|
* compared against a 1.17V internal reference.
|
||||||
|
*/
|
||||||
|
*val = 1170 * 5;
|
||||||
} else {
|
} else {
|
||||||
int voltage_uv;
|
int voltage_uv;
|
||||||
|
|
||||||
voltage_uv = regulator_get_voltage(st->reg);
|
voltage_uv = regulator_get_voltage(st->reg);
|
||||||
if (voltage_uv < 0)
|
if (voltage_uv < 0)
|
||||||
return voltage_uv;
|
return voltage_uv;
|
||||||
scale_pv = (unsigned long long)voltage_uv * 1000000;
|
|
||||||
|
*val = voltage_uv / 1000;
|
||||||
}
|
}
|
||||||
if (unipolar)
|
if (unipolar)
|
||||||
scale_pv >>= chan->scan_type.realbits;
|
*val2 = chan->scan_type.realbits;
|
||||||
else
|
else
|
||||||
scale_pv >>= chan->scan_type.realbits - 1;
|
*val2 = chan->scan_type.realbits - 1;
|
||||||
*val2 = do_div(scale_pv, 1000000000);
|
|
||||||
*val = scale_pv;
|
|
||||||
|
|
||||||
return IIO_VAL_INT_PLUS_NANO;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -366,9 +366,9 @@ static int at91_adc_read_raw(struct iio_dev *idev,
|
|||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
*val = (st->vref_mv * 1000) >> chan->scan_type.realbits;
|
*val = st->vref_mv;
|
||||||
*val2 = 0;
|
*val2 = chan->scan_type.realbits;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,6 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
struct max1363_state *st = iio_priv(indio_dev);
|
struct max1363_state *st = iio_priv(indio_dev);
|
||||||
int ret;
|
int ret;
|
||||||
unsigned long scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
@ -406,10 +405,9 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
|
|||||||
return ret;
|
return ret;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = st->vref_uv >> st->chip_info->bits;
|
*val = st->vref_uv / 1000;
|
||||||
*val = scale_uv / 1000;
|
*val2 = st->chip_info->bits;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,12 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
|
|||||||
struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
|
struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
|
||||||
int state_val;
|
int state_val;
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
if (sensor_hub_device_open(st->hsdev))
|
||||||
|
return -EIO;
|
||||||
|
} else
|
||||||
|
sensor_hub_device_close(st->hsdev);
|
||||||
|
|
||||||
state_val = state ? 1 : 0;
|
state_val = state ? 1 : 0;
|
||||||
if (IS_ENABLED(CONFIG_HID_SENSOR_ENUM_BASE_QUIRKS))
|
if (IS_ENABLED(CONFIG_HID_SENSOR_ENUM_BASE_QUIRKS))
|
||||||
++state_val;
|
++state_val;
|
||||||
|
@ -239,10 +239,9 @@ static int ad5064_read_raw(struct iio_dev *indio_dev,
|
|||||||
if (scale_uv < 0)
|
if (scale_uv < 0)
|
||||||
return scale_uv;
|
return scale_uv;
|
||||||
|
|
||||||
scale_uv = (scale_uv * 100) >> chan->scan_type.realbits;
|
*val = scale_uv / 1000;
|
||||||
*val = scale_uv / 100000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -379,15 +379,14 @@ static int ad5360_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val = ret >> chan->scan_type.shift;
|
*val = ret >> chan->scan_type.shift;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
/* vout = 4 * vref * dac_code */
|
scale_uv = ad5360_get_channel_vref(st, chan->channel);
|
||||||
scale_uv = ad5360_get_channel_vref(st, chan->channel) * 4 * 100;
|
|
||||||
if (scale_uv < 0)
|
if (scale_uv < 0)
|
||||||
return scale_uv;
|
return scale_uv;
|
||||||
|
|
||||||
scale_uv >>= (chan->scan_type.realbits);
|
/* vout = 4 * vref * dac_code */
|
||||||
*val = scale_uv / 100000;
|
*val = scale_uv * 4 / 1000;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
*val2 = chan->scan_type.realbits;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
case IIO_CHAN_INFO_CALIBBIAS:
|
case IIO_CHAN_INFO_CALIBBIAS:
|
||||||
ret = ad5360_read(indio_dev, AD5360_READBACK_OFFSET,
|
ret = ad5360_read(indio_dev, AD5360_READBACK_OFFSET,
|
||||||
chan->address);
|
chan->address);
|
||||||
|
@ -204,7 +204,6 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
|
|||||||
struct iio_chan_spec const *chan, int *val, int *val2, long info)
|
struct iio_chan_spec const *chan, int *val, int *val2, long info)
|
||||||
{
|
{
|
||||||
struct ad5380_state *st = iio_priv(indio_dev);
|
struct ad5380_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (info) {
|
switch (info) {
|
||||||
@ -225,10 +224,9 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
|
|||||||
val -= (1 << chan->scan_type.realbits) / 2;
|
val -= (1 << chan->scan_type.realbits) / 2;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = ((2 * st->vref) >> chan->scan_type.realbits) * 100;
|
*val = 2 * st->vref;
|
||||||
*val = scale_uv / 100000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -271,72 +269,72 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = {
|
|||||||
[ID_AD5380_3] = {
|
[ID_AD5380_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 40,
|
.num_channels = 40,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5380_5] = {
|
[ID_AD5380_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 40,
|
.num_channels = 40,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
[ID_AD5381_3] = {
|
[ID_AD5381_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(12),
|
.channel_template = AD5380_CHANNEL(12),
|
||||||
.num_channels = 16,
|
.num_channels = 16,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5381_5] = {
|
[ID_AD5381_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(12),
|
.channel_template = AD5380_CHANNEL(12),
|
||||||
.num_channels = 16,
|
.num_channels = 16,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
[ID_AD5382_3] = {
|
[ID_AD5382_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 32,
|
.num_channels = 32,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5382_5] = {
|
[ID_AD5382_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 32,
|
.num_channels = 32,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
[ID_AD5383_3] = {
|
[ID_AD5383_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(12),
|
.channel_template = AD5380_CHANNEL(12),
|
||||||
.num_channels = 32,
|
.num_channels = 32,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5383_5] = {
|
[ID_AD5383_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(12),
|
.channel_template = AD5380_CHANNEL(12),
|
||||||
.num_channels = 32,
|
.num_channels = 32,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
[ID_AD5390_3] = {
|
[ID_AD5390_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 16,
|
.num_channels = 16,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5390_5] = {
|
[ID_AD5390_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 16,
|
.num_channels = 16,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
[ID_AD5391_3] = {
|
[ID_AD5391_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(12),
|
.channel_template = AD5380_CHANNEL(12),
|
||||||
.num_channels = 16,
|
.num_channels = 16,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5391_5] = {
|
[ID_AD5391_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(12),
|
.channel_template = AD5380_CHANNEL(12),
|
||||||
.num_channels = 16,
|
.num_channels = 16,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
[ID_AD5392_3] = {
|
[ID_AD5392_3] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 8,
|
.num_channels = 8,
|
||||||
.int_vref = 1250000,
|
.int_vref = 1250,
|
||||||
},
|
},
|
||||||
[ID_AD5392_5] = {
|
[ID_AD5392_5] = {
|
||||||
.channel_template = AD5380_CHANNEL(14),
|
.channel_template = AD5380_CHANNEL(14),
|
||||||
.num_channels = 8,
|
.num_channels = 8,
|
||||||
.int_vref = 2500000,
|
.int_vref = 2500,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -395,7 +393,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st->chip_info->int_vref == 2500000)
|
if (st->chip_info->int_vref == 2500)
|
||||||
ctrl |= AD5380_CTRL_INT_VREF_2V5;
|
ctrl |= AD5380_CTRL_INT_VREF_2V5;
|
||||||
|
|
||||||
st->vref_reg = devm_regulator_get(dev, "vref");
|
st->vref_reg = devm_regulator_get(dev, "vref");
|
||||||
@ -411,7 +409,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error_disable_reg;
|
goto error_disable_reg;
|
||||||
|
|
||||||
st->vref = ret;
|
st->vref = ret / 1000;
|
||||||
} else {
|
} else {
|
||||||
st->vref = st->chip_info->int_vref;
|
st->vref = st->chip_info->int_vref;
|
||||||
ctrl |= AD5380_CTRL_INT_VREF_EN;
|
ctrl |= AD5380_CTRL_INT_VREF_EN;
|
||||||
|
@ -281,18 +281,11 @@ static inline unsigned int ad5421_get_offset(struct ad5421_state *st)
|
|||||||
return (min * (1 << 16)) / (max - min);
|
return (min * (1 << 16)) / (max - min);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int ad5421_get_scale(struct ad5421_state *st)
|
|
||||||
{
|
|
||||||
unsigned int min, max;
|
|
||||||
|
|
||||||
ad5421_get_current_min_max(st, &min, &max);
|
|
||||||
return ((max - min) * 1000) / (1 << 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ad5421_read_raw(struct iio_dev *indio_dev,
|
static int ad5421_read_raw(struct iio_dev *indio_dev,
|
||||||
struct iio_chan_spec const *chan, int *val, int *val2, long m)
|
struct iio_chan_spec const *chan, int *val, int *val2, long m)
|
||||||
{
|
{
|
||||||
struct ad5421_state *st = iio_priv(indio_dev);
|
struct ad5421_state *st = iio_priv(indio_dev);
|
||||||
|
unsigned int min, max;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (chan->type != IIO_CURRENT)
|
if (chan->type != IIO_CURRENT)
|
||||||
@ -306,9 +299,10 @@ static int ad5421_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val = ret;
|
*val = ret;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
*val = 0;
|
ad5421_get_current_min_max(st, &min, &max);
|
||||||
*val2 = ad5421_get_scale(st);
|
*val = max - min;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
*val2 = (1 << 16) * 1000;
|
||||||
|
return IIO_VAL_FRACTIONAL;
|
||||||
case IIO_CHAN_INFO_OFFSET:
|
case IIO_CHAN_INFO_OFFSET:
|
||||||
*val = ad5421_get_offset(st);
|
*val = ad5421_get_offset(st);
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
@ -163,18 +163,15 @@ static int ad5446_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct ad5446_state *st = iio_priv(indio_dev);
|
struct ad5446_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
*val = st->cached_val;
|
*val = st->cached_val;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->vref_mv * 1000) >> chan->scan_type.realbits;
|
*val = st->vref_mv;
|
||||||
*val = scale_uv / 1000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,6 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
|
|||||||
{
|
{
|
||||||
struct ad5449 *st = iio_priv(indio_dev);
|
struct ad5449 *st = iio_priv(indio_dev);
|
||||||
int ret;
|
int ret;
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer t[] = {
|
struct spi_transfer t[] = {
|
||||||
{
|
{
|
||||||
.tx_buf = &st->data[0],
|
.tx_buf = &st->data[0],
|
||||||
@ -114,15 +113,11 @@ static int ad5449_read(struct iio_dev *indio_dev, unsigned int addr,
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
spi_message_init(&msg);
|
|
||||||
spi_message_add_tail(&t[0], &msg);
|
|
||||||
spi_message_add_tail(&t[1], &msg);
|
|
||||||
|
|
||||||
mutex_lock(&indio_dev->mlock);
|
mutex_lock(&indio_dev->mlock);
|
||||||
st->data[0] = cpu_to_be16(addr << 12);
|
st->data[0] = cpu_to_be16(addr << 12);
|
||||||
st->data[1] = cpu_to_be16(AD5449_CMD_NOOP);
|
st->data[1] = cpu_to_be16(AD5449_CMD_NOOP);
|
||||||
|
|
||||||
ret = spi_sync(st->spi, &msg);
|
ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
|
@ -100,7 +100,6 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct ad5504_state *st = iio_priv(indio_dev);
|
struct ad5504_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
@ -113,11 +112,9 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,
|
|||||||
|
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->vref_mv * 1000) >> chan->scan_type.realbits;
|
*val = st->vref_mv;
|
||||||
*val = scale_uv / 1000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -50,15 +50,12 @@ static int ad5624r_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct ad5624r_state *st = iio_priv(indio_dev);
|
struct ad5624r_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->vref_mv * 1000) >> chan->scan_type.realbits;
|
*val = st->vref_mv;
|
||||||
*val = scale_uv / 1000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,6 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct ad5686_state *st = iio_priv(indio_dev);
|
struct ad5686_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
@ -214,12 +213,9 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val = ret;
|
*val = ret;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->vref_mv * 100000)
|
*val = st->vref_mv;
|
||||||
>> (chan->scan_type.realbits);
|
*val2 = chan->scan_type.realbits;
|
||||||
*val = scale_uv / 100000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -253,15 +253,6 @@ static inline int ad5755_get_offset(struct ad5755_state *st,
|
|||||||
return (min * (1 << chan->scan_type.realbits)) / (max - min);
|
return (min * (1 << chan->scan_type.realbits)) / (max - min);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ad5755_get_scale(struct ad5755_state *st,
|
|
||||||
struct iio_chan_spec const *chan)
|
|
||||||
{
|
|
||||||
int min, max;
|
|
||||||
|
|
||||||
ad5755_get_min_max(st, chan, &min, &max);
|
|
||||||
return ((max - min) * 1000000000ULL) >> chan->scan_type.realbits;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ad5755_chan_reg_info(struct ad5755_state *st,
|
static int ad5755_chan_reg_info(struct ad5755_state *st,
|
||||||
struct iio_chan_spec const *chan, long info, bool write,
|
struct iio_chan_spec const *chan, long info, bool write,
|
||||||
unsigned int *reg, unsigned int *shift, unsigned int *offset)
|
unsigned int *reg, unsigned int *shift, unsigned int *offset)
|
||||||
@ -303,13 +294,15 @@ static int ad5755_read_raw(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
struct ad5755_state *st = iio_priv(indio_dev);
|
struct ad5755_state *st = iio_priv(indio_dev);
|
||||||
unsigned int reg, shift, offset;
|
unsigned int reg, shift, offset;
|
||||||
|
int min, max;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (info) {
|
switch (info) {
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
*val = 0;
|
ad5755_get_min_max(st, chan, &min, &max);
|
||||||
*val2 = ad5755_get_scale(st, chan);
|
*val = max - min;
|
||||||
return IIO_VAL_INT_PLUS_NANO;
|
*val2 = chan->scan_type.realbits;
|
||||||
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
case IIO_CHAN_INFO_OFFSET:
|
case IIO_CHAN_INFO_OFFSET:
|
||||||
*val = ad5755_get_offset(st, chan);
|
*val = ad5755_get_offset(st, chan);
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
@ -217,7 +217,6 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
|
|||||||
struct iio_chan_spec const *chan, int *val, int *val2, long info)
|
struct iio_chan_spec const *chan, int *val, int *val2, long info)
|
||||||
{
|
{
|
||||||
struct ad5764_state *st = iio_priv(indio_dev);
|
struct ad5764_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
unsigned int reg;
|
unsigned int reg;
|
||||||
int vref;
|
int vref;
|
||||||
int ret;
|
int ret;
|
||||||
@ -245,15 +244,14 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val = sign_extend32(*val, 5);
|
*val = sign_extend32(*val, 5);
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
/* vout = 4 * vref + ((dac_code / 65535) - 0.5) */
|
/* vout = 4 * vref + ((dac_code / 65536) - 0.5) */
|
||||||
vref = ad5764_get_channel_vref(st, chan->channel);
|
vref = ad5764_get_channel_vref(st, chan->channel);
|
||||||
if (vref < 0)
|
if (vref < 0)
|
||||||
return vref;
|
return vref;
|
||||||
|
|
||||||
scale_uv = (vref * 4 * 100) >> chan->scan_type.realbits;
|
*val = vref * 4 / 1000;
|
||||||
*val = scale_uv / 100000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
case IIO_CHAN_INFO_OFFSET:
|
case IIO_CHAN_INFO_OFFSET:
|
||||||
*val = -(1 << chan->scan_type.realbits) / 2;
|
*val = -(1 << chan->scan_type.realbits) / 2;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
@ -270,9 +270,9 @@ static int ad5791_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val >>= chan->scan_type.shift;
|
*val >>= chan->scan_type.shift;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
*val = 0;
|
*val = st->vref_mv;
|
||||||
*val2 = (((u64)st->vref_mv) * 1000000ULL) >> chan->scan_type.realbits;
|
*val2 = (1 << chan->scan_type.realbits) - 1;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
return IIO_VAL_FRACTIONAL;
|
||||||
case IIO_CHAN_INFO_OFFSET:
|
case IIO_CHAN_INFO_OFFSET:
|
||||||
val64 = (((u64)st->vref_neg_mv) << chan->scan_type.realbits);
|
val64 = (((u64)st->vref_neg_mv) << chan->scan_type.realbits);
|
||||||
do_div(val64, st->vref_mv);
|
do_div(val64, st->vref_mv);
|
||||||
|
@ -82,15 +82,13 @@ static int max517_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct max517_data *data = iio_priv(indio_dev);
|
struct max517_data *data = iio_priv(indio_dev);
|
||||||
unsigned int scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
/* Corresponds to Vref / 2^(bits) */
|
/* Corresponds to Vref / 2^(bits) */
|
||||||
scale_uv = (data->vref_mv[chan->channel] * 1000) >> 8;
|
*val = data->vref_mv[chan->channel];
|
||||||
*val = scale_uv / 1000000;
|
*val2 = 8;
|
||||||
*val2 = scale_uv % 1000000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -239,17 +239,15 @@ static int mcp4725_read_raw(struct iio_dev *indio_dev,
|
|||||||
int *val, int *val2, long mask)
|
int *val, int *val2, long mask)
|
||||||
{
|
{
|
||||||
struct mcp4725_data *data = iio_priv(indio_dev);
|
struct mcp4725_data *data = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
|
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
*val = data->dac_value;
|
*val = data->dac_value;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (data->vref_mv * 1000) >> 12;
|
*val = data->vref_mv;
|
||||||
*val = scale_uv / 1000000;
|
*val2 = 12;
|
||||||
*val2 = scale_uv % 1000000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,6 @@ static int adis16080_read_sample(struct iio_dev *indio_dev,
|
|||||||
u16 addr, int *val)
|
u16 addr, int *val)
|
||||||
{
|
{
|
||||||
struct adis16080_state *st = iio_priv(indio_dev);
|
struct adis16080_state *st = iio_priv(indio_dev);
|
||||||
struct spi_message m;
|
|
||||||
int ret;
|
int ret;
|
||||||
struct spi_transfer t[] = {
|
struct spi_transfer t[] = {
|
||||||
{
|
{
|
||||||
@ -66,11 +65,7 @@ static int adis16080_read_sample(struct iio_dev *indio_dev,
|
|||||||
|
|
||||||
st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE);
|
st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE);
|
||||||
|
|
||||||
spi_message_init(&m);
|
ret = spi_sync_transfer(st->us, t, ARRAY_SIZE(t));
|
||||||
spi_message_add_tail(&t[0], &m);
|
|
||||||
spi_message_add_tail(&t[1], &m);
|
|
||||||
|
|
||||||
ret = spi_sync(st->us, &m);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
*val = sign_extend32(be16_to_cpu(st->buf), 11);
|
*val = sign_extend32(be16_to_cpu(st->buf), 11);
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ static int adis16130_spi_read(struct iio_dev *indio_dev, u8 reg_addr, u32 *val)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct adis16130_state *st = iio_priv(indio_dev);
|
struct adis16130_state *st = iio_priv(indio_dev);
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfer = {
|
struct spi_transfer xfer = {
|
||||||
.tx_buf = st->buf,
|
.tx_buf = st->buf,
|
||||||
.rx_buf = st->buf,
|
.rx_buf = st->buf,
|
||||||
@ -59,10 +58,7 @@ static int adis16130_spi_read(struct iio_dev *indio_dev, u8 reg_addr, u32 *val)
|
|||||||
st->buf[0] = ADIS16130_CON_RD | reg_addr;
|
st->buf[0] = ADIS16130_CON_RD | reg_addr;
|
||||||
st->buf[1] = st->buf[2] = st->buf[3] = 0;
|
st->buf[1] = st->buf[2] = st->buf[3] = 0;
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->us, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->us, &msg);
|
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
*val = (st->buf[1] << 16) | (st->buf[2] << 8) | st->buf[3];
|
*val = (st->buf[1] << 16) | (st->buf[2] << 8) | st->buf[3];
|
||||||
mutex_unlock(&st->buf_lock);
|
mutex_unlock(&st->buf_lock);
|
||||||
|
@ -90,7 +90,6 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
|
|||||||
u8 reg_address,
|
u8 reg_address,
|
||||||
u16 *val)
|
u16 *val)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct adxrs450_state *st = iio_priv(indio_dev);
|
struct adxrs450_state *st = iio_priv(indio_dev);
|
||||||
u32 tx;
|
u32 tx;
|
||||||
int ret;
|
int ret;
|
||||||
@ -114,10 +113,7 @@ static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
|
|||||||
tx |= ADXRS450_P;
|
tx |= ADXRS450_P;
|
||||||
|
|
||||||
st->tx = cpu_to_be32(tx);
|
st->tx = cpu_to_be32(tx);
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
|
||||||
spi_message_add_tail(&xfers[0], &msg);
|
|
||||||
spi_message_add_tail(&xfers[1], &msg);
|
|
||||||
ret = spi_sync(st->us, &msg);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
|
dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
|
||||||
reg_address);
|
reg_address);
|
||||||
@ -169,7 +165,6 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
|
|||||||
**/
|
**/
|
||||||
static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val)
|
static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct adxrs450_state *st = iio_priv(indio_dev);
|
struct adxrs450_state *st = iio_priv(indio_dev);
|
||||||
int ret;
|
int ret;
|
||||||
struct spi_transfer xfers[] = {
|
struct spi_transfer xfers[] = {
|
||||||
@ -188,10 +183,7 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val)
|
|||||||
mutex_lock(&st->buf_lock);
|
mutex_lock(&st->buf_lock);
|
||||||
st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA);
|
st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA);
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
|
||||||
spi_message_add_tail(&xfers[0], &msg);
|
|
||||||
spi_message_add_tail(&xfers[1], &msg);
|
|
||||||
ret = spi_sync(st->us, &msg);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&st->us->dev, "Problem while reading sensor data\n");
|
dev_err(&st->us->dev, "Problem while reading sensor data\n");
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
@ -275,6 +275,12 @@ static int hid_time_probe(struct platform_device *pdev)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = sensor_hub_device_open(hsdev);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(&pdev->dev, "failed to open sensor hub device!\n");
|
||||||
|
goto err_open;
|
||||||
|
}
|
||||||
|
|
||||||
time_state->rtc = devm_rtc_device_register(&pdev->dev,
|
time_state->rtc = devm_rtc_device_register(&pdev->dev,
|
||||||
"hid-sensor-time", &hid_time_rtc_ops,
|
"hid-sensor-time", &hid_time_rtc_ops,
|
||||||
THIS_MODULE);
|
THIS_MODULE);
|
||||||
@ -282,17 +288,24 @@ static int hid_time_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR_OR_NULL(time_state->rtc)) {
|
if (IS_ERR_OR_NULL(time_state->rtc)) {
|
||||||
ret = time_state->rtc ? PTR_ERR(time_state->rtc) : -ENODEV;
|
ret = time_state->rtc ? PTR_ERR(time_state->rtc) : -ENODEV;
|
||||||
time_state->rtc = NULL;
|
time_state->rtc = NULL;
|
||||||
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
|
|
||||||
dev_err(&pdev->dev, "rtc device register failed!\n");
|
dev_err(&pdev->dev, "rtc device register failed!\n");
|
||||||
|
goto err_rtc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
err_rtc:
|
||||||
|
sensor_hub_device_close(hsdev);
|
||||||
|
err_open:
|
||||||
|
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hid_time_remove(struct platform_device *pdev)
|
static int hid_time_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
|
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
|
||||||
|
|
||||||
|
sensor_hub_device_close(hsdev);
|
||||||
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
|
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -13,6 +13,17 @@ Would be nice
|
|||||||
3) Expand device set. Lots of other maxim adc's have very
|
3) Expand device set. Lots of other maxim adc's have very
|
||||||
similar interfaces.
|
similar interfaces.
|
||||||
|
|
||||||
|
MXS LRADC driver:
|
||||||
|
This is a classic MFD device as it combines the following subdevices
|
||||||
|
- touchscreen controller (input subsystem related device)
|
||||||
|
- general purpose ADC channels
|
||||||
|
- battery voltage monitor (power subsystem related device)
|
||||||
|
- die temperature monitor (thermal management)
|
||||||
|
|
||||||
|
At least the battery voltage and die temperature feature is required in-kernel
|
||||||
|
by a driver of the SoC's battery charging unit to avoid any damage to the
|
||||||
|
silicon and the battery.
|
||||||
|
|
||||||
TSL2561
|
TSL2561
|
||||||
Would be nice
|
Would be nice
|
||||||
1) Open question of userspace vs kernel space balance when
|
1) Open question of userspace vs kernel space balance when
|
||||||
|
@ -102,7 +102,6 @@ static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev,
|
|||||||
int addr)
|
int addr)
|
||||||
{
|
{
|
||||||
struct adis16220_state *st = iio_priv(indio_dev);
|
struct adis16220_state *st = iio_priv(indio_dev);
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfers[] = {
|
struct spi_transfer xfers[] = {
|
||||||
{
|
{
|
||||||
.tx_buf = st->tx,
|
.tx_buf = st->tx,
|
||||||
@ -147,10 +146,7 @@ static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev,
|
|||||||
}
|
}
|
||||||
xfers[1].len = count;
|
xfers[1].len = count;
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->adis.spi, xfers, ARRAY_SIZE(xfers));
|
||||||
spi_message_add_tail(&xfers[0], &msg);
|
|
||||||
spi_message_add_tail(&xfers[1], &msg);
|
|
||||||
ret = spi_sync(st->adis.spi, &msg);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|
||||||
mutex_unlock(&st->buf_lock);
|
mutex_unlock(&st->buf_lock);
|
||||||
|
@ -783,7 +783,6 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct ad7280_state *st = iio_priv(indio_dev);
|
struct ad7280_state *st = iio_priv(indio_dev);
|
||||||
unsigned int scale_uv;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
@ -804,13 +803,12 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
|
|||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6)
|
if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6)
|
||||||
scale_uv = (4000 * 1000) >> AD7280A_BITS;
|
*val = 4000;
|
||||||
else
|
else
|
||||||
scale_uv = (5000 * 1000) >> AD7280A_BITS;
|
*val = 5000;
|
||||||
|
|
||||||
*val = scale_uv / 1000;
|
*val2 = AD7280A_BITS;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,6 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct ad7606_state *st = iio_priv(indio_dev);
|
struct ad7606_state *st = iio_priv(indio_dev);
|
||||||
unsigned int scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
@ -101,11 +100,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val = (short) ret;
|
*val = (short) ret;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->range * 1000 * 2)
|
*val = st->range * 2;
|
||||||
>> st->chip_info->channels[0].scan_type.realbits;
|
*val2 = st->chip_info->channels[0].scan_type.realbits;
|
||||||
*val = scale_uv / 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -90,17 +90,14 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
|
|||||||
long m)
|
long m)
|
||||||
{
|
{
|
||||||
struct ad7780_state *st = iio_priv(indio_dev);
|
struct ad7780_state *st = iio_priv(indio_dev);
|
||||||
unsigned long scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
return ad_sigma_delta_single_conversion(indio_dev, chan, val);
|
return ad_sigma_delta_single_conversion(indio_dev, chan, val);
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->int_vref_mv * 100000 * st->gain)
|
*val = st->int_vref_mv * st->gain;
|
||||||
>> (chan->scan_type.realbits - 1);
|
*val2 = chan->scan_type.realbits - 1;
|
||||||
*val = scale_uv / 100000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
*val2 = (scale_uv % 100000) * 10;
|
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
case IIO_CHAN_INFO_OFFSET:
|
case IIO_CHAN_INFO_OFFSET:
|
||||||
*val -= (1 << (chan->scan_type.realbits - 1));
|
*val -= (1 << (chan->scan_type.realbits - 1));
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
@ -163,7 +163,6 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct ad799x_state *st = iio_priv(indio_dev);
|
struct ad799x_state *st = iio_priv(indio_dev);
|
||||||
unsigned int scale_uv;
|
|
||||||
|
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
@ -180,10 +179,9 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
|
|||||||
RES_MASK(chan->scan_type.realbits);
|
RES_MASK(chan->scan_type.realbits);
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_uv = (st->int_vref_mv * 1000) >> chan->scan_type.realbits;
|
*val = st->int_vref_mv;
|
||||||
*val = scale_uv / 1000;
|
*val2 = chan->scan_type.realbits;
|
||||||
*val2 = (scale_uv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -168,10 +168,9 @@ static int spear_read_raw(struct iio_dev *indio_dev,
|
|||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
scale_mv = (info->vref_external * 1000) >> DATA_BITS;
|
*val = info->vref_external;
|
||||||
*val = scale_mv / 1000;
|
*val2 = DATA_BITS;
|
||||||
*val2 = (scale_mv % 1000) * 1000;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -656,20 +656,21 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
|
|||||||
switch (chan->type) {
|
switch (chan->type) {
|
||||||
case IIO_CAPACITANCE:
|
case IIO_CAPACITANCE:
|
||||||
/* 8.192pf / 2^24 */
|
/* 8.192pf / 2^24 */
|
||||||
*val2 = 488;
|
|
||||||
*val = 0;
|
*val = 0;
|
||||||
|
*val2 = 488;
|
||||||
|
ret = IIO_VAL_INT_PLUS_NANO;
|
||||||
break;
|
break;
|
||||||
case IIO_VOLTAGE:
|
case IIO_VOLTAGE:
|
||||||
/* 1170mV / 2^23 */
|
/* 1170mV / 2^23 */
|
||||||
*val2 = 139475;
|
*val = 1170;
|
||||||
*val = 0;
|
*val2 = 23;
|
||||||
|
ret = IIO_VAL_FRACTIONAL_LOG2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = IIO_VAL_INT_PLUS_NANO;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
@ -67,7 +67,6 @@ static ssize_t ad9852_set_parameter(struct device *dev,
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfer;
|
struct spi_transfer xfer;
|
||||||
int ret;
|
int ret;
|
||||||
struct ad9852_config *config = (struct ad9852_config *)buf;
|
struct ad9852_config *config = (struct ad9852_config *)buf;
|
||||||
@ -78,99 +77,77 @@ static ssize_t ad9852_set_parameter(struct device *dev,
|
|||||||
xfer.tx_buf = &config->phajst0[0];
|
xfer.tx_buf = &config->phajst0[0];
|
||||||
mutex_lock(&st->lock);
|
mutex_lock(&st->lock);
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 3;
|
xfer.len = 3;
|
||||||
xfer.tx_buf = &config->phajst1[0];
|
xfer.tx_buf = &config->phajst1[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 6;
|
xfer.len = 6;
|
||||||
xfer.tx_buf = &config->fretun1[0];
|
xfer.tx_buf = &config->fretun1[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 6;
|
xfer.len = 6;
|
||||||
xfer.tx_buf = &config->fretun2[0];
|
xfer.tx_buf = &config->fretun2[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 6;
|
xfer.len = 6;
|
||||||
xfer.tx_buf = &config->dltafre[0];
|
xfer.tx_buf = &config->dltafre[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->updtclk[0];
|
xfer.tx_buf = &config->updtclk[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 4;
|
xfer.len = 4;
|
||||||
xfer.tx_buf = &config->ramprat[0];
|
xfer.tx_buf = &config->ramprat[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->control[0];
|
xfer.tx_buf = &config->control[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 3;
|
xfer.len = 3;
|
||||||
xfer.tx_buf = &config->outpskm[0];
|
xfer.tx_buf = &config->outpskm[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 2;
|
xfer.len = 2;
|
||||||
xfer.tx_buf = &config->outpskr[0];
|
xfer.tx_buf = &config->outpskr[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 3;
|
xfer.len = 3;
|
||||||
xfer.tx_buf = &config->daccntl[0];
|
xfer.tx_buf = &config->daccntl[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
error_ret:
|
error_ret:
|
||||||
|
@ -119,7 +119,6 @@ static ssize_t ad9910_set_parameter(struct device *dev,
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfer;
|
struct spi_transfer xfer;
|
||||||
int ret;
|
int ret;
|
||||||
struct ad9910_config *config = (struct ad9910_config *)buf;
|
struct ad9910_config *config = (struct ad9910_config *)buf;
|
||||||
@ -130,152 +129,118 @@ static ssize_t ad9910_set_parameter(struct device *dev,
|
|||||||
xfer.tx_buf = &config->auxdac[0];
|
xfer.tx_buf = &config->auxdac[0];
|
||||||
mutex_lock(&st->lock);
|
mutex_lock(&st->lock);
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->ioupd[0];
|
xfer.tx_buf = &config->ioupd[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->ftw[0];
|
xfer.tx_buf = &config->ftw[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 3;
|
xfer.len = 3;
|
||||||
xfer.tx_buf = &config->pow[0];
|
xfer.tx_buf = &config->pow[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->asf[0];
|
xfer.tx_buf = &config->asf[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->multc[0];
|
xfer.tx_buf = &config->multc[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->dig_rampl[0];
|
xfer.tx_buf = &config->dig_rampl[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->dig_ramps[0];
|
xfer.tx_buf = &config->dig_ramps[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->dig_rampr[0];
|
xfer.tx_buf = &config->dig_rampr[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep0[0];
|
xfer.tx_buf = &config->sin_tonep0[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep1[0];
|
xfer.tx_buf = &config->sin_tonep1[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep2[0];
|
xfer.tx_buf = &config->sin_tonep2[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep3[0];
|
xfer.tx_buf = &config->sin_tonep3[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep4[0];
|
xfer.tx_buf = &config->sin_tonep4[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep5[0];
|
xfer.tx_buf = &config->sin_tonep5[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep6[0];
|
xfer.tx_buf = &config->sin_tonep6[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 9;
|
xfer.len = 9;
|
||||||
xfer.tx_buf = &config->sin_tonep7[0];
|
xfer.tx_buf = &config->sin_tonep7[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
error_ret:
|
error_ret:
|
||||||
@ -288,7 +253,6 @@ static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9910_set_parameter, 0);
|
|||||||
|
|
||||||
static void ad9910_init(struct ad9910_state *st)
|
static void ad9910_init(struct ad9910_state *st)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfer;
|
struct spi_transfer xfer;
|
||||||
int ret;
|
int ret;
|
||||||
u8 cfr[5];
|
u8 cfr[5];
|
||||||
@ -304,9 +268,7 @@ static void ad9910_init(struct ad9910_state *st)
|
|||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = 𝔠
|
xfer.tx_buf = 𝔠
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
@ -319,9 +281,7 @@ static void ad9910_init(struct ad9910_state *st)
|
|||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = 𝔠
|
xfer.tx_buf = 𝔠
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
@ -334,9 +294,7 @@ static void ad9910_init(struct ad9910_state *st)
|
|||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = 𝔠
|
xfer.tx_buf = 𝔠
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ static ssize_t ad9951_set_parameter(struct device *dev,
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfer;
|
struct spi_transfer xfer;
|
||||||
int ret;
|
int ret;
|
||||||
struct ad9951_config *config = (struct ad9951_config *)buf;
|
struct ad9951_config *config = (struct ad9951_config *)buf;
|
||||||
@ -71,36 +70,28 @@ static ssize_t ad9951_set_parameter(struct device *dev,
|
|||||||
xfer.tx_buf = &config->asf[0];
|
xfer.tx_buf = &config->asf[0];
|
||||||
mutex_lock(&st->lock);
|
mutex_lock(&st->lock);
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 2;
|
xfer.len = 2;
|
||||||
xfer.tx_buf = &config->arr[0];
|
xfer.tx_buf = &config->arr[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = &config->ftw0[0];
|
xfer.tx_buf = &config->ftw0[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
xfer.len = 3;
|
xfer.len = 3;
|
||||||
xfer.tx_buf = &config->ftw1[0];
|
xfer.tx_buf = &config->ftw1[0];
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
error_ret:
|
error_ret:
|
||||||
@ -113,7 +104,6 @@ static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9951_set_parameter, 0);
|
|||||||
|
|
||||||
static void ad9951_init(struct ad9951_state *st)
|
static void ad9951_init(struct ad9951_state *st)
|
||||||
{
|
{
|
||||||
struct spi_message msg;
|
|
||||||
struct spi_transfer xfer;
|
struct spi_transfer xfer;
|
||||||
int ret;
|
int ret;
|
||||||
u8 cfr[5];
|
u8 cfr[5];
|
||||||
@ -129,9 +119,7 @@ static void ad9951_init(struct ad9951_state *st)
|
|||||||
xfer.len = 5;
|
xfer.len = 5;
|
||||||
xfer.tx_buf = 𝔠
|
xfer.tx_buf = 𝔠
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
@ -143,9 +131,7 @@ static void ad9951_init(struct ad9951_state *st)
|
|||||||
xfer.len = 4;
|
xfer.len = 4;
|
||||||
xfer.tx_buf = 𝔠
|
xfer.tx_buf = 𝔠
|
||||||
|
|
||||||
spi_message_init(&msg);
|
ret = spi_sync_transfer(st->sdev, &xfer, 1);
|
||||||
spi_message_add_tail(&xfer, &msg);
|
|
||||||
ret = spi_sync(st->sdev, &msg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
|
@ -29,16 +29,11 @@
|
|||||||
#define HMC5843_CONFIG_REG_B 0x01
|
#define HMC5843_CONFIG_REG_B 0x01
|
||||||
#define HMC5843_MODE_REG 0x02
|
#define HMC5843_MODE_REG 0x02
|
||||||
#define HMC5843_DATA_OUT_X_MSB_REG 0x03
|
#define HMC5843_DATA_OUT_X_MSB_REG 0x03
|
||||||
#define HMC5843_DATA_OUT_X_LSB_REG 0x04
|
|
||||||
#define HMC5843_DATA_OUT_Y_MSB_REG 0x05
|
#define HMC5843_DATA_OUT_Y_MSB_REG 0x05
|
||||||
#define HMC5843_DATA_OUT_Y_LSB_REG 0x06
|
|
||||||
#define HMC5843_DATA_OUT_Z_MSB_REG 0x07
|
#define HMC5843_DATA_OUT_Z_MSB_REG 0x07
|
||||||
#define HMC5843_DATA_OUT_Z_LSB_REG 0x08
|
|
||||||
/* Beware: Y and Z are exchanged on HMC5883 */
|
/* Beware: Y and Z are exchanged on HMC5883 */
|
||||||
#define HMC5883_DATA_OUT_Z_MSB_REG 0x05
|
#define HMC5883_DATA_OUT_Z_MSB_REG 0x05
|
||||||
#define HMC5883_DATA_OUT_Z_LSB_REG 0x06
|
|
||||||
#define HMC5883_DATA_OUT_Y_MSB_REG 0x07
|
#define HMC5883_DATA_OUT_Y_MSB_REG 0x07
|
||||||
#define HMC5883_DATA_OUT_Y_LSB_REG 0x08
|
|
||||||
#define HMC5843_STATUS_REG 0x09
|
#define HMC5843_STATUS_REG 0x09
|
||||||
|
|
||||||
enum hmc5843_ids {
|
enum hmc5843_ids {
|
||||||
@ -56,17 +51,11 @@ enum hmc5843_ids {
|
|||||||
#define HMC5843_RANGE_GAIN_DEFAULT 0x01
|
#define HMC5843_RANGE_GAIN_DEFAULT 0x01
|
||||||
#define HMC5843_RANGE_GAIN_MAX 0x07
|
#define HMC5843_RANGE_GAIN_MAX 0x07
|
||||||
|
|
||||||
/*
|
/* Device status */
|
||||||
* Device status
|
|
||||||
*/
|
|
||||||
#define HMC5843_DATA_READY 0x01
|
#define HMC5843_DATA_READY 0x01
|
||||||
#define HMC5843_DATA_OUTPUT_LOCK 0x02
|
#define HMC5843_DATA_OUTPUT_LOCK 0x02
|
||||||
/* Does not exist on HMC5883, not used */
|
|
||||||
#define HMC5843_VOLTAGE_REGULATOR_ENABLED 0x04
|
|
||||||
|
|
||||||
/*
|
/* Mode register configuration */
|
||||||
* Mode register configuration
|
|
||||||
*/
|
|
||||||
#define HMC5843_MODE_CONVERSION_CONTINUOUS 0x00
|
#define HMC5843_MODE_CONVERSION_CONTINUOUS 0x00
|
||||||
#define HMC5843_MODE_CONVERSION_SINGLE 0x01
|
#define HMC5843_MODE_CONVERSION_SINGLE 0x01
|
||||||
#define HMC5843_MODE_IDLE 0x02
|
#define HMC5843_MODE_IDLE 0x02
|
||||||
@ -78,21 +67,18 @@ enum hmc5843_ids {
|
|||||||
* HMC5883: Typical data output rate
|
* HMC5883: Typical data output rate
|
||||||
*/
|
*/
|
||||||
#define HMC5843_RATE_OFFSET 0x02
|
#define HMC5843_RATE_OFFSET 0x02
|
||||||
|
#define HMC5843_RATE_DEFAULT 0x04
|
||||||
#define HMC5843_RATE_BITMASK 0x1C
|
#define HMC5843_RATE_BITMASK 0x1C
|
||||||
#define HMC5843_RATE_NOT_USED 0x07
|
#define HMC5843_RATE_NOT_USED 0x07
|
||||||
|
|
||||||
/*
|
/* Device measurement configuration */
|
||||||
* Device measurement configuration
|
|
||||||
*/
|
|
||||||
#define HMC5843_MEAS_CONF_NORMAL 0x00
|
#define HMC5843_MEAS_CONF_NORMAL 0x00
|
||||||
#define HMC5843_MEAS_CONF_POSITIVE_BIAS 0x01
|
#define HMC5843_MEAS_CONF_POSITIVE_BIAS 0x01
|
||||||
#define HMC5843_MEAS_CONF_NEGATIVE_BIAS 0x02
|
#define HMC5843_MEAS_CONF_NEGATIVE_BIAS 0x02
|
||||||
#define HMC5843_MEAS_CONF_NOT_USED 0x03
|
#define HMC5843_MEAS_CONF_NOT_USED 0x03
|
||||||
#define HMC5843_MEAS_CONF_MASK 0x03
|
#define HMC5843_MEAS_CONF_MASK 0x03
|
||||||
|
|
||||||
/*
|
/* Scaling factors: 10000000/Gain */
|
||||||
* Scaling factors: 10000000/Gain
|
|
||||||
*/
|
|
||||||
static const int hmc5843_regval_to_nanoscale[] = {
|
static const int hmc5843_regval_to_nanoscale[] = {
|
||||||
6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714
|
6173, 7692, 10309, 12821, 18868, 21739, 25641, 35714
|
||||||
};
|
};
|
||||||
@ -164,24 +150,26 @@ static const int hmc5883l_regval_to_input_field_mga[] = {
|
|||||||
* 6 | 50 | 75
|
* 6 | 50 | 75
|
||||||
* 7 | Not used | Not used
|
* 7 | Not used | Not used
|
||||||
*/
|
*/
|
||||||
static const char * const hmc5843_regval_to_sample_freq[] = {
|
static const int hmc5843_regval_to_samp_freq[7][2] = {
|
||||||
"0.5", "1", "2", "5", "10", "20", "50",
|
{0, 500000}, {1, 0}, {2, 0}, {5, 0}, {10, 0}, {20, 0}, {50, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const hmc5883_regval_to_sample_freq[] = {
|
static const int hmc5883_regval_to_samp_freq[7][2] = {
|
||||||
"0.75", "1.5", "3", "7.5", "15", "30", "75",
|
{0, 750000}, {1, 500000}, {3, 0}, {7, 500000}, {15, 0}, {30, 0},
|
||||||
|
{75, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Describe chip variants */
|
/* Describe chip variants */
|
||||||
struct hmc5843_chip_info {
|
struct hmc5843_chip_info {
|
||||||
const struct iio_chan_spec *channels;
|
const struct iio_chan_spec *channels;
|
||||||
const char * const *regval_to_sample_freq;
|
const int (*regval_to_samp_freq)[2];
|
||||||
const int *regval_to_input_field_mga;
|
const int *regval_to_input_field_mga;
|
||||||
const int *regval_to_nanoscale;
|
const int *regval_to_nanoscale;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Each client has this additional data */
|
/* Each client has this additional data */
|
||||||
struct hmc5843_data {
|
struct hmc5843_data {
|
||||||
|
struct i2c_client *client;
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
u8 rate;
|
u8 rate;
|
||||||
u8 meas_conf;
|
u8 meas_conf;
|
||||||
@ -200,18 +188,15 @@ static s32 hmc5843_configure(struct i2c_client *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return the measurement value from the specified channel */
|
/* Return the measurement value from the specified channel */
|
||||||
static int hmc5843_read_measurement(struct iio_dev *indio_dev,
|
static int hmc5843_read_measurement(struct hmc5843_data *data,
|
||||||
int address,
|
int address, int *val)
|
||||||
int *val)
|
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
|
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
|
||||||
s32 result;
|
s32 result;
|
||||||
int tries = 150;
|
int tries = 150;
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
while (tries-- > 0) {
|
while (tries-- > 0) {
|
||||||
result = i2c_smbus_read_byte_data(client,
|
result = i2c_smbus_read_byte_data(data->client,
|
||||||
HMC5843_STATUS_REG);
|
HMC5843_STATUS_REG);
|
||||||
if (result & HMC5843_DATA_READY)
|
if (result & HMC5843_DATA_READY)
|
||||||
break;
|
break;
|
||||||
@ -219,12 +204,12 @@ static int hmc5843_read_measurement(struct iio_dev *indio_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tries < 0) {
|
if (tries < 0) {
|
||||||
dev_err(&client->dev, "data not ready\n");
|
dev_err(&data->client->dev, "data not ready\n");
|
||||||
mutex_unlock(&data->lock);
|
mutex_unlock(&data->lock);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = i2c_smbus_read_word_swapped(client, address);
|
result = i2c_smbus_read_word_swapped(data->client, address);
|
||||||
mutex_unlock(&data->lock);
|
mutex_unlock(&data->lock);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -318,15 +303,13 @@ static IIO_DEVICE_ATTR(operating_mode,
|
|||||||
* and BN.
|
* and BN.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static s32 hmc5843_set_meas_conf(struct i2c_client *client,
|
static s32 hmc5843_set_meas_conf(struct hmc5843_data *data, u8 meas_conf)
|
||||||
u8 meas_conf)
|
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
|
||||||
u8 reg_val;
|
u8 reg_val;
|
||||||
reg_val = (meas_conf & HMC5843_MEAS_CONF_MASK) |
|
reg_val = (meas_conf & HMC5843_MEAS_CONF_MASK) |
|
||||||
(data->rate << HMC5843_RATE_OFFSET);
|
(data->rate << HMC5843_RATE_OFFSET);
|
||||||
return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val);
|
return i2c_smbus_write_byte_data(data->client, HMC5843_CONFIG_REG_A,
|
||||||
|
reg_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t hmc5843_show_measurement_configuration(struct device *dev,
|
static ssize_t hmc5843_show_measurement_configuration(struct device *dev,
|
||||||
@ -344,7 +327,6 @@ static ssize_t hmc5843_set_measurement_configuration(struct device *dev,
|
|||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
||||||
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
|
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
struct hmc5843_data *data = iio_priv(indio_dev);
|
||||||
unsigned long meas_conf = 0;
|
unsigned long meas_conf = 0;
|
||||||
int error;
|
int error;
|
||||||
@ -357,7 +339,7 @@ static ssize_t hmc5843_set_measurement_configuration(struct device *dev,
|
|||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
dev_dbg(dev, "set measurement configuration to %lu\n", meas_conf);
|
dev_dbg(dev, "set measurement configuration to %lu\n", meas_conf);
|
||||||
if (hmc5843_set_meas_conf(client, meas_conf)) {
|
if (hmc5843_set_meas_conf(data, meas_conf)) {
|
||||||
count = -EINVAL;
|
count = -EINVAL;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -374,110 +356,61 @@ static IIO_DEVICE_ATTR(meas_conf,
|
|||||||
hmc5843_set_measurement_configuration,
|
hmc5843_set_measurement_configuration,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
static ssize_t hmc5843_show_sampling_frequencies_available(struct device *dev,
|
static ssize_t hmc5843_show_int_plus_micros(char *buf,
|
||||||
struct device_attribute *attr,
|
const int (*vals)[2], int n)
|
||||||
char *buf)
|
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
size_t len = 0;
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
|
||||||
ssize_t total_n = 0;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < HMC5843_RATE_NOT_USED; i++) {
|
for (i = 0; i < n; i++)
|
||||||
ssize_t n = sprintf(buf, "%s ", data->variant->regval_to_sample_freq[i]);
|
len += scnprintf(buf + len, PAGE_SIZE - len,
|
||||||
buf += n;
|
"%d.%d ", vals[i][0], vals[i][1]);
|
||||||
total_n += n;
|
|
||||||
}
|
|
||||||
/* replace trailing space by newline */
|
/* replace trailing space by newline */
|
||||||
buf[-1] = '\n';
|
buf[len - 1] = '\n';
|
||||||
|
|
||||||
return total_n;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(hmc5843_show_sampling_frequencies_available);
|
static int hmc5843_check_int_plus_micros(const int (*vals)[2], int n,
|
||||||
|
int val, int val2)
|
||||||
static s32 hmc5843_set_rate(struct i2c_client *client,
|
|
||||||
u8 rate)
|
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
|
||||||
u8 reg_val;
|
|
||||||
|
|
||||||
if (rate >= HMC5843_RATE_NOT_USED) {
|
|
||||||
dev_err(&client->dev,
|
|
||||||
"data output rate is not supported\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
reg_val = data->meas_conf | (rate << HMC5843_RATE_OFFSET);
|
|
||||||
return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int hmc5843_check_sampling_frequency(struct hmc5843_data *data,
|
|
||||||
const char *buf)
|
|
||||||
{
|
|
||||||
const char * const *samp_freq = data->variant->regval_to_sample_freq;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < HMC5843_RATE_NOT_USED; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (sysfs_streq(buf, samp_freq[i]))
|
if (val == vals[i][0] && val2 == vals[i][1])
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t hmc5843_set_sampling_frequency(struct device *dev,
|
static ssize_t hmc5843_show_samp_freq_avail(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr, char *buf)
|
||||||
const char *buf, size_t count)
|
|
||||||
{
|
{
|
||||||
|
struct hmc5843_data *data = iio_priv(dev_to_iio_dev(dev));
|
||||||
|
|
||||||
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
return hmc5843_show_int_plus_micros(buf,
|
||||||
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
|
data->variant->regval_to_samp_freq, HMC5843_RATE_NOT_USED);
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
|
||||||
int rate;
|
|
||||||
|
|
||||||
rate = hmc5843_check_sampling_frequency(data, buf);
|
|
||||||
if (rate < 0) {
|
|
||||||
dev_err(&client->dev,
|
|
||||||
"sampling frequency is not supported\n");
|
|
||||||
return rate;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
|
||||||
dev_dbg(dev, "set rate to %d\n", rate);
|
|
||||||
if (hmc5843_set_rate(client, rate)) {
|
|
||||||
count = -EINVAL;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
data->rate = rate;
|
|
||||||
|
|
||||||
exit:
|
|
||||||
mutex_unlock(&data->lock);
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t hmc5843_show_sampling_frequency(struct device *dev,
|
static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(hmc5843_show_samp_freq_avail);
|
||||||
struct device_attribute *attr, char *buf)
|
|
||||||
{
|
|
||||||
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
|
||||||
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
|
|
||||||
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
|
||||||
s32 rate;
|
|
||||||
|
|
||||||
rate = i2c_smbus_read_byte_data(client, this_attr->address);
|
static s32 hmc5843_set_rate(struct hmc5843_data *data, u8 rate)
|
||||||
if (rate < 0)
|
{
|
||||||
return rate;
|
u8 reg_val = data->meas_conf | (rate << HMC5843_RATE_OFFSET);
|
||||||
rate = (rate & HMC5843_RATE_BITMASK) >> HMC5843_RATE_OFFSET;
|
|
||||||
return sprintf(buf, "%s\n", data->variant->regval_to_sample_freq[rate]);
|
return i2c_smbus_write_byte_data(data->client, HMC5843_CONFIG_REG_A,
|
||||||
|
reg_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static IIO_DEVICE_ATTR(sampling_frequency,
|
static int hmc5843_check_samp_freq(struct hmc5843_data *data,
|
||||||
S_IWUSR | S_IRUGO,
|
int val, int val2)
|
||||||
hmc5843_show_sampling_frequency,
|
{
|
||||||
hmc5843_set_sampling_frequency,
|
return hmc5843_check_int_plus_micros(
|
||||||
HMC5843_CONFIG_REG_A);
|
data->variant->regval_to_samp_freq, HMC5843_RATE_NOT_USED,
|
||||||
|
val, val2);
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t hmc5843_show_range_gain(struct device *dev,
|
static ssize_t hmc5843_show_range_gain(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
@ -497,7 +430,6 @@ static ssize_t hmc5843_set_range_gain(struct device *dev,
|
|||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
||||||
struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
|
|
||||||
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
struct hmc5843_data *data = iio_priv(indio_dev);
|
||||||
unsigned long range = 0;
|
unsigned long range = 0;
|
||||||
@ -518,7 +450,7 @@ static ssize_t hmc5843_set_range_gain(struct device *dev,
|
|||||||
|
|
||||||
data->range = range;
|
data->range = range;
|
||||||
range = range << HMC5843_RANGE_GAIN_OFFSET;
|
range = range << HMC5843_RANGE_GAIN_OFFSET;
|
||||||
if (i2c_smbus_write_byte_data(client, this_attr->address, range))
|
if (i2c_smbus_write_byte_data(data->client, this_attr->address, range))
|
||||||
count = -EINVAL;
|
count = -EINVAL;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@ -534,31 +466,58 @@ static IIO_DEVICE_ATTR(in_magn_range,
|
|||||||
|
|
||||||
static int hmc5843_read_raw(struct iio_dev *indio_dev,
|
static int hmc5843_read_raw(struct iio_dev *indio_dev,
|
||||||
struct iio_chan_spec const *chan,
|
struct iio_chan_spec const *chan,
|
||||||
int *val, int *val2,
|
int *val, int *val2, long mask)
|
||||||
long mask)
|
|
||||||
{
|
{
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
struct hmc5843_data *data = iio_priv(indio_dev);
|
||||||
|
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
return hmc5843_read_measurement(indio_dev,
|
return hmc5843_read_measurement(data, chan->address, val);
|
||||||
chan->address,
|
|
||||||
val);
|
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
*val = 0;
|
*val = 0;
|
||||||
*val2 = data->variant->regval_to_nanoscale[data->range];
|
*val2 = data->variant->regval_to_nanoscale[data->range];
|
||||||
return IIO_VAL_INT_PLUS_NANO;
|
return IIO_VAL_INT_PLUS_NANO;
|
||||||
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||||
|
*val = data->variant->regval_to_samp_freq[data->rate][0];
|
||||||
|
*val2 = data->variant->regval_to_samp_freq[data->rate][1];
|
||||||
|
return IIO_VAL_INT_PLUS_MICRO;
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int hmc5843_write_raw(struct iio_dev *indio_dev,
|
||||||
|
struct iio_chan_spec const *chan,
|
||||||
|
int val, int val2, long mask)
|
||||||
|
{
|
||||||
|
struct hmc5843_data *data = iio_priv(indio_dev);
|
||||||
|
int ret, rate;
|
||||||
|
|
||||||
|
switch (mask) {
|
||||||
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||||
|
rate = hmc5843_check_samp_freq(data, val, val2);
|
||||||
|
if (rate < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
mutex_lock(&data->lock);
|
||||||
|
ret = hmc5843_set_rate(data, rate);
|
||||||
|
if (ret >= 0)
|
||||||
|
data->rate = rate;
|
||||||
|
mutex_unlock(&data->lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define HMC5843_CHANNEL(axis, addr) \
|
#define HMC5843_CHANNEL(axis, addr) \
|
||||||
{ \
|
{ \
|
||||||
.type = IIO_MAGN, \
|
.type = IIO_MAGN, \
|
||||||
.modified = 1, \
|
.modified = 1, \
|
||||||
.channel2 = IIO_MOD_##axis, \
|
.channel2 = IIO_MOD_##axis, \
|
||||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
|
||||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
|
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
|
||||||
|
BIT(IIO_CHAN_INFO_SAMP_FREQ), \
|
||||||
.address = addr \
|
.address = addr \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,7 +536,6 @@ static const struct iio_chan_spec hmc5883_channels[] = {
|
|||||||
static struct attribute *hmc5843_attributes[] = {
|
static struct attribute *hmc5843_attributes[] = {
|
||||||
&iio_dev_attr_meas_conf.dev_attr.attr,
|
&iio_dev_attr_meas_conf.dev_attr.attr,
|
||||||
&iio_dev_attr_operating_mode.dev_attr.attr,
|
&iio_dev_attr_operating_mode.dev_attr.attr,
|
||||||
&iio_dev_attr_sampling_frequency.dev_attr.attr,
|
|
||||||
&iio_dev_attr_in_magn_range.dev_attr.attr,
|
&iio_dev_attr_in_magn_range.dev_attr.attr,
|
||||||
&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
|
&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
|
||||||
NULL
|
NULL
|
||||||
@ -590,49 +548,40 @@ static const struct attribute_group hmc5843_group = {
|
|||||||
static const struct hmc5843_chip_info hmc5843_chip_info_tbl[] = {
|
static const struct hmc5843_chip_info hmc5843_chip_info_tbl[] = {
|
||||||
[HMC5843_ID] = {
|
[HMC5843_ID] = {
|
||||||
.channels = hmc5843_channels,
|
.channels = hmc5843_channels,
|
||||||
.regval_to_sample_freq = hmc5843_regval_to_sample_freq,
|
.regval_to_samp_freq = hmc5843_regval_to_samp_freq,
|
||||||
.regval_to_input_field_mga =
|
.regval_to_input_field_mga =
|
||||||
hmc5843_regval_to_input_field_mga,
|
hmc5843_regval_to_input_field_mga,
|
||||||
.regval_to_nanoscale = hmc5843_regval_to_nanoscale,
|
.regval_to_nanoscale = hmc5843_regval_to_nanoscale,
|
||||||
},
|
},
|
||||||
[HMC5883_ID] = {
|
[HMC5883_ID] = {
|
||||||
.channels = hmc5883_channels,
|
.channels = hmc5883_channels,
|
||||||
.regval_to_sample_freq = hmc5883_regval_to_sample_freq,
|
.regval_to_samp_freq = hmc5883_regval_to_samp_freq,
|
||||||
.regval_to_input_field_mga =
|
.regval_to_input_field_mga =
|
||||||
hmc5883_regval_to_input_field_mga,
|
hmc5883_regval_to_input_field_mga,
|
||||||
.regval_to_nanoscale = hmc5883_regval_to_nanoscale,
|
.regval_to_nanoscale = hmc5883_regval_to_nanoscale,
|
||||||
},
|
},
|
||||||
[HMC5883L_ID] = {
|
[HMC5883L_ID] = {
|
||||||
.channels = hmc5883_channels,
|
.channels = hmc5883_channels,
|
||||||
.regval_to_sample_freq = hmc5883_regval_to_sample_freq,
|
.regval_to_samp_freq = hmc5883_regval_to_samp_freq,
|
||||||
.regval_to_input_field_mga =
|
.regval_to_input_field_mga =
|
||||||
hmc5883l_regval_to_input_field_mga,
|
hmc5883l_regval_to_input_field_mga,
|
||||||
.regval_to_nanoscale = hmc5883l_regval_to_nanoscale,
|
.regval_to_nanoscale = hmc5883l_regval_to_nanoscale,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Called when we have found a new HMC58X3 */
|
static void hmc5843_init(struct hmc5843_data *data)
|
||||||
static void hmc5843_init_client(struct i2c_client *client,
|
|
||||||
const struct i2c_device_id *id)
|
|
||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
hmc5843_set_meas_conf(data, HMC5843_MEAS_CONF_NORMAL);
|
||||||
struct hmc5843_data *data = iio_priv(indio_dev);
|
hmc5843_set_rate(data, HMC5843_RATE_DEFAULT);
|
||||||
|
hmc5843_configure(data->client, HMC5843_MODE_CONVERSION_CONTINUOUS);
|
||||||
data->variant = &hmc5843_chip_info_tbl[id->driver_data];
|
i2c_smbus_write_byte_data(data->client, HMC5843_CONFIG_REG_B,
|
||||||
indio_dev->channels = data->variant->channels;
|
HMC5843_RANGE_GAIN_DEFAULT);
|
||||||
indio_dev->num_channels = 3;
|
|
||||||
hmc5843_set_meas_conf(client, data->meas_conf);
|
|
||||||
hmc5843_set_rate(client, data->rate);
|
|
||||||
hmc5843_configure(client, data->operating_mode);
|
|
||||||
i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_B, data->range);
|
|
||||||
mutex_init(&data->lock);
|
|
||||||
|
|
||||||
pr_info("%s initialized\n", id->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct iio_info hmc5843_info = {
|
static const struct iio_info hmc5843_info = {
|
||||||
.attrs = &hmc5843_group,
|
.attrs = &hmc5843_group,
|
||||||
.read_raw = &hmc5843_read_raw,
|
.read_raw = &hmc5843_read_raw,
|
||||||
|
.write_raw = &hmc5843_write_raw,
|
||||||
.driver_module = THIS_MODULE,
|
.driver_module = THIS_MODULE,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -649,17 +598,19 @@ static int hmc5843_probe(struct i2c_client *client,
|
|||||||
|
|
||||||
/* default settings at probe */
|
/* default settings at probe */
|
||||||
data = iio_priv(indio_dev);
|
data = iio_priv(indio_dev);
|
||||||
data->meas_conf = HMC5843_MEAS_CONF_NORMAL;
|
data->client = client;
|
||||||
data->range = HMC5843_RANGE_GAIN_DEFAULT;
|
data->variant = &hmc5843_chip_info_tbl[id->driver_data];
|
||||||
data->operating_mode = HMC5843_MODE_CONVERSION_CONTINUOUS;
|
mutex_init(&data->lock);
|
||||||
|
|
||||||
i2c_set_clientdata(client, indio_dev);
|
i2c_set_clientdata(client, indio_dev);
|
||||||
hmc5843_init_client(client, id);
|
|
||||||
|
|
||||||
indio_dev->info = &hmc5843_info;
|
indio_dev->info = &hmc5843_info;
|
||||||
indio_dev->name = id->name;
|
indio_dev->name = id->name;
|
||||||
indio_dev->dev.parent = &client->dev;
|
indio_dev->dev.parent = &client->dev;
|
||||||
indio_dev->modes = INDIO_DIRECT_MODE;
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
||||||
|
indio_dev->channels = data->variant->channels;
|
||||||
|
indio_dev->num_channels = 3;
|
||||||
|
|
||||||
|
hmc5843_init(data);
|
||||||
|
|
||||||
err = iio_device_register(indio_dev);
|
err = iio_device_register(indio_dev);
|
||||||
if (err)
|
if (err)
|
||||||
@ -687,10 +638,10 @@ static int hmc5843_suspend(struct device *dev)
|
|||||||
|
|
||||||
static int hmc5843_resume(struct device *dev)
|
static int hmc5843_resume(struct device *dev)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct hmc5843_data *data = iio_priv(i2c_get_clientdata(
|
||||||
struct hmc5843_data *data = iio_priv(i2c_get_clientdata(client));
|
to_i2c_client(dev)));
|
||||||
|
|
||||||
hmc5843_configure(client, data->operating_mode);
|
hmc5843_configure(data->client, data->operating_mode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,13 @@ struct hid_sensor_hub_attribute_info {
|
|||||||
* @hdev: Stores the hid instance.
|
* @hdev: Stores the hid instance.
|
||||||
* @vendor_id: Vendor id of hub device.
|
* @vendor_id: Vendor id of hub device.
|
||||||
* @product_id: Product id of hub device.
|
* @product_id: Product id of hub device.
|
||||||
|
* @ref_cnt: Number of MFD clients have opened this device
|
||||||
*/
|
*/
|
||||||
struct hid_sensor_hub_device {
|
struct hid_sensor_hub_device {
|
||||||
struct hid_device *hdev;
|
struct hid_device *hdev;
|
||||||
u32 vendor_id;
|
u32 vendor_id;
|
||||||
u32 product_id;
|
u32 product_id;
|
||||||
|
int ref_cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,6 +76,22 @@ struct hid_sensor_hub_callbacks {
|
|||||||
void *priv);
|
void *priv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sensor_hub_device_open() - Open hub device
|
||||||
|
* @hsdev: Hub device instance.
|
||||||
|
*
|
||||||
|
* Used to open hid device for sensor hub.
|
||||||
|
*/
|
||||||
|
int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sensor_hub_device_clode() - Close hub device
|
||||||
|
* @hsdev: Hub device instance.
|
||||||
|
*
|
||||||
|
* Used to clode hid device for sensor hub.
|
||||||
|
*/
|
||||||
|
void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
|
||||||
|
|
||||||
/* Registration functions */
|
/* Registration functions */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user