1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* |
3 | * Core functions for TI TPS65912x PMICs |
4 | * |
5 | * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/ |
6 | * Andrew F. Davis <afd@ti.com> |
7 | * |
8 | * Based on the TPS65218 driver and the previous TPS65912 driver by |
9 | * Margarita Olaya Cabrera <magi@slimlogic.co.uk> |
10 | */ |
11 | |
12 | #include <linux/interrupt.h> |
13 | #include <linux/mfd/core.h> |
14 | #include <linux/module.h> |
15 | |
16 | #include <linux/mfd/tps65912.h> |
17 | |
18 | static const struct mfd_cell tps65912_cells[] = { |
19 | { .name = "tps65912-regulator" , }, |
20 | { .name = "tps65912-gpio" , }, |
21 | }; |
22 | |
23 | static const struct regmap_irq tps65912_irqs[] = { |
24 | /* INT_STS IRQs */ |
25 | REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_F, 0, TPS65912_INT_STS_PWRHOLD_F), |
26 | REGMAP_IRQ_REG(TPS65912_IRQ_VMON, 0, TPS65912_INT_STS_VMON), |
27 | REGMAP_IRQ_REG(TPS65912_IRQ_PWRON, 0, TPS65912_INT_STS_PWRON), |
28 | REGMAP_IRQ_REG(TPS65912_IRQ_PWRON_LP, 0, TPS65912_INT_STS_PWRON_LP), |
29 | REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_R, 0, TPS65912_INT_STS_PWRHOLD_R), |
30 | REGMAP_IRQ_REG(TPS65912_IRQ_HOTDIE, 0, TPS65912_INT_STS_HOTDIE), |
31 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_R, 0, TPS65912_INT_STS_GPIO1_R), |
32 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_F, 0, TPS65912_INT_STS_GPIO1_F), |
33 | /* INT_STS2 IRQs */ |
34 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_R, 1, TPS65912_INT_STS2_GPIO2_R), |
35 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_F, 1, TPS65912_INT_STS2_GPIO2_F), |
36 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_R, 1, TPS65912_INT_STS2_GPIO3_R), |
37 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_F, 1, TPS65912_INT_STS2_GPIO3_F), |
38 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_R, 1, TPS65912_INT_STS2_GPIO4_R), |
39 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_F, 1, TPS65912_INT_STS2_GPIO4_F), |
40 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_R, 1, TPS65912_INT_STS2_GPIO5_R), |
41 | REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_F, 1, TPS65912_INT_STS2_GPIO5_F), |
42 | /* INT_STS3 IRQs */ |
43 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC1, 2, TPS65912_INT_STS3_PGOOD_DCDC1), |
44 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC2, 2, TPS65912_INT_STS3_PGOOD_DCDC2), |
45 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC3, 2, TPS65912_INT_STS3_PGOOD_DCDC3), |
46 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC4, 2, TPS65912_INT_STS3_PGOOD_DCDC4), |
47 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO1, 2, TPS65912_INT_STS3_PGOOD_LDO1), |
48 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO2, 2, TPS65912_INT_STS3_PGOOD_LDO2), |
49 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO3, 2, TPS65912_INT_STS3_PGOOD_LDO3), |
50 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO4, 2, TPS65912_INT_STS3_PGOOD_LDO4), |
51 | /* INT_STS4 IRQs */ |
52 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO5, 3, TPS65912_INT_STS4_PGOOD_LDO5), |
53 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO6, 3, TPS65912_INT_STS4_PGOOD_LDO6), |
54 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO7, 3, TPS65912_INT_STS4_PGOOD_LDO7), |
55 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO8, 3, TPS65912_INT_STS4_PGOOD_LDO8), |
56 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO9, 3, TPS65912_INT_STS4_PGOOD_LDO9), |
57 | REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO10, 3, TPS65912_INT_STS4_PGOOD_LDO10), |
58 | }; |
59 | |
60 | static struct regmap_irq_chip tps65912_irq_chip = { |
61 | .name = "tps65912" , |
62 | .irqs = tps65912_irqs, |
63 | .num_irqs = ARRAY_SIZE(tps65912_irqs), |
64 | .num_regs = 4, |
65 | .irq_reg_stride = 2, |
66 | .mask_base = TPS65912_INT_MSK, |
67 | .status_base = TPS65912_INT_STS, |
68 | .ack_base = TPS65912_INT_STS, |
69 | .init_ack_masked = true, |
70 | }; |
71 | |
72 | static const struct regmap_range tps65912_yes_ranges[] = { |
73 | regmap_reg_range(TPS65912_INT_STS, TPS65912_GPIO5), |
74 | }; |
75 | |
76 | static const struct regmap_access_table tps65912_volatile_table = { |
77 | .yes_ranges = tps65912_yes_ranges, |
78 | .n_yes_ranges = ARRAY_SIZE(tps65912_yes_ranges), |
79 | }; |
80 | |
81 | const struct regmap_config tps65912_regmap_config = { |
82 | .reg_bits = 8, |
83 | .val_bits = 8, |
84 | .cache_type = REGCACHE_MAPLE, |
85 | .volatile_table = &tps65912_volatile_table, |
86 | }; |
87 | EXPORT_SYMBOL_GPL(tps65912_regmap_config); |
88 | |
89 | int tps65912_device_init(struct tps65912 *tps) |
90 | { |
91 | int ret; |
92 | |
93 | ret = regmap_add_irq_chip(map: tps->regmap, irq: tps->irq, IRQF_ONESHOT, irq_base: 0, |
94 | chip: &tps65912_irq_chip, data: &tps->irq_data); |
95 | if (ret) |
96 | return ret; |
97 | |
98 | ret = mfd_add_devices(parent: tps->dev, PLATFORM_DEVID_AUTO, cells: tps65912_cells, |
99 | ARRAY_SIZE(tps65912_cells), NULL, irq_base: 0, |
100 | irq_domain: regmap_irq_get_domain(data: tps->irq_data)); |
101 | if (ret) { |
102 | regmap_del_irq_chip(irq: tps->irq, data: tps->irq_data); |
103 | return ret; |
104 | } |
105 | |
106 | return 0; |
107 | } |
108 | EXPORT_SYMBOL_GPL(tps65912_device_init); |
109 | |
110 | void tps65912_device_exit(struct tps65912 *tps) |
111 | { |
112 | regmap_del_irq_chip(irq: tps->irq, data: tps->irq_data); |
113 | } |
114 | EXPORT_SYMBOL_GPL(tps65912_device_exit); |
115 | |
116 | MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>" ); |
117 | MODULE_DESCRIPTION("TPS65912x MFD Driver" ); |
118 | MODULE_LICENSE("GPL v2" ); |
119 | |