diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index c779509..43ae42d 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -51,6 +51,11 @@ config AD525X_DPOT_SPI To compile this driver as a module, choose M here: the module will be called ad525x_dpot-spi. +config MY + tristate "my driver example" + help + just an example for a simple driver dummy + config ATMEL_PWM tristate "Atmel AT32/AT91 PWM support" depends on HAVE_CLK diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 3e1d801..614a3a2 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_AD525X_DPOT_I2C) += ad525x_dpot-i2c.o obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o obj-$(CONFIG_INTEL_MID_PTI) += pti.o obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o +obj-$(CONFIG_MY) += my.o obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o obj-$(CONFIG_BMP085) += bmp085.o diff --git a/drivers/misc/my.c b/drivers/misc/my.c new file mode 100644 index 0000000..49759ad --- /dev/null +++ b/drivers/misc/my.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include + +#define DEVICE_NAME "mydev" +static struct class *dummy; + +static ssize_t my_show_ro(struct device *my_dev, + struct device_attribute *my_attr, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%s\n", "show some cool value"); +} + +static ssize_t my_show_rw(struct device *my_dev, + struct device_attribute *my_attr, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%s\n", "write value and look at dmesg"); +} + +static ssize_t my_store_rw(struct device *my_dev, + struct device_attribute *my_attr, const char *buf, size_t count) +{ + printk(KERN_ERR "my_store_rw: %s", buf); + return count; +} + +static DEVICE_ATTR(ro, S_IRUGO, my_show_ro, NULL); +static DEVICE_ATTR(rw, S_IWUSR | S_IRUGO, my_show_rw, my_store_rw); + +static struct attribute *my_dev_attrs[] = { + &dev_attr_ro.attr, + &dev_attr_rw.attr, + NULL, +}; + +static struct attribute_group my_dev_attr_group = { + .attrs = my_dev_attrs, +}; + +static const struct attribute_group *my_dev_attr_groups[] = { + &my_dev_attr_group, + NULL, +}; + +static struct device my_dev = { + .init_name = "mydevice", +}; + +static int __init my_init(void) +{ + int ret = 0; + + dummy = class_create(THIS_MODULE, "dummy"); + device_initialize(&my_dev); + my_dev.groups = my_dev_attr_groups; + my_dev.parent = NULL; + my_dev.bus = NULL; + my_dev.class = dummy; + ret = device_add(&my_dev); + if (ret) { + printk(KERN_ERR "my: device register failed\n"); + goto failed_dev; + } + return 0; + +failed_dev: + device_del(&my_dev); + class_destroy(dummy); + + return ret; +} + +static void __exit my_exit(void) +{ + device_del(&my_dev); + class_destroy(dummy); +} + +MODULE_AUTHOR("Manuel Traut"); +MODULE_DESCRIPTION("just my example"); +MODULE_VERSION("20120412"); +MODULE_LICENSE("GPL"); + +module_init(my_init); +module_exit(my_exit);