1c20e8c5bSSebastian Reichel // SPDX-License-Identifier: GPL-2.0-only 2c20e8c5bSSebastian Reichel /* 3c20e8c5bSSebastian Reichel * MFD core driver for Rockchip RK8XX 4c20e8c5bSSebastian Reichel * 5c20e8c5bSSebastian Reichel * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd 6c20e8c5bSSebastian Reichel * Copyright (C) 2016 PHYTEC Messtechnik GmbH 7c20e8c5bSSebastian Reichel * 8c20e8c5bSSebastian Reichel * Author: Chris Zhong <zyw@rock-chips.com> 9c20e8c5bSSebastian Reichel * Author: Zhang Qing <zhangqing@rock-chips.com> 10c20e8c5bSSebastian Reichel * Author: Wadim Egorov <w.egorov@phytec.de> 11c20e8c5bSSebastian Reichel */ 12c20e8c5bSSebastian Reichel 13c20e8c5bSSebastian Reichel #include <linux/interrupt.h> 14c20e8c5bSSebastian Reichel #include <linux/mfd/rk808.h> 15c20e8c5bSSebastian Reichel #include <linux/mfd/core.h> 16c20e8c5bSSebastian Reichel #include <linux/module.h> 17c20e8c5bSSebastian Reichel #include <linux/of_device.h> 18c20e8c5bSSebastian Reichel #include <linux/regmap.h> 19c20e8c5bSSebastian Reichel #include <linux/reboot.h> 20c20e8c5bSSebastian Reichel 21c20e8c5bSSebastian Reichel struct rk808_reg_data { 22c20e8c5bSSebastian Reichel int addr; 23c20e8c5bSSebastian Reichel int mask; 24c20e8c5bSSebastian Reichel int value; 25c20e8c5bSSebastian Reichel }; 26c20e8c5bSSebastian Reichel 27c20e8c5bSSebastian Reichel static const struct resource rtc_resources[] = { 28c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK808_IRQ_RTC_ALARM), 29c20e8c5bSSebastian Reichel }; 30c20e8c5bSSebastian Reichel 31c20e8c5bSSebastian Reichel static const struct resource rk817_rtc_resources[] = { 32c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK817_IRQ_RTC_ALARM), 33c20e8c5bSSebastian Reichel }; 34c20e8c5bSSebastian Reichel 35c20e8c5bSSebastian Reichel static const struct resource rk805_key_resources[] = { 36c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK805_IRQ_PWRON_RISE), 37c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK805_IRQ_PWRON_FALL), 38c20e8c5bSSebastian Reichel }; 39c20e8c5bSSebastian Reichel 40*210f418fSSebastian Reichel static struct resource rk806_pwrkey_resources[] = { 41*210f418fSSebastian Reichel DEFINE_RES_IRQ(RK806_IRQ_PWRON_FALL), 42*210f418fSSebastian Reichel DEFINE_RES_IRQ(RK806_IRQ_PWRON_RISE), 43*210f418fSSebastian Reichel }; 44*210f418fSSebastian Reichel 45c20e8c5bSSebastian Reichel static const struct resource rk817_pwrkey_resources[] = { 46c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK817_IRQ_PWRON_RISE), 47c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK817_IRQ_PWRON_FALL), 48c20e8c5bSSebastian Reichel }; 49c20e8c5bSSebastian Reichel 50c20e8c5bSSebastian Reichel static const struct resource rk817_charger_resources[] = { 51c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK817_IRQ_PLUG_IN), 52c20e8c5bSSebastian Reichel DEFINE_RES_IRQ(RK817_IRQ_PLUG_OUT), 53c20e8c5bSSebastian Reichel }; 54c20e8c5bSSebastian Reichel 55c20e8c5bSSebastian Reichel static const struct mfd_cell rk805s[] = { 56c20e8c5bSSebastian Reichel { .name = "rk808-clkout", .id = PLATFORM_DEVID_NONE, }, 57c20e8c5bSSebastian Reichel { .name = "rk808-regulator", .id = PLATFORM_DEVID_NONE, }, 58c20e8c5bSSebastian Reichel { .name = "rk805-pinctrl", .id = PLATFORM_DEVID_NONE, }, 59c20e8c5bSSebastian Reichel { 60c20e8c5bSSebastian Reichel .name = "rk808-rtc", 61c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rtc_resources), 62c20e8c5bSSebastian Reichel .resources = &rtc_resources[0], 63c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 64c20e8c5bSSebastian Reichel }, 65c20e8c5bSSebastian Reichel { .name = "rk805-pwrkey", 66c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rk805_key_resources), 67c20e8c5bSSebastian Reichel .resources = &rk805_key_resources[0], 68c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 69c20e8c5bSSebastian Reichel }, 70c20e8c5bSSebastian Reichel }; 71c20e8c5bSSebastian Reichel 72*210f418fSSebastian Reichel static const struct mfd_cell rk806s[] = { 73*210f418fSSebastian Reichel { .name = "rk805-pinctrl", .id = PLATFORM_DEVID_AUTO, }, 74*210f418fSSebastian Reichel { .name = "rk808-regulator", .id = PLATFORM_DEVID_AUTO, }, 75*210f418fSSebastian Reichel { 76*210f418fSSebastian Reichel .name = "rk805-pwrkey", 77*210f418fSSebastian Reichel .resources = rk806_pwrkey_resources, 78*210f418fSSebastian Reichel .num_resources = ARRAY_SIZE(rk806_pwrkey_resources), 79*210f418fSSebastian Reichel .id = PLATFORM_DEVID_AUTO, 80*210f418fSSebastian Reichel }, 81*210f418fSSebastian Reichel }; 82*210f418fSSebastian Reichel 83c20e8c5bSSebastian Reichel static const struct mfd_cell rk808s[] = { 84c20e8c5bSSebastian Reichel { .name = "rk808-clkout", .id = PLATFORM_DEVID_NONE, }, 85c20e8c5bSSebastian Reichel { .name = "rk808-regulator", .id = PLATFORM_DEVID_NONE, }, 86c20e8c5bSSebastian Reichel { 87c20e8c5bSSebastian Reichel .name = "rk808-rtc", 88c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rtc_resources), 89c20e8c5bSSebastian Reichel .resources = rtc_resources, 90c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 91c20e8c5bSSebastian Reichel }, 92c20e8c5bSSebastian Reichel }; 93c20e8c5bSSebastian Reichel 94c20e8c5bSSebastian Reichel static const struct mfd_cell rk817s[] = { 95c20e8c5bSSebastian Reichel { .name = "rk808-clkout", .id = PLATFORM_DEVID_NONE, }, 96c20e8c5bSSebastian Reichel { .name = "rk808-regulator", .id = PLATFORM_DEVID_NONE, }, 97c20e8c5bSSebastian Reichel { 98c20e8c5bSSebastian Reichel .name = "rk805-pwrkey", 99c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rk817_pwrkey_resources), 100c20e8c5bSSebastian Reichel .resources = &rk817_pwrkey_resources[0], 101c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 102c20e8c5bSSebastian Reichel }, 103c20e8c5bSSebastian Reichel { 104c20e8c5bSSebastian Reichel .name = "rk808-rtc", 105c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rk817_rtc_resources), 106c20e8c5bSSebastian Reichel .resources = &rk817_rtc_resources[0], 107c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 108c20e8c5bSSebastian Reichel }, 109c20e8c5bSSebastian Reichel { .name = "rk817-codec", .id = PLATFORM_DEVID_NONE, }, 110c20e8c5bSSebastian Reichel { 111c20e8c5bSSebastian Reichel .name = "rk817-charger", 112c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rk817_charger_resources), 113c20e8c5bSSebastian Reichel .resources = &rk817_charger_resources[0], 114c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 115c20e8c5bSSebastian Reichel }, 116c20e8c5bSSebastian Reichel }; 117c20e8c5bSSebastian Reichel 118c20e8c5bSSebastian Reichel static const struct mfd_cell rk818s[] = { 119c20e8c5bSSebastian Reichel { .name = "rk808-clkout", .id = PLATFORM_DEVID_NONE, }, 120c20e8c5bSSebastian Reichel { .name = "rk808-regulator", .id = PLATFORM_DEVID_NONE, }, 121c20e8c5bSSebastian Reichel { 122c20e8c5bSSebastian Reichel .name = "rk808-rtc", 123c20e8c5bSSebastian Reichel .num_resources = ARRAY_SIZE(rtc_resources), 124c20e8c5bSSebastian Reichel .resources = rtc_resources, 125c20e8c5bSSebastian Reichel .id = PLATFORM_DEVID_NONE, 126c20e8c5bSSebastian Reichel }, 127c20e8c5bSSebastian Reichel }; 128c20e8c5bSSebastian Reichel 129c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk805_pre_init_reg[] = { 130c20e8c5bSSebastian Reichel {RK805_BUCK1_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK, 131c20e8c5bSSebastian Reichel RK805_BUCK1_2_ILMAX_4000MA}, 132c20e8c5bSSebastian Reichel {RK805_BUCK2_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK, 133c20e8c5bSSebastian Reichel RK805_BUCK1_2_ILMAX_4000MA}, 134c20e8c5bSSebastian Reichel {RK805_BUCK3_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK, 135c20e8c5bSSebastian Reichel RK805_BUCK3_ILMAX_3000MA}, 136c20e8c5bSSebastian Reichel {RK805_BUCK4_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK, 137c20e8c5bSSebastian Reichel RK805_BUCK4_ILMAX_3500MA}, 138c20e8c5bSSebastian Reichel {RK805_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_400MA}, 139c20e8c5bSSebastian Reichel {RK805_THERMAL_REG, TEMP_HOTDIE_MSK, TEMP115C}, 140c20e8c5bSSebastian Reichel }; 141c20e8c5bSSebastian Reichel 142*210f418fSSebastian Reichel static const struct rk808_reg_data rk806_pre_init_reg[] = { 143*210f418fSSebastian Reichel { RK806_GPIO_INT_CONFIG, RK806_INT_POL_MSK, RK806_INT_POL_L }, 144*210f418fSSebastian Reichel { RK806_SYS_CFG3, RK806_SLAVE_RESTART_FUN_MSK, RK806_SLAVE_RESTART_FUN_EN }, 145*210f418fSSebastian Reichel { RK806_SYS_OPTION, RK806_SYS_ENB2_2M_MSK, RK806_SYS_ENB2_2M_EN }, 146*210f418fSSebastian Reichel }; 147*210f418fSSebastian Reichel 148c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk808_pre_init_reg[] = { 149c20e8c5bSSebastian Reichel { RK808_BUCK3_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_150MA }, 150c20e8c5bSSebastian Reichel { RK808_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_200MA }, 151c20e8c5bSSebastian Reichel { RK808_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA }, 152c20e8c5bSSebastian Reichel { RK808_BUCK1_CONFIG_REG, BUCK1_RATE_MASK, BUCK_ILMIN_200MA }, 153c20e8c5bSSebastian Reichel { RK808_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_200MA }, 154c20e8c5bSSebastian Reichel { RK808_DCDC_UV_ACT_REG, BUCK_UV_ACT_MASK, BUCK_UV_ACT_DISABLE}, 155c20e8c5bSSebastian Reichel { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT | 156c20e8c5bSSebastian Reichel VB_LO_SEL_3500MV }, 157c20e8c5bSSebastian Reichel }; 158c20e8c5bSSebastian Reichel 159c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk817_pre_init_reg[] = { 160c20e8c5bSSebastian Reichel {RK817_RTC_CTRL_REG, RTC_STOP, RTC_STOP}, 161c20e8c5bSSebastian Reichel /* Codec specific registers */ 162c20e8c5bSSebastian Reichel { RK817_CODEC_DTOP_VUCTL, MASK_ALL, 0x03 }, 163c20e8c5bSSebastian Reichel { RK817_CODEC_DTOP_VUCTIME, MASK_ALL, 0x00 }, 164c20e8c5bSSebastian Reichel { RK817_CODEC_DTOP_LPT_SRST, MASK_ALL, 0x00 }, 165c20e8c5bSSebastian Reichel { RK817_CODEC_DTOP_DIGEN_CLKE, MASK_ALL, 0x00 }, 166c20e8c5bSSebastian Reichel /* from vendor driver, CODEC_AREF_RTCFG0 not defined in data sheet */ 167c20e8c5bSSebastian Reichel { RK817_CODEC_AREF_RTCFG0, MASK_ALL, 0x00 }, 168c20e8c5bSSebastian Reichel { RK817_CODEC_AREF_RTCFG1, MASK_ALL, 0x06 }, 169c20e8c5bSSebastian Reichel { RK817_CODEC_AADC_CFG0, MASK_ALL, 0xc8 }, 170c20e8c5bSSebastian Reichel /* from vendor driver, CODEC_AADC_CFG1 not defined in data sheet */ 171c20e8c5bSSebastian Reichel { RK817_CODEC_AADC_CFG1, MASK_ALL, 0x00 }, 172c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_VOLL, MASK_ALL, 0x00 }, 173c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_VOLR, MASK_ALL, 0x00 }, 174c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_SR_ACL0, MASK_ALL, 0x00 }, 175c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_ALC1, MASK_ALL, 0x00 }, 176c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_ALC2, MASK_ALL, 0x00 }, 177c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_NG, MASK_ALL, 0x00 }, 178c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_HPF, MASK_ALL, 0x00 }, 179c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_RVOLL, MASK_ALL, 0xff }, 180c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_RVOLR, MASK_ALL, 0xff }, 181c20e8c5bSSebastian Reichel { RK817_CODEC_AMIC_CFG0, MASK_ALL, 0x70 }, 182c20e8c5bSSebastian Reichel { RK817_CODEC_AMIC_CFG1, MASK_ALL, 0x00 }, 183c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_PGA_GAIN, MASK_ALL, 0x66 }, 184c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_LMT1, MASK_ALL, 0x00 }, 185c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_LMT2, MASK_ALL, 0x00 }, 186c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_NG1, MASK_ALL, 0x00 }, 187c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_NG2, MASK_ALL, 0x00 }, 188c20e8c5bSSebastian Reichel /* from vendor driver, CODEC_ADAC_CFG0 not defined in data sheet */ 189c20e8c5bSSebastian Reichel { RK817_CODEC_ADAC_CFG0, MASK_ALL, 0x00 }, 190c20e8c5bSSebastian Reichel { RK817_CODEC_ADAC_CFG1, MASK_ALL, 0x07 }, 191c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_POPD_DACST, MASK_ALL, 0x82 }, 192c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_VOLL, MASK_ALL, 0x00 }, 193c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_VOLR, MASK_ALL, 0x00 }, 194c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_SR_LMT0, MASK_ALL, 0x00 }, 195c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_LMT1, MASK_ALL, 0x00 }, 196c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_LMT2, MASK_ALL, 0x00 }, 197c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_MUTE_MIXCTL, MASK_ALL, 0xa0 }, 198c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_RVOLL, MASK_ALL, 0xff }, 199c20e8c5bSSebastian Reichel { RK817_CODEC_DADC_RVOLR, MASK_ALL, 0xff }, 200c20e8c5bSSebastian Reichel { RK817_CODEC_AMIC_CFG0, MASK_ALL, 0x70 }, 201c20e8c5bSSebastian Reichel { RK817_CODEC_AMIC_CFG1, MASK_ALL, 0x00 }, 202c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_PGA_GAIN, MASK_ALL, 0x66 }, 203c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_LMT1, MASK_ALL, 0x00 }, 204c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_LMT2, MASK_ALL, 0x00 }, 205c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_NG1, MASK_ALL, 0x00 }, 206c20e8c5bSSebastian Reichel { RK817_CODEC_DMIC_NG2, MASK_ALL, 0x00 }, 207c20e8c5bSSebastian Reichel /* from vendor driver, CODEC_ADAC_CFG0 not defined in data sheet */ 208c20e8c5bSSebastian Reichel { RK817_CODEC_ADAC_CFG0, MASK_ALL, 0x00 }, 209c20e8c5bSSebastian Reichel { RK817_CODEC_ADAC_CFG1, MASK_ALL, 0x07 }, 210c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_POPD_DACST, MASK_ALL, 0x82 }, 211c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_VOLL, MASK_ALL, 0x00 }, 212c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_VOLR, MASK_ALL, 0x00 }, 213c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_SR_LMT0, MASK_ALL, 0x00 }, 214c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_LMT1, MASK_ALL, 0x00 }, 215c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_LMT2, MASK_ALL, 0x00 }, 216c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_MUTE_MIXCTL, MASK_ALL, 0xa0 }, 217c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_RVOLL, MASK_ALL, 0xff }, 218c20e8c5bSSebastian Reichel { RK817_CODEC_DDAC_RVOLR, MASK_ALL, 0xff }, 219c20e8c5bSSebastian Reichel { RK817_CODEC_AHP_ANTI0, MASK_ALL, 0x00 }, 220c20e8c5bSSebastian Reichel { RK817_CODEC_AHP_ANTI1, MASK_ALL, 0x00 }, 221c20e8c5bSSebastian Reichel { RK817_CODEC_AHP_CFG0, MASK_ALL, 0xe0 }, 222c20e8c5bSSebastian Reichel { RK817_CODEC_AHP_CFG1, MASK_ALL, 0x1f }, 223c20e8c5bSSebastian Reichel { RK817_CODEC_AHP_CP, MASK_ALL, 0x09 }, 224c20e8c5bSSebastian Reichel { RK817_CODEC_ACLASSD_CFG1, MASK_ALL, 0x69 }, 225c20e8c5bSSebastian Reichel { RK817_CODEC_ACLASSD_CFG2, MASK_ALL, 0x44 }, 226c20e8c5bSSebastian Reichel { RK817_CODEC_APLL_CFG0, MASK_ALL, 0x04 }, 227c20e8c5bSSebastian Reichel { RK817_CODEC_APLL_CFG1, MASK_ALL, 0x00 }, 228c20e8c5bSSebastian Reichel { RK817_CODEC_APLL_CFG2, MASK_ALL, 0x30 }, 229c20e8c5bSSebastian Reichel { RK817_CODEC_APLL_CFG3, MASK_ALL, 0x19 }, 230c20e8c5bSSebastian Reichel { RK817_CODEC_APLL_CFG4, MASK_ALL, 0x65 }, 231c20e8c5bSSebastian Reichel { RK817_CODEC_APLL_CFG5, MASK_ALL, 0x01 }, 232c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_CKM, MASK_ALL, 0x01 }, 233c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_RSD, MASK_ALL, 0x00 }, 234c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_RXCR1, MASK_ALL, 0x00 }, 235c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_RXCR2, MASK_ALL, 0x17 }, 236c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_RXCMD_TSD, MASK_ALL, 0x00 }, 237c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_TXCR1, MASK_ALL, 0x00 }, 238c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_TXCR2, MASK_ALL, 0x17 }, 239c20e8c5bSSebastian Reichel { RK817_CODEC_DI2S_TXCR3_TXCMD, MASK_ALL, 0x00 }, 240c20e8c5bSSebastian Reichel {RK817_GPIO_INT_CFG, RK817_INT_POL_MSK, RK817_INT_POL_L}, 241c20e8c5bSSebastian Reichel {RK817_SYS_CFG(1), RK817_HOTDIE_TEMP_MSK | RK817_TSD_TEMP_MSK, 242c20e8c5bSSebastian Reichel RK817_HOTDIE_105 | RK817_TSD_140}, 243c20e8c5bSSebastian Reichel }; 244c20e8c5bSSebastian Reichel 245c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk818_pre_init_reg[] = { 246c20e8c5bSSebastian Reichel /* improve efficiency */ 247c20e8c5bSSebastian Reichel { RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_250MA }, 248c20e8c5bSSebastian Reichel { RK818_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_250MA }, 249c20e8c5bSSebastian Reichel { RK818_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA }, 250c20e8c5bSSebastian Reichel { RK818_USB_CTRL_REG, RK818_USB_ILIM_SEL_MASK, 251c20e8c5bSSebastian Reichel RK818_USB_ILMIN_2000MA }, 252c20e8c5bSSebastian Reichel /* close charger when usb lower then 3.4V */ 253c20e8c5bSSebastian Reichel { RK818_USB_CTRL_REG, RK818_USB_CHG_SD_VSEL_MASK, 254c20e8c5bSSebastian Reichel (0x7 << 4) }, 255c20e8c5bSSebastian Reichel /* no action when vref */ 256c20e8c5bSSebastian Reichel { RK818_H5V_EN_REG, BIT(1), RK818_REF_RDY_CTRL }, 257c20e8c5bSSebastian Reichel /* enable HDMI 5V */ 258c20e8c5bSSebastian Reichel { RK818_H5V_EN_REG, BIT(0), RK818_H5V_EN }, 259c20e8c5bSSebastian Reichel { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT | 260c20e8c5bSSebastian Reichel VB_LO_SEL_3500MV }, 261c20e8c5bSSebastian Reichel }; 262c20e8c5bSSebastian Reichel 263c20e8c5bSSebastian Reichel static const struct regmap_irq rk805_irqs[] = { 264c20e8c5bSSebastian Reichel [RK805_IRQ_PWRON_RISE] = { 265c20e8c5bSSebastian Reichel .mask = RK805_IRQ_PWRON_RISE_MSK, 266c20e8c5bSSebastian Reichel .reg_offset = 0, 267c20e8c5bSSebastian Reichel }, 268c20e8c5bSSebastian Reichel [RK805_IRQ_VB_LOW] = { 269c20e8c5bSSebastian Reichel .mask = RK805_IRQ_VB_LOW_MSK, 270c20e8c5bSSebastian Reichel .reg_offset = 0, 271c20e8c5bSSebastian Reichel }, 272c20e8c5bSSebastian Reichel [RK805_IRQ_PWRON] = { 273c20e8c5bSSebastian Reichel .mask = RK805_IRQ_PWRON_MSK, 274c20e8c5bSSebastian Reichel .reg_offset = 0, 275c20e8c5bSSebastian Reichel }, 276c20e8c5bSSebastian Reichel [RK805_IRQ_PWRON_LP] = { 277c20e8c5bSSebastian Reichel .mask = RK805_IRQ_PWRON_LP_MSK, 278c20e8c5bSSebastian Reichel .reg_offset = 0, 279c20e8c5bSSebastian Reichel }, 280c20e8c5bSSebastian Reichel [RK805_IRQ_HOTDIE] = { 281c20e8c5bSSebastian Reichel .mask = RK805_IRQ_HOTDIE_MSK, 282c20e8c5bSSebastian Reichel .reg_offset = 0, 283c20e8c5bSSebastian Reichel }, 284c20e8c5bSSebastian Reichel [RK805_IRQ_RTC_ALARM] = { 285c20e8c5bSSebastian Reichel .mask = RK805_IRQ_RTC_ALARM_MSK, 286c20e8c5bSSebastian Reichel .reg_offset = 0, 287c20e8c5bSSebastian Reichel }, 288c20e8c5bSSebastian Reichel [RK805_IRQ_RTC_PERIOD] = { 289c20e8c5bSSebastian Reichel .mask = RK805_IRQ_RTC_PERIOD_MSK, 290c20e8c5bSSebastian Reichel .reg_offset = 0, 291c20e8c5bSSebastian Reichel }, 292c20e8c5bSSebastian Reichel [RK805_IRQ_PWRON_FALL] = { 293c20e8c5bSSebastian Reichel .mask = RK805_IRQ_PWRON_FALL_MSK, 294c20e8c5bSSebastian Reichel .reg_offset = 0, 295c20e8c5bSSebastian Reichel }, 296c20e8c5bSSebastian Reichel }; 297c20e8c5bSSebastian Reichel 298*210f418fSSebastian Reichel static const struct regmap_irq rk806_irqs[] = { 299*210f418fSSebastian Reichel /* INT_STS0 IRQs */ 300*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_PWRON_FALL, 0, RK806_INT_STS_PWRON_FALL), 301*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_PWRON_RISE, 0, RK806_INT_STS_PWRON_RISE), 302*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_PWRON, 0, RK806_INT_STS_PWRON), 303*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_PWRON_LP, 0, RK806_INT_STS_PWRON_LP), 304*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_HOTDIE, 0, RK806_INT_STS_HOTDIE), 305*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_VDC_RISE, 0, RK806_INT_STS_VDC_RISE), 306*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_VDC_FALL, 0, RK806_INT_STS_VDC_FALL), 307*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_VB_LO, 0, RK806_INT_STS_VB_LO), 308*210f418fSSebastian Reichel /* INT_STS1 IRQs */ 309*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_REV0, 1, RK806_INT_STS_REV0), 310*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_REV1, 1, RK806_INT_STS_REV1), 311*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_REV2, 1, RK806_INT_STS_REV2), 312*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_CRC_ERROR, 1, RK806_INT_STS_CRC_ERROR), 313*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_SLP3_GPIO, 1, RK806_INT_STS_SLP3_GPIO), 314*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_SLP2_GPIO, 1, RK806_INT_STS_SLP2_GPIO), 315*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_SLP1_GPIO, 1, RK806_INT_STS_SLP1_GPIO), 316*210f418fSSebastian Reichel REGMAP_IRQ_REG(RK806_IRQ_WDT, 1, RK806_INT_STS_WDT), 317*210f418fSSebastian Reichel }; 318*210f418fSSebastian Reichel 319c20e8c5bSSebastian Reichel static const struct regmap_irq rk808_irqs[] = { 320c20e8c5bSSebastian Reichel /* INT_STS */ 321c20e8c5bSSebastian Reichel [RK808_IRQ_VOUT_LO] = { 322c20e8c5bSSebastian Reichel .mask = RK808_IRQ_VOUT_LO_MSK, 323c20e8c5bSSebastian Reichel .reg_offset = 0, 324c20e8c5bSSebastian Reichel }, 325c20e8c5bSSebastian Reichel [RK808_IRQ_VB_LO] = { 326c20e8c5bSSebastian Reichel .mask = RK808_IRQ_VB_LO_MSK, 327c20e8c5bSSebastian Reichel .reg_offset = 0, 328c20e8c5bSSebastian Reichel }, 329c20e8c5bSSebastian Reichel [RK808_IRQ_PWRON] = { 330c20e8c5bSSebastian Reichel .mask = RK808_IRQ_PWRON_MSK, 331c20e8c5bSSebastian Reichel .reg_offset = 0, 332c20e8c5bSSebastian Reichel }, 333c20e8c5bSSebastian Reichel [RK808_IRQ_PWRON_LP] = { 334c20e8c5bSSebastian Reichel .mask = RK808_IRQ_PWRON_LP_MSK, 335c20e8c5bSSebastian Reichel .reg_offset = 0, 336c20e8c5bSSebastian Reichel }, 337c20e8c5bSSebastian Reichel [RK808_IRQ_HOTDIE] = { 338c20e8c5bSSebastian Reichel .mask = RK808_IRQ_HOTDIE_MSK, 339c20e8c5bSSebastian Reichel .reg_offset = 0, 340c20e8c5bSSebastian Reichel }, 341c20e8c5bSSebastian Reichel [RK808_IRQ_RTC_ALARM] = { 342c20e8c5bSSebastian Reichel .mask = RK808_IRQ_RTC_ALARM_MSK, 343c20e8c5bSSebastian Reichel .reg_offset = 0, 344c20e8c5bSSebastian Reichel }, 345c20e8c5bSSebastian Reichel [RK808_IRQ_RTC_PERIOD] = { 346c20e8c5bSSebastian Reichel .mask = RK808_IRQ_RTC_PERIOD_MSK, 347c20e8c5bSSebastian Reichel .reg_offset = 0, 348c20e8c5bSSebastian Reichel }, 349c20e8c5bSSebastian Reichel 350c20e8c5bSSebastian Reichel /* INT_STS2 */ 351c20e8c5bSSebastian Reichel [RK808_IRQ_PLUG_IN_INT] = { 352c20e8c5bSSebastian Reichel .mask = RK808_IRQ_PLUG_IN_INT_MSK, 353c20e8c5bSSebastian Reichel .reg_offset = 1, 354c20e8c5bSSebastian Reichel }, 355c20e8c5bSSebastian Reichel [RK808_IRQ_PLUG_OUT_INT] = { 356c20e8c5bSSebastian Reichel .mask = RK808_IRQ_PLUG_OUT_INT_MSK, 357c20e8c5bSSebastian Reichel .reg_offset = 1, 358c20e8c5bSSebastian Reichel }, 359c20e8c5bSSebastian Reichel }; 360c20e8c5bSSebastian Reichel 361c20e8c5bSSebastian Reichel static const struct regmap_irq rk818_irqs[] = { 362c20e8c5bSSebastian Reichel /* INT_STS */ 363c20e8c5bSSebastian Reichel [RK818_IRQ_VOUT_LO] = { 364c20e8c5bSSebastian Reichel .mask = RK818_IRQ_VOUT_LO_MSK, 365c20e8c5bSSebastian Reichel .reg_offset = 0, 366c20e8c5bSSebastian Reichel }, 367c20e8c5bSSebastian Reichel [RK818_IRQ_VB_LO] = { 368c20e8c5bSSebastian Reichel .mask = RK818_IRQ_VB_LO_MSK, 369c20e8c5bSSebastian Reichel .reg_offset = 0, 370c20e8c5bSSebastian Reichel }, 371c20e8c5bSSebastian Reichel [RK818_IRQ_PWRON] = { 372c20e8c5bSSebastian Reichel .mask = RK818_IRQ_PWRON_MSK, 373c20e8c5bSSebastian Reichel .reg_offset = 0, 374c20e8c5bSSebastian Reichel }, 375c20e8c5bSSebastian Reichel [RK818_IRQ_PWRON_LP] = { 376c20e8c5bSSebastian Reichel .mask = RK818_IRQ_PWRON_LP_MSK, 377c20e8c5bSSebastian Reichel .reg_offset = 0, 378c20e8c5bSSebastian Reichel }, 379c20e8c5bSSebastian Reichel [RK818_IRQ_HOTDIE] = { 380c20e8c5bSSebastian Reichel .mask = RK818_IRQ_HOTDIE_MSK, 381c20e8c5bSSebastian Reichel .reg_offset = 0, 382c20e8c5bSSebastian Reichel }, 383c20e8c5bSSebastian Reichel [RK818_IRQ_RTC_ALARM] = { 384c20e8c5bSSebastian Reichel .mask = RK818_IRQ_RTC_ALARM_MSK, 385c20e8c5bSSebastian Reichel .reg_offset = 0, 386c20e8c5bSSebastian Reichel }, 387c20e8c5bSSebastian Reichel [RK818_IRQ_RTC_PERIOD] = { 388c20e8c5bSSebastian Reichel .mask = RK818_IRQ_RTC_PERIOD_MSK, 389c20e8c5bSSebastian Reichel .reg_offset = 0, 390c20e8c5bSSebastian Reichel }, 391c20e8c5bSSebastian Reichel [RK818_IRQ_USB_OV] = { 392c20e8c5bSSebastian Reichel .mask = RK818_IRQ_USB_OV_MSK, 393c20e8c5bSSebastian Reichel .reg_offset = 0, 394c20e8c5bSSebastian Reichel }, 395c20e8c5bSSebastian Reichel 396c20e8c5bSSebastian Reichel /* INT_STS2 */ 397c20e8c5bSSebastian Reichel [RK818_IRQ_PLUG_IN] = { 398c20e8c5bSSebastian Reichel .mask = RK818_IRQ_PLUG_IN_MSK, 399c20e8c5bSSebastian Reichel .reg_offset = 1, 400c20e8c5bSSebastian Reichel }, 401c20e8c5bSSebastian Reichel [RK818_IRQ_PLUG_OUT] = { 402c20e8c5bSSebastian Reichel .mask = RK818_IRQ_PLUG_OUT_MSK, 403c20e8c5bSSebastian Reichel .reg_offset = 1, 404c20e8c5bSSebastian Reichel }, 405c20e8c5bSSebastian Reichel [RK818_IRQ_CHG_OK] = { 406c20e8c5bSSebastian Reichel .mask = RK818_IRQ_CHG_OK_MSK, 407c20e8c5bSSebastian Reichel .reg_offset = 1, 408c20e8c5bSSebastian Reichel }, 409c20e8c5bSSebastian Reichel [RK818_IRQ_CHG_TE] = { 410c20e8c5bSSebastian Reichel .mask = RK818_IRQ_CHG_TE_MSK, 411c20e8c5bSSebastian Reichel .reg_offset = 1, 412c20e8c5bSSebastian Reichel }, 413c20e8c5bSSebastian Reichel [RK818_IRQ_CHG_TS1] = { 414c20e8c5bSSebastian Reichel .mask = RK818_IRQ_CHG_TS1_MSK, 415c20e8c5bSSebastian Reichel .reg_offset = 1, 416c20e8c5bSSebastian Reichel }, 417c20e8c5bSSebastian Reichel [RK818_IRQ_TS2] = { 418c20e8c5bSSebastian Reichel .mask = RK818_IRQ_TS2_MSK, 419c20e8c5bSSebastian Reichel .reg_offset = 1, 420c20e8c5bSSebastian Reichel }, 421c20e8c5bSSebastian Reichel [RK818_IRQ_CHG_CVTLIM] = { 422c20e8c5bSSebastian Reichel .mask = RK818_IRQ_CHG_CVTLIM_MSK, 423c20e8c5bSSebastian Reichel .reg_offset = 1, 424c20e8c5bSSebastian Reichel }, 425c20e8c5bSSebastian Reichel [RK818_IRQ_DISCHG_ILIM] = { 426c20e8c5bSSebastian Reichel .mask = RK818_IRQ_DISCHG_ILIM_MSK, 427c20e8c5bSSebastian Reichel .reg_offset = 1, 428c20e8c5bSSebastian Reichel }, 429c20e8c5bSSebastian Reichel }; 430c20e8c5bSSebastian Reichel 431c20e8c5bSSebastian Reichel static const struct regmap_irq rk817_irqs[RK817_IRQ_END] = { 432c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(0, 8), 433c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(1, 8), 434c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(2, 8), 435c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(3, 8), 436c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(4, 8), 437c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(5, 8), 438c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(6, 8), 439c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(7, 8), 440c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(8, 8), 441c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(9, 8), 442c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(10, 8), 443c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(11, 8), 444c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(12, 8), 445c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(13, 8), 446c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(14, 8), 447c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(15, 8), 448c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(16, 8), 449c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(17, 8), 450c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(18, 8), 451c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(19, 8), 452c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(20, 8), 453c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(21, 8), 454c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(22, 8), 455c20e8c5bSSebastian Reichel REGMAP_IRQ_REG_LINE(23, 8) 456c20e8c5bSSebastian Reichel }; 457c20e8c5bSSebastian Reichel 458c20e8c5bSSebastian Reichel static struct regmap_irq_chip rk805_irq_chip = { 459c20e8c5bSSebastian Reichel .name = "rk805", 460c20e8c5bSSebastian Reichel .irqs = rk805_irqs, 461c20e8c5bSSebastian Reichel .num_irqs = ARRAY_SIZE(rk805_irqs), 462c20e8c5bSSebastian Reichel .num_regs = 1, 463c20e8c5bSSebastian Reichel .status_base = RK805_INT_STS_REG, 464c20e8c5bSSebastian Reichel .mask_base = RK805_INT_STS_MSK_REG, 465c20e8c5bSSebastian Reichel .ack_base = RK805_INT_STS_REG, 466c20e8c5bSSebastian Reichel .init_ack_masked = true, 467c20e8c5bSSebastian Reichel }; 468c20e8c5bSSebastian Reichel 469*210f418fSSebastian Reichel static struct regmap_irq_chip rk806_irq_chip = { 470*210f418fSSebastian Reichel .name = "rk806", 471*210f418fSSebastian Reichel .irqs = rk806_irqs, 472*210f418fSSebastian Reichel .num_irqs = ARRAY_SIZE(rk806_irqs), 473*210f418fSSebastian Reichel .num_regs = 2, 474*210f418fSSebastian Reichel .irq_reg_stride = 2, 475*210f418fSSebastian Reichel .mask_base = RK806_INT_MSK0, 476*210f418fSSebastian Reichel .status_base = RK806_INT_STS0, 477*210f418fSSebastian Reichel .ack_base = RK806_INT_STS0, 478*210f418fSSebastian Reichel .init_ack_masked = true, 479*210f418fSSebastian Reichel }; 480*210f418fSSebastian Reichel 481c20e8c5bSSebastian Reichel static const struct regmap_irq_chip rk808_irq_chip = { 482c20e8c5bSSebastian Reichel .name = "rk808", 483c20e8c5bSSebastian Reichel .irqs = rk808_irqs, 484c20e8c5bSSebastian Reichel .num_irqs = ARRAY_SIZE(rk808_irqs), 485c20e8c5bSSebastian Reichel .num_regs = 2, 486c20e8c5bSSebastian Reichel .irq_reg_stride = 2, 487c20e8c5bSSebastian Reichel .status_base = RK808_INT_STS_REG1, 488c20e8c5bSSebastian Reichel .mask_base = RK808_INT_STS_MSK_REG1, 489c20e8c5bSSebastian Reichel .ack_base = RK808_INT_STS_REG1, 490c20e8c5bSSebastian Reichel .init_ack_masked = true, 491c20e8c5bSSebastian Reichel }; 492c20e8c5bSSebastian Reichel 493c20e8c5bSSebastian Reichel static struct regmap_irq_chip rk817_irq_chip = { 494c20e8c5bSSebastian Reichel .name = "rk817", 495c20e8c5bSSebastian Reichel .irqs = rk817_irqs, 496c20e8c5bSSebastian Reichel .num_irqs = ARRAY_SIZE(rk817_irqs), 497c20e8c5bSSebastian Reichel .num_regs = 3, 498c20e8c5bSSebastian Reichel .irq_reg_stride = 2, 499c20e8c5bSSebastian Reichel .status_base = RK817_INT_STS_REG0, 500c20e8c5bSSebastian Reichel .mask_base = RK817_INT_STS_MSK_REG0, 501c20e8c5bSSebastian Reichel .ack_base = RK817_INT_STS_REG0, 502c20e8c5bSSebastian Reichel .init_ack_masked = true, 503c20e8c5bSSebastian Reichel }; 504c20e8c5bSSebastian Reichel 505c20e8c5bSSebastian Reichel static const struct regmap_irq_chip rk818_irq_chip = { 506c20e8c5bSSebastian Reichel .name = "rk818", 507c20e8c5bSSebastian Reichel .irqs = rk818_irqs, 508c20e8c5bSSebastian Reichel .num_irqs = ARRAY_SIZE(rk818_irqs), 509c20e8c5bSSebastian Reichel .num_regs = 2, 510c20e8c5bSSebastian Reichel .irq_reg_stride = 2, 511c20e8c5bSSebastian Reichel .status_base = RK818_INT_STS_REG1, 512c20e8c5bSSebastian Reichel .mask_base = RK818_INT_STS_MSK_REG1, 513c20e8c5bSSebastian Reichel .ack_base = RK818_INT_STS_REG1, 514c20e8c5bSSebastian Reichel .init_ack_masked = true, 515c20e8c5bSSebastian Reichel }; 516c20e8c5bSSebastian Reichel 517c20e8c5bSSebastian Reichel static int rk808_power_off(struct sys_off_data *data) 518c20e8c5bSSebastian Reichel { 519c20e8c5bSSebastian Reichel struct rk808 *rk808 = data->cb_data; 520c20e8c5bSSebastian Reichel int ret; 521c20e8c5bSSebastian Reichel unsigned int reg, bit; 522c20e8c5bSSebastian Reichel 523c20e8c5bSSebastian Reichel switch (rk808->variant) { 524c20e8c5bSSebastian Reichel case RK805_ID: 525c20e8c5bSSebastian Reichel reg = RK805_DEV_CTRL_REG; 526c20e8c5bSSebastian Reichel bit = DEV_OFF; 527c20e8c5bSSebastian Reichel break; 528c20e8c5bSSebastian Reichel case RK808_ID: 529c20e8c5bSSebastian Reichel reg = RK808_DEVCTRL_REG, 530c20e8c5bSSebastian Reichel bit = DEV_OFF_RST; 531c20e8c5bSSebastian Reichel break; 532c20e8c5bSSebastian Reichel case RK809_ID: 533c20e8c5bSSebastian Reichel case RK817_ID: 534c20e8c5bSSebastian Reichel reg = RK817_SYS_CFG(3); 535c20e8c5bSSebastian Reichel bit = DEV_OFF; 536c20e8c5bSSebastian Reichel break; 537c20e8c5bSSebastian Reichel case RK818_ID: 538c20e8c5bSSebastian Reichel reg = RK818_DEVCTRL_REG; 539c20e8c5bSSebastian Reichel bit = DEV_OFF; 540c20e8c5bSSebastian Reichel break; 541c20e8c5bSSebastian Reichel default: 542c20e8c5bSSebastian Reichel return NOTIFY_DONE; 543c20e8c5bSSebastian Reichel } 544c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, reg, bit, bit); 545c20e8c5bSSebastian Reichel if (ret) 546c20e8c5bSSebastian Reichel dev_err(rk808->dev, "Failed to shutdown device!\n"); 547c20e8c5bSSebastian Reichel 548c20e8c5bSSebastian Reichel return NOTIFY_DONE; 549c20e8c5bSSebastian Reichel } 550c20e8c5bSSebastian Reichel 551c20e8c5bSSebastian Reichel static int rk808_restart(struct sys_off_data *data) 552c20e8c5bSSebastian Reichel { 553c20e8c5bSSebastian Reichel struct rk808 *rk808 = data->cb_data; 554c20e8c5bSSebastian Reichel unsigned int reg, bit; 555c20e8c5bSSebastian Reichel int ret; 556c20e8c5bSSebastian Reichel 557c20e8c5bSSebastian Reichel switch (rk808->variant) { 558c20e8c5bSSebastian Reichel case RK809_ID: 559c20e8c5bSSebastian Reichel case RK817_ID: 560c20e8c5bSSebastian Reichel reg = RK817_SYS_CFG(3); 561c20e8c5bSSebastian Reichel bit = DEV_RST; 562c20e8c5bSSebastian Reichel break; 563c20e8c5bSSebastian Reichel 564c20e8c5bSSebastian Reichel default: 565c20e8c5bSSebastian Reichel return NOTIFY_DONE; 566c20e8c5bSSebastian Reichel } 567c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, reg, bit, bit); 568c20e8c5bSSebastian Reichel if (ret) 569c20e8c5bSSebastian Reichel dev_err(rk808->dev, "Failed to restart device!\n"); 570c20e8c5bSSebastian Reichel 571c20e8c5bSSebastian Reichel return NOTIFY_DONE; 572c20e8c5bSSebastian Reichel } 573c20e8c5bSSebastian Reichel 574c20e8c5bSSebastian Reichel void rk8xx_shutdown(struct device *dev) 575c20e8c5bSSebastian Reichel { 576c20e8c5bSSebastian Reichel struct rk808 *rk808 = dev_get_drvdata(dev); 577c20e8c5bSSebastian Reichel int ret; 578c20e8c5bSSebastian Reichel 579c20e8c5bSSebastian Reichel switch (rk808->variant) { 580c20e8c5bSSebastian Reichel case RK805_ID: 581c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, 582c20e8c5bSSebastian Reichel RK805_GPIO_IO_POL_REG, 583c20e8c5bSSebastian Reichel SLP_SD_MSK, 584c20e8c5bSSebastian Reichel SHUTDOWN_FUN); 585c20e8c5bSSebastian Reichel break; 586c20e8c5bSSebastian Reichel case RK809_ID: 587c20e8c5bSSebastian Reichel case RK817_ID: 588c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, 589c20e8c5bSSebastian Reichel RK817_SYS_CFG(3), 590c20e8c5bSSebastian Reichel RK817_SLPPIN_FUNC_MSK, 591c20e8c5bSSebastian Reichel SLPPIN_DN_FUN); 592c20e8c5bSSebastian Reichel break; 593c20e8c5bSSebastian Reichel default: 594c20e8c5bSSebastian Reichel return; 595c20e8c5bSSebastian Reichel } 596c20e8c5bSSebastian Reichel if (ret) 597c20e8c5bSSebastian Reichel dev_warn(dev, 598c20e8c5bSSebastian Reichel "Cannot switch to power down function\n"); 599c20e8c5bSSebastian Reichel } 600c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_shutdown); 601c20e8c5bSSebastian Reichel 602c20e8c5bSSebastian Reichel int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap *regmap) 603c20e8c5bSSebastian Reichel { 604c20e8c5bSSebastian Reichel struct rk808 *rk808; 605c20e8c5bSSebastian Reichel const struct rk808_reg_data *pre_init_reg; 606c20e8c5bSSebastian Reichel const struct mfd_cell *cells; 607*210f418fSSebastian Reichel int dual_support = 0; 608c20e8c5bSSebastian Reichel int nr_pre_init_regs; 609c20e8c5bSSebastian Reichel int nr_cells; 610c20e8c5bSSebastian Reichel int ret; 611c20e8c5bSSebastian Reichel int i; 612c20e8c5bSSebastian Reichel 613c20e8c5bSSebastian Reichel rk808 = devm_kzalloc(dev, sizeof(*rk808), GFP_KERNEL); 614c20e8c5bSSebastian Reichel if (!rk808) 615c20e8c5bSSebastian Reichel return -ENOMEM; 616c20e8c5bSSebastian Reichel rk808->dev = dev; 617c20e8c5bSSebastian Reichel rk808->variant = variant; 618c20e8c5bSSebastian Reichel rk808->regmap = regmap; 619c20e8c5bSSebastian Reichel dev_set_drvdata(dev, rk808); 620c20e8c5bSSebastian Reichel 621c20e8c5bSSebastian Reichel switch (rk808->variant) { 622c20e8c5bSSebastian Reichel case RK805_ID: 623c20e8c5bSSebastian Reichel rk808->regmap_irq_chip = &rk805_irq_chip; 624c20e8c5bSSebastian Reichel pre_init_reg = rk805_pre_init_reg; 625c20e8c5bSSebastian Reichel nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg); 626c20e8c5bSSebastian Reichel cells = rk805s; 627c20e8c5bSSebastian Reichel nr_cells = ARRAY_SIZE(rk805s); 628c20e8c5bSSebastian Reichel break; 629*210f418fSSebastian Reichel case RK806_ID: 630*210f418fSSebastian Reichel rk808->regmap_irq_chip = &rk806_irq_chip; 631*210f418fSSebastian Reichel pre_init_reg = rk806_pre_init_reg; 632*210f418fSSebastian Reichel nr_pre_init_regs = ARRAY_SIZE(rk806_pre_init_reg); 633*210f418fSSebastian Reichel cells = rk806s; 634*210f418fSSebastian Reichel nr_cells = ARRAY_SIZE(rk806s); 635*210f418fSSebastian Reichel dual_support = IRQF_SHARED; 636*210f418fSSebastian Reichel break; 637c20e8c5bSSebastian Reichel case RK808_ID: 638c20e8c5bSSebastian Reichel rk808->regmap_irq_chip = &rk808_irq_chip; 639c20e8c5bSSebastian Reichel pre_init_reg = rk808_pre_init_reg; 640c20e8c5bSSebastian Reichel nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg); 641c20e8c5bSSebastian Reichel cells = rk808s; 642c20e8c5bSSebastian Reichel nr_cells = ARRAY_SIZE(rk808s); 643c20e8c5bSSebastian Reichel break; 644c20e8c5bSSebastian Reichel case RK818_ID: 645c20e8c5bSSebastian Reichel rk808->regmap_irq_chip = &rk818_irq_chip; 646c20e8c5bSSebastian Reichel pre_init_reg = rk818_pre_init_reg; 647c20e8c5bSSebastian Reichel nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg); 648c20e8c5bSSebastian Reichel cells = rk818s; 649c20e8c5bSSebastian Reichel nr_cells = ARRAY_SIZE(rk818s); 650c20e8c5bSSebastian Reichel break; 651c20e8c5bSSebastian Reichel case RK809_ID: 652c20e8c5bSSebastian Reichel case RK817_ID: 653c20e8c5bSSebastian Reichel rk808->regmap_irq_chip = &rk817_irq_chip; 654c20e8c5bSSebastian Reichel pre_init_reg = rk817_pre_init_reg; 655c20e8c5bSSebastian Reichel nr_pre_init_regs = ARRAY_SIZE(rk817_pre_init_reg); 656c20e8c5bSSebastian Reichel cells = rk817s; 657c20e8c5bSSebastian Reichel nr_cells = ARRAY_SIZE(rk817s); 658c20e8c5bSSebastian Reichel break; 659c20e8c5bSSebastian Reichel default: 660c20e8c5bSSebastian Reichel dev_err(dev, "Unsupported RK8XX ID %lu\n", rk808->variant); 661c20e8c5bSSebastian Reichel return -EINVAL; 662c20e8c5bSSebastian Reichel } 663c20e8c5bSSebastian Reichel 664c20e8c5bSSebastian Reichel if (!irq) 665c20e8c5bSSebastian Reichel return dev_err_probe(dev, -EINVAL, "No interrupt support, no core IRQ\n"); 666c20e8c5bSSebastian Reichel 667c20e8c5bSSebastian Reichel ret = devm_regmap_add_irq_chip(dev, rk808->regmap, irq, 668*210f418fSSebastian Reichel IRQF_ONESHOT | dual_support, -1, 669c20e8c5bSSebastian Reichel rk808->regmap_irq_chip, &rk808->irq_data); 670c20e8c5bSSebastian Reichel if (ret) 671c20e8c5bSSebastian Reichel return dev_err_probe(dev, ret, "Failed to add irq_chip\n"); 672c20e8c5bSSebastian Reichel 673c20e8c5bSSebastian Reichel for (i = 0; i < nr_pre_init_regs; i++) { 674c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, 675c20e8c5bSSebastian Reichel pre_init_reg[i].addr, 676c20e8c5bSSebastian Reichel pre_init_reg[i].mask, 677c20e8c5bSSebastian Reichel pre_init_reg[i].value); 678c20e8c5bSSebastian Reichel if (ret) 679c20e8c5bSSebastian Reichel return dev_err_probe(dev, ret, "0x%x write err\n", 680c20e8c5bSSebastian Reichel pre_init_reg[i].addr); 681c20e8c5bSSebastian Reichel } 682c20e8c5bSSebastian Reichel 683*210f418fSSebastian Reichel ret = devm_mfd_add_devices(dev, 0, cells, nr_cells, NULL, 0, 684c20e8c5bSSebastian Reichel regmap_irq_get_domain(rk808->irq_data)); 685c20e8c5bSSebastian Reichel if (ret) 686c20e8c5bSSebastian Reichel return dev_err_probe(dev, ret, "failed to add MFD devices\n"); 687c20e8c5bSSebastian Reichel 688c20e8c5bSSebastian Reichel if (device_property_read_bool(dev, "rockchip,system-power-controller")) { 689c20e8c5bSSebastian Reichel ret = devm_register_sys_off_handler(dev, 690c20e8c5bSSebastian Reichel SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH, 691c20e8c5bSSebastian Reichel &rk808_power_off, rk808); 692c20e8c5bSSebastian Reichel if (ret) 693c20e8c5bSSebastian Reichel return dev_err_probe(dev, ret, 694c20e8c5bSSebastian Reichel "failed to register poweroff handler\n"); 695c20e8c5bSSebastian Reichel 696c20e8c5bSSebastian Reichel switch (rk808->variant) { 697c20e8c5bSSebastian Reichel case RK809_ID: 698c20e8c5bSSebastian Reichel case RK817_ID: 699c20e8c5bSSebastian Reichel ret = devm_register_sys_off_handler(dev, 700c20e8c5bSSebastian Reichel SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH, 701c20e8c5bSSebastian Reichel &rk808_restart, rk808); 702c20e8c5bSSebastian Reichel if (ret) 703c20e8c5bSSebastian Reichel dev_warn(dev, "failed to register rst handler, %d\n", ret); 704c20e8c5bSSebastian Reichel break; 705c20e8c5bSSebastian Reichel default: 706c20e8c5bSSebastian Reichel dev_dbg(dev, "pmic controlled board reset not supported\n"); 707c20e8c5bSSebastian Reichel break; 708c20e8c5bSSebastian Reichel } 709c20e8c5bSSebastian Reichel } 710c20e8c5bSSebastian Reichel 711c20e8c5bSSebastian Reichel return 0; 712c20e8c5bSSebastian Reichel } 713c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_probe); 714c20e8c5bSSebastian Reichel 715c20e8c5bSSebastian Reichel int rk8xx_suspend(struct device *dev) 716c20e8c5bSSebastian Reichel { 717c20e8c5bSSebastian Reichel struct rk808 *rk808 = dev_get_drvdata(dev); 718c20e8c5bSSebastian Reichel int ret = 0; 719c20e8c5bSSebastian Reichel 720c20e8c5bSSebastian Reichel switch (rk808->variant) { 721c20e8c5bSSebastian Reichel case RK805_ID: 722c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, 723c20e8c5bSSebastian Reichel RK805_GPIO_IO_POL_REG, 724c20e8c5bSSebastian Reichel SLP_SD_MSK, 725c20e8c5bSSebastian Reichel SLEEP_FUN); 726c20e8c5bSSebastian Reichel break; 727c20e8c5bSSebastian Reichel case RK809_ID: 728c20e8c5bSSebastian Reichel case RK817_ID: 729c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, 730c20e8c5bSSebastian Reichel RK817_SYS_CFG(3), 731c20e8c5bSSebastian Reichel RK817_SLPPIN_FUNC_MSK, 732c20e8c5bSSebastian Reichel SLPPIN_SLP_FUN); 733c20e8c5bSSebastian Reichel break; 734c20e8c5bSSebastian Reichel default: 735c20e8c5bSSebastian Reichel break; 736c20e8c5bSSebastian Reichel } 737c20e8c5bSSebastian Reichel 738c20e8c5bSSebastian Reichel return ret; 739c20e8c5bSSebastian Reichel } 740c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_suspend); 741c20e8c5bSSebastian Reichel 742c20e8c5bSSebastian Reichel int rk8xx_resume(struct device *dev) 743c20e8c5bSSebastian Reichel { 744c20e8c5bSSebastian Reichel struct rk808 *rk808 = dev_get_drvdata(dev); 745c20e8c5bSSebastian Reichel int ret = 0; 746c20e8c5bSSebastian Reichel 747c20e8c5bSSebastian Reichel switch (rk808->variant) { 748c20e8c5bSSebastian Reichel case RK809_ID: 749c20e8c5bSSebastian Reichel case RK817_ID: 750c20e8c5bSSebastian Reichel ret = regmap_update_bits(rk808->regmap, 751c20e8c5bSSebastian Reichel RK817_SYS_CFG(3), 752c20e8c5bSSebastian Reichel RK817_SLPPIN_FUNC_MSK, 753c20e8c5bSSebastian Reichel SLPPIN_NULL_FUN); 754c20e8c5bSSebastian Reichel break; 755c20e8c5bSSebastian Reichel default: 756c20e8c5bSSebastian Reichel break; 757c20e8c5bSSebastian Reichel } 758c20e8c5bSSebastian Reichel 759c20e8c5bSSebastian Reichel return ret; 760c20e8c5bSSebastian Reichel } 761c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_resume); 762c20e8c5bSSebastian Reichel 763c20e8c5bSSebastian Reichel MODULE_LICENSE("GPL"); 764c20e8c5bSSebastian Reichel MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); 765c20e8c5bSSebastian Reichel MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>"); 766c20e8c5bSSebastian Reichel MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>"); 767c20e8c5bSSebastian Reichel MODULE_DESCRIPTION("RK8xx PMIC core"); 768