18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Hardware monitoring driver for Maxim MAX16064 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2011 Ericsson AB. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/kernel.h> 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/init.h> 118c2ecf20Sopenharmony_ci#include <linux/err.h> 128c2ecf20Sopenharmony_ci#include <linux/i2c.h> 138c2ecf20Sopenharmony_ci#include "pmbus.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define MAX16064_MFR_VOUT_PEAK 0xd4 168c2ecf20Sopenharmony_ci#define MAX16064_MFR_TEMPERATURE_PEAK 0xd6 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic int max16064_read_word_data(struct i2c_client *client, int page, 198c2ecf20Sopenharmony_ci int phase, int reg) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci int ret; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci switch (reg) { 248c2ecf20Sopenharmony_ci case PMBUS_VIRT_READ_VOUT_MAX: 258c2ecf20Sopenharmony_ci ret = pmbus_read_word_data(client, page, phase, 268c2ecf20Sopenharmony_ci MAX16064_MFR_VOUT_PEAK); 278c2ecf20Sopenharmony_ci break; 288c2ecf20Sopenharmony_ci case PMBUS_VIRT_READ_TEMP_MAX: 298c2ecf20Sopenharmony_ci ret = pmbus_read_word_data(client, page, phase, 308c2ecf20Sopenharmony_ci MAX16064_MFR_TEMPERATURE_PEAK); 318c2ecf20Sopenharmony_ci break; 328c2ecf20Sopenharmony_ci case PMBUS_VIRT_RESET_VOUT_HISTORY: 338c2ecf20Sopenharmony_ci case PMBUS_VIRT_RESET_TEMP_HISTORY: 348c2ecf20Sopenharmony_ci ret = 0; 358c2ecf20Sopenharmony_ci break; 368c2ecf20Sopenharmony_ci default: 378c2ecf20Sopenharmony_ci ret = -ENODATA; 388c2ecf20Sopenharmony_ci break; 398c2ecf20Sopenharmony_ci } 408c2ecf20Sopenharmony_ci return ret; 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic int max16064_write_word_data(struct i2c_client *client, int page, 448c2ecf20Sopenharmony_ci int reg, u16 word) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci int ret; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci switch (reg) { 498c2ecf20Sopenharmony_ci case PMBUS_VIRT_RESET_VOUT_HISTORY: 508c2ecf20Sopenharmony_ci ret = pmbus_write_word_data(client, page, 518c2ecf20Sopenharmony_ci MAX16064_MFR_VOUT_PEAK, 0); 528c2ecf20Sopenharmony_ci break; 538c2ecf20Sopenharmony_ci case PMBUS_VIRT_RESET_TEMP_HISTORY: 548c2ecf20Sopenharmony_ci ret = pmbus_write_word_data(client, page, 558c2ecf20Sopenharmony_ci MAX16064_MFR_TEMPERATURE_PEAK, 568c2ecf20Sopenharmony_ci 0xffff); 578c2ecf20Sopenharmony_ci break; 588c2ecf20Sopenharmony_ci default: 598c2ecf20Sopenharmony_ci ret = -ENODATA; 608c2ecf20Sopenharmony_ci break; 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci return ret; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic struct pmbus_driver_info max16064_info = { 668c2ecf20Sopenharmony_ci .pages = 4, 678c2ecf20Sopenharmony_ci .format[PSC_VOLTAGE_IN] = direct, 688c2ecf20Sopenharmony_ci .format[PSC_VOLTAGE_OUT] = direct, 698c2ecf20Sopenharmony_ci .format[PSC_TEMPERATURE] = direct, 708c2ecf20Sopenharmony_ci .m[PSC_VOLTAGE_IN] = 19995, 718c2ecf20Sopenharmony_ci .b[PSC_VOLTAGE_IN] = 0, 728c2ecf20Sopenharmony_ci .R[PSC_VOLTAGE_IN] = -1, 738c2ecf20Sopenharmony_ci .m[PSC_VOLTAGE_OUT] = 19995, 748c2ecf20Sopenharmony_ci .b[PSC_VOLTAGE_OUT] = 0, 758c2ecf20Sopenharmony_ci .R[PSC_VOLTAGE_OUT] = -1, 768c2ecf20Sopenharmony_ci .m[PSC_TEMPERATURE] = -7612, 778c2ecf20Sopenharmony_ci .b[PSC_TEMPERATURE] = 335, 788c2ecf20Sopenharmony_ci .R[PSC_TEMPERATURE] = -3, 798c2ecf20Sopenharmony_ci .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP 808c2ecf20Sopenharmony_ci | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP, 818c2ecf20Sopenharmony_ci .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT, 828c2ecf20Sopenharmony_ci .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT, 838c2ecf20Sopenharmony_ci .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT, 848c2ecf20Sopenharmony_ci .read_word_data = max16064_read_word_data, 858c2ecf20Sopenharmony_ci .write_word_data = max16064_write_word_data, 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic int max16064_probe(struct i2c_client *client) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci return pmbus_do_probe(client, &max16064_info); 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic const struct i2c_device_id max16064_id[] = { 948c2ecf20Sopenharmony_ci {"max16064", 0}, 958c2ecf20Sopenharmony_ci {} 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, max16064_id); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* This is the driver that will be inserted */ 1018c2ecf20Sopenharmony_cistatic struct i2c_driver max16064_driver = { 1028c2ecf20Sopenharmony_ci .driver = { 1038c2ecf20Sopenharmony_ci .name = "max16064", 1048c2ecf20Sopenharmony_ci }, 1058c2ecf20Sopenharmony_ci .probe_new = max16064_probe, 1068c2ecf20Sopenharmony_ci .remove = pmbus_do_remove, 1078c2ecf20Sopenharmony_ci .id_table = max16064_id, 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cimodule_i2c_driver(max16064_driver); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciMODULE_AUTHOR("Guenter Roeck"); 1138c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PMBus driver for Maxim MAX16064"); 1148c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 115