18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Dollar Cove TI PMIC operation region driver 48c2ecf20Sopenharmony_ci * Copyright (C) 2014 Intel Corporation. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Rewritten and cleaned up 78c2ecf20Sopenharmony_ci * Copyright (C) 2017 Takashi Iwai <tiwai@suse.de> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/acpi.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/mfd/intel_soc_pmic.h> 138c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 148c2ecf20Sopenharmony_ci#include "intel_pmic.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* registers stored in 16bit BE (high:low, total 10bit) */ 178c2ecf20Sopenharmony_ci#define CHTDC_TI_VBAT 0x54 188c2ecf20Sopenharmony_ci#define CHTDC_TI_DIETEMP 0x56 198c2ecf20Sopenharmony_ci#define CHTDC_TI_BPTHERM 0x58 208c2ecf20Sopenharmony_ci#define CHTDC_TI_GPADC 0x5a 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic struct pmic_table chtdc_ti_power_table[] = { 238c2ecf20Sopenharmony_ci { .address = 0x00, .reg = 0x41 }, 248c2ecf20Sopenharmony_ci { .address = 0x04, .reg = 0x42 }, 258c2ecf20Sopenharmony_ci { .address = 0x08, .reg = 0x43 }, 268c2ecf20Sopenharmony_ci { .address = 0x0c, .reg = 0x45 }, 278c2ecf20Sopenharmony_ci { .address = 0x10, .reg = 0x46 }, 288c2ecf20Sopenharmony_ci { .address = 0x14, .reg = 0x47 }, 298c2ecf20Sopenharmony_ci { .address = 0x18, .reg = 0x48 }, 308c2ecf20Sopenharmony_ci { .address = 0x1c, .reg = 0x49 }, 318c2ecf20Sopenharmony_ci { .address = 0x20, .reg = 0x4a }, 328c2ecf20Sopenharmony_ci { .address = 0x24, .reg = 0x4b }, 338c2ecf20Sopenharmony_ci { .address = 0x28, .reg = 0x4c }, 348c2ecf20Sopenharmony_ci { .address = 0x2c, .reg = 0x4d }, 358c2ecf20Sopenharmony_ci { .address = 0x30, .reg = 0x4e }, 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic struct pmic_table chtdc_ti_thermal_table[] = { 398c2ecf20Sopenharmony_ci { 408c2ecf20Sopenharmony_ci .address = 0x00, 418c2ecf20Sopenharmony_ci .reg = CHTDC_TI_GPADC 428c2ecf20Sopenharmony_ci }, 438c2ecf20Sopenharmony_ci { 448c2ecf20Sopenharmony_ci .address = 0x0c, 458c2ecf20Sopenharmony_ci .reg = CHTDC_TI_GPADC 468c2ecf20Sopenharmony_ci }, 478c2ecf20Sopenharmony_ci /* TMP2 -> SYSTEMP */ 488c2ecf20Sopenharmony_ci { 498c2ecf20Sopenharmony_ci .address = 0x18, 508c2ecf20Sopenharmony_ci .reg = CHTDC_TI_GPADC 518c2ecf20Sopenharmony_ci }, 528c2ecf20Sopenharmony_ci /* TMP3 -> BPTHERM */ 538c2ecf20Sopenharmony_ci { 548c2ecf20Sopenharmony_ci .address = 0x24, 558c2ecf20Sopenharmony_ci .reg = CHTDC_TI_BPTHERM 568c2ecf20Sopenharmony_ci }, 578c2ecf20Sopenharmony_ci { 588c2ecf20Sopenharmony_ci .address = 0x30, 598c2ecf20Sopenharmony_ci .reg = CHTDC_TI_GPADC 608c2ecf20Sopenharmony_ci }, 618c2ecf20Sopenharmony_ci /* TMP5 -> DIETEMP */ 628c2ecf20Sopenharmony_ci { 638c2ecf20Sopenharmony_ci .address = 0x3c, 648c2ecf20Sopenharmony_ci .reg = CHTDC_TI_DIETEMP 658c2ecf20Sopenharmony_ci }, 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic int chtdc_ti_pmic_get_power(struct regmap *regmap, int reg, int bit, 698c2ecf20Sopenharmony_ci u64 *value) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci int data; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci if (regmap_read(regmap, reg, &data)) 748c2ecf20Sopenharmony_ci return -EIO; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci *value = data & 1; 778c2ecf20Sopenharmony_ci return 0; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic int chtdc_ti_pmic_update_power(struct regmap *regmap, int reg, int bit, 818c2ecf20Sopenharmony_ci bool on) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci return regmap_update_bits(regmap, reg, 1, on); 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic int chtdc_ti_pmic_get_raw_temp(struct regmap *regmap, int reg) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci u8 buf[2]; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci if (regmap_bulk_read(regmap, reg, buf, 2)) 918c2ecf20Sopenharmony_ci return -EIO; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci /* stored in big-endian */ 948c2ecf20Sopenharmony_ci return ((buf[0] & 0x03) << 8) | buf[1]; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic struct intel_pmic_opregion_data chtdc_ti_pmic_opregion_data = { 988c2ecf20Sopenharmony_ci .get_power = chtdc_ti_pmic_get_power, 998c2ecf20Sopenharmony_ci .update_power = chtdc_ti_pmic_update_power, 1008c2ecf20Sopenharmony_ci .get_raw_temp = chtdc_ti_pmic_get_raw_temp, 1018c2ecf20Sopenharmony_ci .power_table = chtdc_ti_power_table, 1028c2ecf20Sopenharmony_ci .power_table_count = ARRAY_SIZE(chtdc_ti_power_table), 1038c2ecf20Sopenharmony_ci .thermal_table = chtdc_ti_thermal_table, 1048c2ecf20Sopenharmony_ci .thermal_table_count = ARRAY_SIZE(chtdc_ti_thermal_table), 1058c2ecf20Sopenharmony_ci .pmic_i2c_address = 0x5e, 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic int chtdc_ti_pmic_opregion_probe(struct platform_device *pdev) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); 1118c2ecf20Sopenharmony_ci int err; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci err = intel_pmic_install_opregion_handler(&pdev->dev, 1148c2ecf20Sopenharmony_ci ACPI_HANDLE(pdev->dev.parent), pmic->regmap, 1158c2ecf20Sopenharmony_ci &chtdc_ti_pmic_opregion_data); 1168c2ecf20Sopenharmony_ci if (err < 0) 1178c2ecf20Sopenharmony_ci return err; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci /* Re-enumerate devices depending on PMIC */ 1208c2ecf20Sopenharmony_ci acpi_walk_dep_device_list(ACPI_HANDLE(pdev->dev.parent)); 1218c2ecf20Sopenharmony_ci return 0; 1228c2ecf20Sopenharmony_ci} 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic const struct platform_device_id chtdc_ti_pmic_opregion_id_table[] = { 1258c2ecf20Sopenharmony_ci { .name = "chtdc_ti_region" }, 1268c2ecf20Sopenharmony_ci {}, 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic struct platform_driver chtdc_ti_pmic_opregion_driver = { 1308c2ecf20Sopenharmony_ci .probe = chtdc_ti_pmic_opregion_probe, 1318c2ecf20Sopenharmony_ci .driver = { 1328c2ecf20Sopenharmony_ci .name = "cht_dollar_cove_ti_pmic", 1338c2ecf20Sopenharmony_ci }, 1348c2ecf20Sopenharmony_ci .id_table = chtdc_ti_pmic_opregion_id_table, 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_cibuiltin_platform_driver(chtdc_ti_pmic_opregion_driver); 137