1 // SPDX-License-Identifier: GPL-2.0
3 * SuperH Pin Function Controller pinmux support.
5 * Copyright (C) 2012 Paul Mundt
8 #define DRV_NAME "sh-pfc"
10 #include <linux/device.h>
11 #include <linux/err.h>
13 #include <linux/module.h>
15 #include <linux/pinctrl/consumer.h>
16 #include <linux/pinctrl/machine.h>
17 #include <linux/pinctrl/pinconf.h>
18 #include <linux/pinctrl/pinconf-generic.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/pinctrl/pinmux.h>
21 #include <linux/slab.h>
22 #include <linux/spinlock.h>
26 #include "../pinconf.h"
28 struct sh_pfc_pin_config {
33 struct sh_pfc_pinctrl {
34 struct pinctrl_dev *pctl;
35 struct pinctrl_desc pctl_desc;
39 struct pinctrl_pin_desc *pins;
40 struct sh_pfc_pin_config *configs;
42 const char *func_prop_name;
43 const char *groups_prop_name;
44 const char *pins_prop_name;
47 static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
49 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
51 return pmx->pfc->info->nr_groups;
54 static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev,
57 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
59 return pmx->pfc->info->groups[selector].name;
62 static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
63 const unsigned **pins, unsigned *num_pins)
65 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
67 *pins = pmx->pfc->info->groups[selector].pins;
68 *num_pins = pmx->pfc->info->groups[selector].nr_pins;
73 static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
76 seq_puts(s, DRV_NAME);
80 static int sh_pfc_map_add_config(struct pinctrl_map *map,
81 const char *group_or_pin,
82 enum pinctrl_map_type type,
83 unsigned long *configs,
84 unsigned int num_configs)
88 cfgs = kmemdup(configs, num_configs * sizeof(*cfgs),
94 map->data.configs.group_or_pin = group_or_pin;
95 map->data.configs.configs = cfgs;
96 map->data.configs.num_configs = num_configs;
101 static int sh_pfc_dt_subnode_to_map(struct pinctrl_dev *pctldev,
102 struct device_node *np,
103 struct pinctrl_map **map,
104 unsigned int *num_maps, unsigned int *index)
106 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
107 struct device *dev = pmx->pfc->dev;
108 struct pinctrl_map *maps = *map;
109 unsigned int nmaps = *num_maps;
110 unsigned int idx = *index;
111 unsigned int num_configs;
112 const char *function = NULL;
113 unsigned long *configs;
114 struct property *prop;
115 unsigned int num_groups;
116 unsigned int num_pins;
121 /* Support both the old Renesas-specific properties and the new standard
122 * properties. Mixing old and new properties isn't allowed, neither
123 * inside a subnode nor across subnodes.
125 if (!pmx->func_prop_name) {
126 if (of_find_property(np, "groups", NULL) ||
127 of_find_property(np, "pins", NULL)) {
128 pmx->func_prop_name = "function";
129 pmx->groups_prop_name = "groups";
130 pmx->pins_prop_name = "pins";
132 pmx->func_prop_name = "renesas,function";
133 pmx->groups_prop_name = "renesas,groups";
134 pmx->pins_prop_name = "renesas,pins";
138 /* Parse the function and configuration properties. At least a function
139 * or one configuration must be specified.
141 ret = of_property_read_string(np, pmx->func_prop_name, &function);
142 if (ret < 0 && ret != -EINVAL) {
143 dev_err(dev, "Invalid function in DT\n");
147 ret = pinconf_generic_parse_dt_config(np, NULL, &configs, &num_configs);
151 if (!function && num_configs == 0) {
153 "DT node must contain at least a function or config\n");
158 /* Count the number of pins and groups and reallocate mappings. */
159 ret = of_property_count_strings(np, pmx->pins_prop_name);
160 if (ret == -EINVAL) {
162 } else if (ret < 0) {
163 dev_err(dev, "Invalid pins list in DT\n");
169 ret = of_property_count_strings(np, pmx->groups_prop_name);
170 if (ret == -EINVAL) {
172 } else if (ret < 0) {
173 dev_err(dev, "Invalid pin groups list in DT\n");
179 if (!num_pins && !num_groups) {
180 dev_err(dev, "No pin or group provided in DT node\n");
188 nmaps += num_pins + num_groups;
190 maps = krealloc(maps, sizeof(*maps) * nmaps, GFP_KERNEL);
199 /* Iterate over pins and groups and create the mappings. */
200 of_property_for_each_string(np, pmx->groups_prop_name, prop, group) {
202 maps[idx].type = PIN_MAP_TYPE_MUX_GROUP;
203 maps[idx].data.mux.group = group;
204 maps[idx].data.mux.function = function;
209 ret = sh_pfc_map_add_config(&maps[idx], group,
210 PIN_MAP_TYPE_CONFIGS_GROUP,
211 configs, num_configs);
224 of_property_for_each_string(np, pmx->pins_prop_name, prop, pin) {
225 ret = sh_pfc_map_add_config(&maps[idx], pin,
226 PIN_MAP_TYPE_CONFIGS_PIN,
227 configs, num_configs);
240 static void sh_pfc_dt_free_map(struct pinctrl_dev *pctldev,
241 struct pinctrl_map *map, unsigned num_maps)
248 for (i = 0; i < num_maps; ++i) {
249 if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP ||
250 map[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
251 kfree(map[i].data.configs.configs);
257 static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev,
258 struct device_node *np,
259 struct pinctrl_map **map, unsigned *num_maps)
261 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
262 struct device *dev = pmx->pfc->dev;
263 struct device_node *child;
271 for_each_child_of_node(np, child) {
272 ret = sh_pfc_dt_subnode_to_map(pctldev, child, map, num_maps,
280 /* If no mapping has been found in child nodes try the config node. */
281 if (*num_maps == 0) {
282 ret = sh_pfc_dt_subnode_to_map(pctldev, np, map, num_maps,
291 dev_err(dev, "no mapping found in node %pOF\n", np);
296 sh_pfc_dt_free_map(pctldev, *map, *num_maps);
300 #endif /* CONFIG_OF */
302 static const struct pinctrl_ops sh_pfc_pinctrl_ops = {
303 .get_groups_count = sh_pfc_get_groups_count,
304 .get_group_name = sh_pfc_get_group_name,
305 .get_group_pins = sh_pfc_get_group_pins,
306 .pin_dbg_show = sh_pfc_pin_dbg_show,
308 .dt_node_to_map = sh_pfc_dt_node_to_map,
309 .dt_free_map = sh_pfc_dt_free_map,
313 static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
315 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
317 return pmx->pfc->info->nr_functions;
320 static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
323 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
325 return pmx->pfc->info->functions[selector].name;
328 static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev,
330 const char * const **groups,
331 unsigned * const num_groups)
333 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
335 *groups = pmx->pfc->info->functions[selector].groups;
336 *num_groups = pmx->pfc->info->functions[selector].nr_groups;
341 static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
344 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
345 struct sh_pfc *pfc = pmx->pfc;
346 const struct sh_pfc_pin_group *grp = &pfc->info->groups[group];
351 dev_dbg(pctldev->dev, "Configuring pin group %s\n", grp->name);
353 spin_lock_irqsave(&pfc->lock, flags);
355 for (i = 0; i < grp->nr_pins; ++i) {
356 int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
357 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
360 * This driver cannot manage both gpio and mux when the gpio
361 * pin is already enabled. So, this function fails.
363 if (cfg->gpio_enabled) {
368 ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
373 /* All group pins are configured, mark the pins as muxed */
374 for (i = 0; i < grp->nr_pins; ++i) {
375 int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
376 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
378 cfg->mux_mark = grp->mux[i];
382 spin_unlock_irqrestore(&pfc->lock, flags);
386 static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
387 struct pinctrl_gpio_range *range,
390 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
391 struct sh_pfc *pfc = pmx->pfc;
392 int idx = sh_pfc_get_pin_index(pfc, offset);
393 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
397 spin_lock_irqsave(&pfc->lock, flags);
399 if (!pfc->gpio && !cfg->mux_mark) {
400 /* If GPIOs are handled externally the pin mux type needs to be
403 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
405 ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
410 cfg->gpio_enabled = true;
415 spin_unlock_irqrestore(&pfc->lock, flags);
420 static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
421 struct pinctrl_gpio_range *range,
424 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
425 struct sh_pfc *pfc = pmx->pfc;
426 int idx = sh_pfc_get_pin_index(pfc, offset);
427 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
430 spin_lock_irqsave(&pfc->lock, flags);
431 cfg->gpio_enabled = false;
432 /* If mux is already set, this configures it here */
434 sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
435 spin_unlock_irqrestore(&pfc->lock, flags);
438 #ifdef CONFIG_PINCTRL_SH_PFC_GPIO
439 static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
440 struct pinctrl_gpio_range *range,
441 unsigned offset, bool input)
443 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
444 struct sh_pfc *pfc = pmx->pfc;
445 int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
446 int idx = sh_pfc_get_pin_index(pfc, offset);
447 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
452 /* Check if the requested direction is supported by the pin. Not all
453 * SoCs provide pin config data, so perform the check conditionally.
456 dir = input ? SH_PFC_PIN_CFG_INPUT : SH_PFC_PIN_CFG_OUTPUT;
457 if (!(pin->configs & dir))
461 spin_lock_irqsave(&pfc->lock, flags);
462 ret = sh_pfc_config_mux(pfc, pin->enum_id, new_type);
463 spin_unlock_irqrestore(&pfc->lock, flags);
467 #define sh_pfc_gpio_set_direction NULL
470 static const struct pinmux_ops sh_pfc_pinmux_ops = {
471 .get_functions_count = sh_pfc_get_functions_count,
472 .get_function_name = sh_pfc_get_function_name,
473 .get_function_groups = sh_pfc_get_function_groups,
474 .set_mux = sh_pfc_func_set_mux,
475 .gpio_request_enable = sh_pfc_gpio_request_enable,
476 .gpio_disable_free = sh_pfc_gpio_disable_free,
477 .gpio_set_direction = sh_pfc_gpio_set_direction,
480 static u32 sh_pfc_pinconf_find_drive_strength_reg(struct sh_pfc *pfc,
481 unsigned int pin, unsigned int *offset, unsigned int *size)
483 const struct pinmux_drive_reg_field *field;
484 const struct pinmux_drive_reg *reg;
487 for (reg = pfc->info->drive_regs; reg->reg; ++reg) {
488 for (i = 0; i < ARRAY_SIZE(reg->fields); ++i) {
489 field = ®->fields[i];
491 if (field->size && field->pin == pin) {
492 *offset = field->offset;
503 static int sh_pfc_pinconf_get_drive_strength(struct sh_pfc *pfc,
511 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
515 val = (sh_pfc_read(pfc, reg) >> offset) & GENMASK(size - 1, 0);
517 /* Convert the value to mA based on a full drive strength value of 24mA.
518 * We can make the full value configurable later if needed.
520 return (val + 1) * (size == 2 ? 6 : 3);
523 static int sh_pfc_pinconf_set_drive_strength(struct sh_pfc *pfc,
524 unsigned int pin, u16 strength)
533 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
537 step = size == 2 ? 6 : 3;
539 if (strength < step || strength > 24)
542 /* Convert the value from mA based on a full drive strength value of
543 * 24mA. We can make the full value configurable later if needed.
545 strength = strength / step - 1;
547 spin_lock_irqsave(&pfc->lock, flags);
549 val = sh_pfc_read(pfc, reg);
550 val &= ~GENMASK(offset + size - 1, offset);
551 val |= strength << offset;
553 sh_pfc_write(pfc, reg, val);
555 spin_unlock_irqrestore(&pfc->lock, flags);
560 /* Check whether the requested parameter is supported for a pin. */
561 static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
562 enum pin_config_param param)
564 int idx = sh_pfc_get_pin_index(pfc, _pin);
565 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
568 case PIN_CONFIG_BIAS_DISABLE:
569 return pin->configs & SH_PFC_PIN_CFG_PULL_UP_DOWN;
571 case PIN_CONFIG_BIAS_PULL_UP:
572 return pin->configs & SH_PFC_PIN_CFG_PULL_UP;
574 case PIN_CONFIG_BIAS_PULL_DOWN:
575 return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
577 case PIN_CONFIG_DRIVE_STRENGTH:
578 return pin->configs & SH_PFC_PIN_CFG_DRIVE_STRENGTH;
580 case PIN_CONFIG_POWER_SOURCE:
581 return pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE;
588 static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
589 unsigned long *config)
591 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
592 struct sh_pfc *pfc = pmx->pfc;
593 enum pin_config_param param = pinconf_to_config_param(*config);
597 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
601 case PIN_CONFIG_BIAS_DISABLE:
602 case PIN_CONFIG_BIAS_PULL_UP:
603 case PIN_CONFIG_BIAS_PULL_DOWN: {
606 if (!pfc->info->ops || !pfc->info->ops->get_bias)
609 spin_lock_irqsave(&pfc->lock, flags);
610 bias = pfc->info->ops->get_bias(pfc, _pin);
611 spin_unlock_irqrestore(&pfc->lock, flags);
620 case PIN_CONFIG_DRIVE_STRENGTH: {
623 ret = sh_pfc_pinconf_get_drive_strength(pfc, _pin);
631 case PIN_CONFIG_POWER_SOURCE: {
632 int idx = sh_pfc_get_pin_index(pfc, _pin);
633 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
634 unsigned int lower_voltage;
638 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
641 bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
642 if (WARN(bit < 0, "invalid pin %#x", _pin))
645 val = sh_pfc_read(pfc, pocctrl);
647 lower_voltage = (pin->configs & SH_PFC_PIN_VOLTAGE_25_33) ?
650 arg = (val & BIT(bit)) ? 3300 : lower_voltage;
658 *config = pinconf_to_config_packed(param, arg);
662 static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin,
663 unsigned long *configs, unsigned num_configs)
665 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
666 struct sh_pfc *pfc = pmx->pfc;
667 enum pin_config_param param;
671 for (i = 0; i < num_configs; i++) {
672 param = pinconf_to_config_param(configs[i]);
674 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
678 case PIN_CONFIG_BIAS_PULL_UP:
679 case PIN_CONFIG_BIAS_PULL_DOWN:
680 case PIN_CONFIG_BIAS_DISABLE:
681 if (!pfc->info->ops || !pfc->info->ops->set_bias)
684 spin_lock_irqsave(&pfc->lock, flags);
685 pfc->info->ops->set_bias(pfc, _pin, param);
686 spin_unlock_irqrestore(&pfc->lock, flags);
690 case PIN_CONFIG_DRIVE_STRENGTH: {
692 pinconf_to_config_argument(configs[i]);
695 ret = sh_pfc_pinconf_set_drive_strength(pfc, _pin, arg);
702 case PIN_CONFIG_POWER_SOURCE: {
703 unsigned int mV = pinconf_to_config_argument(configs[i]);
704 int idx = sh_pfc_get_pin_index(pfc, _pin);
705 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
706 unsigned int lower_voltage;
710 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
713 bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
714 if (WARN(bit < 0, "invalid pin %#x", _pin))
717 lower_voltage = (pin->configs & SH_PFC_PIN_VOLTAGE_25_33) ?
720 if (mV != lower_voltage && mV != 3300)
723 spin_lock_irqsave(&pfc->lock, flags);
724 val = sh_pfc_read(pfc, pocctrl);
729 sh_pfc_write(pfc, pocctrl, val);
730 spin_unlock_irqrestore(&pfc->lock, flags);
738 } /* for each config */
743 static int sh_pfc_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
744 unsigned long *configs,
745 unsigned num_configs)
747 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
748 const unsigned int *pins;
749 unsigned int num_pins;
752 pins = pmx->pfc->info->groups[group].pins;
753 num_pins = pmx->pfc->info->groups[group].nr_pins;
755 for (i = 0; i < num_pins; ++i) {
756 ret = sh_pfc_pinconf_set(pctldev, pins[i], configs, num_configs);
764 static const struct pinconf_ops sh_pfc_pinconf_ops = {
766 .pin_config_get = sh_pfc_pinconf_get,
767 .pin_config_set = sh_pfc_pinconf_set,
768 .pin_config_group_set = sh_pfc_pinconf_group_set,
769 .pin_config_config_dbg_show = pinconf_generic_dump_config,
772 /* PFC ranges -> pinctrl pin descs */
773 static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
777 /* Allocate and initialize the pins and configs arrays. */
778 pmx->pins = devm_kcalloc(pfc->dev,
779 pfc->info->nr_pins, sizeof(*pmx->pins),
781 if (unlikely(!pmx->pins))
784 pmx->configs = devm_kcalloc(pfc->dev,
785 pfc->info->nr_pins, sizeof(*pmx->configs),
787 if (unlikely(!pmx->configs))
790 for (i = 0; i < pfc->info->nr_pins; ++i) {
791 const struct sh_pfc_pin *info = &pfc->info->pins[i];
792 struct pinctrl_pin_desc *pin = &pmx->pins[i];
794 /* If the pin number is equal to -1 all pins are considered */
795 pin->number = info->pin != (u16)-1 ? info->pin : i;
796 pin->name = info->name;
802 int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
804 struct sh_pfc_pinctrl *pmx;
807 pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
813 ret = sh_pfc_map_pins(pfc, pmx);
817 pmx->pctl_desc.name = DRV_NAME;
818 pmx->pctl_desc.owner = THIS_MODULE;
819 pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops;
820 pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops;
821 pmx->pctl_desc.confops = &sh_pfc_pinconf_ops;
822 pmx->pctl_desc.pins = pmx->pins;
823 pmx->pctl_desc.npins = pfc->info->nr_pins;
825 ret = devm_pinctrl_register_and_init(pfc->dev, &pmx->pctl_desc, pmx,
828 dev_err(pfc->dev, "could not register: %i\n", ret);
833 return pinctrl_enable(pmx->pctl);
836 const struct pinmux_bias_reg *
837 rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
842 for (i = 0; info->bias_regs[i].puen || info->bias_regs[i].pud; i++) {
843 for (j = 0; j < ARRAY_SIZE(info->bias_regs[i].pins); j++) {
844 if (info->bias_regs[i].pins[j] == pin) {
846 return &info->bias_regs[i];
851 WARN_ONCE(1, "Pin %u is not in bias info list\n", pin);
856 unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
858 const struct pinmux_bias_reg *reg;
861 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
863 return PIN_CONFIG_BIAS_DISABLE;
866 if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
867 return PIN_CONFIG_BIAS_DISABLE;
868 else if (!reg->pud || (sh_pfc_read(pfc, reg->pud) & BIT(bit)))
869 return PIN_CONFIG_BIAS_PULL_UP;
871 return PIN_CONFIG_BIAS_PULL_DOWN;
873 if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
874 return PIN_CONFIG_BIAS_PULL_DOWN;
876 return PIN_CONFIG_BIAS_DISABLE;
880 void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
883 const struct pinmux_bias_reg *reg;
887 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
892 enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
893 if (bias != PIN_CONFIG_BIAS_DISABLE) {
897 updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
898 if (bias == PIN_CONFIG_BIAS_PULL_UP)
901 sh_pfc_write(pfc, reg->pud, updown);
904 sh_pfc_write(pfc, reg->puen, enable);
906 enable = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
907 if (bias == PIN_CONFIG_BIAS_PULL_DOWN)
910 sh_pfc_write(pfc, reg->pud, enable);
914 #define PORTnCR_PULMD_OFF (0 << 6)
915 #define PORTnCR_PULMD_DOWN (2 << 6)
916 #define PORTnCR_PULMD_UP (3 << 6)
917 #define PORTnCR_PULMD_MASK (3 << 6)
919 unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
921 void __iomem *reg = pfc->windows->virt +
922 pfc->info->ops->pin_to_portcr(pin);
923 u32 value = ioread8(reg) & PORTnCR_PULMD_MASK;
926 case PORTnCR_PULMD_UP:
927 return PIN_CONFIG_BIAS_PULL_UP;
928 case PORTnCR_PULMD_DOWN:
929 return PIN_CONFIG_BIAS_PULL_DOWN;
930 case PORTnCR_PULMD_OFF:
932 return PIN_CONFIG_BIAS_DISABLE;
936 void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
939 void __iomem *reg = pfc->windows->virt +
940 pfc->info->ops->pin_to_portcr(pin);
941 u32 value = ioread8(reg) & ~PORTnCR_PULMD_MASK;
944 case PIN_CONFIG_BIAS_PULL_UP:
945 value |= PORTnCR_PULMD_UP;
947 case PIN_CONFIG_BIAS_PULL_DOWN:
948 value |= PORTnCR_PULMD_DOWN;
952 iowrite8(value, reg);