xref: /linux/drivers/hwmon/pmbus/bel-pfe.c (revision fbf5df34a4dbcd09d433dd4f0916bf9b2ddb16de)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Hardware monitoring driver for BEL PFE family power supplies.
4  *
5  * Copyright (c) 2019 Facebook Inc.
6  */
7 
8 #include <linux/err.h>
9 #include <linux/i2c.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/pmbus.h>
14 
15 #include "pmbus.h"
16 
17 enum chips {pfe1100, pfe3000};
18 
19 /*
20  * Disable status check because some devices report communication error
21  * (invalid command) for VOUT_MODE command (0x20) although the correct
22  * VOUT_MODE (0x16) is returned: it leads to incorrect exponent in linear
23  * mode.
24  * This affects both pfe3000 and pfe1100.
25  */
26 static struct pmbus_platform_data pfe_plat_data = {
27 	.flags = PMBUS_SKIP_STATUS_CHECK,
28 };
29 
30 static struct pmbus_driver_info pfe_driver_info[] = {
31 	[pfe1100] = {
32 		.pages = 1,
33 		.format[PSC_VOLTAGE_IN] = linear,
34 		.format[PSC_VOLTAGE_OUT] = linear,
35 		.format[PSC_CURRENT_IN] = linear,
36 		.format[PSC_CURRENT_OUT] = linear,
37 		.format[PSC_POWER] = linear,
38 		.format[PSC_TEMPERATURE] = linear,
39 		.format[PSC_FAN] = linear,
40 
41 		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
42 			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
43 			   PMBUS_HAVE_POUT |
44 			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
45 			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
46 			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
47 			   PMBUS_HAVE_STATUS_TEMP |
48 			   PMBUS_HAVE_FAN12,
49 	},
50 
51 	[pfe3000] = {
52 		.pages = 7,
53 		.format[PSC_VOLTAGE_IN] = linear,
54 		.format[PSC_VOLTAGE_OUT] = linear,
55 		.format[PSC_CURRENT_IN] = linear,
56 		.format[PSC_CURRENT_OUT] = linear,
57 		.format[PSC_POWER] = linear,
58 		.format[PSC_TEMPERATURE] = linear,
59 		.format[PSC_FAN] = linear,
60 
61 		/* Page 0: V1. */
62 		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
63 			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
64 			   PMBUS_HAVE_POUT | PMBUS_HAVE_FAN12 |
65 			   PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
66 			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
67 			   PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
68 			   PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_TEMP |
69 			   PMBUS_HAVE_VCAP,
70 
71 		/* Page 1: Vsb. */
72 		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
73 			   PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
74 			   PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
75 			   PMBUS_HAVE_POUT,
76 
77 		/*
78 		 * Page 2: V1 Ishare.
79 		 * Page 3: Reserved.
80 		 * Page 4: V1 Cathode.
81 		 * Page 5: Vsb Cathode.
82 		 * Page 6: V1 Sense.
83 		 */
84 		.func[2] = PMBUS_HAVE_VOUT,
85 		.func[4] = PMBUS_HAVE_VOUT,
86 		.func[5] = PMBUS_HAVE_VOUT,
87 		.func[6] = PMBUS_HAVE_VOUT,
88 	},
89 };
90 
91 static int pfe_pmbus_probe(struct i2c_client *client)
92 {
93 	int model = (uintptr_t)i2c_get_match_data(client);
94 
95 	client->dev.platform_data = &pfe_plat_data;
96 
97 	/*
98 	 * PFE3000-12-069RA devices may not stay in page 0 during device
99 	 * probe which leads to probe failure (read status word failed).
100 	 * So let's set the device to page 0 at the beginning.
101 	 */
102 	if (model == pfe3000)
103 		i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
104 
105 	return pmbus_do_probe(client, &pfe_driver_info[model]);
106 }
107 
108 static const struct i2c_device_id pfe_device_id[] = {
109 	{"pfe1100", pfe1100},
110 	{"pfe3000", pfe3000},
111 	{}
112 };
113 
114 MODULE_DEVICE_TABLE(i2c, pfe_device_id);
115 
116 static struct i2c_driver pfe_pmbus_driver = {
117 	.driver = {
118 		   .name = "bel-pfe",
119 	},
120 	.probe = pfe_pmbus_probe,
121 	.id_table = pfe_device_id,
122 };
123 
124 module_i2c_driver(pfe_pmbus_driver);
125 
126 MODULE_AUTHOR("Tao Ren <rentao.bupt@gmail.com>");
127 MODULE_DESCRIPTION("PMBus driver for BEL PFE Family Power Supplies");
128 MODULE_LICENSE("GPL");
129 MODULE_IMPORT_NS("PMBUS");
130