162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Hardware monitoring driver for Infineon Multi-phase Digital VR Controllers
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2022 Infineon Technologies. All rights reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/err.h>
962306a36Sopenharmony_ci#include <linux/i2c.h>
1062306a36Sopenharmony_ci#include <linux/init.h>
1162306a36Sopenharmony_ci#include <linux/kernel.h>
1262306a36Sopenharmony_ci#include <linux/module.h>
1362306a36Sopenharmony_ci#include "pmbus.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define XDPE152_PAGE_NUM 2
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cistatic struct pmbus_driver_info xdpe152_info = {
1862306a36Sopenharmony_ci	.pages = XDPE152_PAGE_NUM,
1962306a36Sopenharmony_ci	.format[PSC_VOLTAGE_IN] = linear,
2062306a36Sopenharmony_ci	.format[PSC_VOLTAGE_OUT] = linear,
2162306a36Sopenharmony_ci	.format[PSC_TEMPERATURE] = linear,
2262306a36Sopenharmony_ci	.format[PSC_CURRENT_IN] = linear,
2362306a36Sopenharmony_ci	.format[PSC_CURRENT_OUT] = linear,
2462306a36Sopenharmony_ci	.format[PSC_POWER] = linear,
2562306a36Sopenharmony_ci	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
2662306a36Sopenharmony_ci		PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
2762306a36Sopenharmony_ci		PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP |
2862306a36Sopenharmony_ci		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
2962306a36Sopenharmony_ci	.func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
3062306a36Sopenharmony_ci		PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
3162306a36Sopenharmony_ci		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistatic int xdpe152_probe(struct i2c_client *client)
3562306a36Sopenharmony_ci{
3662306a36Sopenharmony_ci	struct pmbus_driver_info *info;
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci	info = devm_kmemdup(&client->dev, &xdpe152_info, sizeof(*info),
3962306a36Sopenharmony_ci			    GFP_KERNEL);
4062306a36Sopenharmony_ci	if (!info)
4162306a36Sopenharmony_ci		return -ENOMEM;
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	return pmbus_do_probe(client, info);
4462306a36Sopenharmony_ci}
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistatic const struct i2c_device_id xdpe152_id[] = {
4762306a36Sopenharmony_ci	{"xdpe152c4", 0},
4862306a36Sopenharmony_ci	{"xdpe15284", 0},
4962306a36Sopenharmony_ci	{}
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, xdpe152_id);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic const struct of_device_id __maybe_unused xdpe152_of_match[] = {
5562306a36Sopenharmony_ci	{.compatible = "infineon,xdpe152c4"},
5662306a36Sopenharmony_ci	{.compatible = "infineon,xdpe15284"},
5762306a36Sopenharmony_ci	{}
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, xdpe152_of_match);
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic struct i2c_driver xdpe152_driver = {
6262306a36Sopenharmony_ci	.driver = {
6362306a36Sopenharmony_ci		.name = "xdpe152c4",
6462306a36Sopenharmony_ci		.of_match_table = of_match_ptr(xdpe152_of_match),
6562306a36Sopenharmony_ci	},
6662306a36Sopenharmony_ci	.probe = xdpe152_probe,
6762306a36Sopenharmony_ci	.id_table = xdpe152_id,
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cimodule_i2c_driver(xdpe152_driver);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciMODULE_AUTHOR("Greg Schwendimann <greg.schwendimann@infineon.com>");
7362306a36Sopenharmony_ciMODULE_DESCRIPTION("PMBus driver for Infineon XDPE152 family");
7462306a36Sopenharmony_ciMODULE_LICENSE("GPL");
7562306a36Sopenharmony_ciMODULE_IMPORT_NS(PMBUS);
76