xref: /linux/drivers/hwmon/pmbus/ir36021.c (revision 41e0d49104dbff888ef6446ea46842fde66c0a76)
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 
14 static struct pmbus_driver_info ir36021_info = {
15 	.pages = 1,
16 	.format[PSC_VOLTAGE_IN] = linear,
17 	.format[PSC_VOLTAGE_OUT] = linear,
18 	.format[PSC_CURRENT_IN] = linear,
19 	.format[PSC_CURRENT_OUT] = linear,
20 	.format[PSC_POWER] = linear,
21 	.format[PSC_TEMPERATURE] = linear,
22 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
23 		| PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
24 		| PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
25 		| PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
26 		| PMBUS_HAVE_STATUS_TEMP,
27 };
28 
29 static int ir36021_probe(struct i2c_client *client)
30 {
31 	u8 buf[I2C_SMBUS_BLOCK_MAX];
32 	int ret;
33 
34 	if (!i2c_check_functionality(client->adapter,
35 				     I2C_FUNC_SMBUS_READ_BYTE_DATA
36 				     | I2C_FUNC_SMBUS_READ_WORD_DATA
37 				     | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
38 		return -ENODEV;
39 
40 	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_MFR_MODEL, 2, buf);
41 	if (ret < 0) {
42 		dev_err(&client->dev, "Failed to read PMBUS_MFR_MODEL\n");
43 		return ret;
44 	}
45 	if (ret != 2 || buf[0] != 0x01 || buf[1] != 0x2d) {
46 		dev_err(&client->dev, "MFR_MODEL unrecognised\n");
47 		return -ENODEV;
48 	}
49 
50 	return pmbus_do_probe(client, &ir36021_info);
51 }
52 
53 static const struct i2c_device_id ir36021_id[] = {
54 	{ "ir36021", 0 },
55 	{},
56 };
57 MODULE_DEVICE_TABLE(i2c, ir36021_id);
58 
59 static const struct of_device_id __maybe_unused ir36021_of_id[] = {
60 	{ .compatible = "infineon,ir36021" },
61 	{},
62 };
63 MODULE_DEVICE_TABLE(of, ir36021_of_id);
64 
65 static struct i2c_driver ir36021_driver = {
66 	.class = I2C_CLASS_HWMON,
67 	.driver = {
68 		.name = "ir36021",
69 		.of_match_table = of_match_ptr(ir36021_of_id),
70 	},
71 	.probe_new = ir36021_probe,
72 	.id_table = ir36021_id,
73 };
74 
75 module_i2c_driver(ir36021_driver);
76 
77 MODULE_AUTHOR("Chris Packham <chris.packham@alliedtelesis.co.nz>");
78 MODULE_DESCRIPTION("PMBus driver for Infineon IR36021");
79 MODULE_LICENSE("GPL");
80 MODULE_IMPORT_NS(PMBUS);
81