18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM 48c2ecf20Sopenharmony_ci * and audio CODEC devices 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2005-2006 Texas Instruments, Inc. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Modifications to defer interrupt handling to a kernel thread: 98c2ecf20Sopenharmony_ci * Copyright (C) 2006 MontaVista Software, Inc. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Based on tlv320aic23.c: 128c2ecf20Sopenharmony_ci * Copyright (c) by Kai Svahn <kai.svahn@nokia.com> 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Code cleanup and modifications to IRQ handler. 158c2ecf20Sopenharmony_ci * by syed khasim <x0khasim@ti.com> 168c2ecf20Sopenharmony_ci */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <linux/init.h> 198c2ecf20Sopenharmony_ci#include <linux/mutex.h> 208c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 218c2ecf20Sopenharmony_ci#include <linux/regmap.h> 228c2ecf20Sopenharmony_ci#include <linux/clk.h> 238c2ecf20Sopenharmony_ci#include <linux/err.h> 248c2ecf20Sopenharmony_ci#include <linux/device.h> 258c2ecf20Sopenharmony_ci#include <linux/of.h> 268c2ecf20Sopenharmony_ci#include <linux/of_irq.h> 278c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 288c2ecf20Sopenharmony_ci#include <linux/irq.h> 298c2ecf20Sopenharmony_ci#include <linux/irqdomain.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <linux/i2c.h> 348c2ecf20Sopenharmony_ci#include <linux/mfd/twl.h> 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* Register descriptions for audio */ 378c2ecf20Sopenharmony_ci#include <linux/mfd/twl4030-audio.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include "twl-core.h" 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * The TWL4030 "Triton 2" is one of a family of a multi-function "Power 438c2ecf20Sopenharmony_ci * Management and System Companion Device" chips originally designed for 448c2ecf20Sopenharmony_ci * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C, 458c2ecf20Sopenharmony_ci * often at around 3 Mbit/sec, including for interrupt handling. 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci * This driver core provides genirq support for the interrupts emitted, 488c2ecf20Sopenharmony_ci * by the various modules, and exports register access primitives. 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * FIXME this driver currently requires use of the first interrupt line 518c2ecf20Sopenharmony_ci * (and associated registers). 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define DRIVER_NAME "twl" 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* Triton Core internal information (BEGIN) */ 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* Base Address defns for twl4030_map[] */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* subchip/slave 0 - USB ID */ 618c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_USB 0x0000 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* subchip/slave 1 - AUD ID */ 648c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_AUDIO_VOICE 0x0000 658c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_GPIO 0x0098 668c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_INTBR 0x0085 678c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_PIH 0x0080 688c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_TEST 0x004C 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* subchip/slave 2 - AUX ID */ 718c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_INTERRUPTS 0x00B9 728c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_LED 0x00EE 738c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_MADC 0x0000 748c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_MAIN_CHARGE 0x0074 758c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_PRECHARGE 0x00AA 768c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_PWM 0x00F8 778c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_KEYPAD 0x00D2 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */ 808c2ecf20Sopenharmony_ci#define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's 818c2ecf20Sopenharmony_ci one */ 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* subchip/slave 3 - POWER ID */ 848c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_BACKUP 0x0014 858c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_INT 0x002E 868c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_PM_MASTER 0x0036 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_PM_RECEIVER 0x005B 898c2ecf20Sopenharmony_ci#define TWL4030_DCDC_GLOBAL_CFG 0x06 908c2ecf20Sopenharmony_ci#define SMARTREFLEX_ENABLE BIT(3) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_RTC 0x001C 938c2ecf20Sopenharmony_ci#define TWL4030_BASEADD_SECURED_REG 0x0000 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/* Triton Core internal information (END) */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* subchip/slave 0 0x48 - POWER */ 998c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_RTC 0x0000 1008c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_SECURED_REG 0x0017 1018c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_PM_MASTER 0x001F 1028c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */ 1038c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_PM_MISC 0x00E2 1048c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_PM_PUPD 0x00F0 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* subchip/slave 1 0x49 - FEATURE */ 1078c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_USB 0x0000 1088c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_GPADC_CTRL 0x002E 1098c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_AUX 0x0090 1108c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_PWM 0x00BA 1118c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_GASGAUGE 0x00C0 1128c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_PIH 0x00D0 1138c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_CHARGER 0x00E0 1148c2ecf20Sopenharmony_ci#define TWL6032_BASEADD_CHARGER 0x00DA 1158c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_LED 0x00F4 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* subchip/slave 2 0x4A - DFT */ 1188c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_DIEID 0x00C0 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci/* subchip/slave 3 0x4B - AUDIO */ 1218c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_AUDIO 0x0000 1228c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_RSV 0x0000 1238c2ecf20Sopenharmony_ci#define TWL6030_BASEADD_ZERO 0x0000 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* Few power values */ 1268c2ecf20Sopenharmony_ci#define R_CFG_BOOT 0x05 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/* some fields in R_CFG_BOOT */ 1298c2ecf20Sopenharmony_ci#define HFCLK_FREQ_19p2_MHZ (1 << 0) 1308c2ecf20Sopenharmony_ci#define HFCLK_FREQ_26_MHZ (2 << 0) 1318c2ecf20Sopenharmony_ci#define HFCLK_FREQ_38p4_MHZ (3 << 0) 1328c2ecf20Sopenharmony_ci#define HIGH_PERF_SQ (1 << 3) 1338c2ecf20Sopenharmony_ci#define CK32K_LOWPWR_EN (1 << 7) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/* Structure for each TWL4030/TWL6030 Slave */ 1388c2ecf20Sopenharmony_cistruct twl_client { 1398c2ecf20Sopenharmony_ci struct i2c_client *client; 1408c2ecf20Sopenharmony_ci struct regmap *regmap; 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/* mapping the module id to slave id and base address */ 1448c2ecf20Sopenharmony_cistruct twl_mapping { 1458c2ecf20Sopenharmony_ci unsigned char sid; /* Slave ID */ 1468c2ecf20Sopenharmony_ci unsigned char base; /* base address */ 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistruct twl_private { 1508c2ecf20Sopenharmony_ci bool ready; /* The core driver is ready to be used */ 1518c2ecf20Sopenharmony_ci u32 twl_idcode; /* TWL IDCODE Register value */ 1528c2ecf20Sopenharmony_ci unsigned int twl_id; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci struct twl_mapping *twl_map; 1558c2ecf20Sopenharmony_ci struct twl_client *twl_modules; 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic struct twl_private *twl_priv; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistatic struct twl_mapping twl4030_map[] = { 1618c2ecf20Sopenharmony_ci /* 1628c2ecf20Sopenharmony_ci * NOTE: don't change this table without updating the 1638c2ecf20Sopenharmony_ci * <linux/mfd/twl.h> defines for TWL4030_MODULE_* 1648c2ecf20Sopenharmony_ci * so they continue to match the order in this table. 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci /* Common IPs */ 1688c2ecf20Sopenharmony_ci { 0, TWL4030_BASEADD_USB }, 1698c2ecf20Sopenharmony_ci { 1, TWL4030_BASEADD_PIH }, 1708c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_MAIN_CHARGE }, 1718c2ecf20Sopenharmony_ci { 3, TWL4030_BASEADD_PM_MASTER }, 1728c2ecf20Sopenharmony_ci { 3, TWL4030_BASEADD_PM_RECEIVER }, 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci { 3, TWL4030_BASEADD_RTC }, 1758c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_PWM }, 1768c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_LED }, 1778c2ecf20Sopenharmony_ci { 3, TWL4030_BASEADD_SECURED_REG }, 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci /* TWL4030 specific IPs */ 1808c2ecf20Sopenharmony_ci { 1, TWL4030_BASEADD_AUDIO_VOICE }, 1818c2ecf20Sopenharmony_ci { 1, TWL4030_BASEADD_GPIO }, 1828c2ecf20Sopenharmony_ci { 1, TWL4030_BASEADD_INTBR }, 1838c2ecf20Sopenharmony_ci { 1, TWL4030_BASEADD_TEST }, 1848c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_KEYPAD }, 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_MADC }, 1878c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_INTERRUPTS }, 1888c2ecf20Sopenharmony_ci { 2, TWL4030_BASEADD_PRECHARGE }, 1898c2ecf20Sopenharmony_ci { 3, TWL4030_BASEADD_BACKUP }, 1908c2ecf20Sopenharmony_ci { 3, TWL4030_BASEADD_INT }, 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci { 2, TWL5031_BASEADD_ACCESSORY }, 1938c2ecf20Sopenharmony_ci { 2, TWL5031_BASEADD_INTERRUPTS }, 1948c2ecf20Sopenharmony_ci}; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistatic const struct reg_default twl4030_49_defaults[] = { 1978c2ecf20Sopenharmony_ci /* Audio Registers */ 1988c2ecf20Sopenharmony_ci { 0x01, 0x00}, /* CODEC_MODE */ 1998c2ecf20Sopenharmony_ci { 0x02, 0x00}, /* OPTION */ 2008c2ecf20Sopenharmony_ci /* 0x03 Unused */ 2018c2ecf20Sopenharmony_ci { 0x04, 0x00}, /* MICBIAS_CTL */ 2028c2ecf20Sopenharmony_ci { 0x05, 0x00}, /* ANAMICL */ 2038c2ecf20Sopenharmony_ci { 0x06, 0x00}, /* ANAMICR */ 2048c2ecf20Sopenharmony_ci { 0x07, 0x00}, /* AVADC_CTL */ 2058c2ecf20Sopenharmony_ci { 0x08, 0x00}, /* ADCMICSEL */ 2068c2ecf20Sopenharmony_ci { 0x09, 0x00}, /* DIGMIXING */ 2078c2ecf20Sopenharmony_ci { 0x0a, 0x0f}, /* ATXL1PGA */ 2088c2ecf20Sopenharmony_ci { 0x0b, 0x0f}, /* ATXR1PGA */ 2098c2ecf20Sopenharmony_ci { 0x0c, 0x0f}, /* AVTXL2PGA */ 2108c2ecf20Sopenharmony_ci { 0x0d, 0x0f}, /* AVTXR2PGA */ 2118c2ecf20Sopenharmony_ci { 0x0e, 0x00}, /* AUDIO_IF */ 2128c2ecf20Sopenharmony_ci { 0x0f, 0x00}, /* VOICE_IF */ 2138c2ecf20Sopenharmony_ci { 0x10, 0x3f}, /* ARXR1PGA */ 2148c2ecf20Sopenharmony_ci { 0x11, 0x3f}, /* ARXL1PGA */ 2158c2ecf20Sopenharmony_ci { 0x12, 0x3f}, /* ARXR2PGA */ 2168c2ecf20Sopenharmony_ci { 0x13, 0x3f}, /* ARXL2PGA */ 2178c2ecf20Sopenharmony_ci { 0x14, 0x25}, /* VRXPGA */ 2188c2ecf20Sopenharmony_ci { 0x15, 0x00}, /* VSTPGA */ 2198c2ecf20Sopenharmony_ci { 0x16, 0x00}, /* VRX2ARXPGA */ 2208c2ecf20Sopenharmony_ci { 0x17, 0x00}, /* AVDAC_CTL */ 2218c2ecf20Sopenharmony_ci { 0x18, 0x00}, /* ARX2VTXPGA */ 2228c2ecf20Sopenharmony_ci { 0x19, 0x32}, /* ARXL1_APGA_CTL*/ 2238c2ecf20Sopenharmony_ci { 0x1a, 0x32}, /* ARXR1_APGA_CTL*/ 2248c2ecf20Sopenharmony_ci { 0x1b, 0x32}, /* ARXL2_APGA_CTL*/ 2258c2ecf20Sopenharmony_ci { 0x1c, 0x32}, /* ARXR2_APGA_CTL*/ 2268c2ecf20Sopenharmony_ci { 0x1d, 0x00}, /* ATX2ARXPGA */ 2278c2ecf20Sopenharmony_ci { 0x1e, 0x00}, /* BT_IF */ 2288c2ecf20Sopenharmony_ci { 0x1f, 0x55}, /* BTPGA */ 2298c2ecf20Sopenharmony_ci { 0x20, 0x00}, /* BTSTPGA */ 2308c2ecf20Sopenharmony_ci { 0x21, 0x00}, /* EAR_CTL */ 2318c2ecf20Sopenharmony_ci { 0x22, 0x00}, /* HS_SEL */ 2328c2ecf20Sopenharmony_ci { 0x23, 0x00}, /* HS_GAIN_SET */ 2338c2ecf20Sopenharmony_ci { 0x24, 0x00}, /* HS_POPN_SET */ 2348c2ecf20Sopenharmony_ci { 0x25, 0x00}, /* PREDL_CTL */ 2358c2ecf20Sopenharmony_ci { 0x26, 0x00}, /* PREDR_CTL */ 2368c2ecf20Sopenharmony_ci { 0x27, 0x00}, /* PRECKL_CTL */ 2378c2ecf20Sopenharmony_ci { 0x28, 0x00}, /* PRECKR_CTL */ 2388c2ecf20Sopenharmony_ci { 0x29, 0x00}, /* HFL_CTL */ 2398c2ecf20Sopenharmony_ci { 0x2a, 0x00}, /* HFR_CTL */ 2408c2ecf20Sopenharmony_ci { 0x2b, 0x05}, /* ALC_CTL */ 2418c2ecf20Sopenharmony_ci { 0x2c, 0x00}, /* ALC_SET1 */ 2428c2ecf20Sopenharmony_ci { 0x2d, 0x00}, /* ALC_SET2 */ 2438c2ecf20Sopenharmony_ci { 0x2e, 0x00}, /* BOOST_CTL */ 2448c2ecf20Sopenharmony_ci { 0x2f, 0x00}, /* SOFTVOL_CTL */ 2458c2ecf20Sopenharmony_ci { 0x30, 0x13}, /* DTMF_FREQSEL */ 2468c2ecf20Sopenharmony_ci { 0x31, 0x00}, /* DTMF_TONEXT1H */ 2478c2ecf20Sopenharmony_ci { 0x32, 0x00}, /* DTMF_TONEXT1L */ 2488c2ecf20Sopenharmony_ci { 0x33, 0x00}, /* DTMF_TONEXT2H */ 2498c2ecf20Sopenharmony_ci { 0x34, 0x00}, /* DTMF_TONEXT2L */ 2508c2ecf20Sopenharmony_ci { 0x35, 0x79}, /* DTMF_TONOFF */ 2518c2ecf20Sopenharmony_ci { 0x36, 0x11}, /* DTMF_WANONOFF */ 2528c2ecf20Sopenharmony_ci { 0x37, 0x00}, /* I2S_RX_SCRAMBLE_H */ 2538c2ecf20Sopenharmony_ci { 0x38, 0x00}, /* I2S_RX_SCRAMBLE_M */ 2548c2ecf20Sopenharmony_ci { 0x39, 0x00}, /* I2S_RX_SCRAMBLE_L */ 2558c2ecf20Sopenharmony_ci { 0x3a, 0x06}, /* APLL_CTL */ 2568c2ecf20Sopenharmony_ci { 0x3b, 0x00}, /* DTMF_CTL */ 2578c2ecf20Sopenharmony_ci { 0x3c, 0x44}, /* DTMF_PGA_CTL2 (0x3C) */ 2588c2ecf20Sopenharmony_ci { 0x3d, 0x69}, /* DTMF_PGA_CTL1 (0x3D) */ 2598c2ecf20Sopenharmony_ci { 0x3e, 0x00}, /* MISC_SET_1 */ 2608c2ecf20Sopenharmony_ci { 0x3f, 0x00}, /* PCMBTMUX */ 2618c2ecf20Sopenharmony_ci /* 0x40 - 0x42 Unused */ 2628c2ecf20Sopenharmony_ci { 0x43, 0x00}, /* RX_PATH_SEL */ 2638c2ecf20Sopenharmony_ci { 0x44, 0x32}, /* VDL_APGA_CTL */ 2648c2ecf20Sopenharmony_ci { 0x45, 0x00}, /* VIBRA_CTL */ 2658c2ecf20Sopenharmony_ci { 0x46, 0x00}, /* VIBRA_SET */ 2668c2ecf20Sopenharmony_ci { 0x47, 0x00}, /* VIBRA_PWM_SET */ 2678c2ecf20Sopenharmony_ci { 0x48, 0x00}, /* ANAMIC_GAIN */ 2688c2ecf20Sopenharmony_ci { 0x49, 0x00}, /* MISC_SET_2 */ 2698c2ecf20Sopenharmony_ci /* End of Audio Registers */ 2708c2ecf20Sopenharmony_ci}; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_cistatic bool twl4030_49_nop_reg(struct device *dev, unsigned int reg) 2738c2ecf20Sopenharmony_ci{ 2748c2ecf20Sopenharmony_ci switch (reg) { 2758c2ecf20Sopenharmony_ci case 0x00: 2768c2ecf20Sopenharmony_ci case 0x03: 2778c2ecf20Sopenharmony_ci case 0x40: 2788c2ecf20Sopenharmony_ci case 0x41: 2798c2ecf20Sopenharmony_ci case 0x42: 2808c2ecf20Sopenharmony_ci return false; 2818c2ecf20Sopenharmony_ci default: 2828c2ecf20Sopenharmony_ci return true; 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic const struct regmap_range twl4030_49_volatile_ranges[] = { 2878c2ecf20Sopenharmony_ci regmap_reg_range(TWL4030_BASEADD_TEST, 0xff), 2888c2ecf20Sopenharmony_ci}; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_cistatic const struct regmap_access_table twl4030_49_volatile_table = { 2918c2ecf20Sopenharmony_ci .yes_ranges = twl4030_49_volatile_ranges, 2928c2ecf20Sopenharmony_ci .n_yes_ranges = ARRAY_SIZE(twl4030_49_volatile_ranges), 2938c2ecf20Sopenharmony_ci}; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_cistatic const struct regmap_config twl4030_regmap_config[4] = { 2968c2ecf20Sopenharmony_ci { 2978c2ecf20Sopenharmony_ci /* Address 0x48 */ 2988c2ecf20Sopenharmony_ci .reg_bits = 8, 2998c2ecf20Sopenharmony_ci .val_bits = 8, 3008c2ecf20Sopenharmony_ci .max_register = 0xff, 3018c2ecf20Sopenharmony_ci }, 3028c2ecf20Sopenharmony_ci { 3038c2ecf20Sopenharmony_ci /* Address 0x49 */ 3048c2ecf20Sopenharmony_ci .reg_bits = 8, 3058c2ecf20Sopenharmony_ci .val_bits = 8, 3068c2ecf20Sopenharmony_ci .max_register = 0xff, 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci .readable_reg = twl4030_49_nop_reg, 3098c2ecf20Sopenharmony_ci .writeable_reg = twl4030_49_nop_reg, 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci .volatile_table = &twl4030_49_volatile_table, 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci .reg_defaults = twl4030_49_defaults, 3148c2ecf20Sopenharmony_ci .num_reg_defaults = ARRAY_SIZE(twl4030_49_defaults), 3158c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 3168c2ecf20Sopenharmony_ci }, 3178c2ecf20Sopenharmony_ci { 3188c2ecf20Sopenharmony_ci /* Address 0x4a */ 3198c2ecf20Sopenharmony_ci .reg_bits = 8, 3208c2ecf20Sopenharmony_ci .val_bits = 8, 3218c2ecf20Sopenharmony_ci .max_register = 0xff, 3228c2ecf20Sopenharmony_ci }, 3238c2ecf20Sopenharmony_ci { 3248c2ecf20Sopenharmony_ci /* Address 0x4b */ 3258c2ecf20Sopenharmony_ci .reg_bits = 8, 3268c2ecf20Sopenharmony_ci .val_bits = 8, 3278c2ecf20Sopenharmony_ci .max_register = 0xff, 3288c2ecf20Sopenharmony_ci }, 3298c2ecf20Sopenharmony_ci}; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistatic struct twl_mapping twl6030_map[] = { 3328c2ecf20Sopenharmony_ci /* 3338c2ecf20Sopenharmony_ci * NOTE: don't change this table without updating the 3348c2ecf20Sopenharmony_ci * <linux/mfd/twl.h> defines for TWL4030_MODULE_* 3358c2ecf20Sopenharmony_ci * so they continue to match the order in this table. 3368c2ecf20Sopenharmony_ci */ 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci /* Common IPs */ 3398c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_USB }, 3408c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_PIH }, 3418c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_CHARGER }, 3428c2ecf20Sopenharmony_ci { 0, TWL6030_BASEADD_PM_MASTER }, 3438c2ecf20Sopenharmony_ci { 0, TWL6030_BASEADD_PM_SLAVE_MISC }, 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci { 0, TWL6030_BASEADD_RTC }, 3468c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_PWM }, 3478c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_LED }, 3488c2ecf20Sopenharmony_ci { 0, TWL6030_BASEADD_SECURED_REG }, 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci /* TWL6030 specific IPs */ 3518c2ecf20Sopenharmony_ci { 0, TWL6030_BASEADD_ZERO }, 3528c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_ZERO }, 3538c2ecf20Sopenharmony_ci { 2, TWL6030_BASEADD_ZERO }, 3548c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_GPADC_CTRL }, 3558c2ecf20Sopenharmony_ci { 1, TWL6030_BASEADD_GASGAUGE }, 3568c2ecf20Sopenharmony_ci}; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_cistatic const struct regmap_config twl6030_regmap_config[3] = { 3598c2ecf20Sopenharmony_ci { 3608c2ecf20Sopenharmony_ci /* Address 0x48 */ 3618c2ecf20Sopenharmony_ci .reg_bits = 8, 3628c2ecf20Sopenharmony_ci .val_bits = 8, 3638c2ecf20Sopenharmony_ci .max_register = 0xff, 3648c2ecf20Sopenharmony_ci }, 3658c2ecf20Sopenharmony_ci { 3668c2ecf20Sopenharmony_ci /* Address 0x49 */ 3678c2ecf20Sopenharmony_ci .reg_bits = 8, 3688c2ecf20Sopenharmony_ci .val_bits = 8, 3698c2ecf20Sopenharmony_ci .max_register = 0xff, 3708c2ecf20Sopenharmony_ci }, 3718c2ecf20Sopenharmony_ci { 3728c2ecf20Sopenharmony_ci /* Address 0x4a */ 3738c2ecf20Sopenharmony_ci .reg_bits = 8, 3748c2ecf20Sopenharmony_ci .val_bits = 8, 3758c2ecf20Sopenharmony_ci .max_register = 0xff, 3768c2ecf20Sopenharmony_ci }, 3778c2ecf20Sopenharmony_ci}; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic inline int twl_get_num_slaves(void) 3828c2ecf20Sopenharmony_ci{ 3838c2ecf20Sopenharmony_ci if (twl_class_is_4030()) 3848c2ecf20Sopenharmony_ci return 4; /* TWL4030 class have four slave address */ 3858c2ecf20Sopenharmony_ci else 3868c2ecf20Sopenharmony_ci return 3; /* TWL6030 class have three slave address */ 3878c2ecf20Sopenharmony_ci} 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_cistatic inline int twl_get_last_module(void) 3908c2ecf20Sopenharmony_ci{ 3918c2ecf20Sopenharmony_ci if (twl_class_is_4030()) 3928c2ecf20Sopenharmony_ci return TWL4030_MODULE_LAST; 3938c2ecf20Sopenharmony_ci else 3948c2ecf20Sopenharmony_ci return TWL6030_MODULE_LAST; 3958c2ecf20Sopenharmony_ci} 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci/* Exported Functions */ 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ciunsigned int twl_rev(void) 4008c2ecf20Sopenharmony_ci{ 4018c2ecf20Sopenharmony_ci return twl_priv ? twl_priv->twl_id : 0; 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ciEXPORT_SYMBOL(twl_rev); 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci/** 4068c2ecf20Sopenharmony_ci * twl_get_regmap - Get the regmap associated with the given module 4078c2ecf20Sopenharmony_ci * @mod_no: module number 4088c2ecf20Sopenharmony_ci * 4098c2ecf20Sopenharmony_ci * Returns the regmap pointer or NULL in case of failure. 4108c2ecf20Sopenharmony_ci */ 4118c2ecf20Sopenharmony_cistatic struct regmap *twl_get_regmap(u8 mod_no) 4128c2ecf20Sopenharmony_ci{ 4138c2ecf20Sopenharmony_ci int sid; 4148c2ecf20Sopenharmony_ci struct twl_client *twl; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci if (unlikely(!twl_priv || !twl_priv->ready)) { 4178c2ecf20Sopenharmony_ci pr_err("%s: not initialized\n", DRIVER_NAME); 4188c2ecf20Sopenharmony_ci return NULL; 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci if (unlikely(mod_no >= twl_get_last_module())) { 4218c2ecf20Sopenharmony_ci pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); 4228c2ecf20Sopenharmony_ci return NULL; 4238c2ecf20Sopenharmony_ci } 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci sid = twl_priv->twl_map[mod_no].sid; 4268c2ecf20Sopenharmony_ci twl = &twl_priv->twl_modules[sid]; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci return twl->regmap; 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci/** 4328c2ecf20Sopenharmony_ci * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0 4338c2ecf20Sopenharmony_ci * @mod_no: module number 4348c2ecf20Sopenharmony_ci * @value: an array of num_bytes+1 containing data to write 4358c2ecf20Sopenharmony_ci * @reg: register address (just offset will do) 4368c2ecf20Sopenharmony_ci * @num_bytes: number of bytes to transfer 4378c2ecf20Sopenharmony_ci * 4388c2ecf20Sopenharmony_ci * Returns 0 on success or else a negative error code. 4398c2ecf20Sopenharmony_ci */ 4408c2ecf20Sopenharmony_ciint twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) 4418c2ecf20Sopenharmony_ci{ 4428c2ecf20Sopenharmony_ci struct regmap *regmap = twl_get_regmap(mod_no); 4438c2ecf20Sopenharmony_ci int ret; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci if (!regmap) 4468c2ecf20Sopenharmony_ci return -EPERM; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg, 4498c2ecf20Sopenharmony_ci value, num_bytes); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci if (ret) 4528c2ecf20Sopenharmony_ci pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n", 4538c2ecf20Sopenharmony_ci DRIVER_NAME, mod_no, reg, num_bytes); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci return ret; 4568c2ecf20Sopenharmony_ci} 4578c2ecf20Sopenharmony_ciEXPORT_SYMBOL(twl_i2c_write); 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci/** 4608c2ecf20Sopenharmony_ci * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0 4618c2ecf20Sopenharmony_ci * @mod_no: module number 4628c2ecf20Sopenharmony_ci * @value: an array of num_bytes containing data to be read 4638c2ecf20Sopenharmony_ci * @reg: register address (just offset will do) 4648c2ecf20Sopenharmony_ci * @num_bytes: number of bytes to transfer 4658c2ecf20Sopenharmony_ci * 4668c2ecf20Sopenharmony_ci * Returns 0 on success or else a negative error code. 4678c2ecf20Sopenharmony_ci */ 4688c2ecf20Sopenharmony_ciint twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci struct regmap *regmap = twl_get_regmap(mod_no); 4718c2ecf20Sopenharmony_ci int ret; 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci if (!regmap) 4748c2ecf20Sopenharmony_ci return -EPERM; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg, 4778c2ecf20Sopenharmony_ci value, num_bytes); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci if (ret) 4808c2ecf20Sopenharmony_ci pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n", 4818c2ecf20Sopenharmony_ci DRIVER_NAME, mod_no, reg, num_bytes); 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci return ret; 4848c2ecf20Sopenharmony_ci} 4858c2ecf20Sopenharmony_ciEXPORT_SYMBOL(twl_i2c_read); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci/** 4888c2ecf20Sopenharmony_ci * twl_regcache_bypass - Configure the regcache bypass for the regmap associated 4898c2ecf20Sopenharmony_ci * with the module 4908c2ecf20Sopenharmony_ci * @mod_no: module number 4918c2ecf20Sopenharmony_ci * @enable: Regcache bypass state 4928c2ecf20Sopenharmony_ci * 4938c2ecf20Sopenharmony_ci * Returns 0 else failure. 4948c2ecf20Sopenharmony_ci */ 4958c2ecf20Sopenharmony_ciint twl_set_regcache_bypass(u8 mod_no, bool enable) 4968c2ecf20Sopenharmony_ci{ 4978c2ecf20Sopenharmony_ci struct regmap *regmap = twl_get_regmap(mod_no); 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci if (!regmap) 5008c2ecf20Sopenharmony_ci return -EPERM; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci regcache_cache_bypass(regmap, enable); 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci return 0; 5058c2ecf20Sopenharmony_ci} 5068c2ecf20Sopenharmony_ciEXPORT_SYMBOL(twl_set_regcache_bypass); 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci/** 5118c2ecf20Sopenharmony_ci * twl_read_idcode_register - API to read the IDCODE register. 5128c2ecf20Sopenharmony_ci * 5138c2ecf20Sopenharmony_ci * Unlocks the IDCODE register and read the 32 bit value. 5148c2ecf20Sopenharmony_ci */ 5158c2ecf20Sopenharmony_cistatic int twl_read_idcode_register(void) 5168c2ecf20Sopenharmony_ci{ 5178c2ecf20Sopenharmony_ci int err; 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK, 5208c2ecf20Sopenharmony_ci REG_UNLOCK_TEST_REG); 5218c2ecf20Sopenharmony_ci if (err) { 5228c2ecf20Sopenharmony_ci pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err); 5238c2ecf20Sopenharmony_ci goto fail; 5248c2ecf20Sopenharmony_ci } 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_priv->twl_idcode), 5278c2ecf20Sopenharmony_ci REG_IDCODE_7_0, 4); 5288c2ecf20Sopenharmony_ci if (err) { 5298c2ecf20Sopenharmony_ci pr_err("TWL4030: unable to read IDCODE -%d\n", err); 5308c2ecf20Sopenharmony_ci goto fail; 5318c2ecf20Sopenharmony_ci } 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG); 5348c2ecf20Sopenharmony_ci if (err) 5358c2ecf20Sopenharmony_ci pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err); 5368c2ecf20Sopenharmony_cifail: 5378c2ecf20Sopenharmony_ci return err; 5388c2ecf20Sopenharmony_ci} 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci/** 5418c2ecf20Sopenharmony_ci * twl_get_type - API to get TWL Si type. 5428c2ecf20Sopenharmony_ci * 5438c2ecf20Sopenharmony_ci * Api to get the TWL Si type from IDCODE value. 5448c2ecf20Sopenharmony_ci */ 5458c2ecf20Sopenharmony_ciint twl_get_type(void) 5468c2ecf20Sopenharmony_ci{ 5478c2ecf20Sopenharmony_ci return TWL_SIL_TYPE(twl_priv->twl_idcode); 5488c2ecf20Sopenharmony_ci} 5498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(twl_get_type); 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci/** 5528c2ecf20Sopenharmony_ci * twl_get_version - API to get TWL Si version. 5538c2ecf20Sopenharmony_ci * 5548c2ecf20Sopenharmony_ci * Api to get the TWL Si version from IDCODE value. 5558c2ecf20Sopenharmony_ci */ 5568c2ecf20Sopenharmony_ciint twl_get_version(void) 5578c2ecf20Sopenharmony_ci{ 5588c2ecf20Sopenharmony_ci return TWL_SIL_REV(twl_priv->twl_idcode); 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(twl_get_version); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci/** 5638c2ecf20Sopenharmony_ci * twl_get_hfclk_rate - API to get TWL external HFCLK clock rate. 5648c2ecf20Sopenharmony_ci * 5658c2ecf20Sopenharmony_ci * Api to get the TWL HFCLK rate based on BOOT_CFG register. 5668c2ecf20Sopenharmony_ci */ 5678c2ecf20Sopenharmony_ciint twl_get_hfclk_rate(void) 5688c2ecf20Sopenharmony_ci{ 5698c2ecf20Sopenharmony_ci u8 ctrl; 5708c2ecf20Sopenharmony_ci int rate; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &ctrl, R_CFG_BOOT); 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci switch (ctrl & 0x3) { 5758c2ecf20Sopenharmony_ci case HFCLK_FREQ_19p2_MHZ: 5768c2ecf20Sopenharmony_ci rate = 19200000; 5778c2ecf20Sopenharmony_ci break; 5788c2ecf20Sopenharmony_ci case HFCLK_FREQ_26_MHZ: 5798c2ecf20Sopenharmony_ci rate = 26000000; 5808c2ecf20Sopenharmony_ci break; 5818c2ecf20Sopenharmony_ci case HFCLK_FREQ_38p4_MHZ: 5828c2ecf20Sopenharmony_ci rate = 38400000; 5838c2ecf20Sopenharmony_ci break; 5848c2ecf20Sopenharmony_ci default: 5858c2ecf20Sopenharmony_ci pr_err("TWL4030: HFCLK is not configured\n"); 5868c2ecf20Sopenharmony_ci rate = -EINVAL; 5878c2ecf20Sopenharmony_ci break; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci return rate; 5918c2ecf20Sopenharmony_ci} 5928c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(twl_get_hfclk_rate); 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_cistatic struct device * 5958c2ecf20Sopenharmony_ciadd_numbered_child(unsigned mod_no, const char *name, int num, 5968c2ecf20Sopenharmony_ci void *pdata, unsigned pdata_len, 5978c2ecf20Sopenharmony_ci bool can_wakeup, int irq0, int irq1) 5988c2ecf20Sopenharmony_ci{ 5998c2ecf20Sopenharmony_ci struct platform_device *pdev; 6008c2ecf20Sopenharmony_ci struct twl_client *twl; 6018c2ecf20Sopenharmony_ci int status, sid; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci if (unlikely(mod_no >= twl_get_last_module())) { 6048c2ecf20Sopenharmony_ci pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); 6058c2ecf20Sopenharmony_ci return ERR_PTR(-EPERM); 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci sid = twl_priv->twl_map[mod_no].sid; 6088c2ecf20Sopenharmony_ci twl = &twl_priv->twl_modules[sid]; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci pdev = platform_device_alloc(name, num); 6118c2ecf20Sopenharmony_ci if (!pdev) 6128c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci pdev->dev.parent = &twl->client->dev; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci if (pdata) { 6178c2ecf20Sopenharmony_ci status = platform_device_add_data(pdev, pdata, pdata_len); 6188c2ecf20Sopenharmony_ci if (status < 0) { 6198c2ecf20Sopenharmony_ci dev_dbg(&pdev->dev, "can't add platform_data\n"); 6208c2ecf20Sopenharmony_ci goto put_device; 6218c2ecf20Sopenharmony_ci } 6228c2ecf20Sopenharmony_ci } 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci if (irq0) { 6258c2ecf20Sopenharmony_ci struct resource r[2] = { 6268c2ecf20Sopenharmony_ci { .start = irq0, .flags = IORESOURCE_IRQ, }, 6278c2ecf20Sopenharmony_ci { .start = irq1, .flags = IORESOURCE_IRQ, }, 6288c2ecf20Sopenharmony_ci }; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1); 6318c2ecf20Sopenharmony_ci if (status < 0) { 6328c2ecf20Sopenharmony_ci dev_dbg(&pdev->dev, "can't add irqs\n"); 6338c2ecf20Sopenharmony_ci goto put_device; 6348c2ecf20Sopenharmony_ci } 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci status = platform_device_add(pdev); 6388c2ecf20Sopenharmony_ci if (status) 6398c2ecf20Sopenharmony_ci goto put_device; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci device_init_wakeup(&pdev->dev, can_wakeup); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci return &pdev->dev; 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ciput_device: 6468c2ecf20Sopenharmony_ci platform_device_put(pdev); 6478c2ecf20Sopenharmony_ci dev_err(&twl->client->dev, "failed to add device %s\n", name); 6488c2ecf20Sopenharmony_ci return ERR_PTR(status); 6498c2ecf20Sopenharmony_ci} 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_cistatic inline struct device *add_child(unsigned mod_no, const char *name, 6528c2ecf20Sopenharmony_ci void *pdata, unsigned pdata_len, 6538c2ecf20Sopenharmony_ci bool can_wakeup, int irq0, int irq1) 6548c2ecf20Sopenharmony_ci{ 6558c2ecf20Sopenharmony_ci return add_numbered_child(mod_no, name, -1, pdata, pdata_len, 6568c2ecf20Sopenharmony_ci can_wakeup, irq0, irq1); 6578c2ecf20Sopenharmony_ci} 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_cistatic struct device * 6608c2ecf20Sopenharmony_ciadd_regulator_linked(int num, struct regulator_init_data *pdata, 6618c2ecf20Sopenharmony_ci struct regulator_consumer_supply *consumers, 6628c2ecf20Sopenharmony_ci unsigned num_consumers, unsigned long features) 6638c2ecf20Sopenharmony_ci{ 6648c2ecf20Sopenharmony_ci struct twl_regulator_driver_data drv_data; 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci /* regulator framework demands init_data ... */ 6678c2ecf20Sopenharmony_ci if (!pdata) 6688c2ecf20Sopenharmony_ci return NULL; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci if (consumers) { 6718c2ecf20Sopenharmony_ci pdata->consumer_supplies = consumers; 6728c2ecf20Sopenharmony_ci pdata->num_consumer_supplies = num_consumers; 6738c2ecf20Sopenharmony_ci } 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci if (pdata->driver_data) { 6768c2ecf20Sopenharmony_ci /* If we have existing drv_data, just add the flags */ 6778c2ecf20Sopenharmony_ci struct twl_regulator_driver_data *tmp; 6788c2ecf20Sopenharmony_ci tmp = pdata->driver_data; 6798c2ecf20Sopenharmony_ci tmp->features |= features; 6808c2ecf20Sopenharmony_ci } else { 6818c2ecf20Sopenharmony_ci /* add new driver data struct, used only during init */ 6828c2ecf20Sopenharmony_ci drv_data.features = features; 6838c2ecf20Sopenharmony_ci drv_data.set_voltage = NULL; 6848c2ecf20Sopenharmony_ci drv_data.get_voltage = NULL; 6858c2ecf20Sopenharmony_ci drv_data.data = NULL; 6868c2ecf20Sopenharmony_ci pdata->driver_data = &drv_data; 6878c2ecf20Sopenharmony_ci } 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */ 6908c2ecf20Sopenharmony_ci return add_numbered_child(TWL_MODULE_PM_MASTER, "twl_reg", num, 6918c2ecf20Sopenharmony_ci pdata, sizeof(*pdata), false, 0, 0); 6928c2ecf20Sopenharmony_ci} 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_cistatic struct device * 6958c2ecf20Sopenharmony_ciadd_regulator(int num, struct regulator_init_data *pdata, 6968c2ecf20Sopenharmony_ci unsigned long features) 6978c2ecf20Sopenharmony_ci{ 6988c2ecf20Sopenharmony_ci return add_regulator_linked(num, pdata, NULL, 0, features); 6998c2ecf20Sopenharmony_ci} 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci/* 7028c2ecf20Sopenharmony_ci * NOTE: We know the first 8 IRQs after pdata->base_irq are 7038c2ecf20Sopenharmony_ci * for the PIH, and the next are for the PWR_INT SIH, since 7048c2ecf20Sopenharmony_ci * that's how twl_init_irq() sets things up. 7058c2ecf20Sopenharmony_ci */ 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_cistatic int 7088c2ecf20Sopenharmony_ciadd_children(struct twl4030_platform_data *pdata, unsigned irq_base, 7098c2ecf20Sopenharmony_ci unsigned long features) 7108c2ecf20Sopenharmony_ci{ 7118c2ecf20Sopenharmony_ci struct device *child; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) { 7148c2ecf20Sopenharmony_ci child = add_child(TWL4030_MODULE_GPIO, "twl4030_gpio", 7158c2ecf20Sopenharmony_ci pdata->gpio, sizeof(*pdata->gpio), 7168c2ecf20Sopenharmony_ci false, irq_base + GPIO_INTR_OFFSET, 0); 7178c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7188c2ecf20Sopenharmony_ci return PTR_ERR(child); 7198c2ecf20Sopenharmony_ci } 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) { 7228c2ecf20Sopenharmony_ci child = add_child(TWL4030_MODULE_KEYPAD, "twl4030_keypad", 7238c2ecf20Sopenharmony_ci pdata->keypad, sizeof(*pdata->keypad), 7248c2ecf20Sopenharmony_ci true, irq_base + KEYPAD_INTR_OFFSET, 0); 7258c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7268c2ecf20Sopenharmony_ci return PTR_ERR(child); 7278c2ecf20Sopenharmony_ci } 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc && 7308c2ecf20Sopenharmony_ci twl_class_is_4030()) { 7318c2ecf20Sopenharmony_ci child = add_child(TWL4030_MODULE_MADC, "twl4030_madc", 7328c2ecf20Sopenharmony_ci pdata->madc, sizeof(*pdata->madc), 7338c2ecf20Sopenharmony_ci true, irq_base + MADC_INTR_OFFSET, 0); 7348c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7358c2ecf20Sopenharmony_ci return PTR_ERR(child); 7368c2ecf20Sopenharmony_ci } 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_RTC_DRV_TWL4030)) { 7398c2ecf20Sopenharmony_ci /* 7408c2ecf20Sopenharmony_ci * REVISIT platform_data here currently might expose the 7418c2ecf20Sopenharmony_ci * "msecure" line ... but for now we just expect board 7428c2ecf20Sopenharmony_ci * setup to tell the chip "it's always ok to SET_TIME". 7438c2ecf20Sopenharmony_ci * Eventually, Linux might become more aware of such 7448c2ecf20Sopenharmony_ci * HW security concerns, and "least privilege". 7458c2ecf20Sopenharmony_ci */ 7468c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_RTC, "twl_rtc", NULL, 0, 7478c2ecf20Sopenharmony_ci true, irq_base + RTC_INTR_OFFSET, 0); 7488c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7498c2ecf20Sopenharmony_ci return PTR_ERR(child); 7508c2ecf20Sopenharmony_ci } 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_PWM_TWL)) { 7538c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_PWM, "twl-pwm", NULL, 0, 7548c2ecf20Sopenharmony_ci false, 0, 0); 7558c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7568c2ecf20Sopenharmony_ci return PTR_ERR(child); 7578c2ecf20Sopenharmony_ci } 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_PWM_TWL_LED)) { 7608c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_LED, "twl-pwmled", NULL, 0, 7618c2ecf20Sopenharmony_ci false, 0, 0); 7628c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7638c2ecf20Sopenharmony_ci return PTR_ERR(child); 7648c2ecf20Sopenharmony_ci } 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb && 7678c2ecf20Sopenharmony_ci twl_class_is_4030()) { 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci static struct regulator_consumer_supply usb1v5 = { 7708c2ecf20Sopenharmony_ci .supply = "usb1v5", 7718c2ecf20Sopenharmony_ci }; 7728c2ecf20Sopenharmony_ci static struct regulator_consumer_supply usb1v8 = { 7738c2ecf20Sopenharmony_ci .supply = "usb1v8", 7748c2ecf20Sopenharmony_ci }; 7758c2ecf20Sopenharmony_ci static struct regulator_consumer_supply usb3v1 = { 7768c2ecf20Sopenharmony_ci .supply = "usb3v1", 7778c2ecf20Sopenharmony_ci }; 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci /* First add the regulators so that they can be used by transceiver */ 7808c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) { 7818c2ecf20Sopenharmony_ci /* this is a template that gets copied */ 7828c2ecf20Sopenharmony_ci struct regulator_init_data usb_fixed = { 7838c2ecf20Sopenharmony_ci .constraints.valid_modes_mask = 7848c2ecf20Sopenharmony_ci REGULATOR_MODE_NORMAL 7858c2ecf20Sopenharmony_ci | REGULATOR_MODE_STANDBY, 7868c2ecf20Sopenharmony_ci .constraints.valid_ops_mask = 7878c2ecf20Sopenharmony_ci REGULATOR_CHANGE_MODE 7888c2ecf20Sopenharmony_ci | REGULATOR_CHANGE_STATUS, 7898c2ecf20Sopenharmony_ci }; 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci child = add_regulator_linked(TWL4030_REG_VUSB1V5, 7928c2ecf20Sopenharmony_ci &usb_fixed, &usb1v5, 1, 7938c2ecf20Sopenharmony_ci features); 7948c2ecf20Sopenharmony_ci if (IS_ERR(child)) 7958c2ecf20Sopenharmony_ci return PTR_ERR(child); 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci child = add_regulator_linked(TWL4030_REG_VUSB1V8, 7988c2ecf20Sopenharmony_ci &usb_fixed, &usb1v8, 1, 7998c2ecf20Sopenharmony_ci features); 8008c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8018c2ecf20Sopenharmony_ci return PTR_ERR(child); 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci child = add_regulator_linked(TWL4030_REG_VUSB3V1, 8048c2ecf20Sopenharmony_ci &usb_fixed, &usb3v1, 1, 8058c2ecf20Sopenharmony_ci features); 8068c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8078c2ecf20Sopenharmony_ci return PTR_ERR(child); 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci } 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_USB, "twl4030_usb", 8128c2ecf20Sopenharmony_ci pdata->usb, sizeof(*pdata->usb), true, 8138c2ecf20Sopenharmony_ci /* irq0 = USB_PRES, irq1 = USB */ 8148c2ecf20Sopenharmony_ci irq_base + USB_PRES_INTR_OFFSET, 8158c2ecf20Sopenharmony_ci irq_base + USB_INTR_OFFSET); 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8188c2ecf20Sopenharmony_ci return PTR_ERR(child); 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci /* we need to connect regulators to this transceiver */ 8218c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) { 8228c2ecf20Sopenharmony_ci usb1v5.dev_name = dev_name(child); 8238c2ecf20Sopenharmony_ci usb1v8.dev_name = dev_name(child); 8248c2ecf20Sopenharmony_ci usb3v1.dev_name = dev_name(child); 8258c2ecf20Sopenharmony_ci } 8268c2ecf20Sopenharmony_ci } 8278c2ecf20Sopenharmony_ci 8288c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) { 8298c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_PM_RECEIVER, "twl4030_wdt", NULL, 8308c2ecf20Sopenharmony_ci 0, false, 0, 0); 8318c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8328c2ecf20Sopenharmony_ci return PTR_ERR(child); 8338c2ecf20Sopenharmony_ci } 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) { 8368c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_PM_MASTER, "twl4030_pwrbutton", 8378c2ecf20Sopenharmony_ci NULL, 0, true, irq_base + 8 + 0, 0); 8388c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8398c2ecf20Sopenharmony_ci return PTR_ERR(child); 8408c2ecf20Sopenharmony_ci } 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio && 8438c2ecf20Sopenharmony_ci twl_class_is_4030()) { 8448c2ecf20Sopenharmony_ci child = add_child(TWL4030_MODULE_AUDIO_VOICE, "twl4030-audio", 8458c2ecf20Sopenharmony_ci pdata->audio, sizeof(*pdata->audio), 8468c2ecf20Sopenharmony_ci false, 0, 0); 8478c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8488c2ecf20Sopenharmony_ci return PTR_ERR(child); 8498c2ecf20Sopenharmony_ci } 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci /* twl4030 regulators */ 8528c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_4030()) { 8538c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1, 8548c2ecf20Sopenharmony_ci features); 8558c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8568c2ecf20Sopenharmony_ci return PTR_ERR(child); 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VIO, pdata->vio, 8598c2ecf20Sopenharmony_ci features); 8608c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8618c2ecf20Sopenharmony_ci return PTR_ERR(child); 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1, 8648c2ecf20Sopenharmony_ci features); 8658c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8668c2ecf20Sopenharmony_ci return PTR_ERR(child); 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2, 8698c2ecf20Sopenharmony_ci features); 8708c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8718c2ecf20Sopenharmony_ci return PTR_ERR(child); 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1, 8748c2ecf20Sopenharmony_ci features); 8758c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8768c2ecf20Sopenharmony_ci return PTR_ERR(child); 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VDAC, pdata->vdac, 8798c2ecf20Sopenharmony_ci features); 8808c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8818c2ecf20Sopenharmony_ci return PTR_ERR(child); 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci child = add_regulator((features & TWL4030_VAUX2) 8848c2ecf20Sopenharmony_ci ? TWL4030_REG_VAUX2_4030 8858c2ecf20Sopenharmony_ci : TWL4030_REG_VAUX2, 8868c2ecf20Sopenharmony_ci pdata->vaux2, features); 8878c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8888c2ecf20Sopenharmony_ci return PTR_ERR(child); 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1, 8918c2ecf20Sopenharmony_ci features); 8928c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8938c2ecf20Sopenharmony_ci return PTR_ERR(child); 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2, 8968c2ecf20Sopenharmony_ci features); 8978c2ecf20Sopenharmony_ci if (IS_ERR(child)) 8988c2ecf20Sopenharmony_ci return PTR_ERR(child); 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig, 9018c2ecf20Sopenharmony_ci features); 9028c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9038c2ecf20Sopenharmony_ci return PTR_ERR(child); 9048c2ecf20Sopenharmony_ci } 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_ci /* maybe add LDOs that are omitted on cost-reduced parts */ 9078c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && !(features & TPS_SUBSET) 9088c2ecf20Sopenharmony_ci && twl_class_is_4030()) { 9098c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2, 9108c2ecf20Sopenharmony_ci features); 9118c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9128c2ecf20Sopenharmony_ci return PTR_ERR(child); 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2, 9158c2ecf20Sopenharmony_ci features); 9168c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9178c2ecf20Sopenharmony_ci return PTR_ERR(child); 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VSIM, pdata->vsim, 9208c2ecf20Sopenharmony_ci features); 9218c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9228c2ecf20Sopenharmony_ci return PTR_ERR(child); 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1, 9258c2ecf20Sopenharmony_ci features); 9268c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9278c2ecf20Sopenharmony_ci return PTR_ERR(child); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3, 9308c2ecf20Sopenharmony_ci features); 9318c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9328c2ecf20Sopenharmony_ci return PTR_ERR(child); 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4, 9358c2ecf20Sopenharmony_ci features); 9368c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9378c2ecf20Sopenharmony_ci return PTR_ERR(child); 9388c2ecf20Sopenharmony_ci } 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci && 9418c2ecf20Sopenharmony_ci !(features & (TPS_SUBSET | TWL5031))) { 9428c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_MAIN_CHARGE, "twl4030_bci", 9438c2ecf20Sopenharmony_ci pdata->bci, sizeof(*pdata->bci), false, 9448c2ecf20Sopenharmony_ci /* irq0 = CHG_PRES, irq1 = BCI */ 9458c2ecf20Sopenharmony_ci irq_base + BCI_PRES_INTR_OFFSET, 9468c2ecf20Sopenharmony_ci irq_base + BCI_INTR_OFFSET); 9478c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9488c2ecf20Sopenharmony_ci return PTR_ERR(child); 9498c2ecf20Sopenharmony_ci } 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power) { 9528c2ecf20Sopenharmony_ci child = add_child(TWL_MODULE_PM_MASTER, "twl4030_power", 9538c2ecf20Sopenharmony_ci pdata->power, sizeof(*pdata->power), false, 9548c2ecf20Sopenharmony_ci 0, 0); 9558c2ecf20Sopenharmony_ci if (IS_ERR(child)) 9568c2ecf20Sopenharmony_ci return PTR_ERR(child); 9578c2ecf20Sopenharmony_ci } 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci return 0; 9608c2ecf20Sopenharmony_ci} 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci/* 9658c2ecf20Sopenharmony_ci * These three functions initialize the on-chip clock framework, 9668c2ecf20Sopenharmony_ci * letting it generate the right frequencies for USB, MADC, and 9678c2ecf20Sopenharmony_ci * other purposes. 9688c2ecf20Sopenharmony_ci */ 9698c2ecf20Sopenharmony_cistatic inline int protect_pm_master(void) 9708c2ecf20Sopenharmony_ci{ 9718c2ecf20Sopenharmony_ci int e = 0; 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci e = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0, 9748c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PROTECT_KEY); 9758c2ecf20Sopenharmony_ci return e; 9768c2ecf20Sopenharmony_ci} 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_cistatic inline int unprotect_pm_master(void) 9798c2ecf20Sopenharmony_ci{ 9808c2ecf20Sopenharmony_ci int e = 0; 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_ci e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1, 9838c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PROTECT_KEY); 9848c2ecf20Sopenharmony_ci e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2, 9858c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PROTECT_KEY); 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci return e; 9888c2ecf20Sopenharmony_ci} 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_cistatic void clocks_init(struct device *dev, 9918c2ecf20Sopenharmony_ci struct twl4030_clock_init_data *clock) 9928c2ecf20Sopenharmony_ci{ 9938c2ecf20Sopenharmony_ci int e = 0; 9948c2ecf20Sopenharmony_ci struct clk *osc; 9958c2ecf20Sopenharmony_ci u32 rate; 9968c2ecf20Sopenharmony_ci u8 ctrl = HFCLK_FREQ_26_MHZ; 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci osc = clk_get(dev, "fck"); 9998c2ecf20Sopenharmony_ci if (IS_ERR(osc)) { 10008c2ecf20Sopenharmony_ci printk(KERN_WARNING "Skipping twl internal clock init and " 10018c2ecf20Sopenharmony_ci "using bootloader value (unknown osc rate)\n"); 10028c2ecf20Sopenharmony_ci return; 10038c2ecf20Sopenharmony_ci } 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci rate = clk_get_rate(osc); 10068c2ecf20Sopenharmony_ci clk_put(osc); 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci switch (rate) { 10098c2ecf20Sopenharmony_ci case 19200000: 10108c2ecf20Sopenharmony_ci ctrl = HFCLK_FREQ_19p2_MHZ; 10118c2ecf20Sopenharmony_ci break; 10128c2ecf20Sopenharmony_ci case 26000000: 10138c2ecf20Sopenharmony_ci ctrl = HFCLK_FREQ_26_MHZ; 10148c2ecf20Sopenharmony_ci break; 10158c2ecf20Sopenharmony_ci case 38400000: 10168c2ecf20Sopenharmony_ci ctrl = HFCLK_FREQ_38p4_MHZ; 10178c2ecf20Sopenharmony_ci break; 10188c2ecf20Sopenharmony_ci } 10198c2ecf20Sopenharmony_ci 10208c2ecf20Sopenharmony_ci ctrl |= HIGH_PERF_SQ; 10218c2ecf20Sopenharmony_ci if (clock && clock->ck32k_lowpwr_enable) 10228c2ecf20Sopenharmony_ci ctrl |= CK32K_LOWPWR_EN; 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci e |= unprotect_pm_master(); 10258c2ecf20Sopenharmony_ci /* effect->MADC+USB ck en */ 10268c2ecf20Sopenharmony_ci e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT); 10278c2ecf20Sopenharmony_ci e |= protect_pm_master(); 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci if (e < 0) 10308c2ecf20Sopenharmony_ci pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e); 10318c2ecf20Sopenharmony_ci} 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_cistatic int twl_remove(struct i2c_client *client) 10378c2ecf20Sopenharmony_ci{ 10388c2ecf20Sopenharmony_ci unsigned i, num_slaves; 10398c2ecf20Sopenharmony_ci int status; 10408c2ecf20Sopenharmony_ci 10418c2ecf20Sopenharmony_ci if (twl_class_is_4030()) 10428c2ecf20Sopenharmony_ci status = twl4030_exit_irq(); 10438c2ecf20Sopenharmony_ci else 10448c2ecf20Sopenharmony_ci status = twl6030_exit_irq(); 10458c2ecf20Sopenharmony_ci 10468c2ecf20Sopenharmony_ci if (status < 0) 10478c2ecf20Sopenharmony_ci return status; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci num_slaves = twl_get_num_slaves(); 10508c2ecf20Sopenharmony_ci for (i = 0; i < num_slaves; i++) { 10518c2ecf20Sopenharmony_ci struct twl_client *twl = &twl_priv->twl_modules[i]; 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci if (twl->client && twl->client != client) 10548c2ecf20Sopenharmony_ci i2c_unregister_device(twl->client); 10558c2ecf20Sopenharmony_ci twl->client = NULL; 10568c2ecf20Sopenharmony_ci } 10578c2ecf20Sopenharmony_ci twl_priv->ready = false; 10588c2ecf20Sopenharmony_ci return 0; 10598c2ecf20Sopenharmony_ci} 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_cistatic struct of_dev_auxdata twl_auxdata_lookup[] = { 10628c2ecf20Sopenharmony_ci OF_DEV_AUXDATA("ti,twl4030-gpio", 0, "twl4030-gpio", NULL), 10638c2ecf20Sopenharmony_ci { /* sentinel */ }, 10648c2ecf20Sopenharmony_ci}; 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_ci/* NOTE: This driver only handles a single twl4030/tps659x0 chip */ 10678c2ecf20Sopenharmony_cistatic int 10688c2ecf20Sopenharmony_citwl_probe(struct i2c_client *client, const struct i2c_device_id *id) 10698c2ecf20Sopenharmony_ci{ 10708c2ecf20Sopenharmony_ci struct twl4030_platform_data *pdata = dev_get_platdata(&client->dev); 10718c2ecf20Sopenharmony_ci struct device_node *node = client->dev.of_node; 10728c2ecf20Sopenharmony_ci struct platform_device *pdev; 10738c2ecf20Sopenharmony_ci const struct regmap_config *twl_regmap_config; 10748c2ecf20Sopenharmony_ci int irq_base = 0; 10758c2ecf20Sopenharmony_ci int status; 10768c2ecf20Sopenharmony_ci unsigned i, num_slaves; 10778c2ecf20Sopenharmony_ci 10788c2ecf20Sopenharmony_ci if (!node && !pdata) { 10798c2ecf20Sopenharmony_ci dev_err(&client->dev, "no platform data\n"); 10808c2ecf20Sopenharmony_ci return -EINVAL; 10818c2ecf20Sopenharmony_ci } 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci if (twl_priv) { 10848c2ecf20Sopenharmony_ci dev_dbg(&client->dev, "only one instance of %s allowed\n", 10858c2ecf20Sopenharmony_ci DRIVER_NAME); 10868c2ecf20Sopenharmony_ci return -EBUSY; 10878c2ecf20Sopenharmony_ci } 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_ci pdev = platform_device_alloc(DRIVER_NAME, -1); 10908c2ecf20Sopenharmony_ci if (!pdev) { 10918c2ecf20Sopenharmony_ci dev_err(&client->dev, "can't alloc pdev\n"); 10928c2ecf20Sopenharmony_ci return -ENOMEM; 10938c2ecf20Sopenharmony_ci } 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci status = platform_device_add(pdev); 10968c2ecf20Sopenharmony_ci if (status) { 10978c2ecf20Sopenharmony_ci platform_device_put(pdev); 10988c2ecf20Sopenharmony_ci return status; 10998c2ecf20Sopenharmony_ci } 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { 11028c2ecf20Sopenharmony_ci dev_dbg(&client->dev, "can't talk I2C?\n"); 11038c2ecf20Sopenharmony_ci status = -EIO; 11048c2ecf20Sopenharmony_ci goto free; 11058c2ecf20Sopenharmony_ci } 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private), 11088c2ecf20Sopenharmony_ci GFP_KERNEL); 11098c2ecf20Sopenharmony_ci if (!twl_priv) { 11108c2ecf20Sopenharmony_ci status = -ENOMEM; 11118c2ecf20Sopenharmony_ci goto free; 11128c2ecf20Sopenharmony_ci } 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci if ((id->driver_data) & TWL6030_CLASS) { 11158c2ecf20Sopenharmony_ci twl_priv->twl_id = TWL6030_CLASS_ID; 11168c2ecf20Sopenharmony_ci twl_priv->twl_map = &twl6030_map[0]; 11178c2ecf20Sopenharmony_ci /* The charger base address is different in twl6032 */ 11188c2ecf20Sopenharmony_ci if ((id->driver_data) & TWL6032_SUBCLASS) 11198c2ecf20Sopenharmony_ci twl_priv->twl_map[TWL_MODULE_MAIN_CHARGE].base = 11208c2ecf20Sopenharmony_ci TWL6032_BASEADD_CHARGER; 11218c2ecf20Sopenharmony_ci twl_regmap_config = twl6030_regmap_config; 11228c2ecf20Sopenharmony_ci } else { 11238c2ecf20Sopenharmony_ci twl_priv->twl_id = TWL4030_CLASS_ID; 11248c2ecf20Sopenharmony_ci twl_priv->twl_map = &twl4030_map[0]; 11258c2ecf20Sopenharmony_ci twl_regmap_config = twl4030_regmap_config; 11268c2ecf20Sopenharmony_ci } 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci num_slaves = twl_get_num_slaves(); 11298c2ecf20Sopenharmony_ci twl_priv->twl_modules = devm_kcalloc(&client->dev, 11308c2ecf20Sopenharmony_ci num_slaves, 11318c2ecf20Sopenharmony_ci sizeof(struct twl_client), 11328c2ecf20Sopenharmony_ci GFP_KERNEL); 11338c2ecf20Sopenharmony_ci if (!twl_priv->twl_modules) { 11348c2ecf20Sopenharmony_ci status = -ENOMEM; 11358c2ecf20Sopenharmony_ci goto free; 11368c2ecf20Sopenharmony_ci } 11378c2ecf20Sopenharmony_ci 11388c2ecf20Sopenharmony_ci for (i = 0; i < num_slaves; i++) { 11398c2ecf20Sopenharmony_ci struct twl_client *twl = &twl_priv->twl_modules[i]; 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci if (i == 0) { 11428c2ecf20Sopenharmony_ci twl->client = client; 11438c2ecf20Sopenharmony_ci } else { 11448c2ecf20Sopenharmony_ci twl->client = i2c_new_dummy_device(client->adapter, 11458c2ecf20Sopenharmony_ci client->addr + i); 11468c2ecf20Sopenharmony_ci if (IS_ERR(twl->client)) { 11478c2ecf20Sopenharmony_ci dev_err(&client->dev, 11488c2ecf20Sopenharmony_ci "can't attach client %d\n", i); 11498c2ecf20Sopenharmony_ci status = PTR_ERR(twl->client); 11508c2ecf20Sopenharmony_ci goto fail; 11518c2ecf20Sopenharmony_ci } 11528c2ecf20Sopenharmony_ci } 11538c2ecf20Sopenharmony_ci 11548c2ecf20Sopenharmony_ci twl->regmap = devm_regmap_init_i2c(twl->client, 11558c2ecf20Sopenharmony_ci &twl_regmap_config[i]); 11568c2ecf20Sopenharmony_ci if (IS_ERR(twl->regmap)) { 11578c2ecf20Sopenharmony_ci status = PTR_ERR(twl->regmap); 11588c2ecf20Sopenharmony_ci dev_err(&client->dev, 11598c2ecf20Sopenharmony_ci "Failed to allocate regmap %d, err: %d\n", i, 11608c2ecf20Sopenharmony_ci status); 11618c2ecf20Sopenharmony_ci goto fail; 11628c2ecf20Sopenharmony_ci } 11638c2ecf20Sopenharmony_ci } 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_ci twl_priv->ready = true; 11668c2ecf20Sopenharmony_ci 11678c2ecf20Sopenharmony_ci /* setup clock framework */ 11688c2ecf20Sopenharmony_ci clocks_init(&client->dev, pdata ? pdata->clock : NULL); 11698c2ecf20Sopenharmony_ci 11708c2ecf20Sopenharmony_ci /* read TWL IDCODE Register */ 11718c2ecf20Sopenharmony_ci if (twl_class_is_4030()) { 11728c2ecf20Sopenharmony_ci status = twl_read_idcode_register(); 11738c2ecf20Sopenharmony_ci WARN(status < 0, "Error: reading twl_idcode register value\n"); 11748c2ecf20Sopenharmony_ci } 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci /* Maybe init the T2 Interrupt subsystem */ 11778c2ecf20Sopenharmony_ci if (client->irq) { 11788c2ecf20Sopenharmony_ci if (twl_class_is_4030()) { 11798c2ecf20Sopenharmony_ci twl4030_init_chip_irq(id->name); 11808c2ecf20Sopenharmony_ci irq_base = twl4030_init_irq(&client->dev, client->irq); 11818c2ecf20Sopenharmony_ci } else { 11828c2ecf20Sopenharmony_ci irq_base = twl6030_init_irq(&client->dev, client->irq); 11838c2ecf20Sopenharmony_ci } 11848c2ecf20Sopenharmony_ci 11858c2ecf20Sopenharmony_ci if (irq_base < 0) { 11868c2ecf20Sopenharmony_ci status = irq_base; 11878c2ecf20Sopenharmony_ci goto fail; 11888c2ecf20Sopenharmony_ci } 11898c2ecf20Sopenharmony_ci } 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci /* 11928c2ecf20Sopenharmony_ci * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. 11938c2ecf20Sopenharmony_ci * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0, 11948c2ecf20Sopenharmony_ci * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0. 11958c2ecf20Sopenharmony_ci * 11968c2ecf20Sopenharmony_ci * Also, always enable SmartReflex bit as that's needed for omaps to 11978c2ecf20Sopenharmony_ci * to do anything over I2C4 for voltage scaling even if SmartReflex 11988c2ecf20Sopenharmony_ci * is disabled. Without the SmartReflex bit omap sys_clkreq idle 11998c2ecf20Sopenharmony_ci * signal will never trigger for retention idle. 12008c2ecf20Sopenharmony_ci */ 12018c2ecf20Sopenharmony_ci if (twl_class_is_4030()) { 12028c2ecf20Sopenharmony_ci u8 temp; 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1); 12058c2ecf20Sopenharmony_ci temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \ 12068c2ecf20Sopenharmony_ci I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU); 12078c2ecf20Sopenharmony_ci twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); 12088c2ecf20Sopenharmony_ci 12098c2ecf20Sopenharmony_ci twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &temp, 12108c2ecf20Sopenharmony_ci TWL4030_DCDC_GLOBAL_CFG); 12118c2ecf20Sopenharmony_ci temp |= SMARTREFLEX_ENABLE; 12128c2ecf20Sopenharmony_ci twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, temp, 12138c2ecf20Sopenharmony_ci TWL4030_DCDC_GLOBAL_CFG); 12148c2ecf20Sopenharmony_ci } 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci if (node) { 12178c2ecf20Sopenharmony_ci if (pdata) 12188c2ecf20Sopenharmony_ci twl_auxdata_lookup[0].platform_data = pdata->gpio; 12198c2ecf20Sopenharmony_ci status = of_platform_populate(node, NULL, twl_auxdata_lookup, 12208c2ecf20Sopenharmony_ci &client->dev); 12218c2ecf20Sopenharmony_ci } else { 12228c2ecf20Sopenharmony_ci status = add_children(pdata, irq_base, id->driver_data); 12238c2ecf20Sopenharmony_ci } 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_cifail: 12268c2ecf20Sopenharmony_ci if (status < 0) 12278c2ecf20Sopenharmony_ci twl_remove(client); 12288c2ecf20Sopenharmony_cifree: 12298c2ecf20Sopenharmony_ci if (status < 0) 12308c2ecf20Sopenharmony_ci platform_device_unregister(pdev); 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_ci return status; 12338c2ecf20Sopenharmony_ci} 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_cistatic int __maybe_unused twl_suspend(struct device *dev) 12368c2ecf20Sopenharmony_ci{ 12378c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci if (client->irq) 12408c2ecf20Sopenharmony_ci disable_irq(client->irq); 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ci return 0; 12438c2ecf20Sopenharmony_ci} 12448c2ecf20Sopenharmony_ci 12458c2ecf20Sopenharmony_cistatic int __maybe_unused twl_resume(struct device *dev) 12468c2ecf20Sopenharmony_ci{ 12478c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci if (client->irq) 12508c2ecf20Sopenharmony_ci enable_irq(client->irq); 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci return 0; 12538c2ecf20Sopenharmony_ci} 12548c2ecf20Sopenharmony_ci 12558c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(twl_dev_pm_ops, twl_suspend, twl_resume); 12568c2ecf20Sopenharmony_ci 12578c2ecf20Sopenharmony_cistatic const struct i2c_device_id twl_ids[] = { 12588c2ecf20Sopenharmony_ci { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */ 12598c2ecf20Sopenharmony_ci { "twl5030", 0 }, /* T2 updated */ 12608c2ecf20Sopenharmony_ci { "twl5031", TWL5031 }, /* TWL5030 updated */ 12618c2ecf20Sopenharmony_ci { "tps65950", 0 }, /* catalog version of twl5030 */ 12628c2ecf20Sopenharmony_ci { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */ 12638c2ecf20Sopenharmony_ci { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */ 12648c2ecf20Sopenharmony_ci { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED 12658c2ecf20Sopenharmony_ci and vibrator. Charger in USB module*/ 12668c2ecf20Sopenharmony_ci { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */ 12678c2ecf20Sopenharmony_ci { "twl6032", TWL6030_CLASS | TWL6032_SUBCLASS }, /* "Phoenix lite" */ 12688c2ecf20Sopenharmony_ci { /* end of list */ }, 12698c2ecf20Sopenharmony_ci}; 12708c2ecf20Sopenharmony_ci 12718c2ecf20Sopenharmony_ci/* One Client Driver , 4 Clients */ 12728c2ecf20Sopenharmony_cistatic struct i2c_driver twl_driver = { 12738c2ecf20Sopenharmony_ci .driver.name = DRIVER_NAME, 12748c2ecf20Sopenharmony_ci .driver.pm = &twl_dev_pm_ops, 12758c2ecf20Sopenharmony_ci .id_table = twl_ids, 12768c2ecf20Sopenharmony_ci .probe = twl_probe, 12778c2ecf20Sopenharmony_ci .remove = twl_remove, 12788c2ecf20Sopenharmony_ci}; 12798c2ecf20Sopenharmony_cibuiltin_i2c_driver(twl_driver); 1280