blob: f732b3ac78785444de9ed38b09ad4bd6a5b87b91 [file] [log] [blame]
Stefan Popaca5b4632018-12-17 14:23:36 +02001// SPDX-License-Identifier: GPL-2.0
Michael Hennerichb9618c02011-02-22 21:46:18 +01002/*
3 * AD7606 Parallel Interface ADC driver
4 *
5 * Copyright 2011 Analog Devices Inc.
Michael Hennerichb9618c02011-02-22 21:46:18 +01006 */
7
8#include <linux/module.h>
9#include <linux/platform_device.h>
10#include <linux/types.h>
11#include <linux/err.h>
12#include <linux/io.h>
13
Jonathan Cameron06458e22012-04-25 15:54:58 +010014#include <linux/iio/iio.h>
Michael Hennerichb9618c02011-02-22 21:46:18 +010015#include "ad7606.h"
16
17static int ad7606_par16_read_block(struct device *dev,
Ioana Ciorneie8ef49f2015-10-14 21:14:13 +030018 int count, void *buf)
Michael Hennerichb9618c02011-02-22 21:46:18 +010019{
Wolfram Sangdae013a2018-04-19 16:06:18 +020020 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Michael Henneriche61181d2011-05-18 14:42:01 +010021 struct ad7606_state *st = iio_priv(indio_dev);
Michael Hennerichb9618c02011-02-22 21:46:18 +010022
Ioana Ciorneic30685c2015-10-14 21:14:15 +030023 insw((unsigned long)st->base_address, buf, count);
Michael Hennerichb9618c02011-02-22 21:46:18 +010024
25 return 0;
26}
27
28static const struct ad7606_bus_ops ad7606_par16_bops = {
Stefan Popa54160ae2018-12-17 14:23:38 +020029 .read_block = ad7606_par16_read_block,
Michael Hennerichb9618c02011-02-22 21:46:18 +010030};
31
32static int ad7606_par8_read_block(struct device *dev,
Ioana Ciorneie8ef49f2015-10-14 21:14:13 +030033 int count, void *buf)
Michael Hennerichb9618c02011-02-22 21:46:18 +010034{
Wolfram Sangdae013a2018-04-19 16:06:18 +020035 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Michael Henneriche61181d2011-05-18 14:42:01 +010036 struct ad7606_state *st = iio_priv(indio_dev);
Michael Hennerichb9618c02011-02-22 21:46:18 +010037
Ioana Ciorneic30685c2015-10-14 21:14:15 +030038 insb((unsigned long)st->base_address, buf, count * 2);
Michael Hennerichb9618c02011-02-22 21:46:18 +010039
40 return 0;
41}
42
43static const struct ad7606_bus_ops ad7606_par8_bops = {
Stefan Popa54160ae2018-12-17 14:23:38 +020044 .read_block = ad7606_par8_read_block,
Michael Hennerichb9618c02011-02-22 21:46:18 +010045};
46
Bill Pemberton4ae1c612012-11-19 13:21:57 -050047static int ad7606_par_probe(struct platform_device *pdev)
Michael Hennerichb9618c02011-02-22 21:46:18 +010048{
Lars-Peter Clausen063a51c2016-10-19 19:06:57 +020049 const struct platform_device_id *id = platform_get_device_id(pdev);
Michael Hennerichb9618c02011-02-22 21:46:18 +010050 struct resource *res;
Michael Hennerichb9618c02011-02-22 21:46:18 +010051 void __iomem *addr;
52 resource_size_t remap_size;
Himangi Saraogi744966d62014-01-07 19:44:00 +000053 int irq;
Michael Hennerichb9618c02011-02-22 21:46:18 +010054
55 irq = platform_get_irq(pdev, 0);
Stephen Boyd7c279222019-07-30 11:15:19 -070056 if (irq < 0)
Gustavo A. R. Silvab24d1092017-08-09 10:38:56 -050057 return irq;
Michael Hennerichb9618c02011-02-22 21:46:18 +010058
59 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Himangi Saraogi744966d62014-01-07 19:44:00 +000060 addr = devm_ioremap_resource(&pdev->dev, res);
61 if (IS_ERR(addr))
62 return PTR_ERR(addr);
Michael Hennerichb9618c02011-02-22 21:46:18 +010063
64 remap_size = resource_size(res);
65
Lars-Peter Clausen71faca72016-10-19 19:07:04 +020066 return ad7606_probe(&pdev->dev, irq, addr,
67 id->name, id->driver_data,
68 remap_size > 1 ? &ad7606_par16_bops :
69 &ad7606_par8_bops);
Michael Hennerichb9618c02011-02-22 21:46:18 +010070}
71
Krzysztof Kozlowskiae890d52015-05-02 00:43:22 +090072static const struct platform_device_id ad7606_driver_ids[] = {
Stefan Popa54160ae2018-12-17 14:23:38 +020073 { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
74 { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
75 { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
76 { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
Michael Hennerichb9618c02011-02-22 21:46:18 +010077 { }
78};
Michael Hennerichb9618c02011-02-22 21:46:18 +010079MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
80
Stefan Popa43f9b202018-12-13 14:46:20 +020081static const struct of_device_id ad7606_of_match[] = {
82 { .compatible = "adi,ad7605-4" },
83 { .compatible = "adi,ad7606-4" },
84 { .compatible = "adi,ad7606-6" },
85 { .compatible = "adi,ad7606-8" },
86 { },
87};
88MODULE_DEVICE_TABLE(of, ad7606_of_match);
89
Michael Hennerichb9618c02011-02-22 21:46:18 +010090static struct platform_driver ad7606_driver = {
91 .probe = ad7606_par_probe,
Michael Hennerichb9618c02011-02-22 21:46:18 +010092 .id_table = ad7606_driver_ids,
93 .driver = {
Stefan Popa54160ae2018-12-17 14:23:38 +020094 .name = "ad7606",
95 .pm = AD7606_PM_OPS,
Stefan Popa43f9b202018-12-13 14:46:20 +020096 .of_match_table = ad7606_of_match,
Michael Hennerichb9618c02011-02-22 21:46:18 +010097 },
98};
Michael Hennerich5f953732012-03-01 10:51:05 +010099module_platform_driver(ad7606_driver);
Michael Hennerichb9618c02011-02-22 21:46:18 +0100100
Michael Hennerich9920ed22018-08-14 13:23:17 +0200101MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
Michael Hennerichb9618c02011-02-22 21:46:18 +0100102MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
103MODULE_LICENSE("GPL v2");