加载中…
个人资料
microcreater
microcreater
  • 博客等级:
  • 博客积分:0
  • 博客访问:27,157
  • 关注人气:3
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

linux设备驱动 input设备驱动

(2012-02-23 15:55:28)
标签:

linux

驱动

input

it

分类: linux驱动开发

input设备!

 

#include <linux/types.h>

#include <linux/cdev.h>

#include <linux/fs.h>

#include <linux/device.h>

#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/init.h>

#include <linux/string.h>

#include <linux/platform_device.h>

#include <linux/errno.h>

#include <asm/uaccess.h>

#include <linux/delay.h>

#include <linux/miscdevice.h>

#include <asm/io.h>

#include <linux/poll.h>

#include <linux/wait.h>

#include <linux/interrupt.h>

#include <linux/sched.h>

#include <linux/ioctl.h>

#include <linux/spinlock.h>

#include <asm/system.h>

#include <linux/cdev.h>

#include <linux/mm.h>

#include <linux/irq.h>

#include <asm/irq.h>

#include <mach/hardware.h>

#include <linux/cdev.h>

#include <linux/clk.h>

#include <linux/io.h>

#include <asm/system.h>

#include <linux/slab.h>

 

#define GPIO_PORT_PHY_BASE      0x01c20800

#define GPIO_PORT_PHY_LEN       0x00000500

 

 

#define GPIO_PORT_BASE(n)        (n * 0x24)

#define GPIO_PORT_CFG0(n)        (GPIO_PORT_BASE(n) + 0x00)

#define GPIO_PORT_CFG1(n)        (GPIO_PORT_BASE(n) + 0x04)

#define GPIO_PORT_CFG2(n)        (GPIO_PORT_BASE(n) + 0x08)

#define GPIO_PORT_CFG3(n)        (GPIO_PORT_BASE(n) + 0x0C)

#define GPIO_PORT_DATA(n)        (GPIO_PORT_BASE(n) + 0x10)

#define GPIO_PORT_DRV0(n)        (GPIO_PORT_BASE(n) + 0x14)

#define GPIO_PORT_DRV1(n)        (GPIO_PORT_BASE(n) + 0x18)

#define GPIO_PORT_PUL0(n)        (GPIO_PORT_BASE(n) + 0x1C)

#define GPIO_PORT_PUL1(n)        (GPIO_PORT_BASE(n) + 0x20)

 

#define GPIO_INT_CFG0            0x200

#define GPIO_INT_CFG1            0x204

#define GPIO_INT_CFG2            0x208

#define GPIO_INT_CFG3            0x20C

#define GPIO_INT_CTL             0x210

#define GPIO_INT_STA             0x214

#define GPIO_INT_DEB             0x218

#define SDR_PAD_DRV              0x220

#define SDR_PAD_PUL              0x224

 

 

#define DEV_NAME                 "sun4i_mute_switch"

#define MISC_DEV_NAME            "mute_switch"

#define DRV_VERSION              "1.0.0"

 

enum mute_switch_port

{

 AW_GPIO_PORTA = 0,          

 AW_GPIO_PORTB = 1,          

 AW_GPIO_PORTC = 2,          

 AW_GPIO_PORTD = 3,          

 AW_GPIO_PORTE = 4,          

 AW_GPIO_PORTF = 5,          

 AW_GPIO_PORTG = 6,          

 AW_GPIO_PORTH = 7,          

 AW_GPIO_PORTI = 8,          

 AW_GPIO_PORTS = 9,

};

 

enum mute_switch_port_pull

{

    GPIO_PULL_DISABLE = 0x00,

 GPIO_PULL_UP      = 0x01,

 GPIO_PULL_DOWN    = 0x02,

};

 

enum mute_switch_port_inout

{

    INPUT  0x00,

 OUTPUT =  0x01,

};

 

enum mute_switch_pin_value

{

    LOW   = 0x00,

    HIGHT = 0x01,

};

 

struct mute_switch_device_info

{

 struct              resource       *men;

 void                __iomem        *base;

};

 

struct mute_switch_gpioinfo

{

    enum mute_switch_port port;

 unsigned char id;

 enum mute_switch_port_pull port_pull;

 enum mute_switch_port_inout port_inout;

 enum mute_switch_pin_value pin_value;

};

 

struct mute_switch_gpioinfo gpioinfo[] =

{

     {AW_GPIO_PORTA, 1, GPIO_PULL_UP, INPUT, 0},

     {AW_GPIO_PORTI, 2, GPIO_PULL_UP, OUTPUT, 1},

};

 

static void mute_switch_set_gpiocfg(struct platform_device *dev, unsigned char port_num, unsigned char port_id, unsigned char mode )

{

    struct mute_switch_device_info *gpiocfg_prv = platform_get_drvdata(dev);

 

 

 

 if((port_id >= 0) && (port_id <= 7))

  {

  iowrite32((ioread32(gpiocfg_prv->base + GPIO_PORT_CFG0(port_num)) & ~(0x0000 << (port_id * 4))) | mode << (port_id * 4), gpiocfg_prv->base + GPIO_PORT_CFG0(port_num));

  }

 else

  {

  if((port_id <= 15) && (port_id > 7))

   {

   iowrite32((ioread32(gpiocfg_prv->base + GPIO_PORT_CFG1(port_num)) & ~(0x0000 << ((port_id - 8) * 4))) | mode << ((port_id - 8)* 4), gpiocfg_prv->base + GPIO_PORT_CFG0(port_num));

   }

  else

   {

   iowrite32((ioread32(gpiocfg_prv->base + GPIO_PORT_CFG1(port_num)) & ~(0x0000 << ((port_id - 16) * 4))) | mode << ((port_id - 16)* 4), gpiocfg_prv->base + GPIO_PORT_CFG0(port_num));

   }

  }

}

 

 

static void mute_switch_set_gpiovalue(struct platform_device *dev, unsigned char port_num, unsigned char port_id, unsigned char value )

{

    struct mute_switch_device_info *gpiovalue = platform_get_drvdata(dev);

 unsigned char value_reg = 0;

 

   

 

 ioread32(gpiovalue->base + GPIO_PORT_DATA(port_num));

 value ? (value << port_id) : (value << port_id);

    value_reg =  (value << port_id);

   

 iowrite32( value, gpiovalue->base + GPIO_PORT_DATA(port_num));

}

 

static void mute_switch_get_gpiovalue(struct platform_device *dev, unsigned char port_num, unsigned char port_id, unsigned char mode )

{

}

 

static int __devinit mute_switch_probe(struct platform_device *dev)

{

    int ret = -ENODEV;

 struct mute_switch_device_info *priv_info = NULL;

 struct resource *res = NULL;

 int size = 0;

 

    printk(KERN_ALERT "%s:%s,%s\r\n", __FUNCTION__,__DATE__,__TIME__);

 

    priv_info = kzalloc(sizeof(struct mute_switch_device_info), GFP_KERNEL);

 if (!priv_info) {

  printk("kzalloc is fail!\n\n");

  ret = -ENOMEM;

  goto err_out;

 

 

 res = platform_get_resource( dev, IORESOURCE_MEM, 0 );

    if (NULL == res)

  {

     printk("no memory resource!\n");

     ret = -ENOENT;

  goto err_out_kfree;

     }

 

 size = (res->end-res->start)+1;

 priv_info->men = request_mem_region(res->start, size, dev->name);

    if (NULL == priv_info->men)

    

     printk("failed to get memory!\n");  

     ret = -ENOENT;  

     goto err_release; 

    }

 

 priv_info->base = ioremap(res->start, size);

    if (NULL == priv_info->base)

  

     printk("failed to ioremap!\n");  

     ret = -EINVAL;  

     goto err_iounmap; 

 }

 

 

 

 

 

    platform_set_drvdata(dev, priv_info);

   

 return ret;

 

err_iounmap:

 iounmap(priv_info->base);

err_release:

 release_resource(priv_info->men);

err_out_kfree:

 kfree(priv_info);

err_out:

 return ret;

}

 

static int __devexit mute_switch_remove(struct platform_device *dev)

{

    struct mute_switch_device_info *priv = platform_get_drvdata(dev);

 

 printk(KERN_ALERT "%s:%s,%s\r\n", __FUNCTION__,__DATE__,__TIME__);

 

 platform_set_drvdata(dev, NULL);

 

 

 

 iounmap(priv->base);

    release_resource(priv->men);

 

 kfree(priv);

 

 return 0;

}

 

static struct platform_driver mute_switch_driver = {

        .probe       mute_switch_probe,

  .remove      __devexit_p(mute_switch_remove),

  .driver      {

                        .owner      THIS_MODULE,

      .name       DEV_NAME,

  },

};

 

struct resource mute_switch_resource[] = {       

 [0]={                                                  

  .start =  GPIO_PORT_PHY_BASE,           

  .end   GPIO_PORT_PHY_BASE + GPIO_PORT_PHY_LEN,           

  .flags =  IORESOURCE_MEM,           

  

};

 

static void mute_switch_release(struct device * dev)

{

  printk(KERN_ALERT "%s:%s,%s\r\n", __FUNCTION__,__DATE__,__TIME__);

}

 

struct platform_device mute_switch_device= {       

     .name              DEV_NAME,       

  .id                -1,       

  .num_resources     ARRAY_SIZE(mute_switch_resource),       

  .resource          mute_switch_resource,       

  .dev              

            

  .release           mute_switch_release,

       

 };

 

static int __init mute_switch_init(void)

{

    int ret = -ENODEV;

 

    printk(KERN_INFO "%s FPGA Driver, V%s\n", DEV_NAME, DRV_VERSION);

 

 

 ret = platform_device_register(&mute_switch_device);

 if (ret)

  {

  platform_device_unregister(&mute_switch_device);

        printk("platform_device_register is fail!\n");

  return ret;

  }

 

 

 ret = platform_driver_register (&mute_switch_driver);

 if ( ret )

  {

  printk("platform_driver_register is fail!\n");

  platform_driver_unregister(&mute_switch_driver);

  return ret;

  }

 

 return ret;

}

 

static void __exit mute_switch_exit(void)

{

   

    platform_driver_unregister (&mute_switch_driver);

 

   

 platform_device_unregister (&mute_switch_device);

 

 printk(KERN_ALERT "%s:%s,%s\r\n", __FUNCTION__,__DATE__,__TIME__);

}

 

module_init(mute_switch_init);

module_exit(mute_switch_exit);

 

MODULE_AUTHOR("pangyong");

MODULE_DESCRIPTION("this is mute_switch driver modules");

MODULE_LICENSE("Dual BSD/GPL");

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有