tmp006.c (3bc4f3993b93dbf1f6402e2034a2e20eb07db807) | tmp006.c (da1690e6ca03ae72ff89727d8dfd40f40a365136) |
---|---|
1/* 2 * tmp006.c - Support for TI TMP006 IR thermopile sensor 3 * 4 * Copyright (c) 2013 Peter Meerwald <pmeerw@pmeerw.net> 5 * 6 * This file is subject to the terms and conditions of version 2 of 7 * the GNU General Public License. See the file COPYING in the main 8 * directory of this archive for more details. --- 56 unchanged lines hidden (view full) --- 65 } 66 67 if (tries < 0) 68 return -EIO; 69 70 return i2c_smbus_read_word_swapped(data->client, reg); 71} 72 | 1/* 2 * tmp006.c - Support for TI TMP006 IR thermopile sensor 3 * 4 * Copyright (c) 2013 Peter Meerwald <pmeerw@pmeerw.net> 5 * 6 * This file is subject to the terms and conditions of version 2 of 7 * the GNU General Public License. See the file COPYING in the main 8 * directory of this archive for more details. --- 56 unchanged lines hidden (view full) --- 65 } 66 67 if (tries < 0) 68 return -EIO; 69 70 return i2c_smbus_read_word_swapped(data->client, reg); 71} 72 |
73static const int tmp006_freqs[5][2] = { {4, 0}, {2, 0}, {1, 0}, 74 {0, 500000}, {0, 250000} }; 75 |
|
73static int tmp006_read_raw(struct iio_dev *indio_dev, 74 struct iio_chan_spec const *channel, int *val, 75 int *val2, long mask) 76{ 77 struct tmp006_data *data = iio_priv(indio_dev); 78 s32 ret; | 76static int tmp006_read_raw(struct iio_dev *indio_dev, 77 struct iio_chan_spec const *channel, int *val, 78 int *val2, long mask) 79{ 80 struct tmp006_data *data = iio_priv(indio_dev); 81 s32 ret; |
82 int cr; |
|
79 80 switch (mask) { 81 case IIO_CHAN_INFO_RAW: 82 if (channel->type == IIO_VOLTAGE) { 83 /* LSB is 156.25 nV */ 84 ret = tmp006_read_measurement(data, TMP006_VOBJECT); 85 if (ret < 0) 86 return ret; --- 14 unchanged lines hidden (view full) --- 101 *val2 = 156250; 102 } else if (channel->type == IIO_TEMP) { 103 *val = 31; 104 *val2 = 250000; 105 } else { 106 break; 107 } 108 return IIO_VAL_INT_PLUS_MICRO; | 83 84 switch (mask) { 85 case IIO_CHAN_INFO_RAW: 86 if (channel->type == IIO_VOLTAGE) { 87 /* LSB is 156.25 nV */ 88 ret = tmp006_read_measurement(data, TMP006_VOBJECT); 89 if (ret < 0) 90 return ret; --- 14 unchanged lines hidden (view full) --- 105 *val2 = 156250; 106 } else if (channel->type == IIO_TEMP) { 107 *val = 31; 108 *val2 = 250000; 109 } else { 110 break; 111 } 112 return IIO_VAL_INT_PLUS_MICRO; |
113 case IIO_CHAN_INFO_SAMP_FREQ: 114 cr = (data->config & TMP006_CONFIG_CR_MASK) 115 >> TMP006_CONFIG_CR_SHIFT; 116 *val = tmp006_freqs[cr][0]; 117 *val2 = tmp006_freqs[cr][1]; 118 return IIO_VAL_INT_PLUS_MICRO; |
|
109 default: 110 break; 111 } 112 113 return -EINVAL; 114} 115 | 119 default: 120 break; 121 } 122 123 return -EINVAL; 124} 125 |
116static const char * const tmp006_freqs[] = { "4", "2", "1", "0.5", "0.25" }; 117 118static ssize_t tmp006_show_freq(struct device *dev, 119 struct device_attribute *attr, char *buf) | 126static int tmp006_write_raw(struct iio_dev *indio_dev, 127 struct iio_chan_spec const *chan, 128 int val, 129 int val2, 130 long mask) |
120{ | 131{ |
121 struct tmp006_data *data = iio_priv(dev_to_iio_dev(dev)); 122 int cr = (data->config & TMP006_CONFIG_CR_MASK) 123 >> TMP006_CONFIG_CR_SHIFT; 124 return sprintf(buf, "%s\n", tmp006_freqs[cr]); 125} 126 127static ssize_t tmp006_store_freq(struct device *dev, 128 struct device_attribute *attr, 129 const char *buf, size_t len) 130{ 131 struct iio_dev *indio_dev = dev_to_iio_dev(dev); | |
132 struct tmp006_data *data = iio_priv(indio_dev); 133 int i; | 132 struct tmp006_data *data = iio_priv(indio_dev); 133 int i; |
134 bool found = false; | |
135 136 for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) | 134 135 for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) |
137 if (sysfs_streq(buf, tmp006_freqs[i])) { 138 found = true; 139 break; 140 } 141 if (!found) 142 return -EINVAL; | 136 if ((val == tmp006_freqs[i][0]) && 137 (val2 == tmp006_freqs[i][1])) { 138 data->config &= ~TMP006_CONFIG_CR_MASK; 139 data->config |= i << TMP006_CONFIG_CR_SHIFT; |
143 | 140 |
144 data->config &= ~TMP006_CONFIG_CR_MASK; 145 data->config |= i << TMP006_CONFIG_CR_SHIFT; | 141 return i2c_smbus_write_word_swapped(data->client, 142 TMP006_CONFIG, 143 data->config); |
146 | 144 |
147 return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 148 data->config); | 145 } 146 return -EINVAL; |
149} 150 | 147} 148 |
151static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, 152 tmp006_show_freq, tmp006_store_freq); 153 | |
154static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); 155 156static struct attribute *tmp006_attributes[] = { | 149static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); 150 151static struct attribute *tmp006_attributes[] = { |
157 &iio_dev_attr_sampling_frequency.dev_attr.attr, | |
158 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 159 NULL 160}; 161 162static const struct attribute_group tmp006_attribute_group = { 163 .attrs = tmp006_attributes, 164}; 165 166static const struct iio_chan_spec tmp006_channels[] = { 167 { 168 .type = IIO_VOLTAGE, 169 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 170 BIT(IIO_CHAN_INFO_SCALE), | 152 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 153 NULL 154}; 155 156static const struct attribute_group tmp006_attribute_group = { 157 .attrs = tmp006_attributes, 158}; 159 160static const struct iio_chan_spec tmp006_channels[] = { 161 { 162 .type = IIO_VOLTAGE, 163 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 164 BIT(IIO_CHAN_INFO_SCALE), |
165 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), |
|
171 }, 172 { 173 .type = IIO_TEMP, 174 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 175 BIT(IIO_CHAN_INFO_SCALE), | 166 }, 167 { 168 .type = IIO_TEMP, 169 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 170 BIT(IIO_CHAN_INFO_SCALE), |
171 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), |
|
176 } 177}; 178 179static const struct iio_info tmp006_info = { 180 .read_raw = tmp006_read_raw, | 172 } 173}; 174 175static const struct iio_info tmp006_info = { 176 .read_raw = tmp006_read_raw, |
177 .write_raw = tmp006_write_raw, |
|
181 .attrs = &tmp006_attribute_group, 182 .driver_module = THIS_MODULE, 183}; 184 185static bool tmp006_check_identification(struct i2c_client *client) 186{ 187 int mid, did; 188 --- 103 unchanged lines hidden --- | 178 .attrs = &tmp006_attribute_group, 179 .driver_module = THIS_MODULE, 180}; 181 182static bool tmp006_check_identification(struct i2c_client *client) 183{ 184 int mid, did; 185 --- 103 unchanged lines hidden --- |