| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | # |
|---|
| 4 | # sensors-detect - Detect PCI bus and chips |
|---|
| 5 | # Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 20 | # |
|---|
| 21 | |
|---|
| 22 | # TODO: Better handling of chips with several addresses |
|---|
| 23 | |
|---|
| 24 | # A Perl wizard really ought to look upon this; the PCI and I2C stuff should |
|---|
| 25 | # each be put in a separate file, using modules and packages. That is beyond |
|---|
| 26 | # me. |
|---|
| 27 | |
|---|
| 28 | require 5.004; |
|---|
| 29 | |
|---|
| 30 | use strict; |
|---|
| 31 | use Fcntl; |
|---|
| 32 | use POSIX; |
|---|
| 33 | |
|---|
| 34 | ######################### |
|---|
| 35 | # CONSTANT DECLARATIONS # |
|---|
| 36 | ######################### |
|---|
| 37 | |
|---|
| 38 | use vars qw(@pci_adapters @chip_ids @superio_ids @undetectable_adapters @dmidecode); |
|---|
| 39 | |
|---|
| 40 | @dmidecode = ( '/usr/local/sbin/dmidecode', '/usr/sbin/dmidecode' ); |
|---|
| 41 | |
|---|
| 42 | @undetectable_adapters = ( 'i2c-elektor', 'i2c-elv', 'i2c-philips-par', |
|---|
| 43 | 'i2c-velleman' ); |
|---|
| 44 | |
|---|
| 45 | # This is the list of SMBus or I2C adapters we recognize by their PCI |
|---|
| 46 | # signature. This is an easy and fast way to determine which SMBus or I2C |
|---|
| 47 | # adapters should be present. |
|---|
| 48 | # Each entry must have a vendid (Vendor ID), devid (Device ID), func (PCI |
|---|
| 49 | # Function) and procid (string as appears in /proc/pci; see linux/driver/pci, |
|---|
| 50 | # either pci.c or oldproc.c). If no driver is written yet, omit the |
|---|
| 51 | # driver (Driver Name) field. The match (Match Description) field should |
|---|
| 52 | # contain a function which returns zero if its two parameter matches |
|---|
| 53 | # the text as it would appear in /proc/bus/i2c. |
|---|
| 54 | @pci_adapters = ( |
|---|
| 55 | { |
|---|
| 56 | vendid => 0x8086, |
|---|
| 57 | devid => 0x7113, |
|---|
| 58 | func => 3, |
|---|
| 59 | procid => "Intel 82371AB PIIX4 ACPI", |
|---|
| 60 | driver => "i2c-piix4", |
|---|
| 61 | match => sub { $_[0] =~ /^SMBus PIIX4 adapter at / }, |
|---|
| 62 | } , |
|---|
| 63 | { |
|---|
| 64 | vendid => 0x8086, |
|---|
| 65 | devid => 0x719b, |
|---|
| 66 | func => 3, |
|---|
| 67 | procid => "Intel 82443MX Mobile", |
|---|
| 68 | driver => "i2c-piix4", |
|---|
| 69 | match => sub { $_[0] =~ /^SMBus PIIX4 adapter at / }, |
|---|
| 70 | } , |
|---|
| 71 | { |
|---|
| 72 | vendid => 0x8086, |
|---|
| 73 | devid => 0x2413, |
|---|
| 74 | func => 3, |
|---|
| 75 | procid => "Intel 82801AA ICH", |
|---|
| 76 | driver => "i2c-i801", |
|---|
| 77 | match => sub { $_[0] =~ /^SMBus I801 adapter at [0-9,a-f]{4}/ }, |
|---|
| 78 | } , |
|---|
| 79 | { |
|---|
| 80 | vendid => 0x8086, |
|---|
| 81 | devid => 0x2423, |
|---|
| 82 | func => 3, |
|---|
| 83 | procid => "Intel 82801AB ICH0", |
|---|
| 84 | driver => "i2c-i801", |
|---|
| 85 | match => sub { $_[0] =~ /^SMBus I801 adapter at [0-9,a-f]{4}/ }, |
|---|
| 86 | } , |
|---|
| 87 | { |
|---|
| 88 | vendid => 0x8086, |
|---|
| 89 | devid => 0x2443, |
|---|
| 90 | func => 3, |
|---|
| 91 | procid => "Intel 82801BA ICH2", |
|---|
| 92 | driver => "i2c-i801", |
|---|
| 93 | match => sub { $_[0] =~ /^SMBus I801 adapter at [0-9,a-f]{4}/ }, |
|---|
| 94 | } , |
|---|
| 95 | { |
|---|
| 96 | vendid => 0x8086, |
|---|
| 97 | devid => 0x2483, |
|---|
| 98 | func => 3, |
|---|
| 99 | procid => "Intel 82801CA/CAM ICH3", |
|---|
| 100 | driver => "i2c-i801", |
|---|
| 101 | match => sub { $_[0] =~ /^SMBus I801 adapter at [0-9,a-f]{4}/ }, |
|---|
| 102 | } , |
|---|
| 103 | { |
|---|
| 104 | vendid => 0x8086, |
|---|
| 105 | devid => 0x24C3, |
|---|
| 106 | func => 3, |
|---|
| 107 | procid => "Intel 82801DB ICH4", |
|---|
| 108 | driver => "i2c-i801", |
|---|
| 109 | match => sub { $_[0] =~ /^SMBus I801 adapter at [0-9,a-f]{4}/ }, |
|---|
| 110 | } , |
|---|
| 111 | { |
|---|
| 112 | vendid => 0x1106, |
|---|
| 113 | devid => 0x3040, |
|---|
| 114 | func => 3, |
|---|
| 115 | procid => "VIA Technologies VT82C586B Apollo ACPI", |
|---|
| 116 | driver => "i2c-via", |
|---|
| 117 | match => sub { $_[0] =~ /^VIA i2c/ }, |
|---|
| 118 | } , |
|---|
| 119 | { |
|---|
| 120 | vendid => 0x1106, |
|---|
| 121 | devid => 0x3050, |
|---|
| 122 | func => 3, |
|---|
| 123 | procid => "VIA Technologies VT82C596 Apollo ACPI", |
|---|
| 124 | driver => "i2c-viapro", |
|---|
| 125 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 126 | } , |
|---|
| 127 | { |
|---|
| 128 | vendid => 0x1106, |
|---|
| 129 | devid => 0x3051, |
|---|
| 130 | func => 3, |
|---|
| 131 | procid => "VIA Technologies VT82C596B ACPI", |
|---|
| 132 | driver => "i2c-viapro", |
|---|
| 133 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 134 | } , |
|---|
| 135 | { |
|---|
| 136 | vendid => 0x1106, |
|---|
| 137 | devid => 0x3057, |
|---|
| 138 | func => 4, |
|---|
| 139 | procid => "VIA Technologies VT82C686 Apollo ACPI", |
|---|
| 140 | driver => "i2c-viapro", |
|---|
| 141 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 142 | } , |
|---|
| 143 | { |
|---|
| 144 | vendid => 0x1106, |
|---|
| 145 | devid => 0x3074, |
|---|
| 146 | func => 0, |
|---|
| 147 | procid => "VIA Technologies VT8233 VLink South Bridge", |
|---|
| 148 | driver => "i2c-viapro", |
|---|
| 149 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 150 | } , |
|---|
| 151 | { |
|---|
| 152 | vendid => 0x1106, |
|---|
| 153 | devid => 0x3147, |
|---|
| 154 | func => 0, |
|---|
| 155 | procid => "VIA Technologies VT8233A South Bridge", |
|---|
| 156 | driver => "i2c-viapro", |
|---|
| 157 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 158 | } , |
|---|
| 159 | { |
|---|
| 160 | vendid => 0x1106, |
|---|
| 161 | devid => 0x3177, |
|---|
| 162 | func => 0, |
|---|
| 163 | procid => "VIA Technologies VT8233A/8235 South Bridge", |
|---|
| 164 | driver => "i2c-viapro", |
|---|
| 165 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 166 | } , |
|---|
| 167 | { |
|---|
| 168 | vendid => 0x1106, |
|---|
| 169 | devid => 0x8235, |
|---|
| 170 | func => 4, |
|---|
| 171 | procid => "VIA Technologies VT8231 South Bridge", |
|---|
| 172 | driver => "i2c-viapro", |
|---|
| 173 | match => sub { $_[0] =~ /^SMBus Via Pro adapter at/ }, |
|---|
| 174 | } , |
|---|
| 175 | { |
|---|
| 176 | vendid => 0x1039, |
|---|
| 177 | devid => 0x0008, |
|---|
| 178 | func => 0, |
|---|
| 179 | procid => "Silicon Integrated Systems SIS5595", |
|---|
| 180 | driver => "i2c-sis5595", |
|---|
| 181 | match => sub { $_[0] =~ /^SMBus SIS5595 adapter at [0-9,a-f]{4}/ }, |
|---|
| 182 | } , |
|---|
| 183 | { |
|---|
| 184 | vendid => 0x1039, |
|---|
| 185 | devid => 0x5597, |
|---|
| 186 | func => 0, |
|---|
| 187 | procid => "Silicon Integrated Systems SIS5581/5582/5597/5598 (To be written - Do not use 5595 drivers)", |
|---|
| 188 | driver => "to-be-written", |
|---|
| 189 | match => sub { $_[0] =~ /dontmatchthis/ }, |
|---|
| 190 | } , |
|---|
| 191 | { |
|---|
| 192 | vendid => 0x1039, |
|---|
| 193 | devid => 0x5598, |
|---|
| 194 | func => 0, |
|---|
| 195 | procid => "Silicon Integrated Systems SIS5598 (To be written - Do not use 5595 drivers)", |
|---|
| 196 | driver => "to-be-written", |
|---|
| 197 | match => sub { $_[0] =~ /dontmatchthis/ }, |
|---|
| 198 | } , |
|---|
| 199 | { |
|---|
| 200 | vendid => 0x1039, |
|---|
| 201 | devid => 0x0540, |
|---|
| 202 | func => 0, |
|---|
| 203 | procid => "Silicon Integrated Systems SIS540 (To be written - Do not use 5595 drivers)", |
|---|
| 204 | driver => "to-be-written", |
|---|
| 205 | match => sub { $_[0] =~ /dontmatchthis/ }, |
|---|
| 206 | } , |
|---|
| 207 | { |
|---|
| 208 | vendid => 0x1039, |
|---|
| 209 | devid => 0x0630, |
|---|
| 210 | func => 0, |
|---|
| 211 | procid => "Silicon Integrated Systems SIS630", |
|---|
| 212 | driver => "i2c-sis630", |
|---|
| 213 | match => sub { $_[0] =~ /^SMBus SIS630 adapter at [0-9,a-f]{4}/ }, |
|---|
| 214 | } , |
|---|
| 215 | { |
|---|
| 216 | vendid => 0x1039, |
|---|
| 217 | devid => 0x0645, |
|---|
| 218 | func => 0, |
|---|
| 219 | procid => "Silicon Integrated Systems SIS645", |
|---|
| 220 | driver => "i2c-sis645", |
|---|
| 221 | match => sub { $_[0] =~ /^SMBus SiS645 adapter at 0x[0-9,a-f]{4}/ }, |
|---|
| 222 | } , |
|---|
| 223 | { |
|---|
| 224 | vendid => 0x1039, |
|---|
| 225 | devid => 0x0646, |
|---|
| 226 | func => 0, |
|---|
| 227 | procid => "Silicon Integrated Systems SIS645DX", |
|---|
| 228 | driver => "i2c-sis645", |
|---|
| 229 | match => sub { $_[0] =~ /^SMBus SiS645 adapter at 0x[0-9,a-f]{4}/ }, |
|---|
| 230 | } , |
|---|
| 231 | { |
|---|
| 232 | vendid => 0x1039, |
|---|
| 233 | devid => 0x0650, |
|---|
| 234 | func => 0, |
|---|
| 235 | procid => "Silicon Integrated Systems SIS650", |
|---|
| 236 | driver => "i2c-sis645", |
|---|
| 237 | match => sub { $_[0] =~ /^SMBus SiS645 adapter at 0x[0-9,a-f]{4}/ }, |
|---|
| 238 | } , |
|---|
| 239 | { |
|---|
| 240 | vendid => 0x1039, |
|---|
| 241 | devid => 0x0735, |
|---|
| 242 | func => 0, |
|---|
| 243 | procid => "Silicon Integrated Systems SIS735", |
|---|
| 244 | driver => "i2c-sis645", |
|---|
| 245 | match => sub { $_[0] =~ /^SMBus SiS645 adapter at 0x[0-9,a-f]{4}/ }, |
|---|
| 246 | } , |
|---|
| 247 | { |
|---|
| 248 | vendid => 0x1039, |
|---|
| 249 | devid => 0x0730, |
|---|
| 250 | func => 0, |
|---|
| 251 | procid => "Silicon Integrated Systems SIS730", |
|---|
| 252 | driver => "i2c-sis630", |
|---|
| 253 | match => sub { $_[0] =~ /^SMBus SIS630 adapter at [0-9,a-f]{4}/ }, |
|---|
| 254 | } , |
|---|
| 255 | # |
|---|
| 256 | # Both Ali chips below have same PCI ID. Can't be helped. Only one should load. |
|---|
| 257 | # |
|---|
| 258 | { |
|---|
| 259 | vendid => 0x10b9, |
|---|
| 260 | devid => 0x7101, |
|---|
| 261 | func => 0, |
|---|
| 262 | procid => "Acer Labs 1533/1543", |
|---|
| 263 | driver => "i2c-ali15x3", |
|---|
| 264 | match => sub { $_[0] =~ /^SMBus ALI15X3 adapter at/ }, |
|---|
| 265 | }, |
|---|
| 266 | { |
|---|
| 267 | vendid => 0x10b9, |
|---|
| 268 | devid => 0x7101, |
|---|
| 269 | func => 0, |
|---|
| 270 | procid => "Acer Labs 1535", |
|---|
| 271 | driver => "i2c-ali1535", |
|---|
| 272 | match => sub { $_[0] =~ /^SMBus ALI1535 adapter at/ }, |
|---|
| 273 | }, |
|---|
| 274 | { |
|---|
| 275 | vendid => 0x106b, |
|---|
| 276 | devid => 0x000e, |
|---|
| 277 | func => 0, |
|---|
| 278 | procid => "Apple Computer Inc. Hydra Mac I/O", |
|---|
| 279 | driver => "i2c-hydra", |
|---|
| 280 | match => sub { $_[0] =~ /^Hydra i2c/ }, |
|---|
| 281 | }, |
|---|
| 282 | { |
|---|
| 283 | vendid => 0x1022, |
|---|
| 284 | devid => 0x740b, |
|---|
| 285 | func => 3, |
|---|
| 286 | procid => "AMD-756 Athlon ACPI", |
|---|
| 287 | driver => "i2c-amd756", |
|---|
| 288 | match => sub { $_[0] =~ /^SMBus AMD756 adapter at [0-9,a-f]{4}/ }, |
|---|
| 289 | }, |
|---|
| 290 | { |
|---|
| 291 | vendid => 0x1022, |
|---|
| 292 | devid => 0x7413, |
|---|
| 293 | func => 3, |
|---|
| 294 | procid => "AMD-766 Athlon ACPI", |
|---|
| 295 | driver => "i2c-amd756", |
|---|
| 296 | match => sub { $_[0] =~ /^SMBus AMD766 adapter at [0-9,a-f]{4}/ }, |
|---|
| 297 | }, |
|---|
| 298 | { |
|---|
| 299 | vendid => 0x1022, |
|---|
| 300 | devid => 0x7443, |
|---|
| 301 | func => 3, |
|---|
| 302 | procid => "AMD-768 System Management", |
|---|
| 303 | driver => "i2c-amd756", |
|---|
| 304 | match => sub { $_[0] =~ /^SMBus AMD768 adapter at [0-9,a-f]{4}/ }, |
|---|
| 305 | }, |
|---|
| 306 | { |
|---|
| 307 | vendid => 0x1022, |
|---|
| 308 | devid => 0x746b, |
|---|
| 309 | func => 3, |
|---|
| 310 | procid => "AMD-8111 ACPI", |
|---|
| 311 | driver => "i2c-amd756", |
|---|
| 312 | match => sub { $_[0] =~ /^SMBus AMD8111 adapter at [0-9,a-f]{4}/ }, |
|---|
| 313 | }, |
|---|
| 314 | { |
|---|
| 315 | vendid => 0x1022, |
|---|
| 316 | devid => 0x746a, |
|---|
| 317 | func => 2, |
|---|
| 318 | procid => "AMD-8111 SMBus 2.0", |
|---|
| 319 | driver => "i2c-amd8111", |
|---|
| 320 | match => sub { $_[0] =~ /^SMBus2 AMD8111 adapter at [0-9,a-f]{4}/ }, |
|---|
| 321 | }, |
|---|
| 322 | { |
|---|
| 323 | vendid => 0x102b, |
|---|
| 324 | devid => 0x0519, |
|---|
| 325 | func => 0, |
|---|
| 326 | procid => "MGA 2064W [Millennium]", |
|---|
| 327 | driver => "i2c-matroxfb", |
|---|
| 328 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 329 | }, |
|---|
| 330 | { |
|---|
| 331 | vendid => 0x102b, |
|---|
| 332 | devid => 0x051a, |
|---|
| 333 | func => 0, |
|---|
| 334 | procid => "MGA 1064SG [Mystique]", |
|---|
| 335 | driver => "i2c-matroxfb", |
|---|
| 336 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 337 | }, |
|---|
| 338 | { |
|---|
| 339 | vendid => 0x102b, |
|---|
| 340 | devid => 0x051b, |
|---|
| 341 | func => 0, |
|---|
| 342 | procid => "MGA 2164W [Millennium II]", |
|---|
| 343 | driver => "i2c-matroxfb", |
|---|
| 344 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 345 | }, |
|---|
| 346 | { |
|---|
| 347 | vendid => 0x102b, |
|---|
| 348 | devid => 0x051e, |
|---|
| 349 | func => 0, |
|---|
| 350 | procid => "MGA 1064SG [Mystique] AGP", |
|---|
| 351 | driver => "i2c-matroxfb", |
|---|
| 352 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 353 | }, |
|---|
| 354 | { |
|---|
| 355 | vendid => 0x102b, |
|---|
| 356 | devid => 0x051f, |
|---|
| 357 | func => 0, |
|---|
| 358 | procid => "MGA 2164W [Millennium II] AGP", |
|---|
| 359 | driver => "i2c-matroxfb", |
|---|
| 360 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 361 | }, |
|---|
| 362 | { |
|---|
| 363 | vendid => 0x102b, |
|---|
| 364 | devid => 0x1000, |
|---|
| 365 | func => 0, |
|---|
| 366 | procid => "MGA G100 [Productiva]", |
|---|
| 367 | driver => "i2c-matroxfb", |
|---|
| 368 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 369 | }, |
|---|
| 370 | { |
|---|
| 371 | vendid => 0x102b, |
|---|
| 372 | devid => 0x1001, |
|---|
| 373 | func => 0, |
|---|
| 374 | procid => "MGA G100 [Productiva] AGP", |
|---|
| 375 | driver => "i2c-matroxfb", |
|---|
| 376 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 377 | }, |
|---|
| 378 | { |
|---|
| 379 | vendid => 0x102b, |
|---|
| 380 | devid => 0x0520, |
|---|
| 381 | func => 0, |
|---|
| 382 | procid => "MGA G200", |
|---|
| 383 | driver => "i2c-matroxfb", |
|---|
| 384 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 385 | }, |
|---|
| 386 | { |
|---|
| 387 | vendid => 0x102b, |
|---|
| 388 | devid => 0x0521, |
|---|
| 389 | func => 0, |
|---|
| 390 | procid => "MGA G200 AGP", |
|---|
| 391 | driver => "i2c-matroxfb", |
|---|
| 392 | match => sub { $_[0] =~ /^DDC:fb[0-9]{1,2}/ }, |
|---|
| 393 | }, |
|---|
| 394 | { |
|---|
| 395 | vendid => 0x102b, |
|---|
| 396 | devid => 0x0525, |
|---|
| 397 | func => 0, |
|---|
| 398 | procid => "MGA G400 AGP", |
|---|
| 399 | driver => "i2c-matroxfb", |
|---|
| 400 | match => sub { $_[0] =~ /^(DDC,MAVEN):fb[0-9]{1,2}/ }, |
|---|
| 401 | }, |
|---|
| 402 | { |
|---|
| 403 | vendid => 0x121a, |
|---|
| 404 | devid => 0x0005, |
|---|
| 405 | func => 0, |
|---|
| 406 | procid => "3Dfx Voodoo3", |
|---|
| 407 | driver => "i2c-voodoo3", |
|---|
| 408 | match => sub { $_[0] =~ /Banshee adapter/ }, |
|---|
| 409 | }, |
|---|
| 410 | { |
|---|
| 411 | vendid => 0x121a, |
|---|
| 412 | devid => 0x0003, |
|---|
| 413 | func => 0, |
|---|
| 414 | procid => "3Dfx Voodoo Banshee", |
|---|
| 415 | driver => "i2c-voodoo3", |
|---|
| 416 | match => sub { $_[0] =~ /Banshee adapter/ }, |
|---|
| 417 | }, |
|---|
| 418 | { |
|---|
| 419 | vendid => 0x8086, |
|---|
| 420 | devid => 0x7121, |
|---|
| 421 | func => 0, |
|---|
| 422 | procid => "Intel 82810 GMCH", |
|---|
| 423 | driver => "i2c-i810", |
|---|
| 424 | match => sub { $_[0] =~ /^I810/ }, |
|---|
| 425 | } , |
|---|
| 426 | { |
|---|
| 427 | vendid => 0x8086, |
|---|
| 428 | devid => 0x7123, |
|---|
| 429 | func => 0, |
|---|
| 430 | procid => "Intel 82810-DC100 GMCH", |
|---|
| 431 | driver => "i2c-i810", |
|---|
| 432 | match => sub { $_[0] =~ /^I810/ }, |
|---|
| 433 | } , |
|---|
| 434 | { |
|---|
| 435 | vendid => 0x8086, |
|---|
| 436 | devid => 0x7125, |
|---|
| 437 | func => 0, |
|---|
| 438 | procid => "Intel 82810E GMCH", |
|---|
| 439 | driver => "i2c-i810", |
|---|
| 440 | match => sub { $_[0] =~ /^I810/ }, |
|---|
| 441 | } , |
|---|
| 442 | { |
|---|
| 443 | vendid => 0x8086, |
|---|
| 444 | devid => 0x1132, |
|---|
| 445 | func => 0, |
|---|
| 446 | procid => "Intel 82815 GMCH", |
|---|
| 447 | driver => "i2c-i810", |
|---|
| 448 | match => sub { $_[0] =~ /^I810/ }, |
|---|
| 449 | } , |
|---|
| 450 | { |
|---|
| 451 | vendid => 0x12d2, |
|---|
| 452 | devid => 0x0018, |
|---|
| 453 | func => 0, |
|---|
| 454 | procid => "RIVA 128", |
|---|
| 455 | driver => "i2c-riva", |
|---|
| 456 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 457 | } , |
|---|
| 458 | { |
|---|
| 459 | vendid => 0x10de, |
|---|
| 460 | devid => 0x0020, |
|---|
| 461 | func => 0, |
|---|
| 462 | procid => "RIVA TNT", |
|---|
| 463 | driver => "i2c-riva", |
|---|
| 464 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 465 | } , |
|---|
| 466 | { |
|---|
| 467 | vendid => 0x10de, |
|---|
| 468 | devid => 0x0028, |
|---|
| 469 | func => 0, |
|---|
| 470 | procid => "RIVA TNT2", |
|---|
| 471 | driver => "i2c-riva", |
|---|
| 472 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 473 | } , |
|---|
| 474 | { |
|---|
| 475 | vendid => 0x10de, |
|---|
| 476 | devid => 0x0029, |
|---|
| 477 | func => 0, |
|---|
| 478 | procid => "RIVA UTNT2", |
|---|
| 479 | driver => "i2c-riva", |
|---|
| 480 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 481 | } , |
|---|
| 482 | { |
|---|
| 483 | vendid => 0x10de, |
|---|
| 484 | devid => 0x002c, |
|---|
| 485 | func => 0, |
|---|
| 486 | procid => "RIVA VTNT2", |
|---|
| 487 | driver => "i2c-riva", |
|---|
| 488 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 489 | } , |
|---|
| 490 | { |
|---|
| 491 | vendid => 0x10de, |
|---|
| 492 | devid => 0x002d, |
|---|
| 493 | func => 0, |
|---|
| 494 | procid => "RIVA UVTNT2", |
|---|
| 495 | driver => "i2c-riva", |
|---|
| 496 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 497 | } , |
|---|
| 498 | { |
|---|
| 499 | vendid => 0x10de, |
|---|
| 500 | devid => 0x00a0, |
|---|
| 501 | func => 0, |
|---|
| 502 | procid => "RIVA ITNT2", |
|---|
| 503 | driver => "i2c-riva", |
|---|
| 504 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 505 | } , |
|---|
| 506 | { |
|---|
| 507 | vendid => 0x10de, |
|---|
| 508 | devid => 0x0100, |
|---|
| 509 | func => 0, |
|---|
| 510 | procid => "GeForce SDR", |
|---|
| 511 | driver => "i2c-riva", |
|---|
| 512 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 513 | } , |
|---|
| 514 | { |
|---|
| 515 | vendid => 0x10de, |
|---|
| 516 | devid => 0x0101, |
|---|
| 517 | func => 0, |
|---|
| 518 | procid => "GeForce DDR", |
|---|
| 519 | driver => "i2c-riva", |
|---|
| 520 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 521 | } , |
|---|
| 522 | { |
|---|
| 523 | vendid => 0x10de, |
|---|
| 524 | devid => 0x0102, |
|---|
| 525 | func => 0, |
|---|
| 526 | procid => "Quadro", |
|---|
| 527 | driver => "i2c-riva", |
|---|
| 528 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 529 | } , |
|---|
| 530 | { |
|---|
| 531 | vendid => 0x10de, |
|---|
| 532 | devid => 0x0150, |
|---|
| 533 | func => 0, |
|---|
| 534 | procid => "GeForce2 GTS", |
|---|
| 535 | driver => "i2c-riva", |
|---|
| 536 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 537 | } , |
|---|
| 538 | { |
|---|
| 539 | vendid => 0x10de, |
|---|
| 540 | devid => 0x0110, |
|---|
| 541 | func => 0, |
|---|
| 542 | procid => "GeForce2 MX", |
|---|
| 543 | driver => "i2c-riva", |
|---|
| 544 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 545 | } , |
|---|
| 546 | { |
|---|
| 547 | vendid => 0x10de, |
|---|
| 548 | devid => 0x0111, |
|---|
| 549 | func => 0, |
|---|
| 550 | procid => "GeForce2 MX2", |
|---|
| 551 | driver => "i2c-riva", |
|---|
| 552 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 553 | } , |
|---|
| 554 | { |
|---|
| 555 | vendid => 0x10de, |
|---|
| 556 | devid => 0x0113, |
|---|
| 557 | func => 0, |
|---|
| 558 | procid => "Quadro2 MXR", |
|---|
| 559 | driver => "i2c-riva", |
|---|
| 560 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 561 | } , |
|---|
| 562 | { |
|---|
| 563 | vendid => 0x10de, |
|---|
| 564 | devid => 0x0151, |
|---|
| 565 | func => 0, |
|---|
| 566 | procid => "GeForce2 GTS2", |
|---|
| 567 | driver => "i2c-riva", |
|---|
| 568 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 569 | } , |
|---|
| 570 | { |
|---|
| 571 | vendid => 0x10de, |
|---|
| 572 | devid => 0x0152, |
|---|
| 573 | func => 0, |
|---|
| 574 | procid => "GeForce2 Ultra", |
|---|
| 575 | driver => "i2c-riva", |
|---|
| 576 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 577 | } , |
|---|
| 578 | { |
|---|
| 579 | vendid => 0x10de, |
|---|
| 580 | devid => 0x0153, |
|---|
| 581 | func => 0, |
|---|
| 582 | procid => "Quadro2 Pro", |
|---|
| 583 | driver => "i2c-riva", |
|---|
| 584 | match => sub { $_[0] =~ /^NVIDIA display/ }, |
|---|
| 585 | } , |
|---|
| 586 | { |
|---|
| 587 | vendid => 0x10de, |
|---|
| 588 | devid => 0x01b4, |
|---|
| 589 | func => 1, |
|---|
| 590 | procid => "nVidia nForce SMBus", |
|---|
| 591 | driver => "i2c-amd756", |
|---|
| 592 | match => sub { $_[0] =~ /^SMBus nVidia nForce adapter at [0-9,a-f]{4}/ }, |
|---|
| 593 | } , |
|---|
| 594 | { |
|---|
| 595 | vendid => 0x1166, |
|---|
| 596 | devid => 0x0200, |
|---|
| 597 | func => 0, |
|---|
| 598 | procid => "ServerWorks OSB4 South Bridge", |
|---|
| 599 | driver => "i2c-piix4", |
|---|
| 600 | match => sub { $_[0] =~ /^SMBus PIIX4 adapter at / }, |
|---|
| 601 | } , |
|---|
| 602 | { |
|---|
| 603 | vendid => 0x1055, |
|---|
| 604 | devid => 0x9463, |
|---|
| 605 | func => 0, |
|---|
| 606 | procid => "SMSC Victory66 South Bridge", |
|---|
| 607 | driver => "i2c-piix4", |
|---|
| 608 | match => sub { $_[0] =~ /^SMBus PIIX4 adapter at / }, |
|---|
| 609 | } , |
|---|
| 610 | { |
|---|
| 611 | vendid => 0x1166, |
|---|
| 612 | devid => 0x0201, |
|---|
| 613 | func => 0, |
|---|
| 614 | procid => "ServerWorks CSB5 South Bridge", |
|---|
| 615 | driver => "i2c-piix4", |
|---|
| 616 | match => sub { $_[0] =~ /^SMBus PIIX4 adapter at / }, |
|---|
| 617 | } , |
|---|
| 618 | { |
|---|
| 619 | vendid => 0x1283, |
|---|
| 620 | devid => 0x8172, |
|---|
| 621 | func => 0, |
|---|
| 622 | procid => "ITE 8172G MIPS/SH4 Support Chip", |
|---|
| 623 | driver => "i2c-adap-ite", |
|---|
| 624 | match => sub { $_[0] =~ /^ITE IIC adapter/ }, |
|---|
| 625 | } , |
|---|
| 626 | { |
|---|
| 627 | vendid => 0x5333, |
|---|
| 628 | devid => 0x8A20, |
|---|
| 629 | func => 0, |
|---|
| 630 | procid => "S3 Savage 3D", |
|---|
| 631 | driver => "to-be-written", |
|---|
| 632 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 633 | } , |
|---|
| 634 | { |
|---|
| 635 | vendid => 0x5333, |
|---|
| 636 | devid => 0x8A21, |
|---|
| 637 | func => 0, |
|---|
| 638 | procid => "S3 Savage 3D MV", |
|---|
| 639 | driver => "to-be-written", |
|---|
| 640 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 641 | } , |
|---|
| 642 | { |
|---|
| 643 | vendid => 0x5333, |
|---|
| 644 | devid => 0x8A22, |
|---|
| 645 | func => 0, |
|---|
| 646 | procid => "S3 Savage 4", |
|---|
| 647 | driver => "i2c-savage4", |
|---|
| 648 | match => sub { $_[0] =~ /Savage4 adapter/ }, |
|---|
| 649 | } , |
|---|
| 650 | { |
|---|
| 651 | vendid => 0x5333, |
|---|
| 652 | devid => 0x9102, |
|---|
| 653 | func => 0, |
|---|
| 654 | procid => "S3 Savage 2000", |
|---|
| 655 | driver => "i2c-savage4", |
|---|
| 656 | match => sub { $_[0] =~ /Savage4 adapter/ }, |
|---|
| 657 | } , |
|---|
| 658 | { |
|---|
| 659 | vendid => 0x5333, |
|---|
| 660 | devid => 0x8A25, |
|---|
| 661 | func => 0, |
|---|
| 662 | procid => "S3 ProSavage PM", |
|---|
| 663 | driver => "to-be-written", |
|---|
| 664 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 665 | } , |
|---|
| 666 | { |
|---|
| 667 | vendid => 0x5333, |
|---|
| 668 | devid => 0x8A26, |
|---|
| 669 | func => 0, |
|---|
| 670 | procid => "S3 ProSavage KM", |
|---|
| 671 | driver => "to-be-written", |
|---|
| 672 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 673 | } , |
|---|
| 674 | { |
|---|
| 675 | vendid => 0x5333, |
|---|
| 676 | devid => 0x8C10, |
|---|
| 677 | func => 0, |
|---|
| 678 | procid => "S3 Savage MX MV", |
|---|
| 679 | driver => "to-be-written", |
|---|
| 680 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 681 | } , |
|---|
| 682 | { |
|---|
| 683 | vendid => 0x5333, |
|---|
| 684 | devid => 0x8C11, |
|---|
| 685 | func => 0, |
|---|
| 686 | procid => "S3 Savage MX", |
|---|
| 687 | driver => "to-be-written", |
|---|
| 688 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 689 | } , |
|---|
| 690 | { |
|---|
| 691 | vendid => 0x5333, |
|---|
| 692 | devid => 0x8C12, |
|---|
| 693 | func => 0, |
|---|
| 694 | procid => "S3 Savage IX MV", |
|---|
| 695 | driver => "to-be-written", |
|---|
| 696 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 697 | } , |
|---|
| 698 | { |
|---|
| 699 | vendid => 0x5333, |
|---|
| 700 | devid => 0x8C13, |
|---|
| 701 | func => 0, |
|---|
| 702 | procid => "S3 Savage IX", |
|---|
| 703 | driver => "to-be-written", |
|---|
| 704 | match => sub { $_[0] =~ /^dontmatchthis/ }, |
|---|
| 705 | } , |
|---|
| 706 | ); |
|---|
| 707 | |
|---|
| 708 | use subs qw(mtp008_detect lm78_detect lm78_isa_detect lm78_alias_detect |
|---|
| 709 | lm75_detect lm80_detect w83781d_detect w83781d_alias_detect |
|---|
| 710 | adm1025_detect w83781d_isa_detect gl518sm_detect gl520sm_detect |
|---|
| 711 | adm9240_detect adm1021_detect sis5595_isa_detect eeprom_detect |
|---|
| 712 | via686a_isa_detect adm1022_detect ltc1710_detect gl525sm_detect |
|---|
| 713 | lm87_detect ite_detect ite_isa_detect ite_alias_detect |
|---|
| 714 | ddcmonitor_detect ds1621_detect adm1024_detect fscpos_detect |
|---|
| 715 | fscscy_detect pcf8591_detect arp_detect ipmi_kcs_detect |
|---|
| 716 | ipmi_smic_detect via8231_isa_detect lm85_detect smartbatt_detect); |
|---|
| 717 | |
|---|
| 718 | # This is a list of all recognized chips. |
|---|
| 719 | # Each entry must have the following fields: |
|---|
| 720 | # name: The full chip name |
|---|
| 721 | # driver: The driver name (without .o extension). Put in something like |
|---|
| 722 | # "Unwritten: <drivername>" if it is not yet available. |
|---|
| 723 | # i2c_addrs (optional): For I2C chips, the range of valid I2C addresses to |
|---|
| 724 | # probe. Recommend avoiding 0x69 because of clock chips. |
|---|
| 725 | # i2c_driver_addrs (optional): For I2C chips, the range of valid I2C |
|---|
| 726 | # addresses probed by the kernel driver. Strictly optional. |
|---|
| 727 | # i2c_detect (optional): For I2C chips, the function to call to detect |
|---|
| 728 | # this chip. The function should take two parameters: an open file |
|---|
| 729 | # descriptor to access the bus, and the I2C address to probe. |
|---|
| 730 | # isa_addrs (optional): For ISA chips, the range of valid port addresses to |
|---|
| 731 | # probe. |
|---|
| 732 | # isa_driver_addrs (optional): For ISA chips, the range of valid ISA |
|---|
| 733 | # addresses probed by the kernel driver. Strictly optional. |
|---|
| 734 | # isa_detect (optional): For ISA chips, the function to call to detect |
|---|
| 735 | # this chip. The function should take one parameter: the ISA address |
|---|
| 736 | # to probe. |
|---|
| 737 | # alias_detect (optional): For chips which can be both on the ISA and the |
|---|
| 738 | # I2C bus, a function which detectes whether two entries are the same. |
|---|
| 739 | # The function should take three parameters: The ISA address, the |
|---|
| 740 | # I2C bus number, and the I2C address. |
|---|
| 741 | @chip_ids = ( |
|---|
| 742 | { |
|---|
| 743 | name => "Myson MTP008", |
|---|
| 744 | driver => "mtp008", |
|---|
| 745 | i2c_addrs => [0x2c..0x2e], |
|---|
| 746 | i2c_detect => sub { mtp008_detect @_}, |
|---|
| 747 | } , |
|---|
| 748 | { |
|---|
| 749 | name => "National Semiconductor LM78", |
|---|
| 750 | driver => "lm78", |
|---|
| 751 | i2c_addrs => [0x20..0x2f], |
|---|
| 752 | i2c_detect => sub { lm78_detect 0, @_}, |
|---|
| 753 | isa_addrs => [0x290], |
|---|
| 754 | isa_detect => sub { lm78_isa_detect 0, @_ }, |
|---|
| 755 | alias_detect => sub { lm78_alias_detect 0, @_ }, |
|---|
| 756 | } , |
|---|
| 757 | { |
|---|
| 758 | name => "National Semiconductor LM78-J", |
|---|
| 759 | driver => "lm78", |
|---|
| 760 | i2c_addrs => [0x20..0x2f], |
|---|
| 761 | i2c_detect => sub { lm78_detect 1, @_ }, |
|---|
| 762 | isa_addrs => [0x290], |
|---|
| 763 | isa_detect => sub { lm78_isa_detect 1, @_ }, |
|---|
| 764 | alias_detect => sub { lm78_alias_detect 1, @_ }, |
|---|
| 765 | } , |
|---|
| 766 | { |
|---|
| 767 | name => "National Semiconductor LM79", |
|---|
| 768 | driver => "lm78", |
|---|
| 769 | i2c_addrs => [0x20..0x2f], |
|---|
| 770 | i2c_detect => sub { lm78_detect 2, @_ }, |
|---|
| 771 | isa_addrs => [0x290], |
|---|
| 772 | isa_detect => sub { lm78_isa_detect 2, @_ }, |
|---|
| 773 | alias_detect => sub { lm78_alias_detect 2, @_ }, |
|---|
| 774 | } , |
|---|
| 775 | { |
|---|
| 776 | name => "National Semiconductor LM75", |
|---|
| 777 | driver => "lm75", |
|---|
| 778 | i2c_addrs => [0x48..0x4f], |
|---|
| 779 | i2c_detect => sub { lm75_detect @_}, |
|---|
| 780 | } , |
|---|
| 781 | { |
|---|
| 782 | name => "National Semiconductor LM80", |
|---|
| 783 | driver => "lm80", |
|---|
| 784 | i2c_addrs => [0x28..0x2f], |
|---|
| 785 | i2c_detect => sub { lm80_detect @_} , |
|---|
| 786 | }, |
|---|
| 787 | { |
|---|
| 788 | name => "National Semiconductor LM85", |
|---|
| 789 | driver => "Unwritten: lm85", |
|---|
| 790 | i2c_addrs => [0x2c..0x2e], |
|---|
| 791 | i2c_detect => sub { lm85_detect @_}, |
|---|
| 792 | }, |
|---|
| 793 | { |
|---|
| 794 | name => "National Semiconductor LM87", |
|---|
| 795 | driver => "lm87", |
|---|
| 796 | i2c_addrs => [0x2c..0x2e], |
|---|
| 797 | i2c_detect => sub { lm87_detect @_} , |
|---|
| 798 | }, |
|---|
| 799 | { |
|---|
| 800 | name => "Winbond W83781D", |
|---|
| 801 | driver => "w83781d", |
|---|
| 802 | i2c_detect => sub { w83781d_detect 0, @_}, |
|---|
| 803 | i2c_addrs => [0x20..0x2f], |
|---|
| 804 | isa_addrs => [0x290], |
|---|
| 805 | isa_detect => sub { w83781d_isa_detect 0, @_ }, |
|---|
| 806 | alias_detect => sub { w83781d_alias_detect 0, @_ }, |
|---|
| 807 | } , |
|---|
| 808 | { |
|---|
| 809 | name => "Winbond W83782D", |
|---|
| 810 | driver => "w83781d", |
|---|
| 811 | i2c_addrs => [0x20..0x2f], |
|---|
| 812 | i2c_detect => sub { w83781d_detect 1, @_}, |
|---|
| 813 | isa_addrs => [0x290], |
|---|
| 814 | isa_detect => sub { w83781d_isa_detect 1, @_ }, |
|---|
| 815 | alias_detect => sub { w83781d_alias_detect 1, @_ }, |
|---|
| 816 | } , |
|---|
| 817 | { |
|---|
| 818 | name => "Winbond W83783S", |
|---|
| 819 | driver => "w83781d", |
|---|
| 820 | i2c_addrs => [0x20..0x2f], |
|---|
| 821 | i2c_detect => sub { w83781d_detect 2, @_}, |
|---|
| 822 | } , |
|---|
| 823 | { |
|---|
| 824 | name => "Winbond W83627HF", |
|---|
| 825 | driver => "w83781d", |
|---|
| 826 | i2c_addrs => [0x20..0x2f], |
|---|
| 827 | i2c_detect => sub { w83781d_detect 3, @_}, |
|---|
| 828 | isa_addrs => [0x290], |
|---|
| 829 | isa_detect => sub { w83781d_isa_detect 3, @_ }, |
|---|
| 830 | alias_detect => sub { w83781d_alias_detect 3, @_ }, |
|---|
| 831 | } , |
|---|
| 832 | { |
|---|
| 833 | name => "Asus AS99127F", |
|---|
| 834 | driver => "w83781d", |
|---|
| 835 | i2c_addrs => [0x20..0x2f], |
|---|
| 836 | i2c_detect => sub { w83781d_detect 4, @_}, |
|---|
| 837 | } , |
|---|
| 838 | { |
|---|
| 839 | name => "Winbond W83L784R/AR", |
|---|
| 840 | driver => "to-be-written", |
|---|
| 841 | i2c_addrs => [0x20..0x2f], |
|---|
| 842 | i2c_detect => sub { w83781d_detect 6, @_}, |
|---|
| 843 | } , |
|---|
| 844 | { |
|---|
| 845 | name => "Winbond W83697HF", |
|---|
| 846 | driver => "w83781d", |
|---|
| 847 | isa_addrs => [0x290], |
|---|
| 848 | isa_detect => sub { w83781d_isa_detect 5, @_ }, |
|---|
| 849 | } , |
|---|
| 850 | { |
|---|
| 851 | name => "Genesys Logic GL518SM Revision 0x00", |
|---|
| 852 | driver => "gl518sm", |
|---|
| 853 | i2c_addrs => [0x2c, 0x2d], |
|---|
| 854 | i2c_detect => sub { gl518sm_detect 0, @_} , |
|---|
| 855 | }, |
|---|
| 856 | { |
|---|
| 857 | name => "Genesys Logic GL518SM Revision 0x80", |
|---|
| 858 | driver => "gl518sm", |
|---|
| 859 | i2c_addrs => [0x2c, 0x2d], |
|---|
| 860 | i2c_detect => sub { gl518sm_detect 1, @_} , |
|---|
| 861 | }, |
|---|
| 862 | { |
|---|
| 863 | name => "Genesys Logic GL520SM", |
|---|
| 864 | driver => "gl520sm", |
|---|
| 865 | i2c_addrs => [0x2c, 0x2d], |
|---|
| 866 | i2c_detect => sub { gl520sm_detect @_} , |
|---|
| 867 | }, |
|---|
| 868 | { |
|---|
| 869 | name => "Genesys Logic GL525SM", |
|---|
| 870 | driver => "Unwritten (GL525SM)", |
|---|
| 871 | i2c_addrs => [0x2d], |
|---|
| 872 | i2c_detect => sub { gl525sm_detect @_} , |
|---|
| 873 | }, |
|---|
| 874 | { |
|---|
| 875 | name => "Analog Devices ADM9240", |
|---|
| 876 | driver => "adm9240", |
|---|
| 877 | i2c_addrs => [0x2c..0x2f], |
|---|
| 878 | i2c_detect => sub { adm9240_detect 0, @_ } |
|---|
| 879 | }, |
|---|
| 880 | { |
|---|
| 881 | name => "Dallas Semiconductor DS1621", |
|---|
| 882 | driver => "ds1621", |
|---|
| 883 | i2c_addrs => [0x48..0x4f], |
|---|
| 884 | i2c_detect => sub { ds1621_detect @_}, |
|---|
| 885 | } , |
|---|
| 886 | { |
|---|
| 887 | name => "Dallas Semiconductor DS1780", |
|---|
| 888 | driver => "adm9240", |
|---|
| 889 | i2c_addrs => [0x2c..0x2f], |
|---|
| 890 | i2c_detect => sub { adm9240_detect 1, @_ } |
|---|
| 891 | }, |
|---|
| 892 | { |
|---|
| 893 | name => "National Semiconductor LM81", |
|---|
| 894 | driver => "adm9240", |
|---|
| 895 | i2c_addrs => [0x2c..0x2f], |
|---|
| 896 | i2c_detect => sub { adm9240_detect 2, @_ } |
|---|
| 897 | }, |
|---|
| 898 | { |
|---|
| 899 | name => "Analog Devices ADM1025", |
|---|
| 900 | driver => "adm1025", |
|---|
| 901 | i2c_addrs => [0x2c..0x2e], |
|---|
| 902 | i2c_detect => sub { adm1025_detect 0, @_ } |
|---|
| 903 | }, |
|---|
| 904 | { |
|---|
| 905 | name => "Analog Devices ADM1024", |
|---|
| 906 | driver => "adm1024", |
|---|
| 907 | i2c_addrs => [0x2c..0x2e], |
|---|
| 908 | i2c_detect => sub { adm1024_detect 0, @_ } |
|---|
| 909 | }, |
|---|
| 910 | { |
|---|
| 911 | name => "Analog Devices ADM1021", |
|---|
| 912 | driver => "adm1021", |
|---|
| 913 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 914 | i2c_detect => sub { adm1021_detect 0, @_ }, |
|---|
| 915 | }, |
|---|
| 916 | { |
|---|
| 917 | name => "Maxim MAX1617", |
|---|
| 918 | driver => "adm1021", |
|---|
| 919 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 920 | i2c_detect => sub { adm1021_detect 1, @_ }, |
|---|
| 921 | }, |
|---|
| 922 | { |
|---|
| 923 | name => "Maxim MAX1617A", |
|---|
| 924 | driver => "adm1021", |
|---|
| 925 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 926 | i2c_detect => sub { adm1021_detect 2, @_ }, |
|---|
| 927 | }, |
|---|
| 928 | { |
|---|
| 929 | name => "TI THMC10", |
|---|
| 930 | driver => "adm1021", |
|---|
| 931 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 932 | i2c_detect => sub { adm1021_detect 3, @_ }, |
|---|
| 933 | }, |
|---|
| 934 | { |
|---|
| 935 | name => "National Semiconductor LM84", |
|---|
| 936 | driver => "adm1021", |
|---|
| 937 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 938 | i2c_detect => sub { adm1021_detect 4, @_ }, |
|---|
| 939 | }, |
|---|
| 940 | { |
|---|
| 941 | name => "Genesys Logic GL523SM", |
|---|
| 942 | driver => "adm1021", |
|---|
| 943 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 944 | i2c_detect => sub { adm1021_detect 5, @_ }, |
|---|
| 945 | }, |
|---|
| 946 | { |
|---|
| 947 | name => "Onsemi MC1066", |
|---|
| 948 | driver => "adm1021", |
|---|
| 949 | i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], |
|---|
| 950 | i2c_detect => sub { adm1021_detect 6, @_ }, |
|---|
| 951 | }, |
|---|
| 952 | { |
|---|
| 953 | name => "Analog Devices ADM1022", |
|---|
| 954 | driver => "thmc50", |
|---|
| 955 | i2c_addrs => [0x2c..0x2f], |
|---|
| 956 | i2c_detect => sub { adm1022_detect 0, @_ }, |
|---|
| 957 | }, |
|---|
| 958 | { |
|---|
| 959 | name => "Texas Instruments THMC50", |
|---|
| 960 | driver => "thmc50", |
|---|
| 961 | i2c_addrs => [0x2c..0x2f], |
|---|
| 962 | i2c_detect => sub { adm1022_detect 1, @_ }, |
|---|
| 963 | }, |
|---|
| 964 | { |
|---|
| 965 | name => "Silicon Integrated Systems SIS5595", |
|---|
| 966 | driver => "sis5595", |
|---|
| 967 | isa_addrs => [ 0 ], |
|---|
| 968 | isa_detect => sub { sis5595_isa_detect @_ }, |
|---|
| 969 | }, |
|---|
| 970 | { |
|---|
| 971 | name => "VIA Technologies VT82C686 Integrated Sensors", |
|---|
| 972 | driver => "via686a", |
|---|
| 973 | isa_addrs => [ 0 ], |
|---|
| 974 | isa_detect => sub { via686a_isa_detect @_ }, |
|---|
| 975 | }, |
|---|
| 976 | { |
|---|
| 977 | name => "VIA Technologies VT8231 Integrated Sensors", |
|---|
| 978 | driver => "vt8231", |
|---|
| 979 | isa_addrs => [ 0 ], |
|---|
| 980 | isa_detect => sub { via8231_isa_detect @_ }, |
|---|
| 981 | }, |
|---|
| 982 | { |
|---|
| 983 | name => "ITE IT8705F / IT8712F / SiS 950", |
|---|
| 984 | driver => "it87", |
|---|
| 985 | i2c_addrs => [0x20..0x2f], |
|---|
| 986 | i2c_detect => sub { ite_detect 0, @_ }, |
|---|
| 987 | isa_addrs => [0x290], |
|---|
| 988 | isa_detect => sub { ite_isa_detect 0, @_ }, |
|---|
| 989 | } , |
|---|
| 990 | { |
|---|
| 991 | name => "Serial EEPROM", |
|---|
| 992 | driver => "eeprom", |
|---|
| 993 | i2c_addrs => [0x50..0x57], |
|---|
| 994 | i2c_detect => sub { eeprom_detect @_ }, |
|---|
| 995 | }, |
|---|
| 996 | { |
|---|
| 997 | name => "LTC1710", |
|---|
| 998 | driver => "ltc1710", |
|---|
| 999 | i2c_addrs => [0x58..0x5a], |
|---|
| 1000 | i2c_detect => sub { ltc1710_detect @_ }, |
|---|
| 1001 | }, |
|---|
| 1002 | { |
|---|
| 1003 | name => "DDC monitor", |
|---|
| 1004 | driver => "ddcmon", |
|---|
| 1005 | i2c_addrs => [0x50], |
|---|
| 1006 | i2c_detect => sub { ddcmonitor_detect @_ }, |
|---|
| 1007 | }, |
|---|
| 1008 | { |
|---|
| 1009 | name => "FSC poseidon chip", |
|---|
| 1010 | driver => "fscpos", |
|---|
| 1011 | i2c_addrs => [0x73], |
|---|
| 1012 | i2c_detect => sub { fscpos_detect @_ }, |
|---|
| 1013 | }, |
|---|
| 1014 | { |
|---|
| 1015 | name => "FSC Scylla chip", |
|---|
| 1016 | driver => "fscscy", |
|---|
| 1017 | i2c_addrs => [0x73], |
|---|
| 1018 | i2c_detect => sub { fscscy_detect @_ }, |
|---|
| 1019 | }, |
|---|
| 1020 | { |
|---|
| 1021 | name => "Philips Semiconductors PCF8591", |
|---|
| 1022 | driver => "pcf8591", |
|---|
| 1023 | i2c_addrs => [0x48..0x4f], |
|---|
| 1024 | i2c_detect => sub { pcf8591_detect @_}, |
|---|
| 1025 | }, |
|---|
| 1026 | { |
|---|
| 1027 | name => "SMBus 2.0 ARP-Capable Device", |
|---|
| 1028 | driver => "smbus-arp", |
|---|
| 1029 | i2c_addrs => [0x61], |
|---|
| 1030 | i2c_detect => sub { arp_detect @_}, |
|---|
| 1031 | }, |
|---|
| 1032 | { |
|---|
| 1033 | name => "IPMI BMC KCS", |
|---|
| 1034 | driver => "bmcsensors", |
|---|
| 1035 | isa_addrs => [ 0x0ca0 ], |
|---|
| 1036 | isa_detect => sub { ipmi_kcs_detect @_ }, |
|---|
| 1037 | }, |
|---|
| 1038 | { |
|---|
| 1039 | name => "IPMI BMC SMIC", |
|---|
| 1040 | driver => "bmcsensors", |
|---|
| 1041 | isa_addrs => [ 0x0ca8 ], |
|---|
| 1042 | isa_detect => sub { ipmi_smic_detect @_ }, |
|---|
| 1043 | }, |
|---|
| 1044 | { |
|---|
| 1045 | name => "Smart Battery", |
|---|
| 1046 | driver => "smartbatt", |
|---|
| 1047 | i2c_addrs => [0x0b], |
|---|
| 1048 | i2c_detect => sub { smartbatt_detect @_}, |
|---|
| 1049 | }, |
|---|
| 1050 | ); |
|---|
| 1051 | |
|---|
| 1052 | # This is a list of all recognized superio chips. |
|---|
| 1053 | # Each entry must have the following fields: |
|---|
| 1054 | # name: The full chip name |
|---|
| 1055 | # driver: The driver name (without .o extension). Put in something like |
|---|
| 1056 | # "Unwritten: <drivername>" if it is not yet available. |
|---|
| 1057 | # addrreg: The address register |
|---|
| 1058 | # datareg: The data register |
|---|
| 1059 | # enter: The password sequence to write to the address register |
|---|
| 1060 | # devidreg: The device ID register(s) |
|---|
| 1061 | # devid: The device ID(s) we have to match (base device) |
|---|
| 1062 | # logdevreg: The logical device register |
|---|
| 1063 | # logdev: The logical device containing the sensors |
|---|
| 1064 | # actreg (optional): The activation register within the logical device |
|---|
| 1065 | # actmask (optional): The activation bit in the activation register |
|---|
| 1066 | # basereg: The I/O base register within the logical device |
|---|
| 1067 | # exitreg: The register to write the exit value to |
|---|
| 1068 | # exit: The value to write to the exit register to exit |
|---|
| 1069 | # alias_detect (optional): For chips which can be both on the ISA and the |
|---|
| 1070 | # I2C bus, a function which detectes whether two entries are the same. |
|---|
| 1071 | # The function should take three parameters: The ISA address, the |
|---|
| 1072 | # I2C bus number, and the I2C address. |
|---|
| 1073 | @superio_ids = ( |
|---|
| 1074 | # { |
|---|
| 1075 | # name => "ITE 8705 Super IO Sensors", |
|---|
| 1076 | # driver => "it87", |
|---|
| 1077 | # addrreg => 0x2e, |
|---|
| 1078 | # datareg => 0x2f, |
|---|
| 1079 | # enter => [0x55, 0x01, 0x55, 0x55]. |
|---|
| 1080 | # code doesn't handle multiple devid regs yet |
|---|
| 1081 | # devidreg => [0x20, 0x21], |
|---|
| 1082 | # devid => [0x87, 0x05], |
|---|
| 1083 | # logdevreg => 0x07, |
|---|
| 1084 | # logdev => 0x04, |
|---|
| 1085 | # actreg => 0x30, |
|---|
| 1086 | # actmask => 0x01, |
|---|
| 1087 | # basereg => 0x60, |
|---|
| 1088 | # exit is writing 0x01 to reg 0x02. - not compatible with other superio chips |
|---|
| 1089 | # exitreg => 0x02, |
|---|
| 1090 | # exit => 0x01, |
|---|
| 1091 | # }, |
|---|
| 1092 | { |
|---|
| 1093 | name => "SMSC 47M1xx Super IO Fan Sensors", |
|---|
| 1094 | driver => "smsc47m1", |
|---|
| 1095 | addrreg => 0x2e, |
|---|
| 1096 | exitreg => 0x2e, |
|---|
| 1097 | datareg => 0x2f, |
|---|
| 1098 | enter => [0x55], |
|---|
| 1099 | devidreg => 0x20, |
|---|
| 1100 | devid => 0x59, |
|---|
| 1101 | logdevreg => 0x07, |
|---|
| 1102 | logdev => 0x0a, |
|---|
| 1103 | actreg => 0x20, |
|---|
| 1104 | actmask => 0x01, |
|---|
| 1105 | basereg => 0x60, |
|---|
| 1106 | exit => 0xaa, |
|---|
| 1107 | }, |
|---|
| 1108 | { |
|---|
| 1109 | name => "VT1211 Super IO Sensors", |
|---|
| 1110 | driver => "vt1211", |
|---|
| 1111 | addrreg => 0x2e, |
|---|
| 1112 | exitreg => 0x2e, |
|---|
| 1113 | datareg => 0x2f, |
|---|
| 1114 | enter => [0x87, 0x87], |
|---|
| 1115 | devidreg => 0x20, |
|---|
| 1116 | devid => 0x3c, |
|---|
| 1117 | logdevreg => 0x07, |
|---|
| 1118 | logdev => 0x0b, |
|---|
| 1119 | actreg => 0x30, |
|---|
| 1120 | actmask => 0x01, |
|---|
| 1121 | basereg => 0x60, |
|---|
| 1122 | exit => 0xaa, |
|---|
| 1123 | }, |
|---|
| 1124 | { |
|---|
| 1125 | name => "Winbond W83627HF Super IO Sensors", |
|---|
| 1126 | driver => "w83781d", |
|---|
| 1127 | addrreg => 0x2e, |
|---|
| 1128 | exitreg => 0x2e, |
|---|
| 1129 | datareg => 0x2f, |
|---|
| 1130 | enter => [0x87, 0x87], |
|---|
| 1131 | devidreg => 0x20, |
|---|
| 1132 | devid => 0x52, |
|---|
| 1133 | logdevreg => 0x07, |
|---|
| 1134 | logdev => 0x0b, |
|---|
| 1135 | actreg => 0x30, |
|---|
| 1136 | actmask => 0x01, |
|---|
| 1137 | basereg => 0x60, |
|---|
| 1138 | exit => 0xaa, |
|---|
| 1139 | }, |
|---|
| 1140 | { |
|---|
| 1141 | name => "Winbond W83697HF Super IO Sensors", |
|---|
| 1142 | driver => "w83781d", |
|---|
| 1143 | addrreg => 0x2e, |
|---|
| 1144 | exitreg => 0x2e, |
|---|
| 1145 | datareg => 0x2f, |
|---|
| 1146 | enter => [0x87, 0x87], |
|---|
| 1147 | devidreg => 0x20, |
|---|
| 1148 | devid => 0x60, |
|---|
| 1149 | logdevreg => 0x07, |
|---|
| 1150 | logdev => 0x0b, |
|---|
| 1151 | actreg => 0x30, |
|---|
| 1152 | actmask => 0x01, |
|---|
| 1153 | basereg => 0x60, |
|---|
| 1154 | exit => 0xaa, |
|---|
| 1155 | }, |
|---|
| 1156 | ); |
|---|
| 1157 | |
|---|
| 1158 | ####################### |
|---|
| 1159 | # AUXILIARY FUNCTIONS # |
|---|
| 1160 | ####################### |
|---|
| 1161 | |
|---|
| 1162 | sub swap_bytes |
|---|
| 1163 | { |
|---|
| 1164 | return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 8) |
|---|
| 1165 | } |
|---|
| 1166 | |
|---|
| 1167 | # $_[0] is the sought value |
|---|
| 1168 | # @_[1..] is the list to seek in |
|---|
| 1169 | # Returns: 0 on failure, 1 if found. |
|---|
| 1170 | sub contains |
|---|
| 1171 | { |
|---|
| 1172 | my $sought = shift; |
|---|
| 1173 | foreach (@_) { |
|---|
| 1174 | return 1 if $sought eq $_; |
|---|
| 1175 | } |
|---|
| 1176 | return 0; |
|---|
| 1177 | } |
|---|
| 1178 | |
|---|
| 1179 | sub parse_not_to_scan |
|---|
| 1180 | { |
|---|
| 1181 | my ($min,$max,$to_parse) = @_; |
|---|
| 1182 | my @ranges = split /\s*,\s*/, $to_parse; |
|---|
| 1183 | my @res = (); |
|---|
| 1184 | my $range; |
|---|
| 1185 | foreach $range (@ranges) { |
|---|
| 1186 | my ($start,$end) = split /\s*-s*/, $range; |
|---|
| 1187 | $start = oct $start if $start =~ /^0/; |
|---|
| 1188 | if (defined $end) { |
|---|
| 1189 | $end = oct $end if $end =~ /^0/; |
|---|
| 1190 | $start = $min if $start < $min; |
|---|
| 1191 | $end = $max if $end > $max; |
|---|
| 1192 | push @res, ($start+0..$end+0); |
|---|
| 1193 | } else { |
|---|
| 1194 | push @res, $start+0 if $start >= $min and $start <= $max; |
|---|
| 1195 | } |
|---|
| 1196 | } |
|---|
| 1197 | return sort { $a <=> $b } @res; |
|---|
| 1198 | } |
|---|
| 1199 | |
|---|
| 1200 | # @_[0]: Reference to list 1 |
|---|
| 1201 | # @_[1]: Reference to list 2 |
|---|
| 1202 | # Result: 0 if they have no elements in common, 1 if they have |
|---|
| 1203 | # Elements must be numeric. |
|---|
| 1204 | sub any_list_match |
|---|
| 1205 | { |
|---|
| 1206 | my ($list1,$list2) = @_; |
|---|
| 1207 | my ($el1,$el2); |
|---|
| 1208 | foreach $el1 (@$list1) { |
|---|
| 1209 | foreach $el2 (@$list2) { |
|---|
| 1210 | return 1 if $el1 == $el2; |
|---|
| 1211 | } |
|---|
| 1212 | } |
|---|
| 1213 | return 0; |
|---|
| 1214 | } |
|---|
| 1215 | |
|---|
| 1216 | ################### |
|---|
| 1217 | # I/O port access # |
|---|
| 1218 | ################### |
|---|
| 1219 | |
|---|
| 1220 | sub initialize_ioports |
|---|
| 1221 | { |
|---|
| 1222 | sysopen IOPORTS, "/dev/port", 2; |
|---|
| 1223 | } |
|---|
| 1224 | |
|---|
| 1225 | # $_[0]: port to read |
|---|
| 1226 | # Returns: -1 on failure, read value on success. |
|---|
| 1227 | sub inb |
|---|
| 1228 | { |
|---|
| 1229 | my ($res,$nrchars); |
|---|
| 1230 | sysseek IOPORTS, $_[0], 0 or return -1; |
|---|
| 1231 | $nrchars = sysread IOPORTS, $res, 1; |
|---|
| 1232 | return -1 if not defined $nrchars or $nrchars != 1; |
|---|
| 1233 | $res = unpack "C",$res ; |
|---|
| 1234 | return $res; |
|---|
| 1235 | } |
|---|
| 1236 | |
|---|
| 1237 | # $_[0]: port to write |
|---|
| 1238 | # $_[1]: value to write |
|---|
| 1239 | # Returns: -1 on failure, 0 on success. |
|---|
| 1240 | sub outb |
|---|
| 1241 | { |
|---|
| 1242 | my $towrite = pack "C", $_[1]; |
|---|
| 1243 | sysseek IOPORTS, $_[0], 0 or return -1; |
|---|
| 1244 | my $nrchars = syswrite IOPORTS, $towrite, 1; |
|---|
| 1245 | return -1 if not defined $nrchars or $nrchars != 1; |
|---|
| 1246 | return 0; |
|---|
| 1247 | } |
|---|
| 1248 | |
|---|
| 1249 | # $_[0]: Address register |
|---|
| 1250 | # $_[1]: Data register |
|---|
| 1251 | # $_[2]: Register to read |
|---|
| 1252 | # Returns: read value |
|---|
| 1253 | sub isa_read_byte |
|---|
| 1254 | { |
|---|
| 1255 | outb $_[0],$_[2]; |
|---|
| 1256 | return inb $_[1]; |
|---|
| 1257 | } |
|---|
| 1258 | |
|---|
| 1259 | # $_[0]: Address register |
|---|
| 1260 | # $_[1]: Data register |
|---|
| 1261 | # $_[2]: Register to write |
|---|
| 1262 | # $_[3}: Value to write |
|---|
| 1263 | # Returns: nothing |
|---|
| 1264 | sub isa_write_byte |
|---|
| 1265 | { |
|---|
| 1266 | outb $_[0],$_[2]; |
|---|
| 1267 | outb $_[1],$_[3]; |
|---|
| 1268 | } |
|---|
| 1269 | |
|---|
| 1270 | ########### |
|---|
| 1271 | # MODULES # |
|---|
| 1272 | ########### |
|---|
| 1273 | |
|---|
| 1274 | use vars qw(@modules_list); |
|---|
| 1275 | |
|---|
| 1276 | sub initialize_modules_list |
|---|
| 1277 | { |
|---|
| 1278 | open INPUTFILE, "/proc/modules" or die "Can't access /proc/modules!"; |
|---|
| 1279 | while (<INPUTFILE>) { |
|---|
| 1280 | push @modules_list, /^(\S*)/ ; |
|---|
| 1281 | } |
|---|
| 1282 | close INPUTFILE; |
|---|
| 1283 | } |
|---|
| 1284 | |
|---|
| 1285 | ############## |
|---|
| 1286 | # PCI ACCESS # |
|---|
| 1287 | ############## |
|---|
| 1288 | |
|---|
| 1289 | use vars qw(@pci_list); |
|---|
| 1290 | |
|---|
| 1291 | # This function returns a list of hashes. Each hash has some PCI information |
|---|
| 1292 | # (more than we will ever need, probably). The most important |
|---|
| 1293 | # fields are 'bus', 'slot', 'func' (they uniquely identify a PCI device in |
|---|
| 1294 | # a computer) and 'vendid','devid' (they uniquely identify a type of device). |
|---|
| 1295 | # /proc/bus/pci/devices is only available on late 2.1 and 2.2 kernels. |
|---|
| 1296 | sub read_proc_dev_pci |
|---|
| 1297 | { |
|---|
| 1298 | my ($dfn,$vend,@pci_list); |
|---|
| 1299 | open INPUTFILE, "/proc/bus/pci/devices" or return; |
|---|
| 1300 | while (<INPUTFILE>) { |
|---|
| 1301 | my $record = {}; |
|---|
| 1302 | ($dfn,$vend,$record->{irq},$record->{base_addr0},$record->{base_addr1}, |
|---|
| 1303 | $record->{base_addr2},$record->{base_addr3},$record->{base_addr4}, |
|---|
| 1304 | $record->{base_addr5},$record->{rom_base_addr}) = |
|---|
| 1305 | map { oct "0x$_" } (split) [0..9]; |
|---|
| 1306 | $record->{bus} = $dfn >> 8; |
|---|
| 1307 | $record->{slot} = ($dfn & 0xf8) >> 3; |
|---|
| 1308 | $record->{func} = $dfn & 0x07; |
|---|
| 1309 | $record->{vendid} = $vend >> 16; |
|---|
| 1310 | $record->{devid} = $vend & 0xffff; |
|---|
| 1311 | push @pci_list,$record; |
|---|
| 1312 | } |
|---|
| 1313 | close INPUTFILE or return; |
|---|
| 1314 | return @pci_list; |
|---|
| 1315 | } |
|---|
| 1316 | |
|---|
| 1317 | # This function returns a list of hashes. Each hash has some PCI |
|---|
| 1318 | # information. The important fields here are 'bus', 'slot', 'func' (they |
|---|
| 1319 | # uniquely identify a PCI device in a computer) and 'desc' (a functional |
|---|
| 1320 | # description of the PCI device). If this is an 'unknown device', the |
|---|
| 1321 | # vendid and devid fields are set instead. |
|---|
| 1322 | sub read_proc_pci |
|---|
| 1323 | { |
|---|
| 1324 | my @pci_list; |
|---|
| 1325 | open INPUTFILE, "/proc/pci" or return; |
|---|
| 1326 | while (<INPUTFILE>) { |
|---|
| 1327 | my $record = {}; |
|---|
| 1328 | if (($record->{bus},$record->{slot},$record->{func}) = |
|---|
| 1329 | /^\s*Bus\s*(\S)+\s*,\s*device\s*(\S+)\s*,\s*function\s*(\S+)\s*:\s*$/) { |
|---|
| 1330 | my $desc = <INPUTFILE>; |
|---|
| 1331 | $_ = <INPUTFILE>; |
|---|
| 1332 | if (($desc =~ /Unknown device/) and |
|---|
| 1333 | (($record->{vendid},$record->{devid}) = |
|---|
| 1334 | /^\s*Vendor id=(\S+)\.\s*Device id=(\S+)\.$/)) { |
|---|
| 1335 | $record->{vendid} = hex $record->{vendid}; |
|---|
| 1336 | $record->{devid} = hex $record->{devid}; |
|---|
| 1337 | } else { |
|---|
| 1338 | $record->{desc} = $desc; |
|---|
| 1339 | } |
|---|
| 1340 | push @pci_list,$record; |
|---|
| 1341 | } |
|---|
| 1342 | } |
|---|
| 1343 | close INPUTFILE or return; |
|---|
| 1344 | return @pci_list; |
|---|
| 1345 | } |
|---|
| 1346 | |
|---|
| 1347 | sub initialize_proc_pci |
|---|
| 1348 | { |
|---|
| 1349 | @pci_list = read_proc_dev_pci; |
|---|
| 1350 | @pci_list = read_proc_pci if not defined @pci_list; |
|---|
| 1351 | die "Can't access either /proc/bus/pci/ or /proc/pci!" |
|---|
| 1352 | if not defined @pci_list; |
|---|
| 1353 | } |
|---|
| 1354 | |
|---|
| 1355 | ##################### |
|---|
| 1356 | # ADAPTER DETECTION # |
|---|
| 1357 | ##################### |
|---|
| 1358 | |
|---|
| 1359 | sub all_available_adapters |
|---|
| 1360 | { |
|---|
| 1361 | my @res = (); |
|---|
| 1362 | my ($module,$adapter); |
|---|
| 1363 | MODULES: |
|---|
| 1364 | foreach $module (@modules_list) { |
|---|
| 1365 | foreach $adapter (@pci_adapters) { |
|---|
| 1366 | if (exists $adapter->{driver} and $module eq $adapter->{driver}) { |
|---|
| 1367 | push @res, $module; |
|---|
| 1368 | next MODULES; |
|---|
| 1369 | } |
|---|
| 1370 | } |
|---|
| 1371 | } |
|---|
| 1372 | return @res; |
|---|
| 1373 | } |
|---|
| 1374 | |
|---|
| 1375 | sub adapter_pci_detection |
|---|
| 1376 | { |
|---|
| 1377 | my ($device,$try,@res); |
|---|
| 1378 | print "Probing for PCI bus adapters...\n"; |
|---|
| 1379 | |
|---|
| 1380 | foreach $device (@pci_list) { |
|---|
| 1381 | foreach $try (@pci_adapters) { |
|---|
| 1382 | if ((defined($device->{vendid}) and |
|---|
| 1383 | $try->{vendid} == $device->{vendid} and |
|---|
| 1384 | $try->{devid} == $device->{devid} and |
|---|
| 1385 | $try->{func} == $device->{func}) or |
|---|
| 1386 | (! defined($device->{vendid}) and |
|---|
| 1387 | $device->{desc} =~ /$try->{procid}/ and |
|---|
| 1388 | $try->{func} == $device->{func})) { |
|---|
| 1389 | printf "Use driver `%s' for device %02x:%02x.%x: %s\n", |
|---|
| 1390 | $try->{driver}?$try->{driver}:"<To Be Written>", |
|---|
| 1391 | $device->{bus},$device->{slot},$device->{func},$try->{procid}; |
|---|
| 1392 | push @res,$try->{driver}; |
|---|
| 1393 | } |
|---|
| 1394 | } |
|---|
| 1395 | } |
|---|
| 1396 | if (! @res) { |
|---|
| 1397 | print ("Sorry, no PCI bus adapters found.\n"); |
|---|
| 1398 | } else { |
|---|
| 1399 | printf ("Probe succesfully concluded.\n"); |
|---|
| 1400 | } |
|---|
| 1401 | return @res; |
|---|
| 1402 | } |
|---|
| 1403 | |
|---|
| 1404 | # $_[0]: Adapter description as found in /proc/bus/i2c |
|---|
| 1405 | # $_[1]: Algorithm description as found in /proc/bus/i2c |
|---|
| 1406 | sub find_adapter_driver |
|---|
| 1407 | { |
|---|
| 1408 | my $adapter; |
|---|
| 1409 | for $adapter (@pci_adapters) { |
|---|
| 1410 | return $adapter->{driver} if &{$adapter->{match}} ($_[0],$_[1]); |
|---|
| 1411 | } |
|---|
| 1412 | return "UNKNOWN"; |
|---|
| 1413 | } |
|---|
| 1414 | |
|---|
| 1415 | ############################# |
|---|
| 1416 | # I2C AND SMBUS /DEV ACCESS # |
|---|
| 1417 | ############################# |
|---|
| 1418 | |
|---|
| 1419 | # This should really go into a separate module/package. |
|---|
| 1420 | |
|---|
| 1421 | # To do: support i2c-level access (through sysread/syswrite, probably). |
|---|
| 1422 | # I can't test this at all (PIIX4 does not support this), so I have not |
|---|
| 1423 | # included it. |
|---|
| 1424 | |
|---|
| 1425 | use vars qw($IOCTL_I2C_RETRIES $IOCTL_I2C_TIMEOUT $IOCTL_I2C_UDELAY |
|---|
| 1426 | $IOCTL_I2C_MDELAY $IOCTL_I2C_SLAVE $IOCTL_I2C_TENBIT |
|---|
| 1427 | $IOCTL_I2C_SMBUS); |
|---|
| 1428 | |
|---|
| 1429 | # These are copied from <linux/i2c.h> and <linux/smbus.h> |
|---|
| 1430 | |
|---|
| 1431 | # For bit-adapters: |
|---|
| 1432 | $IOCTL_I2C_RETRIES = 0x0701; |
|---|
| 1433 | $IOCTL_I2C_TIMEOUT = 0x0702; |
|---|
| 1434 | $IOCTL_I2C_UDELAY = 0x0705; |
|---|
| 1435 | $IOCTL_I2C_MDELAY = 0x0706; |
|---|
| 1436 | |
|---|
| 1437 | # General ones: |
|---|
| 1438 | $IOCTL_I2C_SLAVE = 0x0703; |
|---|
| 1439 | $IOCTL_I2C_TENBIT = 0x0704; |
|---|
| 1440 | $IOCTL_I2C_SMBUS = 0x0720; |
|---|
| 1441 | |
|---|
| 1442 | |
|---|
| 1443 | |
|---|
| 1444 | use vars qw($SMBUS_READ $SMBUS_WRITE $SMBUS_QUICK $SMBUS_BYTE $SMBUS_BYTE_DATA |
|---|
| 1445 | $SMBUS_WORD_DATA $SMBUS_PROC_CALL $SMBUS_BLOCK_DATA); |
|---|
| 1446 | |
|---|
| 1447 | # These are copied from <linux/smbus.h> |
|---|
| 1448 | |
|---|
| 1449 | $SMBUS_READ = 1; |
|---|
| 1450 | $SMBUS_WRITE = 0; |
|---|
| 1451 | $SMBUS_QUICK = 0; |
|---|
| 1452 | $SMBUS_BYTE = 1; |
|---|
| 1453 | $SMBUS_BYTE_DATA = 2; |
|---|
| 1454 | $SMBUS_WORD_DATA = 3; |
|---|
| 1455 | $SMBUS_PROC_CALL = 4; |
|---|
| 1456 | $SMBUS_BLOCK_DATA = 5; |
|---|
| 1457 | |
|---|
| 1458 | # Select the device to communicate with through its address. |
|---|
| 1459 | # $_[0]: Reference to an opened filehandle |
|---|
| 1460 | # $_[1]: Address to select |
|---|
| 1461 | # Returns: 0 on failure, 1 on success. |
|---|
| 1462 | sub i2c_set_slave_addr |
|---|
| 1463 | { |
|---|
| 1464 | my ($file,$addr) = @_; |
|---|
| 1465 | ioctl $file, $IOCTL_I2C_SLAVE, $addr or return 0; |
|---|
| 1466 | return 1; |
|---|
| 1467 | } |
|---|
| 1468 | |
|---|
| 1469 | # i2c_smbus_access is based upon the corresponding C function (see |
|---|
| 1470 | # <linux/i2c-dev.h>). You should not need to call this directly. |
|---|
| 1471 | # Exact calling conventions are intricate; read i2c-dev.c if you really need |
|---|
| 1472 | # to know. |
|---|
| 1473 | # $_[0]: Reference to an opened filehandle |
|---|
| 1474 | # $_[1]: $SMBUS_READ for reading, $SMBUS_WRITE for writing |
|---|
| 1475 | # $_[2]: Command (usually register number) |
|---|
| 1476 | # $_[3]: Transaction kind ($SMBUS_BYTE, $SMBUS_BYTE_DATA, etc.) |
|---|
| 1477 | # $_[4]: Reference to an array used for input/output of data |
|---|
| 1478 | # Returns: 0 on failure, 1 on success. |
|---|
| 1479 | # Note that we need to get back to Integer boundaries through the 'x2' |
|---|
| 1480 | # in the pack. This is very compiler-dependent; I wish there was some other |
|---|
| 1481 | # way to do this. |
|---|
| 1482 | sub i2c_smbus_access |
|---|
| 1483 | { |
|---|
| 1484 | my ($file,$read_write,$command,$size,$data) = @_; |
|---|
| 1485 | my $data_array = pack "C32", @$data; |
|---|
| 1486 | my $ioctl_data = pack "C2x2Ip", ($read_write,$command,$size,$data_array); |
|---|
| 1487 | ioctl $file, $IOCTL_I2C_SMBUS, $ioctl_data or return 0; |
|---|
| 1488 | $_[4] = [ unpack "C32",$data_array ]; |
|---|
| 1489 | return 1; |
|---|
| 1490 | } |
|---|
| 1491 | |
|---|
| 1492 | # $_[0]: Reference to an opened filehandle |
|---|
| 1493 | # $_[1]: Either 0 or 1 |
|---|
| 1494 | # Returns: -1 on failure, the 0 on success. |
|---|
| 1495 | sub i2c_smbus_write_quick |
|---|
| 1496 | { |
|---|
| 1497 | my ($file,$value) = @_; |
|---|
| 1498 | my $data = []; |
|---|
| 1499 | i2c_smbus_access $file, $value, 0, $SMBUS_QUICK, $data |
|---|
| 1500 | or return -1; |
|---|
| 1501 | return 0; |
|---|
| 1502 | } |
|---|
| 1503 | |
|---|
| 1504 | # $_[0]: Reference to an opened filehandle |
|---|
| 1505 | # Returns: -1 on failure, the read byte on success. |
|---|
| 1506 | sub i2c_smbus_read_byte |
|---|
| 1507 | { |
|---|
| 1508 | my ($file) = @_; |
|---|
| 1509 | my $data = []; |
|---|
| 1510 | i2c_smbus_access $file, $SMBUS_READ, 0, $SMBUS_BYTE, $data |
|---|
| 1511 | or return -1; |
|---|
| 1512 | return $$data[0]; |
|---|
| 1513 | } |
|---|
| 1514 | |
|---|
| 1515 | # $_[0]: Reference to an opened filehandle |
|---|
| 1516 | # $_[1]: Byte to write |
|---|
| 1517 | # Returns: -1 on failure, 0 on success. |
|---|
| 1518 | sub i2c_smbus_write_byte |
|---|
| 1519 | { |
|---|
| 1520 | my ($file,$command) = @_; |
|---|
| 1521 | my $data = [$command]; |
|---|
| 1522 | i2c_smbus_access $file, $SMBUS_WRITE, 0, $SMBUS_BYTE, $data |
|---|
| 1523 | or return -1; |
|---|
| 1524 | return 0; |
|---|
| 1525 | } |
|---|
| 1526 | |
|---|
| 1527 | # $_[0]: Reference to an opened filehandle |
|---|
| 1528 | # $_[1]: Command byte (usually register number) |
|---|
| 1529 | # Returns: -1 on failure, the read byte on success. |
|---|
| 1530 | sub i2c_smbus_read_byte_data |
|---|
| 1531 | { |
|---|
| 1532 | my ($file,$command) = @_; |
|---|
| 1533 | my $data = []; |
|---|
| 1534 | i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_BYTE_DATA, $data |
|---|
| 1535 | or return -1; |
|---|
| 1536 | return $$data[0]; |
|---|
| 1537 | } |
|---|
| 1538 | |
|---|
| 1539 | # $_[0]: Reference to an opened filehandle |
|---|
| 1540 | # $_[1]: Command byte (usually register number) |
|---|
| 1541 | # $_[2]: Byte to write |
|---|
| 1542 | # Returns: -1 on failure, 0 on success. |
|---|
| 1543 | sub i2c_smbus_write_byte_data |
|---|
| 1544 | { |
|---|
| 1545 | my ($file,$command,$value) = @_; |
|---|
| 1546 | my $data = [$value]; |
|---|
| 1547 | i2c_smbus_access $file, $SMBUS_WRITE, $command, $SMBUS_BYTE_DATA, $data |
|---|
| 1548 | or return -1; |
|---|
| 1549 | return 0; |
|---|
| 1550 | } |
|---|
| 1551 | |
|---|
| 1552 | # $_[0]: Reference to an opened filehandle |
|---|
| 1553 | # $_[1]: Command byte (usually register number) |
|---|
| 1554 | # Returns: -1 on failure, the read word on success. |
|---|
| 1555 | # Note: some devices use the wrong endiannes; use swap_bytes to correct for |
|---|
| 1556 | # this. |
|---|
| 1557 | sub i2c_smbus_read_word_data |
|---|
| 1558 | { |
|---|
| 1559 | my ($file,$command) = @_; |
|---|
| 1560 | my $data = []; |
|---|
| 1561 | i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data |
|---|
| 1562 | or return -1; |
|---|
| 1563 | return $$data[0] + 256 * $$data[1]; |
|---|
| 1564 | } |
|---|
| 1565 | |
|---|
| 1566 | # $_[0]: Reference to an opened filehandle |
|---|
| 1567 | # $_[1]: Command byte (usually register number) |
|---|
| 1568 | # $_[2]: Byte to write |
|---|
| 1569 | # Returns: -1 on failure, 0 on success. |
|---|
| 1570 | # Note: some devices use the wrong endiannes; use swap_bytes to correct for |
|---|
| 1571 | # this. |
|---|
| 1572 | sub i2c_smbus_write_word_data |
|---|
| 1573 | { |
|---|
| 1574 | my ($file,$command,$value) = @_; |
|---|
| 1575 | my $data = [$value & 0xff, $value >> 8]; |
|---|
| 1576 | i2c_smbus_access $file, $SMBUS_WRITE, $command, $SMBUS_WORD_DATA, $data |
|---|
| 1577 | or return -1; |
|---|
| 1578 | return 0; |
|---|
| 1579 | } |
|---|
| 1580 | |
|---|
| 1581 | # $_[0]: Reference to an opened filehandle |
|---|
| 1582 | # $_[1]: Command byte (usually register number) |
|---|
| 1583 | # $_[2]: Word to write |
|---|
| 1584 | # Returns: -1 on failure, read word on success. |
|---|
| 1585 | # Note: some devices use the wrong endiannes; use swap_bytes to correct for |
|---|
| 1586 | # this. |
|---|
| 1587 | sub i2c_smbus_process_call |
|---|
| 1588 | { |
|---|
| 1589 | my ($file,$command,$value) = @_; |
|---|
| 1590 | my $data = [$value & 0xff, $value >> 8]; |
|---|
| 1591 | i2c_smbus_access $file, $SMBUS_WRITE, $command, $SMBUS_PROC_CALL, $data |
|---|
| 1592 | or return -1; |
|---|
| 1593 | return $$data[0] + 256 * $$data[1]; |
|---|
| 1594 | } |
|---|
| 1595 | |
|---|
| 1596 | # $_[0]: Reference to an opened filehandle |
|---|
| 1597 | # $_[1]: Command byte (usually register number) |
|---|
| 1598 | # Returns: Undefined on failure, a list of read bytes on success |
|---|
| 1599 | # Note: some devices use the wrong endiannes; use swap_bytes to correct for |
|---|
| 1600 | # this. |
|---|
| 1601 | sub i2c_smbus_read_block_data |
|---|
| 1602 | { |
|---|
| 1603 | my ($file,$command) = @_; |
|---|
| 1604 | my $data = []; |
|---|
| 1605 | i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_BLOCK_DATA, $data |
|---|
| 1606 | or return; |
|---|
| 1607 | shift @$data; |
|---|
| 1608 | return @$data; |
|---|
| 1609 | } |
|---|
| 1610 | |
|---|
| 1611 | # $_[0]: Reference to an opened filehandle |
|---|
| 1612 | # $_[1]: Command byte (usually register number) |
|---|
| 1613 | # @_[2..]: List of values to write |
|---|
| 1614 | # Returns: -1 on failure, 0 on success. |
|---|
| 1615 | # Note: some devices use the wrong endiannes; use swap_bytes to correct for |
|---|
| 1616 | # this. |
|---|
| 1617 | sub i2c_smbus_write_block_data |
|---|
| 1618 | { |
|---|
| 1619 | my ($file,$command,@data) = @_; |
|---|
| 1620 | i2c_smbus_access $file, $SMBUS_WRITE, $command, $SMBUS_BLOCK_DATA, \@data |
|---|
| 1621 | or return; |
|---|
| 1622 | return 0; |
|---|
| 1623 | } |
|---|
| 1624 | |
|---|
| 1625 | #################### |
|---|
| 1626 | # ADAPTER SCANNING # |
|---|
| 1627 | #################### |
|---|
| 1628 | |
|---|
| 1629 | use vars qw(@chips_detected); |
|---|
| 1630 | |
|---|
| 1631 | # We will build a complicated structure @chips_detected here, being: |
|---|
| 1632 | # A list of |
|---|
| 1633 | # references to hashes |
|---|
| 1634 | # with field 'driver', being a string with the driver name for this chip; |
|---|
| 1635 | # with field 'detected' |
|---|
| 1636 | # being a reference to a list of |
|---|
| 1637 | # references to hashes of type 'detect_data'; |
|---|
| 1638 | # with field 'misdetected' |
|---|
| 1639 | # being a reference to a list of |
|---|
| 1640 | # references to hashes of type 'detect_data' |
|---|
| 1641 | |
|---|
| 1642 | # Type detect_data: |
|---|
| 1643 | # A hash |
|---|
| 1644 | # with field 'i2c_adap' containing an adapter string as appearing |
|---|
| 1645 | # in /proc/bus/i2c (if this is an I2C detection) |
|---|
| 1646 | # with field 'i2c_algo' containing an algorithm string as appearing |
|---|
| 1647 | # in /proc/bus/i2c (if this is an I2C detection) |
|---|
| 1648 | # with field 'i2c_devnr', contianing the /dev/i2c-* number of this |
|---|
| 1649 | # adapter (if this is an I2C detection) |
|---|
| 1650 | # with field 'i2c_driver', containing the driver name for this adapter |
|---|
| 1651 | # (if this is an I2C detection) |
|---|
| 1652 | # with field 'i2c_addr', containing the I2C address of the detection; |
|---|
| 1653 | # (if this is an I2C detection) |
|---|
| 1654 | # with field 'i2c_sub_addrs', containing a reference to a list of |
|---|
| 1655 | # other I2C addresses (if this is an I2C detection) |
|---|
| 1656 | # with field 'i2c_extra' if this is an I2C detection and the address |
|---|
| 1657 | # is not normally probed by the kernel driver |
|---|
| 1658 | # with field 'isa_addr' containing the ISA address this chip is on |
|---|
| 1659 | # (if this is an ISA detection) |
|---|
| 1660 | # with field 'isa_extra' if this is an ISA detection and the address |
|---|
| 1661 | # is not normally probed by the kernel driver |
|---|
| 1662 | # with field 'conf', containing the confidence level of this detection |
|---|
| 1663 | # with field 'chipname', containing the chip name |
|---|
| 1664 | |
|---|
| 1665 | # This adds a detection to the above structure. We do no alias detection |
|---|
| 1666 | # here; so you should do ISA detections *after* all I2C detections. |
|---|
| 1667 | # Not all possibilities of i2c_addr and i2c_sub_addrs are exhausted. |
|---|
| 1668 | # In all normal cases, it should be all right. |
|---|
| 1669 | # $_[0]: chip driver |
|---|
| 1670 | # $_[1]: reference to data hash |
|---|
| 1671 | # Returns: Nothing |
|---|
| 1672 | sub add_i2c_to_chips_detected |
|---|
| 1673 | { |
|---|
| 1674 | my ($chipdriver,$datahash) = @_; |
|---|
| 1675 | my ($i,$new_detected_ref,$new_misdetected_ref,$detected_ref,$misdetected_ref, |
|---|
| 1676 | $main_entry,$detected_entry,$put_in_detected,@hash_addrs,@entry_addrs); |
|---|
| 1677 | |
|---|
| 1678 | # First determine where the hash has to be added. |
|---|
| 1679 | for ($i = 0; $i < @chips_detected; $i++) { |
|---|
| 1680 | last if ($chips_detected[$i]->{driver} eq $chipdriver); |
|---|
| 1681 | } |
|---|
| 1682 | if ($i == @chips_detected) { |
|---|
| 1683 | push @chips_detected, { driver => $chipdriver, |
|---|
| 1684 | detected => [], |
|---|
| 1685 | misdetected => [] }; |
|---|
| 1686 | } |
|---|
| 1687 | $new_detected_ref = $chips_detected[$i]->{detected}; |
|---|
| 1688 | $new_misdetected_ref = $chips_detected[$i]->{misdetected}; |
|---|
| 1689 | |
|---|
| 1690 | # Find out whether our new entry should go into the detected or the |
|---|
| 1691 | # misdetected list. We compare all i2c addresses; if at least one matches, |
|---|
| 1692 | # but our conf value is lower, we assume this is a misdetect. |
|---|
| 1693 | @hash_addrs = ($datahash->{i2c_addr}); |
|---|
| 1694 | push @hash_addrs, @{$datahash->{i2c_sub_addrs}} |
|---|
| 1695 | if exists $datahash->{i2c_sub_addrs}; |
|---|
| 1696 | $put_in_detected = 1; |
|---|
| 1697 | FIND_LOOP: |
|---|
| 1698 | foreach $main_entry (@chips_detected) { |
|---|
| 1699 | foreach $detected_entry (@{$main_entry->{detected}}) { |
|---|
| 1700 | @entry_addrs = ($detected_entry->{i2c_addr}); |
|---|
| 1701 | push @entry_addrs, @{$detected_entry->{i2c_sub_addrs}} |
|---|
| 1702 | if exists $detected_entry->{i2c_sub_addrs}; |
|---|
| 1703 | if ($detected_entry->{i2c_devnr} == $datahash->{i2c_devnr} and |
|---|
| 1704 | any_list_match \@entry_addrs, \@hash_addrs) { |
|---|
| 1705 | if ($detected_entry->{conf} >= $datahash->{conf}) { |
|---|
| 1706 | $put_in_detected = 0; |
|---|
| 1707 | } |
|---|
| 1708 | last FIND_LOOP; |
|---|
| 1709 | } |
|---|
| 1710 | } |
|---|
| 1711 | } |
|---|
| 1712 | |
|---|
| 1713 | if ($put_in_detected) { |
|---|
| 1714 | # Here, we move all entries from detected to misdetected which |
|---|
| 1715 | # match at least in one main or sub address. This may not be the |
|---|
| 1716 | # best idea to do, as it may remove detections without replacing |
|---|
| 1717 | # them with second-best ones. Too bad. |
|---|
| 1718 | @hash_addrs = ($datahash->{i2c_addr}); |
|---|
| 1719 | push @hash_addrs, @{$datahash->{i2c_sub_addrs}} |
|---|
| 1720 | if exists $datahash->{i2c_sub_addrs}; |
|---|
| 1721 | foreach $main_entry (@chips_detected) { |
|---|
| 1722 | $detected_ref = $main_entry->{detected}; |
|---|
| 1723 | $misdetected_ref = $main_entry->{misdetected}; |
|---|
| 1724 | for ($i = @$detected_ref-1; $i >=0; $i--) { |
|---|
| 1725 | @entry_addrs = ($detected_ref->[$i]->{i2c_addr}); |
|---|
| 1726 | push @entry_addrs, @{$detected_ref->[$i]->{i2c_sub_addrs}} |
|---|
| 1727 | if exists $detected_ref->[$i]->{i2c_sub_addrs}; |
|---|
| 1728 | if ($detected_ref->[$i]->{i2c_devnr} == $datahash->{i2c_devnr} and |
|---|
| 1729 | any_list_match \@entry_addrs, \@hash_addrs) { |
|---|
| 1730 | push @$misdetected_ref,$detected_ref->[$i]; |
|---|
| 1731 | splice @$detected_ref, $i, 1; |
|---|
| 1732 | } |
|---|
| 1733 | } |
|---|
| 1734 | } |
|---|
| 1735 | |
|---|
| 1736 | # Now add the new entry to detected |
|---|
| 1737 | push @$new_detected_ref, $datahash; |
|---|
| 1738 | } else { |
|---|
| 1739 | # No hard work here |
|---|
| 1740 | push @$new_misdetected_ref, $datahash; |
|---|
| 1741 | } |
|---|
| 1742 | } |
|---|
| 1743 | |
|---|
| 1744 | # This adds a detection to the above structure. We also do alias detection |
|---|
| 1745 | # here; so you should do ISA detections *after* all I2C detections. |
|---|
| 1746 | # $_[0]: alias detection function |
|---|
| 1747 | # $_[1]: chip driver |
|---|
| 1748 | # $_[2]: reference to data hash |
|---|
| 1749 | # Returns: 0 if it is not an alias, datahash reference if it is. |
|---|
| 1750 | sub add_isa_to_chips_detected |
|---|
| 1751 | { |
|---|
| 1752 | my ($alias_detect,$chipdriver,$datahash) = @_; |
|---|
| 1753 | my ($i,$new_detected_ref,$new_misdetected_ref,$detected_ref,$misdetected_ref, |
|---|
| 1754 | $main_entry,$isalias); |
|---|
| 1755 | |
|---|
| 1756 | # First determine where the hash has to be added. |
|---|
| 1757 | $isalias=0; |
|---|
| 1758 | for ($i = 0; $i < @chips_detected; $i++) { |
|---|
| 1759 | last if ($chips_detected[$i]->{driver} eq $chipdriver); |
|---|
| 1760 | } |
|---|
| 1761 | if ($i == @chips_detected) { |
|---|
| 1762 | push @chips_detected, { driver => $chipdriver, |
|---|
| 1763 | detected => [], |
|---|
| 1764 | misdetected => [] }; |
|---|
| 1765 | } |
|---|
| 1766 | $new_detected_ref = $chips_detected[$i]->{detected}; |
|---|
| 1767 | $new_misdetected_ref = $chips_detected[$i]->{misdetected}; |
|---|
| 1768 | |
|---|
| 1769 | # Now, we are looking for aliases. An alias can only be the same chiptype. |
|---|
| 1770 | # If an alias is found in the misdetected list, we add the new information |
|---|
| 1771 | # and terminate this function. If it is found in the detected list, we |
|---|
| 1772 | # still have to check whether another chip has claimed this ISA address. |
|---|
| 1773 | # So we remove the old entry from the detected list and put it in datahash. |
|---|
| 1774 | |
|---|
| 1775 | # Misdetected alias detection: |
|---|
| 1776 | for ($i = 0; $i < @$new_misdetected_ref; $i++) { |
|---|
| 1777 | if (exists $new_misdetected_ref->[$i]->{i2c_addr} and |
|---|
| 1778 | not exists $new_misdetected_ref->[$i]->{isa_addr} and |
|---|
| 1779 | defined $alias_detect and |
|---|
| 1780 | $new_misdetected_ref->[$i]->{chipname} eq $datahash->{chipname}) { |
|---|
| 1781 | open FILE,"/dev/i2c-$new_misdetected_ref->[$i]->{i2c_devnr}" or |
|---|
| 1782 | open FILE,"/dev/i2c$new_misdetected_ref->[$i]->{i2c_devnr}" or |
|---|
| 1783 | open FILE,"/dev/i2c/$new_misdetected_ref->[$i]->{i2c_devnr}" or |
|---|
| 1784 | print("Can't open ", |
|---|
| 1785 | "/dev/i2c[-/]$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), |
|---|
| 1786 | next; |
|---|
| 1787 | i2c_set_slave_addr \*FILE,$new_misdetected_ref->[$i]->{i2c_addr} or |
|---|
| 1788 | print("Can't set I2C address for ", |
|---|
| 1789 | "/dev/i2c[-/]$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), |
|---|
| 1790 | next; |
|---|
| 1791 | if (&$alias_detect ($datahash->{isa_addr},\*FILE, |
|---|
| 1792 | $new_misdetected_ref->[$i]->{i2c_addr})) { |
|---|
| 1793 | $new_misdetected_ref->[$i]->{isa_addr} = $datahash->{isa_addr}; |
|---|
| 1794 | $new_misdetected_ref->[$i]->{isa_extra} = $datahash->{isa_extra} |
|---|
| 1795 | if exists $datahash->{isa_extra}; |
|---|
| 1796 | close FILE; |
|---|
| 1797 | return $new_misdetected_ref->[$i]; |
|---|
| 1798 | } |
|---|
| 1799 | close FILE; |
|---|
| 1800 | } |
|---|
| 1801 | } |
|---|
| 1802 | |
|---|
| 1803 | # Detected alias detection: |
|---|
| 1804 | for ($i = 0; $i < @$new_detected_ref; $i++) { |
|---|
| 1805 | if (exists $new_detected_ref->[$i]->{i2c_addr} and |
|---|
| 1806 | not exists $new_detected_ref->[$i]->{isa_addr} and |
|---|
| 1807 | defined $alias_detect and |
|---|
| 1808 | $new_detected_ref->[$i]->{chipname} eq $datahash->{chipname}) { |
|---|
| 1809 | open FILE,"/dev/i2c-$new_detected_ref->[$i]->{i2c_devnr}" or |
|---|
| 1810 | open FILE,"/dev/i2c$new_detected_ref->[$i]->{i2c_devnr}" or |
|---|
| 1811 | open FILE,"/dev/i2c/$new_detected_ref->[$i]->{i2c_devnr}" or |
|---|
| 1812 | print("Can't open ", |
|---|
| 1813 | "/dev/i2c[-/]$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), |
|---|
| 1814 | next; |
|---|
| 1815 | i2c_set_slave_addr \*FILE,$new_detected_ref->[$i]->{i2c_addr} or |
|---|
| 1816 | print("Can't set I2C address for ", |
|---|
| 1817 | "/dev/i2c[-/]$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), |
|---|
| 1818 | next; |
|---|
| 1819 | if (&$alias_detect ($datahash->{isa_addr},\*FILE, |
|---|
| 1820 | $new_detected_ref->[$i]->{i2c_addr})) { |
|---|
| 1821 | $new_detected_ref->[$i]->{isa_addr} = $datahash->{isa_addr}; |
|---|
| 1822 | $new_detected_ref->[$i]->{isa_extra} = $datahash->{isa_extra} |
|---|
| 1823 | if exists $datahash->{isa_extra}; |
|---|
| 1824 | ($datahash) = splice (@$new_detected_ref, $i, 1); |
|---|
| 1825 | close FILE; |
|---|
| 1826 | $isalias=1; |
|---|
| 1827 | last; |
|---|
| 1828 | } |
|---|
| 1829 | close FILE; |
|---|
| 1830 | } |
|---|
| 1831 | } |
|---|
| 1832 | |
|---|
| 1833 | |
|---|
| 1834 | # Find out whether our new entry should go into the detected or the |
|---|
| 1835 | # misdetected list. We only compare main isa_addr here, of course. |
|---|
| 1836 | foreach $main_entry (@chips_detected) { |
|---|
| 1837 | $detected_ref = $main_entry->{detected}; |
|---|
| 1838 | $misdetected_ref = $main_entry->{misdetected}; |
|---|
| 1839 | for ($i = 0; $i < @{$main_entry->{detected}}; $i++) { |
|---|
| 1840 | if (exists $detected_ref->[$i]->{isa_addr} and |
|---|
| 1841 | $detected_ref->[$i]->{isa_addr} == $datahash->{isa_addr}) { |
|---|
| 1842 | if ($detected_ref->[$i]->{conf} >= $datahash->{conf}) { |
|---|
| 1843 | push @$new_misdetected_ref, $datahash; |
|---|
| 1844 | } else { |
|---|
| 1845 | push @$misdetected_ref,$detected_ref->[$i]; |
|---|
| 1846 | splice @$detected_ref, $i,1; |
|---|
| 1847 | push @$new_detected_ref, $datahash; |
|---|
| 1848 | } |
|---|
| 1849 | if ($isalias) { |
|---|
| 1850 | return $datahash; |
|---|
| 1851 | } else { |
|---|
| 1852 | return 0; |
|---|
| 1853 | } |
|---|
| 1854 | } |
|---|
| 1855 | } |
|---|
| 1856 | } |
|---|
| 1857 | |
|---|
| 1858 | # Not found? OK, put it in the detected list |
|---|
| 1859 | push @$new_detected_ref, $datahash; |
|---|
| 1860 | if ($isalias) { |
|---|
| 1861 | return $datahash; |
|---|
| 1862 | } else { |
|---|
| 1863 | return 0; |
|---|
| 1864 | } |
|---|
| 1865 | } |
|---|
| 1866 | |
|---|
| 1867 | # $_[0]: The number of the adapter to scan |
|---|
| 1868 | # $_[1]: The name of the adapter, as appearing in /proc/bus/i2c |
|---|
| 1869 | # $_[2]: The name of the algorithm, as appearing in /proc/bus/i2c |
|---|
| 1870 | # $_[3]: The driver of the adapter |
|---|
| 1871 | # @_[4..]: Addresses not to scan |
|---|
| 1872 | sub scan_adapter |
|---|
| 1873 | { |
|---|
| 1874 | my ( $adapter_nr,$adapter_name,$algorithm_name,$adapter_driver, |
|---|
| 1875 | $not_to_scan) = @_; |
|---|
| 1876 | my ($chip, $addr, $conf,@chips,$new_hash,$other_addr); |
|---|
| 1877 | |
|---|
| 1878 | # As we modify it, we need a copy |
|---|
| 1879 | my @not_to_scan = @$not_to_scan; |
|---|
| 1880 | |
|---|
| 1881 | open FILE,"/dev/i2c-$adapter_nr" or |
|---|
| 1882 | open FILE,"/dev/i2c$adapter_nr" or |
|---|
| 1883 | open FILE,"/dev/i2c/$adapter_nr" or |
|---|
| 1884 | (print "Can't open /dev/i2c[-/]$adapter_nr\n"), return; |
|---|
| 1885 | |
|---|
| 1886 | # Now scan each address in turn |
|---|
| 1887 | foreach $addr (0..0x7f) { |
|---|
| 1888 | # As the not_to_scan list is sorted, we can check it fast |
|---|
| 1889 | if (@not_to_scan and $not_to_scan[0] == $addr) { |
|---|
| 1890 | shift @not_to_scan; |
|---|
| 1891 | next; |
|---|
| 1892 | } |
|---|
| 1893 | |
|---|
| 1894 | i2c_set_slave_addr(\*FILE,$addr) or |
|---|
| 1895 | printf("Client at address 0x%02x can not be probed - unload all client drivers first!\n",$addr), next; |
|---|
| 1896 | |
|---|
| 1897 | next unless i2c_smbus_write_quick(\*FILE,$SMBUS_WRITE) >= 0; |
|---|
| 1898 | printf "Client found at address 0x%02x\n",$addr; |
|---|
| 1899 | # Prevent 24RF08 corruption |
|---|
| 1900 | if($addr >= 0x54 and $addr <= 0x57) { |
|---|
| 1901 | i2c_smbus_write_quick(\*FILE,$SMBUS_WRITE); |
|---|
| 1902 | } |
|---|
| 1903 | |
|---|
| 1904 | foreach $chip (@chip_ids) { |
|---|
| 1905 | if (exists $$chip{i2c_addrs} and contains $addr, @{$$chip{i2c_addrs}}) { |
|---|
| 1906 | print "Probing for `$$chip{name}'... "; |
|---|
| 1907 | if (($conf,@chips) = &{$$chip{i2c_detect}} (\*FILE ,$addr)) { |
|---|
| 1908 | print "Success!\n", |
|---|
| 1909 | " (confidence $conf, driver `$$chip{driver}')"; |
|---|
| 1910 | if (@chips) { |
|---|
| 1911 | print ", other addresses:"; |
|---|
| 1912 | @chips = sort @chips; |
|---|
| 1913 | foreach $other_addr (sort @chips) { |
|---|
| 1914 | printf(" 0x%02x",$other_addr); |
|---|
| 1915 | } |
|---|
| 1916 | } |
|---|
| 1917 | printf "\n"; |
|---|
| 1918 | $new_hash = { conf => $conf, |
|---|
| 1919 | i2c_addr => $addr, |
|---|
| 1920 | chipname => $$chip{name}, |
|---|
| 1921 | i2c_adap => $adapter_name, |
|---|
| 1922 | i2c_algo => $algorithm_name, |
|---|
| 1923 | i2c_driver => $adapter_driver, |
|---|
| 1924 | i2c_devnr => $adapter_nr, |
|---|
| 1925 | }; |
|---|
| 1926 | if (@chips) { |
|---|
| 1927 | my @chips_copy = @chips; |
|---|
| 1928 | $new_hash->{i2c_sub_addrs} = \@chips_copy; |
|---|
| 1929 | } |
|---|
| 1930 | $new_hash->{i2c_extra} = 0 |
|---|
| 1931 | if exists $chip->{i2c_driver_addrs} and |
|---|
| 1932 | not contains( $addr , @{$chip->{i2c_driver_addrs}}); |
|---|
| 1933 | add_i2c_to_chips_detected $$chip{driver}, $new_hash; |
|---|
| 1934 | } else { |
|---|
| 1935 | print "Failed!\n"; |
|---|
| 1936 | } |
|---|
| 1937 | } |
|---|
| 1938 | } |
|---|
| 1939 | } |
|---|
| 1940 | } |
|---|
| 1941 | |
|---|
| 1942 | sub scan_isa_bus |
|---|
| 1943 | { |
|---|
| 1944 | my ($chip,$addr,$conf); |
|---|
| 1945 | foreach $chip (@chip_ids) { |
|---|
| 1946 | next if not exists $$chip{isa_addrs} or not exists $$chip{isa_detect}; |
|---|
| 1947 | print "Probing for `$$chip{name}'\n"; |
|---|
| 1948 | foreach $addr (@{$$chip{isa_addrs}}) { |
|---|
| 1949 | if ($addr) { |
|---|
| 1950 | printf " Trying address 0x%04x... ", $addr; |
|---|
| 1951 | } else { |
|---|
| 1952 | print " Trying general detect... "; |
|---|
| 1953 | } |
|---|
| 1954 | $conf = &{$$chip{isa_detect}} ($addr); |
|---|
| 1955 | print("Failed!\n"), next if not defined $conf; |
|---|
| 1956 | print "Success!\n"; |
|---|
| 1957 | printf " (confidence %d, driver `%s')\n", $conf, $$chip{driver}; |
|---|
| 1958 | my $new_hash = { conf => $conf, |
|---|
| 1959 | isa_addr => $addr, |
|---|
| 1960 | chipname => $$chip{name} |
|---|
| 1961 | }; |
|---|
| 1962 | $new_hash->{isa_extra} = 0 |
|---|
| 1963 | if exists $chip->{isa_driver_addrs} and |
|---|
| 1964 | not contains ($addr, @{$chip->{isa_driver_addrs}}); |
|---|
| 1965 | $new_hash = add_isa_to_chips_detected $$chip{alias_detect},$$chip{driver}, |
|---|
| 1966 | $new_hash; |
|---|
| 1967 | if ($new_hash) { |
|---|
| 1968 | printf " Alias of the chip on I2C bus `%s', address 0x%04x\n", |
|---|
| 1969 | $new_hash->{i2c_adap},$new_hash->{i2c_addr}; |
|---|
| 1970 | } |
|---|
| 1971 | } |
|---|
| 1972 | } |
|---|
| 1973 | } |
|---|
| 1974 | |
|---|
| 1975 | sub scan_superio |
|---|
| 1976 | { |
|---|
| 1977 | my ($chip,$val,$addr,$conf); |
|---|
| 1978 | foreach $chip (@superio_ids) { |
|---|
| 1979 | print "Probing for `$$chip{name}'\n"; |
|---|
| 1980 | # write the password |
|---|
| 1981 | foreach $val (@{$$chip{enter}}) { |
|---|
| 1982 | outb($$chip{addrreg}, $val); |
|---|
| 1983 | } |
|---|
| 1984 | # check the device ID |
|---|
| 1985 | outb($$chip{addrreg}, $$chip{devidreg}); |
|---|
| 1986 | $val = inb($$chip{datareg}); |
|---|
| 1987 | if($val == $$chip{devid}) { |
|---|
| 1988 | print " Success..."; |
|---|
| 1989 | # switch to the sensor logical device |
|---|
| 1990 | outb($$chip{addrreg}, $$chip{logdevreg}); |
|---|
| 1991 | outb($$chip{datareg}, $$chip{logdev}); |
|---|
| 1992 | # check the activation register |
|---|
| 1993 | if(exists $$chip{actreg}) { |
|---|
| 1994 | outb($$chip{addrreg}, $$chip{actreg}); |
|---|
| 1995 | $val = inb($$chip{datareg}); |
|---|
| 1996 | if(!($val & $$chip{actmask})) { |
|---|
| 1997 | print " but not activated, module may not find\n"; |
|---|
| 1998 | outb($$chip{exitreg}, $$chip{exit}); |
|---|
| 1999 | next; |
|---|
| 2000 | } |
|---|
| 2001 | } |
|---|
| 2002 | # Get the IO base register |
|---|
| 2003 | outb($$chip{addrreg}, $$chip{basereg}); |
|---|
| 2004 | $addr = inb($$chip{datareg}); |
|---|
| 2005 | outb($$chip{addrreg}, $$chip{basereg} + 1); |
|---|
| 2006 | $addr = ($addr << 8) | inb($$chip{datareg}); |
|---|
| 2007 | if($addr == 0) { |
|---|
| 2008 | print " but not activated, module may not find\n"; |
|---|
| 2009 | outb($$chip{addrreg}, $$chip{exit}); |
|---|
| 2010 | next; |
|---|
| 2011 | } |
|---|
| 2012 | printf " found at address 0x%04x\n", $addr; |
|---|
| 2013 | my $new_hash = { conf => 8, |
|---|
| 2014 | isa_addr => $addr, |
|---|
| 2015 | chipname => $$chip{name} |
|---|
| 2016 | }; |
|---|
| 2017 | add_isa_to_chips_detected $$chip{alias_detect},$$chip{driver}, |
|---|
| 2018 | $new_hash; |
|---|
| 2019 | } else { |
|---|
| 2020 | print " Failed!\n"; |
|---|
| 2021 | } |
|---|
| 2022 | outb($$chip{exitreg}, $$chip{exit}); |
|---|
| 2023 | } |
|---|
| 2024 | } |
|---|
| 2025 | |
|---|
| 2026 | |
|---|
| 2027 | ################## |
|---|
| 2028 | # CHIP DETECTION # |
|---|
| 2029 | ################## |
|---|
| 2030 | |
|---|
| 2031 | # Each function returns a confidence value. The higher this value, the more |
|---|
| 2032 | # sure we are about this chip. A Winbond W83781D, for example, will be |
|---|
| 2033 | # detected as a LM78 too; but as the Winbond detection has a higher confidence |
|---|
| 2034 | # factor, you should identify it as a Winbond. |
|---|
| 2035 | |
|---|
| 2036 | # Each function returns a list. The first element is the confidence value; |
|---|
| 2037 | # Each element after it is an SMBus address. In this way, we can detect |
|---|
| 2038 | # chips with several SMBus addresses. The SMBus address for which the |
|---|
| 2039 | # function was called is never returned. |
|---|
| 2040 | |
|---|
| 2041 | # If there are devices which get confused if they are only read from, then |
|---|
| 2042 | # this program will surely confuse them. But we guarantee never to write to |
|---|
| 2043 | # any of these devices. |
|---|
| 2044 | |
|---|
| 2045 | |
|---|
| 2046 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2047 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2048 | # $_[1]: Address |
|---|
| 2049 | # Returns: undef if not detected, (7) if detected. |
|---|
| 2050 | # Registers used: 0x58 |
|---|
| 2051 | sub mtp008_detect |
|---|
| 2052 | { |
|---|
| 2053 | my ($file,$addr) = @_; |
|---|
| 2054 | return if (i2c_smbus_read_byte_data($file,0x58)) != 0xac; |
|---|
| 2055 | return (8); |
|---|
| 2056 | } |
|---|
| 2057 | |
|---|
| 2058 | # $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) |
|---|
| 2059 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2060 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2061 | # $_[2]: Address |
|---|
| 2062 | # Returns: undef if not detected, (7) if detected. |
|---|
| 2063 | # Registers used: |
|---|
| 2064 | # 0x40: Configuration |
|---|
| 2065 | # 0x48: Full I2C Address |
|---|
| 2066 | # 0x49: Device ID |
|---|
| 2067 | # Note that this function is always called through a closure, so the |
|---|
| 2068 | # arguments are shifted by one place. |
|---|
| 2069 | sub lm78_detect |
|---|
| 2070 | { |
|---|
| 2071 | my $reg; |
|---|
| 2072 | my ($chip,$file,$addr) = @_; |
|---|
| 2073 | return unless i2c_smbus_read_byte_data($file,0x48) == $addr; |
|---|
| 2074 | return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00; |
|---|
| 2075 | $reg = i2c_smbus_read_byte_data($file,0x49); |
|---|
| 2076 | return unless ($chip == 0 and ($reg == 0x00 or $reg == 0x20)) or |
|---|
| 2077 | ($chip == 1 and $reg == 0x40) or |
|---|
| 2078 | ($chip == 2 and ($reg & 0xfe) == 0xc0); |
|---|
| 2079 | return (7); |
|---|
| 2080 | } |
|---|
| 2081 | |
|---|
| 2082 | # $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) |
|---|
| 2083 | # $_[1]: Address |
|---|
| 2084 | # Returns: undef if not detected, 7 if detected. |
|---|
| 2085 | # Note: Only address 0x290 is scanned at this moment. |
|---|
| 2086 | sub lm78_isa_detect |
|---|
| 2087 | { |
|---|
| 2088 | my ($chip,$addr) = @_ ; |
|---|
| 2089 | my $val = inb ($addr + 1); |
|---|
| 2090 | return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or |
|---|
| 2091 | inb ($addr + 7) != $val; |
|---|
| 2092 | |
|---|
| 2093 | $val = inb($addr + 5) & 0x7f; |
|---|
| 2094 | outb($addr+5,~ $val); |
|---|
| 2095 | if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { |
|---|
| 2096 | outb($addr+5,$val); |
|---|
| 2097 | return; |
|---|
| 2098 | } |
|---|
| 2099 | my $readproc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; |
|---|
| 2100 | return unless (&$readproc(0x40) & 0x80) == 0x00; |
|---|
| 2101 | my $reg = &$readproc(0x49); |
|---|
| 2102 | return unless ($chip == 0 and ($reg == 0x00 or $reg == 0x20)) or |
|---|
| 2103 | ($chip == 1 and $reg == 0x40) or |
|---|
| 2104 | ($chip == 2 and ($reg & 0xfe) == 0xc0); |
|---|
| 2105 | return 7; |
|---|
| 2106 | } |
|---|
| 2107 | |
|---|
| 2108 | |
|---|
| 2109 | # $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) |
|---|
| 2110 | # $_[1]: ISA address |
|---|
| 2111 | # $_[2]: I2C file handle |
|---|
| 2112 | # $_[3]: I2C address |
|---|
| 2113 | sub lm78_alias_detect |
|---|
| 2114 | { |
|---|
| 2115 | my ($chip,$isa_addr,$file,$i2c_addr) = @_; |
|---|
| 2116 | my $i; |
|---|
| 2117 | my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; |
|---|
| 2118 | return 0 unless &$readproc(0x48) == $i2c_addr; |
|---|
| 2119 | for ($i = 0x2b; $i <= 0x3d; $i ++) { |
|---|
| 2120 | return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($file,$i); |
|---|
| 2121 | } |
|---|
| 2122 | return 1; |
|---|
| 2123 | } |
|---|
| 2124 | |
|---|
| 2125 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2126 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2127 | # $_[1]: Address |
|---|
| 2128 | # Returns: undef if not detected, (3) if detected. |
|---|
| 2129 | # Registers used: |
|---|
| 2130 | # 0x01: Configuration |
|---|
| 2131 | # 0x02: Hysteresis |
|---|
| 2132 | # 0x03: Overtemperature Shutdown |
|---|
| 2133 | # Detection really sucks! It is only based on the fact that the LM75 has only |
|---|
| 2134 | # four registers. Any other chip in the valid address range with only four |
|---|
| 2135 | # registers will be detected too. |
|---|
| 2136 | # Note that register $00 may change, so we can't use the modulo trick on it. |
|---|
| 2137 | sub lm75_detect |
|---|
| 2138 | { |
|---|
| 2139 | my $i; |
|---|
| 2140 | my ($file,$addr) = @_; |
|---|
| 2141 | my $cur = i2c_smbus_read_word_data($file,0x00); |
|---|
| 2142 | my $conf = i2c_smbus_read_byte_data($file,0x01); |
|---|
| 2143 | my $hyst = i2c_smbus_read_word_data($file,0x02); |
|---|
| 2144 | my $os = i2c_smbus_read_word_data($file,0x03); |
|---|
| 2145 | for ($i = 0x00; $i <= 0x1f; $i += 1) { |
|---|
| 2146 | return if i2c_smbus_read_byte_data($file,($i * 0x08) + 0x01) != $conf; |
|---|
| 2147 | return if i2c_smbus_read_word_data($file,($i * 0x08) + 0x02) != $hyst; |
|---|
| 2148 | return if i2c_smbus_read_word_data($file,($i * 0x08) + 0x03) != $os; |
|---|
| 2149 | } |
|---|
| 2150 | return (3); |
|---|
| 2151 | } |
|---|
| 2152 | |
|---|
| 2153 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2154 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2155 | # $_[1]: Address |
|---|
| 2156 | # Returns: undef if not detected, (3) if detected, |
|---|
| 2157 | # (6) or (9) if even more bits match. |
|---|
| 2158 | # Registers used: |
|---|
| 2159 | # 0xAC: Configuration |
|---|
| 2160 | # Detection is weak. We check if Bit 3 is set and Bit 2 is clear. |
|---|
| 2161 | # The DS1621 will aways have a config like 0x????10??. A even better |
|---|
| 2162 | # match would be 0x0??01000. |
|---|
| 2163 | sub ds1621_detect |
|---|
| 2164 | { |
|---|
| 2165 | my $i; |
|---|
| 2166 | my ($file,$addr) = @_; |
|---|
| 2167 | my $conf = i2c_smbus_read_byte_data($file,0xAC); |
|---|
| 2168 | return (9) if ($conf & 0x9F) == 0x98; |
|---|
| 2169 | return (6) if ($conf & 0x0F) == 0x08; |
|---|
| 2170 | return (3) if ($conf & 0x0C) == 0x08; |
|---|
| 2171 | return ; |
|---|
| 2172 | } |
|---|
| 2173 | |
|---|
| 2174 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2175 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2176 | # $_[1]: Address |
|---|
| 2177 | # Returns: undef if not detected, (3) if detected. |
|---|
| 2178 | # Registers used: |
|---|
| 2179 | # Registers used: |
|---|
| 2180 | # 0x02: Interrupt state register |
|---|
| 2181 | # How to detect this beast? |
|---|
| 2182 | sub lm80_detect |
|---|
| 2183 | { |
|---|
| 2184 | my $i; |
|---|
| 2185 | my ($file,$addr) = @_; |
|---|
| 2186 | return if (i2c_smbus_read_byte_data($file,0x02) & 0xc0) != 0; |
|---|
| 2187 | for ($i = 0x2a; $i <= 0x3d; $i++) { |
|---|
| 2188 | my $reg = i2c_smbus_read_byte_data($file,$i); |
|---|
| 2189 | return if i2c_smbus_read_byte_data($file,$i+0x40) != $reg; |
|---|
| 2190 | return if i2c_smbus_read_byte_data($file,$i+0x80) != $reg; |
|---|
| 2191 | return if i2c_smbus_read_byte_data($file,$i+0xc0) != $reg; |
|---|
| 2192 | } |
|---|
| 2193 | return (3); |
|---|
| 2194 | } |
|---|
| 2195 | |
|---|
| 2196 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2197 | # #_[1]: Base address. |
|---|
| 2198 | # Returns: undef if not detected, (7) if detected. |
|---|
| 2199 | # Registers used: 0x3e == Vendor register. |
|---|
| 2200 | # 0x3f == Version/Stepping register. |
|---|
| 2201 | # Constants used: 0x01 == National Semiconductor Vendor Id. |
|---|
| 2202 | # 0x60 == Version number. The lower 4 stepping |
|---|
| 2203 | # bits are masked and ignored. |
|---|
| 2204 | sub lm85_detect |
|---|
| 2205 | { |
|---|
| 2206 | my ($file,$addr) = @_; |
|---|
| 2207 | return if (i2c_smbus_read_byte_data($file,0x3e)) != 0x01; |
|---|
| 2208 | return if (i2c_smbus_read_byte_data($file,0x3f) & 0xf0) != 0x60; |
|---|
| 2209 | return (7); |
|---|
| 2210 | } |
|---|
| 2211 | |
|---|
| 2212 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2213 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2214 | # $_[1]: Address |
|---|
| 2215 | # Returns: undef if not detected, (7) if detected. |
|---|
| 2216 | # Registers used: 0x3E, 0x3F |
|---|
| 2217 | # Assume lower 2 bits of reg 0x3F are for revisions. |
|---|
| 2218 | sub lm87_detect |
|---|
| 2219 | { |
|---|
| 2220 | my ($file,$addr) = @_; |
|---|
| 2221 | return if (i2c_smbus_read_byte_data($file,0x3e)) != 0x02; |
|---|
| 2222 | return if (i2c_smbus_read_byte_data($file,0x3f) & 0xfc) != 0x04; |
|---|
| 2223 | return (7); |
|---|
| 2224 | } |
|---|
| 2225 | |
|---|
| 2226 | # $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 2 = W83783S, |
|---|
| 2227 | # 3 = W83627HF, 4 = AS99127F, 6 = W83L784R/AR |
|---|
| 2228 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2229 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2230 | # $_[2]: Address |
|---|
| 2231 | # Returns: undef if not detected, (8,addr1,addr2) if detected, but only |
|---|
| 2232 | # if the LM75 chip emulation is enabled. |
|---|
| 2233 | # Registers used: |
|---|
| 2234 | # 0x48: Full I2C Address |
|---|
| 2235 | # 0x4a: I2C addresses of emulated LM75 chips |
|---|
| 2236 | # 0x4e: Vendor ID byte selection, and bank selection |
|---|
| 2237 | # 0x4f: Vendor ID |
|---|
| 2238 | # 0x58: Device ID (only when in bank 0); ignore LSB. |
|---|
| 2239 | # Note: Fails if the W8378xD is not in bank 0! |
|---|
| 2240 | # Note: Detection overrules a previous LM78 detection |
|---|
| 2241 | # Note: AS99127F address register 0x48 not supported? |
|---|
| 2242 | sub w83781d_detect |
|---|
| 2243 | { |
|---|
| 2244 | my ($reg1,$reg2,@res); |
|---|
| 2245 | my ($chip,$file,$addr) = @_; |
|---|
| 2246 | return unless (i2c_smbus_read_byte_data($file,0x48) == $addr) |
|---|
| 2247 | or ($chip == 4) or ($chip == 6); |
|---|
| 2248 | $reg1 = i2c_smbus_read_byte_data($file,0x4e); |
|---|
| 2249 | $reg2 = i2c_smbus_read_byte_data($file,0x4f); |
|---|
| 2250 | if ($chip != 4) { |
|---|
| 2251 | return unless (($reg1 & 0x80) == 0x00 and $reg2 == 0xa3) or |
|---|
| 2252 | (($reg1 & 0x80) == 0x80 and $reg2 == 0x5c); |
|---|
| 2253 | } |
|---|
| 2254 | if ($chip == 4) { |
|---|
| 2255 | return unless (($reg1 & 0x80) == 0x00 and |
|---|
| 2256 | ($reg2 == 0xc3 or $reg2 == 0x94)) or |
|---|
| 2257 | (($reg1 & 0x80) == 0x80 and |
|---|
| 2258 | ($reg2 == 0x12 or $reg2 == 0x06)); |
|---|
| 2259 | } |
|---|
| 2260 | return unless ($reg1 & 0x07) == 0x00; |
|---|
| 2261 | $reg1 = i2c_smbus_read_byte_data($file,0x58) & 0xfe; |
|---|
| 2262 | return if $chip == 0 and $reg1 != 0x10; |
|---|
| 2263 | return if $chip == 1 and $reg1 != 0x30; |
|---|
| 2264 | return if $chip == 2 and $reg1 != 0x40; |
|---|
| 2265 | return if $chip == 3 and $reg1 != 0x20; |
|---|
| 2266 | return if $chip == 4 and $reg1 != 0x30; |
|---|
| 2267 | return if $chip == 6 and $reg1 != 0x50; |
|---|
| 2268 | $reg1 = i2c_smbus_read_byte_data($file,0x4a); |
|---|
| 2269 | @res = (8); |
|---|
| 2270 | push @res, ($reg1 & 0x07) + 0x48 unless $reg1 & 0x08 ; |
|---|
| 2271 | push @res, (($reg1 & 0x80) >> 4) + 0x48 unless ($reg1 & 0x80 or $chip == 2); |
|---|
| 2272 | return @res; |
|---|
| 2273 | } |
|---|
| 2274 | |
|---|
| 2275 | # $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 2 = W83783S, 3 = W83627HF) |
|---|
| 2276 | # $_[1]: ISA address |
|---|
| 2277 | # $_[2]: I2C file handle |
|---|
| 2278 | # $_[3]: I2C address |
|---|
| 2279 | sub w83781d_alias_detect |
|---|
| 2280 | { |
|---|
| 2281 | my ($chip,$isa_addr,$file,$i2c_addr) = @_; |
|---|
| 2282 | my $i; |
|---|
| 2283 | my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; |
|---|
| 2284 | return 0 unless &$readproc(0x48) == $i2c_addr; |
|---|
| 2285 | for ($i = 0x2b; $i <= 0x3d; $i ++) { |
|---|
| 2286 | return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($file,$i); |
|---|
| 2287 | } |
|---|
| 2288 | return 1; |
|---|
| 2289 | } |
|---|
| 2290 | |
|---|
| 2291 | # $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 3 = W83627HF, 5 = W83697HF) |
|---|
| 2292 | # (W83783S and AS99127F not on ISA bus) |
|---|
| 2293 | # $_[1]: Address |
|---|
| 2294 | # Returns: undef if not detected, (8) if detected. |
|---|
| 2295 | sub w83781d_isa_detect |
|---|
| 2296 | { |
|---|
| 2297 | my ($chip,$addr) = @_ ; |
|---|
| 2298 | my ($reg1,$reg2); |
|---|
| 2299 | my $val = inb ($addr + 1); |
|---|
| 2300 | return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or |
|---|
| 2301 | inb ($addr + 7) != $val; |
|---|
| 2302 | |
|---|
| 2303 | $val = inb($addr + 5) & 0x7f; |
|---|
| 2304 | outb($addr+5,~ $val); |
|---|
| 2305 | if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { |
|---|
| 2306 | outb($addr+5,$val); |
|---|
| 2307 | return; |
|---|
| 2308 | } |
|---|
| 2309 | |
|---|
| 2310 | my $read_proc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; |
|---|
| 2311 | $reg1 = &$read_proc(0x4e); |
|---|
| 2312 | $reg2 = &$read_proc(0x4f); |
|---|
| 2313 | return unless (($reg1 & 0x80) == 0x00 and $reg2 == 0xa3) or |
|---|
| 2314 | (($reg1 & 0x80) == 0x80 and $reg2 == 0x5c); |
|---|
| 2315 | return unless ($reg1 & 0x07) == 0x00; |
|---|
| 2316 | $reg1 = &$read_proc(0x58) & 0xfe; |
|---|
| 2317 | return if $chip == 0 and $reg1 != 0x10; |
|---|
| 2318 | return if $chip == 1 and $reg1 != 0x30; |
|---|
| 2319 | return if $chip == 3 and $reg1 != 0x20; |
|---|
| 2320 | return if $chip == 5 and $reg1 != 0x60; |
|---|
| 2321 | return 8; |
|---|
| 2322 | } |
|---|
| 2323 | |
|---|
| 2324 | # $_[0]: Chip to detect (0 = Revision 0x00, 1 = Revision 0x80) |
|---|
| 2325 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2326 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2327 | # $_[2]: Address |
|---|
| 2328 | # Returns: undef if not detected, (6) if detected. |
|---|
| 2329 | # Registers used: |
|---|
| 2330 | # 0x00: Device ID |
|---|
| 2331 | # 0x01: Revision ID |
|---|
| 2332 | # 0x03: Configuration |
|---|
| 2333 | # Mediocre detection |
|---|
| 2334 | sub gl518sm_detect |
|---|
| 2335 | { |
|---|
| 2336 | my $reg; |
|---|
| 2337 | my ($chip,$file,$addr) = @_; |
|---|
| 2338 | return unless i2c_smbus_read_byte_data($file,0x00) == 0x80; |
|---|
| 2339 | return unless (i2c_smbus_read_byte_data($file,0x03) & 0x80) == 0x00; |
|---|
| 2340 | $reg = i2c_smbus_read_byte_data($file,0x01); |
|---|
| 2341 | return unless ($chip == 0 and $reg == 0x00) or |
|---|
| 2342 | ($chip == 1 and $reg == 0x80); |
|---|
| 2343 | return (6); |
|---|
| 2344 | } |
|---|
| 2345 | |
|---|
| 2346 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2347 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2348 | # $_[1]: Address |
|---|
| 2349 | # Returns: undef if not detected, (5) if detected. |
|---|
| 2350 | # Registers used: |
|---|
| 2351 | # 0x00: Device ID |
|---|
| 2352 | # 0x01: Revision ID |
|---|
| 2353 | # 0x03: Configuration |
|---|
| 2354 | # Mediocre detection |
|---|
| 2355 | sub gl520sm_detect |
|---|
| 2356 | { |
|---|
| 2357 | my ($file,$addr) = @_; |
|---|
| 2358 | return unless i2c_smbus_read_byte_data($file,0x00) == 0x20; |
|---|
| 2359 | return unless (i2c_smbus_read_byte_data($file,0x03) & 0x80) == 0x00; |
|---|
| 2360 | # The line below must be better checked before I dare to use it. |
|---|
| 2361 | # return unless i2c_smbus_read_byte_data($file,0x01) == 0x00; |
|---|
| 2362 | return (5); |
|---|
| 2363 | } |
|---|
| 2364 | |
|---|
| 2365 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2366 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2367 | # $_[1]: Address |
|---|
| 2368 | # Returns: undef if not detected, (5) if detected. |
|---|
| 2369 | # Registers used: |
|---|
| 2370 | # 0x00: Device ID |
|---|
| 2371 | # Mediocre detection |
|---|
| 2372 | sub gl525sm_detect |
|---|
| 2373 | { |
|---|
| 2374 | my ($file,$addr) = @_; |
|---|
| 2375 | return unless i2c_smbus_read_byte_data($file,0x00) == 0x25; |
|---|
| 2376 | return (5); |
|---|
| 2377 | } |
|---|
| 2378 | |
|---|
| 2379 | # $_[0]: Chip to detect (0 = ADM9240, 1 = DS1780, 2 = LM81) |
|---|
| 2380 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2381 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2382 | # $_[2]: Address |
|---|
| 2383 | # Returns: undef if not detected, (7) if detected. |
|---|
| 2384 | # Registers used: |
|---|
| 2385 | # 0x3e: Company ID |
|---|
| 2386 | # 0x40: Configuration |
|---|
| 2387 | # 0x48: Full I2C Address |
|---|
| 2388 | # Note: Detection overrules a previous LM78 detection |
|---|
| 2389 | sub adm9240_detect |
|---|
| 2390 | { |
|---|
| 2391 | my $reg; |
|---|
| 2392 | my ($chip, $file,$addr) = @_; |
|---|
| 2393 | $reg = i2c_smbus_read_byte_data($file,0x3e); |
|---|
| 2394 | return unless ($chip == 0 and $reg == 0x23) or |
|---|
| 2395 | ($chip == 1 and $reg == 0xda) or |
|---|
| 2396 | ($chip == 2 and $reg == 0x01); |
|---|
| 2397 | return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00; |
|---|
| 2398 | return unless i2c_smbus_read_byte_data($file,0x48) == $addr; |
|---|
| 2399 | |
|---|
| 2400 | return (7); |
|---|
| 2401 | } |
|---|
| 2402 | |
|---|
| 2403 | # $_[0]: Chip to detect (0 = ADM1022, 1 = THMC50) |
|---|
| 2404 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2405 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2406 | # $_[2]: Address |
|---|
| 2407 | # Returns: undef if not detected, (8) if detected. |
|---|
| 2408 | # Registers used: |
|---|
| 2409 | # 0x3e: Company ID |
|---|
| 2410 | # 0x3f: Revision |
|---|
| 2411 | # 0x40: Configuration |
|---|
| 2412 | # Note: Detection overrules a previous LM78 or ADM9240 detection |
|---|
| 2413 | sub adm1022_detect |
|---|
| 2414 | { |
|---|
| 2415 | my $reg; |
|---|
| 2416 | my ($chip, $file,$addr) = @_; |
|---|
| 2417 | $reg = i2c_smbus_read_byte_data($file,0x3e); |
|---|
| 2418 | return unless ($chip == 0 and $reg == 0x41) or |
|---|
| 2419 | ($chip == 1 and $reg == 0x49); |
|---|
| 2420 | return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00; |
|---|
| 2421 | return unless (i2c_smbus_read_byte_data($file,0x3f) & 0xc0) == 0xc0; |
|---|
| 2422 | return (8); |
|---|
| 2423 | } |
|---|
| 2424 | |
|---|
| 2425 | # $_[0]: Chip to detect (0 = ADM1025) |
|---|
| 2426 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2427 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2428 | # $_[2]: Address |
|---|
| 2429 | # Returns: undef if not detected, (8) if detected. |
|---|
| 2430 | # Registers used: |
|---|
| 2431 | # 0x3e: Company ID |
|---|
| 2432 | # 0x3f: Revision |
|---|
| 2433 | # 0x40: Configuration |
|---|
| 2434 | # Note: Detection overrules a previous LM78 or ADM9240 detection |
|---|
| 2435 | sub adm1025_detect |
|---|
| 2436 | { |
|---|
| 2437 | my $reg; |
|---|
| 2438 | my ($chip, $file,$addr) = @_; |
|---|
| 2439 | $reg = i2c_smbus_read_byte_data($file,0x3e); |
|---|
| 2440 | return unless ($reg == 0x41); |
|---|
| 2441 | return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00; |
|---|
| 2442 | return unless (i2c_smbus_read_byte_data($file,0x3f) & 0xf0) == 0x20; |
|---|
| 2443 | return (8); |
|---|
| 2444 | } |
|---|
| 2445 | |
|---|
| 2446 | # $_[0]: Chip to detect (0 = ADM1024) |
|---|
| 2447 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2448 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2449 | # $_[2]: Address |
|---|
| 2450 | # Returns: undef if not detected, (8) if detected. |
|---|
| 2451 | # Registers used: |
|---|
| 2452 | # 0x3e: Company ID |
|---|
| 2453 | # 0x3f: Revision |
|---|
| 2454 | # 0x40: Configuration |
|---|
| 2455 | sub adm1024_detect |
|---|
| 2456 | { |
|---|
| 2457 | my $reg; |
|---|
| 2458 | my ($chip, $file,$addr) = @_; |
|---|
| 2459 | $reg = i2c_smbus_read_byte_data($file,0x3e); |
|---|
| 2460 | return unless ($reg == 0x41); |
|---|
| 2461 | return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00; |
|---|
| 2462 | return unless (i2c_smbus_read_byte_data($file,0x3f) & 0xf0) == 0x10; |
|---|
| 2463 | return (8); |
|---|
| 2464 | } |
|---|
| 2465 | |
|---|
| 2466 | # $_[0]: Chip to detect |
|---|
| 2467 | # (0 = ADM1021, 1 = MAX1617, 2 = MAX1617A, 3 = THMC10, 4 = LM84, 5 = GL523, 6 = MC1066) |
|---|
| 2468 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2469 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2470 | # $_[2]: Address |
|---|
| 2471 | # Returns: undef if not detected, (6) or (3) if detected. |
|---|
| 2472 | # Registers used: |
|---|
| 2473 | # 0x04: Company ID (LM84 only) |
|---|
| 2474 | # 0xfe: Company ID |
|---|
| 2475 | # 0xff: Revision (Maxim only) |
|---|
| 2476 | # 0x02: Status |
|---|
| 2477 | # Note: Especially the Maxim has very bad detection; we give it a low |
|---|
| 2478 | # confidence value. |
|---|
| 2479 | sub adm1021_detect |
|---|
| 2480 | { |
|---|
| 2481 | my $reg; |
|---|
| 2482 | my ($chip, $file,$addr) = @_; |
|---|
| 2483 | return if $chip == 0 and i2c_smbus_read_byte_data($file,0xfe) != 0x41; |
|---|
| 2484 | return if $chip == 3 and i2c_smbus_read_byte_data($file,0xfe) != 0x49; |
|---|
| 2485 | return if $chip == 4 and i2c_smbus_read_byte_data($file,0x04) != 0x00; |
|---|
| 2486 | return if $chip == 5 and i2c_smbus_read_byte_data($file,0xfe) != 0x23; |
|---|
| 2487 | return if $chip == 2 and i2c_smbus_read_byte_data($file,0xfe) != 0x4d and |
|---|
| 2488 | i2c_smbus_read_byte_data($file,0xff) != 0x01; |
|---|
| 2489 | return if $chip == 6 and i2c_smbus_read_byte_data($file,0xfe) != 0x54; |
|---|
| 2490 | # The remaining things are flaky at best. Perhaps something can be done |
|---|
| 2491 | # with the fact that some registers are unreadable? |
|---|
| 2492 | return if (i2c_smbus_read_byte_data($file,0x02) & 0x03) != 0; |
|---|
| 2493 | if ($chip == 1) { |
|---|
| 2494 | return (3); |
|---|
| 2495 | } else { |
|---|
| 2496 | return (6); |
|---|
| 2497 | } |
|---|
| 2498 | } |
|---|
| 2499 | |
|---|
| 2500 | # $_[0]: Address |
|---|
| 2501 | # Returns: undef if not detected, (9) if detected. |
|---|
| 2502 | # Note: It is already 99% certain this chip exists if we find the PCI |
|---|
| 2503 | # entry. The exact address is encoded in PCI space. |
|---|
| 2504 | sub sis5595_isa_detect |
|---|
| 2505 | { |
|---|
| 2506 | my ($addr) = @_; |
|---|
| 2507 | my ($adapter,$try,$local_try); |
|---|
| 2508 | my $found = 0; |
|---|
| 2509 | foreach $local_try (@pci_adapters) { |
|---|
| 2510 | if ($local_try->{procid} eq "Silicon Integrated Systems SIS5595") { |
|---|
| 2511 | $try = $local_try; |
|---|
| 2512 | $found = 1; |
|---|
| 2513 | last; |
|---|
| 2514 | } |
|---|
| 2515 | } |
|---|
| 2516 | return if not $found; |
|---|
| 2517 | |
|---|
| 2518 | $found = 0; |
|---|
| 2519 | foreach $adapter (@pci_list) { |
|---|
| 2520 | if ((defined($adapter->{vendid}) and |
|---|
| 2521 | $try->{vendid} == $adapter->{vendid} and |
|---|
| 2522 | $try->{devid} == $adapter->{devid} and |
|---|
| 2523 | $try->{func} == $adapter->{func}) or |
|---|
| 2524 | (! defined($adapter->{vendid}) and |
|---|
| 2525 | $adapter->{desc} =~ /$try->{procid}/ and |
|---|
| 2526 | $try->{func} == $adapter->{func})) { |
|---|
| 2527 | $found = 1; |
|---|
| 2528 | last; |
|---|
| 2529 | } |
|---|
| 2530 | } |
|---|
| 2531 | return if not $found; |
|---|
| 2532 | |
|---|
| 2533 | return 9; |
|---|
| 2534 | } |
|---|
| 2535 | |
|---|
| 2536 | # $_[0]: Address |
|---|
| 2537 | # Returns: undef if not detected, (9) if detected. |
|---|
| 2538 | # Note: It is already 99% certain this chip exists if we find the PCI |
|---|
| 2539 | # entry. The exact address is encoded in PCI space. |
|---|
| 2540 | sub via686a_isa_detect |
|---|
| 2541 | { |
|---|
| 2542 | my ($addr) = @_; |
|---|
| 2543 | my ($adapter,$try,$local_try); |
|---|
| 2544 | my $found = 0; |
|---|
| 2545 | foreach $local_try (@pci_adapters) { |
|---|
| 2546 | if ($local_try->{procid} eq "VIA Technologies VT82C686 Apollo ACPI") { |
|---|
| 2547 | $try = $local_try; |
|---|
| 2548 | $found = 1; |
|---|
| 2549 | last; |
|---|
| 2550 | } |
|---|
| 2551 | } |
|---|
| 2552 | return if not $found; |
|---|
| 2553 | |
|---|
| 2554 | $found = 0; |
|---|
| 2555 | foreach $adapter (@pci_list) { |
|---|
| 2556 | if ((defined($adapter->{vendid}) and |
|---|
| 2557 | $try->{vendid} == $adapter->{vendid} and |
|---|
| 2558 | $try->{devid} == $adapter->{devid} and |
|---|
| 2559 | $try->{func} == $adapter->{func}) or |
|---|
| 2560 | (! defined($adapter->{vendid}) and |
|---|
| 2561 | $adapter->{desc} =~ /$try->{procid}/ and |
|---|
| 2562 | $try->{func} == $adapter->{func})) { |
|---|
| 2563 | $found = 1; |
|---|
| 2564 | last; |
|---|
| 2565 | } |
|---|
| 2566 | } |
|---|
| 2567 | return if not $found; |
|---|
| 2568 | |
|---|
| 2569 | return 9; |
|---|
| 2570 | } |
|---|
| 2571 | |
|---|
| 2572 | # $_[0]: Address |
|---|
| 2573 | # Returns: undef if not detected, (9) if detected. |
|---|
| 2574 | # Note: It is already 99% certain this chip exists if we find the PCI |
|---|
| 2575 | # entry. The exact address is encoded in PCI space. |
|---|
| 2576 | sub via8231_isa_detect |
|---|
| 2577 | { |
|---|
| 2578 | my ($addr) = @_; |
|---|
| 2579 | my ($adapter,$try,$local_try); |
|---|
| 2580 | my $found = 0; |
|---|
| 2581 | foreach $local_try (@pci_adapters) { |
|---|
| 2582 | if ($local_try->{procid} eq "VIA Technologies VT8231 South Bridge") { |
|---|
| 2583 | $try = $local_try; |
|---|
| 2584 | $found = 1; |
|---|
| 2585 | last; |
|---|
| 2586 | } |
|---|
| 2587 | } |
|---|
| 2588 | return if not $found; |
|---|
| 2589 | |
|---|
| 2590 | $found = 0; |
|---|
| 2591 | foreach $adapter (@pci_list) { |
|---|
| 2592 | if ((defined($adapter->{vendid}) and |
|---|
| 2593 | $try->{vendid} == $adapter->{vendid} and |
|---|
| 2594 | $try->{devid} == $adapter->{devid} and |
|---|
| 2595 | $try->{func} == $adapter->{func}) or |
|---|
| 2596 | (! defined($adapter->{vendid}) and |
|---|
| 2597 | $adapter->{desc} =~ /$try->{procid}/ and |
|---|
| 2598 | $try->{func} == $adapter->{func})) { |
|---|
| 2599 | $found = 1; |
|---|
| 2600 | last; |
|---|
| 2601 | } |
|---|
| 2602 | } |
|---|
| 2603 | return if not $found; |
|---|
| 2604 | |
|---|
| 2605 | return 9; |
|---|
| 2606 | } |
|---|
| 2607 | |
|---|
| 2608 | # $_[0]: Chip to detect (0 = ..., 1 = ...) |
|---|
| 2609 | # $_[1]: A reference to the file descriptor to access this chip. |
|---|
| 2610 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2611 | # $_[2]: Address |
|---|
| 2612 | # Returns: undef if not detected, 8 if detected (tops LM78). |
|---|
| 2613 | # Registers used: |
|---|
| 2614 | # 0x00: Configuration |
|---|
| 2615 | # 0x48: Full I2C Address |
|---|
| 2616 | # 0x58: Mfr ID |
|---|
| 2617 | # Note that this function is always called through a closure, so the |
|---|
| 2618 | # arguments are shifted by one place. |
|---|
| 2619 | sub ite_detect |
|---|
| 2620 | { |
|---|
| 2621 | my $reg; |
|---|
| 2622 | my ($chip,$file,$addr) = @_; |
|---|
| 2623 | return unless i2c_smbus_read_byte_data($file,0x48) == $addr; |
|---|
| 2624 | return unless (i2c_smbus_read_byte_data($file,0x00) & 0x80) == 0x00; |
|---|
| 2625 | return unless i2c_smbus_read_byte_data($file,0x58) == 0x90; |
|---|
| 2626 | return (8); |
|---|
| 2627 | } |
|---|
| 2628 | |
|---|
| 2629 | # $_[0]: Chip to detect (0 = ..., 1 = ...) |
|---|
| 2630 | # $_[1]: Address |
|---|
| 2631 | # Returns: undef if not detected, 8 if detected (tops LM78). |
|---|
| 2632 | # Note: Only address 0x290 is scanned at this moment. |
|---|
| 2633 | sub ite_isa_detect |
|---|
| 2634 | { |
|---|
| 2635 | my ($chip,$addr) = @_ ; |
|---|
| 2636 | my $val = inb ($addr + 1); |
|---|
| 2637 | return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or |
|---|
| 2638 | inb ($addr + 7) != $val; |
|---|
| 2639 | |
|---|
| 2640 | $val = inb($addr + 5) & 0x7f; |
|---|
| 2641 | outb($addr+5,~ $val); |
|---|
| 2642 | if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { |
|---|
| 2643 | outb($addr+5,$val); |
|---|
| 2644 | return; |
|---|
| 2645 | } |
|---|
| 2646 | my $readproc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; |
|---|
| 2647 | return unless (&$readproc(0x00) & 0x80) == 0x00; |
|---|
| 2648 | my $reg = &$readproc(0x58); |
|---|
| 2649 | return unless ($reg == 0x90); |
|---|
| 2650 | return 8; |
|---|
| 2651 | } |
|---|
| 2652 | |
|---|
| 2653 | |
|---|
| 2654 | # $_[0]: Chip to detect (0 = ..., 1 = ...) |
|---|
| 2655 | # $_[1]: ISA address |
|---|
| 2656 | # $_[2]: I2C file handle |
|---|
| 2657 | # $_[3]: I2C address |
|---|
| 2658 | sub ite_alias_detect |
|---|
| 2659 | { |
|---|
| 2660 | my ($chip,$isa_addr,$file,$i2c_addr) = @_; |
|---|
| 2661 | my $i; |
|---|
| 2662 | my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; |
|---|
| 2663 | return 0 unless &$readproc(0x48) == $i2c_addr; |
|---|
| 2664 | for ($i = 0x2b; $i <= 0x3d; $i ++) { |
|---|
| 2665 | return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($file,$i); |
|---|
| 2666 | } |
|---|
| 2667 | return 1; |
|---|
| 2668 | } |
|---|
| 2669 | |
|---|
| 2670 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2671 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2672 | # $_[1]: Address |
|---|
| 2673 | # Returns: 8 for a memory eeprom, 6 or 8 for a Sony Vaio eeprom, |
|---|
| 2674 | # 1 or 2 for an unknown eeprom |
|---|
| 2675 | # Registers used: |
|---|
| 2676 | # 0-63: PC-100 Data and Checksum |
|---|
| 2677 | # 2-5, 128-131: Sony Vaio Data |
|---|
| 2678 | sub eeprom_detect |
|---|
| 2679 | { |
|---|
| 2680 | my ($file,$addr) = @_; |
|---|
| 2681 | # Check the checksum for validity (only works for PC-100 DIMMs) |
|---|
| 2682 | my $checksum = 0; |
|---|
| 2683 | for (my $i = 0; $i <= 62; $i ++) { |
|---|
| 2684 | $checksum += i2c_smbus_read_byte_data($file,$i); |
|---|
| 2685 | } |
|---|
| 2686 | $checksum &= 255; |
|---|
| 2687 | return 8 |
|---|
| 2688 | if (i2c_smbus_read_byte_data($file,63) == $checksum); |
|---|
| 2689 | # Even if checksum test fails, it still may be an eeprom |
|---|
| 2690 | if (i2c_smbus_read_byte_data($file,2) == 0 |
|---|
| 2691 | && i2c_smbus_read_byte_data($file,3) == 0 |
|---|
| 2692 | && i2c_smbus_read_byte_data($file,4) == 0 |
|---|
| 2693 | && i2c_smbus_read_byte_data($file,5) == 0) |
|---|
| 2694 | { |
|---|
| 2695 | if (i2c_smbus_read_byte_data($file,128) == ord 'P' |
|---|
| 2696 | && i2c_smbus_read_byte_data($file,129) == ord 'C' |
|---|
| 2697 | && i2c_smbus_read_byte_data($file,130) == ord 'G' |
|---|
| 2698 | && i2c_smbus_read_byte_data($file,131) == ord '-') |
|---|
| 2699 | { |
|---|
| 2700 | # Sony Vaio |
|---|
| 2701 | return 8 if ($addr == 0x57); |
|---|
| 2702 | return 6; |
|---|
| 2703 | } |
|---|
| 2704 | return 2; |
|---|
| 2705 | } |
|---|
| 2706 | return 1; |
|---|
| 2707 | } |
|---|
| 2708 | |
|---|
| 2709 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2710 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2711 | # $_[1]: Address |
|---|
| 2712 | # Returns: undef if not detected, (1) if detected. |
|---|
| 2713 | # Detection is impossible! |
|---|
| 2714 | sub ltc1710_detect |
|---|
| 2715 | { |
|---|
| 2716 | return (1); |
|---|
| 2717 | } |
|---|
| 2718 | |
|---|
| 2719 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2720 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2721 | # $_[1]: Address |
|---|
| 2722 | # Returns: undef if not detected, (1) if detected. |
|---|
| 2723 | # Registers used: |
|---|
| 2724 | # 0x00..0x07: DDC signature |
|---|
| 2725 | # 0x08..0x7E: checksumed area |
|---|
| 2726 | # 0x7F: checksum |
|---|
| 2727 | ### commented out additional location checks for now - don't work? |
|---|
| 2728 | sub ddcmonitor_detect |
|---|
| 2729 | { |
|---|
| 2730 | my ($file,$addr) = @_; |
|---|
| 2731 | my $i; |
|---|
| 2732 | ### for ($i = 0; $i < 8; $i ++) { |
|---|
| 2733 | ### i2c_set_slave_addr \*FILE,$addr+$i or goto FAILURE; |
|---|
| 2734 | i2c_smbus_read_byte_data($file,0x00) == 0x00 or goto FAILURE; |
|---|
| 2735 | i2c_smbus_read_byte_data($file,0x01) == 0xFF or goto FAILURE; |
|---|
| 2736 | i2c_smbus_read_byte_data($file,0x02) == 0xFF or goto FAILURE; |
|---|
| 2737 | i2c_smbus_read_byte_data($file,0x03) == 0xFF or goto FAILURE; |
|---|
| 2738 | i2c_smbus_read_byte_data($file,0x04) == 0xFF or goto FAILURE; |
|---|
| 2739 | i2c_smbus_read_byte_data($file,0x05) == 0xFF or goto FAILURE; |
|---|
| 2740 | i2c_smbus_read_byte_data($file,0x06) == 0xFF or goto FAILURE; |
|---|
| 2741 | i2c_smbus_read_byte_data($file,0x07) == 0x00 or goto FAILURE; |
|---|
| 2742 | ### } |
|---|
| 2743 | ### i2c_set_slave_addr \*FILE,$addr or return; |
|---|
| 2744 | # Check the checksum for validity. We should do this for all addresses, |
|---|
| 2745 | # but it would be too slow. |
|---|
| 2746 | my $checksum = 0; |
|---|
| 2747 | for ($i = 0; $i <= 127; $i = $i + 1) { |
|---|
| 2748 | $checksum = $checksum + i2c_smbus_read_byte_data($file,$i); |
|---|
| 2749 | } |
|---|
| 2750 | $checksum=$checksum & 255; |
|---|
| 2751 | if ($checksum != 0) { |
|---|
| 2752 | # I have one such monitor... |
|---|
| 2753 | return (2,$addr+1,$addr+2,$addr+3,$addr+4,$addr+5,$addr+6,$addr+7); |
|---|
| 2754 | } |
|---|
| 2755 | return (8,$addr+1,$addr+2,$addr+3,$addr+4,$addr+5,$addr+6,$addr+7); |
|---|
| 2756 | FAILURE: |
|---|
| 2757 | i2c_set_slave_addr \*FILE,$addr; |
|---|
| 2758 | return; |
|---|
| 2759 | } |
|---|
| 2760 | |
|---|
| 2761 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2762 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2763 | # $_[1]: Address |
|---|
| 2764 | # Returns: undef if not detected, (8) if detected. |
|---|
| 2765 | # Registers used: |
|---|
| 2766 | # 0x00-0x02: Identification ('P','E','G' -> Pegasus ? :-) |
|---|
| 2767 | sub fscpos_detect |
|---|
| 2768 | { |
|---|
| 2769 | my ($file,$addr) = @_; |
|---|
| 2770 | # check the first 3 registers |
|---|
| 2771 | if (i2c_smbus_read_byte_data($file,0x00) != 0x50) { |
|---|
| 2772 | return; |
|---|
| 2773 | } |
|---|
| 2774 | if (i2c_smbus_read_byte_data($file,0x01) != 0x45) { |
|---|
| 2775 | return; |
|---|
| 2776 | } |
|---|
| 2777 | if (i2c_smbus_read_byte_data($file,0x02) != 0x47) { |
|---|
| 2778 | return; |
|---|
| 2779 | } |
|---|
| 2780 | return (8); |
|---|
| 2781 | } |
|---|
| 2782 | |
|---|
| 2783 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2784 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2785 | # $_[1]: Address |
|---|
| 2786 | # Returns: undef if not detected, (8) if detected. |
|---|
| 2787 | # Registers used: |
|---|
| 2788 | # 0x00-0x02: Identification ('S','C','Y') |
|---|
| 2789 | sub fscscy_detect |
|---|
| 2790 | { |
|---|
| 2791 | my ($file,$addr) = @_; |
|---|
| 2792 | # check the first 3 registers |
|---|
| 2793 | if (i2c_smbus_read_byte_data($file,0x00) != 0x53) { |
|---|
| 2794 | return; |
|---|
| 2795 | } |
|---|
| 2796 | if (i2c_smbus_read_byte_data($file,0x01) != 0x43) { |
|---|
| 2797 | return; |
|---|
| 2798 | } |
|---|
| 2799 | if (i2c_smbus_read_byte_data($file,0x02) != 0x59) { |
|---|
| 2800 | return; |
|---|
| 2801 | } |
|---|
| 2802 | return (8); |
|---|
| 2803 | } |
|---|
| 2804 | |
|---|
| 2805 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2806 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2807 | # $_[1]: Address |
|---|
| 2808 | # Returns: 1 |
|---|
| 2809 | # Detection is impossible... |
|---|
| 2810 | sub pcf8591_detect |
|---|
| 2811 | { |
|---|
| 2812 | return (1); |
|---|
| 2813 | } |
|---|
| 2814 | |
|---|
| 2815 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2816 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2817 | # $_[1]: Address |
|---|
| 2818 | # Returns: 1 |
|---|
| 2819 | # This is a placeholder so we get a report if any device responds |
|---|
| 2820 | # to the SMBus Device Default Address (0x61), which is used for |
|---|
| 2821 | # ARP in SMBus 2.0. |
|---|
| 2822 | sub arp_detect |
|---|
| 2823 | { |
|---|
| 2824 | return (1); |
|---|
| 2825 | } |
|---|
| 2826 | |
|---|
| 2827 | # $_[0]: A reference to the file descriptor to access this chip. |
|---|
| 2828 | # We may assume an i2c_set_slave_addr was already done. |
|---|
| 2829 | # $_[1]: Address |
|---|
| 2830 | # Returns: 1 |
|---|
| 2831 | sub smartbatt_detect |
|---|
| 2832 | { |
|---|
| 2833 | my ($file,$addr) = @_; |
|---|
| 2834 | # check some registers |
|---|
| 2835 | if (i2c_smbus_read_byte_data($file,0x08) == 0xff) { |
|---|
| 2836 | return; |
|---|
| 2837 | } |
|---|
| 2838 | if (i2c_smbus_read_byte_data($file,0x09) != 0xff) { |
|---|
| 2839 | return; |
|---|
| 2840 | } |
|---|
| 2841 | if (i2c_smbus_read_byte_data($file,0x0a) != 0xff) { |
|---|
| 2842 | return; |
|---|
| 2843 | } |
|---|
| 2844 | return (3); |
|---|
| 2845 | } |
|---|
| 2846 | |
|---|
| 2847 | # Returns: 4 |
|---|
| 2848 | # These are simple detectors that only look for a register at the |
|---|
| 2849 | # standard location. No writes are performed. |
|---|
| 2850 | # For KCS, use the STATUS register. For SMIC, use the FLAGS register. |
|---|
| 2851 | sub ipmi_kcs_detect |
|---|
| 2852 | { |
|---|
| 2853 | return if inb (0x0ca3) == 0xff; |
|---|
| 2854 | return (4); |
|---|
| 2855 | } |
|---|
| 2856 | |
|---|
| 2857 | sub ipmi_smic_detect |
|---|
| 2858 | { |
|---|
| 2859 | return if inb (0x0cab) == 0xff; |
|---|
| 2860 | return (4); |
|---|
| 2861 | } |
|---|
| 2862 | |
|---|
| 2863 | |
|---|
| 2864 | |
|---|
| 2865 | ################ |
|---|
| 2866 | # MAIN PROGRAM # |
|---|
| 2867 | ################ |
|---|
| 2868 | |
|---|
| 2869 | # $_[0]: reference to a list of chip hashes |
|---|
| 2870 | sub print_chips_report |
|---|
| 2871 | { |
|---|
| 2872 | my ($listref) = @_; |
|---|
| 2873 | my $data; |
|---|
| 2874 | |
|---|
| 2875 | foreach $data (@$listref) { |
|---|
| 2876 | my $is_i2c = exists $data->{i2c_addr}; |
|---|
| 2877 | my $is_isa = exists $data->{isa_addr}; |
|---|
| 2878 | print " * "; |
|---|
| 2879 | if ($is_i2c) { |
|---|
| 2880 | printf "Bus `%s' (%s)\n", $data->{i2c_adap}, $data->{i2c_algo}; |
|---|
| 2881 | printf " Busdriver `%s', I2C address 0x%02x", |
|---|
| 2882 | $data->{i2c_driver}, $data->{i2c_addr}; |
|---|
| 2883 | if (exists $data->{i2c_sub_addrs}) { |
|---|
| 2884 | print " (and"; |
|---|
| 2885 | my $sub_addr; |
|---|
| 2886 | foreach $sub_addr (@{$data->{i2c_sub_addrs}}) { |
|---|
| 2887 | printf " 0x%02x",$sub_addr; |
|---|
| 2888 | } |
|---|
| 2889 | print ")" |
|---|
| 2890 | } |
|---|
| 2891 | print "\n"; |
|---|
| 2892 | } |
|---|
| 2893 | if ($is_isa) { |
|---|
| 2894 | print " " if $is_i2c; |
|---|
| 2895 | if ($data->{isa_addr}) { |
|---|
| 2896 | printf "ISA bus address 0x%04x (Busdriver `i2c-isa')\n", |
|---|
| 2897 | $data->{isa_addr}; |
|---|
| 2898 | } else { |
|---|
| 2899 | printf "ISA bus, undetermined address (Busdriver `i2c-isa')\n" |
|---|
| 2900 | } |
|---|
| 2901 | } |
|---|
| 2902 | printf " Chip `%s' (confidence: %d)\n", |
|---|
| 2903 | $data->{chipname}, $data->{conf}; |
|---|
| 2904 | } |
|---|
| 2905 | } |
|---|
| 2906 | |
|---|
| 2907 | # $_[0]: 1 if ISA bus is prefered, 0 for SMBus |
|---|
| 2908 | # We build here an array adapters, indexed on the number the adapter has |
|---|
| 2909 | # at this moment (we assume only loaded adapters are interesting at all; |
|---|
| 2910 | # everything that got scanned also got loaded). Each entry is a reference |
|---|
| 2911 | # to a hash containing: |
|---|
| 2912 | # driver: Name of the adapter driver |
|---|
| 2913 | # nr_now: Number of the bus now |
|---|
| 2914 | # nr_later: Number of the bus when the modprobes are done (not included if the |
|---|
| 2915 | # driver should not be loaded) |
|---|
| 2916 | # A second array, called |
|---|
| 2917 | sub generate_modprobes |
|---|
| 2918 | { |
|---|
| 2919 | my ($prefer_isa) = @_; |
|---|
| 2920 | |
|---|
| 2921 | my ($chip,$detection,$nr,$i,@optionlist,@probelist,$driver,$isa,$adap); |
|---|
| 2922 | my @adapters; |
|---|
| 2923 | my $modprobes = ""; |
|---|
| 2924 | my $configfile = ""; |
|---|
| 2925 | |
|---|
| 2926 | # These are always needed |
|---|
| 2927 | $configfile .= "# I2C module options\n"; |
|---|
| 2928 | $configfile .= "alias char-major-89 i2c-dev\n"; |
|---|
| 2929 | |
|---|
| 2930 | # Collect all loaded adapters |
|---|
| 2931 | open INPUTFILE,"/proc/bus/i2c" or die "Couldn't open /proc/bus/i2c?!?"; |
|---|
| 2932 | while (<INPUTFILE>) { |
|---|
| 2933 | my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/; |
|---|
| 2934 | next if ($type eq "dummy"); |
|---|
| 2935 | $adapters[$dev_nr]->{driver} = find_adapter_driver($adap,$algo); |
|---|
| 2936 | $adapters[$dev_nr]->{adapname} = $adap; |
|---|
| 2937 | $adapters[$dev_nr]->{algoname} = $algo; |
|---|
| 2938 | } |
|---|
| 2939 | close INPUTFILE; |
|---|
| 2940 | |
|---|
| 2941 | # Collect all adapters used |
|---|
| 2942 | $nr = 0; |
|---|
| 2943 | $isa = 0; |
|---|
| 2944 | $modprobes .= "# I2C adapter drivers\n"; |
|---|
| 2945 | foreach $chip (@chips_detected) { |
|---|
| 2946 | foreach $detection (@{$chip->{detected}}) { |
|---|
| 2947 | # If there is more than one bus detected by a driver, they are |
|---|
| 2948 | # still all added. So we number them in the correct order |
|---|
| 2949 | if (exists $detection->{i2c_driver} and |
|---|
| 2950 | not exists $adapters[$detection->{i2c_devnr}]->{nr_later} and |
|---|
| 2951 | not (exists $detection->{isa_addr} and $prefer_isa)) { |
|---|
| 2952 | foreach $adap (@adapters) { |
|---|
| 2953 | $adap->{nr_later} = $nr++ if $adap->{driver} eq $detection->{i2c_driver}; |
|---|
| 2954 | } |
|---|
| 2955 | } |
|---|
| 2956 | if (exists $detection->{isa_addr} and |
|---|
| 2957 | not (exists $detection->{i2c_driver} and not $prefer_isa)) { |
|---|
| 2958 | $isa=1; |
|---|
| 2959 | } |
|---|
| 2960 | } |
|---|
| 2961 | } |
|---|
| 2962 | |
|---|
| 2963 | for ($i = 0; $i < $nr; $i++) { |
|---|
| 2964 | foreach $adap (@adapters) { |
|---|
| 2965 | if ($adap->{driver} eq "UNKNOWN") { |
|---|
| 2966 | $modprobes .= "# modprobe unknown adapter ".$adap->{adapname}." using ". $adap->{algoname}."\n"; |
|---|
| 2967 | } else { |
|---|
| 2968 | $modprobes .= "modprobe $adap->{driver}\n" if (defined($adap->{nr_later}) and $adap->{nr_later} == $i) and not $modprobes =~ /modprobe $adap->{driver}\n/; |
|---|
| 2969 | } |
|---|
| 2970 | } |
|---|
| 2971 | } |
|---|
| 2972 | $modprobes .= "modprobe i2c-isa\n" if ($isa); |
|---|
| 2973 | |
|---|
| 2974 | # Now determine the chip probe lines |
|---|
| 2975 | $modprobes .= "# I2C chip drivers\n"; |
|---|
| 2976 | foreach $chip (@chips_detected) { |
|---|
| 2977 | next if not @{$chip->{detected}}; |
|---|
| 2978 | $modprobes .= "modprobe $chip->{driver}\n"; |
|---|
| 2979 | @optionlist = (); |
|---|
| 2980 | @probelist = (); |
|---|
| 2981 | |
|---|
| 2982 | # Handle detects at addresses normally not probed |
|---|
| 2983 | foreach $detection (@{$chip->{detected}}) { |
|---|
| 2984 | push @probelist, $adapters[$detection->{i2c_devnr}]->{nr_later}, |
|---|
| 2985 | $detection->{i2c_addr} |
|---|
| 2986 | if exists $detection->{i2c_addr} and |
|---|
| 2987 | exists $detection->{i2c_extra}; |
|---|
| 2988 | push @probelist, -1, $detection->{isa_addr} |
|---|
| 2989 | if exists $detection->{isa_addr} and |
|---|
| 2990 | exists $detection->{isa_extra}; |
|---|
| 2991 | } |
|---|
| 2992 | |
|---|
| 2993 | # Handle misdetects |
|---|
| 2994 | foreach $detection (@{$chip->{misdetected}}) { |
|---|
| 2995 | push @optionlist, $adapters[$detection->{i2c_devnr}]->{nr_later}, |
|---|
| 2996 | $detection->{i2c_addr} |
|---|
| 2997 | if exists $detection->{i2c_addr} and |
|---|
| 2998 | exists $adapters[$detection->{i2c_devnr}]->{nr_later}; |
|---|
| 2999 | push @optionlist, -1, $detection->{isa_addr} |
|---|
| 3000 | if exists $detection->{isa_addr} and $isa; |
|---|
| 3001 | } |
|---|
| 3002 | |
|---|
| 3003 | # Handle aliases |
|---|
| 3004 | foreach $detection (@{$chip->{detected}}) { |
|---|
| 3005 | if (exists $detection->{i2c_driver} and |
|---|
| 3006 | exists $detection->{isa_addr} and |
|---|
| 3007 | exists $adapters[$detection->{i2c_devnr}]->{nr_later} and |
|---|
| 3008 | $isa) { |
|---|
| 3009 | if ($prefer_isa) { |
|---|
| 3010 | push @optionlist,$adapters[$detection->{i2c_devnr}]->{nr_later}, |
|---|
| 3011 | $detection->{i2c_addr}; |
|---|
| 3012 | } else { |
|---|
| 3013 | push @optionlist, -1, $detection->{isa_addr} |
|---|
| 3014 | } |
|---|
| 3015 | } |
|---|
| 3016 | } |
|---|
| 3017 | |
|---|
| 3018 | next if not (@probelist or @optionlist); |
|---|
| 3019 | $configfile .= "options $chip->{driver}"; |
|---|
| 3020 | $configfile .= sprintf " ignore=%d,0x%02x",shift @optionlist, |
|---|
| 3021 | shift @optionlist |
|---|
| 3022 | if @optionlist; |
|---|
| 3023 | $configfile .= sprintf ",%d,0x%02x",shift @optionlist, shift @optionlist |
|---|
| 3024 | while @optionlist; |
|---|
| 3025 | $configfile .= sprintf " probe=%d,0x%02x",shift @probelist, |
|---|
| 3026 | shift @probelist |
|---|
| 3027 | if @probelist; |
|---|
| 3028 | $configfile .= sprintf ",%d,0x%02x",shift @probelist, shift @probelist |
|---|
| 3029 | while @probelist; |
|---|
| 3030 | $configfile .= "\n"; |
|---|
| 3031 | } |
|---|
| 3032 | |
|---|
| 3033 | return ($modprobes,$configfile); |
|---|
| 3034 | |
|---|
| 3035 | } |
|---|
| 3036 | |
|---|
| 3037 | # returns: |
|---|
| 3038 | # system id string (e.g. 'IBM'), unsafe system |
|---|
| 3039 | # '1', safe system |
|---|
| 3040 | # 0, could not determine |
|---|
| 3041 | sub system_safeness_by_dmi |
|---|
| 3042 | { |
|---|
| 3043 | my $opened = 0; |
|---|
| 3044 | foreach my $dmidecode (@dmidecode) |
|---|
| 3045 | { |
|---|
| 3046 | last if (-r $dmidecode && ($opened = open (DMI, "$dmidecode |"))); |
|---|
| 3047 | } |
|---|
| 3048 | |
|---|
| 3049 | unless ($opened) |
|---|
| 3050 | { |
|---|
| 3051 | print " Could not find dmidecode, which should have been installed with lm_sensors.\n", |
|---|
| 3052 | " Runing dmidecode would help us determining your system vendor, which allows\n", |
|---|
| 3053 | " safer operations. Please provide one of the following:\n "; |
|---|
| 3054 | print join ("\n ", @dmidecode); |
|---|
| 3055 | print "\n You can still go on, but you are encouraged to fix the problem first.\n\n"; |
|---|
| 3056 | return 0; |
|---|
| 3057 | } |
|---|
| 3058 | |
|---|
| 3059 | my ($dmitype, $biosversion, $systemvendor); |
|---|
| 3060 | while (<DMI>) |
|---|
| 3061 | { |
|---|
| 3062 | if (m/^\s*DMI type (\d+),/) |
|---|
| 3063 | { |
|---|
| 3064 | $dmitype = $1; |
|---|
| 3065 | next; |
|---|
| 3066 | } |
|---|
| 3067 | next unless defined $dmitype; |
|---|
| 3068 | if ($dmitype == 1 && m/^\s*Vendor: (.*)$/) |
|---|
| 3069 | { |
|---|
| 3070 | $systemvendor = $1; |
|---|
| 3071 | } |
|---|
| 3072 | elsif ($dmitype == 0 && m/^\s*Version: (.*)$/) |
|---|
| 3073 | { |
|---|
| 3074 | $biosversion = $1; |
|---|
| 3075 | } |
|---|
| 3076 | last if (defined $biosversion && defined $systemvendor); |
|---|
| 3077 | } |
|---|
| 3078 | close (DMI); |
|---|
| 3079 | |
|---|
| 3080 | if (defined $systemvendor && $systemvendor !~ m/^\s*$/) |
|---|
| 3081 | { |
|---|
| 3082 | $systemvendor =~ s/\s*$//; |
|---|
| 3083 | print " System vendor (DMI): $systemvendor\n"; |
|---|
| 3084 | if (defined $biosversion && $biosversion !~ m/^\s*$/) |
|---|
| 3085 | { |
|---|
| 3086 | $biosversion =~ s/\s*$//; |
|---|
| 3087 | print " BIOS version (DMI): $biosversion\n"; |
|---|
| 3088 | } |
|---|
| 3089 | return 'IBM' if $systemvendor =~ /\bIBM\b/; |
|---|
| 3090 | return '1'; |
|---|
| 3091 | } |
|---|
| 3092 | |
|---|
| 3093 | return undef; |
|---|
| 3094 | } |
|---|
| 3095 | |
|---|
| 3096 | # returns: |
|---|
| 3097 | # system id string (e.g. 'IBM'), unsafe system |
|---|
| 3098 | # '1', safe system |
|---|
| 3099 | # 0, could not determine |
|---|
| 3100 | sub system_safeness_by_acpi |
|---|
| 3101 | { |
|---|
| 3102 | my $pos = 0xF0000; |
|---|
| 3103 | my $found = 0; |
|---|
| 3104 | my $oem = ''; |
|---|
| 3105 | |
|---|
| 3106 | return 0 |
|---|
| 3107 | unless open MEM, '/dev/mem'; |
|---|
| 3108 | binmode MEM; |
|---|
| 3109 | unless (seek MEM, $pos, SEEK_SET) |
|---|
| 3110 | { |
|---|
| 3111 | close MEM; |
|---|
| 3112 | return 0; |
|---|
| 3113 | } |
|---|
| 3114 | while ($pos <= 0xFFFF0 && !$found) |
|---|
| 3115 | { |
|---|
| 3116 | my $r = read (MEM, my $buf, 16); |
|---|
| 3117 | unless ($r == 16) |
|---|
| 3118 | { |
|---|
| 3119 | close MEM; |
|---|
| 3120 | return 0; |
|---|
| 3121 | } |
|---|
| 3122 | if (substr ($buf, 0, 8) eq 'RSD PTR ') |
|---|
| 3123 | { |
|---|
| 3124 | $oem = substr ($buf, 9, 6); |
|---|
| 3125 | $found++; |
|---|
| 3126 | } |
|---|
| 3127 | $pos += 16; |
|---|
| 3128 | } |
|---|
| 3129 | close MEM; |
|---|
| 3130 | |
|---|
| 3131 | return 0 unless $found; |
|---|
| 3132 | print " BIOS vendor (ACPI): $oem\n"; |
|---|
| 3133 | return 'IBM' if $oem eq 'IBM '; |
|---|
| 3134 | return '1'; |
|---|
| 3135 | } |
|---|
| 3136 | |
|---|
| 3137 | # returns: |
|---|
| 3138 | # 1 : the system is known to be safe |
|---|
| 3139 | # 0 : the system safeness is unknown |
|---|
| 3140 | # If the system is know to be unsafe (i.e. for now, IBM systems), never |
|---|
| 3141 | # return. |
|---|
| 3142 | sub safe_system_vendor |
|---|
| 3143 | { |
|---|
| 3144 | if ($> != 0) |
|---|
| 3145 | { |
|---|
| 3146 | print " As you are not root, we can't determine your system vendor.\n"; |
|---|
| 3147 | return 0; |
|---|
| 3148 | } |
|---|
| 3149 | |
|---|
| 3150 | # We now have two methods for detecting IBM systems: ACPI and DMI. |
|---|
| 3151 | # The ACPI scan is easy and handled internally. The DMI scan, being more |
|---|
| 3152 | # complex, is handled by dmidecode, externally. Each method can return |
|---|
| 3153 | # three status: |
|---|
| 3154 | # * the system is known to be safe (returns '1'); |
|---|
| 3155 | # * the system is known to be unsafe (returns a string that identifies |
|---|
| 3156 | # the system, e.g. 'IBM'); |
|---|
| 3157 | # * the method doesn't permit to detect wether the system is safe |
|---|
| 3158 | # (returns 0). |
|---|
| 3159 | # We then combine both results to come to a conclusion. The rules we |
|---|
| 3160 | # follow are (in order): |
|---|
| 3161 | # * if both methods return 0, we can't say anything and return 0 (meaning |
|---|
| 3162 | # "system safeness is unknown"); |
|---|
| 3163 | # * else, if no method returns an identifier string (that is, each method |
|---|
| 3164 | # returns either 0 or '1'), we assume that the system is safe and |
|---|
| 3165 | # return 1 (meaning "system is safe"); |
|---|
| 3166 | # * else display an alert message and exit; if only one of the methods |
|---|
| 3167 | # worked, ask the user to be kind and send us a report. |
|---|
| 3168 | |
|---|
| 3169 | my $safeness_acpi = system_safeness_by_acpi(); |
|---|
| 3170 | my $safeness_dmi = system_safeness_by_dmi(); |
|---|
| 3171 | |
|---|
| 3172 | return 0 |
|---|
| 3173 | unless ($safeness_acpi || $safeness_dmi); |
|---|
| 3174 | |
|---|
| 3175 | return 1 |
|---|
| 3176 | if ((!$safeness_acpi || $safeness_acpi eq '1') |
|---|
| 3177 | && (!$safeness_dmi || $safeness_dmi eq '1')); |
|---|
| 3178 | |
|---|
| 3179 | my $safeness = (!$safeness_acpi || $safeness_acpi eq '1')? |
|---|
| 3180 | $safeness_dmi:$safeness_acpi; |
|---|
| 3181 | |
|---|
| 3182 | print " Sorry, we won't let you go on. $safeness systems are known to have\n", |
|---|
| 3183 | " serious problems with lm_sensors, resulting in hardware failures.\n", |
|---|
| 3184 | " For more information, see README.thinkpad or\n", |
|---|
| 3185 | " http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/README.thinkpad.\n"; |
|---|
| 3186 | |
|---|
| 3187 | if($safeness_acpi eq '1' || $safeness_dmi eq '1') |
|---|
| 3188 | { |
|---|
| 3189 | print " We used two methods to determine your system's vendor, and they led\n", |
|---|
| 3190 | " to different results. We'd appreciate to have feedback about such\n", |
|---|
| 3191 | " systems. Please, take some time and contact the lm_sensors mailing\n", |
|---|
| 3192 | " list at <sensors\@stimpy.netroedge.com>.\n", |
|---|
| 3193 | " We need the following information:\n", |
|---|
| 3194 | " * The brand and model of your system\n", |
|---|
| 3195 | " * The BIOS vendor (ACPI) displayed above\n", |
|---|
| 3196 | " * The System vendor (DMI) displayed above\n", |
|---|
| 3197 | " Thanks!\n"; |
|---|
| 3198 | } |
|---|
| 3199 | |
|---|
| 3200 | exit; |
|---|
| 3201 | } |
|---|
| 3202 | |
|---|
| 3203 | sub main |
|---|
| 3204 | { |
|---|
| 3205 | my (@adapters,$res,$did_adapter_detection,$detect_others,$adapter); |
|---|
| 3206 | |
|---|
| 3207 | initialize_proc_pci; |
|---|
| 3208 | initialize_modules_list; |
|---|
| 3209 | |
|---|
| 3210 | print " This program will help you to determine which I2C/SMBus modules you ", |
|---|
| 3211 | "need to\n", |
|---|
| 3212 | " load to use lm_sensors most effectively.\n"; |
|---|
| 3213 | print " You need to have done a `make install', issued a `depmod -a' and ", |
|---|
| 3214 | "made sure\n", |
|---|
| 3215 | " `/etc/conf.modules' (or `/etc/modules.conf') contains the ", |
|---|
| 3216 | "appropriate\n", |
|---|
| 3217 | " module path before you can use some functions of this utility. ", |
|---|
| 3218 | "Read\n", |
|---|
| 3219 | " doc/modules for more information.\n"; |
|---|
| 3220 | print " Also, you need to be `root', or at least have access to the ", |
|---|
| 3221 | "/dev/i2c[-/]* files\n", |
|---|
| 3222 | " for some things. You can use prog/mkdev/mkdev.sh to create these ", |
|---|
| 3223 | "/dev files\n", |
|---|
| 3224 | " if you do not have them already.\n"; |
|---|
| 3225 | print " If you have patched your kernel and have some drivers built-in ", |
|---|
| 3226 | "you can\n", |
|---|
| 3227 | " safely answer NO if asked to load some modules. In this case, ", |
|---|
| 3228 | "things may\n", |
|---|
| 3229 | " seem a bit confusing, but they will still work.\n\n"; |
|---|
| 3230 | |
|---|
| 3231 | unless (safe_system_vendor ()) |
|---|
| 3232 | { |
|---|
| 3233 | print " IF THIS IS AN IBM THINKPAD, PRESS CTRL-C NOW!\n"; |
|---|
| 3234 | print " IBM Thinkpads have a severely broken i2c/SMBus implementation, "; |
|---|
| 3235 | print "just scanning\n"; |
|---|
| 3236 | print " the bus will break your Thinkpad forever!\n"; |
|---|
| 3237 | print " If this is a non-Thinkpad IBM, we still suggest you press CTRL+C. We have\n"; |
|---|
| 3238 | print " had users reporting system breakage on other IBM systems as well.\n\n"; |
|---|
| 3239 | } |
|---|
| 3240 | |
|---|
| 3241 | print " We can start with probing for (PCI) I2C or SMBus adapters.\n"; |
|---|
| 3242 | print " You do not need any special privileges for this.\n"; |
|---|
| 3243 | print " Do you want to probe now? (YES/no): "; |
|---|
| 3244 | @adapters = adapter_pci_detection |
|---|
| 3245 | if ($did_adapter_detection = not <STDIN> =~ /\s*[Nn]/); |
|---|
| 3246 | |
|---|
| 3247 | print "\n"; |
|---|
| 3248 | |
|---|
| 3249 | if (not $did_adapter_detection) { |
|---|
| 3250 | print " As you skipped adapter detection, we will only scan already ", |
|---|
| 3251 | "loaded adapter\n", |
|---|
| 3252 | " modules. You can still be prompted for non-detectable adapters.\n", |
|---|
| 3253 | " Do you want to? (yes/NO): "; |
|---|
| 3254 | $detect_others = <STDIN> =~ /^\s*[Yy]/; |
|---|
| 3255 | } elsif ($> != 0) { |
|---|
| 3256 | print " As you are not root, we can't load adapter modules. We will only ", |
|---|
| 3257 | "scan\n", |
|---|
| 3258 | " already loaded adapters.\n"; |
|---|
| 3259 | $detect_others = 0; |
|---|
| 3260 | } else { |
|---|
| 3261 | print " We will now try to load each adapter module in turn.\n"; |
|---|
| 3262 | foreach $adapter (@adapters) { |
|---|
| 3263 | if (contains $adapter, @modules_list) { |
|---|
| 3264 | print "Module `$adapter' already loaded.\n"; |
|---|
| 3265 | } else { |
|---|
| 3266 | print "Load `$adapter' (say NO if built into your kernel)? (YES/no): "; |
|---|
| 3267 | unless (<STDIN> =~ /^\s*[Nn]/) { |
|---|
| 3268 | if (system ("modprobe", $adapter)) { |
|---|
| 3269 | print "Loading failed... skipping.\n"; |
|---|
| 3270 | if ($adapter eq "i2c-riva") { |
|---|
| 3271 | print "** Note: i2c-riva module is available at \n"; |
|---|
| 3272 | print "** http://drama.obuda.kando.hu/~fero/cgi-bin/rivatv.shtml\n"; |
|---|
| 3273 | } |
|---|
| 3274 | } else { |
|---|
| 3275 | print "Module loaded succesfully.\n"; |
|---|
| 3276 | } |
|---|
| 3277 | } |
|---|
| 3278 | } |
|---|
| 3279 | } |
|---|
| 3280 | print " Do you now want to be prompted for non-detectable adapters? ", |
|---|
| 3281 | "(yes/NO): "; |
|---|
| 3282 | $detect_others = <STDIN> =~ /^\s*[Yy]/ ; |
|---|
| 3283 | } |
|---|
| 3284 | |
|---|
| 3285 | if ($detect_others) { |
|---|
| 3286 | foreach $adapter (@undetectable_adapters) { |
|---|
| 3287 | print "Load `$adapter' (say NO if built into your kernel)? (YES/no): "; |
|---|
| 3288 | unless (<STDIN> =~ /^\s*[Nn]/) { |
|---|
| 3289 | if (system ("modprobe", $adapter)) { |
|---|
| 3290 | print "Loading failed... skipping.\n"; |
|---|
| 3291 | } else { |
|---|
| 3292 | print "Module loaded succesfully.\n"; |
|---|
| 3293 | } |
|---|
| 3294 | } |
|---|
| 3295 | } |
|---|
| 3296 | } |
|---|
| 3297 | |
|---|
| 3298 | print " To continue, we need module `i2c-dev' to be loaded.\n"; |
|---|
| 3299 | print " If it is built-in into your kernel, you can safely skip this.\n"; |
|---|
| 3300 | if (contains "i2c-dev", @modules_list) { |
|---|
| 3301 | print "i2c-dev is already loaded.\n"; |
|---|
| 3302 | } else { |
|---|
| 3303 | if ($> != 0) { |
|---|
| 3304 | print " i2c-dev is not loaded. As you are not root, we will just hope ", |
|---|
| 3305 | "you edited\n", |
|---|
| 3306 | " `/etc/conf.modules' (or `/etc/modules.conf') for automatic ", |
|---|
| 3307 | "loading of\n", |
|---|
| 3308 | " this module. If not, you won't be able to open any /dev/i2c[-/]* ", |
|---|
| 3309 | "file.\n"; |
|---|
| 3310 | } else { |
|---|
| 3311 | print " i2c-dev is not loaded. Do you want to load it now? (YES/no): "; |
|---|
| 3312 | if (<STDIN> =~ /^\s*[Nn]/) { |
|---|
| 3313 | print " Well, you will know best. We will just hope you edited ", |
|---|
| 3314 | "`/etc/conf.modules'\n", |
|---|
| 3315 | " (or `/etc/modules.conf') for automatic loading of this ", |
|---|
| 3316 | "module. If not,\n", |
|---|
| 3317 | " you won't be able to open any /dev/i2c[-/]* file (unless you", |
|---|
| 3318 | "have it built-in\n", |
|---|
| 3319 | " into your kernel)\n"; |
|---|
| 3320 | } elsif (system "modprobe","i2c-dev") { |
|---|
| 3321 | print " Loading failed, expect problems later on.\n"; |
|---|
| 3322 | } else { |
|---|
| 3323 | print " Module loaded succesfully.\n"; |
|---|
| 3324 | } |
|---|
| 3325 | } |
|---|
| 3326 | } |
|---|
| 3327 | |
|---|
| 3328 | print "\n We are now going to do the adapter probings. Some adapters may ", |
|---|
| 3329 | "hang halfway\n", |
|---|
| 3330 | " through; we can't really help that. Also, some chips will be double ", |
|---|
| 3331 | "detected;\n", |
|---|
| 3332 | " we choose the one with the highest confidence value in that case.\n", |
|---|
| 3333 | " If you found that the adapter hung after probing a certain address, ", |
|---|
| 3334 | "you can\n", |
|---|
| 3335 | " specify that address to remain unprobed. That ", |
|---|
| 3336 | "often\n", |
|---|
| 3337 | " includes address 0x69 (clock chip).\n"; |
|---|
| 3338 | |
|---|
| 3339 | my ($inp,@not_to_scan,$inp2); |
|---|
| 3340 | open INPUTFILE,"/proc/bus/i2c" or die "Couldn't open /proc/bus/i2c?!?"; |
|---|
| 3341 | while (<INPUTFILE>) { |
|---|
| 3342 | my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/; |
|---|
| 3343 | next if ($type eq "dummy"); |
|---|
| 3344 | print "\n"; |
|---|
| 3345 | print "Next adapter: $adap ($algo)\n"; |
|---|
| 3346 | print "Do you want to scan it? (YES/no/selectively): "; |
|---|
| 3347 | |
|---|
| 3348 | $inp = <STDIN>; |
|---|
| 3349 | @not_to_scan=(); |
|---|
| 3350 | if ($inp =~ /^\s*[Ss]/) { |
|---|
| 3351 | print "Please enter one or more addresses not to scan. Separate them ", |
|---|
| 3352 | "with comma's.\n", |
|---|
| 3353 | "You can specify a range by using dashes. Addresses may be ", |
|---|
| 3354 | "decimal (like 54)\n", |
|---|
| 3355 | "or hexadecimal (like 0x33).\n", |
|---|
| 3356 | "Addresses: "; |
|---|
| 3357 | $inp2 = <STDIN>; |
|---|
| 3358 | chop $inp2; |
|---|
| 3359 | @not_to_scan = parse_not_to_scan 0,0x7f,$inp2; |
|---|
| 3360 | } |
|---|
| 3361 | scan_adapter $dev_nr, $adap, $algo, find_adapter_driver($adap,$algo), |
|---|
| 3362 | \@not_to_scan unless $inp =~ /^\s*[Nn]/; |
|---|
| 3363 | } |
|---|
| 3364 | |
|---|
| 3365 | print "\n Some chips are also accessible through the ISA bus. ISA probes ", |
|---|
| 3366 | "are\n", |
|---|
| 3367 | " typically a bit more dangerous, as we have to write to I/O ports ", |
|---|
| 3368 | "to do\n", |
|---|
| 3369 | " this. "; |
|---|
| 3370 | if ($> != 0) { |
|---|
| 3371 | print "As you are not root, we shall skip this step.\n"; |
|---|
| 3372 | } else { |
|---|
| 3373 | print " Do you want to scan the ISA bus? (YES/no): "; |
|---|
| 3374 | if (not <STDIN> =~ /^\s*[Nn]/) { |
|---|
| 3375 | initialize_ioports or die "Sorry, can't access /dev/port ($!)?!?"; |
|---|
| 3376 | scan_isa_bus; |
|---|
| 3377 | } |
|---|
| 3378 | } |
|---|
| 3379 | |
|---|
| 3380 | print "\n Some Super I/O chips may also contain sensors. Super I/O probes ", |
|---|
| 3381 | "are\n", |
|---|
| 3382 | " typically a bit more dangerous, as we have to write to I/O ports ", |
|---|
| 3383 | "to do\n", |
|---|
| 3384 | " this. "; |
|---|
| 3385 | if ($> != 0) { |
|---|
| 3386 | print "As you are not root, we shall skip this step.\n"; |
|---|
| 3387 | } else { |
|---|
| 3388 | print " Do you want to scan for Super I/O sensors? (YES/no): "; |
|---|
| 3389 | if (not <STDIN> =~ /^\s*[Nn]/) { |
|---|
| 3390 | initialize_ioports or die "Sorry, can't access /dev/port ($!)?!?"; |
|---|
| 3391 | scan_superio; |
|---|
| 3392 | } |
|---|
| 3393 | } |
|---|
| 3394 | |
|---|
| 3395 | if(! @chips_detected) { |
|---|
| 3396 | print "\n Sorry, no chips were detected.\n", |
|---|
| 3397 | " Either your sensors are not supported, or they are\n", |
|---|
| 3398 | " connected to an I2C bus adapter that we do not support.\n", |
|---|
| 3399 | " See doc/FAQ, doc/lm_sensors-FAQ.html, or\n", |
|---|
| 3400 | " http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/doc/lm_sensors-FAQ.html\n", |
|---|
| 3401 | " (FAQ #4.24.3) for further information.\n", |
|---|
| 3402 | " If you find out what chips are on your board, see\n", |
|---|
| 3403 | " http://secure.netroedge.com/~lm78/newdrivers.html for driver status.\n"; |
|---|
| 3404 | exit; |
|---|
| 3405 | } |
|---|
| 3406 | |
|---|
| 3407 | print "\n Now follows a summary of the probes I have just done.\n"; |
|---|
| 3408 | print " Just press ENTER to continue: "; |
|---|
| 3409 | <STDIN>; |
|---|
| 3410 | |
|---|
| 3411 | my ($chip,$data); |
|---|
| 3412 | foreach $chip (@chips_detected) { |
|---|
| 3413 | print "\nDriver `$$chip{driver}' "; |
|---|
| 3414 | if (@{$$chip{detected}}) { |
|---|
| 3415 | if (@{$$chip{misdetected}}) { |
|---|
| 3416 | print "(should be inserted but causes problems):\n"; |
|---|
| 3417 | } else { |
|---|
| 3418 | print "(should be inserted):\n"; |
|---|
| 3419 | } |
|---|
| 3420 | } else { |
|---|
| 3421 | if (@{$$chip{misdetected}}) { |
|---|
| 3422 | print "(may not be inserted):\n"; |
|---|
| 3423 | } else { |
|---|
| 3424 | print "(should not be inserted, but is harmless):\n"; |
|---|
| 3425 | } |
|---|
| 3426 | } |
|---|
| 3427 | if (@{$$chip{detected}}) { |
|---|
| 3428 | print " Detects correctly:\n"; |
|---|
| 3429 | print_chips_report $chip->{detected}; |
|---|
| 3430 | } |
|---|
| 3431 | if (@{$$chip{misdetected}}) { |
|---|
| 3432 | print " Misdetects:\n"; |
|---|
| 3433 | print_chips_report $chip->{misdetected}; |
|---|
| 3434 | } |
|---|
| 3435 | } |
|---|
| 3436 | |
|---|
| 3437 | print "\n\n", |
|---|
| 3438 | " I will now generate the commands needed to load the I2C modules.\n", |
|---|
| 3439 | " Sometimes, a chip is available both through the ISA bus and an ", |
|---|
| 3440 | "I2C bus.\n", |
|---|
| 3441 | " ISA bus access is faster, but you need to load an additional driver ", |
|---|
| 3442 | "module\n", |
|---|
| 3443 | " for it. If you have the choice, do you want to use the ISA bus or ", |
|---|
| 3444 | "the\n", |
|---|
| 3445 | " I2C/SMBus (ISA/smbus)? "; |
|---|
| 3446 | my $use_isa = not <STDIN> =~ /\s*[Ss]/; |
|---|
| 3447 | |
|---|
| 3448 | my ($modprobes,$configfile) = generate_modprobes $use_isa; |
|---|
| 3449 | print "\nWARNING! If you have some things built into your kernel, the \n", |
|---|
| 3450 | "below list will contain too many modules. Skip the appropriate ones!"; |
|---|
| 3451 | print "\nTo load everything that is needed, add this to some /etc/rc* ", |
|---|
| 3452 | "file:\n\n"; |
|---|
| 3453 | print "#----cut here----\n"; |
|---|
| 3454 | print $modprobes; |
|---|
| 3455 | print "# Next 2 lines are optional\n", |
|---|
| 3456 | "sleep 3\n", |
|---|
| 3457 | "sensors -s\n"; |
|---|
| 3458 | print "#----cut here----\n"; |
|---|
| 3459 | print "\nTo make the sensors modules behave correctly, add these lines to ", |
|---|
| 3460 | "either\n", |
|---|
| 3461 | "/etc/modules.conf or /etc/conf.modules:\n\n"; |
|---|
| 3462 | print "#----cut here----\n"; |
|---|
| 3463 | print $configfile; |
|---|
| 3464 | print "#----cut here----\n"; |
|---|
| 3465 | |
|---|
| 3466 | my $have_sysconfig = -d '/etc/sysconfig'; |
|---|
| 3467 | print "\nDo you want to generate /etc/sysconfig/lm_sensors? (". |
|---|
| 3468 | ($have_sysconfig?"YES/no":"yes/NO")."): "; |
|---|
| 3469 | if ($> != 0) { |
|---|
| 3470 | print "\nAs you are not root, we shall skip this step.\n"; |
|---|
| 3471 | } else { |
|---|
| 3472 | if (($have_sysconfig and not <STDIN> =~ /^\s*[Nn]/) or <STDIN> =~ /^\s*[Yy]/) { |
|---|
| 3473 | unless ($have_sysconfig) { |
|---|
| 3474 | mkdir '/etc/sysconfig', 0777 |
|---|
| 3475 | or die "Sorry, can't create /etc/sysconfig ($!)?!?"; |
|---|
| 3476 | } |
|---|
| 3477 | open(SYSCONFIG, ">/etc/sysconfig/lm_sensors") |
|---|
| 3478 | or die "Sorry, can't create /etc/sysconfig/lm_sensors ($!)?!?"; |
|---|
| 3479 | print SYSCONFIG <<'EOT'; |
|---|
| 3480 | # /etc/sysconfig/sensors - Defines modules loaded by /etc/rc.d/init.d/lm_sensors |
|---|
| 3481 | # Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl> |
|---|
| 3482 | # |
|---|
| 3483 | # This program is free software; you can redistribute it and/or modify |
|---|
| 3484 | # it under the terms of the GNU General Public License as published by |
|---|
| 3485 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 3486 | # (at your option) any later version. |
|---|
| 3487 | # |
|---|
| 3488 | # This program is distributed in the hope that it will be useful, |
|---|
| 3489 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 3490 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 3491 | # GNU General Public License for more details. |
|---|
| 3492 | # |
|---|
| 3493 | # You should have received a copy of the GNU General Public License |
|---|
| 3494 | # along with this program; if not, write to the Free Software |
|---|
| 3495 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 3496 | # |
|---|
| 3497 | # |
|---|
| 3498 | # See also the lm_sensors homepage at: |
|---|
| 3499 | # http://www2.lm-sensors.nu/~lm78/index.html |
|---|
| 3500 | # |
|---|
| 3501 | # This file is used by /etc/rc.d/init.d/lm_sensors and defines the modules to |
|---|
| 3502 | # be loaded/unloaded. This file is sourced into /etc/rc.d/init.d/lm_sensors. |
|---|
| 3503 | # |
|---|
| 3504 | # The format of this file is a shell script that simply defines the modules |
|---|
| 3505 | # in order as normal variables with the special names: |
|---|
| 3506 | # MODULE_0, MODULE_1, MODULE_2, etc. |
|---|
| 3507 | # |
|---|
| 3508 | # List the modules that are to be loaded for your system |
|---|
| 3509 | # |
|---|
| 3510 | EOT |
|---|
| 3511 | print SYSCONFIG |
|---|
| 3512 | "# Generated by sensors-detect on " . scalar localtime() . "\n"; |
|---|
| 3513 | my @modules = grep /^modprobe /, split "\n", $modprobes; |
|---|
| 3514 | my $i = 0; |
|---|
| 3515 | my $sysconfig = ""; |
|---|
| 3516 | foreach (@modules) { |
|---|
| 3517 | s/^modprobe //; |
|---|
| 3518 | $sysconfig .= "MODULE_$i=$_\n"; |
|---|
| 3519 | $i++; |
|---|
| 3520 | } |
|---|
| 3521 | print SYSCONFIG $sysconfig; |
|---|
| 3522 | close(SYSCONFIG); |
|---|
| 3523 | print "Copy prog/init/lm_sensors.init to /etc/rc.d/init.d/lm_sensors\n"; |
|---|
| 3524 | print "for initialization at boot time.\n"; |
|---|
| 3525 | } |
|---|
| 3526 | } |
|---|
| 3527 | } |
|---|
| 3528 | |
|---|
| 3529 | main; |
|---|