| | 5797 | # Chip to detect: MAX6642 |
| | 5798 | # Registers used: |
| | 5799 | # 0x02: Status register |
| | 5800 | # 0x03: Configuration register |
| | 5801 | # 0xfe: Manufacturer ID |
| | 5802 | # 0x04, 0x06, 0xff: No registers |
| | 5803 | # We use the 0x04, 0x06 and 0xff addresses (unused) to improve reliability. |
| | 5804 | # These are not real registers and will always return the last returned value. |
| | 5805 | # This isn't documented. |
| | 5806 | sub max6642_detect |
| | 5807 | { |
| | 5808 | my ($file, $addr) = @_; |
| | 5809 | my ($man_id, $conf, $status); |
| | 5810 | |
| | 5811 | $man_id = i2c_smbus_read_byte_data($file, 0xfe); |
| | 5812 | return unless $man_id == 0x4d; # Maxim |
| | 5813 | return if i2c_smbus_read_byte_data($file, 0x04, NO_CACHE) != $man_id; |
| | 5814 | return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $man_id; |
| | 5815 | return if i2c_smbus_read_byte_data($file, 0xff, NO_CACHE) != $man_id; |
| | 5816 | |
| | 5817 | $status = i2c_smbus_read_byte_data($file, 0x02); |
| | 5818 | # Bit 5, 3, 1 and 0 should be zero |
| | 5819 | return unless ($status & 0x2b) == 0x00; |
| | 5820 | return if i2c_smbus_read_byte_data($file, 0x04, NO_CACHE) != $status; |
| | 5821 | return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $status; |
| | 5822 | return if i2c_smbus_read_byte_data($file, 0xff, NO_CACHE) != $status; |
| | 5823 | |
| | 5824 | $conf = i2c_smbus_read_byte_data($file, 0x03); |
| | 5825 | # The 4 lower bits should be zero |
| | 5826 | return unless ($conf & 0x0f) == 0x00; |
| | 5827 | |
| | 5828 | return 5; |
| | 5829 | } |
| | 5830 | |