Lines Matching +full:berlin2 +full:- +full:adc
2 * Marvell Berlin2 ADC driver
6 * Antoine Tenart <antoine.tenart@free-electrons.com>
31 #define BERLIN2_SM_CTRL_ADC_SEL(x) ((x) << 5) /* 0-15 */
51 #define BERLIN2_SM_CTRL_TSEN_MODE_0_125 (0x0 << 22) /* 0-125 C */
52 #define BERLIN2_SM_CTRL_TSEN_MODE_10_50 (0x1 << 22) /* 10-50 C */
57 #define BERLIN2_SM_ADC_STATUS_DATA_RDY(x) BIT(x) /* 0-15 */
59 #define BERLIN2_SM_ADC_STATUS_INT_EN(x) (BIT(x) << 16) /* 0-15 */
114 mutex_lock(&priv->lock); in berlin2_adc_read()
117 regmap_write(priv->regmap, BERLIN2_SM_ADC_STATUS, in berlin2_adc_read()
120 /* Configure the ADC */ in berlin2_adc_read()
121 regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, in berlin2_adc_read()
128 ret = wait_event_interruptible_timeout(priv->wq, priv->data_available, in berlin2_adc_read()
132 regmap_update_bits(priv->regmap, BERLIN2_SM_ADC_STATUS, in berlin2_adc_read()
136 ret = -ETIMEDOUT; in berlin2_adc_read()
138 mutex_unlock(&priv->lock); in berlin2_adc_read()
142 regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, in berlin2_adc_read()
145 data = priv->data; in berlin2_adc_read()
146 priv->data_available = false; in berlin2_adc_read()
148 mutex_unlock(&priv->lock); in berlin2_adc_read()
158 mutex_lock(&priv->lock); in berlin2_adc_tsen_read()
161 regmap_write(priv->regmap, BERLIN2_SM_TSEN_STATUS, in berlin2_adc_tsen_read()
164 /* Configure the ADC */ in berlin2_adc_tsen_read()
165 regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, in berlin2_adc_tsen_read()
171 regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_CTRL, in berlin2_adc_tsen_read()
179 ret = wait_event_interruptible_timeout(priv->wq, priv->data_available, in berlin2_adc_tsen_read()
183 regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_STATUS, in berlin2_adc_tsen_read()
187 ret = -ETIMEDOUT; in berlin2_adc_tsen_read()
189 mutex_unlock(&priv->lock); in berlin2_adc_tsen_read()
193 regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_CTRL, in berlin2_adc_tsen_read()
196 data = priv->data; in berlin2_adc_tsen_read()
197 priv->data_available = false; in berlin2_adc_tsen_read()
199 mutex_unlock(&priv->lock); in berlin2_adc_tsen_read()
212 if (chan->type != IIO_VOLTAGE) in berlin2_adc_read_raw()
213 return -EINVAL; in berlin2_adc_read_raw()
215 *val = berlin2_adc_read(indio_dev, chan->channel); in berlin2_adc_read_raw()
221 if (chan->type != IIO_TEMP) in berlin2_adc_read_raw()
222 return -EINVAL; in berlin2_adc_read_raw()
229 temp -= 4096; in berlin2_adc_read_raw()
232 *val = ((temp * 100000) / 264 - 270000); in berlin2_adc_read_raw()
238 return -EINVAL; in berlin2_adc_read_raw()
246 regmap_read(priv->regmap, BERLIN2_SM_ADC_STATUS, &val); in berlin2_adc_irq()
248 regmap_read(priv->regmap, BERLIN2_SM_ADC_DATA, &priv->data); in berlin2_adc_irq()
249 priv->data &= BERLIN2_SM_ADC_MASK; in berlin2_adc_irq()
252 regmap_write(priv->regmap, BERLIN2_SM_ADC_STATUS, val); in berlin2_adc_irq()
254 priv->data_available = true; in berlin2_adc_irq()
255 wake_up_interruptible(&priv->wq); in berlin2_adc_irq()
266 regmap_read(priv->regmap, BERLIN2_SM_TSEN_STATUS, &val); in berlin2_adc_tsen_irq()
268 regmap_read(priv->regmap, BERLIN2_SM_TSEN_DATA, &priv->data); in berlin2_adc_tsen_irq()
269 priv->data &= BERLIN2_SM_TSEN_MASK; in berlin2_adc_tsen_irq()
272 regmap_write(priv->regmap, BERLIN2_SM_TSEN_STATUS, val); in berlin2_adc_tsen_irq()
274 priv->data_available = true; in berlin2_adc_tsen_irq()
275 wake_up_interruptible(&priv->wq); in berlin2_adc_tsen_irq()
296 struct device_node *parent_np = of_get_parent(pdev->dev.of_node); in berlin2_adc_probe()
300 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); in berlin2_adc_probe()
302 return -ENOMEM; in berlin2_adc_probe()
306 priv->regmap = syscon_node_to_regmap(parent_np); in berlin2_adc_probe()
308 if (IS_ERR(priv->regmap)) in berlin2_adc_probe()
309 return PTR_ERR(priv->regmap); in berlin2_adc_probe()
311 irq = platform_get_irq_byname(pdev, "adc"); in berlin2_adc_probe()
319 ret = devm_request_irq(&pdev->dev, irq, berlin2_adc_irq, 0, in berlin2_adc_probe()
320 pdev->dev.driver->name, indio_dev); in berlin2_adc_probe()
324 ret = devm_request_irq(&pdev->dev, tsen_irq, berlin2_adc_tsen_irq, in berlin2_adc_probe()
325 0, pdev->dev.driver->name, indio_dev); in berlin2_adc_probe()
329 init_waitqueue_head(&priv->wq); in berlin2_adc_probe()
330 mutex_init(&priv->lock); in berlin2_adc_probe()
332 indio_dev->name = dev_name(&pdev->dev); in berlin2_adc_probe()
333 indio_dev->modes = INDIO_DIRECT_MODE; in berlin2_adc_probe()
334 indio_dev->info = &berlin2_adc_info; in berlin2_adc_probe()
336 indio_dev->channels = berlin2_adc_channels; in berlin2_adc_probe()
337 indio_dev->num_channels = ARRAY_SIZE(berlin2_adc_channels); in berlin2_adc_probe()
339 /* Power up the ADC */ in berlin2_adc_probe()
340 regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, in berlin2_adc_probe()
344 ret = devm_add_action_or_reset(&pdev->dev, berlin2_adc_powerdown, in berlin2_adc_probe()
345 priv->regmap); in berlin2_adc_probe()
349 return devm_iio_device_register(&pdev->dev, indio_dev); in berlin2_adc_probe()
353 { .compatible = "marvell,berlin2-adc", },
360 .name = "berlin2-adc",
367 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
368 MODULE_DESCRIPTION("Marvell Berlin2 ADC driver");