Skip to content

Commit a1867f8

Browse files
Min LiLee Jones
authored andcommitted
mfd: Add Renesas Synchronization Management Unit (SMU) support
Add support for ClockMatrix(TM) and 82P33xxx families of timing and synchronization devices. The access interface can be either SPI or I2C. Currently, it will create 2 types of MFD devices, which are to be used by the corresponding rsmu character device driver and the PTP hardware clock driver, respectively. Signed-off-by: Min Li <min.li.xe@renesas.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent e73f0f0 commit a1867f8

9 files changed

Lines changed: 1490 additions & 0 deletions

File tree

‎drivers/mfd/Kconfig‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,5 +2183,33 @@ config MFD_INTEL_M10_BMC
21832183
additional drivers must be enabled in order to use the functionality
21842184
of the device.
21852185

2186+
config MFD_RSMU_I2C
2187+
tristate "Renesas Synchronization Management Unit with I2C"
2188+
depends on I2C && OF
2189+
select MFD_CORE
2190+
select REGMAP_I2C
2191+
help
2192+
Support for the Renesas Synchronization Management Unit, such as
2193+
Clockmatrix and 82P33XXX series. This option supports I2C as
2194+
the control interface.
2195+
2196+
This driver provides common support for accessing the device.
2197+
Additional drivers must be enabled in order to use the functionality
2198+
of the device.
2199+
2200+
config MFD_RSMU_SPI
2201+
tristate "Renesas Synchronization Management Unit with SPI"
2202+
depends on SPI && OF
2203+
select MFD_CORE
2204+
select REGMAP_SPI
2205+
help
2206+
Support for the Renesas Synchronization Management Unit, such as
2207+
Clockmatrix and 82P33XXX series. This option supports SPI as
2208+
the control interface.
2209+
2210+
This driver provides common support for accessing the device.
2211+
Additional drivers must be enabled in order to use the functionality
2212+
of the device.
2213+
21862214
endmenu
21872215
endif

‎drivers/mfd/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,8 @@ obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.o
272272

273273
obj-$(CONFIG_MFD_ATC260X) += atc260x-core.o
274274
obj-$(CONFIG_MFD_ATC260X_I2C) += atc260x-i2c.o
275+
276+
rsmu-i2c-objs := rsmu_core.o rsmu_i2c.o
277+
rsmu-spi-objs := rsmu_core.o rsmu_spi.o
278+
obj-$(CONFIG_MFD_RSMU_I2C) += rsmu-i2c.o
279+
obj-$(CONFIG_MFD_RSMU_SPI) += rsmu-spi.o

‎drivers/mfd/rsmu.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* Renesas Synchronization Management Unit (SMU) devices.
4+
*
5+
* Copyright (C) 2021 Integrated Device Technology, Inc., a Renesas Company.
6+
*/
7+
8+
#ifndef __RSMU_MFD_H
9+
#define __RSMU_MFD_H
10+
11+
#include <linux/mfd/rsmu.h>
12+
13+
int rsmu_core_init(struct rsmu_ddata *rsmu);
14+
void rsmu_core_exit(struct rsmu_ddata *rsmu);
15+
16+
#endif /* __RSMU_MFD_H */

‎drivers/mfd/rsmu_core.c‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Core driver for Renesas Synchronization Management Unit (SMU) devices.
4+
*
5+
* Copyright (C) 2021 Integrated Device Technology, Inc., a Renesas Company.
6+
*/
7+
8+
#include <linux/init.h>
9+
#include <linux/kernel.h>
10+
#include <linux/mfd/core.h>
11+
#include <linux/mfd/rsmu.h>
12+
#include <linux/module.h>
13+
#include <linux/of.h>
14+
#include <linux/regmap.h>
15+
#include <linux/slab.h>
16+
17+
#include "rsmu.h"
18+
19+
enum {
20+
RSMU_PHC = 0,
21+
RSMU_CDEV = 1,
22+
RSMU_N_DEVS = 2,
23+
};
24+
25+
static struct mfd_cell rsmu_cm_devs[] = {
26+
[RSMU_PHC] = {
27+
.name = "8a3400x-phc",
28+
},
29+
[RSMU_CDEV] = {
30+
.name = "8a3400x-cdev",
31+
},
32+
};
33+
34+
static struct mfd_cell rsmu_sabre_devs[] = {
35+
[RSMU_PHC] = {
36+
.name = "82p33x1x-phc",
37+
},
38+
[RSMU_CDEV] = {
39+
.name = "82p33x1x-cdev",
40+
},
41+
};
42+
43+
static struct mfd_cell rsmu_sl_devs[] = {
44+
[RSMU_PHC] = {
45+
.name = "8v19n85x-phc",
46+
},
47+
[RSMU_CDEV] = {
48+
.name = "8v19n85x-cdev",
49+
},
50+
};
51+
52+
int rsmu_core_init(struct rsmu_ddata *rsmu)
53+
{
54+
struct mfd_cell *cells;
55+
int ret;
56+
57+
switch (rsmu->type) {
58+
case RSMU_CM:
59+
cells = rsmu_cm_devs;
60+
break;
61+
case RSMU_SABRE:
62+
cells = rsmu_sabre_devs;
63+
break;
64+
case RSMU_SL:
65+
cells = rsmu_sl_devs;
66+
break;
67+
default:
68+
dev_err(rsmu->dev, "Unsupported RSMU device type: %d\n", rsmu->type);
69+
return -ENODEV;
70+
}
71+
72+
mutex_init(&rsmu->lock);
73+
74+
ret = devm_mfd_add_devices(rsmu->dev, PLATFORM_DEVID_AUTO, cells,
75+
RSMU_N_DEVS, NULL, 0, NULL);
76+
if (ret < 0)
77+
dev_err(rsmu->dev, "Failed to register sub-devices: %d\n", ret);
78+
79+
return ret;
80+
}
81+
82+
void rsmu_core_exit(struct rsmu_ddata *rsmu)
83+
{
84+
mutex_destroy(&rsmu->lock);
85+
}
86+
87+
MODULE_DESCRIPTION("Renesas SMU core driver");
88+
MODULE_LICENSE("GPL");

‎drivers/mfd/rsmu_i2c.c‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* I2C driver for Renesas Synchronization Management Unit (SMU) devices.
4+
*
5+
* Copyright (C) 2021 Integrated Device Technology, Inc., a Renesas Company.
6+
*/
7+
8+
#include <linux/i2c.h>
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>
14+
#include <linux/of.h>
15+
#include <linux/regmap.h>
16+
#include <linux/slab.h>
17+
18+
#include "rsmu.h"
19+
20+
/*
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.
23+
*/
24+
#define RSMU_CM_PAGE_ADDR 0xFD
25+
#define RSMU_CM_PAGE_WINDOW 256
26+
27+
/*
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.
30+
*/
31+
#define RSMU_SABRE_PAGE_ADDR 0x7F
32+
#define RSMU_SABRE_PAGE_WINDOW 128
33+
34+
static const struct regmap_range_cfg rsmu_cm_range_cfg[] = {
35+
{
36+
.range_min = 0,
37+
.range_max = 0xD000,
38+
.selector_reg = RSMU_CM_PAGE_ADDR,
39+
.selector_mask = 0xFF,
40+
.selector_shift = 0,
41+
.window_start = 0,
42+
.window_len = RSMU_CM_PAGE_WINDOW,
43+
}
44+
};
45+
46+
static const struct regmap_range_cfg rsmu_sabre_range_cfg[] = {
47+
{
48+
.range_min = 0,
49+
.range_max = 0x400,
50+
.selector_reg = RSMU_SABRE_PAGE_ADDR,
51+
.selector_mask = 0xFF,
52+
.selector_shift = 0,
53+
.window_start = 0,
54+
.window_len = RSMU_SABRE_PAGE_WINDOW,
55+
}
56+
};
57+
58+
static bool rsmu_cm_volatile_reg(struct device *dev, unsigned int reg)
59+
{
60+
switch (reg) {
61+
case RSMU_CM_PAGE_ADDR:
62+
return false;
63+
default:
64+
return true;
65+
}
66+
}
67+
68+
static bool rsmu_sabre_volatile_reg(struct device *dev, unsigned int reg)
69+
{
70+
switch (reg) {
71+
case RSMU_SABRE_PAGE_ADDR:
72+
return false;
73+
default:
74+
return true;
75+
}
76+
}
77+
78+
static const struct regmap_config rsmu_cm_regmap_config = {
79+
.reg_bits = 8,
80+
.val_bits = 8,
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,
87+
};
88+
89+
static const struct regmap_config rsmu_sabre_regmap_config = {
90+
.reg_bits = 8,
91+
.val_bits = 8,
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,
98+
};
99+
100+
static const struct regmap_config rsmu_sl_regmap_config = {
101+
.reg_bits = 16,
102+
.val_bits = 8,
103+
.reg_format_endian = REGMAP_ENDIAN_BIG,
104+
.max_register = 0x339,
105+
.cache_type = REGCACHE_NONE,
106+
.can_multi_write = true,
107+
};
108+
109+
static int rsmu_i2c_probe(struct i2c_client *client,
110+
const struct i2c_device_id *id)
111+
{
112+
const struct regmap_config *cfg;
113+
struct rsmu_ddata *rsmu;
114+
int ret;
115+
116+
rsmu = devm_kzalloc(&client->dev, sizeof(*rsmu), GFP_KERNEL);
117+
if (!rsmu)
118+
return -ENOMEM;
119+
120+
i2c_set_clientdata(client, rsmu);
121+
122+
rsmu->dev = &client->dev;
123+
rsmu->type = (enum rsmu_type)id->driver_data;
124+
125+
switch (rsmu->type) {
126+
case RSMU_CM:
127+
cfg = &rsmu_cm_regmap_config;
128+
break;
129+
case RSMU_SABRE:
130+
cfg = &rsmu_sabre_regmap_config;
131+
break;
132+
case RSMU_SL:
133+
cfg = &rsmu_sl_regmap_config;
134+
break;
135+
default:
136+
dev_err(rsmu->dev, "Unsupported RSMU device type: %d\n", rsmu->type);
137+
return -ENODEV;
138+
}
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);
143+
return ret;
144+
}
145+
146+
return rsmu_core_init(rsmu);
147+
}
148+
149+
static int rsmu_i2c_remove(struct i2c_client *client)
150+
{
151+
struct rsmu_ddata *rsmu = i2c_get_clientdata(client);
152+
153+
rsmu_core_exit(rsmu);
154+
155+
return 0;
156+
}
157+
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 },
165+
{}
166+
};
167+
MODULE_DEVICE_TABLE(i2c, rsmu_i2c_id);
168+
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 },
176+
{}
177+
};
178+
MODULE_DEVICE_TABLE(of, rsmu_i2c_of_match);
179+
180+
static struct i2c_driver rsmu_i2c_driver = {
181+
.driver = {
182+
.name = "rsmu-i2c",
183+
.of_match_table = of_match_ptr(rsmu_i2c_of_match),
184+
},
185+
.probe = rsmu_i2c_probe,
186+
.remove = rsmu_i2c_remove,
187+
.id_table = rsmu_i2c_id,
188+
};
189+
190+
static int __init rsmu_i2c_init(void)
191+
{
192+
return i2c_add_driver(&rsmu_i2c_driver);
193+
}
194+
subsys_initcall(rsmu_i2c_init);
195+
196+
static void __exit rsmu_i2c_exit(void)
197+
{
198+
i2c_del_driver(&rsmu_i2c_driver);
199+
}
200+
module_exit(rsmu_i2c_exit);
201+
202+
MODULE_DESCRIPTION("Renesas SMU I2C driver");
203+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)