| 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 | #ifdef __KERNEL__ |
|---|
| 24 | |
|---|
| 25 | /* This file must interface with Simon Vogl's i2c driver. Version 19981006 is |
|---|
| 26 | OK, earlier versions are not; later versions will probably give problems |
|---|
| 27 | too. |
|---|
| 28 | */ |
|---|
| 29 | #include <asm/types.h> |
|---|
| 30 | |
|---|
| 31 | /* SPINLOCK is defined in i2c.h. */ |
|---|
| 32 | #ifdef SPINLOCK |
|---|
| 33 | #include <asm/spinlock.h> |
|---|
| 34 | #else |
|---|
| 35 | #include <asm/semaphore.h> |
|---|
| 36 | #endif |
|---|
| 37 | |
|---|
| 38 | #ifdef LM_SENSORS |
|---|
| 39 | #include "i2c.h" |
|---|
| 40 | #else /* ndef LM_SENSORS */ |
|---|
| 41 | #include <linux/i2c.h> |
|---|
| 42 | #endif /* def LM_SENSORS */ |
|---|
| 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 */ |
|---|
| 48 | struct isa_driver; |
|---|
| 49 | struct isa_client; |
|---|
| 50 | struct isa_algorithm; |
|---|
| 51 | struct 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. */ |
|---|
| 56 | struct 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. */ |
|---|
| 70 | struct 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. */ |
|---|
| 86 | struct 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. */ |
|---|
| 102 | struct 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 | |
|---|
| 121 | /* Detect whether we are on the isa bus. If this returns true, all i2c |
|---|
| 122 | access will fail! */ |
|---|
| 123 | #define i2c_is_isa_client(clientptr) \ |
|---|
| 124 | ((clientptr)->adapter->algo->id == ALGO_ISA) |
|---|
| 125 | #define i2c_is_isa_adapter(adapptr) \ |
|---|
| 126 | ((adapptr)->algo->id == ALGO_ISA) |
|---|
| 127 | |
|---|
| 128 | /* Next: define ISA variants of registering. */ |
|---|
| 129 | #define isa_add_algorithm(algoptr) \ |
|---|
| 130 | i2c_add_algorithm((struct i2c_algorithm *) (algoptr)) |
|---|
| 131 | #define isa_del_algorithm(algoptr) \ |
|---|
| 132 | i2c_del_algorithm((struct i2c_algorithm *) (algoptr)) |
|---|
| 133 | |
|---|
| 134 | #define isa_add_adapter(adapptr) \ |
|---|
| 135 | i2c_add_adapter((struct i2c_adapter *) (adapptr)) |
|---|
| 136 | #define isa_del_adapter(adapptr) \ |
|---|
| 137 | i2c_del_adapter((struct i2c_adapter *) (adapptr)) |
|---|
| 138 | |
|---|
| 139 | #define isa_add_driver(driverptr) \ |
|---|
| 140 | i2c_add_driver((struct i2c_driver *) (driverptr)) |
|---|
| 141 | #define isa_del_driver(driverptr) \ |
|---|
| 142 | i2c_add_driver((struct i2c_driver *) (driverptr)) |
|---|
| 143 | |
|---|
| 144 | #define isa_attach_client(clientptr) \ |
|---|
| 145 | i2c_attach_client((struct i2c_client *) (clientptr)) |
|---|
| 146 | #define isa_detach_client(clientptr) \ |
|---|
| 147 | i2c_detach_client((struct i2c_client *) (clientptr)) |
|---|
| 148 | |
|---|
| 149 | #endif /* def __KERNEL__ */ |
|---|
| 150 | |
|---|
| 151 | /* We need to mark ISA algorithms in the algorithm structure. */ |
|---|
| 152 | #define ALGO_ISA 0x50000 |
|---|
| 153 | |
|---|
| 154 | /* ISA Adapter ids */ |
|---|
| 155 | #define ISA_MAIN 1 |
|---|
| 156 | |
|---|
| 157 | #endif /* ndef SENSORS_ISA_H */ |
|---|