1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2022 Richtek Technology Corp.
4 * Author: ChiYuan Huang <cy_huang@richtek.com>
8 #include <linux/kernel.h>
9 #include <linux/mfd/core.h>
10 #include <linux/module.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/regmap.h>
14 #define RT5120_REG_INTENABLE 0x1D
15 #define RT5120_REG_INTSTAT 0x1E
16 #define RT5120_REG_FZCMODE 0x44
18 #define RT5120_INT_HOTDIE 0
19 #define RT5120_INT_PWRKEY_REL 5
20 #define RT5120_INT_PWRKEY_PRESS 6
22 static const struct regmap_range rt5120_rd_yes_ranges[] = {
23 regmap_reg_range(0x03, 0x13),
24 regmap_reg_range(0x1c, 0x20),
25 regmap_reg_range(0x44, 0x44),
28 static const struct regmap_range rt5120_wr_yes_ranges[] = {
29 regmap_reg_range(0x06, 0x13),
30 regmap_reg_range(0x1c, 0x20),
31 regmap_reg_range(0x44, 0x44),
34 static const struct regmap_access_table rt5120_rd_table = {
35 .yes_ranges = rt5120_rd_yes_ranges,
36 .n_yes_ranges = ARRAY_SIZE(rt5120_rd_yes_ranges),
39 static const struct regmap_access_table rt5120_wr_table = {
40 .yes_ranges = rt5120_wr_yes_ranges,
41 .n_yes_ranges = ARRAY_SIZE(rt5120_wr_yes_ranges),
44 static const struct regmap_config rt5120_regmap_config = {
47 .max_register = RT5120_REG_FZCMODE,
49 .wr_table = &rt5120_wr_table,
50 .rd_table = &rt5120_rd_table,
53 static const struct regmap_irq rt5120_irqs[] = {
54 REGMAP_IRQ_REG_LINE(RT5120_INT_HOTDIE, 8),
55 REGMAP_IRQ_REG_LINE(RT5120_INT_PWRKEY_REL, 8),
56 REGMAP_IRQ_REG_LINE(RT5120_INT_PWRKEY_PRESS, 8),
59 static const struct regmap_irq_chip rt5120_irq_chip = {
60 .name = "rt5120-pmic",
61 .status_base = RT5120_REG_INTSTAT,
62 .mask_base = RT5120_REG_INTENABLE,
63 .ack_base = RT5120_REG_INTSTAT,
68 .num_irqs = ARRAY_SIZE(rt5120_irqs),
71 static const struct resource rt5120_regulator_resources[] = {
72 DEFINE_RES_IRQ(RT5120_INT_HOTDIE),
75 static const struct resource rt5120_pwrkey_resources[] = {
76 DEFINE_RES_IRQ_NAMED(RT5120_INT_PWRKEY_PRESS, "pwrkey-press"),
77 DEFINE_RES_IRQ_NAMED(RT5120_INT_PWRKEY_REL, "pwrkey-release"),
80 static const struct mfd_cell rt5120_devs[] = {
81 MFD_CELL_RES("rt5120-regulator", rt5120_regulator_resources),
82 MFD_CELL_OF("rt5120-pwrkey", rt5120_pwrkey_resources, NULL, 0, 0, "richtek,rt5120-pwrkey"),
85 static int rt5120_probe(struct i2c_client *i2c)
87 struct device *dev = &i2c->dev;
88 struct regmap *regmap;
89 struct regmap_irq_chip_data *irq_data;
92 regmap = devm_regmap_init_i2c(i2c, &rt5120_regmap_config);
94 return dev_err_probe(dev, PTR_ERR(regmap),
95 "Failed to init regmap\n");
97 ret = devm_regmap_add_irq_chip(dev, regmap, i2c->irq, IRQF_ONESHOT, 0,
98 &rt5120_irq_chip, &irq_data);
100 return dev_err_probe(dev, ret, "Failed to add IRQ chip\n");
102 return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, rt5120_devs,
103 ARRAY_SIZE(rt5120_devs), NULL, 0,
104 regmap_irq_get_domain(irq_data));
107 static const struct of_device_id rt5120_device_match_table[] = {
108 { .compatible = "richtek,rt5120" },
111 MODULE_DEVICE_TABLE(of, rt5120_device_match_table);
113 static struct i2c_driver rt5120_driver = {
116 .of_match_table = rt5120_device_match_table,
118 .probe_new = rt5120_probe,
120 module_i2c_driver(rt5120_driver);
122 MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>");
123 MODULE_DESCRIPTION("Richtek RT5120 I2C driver");
124 MODULE_LICENSE("GPL v2");