qshi
8 years ago
2 changed files with 148 additions and 2 deletions
@ -0,0 +1,141 @@ |
|||
/* front pannel leds and key input driver */ |
|||
#include <linux/init.h> |
|||
#include <linux/module.h> |
|||
#include <linux/moduleparam.h> |
|||
#include <linux/pnp.h> |
|||
#include <linux/slab.h> |
|||
#include <linux/interrupt.h> |
|||
#include <linux/wait.h> |
|||
#include <linux/acpi.h> |
|||
#include <linux/leds.h> |
|||
#include <linux/kernel.h> |
|||
#include <linux/init.h> |
|||
#include <linux/clk.h> |
|||
#include <linux/module.h> |
|||
#include <linux/miscdevice.h> |
|||
#include <linux/ioctl.h> |
|||
#include <asm/io.h> |
|||
|
|||
enum led_type { |
|||
LED_TYPE_WORK = 0x01, |
|||
LED_TYPE_FAULT, |
|||
LED_TYPE_STATUS |
|||
}; |
|||
|
|||
struct led_arg { |
|||
enum led_type type; |
|||
int on; |
|||
}; |
|||
|
|||
#define FPC_IOCTL 'f' |
|||
#define FPC_IOCTL_KEY _IO(FPC_IOCTL, 0x08) |
|||
#define FPC_IOCTL_LED _IO(FPC_IOCTL, 0x09) |
|||
|
|||
/* The fifth bar of pnp 00:06 */ |
|||
#define PNP5_MEM_START 0xfed0c000 |
|||
#define PNP5_MEM_END 0xfed0ffff |
|||
#define PNP5_MEM_SIZE (PNP5_MEM_END + 1 - PNP5_MEM_START) |
|||
|
|||
#define REG_KEY 0x508 /* input */ |
|||
#define REG_FAULT 0x2198 /* output */ |
|||
#define REG_WORK 0x21A8 /* output */ |
|||
#define REG_STATUS 0x528 /* output */ |
|||
|
|||
#define LED_WORK_ON 0x0 |
|||
#define LED_WORK_OFF 0x1 |
|||
|
|||
#define LED_FAULT_ON 0x0 |
|||
#define LED_FAULT_OFF 0x1 |
|||
|
|||
#define LED_STATUS_ON 0x0 |
|||
#define LED_STATUS_OFF 0x1 |
|||
|
|||
/* set work led */ |
|||
static void work_led_set(int on) |
|||
{ |
|||
|
|||
} |
|||
|
|||
/* set fault led */ |
|||
static void fault_led_set(int on) |
|||
{ |
|||
|
|||
} |
|||
|
|||
|
|||
/* set status led */ |
|||
static void status_led_set(int on) |
|||
{ |
|||
|
|||
} |
|||
|
|||
static int key_status(void ) |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
static void __set_led_var(struct led_arg *lap) |
|||
{ |
|||
switch (lap->type) { |
|||
case LED_TYPE_WORK: |
|||
work_led_set(lap->on); |
|||
break; |
|||
case LED_TYPE_FAULT: |
|||
fault_led_set(lap->on); |
|||
break; |
|||
case LED_TYPE_STATUS: |
|||
status_led_set(lap->on); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
static long button_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
|||
{ |
|||
int ret = 0; |
|||
struct led_arg *lap; |
|||
|
|||
switch (cmd) { |
|||
case FPC_IOCTL_KEY: |
|||
*(int *)arg = key_status(); |
|||
break; |
|||
case FPC_IOCTL_LED: |
|||
lap = (struct led_arg *)arg; |
|||
__set_led_var(lap); |
|||
break; |
|||
default: |
|||
ret = -EINVAL; |
|||
break; |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
static const struct file_operations button_fops = { |
|||
.owner = THIS_MODULE, |
|||
.unlocked_ioctl = button_ioctl, |
|||
.llseek = noop_llseek, |
|||
}; |
|||
|
|||
static struct miscdevice _fpc = { |
|||
.minor = MISC_DYNAMIC_MINOR, |
|||
.name = "fpc", |
|||
.mode = 0666, |
|||
.fops = &button_fops, |
|||
}; |
|||
|
|||
static int __init fpc_init(void) |
|||
{ |
|||
return misc_register(&_fpc); |
|||
} |
|||
|
|||
static void __exit fpc_exit(void) |
|||
{ |
|||
misc_deregister(&_fpc); |
|||
} |
|||
|
|||
module_init(fpc_init); |
|||
module_exit(fpc_exit); |
|||
MODULE_AUTHOR("goohov@cd.com"); |
|||
MODULE_DESCRIPTION("Front Pannel Control Driver"); |
|||
MODULE_VERSION("1.0"); |
|||
MODULE_LICENSE("GPL"); |
|||
|
Loading…
Reference in new issue