必威体育Betway必威体育官网
当前位置:首页 > IT技术

msm8909 模块android 驱动编写

时间:2019-10-26 07:13:16来源:IT技术作者:seo实验室小编阅读:89次「手机版」
 

msm8909

sc20_gpio.c

```
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/types.h>
#include <asm/gpio.h>
#include <mach/gpio.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include<linux/delay.h>
#include <asm/errno.h>
#include <asm-generic/gpio.h>           /* cansleep wrAPPers */
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/sched.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/platform_device.h>
#include <linux/workqueue.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#include <linux/spinlock.h>
#include <linux/pinctrl/consumer.h>


#define DEVICE_NAME "sc20_gpio"
#define USE_MSG_LEV KERN_ERR
#define IOCTL_WR  _IO(10, 0)
#define IOCTL_RD  _IO(10, 1)


typedef struct 
{
    u32 pin;
    u32 val;

}USER_DATA;



int gpio_data=0;
static long sc20_gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{

    USER_DATA usr_data;
    if(copy_from_user(&usr_data,(void __user *)arg,sizeof(USER_DATA))==0)
    {
        if(cmd == IOCTL_WR) //write
        {   

        gpio_set_value(gpio_data, usr_data.val);
        printk(USE_MSG_LEV "gpio write:%d \n",usr_data.val);

        }
        else if(cmd == IOCTL_RD) //read
        {
            usr_data.val = gpio_get_value(gpio_data);
            if(copy_to_user(&arg,&usr_data,sizeof(USER_DATA))==0)
            {
              printk(USE_MSG_LEV "gpio read:%d \n",usr_data.val);
            }
            else
            {
                printk(USE_MSG_LEV "copy_to_user eror \n");
            }
        }
        else
        {
            printk(USE_MSG_LEV "in kgpio illegal cmd\n");
        }
    }
    else
    {
        printk(USE_MSG_LEV "copy_from_user eror \n");
    }
    return 0;
}

static ssize_t sc20_gpio_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
    return 0;
}

static ssize_t sc20_gpio_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
{
    return 0;
}

static int sc20_gpio_release(struct inode *inode, struct file *filp)
{
    return 0;
}

/*文件操作结构体*/
static struct file_operations sc20_gpio_fops = {
    .owner = THIS_MODULE,
    .unlocked_ioctl = sc20_gpio_ioctl,
    .write = sc20_gpio_write,
    .read =  sc20_gpio_read,
    .release = sc20_gpio_release,
    //.open = sc20_gpio_open,
};

/*misc设备结构体初始化*/
static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEVICE_NAME,
    .fops = &sc20_gpio_fops,
};







int gpio_intit(struct platform_device *pdev)
{
    struct device *dev = &pdev->dev;
    struct device_node *node=dev->of_node;
    int ERROR=0;
    enum of_gpio_flags flags;
    const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
    if (!pdata) 
    {
        gpio_data = of_get_gpio_flags(node, 0, &flags);
        if (gpio_is_valid(gpio_data)) 
        {
            error = gpio_request_one(gpio_data, GPIOF_OUT_INIT_HIGH, "net_led");
            if (error < 0)
            {
                dev_err(dev, "Failed to request GPIO %d, error %d\n",gpio_data, error);
                return error;
            }
        }
        gpio_set_value(gpio_data,1);
    }
    return error;
}



static int sc20_gpio_probe(struct platform_device *pdev)
{
    int ret;
    gpio_intit(pdev);
    ret = misc_register(&misc);
    if(ret)
    {
         printk(USE_MSG_LEV "%s register fail\n", DEVICE_NAME);
         //goto err_free_gpiOS;
    }   
    printk(USE_MSG_LEV "%s register success\n", DEVICE_NAME);
    return ret;
}

static int sc20_gpio_remove(struct platform_device *pdev)
{
    misc_deregister(&misc);
    return 0;

}


static struct of_device_id sc20_gpio_of_match[] = 
{
    { .compatible = "gpio-outs", },
    { },
};


module_device_table(of, sc20_gpio_of_match);


static struct platform_driver gpio_keys_device_driver = {
    .probe      = sc20_gpio_probe,
    .remove     = sc20_gpio_remove,
    .driver     = {
        .name   = "gpio-outs",
        .owner  = THIS_MODULE,
        //.pm   = &sc20_gpio_pm_ops,
        .of_match_table = of_match_ptr(sc20_gpio_of_match),
    }
};

#if 0
 void test_for_pin(void)
{
    struct device_node *node,*pp;
    int nbuttons;
    int code;
    const char *desc;
    int gpio;
    node=of_find_compatible_node(NULL,NULL, "gpio-keys");//找到dts中compatible为 "gpio-keys"的节点返回
    printk(KERN_INFO"%d",of_device_is_compatible(node,"gpio-keys"));
    nbuttons = of_get_child_count(node);//算出此节点下面共有多少节点
    printk(KERN_INFO"of_get_child_count: %d\n",nbuttons);

    for_each_child_of_node(node, pp) //遍历每个子节点
    {

        enum of_gpio_flags flags;

        if (!of_find_property(pp, "gpios", NULL)) //子节点里是否包含"gpios" 属性
        {
        printk(KERN_INFO"Found button without gpios\n");
        continue;
        }

        gpio = of_get_gpio_flags(pp, 0, &flags);
        printk(KERN_INFO"of_get_gpio_flags(pp, 0, &flags): %d\n",gpio);

        of_property_read_u32(pp, "linux,code", &code); //读取属性名为"linux,code"属性的节点整形值
        printk(KERN_INFO"of_property_read_u32(pp, \"linux,code\", &code);%d\n",code);

        desc = of_get_property(pp, "label", NULL);//读取属性名为"label"
        printk(KERN_INFO"of_get_property(pp, \"label\", NULL);%s\n",desc);


    }
}
 #endif
static int __init sc20_gpio_init(void)
{
     printk(USE_MSG_LEV "%s sc20_gpio_init\r\n", DEVICE_NAME);
     //test_for_pin();

     return platform_driver_register(&gpio_keys_device_driver);
}

static void __exit sc20_gpio_exit(void)
{
    platform_driver_unregister(&gpio_keys_device_driver);
}

module_init(sc20_gpio_init);
module_exit(sc20_gpio_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("xuliang");

makefile

project=test
curren_dir=$(shell pwd)
build_dir=/code/Android/out/target/product/msm8909/obj/KERNEL_OBJ

obj-m+=sc20_gpio.o
VERSION = 3
PATCHLEVEL = 10
SUBLEVEL = 49
EXTRAVERSION =""
CFLAGS_MODULE=-fno-pic


all:
    $(MAKE) -C $(build_dir) M=$(curren_dir) modules ARCH=arm CROSS_COMPILE=arm-linux-androidkernel-
    perl /code/android/kernel/scripts/sign-file sha512 $(build_dir)/signing_key.priv $(build_dir)/signing_key.x509 /code/driver_debug/sc20_gpio/sc20_gpio.ko 
    echo ok
clean:
    rm *.o *.ko 

设备树中添加

    gpio-outs {
        compatible = "gpio-outs";
        input-name = "gpio-outs";       
        gpios = <&msm_gpio 99 0x0>;
        debounce-Interval = <15>;
    };

说明:

CFLAGS_MODULE=-fno-pic 解决insmod 时 Exec format error,由于andriod引入了数字签名所似生成ko后要手动加入签名

perl /code/android/kernel/scripts/sign-file sha512 (builddir)/signingkey.priv" role="presentation" style="position: relative;">(builddir)/signingkey.priv(build_dir)/signing_key.x509 /code/driver_debug/sc20_gpio/sc20_gpio.ko ,执行hexdump -C hello.ko | tail查看签名

JNI调用源码

文章最后发布于: 2018-08-18 18:54:04

相关阅读

msm8909之LCD移植简述

高通平台LCD驱动移植简述 一:背光配置 二:LK部分配置 三:Kernel部分配置 一:背光配置 : 分为boot 和 kernel 两部分 高通LCD背光: 有

msm8953之串口dts配置

https://blog.csdn.net/xuecz1230/article/details/78672662 msm8953支持4路串口,编号uart2、uart4、uart5、uart6 基地址: 中断号

高通MSM8953处理器(CPU)/骁龙625资料介绍

高通MSM8953即骁龙625,是高通首款采用14nm制程打造的八核心处理器,在为高端智能手机带来优质用户体验的同时,避免了电量的大幅损耗。

高通625系列-MSM8953 (Cortex-A53架构)

核心板特性A53架构 8核(8*2.2GHz(A53)) 产品尺寸小,便于客户集成,减少产品体积;支持4G LTE超高速上网,单板兼容移动/联通/电信2G/3G/4G;

MSM8998(高通835处理器)外接指纹识别传感器linux驱动

/* * FPC1020 Fingerprint sensor device driver * * This driver will control the platform resources that the FPC finger

分享到:

栏目导航

推荐阅读

热门阅读