ucb1x00-assabet.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <asm/dma.h>
  18. #include "ucb1x00.h"
  19. #define UCB1X00_ATTR(name,input)\
  20. static ssize_t name##_show(struct class_device *dev, char *buf) \
  21. { \
  22. struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
  23. int val; \
  24. ucb1x00_adc_enable(ucb); \
  25. val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC); \
  26. ucb1x00_adc_disable(ucb); \
  27. return sprintf(buf, "%d\n", val); \
  28. } \
  29. static CLASS_DEVICE_ATTR(name,0444,name##_show,NULL)
  30. UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
  31. UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
  32. UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
  33. static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
  34. {
  35. class_device_create_file(&dev->ucb->cdev, &class_device_attr_vbatt);
  36. class_device_create_file(&dev->ucb->cdev, &class_device_attr_vcharger);
  37. class_device_create_file(&dev->ucb->cdev, &class_device_attr_batt_temp);
  38. return 0;
  39. }
  40. static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
  41. {
  42. class_device_remove_file(&dev->ucb->cdev, &class_device_attr_batt_temp);
  43. class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vcharger);
  44. class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vbatt);
  45. }
  46. static struct ucb1x00_driver ucb1x00_assabet_driver = {
  47. .add = ucb1x00_assabet_add,
  48. .remove = ucb1x00_assabet_remove,
  49. };
  50. static int __init ucb1x00_assabet_init(void)
  51. {
  52. return ucb1x00_register_driver(&ucb1x00_assabet_driver);
  53. }
  54. static void __exit ucb1x00_assabet_exit(void)
  55. {
  56. ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
  57. }
  58. module_init(ucb1x00_assabet_init);
  59. module_exit(ucb1x00_assabet_exit);
  60. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  61. MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
  62. MODULE_LICENSE("GPL");