亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? i2c-algo-s3c2410.c

?? linux和2410結(jié)合開發(fā) 用他可以生成2410所需的zImage文件
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
   -------------------------------------------------------------------------
   i2c-algo-s3c2410.c i2c driver algorithms for the Samsung S3C2410X
   processor and SMDK2410 reference board.

   Steve Hein <ssh@sgi.com>
   Copyright 2002 SGI, Inc.

   -------------------------------------------------------------------------
   This file was highly leveraged from i2c-algo-ppc405.c:
   
   Ian DaSilva, MontaVista Software, Inc.
   idasilva@mvista.com or source@mvista.com

   Copyright 2000 MontaVista Software Inc.

   Changes made to support the IIC peripheral on the IBM PPC 405

   ---------------------------------------------------------------------------
   This file was highly leveraged from i2c-algo-pcf.c, which was created
   by Simon G. Vogl and Hans Berglund:


     Copyright (C) 1995-1997 Simon G. Vogl
                   1998-2000 Hans Berglund

   With some changes from Ky鰏ti M鋖kki <kmalkki@cc.hut.fi> and 
   Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
   <mbailey@littlefeet-inc.com>


    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/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/version.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/i2c.h>
#include <linux/i2c-algo-s3c2410.h>
#include <linux/i2c-s3c2410.h>

//laputa for to get the PCLK freq.  from s3c2410_get_clk(GET_PCLK)
#include <asm/arch/cpu_s3c2410.h>
//laputa debug msg 030901
#define LAPUTA_DEBUG_MSG	1
#include  "dbg_msg.h"

#undef KERN_DEBUG
#define KERN_DEBUG

#ifdef MODULE_LICENSE
MODULE_LICENSE("GPL");
#endif

/* ----- global defines ----------------------------------------------- */
#define DEB(x) if (s3c2410_i2c_debug>=1) x
#define DEB2(x) if (s3c2410_i2c_debug>=2) x
#define DEB3(x) if (s3c2410_i2c_debug>=3) x /* print several statistical values*/
#define DEBPROTO(x) if (s3c2410_i2c_debug>=9) x;
 	/* debug the protocol by showing transferred bits */
#define DEF_TIMEOUT 2

/* debugging - slow down transfer to have a look at the data .. 	*/
/* I use this with two leds&resistors, each one connected to sda,scl 	*/
/* respectively. This makes sure that the algorithm works. Some chips   */
/* might not like this, as they have an internal timeout of some mils	*/
/*
#define SLO_IO      jif=jiffies;while(jiffies<=jif+i2c_table[minor].veryslow)\
                        if (need_resched) schedule();
*/


/* ----- global variables ---------------------------------------------	*/

#ifdef SLO_IO
	int jif;
#endif

/* module parameters:
 */
int s3c2410_i2c_debug=0;
//laputa for iic clk freq prescale = 1x
//static int i2c_clkdiv=1;  // -- remove
static int i2c_clkdiv=0;	// += modify 030902

/* --- setting states on the bus with the right timing: ---------------	*/

#define s3c2410_outb(adap, reg, val) adap->setiic(adap->data, reg, val)
#define s3c2410_inb(adap, reg) adap->getiic(adap->data, reg)

#define IIC_SINGLE_XFER		0
#define IIC_COMBINED_XFER	1

/* --- other auxiliary functions --------------------------------------	*/

//
// Description: returns the current speed of the I2C clock in kHz
//
static int s3c2410_clkspeed(void)
{
	unsigned long pdiv = ((i2c_clkdiv / 100) != 0) ? 16 : 512;
	unsigned long div = i2c_clkdiv % 100;

//laputa - what (where) is PCLK ?  
#if 0
	return (PCLK/pdiv)/(div+1)/1024;
#else
//laputa for to get Peripheral clock frequency  030830
	unsigned long PCLK = s3c2410_get_bus_clk(GET_PCLK);  //++ append
	return (PCLK/pdiv)/(div+1)/1024;
#endif
//laputa end 030830
}

//
// Description: Puts this process to sleep for a period equal to timeout 
//
static inline void s3c2410_sleep(unsigned long timeout)
{
	schedule_timeout( timeout * HZ);
}


//
// Description: This performs the Samsung S3C2410X IIC initialization sequence
// as described in the S3C2410X data book.
//
static int s3c2410_init(struct i2c_algo_s3c2410_data *adap)
{
	u8 conval = 0;

	// initialize control/status regs to 0
	s3c2410_outb(adap, S3C2410_IICCON, 0);
	s3c2410_outb(adap, S3C2410_IICSTAT, 0);

	// set up a dummy IIC slave addr (even though we never use it!)
	s3c2410_outb(adap, S3C2410_IICADD, 0x10);
	//s3c2410_outb(adap, S3C2410_IICADD, 0xa0);
	

	// set up clock frequency for IIC-bus
	if (i2c_clkdiv/100) {
	   /* IICCLK=PCLK/16 */
	   conval |= (i2c_clkdiv%100);            /* Tx clk = IICCLK/(n+1) */
	} else {
	   conval |= S3C2410_IICCON_TCLK_PCLK512;  /* IICCLK=PCLK/512 */
	   conval |= i2c_clkdiv;                   /* Tx clk = IICCLK/(n+1) */
	}

	// enable interrupts
	conval |= S3C2410_IICCON_INT_EN;

	// enable ACK generation
	conval |= S3C2410_IICCON_ACK_EN;

	// write out the control reg. value
	s3c2410_outb(adap, S3C2410_IICCON, conval);

	// enable I2C bus data output and set master transmit mode
	// to get to a sane state (also generates a STOP condition)
	s3c2410_outb(adap, S3C2410_IICSTAT, S3C2410_IICSTAT_MTX_MODE | S3C2410_IICSTAT_OUT_EN);
	
        DEB2(printk(KERN_DEBUG "s3c2410_init: Initialized IIC on S3C2410X, %dkHz clock\n", s3c2410_clkspeed()));

	mdelay(20);

        return 0;
}


//
// Description: Attempts to reset the I2C controller/bus back to a sane state.
//
static int s3c2410_reset (struct i2c_algo_s3c2410_data *adap)
{
	int ret;
	int count = 0;

	//
	// re-initialize
	//
	s3c2410_init(adap);

	//
	// Assume all is OK if the bus is not busy....
	//
	while((ret = s3c2410_inb(adap, S3C2410_IICSTAT)) & S3C2410_IICSTAT_BUSY) {

	  //
	  // Generate stop condition
	  //
	  DEB2(printk(KERN_DEBUG "s3c2410_reset: Generating STOP condition\n"));
	  s3c2410_outb(adap, S3C2410_IICSTAT, (S3C2410_IICSTAT_MTX_ENABLE & ~S3C2410_IICSTAT_BUSY));

	  //
	  // Clear status register and enable ACK generation
	  //
	  DEB2(printk(KERN_DEBUG "s3c2410_reset: Clearing status register\n"));
	  ret = s3c2410_inb(adap, S3C2410_IICCON);
          ret = (ret & ~S3C2410_IICCON_INT_PEND) | S3C2410_IICCON_ACK_EN;
	  s3c2410_outb(adap, S3C2410_IICCON, ret);

          //
	  // reset I2C again
          //
          s3c2410_init(adap);

#if 0
	  //
	  // If still busy do a dummy read to reset the active slave device
	  //
	  ret = s3c2410_inb(adap, S3C2410_IICSTAT);
	  if (ret & S3C2410_IICSTAT_BUSY) {

	    DEB2(printk(KERN_DEBUG "s3c2410_reset: Clearing status register before dummy read\n"));
	    ret = s3c2410_inb(adap, S3C2410_IICCON);
            ret = ret & ~(S3C2410_IICCON_INT_PEND | S3C2410_IICCON_ACK_EN);
	    s3c2410_outb(adap, S3C2410_IICCON, ret);

	    DEB2(printk(KERN_DEBUG "s3c2410_reset: Dummy read\n"));
	    s3c2410_outb(adap, S3C2410_IICSTAT, S3C2410_IICSTAT_MRX_ENABLE);
	    s3c2410_inb(adap, S3C2410_IICDS);   // dummy read

	    DEB2(printk(KERN_DEBUG "s3c2410_reset: Clearing status register after dummy read\n"));
	    ret = s3c2410_inb(adap, S3C2410_IICCON);
            ret = (ret & ~(S3C2410_IICCON_INT_PEND)) | S3C2410_IICCON_ACK_EN;
	    s3c2410_outb(adap, S3C2410_IICCON, ret);
	  }
#endif

	  //
	  // Bail out after a more than reasonable number of attempts
	  //
	  if (count++ > 50) {
	    printk(KERN_DEBUG "s3c2410_reset: I2C bus stuck BUSY!\n");
	    return -EIO;
	  }
	}

	return 0;
}

//
// Description: After we issue a transaction on the IIC bus, this function
// is called.  It puts this process to sleep until we get an interrupt from
// from the controller telling us that the transaction we requested in complete.
//
static int wait_for_pin(struct i2c_algo_s3c2410_data *adap, int *status) {

	int timeout = DEF_TIMEOUT+2;
	//int retval;
	
	*status = s3c2410_inb(adap, S3C2410_IICCON);
	//printk("wait_for_pin: status = %x\n", *status);

	while (timeout-- && !(*status & S3C2410_IICCON_INT_PEND)) {
	   //printk("wait_for_pin: timeout=%d, status=%x\n", timeout, *status);
	   //printk("wait_for_pin: calling waitforpin\n");
	   adap->waitforpin();
           //printk("wait_for_pin: returning from waitforpin\n");
	   *status = s3c2410_inb(adap, S3C2410_IICCON);
	   s3c2410_inb(adap, S3C2410_IICSTAT);
	}

	//printk("wait_for_pin: returning from wait_for_pin\n");
	if (timeout <= 0) {
	   // reset I2C
	   s3c2410_reset(adap);
#if 0
	   /* Issue stop signal on the bus */
           retval = s3c2410_inb(adap, S3C2410_IICSTAT);
           s3c2410_outb(adap, S3C2410_IICSTAT, retval & ~S3C2410_IICSTAT_BUSY);
	   /* Clear pending interrupt bit */
           retval = s3c2410_inb(adap, S3C2410_IICCON);
           s3c2410_outb(adap, S3C2410_IICCON, retval & ~S3C2410_IICCON_INT_PEND);

	   // wait for the busy condition to clear
	   udelay(adap->udelay);

	   // Check the status of the controller.  Does it still see a
	   // pending transfer, even though we've tried to stop any
	   // ongoing transaction?
           retval = s3c2410_inb(adap, S3C2410_IICSTAT);
           if(retval & S3C2410_IICSTAT_BUSY) {
	      // The iic controller didn't stop when we told it to....
	      // The iic controller is hosed.
              s3c2410_init(adap);
	      /* Is the pending transfer bit in the sts reg finally cleared? */
              retval = s3c2410_inb(adap, S3C2410_IICSTAT);
              if(retval  & S3C2410_IICSTAT_BUSY) {
                 printk("The IIC Controller is hosed.  A processor reset is required\n");
              }
           }
#endif
	   return(-ETIMEDOUT);
	}

	return(0);
}


//------------------------------------
// Utility functions
//

//
// Description: This function tries to verify that the device we want to
// talk to on the IIC bus really exists. 
//
#if 0
static inline int try_address(struct i2c_algo_s3c2410_data *adap,
		       unsigned char addr, int retries)
{
	int i, status, ret = -1;
	for (i=0;i<retries;i++) {
		i2c_outb(adap, addr);
		i2c_start(adap);
		status = s3c2410_inb(adap, 1);
		if (wait_for_pin(adap, &status) >= 0) {
			if ((status & I2C_PCF_LRB) == 0) { 
				i2c_stop(adap);
				break;	/* success! */
			}
		}
		i2c_stop(adap);
		udelay(adap->udelay);
	}
	DEB2(if (i) printk("i2c-algo-s3c2410.o: needed %d retries for %d\n",i,
	                   addr));
	return ret;
}
#endif


//
// Description: Whenever we initiate a transaction, the first byte clocked
// onto the bus after the start condition is the address of the
// device we want to talk to.  This function manipulates the address specified
// so that it makes sense to the hardware when written to the IIC peripheral.
//
static inline unsigned char iic_addr(struct i2c_algo_s3c2410_data *adap,
                                        struct i2c_msg *msg) 
{
	unsigned short flags = msg->flags;
	unsigned char addr;

	addr = ( msg->addr << 1 );  
	
	if (flags & I2C_M_RD )
		addr |= 1;
	if (flags & I2C_M_REV_DIR_ADDR )
		addr ^= 1;

	return addr;
}


//
// Description: This function is waits for an interrupt and checks for
// timeouts and transmit/receive errors.
//
static int s3c2410_wait(struct i2c_adapter *i2c_adap, int check_ack)
{
	struct i2c_algo_s3c2410_data *adap = i2c_adap->algo_data;
	int ret, timeout, status;
	u32 errbits = S3C2410_IICSTAT_ARB_FAILED | ((check_ack) ? S3C2410_IICSTAT_NACK : 0);

	// Wait for transmission to complete.
	DEB2(printk(KERN_DEBUG "s3c2410_wait: Waiting for interrupt\n"));
	timeout = wait_for_pin(adap, &status);
	if(timeout < 0) {
	   // Error handling
           //printk(KERN_ERR "Error: timeout\n");
           return -ETIMEDOUT;
	}
	DEB2(printk(KERN_DEBUG "s3c2410_wait: Got interrupt\n"));

	// Check transfer status
	ret = s3c2410_inb(adap, S3C2410_IICSTAT);
	if (ret & errbits) {
	   if (ret & S3C2410_IICSTAT_ARB_FAILED) {
	      //printk(KERN_ERR "Lost arbitration\n");
	      ret = -EPROTO;
	   }
	   else if (ret & S3C2410_IICSTAT_NACK) {
	      //printk(KERN_ERR "Master transfer aborted by a NACK during the transfer of the address byte\n");
	      ret = -ENODEV;
	   }
	   s3c2410_reset(adap);
	   return ret;
	}
	return 0;
}

//
// Description: This function is called by the upper layers to do the
// grunt work for a master send transaction
//
static int s3c2410_sendbytes(struct i2c_adapter *i2c_adap,
                             struct i2c_msg *pmsg, int xfer_flag)
{
	struct i2c_algo_s3c2410_data *adap = i2c_adap->algo_data;
	int i = 0, count, ret;
	
	// laputa IIC interface is only unsigned char receive & transfer
	//	char *buf;			// -- remove 
	unsigned char *buf;  	// +- modify 030903
    
	u8 addr;
	int rval;
   

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线观看日韩国产| 综合婷婷亚洲小说| 日韩高清国产一区在线| 欧美高清性hdvideosex| 肉色丝袜一区二区| 精品国产亚洲在线| 国产成人综合精品三级| 最新国产の精品合集bt伙计| 91尤物视频在线观看| 亚洲国产精品自拍| 日韩欧美成人一区| 成a人片亚洲日本久久| 亚洲免费观看高清在线观看| 欧美视频在线观看一区二区| 日本v片在线高清不卡在线观看| 欧美成人官网二区| 国产精品1区2区| 亚洲精品国产精品乱码不99| 欧美日韩国产一级| 国产精品一区二区久久精品爱涩| 亚洲欧洲精品一区二区三区| 欧美色综合影院| 精品一区二区久久久| 国产精品毛片久久久久久久| 欧美性大战久久| 国产伦精品一区二区三区视频青涩 | 99精品视频在线播放观看| 久久精品亚洲国产奇米99 | 99久久精品免费观看| 亚洲夂夂婷婷色拍ww47| 精品国产一二三| 色乱码一区二区三区88| 五月婷婷久久丁香| 欧美精品tushy高清| 国产电影精品久久禁18| 国产精品人人做人人爽人人添| 91激情五月电影| 国产剧情av麻豆香蕉精品| 亚洲欧美日韩国产综合在线| 678五月天丁香亚洲综合网| 国产精品资源在线| 日韩高清在线不卡| 亚洲免费在线播放| 国产视频一区二区在线| 7777精品伊人久久久大香线蕉 | 欧美日韩精品系列| 成人午夜在线视频| 蜜桃av一区二区| 亚洲自拍偷拍欧美| 中文字幕制服丝袜一区二区三区 | 蜜桃av一区二区三区| 亚洲欧美国产毛片在线| 久久免费电影网| 制服丝袜亚洲精品中文字幕| www.欧美日韩| 国产福利91精品一区二区三区| 午夜激情久久久| 一区二区三区中文在线观看| 国产日韩精品一区| 久久这里都是精品| 777色狠狠一区二区三区| 91久久一区二区| 91在线视频网址| 99这里只有久久精品视频| 国产一区啦啦啦在线观看| 蜜臀av性久久久久av蜜臀妖精| 亚洲6080在线| 亚洲国产另类精品专区| 亚洲一区免费在线观看| 日韩毛片一二三区| 中文字幕一区二区三区四区不卡 | 91麻豆精品国产91久久久资源速度| 99精品久久只有精品| 懂色av一区二区三区免费观看| 激情综合网天天干| 韩国av一区二区| 国产一区在线观看麻豆| 国产乱码精品一品二品| 国模少妇一区二区三区| 国产乱人伦精品一区二区在线观看| 免费在线一区观看| 九色综合狠狠综合久久| 精品中文字幕一区二区小辣椒| 男女激情视频一区| 精品一区二区三区在线观看国产 | 麻豆成人久久精品二区三区红| 三级久久三级久久久| 免费观看在线色综合| 毛片不卡一区二区| 国产精品一区一区三区| 成人黄色av电影| 色婷婷香蕉在线一区二区| 91久久久免费一区二区| 欧美猛男男办公室激情| 日韩欧美区一区二| 久久久久9999亚洲精品| 国产精品色一区二区三区| 国产精品成人网| 亚洲大尺度视频在线观看| 婷婷国产在线综合| 国产自产视频一区二区三区| 国产高清精品网站| 色综合欧美在线视频区| 欧美伦理影视网| 久久青草国产手机看片福利盒子 | 亚洲欧美国产77777| 午夜影院久久久| 狠狠色狠狠色综合日日91app| 国产suv精品一区二区883| 色偷偷成人一区二区三区91 | 日韩视频一区二区三区在线播放| 精品国产乱码久久久久久久久| 中文字幕国产一区| 亚洲一区二区精品3399| 久久国产日韩欧美精品| 成人免费视频播放| 91麻豆精品久久久久蜜臀| 国产欧美一区二区精品久导航| 一区二区免费看| 国产剧情一区二区三区| 欧美三级视频在线播放| 久久久综合九色合综国产精品| 亚洲精品成人在线| 国产一区二区三区电影在线观看| 91麻豆6部合集magnet| 日韩欧美二区三区| 一级日本不卡的影视| 久久丁香综合五月国产三级网站| 96av麻豆蜜桃一区二区| 欧美日韩视频在线观看一区二区三区 | 欧美电视剧免费全集观看| 久久免费美女视频| 亚洲激情图片qvod| 国内成人自拍视频| 欧美视频中文一区二区三区在线观看| 久久综合九色欧美综合狠狠| 一区二区三区影院| 国产精品一级在线| 欧美一区二区三区四区久久| 日韩一区欧美一区| 国产传媒日韩欧美成人| 日韩欧美一区二区三区在线| 亚洲精品一二三| 成人激情文学综合网| 日韩精品一区二区三区在线播放| 一区二区三区精品在线观看| 国产成人av一区二区| 欧美成人一区二区三区在线观看| 一区二区在线观看不卡| 成人高清免费在线播放| 欧美不卡视频一区| 蜜臀a∨国产成人精品| 一本久久a久久精品亚洲| 成人欧美一区二区三区黑人麻豆| 国产乱淫av一区二区三区| 日韩美女啊v在线免费观看| 国产美女视频91| 欧美一个色资源| 亚洲一区二区三区视频在线播放 | 日本精品一级二级| 亚洲欧洲另类国产综合| 国产精品一色哟哟哟| 欧美成人一区二区三区在线观看| 日韩成人av影视| 欧美一级在线视频| 裸体歌舞表演一区二区| 日韩一区二区电影在线| 日韩成人av影视| 日韩午夜小视频| 美女视频一区二区| 欧美大胆一级视频| 国精产品一区一区三区mba桃花 | 国产亚洲精品bt天堂精选| 国产自产高清不卡| 国产日产欧美精品一区二区三区| 精品99999| 91香蕉视频在线| 一区二区三区精品在线观看| 在线免费观看日韩欧美| 欧美一级片在线看| 日韩精品成人一区二区三区| 4438x亚洲最大成人网| 男人操女人的视频在线观看欧美| 日韩欧美中文字幕精品| 国内精品免费在线观看| 久久伊99综合婷婷久久伊| 国产成人精品影院| 亚洲女同女同女同女同女同69| 91网址在线看| 天天综合色天天综合| 日韩精品自拍偷拍| 成人一区二区三区视频在线观看 | 天天色天天操综合| 日韩欧美一级二级| 国产精品18久久久久久久久久久久| 中文字幕精品一区二区精品绿巨人 | 91在线国产福利| 亚洲视频狠狠干| 欧美午夜理伦三级在线观看| 精品成人佐山爱一区二区|