12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 227c6750eSGraeme Gregory /* 3a8799defSPaul Gortmaker * tps65910.c -- TI TPS6591x chip family multi-function driver 427c6750eSGraeme Gregory * 527c6750eSGraeme Gregory * Copyright 2010 Texas Instruments Inc. 627c6750eSGraeme Gregory * 727c6750eSGraeme Gregory * Author: Graeme Gregory <gg@slimlogic.co.uk> 827c6750eSGraeme Gregory * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk> 927c6750eSGraeme Gregory */ 1027c6750eSGraeme Gregory 1127c6750eSGraeme Gregory #include <linux/init.h> 12dc9913a0SLaxman Dewangan #include <linux/err.h> 1327c6750eSGraeme Gregory #include <linux/slab.h> 1427c6750eSGraeme Gregory #include <linux/i2c.h> 154aab3fadSLaxman Dewangan #include <linux/interrupt.h> 164aab3fadSLaxman Dewangan #include <linux/irq.h> 174aab3fadSLaxman Dewangan #include <linux/irqdomain.h> 1827c6750eSGraeme Gregory #include <linux/mfd/core.h> 19dc9913a0SLaxman Dewangan #include <linux/regmap.h> 2027c6750eSGraeme Gregory #include <linux/mfd/tps65910.h> 211fead3f3SSachin Kamat #include <linux/of.h> 22cd4209ceSRhyland Klein #include <linux/of_device.h> 2327c6750eSGraeme Gregory 240aefed0eSRikard Falkeborn static const struct resource rtc_resources[] = { 255863eabbSVenu Byravarasu { 265863eabbSVenu Byravarasu .start = TPS65910_IRQ_RTC_ALARM, 275863eabbSVenu Byravarasu .end = TPS65910_IRQ_RTC_ALARM, 285863eabbSVenu Byravarasu .flags = IORESOURCE_IRQ, 295863eabbSVenu Byravarasu } 305863eabbSVenu Byravarasu }; 315863eabbSVenu Byravarasu 3230fe2b5bSGeert Uytterhoeven static const struct mfd_cell tps65910s[] = { 3327c6750eSGraeme Gregory { 3432df986eSLaxman Dewangan .name = "tps65910-gpio", 3532df986eSLaxman Dewangan }, 3632df986eSLaxman Dewangan { 3727c6750eSGraeme Gregory .name = "tps65910-pmic", 3827c6750eSGraeme Gregory }, 3927c6750eSGraeme Gregory { 4027c6750eSGraeme Gregory .name = "tps65910-rtc", 415863eabbSVenu Byravarasu .num_resources = ARRAY_SIZE(rtc_resources), 425863eabbSVenu Byravarasu .resources = &rtc_resources[0], 4327c6750eSGraeme Gregory }, 4427c6750eSGraeme Gregory { 4527c6750eSGraeme Gregory .name = "tps65910-power", 4627c6750eSGraeme Gregory }, 4727c6750eSGraeme Gregory }; 4827c6750eSGraeme Gregory 4927c6750eSGraeme Gregory 504aab3fadSLaxman Dewangan static const struct regmap_irq tps65911_irqs[] = { 514aab3fadSLaxman Dewangan /* INT_STS */ 524aab3fadSLaxman Dewangan [TPS65911_IRQ_PWRHOLD_F] = { 534aab3fadSLaxman Dewangan .mask = INT_MSK_PWRHOLD_F_IT_MSK_MASK, 544aab3fadSLaxman Dewangan .reg_offset = 0, 554aab3fadSLaxman Dewangan }, 564aab3fadSLaxman Dewangan [TPS65911_IRQ_VBAT_VMHI] = { 574aab3fadSLaxman Dewangan .mask = INT_MSK_VMBHI_IT_MSK_MASK, 584aab3fadSLaxman Dewangan .reg_offset = 0, 594aab3fadSLaxman Dewangan }, 604aab3fadSLaxman Dewangan [TPS65911_IRQ_PWRON] = { 614aab3fadSLaxman Dewangan .mask = INT_MSK_PWRON_IT_MSK_MASK, 624aab3fadSLaxman Dewangan .reg_offset = 0, 634aab3fadSLaxman Dewangan }, 644aab3fadSLaxman Dewangan [TPS65911_IRQ_PWRON_LP] = { 654aab3fadSLaxman Dewangan .mask = INT_MSK_PWRON_LP_IT_MSK_MASK, 664aab3fadSLaxman Dewangan .reg_offset = 0, 674aab3fadSLaxman Dewangan }, 684aab3fadSLaxman Dewangan [TPS65911_IRQ_PWRHOLD_R] = { 694aab3fadSLaxman Dewangan .mask = INT_MSK_PWRHOLD_R_IT_MSK_MASK, 704aab3fadSLaxman Dewangan .reg_offset = 0, 714aab3fadSLaxman Dewangan }, 724aab3fadSLaxman Dewangan [TPS65911_IRQ_HOTDIE] = { 734aab3fadSLaxman Dewangan .mask = INT_MSK_HOTDIE_IT_MSK_MASK, 744aab3fadSLaxman Dewangan .reg_offset = 0, 754aab3fadSLaxman Dewangan }, 764aab3fadSLaxman Dewangan [TPS65911_IRQ_RTC_ALARM] = { 774aab3fadSLaxman Dewangan .mask = INT_MSK_RTC_ALARM_IT_MSK_MASK, 784aab3fadSLaxman Dewangan .reg_offset = 0, 794aab3fadSLaxman Dewangan }, 804aab3fadSLaxman Dewangan [TPS65911_IRQ_RTC_PERIOD] = { 814aab3fadSLaxman Dewangan .mask = INT_MSK_RTC_PERIOD_IT_MSK_MASK, 824aab3fadSLaxman Dewangan .reg_offset = 0, 834aab3fadSLaxman Dewangan }, 844aab3fadSLaxman Dewangan 854aab3fadSLaxman Dewangan /* INT_STS2 */ 864aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO0_R] = { 874aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO0_R_IT_MSK_MASK, 884aab3fadSLaxman Dewangan .reg_offset = 1, 894aab3fadSLaxman Dewangan }, 904aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO0_F] = { 914aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO0_F_IT_MSK_MASK, 924aab3fadSLaxman Dewangan .reg_offset = 1, 934aab3fadSLaxman Dewangan }, 944aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO1_R] = { 954aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO1_R_IT_MSK_MASK, 964aab3fadSLaxman Dewangan .reg_offset = 1, 974aab3fadSLaxman Dewangan }, 984aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO1_F] = { 994aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO1_F_IT_MSK_MASK, 1004aab3fadSLaxman Dewangan .reg_offset = 1, 1014aab3fadSLaxman Dewangan }, 1024aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO2_R] = { 1034aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO2_R_IT_MSK_MASK, 1044aab3fadSLaxman Dewangan .reg_offset = 1, 1054aab3fadSLaxman Dewangan }, 1064aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO2_F] = { 1074aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO2_F_IT_MSK_MASK, 1084aab3fadSLaxman Dewangan .reg_offset = 1, 1094aab3fadSLaxman Dewangan }, 1104aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO3_R] = { 1114aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO3_R_IT_MSK_MASK, 1124aab3fadSLaxman Dewangan .reg_offset = 1, 1134aab3fadSLaxman Dewangan }, 1144aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO3_F] = { 1154aab3fadSLaxman Dewangan .mask = INT_MSK2_GPIO3_F_IT_MSK_MASK, 1164aab3fadSLaxman Dewangan .reg_offset = 1, 1174aab3fadSLaxman Dewangan }, 1184aab3fadSLaxman Dewangan 1194aab3fadSLaxman Dewangan /* INT_STS2 */ 1204aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO4_R] = { 1214aab3fadSLaxman Dewangan .mask = INT_MSK3_GPIO4_R_IT_MSK_MASK, 1224aab3fadSLaxman Dewangan .reg_offset = 2, 1234aab3fadSLaxman Dewangan }, 1244aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO4_F] = { 1254aab3fadSLaxman Dewangan .mask = INT_MSK3_GPIO4_F_IT_MSK_MASK, 1264aab3fadSLaxman Dewangan .reg_offset = 2, 1274aab3fadSLaxman Dewangan }, 1284aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO5_R] = { 1294aab3fadSLaxman Dewangan .mask = INT_MSK3_GPIO5_R_IT_MSK_MASK, 1304aab3fadSLaxman Dewangan .reg_offset = 2, 1314aab3fadSLaxman Dewangan }, 1324aab3fadSLaxman Dewangan [TPS65911_IRQ_GPIO5_F] = { 1334aab3fadSLaxman Dewangan .mask = INT_MSK3_GPIO5_F_IT_MSK_MASK, 1344aab3fadSLaxman Dewangan .reg_offset = 2, 1354aab3fadSLaxman Dewangan }, 1364aab3fadSLaxman Dewangan [TPS65911_IRQ_WTCHDG] = { 1374aab3fadSLaxman Dewangan .mask = INT_MSK3_WTCHDG_IT_MSK_MASK, 1384aab3fadSLaxman Dewangan .reg_offset = 2, 1394aab3fadSLaxman Dewangan }, 1404aab3fadSLaxman Dewangan [TPS65911_IRQ_VMBCH2_H] = { 1414aab3fadSLaxman Dewangan .mask = INT_MSK3_VMBCH2_H_IT_MSK_MASK, 1424aab3fadSLaxman Dewangan .reg_offset = 2, 1434aab3fadSLaxman Dewangan }, 1444aab3fadSLaxman Dewangan [TPS65911_IRQ_VMBCH2_L] = { 1454aab3fadSLaxman Dewangan .mask = INT_MSK3_VMBCH2_L_IT_MSK_MASK, 1464aab3fadSLaxman Dewangan .reg_offset = 2, 1474aab3fadSLaxman Dewangan }, 1484aab3fadSLaxman Dewangan [TPS65911_IRQ_PWRDN] = { 1494aab3fadSLaxman Dewangan .mask = INT_MSK3_PWRDN_IT_MSK_MASK, 1504aab3fadSLaxman Dewangan .reg_offset = 2, 1514aab3fadSLaxman Dewangan }, 1524aab3fadSLaxman Dewangan }; 1534aab3fadSLaxman Dewangan 1544aab3fadSLaxman Dewangan static const struct regmap_irq tps65910_irqs[] = { 1554aab3fadSLaxman Dewangan /* INT_STS */ 1564aab3fadSLaxman Dewangan [TPS65910_IRQ_VBAT_VMBDCH] = { 1574aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_VMBDCH_IT_MSK_MASK, 1584aab3fadSLaxman Dewangan .reg_offset = 0, 1594aab3fadSLaxman Dewangan }, 1604aab3fadSLaxman Dewangan [TPS65910_IRQ_VBAT_VMHI] = { 1614aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_VMBHI_IT_MSK_MASK, 1624aab3fadSLaxman Dewangan .reg_offset = 0, 1634aab3fadSLaxman Dewangan }, 1644aab3fadSLaxman Dewangan [TPS65910_IRQ_PWRON] = { 1654aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_PWRON_IT_MSK_MASK, 1664aab3fadSLaxman Dewangan .reg_offset = 0, 1674aab3fadSLaxman Dewangan }, 1684aab3fadSLaxman Dewangan [TPS65910_IRQ_PWRON_LP] = { 1694aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_PWRON_LP_IT_MSK_MASK, 1704aab3fadSLaxman Dewangan .reg_offset = 0, 1714aab3fadSLaxman Dewangan }, 1724aab3fadSLaxman Dewangan [TPS65910_IRQ_PWRHOLD] = { 1734aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_PWRHOLD_IT_MSK_MASK, 1744aab3fadSLaxman Dewangan .reg_offset = 0, 1754aab3fadSLaxman Dewangan }, 1764aab3fadSLaxman Dewangan [TPS65910_IRQ_HOTDIE] = { 1774aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_HOTDIE_IT_MSK_MASK, 1784aab3fadSLaxman Dewangan .reg_offset = 0, 1794aab3fadSLaxman Dewangan }, 1804aab3fadSLaxman Dewangan [TPS65910_IRQ_RTC_ALARM] = { 1814aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_RTC_ALARM_IT_MSK_MASK, 1824aab3fadSLaxman Dewangan .reg_offset = 0, 1834aab3fadSLaxman Dewangan }, 1844aab3fadSLaxman Dewangan [TPS65910_IRQ_RTC_PERIOD] = { 1854aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK_RTC_PERIOD_IT_MSK_MASK, 1864aab3fadSLaxman Dewangan .reg_offset = 0, 1874aab3fadSLaxman Dewangan }, 1884aab3fadSLaxman Dewangan 1894aab3fadSLaxman Dewangan /* INT_STS2 */ 1904aab3fadSLaxman Dewangan [TPS65910_IRQ_GPIO_R] = { 1914aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK2_GPIO0_F_IT_MSK_MASK, 1924aab3fadSLaxman Dewangan .reg_offset = 1, 1934aab3fadSLaxman Dewangan }, 1944aab3fadSLaxman Dewangan [TPS65910_IRQ_GPIO_F] = { 1954aab3fadSLaxman Dewangan .mask = TPS65910_INT_MSK2_GPIO0_R_IT_MSK_MASK, 1964aab3fadSLaxman Dewangan .reg_offset = 1, 1974aab3fadSLaxman Dewangan }, 1984aab3fadSLaxman Dewangan }; 1994aab3fadSLaxman Dewangan 2004aab3fadSLaxman Dewangan static struct regmap_irq_chip tps65911_irq_chip = { 2014aab3fadSLaxman Dewangan .name = "tps65910", 2024aab3fadSLaxman Dewangan .irqs = tps65911_irqs, 2034aab3fadSLaxman Dewangan .num_irqs = ARRAY_SIZE(tps65911_irqs), 2044aab3fadSLaxman Dewangan .num_regs = 3, 2054aab3fadSLaxman Dewangan .irq_reg_stride = 2, 2064aab3fadSLaxman Dewangan .status_base = TPS65910_INT_STS, 2074aab3fadSLaxman Dewangan .mask_base = TPS65910_INT_MSK, 2080582c0faSKim, Milo .ack_base = TPS65910_INT_STS, 2094aab3fadSLaxman Dewangan }; 2104aab3fadSLaxman Dewangan 2114aab3fadSLaxman Dewangan static struct regmap_irq_chip tps65910_irq_chip = { 2124aab3fadSLaxman Dewangan .name = "tps65910", 2134aab3fadSLaxman Dewangan .irqs = tps65910_irqs, 2144aab3fadSLaxman Dewangan .num_irqs = ARRAY_SIZE(tps65910_irqs), 2154aab3fadSLaxman Dewangan .num_regs = 2, 2164aab3fadSLaxman Dewangan .irq_reg_stride = 2, 2174aab3fadSLaxman Dewangan .status_base = TPS65910_INT_STS, 2184aab3fadSLaxman Dewangan .mask_base = TPS65910_INT_MSK, 2190582c0faSKim, Milo .ack_base = TPS65910_INT_STS, 2204aab3fadSLaxman Dewangan }; 2214aab3fadSLaxman Dewangan 2224aab3fadSLaxman Dewangan static int tps65910_irq_init(struct tps65910 *tps65910, int irq, 2234aab3fadSLaxman Dewangan struct tps65910_platform_data *pdata) 2244aab3fadSLaxman Dewangan { 225dae3be36SMarkus Elfring int ret; 2264aab3fadSLaxman Dewangan static struct regmap_irq_chip *tps6591x_irqs_chip; 2274aab3fadSLaxman Dewangan 2284aab3fadSLaxman Dewangan if (!irq) { 2294aab3fadSLaxman Dewangan dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n"); 2304aab3fadSLaxman Dewangan return -EINVAL; 2314aab3fadSLaxman Dewangan } 2324aab3fadSLaxman Dewangan 2334aab3fadSLaxman Dewangan if (!pdata) { 2344aab3fadSLaxman Dewangan dev_warn(tps65910->dev, "No interrupt support, no pdata\n"); 2354aab3fadSLaxman Dewangan return -EINVAL; 2364aab3fadSLaxman Dewangan } 2374aab3fadSLaxman Dewangan 2384aab3fadSLaxman Dewangan switch (tps65910_chip_id(tps65910)) { 2394aab3fadSLaxman Dewangan case TPS65910: 2404aab3fadSLaxman Dewangan tps6591x_irqs_chip = &tps65910_irq_chip; 2414aab3fadSLaxman Dewangan break; 2424aab3fadSLaxman Dewangan case TPS65911: 2434aab3fadSLaxman Dewangan tps6591x_irqs_chip = &tps65911_irq_chip; 2444aab3fadSLaxman Dewangan break; 2454aab3fadSLaxman Dewangan } 2464aab3fadSLaxman Dewangan 2474aab3fadSLaxman Dewangan tps65910->chip_irq = irq; 2486167c5bcSLaxman Dewangan ret = devm_regmap_add_irq_chip(tps65910->dev, tps65910->regmap, 2496167c5bcSLaxman Dewangan tps65910->chip_irq, 2504aab3fadSLaxman Dewangan IRQF_ONESHOT, pdata->irq_base, 2514aab3fadSLaxman Dewangan tps6591x_irqs_chip, &tps65910->irq_data); 252483e2dfdSKrzysztof Kozlowski if (ret < 0) { 2534aab3fadSLaxman Dewangan dev_warn(tps65910->dev, "Failed to add irq_chip %d\n", ret); 254483e2dfdSKrzysztof Kozlowski tps65910->chip_irq = 0; 255483e2dfdSKrzysztof Kozlowski } 2564aab3fadSLaxman Dewangan return ret; 2574aab3fadSLaxman Dewangan } 2584aab3fadSLaxman Dewangan 259dc9913a0SLaxman Dewangan static bool is_volatile_reg(struct device *dev, unsigned int reg) 260dc9913a0SLaxman Dewangan { 261dc9913a0SLaxman Dewangan struct tps65910 *tps65910 = dev_get_drvdata(dev); 262dc9913a0SLaxman Dewangan 263dc9913a0SLaxman Dewangan /* 264dc9913a0SLaxman Dewangan * Caching all regulator registers. 265dc9913a0SLaxman Dewangan * All regualator register address range is same for 266dc9913a0SLaxman Dewangan * TPS65910 and TPS65911 267dc9913a0SLaxman Dewangan */ 268dc9913a0SLaxman Dewangan if ((reg >= TPS65910_VIO) && (reg <= TPS65910_VDAC)) { 269dc9913a0SLaxman Dewangan /* Check for non-existing register */ 270dc9913a0SLaxman Dewangan if (tps65910_chip_id(tps65910) == TPS65910) 271dc9913a0SLaxman Dewangan if ((reg == TPS65911_VDDCTRL_OP) || 272dc9913a0SLaxman Dewangan (reg == TPS65911_VDDCTRL_SR)) 273dc9913a0SLaxman Dewangan return true; 274dc9913a0SLaxman Dewangan return false; 275dc9913a0SLaxman Dewangan } 276dc9913a0SLaxman Dewangan return true; 277dc9913a0SLaxman Dewangan } 278dc9913a0SLaxman Dewangan 27939ecb037SLaxman Dewangan static const struct regmap_config tps65910_regmap_config = { 280dc9913a0SLaxman Dewangan .reg_bits = 8, 281dc9913a0SLaxman Dewangan .val_bits = 8, 282dc9913a0SLaxman Dewangan .volatile_reg = is_volatile_reg, 2833bf6bf9bSLaxman Dewangan .max_register = TPS65910_MAX_REGISTER - 1, 284dc9913a0SLaxman Dewangan .cache_type = REGCACHE_RBTREE, 285dc9913a0SLaxman Dewangan }; 286dc9913a0SLaxman Dewangan 287f791be49SBill Pemberton static int tps65910_ck32k_init(struct tps65910 *tps65910, 288712db99dSJohan Hovold struct tps65910_board *pmic_pdata) 289712db99dSJohan Hovold { 290712db99dSJohan Hovold int ret; 291712db99dSJohan Hovold 292d02e83cbSJohan Hovold if (!pmic_pdata->en_ck32k_xtal) 293d02e83cbSJohan Hovold return 0; 294d02e83cbSJohan Hovold 29528faad77SMichał Mirosław ret = regmap_clear_bits(tps65910->regmap, TPS65910_DEVCTRL, 296712db99dSJohan Hovold DEVCTRL_CK32K_CTRL_MASK); 297712db99dSJohan Hovold if (ret < 0) { 298d02e83cbSJohan Hovold dev_err(tps65910->dev, "clear ck32k_ctrl failed: %d\n", ret); 299712db99dSJohan Hovold return ret; 300712db99dSJohan Hovold } 301712db99dSJohan Hovold 302712db99dSJohan Hovold return 0; 303712db99dSJohan Hovold } 304712db99dSJohan Hovold 305f791be49SBill Pemberton static int tps65910_sleepinit(struct tps65910 *tps65910, 306201cf052SLaxman Dewangan struct tps65910_board *pmic_pdata) 307201cf052SLaxman Dewangan { 308da257efaSMarkus Elfring struct device *dev; 309dae3be36SMarkus Elfring int ret; 310201cf052SLaxman Dewangan 311201cf052SLaxman Dewangan if (!pmic_pdata->en_dev_slp) 312201cf052SLaxman Dewangan return 0; 313201cf052SLaxman Dewangan 31471bc4f1dSMarkus Elfring dev = tps65910->dev; 31571bc4f1dSMarkus Elfring 316201cf052SLaxman Dewangan /* enabling SLEEP device state */ 31728faad77SMichał Mirosław ret = regmap_set_bits(tps65910->regmap, TPS65910_DEVCTRL, 318201cf052SLaxman Dewangan DEVCTRL_DEV_SLP_MASK); 319201cf052SLaxman Dewangan if (ret < 0) { 320201cf052SLaxman Dewangan dev_err(dev, "set dev_slp failed: %d\n", ret); 321201cf052SLaxman Dewangan goto err_sleep_init; 322201cf052SLaxman Dewangan } 323201cf052SLaxman Dewangan 324a9bc67deSMichał Mirosław if (pmic_pdata->slp_keepon.therm_keepon) { 32528faad77SMichał Mirosław ret = regmap_set_bits(tps65910->regmap, 3263f7e8275SRhyland Klein TPS65910_SLEEP_KEEP_RES_ON, 327201cf052SLaxman Dewangan SLEEP_KEEP_RES_ON_THERM_KEEPON_MASK); 328201cf052SLaxman Dewangan if (ret < 0) { 329201cf052SLaxman Dewangan dev_err(dev, "set therm_keepon failed: %d\n", ret); 330201cf052SLaxman Dewangan goto disable_dev_slp; 331201cf052SLaxman Dewangan } 332201cf052SLaxman Dewangan } 333201cf052SLaxman Dewangan 334a9bc67deSMichał Mirosław if (pmic_pdata->slp_keepon.clkout32k_keepon) { 33528faad77SMichał Mirosław ret = regmap_set_bits(tps65910->regmap, 3363f7e8275SRhyland Klein TPS65910_SLEEP_KEEP_RES_ON, 337201cf052SLaxman Dewangan SLEEP_KEEP_RES_ON_CLKOUT32K_KEEPON_MASK); 338201cf052SLaxman Dewangan if (ret < 0) { 339201cf052SLaxman Dewangan dev_err(dev, "set clkout32k_keepon failed: %d\n", ret); 340201cf052SLaxman Dewangan goto disable_dev_slp; 341201cf052SLaxman Dewangan } 342201cf052SLaxman Dewangan } 343201cf052SLaxman Dewangan 344a9bc67deSMichał Mirosław if (pmic_pdata->slp_keepon.i2chs_keepon) { 34528faad77SMichał Mirosław ret = regmap_set_bits(tps65910->regmap, 3463f7e8275SRhyland Klein TPS65910_SLEEP_KEEP_RES_ON, 347201cf052SLaxman Dewangan SLEEP_KEEP_RES_ON_I2CHS_KEEPON_MASK); 348201cf052SLaxman Dewangan if (ret < 0) { 349201cf052SLaxman Dewangan dev_err(dev, "set i2chs_keepon failed: %d\n", ret); 350201cf052SLaxman Dewangan goto disable_dev_slp; 351201cf052SLaxman Dewangan } 352201cf052SLaxman Dewangan } 353201cf052SLaxman Dewangan 354201cf052SLaxman Dewangan return 0; 355201cf052SLaxman Dewangan 356201cf052SLaxman Dewangan disable_dev_slp: 35728faad77SMichał Mirosław regmap_clear_bits(tps65910->regmap, TPS65910_DEVCTRL, 3583f7e8275SRhyland Klein DEVCTRL_DEV_SLP_MASK); 359201cf052SLaxman Dewangan 360201cf052SLaxman Dewangan err_sleep_init: 361201cf052SLaxman Dewangan return ret; 362201cf052SLaxman Dewangan } 363201cf052SLaxman Dewangan 364cd4209ceSRhyland Klein #ifdef CONFIG_OF 365c0dfbfe2SJingoo Han static const struct of_device_id tps65910_of_match[] = { 366cd4209ceSRhyland Klein { .compatible = "ti,tps65910", .data = (void *)TPS65910}, 367cd4209ceSRhyland Klein { .compatible = "ti,tps65911", .data = (void *)TPS65911}, 368cd4209ceSRhyland Klein { }, 369cd4209ceSRhyland Klein }; 370cd4209ceSRhyland Klein 371cd4209ceSRhyland Klein static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client, 37201a0f4aaSLee Jones unsigned long *chip_id) 373cd4209ceSRhyland Klein { 374cd4209ceSRhyland Klein struct device_node *np = client->dev.of_node; 375cd4209ceSRhyland Klein struct tps65910_board *board_info; 376cd4209ceSRhyland Klein unsigned int prop; 377cd4209ceSRhyland Klein const struct of_device_id *match; 378dae3be36SMarkus Elfring int ret; 379cd4209ceSRhyland Klein 380cd4209ceSRhyland Klein match = of_match_device(tps65910_of_match, &client->dev); 381cd4209ceSRhyland Klein if (!match) { 382cd4209ceSRhyland Klein dev_err(&client->dev, "Failed to find matching dt id\n"); 383cd4209ceSRhyland Klein return NULL; 384cd4209ceSRhyland Klein } 385cd4209ceSRhyland Klein 38601a0f4aaSLee Jones *chip_id = (unsigned long)match->data; 387cd4209ceSRhyland Klein 388cd4209ceSRhyland Klein board_info = devm_kzalloc(&client->dev, sizeof(*board_info), 389cd4209ceSRhyland Klein GFP_KERNEL); 39093e879efSMarkus Elfring if (!board_info) 391cd4209ceSRhyland Klein return NULL; 392cd4209ceSRhyland Klein 393cd4209ceSRhyland Klein ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop); 394cd4209ceSRhyland Klein if (!ret) 395cd4209ceSRhyland Klein board_info->vmbch_threshold = prop; 396cd4209ceSRhyland Klein 397cd4209ceSRhyland Klein ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop); 398cd4209ceSRhyland Klein if (!ret) 399cd4209ceSRhyland Klein board_info->vmbch2_threshold = prop; 400cd4209ceSRhyland Klein 401bcc1dd4cSJohan Hovold prop = of_property_read_bool(np, "ti,en-ck32k-xtal"); 402bcc1dd4cSJohan Hovold board_info->en_ck32k_xtal = prop; 403bcc1dd4cSJohan Hovold 404a9bc67deSMichał Mirosław prop = of_property_read_bool(np, "ti,sleep-enable"); 405a9bc67deSMichał Mirosław board_info->en_dev_slp = prop; 406a9bc67deSMichał Mirosław 407a9bc67deSMichał Mirosław prop = of_property_read_bool(np, "ti,sleep-keep-therm"); 408a9bc67deSMichał Mirosław board_info->slp_keepon.therm_keepon = prop; 409a9bc67deSMichał Mirosław 410a9bc67deSMichał Mirosław prop = of_property_read_bool(np, "ti,sleep-keep-ck32k"); 411a9bc67deSMichał Mirosław board_info->slp_keepon.clkout32k_keepon = prop; 412a9bc67deSMichał Mirosław 413a9bc67deSMichał Mirosław prop = of_property_read_bool(np, "ti,sleep-keep-hsclk"); 414a9bc67deSMichał Mirosław board_info->slp_keepon.i2chs_keepon = prop; 415a9bc67deSMichał Mirosław 416cd4209ceSRhyland Klein board_info->irq = client->irq; 417cd4209ceSRhyland Klein board_info->irq_base = -1; 418b079fa72SBill Huang board_info->pm_off = of_property_read_bool(np, 419b079fa72SBill Huang "ti,system-power-controller"); 420cd4209ceSRhyland Klein 421cd4209ceSRhyland Klein return board_info; 422cd4209ceSRhyland Klein } 423cd4209ceSRhyland Klein #else 4247f65f74cSSamuel Ortiz static inline 4257f65f74cSSamuel Ortiz struct tps65910_board *tps65910_parse_dt(struct i2c_client *client, 42601a0f4aaSLee Jones unsigned long *chip_id) 427cd4209ceSRhyland Klein { 428cd4209ceSRhyland Klein return NULL; 429cd4209ceSRhyland Klein } 430cd4209ceSRhyland Klein #endif 431201cf052SLaxman Dewangan 432b079fa72SBill Huang static struct i2c_client *tps65910_i2c_client; 433b079fa72SBill Huang static void tps65910_power_off(void) 434b079fa72SBill Huang { 435b079fa72SBill Huang struct tps65910 *tps65910; 436b079fa72SBill Huang 437b079fa72SBill Huang tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev); 438b079fa72SBill Huang 439129989d5SDmitry Osipenko regmap_update_bits(tps65910->regmap, TPS65910_DEVCTRL, 440129989d5SDmitry Osipenko DEVCTRL_DEV_OFF_MASK | DEVCTRL_DEV_ON_MASK, 441129989d5SDmitry Osipenko DEVCTRL_DEV_OFF_MASK); 442b079fa72SBill Huang } 443b079fa72SBill Huang 444f791be49SBill Pemberton static int tps65910_i2c_probe(struct i2c_client *i2c, 44527c6750eSGraeme Gregory const struct i2c_device_id *id) 44627c6750eSGraeme Gregory { 44727c6750eSGraeme Gregory struct tps65910 *tps65910; 4482537df72SGraeme Gregory struct tps65910_board *pmic_plat_data; 449cb8d8654SLaxman Dewangan struct tps65910_board *of_pmic_plat_data = NULL; 450e3471bdcSGraeme Gregory struct tps65910_platform_data *init_data; 45101a0f4aaSLee Jones unsigned long chip_id = id->driver_data; 452dae3be36SMarkus Elfring int ret; 45327c6750eSGraeme Gregory 4542537df72SGraeme Gregory pmic_plat_data = dev_get_platdata(&i2c->dev); 455cd4209ceSRhyland Klein 456cb8d8654SLaxman Dewangan if (!pmic_plat_data && i2c->dev.of_node) { 457cd4209ceSRhyland Klein pmic_plat_data = tps65910_parse_dt(i2c, &chip_id); 458cb8d8654SLaxman Dewangan of_pmic_plat_data = pmic_plat_data; 459cb8d8654SLaxman Dewangan } 460cd4209ceSRhyland Klein 4612537df72SGraeme Gregory if (!pmic_plat_data) 4622537df72SGraeme Gregory return -EINVAL; 4632537df72SGraeme Gregory 46463fe7deeSLaxman Dewangan init_data = devm_kzalloc(&i2c->dev, sizeof(*init_data), GFP_KERNEL); 465e3471bdcSGraeme Gregory if (init_data == NULL) 466e3471bdcSGraeme Gregory return -ENOMEM; 467e3471bdcSGraeme Gregory 46863fe7deeSLaxman Dewangan tps65910 = devm_kzalloc(&i2c->dev, sizeof(*tps65910), GFP_KERNEL); 46963fe7deeSLaxman Dewangan if (tps65910 == NULL) 47027c6750eSGraeme Gregory return -ENOMEM; 47127c6750eSGraeme Gregory 472cb8d8654SLaxman Dewangan tps65910->of_plat_data = of_pmic_plat_data; 47327c6750eSGraeme Gregory i2c_set_clientdata(i2c, tps65910); 47427c6750eSGraeme Gregory tps65910->dev = &i2c->dev; 47527c6750eSGraeme Gregory tps65910->i2c_client = i2c; 476cd4209ceSRhyland Klein tps65910->id = chip_id; 47727c6750eSGraeme Gregory 478be1c7700SArnout Vandecappelle (Essensium/Mind) /* Work around silicon erratum SWCZ010: the tps65910 may miss the 479be1c7700SArnout Vandecappelle (Essensium/Mind) * first I2C transfer. So issue a dummy transfer before the first 480be1c7700SArnout Vandecappelle (Essensium/Mind) * real transfer. 481be1c7700SArnout Vandecappelle (Essensium/Mind) */ 482be1c7700SArnout Vandecappelle (Essensium/Mind) i2c_master_send(i2c, "", 1); 48363fe7deeSLaxman Dewangan tps65910->regmap = devm_regmap_init_i2c(i2c, &tps65910_regmap_config); 484dc9913a0SLaxman Dewangan if (IS_ERR(tps65910->regmap)) { 485dc9913a0SLaxman Dewangan ret = PTR_ERR(tps65910->regmap); 486dc9913a0SLaxman Dewangan dev_err(&i2c->dev, "regmap initialization failed: %d\n", ret); 48763fe7deeSLaxman Dewangan return ret; 488dc9913a0SLaxman Dewangan } 489dc9913a0SLaxman Dewangan 490b1224cd1SJesper Juhl init_data->irq = pmic_plat_data->irq; 4911773140fSLaxman Dewangan init_data->irq_base = pmic_plat_data->irq_base; 492b1224cd1SJesper Juhl 4931e351a95SAfzal Mohammed tps65910_irq_init(tps65910, init_data->irq, init_data); 494d02e83cbSJohan Hovold tps65910_ck32k_init(tps65910, pmic_plat_data); 495201cf052SLaxman Dewangan tps65910_sleepinit(tps65910, pmic_plat_data); 496201cf052SLaxman Dewangan 497b079fa72SBill Huang if (pmic_plat_data->pm_off && !pm_power_off) { 498*7620ad0bSDmitry Osipenko /* 499*7620ad0bSDmitry Osipenko * The PWR_OFF bit needs to be set separately, before 500*7620ad0bSDmitry Osipenko * transitioning to the OFF state. It enables the "sequential" 501*7620ad0bSDmitry Osipenko * power-off mode on TPS65911, it's a NO-OP on TPS65910. 502*7620ad0bSDmitry Osipenko */ 503*7620ad0bSDmitry Osipenko ret = regmap_set_bits(tps65910->regmap, TPS65910_DEVCTRL, 504*7620ad0bSDmitry Osipenko DEVCTRL_PWR_OFF_MASK); 505*7620ad0bSDmitry Osipenko if (ret) { 506*7620ad0bSDmitry Osipenko dev_err(&i2c->dev, "failed to set power-off mode: %d\n", 507*7620ad0bSDmitry Osipenko ret); 508*7620ad0bSDmitry Osipenko return ret; 509*7620ad0bSDmitry Osipenko } 510*7620ad0bSDmitry Osipenko 511b079fa72SBill Huang tps65910_i2c_client = i2c; 512b079fa72SBill Huang pm_power_off = tps65910_power_off; 513b079fa72SBill Huang } 514b079fa72SBill Huang 515f3466e77SLaxman Dewangan ret = devm_mfd_add_devices(tps65910->dev, -1, 51610ecb80eSLaxman Dewangan tps65910s, ARRAY_SIZE(tps65910s), 51717143e38SLaxman Dewangan NULL, 0, 51817143e38SLaxman Dewangan regmap_irq_get_domain(tps65910->irq_data)); 51910ecb80eSLaxman Dewangan if (ret < 0) { 52010ecb80eSLaxman Dewangan dev_err(&i2c->dev, "mfd_add_devices failed: %d\n", ret); 52110ecb80eSLaxman Dewangan return ret; 52210ecb80eSLaxman Dewangan } 52310ecb80eSLaxman Dewangan 52427c6750eSGraeme Gregory return ret; 52527c6750eSGraeme Gregory } 52627c6750eSGraeme Gregory 52727c6750eSGraeme Gregory static const struct i2c_device_id tps65910_i2c_id[] = { 52879557056SJorge Eduardo Candelaria { "tps65910", TPS65910 }, 52979557056SJorge Eduardo Candelaria { "tps65911", TPS65911 }, 53027c6750eSGraeme Gregory { } 53127c6750eSGraeme Gregory }; 53227c6750eSGraeme Gregory 53327c6750eSGraeme Gregory static struct i2c_driver tps65910_i2c_driver = { 53427c6750eSGraeme Gregory .driver = { 53527c6750eSGraeme Gregory .name = "tps65910", 536cd4209ceSRhyland Klein .of_match_table = of_match_ptr(tps65910_of_match), 53727c6750eSGraeme Gregory }, 53827c6750eSGraeme Gregory .probe = tps65910_i2c_probe, 53927c6750eSGraeme Gregory .id_table = tps65910_i2c_id, 54027c6750eSGraeme Gregory }; 54127c6750eSGraeme Gregory 54227c6750eSGraeme Gregory static int __init tps65910_i2c_init(void) 54327c6750eSGraeme Gregory { 54427c6750eSGraeme Gregory return i2c_add_driver(&tps65910_i2c_driver); 54527c6750eSGraeme Gregory } 54627c6750eSGraeme Gregory /* init early so consumer devices can complete system boot */ 54727c6750eSGraeme Gregory subsys_initcall(tps65910_i2c_init); 548