xref: /linux/drivers/hwmon/pmbus/mpq8785.c (revision da5b2ad1c2f18834cb1ce429e2e5a5cf5cbdf21b)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Driver for MPS MPQ8785 Step-Down Converter
4  */
5 
6 #include <linux/i2c.h>
7 #include <linux/module.h>
8 #include <linux/of_device.h>
9 #include "pmbus.h"
10 
11 static int mpq8785_identify(struct i2c_client *client,
12 			    struct pmbus_driver_info *info)
13 {
14 	int vout_mode;
15 
16 	vout_mode = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
17 	if (vout_mode < 0 || vout_mode == 0xff)
18 		return vout_mode < 0 ? vout_mode : -ENODEV;
19 	switch (vout_mode >> 5) {
20 	case 0:
21 		info->format[PSC_VOLTAGE_OUT] = linear;
22 		break;
23 	case 1:
24 	case 2:
25 		info->format[PSC_VOLTAGE_OUT] = direct,
26 		info->m[PSC_VOLTAGE_OUT] = 64;
27 		info->b[PSC_VOLTAGE_OUT] = 0;
28 		info->R[PSC_VOLTAGE_OUT] = 1;
29 		break;
30 	default:
31 		return -ENODEV;
32 	}
33 
34 	return 0;
35 };
36 
37 static struct pmbus_driver_info mpq8785_info = {
38 	.pages = 1,
39 	.format[PSC_VOLTAGE_IN] = direct,
40 	.format[PSC_CURRENT_OUT] = direct,
41 	.format[PSC_TEMPERATURE] = direct,
42 	.m[PSC_VOLTAGE_IN] = 4,
43 	.b[PSC_VOLTAGE_IN] = 0,
44 	.R[PSC_VOLTAGE_IN] = 1,
45 	.m[PSC_CURRENT_OUT] = 16,
46 	.b[PSC_CURRENT_OUT] = 0,
47 	.R[PSC_CURRENT_OUT] = 0,
48 	.m[PSC_TEMPERATURE] = 1,
49 	.b[PSC_TEMPERATURE] = 0,
50 	.R[PSC_TEMPERATURE] = 0,
51 	.func[0] =
52 		PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
53 		PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
54 		PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
55 		PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
56 	.identify = mpq8785_identify,
57 };
58 
59 static int mpq8785_probe(struct i2c_client *client)
60 {
61 	return pmbus_do_probe(client, &mpq8785_info);
62 };
63 
64 static const struct i2c_device_id mpq8785_id[] = {
65 	{ "mpq8785" },
66 	{ },
67 };
68 MODULE_DEVICE_TABLE(i2c, mpq8785_id);
69 
70 static const struct of_device_id __maybe_unused mpq8785_of_match[] = {
71 	{ .compatible = "mps,mpq8785" },
72 	{}
73 };
74 MODULE_DEVICE_TABLE(of, mpq8785_of_match);
75 
76 static struct i2c_driver mpq8785_driver = {
77 	.driver = {
78 		   .name = "mpq8785",
79 		   .of_match_table = of_match_ptr(mpq8785_of_match),
80 	},
81 	.probe = mpq8785_probe,
82 	.id_table = mpq8785_id,
83 };
84 
85 module_i2c_driver(mpq8785_driver);
86 
87 MODULE_AUTHOR("Charles Hsu <ythsu0511@gmail.com>");
88 MODULE_DESCRIPTION("PMBus driver for MPS MPQ8785");
89 MODULE_LICENSE("GPL");
90 MODULE_IMPORT_NS(PMBUS);
91