piix4.c basic skeleton

The real PIIX4 access code must still be written; perhaps somebody else could
do this? Most of it could be copied from the old piix4.c. But check carefully
what you are doing, as some things *have* changed (like the SMBUS_{BYTE,...}
variables!).


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@9 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Frodo Looijaard committed 1998-11-19 15:14:01 +00:00
1 parent 36d5e317ce
commit 9f4acd58b1
8 files changed
+304 -20

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ MODULE_DIR := src
# Regrettably, even 'simply expanded variables' will not put their currently
# defined value verbatim into the command-list of rules...
SRCTARGETS := $(MODULE_DIR)/smbus.o
SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o
# Include all dependency files
include $(SRCTARGETS:.o=.d)
+118
View File
@@ -0,0 +1,118 @@
/*
smbus.c - A Linux module for reading sensor data.
Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl>
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.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include "smbus.h"
static int piix4_init(void);
static int piix4_cleanup(void);
static int piix4_setup(void);
static s32 piix4_access(u8 addr, char read_write,
u8 command, int size, union smbus_data * data);
#ifdef MODULE
extern int init_module(void);
extern int cleanup_module(void);
#endif /* MODULE */
static struct smbus_adapter piix4_adapter;
static int piix4_initialized;
/* Detect whether a PIIX4 can be found, and initialize it, where necessary.
Return -ENODEV if not found. */
int piix4_setup(void)
{
/* TO BE WRITTEN! */
}
/* Return -1 on error. See smbus.h for more information */
s32 piix4_access(u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
/* TO BE WRITTEN! */
}
int piix4_init(void)
{
int res;
#ifdef DEBUG
if (piix4_initialized) {
printk("piix4.o: Oops, piix4_init called a second time!");
return -EBUSY;
}
#endif
piix4_initialized = 0;
if ((res = piix4_setup())) {
printk("piix4.o: PIIX4 not detected, module not inserted");
piix4_cleanup();
return res;
}
piix4_initialized ++;
strcpy(piix4_adapter.name,"SMBus PIIX4 adapter");
piix4_adapter.id = ALGO_SMBUS | SMBUS_PIIX4;
piix4_adapter.algo = &smbus_algorithm;
piix4_adapter.smbus_access = &piix4_access;
if ((res = smbus_add_adapter(&piix4_adapter))) {
printk("piix4.o: smbus_add_adapter failed, module not inserted");
piix4_cleanup();
return res;
}
piix4_initialized++;
printk("piix4.o: PIIX4 bus detected and initialized");
return 0;
}
int piix4_cleanup(void)
{
int res;
if (piix4_initialized >= 2)
{
if ((res = smbus_del_adapter(&piix4_adapter))) {
printk("piix4.o: smbus_del_adapter failed, module not removed");
return res;
}
else
piix4_initialized--;
}
if (piix4_initialized >= 1) {
/* Undo anything piix4_setup did */
piix4_initialized--;
}
return 0;
}
#ifdef MODULE
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("PIIX4 SMBus driver");
int init_module(void)
{
return piix4_init();
}
int cleanup_module(void)
{
return piix4_cleanup();
}
#endif /* MODULE */
+9 -6
View File
@@ -109,9 +109,9 @@ struct smbus_adapter {
int timeout;
int retries;
/* Here ended i2c_algorithm */
s32 (* smbus_access) (__u8 addr, char read_write,
__u8 command, int size, union smbus_data * data);
/* Here ended i2c_adapter */
s32 (* smbus_access) (u8 addr, char read_write,
u8 command, int size, union smbus_data * data);
};
/* We need to mark SMBus algorithms in the algorithm structure.
@@ -121,11 +121,14 @@ struct smbus_adapter {
this flag is set! */
#define ALGO_SMBUS 0x40000
/* SMBus Adapter ids */
#define SMBUS_PIIX4 1
/* This union is used within smbus_access routines */
union smbus_data {
__u8 byte;
__u16 word;
__u8 block[32];
u8 byte;
u16 word;
u8 block[32];
};
/* smbus_access read or write markers */
+24 -3
View File
@@ -19,6 +19,13 @@
#include <linux/module.h>
#include <linux/kernel.h>
#ifdef SPINLOCK
#include <asm/spinlock.h>
#else
#include <asm/semaphore.h>
#endif
#include "smbus.h"
static s32 smbus_access_i2c (struct smbus_adapter * adapter, u8 addr,
@@ -57,14 +64,28 @@ struct smbus_algorithm smbus_algorithm = {
/* OK, so you want to access a bus using the SMBus protocols. Well, it either
is registered as a SMBus-only adapter (like the PIIX4), or we need to
simulate the SMBus commands using the i2c access routines. */
simulate the SMBus commands using the i2c access routines.
We do all locking here, so you can ignore that in the adapter-specific
smbus_accesss routine. */
s32 smbus_access (struct smbus_adapter * adapter, u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
int res;
#ifdef SPINLOCK
spin_lock_irqsave(&adapter->lock,adapter->lockflags);
#else
down(&adapter->lock);
#endif
if (adapter->id & ALGO_SMBUS)
return adapter->smbus_access(addr,read_write,command,size,data);
res = adapter->smbus_access(addr,read_write,command,size,data);
else
return smbus_access_i2c(adapter,addr,read_write,command,size,data);
res = smbus_access_i2c(adapter,addr,read_write,command,size,data);
#ifdef SPINLOCK
spin_unlock_irqrestore(&adapter->lock,adapter->lockflags);
#else
up(&adapter->lock);
#endif
return res;
}
/* Simulate a SMBus command using the i2c protocol
+1 -1
View File
@@ -22,7 +22,7 @@ MODULE_DIR := src
# Regrettably, even 'simply expanded variables' will not put their currently
# defined value verbatim into the command-list of rules...
SRCTARGETS := $(MODULE_DIR)/smbus.o
SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o
# Include all dependency files
include $(SRCTARGETS:.o=.d)
+118
View File
@@ -0,0 +1,118 @@
/*
smbus.c - A Linux module for reading sensor data.
Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl>
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.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include "smbus.h"
static int piix4_init(void);
static int piix4_cleanup(void);
static int piix4_setup(void);
static s32 piix4_access(u8 addr, char read_write,
u8 command, int size, union smbus_data * data);
#ifdef MODULE
extern int init_module(void);
extern int cleanup_module(void);
#endif /* MODULE */
static struct smbus_adapter piix4_adapter;
static int piix4_initialized;
/* Detect whether a PIIX4 can be found, and initialize it, where necessary.
Return -ENODEV if not found. */
int piix4_setup(void)
{
/* TO BE WRITTEN! */
}
/* Return -1 on error. See smbus.h for more information */
s32 piix4_access(u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
/* TO BE WRITTEN! */
}
int piix4_init(void)
{
int res;
#ifdef DEBUG
if (piix4_initialized) {
printk("piix4.o: Oops, piix4_init called a second time!");
return -EBUSY;
}
#endif
piix4_initialized = 0;
if ((res = piix4_setup())) {
printk("piix4.o: PIIX4 not detected, module not inserted");
piix4_cleanup();
return res;
}
piix4_initialized ++;
strcpy(piix4_adapter.name,"SMBus PIIX4 adapter");
piix4_adapter.id = ALGO_SMBUS | SMBUS_PIIX4;
piix4_adapter.algo = &smbus_algorithm;
piix4_adapter.smbus_access = &piix4_access;
if ((res = smbus_add_adapter(&piix4_adapter))) {
printk("piix4.o: smbus_add_adapter failed, module not inserted");
piix4_cleanup();
return res;
}
piix4_initialized++;
printk("piix4.o: PIIX4 bus detected and initialized");
return 0;
}
int piix4_cleanup(void)
{
int res;
if (piix4_initialized >= 2)
{
if ((res = smbus_del_adapter(&piix4_adapter))) {
printk("piix4.o: smbus_del_adapter failed, module not removed");
return res;
}
else
piix4_initialized--;
}
if (piix4_initialized >= 1) {
/* Undo anything piix4_setup did */
piix4_initialized--;
}
return 0;
}
#ifdef MODULE
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("PIIX4 SMBus driver");
int init_module(void)
{
return piix4_init();
}
int cleanup_module(void)
{
return piix4_cleanup();
}
#endif /* MODULE */
+24 -3
View File
@@ -19,6 +19,13 @@
#include <linux/module.h>
#include <linux/kernel.h>
#ifdef SPINLOCK
#include <asm/spinlock.h>
#else
#include <asm/semaphore.h>
#endif
#include "smbus.h"
static s32 smbus_access_i2c (struct smbus_adapter * adapter, u8 addr,
@@ -57,14 +64,28 @@ struct smbus_algorithm smbus_algorithm = {
/* OK, so you want to access a bus using the SMBus protocols. Well, it either
is registered as a SMBus-only adapter (like the PIIX4), or we need to
simulate the SMBus commands using the i2c access routines. */
simulate the SMBus commands using the i2c access routines.
We do all locking here, so you can ignore that in the adapter-specific
smbus_accesss routine. */
s32 smbus_access (struct smbus_adapter * adapter, u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
int res;
#ifdef SPINLOCK
spin_lock_irqsave(&adapter->lock,adapter->lockflags);
#else
down(&adapter->lock);
#endif
if (adapter->id & ALGO_SMBUS)
return adapter->smbus_access(addr,read_write,command,size,data);
res = adapter->smbus_access(addr,read_write,command,size,data);
else
return smbus_access_i2c(adapter,addr,read_write,command,size,data);
res = smbus_access_i2c(adapter,addr,read_write,command,size,data);
#ifdef SPINLOCK
spin_unlock_irqrestore(&adapter->lock,adapter->lockflags);
#else
up(&adapter->lock);
#endif
return res;
}
/* Simulate a SMBus command using the i2c protocol
+9 -6
View File
@@ -109,9 +109,9 @@ struct smbus_adapter {
int timeout;
int retries;
/* Here ended i2c_algorithm */
s32 (* smbus_access) (__u8 addr, char read_write,
__u8 command, int size, union smbus_data * data);
/* Here ended i2c_adapter */
s32 (* smbus_access) (u8 addr, char read_write,
u8 command, int size, union smbus_data * data);
};
/* We need to mark SMBus algorithms in the algorithm structure.
@@ -121,11 +121,14 @@ struct smbus_adapter {
this flag is set! */
#define ALGO_SMBUS 0x40000
/* SMBus Adapter ids */
#define SMBUS_PIIX4 1
/* This union is used within smbus_access routines */
union smbus_data {
__u8 byte;
__u16 word;
__u8 block[32];
u8 byte;
u16 word;
u8 block[32];
};
/* smbus_access read or write markers */