Lines Matching +full:adc +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-or-later
11 * ADC<bb><c>S<sss>, where
13 * * c is the number of channels (1, 2, 4, 8)
18 * http://www.national.com/ds/DC/ADC<bb><c>S<sss>.pdf
32 #include <linux/hwmon-sysfs.h>
42 u32 channels; member
52 struct adcxx *adc = spi_get_drvdata(spi); in adcxx_show() local
58 if (mutex_lock_interruptible(&adc->lock)) in adcxx_show()
59 return -ERESTARTSYS; in adcxx_show()
61 if (adc->channels == 1) { in adcxx_show()
64 tx_buf[0] = attr->index << 3; /* other bits are don't care */ in adcxx_show()
77 value = value * adc->reference >> 12; in adcxx_show()
80 mutex_unlock(&adc->lock); in adcxx_show()
95 struct adcxx *adc = spi_get_drvdata(spi); in adcxx_max_show() local
98 if (mutex_lock_interruptible(&adc->lock)) in adcxx_max_show()
99 return -ERESTARTSYS; in adcxx_max_show()
101 reference = adc->reference; in adcxx_max_show()
103 mutex_unlock(&adc->lock); in adcxx_max_show()
113 struct adcxx *adc = spi_get_drvdata(spi); in adcxx_max_store() local
117 return -EINVAL; in adcxx_max_store()
119 if (mutex_lock_interruptible(&adc->lock)) in adcxx_max_store()
120 return -ERESTARTSYS; in adcxx_max_store()
122 adc->reference = value; in adcxx_max_store()
124 mutex_unlock(&adc->lock); in adcxx_max_store()
132 return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); in adcxx_name_show()
149 /*----------------------------------------------------------------------*/
153 int channels = spi_get_device_id(spi)->driver_data; in adcxx_probe() local
154 struct adcxx *adc; in adcxx_probe() local
158 adc = devm_kzalloc(&spi->dev, sizeof(*adc), GFP_KERNEL); in adcxx_probe()
159 if (!adc) in adcxx_probe()
160 return -ENOMEM; in adcxx_probe()
163 adc->reference = 3300; in adcxx_probe()
164 adc->channels = channels; in adcxx_probe()
165 mutex_init(&adc->lock); in adcxx_probe()
167 mutex_lock(&adc->lock); in adcxx_probe()
169 spi_set_drvdata(spi, adc); in adcxx_probe()
171 for (i = 0; i < 3 + adc->channels; i++) { in adcxx_probe()
172 status = device_create_file(&spi->dev, &ad_input[i].dev_attr); in adcxx_probe()
174 dev_err(&spi->dev, "device_create_file failed.\n"); in adcxx_probe()
179 adc->hwmon_dev = hwmon_device_register(&spi->dev); in adcxx_probe()
180 if (IS_ERR(adc->hwmon_dev)) { in adcxx_probe()
181 dev_err(&spi->dev, "hwmon_device_register failed.\n"); in adcxx_probe()
182 status = PTR_ERR(adc->hwmon_dev); in adcxx_probe()
186 mutex_unlock(&adc->lock); in adcxx_probe()
190 for (i--; i >= 0; i--) in adcxx_probe()
191 device_remove_file(&spi->dev, &ad_input[i].dev_attr); in adcxx_probe()
193 mutex_unlock(&adc->lock); in adcxx_probe()
199 struct adcxx *adc = spi_get_drvdata(spi); in adcxx_remove() local
202 mutex_lock(&adc->lock); in adcxx_remove()
203 hwmon_device_unregister(adc->hwmon_dev); in adcxx_remove()
204 for (i = 0; i < 3 + adc->channels; i++) in adcxx_remove()
205 device_remove_file(&spi->dev, &ad_input[i].dev_attr); in adcxx_remove()
207 mutex_unlock(&adc->lock); in adcxx_remove()