| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#include <linux/irq.h> |
|---|
| 25 |
#define MODULE_NAME "diag" |
|---|
| 26 |
|
|---|
| 27 |
#define MAX_GPIO 8 |
|---|
| 28 |
#define FLASH_TIME HZ/6 |
|---|
| 29 |
|
|---|
| 30 |
enum polarity_t { |
|---|
| 31 |
REVERSE = 0, |
|---|
| 32 |
NORMAL = 1, |
|---|
| 33 |
}; |
|---|
| 34 |
|
|---|
| 35 |
enum { |
|---|
| 36 |
PROC_BUTTON, |
|---|
| 37 |
PROC_LED, |
|---|
| 38 |
PROC_MODEL, |
|---|
| 39 |
PROC_GPIOMASK |
|---|
| 40 |
}; |
|---|
| 41 |
|
|---|
| 42 |
struct prochandler_t { |
|---|
| 43 |
int type; |
|---|
| 44 |
void *ptr; |
|---|
| 45 |
}; |
|---|
| 46 |
|
|---|
| 47 |
struct button_t { |
|---|
| 48 |
struct prochandler_t proc; |
|---|
| 49 |
char *name; |
|---|
| 50 |
u32 gpio; |
|---|
| 51 |
unsigned long seen; |
|---|
| 52 |
u8 pressed; |
|---|
| 53 |
}; |
|---|
| 54 |
|
|---|
| 55 |
struct led_t { |
|---|
| 56 |
struct prochandler_t proc; |
|---|
| 57 |
char *name; |
|---|
| 58 |
u32 gpio; |
|---|
| 59 |
u8 polarity; |
|---|
| 60 |
u8 flash; |
|---|
| 61 |
u8 state; |
|---|
| 62 |
}; |
|---|
| 63 |
|
|---|
| 64 |
struct platform_t { |
|---|
| 65 |
char *name; |
|---|
| 66 |
|
|---|
| 67 |
struct button_t buttons[MAX_GPIO]; |
|---|
| 68 |
u32 button_mask; |
|---|
| 69 |
u32 button_polarity; |
|---|
| 70 |
void (*platform_init)(void); |
|---|
| 71 |
|
|---|
| 72 |
struct led_t leds[MAX_GPIO]; |
|---|
| 73 |
}; |
|---|
| 74 |
|
|---|
| 75 |
struct event_t { |
|---|
| 76 |
struct work_struct wq; |
|---|
| 77 |
char buf[256]; |
|---|
| 78 |
char *argv[3]; |
|---|
| 79 |
char *envp[6]; |
|---|
| 80 |
}; |
|---|
| 81 |
|
|---|
| 82 |
extern char *nvram_get(char *str); |
|---|
| 83 |
|
|---|
| 84 |
static struct platform_t platform; |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
static void register_buttons(struct button_t *b); |
|---|
| 89 |
static void unregister_buttons(struct button_t *b); |
|---|
| 90 |
|
|---|
| 91 |
static void hotplug_button(struct event_t *event); |
|---|
| 92 |
static irqreturn_t button_handler(int irq, void *dev_id, struct pt_regs *regs); |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
static void register_leds(struct led_t *l); |
|---|
| 97 |
static void unregister_leds(struct led_t *l); |
|---|
| 98 |
|
|---|
| 99 |
static void set_led_extif(struct led_t *led); |
|---|
| 100 |
static void led_flash(unsigned long dummy); |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
#ifndef TIMER_INITIALIZER |
|---|
| 104 |
#define TIMER_INITIALIZER(_function, _expires, _data) \ |
|---|
| 105 |
{ \ |
|---|
| 106 |
\ |
|---|
| 107 |
function: _function \ |
|---|
| 108 |
} |
|---|
| 109 |
#endif |
|---|
| 110 |
|
|---|
| 111 |
static struct timer_list led_timer = TIMER_INITIALIZER(&led_flash, 0, 0); |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
static struct proc_dir_entry *diag, *leds; |
|---|
| 116 |
|
|---|
| 117 |
static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos); |
|---|
| 118 |
static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos); |
|---|
| 119 |
|
|---|
| 120 |
static struct file_operations diag_proc_fops = { |
|---|
| 121 |
read: diag_proc_read, |
|---|
| 122 |
write: diag_proc_write |
|---|
| 123 |
}; |
|---|
| 124 |
|
|---|
| 125 |
static struct prochandler_t proc_model = { .type = PROC_MODEL }; |
|---|
| 126 |
static struct prochandler_t proc_gpiomask = { .type = PROC_GPIOMASK }; |
|---|
| 127 |
|
|---|