ucb1x00-assabet.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * linux/drivers/mfd/ucb1x00-assabet.c
  3. *
  4. * Copyright (C) 2001-2003 Russell King, All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License.
  9. *
  10. * We handle the machine-specific bits of the UCB1x00 driver here.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/fs.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/device.h>
  17. #include <linux/mfd/ucb1x00.h>
  18. #include <mach/dma.h>
  19. #define UCB1X00_ATTR(name,input)\
  20. static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
  21. char *buf) \
  22. { \
  23. struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
  24. int val; \
  25. ucb1x00_adc_enable(ucb); \
  26. val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC); \
  27. ucb1x00_adc_disable(ucb); \
  28. return sprintf(buf, "%d\n", val); \
  29. } \
  30. static DEVICE_ATTR(name,0444,name##_show,NULL)
  31. UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
  32. UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
  33. UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
  34. static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
  35. {
  36. device_create_file(&dev->ucb->dev, &dev_attr_vbatt);
  37. device_create_file(&dev->ucb->dev, &dev_attr_vcharger);
  38. device_create_file(&dev->ucb->dev, &dev_attr_batt_temp);
  39. return 0;
  40. }
  41. static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
  42. {
  43. device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
  44. device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
  45. device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
  46. }
  47. static struct ucb1x00_driver ucb1x00_assabet_driver = {
  48. .add = ucb1x00_assabet_add,
  49. .remove = ucb1x00_assabet_remove,
  50. };
  51. static int __init ucb1x00_assabet_init(void)
  52. {
  53. return ucb1x00_register_driver(&ucb1x00_assabet_driver);
  54. }
  55. static void __exit ucb1x00_assabet_exit(void)
  56. {
  57. ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
  58. }
  59. module_init(ucb1x00_assabet_init);
  60. module_exit(ucb1x00_assabet_exit);
  61. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  62. MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
  63. MODULE_LICENSE("GPL");