Skip to content

Commit fad64a4

Browse files
committed
iio: adc: Add initial basic support for MAX22531 ADC
Signed-off-by: Abhinav Jain <[email protected]>
1 parent 15b53e9 commit fad64a4

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

drivers/iio/adc/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,12 @@ config MAX1363
11261126
To compile this driver as a module, choose M here: the module will be
11271127
called max1363.
11281128

1129+
config MAX22531
1130+
tristate "Analog Devices MAX22531 ADC Driver"
1131+
depends on SPI
1132+
help
1133+
Say yes here to build support for this driver.
1134+
11291135
config MAX77541_ADC
11301136
tristate "Analog Devices MAX77541 ADC driver"
11311137
depends on MFD_MAX77541

drivers/iio/adc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ obj-$(CONFIG_MAX11205) += max11205.o
156156
obj-$(CONFIG_MAX11410) += max11410.o
157157
obj-$(CONFIG_MAX1241) += max1241.o
158158
obj-$(CONFIG_MAX1363) += max1363.o
159+
obj-$(CONFIG_MAX22531) += max22531.o
159160
obj-$(CONFIG_MAX77541_ADC) += max77541-adc.o
160161
obj-$(CONFIG_MAX9611) += max9611.o
161162
obj-$(CONFIG_MCP320X) += mcp320x.o

drivers/iio/adc/max22531.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <linux/module.h>
2+
#include <linux/spi/spi.h>
3+
#include <linux/iio/iio.h>
4+
5+
enum max22531_id {
6+
max22531,
7+
};
8+
9+
struct max22531 {
10+
struct spi_device *spi;
11+
struct regulator *vref;
12+
};
13+
14+
#define MAX22531_CHANNEL(ch) \
15+
{ \
16+
.type = IIO_VOLTAGE, \
17+
.indexed = 1, \
18+
.channel = (ch), \
19+
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
20+
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
21+
.scan_index = ch, \
22+
.output = 0, \
23+
}
24+
25+
static const struct iio_chan_spec max22531_channels[] = {
26+
MAX22531_CHANNEL(0),
27+
MAX22531_CHANNEL(1),
28+
MAX22531_CHANNEL(2),
29+
MAX22531_CHANNEL(3),
30+
IIO_CHAN_SOFT_TIMESTAMP(2),
31+
};
32+
33+
static const struct iio_info max22531_info = {
34+
};
35+
36+
static int max22531_probe(struct spi_device *spi)
37+
{
38+
pr_err("max22531: probe on\n");
39+
40+
struct max22531 *adc;
41+
struct iio_dev *indio_dev;
42+
const struct spi_device_id *id = spi_get_device_id(spi);
43+
44+
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
45+
if (!indio_dev) {
46+
pr_err("max22531: Failed to allocate memory for IIO device.\n");
47+
return -ENOMEM;
48+
}
49+
50+
adc = iio_priv(indio_dev);
51+
adc->spi = spi;
52+
53+
indio_dev->name = spi_get_device_id(spi)->name;
54+
indio_dev->info = &max22531_info;
55+
indio_dev->channels = max22531_channels;
56+
indio_dev->num_channels = ARRAY_SIZE(max22531_channels);
57+
58+
return devm_iio_device_register(&spi->dev, indio_dev);
59+
}
60+
61+
static const struct spi_device_id max22531_id[] = {
62+
{ "max22531", max22531 },
63+
{}
64+
};
65+
MODULE_DEVICE_TABLE(spi, max22531_id);
66+
67+
static const struct of_device_id max22531_dt_ids[] = {
68+
{ .compatible = "maxim,max22531" },
69+
{},
70+
};
71+
MODULE_DEVICE_TABLE(of, max22531_dt_ids);
72+
73+
static struct spi_driver max22531_driver = {
74+
.driver = {
75+
.name = "max22531",
76+
.of_match_table = max22531_dt_ids,
77+
},
78+
.probe = max22531_probe,
79+
.id_table = max22531_id,
80+
};
81+
module_spi_driver(max22531_driver);
82+
83+
MODULE_AUTHOR("Abhinav Jain <[email protected]>");
84+
MODULE_DESCRIPTION("MAX22531 ADC");
85+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)