18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Intel BXT WhiskeyCove PMIC operation region driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2015 Intel Corporation. All rights reserved. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/init.h> 98c2ecf20Sopenharmony_ci#include <linux/acpi.h> 108c2ecf20Sopenharmony_ci#include <linux/mfd/intel_soc_pmic.h> 118c2ecf20Sopenharmony_ci#include <linux/regmap.h> 128c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 138c2ecf20Sopenharmony_ci#include "intel_pmic.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define WHISKEY_COVE_ALRT_HIGH_BIT_MASK 0x0F 168c2ecf20Sopenharmony_ci#define WHISKEY_COVE_ADC_HIGH_BIT(x) (((x & 0x0F) << 8)) 178c2ecf20Sopenharmony_ci#define WHISKEY_COVE_ADC_CURSRC(x) (((x & 0xF0) >> 4)) 188c2ecf20Sopenharmony_ci#define VR_MODE_DISABLED 0 198c2ecf20Sopenharmony_ci#define VR_MODE_AUTO BIT(0) 208c2ecf20Sopenharmony_ci#define VR_MODE_NORMAL BIT(1) 218c2ecf20Sopenharmony_ci#define VR_MODE_SWITCH BIT(2) 228c2ecf20Sopenharmony_ci#define VR_MODE_ECO (BIT(0)|BIT(1)) 238c2ecf20Sopenharmony_ci#define VSWITCH2_OUTPUT BIT(5) 248c2ecf20Sopenharmony_ci#define VSWITCH1_OUTPUT BIT(4) 258c2ecf20Sopenharmony_ci#define VUSBPHY_CHARGE BIT(1) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic struct pmic_table power_table[] = { 288c2ecf20Sopenharmony_ci { 298c2ecf20Sopenharmony_ci .address = 0x0, 308c2ecf20Sopenharmony_ci .reg = 0x63, 318c2ecf20Sopenharmony_ci .bit = VR_MODE_AUTO, 328c2ecf20Sopenharmony_ci }, /* VDD1 -> VDD1CNT */ 338c2ecf20Sopenharmony_ci { 348c2ecf20Sopenharmony_ci .address = 0x04, 358c2ecf20Sopenharmony_ci .reg = 0x65, 368c2ecf20Sopenharmony_ci .bit = VR_MODE_AUTO, 378c2ecf20Sopenharmony_ci }, /* VDD2 -> VDD2CNT */ 388c2ecf20Sopenharmony_ci { 398c2ecf20Sopenharmony_ci .address = 0x08, 408c2ecf20Sopenharmony_ci .reg = 0x67, 418c2ecf20Sopenharmony_ci .bit = VR_MODE_AUTO, 428c2ecf20Sopenharmony_ci }, /* VDD3 -> VDD3CNT */ 438c2ecf20Sopenharmony_ci { 448c2ecf20Sopenharmony_ci .address = 0x0c, 458c2ecf20Sopenharmony_ci .reg = 0x6d, 468c2ecf20Sopenharmony_ci .bit = VR_MODE_AUTO, 478c2ecf20Sopenharmony_ci }, /* VLFX -> VFLEXCNT */ 488c2ecf20Sopenharmony_ci { 498c2ecf20Sopenharmony_ci .address = 0x10, 508c2ecf20Sopenharmony_ci .reg = 0x6f, 518c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 528c2ecf20Sopenharmony_ci }, /* VP1A -> VPROG1ACNT */ 538c2ecf20Sopenharmony_ci { 548c2ecf20Sopenharmony_ci .address = 0x14, 558c2ecf20Sopenharmony_ci .reg = 0x70, 568c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 578c2ecf20Sopenharmony_ci }, /* VP1B -> VPROG1BCNT */ 588c2ecf20Sopenharmony_ci { 598c2ecf20Sopenharmony_ci .address = 0x18, 608c2ecf20Sopenharmony_ci .reg = 0x71, 618c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 628c2ecf20Sopenharmony_ci }, /* VP1C -> VPROG1CCNT */ 638c2ecf20Sopenharmony_ci { 648c2ecf20Sopenharmony_ci .address = 0x1c, 658c2ecf20Sopenharmony_ci .reg = 0x72, 668c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 678c2ecf20Sopenharmony_ci }, /* VP1D -> VPROG1DCNT */ 688c2ecf20Sopenharmony_ci { 698c2ecf20Sopenharmony_ci .address = 0x20, 708c2ecf20Sopenharmony_ci .reg = 0x73, 718c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 728c2ecf20Sopenharmony_ci }, /* VP2A -> VPROG2ACNT */ 738c2ecf20Sopenharmony_ci { 748c2ecf20Sopenharmony_ci .address = 0x24, 758c2ecf20Sopenharmony_ci .reg = 0x74, 768c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 778c2ecf20Sopenharmony_ci }, /* VP2B -> VPROG2BCNT */ 788c2ecf20Sopenharmony_ci { 798c2ecf20Sopenharmony_ci .address = 0x28, 808c2ecf20Sopenharmony_ci .reg = 0x75, 818c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 828c2ecf20Sopenharmony_ci }, /* VP2C -> VPROG2CCNT */ 838c2ecf20Sopenharmony_ci { 848c2ecf20Sopenharmony_ci .address = 0x2c, 858c2ecf20Sopenharmony_ci .reg = 0x76, 868c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 878c2ecf20Sopenharmony_ci }, /* VP3A -> VPROG3ACNT */ 888c2ecf20Sopenharmony_ci { 898c2ecf20Sopenharmony_ci .address = 0x30, 908c2ecf20Sopenharmony_ci .reg = 0x77, 918c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 928c2ecf20Sopenharmony_ci }, /* VP3B -> VPROG3BCNT */ 938c2ecf20Sopenharmony_ci { 948c2ecf20Sopenharmony_ci .address = 0x34, 958c2ecf20Sopenharmony_ci .reg = 0x78, 968c2ecf20Sopenharmony_ci .bit = VSWITCH2_OUTPUT, 978c2ecf20Sopenharmony_ci }, /* VSW2 -> VLD0CNT Bit 5*/ 988c2ecf20Sopenharmony_ci { 998c2ecf20Sopenharmony_ci .address = 0x38, 1008c2ecf20Sopenharmony_ci .reg = 0x78, 1018c2ecf20Sopenharmony_ci .bit = VSWITCH1_OUTPUT, 1028c2ecf20Sopenharmony_ci }, /* VSW1 -> VLD0CNT Bit 4 */ 1038c2ecf20Sopenharmony_ci { 1048c2ecf20Sopenharmony_ci .address = 0x3c, 1058c2ecf20Sopenharmony_ci .reg = 0x78, 1068c2ecf20Sopenharmony_ci .bit = VUSBPHY_CHARGE, 1078c2ecf20Sopenharmony_ci }, /* VUPY -> VLDOCNT Bit 1 */ 1088c2ecf20Sopenharmony_ci { 1098c2ecf20Sopenharmony_ci .address = 0x40, 1108c2ecf20Sopenharmony_ci .reg = 0x7b, 1118c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1128c2ecf20Sopenharmony_ci }, /* VRSO -> VREFSOCCNT*/ 1138c2ecf20Sopenharmony_ci { 1148c2ecf20Sopenharmony_ci .address = 0x44, 1158c2ecf20Sopenharmony_ci .reg = 0xA0, 1168c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1178c2ecf20Sopenharmony_ci }, /* VP1E -> VPROG1ECNT */ 1188c2ecf20Sopenharmony_ci { 1198c2ecf20Sopenharmony_ci .address = 0x48, 1208c2ecf20Sopenharmony_ci .reg = 0xA1, 1218c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1228c2ecf20Sopenharmony_ci }, /* VP1F -> VPROG1FCNT */ 1238c2ecf20Sopenharmony_ci { 1248c2ecf20Sopenharmony_ci .address = 0x4c, 1258c2ecf20Sopenharmony_ci .reg = 0xA2, 1268c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1278c2ecf20Sopenharmony_ci }, /* VP2D -> VPROG2DCNT */ 1288c2ecf20Sopenharmony_ci { 1298c2ecf20Sopenharmony_ci .address = 0x50, 1308c2ecf20Sopenharmony_ci .reg = 0xA3, 1318c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1328c2ecf20Sopenharmony_ci }, /* VP4A -> VPROG4ACNT */ 1338c2ecf20Sopenharmony_ci { 1348c2ecf20Sopenharmony_ci .address = 0x54, 1358c2ecf20Sopenharmony_ci .reg = 0xA4, 1368c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1378c2ecf20Sopenharmony_ci }, /* VP4B -> VPROG4BCNT */ 1388c2ecf20Sopenharmony_ci { 1398c2ecf20Sopenharmony_ci .address = 0x58, 1408c2ecf20Sopenharmony_ci .reg = 0xA5, 1418c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1428c2ecf20Sopenharmony_ci }, /* VP4C -> VPROG4CCNT */ 1438c2ecf20Sopenharmony_ci { 1448c2ecf20Sopenharmony_ci .address = 0x5c, 1458c2ecf20Sopenharmony_ci .reg = 0xA6, 1468c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1478c2ecf20Sopenharmony_ci }, /* VP4D -> VPROG4DCNT */ 1488c2ecf20Sopenharmony_ci { 1498c2ecf20Sopenharmony_ci .address = 0x60, 1508c2ecf20Sopenharmony_ci .reg = 0xA7, 1518c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1528c2ecf20Sopenharmony_ci }, /* VP5A -> VPROG5ACNT */ 1538c2ecf20Sopenharmony_ci { 1548c2ecf20Sopenharmony_ci .address = 0x64, 1558c2ecf20Sopenharmony_ci .reg = 0xA8, 1568c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1578c2ecf20Sopenharmony_ci }, /* VP5B -> VPROG5BCNT */ 1588c2ecf20Sopenharmony_ci { 1598c2ecf20Sopenharmony_ci .address = 0x68, 1608c2ecf20Sopenharmony_ci .reg = 0xA9, 1618c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1628c2ecf20Sopenharmony_ci }, /* VP6A -> VPROG6ACNT */ 1638c2ecf20Sopenharmony_ci { 1648c2ecf20Sopenharmony_ci .address = 0x6c, 1658c2ecf20Sopenharmony_ci .reg = 0xAA, 1668c2ecf20Sopenharmony_ci .bit = VR_MODE_NORMAL, 1678c2ecf20Sopenharmony_ci }, /* VP6B -> VPROG6BCNT */ 1688c2ecf20Sopenharmony_ci { 1698c2ecf20Sopenharmony_ci .address = 0x70, 1708c2ecf20Sopenharmony_ci .reg = 0x36, 1718c2ecf20Sopenharmony_ci .bit = BIT(2), 1728c2ecf20Sopenharmony_ci }, /* SDWN_N -> MODEMCTRL Bit 2 */ 1738c2ecf20Sopenharmony_ci { 1748c2ecf20Sopenharmony_ci .address = 0x74, 1758c2ecf20Sopenharmony_ci .reg = 0x36, 1768c2ecf20Sopenharmony_ci .bit = BIT(0), 1778c2ecf20Sopenharmony_ci } /* MOFF -> MODEMCTRL Bit 0 */ 1788c2ecf20Sopenharmony_ci}; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cistatic struct pmic_table thermal_table[] = { 1818c2ecf20Sopenharmony_ci { 1828c2ecf20Sopenharmony_ci .address = 0x00, 1838c2ecf20Sopenharmony_ci .reg = 0x4F39 1848c2ecf20Sopenharmony_ci }, 1858c2ecf20Sopenharmony_ci { 1868c2ecf20Sopenharmony_ci .address = 0x04, 1878c2ecf20Sopenharmony_ci .reg = 0x4F24 1888c2ecf20Sopenharmony_ci }, 1898c2ecf20Sopenharmony_ci { 1908c2ecf20Sopenharmony_ci .address = 0x08, 1918c2ecf20Sopenharmony_ci .reg = 0x4F26 1928c2ecf20Sopenharmony_ci }, 1938c2ecf20Sopenharmony_ci { 1948c2ecf20Sopenharmony_ci .address = 0x0c, 1958c2ecf20Sopenharmony_ci .reg = 0x4F3B 1968c2ecf20Sopenharmony_ci }, 1978c2ecf20Sopenharmony_ci { 1988c2ecf20Sopenharmony_ci .address = 0x10, 1998c2ecf20Sopenharmony_ci .reg = 0x4F28 2008c2ecf20Sopenharmony_ci }, 2018c2ecf20Sopenharmony_ci { 2028c2ecf20Sopenharmony_ci .address = 0x14, 2038c2ecf20Sopenharmony_ci .reg = 0x4F2A 2048c2ecf20Sopenharmony_ci }, 2058c2ecf20Sopenharmony_ci { 2068c2ecf20Sopenharmony_ci .address = 0x18, 2078c2ecf20Sopenharmony_ci .reg = 0x4F3D 2088c2ecf20Sopenharmony_ci }, 2098c2ecf20Sopenharmony_ci { 2108c2ecf20Sopenharmony_ci .address = 0x1c, 2118c2ecf20Sopenharmony_ci .reg = 0x4F2C 2128c2ecf20Sopenharmony_ci }, 2138c2ecf20Sopenharmony_ci { 2148c2ecf20Sopenharmony_ci .address = 0x20, 2158c2ecf20Sopenharmony_ci .reg = 0x4F2E 2168c2ecf20Sopenharmony_ci }, 2178c2ecf20Sopenharmony_ci { 2188c2ecf20Sopenharmony_ci .address = 0x24, 2198c2ecf20Sopenharmony_ci .reg = 0x4F3F 2208c2ecf20Sopenharmony_ci }, 2218c2ecf20Sopenharmony_ci { 2228c2ecf20Sopenharmony_ci .address = 0x28, 2238c2ecf20Sopenharmony_ci .reg = 0x4F30 2248c2ecf20Sopenharmony_ci }, 2258c2ecf20Sopenharmony_ci { 2268c2ecf20Sopenharmony_ci .address = 0x30, 2278c2ecf20Sopenharmony_ci .reg = 0x4F41 2288c2ecf20Sopenharmony_ci }, 2298c2ecf20Sopenharmony_ci { 2308c2ecf20Sopenharmony_ci .address = 0x34, 2318c2ecf20Sopenharmony_ci .reg = 0x4F32 2328c2ecf20Sopenharmony_ci }, 2338c2ecf20Sopenharmony_ci { 2348c2ecf20Sopenharmony_ci .address = 0x3c, 2358c2ecf20Sopenharmony_ci .reg = 0x4F43 2368c2ecf20Sopenharmony_ci }, 2378c2ecf20Sopenharmony_ci { 2388c2ecf20Sopenharmony_ci .address = 0x40, 2398c2ecf20Sopenharmony_ci .reg = 0x4F34 2408c2ecf20Sopenharmony_ci }, 2418c2ecf20Sopenharmony_ci { 2428c2ecf20Sopenharmony_ci .address = 0x48, 2438c2ecf20Sopenharmony_ci .reg = 0x4F6A, 2448c2ecf20Sopenharmony_ci .bit = 0, 2458c2ecf20Sopenharmony_ci }, 2468c2ecf20Sopenharmony_ci { 2478c2ecf20Sopenharmony_ci .address = 0x4C, 2488c2ecf20Sopenharmony_ci .reg = 0x4F6A, 2498c2ecf20Sopenharmony_ci .bit = 1 2508c2ecf20Sopenharmony_ci }, 2518c2ecf20Sopenharmony_ci { 2528c2ecf20Sopenharmony_ci .address = 0x50, 2538c2ecf20Sopenharmony_ci .reg = 0x4F6A, 2548c2ecf20Sopenharmony_ci .bit = 2 2558c2ecf20Sopenharmony_ci }, 2568c2ecf20Sopenharmony_ci { 2578c2ecf20Sopenharmony_ci .address = 0x54, 2588c2ecf20Sopenharmony_ci .reg = 0x4F6A, 2598c2ecf20Sopenharmony_ci .bit = 4 2608c2ecf20Sopenharmony_ci }, 2618c2ecf20Sopenharmony_ci { 2628c2ecf20Sopenharmony_ci .address = 0x58, 2638c2ecf20Sopenharmony_ci .reg = 0x4F6A, 2648c2ecf20Sopenharmony_ci .bit = 5 2658c2ecf20Sopenharmony_ci }, 2668c2ecf20Sopenharmony_ci { 2678c2ecf20Sopenharmony_ci .address = 0x5C, 2688c2ecf20Sopenharmony_ci .reg = 0x4F6A, 2698c2ecf20Sopenharmony_ci .bit = 3 2708c2ecf20Sopenharmony_ci }, 2718c2ecf20Sopenharmony_ci}; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_cistatic int intel_bxtwc_pmic_get_power(struct regmap *regmap, int reg, 2748c2ecf20Sopenharmony_ci int bit, u64 *value) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci int data; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci if (regmap_read(regmap, reg, &data)) 2798c2ecf20Sopenharmony_ci return -EIO; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci *value = (data & bit) ? 1 : 0; 2828c2ecf20Sopenharmony_ci return 0; 2838c2ecf20Sopenharmony_ci} 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistatic int intel_bxtwc_pmic_update_power(struct regmap *regmap, int reg, 2868c2ecf20Sopenharmony_ci int bit, bool on) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci u8 val, mask = bit; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci if (on) 2918c2ecf20Sopenharmony_ci val = 0xFF; 2928c2ecf20Sopenharmony_ci else 2938c2ecf20Sopenharmony_ci val = 0x0; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci return regmap_update_bits(regmap, reg, mask, val); 2968c2ecf20Sopenharmony_ci} 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_cistatic int intel_bxtwc_pmic_get_raw_temp(struct regmap *regmap, int reg) 2998c2ecf20Sopenharmony_ci{ 3008c2ecf20Sopenharmony_ci unsigned int val, adc_val, reg_val; 3018c2ecf20Sopenharmony_ci u8 temp_l, temp_h, cursrc; 3028c2ecf20Sopenharmony_ci unsigned long rlsb; 3038c2ecf20Sopenharmony_ci static const unsigned long rlsb_array[] = { 3048c2ecf20Sopenharmony_ci 0, 260420, 130210, 65100, 32550, 16280, 3058c2ecf20Sopenharmony_ci 8140, 4070, 2030, 0, 260420, 130210 }; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci if (regmap_read(regmap, reg, &val)) 3088c2ecf20Sopenharmony_ci return -EIO; 3098c2ecf20Sopenharmony_ci temp_l = (u8) val; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci if (regmap_read(regmap, (reg - 1), &val)) 3128c2ecf20Sopenharmony_ci return -EIO; 3138c2ecf20Sopenharmony_ci temp_h = (u8) val; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci reg_val = temp_l | WHISKEY_COVE_ADC_HIGH_BIT(temp_h); 3168c2ecf20Sopenharmony_ci cursrc = WHISKEY_COVE_ADC_CURSRC(temp_h); 3178c2ecf20Sopenharmony_ci rlsb = rlsb_array[cursrc]; 3188c2ecf20Sopenharmony_ci adc_val = reg_val * rlsb / 1000; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci return adc_val; 3218c2ecf20Sopenharmony_ci} 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistatic int 3248c2ecf20Sopenharmony_ciintel_bxtwc_pmic_update_aux(struct regmap *regmap, int reg, int raw) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci u32 bsr_num; 3278c2ecf20Sopenharmony_ci u16 resi_val, count = 0, thrsh = 0; 3288c2ecf20Sopenharmony_ci u8 alrt_h, alrt_l, cursel = 0; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci bsr_num = raw; 3318c2ecf20Sopenharmony_ci bsr_num /= (1 << 5); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci count = fls(bsr_num) - 1; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci cursel = clamp_t(s8, (count - 7), 0, 7); 3368c2ecf20Sopenharmony_ci thrsh = raw / (1 << (4 + cursel)); 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci resi_val = (cursel << 9) | thrsh; 3398c2ecf20Sopenharmony_ci alrt_h = (resi_val >> 8) & WHISKEY_COVE_ALRT_HIGH_BIT_MASK; 3408c2ecf20Sopenharmony_ci if (regmap_update_bits(regmap, 3418c2ecf20Sopenharmony_ci reg - 1, 3428c2ecf20Sopenharmony_ci WHISKEY_COVE_ALRT_HIGH_BIT_MASK, 3438c2ecf20Sopenharmony_ci alrt_h)) 3448c2ecf20Sopenharmony_ci return -EIO; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci alrt_l = (u8)resi_val; 3478c2ecf20Sopenharmony_ci return regmap_write(regmap, reg, alrt_l); 3488c2ecf20Sopenharmony_ci} 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_cistatic int 3518c2ecf20Sopenharmony_ciintel_bxtwc_pmic_get_policy(struct regmap *regmap, int reg, int bit, u64 *value) 3528c2ecf20Sopenharmony_ci{ 3538c2ecf20Sopenharmony_ci u8 mask = BIT(bit); 3548c2ecf20Sopenharmony_ci unsigned int val; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci if (regmap_read(regmap, reg, &val)) 3578c2ecf20Sopenharmony_ci return -EIO; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci *value = (val & mask) >> bit; 3608c2ecf20Sopenharmony_ci return 0; 3618c2ecf20Sopenharmony_ci} 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_cistatic int 3648c2ecf20Sopenharmony_ciintel_bxtwc_pmic_update_policy(struct regmap *regmap, 3658c2ecf20Sopenharmony_ci int reg, int bit, int enable) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci u8 mask = BIT(bit), val = enable << bit; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci return regmap_update_bits(regmap, reg, mask, val); 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistatic struct intel_pmic_opregion_data intel_bxtwc_pmic_opregion_data = { 3738c2ecf20Sopenharmony_ci .get_power = intel_bxtwc_pmic_get_power, 3748c2ecf20Sopenharmony_ci .update_power = intel_bxtwc_pmic_update_power, 3758c2ecf20Sopenharmony_ci .get_raw_temp = intel_bxtwc_pmic_get_raw_temp, 3768c2ecf20Sopenharmony_ci .update_aux = intel_bxtwc_pmic_update_aux, 3778c2ecf20Sopenharmony_ci .get_policy = intel_bxtwc_pmic_get_policy, 3788c2ecf20Sopenharmony_ci .update_policy = intel_bxtwc_pmic_update_policy, 3798c2ecf20Sopenharmony_ci .power_table = power_table, 3808c2ecf20Sopenharmony_ci .power_table_count = ARRAY_SIZE(power_table), 3818c2ecf20Sopenharmony_ci .thermal_table = thermal_table, 3828c2ecf20Sopenharmony_ci .thermal_table_count = ARRAY_SIZE(thermal_table), 3838c2ecf20Sopenharmony_ci}; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_cistatic int intel_bxtwc_pmic_opregion_probe(struct platform_device *pdev) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci return intel_pmic_install_opregion_handler(&pdev->dev, 3908c2ecf20Sopenharmony_ci ACPI_HANDLE(pdev->dev.parent), 3918c2ecf20Sopenharmony_ci pmic->regmap, 3928c2ecf20Sopenharmony_ci &intel_bxtwc_pmic_opregion_data); 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_cistatic const struct platform_device_id bxt_wc_opregion_id_table[] = { 3968c2ecf20Sopenharmony_ci { .name = "bxt_wcove_region" }, 3978c2ecf20Sopenharmony_ci {}, 3988c2ecf20Sopenharmony_ci}; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistatic struct platform_driver intel_bxtwc_pmic_opregion_driver = { 4018c2ecf20Sopenharmony_ci .probe = intel_bxtwc_pmic_opregion_probe, 4028c2ecf20Sopenharmony_ci .driver = { 4038c2ecf20Sopenharmony_ci .name = "bxt_whiskey_cove_pmic", 4048c2ecf20Sopenharmony_ci }, 4058c2ecf20Sopenharmony_ci .id_table = bxt_wc_opregion_id_table, 4068c2ecf20Sopenharmony_ci}; 4078c2ecf20Sopenharmony_cibuiltin_platform_driver(intel_bxtwc_pmic_opregion_driver); 408