module: Convert symbol namespace to string literal
[linux.git] / drivers / iio / adc / ad7091r5.c
blobb472b9498fd1307e493579e257769ace233eb073
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * AD7091R5 Analog to Digital converter driver
5 * Copyright 2014-2019 Analog Devices Inc.
6 */
8 #include <linux/i2c.h>
9 #include <linux/iio/iio.h>
10 #include <linux/module.h>
11 #include <linux/regmap.h>
13 #include "ad7091r-base.h"
15 static const struct iio_chan_spec ad7091r5_channels_irq[] = {
16 AD7091R_CHANNEL(0, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
17 AD7091R_CHANNEL(1, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
18 AD7091R_CHANNEL(2, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
19 AD7091R_CHANNEL(3, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
22 static const struct iio_chan_spec ad7091r5_channels_noirq[] = {
23 AD7091R_CHANNEL(0, 12, NULL, 0),
24 AD7091R_CHANNEL(1, 12, NULL, 0),
25 AD7091R_CHANNEL(2, 12, NULL, 0),
26 AD7091R_CHANNEL(3, 12, NULL, 0),
29 static int ad7091r5_set_mode(struct ad7091r_state *st, enum ad7091r_mode mode)
31 int ret, conf;
33 switch (mode) {
34 case AD7091R_MODE_SAMPLE:
35 conf = 0;
36 break;
37 case AD7091R_MODE_COMMAND:
38 conf = AD7091R_REG_CONF_CMD;
39 break;
40 case AD7091R_MODE_AUTOCYCLE:
41 conf = AD7091R_REG_CONF_AUTO;
42 break;
43 default:
44 return -EINVAL;
47 ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
48 AD7091R_REG_CONF_MODE_MASK, conf);
49 if (ret)
50 return ret;
52 st->mode = mode;
54 return 0;
57 static unsigned int ad7091r5_reg_result_chan_id(unsigned int val)
59 return AD7091R5_REG_RESULT_CH_ID(val);
62 static const struct ad7091r_chip_info ad7091r5_chip_info_irq = {
63 .name = "ad7091r-5",
64 .channels = ad7091r5_channels_irq,
65 .num_channels = ARRAY_SIZE(ad7091r5_channels_irq),
66 .vref_mV = 2500,
67 .reg_result_chan_id = &ad7091r5_reg_result_chan_id,
68 .set_mode = &ad7091r5_set_mode,
71 static const struct ad7091r_chip_info ad7091r5_chip_info_noirq = {
72 .name = "ad7091r-5",
73 .channels = ad7091r5_channels_noirq,
74 .num_channels = ARRAY_SIZE(ad7091r5_channels_noirq),
75 .vref_mV = 2500,
76 .reg_result_chan_id = &ad7091r5_reg_result_chan_id,
77 .set_mode = &ad7091r5_set_mode,
80 static const struct regmap_config ad7091r_regmap_config = {
81 .reg_bits = 8,
82 .val_bits = 16,
83 .writeable_reg = ad7091r_writeable_reg,
84 .volatile_reg = ad7091r_volatile_reg,
87 static void ad7091r5_regmap_init(struct ad7091r_state *st,
88 const struct regmap_config *regmap_conf)
90 struct i2c_client *i2c = container_of(st->dev, struct i2c_client, dev);
92 st->map = devm_regmap_init_i2c(i2c, regmap_conf);
95 static struct ad7091r_init_info ad7091r5_init_info = {
96 .info_irq = &ad7091r5_chip_info_irq,
97 .info_no_irq = &ad7091r5_chip_info_noirq,
98 .regmap_config = &ad7091r_regmap_config,
99 .init_adc_regmap = &ad7091r5_regmap_init
102 static int ad7091r5_i2c_probe(struct i2c_client *i2c)
104 const struct ad7091r_init_info *init_info;
106 init_info = i2c_get_match_data(i2c);
107 if (!init_info)
108 return -EINVAL;
110 return ad7091r_probe(&i2c->dev, init_info, i2c->irq);
113 static const struct of_device_id ad7091r5_dt_ids[] = {
114 { .compatible = "adi,ad7091r5", .data = &ad7091r5_init_info },
117 MODULE_DEVICE_TABLE(of, ad7091r5_dt_ids);
119 static const struct i2c_device_id ad7091r5_i2c_ids[] = {
120 { "ad7091r5", (kernel_ulong_t)&ad7091r5_init_info },
123 MODULE_DEVICE_TABLE(i2c, ad7091r5_i2c_ids);
125 static struct i2c_driver ad7091r5_driver = {
126 .driver = {
127 .name = "ad7091r5",
128 .of_match_table = ad7091r5_dt_ids,
130 .probe = ad7091r5_i2c_probe,
131 .id_table = ad7091r5_i2c_ids,
133 module_i2c_driver(ad7091r5_driver);
135 MODULE_AUTHOR("Beniamin Bia <beniamin.bia@analog.com>");
136 MODULE_DESCRIPTION("Analog Devices AD7091R5 multi-channel ADC driver");
137 MODULE_LICENSE("GPL v2");
138 MODULE_IMPORT_NS("IIO_AD7091R");