static int create_simple_config_led_proc_entry(void) { if (simple_config_entry != NULL) { printk("Already have a proc entry for /proc/simple_config!\n"); return -ENOENT; } simple_config_entry = proc_mkdir("simple_config", NULL); if (!simple_config_entry) return -ENOENT; simulate_push_button_entry = create_proc_entry("push_button", 0644, simple_config_entry); if (!simulate_push_button_entry) return -ENOENT; simulate_push_button_entry->write_proc = push_button_write; simulate_push_button_entry->read_proc = push_button_read; tricolor_led_entry = create_proc_entry("tricolor_led", 0644, simple_config_entry); if (!tricolor_led_entry) return -ENOENT; tricolor_led_entry->write_proc = gpio_tricolor_led_write; tricolor_led_entry->read_proc = gpio_tricolor_led_read; /* configure gpio as outputs */ ar7100_gpio_config_output(TRICOLOR_LED_GREEN_PIN); ar7100_gpio_config_output(TRICOLOR_LED_YELLOW_PIN); /* switch off the led */ ar7100_gpio_out_val(TRICOLOR_LED_GREEN_PIN, OFF); ar7100_gpio_out_val(TRICOLOR_LED_YELLOW_PIN, OFF); return 0; }
static int gpio_tricolor_led_write (struct file *file, const char *buf, unsigned long count, void *data) { u_int32_t val, green_led_onoff = 0, yellow_led_onoff = 0; if (sscanf(buf, "%d", &val) != 1) return -EINVAL; if (val >= LED_STATE_MAX) return -EINVAL; if (val == gpio_tricolorled) return count; switch (val) { case LED_STATE_OFF : green_led_onoff = OFF; /* both LEDs OFF */ yellow_led_onoff = OFF; break; case LED_STATE_GREEN: green_led_onoff = ON; /* green ON, Yellow OFF */ yellow_led_onoff = OFF; break; case LED_STATE_YELLOW: green_led_onoff = OFF; /* green OFF, Yellow ON */ yellow_led_onoff = ON; break; case LED_STATE_ORANGE: green_led_onoff = ON; /* both LEDs ON */ yellow_led_onoff = ON; break; } ar7100_gpio_out_val (TRICOLOR_LED_GREEN_PIN, green_led_onoff); ar7100_gpio_out_val (TRICOLOR_LED_YELLOW_PIN, yellow_led_onoff); gpio_tricolorled = val; return count; }