C5222
Posted 码农编程录
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C5222相关的知识,希望对你有一定的参考价值。
xdpe12284.c
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Hardware monitoring driver for Infineon Multi-phase Digital VR Controllers
*
* Copyright (c) 2020 Mellanox Technologies. All rights reserved.
*/
#include <linux/err.h>
#include <linux/hwmon-sysfs.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include "pmbus.h"
#define XDPE122_PROT_VR12_5MV 0x01 /* VR12.0 mode, 5-mV DAC */
#define XDPE122_PROT_VR12_5_10MV 0x02 /* VR12.5 mode, 10-mV DAC */
#define XDPE122_PROT_IMVP9_10MV 0x03 /* IMVP9 mode, 10-mV DAC */
#define XDPE122_AMD_625MV 0x10 /* AMD mode 6.25mV */
#define XDPE122_PAGE_NUM 2
#define XDPE132_PAGE_NUM 2
enum
xdpe12254,
xdpe12284,
xdpe132g5c,
;
static int32_t xdpe122_read_word_data(struct i2c_client *client, int32_t page, int32_t reg)
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
ssize_t val;
int16_t exponent;
int32_t mantissa;
int32_t ret;
if (info == NULL)
return -EINVAL;
switch (reg)
case PMBUS_VOUT_OV_FAULT_LIMIT:
case PMBUS_VOUT_UV_FAULT_LIMIT:
ret = pmbus_read_word_data(client, page, reg);
if (ret < 0)
return ret;
/* Convert register value to LINEAR11 data. */
exponent = ((int16_t)ret) >> 11;
mantissa = ((int16_t)((ret & GENMASK(10, 0)) << 5)) >> 5;
val = mantissa * 1000L;
if (exponent >= 0)
val <<= exponent;
else
val >>= -exponent;
/* Convert data to VID register. */
switch (info->vrm_version[page])
case vr13:
if (val >= 500)
return 1 + DIV_ROUND_CLOSEST(val - 500, 10);
return 0;
case vr12:
if (val >= 250)
return 1 + DIV_ROUND_CLOSEST(val - 250, 5);
return 0;
case imvp9:
if (val >= 200)
return 1 + DIV_ROUND_CLOSEST(val - 200, 10);
return 0;
case amd625mv:
if (val >= 200 && val <= 1550)
return DIV_ROUND_CLOSEST((1550 - val) * 100, 625);
return 0;
default:
return -EINVAL;
default:
return -ENODATA;
return 0;
static int32_t xdpe122_identify(struct i2c_client *client, struct pmbus_driver_info *info)
uint8_t vout_params;
int32_t i;
int32_t ret;
for (i = 0; i < XDPE122_PAGE_NUM; i++)
/* Read the register with VOUT scaling value.*/
ret = pmbus_read_byte_data(client, i, PMBUS_VOUT_MODE);
if (ret < 0)
return ret;
vout_params = ret & GENMASK(4, 0);
switch (vout_params)
case XDPE122_PROT_VR12_5_10MV:
info->vrm_version[i] = vr13;
break;
case XDPE122_PROT_VR12_5MV:
info->vrm_version[i] = vr12;
break;
case XDPE122_PROT_IMVP9_10MV:
info->vrm_version[i] = imvp9;
break;
case XDPE122_AMD_625MV:
info->vrm_version[i] = amd625mv;
break;
default:
return -EINVAL;
return 0;
static struct pmbus_driver_info xdpe122_info =
.pages = XDPE122_PAGE_NUM,
.format[PSC_VOLTAGE_IN] = linear,
.format[PSC_VOLTAGE_OUT] = vid,
.format[PSC_TEMPERATURE] = linear,
.format[PSC_CURRENT_IN] = linear,
.format[PSC_CURRENT_OUT] = linear,
.format[PSC_POWER] = linear,
.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
.func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
.identify = xdpe122_identify,
.read_word_data = xdpe122_read_word_data,
;
static struct pmbus_driver_info xdpe132_info =
.pages = XDPE132_PAGE_NUM,
.format[PSC_VOLTAGE_IN] = linear,
.format[PSC_VOLTAGE_OUT] = linear,
.format[PSC_TEMPERATURE] = linear,
.format[PSC_CURRENT_IN] = linear,
.format[PSC_CURRENT_OUT] = linear,
.format[PSC_POWER] = linear,
.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
.func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
//.groups = xdpe132_attribute_groups,
;
static int32_t xdpe122_probe(struct i2c_client *client, const struct i2c_device_id *id)
struct pmbus_driver_info *info = NULL;
if (id->driver_data == xdpe12254 || id->driver_data == xdpe12284)
info = devm_kmemdup(&client->dev, &xdpe122_info, sizeof(*info), GFP_KERNEL);
else if (id->driver_data == xdpe132g5c)
info = devm_kmemdup(&client->dev, &xdpe132_info, sizeof(*info), GFP_KERNEL);
if (!info)
return -ENOMEM;
return pmbus_do_probe(client, id, info);
static const struct i2c_device_id xdpe1xx_id[] =
"xdpe12254", xdpe12254,
"xdpe12284", xdpe12284,
"xdpe132g5c", xdpe132g5c,
;
MODULE_DEVICE_TABLE(i2c, xdpe1xx_id);
static const struct of_device_id __maybe_unused xdpe122_of_match[] =
.compatible = "infineon,xdpe12254",
.compatible = "infineon,xdpe12284",
.compatible = "infineon,xdpe132g5c",
;
MODULE_DEVICE_TABLE(of, xdpe122_of_match);
static struct i2c_driver xdpe122_driver =
.driver =
.name = "xdpe12284",
.of_match_table = of_match_ptr(xdpe122_of_match),
,
.probe = xdpe122_probe,
.remove = pmbus_do_remove,
.id_table = xdpe1xx_id,
;
module_i2c_driver(xdpe122_driver);
MODULE_AUTHOR("Vadim Pasternak <vadimp@mellanox.com>");
MODULE_DESCRIPTION("PMBus driver for Infineon XDPE122 family");
MODULE_LICENSE("GPL");
zr_optoe.c
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/err.h>
#include <linux/timer.h>
#include <linux/timex.h>
#include <linux/rtc.h>
#include <linux/types.h>
#include "def.h"
#include "zr_optoe.h"
#define OPTOE_ARCH_PAGES 256
#define ONE_ADDR_EEPROM_SIZE ((1 + OPTOE_ARCH_PAGES) * OPTOE_PAGE_SIZE)
#define ONE_ADDR_EEPROM_UNPAGED_SIZE (2 * OPTOE_PAGE_SIZE)
#define TWO_ADDR_EEPROM_SIZE ((3 + OPTOE_ARCH_PAGES) * OPTOE_PAGE_SIZE)
#define TWO_ADDR_EEPROM_UNPAGED_SIZE (4 * OPTOE_PAGE_SIZE)
#define TWO_ADDR_NO_0X51_SIZE (2 * OPTOE_PAGE_SIZE)
#define OPTOE_PAGE_SELECT_REG 0x7F
#define ONE_ADDR_PAGEABLE_REG 0x02
#define QSFP_NOT_PAGEABLE BIT(2)
#define CMIS_NOT_PAGEABLE BIT(7)
#define TWO_ADDR_PAGEABLE_REG 0x40
#define TWO_ADDR_PAGEABLE BIT(4)
#define TWO_ADDR_0X51_REG 92
#define TWO_ADDR_0X51_SUPP BIT(6)
#define OPTOE_ID_REG 0
#define OPTOE_READ_OP 0
#define OPTOE_WRITE_OP 1
#define OPTOE_EOF 0 /* used for access beyond end of device */
#define COLOR_MODULE_STATUS 3
#define COLOR_POWER_SET 26
#define COLOR_ID 128
#define COLOR_VENDOR_NAME 129
#define COLOR_VENDOR_PN 148
#define COLOR_INT_FLAG_L 8 //8-9
#define COLOR_LOW_POWER_MODE 0x40
#define COLOR_HIGH_POWER_MODE 0x00
#define COLOR_TIME_SYNC_ENABLE 0x01
#define POWER_BIT_COLOR BIT(6)
#define WAVELEN_BIT_COLOR BIT(7)
#define LASER_BIT_COLOR BIT(6)
#define I2C_BUS_NUM_START 14
#define QSFP_PORT_NUM 16
#define QSFP_PORT_MASK 1
#define NODE_BASE_INFO "base_info"
#define NODE_TRQ_CLEAN "interrupt_clean"
#define NODE_WAVE_SWITCH "wavelength_switch"
#define NODE_DIAG_INFO "diag_information"
#define NODE_CAP_REPORT "capability_report"
#define NODE_FMEA_POLL "fmea_polling"
#define NODE_THRESHOLD_SET "threshold_setting"
#define HEX2DEC_2_BYTE_LEN 20
#define HEX2DEC_6_BYTE_LEN 20
#define HEX2DEC_16_BYTE_LEN 32
#define VIRTUAL_I2C_QSFP_PORT 16
#define VIRTUAL_I2C_SFP_PORT 0
#define SFF_PORT_TOTAL (VIRTUAL_I2C_QSFP_PORT + VIRTUAL_I2C_SFP_PORT)
#define ONE_ADDR 1
#define TWO_ADDR 2
#define CMIS_ADDR 3
#define TWO_ADDR_OFFSET 255
#define TWO_ADDR_SHIFT 256
#define USLEEP_LOW 1000
#define USLEEP_HIGH 2000
#define MSLEEP_INIT 5000
#define MSLEEP_THREAD 100
#define BYTE_1_LEN 1
#define BYTE_2_LEN 2
#define BYTE_4_LEN 4
#define BYTE_6_LEN 6
#define BYTE_16_LEN 16
#define BYTE_18_LEN 18
#define MONTH_MAX 12
#define MONTH_MIN 1
#define DAY_MAX 31
#define DAY_MIN 1
#define HOUR_MAX 23
#define MINUTE_MAX 59
#define SECOND_MAX 59
#define YEAR_BASE 1900
#define YEAR_FROM 2000
#define YEAR_REM 100
#define MONTH_BASE 1
#define YEAR_BIT 0
#define MONTH_BIT 1
#define DAY_BIT 2
#define HOUR_BIT 3
#define MINUTE_BIT 4
#define SECOND_BIT 5
#define MAX_PORT_NAME_LEN 20
#define PORT_NAME_LEN 12
#define LAST_1_BITS 0x01
#define LAST_7_BITS 0x7f
#define LAST_8_BITS 0xff
#define SHIFT_6_BITS 6
#define SHIFT_7_BITS以上是关于C5222的主要内容,如果未能解决你的问题,请参考以下文章