Lines Matching +full:int +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
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()
124 enum iio_event_direction dir, int state) 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()
161 int xadc_read_event_value(struct iio_dev *indio_dev, in xadc_read_event_value()
164 int *val, int *val2) in xadc_read_event_value()
166 unsigned int offset = xadc_get_threshold_offset(chan, dir); in xadc_read_event_value()
171 *val = xadc->threshold[offset]; in xadc_read_event_value()
174 *val = xadc->temp_hysteresis; in xadc_read_event_value()
177 return -EINVAL; in xadc_read_event_value()
185 int xadc_write_event_value(struct iio_dev *indio_dev, in xadc_write_event_value()
188 int val, int val2) in xadc_write_event_value()
190 unsigned int offset = xadc_get_threshold_offset(chan, dir); in xadc_write_event_value()
192 int ret = 0; in xadc_write_event_value()
197 return -EINVAL; in xadc_write_event_value()
199 mutex_lock(&xadc->mutex); in xadc_write_event_value()
203 xadc->threshold[offset] = val; in xadc_write_event_value()
206 xadc->temp_hysteresis = val; in xadc_write_event_value()
209 mutex_unlock(&xadc->mutex); in xadc_write_event_value()
210 return -EINVAL; in xadc_write_event_value()
213 if (chan->type == IIO_TEMP) { in xadc_write_event_value()
217 * threshold. in xadc_write_event_value()
222 * Since we store the hysteresis as relative (to the threshold) in xadc_write_event_value()
225 * threshold changes. in xadc_write_event_value()
227 if (xadc->threshold[offset] < xadc->temp_hysteresis) in xadc_write_event_value()
228 xadc->threshold[offset + 4] = 0; in xadc_write_event_value()
230 xadc->threshold[offset + 4] = xadc->threshold[offset] - in xadc_write_event_value()
231 xadc->temp_hysteresis; in xadc_write_event_value()
233 xadc->threshold[offset + 4]); in xadc_write_event_value()
242 mutex_unlock(&xadc->mutex); in xadc_write_event_value()