1 // SPDX-License-Identifier: GPL-2.0
3 * Pin Control driver for SuperH Pin Function Controller.
5 * Authors: Magnus Damm, Paul Mundt, Laurent Pinchart
7 * Copyright (C) 2008 Magnus Damm
8 * Copyright (C) 2009 - 2012 Paul Mundt
9 * Copyright (C) 2017 Marek Vasut
12 #define DRV_NAME "sh-pfc"
17 #include <dm/device_compat.h>
18 #include <dm/devres.h>
19 #include <dm/pinctrl.h>
20 #include <linux/bitops.h>
21 #include <linux/bug.h>
23 #include <linux/sizes.h>
48 struct sh_pfc_pin_config {
53 struct sh_pfc_pinctrl {
56 struct sh_pfc_pin_config *configs;
59 struct sh_pfc_pin_range {
64 struct sh_pfc_pinctrl_priv {
66 struct sh_pfc_pinctrl pmx;
69 int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin)
74 for (i = 0, offset = 0; i < pfc->nr_ranges; ++i) {
75 const struct sh_pfc_pin_range *range = &pfc->ranges[i];
77 if (pin <= range->end)
78 return pin >= range->start
79 ? offset + pin - range->start : -1;
81 offset += range->end - range->start + 1;
87 static int sh_pfc_enum_in_range(u16 enum_id, const struct pinmux_range *r)
89 if (enum_id < r->begin)
98 u32 sh_pfc_read_raw_reg(void __iomem *mapped_reg, unsigned int reg_width)
102 return readb(mapped_reg);
104 return readw(mapped_reg);
106 return readl(mapped_reg);
113 void sh_pfc_write_raw_reg(void __iomem *mapped_reg, unsigned int reg_width,
118 writeb(data, mapped_reg);
121 writew(data, mapped_reg);
124 writel(data, mapped_reg);
131 u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg)
133 return sh_pfc_read_raw_reg((void __iomem *)(uintptr_t)reg, 32);
136 static void sh_pfc_unlock_reg(struct sh_pfc *pfc, u32 reg, u32 data)
140 if (!pfc->info->unlock_reg)
143 if (pfc->info->unlock_reg >= 0x80000000UL)
144 unlock = pfc->info->unlock_reg;
146 /* unlock_reg is a mask */
147 unlock = reg & ~pfc->info->unlock_reg;
149 sh_pfc_write_raw_reg((void __iomem *)(uintptr_t)unlock, 32, ~data);
152 void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data)
154 sh_pfc_unlock_reg(pfc, reg, data);
155 sh_pfc_write_raw_reg((void __iomem *)(uintptr_t)reg, 32, data);
158 static void sh_pfc_config_reg_helper(struct sh_pfc *pfc,
159 const struct pinmux_cfg_reg *crp,
161 void __iomem **mapped_regp, u32 *maskp,
166 *mapped_regp = (void __iomem *)(uintptr_t)crp->reg;
168 if (crp->field_width) {
169 *maskp = (1 << crp->field_width) - 1;
170 *posp = crp->reg_width - ((in_pos + 1) * crp->field_width);
172 *maskp = (1 << crp->var_field_width[in_pos]) - 1;
173 *posp = crp->reg_width;
174 for (k = 0; k <= in_pos; k++)
175 *posp -= abs(crp->var_field_width[k]);
179 static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
180 const struct pinmux_cfg_reg *crp,
181 unsigned int field, u32 value)
183 void __iomem *mapped_reg;
187 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
189 dev_dbg(pfc->dev, "write_reg addr = %x, value = 0x%x, field = %u, "
190 "r_width = %u, f_width = %u\n",
191 crp->reg, value, field, crp->reg_width, crp->field_width);
193 mask = ~(mask << pos);
194 value = value << pos;
196 data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width);
200 sh_pfc_unlock_reg(pfc, crp->reg, data);
201 sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
204 static int sh_pfc_get_config_reg(struct sh_pfc *pfc, u16 enum_id,
205 const struct pinmux_cfg_reg **crp,
206 unsigned int *fieldp, u32 *valuep)
211 const struct pinmux_cfg_reg *config_reg =
212 pfc->info->cfg_regs + k;
213 unsigned int r_width = config_reg->reg_width;
214 unsigned int f_width = config_reg->field_width;
215 unsigned int curr_width;
216 unsigned int bit_pos;
217 unsigned int pos = 0;
223 for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width, m++) {
228 curr_width = f_width;
230 curr_width = abs(config_reg->var_field_width[m]);
231 if (config_reg->var_field_width[m] < 0)
235 ncomb = 1 << curr_width;
236 for (n = 0; n < ncomb; n++) {
237 if (config_reg->enum_ids[pos + n] == enum_id) {
252 static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, u16 mark, int pos,
255 const u16 *data = pfc->info->pinmux_data;
259 *enum_idp = data[pos + 1];
263 for (k = 0; k < pfc->info->pinmux_data_size; k++) {
264 if (data[k] == mark) {
265 *enum_idp = data[k + 1];
270 dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n",
275 int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
277 const struct pinmux_range *range;
280 switch (pinmux_type) {
281 case PINMUX_TYPE_GPIO:
282 case PINMUX_TYPE_FUNCTION:
286 case PINMUX_TYPE_OUTPUT:
287 range = &pfc->info->output;
290 case PINMUX_TYPE_INPUT:
291 range = &pfc->info->input;
298 /* Iterate over all the configuration fields we need to update. */
300 const struct pinmux_cfg_reg *cr;
307 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
314 /* Check if the configuration field selects a function. If it
315 * doesn't, skip the field if it's not applicable to the
316 * requested pinmux type.
318 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
320 if (pinmux_type == PINMUX_TYPE_FUNCTION) {
321 /* Functions are allowed to modify all
325 } else if (pinmux_type != PINMUX_TYPE_GPIO) {
326 /* Input/output types can only modify fields
327 * that correspond to their respective ranges.
329 in_range = sh_pfc_enum_in_range(enum_id, range);
332 * special case pass through for fixed
333 * input-only or output-only pins without
334 * function enum register association.
336 if (in_range && enum_id == range->force)
339 /* GPIOs are only allowed to modify function fields. */
345 ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value);
349 sh_pfc_write_config_reg(pfc, cr, field, value);
355 const struct pinmux_bias_reg *
356 rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
361 for (i = 0; info->bias_regs[i].puen || info->bias_regs[i].pud; i++) {
362 for (j = 0; j < ARRAY_SIZE(info->bias_regs[i].pins); j++) {
363 if (info->bias_regs[i].pins[j] == pin) {
365 return &info->bias_regs[i];
370 WARN_ONCE(1, "Pin %u is not in bias info list\n", pin);
375 unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
377 const struct pinmux_bias_reg *reg;
380 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
382 return PIN_CONFIG_BIAS_DISABLE;
385 if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
386 return PIN_CONFIG_BIAS_DISABLE;
387 else if (!reg->pud || (sh_pfc_read(pfc, reg->pud) & BIT(bit)))
388 return PIN_CONFIG_BIAS_PULL_UP;
390 return PIN_CONFIG_BIAS_PULL_DOWN;
392 if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
393 return PIN_CONFIG_BIAS_PULL_DOWN;
395 return PIN_CONFIG_BIAS_DISABLE;
399 void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
402 const struct pinmux_bias_reg *reg;
406 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
411 enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
412 if (bias != PIN_CONFIG_BIAS_DISABLE) {
416 updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
417 if (bias == PIN_CONFIG_BIAS_PULL_UP)
420 sh_pfc_write(pfc, reg->pud, updown);
423 sh_pfc_write(pfc, reg->puen, enable);
425 enable = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
426 if (bias == PIN_CONFIG_BIAS_PULL_DOWN)
429 sh_pfc_write(pfc, reg->pud, enable);
433 static int sh_pfc_init_ranges(struct sh_pfc *pfc)
435 struct sh_pfc_pin_range *range;
436 unsigned int nr_ranges;
439 if (pfc->info->pins[0].pin == (u16)-1) {
440 /* Pin number -1 denotes that the SoC doesn't report pin numbers
441 * in its pin arrays yet. Consider the pin numbers range as
442 * continuous and allocate a single range.
445 pfc->ranges = kzalloc(sizeof(*pfc->ranges), GFP_KERNEL);
446 if (pfc->ranges == NULL)
449 pfc->ranges->start = 0;
450 pfc->ranges->end = pfc->info->nr_pins - 1;
451 pfc->nr_gpio_pins = pfc->info->nr_pins;
456 /* Count, allocate and fill the ranges. The PFC SoC data pins array must
457 * be sorted by pin numbers, and pins without a GPIO port must come
460 for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) {
461 if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1)
465 pfc->nr_ranges = nr_ranges;
466 pfc->ranges = kzalloc(sizeof(*pfc->ranges) * nr_ranges, GFP_KERNEL);
467 if (pfc->ranges == NULL)
471 range->start = pfc->info->pins[0].pin;
473 for (i = 1; i < pfc->info->nr_pins; ++i) {
474 if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1)
477 range->end = pfc->info->pins[i-1].pin;
478 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO))
479 pfc->nr_gpio_pins = range->end + 1;
482 range->start = pfc->info->pins[i].pin;
485 range->end = pfc->info->pins[i-1].pin;
486 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO))
487 pfc->nr_gpio_pins = range->end + 1;
492 static int sh_pfc_pinctrl_get_pins_count(struct udevice *dev)
494 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
496 return priv->pfc.info->nr_pins;
499 static const char *sh_pfc_pinctrl_get_pin_name(struct udevice *dev,
502 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
504 return priv->pfc.info->pins[selector].name;
507 static int sh_pfc_pinctrl_get_groups_count(struct udevice *dev)
509 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
511 return priv->pfc.info->nr_groups;
514 static const char *sh_pfc_pinctrl_get_group_name(struct udevice *dev,
517 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
519 return priv->pfc.info->groups[selector].name;
522 static int sh_pfc_pinctrl_get_pin_muxing(struct udevice *dev,
523 unsigned int selector,
526 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
527 struct sh_pfc_pinctrl *pmx = &priv->pmx;
528 struct sh_pfc *pfc = &priv->pfc;
529 struct sh_pfc_pin_config *cfg;
530 const struct sh_pfc_pin *pin;
533 pin = &priv->pfc.info->pins[selector];
535 snprintf(buf, size, "Unknown");
539 idx = sh_pfc_get_pin_index(pfc, pin->pin);
540 cfg = &pmx->configs[idx];
541 snprintf(buf, size, "%s", cfg->name);
546 static int sh_pfc_pinctrl_get_functions_count(struct udevice *dev)
548 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
550 return priv->pfc.info->nr_functions;
553 static const char *sh_pfc_pinctrl_get_function_name(struct udevice *dev,
556 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
558 return priv->pfc.info->functions[selector].name;
561 static int sh_pfc_gpio_request_enable(struct udevice *dev,
562 unsigned pin_selector)
564 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
565 struct sh_pfc_pinctrl *pmx = &priv->pmx;
566 struct sh_pfc *pfc = &priv->pfc;
567 struct sh_pfc_pin_config *cfg;
568 const struct sh_pfc_pin *pin = NULL;
571 for (i = 0; i < pfc->info->nr_pins; i++) {
572 if (priv->pfc.info->pins[i].pin != pin_selector)
575 pin = &priv->pfc.info->pins[i];
582 idx = sh_pfc_get_pin_index(pfc, pin->pin);
583 cfg = &pmx->configs[idx];
585 if (cfg->type != PINMUX_TYPE_NONE) {
586 if (!strcmp(cfg->name, pin->name))
589 dev_err(pfc->dev, "Pin already used as %s\n",
594 ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
598 cfg->type = PINMUX_TYPE_GPIO;
604 static int sh_pfc_gpio_disable_free(struct udevice *dev,
605 unsigned pin_selector)
607 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
608 struct sh_pfc_pinctrl *pmx = &priv->pmx;
609 struct sh_pfc *pfc = &priv->pfc;
610 struct sh_pfc_pin_config *cfg;
611 const struct sh_pfc_pin *pin = NULL;
614 for (i = 0; i < pfc->info->nr_pins; i++) {
615 if (priv->pfc.info->pins[i].pin != pin_selector)
618 pin = &priv->pfc.info->pins[i];
625 idx = sh_pfc_get_pin_index(pfc, pin->pin);
626 cfg = &pmx->configs[idx];
628 cfg->type = PINMUX_TYPE_NONE;
634 static int sh_pfc_pinctrl_pin_set(struct udevice *dev, unsigned pin_selector,
635 unsigned func_selector)
637 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
638 struct sh_pfc_pinctrl *pmx = &priv->pmx;
639 struct sh_pfc *pfc = &priv->pfc;
640 const struct sh_pfc_pin *pin = &priv->pfc.info->pins[pin_selector];
641 int idx = sh_pfc_get_pin_index(pfc, pin->pin);
642 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
645 if (cfg->type != PINMUX_TYPE_NONE) {
646 if (!strcmp(cfg->name, pin->name))
649 dev_err(pfc->dev, "Pin already used as %s\n",
654 ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_FUNCTION);
658 cfg->type = PINMUX_TYPE_FUNCTION;
659 cfg->name = "function";
664 static int sh_pfc_pinctrl_group_set(struct udevice *dev, unsigned group_selector,
665 unsigned func_selector)
667 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
668 struct sh_pfc_pinctrl *pmx = &priv->pmx;
669 struct sh_pfc *pfc = &priv->pfc;
670 const struct sh_pfc_pin_group *grp = &priv->pfc.info->groups[group_selector];
671 bool grp_pins_configured = true;
672 struct sh_pfc_pin_config *cfg;
677 for (i = 0; i < grp->nr_pins; ++i) {
678 idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
679 cfg = &pmx->configs[idx];
681 if (cfg->type != PINMUX_TYPE_NONE) {
682 if (!strcmp(cfg->name, grp->name))
685 dev_err(pfc->dev, "Pin already used as %s\n",
690 grp_pins_configured = false;
694 if (grp_pins_configured)
697 for (i = 0; i < grp->nr_pins; ++i) {
698 ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
702 idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
703 cfg = &pmx->configs[idx];
704 cfg->type = PINMUX_TYPE_FUNCTION;
705 cfg->name = priv->pfc.info->groups[group_selector].name;
711 #if CONFIG_IS_ENABLED(PINCONF)
712 static const struct pinconf_param sh_pfc_pinconf_params[] = {
713 { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
714 { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
715 { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
716 { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
717 { "power-source", PIN_CONFIG_POWER_SOURCE, 3300 },
720 static void __iomem *
721 sh_pfc_pinconf_find_drive_strength_reg(struct sh_pfc *pfc, unsigned int pin,
722 unsigned int *offset, unsigned int *size)
724 const struct pinmux_drive_reg_field *field;
725 const struct pinmux_drive_reg *reg;
728 for (reg = pfc->info->drive_regs; reg->reg; ++reg) {
729 for (i = 0; i < ARRAY_SIZE(reg->fields); ++i) {
730 field = ®->fields[i];
732 if (field->size && field->pin == pin) {
733 *offset = field->offset;
736 return (void __iomem *)(uintptr_t)reg->reg;
744 static int sh_pfc_pinconf_set_drive_strength(struct sh_pfc *pfc,
745 unsigned int pin, u16 strength)
753 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
757 step = size == 2 ? 6 : 3;
759 if (strength < step || strength > 24)
762 /* Convert the value from mA based on a full drive strength value of
763 * 24mA. We can make the full value configurable later if needed.
765 strength = strength / step - 1;
767 val = sh_pfc_read_raw_reg(reg, 32);
768 val &= ~GENMASK(offset + 4 - 1, offset);
769 val |= strength << offset;
771 sh_pfc_unlock_reg(pfc, (uintptr_t)reg, val);
772 sh_pfc_write_raw_reg(reg, 32, val);
777 /* Check whether the requested parameter is supported for a pin. */
778 static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
781 int idx = sh_pfc_get_pin_index(pfc, _pin);
782 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
785 case PIN_CONFIG_BIAS_DISABLE:
786 return pin->configs &
787 (SH_PFC_PIN_CFG_PULL_UP | SH_PFC_PIN_CFG_PULL_DOWN);
789 case PIN_CONFIG_BIAS_PULL_UP:
790 return pin->configs & SH_PFC_PIN_CFG_PULL_UP;
792 case PIN_CONFIG_BIAS_PULL_DOWN:
793 return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
795 case PIN_CONFIG_DRIVE_STRENGTH:
796 return pin->configs & SH_PFC_PIN_CFG_DRIVE_STRENGTH;
798 case PIN_CONFIG_POWER_SOURCE:
799 return pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE;
806 static int sh_pfc_pinconf_set(struct sh_pfc_pinctrl *pmx, unsigned _pin,
807 unsigned int param, unsigned int arg)
809 struct sh_pfc *pfc = pmx->pfc;
810 void __iomem *pocctrl;
814 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
818 case PIN_CONFIG_BIAS_PULL_UP:
819 case PIN_CONFIG_BIAS_PULL_DOWN:
820 case PIN_CONFIG_BIAS_DISABLE:
821 if (!pfc->info->ops || !pfc->info->ops->set_bias)
824 pfc->info->ops->set_bias(pfc, _pin, param);
828 case PIN_CONFIG_DRIVE_STRENGTH:
829 ret = sh_pfc_pinconf_set_drive_strength(pfc, _pin, arg);
835 case PIN_CONFIG_POWER_SOURCE:
836 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
839 bit = pfc->info->ops->pin_to_pocctrl(_pin, &addr);
841 printf("invalid pin %#x", _pin);
845 if (arg != 1800 && arg != 3300)
848 pocctrl = (void __iomem *)(uintptr_t)addr;
850 val = sh_pfc_read_raw_reg(pocctrl, 32);
856 sh_pfc_unlock_reg(pfc, addr, val);
857 sh_pfc_write_raw_reg(pocctrl, 32, val);
868 static int sh_pfc_pinconf_pin_set(struct udevice *dev,
869 unsigned int pin_selector,
870 unsigned int param, unsigned int arg)
872 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
873 struct sh_pfc_pinctrl *pmx = &priv->pmx;
874 struct sh_pfc *pfc = &priv->pfc;
875 const struct sh_pfc_pin *pin = &pfc->info->pins[pin_selector];
877 sh_pfc_pinconf_set(pmx, pin->pin, param, arg);
882 static int sh_pfc_pinconf_group_set(struct udevice *dev,
883 unsigned int group_selector,
884 unsigned int param, unsigned int arg)
886 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
887 struct sh_pfc_pinctrl *pmx = &priv->pmx;
888 struct sh_pfc *pfc = &priv->pfc;
889 const struct sh_pfc_pin_group *grp = &pfc->info->groups[group_selector];
892 for (i = 0; i < grp->nr_pins; i++)
893 sh_pfc_pinconf_set(pmx, grp->pins[i], param, arg);
899 static struct pinctrl_ops sh_pfc_pinctrl_ops = {
900 .get_pins_count = sh_pfc_pinctrl_get_pins_count,
901 .get_pin_name = sh_pfc_pinctrl_get_pin_name,
902 .get_groups_count = sh_pfc_pinctrl_get_groups_count,
903 .get_group_name = sh_pfc_pinctrl_get_group_name,
904 .get_pin_muxing = sh_pfc_pinctrl_get_pin_muxing,
905 .get_functions_count = sh_pfc_pinctrl_get_functions_count,
906 .get_function_name = sh_pfc_pinctrl_get_function_name,
908 #if CONFIG_IS_ENABLED(PINCONF)
909 .pinconf_num_params = ARRAY_SIZE(sh_pfc_pinconf_params),
910 .pinconf_params = sh_pfc_pinconf_params,
911 .pinconf_set = sh_pfc_pinconf_pin_set,
912 .pinconf_group_set = sh_pfc_pinconf_group_set,
914 .pinmux_set = sh_pfc_pinctrl_pin_set,
915 .pinmux_group_set = sh_pfc_pinctrl_group_set,
916 .set_state = pinctrl_generic_set_state,
918 .gpio_request_enable = sh_pfc_gpio_request_enable,
919 .gpio_disable_free = sh_pfc_gpio_disable_free,
922 static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
926 /* Allocate and initialize the pins and configs arrays. */
927 pmx->configs = kzalloc(sizeof(*pmx->configs) * pfc->info->nr_pins,
929 if (unlikely(!pmx->configs))
932 for (i = 0; i < pfc->info->nr_pins; ++i) {
933 struct sh_pfc_pin_config *cfg = &pmx->configs[i];
934 cfg->type = PINMUX_TYPE_NONE;
942 static int sh_pfc_pinctrl_probe(struct udevice *dev)
944 struct sh_pfc_pinctrl_priv *priv = dev_get_priv(dev);
945 enum sh_pfc_model model = dev_get_driver_data(dev);
948 base = dev_read_addr(dev);
949 if (base == FDT_ADDR_T_NONE)
952 priv->pfc.regs = devm_ioremap(dev, base, SZ_2K);
956 #ifdef CONFIG_PINCTRL_PFC_R8A7790
957 if (model == SH_PFC_R8A7790)
958 priv->pfc.info = &r8a7790_pinmux_info;
960 #ifdef CONFIG_PINCTRL_PFC_R8A7791
961 if (model == SH_PFC_R8A7791)
962 priv->pfc.info = &r8a7791_pinmux_info;
964 #ifdef CONFIG_PINCTRL_PFC_R8A7792
965 if (model == SH_PFC_R8A7792)
966 priv->pfc.info = &r8a7792_pinmux_info;
968 #ifdef CONFIG_PINCTRL_PFC_R8A7793
969 if (model == SH_PFC_R8A7793)
970 priv->pfc.info = &r8a7793_pinmux_info;
972 #ifdef CONFIG_PINCTRL_PFC_R8A7794
973 if (model == SH_PFC_R8A7794)
974 priv->pfc.info = &r8a7794_pinmux_info;
976 #ifdef CONFIG_PINCTRL_PFC_R8A77951
977 if (model == SH_PFC_R8A7795)
978 priv->pfc.info = &r8a77951_pinmux_info;
980 #ifdef CONFIG_PINCTRL_PFC_R8A77960
981 if (model == SH_PFC_R8A77960)
982 priv->pfc.info = &r8a77960_pinmux_info;
984 #ifdef CONFIG_PINCTRL_PFC_R8A77961
985 if (model == SH_PFC_R8A77961)
986 priv->pfc.info = &r8a77961_pinmux_info;
988 #ifdef CONFIG_PINCTRL_PFC_R8A774A1
989 if (model == SH_PFC_R8A774A1)
990 priv->pfc.info = &r8a774a1_pinmux_info;
992 #ifdef CONFIG_PINCTRL_PFC_R8A774B1
993 if (model == SH_PFC_R8A774B1)
994 priv->pfc.info = &r8a774b1_pinmux_info;
996 #ifdef CONFIG_PINCTRL_PFC_R8A774C0
997 if (model == SH_PFC_R8A774C0)
998 priv->pfc.info = &r8a774c0_pinmux_info;
1000 #ifdef CONFIG_PINCTRL_PFC_R8A774E1
1001 if (model == SH_PFC_R8A774E1)
1002 priv->pfc.info = &r8a774e1_pinmux_info;
1004 #ifdef CONFIG_PINCTRL_PFC_R8A77965
1005 if (model == SH_PFC_R8A77965)
1006 priv->pfc.info = &r8a77965_pinmux_info;
1008 #ifdef CONFIG_PINCTRL_PFC_R8A77970
1009 if (model == SH_PFC_R8A77970)
1010 priv->pfc.info = &r8a77970_pinmux_info;
1012 #ifdef CONFIG_PINCTRL_PFC_R8A77980
1013 if (model == SH_PFC_R8A77980)
1014 priv->pfc.info = &r8a77980_pinmux_info;
1016 #ifdef CONFIG_PINCTRL_PFC_R8A77990
1017 if (model == SH_PFC_R8A77990)
1018 priv->pfc.info = &r8a77990_pinmux_info;
1020 #ifdef CONFIG_PINCTRL_PFC_R8A77995
1021 if (model == SH_PFC_R8A77995)
1022 priv->pfc.info = &r8a77995_pinmux_info;
1024 #ifdef CONFIG_PINCTRL_PFC_R8A779A0
1025 if (model == SH_PFC_R8A779A0)
1026 priv->pfc.info = &r8a779a0_pinmux_info;
1029 priv->pmx.pfc = &priv->pfc;
1030 sh_pfc_init_ranges(&priv->pfc);
1031 sh_pfc_map_pins(&priv->pfc, &priv->pmx);
1036 static const struct udevice_id sh_pfc_pinctrl_ids[] = {
1037 #ifdef CONFIG_PINCTRL_PFC_R8A7790
1039 .compatible = "renesas,pfc-r8a7790",
1040 .data = SH_PFC_R8A7790,
1043 #ifdef CONFIG_PINCTRL_PFC_R8A7791
1045 .compatible = "renesas,pfc-r8a7791",
1046 .data = SH_PFC_R8A7791,
1049 #ifdef CONFIG_PINCTRL_PFC_R8A7792
1051 .compatible = "renesas,pfc-r8a7792",
1052 .data = SH_PFC_R8A7792,
1055 #ifdef CONFIG_PINCTRL_PFC_R8A7793
1057 .compatible = "renesas,pfc-r8a7793",
1058 .data = SH_PFC_R8A7793,
1061 #ifdef CONFIG_PINCTRL_PFC_R8A7794
1063 .compatible = "renesas,pfc-r8a7794",
1064 .data = SH_PFC_R8A7794,
1067 #ifdef CONFIG_PINCTRL_PFC_R8A77951
1069 .compatible = "renesas,pfc-r8a7795",
1070 .data = SH_PFC_R8A7795,
1073 #ifdef CONFIG_PINCTRL_PFC_R8A77960
1075 .compatible = "renesas,pfc-r8a7796",
1076 .data = SH_PFC_R8A77960,
1079 #ifdef CONFIG_PINCTRL_PFC_R8A77961
1081 .compatible = "renesas,pfc-r8a77961",
1082 .data = SH_PFC_R8A77961,
1085 #ifdef CONFIG_PINCTRL_PFC_R8A774A1
1087 .compatible = "renesas,pfc-r8a774a1",
1088 .data = SH_PFC_R8A774A1,
1091 #ifdef CONFIG_PINCTRL_PFC_R8A774B1
1093 .compatible = "renesas,pfc-r8a774b1",
1094 .data = SH_PFC_R8A774B1,
1097 #ifdef CONFIG_PINCTRL_PFC_R8A774C0
1099 .compatible = "renesas,pfc-r8a774c0",
1100 .data = SH_PFC_R8A774C0,
1103 #ifdef CONFIG_PINCTRL_PFC_R8A774E1
1105 .compatible = "renesas,pfc-r8a774e1",
1106 .data = SH_PFC_R8A774E1,
1109 #ifdef CONFIG_PINCTRL_PFC_R8A77965
1111 .compatible = "renesas,pfc-r8a77965",
1112 .data = SH_PFC_R8A77965,
1115 #ifdef CONFIG_PINCTRL_PFC_R8A77970
1117 .compatible = "renesas,pfc-r8a77970",
1118 .data = SH_PFC_R8A77970,
1121 #ifdef CONFIG_PINCTRL_PFC_R8A77980
1123 .compatible = "renesas,pfc-r8a77980",
1124 .data = SH_PFC_R8A77980,
1127 #ifdef CONFIG_PINCTRL_PFC_R8A77990
1129 .compatible = "renesas,pfc-r8a77990",
1130 .data = SH_PFC_R8A77990,
1133 #ifdef CONFIG_PINCTRL_PFC_R8A77995
1135 .compatible = "renesas,pfc-r8a77995",
1136 .data = SH_PFC_R8A77995,
1139 #ifdef CONFIG_PINCTRL_PFC_R8A779A0
1141 .compatible = "renesas,pfc-r8a779a0",
1142 .data = SH_PFC_R8A779A0,
1149 U_BOOT_DRIVER(pinctrl_sh_pfc) = {
1150 .name = "sh_pfc_pinctrl",
1151 .id = UCLASS_PINCTRL,
1152 .of_match = sh_pfc_pinctrl_ids,
1153 .priv_auto = sizeof(struct sh_pfc_pinctrl_priv),
1154 .ops = &sh_pfc_pinctrl_ops,
1155 .probe = sh_pfc_pinctrl_probe,