Raspberry Pi3でLEDドライバ その2

Raspberry piで学ぶARMデバイスドライバプログラミングの本の方法は、
最新のカーネルに対応していないとのこと。
以下のページのコードを試したら動いた。 
http://derekmolloy.ie/kernel-gpio-programming-buttons-and-leds/

insmodしたあと、/sys/class/gpio以下に/sys/class/gpio/gpio27ができるので、

$ echo 1 > /sys/class/gpio/27

で、LEDが点灯する。

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/gpio.h>                 // Required for the GPIO functions

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Shohei Aoki");
MODULE_DESCRIPTION("A LED test driver Raspberry Pi 3");
MODULE_VERSION("0.1");

static unsigned int gpioLED = 27;       ///< hard coding the LED gpio for this example to P9_23 (GPIO49)

static int __init ebbgpio_init(void){
	int result = 0;
	printk(KERN_INFO "GPIO_TEST: Initializing the GPIO_TEST LKM\n");
	// Is the GPIO a valid GPIO number (e.g., the BBB has 4x32 but not all available)
	if (!gpio_is_valid(gpioLED)){
		printk(KERN_INFO "GPIO_TEST: invalid LED GPIO\n");
		return -ENODEV;
	}
	// Going to set up the LED. It is a GPIO in output mode and will be on by default
	gpio_request(gpioLED, "sysfs");          // gpioLED is hardcoded to 49, request it
	gpio_direction_output(gpioLED, 1);   // Set the gpio to be in output mode and on
	gpio_set_value(gpioLED, 1);          // Not required as set by line above (here for reference)
	gpio_export(gpioLED, false);             // Causes gpio49 to appear in /sys/class/gpio

	printk(KERN_INFO "GPIO_TEST: The interrupt request result is: %d\n", result);
	return result;
}

static void __exit ebbgpio_exit(void){
	gpio_set_value(gpioLED, 0);              // Turn the LED off, makes it clear the device was unloaded
	gpio_unexport(gpioLED);                  // Unexport the LED GPIO
	gpio_free(gpioLED);                      // Free the LED GPIO
	printk(KERN_INFO "GPIO_TEST: Goodbye from the LKM!\n");
}

module_init(ebbgpio_init);
module_exit(ebbgpio_exit)