Skip to content

Instantly share code, notes, and snippets.

@galaxyfreak
Created November 23, 2015 21:18
Show Gist options
  • Save galaxyfreak/979bdbf20d50816e6dc6 to your computer and use it in GitHub Desktop.
Save galaxyfreak/979bdbf20d50816e6dc6 to your computer and use it in GitHub Desktop.
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
#include <linux/gpio.h>
int ds_gpio = 13;
char ds = '0';
int ds_read( char *page, char **start, off_t off, int count, int *eof, void *data )
{
return sprintf(page, "%c\n", ds );
}
static int __init ds_hw_id_init(void)
{
int ret = -1;
printk(KERN_INFO "ds_hw_id_init enter\n");
ret = gpio_request(ds_gpio, "ds");
if (ret) {
printk(KERN_INFO "gpio_%d request failed!!!!\n", ds_gpio);
} else if (gpio_get_value(ds_gpio))
ds = '1';
gpio_free(ds_gpio);
create_proc_read_entry("ds", 0, NULL, ds_read, NULL);
return 0;
}
static void __exit ds_hw_id_exit(void)
{
printk(KERN_INFO "ds_hw_id_exit enter\n");
}
module_init(ds_hw_id_init);
module_exit(ds_hw_id_exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment