diag.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * diag.h - GPIO interface driver for Broadcom boards
  3. *
  4. * Copyright (C) 2006 Mike Baker <[email protected]>,
  5. * Felix Fietkau <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. */
  22. #include <linux/irq.h>
  23. #define MODULE_NAME "diag"
  24. #define MAX_GPIO 16
  25. #define FLASH_TIME HZ/6
  26. enum polarity_t {
  27. REVERSE = 0,
  28. NORMAL = 1,
  29. INPUT = 2,
  30. };
  31. enum {
  32. PROC_BUTTON,
  33. PROC_LED,
  34. PROC_MODEL,
  35. PROC_GPIOMASK
  36. };
  37. struct prochandler_t {
  38. int type;
  39. void *ptr;
  40. };
  41. struct button_t {
  42. struct prochandler_t proc;
  43. char *name;
  44. u32 gpio;
  45. unsigned long seen;
  46. u8 pressed;
  47. };
  48. struct led_t {
  49. struct prochandler_t proc;
  50. char *name;
  51. u32 gpio;
  52. u8 polarity;
  53. u8 flash;
  54. u8 state;
  55. };
  56. struct platform_t {
  57. char *name;
  58. struct button_t buttons[MAX_GPIO];
  59. u32 button_mask;
  60. u32 button_polarity;
  61. void (*platform_init)(void);
  62. struct led_t leds[MAX_GPIO];
  63. };
  64. struct event_t {
  65. struct work_struct wq;
  66. unsigned long seen;
  67. char *name, *action;
  68. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
  69. struct sk_buff *skb;
  70. #else
  71. char *scratch;
  72. char *argv[4];
  73. char *envp[7];
  74. u8 enr, anr;
  75. #endif
  76. };
  77. extern char *nvram_get(char *str);
  78. static struct platform_t platform;
  79. /* buttons */
  80. static void register_buttons(struct button_t *b);
  81. static void unregister_buttons(struct button_t *b);
  82. static void hotplug_button(struct work_struct *work);
  83. static irqreturn_t button_handler(int irq, void *dev_id);
  84. /* leds */
  85. static void register_leds(struct led_t *l);
  86. static void unregister_leds(struct led_t *l);
  87. static void set_led_extif(struct led_t *led);
  88. static void set_led_shift(struct led_t *led);
  89. static void led_flash(unsigned long dummy);
  90. /* 2.4 compatibility */
  91. #ifndef TIMER_INITIALIZER
  92. #define TIMER_INITIALIZER(_function, _expires, _data) \
  93. { \
  94. /* _expires and _data currently unused */ \
  95. function: _function \
  96. }
  97. #endif
  98. static struct timer_list led_timer = TIMER_INITIALIZER(&led_flash, 0, 0);
  99. /* proc */
  100. static struct proc_dir_entry *diag, *leds;
  101. static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos);
  102. static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos);
  103. static struct file_operations diag_proc_fops = {
  104. read: diag_proc_read,
  105. write: diag_proc_write
  106. };
  107. static struct prochandler_t proc_model = { .type = PROC_MODEL };
  108. static struct prochandler_t proc_gpiomask = { .type = PROC_GPIOMASK };