803-hwmon-tc654-add-detection-routine.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. From 694f9bfb8efaef8a33e8992015ff9d0866faf4a2 Mon Sep 17 00:00:00 2001
  2. From: Christian Lamparter <[email protected]>
  3. Date: Sun, 17 Dec 2017 17:27:15 +0100
  4. Subject: [PATCH 1/2] hwmon: tc654 add detection routine
  5. This patch adds a detection routine for the TC654/TC655
  6. chips. Both IDs are listed in the Datasheet.
  7. Signed-off-by: Christian Lamparter <[email protected]>
  8. ---
  9. drivers/hwmon/tc654.c | 29 +++++++++++++++++++++++++++++
  10. 1 file changed, 29 insertions(+)
  11. --- a/drivers/hwmon/tc654.c
  12. +++ b/drivers/hwmon/tc654.c
  13. @@ -55,6 +55,11 @@ enum tc654_regs {
  14. /* Register data is read (and cached) at most once per second. */
  15. #define TC654_UPDATE_INTERVAL HZ
  16. +/* Manufacturer and Version Identification Register Values */
  17. +#define TC654_MFR_ID_MICROCHIP 0x84
  18. +#define TC654_VER_ID 0x00
  19. +#define TC655_VER_ID 0x01
  20. +
  21. struct tc654_data {
  22. struct i2c_client *client;
  23. @@ -481,6 +486,29 @@ static const struct i2c_device_id tc654_
  24. {}
  25. };
  26. +static int
  27. +tc654_detect(struct i2c_client *new_client, struct i2c_board_info *info)
  28. +{
  29. + struct i2c_adapter *adapter = new_client->adapter;
  30. + int manufacturer, product;
  31. +
  32. + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  33. + return -ENODEV;
  34. +
  35. + manufacturer = i2c_smbus_read_byte_data(new_client, TC654_REG_MFR_ID);
  36. + if (manufacturer != TC654_MFR_ID_MICROCHIP)
  37. + return -ENODEV;
  38. +
  39. + product = i2c_smbus_read_byte_data(new_client, TC654_REG_VER_ID);
  40. + if (!((product == TC654_VER_ID) || (product == TC655_VER_ID)))
  41. + return -ENODEV;
  42. +
  43. + strlcpy(info->type, product == TC654_VER_ID ? "tc654" : "tc655",
  44. + I2C_NAME_SIZE);
  45. + return 0;
  46. +}
  47. +
  48. +
  49. MODULE_DEVICE_TABLE(i2c, tc654_id);
  50. static struct i2c_driver tc654_driver = {
  51. @@ -489,6 +517,7 @@ static struct i2c_driver tc654_driver =
  52. },
  53. .probe_new = tc654_probe,
  54. .id_table = tc654_id,
  55. + .detect = tc654_detect,
  56. };
  57. module_i2c_driver(tc654_driver);