Stefan Popa | ca5b463 | 2018-12-17 14:23:36 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 2 | /* |
| 3 | * AD7606 Parallel Interface ADC driver |
| 4 | * |
| 5 | * Copyright 2011 Analog Devices Inc. |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 6 | */ |
| 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 Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 14 | #include <linux/iio/iio.h> |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 15 | #include "ad7606.h" |
| 16 | |
| 17 | static int ad7606_par16_read_block(struct device *dev, |
Ioana Ciornei | e8ef49f | 2015-10-14 21:14:13 +0300 | [diff] [blame] | 18 | int count, void *buf) |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 19 | { |
Wolfram Sang | dae013a | 2018-04-19 16:06:18 +0200 | [diff] [blame] | 20 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
Michael Hennerich | e61181d | 2011-05-18 14:42:01 +0100 | [diff] [blame] | 21 | struct ad7606_state *st = iio_priv(indio_dev); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 22 | |
Ioana Ciornei | c30685c | 2015-10-14 21:14:15 +0300 | [diff] [blame] | 23 | insw((unsigned long)st->base_address, buf, count); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 24 | |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | static const struct ad7606_bus_ops ad7606_par16_bops = { |
Stefan Popa | 54160ae | 2018-12-17 14:23:38 +0200 | [diff] [blame] | 29 | .read_block = ad7606_par16_read_block, |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | static int ad7606_par8_read_block(struct device *dev, |
Ioana Ciornei | e8ef49f | 2015-10-14 21:14:13 +0300 | [diff] [blame] | 33 | int count, void *buf) |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 34 | { |
Wolfram Sang | dae013a | 2018-04-19 16:06:18 +0200 | [diff] [blame] | 35 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
Michael Hennerich | e61181d | 2011-05-18 14:42:01 +0100 | [diff] [blame] | 36 | struct ad7606_state *st = iio_priv(indio_dev); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 37 | |
Ioana Ciornei | c30685c | 2015-10-14 21:14:15 +0300 | [diff] [blame] | 38 | insb((unsigned long)st->base_address, buf, count * 2); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static const struct ad7606_bus_ops ad7606_par8_bops = { |
Stefan Popa | 54160ae | 2018-12-17 14:23:38 +0200 | [diff] [blame] | 44 | .read_block = ad7606_par8_read_block, |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Bill Pemberton | 4ae1c61 | 2012-11-19 13:21:57 -0500 | [diff] [blame] | 47 | static int ad7606_par_probe(struct platform_device *pdev) |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 48 | { |
Lars-Peter Clausen | 063a51c | 2016-10-19 19:06:57 +0200 | [diff] [blame] | 49 | const struct platform_device_id *id = platform_get_device_id(pdev); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 50 | struct resource *res; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 51 | void __iomem *addr; |
| 52 | resource_size_t remap_size; |
Himangi Saraogi | 744966d6 | 2014-01-07 19:44:00 +0000 | [diff] [blame] | 53 | int irq; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 54 | |
| 55 | irq = platform_get_irq(pdev, 0); |
Stephen Boyd | 7c27922 | 2019-07-30 11:15:19 -0700 | [diff] [blame] | 56 | if (irq < 0) |
Gustavo A. R. Silva | b24d109 | 2017-08-09 10:38:56 -0500 | [diff] [blame] | 57 | return irq; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 58 | |
| 59 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Himangi Saraogi | 744966d6 | 2014-01-07 19:44:00 +0000 | [diff] [blame] | 60 | addr = devm_ioremap_resource(&pdev->dev, res); |
| 61 | if (IS_ERR(addr)) |
| 62 | return PTR_ERR(addr); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 63 | |
| 64 | remap_size = resource_size(res); |
| 65 | |
Lars-Peter Clausen | 71faca7 | 2016-10-19 19:07:04 +0200 | [diff] [blame] | 66 | 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 Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Krzysztof Kozlowski | ae890d5 | 2015-05-02 00:43:22 +0900 | [diff] [blame] | 72 | static const struct platform_device_id ad7606_driver_ids[] = { |
Stefan Popa | 54160ae | 2018-12-17 14:23:38 +0200 | [diff] [blame] | 73 | { .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 Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 77 | { } |
| 78 | }; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 79 | MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); |
| 80 | |
Stefan Popa | 43f9b20 | 2018-12-13 14:46:20 +0200 | [diff] [blame] | 81 | static 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 | }; |
| 88 | MODULE_DEVICE_TABLE(of, ad7606_of_match); |
| 89 | |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 90 | static struct platform_driver ad7606_driver = { |
| 91 | .probe = ad7606_par_probe, |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 92 | .id_table = ad7606_driver_ids, |
| 93 | .driver = { |
Stefan Popa | 54160ae | 2018-12-17 14:23:38 +0200 | [diff] [blame] | 94 | .name = "ad7606", |
| 95 | .pm = AD7606_PM_OPS, |
Stefan Popa | 43f9b20 | 2018-12-13 14:46:20 +0200 | [diff] [blame] | 96 | .of_match_table = ad7606_of_match, |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 97 | }, |
| 98 | }; |
Michael Hennerich | 5f95373 | 2012-03-01 10:51:05 +0100 | [diff] [blame] | 99 | module_platform_driver(ad7606_driver); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 100 | |
Michael Hennerich | 9920ed2 | 2018-08-14 13:23:17 +0200 | [diff] [blame] | 101 | MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 102 | MODULE_DESCRIPTION("Analog Devices AD7606 ADC"); |
| 103 | MODULE_LICENSE("GPL v2"); |