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/seq_file.h>
16 #include <linux/slab.h>
17 #include <linux/spinlock.h>
19 #include <linux/pinctrl/consumer.h>
20 #include <linux/pinctrl/machine.h>
21 #include <linux/pinctrl/pinconf-generic.h>
22 #include <linux/pinctrl/pinconf.h>
23 #include <linux/pinctrl/pinctrl.h>
24 #include <linux/pinctrl/pinmux.h>
28 #include "../pinconf.h"
30 struct sh_pfc_pin_config {
35 struct sh_pfc_pinctrl {
36 struct pinctrl_dev *pctl;
37 struct pinctrl_desc pctl_desc;
41 struct pinctrl_pin_desc *pins;
42 struct sh_pfc_pin_config *configs;
45 static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
47 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
49 return pmx->pfc->info->nr_groups;
52 static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev,
55 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
57 return pmx->pfc->info->groups[selector].name;
60 static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
61 const unsigned **pins, unsigned *num_pins)
63 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
65 *pins = pmx->pfc->info->groups[selector].pins;
66 *num_pins = pmx->pfc->info->groups[selector].nr_pins;
71 static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
74 seq_puts(s, DRV_NAME);
78 static int sh_pfc_map_add_config(struct pinctrl_map *map,
79 const char *group_or_pin,
80 enum pinctrl_map_type type,
81 unsigned long *configs,
82 unsigned int num_configs)
86 cfgs = kmemdup(configs, num_configs * sizeof(*cfgs),
92 map->data.configs.group_or_pin = group_or_pin;
93 map->data.configs.configs = cfgs;
94 map->data.configs.num_configs = num_configs;
99 static int sh_pfc_dt_subnode_to_map(struct pinctrl_dev *pctldev,
100 struct device_node *np,
101 struct pinctrl_map **map,
102 unsigned int *num_maps, unsigned int *index)
104 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
105 struct device *dev = pmx->pfc->dev;
106 struct pinctrl_map *maps = *map;
107 unsigned int nmaps = *num_maps;
108 unsigned int idx = *index;
109 unsigned int num_configs;
110 const char *function = NULL;
111 unsigned long *configs;
112 struct property *prop;
113 unsigned int num_groups;
114 unsigned int num_pins;
119 /* Parse the function and configuration properties. At least a function
120 * or one configuration must be specified.
122 ret = of_property_read_string(np, "function", &function);
123 if (ret < 0 && ret != -EINVAL) {
124 dev_err(dev, "Invalid function in DT\n");
128 ret = pinconf_generic_parse_dt_config(np, NULL, &configs, &num_configs);
132 if (!function && num_configs == 0) {
134 "DT node must contain at least a function or config\n");
139 /* Count the number of pins and groups and reallocate mappings. */
140 ret = of_property_count_strings(np, "pins");
141 if (ret == -EINVAL) {
143 } else if (ret < 0) {
144 dev_err(dev, "Invalid pins list in DT\n");
150 ret = of_property_count_strings(np, "groups");
151 if (ret == -EINVAL) {
153 } else if (ret < 0) {
154 dev_err(dev, "Invalid pin groups list in DT\n");
160 if (!num_pins && !num_groups) {
161 dev_err(dev, "No pin or group provided in DT node\n");
169 nmaps += num_pins + num_groups;
171 maps = krealloc(maps, sizeof(*maps) * nmaps, GFP_KERNEL);
180 /* Iterate over pins and groups and create the mappings. */
181 of_property_for_each_string(np, "groups", prop, group) {
183 maps[idx].type = PIN_MAP_TYPE_MUX_GROUP;
184 maps[idx].data.mux.group = group;
185 maps[idx].data.mux.function = function;
190 ret = sh_pfc_map_add_config(&maps[idx], group,
191 PIN_MAP_TYPE_CONFIGS_GROUP,
192 configs, num_configs);
205 of_property_for_each_string(np, "pins", prop, pin) {
206 ret = sh_pfc_map_add_config(&maps[idx], pin,
207 PIN_MAP_TYPE_CONFIGS_PIN,
208 configs, num_configs);
221 static void sh_pfc_dt_free_map(struct pinctrl_dev *pctldev,
222 struct pinctrl_map *map, unsigned num_maps)
229 for (i = 0; i < num_maps; ++i) {
230 if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP ||
231 map[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
232 kfree(map[i].data.configs.configs);
238 static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev,
239 struct device_node *np,
240 struct pinctrl_map **map, unsigned *num_maps)
242 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
243 struct device *dev = pmx->pfc->dev;
251 for_each_child_of_node_scoped(np, child) {
252 ret = sh_pfc_dt_subnode_to_map(pctldev, child, map, num_maps,
258 /* If no mapping has been found in child nodes try the config node. */
259 if (*num_maps == 0) {
260 ret = sh_pfc_dt_subnode_to_map(pctldev, np, map, num_maps,
269 dev_err(dev, "no mapping found in node %pOF\n", np);
274 sh_pfc_dt_free_map(pctldev, *map, *num_maps);
278 #endif /* CONFIG_OF */
280 static const struct pinctrl_ops sh_pfc_pinctrl_ops = {
281 .get_groups_count = sh_pfc_get_groups_count,
282 .get_group_name = sh_pfc_get_group_name,
283 .get_group_pins = sh_pfc_get_group_pins,
284 .pin_dbg_show = sh_pfc_pin_dbg_show,
286 .dt_node_to_map = sh_pfc_dt_node_to_map,
287 .dt_free_map = sh_pfc_dt_free_map,
291 static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
293 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
295 return pmx->pfc->info->nr_functions;
298 static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
301 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
303 return pmx->pfc->info->functions[selector].name;
306 static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev,
308 const char * const **groups,
309 unsigned * const num_groups)
311 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
313 *groups = pmx->pfc->info->functions[selector].groups;
314 *num_groups = pmx->pfc->info->functions[selector].nr_groups;
319 static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
322 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
323 struct sh_pfc *pfc = pmx->pfc;
324 const struct sh_pfc_pin_group *grp = &pfc->info->groups[group];
329 dev_dbg(pctldev->dev, "Configuring pin group %s\n", grp->name);
331 spin_lock_irqsave(&pfc->lock, flags);
333 for (i = 0; i < grp->nr_pins; ++i) {
334 int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
335 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
338 * This driver cannot manage both gpio and mux when the gpio
339 * pin is already enabled. So, this function fails.
341 if (cfg->gpio_enabled) {
346 ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
351 /* All group pins are configured, mark the pins as muxed */
352 for (i = 0; i < grp->nr_pins; ++i) {
353 int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
354 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
356 cfg->mux_mark = grp->mux[i];
360 spin_unlock_irqrestore(&pfc->lock, flags);
364 static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
365 struct pinctrl_gpio_range *range,
368 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
369 struct sh_pfc *pfc = pmx->pfc;
370 int idx = sh_pfc_get_pin_index(pfc, offset);
371 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
375 spin_lock_irqsave(&pfc->lock, flags);
377 if (!pfc->gpio && !cfg->mux_mark) {
378 /* If GPIOs are handled externally the pin mux type needs to be
381 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
383 ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
388 cfg->gpio_enabled = true;
393 spin_unlock_irqrestore(&pfc->lock, flags);
398 static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
399 struct pinctrl_gpio_range *range,
402 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
403 struct sh_pfc *pfc = pmx->pfc;
404 int idx = sh_pfc_get_pin_index(pfc, offset);
405 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
408 spin_lock_irqsave(&pfc->lock, flags);
409 cfg->gpio_enabled = false;
410 /* If mux is already set, this configures it here */
412 sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
413 spin_unlock_irqrestore(&pfc->lock, flags);
416 #ifdef CONFIG_PINCTRL_SH_PFC_GPIO
417 static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
418 struct pinctrl_gpio_range *range,
419 unsigned offset, bool input)
421 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
422 struct sh_pfc *pfc = pmx->pfc;
423 int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
424 int idx = sh_pfc_get_pin_index(pfc, offset);
425 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
430 /* Check if the requested direction is supported by the pin. Not all
431 * SoCs provide pin config data, so perform the check conditionally.
434 dir = input ? SH_PFC_PIN_CFG_INPUT : SH_PFC_PIN_CFG_OUTPUT;
435 if (!(pin->configs & dir))
439 spin_lock_irqsave(&pfc->lock, flags);
440 ret = sh_pfc_config_mux(pfc, pin->enum_id, new_type);
441 spin_unlock_irqrestore(&pfc->lock, flags);
445 #define sh_pfc_gpio_set_direction NULL
448 static const struct pinmux_ops sh_pfc_pinmux_ops = {
449 .get_functions_count = sh_pfc_get_functions_count,
450 .get_function_name = sh_pfc_get_function_name,
451 .get_function_groups = sh_pfc_get_function_groups,
452 .set_mux = sh_pfc_func_set_mux,
453 .gpio_request_enable = sh_pfc_gpio_request_enable,
454 .gpio_disable_free = sh_pfc_gpio_disable_free,
455 .gpio_set_direction = sh_pfc_gpio_set_direction,
458 static u32 sh_pfc_pinconf_find_drive_strength_reg(struct sh_pfc *pfc,
459 unsigned int pin, unsigned int *offset, unsigned int *size)
461 const struct pinmux_drive_reg_field *field;
462 const struct pinmux_drive_reg *reg;
465 for (reg = pfc->info->drive_regs; reg->reg; ++reg) {
466 for (i = 0; i < ARRAY_SIZE(reg->fields); ++i) {
467 field = ®->fields[i];
469 if (field->size && field->pin == pin) {
470 *offset = field->offset;
481 static int sh_pfc_pinconf_get_drive_strength(struct sh_pfc *pfc,
489 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
493 val = (sh_pfc_read(pfc, reg) >> offset) & GENMASK(size - 1, 0);
495 /* Convert the value to mA based on a full drive strength value of 24mA.
496 * We can make the full value configurable later if needed.
498 return (val + 1) * (size == 2 ? 6 : 3);
501 static int sh_pfc_pinconf_set_drive_strength(struct sh_pfc *pfc,
502 unsigned int pin, u16 strength)
511 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
515 step = size == 2 ? 6 : 3;
517 if (strength < step || strength > 24)
520 /* Convert the value from mA based on a full drive strength value of
521 * 24mA. We can make the full value configurable later if needed.
523 strength = strength / step - 1;
525 spin_lock_irqsave(&pfc->lock, flags);
527 val = sh_pfc_read(pfc, reg);
528 val &= ~GENMASK(offset + size - 1, offset);
529 val |= strength << offset;
531 sh_pfc_write(pfc, reg, val);
533 spin_unlock_irqrestore(&pfc->lock, flags);
538 /* Check whether the requested parameter is supported for a pin. */
539 static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
540 enum pin_config_param param)
542 int idx = sh_pfc_get_pin_index(pfc, _pin);
543 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
546 case PIN_CONFIG_BIAS_DISABLE:
547 return pin->configs & SH_PFC_PIN_CFG_PULL_UP_DOWN;
549 case PIN_CONFIG_BIAS_PULL_UP:
550 return pin->configs & SH_PFC_PIN_CFG_PULL_UP;
552 case PIN_CONFIG_BIAS_PULL_DOWN:
553 return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
555 case PIN_CONFIG_DRIVE_STRENGTH:
556 return pin->configs & SH_PFC_PIN_CFG_DRIVE_STRENGTH;
558 case PIN_CONFIG_POWER_SOURCE:
559 return pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
566 static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
567 unsigned long *config)
569 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
570 struct sh_pfc *pfc = pmx->pfc;
571 enum pin_config_param param = pinconf_to_config_param(*config);
575 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
579 case PIN_CONFIG_BIAS_DISABLE:
580 case PIN_CONFIG_BIAS_PULL_UP:
581 case PIN_CONFIG_BIAS_PULL_DOWN: {
584 if (!pfc->info->ops || !pfc->info->ops->get_bias)
587 spin_lock_irqsave(&pfc->lock, flags);
588 bias = pfc->info->ops->get_bias(pfc, _pin);
589 spin_unlock_irqrestore(&pfc->lock, flags);
598 case PIN_CONFIG_DRIVE_STRENGTH: {
601 ret = sh_pfc_pinconf_get_drive_strength(pfc, _pin);
609 case PIN_CONFIG_POWER_SOURCE: {
610 int idx = sh_pfc_get_pin_index(pfc, _pin);
611 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
612 unsigned int mode, lo, hi;
616 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
619 bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
620 if (WARN(bit < 0, "invalid pin %#x", _pin))
623 val = sh_pfc_read(pfc, pocctrl);
625 mode = pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
626 lo = mode <= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 1800 : 2500;
627 hi = mode >= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 3300 : 2500;
629 arg = (val & BIT(bit)) ? hi : lo;
637 *config = pinconf_to_config_packed(param, arg);
641 static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin,
642 unsigned long *configs, unsigned num_configs)
644 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
645 struct sh_pfc *pfc = pmx->pfc;
646 enum pin_config_param param;
650 for (i = 0; i < num_configs; i++) {
651 param = pinconf_to_config_param(configs[i]);
653 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
657 case PIN_CONFIG_BIAS_PULL_UP:
658 case PIN_CONFIG_BIAS_PULL_DOWN:
659 case PIN_CONFIG_BIAS_DISABLE:
660 if (!pfc->info->ops || !pfc->info->ops->set_bias)
663 spin_lock_irqsave(&pfc->lock, flags);
664 pfc->info->ops->set_bias(pfc, _pin, param);
665 spin_unlock_irqrestore(&pfc->lock, flags);
669 case PIN_CONFIG_DRIVE_STRENGTH: {
671 pinconf_to_config_argument(configs[i]);
674 ret = sh_pfc_pinconf_set_drive_strength(pfc, _pin, arg);
681 case PIN_CONFIG_POWER_SOURCE: {
682 unsigned int mV = pinconf_to_config_argument(configs[i]);
683 int idx = sh_pfc_get_pin_index(pfc, _pin);
684 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
685 unsigned int mode, lo, hi;
689 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
692 bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
693 if (WARN(bit < 0, "invalid pin %#x", _pin))
696 mode = pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
697 lo = mode <= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 1800 : 2500;
698 hi = mode >= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 3300 : 2500;
700 if (mV != lo && mV != hi)
703 spin_lock_irqsave(&pfc->lock, flags);
704 val = sh_pfc_read(pfc, pocctrl);
709 sh_pfc_write(pfc, pocctrl, val);
710 spin_unlock_irqrestore(&pfc->lock, flags);
718 } /* for each config */
723 static int sh_pfc_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
724 unsigned long *configs,
725 unsigned num_configs)
727 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
728 const unsigned int *pins;
729 unsigned int num_pins;
732 pins = pmx->pfc->info->groups[group].pins;
733 num_pins = pmx->pfc->info->groups[group].nr_pins;
735 for (i = 0; i < num_pins; ++i) {
736 ret = sh_pfc_pinconf_set(pctldev, pins[i], configs, num_configs);
744 static const struct pinconf_ops sh_pfc_pinconf_ops = {
746 .pin_config_get = sh_pfc_pinconf_get,
747 .pin_config_set = sh_pfc_pinconf_set,
748 .pin_config_group_set = sh_pfc_pinconf_group_set,
749 .pin_config_config_dbg_show = pinconf_generic_dump_config,
752 /* PFC ranges -> pinctrl pin descs */
753 static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
757 /* Allocate and initialize the pins and configs arrays. */
758 pmx->pins = devm_kcalloc(pfc->dev,
759 pfc->info->nr_pins, sizeof(*pmx->pins),
761 if (unlikely(!pmx->pins))
764 pmx->configs = devm_kcalloc(pfc->dev,
765 pfc->info->nr_pins, sizeof(*pmx->configs),
767 if (unlikely(!pmx->configs))
770 for (i = 0; i < pfc->info->nr_pins; ++i) {
771 const struct sh_pfc_pin *info = &pfc->info->pins[i];
772 struct pinctrl_pin_desc *pin = &pmx->pins[i];
774 /* If the pin number is equal to -1 all pins are considered */
775 pin->number = info->pin != (u16)-1 ? info->pin : i;
776 pin->name = info->name;
782 int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
784 struct sh_pfc_pinctrl *pmx;
787 pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
793 ret = sh_pfc_map_pins(pfc, pmx);
797 pmx->pctl_desc.name = DRV_NAME;
798 pmx->pctl_desc.owner = THIS_MODULE;
799 pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops;
800 pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops;
801 pmx->pctl_desc.confops = &sh_pfc_pinconf_ops;
802 pmx->pctl_desc.pins = pmx->pins;
803 pmx->pctl_desc.npins = pfc->info->nr_pins;
805 ret = devm_pinctrl_register_and_init(pfc->dev, &pmx->pctl_desc, pmx,
808 dev_err(pfc->dev, "could not register: %i\n", ret);
813 return pinctrl_enable(pmx->pctl);
816 const struct pinmux_bias_reg *
817 rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
822 for (i = 0; info->bias_regs[i].puen || info->bias_regs[i].pud; i++) {
823 for (j = 0; j < ARRAY_SIZE(info->bias_regs[i].pins); j++) {
824 if (info->bias_regs[i].pins[j] == pin) {
826 return &info->bias_regs[i];
831 WARN_ONCE(1, "Pin %u is not in bias info list\n", pin);
836 unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
838 const struct pinmux_bias_reg *reg;
841 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
843 return PIN_CONFIG_BIAS_DISABLE;
846 if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
847 return PIN_CONFIG_BIAS_DISABLE;
848 else if (!reg->pud || (sh_pfc_read(pfc, reg->pud) & BIT(bit)))
849 return PIN_CONFIG_BIAS_PULL_UP;
851 return PIN_CONFIG_BIAS_PULL_DOWN;
853 if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
854 return PIN_CONFIG_BIAS_PULL_DOWN;
856 return PIN_CONFIG_BIAS_DISABLE;
860 void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
863 const struct pinmux_bias_reg *reg;
867 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
872 enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
873 if (bias != PIN_CONFIG_BIAS_DISABLE) {
877 updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
878 if (bias == PIN_CONFIG_BIAS_PULL_UP)
881 sh_pfc_write(pfc, reg->pud, updown);
884 sh_pfc_write(pfc, reg->puen, enable);
886 enable = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
887 if (bias == PIN_CONFIG_BIAS_PULL_DOWN)
890 sh_pfc_write(pfc, reg->pud, enable);
894 #define PORTnCR_PULMD_OFF (0 << 6)
895 #define PORTnCR_PULMD_DOWN (2 << 6)
896 #define PORTnCR_PULMD_UP (3 << 6)
897 #define PORTnCR_PULMD_MASK (3 << 6)
899 unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
901 void __iomem *reg = pfc->windows->virt +
902 pfc->info->ops->pin_to_portcr(pin);
903 u32 value = ioread8(reg) & PORTnCR_PULMD_MASK;
906 case PORTnCR_PULMD_UP:
907 return PIN_CONFIG_BIAS_PULL_UP;
908 case PORTnCR_PULMD_DOWN:
909 return PIN_CONFIG_BIAS_PULL_DOWN;
910 case PORTnCR_PULMD_OFF:
912 return PIN_CONFIG_BIAS_DISABLE;
916 void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
919 void __iomem *reg = pfc->windows->virt +
920 pfc->info->ops->pin_to_portcr(pin);
921 u32 value = ioread8(reg) & ~PORTnCR_PULMD_MASK;
924 case PIN_CONFIG_BIAS_PULL_UP:
925 value |= PORTnCR_PULMD_UP;
927 case PIN_CONFIG_BIAS_PULL_DOWN:
928 value |= PORTnCR_PULMD_DOWN;
932 iowrite8(value, reg);