xref: /linux/drivers/hwmon/pmbus/ir38064.c (revision d8a66f3621c2886ad328d9df53349fc10251f583)
100669d19SMaxim Sloyko // SPDX-License-Identifier: GPL-2.0+
200669d19SMaxim Sloyko /*
300669d19SMaxim Sloyko  * Hardware monitoring driver for Infineon IR38064
400669d19SMaxim Sloyko  *
500669d19SMaxim Sloyko  * Copyright (c) 2017 Google Inc
600669d19SMaxim Sloyko  *
700669d19SMaxim Sloyko  * VOUT_MODE is not supported by the device. The driver fakes VOUT linear16
800669d19SMaxim Sloyko  * mode with exponent value -8 as direct mode with m=256/b=0/R=0.
900669d19SMaxim Sloyko  *
1000669d19SMaxim Sloyko  * The device supports VOUT_PEAK, IOUT_PEAK, and TEMPERATURE_PEAK, however
1100669d19SMaxim Sloyko  * this driver does not currently support them.
1200669d19SMaxim Sloyko  */
1300669d19SMaxim Sloyko 
1400669d19SMaxim Sloyko #include <linux/err.h>
1500669d19SMaxim Sloyko #include <linux/i2c.h>
1600669d19SMaxim Sloyko #include <linux/init.h>
1700669d19SMaxim Sloyko #include <linux/kernel.h>
1800669d19SMaxim Sloyko #include <linux/module.h>
1939f03438SRob Herring #include <linux/of.h>
200ee7f624SPatrick Rudolph #include <linux/regulator/driver.h>
2100669d19SMaxim Sloyko #include "pmbus.h"
2200669d19SMaxim Sloyko 
230ee7f624SPatrick Rudolph #if IS_ENABLED(CONFIG_SENSORS_IR38064_REGULATOR)
240ee7f624SPatrick Rudolph static const struct regulator_desc ir38064_reg_desc[] = {
25cb722299SGuenter Roeck 	PMBUS_REGULATOR_ONE("vout"),
260ee7f624SPatrick Rudolph };
270ee7f624SPatrick Rudolph #endif /* CONFIG_SENSORS_IR38064_REGULATOR */
280ee7f624SPatrick Rudolph 
2900669d19SMaxim Sloyko static struct pmbus_driver_info ir38064_info = {
3000669d19SMaxim Sloyko 	.pages = 1,
3100669d19SMaxim Sloyko 	.format[PSC_VOLTAGE_IN] = linear,
3200669d19SMaxim Sloyko 	.format[PSC_VOLTAGE_OUT] = direct,
3300669d19SMaxim Sloyko 	.format[PSC_CURRENT_OUT] = linear,
3400669d19SMaxim Sloyko 	.format[PSC_POWER] = linear,
3500669d19SMaxim Sloyko 	.format[PSC_TEMPERATURE] = linear,
3600669d19SMaxim Sloyko 	.m[PSC_VOLTAGE_OUT] = 256,
3700669d19SMaxim Sloyko 	.b[PSC_VOLTAGE_OUT] = 0,
3800669d19SMaxim Sloyko 	.R[PSC_VOLTAGE_OUT] = 0,
3900669d19SMaxim Sloyko 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT
4000669d19SMaxim Sloyko 	    | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP
4100669d19SMaxim Sloyko 	    | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
4200669d19SMaxim Sloyko 	    | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT
4300669d19SMaxim Sloyko 	    | PMBUS_HAVE_POUT,
440ee7f624SPatrick Rudolph #if IS_ENABLED(CONFIG_SENSORS_IR38064_REGULATOR)
450ee7f624SPatrick Rudolph 	.num_regulators = 1,
460ee7f624SPatrick Rudolph 	.reg_desc = ir38064_reg_desc,
470ee7f624SPatrick Rudolph #endif
4800669d19SMaxim Sloyko };
4900669d19SMaxim Sloyko 
50dd431939SStephen Kitt static int ir38064_probe(struct i2c_client *client)
5100669d19SMaxim Sloyko {
52dd431939SStephen Kitt 	return pmbus_do_probe(client, &ir38064_info);
5300669d19SMaxim Sloyko }
5400669d19SMaxim Sloyko 
5500669d19SMaxim Sloyko static const struct i2c_device_id ir38064_id[] = {
56*d8a66f36SUwe Kleine-König 	{"ir38060"},
57*d8a66f36SUwe Kleine-König 	{"ir38064"},
58*d8a66f36SUwe Kleine-König 	{"ir38164"},
59*d8a66f36SUwe Kleine-König 	{"ir38263"},
6000669d19SMaxim Sloyko 	{}
6100669d19SMaxim Sloyko };
6200669d19SMaxim Sloyko 
6300669d19SMaxim Sloyko MODULE_DEVICE_TABLE(i2c, ir38064_id);
6400669d19SMaxim Sloyko 
65f1e75e0dSGuenter Roeck static const struct of_device_id __maybe_unused ir38064_of_match[] = {
66e65de225SArthur Heymans 	{ .compatible = "infineon,ir38060" },
67e65de225SArthur Heymans 	{ .compatible = "infineon,ir38064" },
68e65de225SArthur Heymans 	{ .compatible = "infineon,ir38164" },
69e65de225SArthur Heymans 	{ .compatible = "infineon,ir38263" },
70e65de225SArthur Heymans 	{}
71e65de225SArthur Heymans };
72e65de225SArthur Heymans 
73e65de225SArthur Heymans MODULE_DEVICE_TABLE(of, ir38064_of_match);
74e65de225SArthur Heymans 
7500669d19SMaxim Sloyko /* This is the driver that will be inserted */
7600669d19SMaxim Sloyko static struct i2c_driver ir38064_driver = {
7700669d19SMaxim Sloyko 	.driver = {
7800669d19SMaxim Sloyko 		   .name = "ir38064",
79e65de225SArthur Heymans 		   .of_match_table = of_match_ptr(ir38064_of_match),
8000669d19SMaxim Sloyko 		   },
811975d167SUwe Kleine-König 	.probe = ir38064_probe,
8200669d19SMaxim Sloyko 	.id_table = ir38064_id,
8300669d19SMaxim Sloyko };
8400669d19SMaxim Sloyko 
8500669d19SMaxim Sloyko module_i2c_driver(ir38064_driver);
8600669d19SMaxim Sloyko 
8700669d19SMaxim Sloyko MODULE_AUTHOR("Maxim Sloyko <maxims@google.com>");
8823c7df14SColin Ian King MODULE_DESCRIPTION("PMBus driver for Infineon IR38064 and compatible chips");
8900669d19SMaxim Sloyko MODULE_LICENSE("GPL");
90b94ca77eSGuenter Roeck MODULE_IMPORT_NS(PMBUS);
91