`

I2C bus glue for Cirrus EP93xx

 
阅读更多

转自 http://arm.cirrus.com/forum/viewtopic.php?t=51&highlight=i2c

 

The attached file should be placed in linux-2.4.21\drivers\i2c\ . 

In Config.in I have added: 

dep_tristate ' I2C bus glue for Cirrus EP93xx processors' CONFIG_I2C_EP93XX $CONFIG_I2C_ALGOBIT 

And in Makefile: 

obj-$(CONFIG_I2C_EP93XX) += i2c-ep93xx.o 

 

 

/* ------------------------------------------------------------------------ *
 * i2c-ep933xx.c I2C bus glue for Cirrus EP93xx                             *
 * ------------------------------------------------------------------------ *

   Copyright (C) 2004 Michael Burian
   
   Based on i2c-parport-light.c
   Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org>
  
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * ------------------------------------------------------------------------ */


#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>
#include <asm/io.h>

//1/(2*clockfrequency)
#define EE_DELAY_USEC       50
#define GPIOG_EECLK 1
#define GPIOG_EEDAT 2

/* ----- I2C algorithm call-back functions and structures ----------------- */

// TODO: optimize
static void ep93xx_setscl(void *data, int state)
{
	unsigned int val, dir;

	val = inl(GPIO_PGDR);
	dir = inl(GPIO_PGDDR);

	/* Configure the clock line as output. */
	dir |= GPIOG_EECLK;
	outl(dir, GPIO_PGDDR);

	/* Set clock line to state */
	if(state)
		val |= GPIOG_EECLK;
	else
		val &= ~GPIOG_EECLK;
	
	outl(val, GPIO_PGDR);
}

static void ep93xx_setsda(void *data, int state)
{
	unsigned int val, dir;
	val = inl(GPIO_PGDR);
	dir = inl(GPIO_PGDDR);

	/* Configure the data line as output. */
	dir |= GPIOG_EEDAT;
	outl(dir, GPIO_PGDDR);

	/* Set data line to state */
	if(state)
		val |= GPIOG_EEDAT;
	else
		val &= ~GPIOG_EEDAT;
	
	outl(val, GPIO_PGDR);
}

static int ep93xx_getscl(void *data)
{
	unsigned int val, dir;
	val = inl(GPIO_PGDR);
	dir = inl(GPIO_PGDDR);

	/* Configure the clock line as input */
	dir &= ~GPIOG_EECLK;
	outl(dir, GPIO_PGDDR);
	
	/* Return state of the clock line */
	return (inl(GPIO_PGDR) & GPIOG_EECLK) ? 1 : 0;
}

static int ep93xx_getsda(void *data)
{
	unsigned int val, dir;
	val = inl(GPIO_PGDR);
	dir = inl(GPIO_PGDDR);

	/* Configure the data line as input */
	dir &= ~GPIOG_EEDAT;
	outl(dir, GPIO_PGDDR);

	/* Return state of the data line */
	return (inl(GPIO_PGDR) & GPIOG_EEDAT) ? 1 : 0;
}

static int ep93xx_reg(struct i2c_client *client)
{
	return 0;
}

static int ep93xx_unreg(struct i2c_client *client)
{
	return 0;
}

static void ep93xx_inc_use(struct i2c_adapter *adap)
{
#ifdef MODULE
	MOD_INC_USE_COUNT;
#endif
}

static void ep93xx_dec_use(struct i2c_adapter *adap)
{
#ifdef MODULE
	MOD_DEC_USE_COUNT;
#endif
}
/* ------------------------------------------------------------------------
 * Encapsulate the above functions in the correct operations structure.
 * This is only done when more than one hardware adapter is supported.
 */

/* last line (us, ms, timout)
 * us dominates the bit rate: 10us  means: 100Kbit/sec(25 means 40kbps)
 *                            10ms  not known
 *                            100ms timeout
 */
static struct i2c_algo_bit_data ep93xx_data = {
	NULL,
	ep93xx_setsda,
	ep93xx_setscl,
	ep93xx_getsda,
	ep93xx_getscl,
//	EE_DELAY_USEC, EE_DELAY_USEC, 100,	/* orginal (non-guide) value 10, 10, 100  */
	10, 10, 100,	/* orginal (non-guide) value 10, 10, 100  */
};

/* ----- I2c structure ---------------------------------------------------- */
static struct i2c_adapter ep93xx_adapter = {
	"EP93XX I2C interface",
	I2C_HW_B_LP, //I2C_HW_B_GUIDE
	NULL,
	&ep93xx_data,
	ep93xx_inc_use,
	ep93xx_dec_use,
	ep93xx_reg,
	ep93xx_unreg,
};

/* ----- Module loading, unloading and information ------------------------ */

static int __init i2c_ep93xx_init(void)
{
	unsigned long uiVal, uiDDR;
	
	/* Read the current value of the GPIO data and data direction registers. */
	uiVal = inl(GPIO_PGDR);
	uiDDR = inl(GPIO_PGDDR);

	/* If the GPIO pins have not been configured since reset, the data 
	 * and clock lines will be set as inputs and with data value of 0.
	 * External pullup resisters are pulling them high.
	 * Set them both high before configuring them as outputs. */
	uiVal |= (GPIOG_EEDAT | GPIOG_EECLK);
	outl(uiVal, GPIO_PGDR);

	/* Delay to meet the EE Interface timing specification. */
	udelay(EE_DELAY_USEC);

	
	/* Configure the EE data and clock lines as outputs. */
	uiDDR |= (GPIOG_EEDAT | GPIOG_EECLK);
	outl(uiDDR, GPIO_PGDDR);

	/* Delay to meet the EE Interface timing specification. */
	udelay(EE_DELAY_USEC);

	/* Reset hardware to a sane state (SCL and SDA high) */
	ep93xx_setsda(NULL, 1);
	ep93xx_setscl(NULL, 1);

	if (i2c_bit_add_bus(&ep93xx_adapter) < 0) {
		printk(KERN_ERR "i2c-ep93xx: Unable to register with I2C\n");
		return -ENODEV;
	}
	
	return 0;
}

static void __exit i2c_ep93xx_exit(void)
{
	i2c_bit_del_bus(&ep93xx_adapter);
}

EXPORT_NO_SYMBOLS;

MODULE_AUTHOR("Michael Burian");
MODULE_DESCRIPTION("I2C bus glue for Cirrus EP93xx processors");
MODULE_LICENSE("GPL");

module_init(i2c_ep93xx_init);
module_exit(i2c_ep93xx_exit);
分享到:
评论

相关推荐

    ohci-omap.zip_OMAP bus glue_glue

    OMAP Bus Glue OHCI驱动程序是专门为Linux操作系统设计的,用于支持OMAP(Open Multimedia Applications Platform)平台上的USB主机控制器。这个驱动程序的核心在于它实现了OHCI(Open Host Controller Interface)...

    Glue

    Glue在IT行业中通常指的是Amazon Glue,这是一个完全托管的数据集成服务,由亚马逊AWS提供。Amazon Glue帮助企业轻松地发现、编目、清理和转换数据,以便进行分析和机器学习。它是一个全托管的服务,无需预置或管理...

    Glue26_2016_glue262016ver_max_

    《3ds Max脚本插件Glue26_2016:提升3D建模与拼接效率的利器》 在3D建模领域,3ds Max是一款广泛使用的专业软件,其强大的功能和丰富的扩展性深受用户喜爱。在这款软件中,各种脚本和插件的使用可以极大地提高工作...

    Glue27_2020_max_3dmaxversionn_glue272020version_

    《3D Max脚本Glue27在2020版本中的应用与解析》 3D Max是一款由Autodesk公司开发的三维建模、动画和渲染软件,广泛应用于游戏开发、影视特效、建筑设计等多个领域。在2020版本中,3D Max引入了众多新特性,其中之一...

    安装Cluster Glue所需包

    2. **Development Tools**:如gcc编译器、make构建工具、autoconf和automake自动化构建工具,它们用于编译源代码安装Cluster Glue及其依赖项。 3. **Network Utilities**:如nc(netcat)、ssh(Secure Shell)、...

    xhci-pci.rar_glue_xhci

    PCI(Peripheral Component Interconnect)总线是计算机内部连接外部设备的一种标准,而“PCI Bus Glue”在这里指的是连接xHCI主机控制器与PCI总线之间的桥梁软件,它在操作系统和硬件之间起着关键作用。 xHCI-pci....

    CSS 精灵生成工具 Glue.zip

    2. 下载并解压Glue的源码(如glue-master)。 3. 在命令行中进入Glue的源码目录,运行Python脚本,提供需要合并的图像文件夹路径和输出配置。 4. 检查生成的CSS文件和精灵图,将其引入到HTML页面中。 **优点与应用...

    GLUE数据集GLUE数据集

    GLUE(General Language Understanding Evaluation)数据集是自然语言处理领域的一个重要资源,旨在评估模型在理解和生成人类语言方面的性能。这个数据集包含了多种任务,涵盖了广泛的语言理解挑战,包括语义相似度...

    GLUE任务中MRPC任务数据集.zip

    里面是GLUE官网下载的MRPC任务数据集,官网上指定的方式是通过跑脚本download_glue_data.py来下载 GLUE data 。指定数据存放地址为:glue_data。执行后发现下载失败,究其原因是下面这两个链接访问不上,几天后试了...

    GLUE通用语言理解评估标准.rar

    GLUE(General Language Understanding Evaluation)是一项基准测试,旨在评估机器学习模型在自然语言处理任务中的性能,特别是理解和生成人类语言的能力。这个压缩包文件“GLUE通用语言理解评估标准.rar”包含了...

    Laravel开发-glue

    "Laravel开发-glue" 提到的"glue"很可能是某个特定的扩展包或者工具,它是为了方便Laravel开发者更好地整合和管理项目中的组件。在Laravel生态中,经常有开发者创建自定义的包来解决特定问题或提供额外的功能,"glue...

    camellia_aesni_avx2_glue.rar_glue

    "camellia_aesni_avx2_glue.c"这个文件很可能是C语言实现的源代码,包含了实现这一融合的关键逻辑。代码可能涉及了如何初始化和调用AES-NI指令,如何在Camellia算法的不同阶段插入AVX2优化的计算,以及如何确保整个...

    GLUE.rar_GLUE MATLAB_glue方法_不确定_不确定分析_水文模型参数

    参数不确定性分析方法GLUE 来自王书功水文模型参数估计及不确定性分析

    bert测试数据集GLUE("CoLA", "SST", "MRPC"等)

    标题中的“BERT测试数据集GLUE”涉及到两个关键概念:BERT和GLUE。BERT,全称为Bidirectional Encoder Representations from Transformers,是由Google在2018年推出的一种预训练语言模型。它通过在大规模无标注文本...

    Reusable-Cluster-Components-glue--0a7add1d9996 el7 亲测有效

    Reusable-Cluster-Components-glue--0a7add1d9996 Cluster Glue 1.0.12 for el7 官方连接已无法打开 http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2

    mmp2.rar_glue

    标题"MMP2.rar_glue"涉及的是一个与128位块加密算法相关的共享胶水代码,其中包含AVX2汇编宏。这个压缩包文件包含了一系列与优化加密操作相关的源代码文件,主要关注128位数据块的处理,并且利用了Intel AVX2指令集...

    Go-Glue-GoRPC客户端代码生成器

    Go-Glue-GoRPC客户端代码生成器是一个用于简化Go语言中gRPC客户端代码编写的工具,名为"Glue"。gRPC是一个高性能、开源、通用的RPC框架,基于HTTP/2协议,由Google推出,它支持多种语言,包括Go。在使用gRPC时,通常...

    cluster-glue-libs-1.0.5-6.el6.i686.rpm

    cluster-glue-libs-1.0.5-6.el6.i686.rpm是centos工具包。

    cluster-glue-1.0.5-6.el6.i686.rpm

    cluster-glue-1.0.5-6.el6.i686.rpm是centos工具包。

    sha1_glue.rar_glue

    压缩包内的文件“sha1_glue.c”很可能是实现这个胶水代码的源文件,它包含C语言编写的功能,这些功能会调用汇编实现的SHA1算法,并提供一个用户友好的API供其他C代码使用。在分析这个源码时,我们可能会看到一些关键...

Global site tag (gtag.js) - Google Analytics