root/lm-sensors/trunk/kernel/include/i2c-isa.h @ 13

Revision 13, 4.9 KB (checked in by frodo, 14 years ago)

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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    isa.h - A Linux module for reading sensor data.
3    Copyright (c) 1998  Frodo Looijaard <frodol@dds.nl>
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#ifndef SENSORS_SENSOR_H
21#define SENSORS_SENSOR_H
22
23/* This file must interface with Simon Vogl's i2c driver. Version 19981006 is
24   OK, earlier versions are not; later versions will probably give problems
25   too.
26*/
27#ifdef I2C
28#include "i2c/i2c.h"
29#else /* def I2C */
30#include <linux/i2c.h>
31#endif /* def I2C */
32
33#include <asm/types.h>
34
35/* SPINLOCK is defined in i2c.h. */
36#ifdef SPINLOCK
37#include <asm/spinlock.h>
38#else
39#include <asm/semaphore.h>
40#endif
41
42#include "isa.h"
43
44/* Note that this driver is *not* built upon smbus.c, but is parallel to it.
45   We do not need SMBus facilities if we are on the ISA bus, after all */
46
47/* Declarations, to keep the compiler happy */
48struct isa_driver;
49struct isa_client;
50struct isa_algorithm;
51struct isa_adapter;
52
53/* A driver tells us how we should handle a specific kind of chip.
54   A specific instance of such a chip is called a client. 
55   This structure is essentially the same as i2c_driver. */
56struct isa_driver {
57  char name[32];
58  int id;
59  unsigned int flags;
60  int (* attach_adapter) (struct isa_adapter *);
61  int (* detach_client) (struct isa_client *);
62  int (* command) (struct isa_client *, unsigned int cmd, void *arg);
63  void (* inc_use) (struct isa_client *);
64  void (* dec_use) (struct isa_client *);
65};
66
67/* A client is a specifc instance of a chip: for each detected chip, there will
68   be a client. Its operation is controlled by a driver.
69   This structure is an extension of i2c_client. */
70struct isa_client {
71  char name[32];
72  int id;
73  unsigned int flags;
74  unsigned char addr;
75  struct isa_adapter *adapter;
76  struct isa_driver *driver;
77  void *data;
78
79  /* Here ended i2c_client */
80  unsigned int isa_addr;
81};
82
83/* An algorithm describes how a certain class of busses can be accessed.
84   A specific instance of sucj a bus is called an adapter.
85   This structure is essentially the same as i2c_adapter. */
86struct isa_algorithm {
87  char name[32];
88  unsigned int id;
89  int (* master_xfer) (struct isa_adapter *adap, struct i2c_msg msgs[],
90                       int num);
91  int (* slave_send) (struct isa_adapter *,char *, int);
92  int (* slave_recv) (struct isa_adapter *,char *, int);
93  int (* algo_control) (struct isa_adapter *, unsigned int, unsigned long);
94  int (* client_register) (struct isa_client *);
95  int (* client_unregister) (struct isa_client *);
96};
97
98/* An adapter is a specifc instance of a bus: for each detected bus, there will
99   be an adapter. Its operation is controlled by an algorithm.
100   SPINLOCK must be the same as declared in i2c.h.
101   This structure is essentially the same as i2c_algorithm. */
102struct isa_adapter {
103  char name[32];
104  unsigned int id;
105  struct isa_algorithm *algo;
106  void *data;
107#ifdef SPINLOCK
108  spinlock_t lock;
109  unsigned long lockflags;
110#else
111  struct semaphore lock;
112#endif
113  unsigned int flags;
114  struct isa_client *clients[I2C_CLIENT_MAX];
115  int client_count;
116  int timeout;
117  int retries;
118};
119
120/* We need to mark ISA algorithms in the algorithm structure. */
121#define ALGO_ISA 0x50000
122
123/* ISA Adapter ids */
124#define ISA_MAIN 1
125
126/* Detect whether we are on the isa bus. If this returns true, all i2c
127  access will fail! */
128#define i2c_is_isa_client(clientptr) \
129        ((clientptr)->adapter->algo->id == ALGO_ISA)
130#define i2c_is_isa_adapter(adapptr) \
131        ((adapptr)->algo->id == ALGO_ISA)
132
133/* Next: define ISA variants of registering. */
134#define isa_add_algorithm(algoptr) \
135        i2c_add_algorithm((struct i2c_algorithm *) (algoptr))
136#define isa_del_algorithm(algoptr) \
137        i2c_del_algorithm((struct i2c_algorithm *) (algoptr))
138
139#define isa_add_adapter(adapptr) \
140        i2c_add_adapter((struct i2c_adapter *) (adapptr))
141#define isa_del_adapter(adapptr) \
142        i2c_del_adapter((struct i2c_adapter *) (adapptr))
143
144#define isa_add_driver(driverptr) \
145        i2c_add_driver((struct i2c_driver *) (driverptr))
146#define isa_del_driver(driverptr) \
147        i2c_add_driver((struct i2c_driver *) (driverptr))
148
149#define isa_attach_client(clientptr) \
150        i2c_attach_client((struct i2c_client *) (clientptr))
151#define isa_detach_client(clientptr) \
152        i2c_detach_client((struct i2c_client *) (clientptr))
153
154
155#endif /* ndef SENSORS_ISA_H */
Note: See TracBrowser for help on using the browser.