mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-10 16:30:50 +00:00
The basic directory structure for lmsensors2.
README.directories contains a description of the directories I created; read it if you have questions about them. doc/design is the design document I sent before through email. doc/useful_addresses.html contains links to I2C, SMBus and sensors information. Note that we may have to change minor i2c things, like Makefiles; this is why I put it in the archive too (we should, of course, send important changes to Simon Vogl). git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
8e82d8354a
commit
11e88380d5
32 files changed
+5012
No files matched your search
@@ -0,0 +1,291 @@
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* adap-bit.c i2c driver algorithms for bit-shift adapters */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Copyright (C) 1995-97 Simon G. Vogl
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
static char alg_rcsid[] = "$Id: algo-pcf.c,v 1.1 1998/09/05 18:20:09 i2c Exp $";
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/malloc.h>
|
||||
#include <linux/version.h>
|
||||
|
||||
|
||||
#if LINUX_VERSION_CODE >= 0x020100
|
||||
|
||||
# include <asm/uaccess.h>
|
||||
#else
|
||||
# include <asm/segment.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/sched.h>
|
||||
|
||||
#include "i2c.h"
|
||||
#include "algo-pcf.h"
|
||||
|
||||
/* ----- global defines ---------------------------------------------------- */
|
||||
#define DEB(x) /* should be reasonable open, close &c. */
|
||||
#define DEB2(x) /* low level debugging - very slow */
|
||||
#define DEBE(x) /* error messages */
|
||||
#define DEBI(x) /* ioctl and its arguments */
|
||||
#define DEBACK(x) x /* ack failed message */
|
||||
#define DEBSTAT(x) /* print several statistical values */
|
||||
|
||||
#define DEBPROTO(x) /* debug the protocol by showing transferred bytes*/
|
||||
|
||||
|
||||
/* ----- global variables --------------------------------------------- */
|
||||
|
||||
/* module parameters:
|
||||
*/
|
||||
static int test=0; /* see if the line-setting functions work */
|
||||
static int scan=0; /* have a look at what's hanging 'round */
|
||||
|
||||
/*
|
||||
* This array contains the hw-specific functions for
|
||||
* each port (hardware) type.
|
||||
*/
|
||||
static struct pcf_adapter *pcf_adaps[PCF_ADAP_MAX];
|
||||
static int adap_count;
|
||||
static struct i2c_adapter *i2c_adaps[PCF_ADAP_MAX];
|
||||
|
||||
/* --- setting states on the bus with the right timing: --------------- */
|
||||
|
||||
/*
|
||||
* Sanity check for the adapter hardware - check the reaction of
|
||||
* the bus lines only if it seems to be idle.
|
||||
*/
|
||||
static int test_bus(struct pcf_adapter *adap)
|
||||
{
|
||||
}
|
||||
|
||||
/* ----- Utility functions
|
||||
*/
|
||||
|
||||
|
||||
/* send a message to a client.
|
||||
*/
|
||||
static int pcf_send(struct i2c_client *client,const char *buf, int count)
|
||||
{
|
||||
struct i2c_adapter *adapter=client->adapter;
|
||||
struct pcf_adapter *adap=(struct pcf_adapter*)adapter->data;
|
||||
int ret,i;
|
||||
|
||||
DEB2(printk(" i2c_write: wrote %d bytes.\n",wrcount));
|
||||
return wrcount;
|
||||
}
|
||||
|
||||
|
||||
static int pcf_recv(struct i2c_client *client,char *buf,int count)
|
||||
{
|
||||
struct i2c_adapter *adapter = client->adapter;
|
||||
struct pcf_adapter *adap = (struct pcf_adapter*)adapter->data;
|
||||
unsigned int flags = client->flags;
|
||||
char addr;
|
||||
int ret=0,i,rdcount;
|
||||
|
||||
DEB(printk("i2c(bit): i2c_read: %d byte(s) read.\n", rdcount ));
|
||||
return rdcount;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* alpha version of combined transmit
|
||||
*/
|
||||
static int pcf_comb(struct i2c_client *client, char *readbuf,const char *writebuf,
|
||||
int nread, int nwrite, int dir)
|
||||
{
|
||||
/* struct i2c_adapter *adapter = client->adapter;
|
||||
struct pcf_adapter *adap = (struct pcf_adapter*)adapter->data;
|
||||
unsigned int flags = client->flags;
|
||||
char addr;
|
||||
int ret=0,i,rdcount=0,wrcount=0;
|
||||
|
||||
|
||||
DEB(printk("i2c(bit): i2c_read: %d byte(s) read.\n", rdcount ));
|
||||
return wrcount+rdcount;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int algo_control(struct i2c_adapter *adapter,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int client_register(struct i2c_client *client)
|
||||
{
|
||||
struct i2c_adapter *adapter = client->adapter;
|
||||
struct pcf_adapter *adap = (struct pcf_adapter*)adapter->data;
|
||||
|
||||
if (adap->client_register != NULL)
|
||||
return adap->client_register(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int client_unregister(struct i2c_client *client)
|
||||
{
|
||||
struct i2c_adapter *adapter = client->adapter;
|
||||
struct pcf_adapter *adap = (struct pcf_adapter*)adapter->data;
|
||||
|
||||
if (adap->client_unregister != NULL)
|
||||
return adap->client_unregister(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----exported algorithm data: ------------------------------------- */
|
||||
|
||||
struct i2c_algorithm pcf_algo = {
|
||||
"PCF 8584 algorithm",
|
||||
ALGO_BIT,
|
||||
pcf_send, /* master_xmit */
|
||||
pcf_recv, /* master_recv */
|
||||
pcf_comb, /* master_comb */
|
||||
NULL, /* slave_xmit */
|
||||
NULL, /* slave_recv */
|
||||
algo_control, /* ioctl */
|
||||
client_register,
|
||||
client_unregister,
|
||||
};
|
||||
|
||||
/*
|
||||
* registering functions to load algorithms at runtime
|
||||
*/
|
||||
int i2c_pcf_add_bus(struct pcf_adapter *adap)
|
||||
{
|
||||
int i,ack;
|
||||
struct i2c_adapter *i2c_adap;
|
||||
|
||||
for (i = 0; i < PCF_ADAP_MAX; i++)
|
||||
if (NULL == pcf_adaps[i])
|
||||
break;
|
||||
if (PCF_ADAP_MAX == i)
|
||||
return -ENOMEM;
|
||||
|
||||
if (test) {
|
||||
int ret = test_bus(adap);
|
||||
if (ret<0)
|
||||
return -ENODEV;
|
||||
}
|
||||
i2c_adap = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
|
||||
if (i2c_adap == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
pcf_adaps[i] = adap;
|
||||
adap_count++;
|
||||
DEB(printk("i2c(bit): algorithm %s registered.\n",adap->name));
|
||||
|
||||
/* register new adapter to i2c module... */
|
||||
|
||||
memset(i2c_adap,0,sizeof(struct i2c_adapter));
|
||||
strcpy(i2c_adap->name,adap->name);
|
||||
i2c_adap->id = pcf_algo.id | adap->id;
|
||||
i2c_adap->algo = &pcf_algo;
|
||||
i2c_adap->data = adap;
|
||||
i2c_adap->timeout = 100; /* default values, should */
|
||||
i2c_adap->retries = 3; /* be replaced by defines */
|
||||
i2c_adaps[i] = i2c_adap;
|
||||
i2c_add_adapter(i2c_adap);
|
||||
|
||||
/* scan bus */
|
||||
if (scan) {
|
||||
#if 0
|
||||
printk(KERN_INFO "i2c(bit): scanning bus %s.\n", adap->name);
|
||||
for (i = 0x00; i < 0xff; i+=2) {
|
||||
i2c_start(adap);
|
||||
ack = i2c_outb(adap,i);
|
||||
i2c_stop(adap);
|
||||
if (ack>0) {
|
||||
printk(KERN_INFO
|
||||
"i2c(bit): found chip at addr=0x%2x\n",i>>1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int i2c_pcf_del_bus(struct pcf_adapter *adap)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < PCF_ADAP_MAX; i++)
|
||||
if ( adap == pcf_adaps[i])
|
||||
break;
|
||||
if ( PCF_ADAP_MAX == i) {
|
||||
printk(KERN_WARNING "i2c(bit): could not unregister bus: %s\n",
|
||||
adap->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
pcf_adaps[i] = NULL;
|
||||
i2c_del_adapter(i2c_adaps[i]);
|
||||
kfree(i2c_adaps[i]);
|
||||
i2c_adaps[i] = NULL;
|
||||
adap_count--;
|
||||
DEB(printk("i2c(bit): adapter unregistered: %s\n",adap->name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int algo_pcf_init (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0;i<PCF_ADAP_MAX;i++) {
|
||||
pcf_adaps[i]=NULL;
|
||||
}
|
||||
adap_count=0;
|
||||
i2c_add_algorithm(&pcf_algo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MODULE
|
||||
MODULE_PARM(test, "i");
|
||||
MODULE_PARM(scan, "i");
|
||||
|
||||
EXPORT_SYMBOL(i2c_pcf_add_bus);
|
||||
EXPORT_SYMBOL(i2c_pcf_del_bus);
|
||||
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return algo_pcf_init();
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
{
|
||||
i2c_del_algorithm(&pcf_algo);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* bit-lp.c i2c-hw access for philips style parallel port adapters */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Copyright (C) 1995-97 Simon G. Vogl
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
static char rcsid[] = "$Id: bit-lp-multi.c,v 1.1 1998/09/05 18:20:09 i2c Exp $";
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/module.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
|
||||
#include "i2c.h"
|
||||
#include "algo-bit.h"
|
||||
|
||||
|
||||
#define BIT_LP_MAX 3 /* max. number of addresses to probe */
|
||||
|
||||
struct bit_lp_data {
|
||||
unsigned int base; /* base address */
|
||||
};
|
||||
|
||||
static struct bit_lp_data bit_lp_adaps[BIT_LP_MAX] = {
|
||||
{0,},
|
||||
{0,},
|
||||
{0,},
|
||||
};
|
||||
static int adap_count=0;
|
||||
|
||||
/* ----- global defines ----------------------------------------------- */
|
||||
#define DEB(x) /* should be reasonable open, close &c. */
|
||||
#define DEB2(x) /* low level debugging - very slow */
|
||||
#define DEBE(x) x /* error messages */
|
||||
|
||||
/* ----- printer port defines ------------------------------------------*/
|
||||
/* Pin Port Inverted name */
|
||||
#define I2C_ON 0x20 /* 12 status N paper */
|
||||
/* ... only for phil. not used */
|
||||
#define I2C_SDA 0x80 /* 9 data N data7 */
|
||||
#define I2C_SCL 0x08 /* 17 ctrl N dsel */
|
||||
|
||||
#define I2C_SDAIN 0x80 /* 11 stat Y busy */
|
||||
#define I2C_SCLIN 0x08 /* 15 stat Y enable */
|
||||
|
||||
#define I2C_DMASK 0x7f
|
||||
#define I2C_CMASK 0xf7
|
||||
|
||||
/* --- Convenience defines for the parallel port: */
|
||||
#define BASE bit_lp_adaps[minor].base
|
||||
#define DATA BASE /* Centronics data port */
|
||||
#define STAT (BASE+1) /* Centronics status port */
|
||||
#define CTRL (BASE+2) /* Centronics control port */
|
||||
|
||||
/* ----- local functions ---------------------------------------------- */
|
||||
|
||||
static void bit_lp_setscl(int minor, int state)
|
||||
{
|
||||
if (state) {
|
||||
outb(I2C_SCL, CTRL);
|
||||
} else {
|
||||
outb(I2C_CMASK, CTRL);
|
||||
}
|
||||
}
|
||||
|
||||
static void bit_lp_setsda(int minor, int state)
|
||||
{
|
||||
if (state) {
|
||||
outb(I2C_DMASK , DATA);
|
||||
} else {
|
||||
outb(I2C_SDA , DATA);
|
||||
}
|
||||
}
|
||||
|
||||
static int bit_lp_getscl(int minor)
|
||||
{
|
||||
return ( 0 != ( (inb(STAT)) & I2C_SCLIN ) );
|
||||
}
|
||||
|
||||
static int bit_lp_getsda(int minor)
|
||||
{
|
||||
return ( 0 != ( (inb(STAT)) & I2C_SDAIN ) );
|
||||
}
|
||||
|
||||
static int bit_lp_init(int minor)
|
||||
{
|
||||
if (check_region(bit_lp_adaps[minor].base,
|
||||
(bit_lp_adaps[minor].base == 0x3bc)? 3 : 8) < 0 ) {
|
||||
return -ENODEV;
|
||||
} else {
|
||||
request_region(bit_lp_adaps[minor].base,
|
||||
(bit_lp_adaps[minor].base == 0x3bc)? 3 : 8,
|
||||
"i2c (parallel port adapter)");
|
||||
bit_lp_setsda(minor,1);
|
||||
bit_lp_setscl(minor,1);
|
||||
}
|
||||
printk("i2c%d: scl: %d sda %d \n",minor,bit_lp_getscl(minor),bit_lp_getsda(minor));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bit_lp_exit(int minor)
|
||||
{
|
||||
release_region( bit_lp_adaps[minor].base ,
|
||||
(bit_lp_adaps[minor].base == 0x3bc)? 3 : 8 );
|
||||
release_region( bit_lp_adaps[minor].base + 0x0400, 8 );
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Encapsulate the above functions in the correct operations structure.
|
||||
* This is only done when more than one hardware adapter is supported.
|
||||
*/
|
||||
struct bit_adapter bit_lp_ops = {
|
||||
"Philips Parallel port adapter",
|
||||
bit_lp_setscl,
|
||||
bit_lp_setsda,
|
||||
bit_lp_getscl,
|
||||
bit_lp_getsda,
|
||||
bit_lp_init,
|
||||
bit_lp_exit
|
||||
};
|
||||
|
||||
#ifdef MODULE
|
||||
static int base[BIT_LP_MAX+1] = { [0 ... BIT_LP_MAX] = 0 };
|
||||
MODULE_PARM(base, "1-" __MODULE_STRING(BIT_LP_MAX) "i");
|
||||
|
||||
/*
|
||||
EXPORT_SYMBOL(i2c_bit_add_bus);
|
||||
EXPORT_SYMBOL(i2c_bit_del_bus);
|
||||
*/
|
||||
int init_module(void)
|
||||
{
|
||||
/* Work out how many ports we have, then get parport_share to parse
|
||||
the irq values. */
|
||||
unsigned int i;
|
||||
for (i = 0; i < BIT_LP_MAX && base[i]; i++) {
|
||||
bit_lp_adaps[adap_count].base = base[i];
|
||||
if (bit_lp_init(adap_count)==0) {
|
||||
/* i2c_bit_add_bus(struct bit_adapter *algo);*/
|
||||
/* bit_add_adapter();*/
|
||||
adap_count++;
|
||||
}
|
||||
}
|
||||
if (i==0) { /* no values specified -> probe */
|
||||
}
|
||||
|
||||
/* count += probe_one_port(0x3bc, irq[0], dma[0]);
|
||||
count += probe_one_port(0x378, irq[0], dma[0]);
|
||||
count += probe_one_port(0x278, irq[0], dma[0]);
|
||||
*/
|
||||
printk("bit_lp: found %d devices.\n",adap_count);
|
||||
|
||||
if (adap_count==0)
|
||||
return -ENODEV;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<adap_count;i++) {
|
||||
int i2c_bit_del_bus(struct bit_adapter *algo);
|
||||
bit_lp_exit(i);
|
||||
}
|
||||
/* i2c_del_algorithm(&alg_bit_opns);*/
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* pcf-lp.c i2c-hw access for PCF 8584 on bidir. parallel ports */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
Copyright (C) 1995-97 Simon G. Vogl
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
static char rcsid[] = "$Id: pcf-elektor.c,v 1.1 1998/09/05 18:20:09 i2c Exp $";
|
||||
/*
|
||||
* $Log: pcf-elektor.c,v $
|
||||
* Revision 1.1 1998/09/05 18:20:09 i2c
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.1 1998/01/20 10:01:29 i2c
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.2 1997/06/03 06:00:10 i2c
|
||||
* first version that works
|
||||
*
|
||||
* Revision 1.2 1996/11/20 20:20:46 i2c
|
||||
* first version for ISA bus.
|
||||
*
|
||||
* Revision 1.1 1996/11/17 11:00:03 i2c
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <asm/io.h>
|
||||
#include <linux/errno.h>
|
||||
|
||||
#include "i2c.h"
|
||||
#include "i2c-priv.h"
|
||||
|
||||
/* ----- global defines ----------------------------------------------- */
|
||||
#define DEB(x) /* should be reasonable open, close &c. */
|
||||
#define DEB2(x) /* low level debugging - very slow */
|
||||
#define DEBE(x) x /* error messages */
|
||||
|
||||
#define DEBHW(x) x /* lowest level hardware debug -- log changes of*/
|
||||
/* the bit lines... */
|
||||
|
||||
#define basePort(port) (i2c_table[minor].base+(port))
|
||||
|
||||
/* ----- local functions ---------------------------------------------- */
|
||||
|
||||
#if (PCFADAPS) > 1
|
||||
# define Local static
|
||||
#else
|
||||
# define Local inline
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Local int pcf_read (int minor, int adr)
|
||||
{
|
||||
int ret;
|
||||
udelay(10); /* Give the card some time */
|
||||
ret = inb(basePort( (adr!=0) ));/* force max. increment of 1 */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Local void pcf_write (int minor, int adr,char data)
|
||||
{
|
||||
udelay(10); /* Give the card some time */
|
||||
outb(data,basePort( (adr!=0) ));
|
||||
}
|
||||
|
||||
|
||||
Local int pcf_init (int minor)
|
||||
{
|
||||
if (check_region(i2c_table[minor].base, 4) < 0 ) {
|
||||
return -ENODEV;
|
||||
} else {
|
||||
request_region(i2c_table[minor].base, 4, "i2c (Elektor)");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Local void pcf_exit (int minor)
|
||||
{
|
||||
release_region( i2c_table[minor].base, 4 );
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Encapsulate the above functions in the correct operations structure.
|
||||
* This is only done when more than one hardware adapter is supported.
|
||||
*/
|
||||
#if (PCFADAPS) > 1
|
||||
struct i2c_pcf_ops pcf_lp_ops = {
|
||||
pcf_read,
|
||||
pcf_write,
|
||||
pcf_init,
|
||||
pcf_exit
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* pcf-isa.c i2c-hw access for PCF 8584 on ISA boards */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Copyright (C) 1995-96 Simon G. Vogl
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
static char rcsid[] = "$Id: pcf-isa.c,v 1.1 1998/09/05 18:20:09 i2c Exp $";
|
||||
/*
|
||||
* $Log: pcf-isa.c,v $
|
||||
* Revision 1.1 1998/09/05 18:20:09 i2c
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.3 1998/01/20 10:01:29 i2c
|
||||
* *** empty log message ***
|
||||
*
|
||||
* Revision 1.2 1996/11/20 20:20:46 i2c
|
||||
* first version for ISA bus.
|
||||
*
|
||||
* Revision 1.1 1996/11/17 11:00:03 i2c
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <asm/io.h>
|
||||
#include <linux/errno.h>
|
||||
|
||||
#include "i2c.h"
|
||||
#include "i2c-priv.h"
|
||||
|
||||
/* ----- global defines ----------------------------------------------- */
|
||||
#define DEB(x) /* should be reasonable open, close &c. */
|
||||
#define DEB2(x) /* low level debugging - very slow */
|
||||
#define DEBE(x) x /* error messages */
|
||||
|
||||
/* ----- local functions --------------------------------------------------- */
|
||||
|
||||
#if (PCFADAPS) > 1
|
||||
# define Local static
|
||||
#else
|
||||
# define Local inline
|
||||
#endif
|
||||
|
||||
|
||||
Local int pcf_read (int minor, int adr)
|
||||
{
|
||||
if (adr)
|
||||
return inb(BASE + 1); /* read status port */
|
||||
else
|
||||
return inb(BASE); /* read data port */
|
||||
}
|
||||
|
||||
|
||||
Local void pcf_write (int minor, int adr,char data)
|
||||
{
|
||||
if (adr)
|
||||
outb(data, BASE + 1);
|
||||
else
|
||||
outb(data, BASE);
|
||||
}
|
||||
|
||||
|
||||
Local int pcf_init (int minor)
|
||||
{
|
||||
if (check_region(i2c_table[minor].base, 2) < 0 ) {
|
||||
DEBE(printk("i2c_init: Port %#x already in use.\n",
|
||||
i2c_table[minor].base));
|
||||
return -ENODEV;
|
||||
} else {
|
||||
request_region(i2c_table[minor].base, 2,
|
||||
"i2c (ISA bus)");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Local void pcf_exit (int minor)
|
||||
{
|
||||
release_region( i2c_table[minor].base , 2 );
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Encapsulate the above functions in the correct operations structure.
|
||||
* This is only done when more than one hardware adapter is supported.
|
||||
*/
|
||||
#if (PCFADAPS) > 1
|
||||
struct i2c_pcf_ops pcf_isa_ops = {
|
||||
pcf_read,
|
||||
pcf_write,
|
||||
pcf_init,
|
||||
pcf_exit
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,228 @@
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* pcf-lp.c i2c-hw access for PCF 8584 on bidir. parallel ports */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
-----.-.---....------..-.-.---.... Oh bugger! Hope it works this time......
|
||||
|
||||
Copyright (C) 1995-97 Simon G. Vogl
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
static char rcsid[] = "$Id: pcf-lp.c,v 1.1 1998/09/05 18:20:09 i2c Exp $";
|
||||
/*
|
||||
* $Log: pcf-lp.c,v $
|
||||
* Revision 1.1 1998/09/05 18:20:09 i2c
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.4 1998/01/20 10:01:29 i2c
|
||||
* *** empty log message ***
|
||||
*
|
||||
* Revision 1.3 1997/06/15 14:21:37 i2c
|
||||
* removed debugging messages
|
||||
*
|
||||
* Revision 1.2 1997/06/03 06:00:10 i2c
|
||||
* first version that works
|
||||
*
|
||||
* Revision 1.2 1996/11/20 20:20:46 i2c
|
||||
* first version for ISA bus.
|
||||
*
|
||||
* Revision 1.1 1996/11/17 11:00:03 i2c
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <asm/io.h>
|
||||
#include <linux/errno.h>
|
||||
|
||||
#include "i2c.h"
|
||||
#include "i2c-priv.h"
|
||||
|
||||
/* ----- global defines ----------------------------------------------- */
|
||||
#define DEB(x) /* should be reasonable open, close &c. */
|
||||
#define DEB2(x) /* low level debugging - very slow */
|
||||
#define DEBE(x) x /* error messages */
|
||||
|
||||
#define DEBHW(x) x /* lowest level hardware debug -- log changes of*/
|
||||
/* the bit lines... */
|
||||
|
||||
#define lpPort(port) (i2c_table[minor].base+(port))
|
||||
|
||||
|
||||
/* ----- local variables ---------------------------------------------- */
|
||||
|
||||
static unsigned char ctrl; /* remember line states */
|
||||
|
||||
/* (re)set line states */
|
||||
#define Strobe(arg) if (!arg) ctrl|= 0x01; else ctrl &=!0x01;\
|
||||
outb_p(ctrl,lpPort(2)) /* Strobe -- pin 1 */
|
||||
#define AutoLF(arg) if (!arg) ctrl|= 0x02; else ctrl &=!0x02;\
|
||||
outb_p(ctrl,lpPort(2)) /* AutoLF -- pin 14 */
|
||||
#define Init(arg) if ( arg) ctrl|= 0x04; else ctrl &=!0x04;\
|
||||
outb(ctrl,lpPort(2)) /* Init -- pin 16 */
|
||||
#define Select(arg) if (!arg) ctrl|= 0x08; else ctrl &=!0x08;\
|
||||
outb_p(ctrl,lpPort(2)) /* Sel. in - pin 17 */
|
||||
/* 0x10 -- Int Enable */
|
||||
#define ReadBit(arg) if(arg) ctrl|= 0x20; else ctrl &=!0x20;\
|
||||
outb_p(ctrl,lpPort(2)) /* direction bit */
|
||||
|
||||
#define inStr() (! (0x01 & inb(lpPort(2)) ) ) /* Strobe -- pin 1 */
|
||||
#define inALF() (! (0x02 & inb(lpPort(2)) ) ) /* AutoLF -- pin 14 */
|
||||
#define inIni() ( (0x04 & inb(lpPort(2)) ) ) /* Init -- pin 16 */
|
||||
#define inSel() (! (0x08 & inb(lpPort(2)) ) ) /* Sel. in - pin 17 */
|
||||
/* 0x10 -- Int Enable */
|
||||
/*
|
||||
#define Argl() printk("(wr-%d cs-%d a0-%d (%#2x, %#2x))\n", \
|
||||
inStr(),inALF(),inIni(),inb(lpPort(0)),inb(lpPort(1)) )
|
||||
*/
|
||||
#define Argl() /**/
|
||||
|
||||
#define wr(arg) Strobe(arg); Argl() /* write line */
|
||||
#define cs(arg) AutoLF(arg); Argl() /* chip select */
|
||||
#define a0(arg) Init (arg); Argl() /* address line */
|
||||
|
||||
/* ----- local functions ---------------------------------------------- */
|
||||
/*
|
||||
#if (PCFADAPS) > 1
|
||||
# define Local static
|
||||
#else
|
||||
# define Local inline
|
||||
#endif
|
||||
*/
|
||||
#define Local /**/
|
||||
|
||||
/* --------- okay, I borrowed it. Stays here for debugging.
|
||||
* check the epp status. After a EPP transfer, it should be true that
|
||||
* 1) the TIMEOUT bit (SPP_STR.0) is clear
|
||||
* 2) the READY bit (SPP_STR.7) is set
|
||||
* returns 1 if okay
|
||||
*/
|
||||
static int ex_ppa_check_epp_status(int minor)
|
||||
{
|
||||
char r;
|
||||
inb(STAT);
|
||||
r = inb(STAT);
|
||||
|
||||
if (r & 1) {
|
||||
outb(r, STAT);
|
||||
outb(r&0xfe, STAT);
|
||||
printk("timed out on port 0x%04x\n", BASE);
|
||||
return 0;
|
||||
}
|
||||
if (!(r & 0x80)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Local int pcf_read (int minor, int adr)
|
||||
{
|
||||
int ret;
|
||||
a0(adr);
|
||||
ex_ppa_check_epp_status(minor);
|
||||
ret = inb(lpPort(4));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Local void pcf_write (int minor, int adr,char data)
|
||||
{
|
||||
a0(adr);
|
||||
ex_ppa_check_epp_status(minor);
|
||||
outb(data,lpPort(4));
|
||||
}
|
||||
|
||||
|
||||
Local int pcf_init (int minor)
|
||||
{
|
||||
char ctrl,ecr; /* parallel port registers */
|
||||
|
||||
if (check_region(i2c_table[minor].base, 8) < 0 ) {
|
||||
return -ENODEV;
|
||||
} else {
|
||||
request_region(i2c_table[minor].base, 8, "i2c (pcf-lp)");
|
||||
}
|
||||
|
||||
/* This is the standard detection algorithm for ECP ports */
|
||||
/* now detect, what kind of parallel port we have: */
|
||||
ecr = inb(i2c_table[minor].base+0x402);
|
||||
ctrl= inb(i2c_table[minor].base+0x002);
|
||||
if (ecr!=ctrl) { /* Okay, we seem to have an extended port :) */
|
||||
if (check_region(i2c_table[minor].base + 0x400, 8) < 0 ) {
|
||||
DEBE(printk( "i2c_init, port %#x: ext. ports already in use "
|
||||
"using only standard driver.\n",
|
||||
i2c_table[minor].base));
|
||||
return -ENODEV;
|
||||
} else {
|
||||
if ( (ecr & 0x03) != 0x01 ) { /* FIFO empty? */
|
||||
printk("FIFO not empty\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
outb(0x34,i2c_table[minor].base+0x402);
|
||||
if (inb(i2c_table[minor].base+0x402) != 0x35 ){ /* bits 0,1 readonly */
|
||||
printk("bits 0,1 not rd/only");
|
||||
return -ENODEV;
|
||||
}
|
||||
/* Okay, now we should have an ECP-capable printer port */
|
||||
printk("i2c%d: ECP parallel port.\n",minor);
|
||||
request_region(i2c_table[minor].base+0x0400, 3 ,
|
||||
"i2c (Extended Parallel port adapter)");
|
||||
outb(0x94 ,lpPort(0x402)); /* EPP mode */
|
||||
ctrl = inb(CTRL);
|
||||
|
||||
if (i2c_table[minor].irq > 0){ /* enable int. */
|
||||
outb(inb(lpPort(0x402)|0x10), lpPort(0x402));
|
||||
outb(ctrl|0x10,CTRL);
|
||||
}
|
||||
|
||||
ex_ppa_check_epp_status(minor);
|
||||
printk("status reads %2x\n",pcf_read(minor,1));
|
||||
ex_ppa_check_epp_status(minor);
|
||||
printk("data reads %2x\n",pcf_read(minor,0));
|
||||
}
|
||||
} else {
|
||||
printk("i2c%d: Need EPP port. Sorry.\n",minor);
|
||||
return -ENODEV;
|
||||
}
|
||||
/* Okay, now it's time to init my data structures */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Local void pcf_exit (int minor)
|
||||
{
|
||||
release_region( i2c_table[minor].base, 8 );
|
||||
release_region( i2c_table[minor].base + 0x0400, 3 );
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Encapsulate the above functions in the correct operations structure.
|
||||
* This is only done when more than one hardware adapter is supported.
|
||||
*/
|
||||
#if (PCFADAPS) > 1
|
||||
struct i2c_pcf_ops pcf_lp_ops = {
|
||||
pcf_read,
|
||||
pcf_write,
|
||||
pcf_init,
|
||||
pcf_exit
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* PCF 8584 global defines */
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Copyright (C) 19996 Simon G. Vogl
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* $Id: pcf8584.h,v 1.1 1998/07/29 08:09:51 i2c Exp $
|
||||
* $Log: pcf8584.h,v $
|
||||
* Revision 1.1 1998/07/29 08:09:51 i2c
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* ----- Control register bits ---------------------------------------- */
|
||||
#define PCF_PIN 0x80
|
||||
#define PCF_ESO 0x40
|
||||
#define PCF_ES1 0x20
|
||||
#define PCF_ES2 0x10
|
||||
#define PCF_ENI 0x08
|
||||
#define PCF_STA 0x04
|
||||
#define PCF_STO 0x02
|
||||
#define PCF_ACK 0x01
|
||||
|
||||
/* ----- Status register bits ----------------------------------------- */
|
||||
/*#define PCF_PIN 0x80 as above*/
|
||||
|
||||
#define PCF_INI 0x40 /* 1 if not initialized */
|
||||
#define PCF_STS 0x20
|
||||
#define PCF_BER 0x10
|
||||
#define PCF_AD0 0x08
|
||||
#define PCF_LRB 0x08
|
||||
#define PCF_AAS 0x04
|
||||
#define PCF_LAB 0x02
|
||||
#define PCF_BB 0x01
|
||||
|
||||
/* ----- Chip clock frequencies --------------------------------------- */
|
||||
#define PCF_CLK3 0x00
|
||||
#define PCF_CLK443 0x10
|
||||
#define PCF_CLK6 0x14
|
||||
#define PCF_CLK8 0x18
|
||||
#define PCF_CLK12 0x1c
|
||||
|
||||
/* ----- transmission frequencies ------------------------------------- */
|
||||
#define PCF_TRNS90 0x00 /* 90 kHz */
|
||||
#define PCF_TRNS45 0x01 /* 45 kHz */
|
||||
#define PCF_TRNS11 0x02 /* 11 kHz */
|
||||
#define PCF_TRNS15 0x03 /* 1.5 kHz */
|
||||
|
||||
|
||||
/* ----- Access to internal registers according to ES1,ES2 ------------ */
|
||||
/* they are mapped to the data port ( a0 = 0 ) */
|
||||
/* available when ESO == 0 : */
|
||||
|
||||
#define PCF_OWNADR 0
|
||||
#define PCF_INTREG PCF_ES2
|
||||
#define PCF_CLKREG PCF_ES1
|
||||
|
||||
|
||||
Reference in new issue
Block a user