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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? i2c-dev.c

?? linux 內核源代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*    i2c-dev.c - i2c-bus driver, char device interface    Copyright (C) 1995-97 Simon G. Vogl    Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl>    Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.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.*//* Note that this is a complete rewrite of Simon Vogl's i2c-dev module.   But I have used so much of his original code and ideas that it seems   only fair to recognize him as co-author -- Frodo *//* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */#include <linux/kernel.h>#include <linux/module.h>#include <linux/fs.h>#include <linux/slab.h>#include <linux/init.h>#include <linux/list.h>#include <linux/i2c.h>#include <linux/i2c-dev.h>#include <asm/uaccess.h>static struct i2c_driver i2cdev_driver;/* * An i2c_dev represents an i2c_adapter ... an I2C or SMBus master, not a * slave (i2c_client) with which messages will be exchanged.  It's coupled * with a character special file which is accessed by user mode drivers. * * The list of i2c_dev structures is parallel to the i2c_adapter lists * maintained by the driver model, and is updated using notifications * delivered to the i2cdev_driver. */struct i2c_dev {	struct list_head list;	struct i2c_adapter *adap;	struct device *dev;};#define I2C_MINORS	256static LIST_HEAD(i2c_dev_list);static DEFINE_SPINLOCK(i2c_dev_list_lock);static struct i2c_dev *i2c_dev_get_by_minor(unsigned index){	struct i2c_dev *i2c_dev;	spin_lock(&i2c_dev_list_lock);	list_for_each_entry(i2c_dev, &i2c_dev_list, list) {		if (i2c_dev->adap->nr == index)			goto found;	}	i2c_dev = NULL;found:	spin_unlock(&i2c_dev_list_lock);	return i2c_dev;}static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap){	struct i2c_dev *i2c_dev;	if (adap->nr >= I2C_MINORS) {		printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n",		       adap->nr);		return ERR_PTR(-ENODEV);	}	i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);	if (!i2c_dev)		return ERR_PTR(-ENOMEM);	i2c_dev->adap = adap;	spin_lock(&i2c_dev_list_lock);	list_add_tail(&i2c_dev->list, &i2c_dev_list);	spin_unlock(&i2c_dev_list_lock);	return i2c_dev;}static void return_i2c_dev(struct i2c_dev *i2c_dev){	spin_lock(&i2c_dev_list_lock);	list_del(&i2c_dev->list);	spin_unlock(&i2c_dev_list_lock);	kfree(i2c_dev);}static ssize_t show_adapter_name(struct device *dev,				 struct device_attribute *attr, char *buf){	struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt));	if (!i2c_dev)		return -ENODEV;	return sprintf(buf, "%s\n", i2c_dev->adap->name);}static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);/* ------------------------------------------------------------------------- *//* * After opening an instance of this character special file, a file * descriptor starts out associated only with an i2c_adapter (and bus). * * Using the I2C_RDWR ioctl(), you can then *immediately* issue i2c_msg * traffic to any devices on the bus used by that adapter.  That's because * the i2c_msg vectors embed all the addressing information they need, and * are submitted directly to an i2c_adapter.  However, SMBus-only adapters * don't support that interface. * * To use read()/write() system calls on that file descriptor, or to use * SMBus interfaces (and work with SMBus-only hosts!), you must first issue * an I2C_SLAVE (or I2C_SLAVE_FORCE) ioctl.  That configures an anonymous * (never registered) i2c_client so it holds the addressing information * needed by those system calls and by this SMBus interface. */static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,                            loff_t *offset){	char *tmp;	int ret;	struct i2c_client *client = (struct i2c_client *)file->private_data;	if (count > 8192)		count = 8192;	tmp = kmalloc(count,GFP_KERNEL);	if (tmp==NULL)		return -ENOMEM;	pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n",		iminor(file->f_path.dentry->d_inode), count);	ret = i2c_master_recv(client,tmp,count);	if (ret >= 0)		ret = copy_to_user(buf,tmp,count)?-EFAULT:ret;	kfree(tmp);	return ret;}static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t count,                             loff_t *offset){	int ret;	char *tmp;	struct i2c_client *client = (struct i2c_client *)file->private_data;	if (count > 8192)		count = 8192;	tmp = kmalloc(count,GFP_KERNEL);	if (tmp==NULL)		return -ENOMEM;	if (copy_from_user(tmp,buf,count)) {		kfree(tmp);		return -EFAULT;	}	pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n",		iminor(file->f_path.dentry->d_inode), count);	ret = i2c_master_send(client,tmp,count);	kfree(tmp);	return ret;}/* This address checking function differs from the one in i2c-core   in that it considers an address with a registered device, but no   bound driver, as NOT busy. */static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr){	struct list_head *item;	struct i2c_client *client;	int res = 0;	mutex_lock(&adapter->clist_lock);	list_for_each(item, &adapter->clients) {		client = list_entry(item, struct i2c_client, list);		if (client->addr == addr) {			if (client->driver)				res = -EBUSY;			break;		}	}	mutex_unlock(&adapter->clist_lock);	return res;}static int i2cdev_ioctl(struct inode *inode, struct file *file,		unsigned int cmd, unsigned long arg){	struct i2c_client *client = (struct i2c_client *)file->private_data;	struct i2c_rdwr_ioctl_data rdwr_arg;	struct i2c_smbus_ioctl_data data_arg;	union i2c_smbus_data temp;	struct i2c_msg *rdwr_pa;	u8 __user **data_ptrs;	int i,datasize,res;	unsigned long funcs;	dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n",		cmd, arg);	switch ( cmd ) {	case I2C_SLAVE:	case I2C_SLAVE_FORCE:		/* NOTE:  devices set up to work with "new style" drivers		 * can't use I2C_SLAVE, even when the device node is not		 * bound to a driver.  Only I2C_SLAVE_FORCE will work.		 *		 * Setting the PEC flag here won't affect kernel drivers,		 * which will be using the i2c_client node registered with		 * the driver model core.  Likewise, when that client has		 * the PEC flag already set, the i2c-dev driver won't see		 * (or use) this setting.		 */		if ((arg > 0x3ff) ||		    (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f))			return -EINVAL;		if (cmd == I2C_SLAVE && i2cdev_check_addr(client->adapter, arg))			return -EBUSY;		/* REVISIT: address could become busy later */		client->addr = arg;		return 0;	case I2C_TENBIT:		if (arg)			client->flags |= I2C_M_TEN;		else			client->flags &= ~I2C_M_TEN;		return 0;	case I2C_PEC:		if (arg)			client->flags |= I2C_CLIENT_PEC;		else			client->flags &= ~I2C_CLIENT_PEC;		return 0;	case I2C_FUNCS:		funcs = i2c_get_functionality(client->adapter);		return put_user(funcs, (unsigned long __user *)arg);	case I2C_RDWR:		if (copy_from_user(&rdwr_arg,				   (struct i2c_rdwr_ioctl_data __user *)arg,				   sizeof(rdwr_arg)))			return -EFAULT;		/* Put an arbitrary limit on the number of messages that can		 * be sent at once */		if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)			return -EINVAL;		rdwr_pa = (struct i2c_msg *)			kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),			GFP_KERNEL);		if (rdwr_pa == NULL) return -ENOMEM;		if (copy_from_user(rdwr_pa, rdwr_arg.msgs,				   rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {			kfree(rdwr_pa);			return -EFAULT;		}		data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);		if (data_ptrs == NULL) {			kfree(rdwr_pa);			return -ENOMEM;		}		res = 0;		for( i=0; i<rdwr_arg.nmsgs; i++ ) {			/* Limit the size of the message to a sane amount;			 * and don't let length change either. */			if ((rdwr_pa[i].len > 8192) ||			    (rdwr_pa[i].flags & I2C_M_RECV_LEN)) {				res = -EINVAL;				break;			}			data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;			rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL);			if(rdwr_pa[i].buf == NULL) {				res = -ENOMEM;				break;			}			if(copy_from_user(rdwr_pa[i].buf,				data_ptrs[i],				rdwr_pa[i].len)) {					++i; /* Needs to be kfreed too */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91久久奴性调教| 国产精品美女久久久久久| 国产午夜精品一区二区| 亚洲成人av免费| 高清在线观看日韩| 欧美大尺度电影在线| 一区二区三区自拍| a在线欧美一区| 久久综合九色欧美综合狠狠| 午夜精品一区二区三区三上悠亚 | 亚洲一区二区美女| 成人一区二区视频| 久久婷婷综合激情| 蜜臀av性久久久久蜜臀aⅴ流畅| 日本韩国视频一区二区| 中文字幕免费一区| 国产成人精品1024| 欧美成人video| 麻豆freexxxx性91精品| 欧美美女bb生活片| 亚洲国产精品久久久久婷婷884 | 国产精品久久久久一区二区三区 | 国产精品久久久99| 国产乱一区二区| 精品国产一区a| 久久成人久久鬼色| 精品国产精品一区二区夜夜嗨| 亚洲成精国产精品女| 欧美日韩一本到| 亚洲成人高清在线| 欧美日韩三级在线| 天涯成人国产亚洲精品一区av| 欧美日韩在线综合| 三级亚洲高清视频| 日韩欧美黄色影院| 国产乱一区二区| 国产精品久久看| 色噜噜久久综合| 舔着乳尖日韩一区| 欧美不卡一区二区三区| 国产精品综合久久| 国产精品女同互慰在线看| 99精品欧美一区二区蜜桃免费 | 麻豆精品久久精品色综合| 欧美电视剧免费全集观看| 激情久久五月天| 国产精品久久久久久亚洲伦| 成人高清免费观看| 亚洲一区二区三区四区在线观看| 欧美丝袜自拍制服另类| 日韩有码一区二区三区| 欧美mv日韩mv国产| 成人黄色在线网站| 亚洲最大的成人av| 欧美一区二区三区在线观看| 久久国产精品区| 中文字幕中文字幕在线一区| 色偷偷一区二区三区| 毛片基地黄久久久久久天堂| 国产偷v国产偷v亚洲高清| 91碰在线视频| 久久se精品一区精品二区| 国产精品国产馆在线真实露脸| 欧美午夜寂寞影院| 国产一区二区三区电影在线观看| 亚洲另类春色国产| 欧美电视剧在线看免费| 91一区二区在线观看| 蜜臀久久久99精品久久久久久| 亚洲国产精品二十页| 欧美日韩视频在线一区二区| 国产夫妻精品视频| 天天亚洲美女在线视频| 国产精品白丝在线| 亚洲精品一区二区精华| 色网站国产精品| 激情另类小说区图片区视频区| 亚洲摸摸操操av| 久久人人超碰精品| 欧美久久久久中文字幕| 波波电影院一区二区三区| 日本欧美一区二区三区乱码| 国产精品大尺度| 精品免费国产一区二区三区四区| 一本一本大道香蕉久在线精品| 国产在线精品一区二区| 香蕉乱码成人久久天堂爱免费| 国产精品私人自拍| 精品奇米国产一区二区三区| 欧美性色aⅴ视频一区日韩精品| 成人在线视频一区| 国产一区二区三区电影在线观看| 天天综合网 天天综合色| 亚洲欧美激情插 | 色综合中文字幕| 粉嫩久久99精品久久久久久夜| 免费高清在线一区| 天天综合网 天天综合色| 亚洲一区二区在线视频| 亚洲欧美一区二区三区极速播放| 久久久精品国产免大香伊| 欧美大片免费久久精品三p| 777奇米成人网| 欧美精品xxxxbbbb| 欧美日韩专区在线| 日本丰满少妇一区二区三区| 99久久久国产精品免费蜜臀| 高清国产一区二区三区| 国产乱子伦视频一区二区三区| 韩国毛片一区二区三区| 国产一区二三区| 国内精品久久久久影院一蜜桃| 美女视频黄频大全不卡视频在线播放| 午夜精品视频一区| 视频一区欧美日韩| 蜜桃传媒麻豆第一区在线观看| 五月天欧美精品| 日韩电影在线免费看| 日本va欧美va欧美va精品| 日本sm残虐另类| 激情综合亚洲精品| 成人激情av网| 91在线观看成人| 在线免费观看日本欧美| 欧美三级电影网| 91精品久久久久久久久99蜜臂| 日韩欧美电影一区| 久久久精品综合| 亚洲免费视频成人| 亚洲一卡二卡三卡四卡无卡久久| 亚洲第一综合色| 奇米影视7777精品一区二区| 国产一区二区三区综合| 99v久久综合狠狠综合久久| 91欧美激情一区二区三区成人| 欧美视频精品在线| 欧美电视剧免费全集观看| 亚洲国产精品精华液ab| 亚洲午夜视频在线观看| 黑人精品欧美一区二区蜜桃| 成人av动漫网站| 宅男在线国产精品| 国产女主播在线一区二区| 一区二区久久久| 国产在线播放一区| 欧美综合一区二区| 久久久99免费| 亚洲国产精品一区二区久久| 激情六月婷婷综合| 欧美综合久久久| 国产欧美va欧美不卡在线| 亚洲国产综合色| 国产jizzjizz一区二区| 在线观看日韩一区| 国产日韩综合av| 日韩成人一区二区三区在线观看| 成人三级在线视频| 91精品国产91热久久久做人人| 国产欧美一区二区精品仙草咪| 亚洲bt欧美bt精品| 成人sese在线| 欧美精品一区二区三区久久久 | 一本色道久久加勒比精品| 91精品国产一区二区| 中文字幕在线不卡国产视频| 美国十次了思思久久精品导航| 91浏览器在线视频| 国产日本一区二区| 久久精品国产77777蜜臀| 欧洲日韩一区二区三区| 国产精品乱人伦一区二区| 免费人成黄页网站在线一区二区| aaa欧美日韩| 国产欧美精品区一区二区三区 | 欧美成人乱码一区二区三区| 伊人一区二区三区| 成人深夜视频在线观看| 久久久精品黄色| 久久精品国产色蜜蜜麻豆| 精品污污网站免费看| 亚洲视频在线观看一区| 丁香婷婷综合激情五月色| 日韩女优制服丝袜电影| 日日夜夜精品视频免费| 欧美亚洲综合一区| 尤物av一区二区| 在线视频国产一区| 亚洲男人都懂的| 色狠狠综合天天综合综合| 亚洲欧美日韩成人高清在线一区| 波多野结衣在线aⅴ中文字幕不卡 波多野结衣在线一区 | 这里只有精品视频在线观看| 亚洲成a天堂v人片| 欧美日韩精品一区二区三区蜜桃| 亚洲国产一区视频| 欧美色偷偷大香| 丝袜美腿亚洲色图| 91精品国产91久久综合桃花| 日韩av中文字幕一区二区三区| 正在播放亚洲一区|