Lines Matching +full:static +full:- +full:config

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mcp3422.c - driver for the Microchip mcp3421/2/3/4/5/6/7/8 chip family
41 #define MCP3422_CHANNEL(config) (((config) & MCP3422_CHANNEL_MASK) >> 5) argument
42 #define MCP3422_PGA(config) ((config) & MCP3422_PGA_MASK) argument
43 #define MCP3422_SAMPLE_RATE(config) (((config) & MCP3422_SRATE_MASK) >> 2) argument
59 static const int mcp3422_scales[4][4] = {
66 static const int mcp3422_read_times[4] = {
73 static const int mcp3422_sample_rates[4] = {
80 static const int mcp3422_sign_extend[4] = {
90 u8 config; member
95 static int mcp3422_update_config(struct mcp3422 *adc, u8 newconfig) in mcp3422_update_config()
99 ret = i2c_master_send(adc->i2c, &newconfig, 1); in mcp3422_update_config()
101 adc->config = newconfig; in mcp3422_update_config()
108 static int mcp3422_read(struct mcp3422 *adc, int *value, u8 *config) in mcp3422_read() argument
111 u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config); in mcp3422_read()
116 ret = i2c_master_recv(adc->i2c, buf, 4); in mcp3422_read()
118 *config = buf[3]; in mcp3422_read()
120 ret = i2c_master_recv(adc->i2c, buf, 3); in mcp3422_read()
122 *config = buf[2]; in mcp3422_read()
130 static int mcp3422_read_channel(struct mcp3422 *adc, in mcp3422_read_channel()
134 u8 config; in mcp3422_read_channel() local
135 u8 req_channel = channel->channel; in mcp3422_read_channel()
137 mutex_lock(&adc->lock); in mcp3422_read_channel()
139 if (req_channel != MCP3422_CHANNEL(adc->config)) { in mcp3422_read_channel()
140 config = adc->config; in mcp3422_read_channel()
141 config &= ~MCP3422_CHANNEL_MASK; in mcp3422_read_channel()
142 config |= MCP3422_CHANNEL_VALUE(req_channel); in mcp3422_read_channel()
143 config &= ~MCP3422_PGA_MASK; in mcp3422_read_channel()
144 config |= MCP3422_PGA_VALUE(adc->pga[req_channel]); in mcp3422_read_channel()
145 ret = mcp3422_update_config(adc, config); in mcp3422_read_channel()
147 mutex_unlock(&adc->lock); in mcp3422_read_channel()
150 msleep(mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->config)]); in mcp3422_read_channel()
153 ret = mcp3422_read(adc, value, &config); in mcp3422_read_channel()
155 mutex_unlock(&adc->lock); in mcp3422_read_channel()
160 static int mcp3422_read_raw(struct iio_dev *iio, in mcp3422_read_raw()
167 u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config); in mcp3422_read_raw()
168 u8 pga = MCP3422_PGA(adc->config); in mcp3422_read_raw()
174 return -EINVAL; in mcp3422_read_raw()
184 *val1 = mcp3422_sample_rates[MCP3422_SAMPLE_RATE(adc->config)]; in mcp3422_read_raw()
191 return -EINVAL; in mcp3422_read_raw()
194 static int mcp3422_write_raw(struct iio_dev *iio, in mcp3422_write_raw()
200 u8 config = adc->config; in mcp3422_write_raw() local
201 u8 req_channel = channel->channel; in mcp3422_write_raw()
202 u8 sample_rate = MCP3422_SAMPLE_RATE(config); in mcp3422_write_raw()
208 return -EINVAL; in mcp3422_write_raw()
212 adc->pga[req_channel] = i; in mcp3422_write_raw()
214 config &= ~MCP3422_CHANNEL_MASK; in mcp3422_write_raw()
215 config |= MCP3422_CHANNEL_VALUE(req_channel); in mcp3422_write_raw()
216 config &= ~MCP3422_PGA_MASK; in mcp3422_write_raw()
217 config |= MCP3422_PGA_VALUE(adc->pga[req_channel]); in mcp3422_write_raw()
219 return mcp3422_update_config(adc, config); in mcp3422_write_raw()
222 return -EINVAL; in mcp3422_write_raw()
236 if (adc->id > 4) in mcp3422_write_raw()
237 return -EINVAL; in mcp3422_write_raw()
241 return -EINVAL; in mcp3422_write_raw()
244 config &= ~MCP3422_CHANNEL_MASK; in mcp3422_write_raw()
245 config |= MCP3422_CHANNEL_VALUE(req_channel); in mcp3422_write_raw()
246 config &= ~MCP3422_SRATE_MASK; in mcp3422_write_raw()
247 config |= MCP3422_SAMPLE_RATE_VALUE(temp); in mcp3422_write_raw()
249 return mcp3422_update_config(adc, config); in mcp3422_write_raw()
255 return -EINVAL; in mcp3422_write_raw()
258 static int mcp3422_write_raw_get_fmt(struct iio_dev *indio_dev, in mcp3422_write_raw_get_fmt()
267 return -EINVAL; in mcp3422_write_raw_get_fmt()
271 static ssize_t mcp3422_show_samp_freqs(struct device *dev, in mcp3422_show_samp_freqs()
276 if (adc->id > 4) in mcp3422_show_samp_freqs()
282 static ssize_t mcp3422_show_scales(struct device *dev, in mcp3422_show_scales()
286 u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config); in mcp3422_show_scales()
295 static IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO,
297 static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO,
300 static struct attribute *mcp3422_attributes[] = {
306 static const struct attribute_group mcp3422_attribute_group = {
310 static const struct iio_chan_spec mcp3421_channels[] = {
314 static const struct iio_chan_spec mcp3422_channels[] = {
319 static const struct iio_chan_spec mcp3424_channels[] = {
326 static const struct iio_info mcp3422_info = {
333 static int mcp3422_probe(struct i2c_client *client) in mcp3422_probe()
339 u8 config; in mcp3422_probe() local
341 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in mcp3422_probe()
342 return -EOPNOTSUPP; in mcp3422_probe()
344 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adc)); in mcp3422_probe()
346 return -ENOMEM; in mcp3422_probe()
349 adc->i2c = client; in mcp3422_probe()
350 adc->id = (u8)(id->driver_data); in mcp3422_probe()
352 mutex_init(&adc->lock); in mcp3422_probe()
354 indio_dev->name = dev_name(&client->dev); in mcp3422_probe()
355 indio_dev->modes = INDIO_DIRECT_MODE; in mcp3422_probe()
356 indio_dev->info = &mcp3422_info; in mcp3422_probe()
358 switch (adc->id) { in mcp3422_probe()
361 indio_dev->channels = mcp3421_channels; in mcp3422_probe()
362 indio_dev->num_channels = ARRAY_SIZE(mcp3421_channels); in mcp3422_probe()
368 indio_dev->channels = mcp3422_channels; in mcp3422_probe()
369 indio_dev->num_channels = ARRAY_SIZE(mcp3422_channels); in mcp3422_probe()
373 indio_dev->channels = mcp3424_channels; in mcp3422_probe()
374 indio_dev->num_channels = ARRAY_SIZE(mcp3424_channels); in mcp3422_probe()
379 config = (MCP3422_CONT_SAMPLING in mcp3422_probe()
383 err = mcp3422_update_config(adc, config); in mcp3422_probe()
387 err = devm_iio_device_register(&client->dev, indio_dev); in mcp3422_probe()
396 static const struct i2c_device_id mcp3422_id[] = {
409 static const struct of_device_id mcp3422_of_match[] = {
415 static struct i2c_driver mcp3422_driver = {