Changeset 13

Show
Ignore:
Timestamp:
11/26/98 11:16:08 (15 years ago)
Author:
frodo
Message:

Example lm_sensors-2 driver

Though it is called the LM78 driver, there is not too much LM78 specific
code in it; it can better be seen as an example code skeleton for other
drivers. Right now, it creats a file /proc/sensors-test, which contains
a list of busses it registered itself on. Stupid, but very useful for
testing purposes!

You need a 2.0 kernel for lm78.o to insert (or hack the /proc system
specific parts; see lm78.c of lm_sensors version 1 how to do this).
Other parts of lm_sensors-2 are not tested for 2.1 kernels either, but
I am certain it won't work in this case :-).

See the TODO list to get some idea what is left to do, choose something
and implement it. Or not :-). But please, send a note to the mailing
list when you start on something, to avoid duplicate work...

Other notable changes:

the smbus_access routines now use (the more logical) i2c_adapter
structure, instead of smbus_adapter.

Location:
lm-sensors/trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/TODO

    r8 r13  
    11Many, many things. Most notably: 
    22 
    3 * Write s32 smbus_access_i2c in smbus.c 
    4 * Check out whether we can use the dev interface for smbus (like i2c) 
    5 * Write all other modules 
     3* Write smbus_access_i2c in smbus.c 
     4* Write piix4_* in piix4.c 
     5* Complete lm78 driver 
     6* Extend dev interface for SMBus 
     7* Create entries in /proc/bus: a list of all registered busses, and for 
     8  each bus, a file with registered clients. 
     9* Write all other drivers 
     10* How to make drivers detect thing *not*; for example, if a Winbond is  
     11  present, the LM75 driver should not try to access its simulated 
     12  LM75 chips! 
     13* Write a userland-library for SMBus/i2c access (through the /dev interface) 
     14* Write a userland detection program for busses (clients are less important; 
     15  but perhaps needed too). 
     16* Bring doc/design up-to-date (it is horribly out of date right now) 
  • lm-sensors/trunk/kernel/Module.mk

    r12 r13  
    2323# Regrettably, even 'simply expanded variables' will not put their currently 
    2424# defined value verbatim into the command-list of rules... 
    25 SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o $(MODULE_DIR)/isa.o 
     25SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o $(MODULE_DIR)/isa.o \ 
     26              $(MODULE_DIR)/lm78.o 
    2627 
    2728# Include all dependency files 
  • lm-sensors/trunk/kernel/busses/i2c-piix4.c

    r11 r13  
    5050{ 
    5151  /* TO BE WRITTEN! */ 
     52  return -1; 
    5253} 
    5354 
     
    9091  { 
    9192    if ((res = smbus_del_adapter(&piix4_adapter))) { 
    92       printk("piix4.o: smbus_del_adapter failed, module not removed"); 
     93      printk("piix4.o: smbus_del_adapter failed, module not removed\n"); 
    9394      return res; 
    94     } 
    95     else 
     95    } else 
    9696      piix4_initialized--; 
    9797  } 
  • lm-sensors/trunk/kernel/include/i2c-isa.h

    r12 r13  
    7878 
    7979  /* Here ended i2c_client */ 
    80   unsigned int full_address; 
     80  unsigned int isa_addr; 
    8181}; 
    8282 
     
    128128#define i2c_is_isa_client(clientptr) \ 
    129129        ((clientptr)->adapter->algo->id == ALGO_ISA) 
     130#define i2c_is_isa_adapter(adapptr) \ 
     131        ((adapptr)->algo->id == ALGO_ISA) 
    130132 
    131133/* Next: define ISA variants of registering. */ 
  • lm-sensors/trunk/kernel/include/isa.h

    r12 r13  
    7878 
    7979  /* Here ended i2c_client */ 
    80   unsigned int full_address; 
     80  unsigned int isa_addr; 
    8181}; 
    8282 
     
    128128#define i2c_is_isa_client(clientptr) \ 
    129129        ((clientptr)->adapter->algo->id == ALGO_ISA) 
     130#define i2c_is_isa_adapter(adapptr) \ 
     131        ((adapptr)->algo->id == ALGO_ISA) 
    130132 
    131133/* Next: define ISA variants of registering. */ 
  • lm-sensors/trunk/kernel/include/smbus.h

    r12 r13  
    131131#define i2c_is_smbus_client(clientptr) \ 
    132132        ((clientptr)->adapter->algo->id == ALGO_SMBUS) 
     133#define i2c_is_smbus_adapter(adapptr) \ 
     134        ((adapptr)->algo->id == ALGO_SMBUS) 
    133135 
    134136/* This union is used within smbus_access routines */ 
     
    158160/* This is the very generalized SMBus access routine. You probably do not 
    159161   want to use this, though; one of the functions below may be much easier, 
    160    and probably just as fast. */ 
    161 extern s32 smbus_access (struct smbus_adapter * adapter, u8 addr,  
     162   and probably just as fast.  
     163   Note that we use i2c_adapter here, because you do not need a specific 
     164   smbus adapter to call this function. */ 
     165extern s32 smbus_access (struct i2c_adapter * adapter, u8 addr,  
    162166                         char read_write, u8 command, int size, 
    163167                         union smbus_data * data); 
     
    166170   conventions of smbus_access. */ 
    167171 
    168 extern inline s32 smbus_write_quick(struct smbus_adapter * adapter, u8 addr,  
     172extern inline s32 smbus_write_quick(struct i2c_adapter * adapter, u8 addr,  
    169173                                    u8 value) 
    170174{ 
     
    172176} 
    173177 
    174 extern inline s32 smbus_read_byte(struct smbus_adapter * adapter,u8 addr) 
     178extern inline s32 smbus_read_byte(struct i2c_adapter * adapter,u8 addr) 
    175179{ 
    176180  union smbus_data data; 
     
    181185} 
    182186 
    183 extern inline s32 smbus_write_byte(struct smbus_adapter * adapter, u8 addr,  
     187extern inline s32 smbus_write_byte(struct i2c_adapter * adapter, u8 addr,  
    184188                                   u8 value) 
    185189{ 
     
    187191} 
    188192 
    189 extern inline s32 smbus_read_byte_data(struct smbus_adapter * adapter, 
     193extern inline s32 smbus_read_byte_data(struct i2c_adapter * adapter, 
    190194                                       u8 addr, u8 command) 
    191195{ 
     
    197201} 
    198202 
    199 extern inline s32 smbus_write_byte_data(struct smbus_adapter * adapter, 
     203extern inline s32 smbus_write_byte_data(struct i2c_adapter * adapter, 
    200204                                        u8 addr, u8 command, u8 value) 
    201205{ 
     
    205209} 
    206210 
    207 extern inline s32 smbus_read_word_data(struct smbus_adapter * adapter, 
     211extern inline s32 smbus_read_word_data(struct i2c_adapter * adapter, 
    208212                                       u8 addr, u8 command) 
    209213{ 
     
    215219} 
    216220 
    217 extern inline s32 smbus_write_word_data(struct smbus_adapter * adapter, 
     221extern inline s32 smbus_write_word_data(struct i2c_adapter * adapter, 
    218222                                        u8 addr, u8 command, u16 value) 
    219223{ 
     
    223227} 
    224228 
    225 extern inline s32 smbus_process_call(struct smbus_adapter * adapter, 
     229extern inline s32 smbus_process_call(struct i2c_adapter * adapter, 
    226230                                     u8 addr, u8 command, u16 value) 
    227231{ 
     
    235239 
    236240/* Returns the number of read bytes */ 
    237 extern inline s32 smbus_read_block_data(struct smbus_adapter * adapter, 
     241extern inline s32 smbus_read_block_data(struct i2c_adapter * adapter, 
    238242                                        u8 addr, u8 command, u8 *values) 
    239243{ 
     
    249253} 
    250254 
    251 extern inline int smbus_write_block_data(struct smbus_adapter * adapter, 
     255extern inline int smbus_write_block_data(struct i2c_adapter * adapter, 
    252256                                         u8 addr, u8 command, u8 length, 
    253257                                         u8 *values) 
  • lm-sensors/trunk/kernel/smbus.c

    r12 r13  
    3131#include "smbus.h" 
    3232 
    33 static s32 smbus_access_i2c (struct smbus_adapter * adapter, u8 addr, 
     33static s32 smbus_access_i2c (struct i2c_adapter * adapter, u8 addr, 
    3434                             char read_write, u8 command, int size, 
    3535                             union smbus_data * data); 
     
    7070   We do all locking here, so you can ignore that in the adapter-specific 
    7171   smbus_accesss routine. */ 
    72 s32 smbus_access (struct smbus_adapter * adapter, u8 addr, char read_write, 
     72s32 smbus_access (struct i2c_adapter * adapter, u8 addr, char read_write, 
    7373                  u8 command, int size, union smbus_data * data) 
    7474{ 
     
    8080#endif 
    8181  if (adapter->id & ALGO_SMBUS)  
    82     res = adapter->smbus_access(addr,read_write,command,size,data); 
     82    res = ((struct smbus_adapter *) adapter) ->  
     83           smbus_access(addr,read_write,command,size,data); 
    8384  else 
    8485    res = smbus_access_i2c(adapter,addr,read_write,command,size,data); 
     
    9697   For SMBUS_BYTE: Use addr, read_write, command  
    9798   ....  */ 
    98 s32 smbus_access_i2c(struct smbus_adapter * adapter, u8 addr, char read_write, 
     99s32 smbus_access_i2c(struct i2c_adapter * adapter, u8 addr, char read_write, 
    99100                     u8 command, int size, union smbus_data * data) 
    100101{ 
  • lm-sensors/trunk/src/Module.mk

    r12 r13  
    2323# Regrettably, even 'simply expanded variables' will not put their currently 
    2424# defined value verbatim into the command-list of rules... 
    25 SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o $(MODULE_DIR)/isa.o 
     25SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o $(MODULE_DIR)/isa.o \ 
     26              $(MODULE_DIR)/lm78.o 
    2627 
    2728# Include all dependency files 
  • lm-sensors/trunk/src/isa.h

    r12 r13  
    7878 
    7979  /* Here ended i2c_client */ 
    80   unsigned int full_address; 
     80  unsigned int isa_addr; 
    8181}; 
    8282 
     
    128128#define i2c_is_isa_client(clientptr) \ 
    129129        ((clientptr)->adapter->algo->id == ALGO_ISA) 
     130#define i2c_is_isa_adapter(adapptr) \ 
     131        ((adapptr)->algo->id == ALGO_ISA) 
    130132 
    131133/* Next: define ISA variants of registering. */ 
  • lm-sensors/trunk/src/piix4.c

    r11 r13  
    5050{ 
    5151  /* TO BE WRITTEN! */ 
     52  return -1; 
    5253} 
    5354 
     
    9091  { 
    9192    if ((res = smbus_del_adapter(&piix4_adapter))) { 
    92       printk("piix4.o: smbus_del_adapter failed, module not removed"); 
     93      printk("piix4.o: smbus_del_adapter failed, module not removed\n"); 
    9394      return res; 
    94     } 
    95     else 
     95    } else 
    9696      piix4_initialized--; 
    9797  } 
  • lm-sensors/trunk/src/smbus.c

    r12 r13  
    3131#include "smbus.h" 
    3232 
    33 static s32 smbus_access_i2c (struct smbus_adapter * adapter, u8 addr, 
     33static s32 smbus_access_i2c (struct i2c_adapter * adapter, u8 addr, 
    3434                             char read_write, u8 command, int size, 
    3535                             union smbus_data * data); 
     
    7070   We do all locking here, so you can ignore that in the adapter-specific 
    7171   smbus_accesss routine. */ 
    72 s32 smbus_access (struct smbus_adapter * adapter, u8 addr, char read_write, 
     72s32 smbus_access (struct i2c_adapter * adapter, u8 addr, char read_write, 
    7373                  u8 command, int size, union smbus_data * data) 
    7474{ 
     
    8080#endif 
    8181  if (adapter->id & ALGO_SMBUS)  
    82     res = adapter->smbus_access(addr,read_write,command,size,data); 
     82    res = ((struct smbus_adapter *) adapter) ->  
     83           smbus_access(addr,read_write,command,size,data); 
    8384  else 
    8485    res = smbus_access_i2c(adapter,addr,read_write,command,size,data); 
     
    9697   For SMBUS_BYTE: Use addr, read_write, command  
    9798   ....  */ 
    98 s32 smbus_access_i2c(struct smbus_adapter * adapter, u8 addr, char read_write, 
     99s32 smbus_access_i2c(struct i2c_adapter * adapter, u8 addr, char read_write, 
    99100                     u8 command, int size, union smbus_data * data) 
    100101{ 
  • lm-sensors/trunk/src/smbus.h

    r12 r13  
    131131#define i2c_is_smbus_client(clientptr) \ 
    132132        ((clientptr)->adapter->algo->id == ALGO_SMBUS) 
     133#define i2c_is_smbus_adapter(adapptr) \ 
     134        ((adapptr)->algo->id == ALGO_SMBUS) 
    133135 
    134136/* This union is used within smbus_access routines */ 
     
    158160/* This is the very generalized SMBus access routine. You probably do not 
    159161   want to use this, though; one of the functions below may be much easier, 
    160    and probably just as fast. */ 
    161 extern s32 smbus_access (struct smbus_adapter * adapter, u8 addr,  
     162   and probably just as fast.  
     163   Note that we use i2c_adapter here, because you do not need a specific 
     164   smbus adapter to call this function. */ 
     165extern s32 smbus_access (struct i2c_adapter * adapter, u8 addr,  
    162166                         char read_write, u8 command, int size, 
    163167                         union smbus_data * data); 
     
    166170   conventions of smbus_access. */ 
    167171 
    168 extern inline s32 smbus_write_quick(struct smbus_adapter * adapter, u8 addr,  
     172extern inline s32 smbus_write_quick(struct i2c_adapter * adapter, u8 addr,  
    169173                                    u8 value) 
    170174{ 
     
    172176} 
    173177 
    174 extern inline s32 smbus_read_byte(struct smbus_adapter * adapter,u8 addr) 
     178extern inline s32 smbus_read_byte(struct i2c_adapter * adapter,u8 addr) 
    175179{ 
    176180  union smbus_data data; 
     
    181185} 
    182186 
    183 extern inline s32 smbus_write_byte(struct smbus_adapter * adapter, u8 addr,  
     187extern inline s32 smbus_write_byte(struct i2c_adapter * adapter, u8 addr,  
    184188                                   u8 value) 
    185189{ 
     
    187191} 
    188192 
    189 extern inline s32 smbus_read_byte_data(struct smbus_adapter * adapter, 
     193extern inline s32 smbus_read_byte_data(struct i2c_adapter * adapter, 
    190194                                       u8 addr, u8 command) 
    191195{ 
     
    197201} 
    198202 
    199 extern inline s32 smbus_write_byte_data(struct smbus_adapter * adapter, 
     203extern inline s32 smbus_write_byte_data(struct i2c_adapter * adapter, 
    200204                                        u8 addr, u8 command, u8 value) 
    201205{ 
     
    205209} 
    206210 
    207 extern inline s32 smbus_read_word_data(struct smbus_adapter * adapter, 
     211extern inline s32 smbus_read_word_data(struct i2c_adapter * adapter, 
    208212                                       u8 addr, u8 command) 
    209213{ 
     
    215219} 
    216220 
    217 extern inline s32 smbus_write_word_data(struct smbus_adapter * adapter, 
     221extern inline s32 smbus_write_word_data(struct i2c_adapter * adapter, 
    218222                                        u8 addr, u8 command, u16 value) 
    219223{ 
     
    223227} 
    224228 
    225 extern inline s32 smbus_process_call(struct smbus_adapter * adapter, 
     229extern inline s32 smbus_process_call(struct i2c_adapter * adapter, 
    226230                                     u8 addr, u8 command, u16 value) 
    227231{ 
     
    235239 
    236240/* Returns the number of read bytes */ 
    237 extern inline s32 smbus_read_block_data(struct smbus_adapter * adapter, 
     241extern inline s32 smbus_read_block_data(struct i2c_adapter * adapter, 
    238242                                        u8 addr, u8 command, u8 *values) 
    239243{ 
     
    249253} 
    250254 
    251 extern inline int smbus_write_block_data(struct smbus_adapter * adapter, 
     255extern inline int smbus_write_block_data(struct i2c_adapter * adapter, 
    252256                                         u8 addr, u8 command, u8 length, 
    253257                                         u8 *values)