Changeset 160

Show
Ignore:
Timestamp:
01/13/99 20:07:57 (10 years ago)
Author:
frodo
Message:

Completed i2c-dev. Not tested yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/TODO

    r159 r160  
    11Many, many things. Most notably: 
    22 
     3* Check for block read/writes in smbus-on-i2c emulation code 
    34* Merge newest Simon Vogl archive 
    45* Merge man-pages 
  • lm-sensors/trunk/kernel/i2c-dev.c

    r158 r160  
    2929#include "compat.h" 
    3030#include "i2c.h" 
     31#include "smbus.h" 
    3132#include "isa.h" 
    3233#include "sensors.h" 
    3334#include "version.h" 
     35#include "i2c-dev.h" 
    3436 
    3537#ifdef MODULE 
     
    145147#endif 
    146148{ 
     149#ifdef DEBUG 
     150#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,56)) 
     151   struct inode *inode = file->f_dentry->d_inode; 
     152#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     153  printk("i2c_dev,o: i2c-%d lseek to %ld bytes relative to %d.\n", 
     154         MINOR(inode->i_rdev),offset,origin); 
     155#endif /* DEBUG */ 
    147156  return -ESPIPE; 
    148157} 
     
    162171  int ret; 
    163172 
     173#ifdef DEBUG 
     174#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) 
     175   struct inode *inode = file->f_dentry->d_inode; 
     176#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     177#endif /* DEBUG */ 
     178 
    164179  struct i2c_client *client = (struct i2c_client *)file->private_data; 
    165  
    166 #ifdef  DEBUG 
    167   printk("i2cdev_read: i2c%d reading %d bytes from %d.\n",minor,count, 
    168          client->addr); 
    169 #endif 
    170180 
    171181  /* copy user space data to kernel space. */ 
     
    173183  if (tmp==NULL) 
    174184     return -ENOMEM; 
     185 
     186#ifdef DEBUG 
     187  printk("i2c_dev,o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),count); 
     188#endif 
     189 
    175190  ret = i2c_master_recv(client,tmp,count); 
    176191  copy_to_user(buf,tmp,count); 
     
    194209  struct i2c_client *client = (struct i2c_client *)file->private_data; 
    195210 
     211#ifdef DEBUG 
     212#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) 
     213   struct inode *inode = file->f_dentry->d_inode; 
     214#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     215#endif /* DEBUG */ 
     216 
    196217  /* copy user space data to kernel space. */ 
    197218  tmp = kmalloc(count,GFP_KERNEL); 
     
    201222 
    202223#ifdef DEBUG 
    203   printk("i2c_write: i2c%d writing %d bytes.\n",minor,count); 
     224  printk("i2c_dev,o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),count); 
    204225#endif 
    205226  ret = i2c_master_send(client,tmp,count); 
     
    208229} 
    209230 
    210    
     231int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,  
     232                  unsigned long arg) 
     233
     234  struct i2c_client *client = (struct i2c_client *)file->private_data; 
     235  struct i2c_smbus_data *data_arg; 
     236  union smbus_data temp; 
     237  int ver,datasize,res; 
     238 
     239#ifdef DEBUG 
     240#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) 
     241   struct inode *inode = file->f_dentry->d_inode; 
     242#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     243  printk("i2c_dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",  
     244         MINOR(inode->i_rdev),cmd, arg); 
     245#endif /* DEBUG */ 
     246 
     247  switch ( cmd ) { 
     248    case I2C_SLAVE: 
     249      if (arg > 0x7f) 
     250        return -EINVAL; 
     251      client->addr = arg; 
     252      return 0; 
     253    case I2C_TENBIT: 
     254      printk("i2c-dev.o: ioctl I2C_TENBIT not (yet) supported!\n"); 
     255      return -EINVAL; 
     256    case I2C_SMBUS: 
     257      if (! (data_arg = (struct i2c_smbus_data *) arg)) { 
     258#ifdef DEBUG 
     259        printk("i2c-dev.o: NULL argument pointer in ioctl I2C_SMBUS.\n"); 
     260#endif 
     261        return -EINVAL; 
     262      } 
     263      if (verify_area(VERIFY_READ,data_arg,sizeof(struct i2c_smbus_data))) { 
     264#ifdef DEBUG 
     265        printk("i2c-dev.o: invalid argument pointer (%p) " 
     266               "in IOCTL I2C_SMBUS.\n", data_arg); 
     267#endif 
     268        return -EINVAL; 
     269      } 
     270      if ((data_arg->size != SMBUS_BYTE) &&  
     271          (data_arg->size != SMBUS_QUICK) && 
     272          (data_arg->size != SMBUS_BYTE_DATA) &&  
     273          (data_arg->size != SMBUS_WORD_DATA) && 
     274          (data_arg->size != SMBUS_PROC_CALL) && 
     275          (data_arg->size != SMBUS_BLOCK_DATA)) { 
     276#ifdef DEBUG 
     277        printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n", 
     278               data_arg->size); 
     279#endif 
     280        return -EINVAL; 
     281      } 
     282      /* Note that SMBUS_READ and SMBUS_WRITE are 0 and 1, so the check is 
     283         valid if size==SMBUS_QUICK too. */ 
     284      if ((data_arg->read_write != SMBUS_READ) &&  
     285          (data_arg->read_write != SMBUS_WRITE)) { 
     286#ifdef DEBUG 
     287        printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n", 
     288               data_arg->read_write); 
     289#endif 
     290        return -EINVAL; 
     291      } 
     292 
     293      /* Note that command values are always valid! */ 
     294 
     295      if ((data_arg->size == SMBUS_QUICK) || 
     296          ((data_arg->size == SMBUS_BYTE) &&  
     297           (data_arg->read_write == SMBUS_WRITE))) 
     298        /* These are special: we do not use data */ 
     299        return smbus_access(client->adapter, client->addr,  
     300                            data_arg->read_write, data_arg->command, 
     301                            data_arg->size, NULL); 
     302 
     303      if (data_arg->data == NULL) { 
     304#ifdef DEBUG 
     305        printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n"); 
     306#endif 
     307        return -EINVAL; 
     308      } 
     309 
     310      /* This seems unlogical but it is not: if the user wants to read a 
     311         value, we must write that value to user memory! */ 
     312      ver = (data_arg->read_write == SMBUS_WRITE)?VERIFY_READ:VERIFY_WRITE; 
     313 
     314      if ((data_arg->size == SMBUS_BYTE_DATA) || (data_arg->size == SMBUS_BYTE)) 
     315        datasize = sizeof(data_arg->data->byte); 
     316      else if (data_arg->size == SMBUS_WORD_DATA) 
     317        datasize = sizeof(data_arg->data->word); 
     318      else /* size == SMBUS_BLOCK_DATA */ 
     319        datasize = sizeof(data_arg->data->block); 
     320 
     321      if (verify_area(ver,data_arg->data,datasize)) { 
     322#ifdef DEBUG 
     323        printk("i2c-dev.o: invalid pointer data (%p) in ioctl I2C_SMBUS.\n", 
     324               data_arg->data); 
     325#endif 
     326        return -EINVAL; 
     327      } 
     328      if (data_arg->read_write == SMBUS_WRITE) { 
     329        copy_from_user(&temp,data_arg->data,datasize); 
     330        return smbus_access(client->adapter,client->addr,data_arg->read_write, 
     331                            data_arg->command,data_arg->size,&temp); 
     332      } else { 
     333        res = smbus_access(client->adapter,client->addr,data_arg->read_write, 
     334                           data_arg->command,data_arg->size,&temp); 
     335        if (!res) 
     336          copy_to_user(data_arg->data,&temp,datasize); 
     337        return res; 
     338      } 
     339    default: 
     340      return i2c_control(client,cmd,arg); 
     341   } 
     342  return 0; 
     343
     344 
    211345int i2cdev_open (struct inode *inode, struct file *file) 
    212346{ 
     
    216350  if (! i2cdev_clients[minor]) { 
    217351#ifdef DEBUG 
    218     printk("i2cdev: trying to open unattached adapter i2c-%d\n",minor); 
     352    printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n",minor); 
    219353#endif 
    220354    return -ENODEV; 
     
    232366 
    233367#ifdef DEBUG 
    234   printk("i2cdev_open: i2c-%d\n",minor); 
     368  printk("i2c-dev.o: opened i2c-%d\n",minor); 
    235369#endif 
    236370  return 0; 
     
    246380   file->private_data=NULL; 
    247381#ifdef DEBUG 
    248    printk("i2c_close: i2c-%d\n", MINOR(inode->i_rdev)); 
     382   printk("i2c-dev.o: Closed: i2c-%d\n", MINOR(inode->i_rdev)); 
    249383#endif 
    250384  MOD_DEC_USE_COUNT; 
     
    260394 
    261395  if ((i = i2c_adapter_id(adap)) < 0) { 
    262     printk("i2cdev_attach_adapter: unknown adapter?!?\n"); 
     396    printk("i2c-dev.o: Unknown adapter to attach?!?\n"); 
    263397    return -ENODEV; 
    264398  } 
    265399  if (i >= I2CDEV_CLIENTS_MAX) { 
    266     printk("i2cdev_attach_adapter: adapter number too large?!? (%d)\n",i); 
     400    printk("i2c-dev.o: Adapter number to attach too large?!? (%d)\n",i); 
    267401    return -ENODEV; 
    268402  } 
    269403  if (i2cdev_clients[i]) { 
    270     printk("i2cdev_attach_adapter: adapter already in use?!? (%d)\n",i); 
     404    printk("i2c-dev.o: Adapter to attach already in use?!? (%d)\n",i); 
    271405    return -EBUSY; 
    272406  } 
    273407  if (i2c_is_isa_adapter(adap)) { 
    274     printk("i2cdev_attach_adapter: Can't open ISA adapter!\n"); 
    275     return -ENODEV; 
     408#ifdef DEBUG 
     409    printk("i2c-dev.o: Can't open ISA adapter!\n"); 
     410#endif 
     411    return 0; 
    276412  } 
    277413 
     
    282418  client->adapter = adap; 
    283419  if ((res =  i2c_attach_client(client))) { 
    284     printk("i2cdev_attach_adapter: attaching client failed.\n"); 
     420    printk("i2c-dev.o: Attaching client failed.\n"); 
    285421    kfree(client); 
    286422    return res; 
    287423  } 
    288424  i2cdev_clients[i] = client; 
    289   printk("i2cdev: registered '%s' as minor %d\n",adap->name,i); 
     425  printk("i2cdev.o: Registered '%s' as minor %d\n",adap->name,i); 
    290426  return 0; 
    291427} 
     
    297433 
    298434  if ((i = i2c_adapter_id(adap)) < 0) { 
    299     printk("i2cdev_detach_adapter: unknown adapter?!?\n"); 
     435    printk("i2c-dev.o: Detaching unknown adapter?!?\n"); 
    300436    return -ENODEV; 
    301437  } 
    302438  if (i >= I2CDEV_CLIENTS_MAX) { 
    303     printk("i2cdev_detach_adapter: adapter number too large?!? (%d)\n",i); 
     439    printk("i2c-dev.o: Adapter number to detach too large?!? (%d)\n",i); 
    304440    return -ENODEV; 
    305441  } 
    306442  if (!i2cdev_clients[i]) { 
    307     printk("i2cdev_detach_adapter: adapter not in use?!? (%d)\n",i); 
     443    printk("i2c-dev.o: Adapter to detach not in use?!? (%d)\n",i); 
    308444    return -ENODEV; 
    309445  } 
    310446 
    311447  if ((res =  i2c_detach_client(client))) { 
    312     printk("i2cdev_detach_adapter: detaching client failed.\n"); 
     448    printk("i2c-dev.o: detaching client %d failed.\n",i); 
    313449    return res; 
    314450  } 
     
    318454 
    319455#ifdef DEBUG 
    320   printk("i2c(char): adapter unregistered: %s\n",adap->name); 
     456  printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name); 
    321457#endif 
    322458  return 0; 
  • lm-sensors/trunk/kernel/include/i2c-dev.h

    r159 r160  
    2424#ifdef LM_SENSORS 
    2525#include "i2c.h" 
     26#include "smbus.h" 
    2627#else /* ndef LM_SENSORS */ 
    2728#include <linux/i2c.h> 
     29#include <linux/smbus.h> 
    2830#endif /* def LM_SENSORS */ 
    2931 
     
    3537/* This is the structure as used in the I2C_SMBUS ioctl call */ 
    3638struct i2c_smbus_data { 
    37   char read_write, 
    38   u8 command, 
    39   int size, 
    40   union smbus_data data 
     39  char read_write; 
     40  u8 command; 
     41  int size; 
     42  union smbus_data *data; 
    4143}; 
     44 
     45#ifndef __KERNEL__ 
     46 
     47#include <linux/ioctl.h> 
    4248 
    4349extern inline s32 i2c_smbus_access(int file, char read_write, u8 command,  
     
    5056  args.command = command; 
    5157  args.size = size; 
    52   if (data) 
    53     memcpy(&args.data,data,sizeof(union smbus_data)); 
    54   res = ioctl(f,I2C_SMBUS,&args); 
    55   if (data) 
    56     memcpy(data,&args,sizeof(union smbus_data)); 
    57   return res; 
     58  args.data = data; 
     59  return ioctl(file,I2C_SMBUS,&args); 
    5860} 
    5961 
     
    148150} 
    149151 
     152#endif /* ndef __KERNEL__ */ 
     153 
    150154#endif 
  • lm-sensors/trunk/src/i2c-dev.c

    r158 r160  
    2929#include "compat.h" 
    3030#include "i2c.h" 
     31#include "smbus.h" 
    3132#include "isa.h" 
    3233#include "sensors.h" 
    3334#include "version.h" 
     35#include "i2c-dev.h" 
    3436 
    3537#ifdef MODULE 
     
    145147#endif 
    146148{ 
     149#ifdef DEBUG 
     150#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,56)) 
     151   struct inode *inode = file->f_dentry->d_inode; 
     152#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     153  printk("i2c_dev,o: i2c-%d lseek to %ld bytes relative to %d.\n", 
     154         MINOR(inode->i_rdev),offset,origin); 
     155#endif /* DEBUG */ 
    147156  return -ESPIPE; 
    148157} 
     
    162171  int ret; 
    163172 
     173#ifdef DEBUG 
     174#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) 
     175   struct inode *inode = file->f_dentry->d_inode; 
     176#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     177#endif /* DEBUG */ 
     178 
    164179  struct i2c_client *client = (struct i2c_client *)file->private_data; 
    165  
    166 #ifdef  DEBUG 
    167   printk("i2cdev_read: i2c%d reading %d bytes from %d.\n",minor,count, 
    168          client->addr); 
    169 #endif 
    170180 
    171181  /* copy user space data to kernel space. */ 
     
    173183  if (tmp==NULL) 
    174184     return -ENOMEM; 
     185 
     186#ifdef DEBUG 
     187  printk("i2c_dev,o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),count); 
     188#endif 
     189 
    175190  ret = i2c_master_recv(client,tmp,count); 
    176191  copy_to_user(buf,tmp,count); 
     
    194209  struct i2c_client *client = (struct i2c_client *)file->private_data; 
    195210 
     211#ifdef DEBUG 
     212#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) 
     213   struct inode *inode = file->f_dentry->d_inode; 
     214#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     215#endif /* DEBUG */ 
     216 
    196217  /* copy user space data to kernel space. */ 
    197218  tmp = kmalloc(count,GFP_KERNEL); 
     
    201222 
    202223#ifdef DEBUG 
    203   printk("i2c_write: i2c%d writing %d bytes.\n",minor,count); 
     224  printk("i2c_dev,o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),count); 
    204225#endif 
    205226  ret = i2c_master_send(client,tmp,count); 
     
    208229} 
    209230 
    210    
     231int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,  
     232                  unsigned long arg) 
     233
     234  struct i2c_client *client = (struct i2c_client *)file->private_data; 
     235  struct i2c_smbus_data *data_arg; 
     236  union smbus_data temp; 
     237  int ver,datasize,res; 
     238 
     239#ifdef DEBUG 
     240#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) 
     241   struct inode *inode = file->f_dentry->d_inode; 
     242#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ 
     243  printk("i2c_dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",  
     244         MINOR(inode->i_rdev),cmd, arg); 
     245#endif /* DEBUG */ 
     246 
     247  switch ( cmd ) { 
     248    case I2C_SLAVE: 
     249      if (arg > 0x7f) 
     250        return -EINVAL; 
     251      client->addr = arg; 
     252      return 0; 
     253    case I2C_TENBIT: 
     254      printk("i2c-dev.o: ioctl I2C_TENBIT not (yet) supported!\n"); 
     255      return -EINVAL; 
     256    case I2C_SMBUS: 
     257      if (! (data_arg = (struct i2c_smbus_data *) arg)) { 
     258#ifdef DEBUG 
     259        printk("i2c-dev.o: NULL argument pointer in ioctl I2C_SMBUS.\n"); 
     260#endif 
     261        return -EINVAL; 
     262      } 
     263      if (verify_area(VERIFY_READ,data_arg,sizeof(struct i2c_smbus_data))) { 
     264#ifdef DEBUG 
     265        printk("i2c-dev.o: invalid argument pointer (%p) " 
     266               "in IOCTL I2C_SMBUS.\n", data_arg); 
     267#endif 
     268        return -EINVAL; 
     269      } 
     270      if ((data_arg->size != SMBUS_BYTE) &&  
     271          (data_arg->size != SMBUS_QUICK) && 
     272          (data_arg->size != SMBUS_BYTE_DATA) &&  
     273          (data_arg->size != SMBUS_WORD_DATA) && 
     274          (data_arg->size != SMBUS_PROC_CALL) && 
     275          (data_arg->size != SMBUS_BLOCK_DATA)) { 
     276#ifdef DEBUG 
     277        printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n", 
     278               data_arg->size); 
     279#endif 
     280        return -EINVAL; 
     281      } 
     282      /* Note that SMBUS_READ and SMBUS_WRITE are 0 and 1, so the check is 
     283         valid if size==SMBUS_QUICK too. */ 
     284      if ((data_arg->read_write != SMBUS_READ) &&  
     285          (data_arg->read_write != SMBUS_WRITE)) { 
     286#ifdef DEBUG 
     287        printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n", 
     288               data_arg->read_write); 
     289#endif 
     290        return -EINVAL; 
     291      } 
     292 
     293      /* Note that command values are always valid! */ 
     294 
     295      if ((data_arg->size == SMBUS_QUICK) || 
     296          ((data_arg->size == SMBUS_BYTE) &&  
     297           (data_arg->read_write == SMBUS_WRITE))) 
     298        /* These are special: we do not use data */ 
     299        return smbus_access(client->adapter, client->addr,  
     300                            data_arg->read_write, data_arg->command, 
     301                            data_arg->size, NULL); 
     302 
     303      if (data_arg->data == NULL) { 
     304#ifdef DEBUG 
     305        printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n"); 
     306#endif 
     307        return -EINVAL; 
     308      } 
     309 
     310      /* This seems unlogical but it is not: if the user wants to read a 
     311         value, we must write that value to user memory! */ 
     312      ver = (data_arg->read_write == SMBUS_WRITE)?VERIFY_READ:VERIFY_WRITE; 
     313 
     314      if ((data_arg->size == SMBUS_BYTE_DATA) || (data_arg->size == SMBUS_BYTE)) 
     315        datasize = sizeof(data_arg->data->byte); 
     316      else if (data_arg->size == SMBUS_WORD_DATA) 
     317        datasize = sizeof(data_arg->data->word); 
     318      else /* size == SMBUS_BLOCK_DATA */ 
     319        datasize = sizeof(data_arg->data->block); 
     320 
     321      if (verify_area(ver,data_arg->data,datasize)) { 
     322#ifdef DEBUG 
     323        printk("i2c-dev.o: invalid pointer data (%p) in ioctl I2C_SMBUS.\n", 
     324               data_arg->data); 
     325#endif 
     326        return -EINVAL; 
     327      } 
     328      if (data_arg->read_write == SMBUS_WRITE) { 
     329        copy_from_user(&temp,data_arg->data,datasize); 
     330        return smbus_access(client->adapter,client->addr,data_arg->read_write, 
     331                            data_arg->command,data_arg->size,&temp); 
     332      } else { 
     333        res = smbus_access(client->adapter,client->addr,data_arg->read_write, 
     334                           data_arg->command,data_arg->size,&temp); 
     335        if (!res) 
     336          copy_to_user(data_arg->data,&temp,datasize); 
     337        return res; 
     338      } 
     339    default: 
     340      return i2c_control(client,cmd,arg); 
     341   } 
     342  return 0; 
     343
     344 
    211345int i2cdev_open (struct inode *inode, struct file *file) 
    212346{ 
     
    216350  if (! i2cdev_clients[minor]) { 
    217351#ifdef DEBUG 
    218     printk("i2cdev: trying to open unattached adapter i2c-%d\n",minor); 
     352    printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n",minor); 
    219353#endif 
    220354    return -ENODEV; 
     
    232366 
    233367#ifdef DEBUG 
    234   printk("i2cdev_open: i2c-%d\n",minor); 
     368  printk("i2c-dev.o: opened i2c-%d\n",minor); 
    235369#endif 
    236370  return 0; 
     
    246380   file->private_data=NULL; 
    247381#ifdef DEBUG 
    248    printk("i2c_close: i2c-%d\n", MINOR(inode->i_rdev)); 
     382   printk("i2c-dev.o: Closed: i2c-%d\n", MINOR(inode->i_rdev)); 
    249383#endif 
    250384  MOD_DEC_USE_COUNT; 
     
    260394 
    261395  if ((i = i2c_adapter_id(adap)) < 0) { 
    262     printk("i2cdev_attach_adapter: unknown adapter?!?\n"); 
     396    printk("i2c-dev.o: Unknown adapter to attach?!?\n"); 
    263397    return -ENODEV; 
    264398  } 
    265399  if (i >= I2CDEV_CLIENTS_MAX) { 
    266     printk("i2cdev_attach_adapter: adapter number too large?!? (%d)\n",i); 
     400    printk("i2c-dev.o: Adapter number to attach too large?!? (%d)\n",i); 
    267401    return -ENODEV; 
    268402  } 
    269403  if (i2cdev_clients[i]) { 
    270     printk("i2cdev_attach_adapter: adapter already in use?!? (%d)\n",i); 
     404    printk("i2c-dev.o: Adapter to attach already in use?!? (%d)\n",i); 
    271405    return -EBUSY; 
    272406  } 
    273407  if (i2c_is_isa_adapter(adap)) { 
    274     printk("i2cdev_attach_adapter: Can't open ISA adapter!\n"); 
    275     return -ENODEV; 
     408#ifdef DEBUG 
     409    printk("i2c-dev.o: Can't open ISA adapter!\n"); 
     410#endif 
     411    return 0; 
    276412  } 
    277413 
     
    282418  client->adapter = adap; 
    283419  if ((res =  i2c_attach_client(client))) { 
    284     printk("i2cdev_attach_adapter: attaching client failed.\n"); 
     420    printk("i2c-dev.o: Attaching client failed.\n"); 
    285421    kfree(client); 
    286422    return res; 
    287423  } 
    288424  i2cdev_clients[i] = client; 
    289   printk("i2cdev: registered '%s' as minor %d\n",adap->name,i); 
     425  printk("i2cdev.o: Registered '%s' as minor %d\n",adap->name,i); 
    290426  return 0; 
    291427} 
     
    297433 
    298434  if ((i = i2c_adapter_id(adap)) < 0) { 
    299     printk("i2cdev_detach_adapter: unknown adapter?!?\n"); 
     435    printk("i2c-dev.o: Detaching unknown adapter?!?\n"); 
    300436    return -ENODEV; 
    301437  } 
    302438  if (i >= I2CDEV_CLIENTS_MAX) { 
    303     printk("i2cdev_detach_adapter: adapter number too large?!? (%d)\n",i); 
     439    printk("i2c-dev.o: Adapter number to detach too large?!? (%d)\n",i); 
    304440    return -ENODEV; 
    305441  } 
    306442  if (!i2cdev_clients[i]) { 
    307     printk("i2cdev_detach_adapter: adapter not in use?!? (%d)\n",i); 
     443    printk("i2c-dev.o: Adapter to detach not in use?!? (%d)\n",i); 
    308444    return -ENODEV; 
    309445  } 
    310446 
    311447  if ((res =  i2c_detach_client(client))) { 
    312     printk("i2cdev_detach_adapter: detaching client failed.\n"); 
     448    printk("i2c-dev.o: detaching client %d failed.\n",i); 
    313449    return res; 
    314450  } 
     
    318454 
    319455#ifdef DEBUG 
    320   printk("i2c(char): adapter unregistered: %s\n",adap->name); 
     456  printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name); 
    321457#endif 
    322458  return 0; 
  • lm-sensors/trunk/src/i2c-dev.h

    r159 r160  
    2424#ifdef LM_SENSORS 
    2525#include "i2c.h" 
     26#include "smbus.h" 
    2627#else /* ndef LM_SENSORS */ 
    2728#include <linux/i2c.h> 
     29#include <linux/smbus.h> 
    2830#endif /* def LM_SENSORS */ 
    2931 
     
    3537/* This is the structure as used in the I2C_SMBUS ioctl call */ 
    3638struct i2c_smbus_data { 
    37   char read_write, 
    38   u8 command, 
    39   int size, 
    40   union smbus_data data 
     39  char read_write; 
     40  u8 command; 
     41  int size; 
     42  union smbus_data *data; 
    4143}; 
     44 
     45#ifndef __KERNEL__ 
     46 
     47#include <linux/ioctl.h> 
    4248 
    4349extern inline s32 i2c_smbus_access(int file, char read_write, u8 command,  
     
    5056  args.command = command; 
    5157  args.size = size; 
    52   if (data) 
    53     memcpy(&args.data,data,sizeof(union smbus_data)); 
    54   res = ioctl(f,I2C_SMBUS,&args); 
    55   if (data) 
    56     memcpy(data,&args,sizeof(union smbus_data)); 
    57   return res; 
     58  args.data = data; 
     59  return ioctl(file,I2C_SMBUS,&args); 
    5860} 
    5961 
     
    148150} 
    149151 
     152#endif /* ndef __KERNEL__ */ 
     153 
    150154#endif