ucb1x00-assabet.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/drivers/mfd/ucb1x00-assabet.c
  4. *
  5. * Copyright (C) 2001-2003 Russell King, All Rights Reserved.
  6. *
  7. * We handle the machine-specific bits of the UCB1x00 driver here.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/device.h>
  12. #include <linux/err.h>
  13. #include <linux/fs.h>
  14. #include <linux/gpio_keys.h>
  15. #include <linux/input.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/mfd/ucb1x00.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. struct ucb1x00 *ucb = dev->ucb;
  37. struct platform_device *pdev;
  38. struct gpio_keys_platform_data keys;
  39. static struct gpio_keys_button buttons[6];
  40. unsigned i;
  41. memset(buttons, 0, sizeof(buttons));
  42. memset(&keys, 0, sizeof(keys));
  43. for (i = 0; i < ARRAY_SIZE(buttons); i++) {
  44. buttons[i].code = BTN_0 + i;
  45. buttons[i].gpio = ucb->gpio.base + i;
  46. buttons[i].type = EV_KEY;
  47. buttons[i].can_disable = true;
  48. }
  49. keys.buttons = buttons;
  50. keys.nbuttons = ARRAY_SIZE(buttons);
  51. keys.poll_interval = 50;
  52. keys.name = "ucb1x00";
  53. pdev = platform_device_register_data(&ucb->dev, "gpio-keys", -1,
  54. &keys, sizeof(keys));
  55. device_create_file(&ucb->dev, &dev_attr_vbatt);
  56. device_create_file(&ucb->dev, &dev_attr_vcharger);
  57. device_create_file(&ucb->dev, &dev_attr_batt_temp);
  58. dev->priv = pdev;
  59. return 0;
  60. }
  61. static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
  62. {
  63. struct platform_device *pdev = dev->priv;
  64. if (!IS_ERR(pdev))
  65. platform_device_unregister(pdev);
  66. device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
  67. device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
  68. device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
  69. }
  70. static struct ucb1x00_driver ucb1x00_assabet_driver = {
  71. .add = ucb1x00_assabet_add,
  72. .remove = ucb1x00_assabet_remove,
  73. };
  74. static int __init ucb1x00_assabet_init(void)
  75. {
  76. return ucb1x00_register_driver(&ucb1x00_assabet_driver);
  77. }
  78. static void __exit ucb1x00_assabet_exit(void)
  79. {
  80. ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
  81. }
  82. module_init(ucb1x00_assabet_init);
  83. module_exit(ucb1x00_assabet_exit);
  84. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  85. MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
  86. MODULE_LICENSE("GPL");