10 #define DRV_NAME "pinctrl-sh_pfc"
12 #define pr_fmt(fmt) DRV_NAME " " KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
18 #include <linux/slab.h>
34 struct pinctrl_pin_desc *
pads;
42 static int sh_pfc_get_groups_count(
struct pinctrl_dev *pctldev)
49 static const char *sh_pfc_get_group_name(
struct pinctrl_dev *pctldev,
54 return pmx->
pads[selector].name;
57 static int sh_pfc_get_group_pins(
struct pinctrl_dev *pctldev,
unsigned group,
58 const unsigned **
pins,
unsigned *num_pins)
74 static struct pinctrl_ops sh_pfc_pinctrl_ops = {
75 .get_groups_count = sh_pfc_get_groups_count,
76 .get_group_name = sh_pfc_get_group_name,
77 .get_group_pins = sh_pfc_get_group_pins,
78 .pin_dbg_show = sh_pfc_pin_dbg_show,
81 static int sh_pfc_get_functions_count(
struct pinctrl_dev *pctldev)
88 static const char *sh_pfc_get_function_name(
struct pinctrl_dev *pctldev,
96 static int sh_pfc_get_function_groups(
struct pinctrl_dev *pctldev,
unsigned func,
97 const char *
const **groups,
98 unsigned *
const num_groups)
108 static int sh_pfc_noop_enable(
struct pinctrl_dev *pctldev,
unsigned func,
114 static void sh_pfc_noop_disable(
struct pinctrl_dev *pctldev,
unsigned func,
119 static inline int sh_pfc_config_function(
struct sh_pfc *
pfc,
unsigned offset)
134 static int sh_pfc_reconfig_pin(
struct sh_pfc *pfc,
unsigned offset,
148 switch (pinmux_type) {
181 spin_unlock_irqrestore(&pfc->
lock, flags);
187 static int sh_pfc_gpio_request_enable(
struct pinctrl_dev *pctldev,
188 struct pinctrl_gpio_range *
range,
194 int ret, pinmux_type;
200 switch (pinmux_type) {
203 "deprecated, convert to pinctrl\n");
205 ret = sh_pfc_config_function(pfc, offset);
215 pr_err(
"Unsupported mux type (%d), bailing...\n", pinmux_type);
223 spin_unlock_irqrestore(&pfc->
lock, flags);
228 static void sh_pfc_gpio_disable_free(
struct pinctrl_dev *pctldev,
229 struct pinctrl_gpio_range *range,
243 spin_unlock_irqrestore(&pfc->
lock, flags);
246 static int sh_pfc_gpio_set_direction(
struct pinctrl_dev *pctldev,
247 struct pinctrl_gpio_range *range,
248 unsigned offset,
bool input)
253 return sh_pfc_reconfig_pin(pmx->
pfc, offset, type);
256 static struct pinmux_ops sh_pfc_pinmux_ops = {
257 .get_functions_count = sh_pfc_get_functions_count,
258 .get_function_name = sh_pfc_get_function_name,
259 .get_function_groups = sh_pfc_get_function_groups,
260 .enable = sh_pfc_noop_enable,
261 .disable = sh_pfc_noop_disable,
262 .gpio_request_enable = sh_pfc_gpio_request_enable,
263 .gpio_disable_free = sh_pfc_gpio_disable_free,
264 .gpio_set_direction = sh_pfc_gpio_set_direction,
267 static int sh_pfc_pinconf_get(
struct pinctrl_dev *pctldev,
unsigned pin,
278 static int sh_pfc_pinconf_set(
struct pinctrl_dev *pctldev,
unsigned pin,
287 return sh_pfc_reconfig_pin(pmx->
pfc, pin, config);
290 static void sh_pfc_pinconf_dbg_show(
struct pinctrl_dev *pctldev,
293 const char *pinmux_type_str[] = {
305 rc = sh_pfc_pinconf_get(pctldev, pin, &config);
309 seq_printf(s,
" %s", pinmux_type_str[config]);
312 static struct pinconf_ops sh_pfc_pinconf_ops = {
313 .pin_config_get = sh_pfc_pinconf_get,
314 .pin_config_set = sh_pfc_pinconf_set,
315 .pin_config_dbg_show = sh_pfc_pinconf_dbg_show,
318 static struct pinctrl_gpio_range sh_pfc_gpio_range = {
323 static struct pinctrl_desc sh_pfc_pinctrl_desc = {
326 .pctlops = &sh_pfc_pinctrl_ops,
327 .pmxops = &sh_pfc_pinmux_ops,
328 .confops = &sh_pfc_pinconf_ops,
349 spin_unlock_irqrestore(&pmx->
lock, flags);
377 for (i = 0; i < pmx->
nr_pads; i++) {
378 struct pinctrl_pin_desc *pin = pmx->
pads +
i;
382 pin->name = gpio->
name;
388 sh_pfc_map_one_gpio(pfc, pmx, gpio, i);
391 spin_unlock_irqrestore(&pfc->
lock, flags);
393 sh_pfc_pinctrl_desc.pins = pmx->
pads;
394 sh_pfc_pinctrl_desc.npins = pmx->
nr_pads;
412 for (i = fn = 0; i < pmx->
nr_pads; i++) {
419 spin_unlock_irqrestore(&pmx->
lock, flags);
432 pfc = sh_pfc_pmx->
pfc;
434 ret = sh_pfc_map_gpios(pfc, sh_pfc_pmx);
438 ret = sh_pfc_map_functions(pfc, sh_pfc_pmx);
444 if (IS_ERR(sh_pfc_pmx->
pctl)) {
445 ret = PTR_ERR(sh_pfc_pmx->
pctl);
455 platform_set_drvdata(pdev, sh_pfc_pmx);
474 platform_set_drvdata(pdev,
NULL);
484 .probe = sh_pfc_pinctrl_probe,
497 static int sh_pfc_pinctrl_init(
void)
519 sh_pfc_pmx->
pfc = pfc;
521 return sh_pfc_pinctrl_init();
525 static void __exit sh_pfc_pinctrl_exit(
void)