ad7606_par.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * AD7606 Parallel Interface ADC driver
  3. *
  4. * Copyright 2011 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2.
  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. #include <linux/iio/iio.h>
  14. #include "ad7606.h"
  15. static int ad7606_par16_read_block(struct device *dev,
  16. int count, void *buf)
  17. {
  18. struct platform_device *pdev = to_platform_device(dev);
  19. struct iio_dev *indio_dev = platform_get_drvdata(pdev);
  20. struct ad7606_state *st = iio_priv(indio_dev);
  21. insw((unsigned long)st->base_address, buf, count);
  22. return 0;
  23. }
  24. static const struct ad7606_bus_ops ad7606_par16_bops = {
  25. .read_block = ad7606_par16_read_block,
  26. };
  27. static int ad7606_par8_read_block(struct device *dev,
  28. int count, void *buf)
  29. {
  30. struct platform_device *pdev = to_platform_device(dev);
  31. struct iio_dev *indio_dev = platform_get_drvdata(pdev);
  32. struct ad7606_state *st = iio_priv(indio_dev);
  33. insb((unsigned long)st->base_address, buf, count * 2);
  34. return 0;
  35. }
  36. static const struct ad7606_bus_ops ad7606_par8_bops = {
  37. .read_block = ad7606_par8_read_block,
  38. };
  39. static int ad7606_par_probe(struct platform_device *pdev)
  40. {
  41. struct resource *res;
  42. struct iio_dev *indio_dev;
  43. void __iomem *addr;
  44. resource_size_t remap_size;
  45. int irq;
  46. irq = platform_get_irq(pdev, 0);
  47. if (irq < 0) {
  48. dev_err(&pdev->dev, "no irq\n");
  49. return -ENODEV;
  50. }
  51. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  52. addr = devm_ioremap_resource(&pdev->dev, res);
  53. if (IS_ERR(addr))
  54. return PTR_ERR(addr);
  55. remap_size = resource_size(res);
  56. indio_dev = ad7606_probe(&pdev->dev, irq, addr,
  57. platform_get_device_id(pdev)->driver_data,
  58. remap_size > 1 ? &ad7606_par16_bops :
  59. &ad7606_par8_bops);
  60. if (IS_ERR(indio_dev))
  61. return PTR_ERR(indio_dev);
  62. platform_set_drvdata(pdev, indio_dev);
  63. return 0;
  64. }
  65. static int ad7606_par_remove(struct platform_device *pdev)
  66. {
  67. struct iio_dev *indio_dev = platform_get_drvdata(pdev);
  68. ad7606_remove(indio_dev, platform_get_irq(pdev, 0));
  69. return 0;
  70. }
  71. #ifdef CONFIG_PM
  72. static int ad7606_par_suspend(struct device *dev)
  73. {
  74. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  75. ad7606_suspend(indio_dev);
  76. return 0;
  77. }
  78. static int ad7606_par_resume(struct device *dev)
  79. {
  80. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  81. ad7606_resume(indio_dev);
  82. return 0;
  83. }
  84. static const struct dev_pm_ops ad7606_pm_ops = {
  85. .suspend = ad7606_par_suspend,
  86. .resume = ad7606_par_resume,
  87. };
  88. #define AD7606_PAR_PM_OPS (&ad7606_pm_ops)
  89. #else
  90. #define AD7606_PAR_PM_OPS NULL
  91. #endif /* CONFIG_PM */
  92. static const struct platform_device_id ad7606_driver_ids[] = {
  93. {
  94. .name = "ad7606-8",
  95. .driver_data = ID_AD7606_8,
  96. }, {
  97. .name = "ad7606-6",
  98. .driver_data = ID_AD7606_6,
  99. }, {
  100. .name = "ad7606-4",
  101. .driver_data = ID_AD7606_4,
  102. },
  103. { }
  104. };
  105. MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
  106. static struct platform_driver ad7606_driver = {
  107. .probe = ad7606_par_probe,
  108. .remove = ad7606_par_remove,
  109. .id_table = ad7606_driver_ids,
  110. .driver = {
  111. .name = "ad7606",
  112. .pm = AD7606_PAR_PM_OPS,
  113. },
  114. };
  115. module_platform_driver(ad7606_driver);
  116. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  117. MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
  118. MODULE_LICENSE("GPL v2");