| | 4552 | } |
| | 4553 | |
| | 4554 | # Registers used: |
| | 4555 | # 0x02: Status |
| | 4556 | # 0x0a: Thyst |
| | 4557 | # 0x0b: ID |
| | 4558 | # We also rely on the fact that only the 5 LSB of the address pointer |
| | 4559 | # are considered, so registers cycle over 32 byte boundaries. |
| | 4560 | sub adt7410_detect |
| | 4561 | { |
| | 4562 | my ($file, $addr) = @_; |
| | 4563 | my $status = i2c_smbus_read_byte_data($file, 0x02); |
| | 4564 | my $thyst = i2c_smbus_read_byte_data($file, 0x0a); |
| | 4565 | my $id = i2c_smbus_read_byte_data($file, 0x0b); |
| | 4566 | |
| | 4567 | # Unused bits |
| | 4568 | return if ($status & 0x0f); |
| | 4569 | return if ($thyst & 0xf0); |
| | 4570 | |
| | 4571 | # ID register |
| | 4572 | return if $id != 0xcb; |
| | 4573 | |
| | 4574 | # Cycling registers |
| | 4575 | for (my $i = 2; $i < 16; $i *= 2) { |
| | 4576 | return if i2c_smbus_read_byte_data($file, 0x0a + $i * 16) != $thyst; |
| | 4577 | return if i2c_smbus_read_byte_data($file, 0x0b + $i * 16) != $id; |
| | 4578 | } |
| | 4579 | |
| | 4580 | # Non-existent registers (other devices tend to have ID registers there) |
| | 4581 | return if i2c_smbus_read_byte_data($file, 0x03e) != 0; |
| | 4582 | return if i2c_smbus_read_byte_data($file, 0x03f) != 0; |
| | 4583 | return if i2c_smbus_read_byte_data($file, 0x0fe) != 0; |
| | 4584 | return if i2c_smbus_read_byte_data($file, 0x0ff) != 0; |
| | 4585 | |
| | 4586 | return 3; |