diff options
author | Jonathan Cameron <jic23@kernel.org> | 2013-09-08 09:57:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-09-15 12:47:38 -0400 |
commit | da1690e6ca03ae72ff89727d8dfd40f40a365136 (patch) | |
tree | 121de8db68cad2df2169e8ebb7fd6ada53f8e8fc /drivers/iio/temperature | |
parent | 6a63aa0a09414256c89b48fc012b189756da690e (diff) |
iio:temperature:tmp006 put sampling_frequency in info_mask_shared_by_all
Doing this makes it possible to access this control from within the kernel.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Acked-by: Peter Meerwald <pmeerw@pmeerw.net>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Diffstat (limited to 'drivers/iio/temperature')
-rw-r--r-- | drivers/iio/temperature/tmp006.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index 64ccde3f1f7a..4e950979f43e 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c | |||
@@ -70,12 +70,16 @@ static int tmp006_read_measurement(struct tmp006_data *data, u8 reg) | |||
70 | return i2c_smbus_read_word_swapped(data->client, reg); | 70 | return i2c_smbus_read_word_swapped(data->client, reg); |
71 | } | 71 | } |
72 | 72 | ||
73 | static const int tmp006_freqs[5][2] = { {4, 0}, {2, 0}, {1, 0}, | ||
74 | {0, 500000}, {0, 250000} }; | ||
75 | |||
73 | static int tmp006_read_raw(struct iio_dev *indio_dev, | 76 | static int tmp006_read_raw(struct iio_dev *indio_dev, |
74 | struct iio_chan_spec const *channel, int *val, | 77 | struct iio_chan_spec const *channel, int *val, |
75 | int *val2, long mask) | 78 | int *val2, long mask) |
76 | { | 79 | { |
77 | struct tmp006_data *data = iio_priv(indio_dev); | 80 | struct tmp006_data *data = iio_priv(indio_dev); |
78 | s32 ret; | 81 | s32 ret; |
82 | int cr; | ||
79 | 83 | ||
80 | switch (mask) { | 84 | switch (mask) { |
81 | case IIO_CHAN_INFO_RAW: | 85 | case IIO_CHAN_INFO_RAW: |
@@ -106,6 +110,12 @@ static int tmp006_read_raw(struct iio_dev *indio_dev, | |||
106 | break; | 110 | break; |
107 | } | 111 | } |
108 | return IIO_VAL_INT_PLUS_MICRO; | 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: | 119 | default: |
110 | break; | 120 | break; |
111 | } | 121 | } |
@@ -113,48 +123,32 @@ static int tmp006_read_raw(struct iio_dev *indio_dev, | |||
113 | return -EINVAL; | 123 | return -EINVAL; |
114 | } | 124 | } |
115 | 125 | ||
116 | static const char * const tmp006_freqs[] = { "4", "2", "1", "0.5", "0.25" }; | 126 | static int tmp006_write_raw(struct iio_dev *indio_dev, |
117 | 127 | struct iio_chan_spec const *chan, | |
118 | static ssize_t tmp006_show_freq(struct device *dev, | 128 | int val, |
119 | struct device_attribute *attr, char *buf) | 129 | int val2, |
120 | { | 130 | long mask) |
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 | |||
127 | static ssize_t tmp006_store_freq(struct device *dev, | ||
128 | struct device_attribute *attr, | ||
129 | const char *buf, size_t len) | ||
130 | { | 131 | { |
131 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
132 | struct tmp006_data *data = iio_priv(indio_dev); | 132 | struct tmp006_data *data = iio_priv(indio_dev); |
133 | int i; | 133 | int i; |
134 | bool found = false; | ||
135 | 134 | ||
136 | for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) | 135 | for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) |
137 | if (sysfs_streq(buf, tmp006_freqs[i])) { | 136 | if ((val == tmp006_freqs[i][0]) && |
138 | found = true; | 137 | (val2 == tmp006_freqs[i][1])) { |
139 | break; | 138 | data->config &= ~TMP006_CONFIG_CR_MASK; |
140 | } | 139 | data->config |= i << TMP006_CONFIG_CR_SHIFT; |
141 | if (!found) | ||
142 | return -EINVAL; | ||
143 | 140 | ||
144 | data->config &= ~TMP006_CONFIG_CR_MASK; | 141 | return i2c_smbus_write_word_swapped(data->client, |
145 | data->config |= i << TMP006_CONFIG_CR_SHIFT; | 142 | TMP006_CONFIG, |
143 | data->config); | ||
146 | 144 | ||
147 | return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, | 145 | } |
148 | data->config); | 146 | return -EINVAL; |
149 | } | 147 | } |
150 | 148 | ||
151 | static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, | ||
152 | tmp006_show_freq, tmp006_store_freq); | ||
153 | |||
154 | static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); | 149 | static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); |
155 | 150 | ||
156 | static struct attribute *tmp006_attributes[] = { | 151 | static struct attribute *tmp006_attributes[] = { |
157 | &iio_dev_attr_sampling_frequency.dev_attr.attr, | ||
158 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, | 152 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, |
159 | NULL | 153 | NULL |
160 | }; | 154 | }; |
@@ -168,16 +162,19 @@ static const struct iio_chan_spec tmp006_channels[] = { | |||
168 | .type = IIO_VOLTAGE, | 162 | .type = IIO_VOLTAGE, |
169 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | 163 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | |
170 | BIT(IIO_CHAN_INFO_SCALE), | 164 | BIT(IIO_CHAN_INFO_SCALE), |
165 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), | ||
171 | }, | 166 | }, |
172 | { | 167 | { |
173 | .type = IIO_TEMP, | 168 | .type = IIO_TEMP, |
174 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | 169 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | |
175 | BIT(IIO_CHAN_INFO_SCALE), | 170 | BIT(IIO_CHAN_INFO_SCALE), |
171 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), | ||
176 | } | 172 | } |
177 | }; | 173 | }; |
178 | 174 | ||
179 | static const struct iio_info tmp006_info = { | 175 | static const struct iio_info tmp006_info = { |
180 | .read_raw = tmp006_read_raw, | 176 | .read_raw = tmp006_read_raw, |
177 | .write_raw = tmp006_write_raw, | ||
181 | .attrs = &tmp006_attribute_group, | 178 | .attrs = &tmp006_attribute_group, |
182 | .driver_module = THIS_MODULE, | 179 | .driver_module = THIS_MODULE, |
183 | }; | 180 | }; |