| 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 | /* ------------------------------------------------------------------------- */ |
|---|
| 20 | static char rcsid[] = "$Id: bit-lp-multi.c,v 1.1 1998/09/05 18:20:09 i2c Exp $"; |
|---|
| 21 | /* ------------------------------------------------------------------------- */ |
|---|
| 22 | |
|---|
| 23 | #include <linux/kernel.h> |
|---|
| 24 | #include <linux/delay.h> |
|---|
| 25 | #include <linux/ioport.h> |
|---|
| 26 | #include <linux/errno.h> |
|---|
| 27 | #include <linux/module.h> |
|---|
| 28 | #include <asm/io.h> |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | #include "i2c.h" |
|---|
| 32 | #include "algo-bit.h" |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | #define BIT_LP_MAX 3 /* max. number of addresses to probe */ |
|---|
| 36 | |
|---|
| 37 | struct bit_lp_data { |
|---|
| 38 | unsigned int base; /* base address */ |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | static struct bit_lp_data bit_lp_adaps[BIT_LP_MAX] = { |
|---|
| 42 | {0,}, |
|---|
| 43 | {0,}, |
|---|
| 44 | {0,}, |
|---|
| 45 | }; |
|---|
| 46 | static int adap_count=0; |
|---|
| 47 | |
|---|
| 48 | /* ----- global defines ----------------------------------------------- */ |
|---|
| 49 | #define DEB(x) /* should be reasonable open, close &c. */ |
|---|
| 50 | #define DEB2(x) /* low level debugging - very slow */ |
|---|
| 51 | #define DEBE(x) x /* error messages */ |
|---|
| 52 | |
|---|
| 53 | /* ----- printer port defines ------------------------------------------*/ |
|---|
| 54 | /* Pin Port Inverted name */ |
|---|
| 55 | #define I2C_ON 0x20 /* 12 status N paper */ |
|---|
| 56 | /* ... only for phil. not used */ |
|---|
| 57 | #define I2C_SDA 0x80 /* 9 data N data7 */ |
|---|
| 58 | #define I2C_SCL 0x08 /* 17 ctrl N dsel */ |
|---|
| 59 | |
|---|
| 60 | #define I2C_SDAIN 0x80 /* 11 stat Y busy */ |
|---|
| 61 | #define I2C_SCLIN 0x08 /* 15 stat Y enable */ |
|---|
| 62 | |
|---|
| 63 | #define I2C_DMASK 0x7f |
|---|
| 64 | #define I2C_CMASK 0xf7 |
|---|
| 65 | |
|---|
| 66 | /* --- Convenience defines for the parallel port: */ |
|---|
| 67 | #define BASE bit_lp_adaps[minor].base |
|---|
| 68 | #define DATA BASE /* Centronics data port */ |
|---|
| 69 | #define STAT (BASE+1) /* Centronics status port */ |
|---|
| 70 | #define CTRL (BASE+2) /* Centronics control port */ |
|---|
| 71 | |
|---|
| 72 | /* ----- local functions ---------------------------------------------- */ |
|---|
| 73 | |
|---|
| 74 | static void bit_lp_setscl(int minor, int state) |
|---|
| 75 | { |
|---|
| 76 | if (state) { |
|---|
| 77 | outb(I2C_SCL, CTRL); |
|---|
| 78 | } else { |
|---|
| 79 | outb(I2C_CMASK, CTRL); |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | static void bit_lp_setsda(int minor, int state) |
|---|
| 84 | { |
|---|
| 85 | if (state) { |
|---|
| 86 | outb(I2C_DMASK , DATA); |
|---|
| 87 | } else { |
|---|
| 88 | outb(I2C_SDA , DATA); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | static int bit_lp_getscl(int minor) |
|---|
| 93 | { |
|---|
| 94 | return ( 0 != ( (inb(STAT)) & I2C_SCLIN ) ); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | static int bit_lp_getsda(int minor) |
|---|
| 98 | { |
|---|
| 99 | return ( 0 != ( (inb(STAT)) & I2C_SDAIN ) ); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | static int bit_lp_init(int minor) |
|---|
| 103 | { |
|---|
| 104 | if (check_region(bit_lp_adaps[minor].base, |
|---|
| 105 | (bit_lp_adaps[minor].base == 0x3bc)? 3 : 8) < 0 ) { |
|---|
| 106 | return -ENODEV; |
|---|
| 107 | } else { |
|---|
| 108 | request_region(bit_lp_adaps[minor].base, |
|---|
| 109 | (bit_lp_adaps[minor].base == 0x3bc)? 3 : 8, |
|---|
| 110 | "i2c (parallel port adapter)"); |
|---|
| 111 | bit_lp_setsda(minor,1); |
|---|
| 112 | bit_lp_setscl(minor,1); |
|---|
| 113 | } |
|---|
| 114 | printk("i2c%d: scl: %d sda %d \n",minor,bit_lp_getscl(minor),bit_lp_getsda(minor)); |
|---|
| 115 | return 0; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | static void bit_lp_exit(int minor) |
|---|
| 119 | { |
|---|
| 120 | release_region( bit_lp_adaps[minor].base , |
|---|
| 121 | (bit_lp_adaps[minor].base == 0x3bc)? 3 : 8 ); |
|---|
| 122 | release_region( bit_lp_adaps[minor].base + 0x0400, 8 ); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | /* ------------------------------------------------------------------------ |
|---|
| 127 | * Encapsulate the above functions in the correct operations structure. |
|---|
| 128 | * This is only done when more than one hardware adapter is supported. |
|---|
| 129 | */ |
|---|
| 130 | struct bit_adapter bit_lp_ops = { |
|---|
| 131 | "Philips Parallel port adapter", |
|---|
| 132 | bit_lp_setscl, |
|---|
| 133 | bit_lp_setsda, |
|---|
| 134 | bit_lp_getscl, |
|---|
| 135 | bit_lp_getsda, |
|---|
| 136 | bit_lp_init, |
|---|
| 137 | bit_lp_exit |
|---|
| 138 | }; |
|---|
| 139 | |
|---|
| 140 | #ifdef MODULE |
|---|
| 141 | static int base[BIT_LP_MAX+1] = { [0 ... BIT_LP_MAX] = 0 }; |
|---|
| 142 | MODULE_PARM(base, "1-" __MODULE_STRING(BIT_LP_MAX) "i"); |
|---|
| 143 | |
|---|
| 144 | /* |
|---|
| 145 | EXPORT_SYMBOL(i2c_bit_add_bus); |
|---|
| 146 | EXPORT_SYMBOL(i2c_bit_del_bus); |
|---|
| 147 | */ |
|---|
| 148 | int init_module(void) |
|---|
| 149 | { |
|---|
| 150 | /* Work out how many ports we have, then get parport_share to parse |
|---|
| 151 | the irq values. */ |
|---|
| 152 | unsigned int i; |
|---|
| 153 | for (i = 0; i < BIT_LP_MAX && base[i]; i++) { |
|---|
| 154 | bit_lp_adaps[adap_count].base = base[i]; |
|---|
| 155 | if (bit_lp_init(adap_count)==0) { |
|---|
| 156 | /* i2c_bit_add_bus(struct bit_adapter *algo);*/ |
|---|
| 157 | /* bit_add_adapter();*/ |
|---|
| 158 | adap_count++; |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | if (i==0) { /* no values specified -> probe */ |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | /* count += probe_one_port(0x3bc, irq[0], dma[0]); |
|---|
| 165 | count += probe_one_port(0x378, irq[0], dma[0]); |
|---|
| 166 | count += probe_one_port(0x278, irq[0], dma[0]); |
|---|
| 167 | */ |
|---|
| 168 | printk("bit_lp: found %d devices.\n",adap_count); |
|---|
| 169 | |
|---|
| 170 | if (adap_count==0) |
|---|
| 171 | return -ENODEV; |
|---|
| 172 | else |
|---|
| 173 | return 0; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | void cleanup_module(void) |
|---|
| 177 | { |
|---|
| 178 | int i; |
|---|
| 179 | for (i=0;i<adap_count;i++) { |
|---|
| 180 | int i2c_bit_del_bus(struct bit_adapter *algo); |
|---|
| 181 | bit_lp_exit(i); |
|---|
| 182 | } |
|---|
| 183 | /* i2c_del_algorithm(&alg_bit_opns);*/ |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | #endif |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|