Skip to content

Commit b4b993c

Browse files
mbriandlag-linaro
authored andcommitted
pinctrl: Add MAX7360 pinctrl driver
Add driver for Maxim Integrated MAX7360 pinctrl on the PORT pins. Pins can be used either for GPIO, PWM or rotary encoder functionalities. Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20250824-mdb-max7360-support-v14-3-435cfda2b1ea@bootlin.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent a22ddee commit b4b993c

3 files changed

Lines changed: 227 additions & 0 deletions

File tree

drivers/pinctrl/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ config PINCTRL_LPC18XX
358358
help
359359
Pinctrl driver for NXP LPC18xx/43xx System Control Unit (SCU).
360360

361+
config PINCTRL_MAX7360
362+
tristate "MAX7360 Pincontrol support"
363+
depends on MFD_MAX7360
364+
select PINMUX
365+
select GENERIC_PINCONF
366+
help
367+
Say Y here to enable pin control support for Maxim MAX7360 keypad
368+
controller.
369+
This keypad controller has 8 GPIO pins that may work as GPIO, or PWM,
370+
or rotary encoder alternate modes.
371+
361372
config PINCTRL_MAX77620
362373
tristate "MAX77620/MAX20024 Pincontrol support"
363374
depends on MFD_MAX77620 && OF

drivers/pinctrl/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ obj-$(CONFIG_PINCTRL_FALCON) += pinctrl-falcon.o
3737
obj-$(CONFIG_PINCTRL_LOONGSON2) += pinctrl-loongson2.o
3838
obj-$(CONFIG_PINCTRL_XWAY) += pinctrl-xway.o
3939
obj-$(CONFIG_PINCTRL_LPC18XX) += pinctrl-lpc18xx.o
40+
obj-$(CONFIG_PINCTRL_MAX7360) += pinctrl-max7360.o
4041
obj-$(CONFIG_PINCTRL_MAX77620) += pinctrl-max77620.o
4142
obj-$(CONFIG_PINCTRL_MCP23S08_I2C) += pinctrl-mcp23s08_i2c.o
4243
obj-$(CONFIG_PINCTRL_MCP23S08_SPI) += pinctrl-mcp23s08_spi.o

drivers/pinctrl/pinctrl-max7360.c

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright 2025 Bootlin
4+
*
5+
* Author: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
6+
*/
7+
8+
#include <linux/array_size.h>
9+
#include <linux/dev_printk.h>
10+
#include <linux/device.h>
11+
#include <linux/device/devres.h>
12+
#include <linux/err.h>
13+
#include <linux/init.h>
14+
#include <linux/mfd/max7360.h>
15+
#include <linux/module.h>
16+
#include <linux/platform_device.h>
17+
#include <linux/regmap.h>
18+
#include <linux/stddef.h>
19+
20+
#include <linux/pinctrl/pinctrl.h>
21+
#include <linux/pinctrl/pinconf-generic.h>
22+
#include <linux/pinctrl/pinmux.h>
23+
24+
#include "core.h"
25+
#include "pinmux.h"
26+
27+
struct max7360_pinctrl {
28+
struct pinctrl_dev *pctldev;
29+
struct pinctrl_desc pinctrl_desc;
30+
};
31+
32+
static const struct pinctrl_pin_desc max7360_pins[] = {
33+
PINCTRL_PIN(0, "PORT0"),
34+
PINCTRL_PIN(1, "PORT1"),
35+
PINCTRL_PIN(2, "PORT2"),
36+
PINCTRL_PIN(3, "PORT3"),
37+
PINCTRL_PIN(4, "PORT4"),
38+
PINCTRL_PIN(5, "PORT5"),
39+
PINCTRL_PIN(6, "PORT6"),
40+
PINCTRL_PIN(7, "PORT7"),
41+
};
42+
43+
static const unsigned int port0_pins[] = {0};
44+
static const unsigned int port1_pins[] = {1};
45+
static const unsigned int port2_pins[] = {2};
46+
static const unsigned int port3_pins[] = {3};
47+
static const unsigned int port4_pins[] = {4};
48+
static const unsigned int port5_pins[] = {5};
49+
static const unsigned int port6_pins[] = {6};
50+
static const unsigned int port7_pins[] = {7};
51+
static const unsigned int rotary_pins[] = {6, 7};
52+
53+
static const struct pingroup max7360_groups[] = {
54+
PINCTRL_PINGROUP("PORT0", port0_pins, ARRAY_SIZE(port0_pins)),
55+
PINCTRL_PINGROUP("PORT1", port1_pins, ARRAY_SIZE(port1_pins)),
56+
PINCTRL_PINGROUP("PORT2", port2_pins, ARRAY_SIZE(port2_pins)),
57+
PINCTRL_PINGROUP("PORT3", port3_pins, ARRAY_SIZE(port3_pins)),
58+
PINCTRL_PINGROUP("PORT4", port4_pins, ARRAY_SIZE(port4_pins)),
59+
PINCTRL_PINGROUP("PORT5", port5_pins, ARRAY_SIZE(port5_pins)),
60+
PINCTRL_PINGROUP("PORT6", port6_pins, ARRAY_SIZE(port6_pins)),
61+
PINCTRL_PINGROUP("PORT7", port7_pins, ARRAY_SIZE(port7_pins)),
62+
PINCTRL_PINGROUP("ROTARY", rotary_pins, ARRAY_SIZE(rotary_pins)),
63+
};
64+
65+
static int max7360_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
66+
{
67+
return ARRAY_SIZE(max7360_groups);
68+
}
69+
70+
static const char *max7360_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
71+
unsigned int group)
72+
{
73+
return max7360_groups[group].name;
74+
}
75+
76+
static int max7360_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
77+
unsigned int group,
78+
const unsigned int **pins,
79+
unsigned int *num_pins)
80+
{
81+
*pins = max7360_groups[group].pins;
82+
*num_pins = max7360_groups[group].npins;
83+
return 0;
84+
}
85+
86+
static const struct pinctrl_ops max7360_pinctrl_ops = {
87+
.get_groups_count = max7360_pinctrl_get_groups_count,
88+
.get_group_name = max7360_pinctrl_get_group_name,
89+
.get_group_pins = max7360_pinctrl_get_group_pins,
90+
#ifdef CONFIG_OF
91+
.dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
92+
.dt_free_map = pinconf_generic_dt_free_map,
93+
#endif
94+
};
95+
96+
static const char * const simple_groups[] = {
97+
"PORT0", "PORT1", "PORT2", "PORT3",
98+
"PORT4", "PORT5", "PORT6", "PORT7",
99+
};
100+
101+
static const char * const rotary_groups[] = { "ROTARY" };
102+
103+
#define MAX7360_PINCTRL_FN_GPIO 0
104+
#define MAX7360_PINCTRL_FN_PWM 1
105+
#define MAX7360_PINCTRL_FN_ROTARY 2
106+
static const struct pinfunction max7360_functions[] = {
107+
[MAX7360_PINCTRL_FN_GPIO] = PINCTRL_PINFUNCTION("gpio", simple_groups,
108+
ARRAY_SIZE(simple_groups)),
109+
[MAX7360_PINCTRL_FN_PWM] = PINCTRL_PINFUNCTION("pwm", simple_groups,
110+
ARRAY_SIZE(simple_groups)),
111+
[MAX7360_PINCTRL_FN_ROTARY] = PINCTRL_PINFUNCTION("rotary", rotary_groups,
112+
ARRAY_SIZE(rotary_groups)),
113+
};
114+
115+
static int max7360_get_functions_count(struct pinctrl_dev *pctldev)
116+
{
117+
return ARRAY_SIZE(max7360_functions);
118+
}
119+
120+
static const char *max7360_get_function_name(struct pinctrl_dev *pctldev, unsigned int selector)
121+
{
122+
return max7360_functions[selector].name;
123+
}
124+
125+
static int max7360_get_function_groups(struct pinctrl_dev *pctldev, unsigned int selector,
126+
const char * const **groups,
127+
unsigned int * const num_groups)
128+
{
129+
*groups = max7360_functions[selector].groups;
130+
*num_groups = max7360_functions[selector].ngroups;
131+
132+
return 0;
133+
}
134+
135+
static int max7360_set_mux(struct pinctrl_dev *pctldev, unsigned int selector,
136+
unsigned int group)
137+
{
138+
struct regmap *regmap = dev_get_regmap(pctldev->dev->parent, NULL);
139+
int val;
140+
141+
/*
142+
* GPIO and PWM functions are the same: we only need to handle the
143+
* rotary encoder function, on pins 6 and 7.
144+
*/
145+
if (max7360_groups[group].pins[0] >= 6) {
146+
if (selector == MAX7360_PINCTRL_FN_ROTARY)
147+
val = MAX7360_GPIO_CFG_RTR_EN;
148+
else
149+
val = 0;
150+
151+
return regmap_write_bits(regmap, MAX7360_REG_GPIOCFG, MAX7360_GPIO_CFG_RTR_EN, val);
152+
}
153+
154+
return 0;
155+
}
156+
157+
static const struct pinmux_ops max7360_pmxops = {
158+
.get_functions_count = max7360_get_functions_count,
159+
.get_function_name = max7360_get_function_name,
160+
.get_function_groups = max7360_get_function_groups,
161+
.set_mux = max7360_set_mux,
162+
.strict = true,
163+
};
164+
165+
static int max7360_pinctrl_probe(struct platform_device *pdev)
166+
{
167+
struct regmap *regmap;
168+
struct pinctrl_desc *pd;
169+
struct max7360_pinctrl *chip;
170+
struct device *dev = &pdev->dev;
171+
172+
regmap = dev_get_regmap(dev->parent, NULL);
173+
if (!regmap)
174+
return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n");
175+
176+
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
177+
if (!chip)
178+
return -ENOMEM;
179+
180+
pd = &chip->pinctrl_desc;
181+
182+
pd->pctlops = &max7360_pinctrl_ops;
183+
pd->pmxops = &max7360_pmxops;
184+
pd->name = dev_name(dev);
185+
pd->pins = max7360_pins;
186+
pd->npins = MAX7360_MAX_GPIO;
187+
pd->owner = THIS_MODULE;
188+
189+
/*
190+
* This MFD sub-device does not have any associated device tree node:
191+
* properties are stored in the device node of the parent (MFD) device
192+
* and this same node is used in phandles of client devices.
193+
* Reuse this device tree node here, as otherwise the pinctrl subsystem
194+
* would be confused by this topology.
195+
*/
196+
device_set_of_node_from_dev(dev, dev->parent);
197+
198+
chip->pctldev = devm_pinctrl_register(dev, pd, chip);
199+
if (IS_ERR(chip->pctldev))
200+
return dev_err_probe(dev, PTR_ERR(chip->pctldev), "can't register controller\n");
201+
202+
return 0;
203+
}
204+
205+
static struct platform_driver max7360_pinctrl_driver = {
206+
.driver = {
207+
.name = "max7360-pinctrl",
208+
},
209+
.probe = max7360_pinctrl_probe,
210+
};
211+
module_platform_driver(max7360_pinctrl_driver);
212+
213+
MODULE_DESCRIPTION("MAX7360 pinctrl driver");
214+
MODULE_AUTHOR("Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>");
215+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)