162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Core functions for TI TPS65912x PMICs 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/ 662306a36Sopenharmony_ci * Andrew F. Davis <afd@ti.com> 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Based on the TPS65218 driver and the previous TPS65912 driver by 962306a36Sopenharmony_ci * Margarita Olaya Cabrera <magi@slimlogic.co.uk> 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/interrupt.h> 1362306a36Sopenharmony_ci#include <linux/mfd/core.h> 1462306a36Sopenharmony_ci#include <linux/module.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include <linux/mfd/tps65912.h> 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_cistatic const struct mfd_cell tps65912_cells[] = { 1962306a36Sopenharmony_ci { .name = "tps65912-regulator", }, 2062306a36Sopenharmony_ci { .name = "tps65912-gpio", }, 2162306a36Sopenharmony_ci}; 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_cistatic const struct regmap_irq tps65912_irqs[] = { 2462306a36Sopenharmony_ci /* INT_STS IRQs */ 2562306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_F, 0, TPS65912_INT_STS_PWRHOLD_F), 2662306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_VMON, 0, TPS65912_INT_STS_VMON), 2762306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PWRON, 0, TPS65912_INT_STS_PWRON), 2862306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PWRON_LP, 0, TPS65912_INT_STS_PWRON_LP), 2962306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_R, 0, TPS65912_INT_STS_PWRHOLD_R), 3062306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_HOTDIE, 0, TPS65912_INT_STS_HOTDIE), 3162306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_R, 0, TPS65912_INT_STS_GPIO1_R), 3262306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_F, 0, TPS65912_INT_STS_GPIO1_F), 3362306a36Sopenharmony_ci /* INT_STS2 IRQs */ 3462306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_R, 1, TPS65912_INT_STS2_GPIO2_R), 3562306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_F, 1, TPS65912_INT_STS2_GPIO2_F), 3662306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_R, 1, TPS65912_INT_STS2_GPIO3_R), 3762306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_F, 1, TPS65912_INT_STS2_GPIO3_F), 3862306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_R, 1, TPS65912_INT_STS2_GPIO4_R), 3962306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_F, 1, TPS65912_INT_STS2_GPIO4_F), 4062306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_R, 1, TPS65912_INT_STS2_GPIO5_R), 4162306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_F, 1, TPS65912_INT_STS2_GPIO5_F), 4262306a36Sopenharmony_ci /* INT_STS3 IRQs */ 4362306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC1, 2, TPS65912_INT_STS3_PGOOD_DCDC1), 4462306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC2, 2, TPS65912_INT_STS3_PGOOD_DCDC2), 4562306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC3, 2, TPS65912_INT_STS3_PGOOD_DCDC3), 4662306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC4, 2, TPS65912_INT_STS3_PGOOD_DCDC4), 4762306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO1, 2, TPS65912_INT_STS3_PGOOD_LDO1), 4862306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO2, 2, TPS65912_INT_STS3_PGOOD_LDO2), 4962306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO3, 2, TPS65912_INT_STS3_PGOOD_LDO3), 5062306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO4, 2, TPS65912_INT_STS3_PGOOD_LDO4), 5162306a36Sopenharmony_ci /* INT_STS4 IRQs */ 5262306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO5, 3, TPS65912_INT_STS4_PGOOD_LDO5), 5362306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO6, 3, TPS65912_INT_STS4_PGOOD_LDO6), 5462306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO7, 3, TPS65912_INT_STS4_PGOOD_LDO7), 5562306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO8, 3, TPS65912_INT_STS4_PGOOD_LDO8), 5662306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO9, 3, TPS65912_INT_STS4_PGOOD_LDO9), 5762306a36Sopenharmony_ci REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO10, 3, TPS65912_INT_STS4_PGOOD_LDO10), 5862306a36Sopenharmony_ci}; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistatic struct regmap_irq_chip tps65912_irq_chip = { 6162306a36Sopenharmony_ci .name = "tps65912", 6262306a36Sopenharmony_ci .irqs = tps65912_irqs, 6362306a36Sopenharmony_ci .num_irqs = ARRAY_SIZE(tps65912_irqs), 6462306a36Sopenharmony_ci .num_regs = 4, 6562306a36Sopenharmony_ci .irq_reg_stride = 2, 6662306a36Sopenharmony_ci .mask_base = TPS65912_INT_MSK, 6762306a36Sopenharmony_ci .status_base = TPS65912_INT_STS, 6862306a36Sopenharmony_ci .ack_base = TPS65912_INT_STS, 6962306a36Sopenharmony_ci .init_ack_masked = true, 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_cistatic const struct regmap_range tps65912_yes_ranges[] = { 7362306a36Sopenharmony_ci regmap_reg_range(TPS65912_INT_STS, TPS65912_GPIO5), 7462306a36Sopenharmony_ci}; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistatic const struct regmap_access_table tps65912_volatile_table = { 7762306a36Sopenharmony_ci .yes_ranges = tps65912_yes_ranges, 7862306a36Sopenharmony_ci .n_yes_ranges = ARRAY_SIZE(tps65912_yes_ranges), 7962306a36Sopenharmony_ci}; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciconst struct regmap_config tps65912_regmap_config = { 8262306a36Sopenharmony_ci .reg_bits = 8, 8362306a36Sopenharmony_ci .val_bits = 8, 8462306a36Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 8562306a36Sopenharmony_ci .volatile_table = &tps65912_volatile_table, 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(tps65912_regmap_config); 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciint tps65912_device_init(struct tps65912 *tps) 9062306a36Sopenharmony_ci{ 9162306a36Sopenharmony_ci int ret; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0, 9462306a36Sopenharmony_ci &tps65912_irq_chip, &tps->irq_data); 9562306a36Sopenharmony_ci if (ret) 9662306a36Sopenharmony_ci return ret; 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65912_cells, 9962306a36Sopenharmony_ci ARRAY_SIZE(tps65912_cells), NULL, 0, 10062306a36Sopenharmony_ci regmap_irq_get_domain(tps->irq_data)); 10162306a36Sopenharmony_ci if (ret) { 10262306a36Sopenharmony_ci regmap_del_irq_chip(tps->irq, tps->irq_data); 10362306a36Sopenharmony_ci return ret; 10462306a36Sopenharmony_ci } 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci return 0; 10762306a36Sopenharmony_ci} 10862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(tps65912_device_init); 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_civoid tps65912_device_exit(struct tps65912 *tps) 11162306a36Sopenharmony_ci{ 11262306a36Sopenharmony_ci regmap_del_irq_chip(tps->irq, tps->irq_data); 11362306a36Sopenharmony_ci} 11462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(tps65912_device_exit); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ciMODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); 11762306a36Sopenharmony_ciMODULE_DESCRIPTION("TPS65912x MFD Driver"); 11862306a36Sopenharmony_ciMODULE_LICENSE("GPL v2"); 119