root/lm-sensors/trunk/i2c/bit-lp.c @ 430

Revision 430, 4.9 KB (checked in by frodo, 15 years ago)

Geert's PPC support and Hydra driver

  • Property svn:eol-style set to native
Line 
1/* ------------------------------------------------------------------------- */
2/* bit-lp.c i2c-hw access for philips style parallel port adapters           */
3/* ------------------------------------------------------------------------- */
4/*   Copyright (C) 1995-97 Simon G. Vogl
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
19/* ------------------------------------------------------------------------- */
20static char rcsid[] = "$Id: bit-lp.c,v 1.6 1998/12/30 08:36:08 i2c Exp i2c $";
21/* ------------------------------------------------------------------------- */
22
23#include <linux/kernel.h>
24#include <linux/ioport.h>
25#include <linux/module.h>
26#include <asm/io.h>
27#include <linux/stddef.h>
28
29#include "i2c.h"
30#include "algo-bit.h"
31
32#define DEFAULT_BASE 0x378
33int base=0;
34
35/* Note: all we need to know is the base address of the parallel port, so
36 * instead of having a dedicated struct to store this value, we store this
37 * int in the pointer field (=bit_lp_ops.data) itself.
38 */
39
40/* Note2: as the hw that implements the i2c bus on the parallel port is
41 * incompatible with other epp stuff etc., we access the port exclusively
42 * and don't cooperate with parport functions.
43 */
44
45/* ----- global defines ----------------------------------------------- */
46#define DEB(x)          /* should be reasonable open, close &c.         */
47#define DEB2(x)         /* low level debugging - very slow              */
48#define DEBE(x) x       /* error messages                               */
49
50/* ----- printer port defines ------------------------------------------*/
51                                        /* Pin Port  Inverted   name    */
52#define I2C_ON          0x20            /* 12 status N  paper           */
53                                        /* ... only for phil. not used  */
54#define I2C_SDA         0x80            /*  9 data   N  data7           */
55#define I2C_SCL         0x08            /* 17 ctrl   N  dsel            */
56
57#define I2C_SDAIN       0x80            /* 11 stat   Y  busy            */
58#define I2C_SCLIN       0x08            /* 15 stat   Y  enable          */
59
60#define I2C_DMASK       0x7f
61#define I2C_CMASK       0xf7
62
63/* --- Convenience defines for the parallel port:                       */
64#define BASE    (unsigned int)(data)
65#define DATA    BASE                    /* Centronics data port         */
66#define STAT    (BASE+1)                /* Centronics status port       */
67#define CTRL    (BASE+2)                /* Centronics control port      */
68
69/* ----- local functions ---------------------------------------------- */
70
71void bit_lp_setscl(void *data, int state)
72{
73        /*be cautious about state of the control register -
74                touch only the one bit needed*/
75        if (state) {
76                outb(inb(CTRL)|I2C_SCL,   CTRL);
77        } else {
78                outb(inb(CTRL)&I2C_CMASK, CTRL);
79        }
80}
81
82void bit_lp_setsda(void *data, int state)
83{
84        if (state) {
85                outb(I2C_DMASK , DATA);
86        } else {
87                outb(I2C_SDA , DATA);
88        }
89}
90
91int bit_lp_getscl(void *data)
92{
93        return ( 0 != ( (inb(STAT)) & I2C_SCLIN ) );
94}
95
96int bit_lp_getsda(void *data)
97{
98        return ( 0 != ( (inb(STAT)) & I2C_SDAIN ) );
99}
100
101int bit_lp_init(void)
102{
103        if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
104                return -ENODEV;
105        } else {
106                request_region(base,(base == 0x3bc)? 3 : 8,
107                        "i2c (parallel port adapter)");
108                /* reset hardware to sane state */
109                bit_lp_setsda((void*)base,1);
110                bit_lp_setscl((void*)base,1);
111        }
112        return 0;
113}
114
115void bit_lp_exit(void)
116{
117        release_region( base , (base == 0x3bc)? 3 : 8 );
118}
119
120int bit_lp_reg(struct i2c_client *client)
121{
122        return 0;
123}
124
125int bit_lp_unreg(struct i2c_client *client)
126{
127        return 0;
128}
129
130/* ------------------------------------------------------------------------
131 * Encapsulate the above functions in the correct operations structure.
132 * This is only done when more than one hardware adapter is supported.
133 */
134struct bit_adapter bit_lp_ops = {
135        "Philips Parallel port adapter",
136        HW_B_LP,
137        NULL,
138        bit_lp_setsda,
139        bit_lp_setscl,
140        bit_lp_getsda,
141        bit_lp_getscl,
142        bit_lp_reg,
143        bit_lp_unreg,
144        80, 80, 100,            /*      waits, timeout */
145};
146
147#ifdef MODULE
148MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
149MODULE_DESCRIPTION("I2C-Bus adapter routines for Philips parallel port adapter");
150
151MODULE_PARM(base, "i");
152
153#ifndef LM_SENSORS
154EXPORT_NO_SYMBOLS;
155#endif
156
157int init_module(void) 
158{
159        if (base==0) {
160                /* probe some values */
161                base=DEFAULT_BASE;
162                bit_lp_ops.data=(void*)DEFAULT_BASE;
163                if (bit_lp_init()==0) {
164                        i2c_bit_add_bus(&bit_lp_ops);
165                } else {
166                        return -ENODEV;
167                }
168        } else {
169                bit_lp_ops.data=(void*)base;
170                if (bit_lp_init()==0) {
171                        i2c_bit_add_bus(&bit_lp_ops);
172                } else {
173                        return -ENODEV;
174                }
175        }
176        printk("bit_lp: found device at %#x.\n",base);
177        return 0;
178}
179
180void cleanup_module(void) 
181{
182        i2c_bit_del_bus(&bit_lp_ops);
183        bit_lp_exit();
184}
185
186#endif
187
188
189
Note: See TracBrowser for help on using the browser.