| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Copyright 2024 IBM Corp. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <linux/i2c.h> |
| 7 |
#include <linux/of.h> |
| 8 |
#include <linux/pmbus.h> |
| 9 |
|
| 10 |
#include "pmbus.h" |
| 11 |
|
| 12 |
static const struct i2c_device_id crps_id[] = { |
| 13 |
{ "intel_crps185" }, |
| 14 |
{} |
| 15 |
}; |
| 16 |
MODULE_DEVICE_TABLE(i2c, crps_id); |
| 17 |
|
| 18 |
static struct pmbus_driver_info crps_info = { |
| 19 |
.pages = 1, |
| 20 |
/* PSU uses default linear data format. */ |
| 21 |
.func[0] = PMBUS_HAVE_PIN | PMBUS_HAVE_IOUT | |
| 22 |
PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_IIN | |
| 23 |
PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT | |
| 24 |
PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | |
| 25 |
PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | |
| 26 |
PMBUS_HAVE_STATUS_TEMP | |
| 27 |
PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12, |
| 28 |
}; |
| 29 |
|
| 30 |
static int crps_probe(struct i2c_client *client) |
| 31 |
{ |
| 32 |
int rc; |
| 33 |
struct device *dev = &client->dev; |
| 34 |
char buf[I2C_SMBUS_BLOCK_MAX + 2] = { 0 }; |
| 35 |
|
| 36 |
rc = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); |
| 37 |
if (rc < 0) |
| 38 |
return dev_err_probe(dev, rc, "Failed to read PMBUS_MFR_MODEL\n"); |
| 39 |
|
| 40 |
if (rc != 7 || strncmp(buf, "03NK260", 7)) { |
| 41 |
buf[rc] = '\0'; |
| 42 |
return dev_err_probe(dev, -ENODEV, "Model '%s' not supported\n", buf); |
| 43 |
} |
| 44 |
|
| 45 |
rc = pmbus_do_probe(client, &crps_info); |
| 46 |
if (rc) |
| 47 |
return dev_err_probe(dev, rc, "Failed to probe\n"); |
| 48 |
|
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
static const struct of_device_id crps_of_match[] = { |
| 53 |
{ |
| 54 |
.compatible = "intel,crps185", |
| 55 |
}, |
| 56 |
{} |
| 57 |
}; |
| 58 |
MODULE_DEVICE_TABLE(of, crps_of_match); |
| 59 |
|
| 60 |
static struct i2c_driver crps_driver = { |
| 61 |
.driver = { |
| 62 |
.name = "crps", |
| 63 |
.of_match_table = crps_of_match, |
| 64 |
}, |
| 65 |
.probe = crps_probe, |
| 66 |
.id_table = crps_id, |
| 67 |
}; |
| 68 |
|
| 69 |
module_i2c_driver(crps_driver); |
| 70 |
|
| 71 |
MODULE_AUTHOR("Ninad Palsule"); |
| 72 |
MODULE_DESCRIPTION("PMBus driver for Intel Common Redundant power supplies"); |
| 73 |
MODULE_LICENSE("GPL"); |
| 74 |
MODULE_IMPORT_NS("PMBUS"); |