Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Hardware monitoring driver for Infineon IR36021
0004  *
0005  * Copyright (c) 2021 Allied Telesis
0006  */
0007 #include <linux/err.h>
0008 #include <linux/i2c.h>
0009 #include <linux/init.h>
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include "pmbus.h"
0013 
0014 static struct pmbus_driver_info ir36021_info = {
0015     .pages = 1,
0016     .format[PSC_VOLTAGE_IN] = linear,
0017     .format[PSC_VOLTAGE_OUT] = linear,
0018     .format[PSC_CURRENT_IN] = linear,
0019     .format[PSC_CURRENT_OUT] = linear,
0020     .format[PSC_POWER] = linear,
0021     .format[PSC_TEMPERATURE] = linear,
0022     .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
0023         | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
0024         | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
0025         | PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
0026         | PMBUS_HAVE_STATUS_TEMP,
0027 };
0028 
0029 static int ir36021_probe(struct i2c_client *client)
0030 {
0031     u8 buf[I2C_SMBUS_BLOCK_MAX];
0032     int ret;
0033 
0034     if (!i2c_check_functionality(client->adapter,
0035                      I2C_FUNC_SMBUS_READ_BYTE_DATA
0036                      | I2C_FUNC_SMBUS_READ_WORD_DATA
0037                      | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
0038         return -ENODEV;
0039 
0040     ret = i2c_smbus_read_i2c_block_data(client, PMBUS_MFR_MODEL, 2, buf);
0041     if (ret < 0) {
0042         dev_err(&client->dev, "Failed to read PMBUS_MFR_MODEL\n");
0043         return ret;
0044     }
0045     if (ret != 2 || buf[0] != 0x01 || buf[1] != 0x2d) {
0046         dev_err(&client->dev, "MFR_MODEL unrecognised\n");
0047         return -ENODEV;
0048     }
0049 
0050     return pmbus_do_probe(client, &ir36021_info);
0051 }
0052 
0053 static const struct i2c_device_id ir36021_id[] = {
0054     { "ir36021", 0 },
0055     {},
0056 };
0057 MODULE_DEVICE_TABLE(i2c, ir36021_id);
0058 
0059 static const struct of_device_id __maybe_unused ir36021_of_id[] = {
0060     { .compatible = "infineon,ir36021" },
0061     {},
0062 };
0063 MODULE_DEVICE_TABLE(of, ir36021_of_id);
0064 
0065 static struct i2c_driver ir36021_driver = {
0066     .class = I2C_CLASS_HWMON,
0067     .driver = {
0068         .name = "ir36021",
0069         .of_match_table = of_match_ptr(ir36021_of_id),
0070     },
0071     .probe_new = ir36021_probe,
0072     .id_table = ir36021_id,
0073 };
0074 
0075 module_i2c_driver(ir36021_driver);
0076 
0077 MODULE_AUTHOR("Chris Packham <chris.packham@alliedtelesis.co.nz>");
0078 MODULE_DESCRIPTION("PMBus driver for Infineon IR36021");
0079 MODULE_LICENSE("GPL");
0080 MODULE_IMPORT_NS(PMBUS);