18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// max8997.c - mfd core driver for the Maxim 8966 and 8997 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright (C) 2011 Samsung Electronics 68c2ecf20Sopenharmony_ci// MyungJoo Ham <myungjoo.ham@samsung.com> 78c2ecf20Sopenharmony_ci// 88c2ecf20Sopenharmony_ci// This driver is based on max8998.c 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/err.h> 118c2ecf20Sopenharmony_ci#include <linux/slab.h> 128c2ecf20Sopenharmony_ci#include <linux/i2c.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/of_irq.h> 158c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 168c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 178c2ecf20Sopenharmony_ci#include <linux/init.h> 188c2ecf20Sopenharmony_ci#include <linux/mutex.h> 198c2ecf20Sopenharmony_ci#include <linux/mfd/core.h> 208c2ecf20Sopenharmony_ci#include <linux/mfd/max8997.h> 218c2ecf20Sopenharmony_ci#include <linux/mfd/max8997-private.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define I2C_ADDR_PMIC (0xCC >> 1) 248c2ecf20Sopenharmony_ci#define I2C_ADDR_MUIC (0x4A >> 1) 258c2ecf20Sopenharmony_ci#define I2C_ADDR_BATTERY (0x6C >> 1) 268c2ecf20Sopenharmony_ci#define I2C_ADDR_RTC (0x0C >> 1) 278c2ecf20Sopenharmony_ci#define I2C_ADDR_HAPTIC (0x90 >> 1) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic const struct mfd_cell max8997_devs[] = { 308c2ecf20Sopenharmony_ci { .name = "max8997-pmic", }, 318c2ecf20Sopenharmony_ci { .name = "max8997-rtc", }, 328c2ecf20Sopenharmony_ci { .name = "max8997-battery", }, 338c2ecf20Sopenharmony_ci { .name = "max8997-haptic", }, 348c2ecf20Sopenharmony_ci { .name = "max8997-muic", }, 358c2ecf20Sopenharmony_ci { .name = "max8997-led", .id = 1 }, 368c2ecf20Sopenharmony_ci { .name = "max8997-led", .id = 2 }, 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 408c2ecf20Sopenharmony_cistatic const struct of_device_id max8997_pmic_dt_match[] = { 418c2ecf20Sopenharmony_ci { .compatible = "maxim,max8997-pmic", .data = (void *)TYPE_MAX8997 }, 428c2ecf20Sopenharmony_ci {}, 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci#endif 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciint max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 498c2ecf20Sopenharmony_ci int ret; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci mutex_lock(&max8997->iolock); 528c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(i2c, reg); 538c2ecf20Sopenharmony_ci mutex_unlock(&max8997->iolock); 548c2ecf20Sopenharmony_ci if (ret < 0) 558c2ecf20Sopenharmony_ci return ret; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci ret &= 0xff; 588c2ecf20Sopenharmony_ci *dest = ret; 598c2ecf20Sopenharmony_ci return 0; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(max8997_read_reg); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciint max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 668c2ecf20Sopenharmony_ci int ret; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci mutex_lock(&max8997->iolock); 698c2ecf20Sopenharmony_ci ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf); 708c2ecf20Sopenharmony_ci mutex_unlock(&max8997->iolock); 718c2ecf20Sopenharmony_ci if (ret < 0) 728c2ecf20Sopenharmony_ci return ret; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(max8997_bulk_read); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciint max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 818c2ecf20Sopenharmony_ci int ret; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci mutex_lock(&max8997->iolock); 848c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(i2c, reg, value); 858c2ecf20Sopenharmony_ci mutex_unlock(&max8997->iolock); 868c2ecf20Sopenharmony_ci return ret; 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(max8997_write_reg); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ciint max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 938c2ecf20Sopenharmony_ci int ret; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci mutex_lock(&max8997->iolock); 968c2ecf20Sopenharmony_ci ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf); 978c2ecf20Sopenharmony_ci mutex_unlock(&max8997->iolock); 988c2ecf20Sopenharmony_ci if (ret < 0) 998c2ecf20Sopenharmony_ci return ret; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci return 0; 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(max8997_bulk_write); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciint max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 1088c2ecf20Sopenharmony_ci int ret; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci mutex_lock(&max8997->iolock); 1118c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(i2c, reg); 1128c2ecf20Sopenharmony_ci if (ret >= 0) { 1138c2ecf20Sopenharmony_ci u8 old_val = ret & 0xff; 1148c2ecf20Sopenharmony_ci u8 new_val = (val & mask) | (old_val & (~mask)); 1158c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(i2c, reg, new_val); 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci mutex_unlock(&max8997->iolock); 1188c2ecf20Sopenharmony_ci return ret; 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(max8997_update_reg); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* 1238c2ecf20Sopenharmony_ci * Only the common platform data elements for max8997 are parsed here from the 1248c2ecf20Sopenharmony_ci * device tree. Other sub-modules of max8997 such as pmic, rtc and others have 1258c2ecf20Sopenharmony_ci * to parse their own platform data elements from device tree. 1268c2ecf20Sopenharmony_ci * 1278c2ecf20Sopenharmony_ci * The max8997 platform data structure is instantiated here and the drivers for 1288c2ecf20Sopenharmony_ci * the sub-modules need not instantiate another instance while parsing their 1298c2ecf20Sopenharmony_ci * platform data. 1308c2ecf20Sopenharmony_ci */ 1318c2ecf20Sopenharmony_cistatic struct max8997_platform_data *max8997_i2c_parse_dt_pdata( 1328c2ecf20Sopenharmony_ci struct device *dev) 1338c2ecf20Sopenharmony_ci{ 1348c2ecf20Sopenharmony_ci struct max8997_platform_data *pd; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); 1378c2ecf20Sopenharmony_ci if (!pd) 1388c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci pd->ono = irq_of_parse_and_map(dev->of_node, 1); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci return pd; 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistatic inline unsigned long max8997_i2c_get_driver_data(struct i2c_client *i2c, 1468c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { 1498c2ecf20Sopenharmony_ci const struct of_device_id *match; 1508c2ecf20Sopenharmony_ci match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node); 1518c2ecf20Sopenharmony_ci return (unsigned long)match->data; 1528c2ecf20Sopenharmony_ci } 1538c2ecf20Sopenharmony_ci return id->driver_data; 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistatic int max8997_i2c_probe(struct i2c_client *i2c, 1578c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 1588c2ecf20Sopenharmony_ci{ 1598c2ecf20Sopenharmony_ci struct max8997_dev *max8997; 1608c2ecf20Sopenharmony_ci struct max8997_platform_data *pdata = dev_get_platdata(&i2c->dev); 1618c2ecf20Sopenharmony_ci int ret = 0; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci max8997 = devm_kzalloc(&i2c->dev, sizeof(struct max8997_dev), 1648c2ecf20Sopenharmony_ci GFP_KERNEL); 1658c2ecf20Sopenharmony_ci if (max8997 == NULL) 1668c2ecf20Sopenharmony_ci return -ENOMEM; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci i2c_set_clientdata(i2c, max8997); 1698c2ecf20Sopenharmony_ci max8997->dev = &i2c->dev; 1708c2ecf20Sopenharmony_ci max8997->i2c = i2c; 1718c2ecf20Sopenharmony_ci max8997->type = max8997_i2c_get_driver_data(i2c, id); 1728c2ecf20Sopenharmony_ci max8997->irq = i2c->irq; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_OF) && max8997->dev->of_node) { 1758c2ecf20Sopenharmony_ci pdata = max8997_i2c_parse_dt_pdata(max8997->dev); 1768c2ecf20Sopenharmony_ci if (IS_ERR(pdata)) 1778c2ecf20Sopenharmony_ci return PTR_ERR(pdata); 1788c2ecf20Sopenharmony_ci } 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci if (!pdata) 1818c2ecf20Sopenharmony_ci return ret; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci max8997->pdata = pdata; 1848c2ecf20Sopenharmony_ci max8997->ono = pdata->ono; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci mutex_init(&max8997->iolock); 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci max8997->rtc = i2c_new_dummy_device(i2c->adapter, I2C_ADDR_RTC); 1898c2ecf20Sopenharmony_ci if (IS_ERR(max8997->rtc)) { 1908c2ecf20Sopenharmony_ci dev_err(max8997->dev, "Failed to allocate I2C device for RTC\n"); 1918c2ecf20Sopenharmony_ci return PTR_ERR(max8997->rtc); 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci i2c_set_clientdata(max8997->rtc, max8997); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci max8997->haptic = i2c_new_dummy_device(i2c->adapter, I2C_ADDR_HAPTIC); 1968c2ecf20Sopenharmony_ci if (IS_ERR(max8997->haptic)) { 1978c2ecf20Sopenharmony_ci dev_err(max8997->dev, "Failed to allocate I2C device for Haptic\n"); 1988c2ecf20Sopenharmony_ci ret = PTR_ERR(max8997->haptic); 1998c2ecf20Sopenharmony_ci goto err_i2c_haptic; 2008c2ecf20Sopenharmony_ci } 2018c2ecf20Sopenharmony_ci i2c_set_clientdata(max8997->haptic, max8997); 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci max8997->muic = i2c_new_dummy_device(i2c->adapter, I2C_ADDR_MUIC); 2048c2ecf20Sopenharmony_ci if (IS_ERR(max8997->muic)) { 2058c2ecf20Sopenharmony_ci dev_err(max8997->dev, "Failed to allocate I2C device for MUIC\n"); 2068c2ecf20Sopenharmony_ci ret = PTR_ERR(max8997->muic); 2078c2ecf20Sopenharmony_ci goto err_i2c_muic; 2088c2ecf20Sopenharmony_ci } 2098c2ecf20Sopenharmony_ci i2c_set_clientdata(max8997->muic, max8997); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci pm_runtime_set_active(max8997->dev); 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci max8997_irq_init(max8997); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci ret = mfd_add_devices(max8997->dev, -1, max8997_devs, 2168c2ecf20Sopenharmony_ci ARRAY_SIZE(max8997_devs), 2178c2ecf20Sopenharmony_ci NULL, 0, NULL); 2188c2ecf20Sopenharmony_ci if (ret < 0) { 2198c2ecf20Sopenharmony_ci dev_err(max8997->dev, "failed to add MFD devices %d\n", ret); 2208c2ecf20Sopenharmony_ci goto err_mfd; 2218c2ecf20Sopenharmony_ci } 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci /* 2248c2ecf20Sopenharmony_ci * TODO: enable others (flash, muic, rtc, battery, ...) and 2258c2ecf20Sopenharmony_ci * check the return value 2268c2ecf20Sopenharmony_ci */ 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci /* MAX8997 has a power button input. */ 2298c2ecf20Sopenharmony_ci device_init_wakeup(max8997->dev, true); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci return ret; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cierr_mfd: 2348c2ecf20Sopenharmony_ci mfd_remove_devices(max8997->dev); 2358c2ecf20Sopenharmony_ci i2c_unregister_device(max8997->muic); 2368c2ecf20Sopenharmony_cierr_i2c_muic: 2378c2ecf20Sopenharmony_ci i2c_unregister_device(max8997->haptic); 2388c2ecf20Sopenharmony_cierr_i2c_haptic: 2398c2ecf20Sopenharmony_ci i2c_unregister_device(max8997->rtc); 2408c2ecf20Sopenharmony_ci return ret; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic const struct i2c_device_id max8997_i2c_id[] = { 2448c2ecf20Sopenharmony_ci { "max8997", TYPE_MAX8997 }, 2458c2ecf20Sopenharmony_ci { "max8966", TYPE_MAX8966 }, 2468c2ecf20Sopenharmony_ci { } 2478c2ecf20Sopenharmony_ci}; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic u8 max8997_dumpaddr_pmic[] = { 2508c2ecf20Sopenharmony_ci MAX8997_REG_INT1MSK, 2518c2ecf20Sopenharmony_ci MAX8997_REG_INT2MSK, 2528c2ecf20Sopenharmony_ci MAX8997_REG_INT3MSK, 2538c2ecf20Sopenharmony_ci MAX8997_REG_INT4MSK, 2548c2ecf20Sopenharmony_ci MAX8997_REG_MAINCON1, 2558c2ecf20Sopenharmony_ci MAX8997_REG_MAINCON2, 2568c2ecf20Sopenharmony_ci MAX8997_REG_BUCKRAMP, 2578c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1CTRL, 2588c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS1, 2598c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS2, 2608c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS3, 2618c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS4, 2628c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS5, 2638c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS6, 2648c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS7, 2658c2ecf20Sopenharmony_ci MAX8997_REG_BUCK1DVS8, 2668c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2CTRL, 2678c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS1, 2688c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS2, 2698c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS3, 2708c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS4, 2718c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS5, 2728c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS6, 2738c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS7, 2748c2ecf20Sopenharmony_ci MAX8997_REG_BUCK2DVS8, 2758c2ecf20Sopenharmony_ci MAX8997_REG_BUCK3CTRL, 2768c2ecf20Sopenharmony_ci MAX8997_REG_BUCK3DVS, 2778c2ecf20Sopenharmony_ci MAX8997_REG_BUCK4CTRL, 2788c2ecf20Sopenharmony_ci MAX8997_REG_BUCK4DVS, 2798c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5CTRL, 2808c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS1, 2818c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS2, 2828c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS3, 2838c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS4, 2848c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS5, 2858c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS6, 2868c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS7, 2878c2ecf20Sopenharmony_ci MAX8997_REG_BUCK5DVS8, 2888c2ecf20Sopenharmony_ci MAX8997_REG_BUCK6CTRL, 2898c2ecf20Sopenharmony_ci MAX8997_REG_BUCK6BPSKIPCTRL, 2908c2ecf20Sopenharmony_ci MAX8997_REG_BUCK7CTRL, 2918c2ecf20Sopenharmony_ci MAX8997_REG_BUCK7DVS, 2928c2ecf20Sopenharmony_ci MAX8997_REG_LDO1CTRL, 2938c2ecf20Sopenharmony_ci MAX8997_REG_LDO2CTRL, 2948c2ecf20Sopenharmony_ci MAX8997_REG_LDO3CTRL, 2958c2ecf20Sopenharmony_ci MAX8997_REG_LDO4CTRL, 2968c2ecf20Sopenharmony_ci MAX8997_REG_LDO5CTRL, 2978c2ecf20Sopenharmony_ci MAX8997_REG_LDO6CTRL, 2988c2ecf20Sopenharmony_ci MAX8997_REG_LDO7CTRL, 2998c2ecf20Sopenharmony_ci MAX8997_REG_LDO8CTRL, 3008c2ecf20Sopenharmony_ci MAX8997_REG_LDO9CTRL, 3018c2ecf20Sopenharmony_ci MAX8997_REG_LDO10CTRL, 3028c2ecf20Sopenharmony_ci MAX8997_REG_LDO11CTRL, 3038c2ecf20Sopenharmony_ci MAX8997_REG_LDO12CTRL, 3048c2ecf20Sopenharmony_ci MAX8997_REG_LDO13CTRL, 3058c2ecf20Sopenharmony_ci MAX8997_REG_LDO14CTRL, 3068c2ecf20Sopenharmony_ci MAX8997_REG_LDO15CTRL, 3078c2ecf20Sopenharmony_ci MAX8997_REG_LDO16CTRL, 3088c2ecf20Sopenharmony_ci MAX8997_REG_LDO17CTRL, 3098c2ecf20Sopenharmony_ci MAX8997_REG_LDO18CTRL, 3108c2ecf20Sopenharmony_ci MAX8997_REG_LDO21CTRL, 3118c2ecf20Sopenharmony_ci MAX8997_REG_MBCCTRL1, 3128c2ecf20Sopenharmony_ci MAX8997_REG_MBCCTRL2, 3138c2ecf20Sopenharmony_ci MAX8997_REG_MBCCTRL3, 3148c2ecf20Sopenharmony_ci MAX8997_REG_MBCCTRL4, 3158c2ecf20Sopenharmony_ci MAX8997_REG_MBCCTRL5, 3168c2ecf20Sopenharmony_ci MAX8997_REG_MBCCTRL6, 3178c2ecf20Sopenharmony_ci MAX8997_REG_OTPCGHCVS, 3188c2ecf20Sopenharmony_ci MAX8997_REG_SAFEOUTCTRL, 3198c2ecf20Sopenharmony_ci MAX8997_REG_LBCNFG1, 3208c2ecf20Sopenharmony_ci MAX8997_REG_LBCNFG2, 3218c2ecf20Sopenharmony_ci MAX8997_REG_BBCCTRL, 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci MAX8997_REG_FLASH1_CUR, 3248c2ecf20Sopenharmony_ci MAX8997_REG_FLASH2_CUR, 3258c2ecf20Sopenharmony_ci MAX8997_REG_MOVIE_CUR, 3268c2ecf20Sopenharmony_ci MAX8997_REG_GSMB_CUR, 3278c2ecf20Sopenharmony_ci MAX8997_REG_BOOST_CNTL, 3288c2ecf20Sopenharmony_ci MAX8997_REG_LEN_CNTL, 3298c2ecf20Sopenharmony_ci MAX8997_REG_FLASH_CNTL, 3308c2ecf20Sopenharmony_ci MAX8997_REG_WDT_CNTL, 3318c2ecf20Sopenharmony_ci MAX8997_REG_MAXFLASH1, 3328c2ecf20Sopenharmony_ci MAX8997_REG_MAXFLASH2, 3338c2ecf20Sopenharmony_ci MAX8997_REG_FLASHSTATUSMASK, 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL1, 3368c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL2, 3378c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL3, 3388c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL4, 3398c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL5, 3408c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL6, 3418c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL7, 3428c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL8, 3438c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL9, 3448c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL10, 3458c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL11, 3468c2ecf20Sopenharmony_ci MAX8997_REG_GPIOCNTL12, 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci MAX8997_REG_LDO1CONFIG, 3498c2ecf20Sopenharmony_ci MAX8997_REG_LDO2CONFIG, 3508c2ecf20Sopenharmony_ci MAX8997_REG_LDO3CONFIG, 3518c2ecf20Sopenharmony_ci MAX8997_REG_LDO4CONFIG, 3528c2ecf20Sopenharmony_ci MAX8997_REG_LDO5CONFIG, 3538c2ecf20Sopenharmony_ci MAX8997_REG_LDO6CONFIG, 3548c2ecf20Sopenharmony_ci MAX8997_REG_LDO7CONFIG, 3558c2ecf20Sopenharmony_ci MAX8997_REG_LDO8CONFIG, 3568c2ecf20Sopenharmony_ci MAX8997_REG_LDO9CONFIG, 3578c2ecf20Sopenharmony_ci MAX8997_REG_LDO10CONFIG, 3588c2ecf20Sopenharmony_ci MAX8997_REG_LDO11CONFIG, 3598c2ecf20Sopenharmony_ci MAX8997_REG_LDO12CONFIG, 3608c2ecf20Sopenharmony_ci MAX8997_REG_LDO13CONFIG, 3618c2ecf20Sopenharmony_ci MAX8997_REG_LDO14CONFIG, 3628c2ecf20Sopenharmony_ci MAX8997_REG_LDO15CONFIG, 3638c2ecf20Sopenharmony_ci MAX8997_REG_LDO16CONFIG, 3648c2ecf20Sopenharmony_ci MAX8997_REG_LDO17CONFIG, 3658c2ecf20Sopenharmony_ci MAX8997_REG_LDO18CONFIG, 3668c2ecf20Sopenharmony_ci MAX8997_REG_LDO21CONFIG, 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci MAX8997_REG_DVSOKTIMER1, 3698c2ecf20Sopenharmony_ci MAX8997_REG_DVSOKTIMER2, 3708c2ecf20Sopenharmony_ci MAX8997_REG_DVSOKTIMER4, 3718c2ecf20Sopenharmony_ci MAX8997_REG_DVSOKTIMER5, 3728c2ecf20Sopenharmony_ci}; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_cistatic u8 max8997_dumpaddr_muic[] = { 3758c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_INTMASK1, 3768c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_INTMASK2, 3778c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_INTMASK3, 3788c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_CDETCTRL, 3798c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_CONTROL1, 3808c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_CONTROL2, 3818c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_CONTROL3, 3828c2ecf20Sopenharmony_ci}; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic u8 max8997_dumpaddr_haptic[] = { 3858c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_CONF1, 3868c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_CONF2, 3878c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_DRVCONF, 3888c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_CYCLECONF1, 3898c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_CYCLECONF2, 3908c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGCONF1, 3918c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGCONF2, 3928c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGCONF3, 3938c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGCONF4, 3948c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGDC1, 3958c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGDC2, 3968c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGPWMDC1, 3978c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGPWMDC2, 3988c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGPWMDC3, 3998c2ecf20Sopenharmony_ci MAX8997_HAPTIC_REG_SIGPWMDC4, 4008c2ecf20Sopenharmony_ci}; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_cistatic int max8997_freeze(struct device *dev) 4038c2ecf20Sopenharmony_ci{ 4048c2ecf20Sopenharmony_ci struct i2c_client *i2c = to_i2c_client(dev); 4058c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 4068c2ecf20Sopenharmony_ci int i; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++) 4098c2ecf20Sopenharmony_ci max8997_read_reg(i2c, max8997_dumpaddr_pmic[i], 4108c2ecf20Sopenharmony_ci &max8997->reg_dump[i]); 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++) 4138c2ecf20Sopenharmony_ci max8997_read_reg(i2c, max8997_dumpaddr_muic[i], 4148c2ecf20Sopenharmony_ci &max8997->reg_dump[i + MAX8997_REG_PMIC_END]); 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++) 4178c2ecf20Sopenharmony_ci max8997_read_reg(i2c, max8997_dumpaddr_haptic[i], 4188c2ecf20Sopenharmony_ci &max8997->reg_dump[i + MAX8997_REG_PMIC_END + 4198c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_END]); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci return 0; 4228c2ecf20Sopenharmony_ci} 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_cistatic int max8997_restore(struct device *dev) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci struct i2c_client *i2c = to_i2c_client(dev); 4278c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 4288c2ecf20Sopenharmony_ci int i; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++) 4318c2ecf20Sopenharmony_ci max8997_write_reg(i2c, max8997_dumpaddr_pmic[i], 4328c2ecf20Sopenharmony_ci max8997->reg_dump[i]); 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++) 4358c2ecf20Sopenharmony_ci max8997_write_reg(i2c, max8997_dumpaddr_muic[i], 4368c2ecf20Sopenharmony_ci max8997->reg_dump[i + MAX8997_REG_PMIC_END]); 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++) 4398c2ecf20Sopenharmony_ci max8997_write_reg(i2c, max8997_dumpaddr_haptic[i], 4408c2ecf20Sopenharmony_ci max8997->reg_dump[i + MAX8997_REG_PMIC_END + 4418c2ecf20Sopenharmony_ci MAX8997_MUIC_REG_END]); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci return 0; 4448c2ecf20Sopenharmony_ci} 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_cistatic int max8997_suspend(struct device *dev) 4478c2ecf20Sopenharmony_ci{ 4488c2ecf20Sopenharmony_ci struct i2c_client *i2c = to_i2c_client(dev); 4498c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci disable_irq(max8997->irq); 4528c2ecf20Sopenharmony_ci if (device_may_wakeup(dev)) 4538c2ecf20Sopenharmony_ci irq_set_irq_wake(max8997->irq, 1); 4548c2ecf20Sopenharmony_ci return 0; 4558c2ecf20Sopenharmony_ci} 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_cistatic int max8997_resume(struct device *dev) 4588c2ecf20Sopenharmony_ci{ 4598c2ecf20Sopenharmony_ci struct i2c_client *i2c = to_i2c_client(dev); 4608c2ecf20Sopenharmony_ci struct max8997_dev *max8997 = i2c_get_clientdata(i2c); 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci if (device_may_wakeup(dev)) 4638c2ecf20Sopenharmony_ci irq_set_irq_wake(max8997->irq, 0); 4648c2ecf20Sopenharmony_ci enable_irq(max8997->irq); 4658c2ecf20Sopenharmony_ci return max8997_irq_resume(max8997); 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_cistatic const struct dev_pm_ops max8997_pm = { 4698c2ecf20Sopenharmony_ci .suspend = max8997_suspend, 4708c2ecf20Sopenharmony_ci .resume = max8997_resume, 4718c2ecf20Sopenharmony_ci .freeze = max8997_freeze, 4728c2ecf20Sopenharmony_ci .restore = max8997_restore, 4738c2ecf20Sopenharmony_ci}; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_cistatic struct i2c_driver max8997_i2c_driver = { 4768c2ecf20Sopenharmony_ci .driver = { 4778c2ecf20Sopenharmony_ci .name = "max8997", 4788c2ecf20Sopenharmony_ci .pm = &max8997_pm, 4798c2ecf20Sopenharmony_ci .suppress_bind_attrs = true, 4808c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(max8997_pmic_dt_match), 4818c2ecf20Sopenharmony_ci }, 4828c2ecf20Sopenharmony_ci .probe = max8997_i2c_probe, 4838c2ecf20Sopenharmony_ci .id_table = max8997_i2c_id, 4848c2ecf20Sopenharmony_ci}; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic int __init max8997_i2c_init(void) 4878c2ecf20Sopenharmony_ci{ 4888c2ecf20Sopenharmony_ci return i2c_add_driver(&max8997_i2c_driver); 4898c2ecf20Sopenharmony_ci} 4908c2ecf20Sopenharmony_ci/* init early so consumer devices can complete system boot */ 4918c2ecf20Sopenharmony_cisubsys_initcall(max8997_i2c_init); 492