一、设备树和bit
在设备树中PL下添加一个GPIO,这里使用标号56。
ch_emio {
compatible = "ch,emio_led";
enable_pin {
label = "enable";
gpios = <&gpio0 56 0>;
};
};
vivado 工程打开GPIO,并约束好引脚到LED。编译生成新的.bit文件。
二、程序
/*
* LEDs driver for GPIOs
*
* Copyright (C) 2007 8D Technologies inc.
* Raphael Assenat <raph@8d.com>
* Copyright (C) 2008 Freescale Semiconductor, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <asm/atomic.h>
#include <asm/unaligned.h>
#include <linux/uaccess.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/string.h>
#include <linux/io.h>
#define DEVICE_NAME "emio_led"
struct gpio_emio{
char name[10];
struct gpio_desc *gpiod;
struct device *gpio_dev;
}gpio_emio_dev;
static int gpio_emio_major;
static struct class* gpio_emio_class = NULL;
static