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

Configure Feed

Select the types of activity you want to include in your feed.

iio: chemical: atlas-ezo-sensor: add support for O2 sensor

Add support for the Atlas EZO O2 chemical sensor which required
some refactoring of the driver and parsing of i2c transfer.

Sensor data is converted by the scaling value from percent to
IIO_CONCENTRATION.

Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matt Ranostay and committed by
Jonathan Cameron
6da3a6ce 4ffa22fd

+54 -19
+54 -19
drivers/iio/chemical/atlas-ezo-sensor.c
··· 16 16 #include <linux/iio/iio.h> 17 17 18 18 #define ATLAS_EZO_DRV_NAME "atlas-ezo-sensor" 19 - #define ATLAS_CO2_INT_TIME_IN_MS 950 19 + #define ATLAS_INT_TIME_IN_MS 950 20 20 21 21 enum { 22 22 ATLAS_CO2_EZO, 23 + ATLAS_O2_EZO, 23 24 }; 24 25 25 26 struct atlas_ezo_device { ··· 39 38 u8 buffer[8]; 40 39 }; 41 40 41 + #define ATLAS_CONCENTRATION_CHANNEL(_modifier) \ 42 + { \ 43 + .type = IIO_CONCENTRATION, \ 44 + .modified = 1,\ 45 + .channel2 = _modifier, \ 46 + .info_mask_separate = \ 47 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \ 48 + .scan_index = 0, \ 49 + .scan_type = { \ 50 + .sign = 'u', \ 51 + .realbits = 32, \ 52 + .storagebits = 32, \ 53 + .endianness = IIO_CPU, \ 54 + }, \ 55 + } 56 + 42 57 static const struct iio_chan_spec atlas_co2_ezo_channels[] = { 43 - { 44 - .type = IIO_CONCENTRATION, 45 - .modified = 1, 46 - .channel2 = IIO_MOD_CO2, 47 - .info_mask_separate = 48 - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 49 - .scan_index = 0, 50 - .scan_type = { 51 - .sign = 'u', 52 - .realbits = 32, 53 - .storagebits = 32, 54 - .endianness = IIO_CPU, 55 - }, 56 - }, 58 + ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2), 59 + }; 60 + 61 + static const struct iio_chan_spec atlas_o2_ezo_channels[] = { 62 + ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2), 57 63 }; 58 64 59 65 static struct atlas_ezo_device atlas_ezo_devices[] = { 60 66 [ATLAS_CO2_EZO] = { 61 67 .channels = atlas_co2_ezo_channels, 62 68 .num_channels = 1, 63 - .delay = ATLAS_CO2_INT_TIME_IN_MS, 69 + .delay = ATLAS_INT_TIME_IN_MS, 64 70 }, 71 + [ATLAS_O2_EZO] = { 72 + .channels = atlas_o2_ezo_channels, 73 + .num_channels = 1, 74 + .delay = ATLAS_INT_TIME_IN_MS, 75 + } 65 76 }; 77 + 78 + static void atlas_ezo_sanitize(char *buf) 79 + { 80 + char *ptr = strchr(buf, '.'); 81 + 82 + if (!ptr) 83 + return; 84 + 85 + memmove(ptr, ptr + 1, strlen(ptr)); 86 + } 66 87 67 88 static int atlas_ezo_read_raw(struct iio_dev *indio_dev, 68 89 struct iio_chan_spec const *chan, ··· 119 96 return -EBUSY; 120 97 } 121 98 99 + /* removing floating point for fixed number representation */ 100 + atlas_ezo_sanitize(data->buffer + 2); 101 + 122 102 ret = kstrtol(data->buffer + 1, 10, &tmp); 123 103 124 104 *val = tmp; ··· 131 105 return ret ? ret : IIO_VAL_INT; 132 106 } 133 107 case IIO_CHAN_INFO_SCALE: 134 - *val = 0; 135 - *val2 = 100; /* 0.0001 */ 136 - return IIO_VAL_INT_PLUS_MICRO; 108 + switch (chan->channel2) { 109 + case IIO_MOD_CO2: 110 + *val = 0; 111 + *val2 = 100; /* 0.0001 */ 112 + return IIO_VAL_INT_PLUS_MICRO; 113 + case IIO_MOD_O2: 114 + *val = 100; 115 + return IIO_VAL_INT; 116 + } 117 + return -EINVAL; 137 118 } 138 119 139 120 return 0; ··· 152 119 153 120 static const struct i2c_device_id atlas_ezo_id[] = { 154 121 { "atlas-co2-ezo", ATLAS_CO2_EZO }, 122 + { "atlas-o2-ezo", ATLAS_O2_EZO }, 155 123 {} 156 124 }; 157 125 MODULE_DEVICE_TABLE(i2c, atlas_ezo_id); 158 126 159 127 static const struct of_device_id atlas_ezo_dt_ids[] = { 160 128 { .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, }, 129 + { .compatible = "atlas,o2-ezo", .data = (void *)ATLAS_O2_EZO, }, 161 130 {} 162 131 }; 163 132 MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);