ad7606_par.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * AD7606 Parallel Interface ADC driver
  4. *
  5. * Copyright 2011 Analog Devices Inc.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/types.h>
  10. #include <linux/err.h>
  11. #include <linux/io.h>
  12. #include <linux/iio/iio.h>
  13. #include "ad7606.h"
  14. static int ad7606_par16_read_block(struct device *dev,
  15. int count, void *buf)
  16. {
  17. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  18. struct ad7606_state *st = iio_priv(indio_dev);
  19. insw((unsigned long)st->base_address, buf, count);
  20. return 0;
  21. }
  22. static const struct ad7606_bus_ops ad7606_par16_bops = {
  23. .read_block = ad7606_par16_read_block,
  24. };
  25. static int ad7606_par8_read_block(struct device *dev,
  26. int count, void *buf)
  27. {
  28. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  29. struct ad7606_state *st = iio_priv(indio_dev);
  30. insb((unsigned long)st->base_address, buf, count * 2);
  31. return 0;
  32. }
  33. static const struct ad7606_bus_ops ad7606_par8_bops = {
  34. .read_block = ad7606_par8_read_block,
  35. };
  36. static int ad7606_par_probe(struct platform_device *pdev)
  37. {
  38. const struct platform_device_id *id = platform_get_device_id(pdev);
  39. struct resource *res;
  40. void __iomem *addr;
  41. resource_size_t remap_size;
  42. int irq;
  43. irq = platform_get_irq(pdev, 0);
  44. if (irq < 0)
  45. return irq;
  46. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  47. addr = devm_ioremap_resource(&pdev->dev, res);
  48. if (IS_ERR(addr))
  49. return PTR_ERR(addr);
  50. remap_size = resource_size(res);
  51. return ad7606_probe(&pdev->dev, irq, addr,
  52. id->name, id->driver_data,
  53. remap_size > 1 ? &ad7606_par16_bops :
  54. &ad7606_par8_bops);
  55. }
  56. static const struct platform_device_id ad7606_driver_ids[] = {
  57. { .name = "ad7605-4", .driver_data = ID_AD7605_4, },
  58. { .name = "ad7606-4", .driver_data = ID_AD7606_4, },
  59. { .name = "ad7606-6", .driver_data = ID_AD7606_6, },
  60. { .name = "ad7606-8", .driver_data = ID_AD7606_8, },
  61. { }
  62. };
  63. MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
  64. static const struct of_device_id ad7606_of_match[] = {
  65. { .compatible = "adi,ad7605-4" },
  66. { .compatible = "adi,ad7606-4" },
  67. { .compatible = "adi,ad7606-6" },
  68. { .compatible = "adi,ad7606-8" },
  69. { },
  70. };
  71. MODULE_DEVICE_TABLE(of, ad7606_of_match);
  72. static struct platform_driver ad7606_driver = {
  73. .probe = ad7606_par_probe,
  74. .id_table = ad7606_driver_ids,
  75. .driver = {
  76. .name = "ad7606",
  77. .pm = AD7606_PM_OPS,
  78. .of_match_table = ad7606_of_match,
  79. },
  80. };
  81. module_platform_driver(ad7606_driver);
  82. MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
  83. MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
  84. MODULE_LICENSE("GPL v2");