Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Hardware monitoring driver for Infineon IR38064 |
| 4 | * |
| 5 | * Copyright (c) 2017 Google Inc |
| 6 | * |
| 7 | * VOUT_MODE is not supported by the device. The driver fakes VOUT linear16 |
| 8 | * mode with exponent value -8 as direct mode with m=256/b=0/R=0. |
| 9 | * |
| 10 | * The device supports VOUT_PEAK, IOUT_PEAK, and TEMPERATURE_PEAK, however |
| 11 | * this driver does not currently support them. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/i2c.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
Arthur Heymans | e65de22 | 2021-12-13 15:28:13 +0100 | [diff] [blame] | 19 | #include <linux/of_device.h> |
Patrick Rudolph | 0ee7f62 | 2021-12-13 15:28:14 +0100 | [diff] [blame] | 20 | #include <linux/regulator/driver.h> |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 21 | #include "pmbus.h" |
| 22 | |
Patrick Rudolph | 0ee7f62 | 2021-12-13 15:28:14 +0100 | [diff] [blame] | 23 | #if IS_ENABLED(CONFIG_SENSORS_IR38064_REGULATOR) |
| 24 | static const struct regulator_desc ir38064_reg_desc[] = { |
| 25 | PMBUS_REGULATOR("vout", 0), |
| 26 | }; |
| 27 | #endif /* CONFIG_SENSORS_IR38064_REGULATOR */ |
| 28 | |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 29 | static struct pmbus_driver_info ir38064_info = { |
| 30 | .pages = 1, |
| 31 | .format[PSC_VOLTAGE_IN] = linear, |
| 32 | .format[PSC_VOLTAGE_OUT] = direct, |
| 33 | .format[PSC_CURRENT_OUT] = linear, |
| 34 | .format[PSC_POWER] = linear, |
| 35 | .format[PSC_TEMPERATURE] = linear, |
| 36 | .m[PSC_VOLTAGE_OUT] = 256, |
| 37 | .b[PSC_VOLTAGE_OUT] = 0, |
| 38 | .R[PSC_VOLTAGE_OUT] = 0, |
| 39 | .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 40 | | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
| 41 | | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 42 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
| 43 | | PMBUS_HAVE_POUT, |
Patrick Rudolph | 0ee7f62 | 2021-12-13 15:28:14 +0100 | [diff] [blame] | 44 | #if IS_ENABLED(CONFIG_SENSORS_IR38064_REGULATOR) |
| 45 | .num_regulators = 1, |
| 46 | .reg_desc = ir38064_reg_desc, |
| 47 | #endif |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Stephen Kitt | dd43193 | 2020-08-08 23:00:04 +0200 | [diff] [blame] | 50 | static int ir38064_probe(struct i2c_client *client) |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 51 | { |
Stephen Kitt | dd43193 | 2020-08-08 23:00:04 +0200 | [diff] [blame] | 52 | return pmbus_do_probe(client, &ir38064_info); |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static const struct i2c_device_id ir38064_id[] = { |
Patrick Rudolph | ca003af | 2021-12-13 15:28:12 +0100 | [diff] [blame] | 56 | {"ir38060", 0}, |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 57 | {"ir38064", 0}, |
Patrick Rudolph | ca003af | 2021-12-13 15:28:12 +0100 | [diff] [blame] | 58 | {"ir38164", 0}, |
| 59 | {"ir38263", 0}, |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 60 | {} |
| 61 | }; |
| 62 | |
| 63 | MODULE_DEVICE_TABLE(i2c, ir38064_id); |
| 64 | |
Guenter Roeck | f1e75e0 | 2022-01-18 07:53:19 -0800 | [diff] [blame] | 65 | static const struct of_device_id __maybe_unused ir38064_of_match[] = { |
Arthur Heymans | e65de22 | 2021-12-13 15:28:13 +0100 | [diff] [blame] | 66 | { .compatible = "infineon,ir38060" }, |
| 67 | { .compatible = "infineon,ir38064" }, |
| 68 | { .compatible = "infineon,ir38164" }, |
| 69 | { .compatible = "infineon,ir38263" }, |
| 70 | {} |
| 71 | }; |
| 72 | |
| 73 | MODULE_DEVICE_TABLE(of, ir38064_of_match); |
| 74 | |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 75 | /* This is the driver that will be inserted */ |
| 76 | static struct i2c_driver ir38064_driver = { |
| 77 | .driver = { |
| 78 | .name = "ir38064", |
Arthur Heymans | e65de22 | 2021-12-13 15:28:13 +0100 | [diff] [blame] | 79 | .of_match_table = of_match_ptr(ir38064_of_match), |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 80 | }, |
Stephen Kitt | dd43193 | 2020-08-08 23:00:04 +0200 | [diff] [blame] | 81 | .probe_new = ir38064_probe, |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 82 | .id_table = ir38064_id, |
| 83 | }; |
| 84 | |
| 85 | module_i2c_driver(ir38064_driver); |
| 86 | |
| 87 | MODULE_AUTHOR("Maxim Sloyko <maxims@google.com>"); |
Colin Ian King | 23c7df1 | 2021-12-20 15:55:27 +0000 | [diff] [blame] | 88 | MODULE_DESCRIPTION("PMBus driver for Infineon IR38064 and compatible chips"); |
Maxim Sloyko | 00669d1 | 2019-04-12 13:37:56 -0700 | [diff] [blame] | 89 | MODULE_LICENSE("GPL"); |
Guenter Roeck | b94ca77 | 2021-04-19 23:07:07 -0700 | [diff] [blame] | 90 | MODULE_IMPORT_NS(PMBUS); |