Lines Matching +full:int +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Author: Lars-Peter Clausen <[email protected]>
13 #include "xilinx-xadc.h"
16 struct iio_dev *indio_dev, unsigned int event) in xadc_event_to_channel()
21 return &indio_dev->channels[0]; in xadc_event_to_channel()
24 return &indio_dev->channels[event]; in xadc_event_to_channel()
26 return &indio_dev->channels[event-1]; in xadc_event_to_channel()
30 static void xadc_handle_event(struct iio_dev *indio_dev, unsigned int event) in xadc_handle_event()
34 /* Temperature threshold error, we don't handle this yet */ in xadc_handle_event()
40 if (chan->type == IIO_TEMP) { in xadc_handle_event()
42 * The temperature channel only supports over-temperature in xadc_handle_event()
46 IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, in xadc_handle_event()
52 * lower threshold event. Userspace will have to check the in xadc_handle_event()
56 IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, in xadc_handle_event()
64 unsigned int i; in xadc_handle_events()
70 static unsigned int xadc_get_threshold_offset(const struct iio_chan_spec *chan, in xadc_get_threshold_offset()
73 unsigned int offset; in xadc_get_threshold_offset()
75 if (chan->type == IIO_TEMP) { in xadc_get_threshold_offset()
78 if (chan->channel < 2) in xadc_get_threshold_offset()
79 offset = chan->channel + 1; in xadc_get_threshold_offset()
81 offset = chan->channel + 6; in xadc_get_threshold_offset()
90 static unsigned int xadc_get_alarm_mask(const struct iio_chan_spec *chan) in xadc_get_alarm_mask()
92 if (chan->type == IIO_TEMP) in xadc_get_alarm_mask()
94 switch (chan->channel) { in xadc_get_alarm_mask()
113 int xadc_read_event_config(struct iio_dev *indio_dev, in xadc_read_event_config()
119 return (bool)(xadc->alarm_mask & xadc_get_alarm_mask(chan)); in xadc_read_event_config()
122 int xadc_write_event_config(struct iio_dev *indio_dev, in xadc_write_event_config()
126 unsigned int alarm = xadc_get_alarm_mask(chan); in xadc_write_event_config()
129 int ret; in xadc_write_event_config()
131 mutex_lock(&xadc->mutex); in xadc_write_event_config()
134 xadc->alarm_mask |= alarm; in xadc_write_event_config()
136 xadc->alarm_mask &= ~alarm; in xadc_write_event_config()
138 xadc->ops->update_alarm(xadc, xadc->alarm_mask); in xadc_write_event_config()
146 cfg &= ~((xadc->alarm_mask & 0xf0) << 4); /* bram, pint, paux, ddr */ in xadc_write_event_config()
147 cfg &= ~((xadc->alarm_mask & 0x08) >> 3); /* ot */ in xadc_write_event_config()
148 cfg &= ~((xadc->alarm_mask & 0x07) << 1); /* temp, vccint, vccaux */ in xadc_write_event_config()
153 mutex_unlock(&xadc->mutex); in xadc_write_event_config()
158 int xadc_read_event_value(struct iio_dev *indio_dev, in xadc_read_event_value()
161 int *val, int *val2) in xadc_read_event_value()
163 unsigned int offset = xadc_get_threshold_offset(chan, dir); in xadc_read_event_value()
168 *val = xadc->threshold[offset]; in xadc_read_event_value()
171 *val = xadc->temp_hysteresis; in xadc_read_event_value()
174 return -EINVAL; in xadc_read_event_value()
178 *val >>= 16 - chan->scan_type.realbits; in xadc_read_event_value()
183 int xadc_write_event_value(struct iio_dev *indio_dev, in xadc_write_event_value()
186 int val, int val2) in xadc_write_event_value()
188 unsigned int offset = xadc_get_threshold_offset(chan, dir); in xadc_write_event_value()
190 int ret = 0; in xadc_write_event_value()
193 val <<= 16 - chan->scan_type.realbits; in xadc_write_event_value()
196 return -EINVAL; in xadc_write_event_value()
198 mutex_lock(&xadc->mutex); in xadc_write_event_value()
202 xadc->threshold[offset] = val; in xadc_write_event_value()
205 xadc->temp_hysteresis = val; in xadc_write_event_value()
208 mutex_unlock(&xadc->mutex); in xadc_write_event_value()
209 return -EINVAL; in xadc_write_event_value()
212 if (chan->type == IIO_TEMP) { in xadc_write_event_value()
216 * threshold. in xadc_write_event_value()
221 * Since we store the hysteresis as relative (to the threshold) in xadc_write_event_value()
224 * threshold changes. in xadc_write_event_value()
226 if (xadc->threshold[offset] < xadc->temp_hysteresis) in xadc_write_event_value()
227 xadc->threshold[offset + 4] = 0; in xadc_write_event_value()
229 xadc->threshold[offset + 4] = xadc->threshold[offset] - in xadc_write_event_value()
230 xadc->temp_hysteresis; in xadc_write_event_value()
232 xadc->threshold[offset + 4]); in xadc_write_event_value()
241 mutex_unlock(&xadc->mutex); in xadc_write_event_value()