root/lm-sensors/trunk/kernel/busses/i2c-isa.c @ 12

Revision 12, 5.4 KB (checked in by frodo, 15 years ago)

isa module added, some bugfixes

'isa.o' is roughly what was called 'sensor.o' in doc/design.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    isa.c - 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/* This implements an i2c algorithm/adapter for ISA bus. Not that this is
21   on first sight very useful; almost no functionality is preserved.
22   Except that it makes writing drivers for chips which can be on both
23   the SMBus and the ISA bus very much easier. See lm78.c for an example
24   of this. */
25
26#include <linux/module.h>
27#include <linux/kernel.h>
28
29#include "i2c.h"
30#ifdef SPINLOCK
31#include <asm/spinlock.h>
32#else
33#include <asm/semaphore.h>
34#endif
35
36#include "version.h"
37#include "isa.h"
38
39static int isa_master_xfer (struct isa_adapter *adap,
40                            struct i2c_msg msgs[], int num);
41static int isa_slave_send (struct isa_adapter *adap, char *data, int len);
42static int isa_slave_recv (struct isa_adapter *adap, char *data, int len);
43static int isa_algo_control (struct isa_adapter *adap, unsigned int cmd,
44                             unsigned long arg);
45static int isa_client_register (struct isa_client *client);
46static int isa_client_unregister (struct isa_client *client);
47
48static int isa_init(void);
49static int isa_cleanup(void);
50
51#ifdef MODULE
52extern int init_module(void);
53extern int cleanup_module(void);
54#endif /* MODULE */
55
56/* This is the actual algorithm we define */
57static struct isa_algorithm isa_algorithm = {
58  /* name */            "ISA bus adapter",
59  /* id */              ALGO_ISA,
60  /* master_xfer */     &isa_master_xfer,
61  /* slave_send */      &isa_slave_send,
62  /* slave_rcv */       &isa_slave_recv,
63  /* algo_control */    &isa_algo_control,
64  /* client_register */ &isa_client_register,
65  /* client_unregister*/&isa_client_unregister
66};
67
68/* There can only be one... */
69static struct isa_adapter isa_adapter;
70
71/* Used in isa_init/cleanup */
72static int isa_initialized;
73
74/* Algorithm master_xfer call-back implementation. Can't do that... */
75int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[],
76                     int num)
77{
78  printk("isa_master_xfer called for adapter `%s' "
79         "(no i2c level access possible!)\n",
80         adap->name);
81  return 0;
82}
83
84/* Algorithm slave_send call-back implementation. Can't do that... */
85int isa_slave_send (struct isa_adapter *adap, char *data, int len)
86{
87  printk("isa_slave_send called for adapter `%s' "
88         "(no i2c level access possible!)\n",
89         adap->name);
90  return 0;
91}
92
93/* Algorithm slave_recv call-back implementation. Can't do that... */
94int isa_slave_recv (struct isa_adapter *adap, char *data, int len)
95{
96  printk("isa_slave_recv called for adapter `%s' "
97         "(no i2c level access possible!)\n",
98         adap->name);
99  return 0;
100}
101
102/* Here we can put additional calls to modify the workings of the algorithm.
103   But right now, there is no need for that. */
104int isa_algo_control (struct isa_adapter *adap, unsigned int cmd,
105                       unsigned long arg)
106{
107  return 0;
108}
109
110/* Ehm... This is called when a client is registered to an adapter. We could
111   do all kinds of neat stuff here like, ehm - returning success? */
112int isa_client_register (struct isa_client *client)
113{
114  return 0;
115}
116
117int isa_client_unregister (struct isa_client *client)
118{
119  return 0;
120}
121
122int isa_init(void)
123{
124  int res;
125  printk("isa.o version %s (%s)\n",LM_VERSION,LM_DATE);
126#ifdef DEBUG
127  if (isa_initialized) {
128    printk("isa.o: Oops, isa_init called a second time!\n");
129    return -EBUSY;
130  }
131#endif
132  isa_initialized = 0;
133  if ((res = isa_add_algorithm(&isa_algorithm))) {
134    printk("isa.o: Algorithm registration failed, module isa.o not inserted\n");
135    isa_cleanup();
136    return res;
137  }
138  isa_initialized++;
139  strcpy(isa_adapter.name,"ISA main adapter");
140  isa_adapter.id = ALGO_ISA | ISA_MAIN;
141  isa_adapter.algo = &isa_algorithm;
142  if ((res = isa_add_adapter(&isa_adapter))) {
143    printk("isa.o: Adapter registration failed, "
144           "module isa.o is not inserted\n");
145    isa_cleanup();
146    return res;
147  }
148  isa_initialized++;
149  printk("isa.o: ISA bus access for i2c modules initialized\n");
150  return 0;
151}
152
153int isa_cleanup(void)
154{
155  int res;
156  if (isa_initialized >= 2)
157  {
158    if ((res = isa_del_adapter(&isa_adapter))) {
159      printk("isa.o: isa_del_adapter failed, module not removed\n");
160      return res;
161    } else
162      isa_initialized--;
163  }
164  if (isa_initialized >= 1)
165  {
166    if ((res = isa_del_algorithm(&isa_algorithm))) {
167      printk("isa.o: isa_del_algorithm failed, module not removed\n");
168      return res;
169    } else
170      isa_initialized--;
171  }
172  return 0;
173}
174
175#ifdef MODULE
176
177MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
178MODULE_DESCRIPTION("ISA bus access through i2c");
179
180int init_module(void)
181{
182  return isa_init();
183}
184
185int cleanup_module(void)
186{
187  return isa_cleanup();
188}
189
190#endif /* MODULE */
191
Note: See TracBrowser for help on using the browser.