ir36021.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Hardware monitoring driver for Infineon IR36021
  4. *
  5. * Copyright (c) 2021 Allied Telesis
  6. */
  7. #include <linux/err.h>
  8. #include <linux/i2c.h>
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include "pmbus.h"
  13. static struct pmbus_driver_info ir36021_info = {
  14. .pages = 1,
  15. .format[PSC_VOLTAGE_IN] = linear,
  16. .format[PSC_VOLTAGE_OUT] = linear,
  17. .format[PSC_CURRENT_IN] = linear,
  18. .format[PSC_CURRENT_OUT] = linear,
  19. .format[PSC_POWER] = linear,
  20. .format[PSC_TEMPERATURE] = linear,
  21. .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
  22. | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
  23. | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
  24. | PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
  25. | PMBUS_HAVE_STATUS_TEMP,
  26. };
  27. static int ir36021_probe(struct i2c_client *client)
  28. {
  29. u8 buf[I2C_SMBUS_BLOCK_MAX];
  30. int ret;
  31. if (!i2c_check_functionality(client->adapter,
  32. I2C_FUNC_SMBUS_READ_BYTE_DATA
  33. | I2C_FUNC_SMBUS_READ_WORD_DATA
  34. | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
  35. return -ENODEV;
  36. ret = i2c_smbus_read_i2c_block_data(client, PMBUS_MFR_MODEL, 2, buf);
  37. if (ret < 0) {
  38. dev_err(&client->dev, "Failed to read PMBUS_MFR_MODEL\n");
  39. return ret;
  40. }
  41. if (ret != 2 || buf[0] != 0x01 || buf[1] != 0x2d) {
  42. dev_err(&client->dev, "MFR_MODEL unrecognised\n");
  43. return -ENODEV;
  44. }
  45. return pmbus_do_probe(client, &ir36021_info);
  46. }
  47. static const struct i2c_device_id ir36021_id[] = {
  48. { "ir36021", 0 },
  49. {},
  50. };
  51. MODULE_DEVICE_TABLE(i2c, ir36021_id);
  52. static const struct of_device_id __maybe_unused ir36021_of_id[] = {
  53. { .compatible = "infineon,ir36021" },
  54. {},
  55. };
  56. MODULE_DEVICE_TABLE(of, ir36021_of_id);
  57. static struct i2c_driver ir36021_driver = {
  58. .class = I2C_CLASS_HWMON,
  59. .driver = {
  60. .name = "ir36021",
  61. .of_match_table = of_match_ptr(ir36021_of_id),
  62. },
  63. .probe_new = ir36021_probe,
  64. .id_table = ir36021_id,
  65. };
  66. module_i2c_driver(ir36021_driver);
  67. MODULE_AUTHOR("Chris Packham <[email protected]>");
  68. MODULE_DESCRIPTION("PMBus driver for Infineon IR36021");
  69. MODULE_LICENSE("GPL");
  70. MODULE_IMPORT_NS(PMBUS);