| | 5310 | } |
| | 5311 | |
| | 5312 | # Chip to detect: 0 = STTS424 |
| | 5313 | # Registers used: |
| | 5314 | # 0x00: Capabilities |
| | 5315 | # 0x01: Configuration |
| | 5316 | # 0x06: Manufacturer ID |
| | 5317 | # 0x07: Device ID |
| | 5318 | sub jedec_JC42_4_detect |
| | 5319 | { |
| | 5320 | my ($file, $addr, $chip) = @_; |
| | 5321 | my ($reg, $manid, $devid); |
| | 5322 | |
| | 5323 | # We test the MSB only at first, because not all chips enjoy |
| | 5324 | # word access. |
| | 5325 | |
| | 5326 | # Check for unused bits |
| | 5327 | $reg = i2c_smbus_read_byte_data($file, 0x00); |
| | 5328 | return if $reg & 0xff; |
| | 5329 | $reg = i2c_smbus_read_byte_data($file, 0x01); |
| | 5330 | return if $reg & 0xf8; |
| | 5331 | |
| | 5332 | # Check for manufacturer and device ID |
| | 5333 | $manid = i2c_smbus_read_byte_data($file, 0x06); |
| | 5334 | $devid = i2c_smbus_read_byte_data($file, 0x07); |
| | 5335 | if ($chip == 0) { |
| | 5336 | return unless $manid == 0x10; # STMicrolectronics |
| | 5337 | return unless $devid == 0x00; # STTS424 |
| | 5338 | } |
| | 5339 | |
| | 5340 | # Now, do it all again with words. Note that we get |
| | 5341 | # the MSB first, so all value checks are byte-swapped. |
| | 5342 | |
| | 5343 | # Check for unused bits |
| | 5344 | $reg = i2c_smbus_read_word_data($file, 0x00); |
| | 5345 | return if $reg < 0 || $reg & 0xc0ff; |
| | 5346 | |
| | 5347 | $manid = i2c_smbus_read_word_data($file, 0x06); |
| | 5348 | $devid = i2c_smbus_read_word_data($file, 0x07); |
| | 5349 | return if $manid < 0 || $devid < 0; |
| | 5350 | if ($chip == 0) { |
| | 5351 | return unless $manid == 0x4a10; # STMicrolectronics |
| | 5352 | return unless ($devid & 0xfeff) == 0x0000; # STTS424 |
| | 5353 | } |
| | 5354 | |
| | 5355 | return 5; |