首先来看s3c_gpio_cfgpin();

int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
{
struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);//得到对应GPIO结构体首指针,里面包含了该GPIO的各种参数
    unsigned long flags;
int offset;
int ret; if (!chip)
return -EINVAL; offset = pin - chip->chip.base; s3c_gpio_lock(chip, flags);
ret = s3c_gpio_do_setcfg(chip, offset, config);//设置该GPIO状态寄存器的数值为config
    s3c_gpio_unlock(chip, flags);

    return ret;
}
static inline struct s3c_gpio_chip *s3c_gpiolib_getchip(unsigned int chip)
{
return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
}
static inline int s3c_gpio_do_setcfg(struct s3c_gpio_chip *chip,
unsigned int off, unsigned int config)
{
return (chip->config->set_config)(chip, off, config);
}
static struct s3c_gpio_cfg gpio_cfg = {
.set_config = s3c_gpio_setcfg_s3c64xx_4bit,
.set_pull = s3c_gpio_setpull_updown,
.get_pull = s3c_gpio_getpull_updown,
};
int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
unsigned int off, unsigned int cfg)
{
void __iomem *reg = chip->base;
unsigned int shift = (off & ) * ;
u32 con; if (off < && chip->chip.ngpio > )
reg -= ; if (s3c_gpio_is_cfg_special(cfg)) {
cfg &= 0xf;
cfg <<= shift;
} con = __raw_readl(reg);//读GPXCON的值
con &= ~(0xf << shift);//清零
con |= cfg;//设置config
__raw_writel(con, reg);//写值 return ;
}

其中结构体s3c_gpio_chip如下:

/**
* struct s3c_gpio_chip - wrapper for specific implementation of gpio
* @chip: The chip structure to be exported via gpiolib.
* @base: The base pointer to the gpio configuration registers.
* @config: special function and pull-resistor control information.
* @lock: Lock for exclusive access to this gpio bank.
* @pm_save: Save information for suspend/resume support.
*
* This wrapper provides the necessary information for the Samsung
* specific gpios being registered with gpiolib.
*
* The lock protects each gpio bank from multiple access of the shared
* configuration registers, or from reading of data whilst another thread
* is writing to the register set.
*
* Each chip has its own lock to avoid any contention between different
* CPU cores trying to get one lock for different GPIO banks, where each
* bank of GPIO has its own register space and configuration registers.
*/
struct s3c_gpio_chip {
struct gpio_chip chip;
struct s3c_gpio_cfg *config;
struct s3c_gpio_pm *pm;
void __iomem *base;
int eint_offset;
spinlock_t lock;
#ifdef CONFIG_PM
u32 pm_save[];
#endif
};
static struct s3c_gpio_chip s5pv210_gpio_4bit[] = {//描述了芯片中所有的GPIO端口
{
.chip = {
.base = S5PV210_GPA0(),
.ngpio = S5PV210_GPIO_A0_NR,
.label = "GPA0",
.to_irq = s5p_gpiolib_gpioint_to_irq,
},
},{
。。。。
}
。。。。
};

接下来看gpio_set_value();

void __gpio_set_value(unsigned gpio, int value)
{
struct gpio_chip *chip; chip = gpio_to_chip(gpio);//返回对应于pin的gpio_desc[pin].chip指针
WARN_ON(extra_checks && chip->can_sleep);
chip->set(chip, gpio - chip->base, value);//调用chip->set
}

那么chip的成员函数set是怎么实现的呢?请看下篇

Linux下GPIO驱动(二) ----s3c_gpio_cfgpin();gpio_set_value();的更多相关文章

  1. 很好的linux下GPIO驱动详解文章

    原文地址  http://blog.csdn.net/llxmedici/article/details/6282372 打算跟着友善之臂的<mini2440 linux移植开发指南>来做 ...

  2. Linux下GPIO驱动(一) ----一个简单的LED驱动

    /******************************* * *杂项设备驱动:miscdevice *majior=10; * * *****************************/ ...

  3. Linux下GPIO驱动

    编写驱动程序,首先要了解是什么类型的设备.linux下的设备分为三类,分别为:字符设备,块设备和网络设备.字符设备类型是根据是否以字符流为数据的交换方式,大部分设备都是字符设备,如键盘,串口等,块设备 ...

  4. Linux下GPIO驱动(三) ----gpio_desc()的分析

    上篇最后提出的疑问是结构体gpio_chip中的成员函数set等是怎么实现的,在回答之前先介绍下gpio_desc这个结构体. 如上图所示,右上方部分为GPIO驱动对其它驱动提供的GPIO操作接口,其 ...

  5. Linux下GPIO驱动(五) ----misc_register();

    // struct miscdevice { int minor; const char *name; const struct file_operations *fops; struct list_ ...

  6. Linux下GPIO驱动(四) ----gpio_request();gpio_free();

    //gpio_request申请gpio口 int gpio_request(unsigned gpio, const char *label) { struct gpio_desc *desc; s ...

  7. 飞思卡尔imx6开发板Linux下GPIO驱动

    控制GPIO_1_28的输出: #define MY_BOMB_GPIO       IMX_GPIO_NR(1, 28) 配置为输出方式: gpio_direction_output (MY_BOM ...

  8. 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之二

    /** ****************************************************************************** * @author    暴走的小 ...

  9. 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之一

    /** ****************************************************************************** * @author    暴走的小 ...

随机推荐

  1. 解决MVC Jquery"此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站"的问题

    在ASP.NET MVC项目中,使用AJAX向控制器发送GET请求获取JSON数据时,出现这个错误:"此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站.若要允许 G ...

  2. js代码 设为首页 加入收藏

    // JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...

  3. 西门子PLC两线制,四线制

    1 一.对于控制系统模块:两线制,四线制信号都只有两根线接入模件,区别在于: 两线制信号的这两根线一正一负,不带提供信号电流,而且提供供电电压:一般流量,压力,液位等等的信号常用两线制信号,但也要根据 ...

  4. cgi表单的处理

    在HTML中,当客户填写了表单,并按下了发送(submit)按钮后,表单的内容被发送 到了服务器端,一般的,这时就需要有一个服务器端脚本来对表单的内容进行一些处理, 或者是把它们保存起来,或者是按内容 ...

  5. 最小生成树------Prim算法

    定义:设G=(V,E)是一个无向连通图.如果G的生成子图T=(V,E’)是一棵树,则称T是G的一棵生成树(Spanning Tree). 应用生成树可以得到关于一个电网的一组独立的回路方程.第一步是要 ...

  6. Linux服务器命令行模式安装Matlab2014a

    Linux服务器命令行模式安装Matlab2014a,有需要的朋友可以参考下. 0.下载安装包 下载Matlab2014a for Linux安装包的ISO镜像文件(感谢万能的度娘)以及破解包(下载地 ...

  7. 浅谈用java解析xml文档(二)

    上一文中总结了dom解析xml文档的方式,本文开始总结使用SAX解析xml 的方式及它的优缺点! SAX(Simple API for XML),是指一种接口,或者一个软件包. 首先我们应该知道SAX ...

  8. JDK Tools - xjc: 将 XML Schema 编译成 Java 类

    xjc 是 JAXB 将 xsd 生成 Java 类的工具. 命令格式 xjc [ options ] schema file/URL/dir/jar ... [-b bindinfo ] ... 命 ...

  9. js 获取url中的查询字符串

    function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)( ...

  10. QL Server 中四种匹配符的含义

    SQL中我们会见到很多的匹配符,下面解释一下 % 代表零个或者多个任意字符 _ 代表一个任意字符 [] 指定范围内的任意单个字符 [^] 不在指定范围内的任意单个字符 带有匹配符的字符串必须使用引号引 ...