root/drivers/hwmon/pmbus/pxe1610.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pxe1610_identify
  2. pxe1610_probe

   1 // SPDX-License-Identifier: GPL-2.0+
   2 /*
   3  * Hardware monitoring driver for Infineon PXE1610
   4  *
   5  * Copyright (c) 2019 Facebook Inc
   6  *
   7  */
   8 
   9 #include <linux/err.h>
  10 #include <linux/i2c.h>
  11 #include <linux/init.h>
  12 #include <linux/kernel.h>
  13 #include <linux/module.h>
  14 #include "pmbus.h"
  15 
  16 #define PXE1610_NUM_PAGES 3
  17 
  18 /* Identify chip parameters. */
  19 static int pxe1610_identify(struct i2c_client *client,
  20                              struct pmbus_driver_info *info)
  21 {
  22         if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) {
  23                 u8 vout_mode;
  24                 int ret;
  25 
  26                 /* Read the register with VOUT scaling value.*/
  27                 ret = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
  28                 if (ret < 0)
  29                         return ret;
  30 
  31                 vout_mode = ret & GENMASK(4, 0);
  32 
  33                 switch (vout_mode) {
  34                 case 1:
  35                         info->vrm_version = vr12;
  36                         break;
  37                 case 2:
  38                         info->vrm_version = vr13;
  39                         break;
  40                 default:
  41                         return -ENODEV;
  42                 }
  43         }
  44 
  45         return 0;
  46 }
  47 
  48 static struct pmbus_driver_info pxe1610_info = {
  49         .pages = PXE1610_NUM_PAGES,
  50         .format[PSC_VOLTAGE_IN] = linear,
  51         .format[PSC_VOLTAGE_OUT] = vid,
  52         .format[PSC_CURRENT_IN] = linear,
  53         .format[PSC_CURRENT_OUT] = linear,
  54         .format[PSC_TEMPERATURE] = linear,
  55         .format[PSC_POWER] = linear,
  56         .func[0] = PMBUS_HAVE_VIN
  57                 | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN
  58                 | PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN
  59                 | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP
  60                 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT
  61                 | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
  62         .func[1] = PMBUS_HAVE_VIN
  63                 | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN
  64                 | PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN
  65                 | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP
  66                 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT
  67                 | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
  68         .func[2] = PMBUS_HAVE_VIN
  69                 | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN
  70                 | PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN
  71                 | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP
  72                 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT
  73                 | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
  74         .identify = pxe1610_identify,
  75 };
  76 
  77 static int pxe1610_probe(struct i2c_client *client,
  78                           const struct i2c_device_id *id)
  79 {
  80         struct pmbus_driver_info *info;
  81         u8 buf[I2C_SMBUS_BLOCK_MAX];
  82         int ret;
  83 
  84         if (!i2c_check_functionality(
  85                         client->adapter,
  86                         I2C_FUNC_SMBUS_READ_BYTE_DATA
  87                         | I2C_FUNC_SMBUS_READ_WORD_DATA
  88                         | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
  89                 return -ENODEV;
  90 
  91         /*
  92          * By default this device doesn't boot to page 0, so set page 0
  93          * to access all pmbus registers.
  94          */
  95         i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
  96 
  97         /* Read Manufacturer id */
  98         ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
  99         if (ret < 0) {
 100                 dev_err(&client->dev, "Failed to read PMBUS_MFR_ID\n");
 101                 return ret;
 102         }
 103         if (ret != 2 || strncmp(buf, "XP", 2)) {
 104                 dev_err(&client->dev, "MFR_ID unrecognized\n");
 105                 return -ENODEV;
 106         }
 107 
 108         info = devm_kmemdup(&client->dev, &pxe1610_info,
 109                             sizeof(struct pmbus_driver_info),
 110                             GFP_KERNEL);
 111         if (!info)
 112                 return -ENOMEM;
 113 
 114         return pmbus_do_probe(client, id, info);
 115 }
 116 
 117 static const struct i2c_device_id pxe1610_id[] = {
 118         {"pxe1610", 0},
 119         {"pxe1110", 0},
 120         {"pxm1310", 0},
 121         {}
 122 };
 123 
 124 MODULE_DEVICE_TABLE(i2c, pxe1610_id);
 125 
 126 static struct i2c_driver pxe1610_driver = {
 127         .driver = {
 128                         .name = "pxe1610",
 129                         },
 130         .probe = pxe1610_probe,
 131         .remove = pmbus_do_remove,
 132         .id_table = pxe1610_id,
 133 };
 134 
 135 module_i2c_driver(pxe1610_driver);
 136 
 137 MODULE_AUTHOR("Vijay Khemka <vijaykhemka@fb.com>");
 138 MODULE_DESCRIPTION("PMBus driver for Infineon PXE1610, PXE1110 and PXM1310");
 139 MODULE_LICENSE("GPL");

/* [<][>][^][v][top][bottom][index][help] */