?????????Sinlinx A64 linux ??????????????????LED???????????????????????????????????????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了?????????Sinlinx A64 linux ??????????????????LED???????????????????????????????????????相关的知识,希望对你有一定的参考价值。

?????????flags   fine   opera   logs   ??????   lag   def   ??????   gis   

???????????? ?????????Sinlinx A64

????????? 1GB ????????? 4GB
???????????? https://m.tb.cn/h.3wMaSKm
?????????????????? 641395230

??????A64??????????????????

#include <linux/of.h> //???????????????????????????????????????????????????????????????????????????

struct device_node
{
    const char *name;
    const char *type;
    phandle phandle;
    const char *full_name;
    struct property *properties; //??????
    struct property *deadprops; /* removed properties */
    struct device_node *parent; //??????????????????????????????????????????????????????
    struct device_node *child; //?????????????????????????????????
    struct device_node *sibling; //??????????????????????????????.
    struct device_node *next; /* next device of same type */ //????????????device_type??????????????????
    struct device_node *allnext; /* next in list of all nodes */ ...
};

//?????????????????????????????????????????????????????????????????????
extern struct device_node *of_find_node_by_name(struct device_node *from, const char *name);
//???????????????????????????????????????
static inline int of_get_child_count(const struct device_node *np);
//????????????????????????????????????
extern struct device_node *of_find_node_by_path(const char *path);
//??????????????????????????????????????????????????????????????????
extern struct device_node *of_find_node_by_type(struct device_node *from, const char *type); //???????????????device_type?????????????????????

//???????????????????????????????????????????????????????????????

static inline int of_property_read_u32(const struct device_node *np, const char *propname, u32 *out_value)
extern int of_property_read_u32_index(const struct device_node *np, const char *propname, u32 index, u32 *out_value);
extern int of_property_read_u8_array(const struct device_node *np, const char *propname, u8 *out_values, size_t sz);
extern int of_property_read_u16_array(const struct device_node *np, const char *propname, u16 *out_values, size_t sz);
extern int of_property_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz);
extern int of_property_read_u64(const struct device_node *np, const char *propname, u64 *out_value);
extern int of_property_read_string(struct device_node *np, const char *propname, const char **out_string)

???????????????????????????dtsi?????????
vim /lichee/linux-3.10/arch/arm64/boot/dts/sun50iw1p1-pinctrl.dtsi
????????????

????????????

???????????????

    #include <linux/module.h>   
    #include <linux/init.h>  
    #include <linux/fs.h>   
    #include <linux/device.h>   
    #include <linux/slab.h>  
    #include <linux/cdev.h>  
    #include <asm/uaccess.h>  
    #include <linux/io.h>  
    #include <linux/of.h>  
    #include <linux/of_gpio.h>  
    #include <linux/gpio.h>  
    #include <linux/sys_config.h>  

    #define MY_DEVICE_NAME "my_led_device"  
    // ??????????????????????????????  
    static int gpio = -1;   
    int get_irqno_from_node(void)  
    {  

        struct gpio_config config;   
        struct device_node *np = of_find_node_by_path("/leds");  
        if(np){  
            printk("find node ok
");  
        }  
        else{  
            printk("find node failed
");  
        }  

        gpio = of_get_named_gpio_flags(nd, "gpios", i, (enum of_gpio_flags *)&config);// ?????????????????????gpios???GPIO?????????????????????  
        if(!gpio_is_valid(gpio)){  
            //????????? GPIO ???????????????????????????gpio_request ?????????????????? GPIO????????????????????????????????????????????? gpio_free ???????????????????????????????????? GPIO   
            printk("gpio isn???t valid
");  
            return -1;  
        }  
        if(gpio_request(gpio, "leds") < 0)   
            printk("gpio request failed %d
", gpio);   
        gpio_direction_output(gpio, 1); //??????  

        return 0;   

    }  

    static int my_open (struct inode *node, struct file *filp)  
    {  
        if(gpio)   
        {  
            printk("open ok
");   
        }  
        else   
        {  
            return -EINVAL;  
        }  
        return 0;  
    }  

    static ssize_t my_write (struct file *filp, const char __user *buf, size_t size, loff_t *off)  
    {  
        unsigned char val;          
        copy_from_user(&val, buf, 1);  
        printk(" gpl_dat address   0x%x
",gpl_dat);  
        if (val)  
        {      
            gpio_direction_output(gpio, 0); //??????  
            printk("led on
");  
        }  
        else  
        {  
           gpio_direction_output(gpio, 1); //??????  
            printk("led off
");  
        }  

        return 1;   
    }  

    static const struct file_operations my_led_fops = {  
        //step 1 ?????????file_operations?????????  
        .open = my_open,  
        .write = my_write,      
    };  

    //step 1 ???  
    static struct class *led_class;  
    static struct cdev *pcdev;      //????????????cdev??????  
    static dev_t n_dev;            //??????????????????(??????????????????)  
    static int __init led_device_init(void)  
    {//step 2 :??????   
        int ret = -1;  
        pcdev = cdev_alloc();//??????cdev????????????  
        if(pcdev == NULL) {  
            printk(KERN_EMERG" cdev_alloc  error
");  
            ret = -ENOMEM;   /* ???????????? */  
            return ret;  
        }  
        //2. ?????????????????????  
        ret = alloc_chrdev_region(&n_dev, 0 , 2, MY_DEVICE_NAME);  
        if(ret < 0 ) {  
            //???????????????????????????  
            kfree(pcdev);                              /*??????cdev???????????? */  
            printk(KERN_EMERG"alloc_chrdev_region  error
");  
            return ret;  
        }      
        cdev_init(pcdev, &my_led_fops);     //?????????cdev??????           /* ??????cdev???file_operations??????????????? */   
        /* 
            ??????????????????cdev?????? 
            pcdev->owner = THIS_MODULE; 
            pcdev->ops = &my_led_fops; 
        */  
        ret = cdev_add(pcdev, n_dev, 2) ;// ????????????????????????????????????????????????  
        if(ret < 0 ) {  
            //???????????????????????????  
            unregister_chrdev_region(n_dev,  2);       /*  ??????????????????????????????*/  
            kfree(pcdev);                               /* ??????cdev???????????? */  
            printk(KERN_EMERG"alloc_chrdev_region  error
");  
            return ret;  
        }  

        /*????????????????????????/dev/SinlinxA64_LED*/  
        led_class = class_create(THIS_MODULE, "myled");      
        device_create(led_class, NULL, n_dev, NULL, "SinlinxA64_LED");   

        get_irqno_from_node();  
        printk(KERN_EMERG"cdev ok
");      
        return 0;  
    }  

    static void __exit led_device_exit(void)  
    {    //step 2 :??????  

        //??????cdev??????  
        cdev_del(pcdev);  
        //???????????????  
        unregister_chrdev_region(n_dev, 2); /*???????????????(?????????) ???????????????????????????*/  
        //??????cdev????????????  
        kfree(pcdev);  

        device_destroy(led_class, n_dev);  
        class_destroy(led_class);  
        gpio_free(gpio);   
        printk(KERN_EMERG"cdev_del ok
");  
    }  

    module_init(led_device_init);  
    module_exit(led_device_exit);  
    MODULE_LICENSE("GPL");  

???????????????https://blog.csdn.net/jklinux/article/details/82382066

以上是关于?????????Sinlinx A64 linux ??????????????????LED???????????????????????????????????????的主要内容,如果未能解决你的问题,请参考以下文章

芯灵思Sinlinx A64 开发板移植SQLite3

芯灵思Sinlinx A64 Linux&qt编译安装

芯灵思Sinlinx A64开发板 Linux内核等待队列poll ---阻塞与非阻塞

A64 I2S调试

A64dbg详解

ARMv8 A64 程序集中的立即数范围