aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/i2c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /Documentation/i2c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'Documentation/i2c')
-rw-r--r--Documentation/i2c/busses/i2c-ali153542
-rw-r--r--Documentation/i2c/busses/i2c-ali156327
-rw-r--r--Documentation/i2c/busses/i2c-ali15x3112
-rw-r--r--Documentation/i2c/busses/i2c-amd75625
-rw-r--r--Documentation/i2c/busses/i2c-amd811141
-rw-r--r--Documentation/i2c/busses/i2c-i80180
-rw-r--r--Documentation/i2c/busses/i2c-i81046
-rw-r--r--Documentation/i2c/busses/i2c-nforce241
-rw-r--r--Documentation/i2c/busses/i2c-parport154
-rw-r--r--Documentation/i2c/busses/i2c-parport-light11
-rw-r--r--Documentation/i2c/busses/i2c-pca-isa23
-rw-r--r--Documentation/i2c/busses/i2c-piix472
-rw-r--r--Documentation/i2c/busses/i2c-prosavage23
-rw-r--r--Documentation/i2c/busses/i2c-savage426
-rw-r--r--Documentation/i2c/busses/i2c-sis559559
-rw-r--r--Documentation/i2c/busses/i2c-sis63049
-rw-r--r--Documentation/i2c/busses/i2c-sis69x73
-rw-r--r--Documentation/i2c/busses/i2c-via34
-rw-r--r--Documentation/i2c/busses/i2c-viapro47
-rw-r--r--Documentation/i2c/busses/i2c-voodoo362
-rw-r--r--Documentation/i2c/busses/scx200_acb14
-rw-r--r--Documentation/i2c/chips/smsc47b397.txt146
-rw-r--r--Documentation/i2c/dev-interface146
-rw-r--r--Documentation/i2c/functionality135
-rw-r--r--Documentation/i2c/i2c-protocol76
-rw-r--r--Documentation/i2c/i2c-stub38
-rw-r--r--Documentation/i2c/porting-clients133
-rw-r--r--Documentation/i2c/smbus-protocol216
-rw-r--r--Documentation/i2c/summary75
-rw-r--r--Documentation/i2c/sysfs-interface274
-rw-r--r--Documentation/i2c/ten-bit-addresses22
-rw-r--r--Documentation/i2c/writing-clients816
32 files changed, 3138 insertions, 0 deletions
diff --git a/Documentation/i2c/busses/i2c-ali1535 b/Documentation/i2c/busses/i2c-ali1535
new file mode 100644
index 000000000000..0db3b4c74ad1
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-ali1535
@@ -0,0 +1,42 @@
1Kernel driver i2c-ali1535
2
3Supported adapters:
4 * Acer Labs, Inc. ALI 1535 (south bridge)
5 Datasheet: Now under NDA
6 http://www.ali.com.tw/eng/support/datasheet_request.php
7
8Authors:
9 Frodo Looijaard <frodol@dds.nl>,
10 Philip Edelbrock <phil@netroedge.com>,
11 Mark D. Studebaker <mdsxyz123@yahoo.com>,
12 Dan Eaton <dan.eaton@rocketlogix.com>,
13 Stephen Rousset<stephen.rousset@rocketlogix.com>
14
15Description
16-----------
17
18This is the driver for the SMB Host controller on Acer Labs Inc. (ALI)
19M1535 South Bridge.
20
21The M1535 is a South bridge for portable systems. It is very similar to the
22M15x3 South bridges also produced by Acer Labs Inc. Some of the registers
23within the part have moved and some have been redefined slightly.
24Additionally, the sequencing of the SMBus transactions has been modified to
25be more consistent with the sequencing recommended by the manufacturer and
26observed through testing. These changes are reflected in this driver and
27can be identified by comparing this driver to the i2c-ali15x3 driver. For
28an overview of these chips see http://www.acerlabs.com
29
30The SMB controller is part of the M7101 device, which is an ACPI-compliant
31Power Management Unit (PMU).
32
33The whole M7101 device has to be enabled for the SMB to work. You can't
34just enable the SMB alone. The SMB and the ACPI have separate I/O spaces.
35We make sure that the SMB is enabled. We leave the ACPI alone.
36
37
38Features
39--------
40
41This driver controls the SMB Host only. This driver does not use
42interrupts.
diff --git a/Documentation/i2c/busses/i2c-ali1563 b/Documentation/i2c/busses/i2c-ali1563
new file mode 100644
index 000000000000..99ad4b9bcc32
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-ali1563
@@ -0,0 +1,27 @@
1Kernel driver i2c-ali1563
2
3Supported adapters:
4 * Acer Labs, Inc. ALI 1563 (south bridge)
5 Datasheet: Now under NDA
6 http://www.ali.com.tw/eng/support/datasheet_request.php
7
8Author: Patrick Mochel <mochel@digitalimplant.org>
9
10Description
11-----------
12
13This is the driver for the SMB Host controller on Acer Labs Inc. (ALI)
14M1563 South Bridge.
15
16For an overview of these chips see http://www.acerlabs.com
17
18The M1563 southbridge is deceptively similar to the M1533, with a few
19notable exceptions. One of those happens to be the fact they upgraded the
20i2c core to be SMBus 2.0 compliant, and happens to be almost identical to
21the i2c controller found in the Intel 801 south bridges.
22
23Features
24--------
25
26This driver controls the SMB Host only. This driver does not use
27interrupts.
diff --git a/Documentation/i2c/busses/i2c-ali15x3 b/Documentation/i2c/busses/i2c-ali15x3
new file mode 100644
index 000000000000..ff28d381bebe
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-ali15x3
@@ -0,0 +1,112 @@
1Kernel driver i2c-ali15x3
2
3Supported adapters:
4 * Acer Labs, Inc. ALI 1533 and 1543C (south bridge)
5 Datasheet: Now under NDA
6 http://www.ali.com.tw/eng/support/datasheet_request.php
7
8Authors:
9 Frodo Looijaard <frodol@dds.nl>,
10 Philip Edelbrock <phil@netroedge.com>,
11 Mark D. Studebaker <mdsxyz123@yahoo.com>
12
13Module Parameters
14-----------------
15
16* force_addr: int
17 Initialize the base address of the i2c controller
18
19
20Notes
21-----
22
23The force_addr parameter is useful for boards that don't set the address in
24the BIOS. Does not do a PCI force; the device must still be present in
25lspci. Don't use this unless the driver complains that the base address is
26not set.
27
28Example: 'modprobe i2c-ali15x3 force_addr=0xe800'
29
30SMBus periodically hangs on ASUS P5A motherboards and can only be cleared
31by a power cycle. Cause unknown (see Issues below).
32
33
34Description
35-----------
36
37This is the driver for the SMB Host controller on Acer Labs Inc. (ALI)
38M1541 and M1543C South Bridges.
39
40The M1543C is a South bridge for desktop systems.
41The M1541 is a South bridge for portable systems.
42They are part of the following ALI chipsets:
43
44 * "Aladdin Pro 2" includes the M1621 Slot 1 North bridge with AGP and
45 100MHz CPU Front Side bus
46 * "Aladdin V" includes the M1541 Socket 7 North bridge with AGP and 100MHz
47 CPU Front Side bus
48 Some Aladdin V motherboards:
49 Asus P5A
50 Atrend ATC-5220
51 BCM/GVC VP1541
52 Biostar M5ALA
53 Gigabyte GA-5AX (** Generally doesn't work because the BIOS doesn't
54 enable the 7101 device! **)
55 Iwill XA100 Plus
56 Micronics C200
57 Microstar (MSI) MS-5169
58
59 * "Aladdin IV" includes the M1541 Socket 7 North bridge
60 with host bus up to 83.3 MHz.
61
62For an overview of these chips see http://www.acerlabs.com. At this time the
63full data sheets on the web site are password protected, however if you
64contact the ALI office in San Jose they may give you the password.
65
66The M1533/M1543C devices appear as FOUR separate devices on the PCI bus. An
67output of lspci will show something similar to the following:
68
69 00:02.0 USB Controller: Acer Laboratories Inc. M5237 (rev 03)
70 00:03.0 Bridge: Acer Laboratories Inc. M7101 <= THIS IS THE ONE WE NEED
71 00:07.0 ISA bridge: Acer Laboratories Inc. M1533 (rev c3)
72 00:0f.0 IDE interface: Acer Laboratories Inc. M5229 (rev c1)
73
74** IMPORTANT **
75** If you have a M1533 or M1543C on the board and you get
76** "ali15x3: Error: Can't detect ali15x3!"
77** then run lspci.
78** If you see the 1533 and 5229 devices but NOT the 7101 device,
79** then you must enable ACPI, the PMU, SMB, or something similar
80** in the BIOS.
81** The driver won't work if it can't find the M7101 device.
82
83The SMB controller is part of the M7101 device, which is an ACPI-compliant
84Power Management Unit (PMU).
85
86The whole M7101 device has to be enabled for the SMB to work. You can't
87just enable the SMB alone. The SMB and the ACPI have separate I/O spaces.
88We make sure that the SMB is enabled. We leave the ACPI alone.
89
90Features
91--------
92
93This driver controls the SMB Host only. The SMB Slave
94controller on the M15X3 is not enabled. This driver does not use
95interrupts.
96
97
98Issues
99------
100
101This driver requests the I/O space for only the SMB
102registers. It doesn't use the ACPI region.
103
104On the ASUS P5A motherboard, there are several reports that
105the SMBus will hang and this can only be resolved by
106powering off the computer. It appears to be worse when the board
107gets hot, for example under heavy CPU load, or in the summer.
108There may be electrical problems on this board.
109On the P5A, the W83781D sensor chip is on both the ISA and
110SMBus. Therefore the SMBus hangs can generally be avoided
111by accessing the W83781D on the ISA bus only.
112
diff --git a/Documentation/i2c/busses/i2c-amd756 b/Documentation/i2c/busses/i2c-amd756
new file mode 100644
index 000000000000..67f30874d0bf
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-amd756
@@ -0,0 +1,25 @@
1Kernel driver i2c-amd756
2
3Supported adapters:
4 * AMD 756
5 * AMD 766
6 * AMD 768
7 * AMD 8111
8 Datasheets: Publicly available on AMD website
9
10 * nVidia nForce
11 Datasheet: Unavailable
12
13Authors:
14 Frodo Looijaard <frodol@dds.nl>,
15 Philip Edelbrock <phil@netroedge.com>
16
17Description
18-----------
19
20This driver supports the AMD 756, 766, 768 and 8111 Peripheral Bus
21Controllers, and the nVidia nForce.
22
23Note that for the 8111, there are two SMBus adapters. The SMBus 1.0 adapter
24is supported by this driver, and the SMBus 2.0 adapter is supported by the
25i2c-amd8111 driver.
diff --git a/Documentation/i2c/busses/i2c-amd8111 b/Documentation/i2c/busses/i2c-amd8111
new file mode 100644
index 000000000000..db294ee7455a
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-amd8111
@@ -0,0 +1,41 @@
1Kernel driver i2c-adm8111
2
3Supported adapters:
4 * AMD-8111 SMBus 2.0 PCI interface
5
6Datasheets:
7 AMD datasheet not yet available, but almost everything can be found
8 in publically available ACPI 2.0 specification, which the adapter
9 follows.
10
11Author: Vojtech Pavlik <vojtech@suse.cz>
12
13Description
14-----------
15
16If you see something like this:
17
1800:07.2 SMBus: Advanced Micro Devices [AMD] AMD-8111 SMBus 2.0 (rev 02)
19 Subsystem: Advanced Micro Devices [AMD] AMD-8111 SMBus 2.0
20 Flags: medium devsel, IRQ 19
21 I/O ports at d400 [size=32]
22
23in your 'lspci -v', then this driver is for your chipset.
24
25Process Call Support
26--------------------
27
28Supported.
29
30SMBus 2.0 Support
31-----------------
32
33Supported. Both PEC and block process call support is implemented. Slave
34mode or host notification are not yet implemented.
35
36Notes
37-----
38
39Note that for the 8111, there are two SMBus adapters. The SMBus 2.0 adapter
40is supported by this driver, and the SMBus 1.0 adapter is supported by the
41i2c-amd756 driver.
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
new file mode 100644
index 000000000000..fd4b2712d570
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-i801
@@ -0,0 +1,80 @@
1Kernel driver i2c-i801
2
3Supported adapters:
4 * Intel 82801AA and 82801AB (ICH and ICH0 - part of the
5 '810' and '810E' chipsets)
6 * Intel 82801BA (ICH2 - part of the '815E' chipset)
7 * Intel 82801CA/CAM (ICH3)
8 * Intel 82801DB (ICH4) (HW PEC supported, 32 byte buffer not supported)
9 * Intel 82801EB/ER (ICH5) (HW PEC supported, 32 byte buffer not supported)
10 * Intel 6300ESB
11 * Intel 82801FB/FR/FW/FRW (ICH6)
12 * Intel ICH7
13 Datasheets: Publicly available at the Intel website
14
15Authors:
16 Frodo Looijaard <frodol@dds.nl>,
17 Philip Edelbrock <phil@netroedge.com>,
18 Mark Studebaker <mdsxyz123@yahoo.com>
19
20
21Module Parameters
22-----------------
23
24* force_addr: int
25 Forcibly enable the ICH at the given address. EXTREMELY DANGEROUS!
26
27
28Description
29-----------
30
31The ICH (properly known as the 82801AA), ICH0 (82801AB), ICH2 (82801BA),
32ICH3 (82801CA/CAM) and later devices are Intel chips that are a part of
33Intel's '810' chipset for Celeron-based PCs, '810E' chipset for
34Pentium-based PCs, '815E' chipset, and others.
35
36The ICH chips contain at least SEVEN separate PCI functions in TWO logical
37PCI devices. An output of lspci will show something similar to the
38following:
39
40 00:1e.0 PCI bridge: Intel Corporation: Unknown device 2418 (rev 01)
41 00:1f.0 ISA bridge: Intel Corporation: Unknown device 2410 (rev 01)
42 00:1f.1 IDE interface: Intel Corporation: Unknown device 2411 (rev 01)
43 00:1f.2 USB Controller: Intel Corporation: Unknown device 2412 (rev 01)
44 00:1f.3 Unknown class [0c05]: Intel Corporation: Unknown device 2413 (rev 01)
45
46The SMBus controller is function 3 in device 1f. Class 0c05 is SMBus Serial
47Controller.
48
49If you do NOT see the 24x3 device at function 3, and you can't figure out
50any way in the BIOS to enable it,
51
52The ICH chips are quite similar to Intel's PIIX4 chip, at least in the
53SMBus controller.
54
55See the file i2c-piix4 for some additional information.
56
57
58Process Call Support
59--------------------
60
61Not supported.
62
63
64I2C Block Read Support
65----------------------
66
67Not supported at the moment.
68
69
70SMBus 2.0 Support
71-----------------
72
73The 82801DB (ICH4) and later chips support several SMBus 2.0 features.
74
75**********************
76The lm_sensors project gratefully acknowledges the support of Texas
77Instruments in the initial development of this driver.
78
79The lm_sensors project gratefully acknowledges the support of Intel in the
80development of SMBus 2.0 / ICH4 features of this driver.
diff --git a/Documentation/i2c/busses/i2c-i810 b/Documentation/i2c/busses/i2c-i810
new file mode 100644
index 000000000000..0544eb332887
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-i810
@@ -0,0 +1,46 @@
1Kernel driver i2c-i810
2
3Supported adapters:
4 * Intel 82810, 82810-DC100, 82810E, and 82815 (GMCH)
5
6Authors:
7 Frodo Looijaard <frodol@dds.nl>,
8 Philip Edelbrock <phil@netroedge.com>,
9 Kyösti Mälkki <kmalkki@cc.hut.fi>,
10 Ralph Metzler <rjkm@thp.uni-koeln.de>,
11 Mark D. Studebaker <mdsxyz123@yahoo.com>
12
13Main contact: Mark Studebaker <mdsxyz123@yahoo.com>
14
15Description
16-----------
17
18WARNING: If you have an '810' or '815' motherboard, your standard I2C
19temperature sensors are most likely on the 801's I2C bus. You want the
20i2c-i801 driver for those, not this driver.
21
22Now for the i2c-i810...
23
24The GMCH chip contains two I2C interfaces.
25
26The first interface is used for DDC (Data Display Channel) which is a
27serial channel through the VGA monitor connector to a DDC-compliant
28monitor. This interface is defined by the Video Electronics Standards
29Association (VESA). The standards are available for purchase at
30http://www.vesa.org .
31
32The second interface is a general-purpose I2C bus. It may be connected to a
33TV-out chip such as the BT869 or possibly to a digital flat-panel display.
34
35Features
36--------
37
38Both busses use the i2c-algo-bit driver for 'bit banging'
39and support for specific transactions is provided by i2c-algo-bit.
40
41Issues
42------
43
44If you enable bus testing in i2c-algo-bit (insmod i2c-algo-bit bit_test=1),
45the test may fail; if so, the i2c-i810 driver won't be inserted. However,
46we think this has been fixed.
diff --git a/Documentation/i2c/busses/i2c-nforce2 b/Documentation/i2c/busses/i2c-nforce2
new file mode 100644
index 000000000000..e379e182e64f
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-nforce2
@@ -0,0 +1,41 @@
1Kernel driver i2c-nforce2
2
3Supported adapters:
4 * nForce2 MCP 10de:0064
5 * nForce2 Ultra 400 MCP 10de:0084
6 * nForce3 Pro150 MCP 10de:00D4
7 * nForce3 250Gb MCP 10de:00E4
8 * nForce4 MCP 10de:0052
9
10Datasheet: not publically available, but seems to be similar to the
11 AMD-8111 SMBus 2.0 adapter.
12
13Authors:
14 Hans-Frieder Vogt <hfvogt@arcor.de>,
15 Thomas Leibold <thomas@plx.com>,
16 Patrick Dreker <patrick@dreker.de>
17
18Description
19-----------
20
21i2c-nforce2 is a driver for the SMBuses included in the nVidia nForce2 MCP.
22
23If your 'lspci -v' listing shows something like the following,
24
2500:01.1 SMBus: nVidia Corporation: Unknown device 0064 (rev a2)
26 Subsystem: Asustek Computer, Inc.: Unknown device 0c11
27 Flags: 66Mhz, fast devsel, IRQ 5
28 I/O ports at c000 [size=32]
29 Capabilities: <available only to root>
30
31then this driver should support the SMBuses of your motherboard.
32
33
34Notes
35-----
36
37The SMBus adapter in the nForce2 chipset seems to be very similar to the
38SMBus 2.0 adapter in the AMD-8111 southbridge. However, I could only get
39the driver to work with direct I/O access, which is different to the EC
40interface of the AMD-8111. Tested on Asus A7N8X. The ACPI DSDT table of the
41Asus A7N8X lists two SMBuses, both of which are supported by this driver.
diff --git a/Documentation/i2c/busses/i2c-parport b/Documentation/i2c/busses/i2c-parport
new file mode 100644
index 000000000000..9f1d0082da18
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-parport
@@ -0,0 +1,154 @@
1Kernel driver i2c-parport
2
3Author: Jean Delvare <khali@linux-fr.org>
4
5This is a unified driver for several i2c-over-parallel-port adapters,
6such as the ones made by Philips, Velleman or ELV. This driver is
7meant as a replacement for the older, individual drivers:
8 * i2c-philips-par
9 * i2c-elv
10 * i2c-velleman
11 * video/i2c-parport (NOT the same as this one, dedicated to home brew
12 teletext adapters)
13
14It currently supports the following devices:
15 * Philips adapter
16 * home brew teletext adapter
17 * Velleman K8000 adapter
18 * ELV adapter
19 * Analog Devices evaluation boards (ADM1025, ADM1030, ADM1031, ADM1032)
20
21These devices use different pinout configurations, so you have to tell
22the driver what you have, using the type module parameter. There is no
23way to autodetect the devices. Support for different pinout configurations
24can be easily added when needed.
25
26
27Building your own adapter
28-------------------------
29
30If you want to build you own i2c-over-parallel-port adapter, here is
31a sample electronics schema (credits go to Sylvain Munaut):
32
33Device PC
34Side ___________________Vdd (+) Side
35 | | |
36 --- --- ---
37 | | | | | |
38 |R| |R| |R|
39 | | | | | |
40 --- --- ---
41 | | |
42 | | /| |
43SCL ----------x--------o |-----------x------------------- pin 2
44 | \| | |
45 | | |
46 | |\ | |
47SDA ----------x----x---| o---x--------------------------- pin 13
48 | |/ |
49 | |
50 | /| |
51 ---------o |----------------x-------------- pin 3
52 \| | |
53 | |
54 --- ---
55 | | | |
56 |R| |R|
57 | | | |
58 --- ---
59 | |
60 ### ###
61 GND GND
62
63Remarks:
64 - This is the exact pinout and electronics used on the Analog Devices
65 evaluation boards.
66 /|
67 - All inverters -o |- must be 74HC05, they must be open collector output.
68 \|
69 - All resitors are 10k.
70 - Pins 18-25 of the parallel port connected to GND.
71 - Pins 4-9 (D2-D7) could be used as VDD is the driver drives them high.
72 The ADM1032 evaluation board uses D4-D7. Beware that the amount of
73 current you can draw from the parallel port is limited. Also note that
74 all connected lines MUST BE driven at the same state, else you'll short
75 circuit the output buffers! So plugging the I2C adapter after loading
76 the i2c-parport module might be a good safety since data line state
77 prior to init may be unknown.
78 - This is 5V!
79 - Obviously you cannot read SCL (so it's not really standard-compliant).
80 Pretty easy to add, just copy the SDA part and use another input pin.
81 That would give (ELV compatible pinout):
82
83
84Device PC
85Side ______________________________Vdd (+) Side
86 | | | |
87 --- --- --- ---
88 | | | | | | | |
89 |R| |R| |R| |R|
90 | | | | | | | |
91 --- --- --- ---
92 | | | |
93 | | |\ | |
94SCL ----------x--------x--| o---x------------------------ pin 15
95 | | |/ |
96 | | |
97 | | /| |
98 | ---o |-------------x-------------- pin 2
99 | \| | |
100 | | |
101 | | |
102 | |\ | |
103SDA ---------------x---x--| o--------x------------------- pin 10
104 | |/ |
105 | |
106 | /| |
107 ---o |------------------x--------- pin 3
108 \| | |
109 | |
110 --- ---
111 | | | |
112 |R| |R|
113 | | | |
114 --- ---
115 | |
116 ### ###
117 GND GND
118
119
120If possible, you should use the same pinout configuration as existing
121adapters do, so you won't even have to change the code.
122
123
124Similar (but different) drivers
125-------------------------------
126
127This driver is NOT the same as the i2c-pport driver found in the i2c
128package. The i2c-pport driver makes use of modern parallel port features so
129that you don't need additional electronics. It has other restrictions
130however, and was not ported to Linux 2.6 (yet).
131
132This driver is also NOT the same as the i2c-pcf-epp driver found in the
133lm_sensors package. The i2c-pcf-epp driver doesn't use the parallel port as
134an I2C bus directly. Instead, it uses it to control an external I2C bus
135master. That driver was not ported to Linux 2.6 (yet) either.
136
137
138Legacy documentation for Velleman adapter
139-----------------------------------------
140
141Useful links:
142Velleman http://www.velleman.be/
143Velleman K8000 Howto http://howto.htlw16.ac.at/k8000-howto.html
144
145The project has lead to new libs for the Velleman K8000 and K8005:
146 LIBK8000 v1.99.1 and LIBK8005 v0.21
147With these libs, you can control the K8000 interface card and the K8005
148stepper motor card with the simple commands which are in the original
149Velleman software, like SetIOchannel, ReadADchannel, SendStepCCWFull and
150many more, using /dev/velleman.
151 http://home.wanadoo.nl/hihihi/libk8000.htm
152 http://home.wanadoo.nl/hihihi/libk8005.htm
153 http://struyve.mine.nu:8080/index.php?block=k8000
154 http://sourceforge.net/projects/libk8005/
diff --git a/Documentation/i2c/busses/i2c-parport-light b/Documentation/i2c/busses/i2c-parport-light
new file mode 100644
index 000000000000..287436478520
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-parport-light
@@ -0,0 +1,11 @@
1Kernel driver i2c-parport-light
2
3Author: Jean Delvare <khali@linux-fr.org>
4
5This driver is a light version of i2c-parport. It doesn't depend
6on the parport driver, and uses direct I/O access instead. This might be
7prefered on embedded systems where wasting memory for the clean but heavy
8parport handling is not an option. The drawback is a reduced portability
9and the impossibility to daisy-chain other parallel port devices.
10
11Please see i2c-parport for documentation.
diff --git a/Documentation/i2c/busses/i2c-pca-isa b/Documentation/i2c/busses/i2c-pca-isa
new file mode 100644
index 000000000000..6fc8f4c27c3c
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-pca-isa
@@ -0,0 +1,23 @@
1Kernel driver i2c-pca-isa
2
3Supported adapters:
4This driver supports ISA boards using the Philips PCA 9564
5Parallel bus to I2C bus controller
6
7Author: Ian Campbell <icampbell@arcom.com>, Arcom Control Systems
8
9Module Parameters
10-----------------
11
12* base int
13 I/O base address
14* irq int
15 IRQ interrupt
16* clock int
17 Clock rate as described in table 1 of PCA9564 datasheet
18
19Description
20-----------
21
22This driver supports ISA boards using the Philips PCA 9564
23Parallel bus to I2C bus controller
diff --git a/Documentation/i2c/busses/i2c-piix4 b/Documentation/i2c/busses/i2c-piix4
new file mode 100644
index 000000000000..856b4b8b962c
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-piix4
@@ -0,0 +1,72 @@
1Kernel driver i2c-piix4
2
3Supported adapters:
4 * Intel 82371AB PIIX4 and PIIX4E
5 * Intel 82443MX (440MX)
6 Datasheet: Publicly available at the Intel website
7 * ServerWorks OSB4, CSB5 and CSB6 southbridges
8 Datasheet: Only available via NDA from ServerWorks
9 * Standard Microsystems (SMSC) SLC90E66 (Victory66) southbridge
10 Datasheet: Publicly available at the SMSC website http://www.smsc.com
11
12Authors:
13 Frodo Looijaard <frodol@dds.nl>
14 Philip Edelbrock <phil@netroedge.com>
15
16
17Module Parameters
18-----------------
19
20* force: int
21 Forcibly enable the PIIX4. DANGEROUS!
22* force_addr: int
23 Forcibly enable the PIIX4 at the given address. EXTREMELY DANGEROUS!
24* fix_hstcfg: int
25 Fix config register. Needed on some boards (Force CPCI735).
26
27
28Description
29-----------
30
31The PIIX4 (properly known as the 82371AB) is an Intel chip with a lot of
32functionality. Among other things, it implements the PCI bus. One of its
33minor functions is implementing a System Management Bus. This is a true
34SMBus - you can not access it on I2C levels. The good news is that it
35natively understands SMBus commands and you do not have to worry about
36timing problems. The bad news is that non-SMBus devices connected to it can
37confuse it mightily. Yes, this is known to happen...
38
39Do 'lspci -v' and see whether it contains an entry like this:
40
410000:00:02.3 Bridge: Intel Corp. 82371AB/EB/MB PIIX4 ACPI (rev 02)
42 Flags: medium devsel, IRQ 9
43
44Bus and device numbers may differ, but the function number must be
45identical (like many PCI devices, the PIIX4 incorporates a number of
46different 'functions', which can be considered as separate devices). If you
47find such an entry, you have a PIIX4 SMBus controller.
48
49On some computers (most notably, some Dells), the SMBus is disabled by
50default. If you use the insmod parameter 'force=1', the kernel module will
51try to enable it. THIS IS VERY DANGEROUS! If the BIOS did not set up a
52correct address for this module, you could get in big trouble (read:
53crashes, data corruption, etc.). Try this only as a last resort (try BIOS
54updates first, for example), and backup first! An even more dangerous
55option is 'force_addr=<IOPORT>'. This will not only enable the PIIX4 like
56'force' foes, but it will also set a new base I/O port address. The SMBus
57parts of the PIIX4 needs a range of 8 of these addresses to function
58correctly. If these addresses are already reserved by some other device,
59you will get into big trouble! DON'T USE THIS IF YOU ARE NOT VERY SURE
60ABOUT WHAT YOU ARE DOING!
61
62The PIIX4E is just an new version of the PIIX4; it is supported as well.
63The PIIX/PIIX3 does not implement an SMBus or I2C bus, so you can't use
64this driver on those mainboards.
65
66The ServerWorks Southbridges, the Intel 440MX, and the Victory766 are
67identical to the PIIX4 in I2C/SMBus support.
68
69A few OSB4 southbridges are known to be misconfigured by the BIOS. In this
70case, you have you use the fix_hstcfg module parameter. Do not use it
71unless you know you have to, because in some cases it also breaks
72configuration on southbridges that don't need it.
diff --git a/Documentation/i2c/busses/i2c-prosavage b/Documentation/i2c/busses/i2c-prosavage
new file mode 100644
index 000000000000..703687902511
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-prosavage
@@ -0,0 +1,23 @@
1Kernel driver i2c-prosavage
2
3Supported adapters:
4
5 S3/VIA KM266/VT8375 aka ProSavage8
6 S3/VIA KM133/VT8365 aka Savage4
7
8Author: Henk Vergonet <henk@god.dyndns.org>
9
10Description
11-----------
12
13The Savage4 chips contain two I2C interfaces (aka a I2C 'master' or
14'host').
15
16The first interface is used for DDC (Data Display Channel) which is a
17serial channel through the VGA monitor connector to a DDC-compliant
18monitor. This interface is defined by the Video Electronics Standards
19Association (VESA). The standards are available for purchase at
20http://www.vesa.org . The second interface is a general-purpose I2C bus.
21
22Usefull for gaining access to the TV Encoder chips.
23
diff --git a/Documentation/i2c/busses/i2c-savage4 b/Documentation/i2c/busses/i2c-savage4
new file mode 100644
index 000000000000..6ecceab618d3
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-savage4
@@ -0,0 +1,26 @@
1Kernel driver i2c-savage4
2
3Supported adapters:
4 * Savage4
5 * Savage2000
6
7Authors:
8 Alexander Wold <awold@bigfoot.com>,
9 Mark D. Studebaker <mdsxyz123@yahoo.com>
10
11Description
12-----------
13
14The Savage4 chips contain two I2C interfaces (aka a I2C 'master'
15or 'host').
16
17The first interface is used for DDC (Data Display Channel) which is a
18serial channel through the VGA monitor connector to a DDC-compliant
19monitor. This interface is defined by the Video Electronics Standards
20Association (VESA). The standards are available for purchase at
21http://www.vesa.org . The DDC bus is not yet supported because its register
22is not directly memory-mapped.
23
24The second interface is a general-purpose I2C bus. This is the only
25interface supported by the driver at the moment.
26
diff --git a/Documentation/i2c/busses/i2c-sis5595 b/Documentation/i2c/busses/i2c-sis5595
new file mode 100644
index 000000000000..cc47db7d00a9
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-sis5595
@@ -0,0 +1,59 @@
1Kernel driver i2c-sis5595
2
3Authors:
4 Frodo Looijaard <frodol@dds.nl>,
5 Mark D. Studebaker <mdsxyz123@yahoo.com>,
6 Philip Edelbrock <phil@netroedge.com>
7
8Supported adapters:
9 * Silicon Integrated Systems Corp. SiS5595 Southbridge
10 Datasheet: Publicly available at the Silicon Integrated Systems Corp. site.
11
12Note: all have mfr. ID 0x1039.
13
14 SUPPORTED PCI ID
15 5595 0008
16
17 Note: these chips contain a 0008 device which is incompatible with the
18 5595. We recognize these by the presence of the listed
19 "blacklist" PCI ID and refuse to load.
20
21 NOT SUPPORTED PCI ID BLACKLIST PCI ID
22 540 0008 0540
23 550 0008 0550
24 5513 0008 5511
25 5581 0008 5597
26 5582 0008 5597
27 5597 0008 5597
28 5598 0008 5597/5598
29 630 0008 0630
30 645 0008 0645
31 646 0008 0646
32 648 0008 0648
33 650 0008 0650
34 651 0008 0651
35 730 0008 0730
36 735 0008 0735
37 745 0008 0745
38 746 0008 0746
39
40Module Parameters
41-----------------
42
43* force_addr=0xaddr Set the I/O base address. Useful for boards
44 that don't set the address in the BIOS. Does not do a
45 PCI force; the device must still be present in lspci.
46 Don't use this unless the driver complains that the
47 base address is not set.
48
49Description
50-----------
51
52i2c-sis5595 is a true SMBus host driver for motherboards with the SiS5595
53southbridges.
54
55WARNING: If you are trying to access the integrated sensors on the SiS5595
56chip, you want the sis5595 driver for those, not this driver. This driver
57is a BUS driver, not a CHIP driver. A BUS driver is used by other CHIP
58drivers to access chips on the bus.
59
diff --git a/Documentation/i2c/busses/i2c-sis630 b/Documentation/i2c/busses/i2c-sis630
new file mode 100644
index 000000000000..9aca6889f748
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-sis630
@@ -0,0 +1,49 @@
1Kernel driver i2c-sis630
2
3Supported adapters:
4 * Silicon Integrated Systems Corp (SiS)
5 630 chipset (Datasheet: available at http://amalysh.bei.t-online.de/docs/SIS/)
6 730 chipset
7 * Possible other SiS chipsets ?
8
9Author: Alexander Malysh <amalysh@web.de>
10
11Module Parameters
12-----------------
13
14* force = [1|0] Forcibly enable the SIS630. DANGEROUS!
15 This can be interesting for chipsets not named
16 above to check if it works for you chipset, but DANGEROUS!
17
18* high_clock = [1|0] Forcibly set Host Master Clock to 56KHz (default,
19 what your BIOS use). DANGEROUS! This should be a bit
20 faster, but freeze some systems (i.e. my Laptop).
21
22
23Description
24-----------
25
26This SMBus only driver is known to work on motherboards with the above
27named chipsets.
28
29If you see something like this:
30
3100:00.0 Host bridge: Silicon Integrated Systems [SiS] 630 Host (rev 31)
3200:01.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513
33
34or like this:
35
3600:00.0 Host bridge: Silicon Integrated Systems [SiS] 730 Host (rev 02)
3700:01.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513
38
39in your 'lspci' output , then this driver is for your chipset.
40
41Thank You
42---------
43Philip Edelbrock <phil@netroedge.com>
44- testing SiS730 support
45Mark M. Hoffman <mhoffman@lightlink.com>
46- bug fixes
47
48To anyone else which I forgot here ;), thanks!
49
diff --git a/Documentation/i2c/busses/i2c-sis69x b/Documentation/i2c/busses/i2c-sis69x
new file mode 100644
index 000000000000..5be48769f65b
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-sis69x
@@ -0,0 +1,73 @@
1Kernel driver i2c-sis96x
2
3Replaces 2.4.x i2c-sis645
4
5Supported adapters:
6 * Silicon Integrated Systems Corp (SiS)
7 Any combination of these host bridges:
8 645, 645DX (aka 646), 648, 650, 651, 655, 735, 745, 746
9 and these south bridges:
10 961, 962, 963(L)
11
12Author: Mark M. Hoffman <mhoffman@lightlink.com>
13
14Description
15-----------
16
17This SMBus only driver is known to work on motherboards with the above
18named chipset combinations. The driver was developed without benefit of a
19proper datasheet from SiS. The SMBus registers are assumed compatible with
20those of the SiS630, although they are located in a completely different
21place. Thanks to Alexander Malysh <amalysh@web.de> for providing the
22SiS630 datasheet (and driver).
23
24The command "lspci" as root should produce something like these lines:
25
2600:00.0 Host bridge: Silicon Integrated Systems [SiS]: Unknown device 0645
2700:02.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513
2800:02.1 SMBus: Silicon Integrated Systems [SiS]: Unknown device 0016
29
30or perhaps this...
31
3200:00.0 Host bridge: Silicon Integrated Systems [SiS]: Unknown device 0645
3300:02.0 ISA bridge: Silicon Integrated Systems [SiS]: Unknown device 0961
3400:02.1 SMBus: Silicon Integrated Systems [SiS]: Unknown device 0016
35
36(kernel versions later than 2.4.18 may fill in the "Unknown"s)
37
38If you cant see it please look on quirk_sis_96x_smbus
39(drivers/pci/quirks.c) (also if southbridge detection fails)
40
41I suspect that this driver could be made to work for the following SiS
42chipsets as well: 635, and 635T. If anyone owns a board with those chips
43AND is willing to risk crashing & burning an otherwise well-behaved kernel
44in the name of progress... please contact me at <mhoffman@lightlink.com> or
45via the project's mailing list: <sensors@stimpy.netroedge.com>. Please
46send bug reports and/or success stories as well.
47
48
49TO DOs
50------
51
52* The driver does not support SMBus block reads/writes; I may add them if a
53scenario is found where they're needed.
54
55
56Thank You
57---------
58
59Mark D. Studebaker <mdsxyz123@yahoo.com>
60 - design hints and bug fixes
61Alexander Maylsh <amalysh@web.de>
62 - ditto, plus an important datasheet... almost the one I really wanted
63Hans-Günter Lütke Uphues <hg_lu@t-online.de>
64 - patch for SiS735
65Robert Zwerus <arzie@dds.nl>
66 - testing for SiS645DX
67Kianusch Sayah Karadji <kianusch@sk-tech.net>
68 - patch for SiS645DX/962
69Ken Healy
70 - patch for SiS655
71
72To anyone else who has written w/ feedback, thanks!
73
diff --git a/Documentation/i2c/busses/i2c-via b/Documentation/i2c/busses/i2c-via
new file mode 100644
index 000000000000..55edfe1a640b
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-via
@@ -0,0 +1,34 @@
1Kernel driver i2c-via
2
3Supported adapters:
4 * VIA Technologies, InC. VT82C586B
5 Datasheet: Publicly available at the VIA website
6
7Author: Kyösti Mälkki <kmalkki@cc.hut.fi>
8
9Description
10-----------
11
12i2c-via is an i2c bus driver for motherboards with VIA chipset.
13
14The following VIA pci chipsets are supported:
15 - MVP3, VP3, VP2/97, VPX/97
16 - others with South bridge VT82C586B
17
18Your lspci listing must show this :
19
20 Bridge: VIA Technologies, Inc. VT82C586B ACPI (rev 10)
21
22 Problems?
23
24 Q: You have VT82C586B on the motherboard, but not in the listing.
25
26 A: Go to your BIOS setup, section PCI devices or similar.
27 Turn USB support on, and try again.
28
29 Q: No error messages, but still i2c doesn't seem to work.
30
31 A: This can happen. This driver uses the pins VIA recommends in their
32 datasheets, but there are several ways the motherboard manufacturer
33 can actually wire the lines.
34
diff --git a/Documentation/i2c/busses/i2c-viapro b/Documentation/i2c/busses/i2c-viapro
new file mode 100644
index 000000000000..702f5ac68c09
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-viapro
@@ -0,0 +1,47 @@
1Kernel driver i2c-viapro
2
3Supported adapters:
4 * VIA Technologies, Inc. VT82C596A/B
5 Datasheet: Sometimes available at the VIA website
6
7 * VIA Technologies, Inc. VT82C686A/B
8 Datasheet: Sometimes available at the VIA website
9
10 * VIA Technologies, Inc. VT8231, VT8233, VT8233A, VT8235, VT8237
11 Datasheet: available on request from Via
12
13Authors:
14 Frodo Looijaard <frodol@dds.nl>,
15 Philip Edelbrock <phil@netroedge.com>,
16 Kyösti Mälkki <kmalkki@cc.hut.fi>,
17 Mark D. Studebaker <mdsxyz123@yahoo.com>
18
19Module Parameters
20-----------------
21
22* force: int
23 Forcibly enable the SMBus controller. DANGEROUS!
24* force_addr: int
25 Forcibly enable the SMBus at the given address. EXTREMELY DANGEROUS!
26
27Description
28-----------
29
30i2c-viapro is a true SMBus host driver for motherboards with one of the
31supported VIA southbridges.
32
33Your lspci -n listing must show one of these :
34
35 device 1106:3050 (VT82C596 function 3)
36 device 1106:3051 (VT82C596 function 3)
37 device 1106:3057 (VT82C686 function 4)
38 device 1106:3074 (VT8233)
39 device 1106:3147 (VT8233A)
40 device 1106:8235 (VT8231)
41 devide 1106:3177 (VT8235)
42 devide 1106:3227 (VT8237)
43
44If none of these show up, you should look in the BIOS for settings like
45enable ACPI / SMBus or even USB.
46
47
diff --git a/Documentation/i2c/busses/i2c-voodoo3 b/Documentation/i2c/busses/i2c-voodoo3
new file mode 100644
index 000000000000..62d90a454d39
--- /dev/null
+++ b/Documentation/i2c/busses/i2c-voodoo3
@@ -0,0 +1,62 @@
1Kernel driver i2c-voodoo3
2
3Supported adapters:
4 * 3dfx Voodoo3 based cards
5 * Voodoo Banshee based cards
6
7Authors:
8 Frodo Looijaard <frodol@dds.nl>,
9 Philip Edelbrock <phil@netroedge.com>,
10 Ralph Metzler <rjkm@thp.uni-koeln.de>,
11 Mark D. Studebaker <mdsxyz123@yahoo.com>
12
13Main contact: Philip Edelbrock <phil@netroedge.com>
14
15The code is based upon Ralph's test code (he did the hard stuff ;')
16
17Description
18-----------
19
20The 3dfx Voodoo3 chip contains two I2C interfaces (aka a I2C 'master' or
21'host').
22
23The first interface is used for DDC (Data Display Channel) which is a
24serial channel through the VGA monitor connector to a DDC-compliant
25monitor. This interface is defined by the Video Electronics Standards
26Association (VESA). The standards are available for purchase at
27http://www.vesa.org .
28
29The second interface is a general-purpose I2C bus. The intent by 3dfx was
30to allow manufacturers to add extra chips to the video card such as a
31TV-out chip such as the BT869 or possibly even I2C based temperature
32sensors like the ADM1021 or LM75.
33
34Stability
35---------
36
37Seems to be stable on the test machine, but needs more testing on other
38machines. Simultaneous accesses of the DDC and I2C busses may cause errors.
39
40Supported Devices
41-----------------
42
43Specifically, this driver was written and tested on the '3dfx Voodoo3 AGP
443000' which has a tv-out feature (s-video or composite). According to the
45docs and discussions, this code should work for any Voodoo3 based cards as
46well as Voodoo Banshee based cards. The DDC interface has been tested on a
47Voodoo Banshee card.
48
49Issues
50------
51
52Probably many, but it seems to work OK on my system. :')
53
54
55External Device Connection
56--------------------------
57
58The digital video input jumpers give availability to the I2C bus.
59Specifically, pins 13 and 25 (bottom row middle, and bottom right-end) are
60the I2C clock and I2C data lines, respectively. +5V and GND are probably
61also easily available making the addition of extra I2C/SMBus devices easy
62to implement.
diff --git a/Documentation/i2c/busses/scx200_acb b/Documentation/i2c/busses/scx200_acb
new file mode 100644
index 000000000000..08c8cd1df60c
--- /dev/null
+++ b/Documentation/i2c/busses/scx200_acb
@@ -0,0 +1,14 @@
1Kernel driver scx200_acb
2
3Author: Christer Weinigel <wingel@nano-system.com>
4
5Module Parameters
6-----------------
7
8* base: int
9 Base addresses for the ACCESS.bus controllers
10
11Description
12-----------
13
14Enable the use of the ACCESS.bus controllers of a SCx200 processor.
diff --git a/Documentation/i2c/chips/smsc47b397.txt b/Documentation/i2c/chips/smsc47b397.txt
new file mode 100644
index 000000000000..389edae7f8df
--- /dev/null
+++ b/Documentation/i2c/chips/smsc47b397.txt
@@ -0,0 +1,146 @@
1November 23, 2004
2
3The following specification describes the SMSC LPC47B397-NC sensor chip
4(for which there is no public datasheet available). This document was
5provided by Craig Kelly (In-Store Broadcast Network) and edited/corrected
6by Mark M. Hoffman <mhoffman@lightlink.com>.
7
8* * * * *
9
10Methods for detecting the HP SIO and reading the thermal data on a dc7100.
11
12The thermal information on the dc7100 is contained in the SIO Hardware Monitor
13(HWM). The information is accessed through an index/data pair. The index/data
14pair is located at the HWM Base Address + 0 and the HWM Base Address + 1. The
15HWM Base address can be obtained from Logical Device 8, registers 0x60 (MSB)
16and 0x61 (LSB). Currently we are using 0x480 for the HWM Base Address and
170x480 and 0x481 for the index/data pair.
18
19Reading temperature information.
20The temperature information is located in the following registers:
21Temp1 0x25 (Currently, this reflects the CPU temp on all systems).
22Temp2 0x26
23Temp3 0x27
24Temp4 0x80
25
26Programming Example
27The following is an example of how to read the HWM temperature registers:
28MOV DX,480H
29MOV AX,25H
30OUT DX,AL
31MOV DX,481H
32IN AL,DX
33
34AL contains the data in hex, the temperature in Celsius is the decimal
35equivalent.
36
37Ex: If AL contains 0x2A, the temperature is 42 degrees C.
38
39Reading tach information.
40The fan speed information is located in the following registers:
41 LSB MSB
42Tach1 0x28 0x29 (Currently, this reflects the CPU
43 fan speed on all systems).
44Tach2 0x2A 0x2B
45Tach3 0x2C 0x2D
46Tach4 0x2E 0x2F
47
48Important!!!
49Reading the tach LSB locks the tach MSB.
50The LSB Must be read first.
51
52How to convert the tach reading to RPM.
53The tach reading (TCount) is given by: (Tach MSB * 256) + (Tach LSB)
54The SIO counts the number of 90kHz (11.111us) pulses per revolution.
55RPM = 60/(TCount * 11.111us)
56
57Example:
58Reg 0x28 = 0x9B
59Reg 0x29 = 0x08
60
61TCount = 0x89B = 2203
62
63RPM = 60 / (2203 * 11.11111 E-6) = 2451 RPM
64
65Obtaining the SIO version.
66
67CONFIGURATION SEQUENCE
68To program the configuration registers, the following sequence must be followed:
691. Enter Configuration Mode
702. Configure the Configuration Registers
713. Exit Configuration Mode.
72
73Enter Configuration Mode
74To place the chip into the Configuration State The config key (0x55) is written
75to the CONFIG PORT (0x2E).
76
77Configuration Mode
78In configuration mode, the INDEX PORT is located at the CONFIG PORT address and
79the DATA PORT is at INDEX PORT address + 1.
80
81The desired configuration registers are accessed in two steps:
82a. Write the index of the Logical Device Number Configuration Register
83 (i.e., 0x07) to the INDEX PORT and then write the number of the
84 desired logical device to the DATA PORT.
85
86b. Write the address of the desired configuration register within the
87 logical device to the INDEX PORT and then write or read the config-
88 uration register through the DATA PORT.
89
90Note: If accessing the Global Configuration Registers, step (a) is not required.
91
92Exit Configuration Mode
93To exit the Configuration State the write 0xAA to the CONFIG PORT (0x2E).
94The chip returns to the RUN State. (This is important).
95
96Programming Example
97The following is an example of how to read the SIO Device ID located at 0x20
98
99; ENTER CONFIGURATION MODE
100MOV DX,02EH
101MOV AX,055H
102OUT DX,AL
103; GLOBAL CONFIGURATION REGISTER
104MOV DX,02EH
105MOV AL,20H
106OUT DX,AL
107; READ THE DATA
108MOV DX,02FH
109IN AL,DX
110; EXIT CONFIGURATION MODE
111MOV DX,02EH
112MOV AX,0AAH
113OUT DX,AL
114
115The registers of interest for identifying the SIO on the dc7100 are Device ID
116(0x20) and Device Rev (0x21).
117
118The Device ID will read 0X6F
119The Device Rev currently reads 0x01
120
121Obtaining the HWM Base Address.
122The following is an example of how to read the HWM Base Address located in
123Logical Device 8.
124
125; ENTER CONFIGURATION MODE
126MOV DX,02EH
127MOV AX,055H
128OUT DX,AL
129; CONFIGURE REGISTER CRE0,
130; LOGICAL DEVICE 8
131MOV DX,02EH
132MOV AL,07H
133OUT DX,AL ;Point to LD# Config Reg
134MOV DX,02FH
135MOV AL, 08H
136OUT DX,AL;Point to Logical Device 8
137;
138MOV DX,02EH
139MOV AL,60H
140OUT DX,AL ; Point to HWM Base Addr MSB
141MOV DX,02FH
142IN AL,DX ; Get MSB of HWM Base Addr
143; EXIT CONFIGURATION MODE
144MOV DX,02EH
145MOV AX,0AAH
146OUT DX,AL
diff --git a/Documentation/i2c/dev-interface b/Documentation/i2c/dev-interface
new file mode 100644
index 000000000000..09d6cda2a1fb
--- /dev/null
+++ b/Documentation/i2c/dev-interface
@@ -0,0 +1,146 @@
1Usually, i2c devices are controlled by a kernel driver. But it is also
2possible to access all devices on an adapter from userspace, through
3the /dev interface. You need to load module i2c-dev for this.
4
5Each registered i2c adapter gets a number, counting from 0. You can
6examine /sys/class/i2c-dev/ to see what number corresponds to which adapter.
7I2C device files are character device files with major device number 89
8and a minor device number corresponding to the number assigned as
9explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ...,
10i2c-10, ...). All 256 minor device numbers are reserved for i2c.
11
12
13C example
14=========
15
16So let's say you want to access an i2c adapter from a C program. The
17first thing to do is `#include <linux/i2c.h>" and "#include <linux/i2c-dev.h>.
18Yes, I know, you should never include kernel header files, but until glibc
19knows about i2c, there is not much choice.
20
21Now, you have to decide which adapter you want to access. You should
22inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned
23somewhat dynamically, so you can not even assume /dev/i2c-0 is the
24first adapter.
25
26Next thing, open the device file, as follows:
27 int file;
28 int adapter_nr = 2; /* probably dynamically determined */
29 char filename[20];
30
31 sprintf(filename,"/dev/i2c-%d",adapter_nr);
32 if ((file = open(filename,O_RDWR)) < 0) {
33 /* ERROR HANDLING; you can check errno to see what went wrong */
34 exit(1);
35 }
36
37When you have opened the device, you must specify with what device
38address you want to communicate:
39 int addr = 0x40; /* The I2C address */
40 if (ioctl(file,I2C_SLAVE,addr) < 0) {
41 /* ERROR HANDLING; you can check errno to see what went wrong */
42 exit(1);
43 }
44
45Well, you are all set up now. You can now use SMBus commands or plain
46I2C to communicate with your device. SMBus commands are preferred if
47the device supports them. Both are illustrated below.
48 __u8 register = 0x10; /* Device register to access */
49 __s32 res;
50 char buf[10];
51 /* Using SMBus commands */
52 res = i2c_smbus_read_word_data(file,register);
53 if (res < 0) {
54 /* ERROR HANDLING: i2c transaction failed */
55 } else {
56 /* res contains the read word */
57 }
58 /* Using I2C Write, equivalent of
59 i2c_smbus_write_word_data(file,register,0x6543) */
60 buf[0] = register;
61 buf[1] = 0x43;
62 buf[2] = 0x65;
63 if ( write(file,buf,3) != 3) {
64 /* ERROR HANDLING: i2c transaction failed */
65 }
66 /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */
67 if (read(file,buf,1) != 1) {
68 /* ERROR HANDLING: i2c transaction failed */
69 } else {
70 /* buf[0] contains the read byte */
71 }
72
73IMPORTANT: because of the use of inline functions, you *have* to use
74'-O' or some variation when you compile your program!
75
76
77Full interface description
78==========================
79
80The following IOCTLs are defined and fully supported
81(see also i2c-dev.h and i2c.h):
82
83ioctl(file,I2C_SLAVE,long addr)
84 Change slave address. The address is passed in the 7 lower bits of the
85 argument (except for 10 bit addresses, passed in the 10 lower bits in this
86 case).
87
88ioctl(file,I2C_TENBIT,long select)
89 Selects ten bit addresses if select not equals 0, selects normal 7 bit
90 addresses if select equals 0. Default 0.
91
92ioctl(file,I2C_PEC,long select)
93 Selects SMBus PEC (packet error checking) generation and verification
94 if select not equals 0, disables if select equals 0. Default 0.
95 Used only for SMBus transactions.
96
97ioctl(file,I2C_FUNCS,unsigned long *funcs)
98 Gets the adapter functionality and puts it in *funcs.
99
100ioctl(file,I2C_RDWR,struct i2c_ioctl_rdwr_data *msgset)
101
102 Do combined read/write transaction without stop in between.
103 The argument is a pointer to a struct i2c_ioctl_rdwr_data {
104
105 struct i2c_msg *msgs; /* ptr to array of simple messages */
106 int nmsgs; /* number of messages to exchange */
107 }
108
109 The msgs[] themselves contain further pointers into data buffers.
110 The function will write or read data to or from that buffers depending
111 on whether the I2C_M_RD flag is set in a particular message or not.
112 The slave address and whether to use ten bit address mode has to be
113 set in each message, overriding the values set with the above ioctl's.
114
115
116Other values are NOT supported at this moment, except for I2C_SMBUS,
117which you should never directly call; instead, use the access functions
118below.
119
120You can do plain i2c transactions by using read(2) and write(2) calls.
121You do not need to pass the address byte; instead, set it through
122ioctl I2C_SLAVE before you try to access the device.
123
124You can do SMBus level transactions (see documentation file smbus-protocol
125for details) through the following functions:
126 __s32 i2c_smbus_write_quick(int file, __u8 value);
127 __s32 i2c_smbus_read_byte(int file);
128 __s32 i2c_smbus_write_byte(int file, __u8 value);
129 __s32 i2c_smbus_read_byte_data(int file, __u8 command);
130 __s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value);
131 __s32 i2c_smbus_read_word_data(int file, __u8 command);
132 __s32 i2c_smbus_write_word_data(int file, __u8 command, __u16 value);
133 __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value);
134 __s32 i2c_smbus_read_block_data(int file, __u8 command, __u8 *values);
135 __s32 i2c_smbus_write_block_data(int file, __u8 command, __u8 length,
136 __u8 *values);
137All these transactions return -1 on failure; you can read errno to see
138what happened. The 'write' transactions return 0 on success; the
139'read' transactions return the read value, except for read_block, which
140returns the number of values read. The block buffers need not be longer
141than 32 bytes.
142
143The above functions are all macros, that resolve to calls to the
144i2c_smbus_access function, that on its turn calls a specific ioctl
145with the data in a specific format. Read the source code if you
146want to know what happens behind the screens.
diff --git a/Documentation/i2c/functionality b/Documentation/i2c/functionality
new file mode 100644
index 000000000000..8a78a95ae04e
--- /dev/null
+++ b/Documentation/i2c/functionality
@@ -0,0 +1,135 @@
1INTRODUCTION
2------------
3
4Because not every I2C or SMBus adapter implements everything in the
5I2C specifications, a client can not trust that everything it needs
6is implemented when it is given the option to attach to an adapter:
7the client needs some way to check whether an adapter has the needed
8functionality.
9
10
11FUNCTIONALITY CONSTANTS
12-----------------------
13
14For the most up-to-date list of functionality constants, please check
15<linux/i2c.h>!
16
17 I2C_FUNC_I2C Plain i2c-level commands (Pure SMBus
18 adapters typically can not do these)
19 I2C_FUNC_10BIT_ADDR Handles the 10-bit address extensions
20 I2C_FUNC_PROTOCOL_MANGLING Knows about the I2C_M_REV_DIR_ADDR,
21 I2C_M_REV_DIR_ADDR and I2C_M_REV_DIR_NOSTART
22 flags (which modify the i2c protocol!)
23 I2C_FUNC_SMBUS_QUICK Handles the SMBus write_quick command
24 I2C_FUNC_SMBUS_READ_BYTE Handles the SMBus read_byte command
25 I2C_FUNC_SMBUS_WRITE_BYTE Handles the SMBus write_byte command
26 I2C_FUNC_SMBUS_READ_BYTE_DATA Handles the SMBus read_byte_data command
27 I2C_FUNC_SMBUS_WRITE_BYTE_DATA Handles the SMBus write_byte_data command
28 I2C_FUNC_SMBUS_READ_WORD_DATA Handles the SMBus read_word_data command
29 I2C_FUNC_SMBUS_WRITE_WORD_DATA Handles the SMBus write_byte_data command
30 I2C_FUNC_SMBUS_PROC_CALL Handles the SMBus process_call command
31 I2C_FUNC_SMBUS_READ_BLOCK_DATA Handles the SMBus read_block_data command
32 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA Handles the SMBus write_block_data command
33 I2C_FUNC_SMBUS_READ_I2C_BLOCK Handles the SMBus read_i2c_block_data command
34 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK Handles the SMBus write_i2c_block_data command
35
36A few combinations of the above flags are also defined for your convenience:
37
38 I2C_FUNC_SMBUS_BYTE Handles the SMBus read_byte
39 and write_byte commands
40 I2C_FUNC_SMBUS_BYTE_DATA Handles the SMBus read_byte_data
41 and write_byte_data commands
42 I2C_FUNC_SMBUS_WORD_DATA Handles the SMBus read_word_data
43 and write_word_data commands
44 I2C_FUNC_SMBUS_BLOCK_DATA Handles the SMBus read_block_data
45 and write_block_data commands
46 I2C_FUNC_SMBUS_I2C_BLOCK Handles the SMBus read_i2c_block_data
47 and write_i2c_block_data commands
48 I2C_FUNC_SMBUS_EMUL Handles all SMBus commands than can be
49 emulated by a real I2C adapter (using
50 the transparent emulation layer)
51
52
53ALGORITHM/ADAPTER IMPLEMENTATION
54--------------------------------
55
56When you write a new algorithm driver, you will have to implement a
57function callback `functionality', that gets an i2c_adapter structure
58pointer as its only parameter:
59
60 struct i2c_algorithm {
61 /* Many other things of course; check <linux/i2c.h>! */
62 u32 (*functionality) (struct i2c_adapter *);
63 }
64
65A typically implementation is given below, from i2c-algo-bit.c:
66
67 static u32 bit_func(struct i2c_adapter *adap)
68 {
69 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
70 I2C_FUNC_PROTOCOL_MANGLING;
71 }
72
73
74
75CLIENT CHECKING
76---------------
77
78Before a client tries to attach to an adapter, or even do tests to check
79whether one of the devices it supports is present on an adapter, it should
80check whether the needed functionality is present. There are two functions
81defined which should be used instead of calling the functionality hook
82in the algorithm structure directly:
83
84 /* Return the functionality mask */
85 extern u32 i2c_get_functionality (struct i2c_adapter *adap);
86
87 /* Return 1 if adapter supports everything we need, 0 if not. */
88 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
89
90This is a typical way to use these functions (from the writing-clients
91document):
92 int foo_detect_client(struct i2c_adapter *adapter, int address,
93 unsigned short flags, int kind)
94 {
95 /* Define needed variables */
96
97 /* As the very first action, we check whether the adapter has the
98 needed functionality: we need the SMBus read_word_data,
99 write_word_data and write_byte functions in this example. */
100 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA |
101 I2C_FUNC_SMBUS_WRITE_BYTE))
102 goto ERROR0;
103
104 /* Now we can do the real detection */
105
106 ERROR0:
107 /* Return an error */
108 }
109
110
111
112CHECKING THROUGH /DEV
113---------------------
114
115If you try to access an adapter from a userspace program, you will have
116to use the /dev interface. You will still have to check whether the
117functionality you need is supported, of course. This is done using
118the I2C_FUNCS ioctl. An example, adapted from the lm_sensors i2c_detect
119program, is below:
120
121 int file;
122 if (file = open("/dev/i2c-0",O_RDWR) < 0) {
123 /* Some kind of error handling */
124 exit(1);
125 }
126 if (ioctl(file,I2C_FUNCS,&funcs) < 0) {
127 /* Some kind of error handling */
128 exit(1);
129 }
130 if (! (funcs & I2C_FUNC_SMBUS_QUICK)) {
131 /* Oops, the needed functionality (SMBus write_quick function) is
132 not available! */
133 exit(1);
134 }
135 /* Now it is safe to use the SMBus write_quick command */
diff --git a/Documentation/i2c/i2c-protocol b/Documentation/i2c/i2c-protocol
new file mode 100644
index 000000000000..b4022c914210
--- /dev/null
+++ b/Documentation/i2c/i2c-protocol
@@ -0,0 +1,76 @@
1This document describes the i2c protocol. Or will, when it is finished :-)
2
3Key to symbols
4==============
5
6S (1 bit) : Start bit
7P (1 bit) : Stop bit
8Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
9A, NA (1 bit) : Accept and reverse accept bit.
10Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to
11 get a 10 bit I2C address.
12Comm (8 bits): Command byte, a data byte which often selects a register on
13 the device.
14Data (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh
15 for 16 bit data.
16Count (8 bits): A data byte containing the length of a block operation.
17
18[..]: Data sent by I2C device, as opposed to data sent by the host adapter.
19
20
21Simple send transaction
22======================
23
24This corresponds to i2c_master_send.
25
26 S Addr Wr [A] Data [A] Data [A] ... [A] Data [A] P
27
28
29Simple receive transaction
30===========================
31
32This corresponds to i2c_master_recv
33
34 S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
35
36
37Combined transactions
38====================
39
40This corresponds to i2c_transfer
41
42They are just like the above transactions, but instead of a stop bit P
43a start bit S is sent and the transaction continues. An example of
44a byte read, followed by a byte write:
45
46 S Addr Rd [A] [Data] NA S Addr Wr [A] Data [A] P
47
48
49Modified transactions
50=====================
51
52We have found some I2C devices that needs the following modifications:
53
54 Flag I2C_M_NOSTART:
55 In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
56 point. For example, setting I2C_M_NOSTART on the second partial message
57 generates something like:
58 S Addr Rd [A] [Data] NA Data [A] P
59 If you set the I2C_M_NOSTART variable for the first partial message,
60 we do not generate Addr, but we do generate the startbit S. This will
61 probably confuse all other clients on your bus, so don't try this.
62
63 Flags I2C_M_REV_DIR_ADDR
64 This toggles the Rd/Wr flag. That is, if you want to do a write, but
65 need to emit an Rd instead of a Wr, or vice versa, you set this
66 flag. For example:
67 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
68
69 Flags I2C_M_IGNORE_NAK
70 Normally message is interrupted immediately if there is [NA] from the
71 client. Setting this flag treats any [NA] as [A], and all of
72 message is sent.
73 These messages may still fail to SCL lo->hi timeout.
74
75 Flags I2C_M_NO_RD_ACK
76 In a read message, master A/NA bit is skipped.
diff --git a/Documentation/i2c/i2c-stub b/Documentation/i2c/i2c-stub
new file mode 100644
index 000000000000..d6dcb138abf5
--- /dev/null
+++ b/Documentation/i2c/i2c-stub
@@ -0,0 +1,38 @@
1MODULE: i2c-stub
2
3DESCRIPTION:
4
5This module is a very simple fake I2C/SMBus driver. It implements four
6types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and
7(r/w) word data.
8
9No hardware is needed nor associated with this module. It will accept write
10quick commands to all addresses; it will respond to the other commands (also
11to all addresses) by reading from or writing to an array in memory. It will
12also spam the kernel logs for every command it handles.
13
14A pointer register with auto-increment is implemented for all byte
15operations. This allows for continuous byte reads like those supported by
16EEPROMs, among others.
17
18The typical use-case is like this:
19 1. load this module
20 2. use i2cset (from lm_sensors project) to pre-load some data
21 3. load the target sensors chip driver module
22 4. observe its behavior in the kernel log
23
24CAVEATS:
25
26There are independent arrays for byte/data and word/data commands. Depending
27on if/how a target driver mixes them, you'll need to be careful.
28
29If your target driver polls some byte or word waiting for it to change, the
30stub could lock it up. Use i2cset to unlock it.
31
32If the hardware for your driver has banked registers (e.g. Winbond sensors
33chips) this module will not work well - although it could be extended to
34support that pretty easily.
35
36If you spam it hard enough, printk can be lossy. This module really wants
37something like relayfs.
38
diff --git a/Documentation/i2c/porting-clients b/Documentation/i2c/porting-clients
new file mode 100644
index 000000000000..56404918eabc
--- /dev/null
+++ b/Documentation/i2c/porting-clients
@@ -0,0 +1,133 @@
1Revision 4, 2004-03-30
2Jean Delvare <khali@linux-fr.org>
3Greg KH <greg@kroah.com>
4
5This is a guide on how to convert I2C chip drivers from Linux 2.4 to
6Linux 2.6. I have been using existing drivers (lm75, lm78) as examples.
7Then I converted a driver myself (lm83) and updated this document.
8
9There are two sets of points below. The first set concerns technical
10changes. The second set concerns coding policy. Both are mandatory.
11
12Although reading this guide will help you porting drivers, I suggest
13you keep an eye on an already ported driver while porting your own
14driver. This will help you a lot understanding what this guide
15exactly means. Choose the chip driver that is the more similar to
16yours for best results.
17
18Technical changes:
19
20* [Includes] Get rid of "version.h". Replace <linux/i2c-proc.h> with
21 <linux/i2c-sensor.h>. Includes typically look like that:
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c-sensor.h>
27 #include <linux/i2c-vid.h> /* if you need VRM support */
28 #include <asm/io.h> /* if you have I/O operations */
29 Please respect this inclusion order. Some extra headers may be
30 required for a given driver (e.g. "lm75.h").
31
32* [Addresses] SENSORS_I2C_END becomes I2C_CLIENT_END, SENSORS_ISA_END
33 becomes I2C_CLIENT_ISA_END.
34
35* [Client data] Get rid of sysctl_id. Try using standard names for
36 register values (for example, temp_os becomes temp_max). You're
37 still relatively free here, but you *have* to follow the standard
38 names for sysfs files (see the Sysctl section below).
39
40* [Function prototypes] The detect functions loses its flags
41 parameter. Sysctl (e.g. lm75_temp) and miscellaneous functions
42 are off the list of prototypes. This usually leaves five
43 prototypes:
44 static int lm75_attach_adapter(struct i2c_adapter *adapter);
45 static int lm75_detect(struct i2c_adapter *adapter, int address,
46 int kind);
47 static void lm75_init_client(struct i2c_client *client);
48 static int lm75_detach_client(struct i2c_client *client);
49 static void lm75_update_client(struct i2c_client *client);
50
51* [Sysctl] All sysctl stuff is of course gone (defines, ctl_table
52 and functions). Instead, you have to define show and set functions for
53 each sysfs file. Only define set for writable values. Take a look at an
54 existing 2.6 driver for details (lm78 for example). Don't forget
55 to define the attributes for each file (this is that step that
56 links callback functions). Use the file names specified in
57 Documentation/i2c/sysfs-interface for the individual files. Also
58 convert the units these files read and write to the specified ones.
59 If you need to add a new type of file, please discuss it on the
60 sensors mailing list <sensors@stimpy.netroedge.com> by providing a
61 patch to the Documentation/i2c/sysfs-interface file.
62
63* [Attach] For I2C drivers, the attach function should make sure
64 that the adapter's class has I2C_CLASS_HWMON, using the
65 following construct:
66 if (!(adapter->class & I2C_CLASS_HWMON))
67 return 0;
68 ISA-only drivers of course don't need this.
69
70* [Detect] As mentioned earlier, the flags parameter is gone.
71 The type_name and client_name strings are replaced by a single
72 name string, which will be filled with a lowercase, short string
73 (typically the driver name, e.g. "lm75").
74 In i2c-only drivers, drop the i2c_is_isa_adapter check, it's
75 useless.
76 The errorN labels are reduced to the number needed. If that number
77 is 2 (i2c-only drivers), it is advised that the labels are named
78 exit and exit_free. For i2c+isa drivers, labels should be named
79 ERROR0, ERROR1 and ERROR2. Don't forget to properly set err before
80 jumping to error labels. By the way, labels should be left-aligned.
81 Use memset to fill the client and data area with 0x00.
82 Use i2c_set_clientdata to set the client data (as opposed to
83 a direct access to client->data).
84 Use strlcpy instead of strcpy to copy the client name.
85 Replace the sysctl directory registration by calls to
86 device_create_file. Move the driver initialization before any
87 sysfs file creation.
88 Drop client->id.
89
90* [Init] Limits must not be set by the driver (can be done later in
91 user-space). Chip should not be reset default (although a module
92 parameter may be used to force is), and initialization should be
93 limited to the strictly necessary steps.
94
95* [Detach] Get rid of data, remove the call to
96 i2c_deregister_entry.
97
98* [Update] Don't access client->data directly, use
99 i2c_get_clientdata(client) instead.
100
101* [Interface] Init function should not print anything. Make sure
102 there is a MODULE_LICENSE() line, at the bottom of the file
103 (after MODULE_AUTHOR() and MODULE_DESCRIPTION(), in this order).
104
105Coding policy:
106
107* [Copyright] Use (C), not (c), for copyright.
108
109* [Debug/log] Get rid of #ifdef DEBUG/#endif constructs whenever you
110 can. Calls to printk/pr_debug for debugging purposes are replaced
111 by calls to dev_dbg. Here is an example on how to call it (taken
112 from lm75_detect):
113 dev_dbg(&client->dev, "Starting lm75 update\n");
114 Replace other printk calls with the dev_info, dev_err or dev_warn
115 function, as appropriate.
116
117* [Constants] Constants defines (registers, conversions, initial
118 values) should be aligned. This greatly improves readability.
119 Same goes for variables declarations. Alignments are achieved by the
120 means of tabs, not spaces. Remember that tabs are set to 8 in the
121 Linux kernel code.
122
123* [Structure definition] The name field should be standardized. All
124 lowercase and as simple as the driver name itself (e.g. "lm75").
125
126* [Layout] Avoid extra empty lines between comments and what they
127 comment. Respect the coding style (see Documentation/CodingStyle),
128 in particular when it comes to placing curly braces.
129
130* [Comments] Make sure that no comment refers to a file that isn't
131 part of the Linux source tree (typically doc/chips/<chip name>),
132 and that remaining comments still match the code. Merging comment
133 lines when possible is encouraged.
diff --git a/Documentation/i2c/smbus-protocol b/Documentation/i2c/smbus-protocol
new file mode 100644
index 000000000000..09f5e5ca4927
--- /dev/null
+++ b/Documentation/i2c/smbus-protocol
@@ -0,0 +1,216 @@
1SMBus Protocol Summary
2======================
3The following is a summary of the SMBus protocol. It applies to
4all revisions of the protocol (1.0, 1.1, and 2.0).
5Certain protocol features which are not supported by
6this package are briefly described at the end of this document.
7
8Some adapters understand only the SMBus (System Management Bus) protocol,
9which is a subset from the I2C protocol. Fortunately, many devices use
10only the same subset, which makes it possible to put them on an SMBus.
11If you write a driver for some I2C device, please try to use the SMBus
12commands if at all possible (if the device uses only that subset of the
13I2C protocol). This makes it possible to use the device driver on both
14SMBus adapters and I2C adapters (the SMBus command set is automatically
15translated to I2C on I2C adapters, but plain I2C commands can not be
16handled at all on most pure SMBus adapters).
17
18Below is a list of SMBus commands.
19
20Key to symbols
21==============
22
23S (1 bit) : Start bit
24P (1 bit) : Stop bit
25Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
26A, NA (1 bit) : Accept and reverse accept bit.
27Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to
28 get a 10 bit I2C address.
29Comm (8 bits): Command byte, a data byte which often selects a register on
30 the device.
31Data (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh
32 for 16 bit data.
33Count (8 bits): A data byte containing the length of a block operation.
34
35[..]: Data sent by I2C device, as opposed to data sent by the host adapter.
36
37
38SMBus Write Quick
39=================
40
41This sends a single bit to the device, at the place of the Rd/Wr bit.
42There is no equivalent Read Quick command.
43
44A Addr Rd/Wr [A] P
45
46
47SMBus Read Byte
48===============
49
50This reads a single byte from a device, without specifying a device
51register. Some devices are so simple that this interface is enough; for
52others, it is a shorthand if you want to read the same register as in
53the previous SMBus command.
54
55S Addr Rd [A] [Data] NA P
56
57
58SMBus Write Byte
59================
60
61This is the reverse of Read Byte: it sends a single byte to a device.
62See Read Byte for more information.
63
64S Addr Wr [A] Data [A] P
65
66
67SMBus Read Byte Data
68====================
69
70This reads a single byte from a device, from a designated register.
71The register is specified through the Comm byte.
72
73S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P
74
75
76SMBus Read Word Data
77====================
78
79This command is very like Read Byte Data; again, data is read from a
80device, from a designated register that is specified through the Comm
81byte. But this time, the data is a complete word (16 bits).
82
83S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
84
85
86SMBus Write Byte Data
87=====================
88
89This writes a single byte to a device, to a designated register. The
90register is specified through the Comm byte. This is the opposite of
91the Read Byte Data command.
92
93S Addr Wr [A] Comm [A] Data [A] P
94
95
96SMBus Write Word Data
97=====================
98
99This is the opposite operation of the Read Word Data command. 16 bits
100of data is read from a device, from a designated register that is
101specified through the Comm byte.
102
103S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
104
105
106SMBus Process Call
107==================
108
109This command selects a device register (through the Comm byte), sends
11016 bits of data to it, and reads 16 bits of data in return.
111
112S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
113 S Addr Rd [A] [DataLow] A [DataHigh] NA P
114
115
116SMBus Block Read
117================
118
119This command reads a block of up to 32 bytes from a device, from a
120designated register that is specified through the Comm byte. The amount
121of data is specified by the device in the Count byte.
122
123S Addr Wr [A] Comm [A]
124 S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
125
126
127SMBus Block Write
128=================
129
130The opposite of the Block Read command, this writes up to 32 bytes to
131a device, to a designated register that is specified through the
132Comm byte. The amount of data is specified in the Count byte.
133
134S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
135
136
137SMBus Block Process Call
138========================
139
140SMBus Block Process Call was introduced in Revision 2.0 of the specification.
141
142This command selects a device register (through the Comm byte), sends
1431 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.
144
145S Addr Wr [A] Comm [A] Count [A] Data [A] ...
146 S Addr Rd [A] [Count] A [Data] ... A P
147
148
149SMBus Host Notify
150=================
151
152This command is sent from a SMBus device acting as a master to the
153SMBus host acting as a slave.
154It is the same form as Write Word, with the command code replaced by the
155alerting device's address.
156
157[S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
158
159
160Packet Error Checking (PEC)
161===========================
162Packet Error Checking was introduced in Revision 1.1 of the specification.
163
164PEC adds a CRC-8 error-checking byte to all transfers.
165
166
167Address Resolution Protocol (ARP)
168=================================
169The Address Resolution Protocol was introduced in Revision 2.0 of
170the specification. It is a higher-layer protocol which uses the
171messages above.
172
173ARP adds device enumeration and dynamic address assignment to
174the protocol. All ARP communications use slave address 0x61 and
175require PEC checksums.
176
177
178I2C Block Transactions
179======================
180The following I2C block transactions are supported by the
181SMBus layer and are described here for completeness.
182I2C block transactions do not limit the number of bytes transferred
183but the SMBus layer places a limit of 32 bytes.
184
185
186I2C Block Read
187==============
188
189This command reads a block of bytes from a device, from a
190designated register that is specified through the Comm byte.
191
192S Addr Wr [A] Comm [A]
193 S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
194
195
196I2C Block Read (2 Comm bytes)
197=============================
198
199This command reads a block of bytes from a device, from a
200designated register that is specified through the two Comm bytes.
201
202S Addr Wr [A] Comm1 [A] Comm2 [A]
203 S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
204
205
206I2C Block Write
207===============
208
209The opposite of the Block Read command, this writes bytes to
210a device, to a designated register that is specified through the
211Comm byte. Note that command lengths of 0, 2, or more bytes are
212supported as they are indistinguishable from data.
213
214S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
215
216
diff --git a/Documentation/i2c/summary b/Documentation/i2c/summary
new file mode 100644
index 000000000000..41dde8776791
--- /dev/null
+++ b/Documentation/i2c/summary
@@ -0,0 +1,75 @@
1This is an explanation of what i2c is, and what is supported in this package.
2
3I2C and SMBus
4=============
5
6I2C (pronounce: I squared C) is a protocol developed by Philips. It is a
7slow two-wire protocol (10-400 kHz), but it suffices for many types of
8devices.
9
10SMBus (System Management Bus) is a subset of the I2C protocol. Many
11modern mainboards have a System Management Bus. There are a lot of
12devices which can be connected to a SMBus; the most notable are modern
13memory chips with EEPROM memories and chips for hardware monitoring.
14
15Because the SMBus is just a special case of the generalized I2C bus, we
16can simulate the SMBus protocol on plain I2C busses. The reverse is
17regretfully impossible.
18
19
20Terminology
21===========
22
23When we talk about I2C, we use the following terms:
24 Bus -> Algorithm
25 Adapter
26 Device -> Driver
27 Client
28
29An Algorithm driver contains general code that can be used for a whole class
30of I2C adapters. Each specific adapter driver depends on one algorithm
31driver.
32A Driver driver (yes, this sounds ridiculous, sorry) contains the general
33code to access some type of device. Each detected device gets its own
34data in the Client structure. Usually, Driver and Client are more closely
35integrated than Algorithm and Adapter.
36
37For a given configuration, you will need a driver for your I2C bus (usually
38a separate Adapter and Algorithm driver), and drivers for your I2C devices
39(usually one driver for each device). There are no I2C device drivers
40in this package. See the lm_sensors project http://www.lm-sensors.nu
41for device drivers.
42
43
44Included Bus Drivers
45====================
46Note that only stable drivers are patched into the kernel by 'mkpatch'.
47
48
49Base modules
50------------
51
52i2c-core: The basic I2C code, including the /proc/bus/i2c* interface
53i2c-dev: The /dev/i2c-* interface
54i2c-proc: The /proc/sys/dev/sensors interface for device (client) drivers
55
56Algorithm drivers
57-----------------
58
59i2c-algo-8xx: An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT)
60i2c-algo-bit: A bit-banging algorithm
61i2c-algo-pcf: A PCF 8584 style algorithm
62i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
63
64Adapter drivers
65---------------
66
67i2c-elektor: Elektor ISA card (uses i2c-algo-pcf)
68i2c-elv: ELV parallel port adapter (uses i2c-algo-bit)
69i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
70i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
71i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
72i2c-pport: Primitive parallel port adapter (uses i2c-algo-bit)
73i2c-rpx: RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
74i2c-velleman: Velleman K8000 parallel port adapter (uses i2c-algo-bit)
75
diff --git a/Documentation/i2c/sysfs-interface b/Documentation/i2c/sysfs-interface
new file mode 100644
index 000000000000..346400519d0d
--- /dev/null
+++ b/Documentation/i2c/sysfs-interface
@@ -0,0 +1,274 @@
1Naming and data format standards for sysfs files
2------------------------------------------------
3
4The libsensors library offers an interface to the raw sensors data
5through the sysfs interface. See libsensors documentation and source for
6more further information. As of writing this document, libsensors
7(from lm_sensors 2.8.3) is heavily chip-dependant. Adding or updating
8support for any given chip requires modifying the library's code.
9This is because libsensors was written for the procfs interface
10older kernel modules were using, which wasn't standardized enough.
11Recent versions of libsensors (from lm_sensors 2.8.2 and later) have
12support for the sysfs interface, though.
13
14The new sysfs interface was designed to be as chip-independant as
15possible.
16
17Note that motherboards vary widely in the connections to sensor chips.
18There is no standard that ensures, for example, that the second
19temperature sensor is connected to the CPU, or that the second fan is on
20the CPU. Also, some values reported by the chips need some computation
21before they make full sense. For example, most chips can only measure
22voltages between 0 and +4V. Other voltages are scaled back into that
23range using external resistors. Since the values of these resistors
24can change from motherboard to motherboard, the conversions cannot be
25hard coded into the driver and have to be done in user space.
26
27For this reason, even if we aim at a chip-independant libsensors, it will
28still require a configuration file (e.g. /etc/sensors.conf) for proper
29values conversion, labeling of inputs and hiding of unused inputs.
30
31An alternative method that some programs use is to access the sysfs
32files directly. This document briefly describes the standards that the
33drivers follow, so that an application program can scan for entries and
34access this data in a simple and consistent way. That said, such programs
35will have to implement conversion, labeling and hiding of inputs. For
36this reason, it is still not recommended to bypass the library.
37
38If you are developing a userspace application please send us feedback on
39this standard.
40
41Note that this standard isn't completely established yet, so it is subject
42to changes, even important ones. One more reason to use the library instead
43of accessing sysfs files directly.
44
45Each chip gets its own directory in the sysfs /sys/devices tree. To
46find all sensor chips, it is easier to follow the symlinks from
47/sys/i2c/devices/
48
49All sysfs values are fixed point numbers. To get the true value of some
50of the values, you should divide by the specified value.
51
52There is only one value per file, unlike the older /proc specification.
53The common scheme for files naming is: <type><number>_<item>. Usual
54types for sensor chips are "in" (voltage), "temp" (temperature) and
55"fan" (fan). Usual items are "input" (measured value), "max" (high
56threshold, "min" (low threshold). Numbering usually starts from 1,
57except for voltages which start from 0 (because most data sheets use
58this). A number is always used for elements that can be present more
59than once, even if there is a single element of the given type on the
60specific chip. Other files do not refer to a specific element, so
61they have a simple name, and no number.
62
63Alarms are direct indications read from the chips. The drivers do NOT
64make comparisons of readings to thresholds. This allows violations
65between readings to be caught and alarmed. The exact definition of an
66alarm (for example, whether a threshold must be met or must be exceeded
67to cause an alarm) is chip-dependent.
68
69
70-------------------------------------------------------------------------
71
72************
73* Voltages *
74************
75
76in[0-8]_min Voltage min value.
77 Unit: millivolt
78 Read/Write
79
80in[0-8]_max Voltage max value.
81 Unit: millivolt
82 Read/Write
83
84in[0-8]_input Voltage input value.
85 Unit: millivolt
86 Read only
87 Actual voltage depends on the scaling resistors on the
88 motherboard, as recommended in the chip datasheet.
89 This varies by chip and by motherboard.
90 Because of this variation, values are generally NOT scaled
91 by the chip driver, and must be done by the application.
92 However, some drivers (notably lm87 and via686a)
93 do scale, with various degrees of success.
94 These drivers will output the actual voltage.
95
96 Typical usage:
97 in0_* CPU #1 voltage (not scaled)
98 in1_* CPU #2 voltage (not scaled)
99 in2_* 3.3V nominal (not scaled)
100 in3_* 5.0V nominal (scaled)
101 in4_* 12.0V nominal (scaled)
102 in5_* -12.0V nominal (scaled)
103 in6_* -5.0V nominal (scaled)
104 in7_* varies
105 in8_* varies
106
107cpu[0-1]_vid CPU core reference voltage.
108 Unit: millivolt
109 Read only.
110 Not always correct.
111
112vrm Voltage Regulator Module version number.
113 Read only.
114 Two digit number, first is major version, second is
115 minor version.
116 Affects the way the driver calculates the CPU core reference
117 voltage from the vid pins.
118
119
120********
121* Fans *
122********
123
124fan[1-3]_min Fan minimum value
125 Unit: revolution/min (RPM)
126 Read/Write.
127
128fan[1-3]_input Fan input value.
129 Unit: revolution/min (RPM)
130 Read only.
131
132fan[1-3]_div Fan divisor.
133 Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128).
134 Some chips only support values 1, 2, 4 and 8.
135 Note that this is actually an internal clock divisor, which
136 affects the measurable speed range, not the read value.
137
138*******
139* PWM *
140*******
141
142pwm[1-3] Pulse width modulation fan control.
143 Integer value in the range 0 to 255
144 Read/Write
145 255 is max or 100%.
146
147pwm[1-3]_enable
148 Switch PWM on and off.
149 Not always present even if fan*_pwm is.
150 0 to turn off
151 1 to turn on in manual mode
152 2 to turn on in automatic mode
153 Read/Write
154
155pwm[1-*]_auto_channels_temp
156 Select which temperature channels affect this PWM output in
157 auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc...
158 Which values are possible depend on the chip used.
159
160pwm[1-*]_auto_point[1-*]_pwm
161pwm[1-*]_auto_point[1-*]_temp
162pwm[1-*]_auto_point[1-*]_temp_hyst
163 Define the PWM vs temperature curve. Number of trip points is
164 chip-dependent. Use this for chips which associate trip points
165 to PWM output channels.
166
167OR
168
169temp[1-*]_auto_point[1-*]_pwm
170temp[1-*]_auto_point[1-*]_temp
171temp[1-*]_auto_point[1-*]_temp_hyst
172 Define the PWM vs temperature curve. Number of trip points is
173 chip-dependent. Use this for chips which associate trip points
174 to temperature channels.
175
176
177****************
178* Temperatures *
179****************
180
181temp[1-3]_type Sensor type selection.
182 Integers 1, 2, 3 or thermistor Beta value (3435)
183 Read/Write.
184 1: PII/Celeron Diode
185 2: 3904 transistor
186 3: thermal diode
187 Not all types are supported by all chips
188
189temp[1-4]_max Temperature max value.
190 Unit: millidegree Celcius
191 Read/Write value.
192
193temp[1-3]_min Temperature min value.
194 Unit: millidegree Celcius
195 Read/Write value.
196
197temp[1-3]_max_hyst
198 Temperature hysteresis value for max limit.
199 Unit: millidegree Celcius
200 Must be reported as an absolute temperature, NOT a delta
201 from the max value.
202 Read/Write value.
203
204temp[1-4]_input Temperature input value.
205 Unit: millidegree Celcius
206 Read only value.
207
208temp[1-4]_crit Temperature critical value, typically greater than
209 corresponding temp_max values.
210 Unit: millidegree Celcius
211 Read/Write value.
212
213temp[1-2]_crit_hyst
214 Temperature hysteresis value for critical limit.
215 Unit: millidegree Celcius
216 Must be reported as an absolute temperature, NOT a delta
217 from the critical value.
218 Read/Write value.
219
220 If there are multiple temperature sensors, temp1_* is
221 generally the sensor inside the chip itself,
222 reported as "motherboard temperature". temp2_* to
223 temp4_* are generally sensors external to the chip
224 itself, for example the thermal diode inside the CPU or
225 a thermistor nearby.
226
227
228************
229* Currents *
230************
231
232Note that no known chip provides current measurements as of writing,
233so this part is theoretical, so to say.
234
235curr[1-n]_max Current max value
236 Unit: milliampere
237 Read/Write.
238
239curr[1-n]_min Current min value.
240 Unit: milliampere
241 Read/Write.
242
243curr[1-n]_input Current input value
244 Unit: milliampere
245 Read only.
246
247
248*********
249* Other *
250*********
251
252alarms Alarm bitmask.
253 Read only.
254 Integer representation of one to four bytes.
255 A '1' bit means an alarm.
256 Chips should be programmed for 'comparator' mode so that
257 the alarm will 'come back' after you read the register
258 if it is still valid.
259 Generally a direct representation of a chip's internal
260 alarm registers; there is no standard for the position
261 of individual bits.
262 Bits are defined in kernel/include/sensors.h.
263
264beep_enable Beep/interrupt enable
265 0 to disable.
266 1 to enable.
267 Read/Write
268
269beep_mask Bitmask for beep.
270 Same format as 'alarms' with the same bit locations.
271 Read/Write
272
273eeprom Raw EEPROM data in binary form.
274 Read only.
diff --git a/Documentation/i2c/ten-bit-addresses b/Documentation/i2c/ten-bit-addresses
new file mode 100644
index 000000000000..200074f81360
--- /dev/null
+++ b/Documentation/i2c/ten-bit-addresses
@@ -0,0 +1,22 @@
1The I2C protocol knows about two kinds of device addresses: normal 7 bit
2addresses, and an extended set of 10 bit addresses. The sets of addresses
3do not intersect: the 7 bit address 0x10 is not the same as the 10 bit
4address 0x10 (though a single device could respond to both of them). You
5select a 10 bit address by adding an extra byte after the address
6byte:
7 S Addr7 Rd/Wr ....
8becomes
9 S 11110 Addr10 Rd/Wr
10S is the start bit, Rd/Wr the read/write bit, and if you count the number
11of bits, you will see the there are 8 after the S bit for 7 bit addresses,
12and 16 after the S bit for 10 bit addresses.
13
14WARNING! The current 10 bit address support is EXPERIMENTAL. There are
15several places in the code that will cause SEVERE PROBLEMS with 10 bit
16addresses, even though there is some basic handling and hooks. Also,
17almost no supported adapter handles the 10 bit addresses correctly.
18
19As soon as a real 10 bit address device is spotted 'in the wild', we
20can and will add proper support. Right now, 10 bit address devices
21are defined by the I2C protocol, but we have never seen a single device
22which supports them.
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
new file mode 100644
index 000000000000..ad27511e3c7d
--- /dev/null
+++ b/Documentation/i2c/writing-clients
@@ -0,0 +1,816 @@
1This is a small guide for those who want to write kernel drivers for I2C
2or SMBus devices.
3
4To set up a driver, you need to do several things. Some are optional, and
5some things can be done slightly or completely different. Use this as a
6guide, not as a rule book!
7
8
9General remarks
10===============
11
12Try to keep the kernel namespace as clean as possible. The best way to
13do this is to use a unique prefix for all global symbols. This is
14especially important for exported symbols, but it is a good idea to do
15it for non-exported symbols too. We will use the prefix `foo_' in this
16tutorial, and `FOO_' for preprocessor variables.
17
18
19The driver structure
20====================
21
22Usually, you will implement a single driver structure, and instantiate
23all clients from it. Remember, a driver structure contains general access
24routines, a client structure specific information like the actual I2C
25address.
26
27static struct i2c_driver foo_driver = {
28 .owner = THIS_MODULE,
29 .name = "Foo version 2.3 driver",
30 .id = I2C_DRIVERID_FOO, /* from i2c-id.h, optional */
31 .flags = I2C_DF_NOTIFY,
32 .attach_adapter = &foo_attach_adapter,
33 .detach_client = &foo_detach_client,
34 .command = &foo_command /* may be NULL */
35}
36
37The name can be chosen freely, and may be upto 40 characters long. Please
38use something descriptive here.
39
40If used, the id should be a unique ID. The range 0xf000 to 0xffff is
41reserved for local use, and you can use one of those until you start
42distributing the driver, at which time you should contact the i2c authors
43to get your own ID(s). Note that most of the time you don't need an ID
44at all so you can just omit it.
45
46Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This
47means that your driver will be notified when new adapters are found.
48This is almost always what you want.
49
50All other fields are for call-back functions which will be explained
51below.
52
53There use to be two additional fields in this structure, inc_use et dec_use,
54for module usage count, but these fields were obsoleted and removed.
55
56
57Extra client data
58=================
59
60The client structure has a special `data' field that can point to any
61structure at all. You can use this to keep client-specific data. You
62do not always need this, but especially for `sensors' drivers, it can
63be very useful.
64
65An example structure is below.
66
67 struct foo_data {
68 struct semaphore lock; /* For ISA access in `sensors' drivers. */
69 int sysctl_id; /* To keep the /proc directory entry for
70 `sensors' drivers. */
71 enum chips type; /* To keep the chips type for `sensors' drivers. */
72
73 /* Because the i2c bus is slow, it is often useful to cache the read
74 information of a chip for some time (for example, 1 or 2 seconds).
75 It depends of course on the device whether this is really worthwhile
76 or even sensible. */
77 struct semaphore update_lock; /* When we are reading lots of information,
78 another process should not update the
79 below information */
80 char valid; /* != 0 if the following fields are valid. */
81 unsigned long last_updated; /* In jiffies */
82 /* Add the read information here too */
83 };
84
85
86Accessing the client
87====================
88
89Let's say we have a valid client structure. At some time, we will need
90to gather information from the client, or write new information to the
91client. How we will export this information to user-space is less
92important at this moment (perhaps we do not need to do this at all for
93some obscure clients). But we need generic reading and writing routines.
94
95I have found it useful to define foo_read and foo_write function for this.
96For some cases, it will be easier to call the i2c functions directly,
97but many chips have some kind of register-value idea that can easily
98be encapsulated. Also, some chips have both ISA and I2C interfaces, and
99it useful to abstract from this (only for `sensors' drivers).
100
101The below functions are simple examples, and should not be copied
102literally.
103
104 int foo_read_value(struct i2c_client *client, u8 reg)
105 {
106 if (reg < 0x10) /* byte-sized register */
107 return i2c_smbus_read_byte_data(client,reg);
108 else /* word-sized register */
109 return i2c_smbus_read_word_data(client,reg);
110 }
111
112 int foo_write_value(struct i2c_client *client, u8 reg, u16 value)
113 {
114 if (reg == 0x10) /* Impossible to write - driver error! */ {
115 return -1;
116 else if (reg < 0x10) /* byte-sized register */
117 return i2c_smbus_write_byte_data(client,reg,value);
118 else /* word-sized register */
119 return i2c_smbus_write_word_data(client,reg,value);
120 }
121
122For sensors code, you may have to cope with ISA registers too. Something
123like the below often works. Note the locking!
124
125 int foo_read_value(struct i2c_client *client, u8 reg)
126 {
127 int res;
128 if (i2c_is_isa_client(client)) {
129 down(&(((struct foo_data *) (client->data)) -> lock));
130 outb_p(reg,client->addr + FOO_ADDR_REG_OFFSET);
131 res = inb_p(client->addr + FOO_DATA_REG_OFFSET);
132 up(&(((struct foo_data *) (client->data)) -> lock));
133 return res;
134 } else
135 return i2c_smbus_read_byte_data(client,reg);
136 }
137
138Writing is done the same way.
139
140
141Probing and attaching
142=====================
143
144Most i2c devices can be present on several i2c addresses; for some this
145is determined in hardware (by soldering some chip pins to Vcc or Ground),
146for others this can be changed in software (by writing to specific client
147registers). Some devices are usually on a specific address, but not always;
148and some are even more tricky. So you will probably need to scan several
149i2c addresses for your clients, and do some sort of detection to see
150whether it is actually a device supported by your driver.
151
152To give the user a maximum of possibilities, some default module parameters
153are defined to help determine what addresses are scanned. Several macros
154are defined in i2c.h to help you support them, as well as a generic
155detection algorithm.
156
157You do not have to use this parameter interface; but don't try to use
158function i2c_probe() (or i2c_detect()) if you don't.
159
160NOTE: If you want to write a `sensors' driver, the interface is slightly
161 different! See below.
162
163
164
165Probing classes (i2c)
166---------------------
167
168All parameters are given as lists of unsigned 16-bit integers. Lists are
169terminated by I2C_CLIENT_END.
170The following lists are used internally:
171
172 normal_i2c: filled in by the module writer.
173 A list of I2C addresses which should normally be examined.
174 normal_i2c_range: filled in by the module writer.
175 A list of pairs of I2C addresses, each pair being an inclusive range of
176 addresses which should normally be examined.
177 probe: insmod parameter.
178 A list of pairs. The first value is a bus number (-1 for any I2C bus),
179 the second is the address. These addresses are also probed, as if they
180 were in the 'normal' list.
181 probe_range: insmod parameter.
182 A list of triples. The first value is a bus number (-1 for any I2C bus),
183 the second and third are addresses. These form an inclusive range of
184 addresses that are also probed, as if they were in the 'normal' list.
185 ignore: insmod parameter.
186 A list of pairs. The first value is a bus number (-1 for any I2C bus),
187 the second is the I2C address. These addresses are never probed.
188 This parameter overrules 'normal' and 'probe', but not the 'force' lists.
189 ignore_range: insmod parameter.
190 A list of triples. The first value is a bus number (-1 for any I2C bus),
191 the second and third are addresses. These form an inclusive range of
192 I2C addresses that are never probed.
193 This parameter overrules 'normal' and 'probe', but not the 'force' lists.
194 force: insmod parameter.
195 A list of pairs. The first value is a bus number (-1 for any I2C bus),
196 the second is the I2C address. A device is blindly assumed to be on
197 the given address, no probing is done.
198
199Fortunately, as a module writer, you just have to define the `normal'
200and/or `normal_range' parameters. The complete declaration could look
201like this:
202
203 /* Scan 0x20 to 0x2f, 0x37, and 0x40 to 0x4f */
204 static unsigned short normal_i2c[] = { 0x37,I2C_CLIENT_END };
205 static unsigned short normal_i2c_range[] = { 0x20, 0x2f, 0x40, 0x4f,
206 I2C_CLIENT_END };
207
208 /* Magic definition of all other variables and things */
209 I2C_CLIENT_INSMOD;
210
211Note that you *have* to call the two defined variables `normal_i2c' and
212`normal_i2c_range', without any prefix!
213
214
215Probing classes (sensors)
216-------------------------
217
218If you write a `sensors' driver, you use a slightly different interface.
219As well as I2C addresses, we have to cope with ISA addresses. Also, we
220use a enum of chip types. Don't forget to include `sensors.h'.
221
222The following lists are used internally. They are all lists of integers.
223
224 normal_i2c: filled in by the module writer. Terminated by SENSORS_I2C_END.
225 A list of I2C addresses which should normally be examined.
226 normal_i2c_range: filled in by the module writer. Terminated by
227 SENSORS_I2C_END
228 A list of pairs of I2C addresses, each pair being an inclusive range of
229 addresses which should normally be examined.
230 normal_isa: filled in by the module writer. Terminated by SENSORS_ISA_END.
231 A list of ISA addresses which should normally be examined.
232 normal_isa_range: filled in by the module writer. Terminated by
233 SENSORS_ISA_END
234 A list of triples. The first two elements are ISA addresses, being an
235 range of addresses which should normally be examined. The third is the
236 modulo parameter: only addresses which are 0 module this value relative
237 to the first address of the range are actually considered.
238 probe: insmod parameter. Initialize this list with SENSORS_I2C_END values.
239 A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
240 the ISA bus, -1 for any I2C bus), the second is the address. These
241 addresses are also probed, as if they were in the 'normal' list.
242 probe_range: insmod parameter. Initialize this list with SENSORS_I2C_END
243 values.
244 A list of triples. The first value is a bus number (SENSORS_ISA_BUS for
245 the ISA bus, -1 for any I2C bus), the second and third are addresses.
246 These form an inclusive range of addresses that are also probed, as
247 if they were in the 'normal' list.
248 ignore: insmod parameter. Initialize this list with SENSORS_I2C_END values.
249 A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
250 the ISA bus, -1 for any I2C bus), the second is the I2C address. These
251 addresses are never probed. This parameter overrules 'normal' and
252 'probe', but not the 'force' lists.
253 ignore_range: insmod parameter. Initialize this list with SENSORS_I2C_END
254 values.
255 A list of triples. The first value is a bus number (SENSORS_ISA_BUS for
256 the ISA bus, -1 for any I2C bus), the second and third are addresses.
257 These form an inclusive range of I2C addresses that are never probed.
258 This parameter overrules 'normal' and 'probe', but not the 'force' lists.
259
260Also used is a list of pointers to sensors_force_data structures:
261 force_data: insmod parameters. A list, ending with an element of which
262 the force field is NULL.
263 Each element contains the type of chip and a list of pairs.
264 The first value is a bus number (SENSORS_ISA_BUS for the ISA bus,
265 -1 for any I2C bus), the second is the address.
266 These are automatically translated to insmod variables of the form
267 force_foo.
268
269So we have a generic insmod variabled `force', and chip-specific variables
270`force_CHIPNAME'.
271
272Fortunately, as a module writer, you just have to define the `normal'
273and/or `normal_range' parameters, and define what chip names are used.
274The complete declaration could look like this:
275 /* Scan i2c addresses 0x20 to 0x2f, 0x37, and 0x40 to 0x4f
276 static unsigned short normal_i2c[] = {0x37,SENSORS_I2C_END};
277 static unsigned short normal_i2c_range[] = {0x20,0x2f,0x40,0x4f,
278 SENSORS_I2C_END};
279 /* Scan ISA address 0x290 */
280 static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END};
281 static unsigned int normal_isa_range[] = {SENSORS_ISA_END};
282
283 /* Define chips foo and bar, as well as all module parameters and things */
284 SENSORS_INSMOD_2(foo,bar);
285
286If you have one chip, you use macro SENSORS_INSMOD_1(chip), if you have 2
287you use macro SENSORS_INSMOD_2(chip1,chip2), etc. If you do not want to
288bother with chip types, you can use SENSORS_INSMOD_0.
289
290A enum is automatically defined as follows:
291 enum chips { any_chip, chip1, chip2, ... }
292
293
294Attaching to an adapter
295-----------------------
296
297Whenever a new adapter is inserted, or for all adapters if the driver is
298being registered, the callback attach_adapter() is called. Now is the
299time to determine what devices are present on the adapter, and to register
300a client for each of them.
301
302The attach_adapter callback is really easy: we just call the generic
303detection function. This function will scan the bus for us, using the
304information as defined in the lists explained above. If a device is
305detected at a specific address, another callback is called.
306
307 int foo_attach_adapter(struct i2c_adapter *adapter)
308 {
309 return i2c_probe(adapter,&addr_data,&foo_detect_client);
310 }
311
312For `sensors' drivers, use the i2c_detect function instead:
313
314 int foo_attach_adapter(struct i2c_adapter *adapter)
315 {
316 return i2c_detect(adapter,&addr_data,&foo_detect_client);
317 }
318
319Remember, structure `addr_data' is defined by the macros explained above,
320so you do not have to define it yourself.
321
322The i2c_probe or i2c_detect function will call the foo_detect_client
323function only for those i2c addresses that actually have a device on
324them (unless a `force' parameter was used). In addition, addresses that
325are already in use (by some other registered client) are skipped.
326
327
328The detect client function
329--------------------------
330
331The detect client function is called by i2c_probe or i2c_detect.
332The `kind' parameter contains 0 if this call is due to a `force'
333parameter, and -1 otherwise (for i2c_detect, it contains 0 if
334this call is due to the generic `force' parameter, and the chip type
335number if it is due to a specific `force' parameter).
336
337Below, some things are only needed if this is a `sensors' driver. Those
338parts are between /* SENSORS ONLY START */ and /* SENSORS ONLY END */
339markers.
340
341This function should only return an error (any value != 0) if there is
342some reason why no more detection should be done anymore. If the
343detection just fails for this address, return 0.
344
345For now, you can ignore the `flags' parameter. It is there for future use.
346
347 int foo_detect_client(struct i2c_adapter *adapter, int address,
348 unsigned short flags, int kind)
349 {
350 int err = 0;
351 int i;
352 struct i2c_client *new_client;
353 struct foo_data *data;
354 const char *client_name = ""; /* For non-`sensors' drivers, put the real
355 name here! */
356
357 /* Let's see whether this adapter can support what we need.
358 Please substitute the things you need here!
359 For `sensors' drivers, add `! is_isa &&' to the if statement */
360 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA |
361 I2C_FUNC_SMBUS_WRITE_BYTE))
362 goto ERROR0;
363
364 /* SENSORS ONLY START */
365 const char *type_name = "";
366 int is_isa = i2c_is_isa_adapter(adapter);
367
368 if (is_isa) {
369
370 /* If this client can't be on the ISA bus at all, we can stop now
371 (call `goto ERROR0'). But for kicks, we will assume it is all
372 right. */
373
374 /* Discard immediately if this ISA range is already used */
375 if (check_region(address,FOO_EXTENT))
376 goto ERROR0;
377
378 /* Probe whether there is anything on this address.
379 Some example code is below, but you will have to adapt this
380 for your own driver */
381
382 if (kind < 0) /* Only if no force parameter was used */ {
383 /* We may need long timeouts at least for some chips. */
384 #define REALLY_SLOW_IO
385 i = inb_p(address + 1);
386 if (inb_p(address + 2) != i)
387 goto ERROR0;
388 if (inb_p(address + 3) != i)
389 goto ERROR0;
390 if (inb_p(address + 7) != i)
391 goto ERROR0;
392 #undef REALLY_SLOW_IO
393
394 /* Let's just hope nothing breaks here */
395 i = inb_p(address + 5) & 0x7f;
396 outb_p(~i & 0x7f,address+5);
397 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
398 outb_p(i,address+5);
399 return 0;
400 }
401 }
402 }
403
404 /* SENSORS ONLY END */
405
406 /* OK. For now, we presume we have a valid client. We now create the
407 client structure, even though we cannot fill it completely yet.
408 But it allows us to access several i2c functions safely */
409
410 /* Note that we reserve some space for foo_data too. If you don't
411 need it, remove it. We do it here to help to lessen memory
412 fragmentation. */
413 if (! (new_client = kmalloc(sizeof(struct i2c_client) +
414 sizeof(struct foo_data),
415 GFP_KERNEL))) {
416 err = -ENOMEM;
417 goto ERROR0;
418 }
419
420 /* This is tricky, but it will set the data to the right value. */
421 client->data = new_client + 1;
422 data = (struct foo_data *) (client->data);
423
424 new_client->addr = address;
425 new_client->data = data;
426 new_client->adapter = adapter;
427 new_client->driver = &foo_driver;
428 new_client->flags = 0;
429
430 /* Now, we do the remaining detection. If no `force' parameter is used. */
431
432 /* First, the generic detection (if any), that is skipped if any force
433 parameter was used. */
434 if (kind < 0) {
435 /* The below is of course bogus */
436 if (foo_read(new_client,FOO_REG_GENERIC) != FOO_GENERIC_VALUE)
437 goto ERROR1;
438 }
439
440 /* SENSORS ONLY START */
441
442 /* Next, specific detection. This is especially important for `sensors'
443 devices. */
444
445 /* Determine the chip type. Not needed if a `force_CHIPTYPE' parameter
446 was used. */
447 if (kind <= 0) {
448 i = foo_read(new_client,FOO_REG_CHIPTYPE);
449 if (i == FOO_TYPE_1)
450 kind = chip1; /* As defined in the enum */
451 else if (i == FOO_TYPE_2)
452 kind = chip2;
453 else {
454 printk("foo: Ignoring 'force' parameter for unknown chip at "
455 "adapter %d, address 0x%02x\n",i2c_adapter_id(adapter),address);
456 goto ERROR1;
457 }
458 }
459
460 /* Now set the type and chip names */
461 if (kind == chip1) {
462 type_name = "chip1"; /* For /proc entry */
463 client_name = "CHIP 1";
464 } else if (kind == chip2) {
465 type_name = "chip2"; /* For /proc entry */
466 client_name = "CHIP 2";
467 }
468
469 /* Reserve the ISA region */
470 if (is_isa)
471 request_region(address,FOO_EXTENT,type_name);
472
473 /* SENSORS ONLY END */
474
475 /* Fill in the remaining client fields. */
476 strcpy(new_client->name,client_name);
477
478 /* SENSORS ONLY BEGIN */
479 data->type = kind;
480 /* SENSORS ONLY END */
481
482 data->valid = 0; /* Only if you use this field */
483 init_MUTEX(&data->update_lock); /* Only if you use this field */
484
485 /* Any other initializations in data must be done here too. */
486
487 /* Tell the i2c layer a new client has arrived */
488 if ((err = i2c_attach_client(new_client)))
489 goto ERROR3;
490
491 /* SENSORS ONLY BEGIN */
492 /* Register a new directory entry with module sensors. See below for
493 the `template' structure. */
494 if ((i = i2c_register_entry(new_client, type_name,
495 foo_dir_table_template,THIS_MODULE)) < 0) {
496 err = i;
497 goto ERROR4;
498 }
499 data->sysctl_id = i;
500
501 /* SENSORS ONLY END */
502
503 /* This function can write default values to the client registers, if
504 needed. */
505 foo_init_client(new_client);
506 return 0;
507
508 /* OK, this is not exactly good programming practice, usually. But it is
509 very code-efficient in this case. */
510
511 ERROR4:
512 i2c_detach_client(new_client);
513 ERROR3:
514 ERROR2:
515 /* SENSORS ONLY START */
516 if (is_isa)
517 release_region(address,FOO_EXTENT);
518 /* SENSORS ONLY END */
519 ERROR1:
520 kfree(new_client);
521 ERROR0:
522 return err;
523 }
524
525
526Removing the client
527===================
528
529The detach_client call back function is called when a client should be
530removed. It may actually fail, but only when panicking. This code is
531much simpler than the attachment code, fortunately!
532
533 int foo_detach_client(struct i2c_client *client)
534 {
535 int err,i;
536
537 /* SENSORS ONLY START */
538 /* Deregister with the `i2c-proc' module. */
539 i2c_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id);
540 /* SENSORS ONLY END */
541
542 /* Try to detach the client from i2c space */
543 if ((err = i2c_detach_client(client))) {
544 printk("foo.o: Client deregistration failed, client not detached.\n");
545 return err;
546 }
547
548 /* SENSORS ONLY START */
549 if i2c_is_isa_client(client)
550 release_region(client->addr,LM78_EXTENT);
551 /* SENSORS ONLY END */
552
553 kfree(client); /* Frees client data too, if allocated at the same time */
554 return 0;
555 }
556
557
558Initializing the module or kernel
559=================================
560
561When the kernel is booted, or when your foo driver module is inserted,
562you have to do some initializing. Fortunately, just attaching (registering)
563the driver module is usually enough.
564
565 /* Keep track of how far we got in the initialization process. If several
566 things have to initialized, and we fail halfway, only those things
567 have to be cleaned up! */
568 static int __initdata foo_initialized = 0;
569
570 static int __init foo_init(void)
571 {
572 int res;
573 printk("foo version %s (%s)\n",FOO_VERSION,FOO_DATE);
574
575 if ((res = i2c_add_driver(&foo_driver))) {
576 printk("foo: Driver registration failed, module not inserted.\n");
577 foo_cleanup();
578 return res;
579 }
580 foo_initialized ++;
581 return 0;
582 }
583
584 void foo_cleanup(void)
585 {
586 if (foo_initialized == 1) {
587 if ((res = i2c_del_driver(&foo_driver))) {
588 printk("foo: Driver registration failed, module not removed.\n");
589 return;
590 }
591 foo_initialized --;
592 }
593 }
594
595 /* Substitute your own name and email address */
596 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"
597 MODULE_DESCRIPTION("Driver for Barf Inc. Foo I2C devices");
598
599 module_init(foo_init);
600 module_exit(foo_cleanup);
601
602Note that some functions are marked by `__init', and some data structures
603by `__init_data'. Hose functions and structures can be removed after
604kernel booting (or module loading) is completed.
605
606Command function
607================
608
609A generic ioctl-like function call back is supported. You will seldom
610need this. You may even set it to NULL.
611
612 /* No commands defined */
613 int foo_command(struct i2c_client *client, unsigned int cmd, void *arg)
614 {
615 return 0;
616 }
617
618
619Sending and receiving
620=====================
621
622If you want to communicate with your device, there are several functions
623to do this. You can find all of them in i2c.h.
624
625If you can choose between plain i2c communication and SMBus level
626communication, please use the last. All adapters understand SMBus level
627commands, but only some of them understand plain i2c!
628
629
630Plain i2c communication
631-----------------------
632
633 extern int i2c_master_send(struct i2c_client *,const char* ,int);
634 extern int i2c_master_recv(struct i2c_client *,char* ,int);
635
636These routines read and write some bytes from/to a client. The client
637contains the i2c address, so you do not have to include it. The second
638parameter contains the bytes the read/write, the third the length of the
639buffer. Returned is the actual number of bytes read/written.
640
641 extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msg,
642 int num);
643
644This sends a series of messages. Each message can be a read or write,
645and they can be mixed in any way. The transactions are combined: no
646stop bit is sent between transaction. The i2c_msg structure contains
647for each message the client address, the number of bytes of the message
648and the message data itself.
649
650You can read the file `i2c-protocol' for more information about the
651actual i2c protocol.
652
653
654SMBus communication
655-------------------
656
657 extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr,
658 unsigned short flags,
659 char read_write, u8 command, int size,
660 union i2c_smbus_data * data);
661
662 This is the generic SMBus function. All functions below are implemented
663 in terms of it. Never use this function directly!
664
665
666 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value);
667 extern s32 i2c_smbus_read_byte(struct i2c_client * client);
668 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value);
669 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command);
670 extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,
671 u8 command, u8 value);
672 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);
673 extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
674 u8 command, u16 value);
675 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
676 u8 command, u8 length,
677 u8 *values);
678
679These ones were removed in Linux 2.6.10 because they had no users, but could
680be added back later if needed:
681
682 extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
683 u8 command, u8 *values);
684 extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
685 u8 command, u8 *values);
686 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
687 u8 command, u8 length,
688 u8 *values);
689 extern s32 i2c_smbus_process_call(struct i2c_client * client,
690 u8 command, u16 value);
691 extern s32 i2c_smbus_block_process_call(struct i2c_client *client,
692 u8 command, u8 length,
693 u8 *values)
694
695All these transactions return -1 on failure. The 'write' transactions
696return 0 on success; the 'read' transactions return the read value, except
697for read_block, which returns the number of values read. The block buffers
698need not be longer than 32 bytes.
699
700You can read the file `smbus-protocol' for more information about the
701actual SMBus protocol.
702
703
704General purpose routines
705========================
706
707Below all general purpose routines are listed, that were not mentioned
708before.
709
710 /* This call returns a unique low identifier for each registered adapter,
711 * or -1 if the adapter was not registered.
712 */
713 extern int i2c_adapter_id(struct i2c_adapter *adap);
714
715
716The sensors sysctl/proc interface
717=================================
718
719This section only applies if you write `sensors' drivers.
720
721Each sensors driver creates a directory in /proc/sys/dev/sensors for each
722registered client. The directory is called something like foo-i2c-4-65.
723The sensors module helps you to do this as easily as possible.
724
725The template
726------------
727
728You will need to define a ctl_table template. This template will automatically
729be copied to a newly allocated structure and filled in where necessary when
730you call sensors_register_entry.
731
732First, I will give an example definition.
733 static ctl_table foo_dir_table_template[] = {
734 { FOO_SYSCTL_FUNC1, "func1", NULL, 0, 0644, NULL, &i2c_proc_real,
735 &i2c_sysctl_real,NULL,&foo_func },
736 { FOO_SYSCTL_FUNC2, "func2", NULL, 0, 0644, NULL, &i2c_proc_real,
737 &i2c_sysctl_real,NULL,&foo_func },
738 { FOO_SYSCTL_DATA, "data", NULL, 0, 0644, NULL, &i2c_proc_real,
739 &i2c_sysctl_real,NULL,&foo_data },
740 { 0 }
741 };
742
743In the above example, three entries are defined. They can either be
744accessed through the /proc interface, in the /proc/sys/dev/sensors/*
745directories, as files named func1, func2 and data, or alternatively
746through the sysctl interface, in the appropriate table, with identifiers
747FOO_SYSCTL_FUNC1, FOO_SYSCTL_FUNC2 and FOO_SYSCTL_DATA.
748
749The third, sixth and ninth parameters should always be NULL, and the
750fourth should always be 0. The fifth is the mode of the /proc file;
7510644 is safe, as the file will be owned by root:root.
752
753The seventh and eighth parameters should be &i2c_proc_real and
754&i2c_sysctl_real if you want to export lists of reals (scaled
755integers). You can also use your own function for them, as usual.
756Finally, the last parameter is the call-back to gather the data
757(see below) if you use the *_proc_real functions.
758
759
760Gathering the data
761------------------
762
763The call back functions (foo_func and foo_data in the above example)
764can be called in several ways; the operation parameter determines
765what should be done:
766
767 * If operation == SENSORS_PROC_REAL_INFO, you must return the
768 magnitude (scaling) in nrels_mag;
769 * If operation == SENSORS_PROC_REAL_READ, you must read information
770 from the chip and return it in results. The number of integers
771 to display should be put in nrels_mag;
772 * If operation == SENSORS_PROC_REAL_WRITE, you must write the
773 supplied information to the chip. nrels_mag will contain the number
774 of integers, results the integers themselves.
775
776The *_proc_real functions will display the elements as reals for the
777/proc interface. If you set the magnitude to 2, and supply 345 for
778SENSORS_PROC_REAL_READ, it would display 3.45; and if the user would
779write 45.6 to the /proc file, it would be returned as 4560 for
780SENSORS_PROC_REAL_WRITE. A magnitude may even be negative!
781
782An example function:
783
784 /* FOO_FROM_REG and FOO_TO_REG translate between scaled values and
785 register values. Note the use of the read cache. */
786 void foo_in(struct i2c_client *client, int operation, int ctl_name,
787 int *nrels_mag, long *results)
788 {
789 struct foo_data *data = client->data;
790 int nr = ctl_name - FOO_SYSCTL_FUNC1; /* reduce to 0 upwards */
791
792 if (operation == SENSORS_PROC_REAL_INFO)
793 *nrels_mag = 2;
794 else if (operation == SENSORS_PROC_REAL_READ) {
795 /* Update the readings cache (if necessary) */
796 foo_update_client(client);
797 /* Get the readings from the cache */
798 results[0] = FOO_FROM_REG(data->foo_func_base[nr]);
799 results[1] = FOO_FROM_REG(data->foo_func_more[nr]);
800 results[2] = FOO_FROM_REG(data->foo_func_readonly[nr]);
801 *nrels_mag = 2;
802 } else if (operation == SENSORS_PROC_REAL_WRITE) {
803 if (*nrels_mag >= 1) {
804 /* Update the cache */
805 data->foo_base[nr] = FOO_TO_REG(results[0]);
806 /* Update the chip */
807 foo_write_value(client,FOO_REG_FUNC_BASE(nr),data->foo_base[nr]);
808 }
809 if (*nrels_mag >= 2) {
810 /* Update the cache */
811 data->foo_more[nr] = FOO_TO_REG(results[1]);
812 /* Update the chip */
813 foo_write_value(client,FOO_REG_FUNC_MORE(nr),data->foo_more[nr]);
814 }
815 }
816 }