Module smbus.o, many other small changes

git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@8 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Frodo Looijaard committed 1998-11-19 03:07:18 +00:00
1 parent afe6d17ee3
commit 36d5e317ce
20 files changed
+1691 -62

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
This package could not have been created without the help of many, many people.
The most notable contributors are listed below.
* Alexander Larsson <alla@lysator.liu.se>
Wrote the original lm78 module; lm_sensors version 1 was no more than an
extension of this module. He still likes to keep an eye on current
developments, but is usually too busy with other things to do much work
on them
* Philip Edelbrock <phil@netroedge.com>
Took up the development of the Alex' lm78 module. Responsible for most
SMBus code, and many, many other things. He is still one of the main
developers of the current package.
* Frodo Looijaard <frodol@dds.nl>
Took up the development of Alex' lm78 module. Large pieces of code were
written by him. Designed lm_sensors version 2.
* William Morgan <wmorgan@cmu.edu>
Helped with some patches in lm_sensors version 1. He provided us with
the original CVS archive, and even managed to explain to us how to use
it.
* Simon Vogl <simon@tk.uni-linz.ac.at>
Wrote the new i2c kernel driver. This driver is indispensable for the
workings of lm_sensors version 2.
* Gerd Knorr <kraxel@cs.tu-berlin.de> (?)
Designed the i2c structs, which made it possible to use the smbus-is-
just-an-i2c-extension approach.
+339
View File
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
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.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
+42 -9
View File
@@ -1,3 +1,21 @@
# Makefile - Makefile for 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.
# Uncomment the third line on SMP systems if the magic invocation fails.
SMP := $(shell if grep -q '^SMP[[:space:]]*=' /usr/src/linux/Makefile; then echo 1; else echo 0; fi)
#SMP := 0
@@ -12,6 +30,8 @@ MODVER := $(shell if cat /usr/include/linux/config.h /usr/include/linux/autoconf
# Uncomment the second line if you do not want to compile the included
# i2c modules. WARNING! If the i2c module version does not match the
# smbus/sensor module versions, you will get into severe problems.
# If you want to use a self-compiled version of the i2c modules, make
# sure <linux/i2c.h> contains the *correct* i2c header file!
I2C := 1
#I2C := 0
@@ -45,17 +65,21 @@ INCLUDEDIR := /usr/local/include/linux
# to do this.
# The subdirectories we need to build things in
MODULES :=
MODULES := src
ifeq ($(I2C),1)
MODULES += i2c
MODULES += i2c i2c/detect i2c/drivers i2c/eeprom
endif
# Some often-used commands with default options
MKDIR := mkdir -p
RM := rm -f
CC := gcc
# Determine the default compiler flags
CFLAGS := -D__KERNEL__ -DMODULE -I. -O2 -fomit-frame-pointer
# CFLAGS is to create in-kernel object files (modules); EXCFLAGS is to create
# non-kernel object files (which are linked into executables).
CFLAGS := -D__KERNEL__ -DMODULE -I. -Ii2c -O2 -fomit-frame-pointer
EXCFLAGS := -I. -O2 -Ii2c
ifeq ($(SMP),1)
CFLAGS += -D__SMP__
@@ -64,13 +88,19 @@ endif
ifeq ($(WARN),1)
CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
-Wcast-align -Wwrite-strings -Wnested-externs -Winline
EXCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
-Wcast-align -Wwrite-strings -Wnested-externs -Winline
endif
ifeq ($(MODVER),1)
CFLAGS += -DMODVERSIONS -include /usr/include/linux/modversions.h
endif
.PHONY: all clean install version package
ifeq ($(I2C),1)
CFLAGS += -DI2C
endif
.PHONY: all clean install version package dep
# Make all the default rule
all::
@@ -78,18 +108,21 @@ all::
# Include all makefiles for sub-modules
include $(patsubst %,%/Module.mk,$(MODULES))
# Making the dependency files - done automatically!
dep:
all::
all ::
install::
install :: all
clean::
$(RM) lm_sensors-*
# Create a dependency file. Tricky.
# Create a dependency file. Tricky. We sed rule puts dir/file.d and dir/file.c
# in front of the dependency file rule.
%.d: %.c
gcc -M -MG $(CFLAGS) $< | \
sed -e 's@ /[^ ]*@@g' -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $@
$(CC) -M -MG $(CFLAGS) $< | \
sed -e 's@^\(.*\)\.o:@$*.d $*.o Makefile '`dirname $*.d`/Module.mk':@' > $@
# This is tricky, but it works like a charm. It needs lots of utilities
+5
View File
@@ -0,0 +1,5 @@
Many, many things. Most notably:
* Write s32 smbus_access_i2c in smbus.c
* Check out whether we can use the dev interface for smbus (like i2c)
* Write all other modules
+28 -17
View File
@@ -4,6 +4,8 @@ distribute it, as long as you recognize me as the author, and mark any
changes you make as being your own, and distribute this notice with it.
Document version 1.0, 19981101.
1.1, 19981111.
1.2, 19981118.
Object oriented approach
@@ -130,6 +132,7 @@ Unites SMBus adapters and ISA adapters.
smbus.o
Main SMBus handling
Unites I2C adapters and SMBus hosts (like the PIIX4)
Defines smbus_algorithm
piix4.o
SMBus adapter driver for the PIIX4 SMBus host.
@@ -331,9 +334,13 @@ means there must be some way of selecting which of the many possible adapters
is in fact *the* SMBus. For now, I will ignore this problem. Later on,
we can add a hook somewhere in the i2c module to help us decide this.
This module consists in fact of two separate parts: first of all, it extends
all i2c structs to accomodate the new smbus fields. Second, it defines a
new algorithm (smbus_algorithm), that will be used by all non-i2c adapters.
A driver, client and adapter
-------------------
A driver, client and algorithm
------------------------------
We will not need to extend i2c_driver, i2c_client or i2c_adapter. This means
that struct smbus_driver is exactly the same as struct i2c_driver, and
@@ -346,30 +353,34 @@ partially supported by the i2c module. We will ignore this issue for
now.
An algorithm
An adapter
------------
struct smbus_algorithm {
struct smbus_adapter {
char name[32];
unsigned int id;
int (* master_xfer) (struct smbus_adapter *adap, struct smbus_msg msgs[],
int num);
int (* slave_send) (struct smbus_adapter *,char *, int);
int (* slave_recv) (struct smbus_adapter *,char *, int);
int (* algo_control) (struct smbus_adapter *, unsigned int, unsigned long);
int (* client_register) (struct smbus_client *);
int (* client_unregister) (struct smbus_client *);
struct smbus_algorithm *algo;
void *data;
#ifdef SPINLOCK
spinlock_t lock;
unsigned long lockflags;
#else
struct semaphore lock;
#endif
unsigned int flags;
struct smbus_client *clients[I2C_CLIENT_MAX];
int client_count;
int timeout;
int retries;
int (* smbus_access) (struct smbus_adapter *, __u8 addr, char read_write,
/* Here ended i2c_algorithm */
s32 (* smbus_access) (__u8 addr, char read_write,
__u8 command, int size, union smbus_data * data);
}
A description of the above struct:
smbus_access: A function to access the SMBus. If the algorithm describes
a i2c bus, it will use master_xfer to simulate this operation. In
case of a PIIX4, master_xfer, slave_send and slave_recv will not be
implemented.
smbus_access: A function to access the SMBus. It is only used for non-i2c
smbus adapters.
Access functions
+33
View File
@@ -0,0 +1,33 @@
This is a list of modifications between the stock i2c code as distributed
by Simon Vogl, and the code included in and beneath this directory. None
of these changes are important; you can still use a self-compiled version
of the i2c code and not compile the version in here.
* rscid declarations are changed
This is an unfortunate interaction between our CVS server and Simon's
RCS (CVS?) server. As these ids do not seem to be accessed anywhere,
there should be no change in the final object code
* Log entries are added
Another RCS/CVS side effect. Our logs are sometimes put in the source
code. As they are just comments, they will do no harm.
* EXPORT_SYMBOL declarations removed
They only work if you use the Linux source tree Makefiles. As we want to
use our own Makefile, we have removed them. This should have almost no
influence on the resulting object code; a few more functions may be
exported, but this should do no harm.
* bit-mb: Linux 2.0.x fixes
Some small changes to make this file compile with 2.0 kernels. These
changes will probably be included in the next i2c version.
* New file: Module.mk
The Makefile fragment we use to compile the files in this directory.
* New file: MODIFICATIONS
The file you are reading right now.
* Removed files: object files and executables
Everywhere, remakeable files are removed, to keep the source distribution
small and lean.
+27 -8
View File
@@ -1,20 +1,39 @@
# Module.mk - Makefile for 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.
# Note that MODULE_DIR (the directory in which this file resides) is a
# 'simply expanded variable'. That means that its value is substituted
# verbatim in the rules, until it is redefined.
MODULE_DIR := i2c
TARGETS := $(MODULE_DIR)/i2c-core.o $(MODULE_DIR)/algo-bit.o \
$(MODULE_DIR)/i2c-dev.o $(MODULE_DIR)/bit-lp.o \
$(MODULE_DIR)/bit-velle.o $(MODULE_DIR)/bit-mb.o
# Regrettably, even 'simply expanded variables' will not put their currently
# defined value verbatim into the command-list of rules...
I2CTARGETS := $(MODULE_DIR)/i2c-core.o $(MODULE_DIR)/algo-bit.o \
$(MODULE_DIR)/i2c-dev.o $(MODULE_DIR)/bit-lp.o \
$(MODULE_DIR)/bit-velle.o $(MODULE_DIR)/bit-mb.o
# Include all dependency files
include $(TARGETS:.o=.d)
include $(I2CTARGETS:.o=.d)
all :: $(TARGETS)
all :: $(I2CTARGETS)
install :: $(TARGETS)
install ::
$(MKDIR) $(MODDIR)
install -o root -g root -m 644 $(TARGETS) $(MODDIR)
install -o root -g root -m 644 $(I2CTARGETS) $(MODDIR)
clean ::
$(RM) $(TARGETS) $(TARGETS:.o=.d)
$(RM) $(I2CTARGETS) $(I2CTARGETS:.o=.d)
+1 -5
View File
@@ -17,7 +17,7 @@
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-bit.c,v 1.1 1998/11/02 20:29:27 frodo Exp $";
static char alg_rcsid[] = "$Id: algo-bit.c,v 1.2 1998/11/03 03:48:44 phil Exp $";
#include <linux/kernel.h>
#include <linux/module.h>
@@ -638,10 +638,6 @@ MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
MODULE_PARM_DESC(i2c_debug,"debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0))
EXPORT_SYMBOL(i2c_bit_add_bus);
EXPORT_SYMBOL(i2c_bit_del_bus);
#endif
int init_module(void)
{
+1 -3
View File
@@ -17,7 +17,7 @@
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.c,v 1.5 1998/09/28 06:45:38 i2c Exp i2c $";
static char rcsid[] = "$Id: bit-lp.c,v 1.1 1998/11/02 20:29:27 frodo Exp $";
/* ------------------------------------------------------------------------- */
#include <linux/kernel.h>
@@ -151,8 +151,6 @@ MODULE_DESCRIPTION("I2C-Bus adapter routines for Philips parallel port adapter")
MODULE_PARM(base, "i");
EXPORT_NO_SYMBOLS;
int init_module(void)
{
if (base==0) {
+53
View File
@@ -0,0 +1,53 @@
# Module.mk - Makefile for 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.
# Note that MODULE_DIR (the directory in which this file resides) is a
# 'simply expanded variable'. That means that its value is substituted
# verbatim in the rules, until it is redefined.
MODULE_DIR := i2c/detect
# Regrettably, even 'simply expanded variables' will not put their currently
# defined value verbatim into the command-list of rules...
I2CDETECTTARGETS := $(MODULE_DIR)/detect
I2CDETECTSOURCES := $(MODULE_DIR)/detect.c
# Include all dependency files
include $(I2CDETECTSOURCES:.c=.d)
all :: $(I2CDETECTTARGETS)
# No install rule
clean ::
$(RM) $(I2CDETECTSOURCES:.c=.d) $(I2CDETECTSOURCES:.c=.o) \
$(I2CDETECTTARGETS)
# The targets
$(MODULE_DIR)/detect: $(MODULE_DIR)/detect.o
# Oops, we need to use EXCFLAGS instead of CFLAGS... And we have to deal with
# an executable. Ugly code approaching... :-)
$(I2CDETECTSOURCES:.c=.o):
$(CC) $(EXCFLAGS) -c $(@:.o=.c) -o $@
$(I2CDETECTSOURCES:.c=.d):
$(CC) -M -MG $(EXCFLAGS) $(@:.d=.c) | \
sed -e \
's@^\(.*\)\.o:@$@ $(@:.d=.o) Makefile '`dirname $@`/Module.mk':@' > $@
+37
View File
@@ -0,0 +1,37 @@
# Module.mk - Makefile for 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.
# Note that MODULE_DIR (the directory in which this file resides) is a
# 'simply expanded variable'. That means that its value is substituted
# verbatim in the rules, until it is redefined.
MODULE_DIR := i2c/drivers
# Regrettably, even 'simply expanded variables' will not put their currently
# defined value verbatim into the command-list of rules...
I2CDRIVERTARGETS := $(MODULE_DIR)/eeprom.o
# Include all dependency files
include $(I2CDRIVERTARGETS:.o=.d)
all :: $(I2CDRIVERTARGETS)
install ::
$(MKDIR) $(MODDIR)
install -o root -g root -m 644 $(I2CDRIVERTARGETS) $(MODDIR)
clean ::
$(RM) $(I2CDRIVERTARGETS) $(I2CDRIVERTARGETS:.o=.d)
+53
View File
@@ -0,0 +1,53 @@
# Module.mk - Makefile for 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.
# Note that MODULE_DIR (the directory in which this file resides) is a
# 'simply expanded variable'. That means that its value is substituted
# verbatim in the rules, until it is redefined.
MODULE_DIR := i2c/eeprom
# Regrettably, even 'simply expanded variables' will not put their currently
# defined value verbatim into the command-list of rules...
I2CEEPROMTARGETS := $(MODULE_DIR)/eeprom
I2CEEPROMSOURCES := $(MODULE_DIR)/eeprom.c
# Include all dependency files
include $(I2CEEPROMSOURCES:.c=.d)
all :: $(I2CEEPROMTARGETS)
# No install rule
clean ::
$(RM) $(I2CEEPROMSOURCES:.c=.d) $(I2CEEPROMSOURCES:.c=.o) \
$(I2CEEPROMTARGETS)
# The targets
$(MODULE_DIR)/eeprom: $(MODULE_DIR)/eeprom.o
# Oops, we need to use EXCFLAGS instead of CFLAGS... And we have to deal with
# an executable. Ugly code approaching... :-)
$(I2CEEPROMSOURCES:.c=.o):
$(CC) $(EXCFLAGS) -c $(@:.o=.c) -o $@
$(I2CEEPROMSOURCES:.c=.d):
$(CC) -M -MG $(EXCFLAGS) $(@:.d=.c) | \
sed -e \
's@^\(.*\)\.o:@$@ $(@:.d=.o) Makefile '`dirname $@`/Module.mk':@' > $@
+1 -17
View File
@@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* ------------------------------------------------------------------------- */
#define RCSID "$Id: i2c-core.c,v 1.1 1998/11/02 20:29:27 frodo Exp $"
#define RCSID "$Id: i2c-core.c,v 1.2 1998/11/03 03:48:44 phil Exp $"
/* ------------------------------------------------------------------------- */
#include <linux/module.h>
@@ -441,22 +441,6 @@ MODULE_DESCRIPTION("I2C-Bus main module");
MODULE_PARM(i2c_debug, "i");
MODULE_PARM_DESC(i2c_debug,"debug level");
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0))
EXPORT_SYMBOL(i2c_add_algorithm);
EXPORT_SYMBOL(i2c_del_algorithm);
EXPORT_SYMBOL(i2c_add_adapter);
EXPORT_SYMBOL(i2c_del_adapter);
EXPORT_SYMBOL(i2c_add_driver);
EXPORT_SYMBOL(i2c_del_driver);
EXPORT_SYMBOL(i2c_attach_client);
EXPORT_SYMBOL(i2c_detach_client);
EXPORT_SYMBOL(i2c_master_send);
EXPORT_SYMBOL(i2c_master_recv);
EXPORT_SYMBOL(i2c_control);
EXPORT_SYMBOL(i2c_transfer);
#endif
int init_module(void)
{
return i2c_init();
+1 -3
View File
@@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* ------------------------------------------------------------------------- */
#define RCSID "$Id: i2c-dev.c,v 1.6 1998/09/28 06:45:38 i2c Exp i2c $"
#define RCSID "$Id: i2c-dev.c,v 1.1 1998/11/02 20:29:27 frodo Exp $"
/* ------------------------------------------------------------------------- */
#include <linux/kernel.h>
@@ -337,8 +337,6 @@ struct i2c_driver driver = {
MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
MODULE_DESCRIPTION("I2C-Bus character device interface");
EXPORT_NO_SYMBOLS;
int init_module(void)
{
if (register_chrdev(I2C_MAJOR,"i2c",&i2c_fops)) {
+37
View File
@@ -0,0 +1,37 @@
# Module.mk - Makefile for 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.
# Note that MODULE_DIR (the directory in which this file resides) is a
# 'simply expanded variable'. That means that its value is substituted
# verbatim in the rules, until it is redefined.
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
# Include all dependency files
include $(SRCTARGETS:.o=.d)
all :: $(SRCTARGETS)
install ::
$(MKDIR) $(MODDIR)
install -o root -g root -m 644 $(SRCTARGETS) $(MODDIR)
clean ::
$(RM) $(SRCTARGETS) $(SRCTARGETS:.o=.d)
+270
View File
@@ -0,0 +1,270 @@
/*
smbus.h - 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.
*/
#ifndef SENSORS_SMBUS_H
#define SENSORS_SMBUS_H
/* This file must interface with Simon Vogl's i2c driver. Version 19981006 is
OK, earlier versions are not; later versions will probably give problems
too.
*/
#ifdef I2C
#include "i2c/i2c.h"
#else /* def I2C */
#include <linux/i2c.h>
#endif /* def I2C */
#include <asm/types.h>
/* SPINLOCK is defined in i2c.h. */
#ifdef SPINLOCK
#include <asm/spinlock.h>
#else
#include <asm/semaphore.h>
#endif
/* Declarations, to keep the compiler happy */
struct smbus_driver;
struct smbus_client;
struct smbus_algorithm;
struct smbus_adapter;
union smbus_data;
/* A driver tells us how we should handle a specific kind of chip.
A specific instance of such a chip is called a client.
This structure is essentially the same as i2c_driver. */
struct smbus_driver {
char name[32];
int id;
unsigned int flags;
int (* attach_adapter) (struct smbus_adapter *);
int (* detach_client) (struct smbus_client *);
int (* command) (struct smbus_client *, unsigned int cmd, void *arg);
void (* inc_use) (struct smbus_client *);
void (* dec_use) (struct smbus_client *);
};
/* A client is a specifc instance of a chip: for each detected chip, there will
be a client. Its operation is controlled by a driver.
This structure is essentially the same as i2c_client. */
struct smbus_client {
char name[32];
int id;
unsigned int flags;
unsigned char addr;
struct smbus_adapter *adapter;
struct smbus_driver *driver;
void *data;
};
/* An algorithm describes how a certain class of busses can be accessed.
A specific instance of sucj a bus is called an adapter.
This structure is essentially the same as i2c_adapter. */
struct smbus_algorithm {
char name[32];
unsigned int id;
int (* master_xfer) (struct smbus_adapter *adap, struct i2c_msg msgs[],
int num);
int (* slave_send) (struct smbus_adapter *,char *, int);
int (* slave_recv) (struct smbus_adapter *,char *, int);
int (* algo_control) (struct smbus_adapter *, unsigned int, unsigned long);
int (* client_register) (struct smbus_client *);
int (* client_unregister) (struct smbus_client *);
};
/* An adapter is a specifc instance of a bus: for each detected bus, there will
be an adapter. Its operation is controlled by an algorithm.
SPINLOCK must be the same as declared in i2c.h.
This structure is an extension of i2c_algorithm. */
struct smbus_adapter {
char name[32];
unsigned int id;
struct smbus_algorithm *algo;
void *data;
#ifdef SPINLOCK
spinlock_t lock;
unsigned long lockflags;
#else
struct semaphore lock;
#endif
unsigned int flags;
struct smbus_client *clients[I2C_CLIENT_MAX];
int client_count;
int timeout;
int retries;
/* Here ended i2c_algorithm */
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.
Note that any and all adapters using a non-i2c driver use in this
setup ALGO_SMBUS. Adapters define their own smbus access routine.
This also means that adapter->smbus_access is only available if
this flag is set! */
#define ALGO_SMBUS 0x40000
/* This union is used within smbus_access routines */
union smbus_data {
__u8 byte;
__u16 word;
__u8 block[32];
};
/* smbus_access read or write markers */
#define SMBUS_READ 1
#define SMBUS_WRITE 0
/* SMBus transaction types (size parameter in the above functions)
Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
#define SMBUS_QUICK 0
#define SMBUS_BYTE 1
#define SMBUS_BYTE_DATA 2
#define SMBUS_WORD_DATA 3
#define SMBUS_PROC_CALL 4
#define SMBUS_BLOCK_DATA 5
/* Declare an algorithm structure. All SMBus derived adapters should use this
algorithm! */
extern struct smbus_algorithm smbus_algorithm;
/* This is the very generalized SMBus access routine. You probably do not
want to use this, though; one of the functions below may be much easier,
and probably just as fast. */
extern s32 smbus_access (struct smbus_adapter * adapter, u8 addr,
char read_write, u8 command, int size,
union smbus_data * data);
/* Now follow the 'nice' access routines. These also document the calling
conventions of smbus_access. */
extern inline s32 smbus_write_quick(struct smbus_adapter * adapter, u8 addr,
u8 value)
{
return smbus_access(adapter,addr,value,0,SMBUS_QUICK,NULL);
}
extern inline s32 smbus_read_byte(struct smbus_adapter * adapter,u8 addr)
{
union smbus_data data;
if (smbus_access(adapter,addr,SMBUS_READ,0,SMBUS_BYTE,&data))
return -1;
else
return data.byte;
}
extern inline s32 smbus_write_byte(struct smbus_adapter * adapter, u8 addr,
u8 value)
{
return smbus_access(adapter,addr,SMBUS_WRITE,value, SMBUS_BYTE,NULL);
}
extern inline s32 smbus_read_byte_data(struct smbus_adapter * adapter,
u8 addr, u8 command)
{
union smbus_data data;
if (smbus_access(adapter,addr,SMBUS_READ,command,SMBUS_BYTE_DATA,&data))
return -1;
else
return data.byte;
}
extern inline s32 smbus_write_byte_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u8 value)
{
union smbus_data data;
data.byte = value;
return smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_BYTE_DATA,&data);
}
extern inline s32 smbus_read_word_data(struct smbus_adapter * adapter,
u8 addr, u8 command)
{
union smbus_data data;
if (smbus_access(adapter,addr,SMBUS_READ,command,SMBUS_WORD_DATA,&data))
return -1;
else
return data.word;
}
extern inline s32 smbus_write_word_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u16 value)
{
union smbus_data data;
data.word = value;
return smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_WORD_DATA,&data);
}
extern inline s32 smbus_process_call(struct smbus_adapter * adapter,
u8 addr, u8 command, u16 value)
{
union smbus_data data;
data.word = value;
if (smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_PROC_CALL,&data))
return -1;
else
return data.word;
}
/* Returns the number of read bytes */
extern inline s32 smbus_read_block_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u8 *values)
{
union smbus_data data;
int i;
if (smbus_access(adapter,addr,SMBUS_READ,command,SMBUS_BLOCK_DATA,&data))
return -1;
else {
for (i = 1; i <= data.block[0]; i++)
values[i-1] = data.block[i];
return data.block[0];
}
}
extern inline int smbus_write_block_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u8 length,
u8 *values)
{
union smbus_data data;
int i;
if (length > 32)
length = 32;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
return smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_BLOCK_DATA,&data);
}
/* Next: define SMBus variants of registering. */
extern int smbus_add_algorithm(struct smbus_algorithm *algorithm);
extern int smbus_del_algorithm(struct smbus_algorithm *algorithm);
extern int smbus_add_adapter(struct smbus_adapter *adapter);
extern int smbus_del_adapter(struct smbus_adapter *adapter);
extern int smbus_add_driver(struct smbus_driver *driver);
extern int smbus_del_driver(struct smbus_driver *driver);
extern int smbus_attach_client(struct smbus_client *client);
extern int smbus_detach_client(struct smbus_client *client);
#endif /* ndef SENSORS_SMBUS_H */
+215
View File
@@ -0,0 +1,215 @@
/*
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 s32 smbus_access_i2c (struct smbus_adapter * adapter, u8 addr,
char read_write, u8 command, int size,
union smbus_data * data);
static int smbus_master_xfer (struct smbus_adapter *adap,
struct i2c_msg msgs[], int num);
static int smbus_slave_send (struct smbus_adapter *adap, char *data, int len);
static int smbus_slave_recv (struct smbus_adapter *adap, char *data, int len);
static int smbus_algo_control (struct smbus_adapter *adap, unsigned int cmd,
unsigned long arg);
static int smbus_client_register (struct smbus_client *client);
static int smbus_client_unregister (struct smbus_client *client);
static int smbus_init(void);
static int smbus_cleanup(void);
#ifdef MODULE
extern int init_module(void);
extern int cleanup_module(void);
#endif /* MODULE */
/* This is the actual algorithm we define */
struct smbus_algorithm smbus_algorithm = {
/* name */ "Non-I2C SMBus adapter",
/* id */ ALGO_SMBUS,
/* master_xfer */ &smbus_master_xfer,
/* slave_send */ &smbus_slave_send,
/* slave_rcv */ &smbus_slave_recv,
/* algo_control */ &smbus_algo_control,
/* client_register */ &smbus_client_register,
/* client_unregister*/&smbus_client_unregister
};
/* 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. */
s32 smbus_access (struct smbus_adapter * adapter, u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
if (adapter->id & ALGO_SMBUS)
return adapter->smbus_access(addr,read_write,command,size,data);
else
return smbus_access_i2c(adapter,addr,read_write,command,size,data);
}
/* Simulate a SMBus command using the i2c protocol
No checking of paramters is done!
For SMBUS_QUICK: Use addr, read_write
For SMBUS_BYTE: Use addr, read_write, command
.... */
s32 smbus_access_i2c(struct smbus_adapter * adapter, u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
/* So we need to generate a series of msgs */
struct i2c_msg msg[2];
char msgbuf0[2];
char msgbuf1[32];
msg[0].addr = addr;
msg[0].flags = read_write;
msg[0].len = 0;
msg[0].buf = msgbuf0;
/* WHATEVER */
}
/* Algorithm master_xfer call-back implementation. Can't do that... */
int smbus_master_xfer (struct smbus_adapter *adap, struct i2c_msg msgs[],
int num)
{
printk("smbus_master_xfer called for adapter `%s' "
"(no i2c level access possible!)\n",
adap->name);
return 0;
}
/* Algorithm slave_send call-back implementation. Can't do that... */
int smbus_slave_send (struct smbus_adapter *adap, char *data, int len)
{
printk("smbus_slave_send called for adapter `%s' "
"(no i2c level access possible!)\n",
adap->name);
return 0;
}
/* Algorithm slave_recv call-back implementation. Can't do that... */
int smbus_slave_recv (struct smbus_adapter *adap, char *data, int len)
{
printk("smbus_slave_recv called for adapter `%s' "
"(no i2c level access possible!)\n",
adap->name);
return 0;
}
/* Here we can put additional calls to modify the workings of the algorithm.
But right now, there is no need for that. */
int smbus_algo_control (struct smbus_adapter *adap, unsigned int cmd,
unsigned long arg)
{
return 0;
}
/* Ehm... This is called when a client is registered to an adapter. We could
do all kinds of neat stuff here like, ehm - returning success? */
int smbus_client_register (struct smbus_client *client)
{
return 0;
}
int smbus_client_unregister (struct smbus_client *client)
{
return 0;
}
/* Next: define SMBus variants of registering. Very boring. To make it possible
to change these definitions in the future without recompiling all modules,
we do not define them as inline. */
int smbus_add_algorithm(struct smbus_algorithm *algorithm)
{
return i2c_add_algorithm( (struct i2c_algorithm *) algorithm);
}
int smbus_del_algorithm(struct smbus_algorithm *algorithm)
{
return i2c_del_algorithm( (struct i2c_algorithm *) algorithm);
}
int smbus_add_adapter(struct smbus_adapter *adapter)
{
return i2c_add_adapter( (struct i2c_adapter *) adapter);
}
int smbus_del_adapter(struct smbus_adapter *adapter)
{
return i2c_del_adapter( (struct i2c_adapter *) adapter);
}
int smbus_add_driver(struct smbus_driver *driver)
{
return i2c_add_driver( (struct i2c_driver *) driver);
}
int smbus_del_driver(struct smbus_driver *driver)
{
return i2c_del_driver( (struct i2c_driver *) driver);
}
int smbus_attach_client(struct smbus_client *client)
{
return i2c_attach_client( (struct i2c_client *) client);
}
int smbus_detach_client(struct smbus_client *client)
{
return i2c_detach_client( (struct i2c_client *) client);
}
int smbus_init(void)
{
int res;
if ((res = smbus_add_algorithm(&smbus_algorithm)))
printk("Module smbus.o not inserted!\n");
else
printk("smbus.o initialized");
return res;
}
int smbus_cleanup(void)
{
int res;
if ((res = smbus_del_algorithm(&smbus_algorithm)))
printk("Module smbus.o could not be removed cleanly!\n");
return res;
}
/* OK, this will for now _only_ compile as a module, but this is neat for
later, if we want to compile it straight into the kernel */
#ifdef MODULE
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("System Management Bus (SMBus) access");
int init_module(void)
{
return smbus_init();
}
int cleanup_module(void)
{
return smbus_cleanup();
}
#endif /* MODULE */
+37
View File
@@ -0,0 +1,37 @@
# Module.mk - Makefile for 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.
# Note that MODULE_DIR (the directory in which this file resides) is a
# 'simply expanded variable'. That means that its value is substituted
# verbatim in the rules, until it is redefined.
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
# Include all dependency files
include $(SRCTARGETS:.o=.d)
all :: $(SRCTARGETS)
install ::
$(MKDIR) $(MODDIR)
install -o root -g root -m 644 $(SRCTARGETS) $(MODDIR)
clean ::
$(RM) $(SRCTARGETS) $(SRCTARGETS:.o=.d)
+215
View File
@@ -0,0 +1,215 @@
/*
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 s32 smbus_access_i2c (struct smbus_adapter * adapter, u8 addr,
char read_write, u8 command, int size,
union smbus_data * data);
static int smbus_master_xfer (struct smbus_adapter *adap,
struct i2c_msg msgs[], int num);
static int smbus_slave_send (struct smbus_adapter *adap, char *data, int len);
static int smbus_slave_recv (struct smbus_adapter *adap, char *data, int len);
static int smbus_algo_control (struct smbus_adapter *adap, unsigned int cmd,
unsigned long arg);
static int smbus_client_register (struct smbus_client *client);
static int smbus_client_unregister (struct smbus_client *client);
static int smbus_init(void);
static int smbus_cleanup(void);
#ifdef MODULE
extern int init_module(void);
extern int cleanup_module(void);
#endif /* MODULE */
/* This is the actual algorithm we define */
struct smbus_algorithm smbus_algorithm = {
/* name */ "Non-I2C SMBus adapter",
/* id */ ALGO_SMBUS,
/* master_xfer */ &smbus_master_xfer,
/* slave_send */ &smbus_slave_send,
/* slave_rcv */ &smbus_slave_recv,
/* algo_control */ &smbus_algo_control,
/* client_register */ &smbus_client_register,
/* client_unregister*/&smbus_client_unregister
};
/* 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. */
s32 smbus_access (struct smbus_adapter * adapter, u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
if (adapter->id & ALGO_SMBUS)
return adapter->smbus_access(addr,read_write,command,size,data);
else
return smbus_access_i2c(adapter,addr,read_write,command,size,data);
}
/* Simulate a SMBus command using the i2c protocol
No checking of paramters is done!
For SMBUS_QUICK: Use addr, read_write
For SMBUS_BYTE: Use addr, read_write, command
.... */
s32 smbus_access_i2c(struct smbus_adapter * adapter, u8 addr, char read_write,
u8 command, int size, union smbus_data * data)
{
/* So we need to generate a series of msgs */
struct i2c_msg msg[2];
char msgbuf0[2];
char msgbuf1[32];
msg[0].addr = addr;
msg[0].flags = read_write;
msg[0].len = 0;
msg[0].buf = msgbuf0;
/* WHATEVER */
}
/* Algorithm master_xfer call-back implementation. Can't do that... */
int smbus_master_xfer (struct smbus_adapter *adap, struct i2c_msg msgs[],
int num)
{
printk("smbus_master_xfer called for adapter `%s' "
"(no i2c level access possible!)\n",
adap->name);
return 0;
}
/* Algorithm slave_send call-back implementation. Can't do that... */
int smbus_slave_send (struct smbus_adapter *adap, char *data, int len)
{
printk("smbus_slave_send called for adapter `%s' "
"(no i2c level access possible!)\n",
adap->name);
return 0;
}
/* Algorithm slave_recv call-back implementation. Can't do that... */
int smbus_slave_recv (struct smbus_adapter *adap, char *data, int len)
{
printk("smbus_slave_recv called for adapter `%s' "
"(no i2c level access possible!)\n",
adap->name);
return 0;
}
/* Here we can put additional calls to modify the workings of the algorithm.
But right now, there is no need for that. */
int smbus_algo_control (struct smbus_adapter *adap, unsigned int cmd,
unsigned long arg)
{
return 0;
}
/* Ehm... This is called when a client is registered to an adapter. We could
do all kinds of neat stuff here like, ehm - returning success? */
int smbus_client_register (struct smbus_client *client)
{
return 0;
}
int smbus_client_unregister (struct smbus_client *client)
{
return 0;
}
/* Next: define SMBus variants of registering. Very boring. To make it possible
to change these definitions in the future without recompiling all modules,
we do not define them as inline. */
int smbus_add_algorithm(struct smbus_algorithm *algorithm)
{
return i2c_add_algorithm( (struct i2c_algorithm *) algorithm);
}
int smbus_del_algorithm(struct smbus_algorithm *algorithm)
{
return i2c_del_algorithm( (struct i2c_algorithm *) algorithm);
}
int smbus_add_adapter(struct smbus_adapter *adapter)
{
return i2c_add_adapter( (struct i2c_adapter *) adapter);
}
int smbus_del_adapter(struct smbus_adapter *adapter)
{
return i2c_del_adapter( (struct i2c_adapter *) adapter);
}
int smbus_add_driver(struct smbus_driver *driver)
{
return i2c_add_driver( (struct i2c_driver *) driver);
}
int smbus_del_driver(struct smbus_driver *driver)
{
return i2c_del_driver( (struct i2c_driver *) driver);
}
int smbus_attach_client(struct smbus_client *client)
{
return i2c_attach_client( (struct i2c_client *) client);
}
int smbus_detach_client(struct smbus_client *client)
{
return i2c_detach_client( (struct i2c_client *) client);
}
int smbus_init(void)
{
int res;
if ((res = smbus_add_algorithm(&smbus_algorithm)))
printk("Module smbus.o not inserted!\n");
else
printk("smbus.o initialized");
return res;
}
int smbus_cleanup(void)
{
int res;
if ((res = smbus_del_algorithm(&smbus_algorithm)))
printk("Module smbus.o could not be removed cleanly!\n");
return res;
}
/* OK, this will for now _only_ compile as a module, but this is neat for
later, if we want to compile it straight into the kernel */
#ifdef MODULE
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("System Management Bus (SMBus) access");
int init_module(void)
{
return smbus_init();
}
int cleanup_module(void)
{
return smbus_cleanup();
}
#endif /* MODULE */
+270
View File
@@ -0,0 +1,270 @@
/*
smbus.h - 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.
*/
#ifndef SENSORS_SMBUS_H
#define SENSORS_SMBUS_H
/* This file must interface with Simon Vogl's i2c driver. Version 19981006 is
OK, earlier versions are not; later versions will probably give problems
too.
*/
#ifdef I2C
#include "i2c/i2c.h"
#else /* def I2C */
#include <linux/i2c.h>
#endif /* def I2C */
#include <asm/types.h>
/* SPINLOCK is defined in i2c.h. */
#ifdef SPINLOCK
#include <asm/spinlock.h>
#else
#include <asm/semaphore.h>
#endif
/* Declarations, to keep the compiler happy */
struct smbus_driver;
struct smbus_client;
struct smbus_algorithm;
struct smbus_adapter;
union smbus_data;
/* A driver tells us how we should handle a specific kind of chip.
A specific instance of such a chip is called a client.
This structure is essentially the same as i2c_driver. */
struct smbus_driver {
char name[32];
int id;
unsigned int flags;
int (* attach_adapter) (struct smbus_adapter *);
int (* detach_client) (struct smbus_client *);
int (* command) (struct smbus_client *, unsigned int cmd, void *arg);
void (* inc_use) (struct smbus_client *);
void (* dec_use) (struct smbus_client *);
};
/* A client is a specifc instance of a chip: for each detected chip, there will
be a client. Its operation is controlled by a driver.
This structure is essentially the same as i2c_client. */
struct smbus_client {
char name[32];
int id;
unsigned int flags;
unsigned char addr;
struct smbus_adapter *adapter;
struct smbus_driver *driver;
void *data;
};
/* An algorithm describes how a certain class of busses can be accessed.
A specific instance of sucj a bus is called an adapter.
This structure is essentially the same as i2c_adapter. */
struct smbus_algorithm {
char name[32];
unsigned int id;
int (* master_xfer) (struct smbus_adapter *adap, struct i2c_msg msgs[],
int num);
int (* slave_send) (struct smbus_adapter *,char *, int);
int (* slave_recv) (struct smbus_adapter *,char *, int);
int (* algo_control) (struct smbus_adapter *, unsigned int, unsigned long);
int (* client_register) (struct smbus_client *);
int (* client_unregister) (struct smbus_client *);
};
/* An adapter is a specifc instance of a bus: for each detected bus, there will
be an adapter. Its operation is controlled by an algorithm.
SPINLOCK must be the same as declared in i2c.h.
This structure is an extension of i2c_algorithm. */
struct smbus_adapter {
char name[32];
unsigned int id;
struct smbus_algorithm *algo;
void *data;
#ifdef SPINLOCK
spinlock_t lock;
unsigned long lockflags;
#else
struct semaphore lock;
#endif
unsigned int flags;
struct smbus_client *clients[I2C_CLIENT_MAX];
int client_count;
int timeout;
int retries;
/* Here ended i2c_algorithm */
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.
Note that any and all adapters using a non-i2c driver use in this
setup ALGO_SMBUS. Adapters define their own smbus access routine.
This also means that adapter->smbus_access is only available if
this flag is set! */
#define ALGO_SMBUS 0x40000
/* This union is used within smbus_access routines */
union smbus_data {
__u8 byte;
__u16 word;
__u8 block[32];
};
/* smbus_access read or write markers */
#define SMBUS_READ 1
#define SMBUS_WRITE 0
/* SMBus transaction types (size parameter in the above functions)
Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
#define SMBUS_QUICK 0
#define SMBUS_BYTE 1
#define SMBUS_BYTE_DATA 2
#define SMBUS_WORD_DATA 3
#define SMBUS_PROC_CALL 4
#define SMBUS_BLOCK_DATA 5
/* Declare an algorithm structure. All SMBus derived adapters should use this
algorithm! */
extern struct smbus_algorithm smbus_algorithm;
/* This is the very generalized SMBus access routine. You probably do not
want to use this, though; one of the functions below may be much easier,
and probably just as fast. */
extern s32 smbus_access (struct smbus_adapter * adapter, u8 addr,
char read_write, u8 command, int size,
union smbus_data * data);
/* Now follow the 'nice' access routines. These also document the calling
conventions of smbus_access. */
extern inline s32 smbus_write_quick(struct smbus_adapter * adapter, u8 addr,
u8 value)
{
return smbus_access(adapter,addr,value,0,SMBUS_QUICK,NULL);
}
extern inline s32 smbus_read_byte(struct smbus_adapter * adapter,u8 addr)
{
union smbus_data data;
if (smbus_access(adapter,addr,SMBUS_READ,0,SMBUS_BYTE,&data))
return -1;
else
return data.byte;
}
extern inline s32 smbus_write_byte(struct smbus_adapter * adapter, u8 addr,
u8 value)
{
return smbus_access(adapter,addr,SMBUS_WRITE,value, SMBUS_BYTE,NULL);
}
extern inline s32 smbus_read_byte_data(struct smbus_adapter * adapter,
u8 addr, u8 command)
{
union smbus_data data;
if (smbus_access(adapter,addr,SMBUS_READ,command,SMBUS_BYTE_DATA,&data))
return -1;
else
return data.byte;
}
extern inline s32 smbus_write_byte_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u8 value)
{
union smbus_data data;
data.byte = value;
return smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_BYTE_DATA,&data);
}
extern inline s32 smbus_read_word_data(struct smbus_adapter * adapter,
u8 addr, u8 command)
{
union smbus_data data;
if (smbus_access(adapter,addr,SMBUS_READ,command,SMBUS_WORD_DATA,&data))
return -1;
else
return data.word;
}
extern inline s32 smbus_write_word_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u16 value)
{
union smbus_data data;
data.word = value;
return smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_WORD_DATA,&data);
}
extern inline s32 smbus_process_call(struct smbus_adapter * adapter,
u8 addr, u8 command, u16 value)
{
union smbus_data data;
data.word = value;
if (smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_PROC_CALL,&data))
return -1;
else
return data.word;
}
/* Returns the number of read bytes */
extern inline s32 smbus_read_block_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u8 *values)
{
union smbus_data data;
int i;
if (smbus_access(adapter,addr,SMBUS_READ,command,SMBUS_BLOCK_DATA,&data))
return -1;
else {
for (i = 1; i <= data.block[0]; i++)
values[i-1] = data.block[i];
return data.block[0];
}
}
extern inline int smbus_write_block_data(struct smbus_adapter * adapter,
u8 addr, u8 command, u8 length,
u8 *values)
{
union smbus_data data;
int i;
if (length > 32)
length = 32;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
return smbus_access(adapter,addr,SMBUS_WRITE,command,SMBUS_BLOCK_DATA,&data);
}
/* Next: define SMBus variants of registering. */
extern int smbus_add_algorithm(struct smbus_algorithm *algorithm);
extern int smbus_del_algorithm(struct smbus_algorithm *algorithm);
extern int smbus_add_adapter(struct smbus_adapter *adapter);
extern int smbus_del_adapter(struct smbus_adapter *adapter);
extern int smbus_add_driver(struct smbus_driver *driver);
extern int smbus_del_driver(struct smbus_driver *driver);
extern int smbus_attach_client(struct smbus_client *client);
extern int smbus_detach_client(struct smbus_client *client);
#endif /* ndef SENSORS_SMBUS_H */