1 // SPDX-License-Identifier: GPL-2.0+
3 * I2C driver for Renesas Synchronization Management Unit (SMU) devices.
5 * Copyright (C) 2021 Integrated Device Technology, Inc., a Renesas Company.
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/mfd/core.h>
12 #include <linux/mfd/rsmu.h>
13 #include <linux/module.h>
15 #include <linux/regmap.h>
16 #include <linux/slab.h>
21 * 16-bit register address: the lower 8 bits of the register address come
22 * from the offset addr byte and the upper 8 bits come from the page register.
24 #define RSMU_CM_PAGE_ADDR 0xFD
25 #define RSMU_CM_PAGE_WINDOW 256
28 * 15-bit register address: the lower 7 bits of the register address come
29 * from the offset addr byte and the upper 8 bits come from the page register.
31 #define RSMU_SABRE_PAGE_ADDR 0x7F
32 #define RSMU_SABRE_PAGE_WINDOW 128
34 static const struct regmap_range_cfg rsmu_cm_range_cfg[] = {
38 .selector_reg = RSMU_CM_PAGE_ADDR,
39 .selector_mask = 0xFF,
42 .window_len = RSMU_CM_PAGE_WINDOW,
46 static const struct regmap_range_cfg rsmu_sabre_range_cfg[] = {
50 .selector_reg = RSMU_SABRE_PAGE_ADDR,
51 .selector_mask = 0xFF,
54 .window_len = RSMU_SABRE_PAGE_WINDOW,
58 static bool rsmu_cm_volatile_reg(struct device *dev, unsigned int reg)
61 case RSMU_CM_PAGE_ADDR:
68 static bool rsmu_sabre_volatile_reg(struct device *dev, unsigned int reg)
71 case RSMU_SABRE_PAGE_ADDR:
78 static const struct regmap_config rsmu_cm_regmap_config = {
81 .max_register = 0xD000,
82 .ranges = rsmu_cm_range_cfg,
83 .num_ranges = ARRAY_SIZE(rsmu_cm_range_cfg),
84 .volatile_reg = rsmu_cm_volatile_reg,
85 .cache_type = REGCACHE_RBTREE,
86 .can_multi_write = true,
89 static const struct regmap_config rsmu_sabre_regmap_config = {
92 .max_register = 0x400,
93 .ranges = rsmu_sabre_range_cfg,
94 .num_ranges = ARRAY_SIZE(rsmu_sabre_range_cfg),
95 .volatile_reg = rsmu_sabre_volatile_reg,
96 .cache_type = REGCACHE_RBTREE,
97 .can_multi_write = true,
100 static const struct regmap_config rsmu_sl_regmap_config = {
103 .reg_format_endian = REGMAP_ENDIAN_BIG,
104 .max_register = 0x339,
105 .cache_type = REGCACHE_NONE,
106 .can_multi_write = true,
109 static int rsmu_i2c_probe(struct i2c_client *client,
110 const struct i2c_device_id *id)
112 const struct regmap_config *cfg;
113 struct rsmu_ddata *rsmu;
116 rsmu = devm_kzalloc(&client->dev, sizeof(*rsmu), GFP_KERNEL);
120 i2c_set_clientdata(client, rsmu);
122 rsmu->dev = &client->dev;
123 rsmu->type = (enum rsmu_type)id->driver_data;
125 switch (rsmu->type) {
127 cfg = &rsmu_cm_regmap_config;
130 cfg = &rsmu_sabre_regmap_config;
133 cfg = &rsmu_sl_regmap_config;
136 dev_err(rsmu->dev, "Unsupported RSMU device type: %d\n", rsmu->type);
139 rsmu->regmap = devm_regmap_init_i2c(client, cfg);
140 if (IS_ERR(rsmu->regmap)) {
141 ret = PTR_ERR(rsmu->regmap);
142 dev_err(rsmu->dev, "Failed to allocate register map: %d\n", ret);
146 return rsmu_core_init(rsmu);
149 static int rsmu_i2c_remove(struct i2c_client *client)
151 struct rsmu_ddata *rsmu = i2c_get_clientdata(client);
153 rsmu_core_exit(rsmu);
158 static const struct i2c_device_id rsmu_i2c_id[] = {
159 { "8a34000", RSMU_CM },
160 { "8a34001", RSMU_CM },
161 { "82p33810", RSMU_SABRE },
162 { "82p33811", RSMU_SABRE },
163 { "8v19n850", RSMU_SL },
164 { "8v19n851", RSMU_SL },
167 MODULE_DEVICE_TABLE(i2c, rsmu_i2c_id);
169 static const struct of_device_id rsmu_i2c_of_match[] = {
170 { .compatible = "idt,8a34000", .data = (void *)RSMU_CM },
171 { .compatible = "idt,8a34001", .data = (void *)RSMU_CM },
172 { .compatible = "idt,82p33810", .data = (void *)RSMU_SABRE },
173 { .compatible = "idt,82p33811", .data = (void *)RSMU_SABRE },
174 { .compatible = "idt,8v19n850", .data = (void *)RSMU_SL },
175 { .compatible = "idt,8v19n851", .data = (void *)RSMU_SL },
178 MODULE_DEVICE_TABLE(of, rsmu_i2c_of_match);
180 static struct i2c_driver rsmu_i2c_driver = {
183 .of_match_table = of_match_ptr(rsmu_i2c_of_match),
185 .probe = rsmu_i2c_probe,
186 .remove = rsmu_i2c_remove,
187 .id_table = rsmu_i2c_id,
190 static int __init rsmu_i2c_init(void)
192 return i2c_add_driver(&rsmu_i2c_driver);
194 subsys_initcall(rsmu_i2c_init);
196 static void __exit rsmu_i2c_exit(void)
198 i2c_del_driver(&rsmu_i2c_driver);
200 module_exit(rsmu_i2c_exit);
202 MODULE_DESCRIPTION("Renesas SMU I2C driver");
203 MODULE_LICENSE("GPL");