diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /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')
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 @@ | |||
1 | Kernel driver i2c-ali1535 | ||
2 | |||
3 | Supported 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 | |||
8 | Authors: | ||
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 | |||
15 | Description | ||
16 | ----------- | ||
17 | |||
18 | This is the driver for the SMB Host controller on Acer Labs Inc. (ALI) | ||
19 | M1535 South Bridge. | ||
20 | |||
21 | The M1535 is a South bridge for portable systems. It is very similar to the | ||
22 | M15x3 South bridges also produced by Acer Labs Inc. Some of the registers | ||
23 | within the part have moved and some have been redefined slightly. | ||
24 | Additionally, the sequencing of the SMBus transactions has been modified to | ||
25 | be more consistent with the sequencing recommended by the manufacturer and | ||
26 | observed through testing. These changes are reflected in this driver and | ||
27 | can be identified by comparing this driver to the i2c-ali15x3 driver. For | ||
28 | an overview of these chips see http://www.acerlabs.com | ||
29 | |||
30 | The SMB controller is part of the M7101 device, which is an ACPI-compliant | ||
31 | Power Management Unit (PMU). | ||
32 | |||
33 | The whole M7101 device has to be enabled for the SMB to work. You can't | ||
34 | just enable the SMB alone. The SMB and the ACPI have separate I/O spaces. | ||
35 | We make sure that the SMB is enabled. We leave the ACPI alone. | ||
36 | |||
37 | |||
38 | Features | ||
39 | -------- | ||
40 | |||
41 | This driver controls the SMB Host only. This driver does not use | ||
42 | interrupts. | ||
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 @@ | |||
1 | Kernel driver i2c-ali1563 | ||
2 | |||
3 | Supported 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 | |||
8 | Author: Patrick Mochel <mochel@digitalimplant.org> | ||
9 | |||
10 | Description | ||
11 | ----------- | ||
12 | |||
13 | This is the driver for the SMB Host controller on Acer Labs Inc. (ALI) | ||
14 | M1563 South Bridge. | ||
15 | |||
16 | For an overview of these chips see http://www.acerlabs.com | ||
17 | |||
18 | The M1563 southbridge is deceptively similar to the M1533, with a few | ||
19 | notable exceptions. One of those happens to be the fact they upgraded the | ||
20 | i2c core to be SMBus 2.0 compliant, and happens to be almost identical to | ||
21 | the i2c controller found in the Intel 801 south bridges. | ||
22 | |||
23 | Features | ||
24 | -------- | ||
25 | |||
26 | This driver controls the SMB Host only. This driver does not use | ||
27 | interrupts. | ||
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 @@ | |||
1 | Kernel driver i2c-ali15x3 | ||
2 | |||
3 | Supported 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 | |||
8 | Authors: | ||
9 | Frodo Looijaard <frodol@dds.nl>, | ||
10 | Philip Edelbrock <phil@netroedge.com>, | ||
11 | Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
12 | |||
13 | Module Parameters | ||
14 | ----------------- | ||
15 | |||
16 | * force_addr: int | ||
17 | Initialize the base address of the i2c controller | ||
18 | |||
19 | |||
20 | Notes | ||
21 | ----- | ||
22 | |||
23 | The force_addr parameter is useful for boards that don't set the address in | ||
24 | the BIOS. Does not do a PCI force; the device must still be present in | ||
25 | lspci. Don't use this unless the driver complains that the base address is | ||
26 | not set. | ||
27 | |||
28 | Example: 'modprobe i2c-ali15x3 force_addr=0xe800' | ||
29 | |||
30 | SMBus periodically hangs on ASUS P5A motherboards and can only be cleared | ||
31 | by a power cycle. Cause unknown (see Issues below). | ||
32 | |||
33 | |||
34 | Description | ||
35 | ----------- | ||
36 | |||
37 | This is the driver for the SMB Host controller on Acer Labs Inc. (ALI) | ||
38 | M1541 and M1543C South Bridges. | ||
39 | |||
40 | The M1543C is a South bridge for desktop systems. | ||
41 | The M1541 is a South bridge for portable systems. | ||
42 | They 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 | |||
62 | For an overview of these chips see http://www.acerlabs.com. At this time the | ||
63 | full data sheets on the web site are password protected, however if you | ||
64 | contact the ALI office in San Jose they may give you the password. | ||
65 | |||
66 | The M1533/M1543C devices appear as FOUR separate devices on the PCI bus. An | ||
67 | output 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 | |||
83 | The SMB controller is part of the M7101 device, which is an ACPI-compliant | ||
84 | Power Management Unit (PMU). | ||
85 | |||
86 | The whole M7101 device has to be enabled for the SMB to work. You can't | ||
87 | just enable the SMB alone. The SMB and the ACPI have separate I/O spaces. | ||
88 | We make sure that the SMB is enabled. We leave the ACPI alone. | ||
89 | |||
90 | Features | ||
91 | -------- | ||
92 | |||
93 | This driver controls the SMB Host only. The SMB Slave | ||
94 | controller on the M15X3 is not enabled. This driver does not use | ||
95 | interrupts. | ||
96 | |||
97 | |||
98 | Issues | ||
99 | ------ | ||
100 | |||
101 | This driver requests the I/O space for only the SMB | ||
102 | registers. It doesn't use the ACPI region. | ||
103 | |||
104 | On the ASUS P5A motherboard, there are several reports that | ||
105 | the SMBus will hang and this can only be resolved by | ||
106 | powering off the computer. It appears to be worse when the board | ||
107 | gets hot, for example under heavy CPU load, or in the summer. | ||
108 | There may be electrical problems on this board. | ||
109 | On the P5A, the W83781D sensor chip is on both the ISA and | ||
110 | SMBus. Therefore the SMBus hangs can generally be avoided | ||
111 | by 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 @@ | |||
1 | Kernel driver i2c-amd756 | ||
2 | |||
3 | Supported 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 | |||
13 | Authors: | ||
14 | Frodo Looijaard <frodol@dds.nl>, | ||
15 | Philip Edelbrock <phil@netroedge.com> | ||
16 | |||
17 | Description | ||
18 | ----------- | ||
19 | |||
20 | This driver supports the AMD 756, 766, 768 and 8111 Peripheral Bus | ||
21 | Controllers, and the nVidia nForce. | ||
22 | |||
23 | Note that for the 8111, there are two SMBus adapters. The SMBus 1.0 adapter | ||
24 | is supported by this driver, and the SMBus 2.0 adapter is supported by the | ||
25 | i2c-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 @@ | |||
1 | Kernel driver i2c-adm8111 | ||
2 | |||
3 | Supported adapters: | ||
4 | * AMD-8111 SMBus 2.0 PCI interface | ||
5 | |||
6 | Datasheets: | ||
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 | |||
11 | Author: Vojtech Pavlik <vojtech@suse.cz> | ||
12 | |||
13 | Description | ||
14 | ----------- | ||
15 | |||
16 | If you see something like this: | ||
17 | |||
18 | 00: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 | |||
23 | in your 'lspci -v', then this driver is for your chipset. | ||
24 | |||
25 | Process Call Support | ||
26 | -------------------- | ||
27 | |||
28 | Supported. | ||
29 | |||
30 | SMBus 2.0 Support | ||
31 | ----------------- | ||
32 | |||
33 | Supported. Both PEC and block process call support is implemented. Slave | ||
34 | mode or host notification are not yet implemented. | ||
35 | |||
36 | Notes | ||
37 | ----- | ||
38 | |||
39 | Note that for the 8111, there are two SMBus adapters. The SMBus 2.0 adapter | ||
40 | is supported by this driver, and the SMBus 1.0 adapter is supported by the | ||
41 | i2c-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 @@ | |||
1 | Kernel driver i2c-i801 | ||
2 | |||
3 | Supported 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 | |||
15 | Authors: | ||
16 | Frodo Looijaard <frodol@dds.nl>, | ||
17 | Philip Edelbrock <phil@netroedge.com>, | ||
18 | Mark Studebaker <mdsxyz123@yahoo.com> | ||
19 | |||
20 | |||
21 | Module Parameters | ||
22 | ----------------- | ||
23 | |||
24 | * force_addr: int | ||
25 | Forcibly enable the ICH at the given address. EXTREMELY DANGEROUS! | ||
26 | |||
27 | |||
28 | Description | ||
29 | ----------- | ||
30 | |||
31 | The ICH (properly known as the 82801AA), ICH0 (82801AB), ICH2 (82801BA), | ||
32 | ICH3 (82801CA/CAM) and later devices are Intel chips that are a part of | ||
33 | Intel's '810' chipset for Celeron-based PCs, '810E' chipset for | ||
34 | Pentium-based PCs, '815E' chipset, and others. | ||
35 | |||
36 | The ICH chips contain at least SEVEN separate PCI functions in TWO logical | ||
37 | PCI devices. An output of lspci will show something similar to the | ||
38 | following: | ||
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 | |||
46 | The SMBus controller is function 3 in device 1f. Class 0c05 is SMBus Serial | ||
47 | Controller. | ||
48 | |||
49 | If you do NOT see the 24x3 device at function 3, and you can't figure out | ||
50 | any way in the BIOS to enable it, | ||
51 | |||
52 | The ICH chips are quite similar to Intel's PIIX4 chip, at least in the | ||
53 | SMBus controller. | ||
54 | |||
55 | See the file i2c-piix4 for some additional information. | ||
56 | |||
57 | |||
58 | Process Call Support | ||
59 | -------------------- | ||
60 | |||
61 | Not supported. | ||
62 | |||
63 | |||
64 | I2C Block Read Support | ||
65 | ---------------------- | ||
66 | |||
67 | Not supported at the moment. | ||
68 | |||
69 | |||
70 | SMBus 2.0 Support | ||
71 | ----------------- | ||
72 | |||
73 | The 82801DB (ICH4) and later chips support several SMBus 2.0 features. | ||
74 | |||
75 | ********************** | ||
76 | The lm_sensors project gratefully acknowledges the support of Texas | ||
77 | Instruments in the initial development of this driver. | ||
78 | |||
79 | The lm_sensors project gratefully acknowledges the support of Intel in the | ||
80 | development 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 @@ | |||
1 | Kernel driver i2c-i810 | ||
2 | |||
3 | Supported adapters: | ||
4 | * Intel 82810, 82810-DC100, 82810E, and 82815 (GMCH) | ||
5 | |||
6 | Authors: | ||
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 | |||
13 | Main contact: Mark Studebaker <mdsxyz123@yahoo.com> | ||
14 | |||
15 | Description | ||
16 | ----------- | ||
17 | |||
18 | WARNING: If you have an '810' or '815' motherboard, your standard I2C | ||
19 | temperature sensors are most likely on the 801's I2C bus. You want the | ||
20 | i2c-i801 driver for those, not this driver. | ||
21 | |||
22 | Now for the i2c-i810... | ||
23 | |||
24 | The GMCH chip contains two I2C interfaces. | ||
25 | |||
26 | The first interface is used for DDC (Data Display Channel) which is a | ||
27 | serial channel through the VGA monitor connector to a DDC-compliant | ||
28 | monitor. This interface is defined by the Video Electronics Standards | ||
29 | Association (VESA). The standards are available for purchase at | ||
30 | http://www.vesa.org . | ||
31 | |||
32 | The second interface is a general-purpose I2C bus. It may be connected to a | ||
33 | TV-out chip such as the BT869 or possibly to a digital flat-panel display. | ||
34 | |||
35 | Features | ||
36 | -------- | ||
37 | |||
38 | Both busses use the i2c-algo-bit driver for 'bit banging' | ||
39 | and support for specific transactions is provided by i2c-algo-bit. | ||
40 | |||
41 | Issues | ||
42 | ------ | ||
43 | |||
44 | If you enable bus testing in i2c-algo-bit (insmod i2c-algo-bit bit_test=1), | ||
45 | the test may fail; if so, the i2c-i810 driver won't be inserted. However, | ||
46 | we 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 @@ | |||
1 | Kernel driver i2c-nforce2 | ||
2 | |||
3 | Supported 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 | |||
10 | Datasheet: not publically available, but seems to be similar to the | ||
11 | AMD-8111 SMBus 2.0 adapter. | ||
12 | |||
13 | Authors: | ||
14 | Hans-Frieder Vogt <hfvogt@arcor.de>, | ||
15 | Thomas Leibold <thomas@plx.com>, | ||
16 | Patrick Dreker <patrick@dreker.de> | ||
17 | |||
18 | Description | ||
19 | ----------- | ||
20 | |||
21 | i2c-nforce2 is a driver for the SMBuses included in the nVidia nForce2 MCP. | ||
22 | |||
23 | If your 'lspci -v' listing shows something like the following, | ||
24 | |||
25 | 00: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 | |||
31 | then this driver should support the SMBuses of your motherboard. | ||
32 | |||
33 | |||
34 | Notes | ||
35 | ----- | ||
36 | |||
37 | The SMBus adapter in the nForce2 chipset seems to be very similar to the | ||
38 | SMBus 2.0 adapter in the AMD-8111 southbridge. However, I could only get | ||
39 | the driver to work with direct I/O access, which is different to the EC | ||
40 | interface of the AMD-8111. Tested on Asus A7N8X. The ACPI DSDT table of the | ||
41 | Asus 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 @@ | |||
1 | Kernel driver i2c-parport | ||
2 | |||
3 | Author: Jean Delvare <khali@linux-fr.org> | ||
4 | |||
5 | This is a unified driver for several i2c-over-parallel-port adapters, | ||
6 | such as the ones made by Philips, Velleman or ELV. This driver is | ||
7 | meant 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 | |||
14 | It 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 | |||
21 | These devices use different pinout configurations, so you have to tell | ||
22 | the driver what you have, using the type module parameter. There is no | ||
23 | way to autodetect the devices. Support for different pinout configurations | ||
24 | can be easily added when needed. | ||
25 | |||
26 | |||
27 | Building your own adapter | ||
28 | ------------------------- | ||
29 | |||
30 | If you want to build you own i2c-over-parallel-port adapter, here is | ||
31 | a sample electronics schema (credits go to Sylvain Munaut): | ||
32 | |||
33 | Device PC | ||
34 | Side ___________________Vdd (+) Side | ||
35 | | | | | ||
36 | --- --- --- | ||
37 | | | | | | | | ||
38 | |R| |R| |R| | ||
39 | | | | | | | | ||
40 | --- --- --- | ||
41 | | | | | ||
42 | | | /| | | ||
43 | SCL ----------x--------o |-----------x------------------- pin 2 | ||
44 | | \| | | | ||
45 | | | | | ||
46 | | |\ | | | ||
47 | SDA ----------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 | |||
63 | Remarks: | ||
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 | |||
84 | Device PC | ||
85 | Side ______________________________Vdd (+) Side | ||
86 | | | | | | ||
87 | --- --- --- --- | ||
88 | | | | | | | | | | ||
89 | |R| |R| |R| |R| | ||
90 | | | | | | | | | | ||
91 | --- --- --- --- | ||
92 | | | | | | ||
93 | | | |\ | | | ||
94 | SCL ----------x--------x--| o---x------------------------ pin 15 | ||
95 | | | |/ | | ||
96 | | | | | ||
97 | | | /| | | ||
98 | | ---o |-------------x-------------- pin 2 | ||
99 | | \| | | | ||
100 | | | | | ||
101 | | | | | ||
102 | | |\ | | | ||
103 | SDA ---------------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 | |||
120 | If possible, you should use the same pinout configuration as existing | ||
121 | adapters do, so you won't even have to change the code. | ||
122 | |||
123 | |||
124 | Similar (but different) drivers | ||
125 | ------------------------------- | ||
126 | |||
127 | This driver is NOT the same as the i2c-pport driver found in the i2c | ||
128 | package. The i2c-pport driver makes use of modern parallel port features so | ||
129 | that you don't need additional electronics. It has other restrictions | ||
130 | however, and was not ported to Linux 2.6 (yet). | ||
131 | |||
132 | This driver is also NOT the same as the i2c-pcf-epp driver found in the | ||
133 | lm_sensors package. The i2c-pcf-epp driver doesn't use the parallel port as | ||
134 | an I2C bus directly. Instead, it uses it to control an external I2C bus | ||
135 | master. That driver was not ported to Linux 2.6 (yet) either. | ||
136 | |||
137 | |||
138 | Legacy documentation for Velleman adapter | ||
139 | ----------------------------------------- | ||
140 | |||
141 | Useful links: | ||
142 | Velleman http://www.velleman.be/ | ||
143 | Velleman K8000 Howto http://howto.htlw16.ac.at/k8000-howto.html | ||
144 | |||
145 | The project has lead to new libs for the Velleman K8000 and K8005: | ||
146 | LIBK8000 v1.99.1 and LIBK8005 v0.21 | ||
147 | With these libs, you can control the K8000 interface card and the K8005 | ||
148 | stepper motor card with the simple commands which are in the original | ||
149 | Velleman software, like SetIOchannel, ReadADchannel, SendStepCCWFull and | ||
150 | many 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 @@ | |||
1 | Kernel driver i2c-parport-light | ||
2 | |||
3 | Author: Jean Delvare <khali@linux-fr.org> | ||
4 | |||
5 | This driver is a light version of i2c-parport. It doesn't depend | ||
6 | on the parport driver, and uses direct I/O access instead. This might be | ||
7 | prefered on embedded systems where wasting memory for the clean but heavy | ||
8 | parport handling is not an option. The drawback is a reduced portability | ||
9 | and the impossibility to daisy-chain other parallel port devices. | ||
10 | |||
11 | Please 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 @@ | |||
1 | Kernel driver i2c-pca-isa | ||
2 | |||
3 | Supported adapters: | ||
4 | This driver supports ISA boards using the Philips PCA 9564 | ||
5 | Parallel bus to I2C bus controller | ||
6 | |||
7 | Author: Ian Campbell <icampbell@arcom.com>, Arcom Control Systems | ||
8 | |||
9 | Module 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 | |||
19 | Description | ||
20 | ----------- | ||
21 | |||
22 | This driver supports ISA boards using the Philips PCA 9564 | ||
23 | Parallel 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 @@ | |||
1 | Kernel driver i2c-piix4 | ||
2 | |||
3 | Supported 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 | |||
12 | Authors: | ||
13 | Frodo Looijaard <frodol@dds.nl> | ||
14 | Philip Edelbrock <phil@netroedge.com> | ||
15 | |||
16 | |||
17 | Module 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 | |||
28 | Description | ||
29 | ----------- | ||
30 | |||
31 | The PIIX4 (properly known as the 82371AB) is an Intel chip with a lot of | ||
32 | functionality. Among other things, it implements the PCI bus. One of its | ||
33 | minor functions is implementing a System Management Bus. This is a true | ||
34 | SMBus - you can not access it on I2C levels. The good news is that it | ||
35 | natively understands SMBus commands and you do not have to worry about | ||
36 | timing problems. The bad news is that non-SMBus devices connected to it can | ||
37 | confuse it mightily. Yes, this is known to happen... | ||
38 | |||
39 | Do 'lspci -v' and see whether it contains an entry like this: | ||
40 | |||
41 | 0000:00:02.3 Bridge: Intel Corp. 82371AB/EB/MB PIIX4 ACPI (rev 02) | ||
42 | Flags: medium devsel, IRQ 9 | ||
43 | |||
44 | Bus and device numbers may differ, but the function number must be | ||
45 | identical (like many PCI devices, the PIIX4 incorporates a number of | ||
46 | different 'functions', which can be considered as separate devices). If you | ||
47 | find such an entry, you have a PIIX4 SMBus controller. | ||
48 | |||
49 | On some computers (most notably, some Dells), the SMBus is disabled by | ||
50 | default. If you use the insmod parameter 'force=1', the kernel module will | ||
51 | try to enable it. THIS IS VERY DANGEROUS! If the BIOS did not set up a | ||
52 | correct address for this module, you could get in big trouble (read: | ||
53 | crashes, data corruption, etc.). Try this only as a last resort (try BIOS | ||
54 | updates first, for example), and backup first! An even more dangerous | ||
55 | option 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 | ||
57 | parts of the PIIX4 needs a range of 8 of these addresses to function | ||
58 | correctly. If these addresses are already reserved by some other device, | ||
59 | you will get into big trouble! DON'T USE THIS IF YOU ARE NOT VERY SURE | ||
60 | ABOUT WHAT YOU ARE DOING! | ||
61 | |||
62 | The PIIX4E is just an new version of the PIIX4; it is supported as well. | ||
63 | The PIIX/PIIX3 does not implement an SMBus or I2C bus, so you can't use | ||
64 | this driver on those mainboards. | ||
65 | |||
66 | The ServerWorks Southbridges, the Intel 440MX, and the Victory766 are | ||
67 | identical to the PIIX4 in I2C/SMBus support. | ||
68 | |||
69 | A few OSB4 southbridges are known to be misconfigured by the BIOS. In this | ||
70 | case, you have you use the fix_hstcfg module parameter. Do not use it | ||
71 | unless you know you have to, because in some cases it also breaks | ||
72 | configuration 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 @@ | |||
1 | Kernel driver i2c-prosavage | ||
2 | |||
3 | Supported adapters: | ||
4 | |||
5 | S3/VIA KM266/VT8375 aka ProSavage8 | ||
6 | S3/VIA KM133/VT8365 aka Savage4 | ||
7 | |||
8 | Author: Henk Vergonet <henk@god.dyndns.org> | ||
9 | |||
10 | Description | ||
11 | ----------- | ||
12 | |||
13 | The Savage4 chips contain two I2C interfaces (aka a I2C 'master' or | ||
14 | 'host'). | ||
15 | |||
16 | The first interface is used for DDC (Data Display Channel) which is a | ||
17 | serial channel through the VGA monitor connector to a DDC-compliant | ||
18 | monitor. This interface is defined by the Video Electronics Standards | ||
19 | Association (VESA). The standards are available for purchase at | ||
20 | http://www.vesa.org . The second interface is a general-purpose I2C bus. | ||
21 | |||
22 | Usefull 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 @@ | |||
1 | Kernel driver i2c-savage4 | ||
2 | |||
3 | Supported adapters: | ||
4 | * Savage4 | ||
5 | * Savage2000 | ||
6 | |||
7 | Authors: | ||
8 | Alexander Wold <awold@bigfoot.com>, | ||
9 | Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
10 | |||
11 | Description | ||
12 | ----------- | ||
13 | |||
14 | The Savage4 chips contain two I2C interfaces (aka a I2C 'master' | ||
15 | or 'host'). | ||
16 | |||
17 | The first interface is used for DDC (Data Display Channel) which is a | ||
18 | serial channel through the VGA monitor connector to a DDC-compliant | ||
19 | monitor. This interface is defined by the Video Electronics Standards | ||
20 | Association (VESA). The standards are available for purchase at | ||
21 | http://www.vesa.org . The DDC bus is not yet supported because its register | ||
22 | is not directly memory-mapped. | ||
23 | |||
24 | The second interface is a general-purpose I2C bus. This is the only | ||
25 | interface 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 @@ | |||
1 | Kernel driver i2c-sis5595 | ||
2 | |||
3 | Authors: | ||
4 | Frodo Looijaard <frodol@dds.nl>, | ||
5 | Mark D. Studebaker <mdsxyz123@yahoo.com>, | ||
6 | Philip Edelbrock <phil@netroedge.com> | ||
7 | |||
8 | Supported adapters: | ||
9 | * Silicon Integrated Systems Corp. SiS5595 Southbridge | ||
10 | Datasheet: Publicly available at the Silicon Integrated Systems Corp. site. | ||
11 | |||
12 | Note: 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 | |||
40 | Module 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 | |||
49 | Description | ||
50 | ----------- | ||
51 | |||
52 | i2c-sis5595 is a true SMBus host driver for motherboards with the SiS5595 | ||
53 | southbridges. | ||
54 | |||
55 | WARNING: If you are trying to access the integrated sensors on the SiS5595 | ||
56 | chip, you want the sis5595 driver for those, not this driver. This driver | ||
57 | is a BUS driver, not a CHIP driver. A BUS driver is used by other CHIP | ||
58 | drivers 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 @@ | |||
1 | Kernel driver i2c-sis630 | ||
2 | |||
3 | Supported 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 | |||
9 | Author: Alexander Malysh <amalysh@web.de> | ||
10 | |||
11 | Module 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 | |||
23 | Description | ||
24 | ----------- | ||
25 | |||
26 | This SMBus only driver is known to work on motherboards with the above | ||
27 | named chipsets. | ||
28 | |||
29 | If you see something like this: | ||
30 | |||
31 | 00:00.0 Host bridge: Silicon Integrated Systems [SiS] 630 Host (rev 31) | ||
32 | 00:01.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513 | ||
33 | |||
34 | or like this: | ||
35 | |||
36 | 00:00.0 Host bridge: Silicon Integrated Systems [SiS] 730 Host (rev 02) | ||
37 | 00:01.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513 | ||
38 | |||
39 | in your 'lspci' output , then this driver is for your chipset. | ||
40 | |||
41 | Thank You | ||
42 | --------- | ||
43 | Philip Edelbrock <phil@netroedge.com> | ||
44 | - testing SiS730 support | ||
45 | Mark M. Hoffman <mhoffman@lightlink.com> | ||
46 | - bug fixes | ||
47 | |||
48 | To 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 @@ | |||
1 | Kernel driver i2c-sis96x | ||
2 | |||
3 | Replaces 2.4.x i2c-sis645 | ||
4 | |||
5 | Supported 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 | |||
12 | Author: Mark M. Hoffman <mhoffman@lightlink.com> | ||
13 | |||
14 | Description | ||
15 | ----------- | ||
16 | |||
17 | This SMBus only driver is known to work on motherboards with the above | ||
18 | named chipset combinations. The driver was developed without benefit of a | ||
19 | proper datasheet from SiS. The SMBus registers are assumed compatible with | ||
20 | those of the SiS630, although they are located in a completely different | ||
21 | place. Thanks to Alexander Malysh <amalysh@web.de> for providing the | ||
22 | SiS630 datasheet (and driver). | ||
23 | |||
24 | The command "lspci" as root should produce something like these lines: | ||
25 | |||
26 | 00:00.0 Host bridge: Silicon Integrated Systems [SiS]: Unknown device 0645 | ||
27 | 00:02.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513 | ||
28 | 00:02.1 SMBus: Silicon Integrated Systems [SiS]: Unknown device 0016 | ||
29 | |||
30 | or perhaps this... | ||
31 | |||
32 | 00:00.0 Host bridge: Silicon Integrated Systems [SiS]: Unknown device 0645 | ||
33 | 00:02.0 ISA bridge: Silicon Integrated Systems [SiS]: Unknown device 0961 | ||
34 | 00: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 | |||
38 | If you cant see it please look on quirk_sis_96x_smbus | ||
39 | (drivers/pci/quirks.c) (also if southbridge detection fails) | ||
40 | |||
41 | I suspect that this driver could be made to work for the following SiS | ||
42 | chipsets as well: 635, and 635T. If anyone owns a board with those chips | ||
43 | AND is willing to risk crashing & burning an otherwise well-behaved kernel | ||
44 | in the name of progress... please contact me at <mhoffman@lightlink.com> or | ||
45 | via the project's mailing list: <sensors@stimpy.netroedge.com>. Please | ||
46 | send bug reports and/or success stories as well. | ||
47 | |||
48 | |||
49 | TO DOs | ||
50 | ------ | ||
51 | |||
52 | * The driver does not support SMBus block reads/writes; I may add them if a | ||
53 | scenario is found where they're needed. | ||
54 | |||
55 | |||
56 | Thank You | ||
57 | --------- | ||
58 | |||
59 | Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
60 | - design hints and bug fixes | ||
61 | Alexander Maylsh <amalysh@web.de> | ||
62 | - ditto, plus an important datasheet... almost the one I really wanted | ||
63 | Hans-Günter Lütke Uphues <hg_lu@t-online.de> | ||
64 | - patch for SiS735 | ||
65 | Robert Zwerus <arzie@dds.nl> | ||
66 | - testing for SiS645DX | ||
67 | Kianusch Sayah Karadji <kianusch@sk-tech.net> | ||
68 | - patch for SiS645DX/962 | ||
69 | Ken Healy | ||
70 | - patch for SiS655 | ||
71 | |||
72 | To 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 @@ | |||
1 | Kernel driver i2c-via | ||
2 | |||
3 | Supported adapters: | ||
4 | * VIA Technologies, InC. VT82C586B | ||
5 | Datasheet: Publicly available at the VIA website | ||
6 | |||
7 | Author: Kyösti Mälkki <kmalkki@cc.hut.fi> | ||
8 | |||
9 | Description | ||
10 | ----------- | ||
11 | |||
12 | i2c-via is an i2c bus driver for motherboards with VIA chipset. | ||
13 | |||
14 | The following VIA pci chipsets are supported: | ||
15 | - MVP3, VP3, VP2/97, VPX/97 | ||
16 | - others with South bridge VT82C586B | ||
17 | |||
18 | Your 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 @@ | |||
1 | Kernel driver i2c-viapro | ||
2 | |||
3 | Supported 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 | |||
13 | Authors: | ||
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 | |||
19 | Module 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 | |||
27 | Description | ||
28 | ----------- | ||
29 | |||
30 | i2c-viapro is a true SMBus host driver for motherboards with one of the | ||
31 | supported VIA southbridges. | ||
32 | |||
33 | Your 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 | |||
44 | If none of these show up, you should look in the BIOS for settings like | ||
45 | enable 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 @@ | |||
1 | Kernel driver i2c-voodoo3 | ||
2 | |||
3 | Supported adapters: | ||
4 | * 3dfx Voodoo3 based cards | ||
5 | * Voodoo Banshee based cards | ||
6 | |||
7 | Authors: | ||
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 | |||
13 | Main contact: Philip Edelbrock <phil@netroedge.com> | ||
14 | |||
15 | The code is based upon Ralph's test code (he did the hard stuff ;') | ||
16 | |||
17 | Description | ||
18 | ----------- | ||
19 | |||
20 | The 3dfx Voodoo3 chip contains two I2C interfaces (aka a I2C 'master' or | ||
21 | 'host'). | ||
22 | |||
23 | The first interface is used for DDC (Data Display Channel) which is a | ||
24 | serial channel through the VGA monitor connector to a DDC-compliant | ||
25 | monitor. This interface is defined by the Video Electronics Standards | ||
26 | Association (VESA). The standards are available for purchase at | ||
27 | http://www.vesa.org . | ||
28 | |||
29 | The second interface is a general-purpose I2C bus. The intent by 3dfx was | ||
30 | to allow manufacturers to add extra chips to the video card such as a | ||
31 | TV-out chip such as the BT869 or possibly even I2C based temperature | ||
32 | sensors like the ADM1021 or LM75. | ||
33 | |||
34 | Stability | ||
35 | --------- | ||
36 | |||
37 | Seems to be stable on the test machine, but needs more testing on other | ||
38 | machines. Simultaneous accesses of the DDC and I2C busses may cause errors. | ||
39 | |||
40 | Supported Devices | ||
41 | ----------------- | ||
42 | |||
43 | Specifically, this driver was written and tested on the '3dfx Voodoo3 AGP | ||
44 | 3000' which has a tv-out feature (s-video or composite). According to the | ||
45 | docs and discussions, this code should work for any Voodoo3 based cards as | ||
46 | well as Voodoo Banshee based cards. The DDC interface has been tested on a | ||
47 | Voodoo Banshee card. | ||
48 | |||
49 | Issues | ||
50 | ------ | ||
51 | |||
52 | Probably many, but it seems to work OK on my system. :') | ||
53 | |||
54 | |||
55 | External Device Connection | ||
56 | -------------------------- | ||
57 | |||
58 | The digital video input jumpers give availability to the I2C bus. | ||
59 | Specifically, pins 13 and 25 (bottom row middle, and bottom right-end) are | ||
60 | the I2C clock and I2C data lines, respectively. +5V and GND are probably | ||
61 | also easily available making the addition of extra I2C/SMBus devices easy | ||
62 | to 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 @@ | |||
1 | Kernel driver scx200_acb | ||
2 | |||
3 | Author: Christer Weinigel <wingel@nano-system.com> | ||
4 | |||
5 | Module Parameters | ||
6 | ----------------- | ||
7 | |||
8 | * base: int | ||
9 | Base addresses for the ACCESS.bus controllers | ||
10 | |||
11 | Description | ||
12 | ----------- | ||
13 | |||
14 | Enable 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 @@ | |||
1 | November 23, 2004 | ||
2 | |||
3 | The following specification describes the SMSC LPC47B397-NC sensor chip | ||
4 | (for which there is no public datasheet available). This document was | ||
5 | provided by Craig Kelly (In-Store Broadcast Network) and edited/corrected | ||
6 | by Mark M. Hoffman <mhoffman@lightlink.com>. | ||
7 | |||
8 | * * * * * | ||
9 | |||
10 | Methods for detecting the HP SIO and reading the thermal data on a dc7100. | ||
11 | |||
12 | The 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 | ||
14 | pair is located at the HWM Base Address + 0 and the HWM Base Address + 1. The | ||
15 | HWM Base address can be obtained from Logical Device 8, registers 0x60 (MSB) | ||
16 | and 0x61 (LSB). Currently we are using 0x480 for the HWM Base Address and | ||
17 | 0x480 and 0x481 for the index/data pair. | ||
18 | |||
19 | Reading temperature information. | ||
20 | The temperature information is located in the following registers: | ||
21 | Temp1 0x25 (Currently, this reflects the CPU temp on all systems). | ||
22 | Temp2 0x26 | ||
23 | Temp3 0x27 | ||
24 | Temp4 0x80 | ||
25 | |||
26 | Programming Example | ||
27 | The following is an example of how to read the HWM temperature registers: | ||
28 | MOV DX,480H | ||
29 | MOV AX,25H | ||
30 | OUT DX,AL | ||
31 | MOV DX,481H | ||
32 | IN AL,DX | ||
33 | |||
34 | AL contains the data in hex, the temperature in Celsius is the decimal | ||
35 | equivalent. | ||
36 | |||
37 | Ex: If AL contains 0x2A, the temperature is 42 degrees C. | ||
38 | |||
39 | Reading tach information. | ||
40 | The fan speed information is located in the following registers: | ||
41 | LSB MSB | ||
42 | Tach1 0x28 0x29 (Currently, this reflects the CPU | ||
43 | fan speed on all systems). | ||
44 | Tach2 0x2A 0x2B | ||
45 | Tach3 0x2C 0x2D | ||
46 | Tach4 0x2E 0x2F | ||
47 | |||
48 | Important!!! | ||
49 | Reading the tach LSB locks the tach MSB. | ||
50 | The LSB Must be read first. | ||
51 | |||
52 | How to convert the tach reading to RPM. | ||
53 | The tach reading (TCount) is given by: (Tach MSB * 256) + (Tach LSB) | ||
54 | The SIO counts the number of 90kHz (11.111us) pulses per revolution. | ||
55 | RPM = 60/(TCount * 11.111us) | ||
56 | |||
57 | Example: | ||
58 | Reg 0x28 = 0x9B | ||
59 | Reg 0x29 = 0x08 | ||
60 | |||
61 | TCount = 0x89B = 2203 | ||
62 | |||
63 | RPM = 60 / (2203 * 11.11111 E-6) = 2451 RPM | ||
64 | |||
65 | Obtaining the SIO version. | ||
66 | |||
67 | CONFIGURATION SEQUENCE | ||
68 | To program the configuration registers, the following sequence must be followed: | ||
69 | 1. Enter Configuration Mode | ||
70 | 2. Configure the Configuration Registers | ||
71 | 3. Exit Configuration Mode. | ||
72 | |||
73 | Enter Configuration Mode | ||
74 | To place the chip into the Configuration State The config key (0x55) is written | ||
75 | to the CONFIG PORT (0x2E). | ||
76 | |||
77 | Configuration Mode | ||
78 | In configuration mode, the INDEX PORT is located at the CONFIG PORT address and | ||
79 | the DATA PORT is at INDEX PORT address + 1. | ||
80 | |||
81 | The desired configuration registers are accessed in two steps: | ||
82 | a. 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 | |||
86 | b. 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 | |||
90 | Note: If accessing the Global Configuration Registers, step (a) is not required. | ||
91 | |||
92 | Exit Configuration Mode | ||
93 | To exit the Configuration State the write 0xAA to the CONFIG PORT (0x2E). | ||
94 | The chip returns to the RUN State. (This is important). | ||
95 | |||
96 | Programming Example | ||
97 | The following is an example of how to read the SIO Device ID located at 0x20 | ||
98 | |||
99 | ; ENTER CONFIGURATION MODE | ||
100 | MOV DX,02EH | ||
101 | MOV AX,055H | ||
102 | OUT DX,AL | ||
103 | ; GLOBAL CONFIGURATION REGISTER | ||
104 | MOV DX,02EH | ||
105 | MOV AL,20H | ||
106 | OUT DX,AL | ||
107 | ; READ THE DATA | ||
108 | MOV DX,02FH | ||
109 | IN AL,DX | ||
110 | ; EXIT CONFIGURATION MODE | ||
111 | MOV DX,02EH | ||
112 | MOV AX,0AAH | ||
113 | OUT DX,AL | ||
114 | |||
115 | The registers of interest for identifying the SIO on the dc7100 are Device ID | ||
116 | (0x20) and Device Rev (0x21). | ||
117 | |||
118 | The Device ID will read 0X6F | ||
119 | The Device Rev currently reads 0x01 | ||
120 | |||
121 | Obtaining the HWM Base Address. | ||
122 | The following is an example of how to read the HWM Base Address located in | ||
123 | Logical Device 8. | ||
124 | |||
125 | ; ENTER CONFIGURATION MODE | ||
126 | MOV DX,02EH | ||
127 | MOV AX,055H | ||
128 | OUT DX,AL | ||
129 | ; CONFIGURE REGISTER CRE0, | ||
130 | ; LOGICAL DEVICE 8 | ||
131 | MOV DX,02EH | ||
132 | MOV AL,07H | ||
133 | OUT DX,AL ;Point to LD# Config Reg | ||
134 | MOV DX,02FH | ||
135 | MOV AL, 08H | ||
136 | OUT DX,AL;Point to Logical Device 8 | ||
137 | ; | ||
138 | MOV DX,02EH | ||
139 | MOV AL,60H | ||
140 | OUT DX,AL ; Point to HWM Base Addr MSB | ||
141 | MOV DX,02FH | ||
142 | IN AL,DX ; Get MSB of HWM Base Addr | ||
143 | ; EXIT CONFIGURATION MODE | ||
144 | MOV DX,02EH | ||
145 | MOV AX,0AAH | ||
146 | OUT 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 @@ | |||
1 | Usually, i2c devices are controlled by a kernel driver. But it is also | ||
2 | possible to access all devices on an adapter from userspace, through | ||
3 | the /dev interface. You need to load module i2c-dev for this. | ||
4 | |||
5 | Each registered i2c adapter gets a number, counting from 0. You can | ||
6 | examine /sys/class/i2c-dev/ to see what number corresponds to which adapter. | ||
7 | I2C device files are character device files with major device number 89 | ||
8 | and a minor device number corresponding to the number assigned as | ||
9 | explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., | ||
10 | i2c-10, ...). All 256 minor device numbers are reserved for i2c. | ||
11 | |||
12 | |||
13 | C example | ||
14 | ========= | ||
15 | |||
16 | So let's say you want to access an i2c adapter from a C program. The | ||
17 | first thing to do is `#include <linux/i2c.h>" and "#include <linux/i2c-dev.h>. | ||
18 | Yes, I know, you should never include kernel header files, but until glibc | ||
19 | knows about i2c, there is not much choice. | ||
20 | |||
21 | Now, you have to decide which adapter you want to access. You should | ||
22 | inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned | ||
23 | somewhat dynamically, so you can not even assume /dev/i2c-0 is the | ||
24 | first adapter. | ||
25 | |||
26 | Next 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 | |||
37 | When you have opened the device, you must specify with what device | ||
38 | address 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 | |||
45 | Well, you are all set up now. You can now use SMBus commands or plain | ||
46 | I2C to communicate with your device. SMBus commands are preferred if | ||
47 | the 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 | |||
73 | IMPORTANT: because of the use of inline functions, you *have* to use | ||
74 | '-O' or some variation when you compile your program! | ||
75 | |||
76 | |||
77 | Full interface description | ||
78 | ========================== | ||
79 | |||
80 | The following IOCTLs are defined and fully supported | ||
81 | (see also i2c-dev.h and i2c.h): | ||
82 | |||
83 | ioctl(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 | |||
88 | ioctl(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 | |||
92 | ioctl(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 | |||
97 | ioctl(file,I2C_FUNCS,unsigned long *funcs) | ||
98 | Gets the adapter functionality and puts it in *funcs. | ||
99 | |||
100 | ioctl(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 | |||
116 | Other values are NOT supported at this moment, except for I2C_SMBUS, | ||
117 | which you should never directly call; instead, use the access functions | ||
118 | below. | ||
119 | |||
120 | You can do plain i2c transactions by using read(2) and write(2) calls. | ||
121 | You do not need to pass the address byte; instead, set it through | ||
122 | ioctl I2C_SLAVE before you try to access the device. | ||
123 | |||
124 | You can do SMBus level transactions (see documentation file smbus-protocol | ||
125 | for 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); | ||
137 | All these transactions return -1 on failure; you can read errno to see | ||
138 | what happened. The 'write' transactions return 0 on success; the | ||
139 | 'read' transactions return the read value, except for read_block, which | ||
140 | returns the number of values read. The block buffers need not be longer | ||
141 | than 32 bytes. | ||
142 | |||
143 | The above functions are all macros, that resolve to calls to the | ||
144 | i2c_smbus_access function, that on its turn calls a specific ioctl | ||
145 | with the data in a specific format. Read the source code if you | ||
146 | want 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 @@ | |||
1 | INTRODUCTION | ||
2 | ------------ | ||
3 | |||
4 | Because not every I2C or SMBus adapter implements everything in the | ||
5 | I2C specifications, a client can not trust that everything it needs | ||
6 | is implemented when it is given the option to attach to an adapter: | ||
7 | the client needs some way to check whether an adapter has the needed | ||
8 | functionality. | ||
9 | |||
10 | |||
11 | FUNCTIONALITY CONSTANTS | ||
12 | ----------------------- | ||
13 | |||
14 | For 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 | |||
36 | A 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 | |||
53 | ALGORITHM/ADAPTER IMPLEMENTATION | ||
54 | -------------------------------- | ||
55 | |||
56 | When you write a new algorithm driver, you will have to implement a | ||
57 | function callback `functionality', that gets an i2c_adapter structure | ||
58 | pointer 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 | |||
65 | A 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 | |||
75 | CLIENT CHECKING | ||
76 | --------------- | ||
77 | |||
78 | Before a client tries to attach to an adapter, or even do tests to check | ||
79 | whether one of the devices it supports is present on an adapter, it should | ||
80 | check whether the needed functionality is present. There are two functions | ||
81 | defined which should be used instead of calling the functionality hook | ||
82 | in 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 | |||
90 | This is a typical way to use these functions (from the writing-clients | ||
91 | document): | ||
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 | |||
112 | CHECKING THROUGH /DEV | ||
113 | --------------------- | ||
114 | |||
115 | If you try to access an adapter from a userspace program, you will have | ||
116 | to use the /dev interface. You will still have to check whether the | ||
117 | functionality you need is supported, of course. This is done using | ||
118 | the I2C_FUNCS ioctl. An example, adapted from the lm_sensors i2c_detect | ||
119 | program, 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 @@ | |||
1 | This document describes the i2c protocol. Or will, when it is finished :-) | ||
2 | |||
3 | Key to symbols | ||
4 | ============== | ||
5 | |||
6 | S (1 bit) : Start bit | ||
7 | P (1 bit) : Stop bit | ||
8 | Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. | ||
9 | A, NA (1 bit) : Accept and reverse accept bit. | ||
10 | Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to | ||
11 | get a 10 bit I2C address. | ||
12 | Comm (8 bits): Command byte, a data byte which often selects a register on | ||
13 | the device. | ||
14 | Data (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh | ||
15 | for 16 bit data. | ||
16 | Count (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 | |||
21 | Simple send transaction | ||
22 | ====================== | ||
23 | |||
24 | This corresponds to i2c_master_send. | ||
25 | |||
26 | S Addr Wr [A] Data [A] Data [A] ... [A] Data [A] P | ||
27 | |||
28 | |||
29 | Simple receive transaction | ||
30 | =========================== | ||
31 | |||
32 | This corresponds to i2c_master_recv | ||
33 | |||
34 | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P | ||
35 | |||
36 | |||
37 | Combined transactions | ||
38 | ==================== | ||
39 | |||
40 | This corresponds to i2c_transfer | ||
41 | |||
42 | They are just like the above transactions, but instead of a stop bit P | ||
43 | a start bit S is sent and the transaction continues. An example of | ||
44 | a byte read, followed by a byte write: | ||
45 | |||
46 | S Addr Rd [A] [Data] NA S Addr Wr [A] Data [A] P | ||
47 | |||
48 | |||
49 | Modified transactions | ||
50 | ===================== | ||
51 | |||
52 | We 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 @@ | |||
1 | MODULE: i2c-stub | ||
2 | |||
3 | DESCRIPTION: | ||
4 | |||
5 | This module is a very simple fake I2C/SMBus driver. It implements four | ||
6 | types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and | ||
7 | (r/w) word data. | ||
8 | |||
9 | No hardware is needed nor associated with this module. It will accept write | ||
10 | quick commands to all addresses; it will respond to the other commands (also | ||
11 | to all addresses) by reading from or writing to an array in memory. It will | ||
12 | also spam the kernel logs for every command it handles. | ||
13 | |||
14 | A pointer register with auto-increment is implemented for all byte | ||
15 | operations. This allows for continuous byte reads like those supported by | ||
16 | EEPROMs, among others. | ||
17 | |||
18 | The 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 | |||
24 | CAVEATS: | ||
25 | |||
26 | There are independent arrays for byte/data and word/data commands. Depending | ||
27 | on if/how a target driver mixes them, you'll need to be careful. | ||
28 | |||
29 | If your target driver polls some byte or word waiting for it to change, the | ||
30 | stub could lock it up. Use i2cset to unlock it. | ||
31 | |||
32 | If the hardware for your driver has banked registers (e.g. Winbond sensors | ||
33 | chips) this module will not work well - although it could be extended to | ||
34 | support that pretty easily. | ||
35 | |||
36 | If you spam it hard enough, printk can be lossy. This module really wants | ||
37 | something 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 @@ | |||
1 | Revision 4, 2004-03-30 | ||
2 | Jean Delvare <khali@linux-fr.org> | ||
3 | Greg KH <greg@kroah.com> | ||
4 | |||
5 | This is a guide on how to convert I2C chip drivers from Linux 2.4 to | ||
6 | Linux 2.6. I have been using existing drivers (lm75, lm78) as examples. | ||
7 | Then I converted a driver myself (lm83) and updated this document. | ||
8 | |||
9 | There are two sets of points below. The first set concerns technical | ||
10 | changes. The second set concerns coding policy. Both are mandatory. | ||
11 | |||
12 | Although reading this guide will help you porting drivers, I suggest | ||
13 | you keep an eye on an already ported driver while porting your own | ||
14 | driver. This will help you a lot understanding what this guide | ||
15 | exactly means. Choose the chip driver that is the more similar to | ||
16 | yours for best results. | ||
17 | |||
18 | Technical 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 | |||
105 | Coding 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 @@ | |||
1 | SMBus Protocol Summary | ||
2 | ====================== | ||
3 | The following is a summary of the SMBus protocol. It applies to | ||
4 | all revisions of the protocol (1.0, 1.1, and 2.0). | ||
5 | Certain protocol features which are not supported by | ||
6 | this package are briefly described at the end of this document. | ||
7 | |||
8 | Some adapters understand only the SMBus (System Management Bus) protocol, | ||
9 | which is a subset from the I2C protocol. Fortunately, many devices use | ||
10 | only the same subset, which makes it possible to put them on an SMBus. | ||
11 | If you write a driver for some I2C device, please try to use the SMBus | ||
12 | commands if at all possible (if the device uses only that subset of the | ||
13 | I2C protocol). This makes it possible to use the device driver on both | ||
14 | SMBus adapters and I2C adapters (the SMBus command set is automatically | ||
15 | translated to I2C on I2C adapters, but plain I2C commands can not be | ||
16 | handled at all on most pure SMBus adapters). | ||
17 | |||
18 | Below is a list of SMBus commands. | ||
19 | |||
20 | Key to symbols | ||
21 | ============== | ||
22 | |||
23 | S (1 bit) : Start bit | ||
24 | P (1 bit) : Stop bit | ||
25 | Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. | ||
26 | A, NA (1 bit) : Accept and reverse accept bit. | ||
27 | Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to | ||
28 | get a 10 bit I2C address. | ||
29 | Comm (8 bits): Command byte, a data byte which often selects a register on | ||
30 | the device. | ||
31 | Data (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh | ||
32 | for 16 bit data. | ||
33 | Count (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 | |||
38 | SMBus Write Quick | ||
39 | ================= | ||
40 | |||
41 | This sends a single bit to the device, at the place of the Rd/Wr bit. | ||
42 | There is no equivalent Read Quick command. | ||
43 | |||
44 | A Addr Rd/Wr [A] P | ||
45 | |||
46 | |||
47 | SMBus Read Byte | ||
48 | =============== | ||
49 | |||
50 | This reads a single byte from a device, without specifying a device | ||
51 | register. Some devices are so simple that this interface is enough; for | ||
52 | others, it is a shorthand if you want to read the same register as in | ||
53 | the previous SMBus command. | ||
54 | |||
55 | S Addr Rd [A] [Data] NA P | ||
56 | |||
57 | |||
58 | SMBus Write Byte | ||
59 | ================ | ||
60 | |||
61 | This is the reverse of Read Byte: it sends a single byte to a device. | ||
62 | See Read Byte for more information. | ||
63 | |||
64 | S Addr Wr [A] Data [A] P | ||
65 | |||
66 | |||
67 | SMBus Read Byte Data | ||
68 | ==================== | ||
69 | |||
70 | This reads a single byte from a device, from a designated register. | ||
71 | The register is specified through the Comm byte. | ||
72 | |||
73 | S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P | ||
74 | |||
75 | |||
76 | SMBus Read Word Data | ||
77 | ==================== | ||
78 | |||
79 | This command is very like Read Byte Data; again, data is read from a | ||
80 | device, from a designated register that is specified through the Comm | ||
81 | byte. But this time, the data is a complete word (16 bits). | ||
82 | |||
83 | S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P | ||
84 | |||
85 | |||
86 | SMBus Write Byte Data | ||
87 | ===================== | ||
88 | |||
89 | This writes a single byte to a device, to a designated register. The | ||
90 | register is specified through the Comm byte. This is the opposite of | ||
91 | the Read Byte Data command. | ||
92 | |||
93 | S Addr Wr [A] Comm [A] Data [A] P | ||
94 | |||
95 | |||
96 | SMBus Write Word Data | ||
97 | ===================== | ||
98 | |||
99 | This is the opposite operation of the Read Word Data command. 16 bits | ||
100 | of data is read from a device, from a designated register that is | ||
101 | specified through the Comm byte. | ||
102 | |||
103 | S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P | ||
104 | |||
105 | |||
106 | SMBus Process Call | ||
107 | ================== | ||
108 | |||
109 | This command selects a device register (through the Comm byte), sends | ||
110 | 16 bits of data to it, and reads 16 bits of data in return. | ||
111 | |||
112 | S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] | ||
113 | S Addr Rd [A] [DataLow] A [DataHigh] NA P | ||
114 | |||
115 | |||
116 | SMBus Block Read | ||
117 | ================ | ||
118 | |||
119 | This command reads a block of up to 32 bytes from a device, from a | ||
120 | designated register that is specified through the Comm byte. The amount | ||
121 | of data is specified by the device in the Count byte. | ||
122 | |||
123 | S Addr Wr [A] Comm [A] | ||
124 | S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P | ||
125 | |||
126 | |||
127 | SMBus Block Write | ||
128 | ================= | ||
129 | |||
130 | The opposite of the Block Read command, this writes up to 32 bytes to | ||
131 | a device, to a designated register that is specified through the | ||
132 | Comm byte. The amount of data is specified in the Count byte. | ||
133 | |||
134 | S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P | ||
135 | |||
136 | |||
137 | SMBus Block Process Call | ||
138 | ======================== | ||
139 | |||
140 | SMBus Block Process Call was introduced in Revision 2.0 of the specification. | ||
141 | |||
142 | This command selects a device register (through the Comm byte), sends | ||
143 | 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return. | ||
144 | |||
145 | S Addr Wr [A] Comm [A] Count [A] Data [A] ... | ||
146 | S Addr Rd [A] [Count] A [Data] ... A P | ||
147 | |||
148 | |||
149 | SMBus Host Notify | ||
150 | ================= | ||
151 | |||
152 | This command is sent from a SMBus device acting as a master to the | ||
153 | SMBus host acting as a slave. | ||
154 | It is the same form as Write Word, with the command code replaced by the | ||
155 | alerting device's address. | ||
156 | |||
157 | [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P] | ||
158 | |||
159 | |||
160 | Packet Error Checking (PEC) | ||
161 | =========================== | ||
162 | Packet Error Checking was introduced in Revision 1.1 of the specification. | ||
163 | |||
164 | PEC adds a CRC-8 error-checking byte to all transfers. | ||
165 | |||
166 | |||
167 | Address Resolution Protocol (ARP) | ||
168 | ================================= | ||
169 | The Address Resolution Protocol was introduced in Revision 2.0 of | ||
170 | the specification. It is a higher-layer protocol which uses the | ||
171 | messages above. | ||
172 | |||
173 | ARP adds device enumeration and dynamic address assignment to | ||
174 | the protocol. All ARP communications use slave address 0x61 and | ||
175 | require PEC checksums. | ||
176 | |||
177 | |||
178 | I2C Block Transactions | ||
179 | ====================== | ||
180 | The following I2C block transactions are supported by the | ||
181 | SMBus layer and are described here for completeness. | ||
182 | I2C block transactions do not limit the number of bytes transferred | ||
183 | but the SMBus layer places a limit of 32 bytes. | ||
184 | |||
185 | |||
186 | I2C Block Read | ||
187 | ============== | ||
188 | |||
189 | This command reads a block of bytes from a device, from a | ||
190 | designated register that is specified through the Comm byte. | ||
191 | |||
192 | S Addr Wr [A] Comm [A] | ||
193 | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P | ||
194 | |||
195 | |||
196 | I2C Block Read (2 Comm bytes) | ||
197 | ============================= | ||
198 | |||
199 | This command reads a block of bytes from a device, from a | ||
200 | designated register that is specified through the two Comm bytes. | ||
201 | |||
202 | S Addr Wr [A] Comm1 [A] Comm2 [A] | ||
203 | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P | ||
204 | |||
205 | |||
206 | I2C Block Write | ||
207 | =============== | ||
208 | |||
209 | The opposite of the Block Read command, this writes bytes to | ||
210 | a device, to a designated register that is specified through the | ||
211 | Comm byte. Note that command lengths of 0, 2, or more bytes are | ||
212 | supported as they are indistinguishable from data. | ||
213 | |||
214 | S 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 @@ | |||
1 | This is an explanation of what i2c is, and what is supported in this package. | ||
2 | |||
3 | I2C and SMBus | ||
4 | ============= | ||
5 | |||
6 | I2C (pronounce: I squared C) is a protocol developed by Philips. It is a | ||
7 | slow two-wire protocol (10-400 kHz), but it suffices for many types of | ||
8 | devices. | ||
9 | |||
10 | SMBus (System Management Bus) is a subset of the I2C protocol. Many | ||
11 | modern mainboards have a System Management Bus. There are a lot of | ||
12 | devices which can be connected to a SMBus; the most notable are modern | ||
13 | memory chips with EEPROM memories and chips for hardware monitoring. | ||
14 | |||
15 | Because the SMBus is just a special case of the generalized I2C bus, we | ||
16 | can simulate the SMBus protocol on plain I2C busses. The reverse is | ||
17 | regretfully impossible. | ||
18 | |||
19 | |||
20 | Terminology | ||
21 | =========== | ||
22 | |||
23 | When we talk about I2C, we use the following terms: | ||
24 | Bus -> Algorithm | ||
25 | Adapter | ||
26 | Device -> Driver | ||
27 | Client | ||
28 | |||
29 | An Algorithm driver contains general code that can be used for a whole class | ||
30 | of I2C adapters. Each specific adapter driver depends on one algorithm | ||
31 | driver. | ||
32 | A Driver driver (yes, this sounds ridiculous, sorry) contains the general | ||
33 | code to access some type of device. Each detected device gets its own | ||
34 | data in the Client structure. Usually, Driver and Client are more closely | ||
35 | integrated than Algorithm and Adapter. | ||
36 | |||
37 | For a given configuration, you will need a driver for your I2C bus (usually | ||
38 | a separate Adapter and Algorithm driver), and drivers for your I2C devices | ||
39 | (usually one driver for each device). There are no I2C device drivers | ||
40 | in this package. See the lm_sensors project http://www.lm-sensors.nu | ||
41 | for device drivers. | ||
42 | |||
43 | |||
44 | Included Bus Drivers | ||
45 | ==================== | ||
46 | Note that only stable drivers are patched into the kernel by 'mkpatch'. | ||
47 | |||
48 | |||
49 | Base modules | ||
50 | ------------ | ||
51 | |||
52 | i2c-core: The basic I2C code, including the /proc/bus/i2c* interface | ||
53 | i2c-dev: The /dev/i2c-* interface | ||
54 | i2c-proc: The /proc/sys/dev/sensors interface for device (client) drivers | ||
55 | |||
56 | Algorithm drivers | ||
57 | ----------------- | ||
58 | |||
59 | i2c-algo-8xx: An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT) | ||
60 | i2c-algo-bit: A bit-banging algorithm | ||
61 | i2c-algo-pcf: A PCF 8584 style algorithm | ||
62 | i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT) | ||
63 | |||
64 | Adapter drivers | ||
65 | --------------- | ||
66 | |||
67 | i2c-elektor: Elektor ISA card (uses i2c-algo-pcf) | ||
68 | i2c-elv: ELV parallel port adapter (uses i2c-algo-bit) | ||
69 | i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched) | ||
70 | i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit) | ||
71 | i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT) | ||
72 | i2c-pport: Primitive parallel port adapter (uses i2c-algo-bit) | ||
73 | i2c-rpx: RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT) | ||
74 | i2c-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 @@ | |||
1 | Naming and data format standards for sysfs files | ||
2 | ------------------------------------------------ | ||
3 | |||
4 | The libsensors library offers an interface to the raw sensors data | ||
5 | through the sysfs interface. See libsensors documentation and source for | ||
6 | more further information. As of writing this document, libsensors | ||
7 | (from lm_sensors 2.8.3) is heavily chip-dependant. Adding or updating | ||
8 | support for any given chip requires modifying the library's code. | ||
9 | This is because libsensors was written for the procfs interface | ||
10 | older kernel modules were using, which wasn't standardized enough. | ||
11 | Recent versions of libsensors (from lm_sensors 2.8.2 and later) have | ||
12 | support for the sysfs interface, though. | ||
13 | |||
14 | The new sysfs interface was designed to be as chip-independant as | ||
15 | possible. | ||
16 | |||
17 | Note that motherboards vary widely in the connections to sensor chips. | ||
18 | There is no standard that ensures, for example, that the second | ||
19 | temperature sensor is connected to the CPU, or that the second fan is on | ||
20 | the CPU. Also, some values reported by the chips need some computation | ||
21 | before they make full sense. For example, most chips can only measure | ||
22 | voltages between 0 and +4V. Other voltages are scaled back into that | ||
23 | range using external resistors. Since the values of these resistors | ||
24 | can change from motherboard to motherboard, the conversions cannot be | ||
25 | hard coded into the driver and have to be done in user space. | ||
26 | |||
27 | For this reason, even if we aim at a chip-independant libsensors, it will | ||
28 | still require a configuration file (e.g. /etc/sensors.conf) for proper | ||
29 | values conversion, labeling of inputs and hiding of unused inputs. | ||
30 | |||
31 | An alternative method that some programs use is to access the sysfs | ||
32 | files directly. This document briefly describes the standards that the | ||
33 | drivers follow, so that an application program can scan for entries and | ||
34 | access this data in a simple and consistent way. That said, such programs | ||
35 | will have to implement conversion, labeling and hiding of inputs. For | ||
36 | this reason, it is still not recommended to bypass the library. | ||
37 | |||
38 | If you are developing a userspace application please send us feedback on | ||
39 | this standard. | ||
40 | |||
41 | Note that this standard isn't completely established yet, so it is subject | ||
42 | to changes, even important ones. One more reason to use the library instead | ||
43 | of accessing sysfs files directly. | ||
44 | |||
45 | Each chip gets its own directory in the sysfs /sys/devices tree. To | ||
46 | find all sensor chips, it is easier to follow the symlinks from | ||
47 | /sys/i2c/devices/ | ||
48 | |||
49 | All sysfs values are fixed point numbers. To get the true value of some | ||
50 | of the values, you should divide by the specified value. | ||
51 | |||
52 | There is only one value per file, unlike the older /proc specification. | ||
53 | The common scheme for files naming is: <type><number>_<item>. Usual | ||
54 | types for sensor chips are "in" (voltage), "temp" (temperature) and | ||
55 | "fan" (fan). Usual items are "input" (measured value), "max" (high | ||
56 | threshold, "min" (low threshold). Numbering usually starts from 1, | ||
57 | except for voltages which start from 0 (because most data sheets use | ||
58 | this). A number is always used for elements that can be present more | ||
59 | than once, even if there is a single element of the given type on the | ||
60 | specific chip. Other files do not refer to a specific element, so | ||
61 | they have a simple name, and no number. | ||
62 | |||
63 | Alarms are direct indications read from the chips. The drivers do NOT | ||
64 | make comparisons of readings to thresholds. This allows violations | ||
65 | between readings to be caught and alarmed. The exact definition of an | ||
66 | alarm (for example, whether a threshold must be met or must be exceeded | ||
67 | to cause an alarm) is chip-dependent. | ||
68 | |||
69 | |||
70 | ------------------------------------------------------------------------- | ||
71 | |||
72 | ************ | ||
73 | * Voltages * | ||
74 | ************ | ||
75 | |||
76 | in[0-8]_min Voltage min value. | ||
77 | Unit: millivolt | ||
78 | Read/Write | ||
79 | |||
80 | in[0-8]_max Voltage max value. | ||
81 | Unit: millivolt | ||
82 | Read/Write | ||
83 | |||
84 | in[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 | |||
107 | cpu[0-1]_vid CPU core reference voltage. | ||
108 | Unit: millivolt | ||
109 | Read only. | ||
110 | Not always correct. | ||
111 | |||
112 | vrm 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 | |||
124 | fan[1-3]_min Fan minimum value | ||
125 | Unit: revolution/min (RPM) | ||
126 | Read/Write. | ||
127 | |||
128 | fan[1-3]_input Fan input value. | ||
129 | Unit: revolution/min (RPM) | ||
130 | Read only. | ||
131 | |||
132 | fan[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 | |||
142 | pwm[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 | |||
147 | pwm[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 | |||
155 | pwm[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 | |||
160 | pwm[1-*]_auto_point[1-*]_pwm | ||
161 | pwm[1-*]_auto_point[1-*]_temp | ||
162 | pwm[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 | |||
167 | OR | ||
168 | |||
169 | temp[1-*]_auto_point[1-*]_pwm | ||
170 | temp[1-*]_auto_point[1-*]_temp | ||
171 | temp[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 | |||
181 | temp[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 | |||
189 | temp[1-4]_max Temperature max value. | ||
190 | Unit: millidegree Celcius | ||
191 | Read/Write value. | ||
192 | |||
193 | temp[1-3]_min Temperature min value. | ||
194 | Unit: millidegree Celcius | ||
195 | Read/Write value. | ||
196 | |||
197 | temp[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 | |||
204 | temp[1-4]_input Temperature input value. | ||
205 | Unit: millidegree Celcius | ||
206 | Read only value. | ||
207 | |||
208 | temp[1-4]_crit Temperature critical value, typically greater than | ||
209 | corresponding temp_max values. | ||
210 | Unit: millidegree Celcius | ||
211 | Read/Write value. | ||
212 | |||
213 | temp[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 | |||
232 | Note that no known chip provides current measurements as of writing, | ||
233 | so this part is theoretical, so to say. | ||
234 | |||
235 | curr[1-n]_max Current max value | ||
236 | Unit: milliampere | ||
237 | Read/Write. | ||
238 | |||
239 | curr[1-n]_min Current min value. | ||
240 | Unit: milliampere | ||
241 | Read/Write. | ||
242 | |||
243 | curr[1-n]_input Current input value | ||
244 | Unit: milliampere | ||
245 | Read only. | ||
246 | |||
247 | |||
248 | ********* | ||
249 | * Other * | ||
250 | ********* | ||
251 | |||
252 | alarms 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 | |||
264 | beep_enable Beep/interrupt enable | ||
265 | 0 to disable. | ||
266 | 1 to enable. | ||
267 | Read/Write | ||
268 | |||
269 | beep_mask Bitmask for beep. | ||
270 | Same format as 'alarms' with the same bit locations. | ||
271 | Read/Write | ||
272 | |||
273 | eeprom 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 @@ | |||
1 | The I2C protocol knows about two kinds of device addresses: normal 7 bit | ||
2 | addresses, and an extended set of 10 bit addresses. The sets of addresses | ||
3 | do not intersect: the 7 bit address 0x10 is not the same as the 10 bit | ||
4 | address 0x10 (though a single device could respond to both of them). You | ||
5 | select a 10 bit address by adding an extra byte after the address | ||
6 | byte: | ||
7 | S Addr7 Rd/Wr .... | ||
8 | becomes | ||
9 | S 11110 Addr10 Rd/Wr | ||
10 | S is the start bit, Rd/Wr the read/write bit, and if you count the number | ||
11 | of bits, you will see the there are 8 after the S bit for 7 bit addresses, | ||
12 | and 16 after the S bit for 10 bit addresses. | ||
13 | |||
14 | WARNING! The current 10 bit address support is EXPERIMENTAL. There are | ||
15 | several places in the code that will cause SEVERE PROBLEMS with 10 bit | ||
16 | addresses, even though there is some basic handling and hooks. Also, | ||
17 | almost no supported adapter handles the 10 bit addresses correctly. | ||
18 | |||
19 | As soon as a real 10 bit address device is spotted 'in the wild', we | ||
20 | can and will add proper support. Right now, 10 bit address devices | ||
21 | are defined by the I2C protocol, but we have never seen a single device | ||
22 | which 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 @@ | |||
1 | This is a small guide for those who want to write kernel drivers for I2C | ||
2 | or SMBus devices. | ||
3 | |||
4 | To set up a driver, you need to do several things. Some are optional, and | ||
5 | some things can be done slightly or completely different. Use this as a | ||
6 | guide, not as a rule book! | ||
7 | |||
8 | |||
9 | General remarks | ||
10 | =============== | ||
11 | |||
12 | Try to keep the kernel namespace as clean as possible. The best way to | ||
13 | do this is to use a unique prefix for all global symbols. This is | ||
14 | especially important for exported symbols, but it is a good idea to do | ||
15 | it for non-exported symbols too. We will use the prefix `foo_' in this | ||
16 | tutorial, and `FOO_' for preprocessor variables. | ||
17 | |||
18 | |||
19 | The driver structure | ||
20 | ==================== | ||
21 | |||
22 | Usually, you will implement a single driver structure, and instantiate | ||
23 | all clients from it. Remember, a driver structure contains general access | ||
24 | routines, a client structure specific information like the actual I2C | ||
25 | address. | ||
26 | |||
27 | static 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 | |||
37 | The name can be chosen freely, and may be upto 40 characters long. Please | ||
38 | use something descriptive here. | ||
39 | |||
40 | If used, the id should be a unique ID. The range 0xf000 to 0xffff is | ||
41 | reserved for local use, and you can use one of those until you start | ||
42 | distributing the driver, at which time you should contact the i2c authors | ||
43 | to get your own ID(s). Note that most of the time you don't need an ID | ||
44 | at all so you can just omit it. | ||
45 | |||
46 | Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This | ||
47 | means that your driver will be notified when new adapters are found. | ||
48 | This is almost always what you want. | ||
49 | |||
50 | All other fields are for call-back functions which will be explained | ||
51 | below. | ||
52 | |||
53 | There use to be two additional fields in this structure, inc_use et dec_use, | ||
54 | for module usage count, but these fields were obsoleted and removed. | ||
55 | |||
56 | |||
57 | Extra client data | ||
58 | ================= | ||
59 | |||
60 | The client structure has a special `data' field that can point to any | ||
61 | structure at all. You can use this to keep client-specific data. You | ||
62 | do not always need this, but especially for `sensors' drivers, it can | ||
63 | be very useful. | ||
64 | |||
65 | An 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 | |||
86 | Accessing the client | ||
87 | ==================== | ||
88 | |||
89 | Let's say we have a valid client structure. At some time, we will need | ||
90 | to gather information from the client, or write new information to the | ||
91 | client. How we will export this information to user-space is less | ||
92 | important at this moment (perhaps we do not need to do this at all for | ||
93 | some obscure clients). But we need generic reading and writing routines. | ||
94 | |||
95 | I have found it useful to define foo_read and foo_write function for this. | ||
96 | For some cases, it will be easier to call the i2c functions directly, | ||
97 | but many chips have some kind of register-value idea that can easily | ||
98 | be encapsulated. Also, some chips have both ISA and I2C interfaces, and | ||
99 | it useful to abstract from this (only for `sensors' drivers). | ||
100 | |||
101 | The below functions are simple examples, and should not be copied | ||
102 | literally. | ||
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 | |||
122 | For sensors code, you may have to cope with ISA registers too. Something | ||
123 | like 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 | |||
138 | Writing is done the same way. | ||
139 | |||
140 | |||
141 | Probing and attaching | ||
142 | ===================== | ||
143 | |||
144 | Most i2c devices can be present on several i2c addresses; for some this | ||
145 | is determined in hardware (by soldering some chip pins to Vcc or Ground), | ||
146 | for others this can be changed in software (by writing to specific client | ||
147 | registers). Some devices are usually on a specific address, but not always; | ||
148 | and some are even more tricky. So you will probably need to scan several | ||
149 | i2c addresses for your clients, and do some sort of detection to see | ||
150 | whether it is actually a device supported by your driver. | ||
151 | |||
152 | To give the user a maximum of possibilities, some default module parameters | ||
153 | are defined to help determine what addresses are scanned. Several macros | ||
154 | are defined in i2c.h to help you support them, as well as a generic | ||
155 | detection algorithm. | ||
156 | |||
157 | You do not have to use this parameter interface; but don't try to use | ||
158 | function i2c_probe() (or i2c_detect()) if you don't. | ||
159 | |||
160 | NOTE: If you want to write a `sensors' driver, the interface is slightly | ||
161 | different! See below. | ||
162 | |||
163 | |||
164 | |||
165 | Probing classes (i2c) | ||
166 | --------------------- | ||
167 | |||
168 | All parameters are given as lists of unsigned 16-bit integers. Lists are | ||
169 | terminated by I2C_CLIENT_END. | ||
170 | The 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 | |||
199 | Fortunately, as a module writer, you just have to define the `normal' | ||
200 | and/or `normal_range' parameters. The complete declaration could look | ||
201 | like 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 | |||
211 | Note that you *have* to call the two defined variables `normal_i2c' and | ||
212 | `normal_i2c_range', without any prefix! | ||
213 | |||
214 | |||
215 | Probing classes (sensors) | ||
216 | ------------------------- | ||
217 | |||
218 | If you write a `sensors' driver, you use a slightly different interface. | ||
219 | As well as I2C addresses, we have to cope with ISA addresses. Also, we | ||
220 | use a enum of chip types. Don't forget to include `sensors.h'. | ||
221 | |||
222 | The 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 | |||
260 | Also 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 | |||
269 | So we have a generic insmod variabled `force', and chip-specific variables | ||
270 | `force_CHIPNAME'. | ||
271 | |||
272 | Fortunately, as a module writer, you just have to define the `normal' | ||
273 | and/or `normal_range' parameters, and define what chip names are used. | ||
274 | The 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 | |||
286 | If you have one chip, you use macro SENSORS_INSMOD_1(chip), if you have 2 | ||
287 | you use macro SENSORS_INSMOD_2(chip1,chip2), etc. If you do not want to | ||
288 | bother with chip types, you can use SENSORS_INSMOD_0. | ||
289 | |||
290 | A enum is automatically defined as follows: | ||
291 | enum chips { any_chip, chip1, chip2, ... } | ||
292 | |||
293 | |||
294 | Attaching to an adapter | ||
295 | ----------------------- | ||
296 | |||
297 | Whenever a new adapter is inserted, or for all adapters if the driver is | ||
298 | being registered, the callback attach_adapter() is called. Now is the | ||
299 | time to determine what devices are present on the adapter, and to register | ||
300 | a client for each of them. | ||
301 | |||
302 | The attach_adapter callback is really easy: we just call the generic | ||
303 | detection function. This function will scan the bus for us, using the | ||
304 | information as defined in the lists explained above. If a device is | ||
305 | detected 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 | |||
312 | For `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 | |||
319 | Remember, structure `addr_data' is defined by the macros explained above, | ||
320 | so you do not have to define it yourself. | ||
321 | |||
322 | The i2c_probe or i2c_detect function will call the foo_detect_client | ||
323 | function only for those i2c addresses that actually have a device on | ||
324 | them (unless a `force' parameter was used). In addition, addresses that | ||
325 | are already in use (by some other registered client) are skipped. | ||
326 | |||
327 | |||
328 | The detect client function | ||
329 | -------------------------- | ||
330 | |||
331 | The detect client function is called by i2c_probe or i2c_detect. | ||
332 | The `kind' parameter contains 0 if this call is due to a `force' | ||
333 | parameter, and -1 otherwise (for i2c_detect, it contains 0 if | ||
334 | this call is due to the generic `force' parameter, and the chip type | ||
335 | number if it is due to a specific `force' parameter). | ||
336 | |||
337 | Below, some things are only needed if this is a `sensors' driver. Those | ||
338 | parts are between /* SENSORS ONLY START */ and /* SENSORS ONLY END */ | ||
339 | markers. | ||
340 | |||
341 | This function should only return an error (any value != 0) if there is | ||
342 | some reason why no more detection should be done anymore. If the | ||
343 | detection just fails for this address, return 0. | ||
344 | |||
345 | For 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 | |||
526 | Removing the client | ||
527 | =================== | ||
528 | |||
529 | The detach_client call back function is called when a client should be | ||
530 | removed. It may actually fail, but only when panicking. This code is | ||
531 | much 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 | |||
558 | Initializing the module or kernel | ||
559 | ================================= | ||
560 | |||
561 | When the kernel is booted, or when your foo driver module is inserted, | ||
562 | you have to do some initializing. Fortunately, just attaching (registering) | ||
563 | the 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 | |||
602 | Note that some functions are marked by `__init', and some data structures | ||
603 | by `__init_data'. Hose functions and structures can be removed after | ||
604 | kernel booting (or module loading) is completed. | ||
605 | |||
606 | Command function | ||
607 | ================ | ||
608 | |||
609 | A generic ioctl-like function call back is supported. You will seldom | ||
610 | need 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 | |||
619 | Sending and receiving | ||
620 | ===================== | ||
621 | |||
622 | If you want to communicate with your device, there are several functions | ||
623 | to do this. You can find all of them in i2c.h. | ||
624 | |||
625 | If you can choose between plain i2c communication and SMBus level | ||
626 | communication, please use the last. All adapters understand SMBus level | ||
627 | commands, but only some of them understand plain i2c! | ||
628 | |||
629 | |||
630 | Plain 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 | |||
636 | These routines read and write some bytes from/to a client. The client | ||
637 | contains the i2c address, so you do not have to include it. The second | ||
638 | parameter contains the bytes the read/write, the third the length of the | ||
639 | buffer. 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 | |||
644 | This sends a series of messages. Each message can be a read or write, | ||
645 | and they can be mixed in any way. The transactions are combined: no | ||
646 | stop bit is sent between transaction. The i2c_msg structure contains | ||
647 | for each message the client address, the number of bytes of the message | ||
648 | and the message data itself. | ||
649 | |||
650 | You can read the file `i2c-protocol' for more information about the | ||
651 | actual i2c protocol. | ||
652 | |||
653 | |||
654 | SMBus 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 | |||
679 | These ones were removed in Linux 2.6.10 because they had no users, but could | ||
680 | be 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 | |||
695 | All these transactions return -1 on failure. The 'write' transactions | ||
696 | return 0 on success; the 'read' transactions return the read value, except | ||
697 | for read_block, which returns the number of values read. The block buffers | ||
698 | need not be longer than 32 bytes. | ||
699 | |||
700 | You can read the file `smbus-protocol' for more information about the | ||
701 | actual SMBus protocol. | ||
702 | |||
703 | |||
704 | General purpose routines | ||
705 | ======================== | ||
706 | |||
707 | Below all general purpose routines are listed, that were not mentioned | ||
708 | before. | ||
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 | |||
716 | The sensors sysctl/proc interface | ||
717 | ================================= | ||
718 | |||
719 | This section only applies if you write `sensors' drivers. | ||
720 | |||
721 | Each sensors driver creates a directory in /proc/sys/dev/sensors for each | ||
722 | registered client. The directory is called something like foo-i2c-4-65. | ||
723 | The sensors module helps you to do this as easily as possible. | ||
724 | |||
725 | The template | ||
726 | ------------ | ||
727 | |||
728 | You will need to define a ctl_table template. This template will automatically | ||
729 | be copied to a newly allocated structure and filled in where necessary when | ||
730 | you call sensors_register_entry. | ||
731 | |||
732 | First, 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 | |||
743 | In the above example, three entries are defined. They can either be | ||
744 | accessed through the /proc interface, in the /proc/sys/dev/sensors/* | ||
745 | directories, as files named func1, func2 and data, or alternatively | ||
746 | through the sysctl interface, in the appropriate table, with identifiers | ||
747 | FOO_SYSCTL_FUNC1, FOO_SYSCTL_FUNC2 and FOO_SYSCTL_DATA. | ||
748 | |||
749 | The third, sixth and ninth parameters should always be NULL, and the | ||
750 | fourth should always be 0. The fifth is the mode of the /proc file; | ||
751 | 0644 is safe, as the file will be owned by root:root. | ||
752 | |||
753 | The seventh and eighth parameters should be &i2c_proc_real and | ||
754 | &i2c_sysctl_real if you want to export lists of reals (scaled | ||
755 | integers). You can also use your own function for them, as usual. | ||
756 | Finally, the last parameter is the call-back to gather the data | ||
757 | (see below) if you use the *_proc_real functions. | ||
758 | |||
759 | |||
760 | Gathering the data | ||
761 | ------------------ | ||
762 | |||
763 | The call back functions (foo_func and foo_data in the above example) | ||
764 | can be called in several ways; the operation parameter determines | ||
765 | what 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 | |||
776 | The *_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 | ||
778 | SENSORS_PROC_REAL_READ, it would display 3.45; and if the user would | ||
779 | write 45.6 to the /proc file, it would be returned as 4560 for | ||
780 | SENSORS_PROC_REAL_WRITE. A magnitude may even be negative! | ||
781 | |||
782 | An 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 | } | ||