ucb1x00-assabet.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/device.h>
  15. #include <linux/err.h>
  16. #include <linux/fs.h>
  17. #include <linux/gpio_keys.h>
  18. #include <linux/input.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/mfd/ucb1x00.h>
  22. #define UCB1X00_ATTR(name,input)\
  23. static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
  24. char *buf) \
  25. { \
  26. struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
  27. int val; \
  28. ucb1x00_adc_enable(ucb); \
  29. val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC); \
  30. ucb1x00_adc_disable(ucb); \
  31. return sprintf(buf, "%d\n", val); \
  32. } \
  33. static DEVICE_ATTR(name,0444,name##_show,NULL)
  34. UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
  35. UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
  36. UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
  37. static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
  38. {
  39. struct ucb1x00 *ucb = dev->ucb;
  40. struct platform_device *pdev;
  41. struct gpio_keys_platform_data keys;
  42. static struct gpio_keys_button buttons[6];
  43. unsigned i;
  44. memset(buttons, 0, sizeof(buttons));
  45. memset(&keys, 0, sizeof(keys));
  46. for (i = 0; i < ARRAY_SIZE(buttons); i++) {
  47. buttons[i].code = BTN_0 + i;
  48. buttons[i].gpio = ucb->gpio.base + i;
  49. buttons[i].type = EV_KEY;
  50. buttons[i].can_disable = true;
  51. }
  52. keys.buttons = buttons;
  53. keys.nbuttons = ARRAY_SIZE(buttons);
  54. keys.poll_interval = 50;
  55. keys.name = "ucb1x00";
  56. pdev = platform_device_register_data(&ucb->dev, "gpio-keys", -1,
  57. &keys, sizeof(keys));
  58. device_create_file(&ucb->dev, &dev_attr_vbatt);
  59. device_create_file(&ucb->dev, &dev_attr_vcharger);
  60. device_create_file(&ucb->dev, &dev_attr_batt_temp);
  61. dev->priv = pdev;
  62. return 0;
  63. }
  64. static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
  65. {
  66. struct platform_device *pdev = dev->priv;
  67. if (!IS_ERR(pdev))
  68. platform_device_unregister(pdev);
  69. device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
  70. device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
  71. device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
  72. }
  73. static struct ucb1x00_driver ucb1x00_assabet_driver = {
  74. .add = ucb1x00_assabet_add,
  75. .remove = ucb1x00_assabet_remove,
  76. };
  77. static int __init ucb1x00_assabet_init(void)
  78. {
  79. return ucb1x00_register_driver(&ucb1x00_assabet_driver);
  80. }
  81. static void __exit ucb1x00_assabet_exit(void)
  82. {
  83. ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
  84. }
  85. module_init(ucb1x00_assabet_init);
  86. module_exit(ucb1x00_assabet_exit);
  87. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  88. MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
  89. MODULE_LICENSE("GPL");