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;
244 struct device_node *child;
252 for_each_child_of_node(np, child) {
253 ret = sh_pfc_dt_subnode_to_map(pctldev, child, map, num_maps,
261 /* If no mapping has been found in child nodes try the config node. */
262 if (*num_maps == 0) {
263 ret = sh_pfc_dt_subnode_to_map(pctldev, np, map, num_maps,
272 dev_err(dev, "no mapping found in node %pOF\n", np);
277 sh_pfc_dt_free_map(pctldev, *map, *num_maps);
281 #endif /* CONFIG_OF */
283 static const struct pinctrl_ops sh_pfc_pinctrl_ops = {
284 .get_groups_count = sh_pfc_get_groups_count,
285 .get_group_name = sh_pfc_get_group_name,
286 .get_group_pins = sh_pfc_get_group_pins,
287 .pin_dbg_show = sh_pfc_pin_dbg_show,
289 .dt_node_to_map = sh_pfc_dt_node_to_map,
290 .dt_free_map = sh_pfc_dt_free_map,
294 static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
296 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
298 return pmx->pfc->info->nr_functions;
301 static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
304 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
306 return pmx->pfc->info->functions[selector].name;
309 static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev,
311 const char * const **groups,
312 unsigned * const num_groups)
314 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
316 *groups = pmx->pfc->info->functions[selector].groups;
317 *num_groups = pmx->pfc->info->functions[selector].nr_groups;
322 static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
325 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
326 struct sh_pfc *pfc = pmx->pfc;
327 const struct sh_pfc_pin_group *grp = &pfc->info->groups[group];
332 dev_dbg(pctldev->dev, "Configuring pin group %s\n", grp->name);
334 spin_lock_irqsave(&pfc->lock, flags);
336 for (i = 0; i < grp->nr_pins; ++i) {
337 int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
338 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
341 * This driver cannot manage both gpio and mux when the gpio
342 * pin is already enabled. So, this function fails.
344 if (cfg->gpio_enabled) {
349 ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
354 /* All group pins are configured, mark the pins as muxed */
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];
359 cfg->mux_mark = grp->mux[i];
363 spin_unlock_irqrestore(&pfc->lock, flags);
367 static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
368 struct pinctrl_gpio_range *range,
371 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
372 struct sh_pfc *pfc = pmx->pfc;
373 int idx = sh_pfc_get_pin_index(pfc, offset);
374 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
378 spin_lock_irqsave(&pfc->lock, flags);
380 if (!pfc->gpio && !cfg->mux_mark) {
381 /* If GPIOs are handled externally the pin mux type needs to be
384 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
386 ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
391 cfg->gpio_enabled = true;
396 spin_unlock_irqrestore(&pfc->lock, flags);
401 static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
402 struct pinctrl_gpio_range *range,
405 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
406 struct sh_pfc *pfc = pmx->pfc;
407 int idx = sh_pfc_get_pin_index(pfc, offset);
408 struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
411 spin_lock_irqsave(&pfc->lock, flags);
412 cfg->gpio_enabled = false;
413 /* If mux is already set, this configures it here */
415 sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
416 spin_unlock_irqrestore(&pfc->lock, flags);
419 #ifdef CONFIG_PINCTRL_SH_PFC_GPIO
420 static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
421 struct pinctrl_gpio_range *range,
422 unsigned offset, bool input)
424 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
425 struct sh_pfc *pfc = pmx->pfc;
426 int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
427 int idx = sh_pfc_get_pin_index(pfc, offset);
428 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
433 /* Check if the requested direction is supported by the pin. Not all
434 * SoCs provide pin config data, so perform the check conditionally.
437 dir = input ? SH_PFC_PIN_CFG_INPUT : SH_PFC_PIN_CFG_OUTPUT;
438 if (!(pin->configs & dir))
442 spin_lock_irqsave(&pfc->lock, flags);
443 ret = sh_pfc_config_mux(pfc, pin->enum_id, new_type);
444 spin_unlock_irqrestore(&pfc->lock, flags);
448 #define sh_pfc_gpio_set_direction NULL
451 static const struct pinmux_ops sh_pfc_pinmux_ops = {
452 .get_functions_count = sh_pfc_get_functions_count,
453 .get_function_name = sh_pfc_get_function_name,
454 .get_function_groups = sh_pfc_get_function_groups,
455 .set_mux = sh_pfc_func_set_mux,
456 .gpio_request_enable = sh_pfc_gpio_request_enable,
457 .gpio_disable_free = sh_pfc_gpio_disable_free,
458 .gpio_set_direction = sh_pfc_gpio_set_direction,
461 static u32 sh_pfc_pinconf_find_drive_strength_reg(struct sh_pfc *pfc,
462 unsigned int pin, unsigned int *offset, unsigned int *size)
464 const struct pinmux_drive_reg_field *field;
465 const struct pinmux_drive_reg *reg;
468 for (reg = pfc->info->drive_regs; reg->reg; ++reg) {
469 for (i = 0; i < ARRAY_SIZE(reg->fields); ++i) {
470 field = ®->fields[i];
472 if (field->size && field->pin == pin) {
473 *offset = field->offset;
484 static int sh_pfc_pinconf_get_drive_strength(struct sh_pfc *pfc,
492 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
496 val = (sh_pfc_read(pfc, reg) >> offset) & GENMASK(size - 1, 0);
498 /* Convert the value to mA based on a full drive strength value of 24mA.
499 * We can make the full value configurable later if needed.
501 return (val + 1) * (size == 2 ? 6 : 3);
504 static int sh_pfc_pinconf_set_drive_strength(struct sh_pfc *pfc,
505 unsigned int pin, u16 strength)
514 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
518 step = size == 2 ? 6 : 3;
520 if (strength < step || strength > 24)
523 /* Convert the value from mA based on a full drive strength value of
524 * 24mA. We can make the full value configurable later if needed.
526 strength = strength / step - 1;
528 spin_lock_irqsave(&pfc->lock, flags);
530 val = sh_pfc_read(pfc, reg);
531 val &= ~GENMASK(offset + size - 1, offset);
532 val |= strength << offset;
534 sh_pfc_write(pfc, reg, val);
536 spin_unlock_irqrestore(&pfc->lock, flags);
541 /* Check whether the requested parameter is supported for a pin. */
542 static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
543 enum pin_config_param param)
545 int idx = sh_pfc_get_pin_index(pfc, _pin);
546 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
549 case PIN_CONFIG_BIAS_DISABLE:
550 return pin->configs & SH_PFC_PIN_CFG_PULL_UP_DOWN;
552 case PIN_CONFIG_BIAS_PULL_UP:
553 return pin->configs & SH_PFC_PIN_CFG_PULL_UP;
555 case PIN_CONFIG_BIAS_PULL_DOWN:
556 return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
558 case PIN_CONFIG_DRIVE_STRENGTH:
559 return pin->configs & SH_PFC_PIN_CFG_DRIVE_STRENGTH;
561 case PIN_CONFIG_POWER_SOURCE:
562 return pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
569 static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
570 unsigned long *config)
572 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
573 struct sh_pfc *pfc = pmx->pfc;
574 enum pin_config_param param = pinconf_to_config_param(*config);
578 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
582 case PIN_CONFIG_BIAS_DISABLE:
583 case PIN_CONFIG_BIAS_PULL_UP:
584 case PIN_CONFIG_BIAS_PULL_DOWN: {
587 if (!pfc->info->ops || !pfc->info->ops->get_bias)
590 spin_lock_irqsave(&pfc->lock, flags);
591 bias = pfc->info->ops->get_bias(pfc, _pin);
592 spin_unlock_irqrestore(&pfc->lock, flags);
601 case PIN_CONFIG_DRIVE_STRENGTH: {
604 ret = sh_pfc_pinconf_get_drive_strength(pfc, _pin);
612 case PIN_CONFIG_POWER_SOURCE: {
613 int idx = sh_pfc_get_pin_index(pfc, _pin);
614 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
615 unsigned int mode, lo, hi;
619 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
622 bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
623 if (WARN(bit < 0, "invalid pin %#x", _pin))
626 val = sh_pfc_read(pfc, pocctrl);
628 mode = pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
629 lo = mode <= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 1800 : 2500;
630 hi = mode >= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 3300 : 2500;
632 arg = (val & BIT(bit)) ? hi : lo;
640 *config = pinconf_to_config_packed(param, arg);
644 static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin,
645 unsigned long *configs, unsigned num_configs)
647 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
648 struct sh_pfc *pfc = pmx->pfc;
649 enum pin_config_param param;
653 for (i = 0; i < num_configs; i++) {
654 param = pinconf_to_config_param(configs[i]);
656 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
660 case PIN_CONFIG_BIAS_PULL_UP:
661 case PIN_CONFIG_BIAS_PULL_DOWN:
662 case PIN_CONFIG_BIAS_DISABLE:
663 if (!pfc->info->ops || !pfc->info->ops->set_bias)
666 spin_lock_irqsave(&pfc->lock, flags);
667 pfc->info->ops->set_bias(pfc, _pin, param);
668 spin_unlock_irqrestore(&pfc->lock, flags);
672 case PIN_CONFIG_DRIVE_STRENGTH: {
674 pinconf_to_config_argument(configs[i]);
677 ret = sh_pfc_pinconf_set_drive_strength(pfc, _pin, arg);
684 case PIN_CONFIG_POWER_SOURCE: {
685 unsigned int mV = pinconf_to_config_argument(configs[i]);
686 int idx = sh_pfc_get_pin_index(pfc, _pin);
687 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
688 unsigned int mode, lo, hi;
692 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
695 bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
696 if (WARN(bit < 0, "invalid pin %#x", _pin))
699 mode = pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
700 lo = mode <= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 1800 : 2500;
701 hi = mode >= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 3300 : 2500;
703 if (mV != lo && mV != hi)
706 spin_lock_irqsave(&pfc->lock, flags);
707 val = sh_pfc_read(pfc, pocctrl);
712 sh_pfc_write(pfc, pocctrl, val);
713 spin_unlock_irqrestore(&pfc->lock, flags);
721 } /* for each config */
726 static int sh_pfc_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
727 unsigned long *configs,
728 unsigned num_configs)
730 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
731 const unsigned int *pins;
732 unsigned int num_pins;
735 pins = pmx->pfc->info->groups[group].pins;
736 num_pins = pmx->pfc->info->groups[group].nr_pins;
738 for (i = 0; i < num_pins; ++i) {
739 ret = sh_pfc_pinconf_set(pctldev, pins[i], configs, num_configs);
747 static const struct pinconf_ops sh_pfc_pinconf_ops = {
749 .pin_config_get = sh_pfc_pinconf_get,
750 .pin_config_set = sh_pfc_pinconf_set,
751 .pin_config_group_set = sh_pfc_pinconf_group_set,
752 .pin_config_config_dbg_show = pinconf_generic_dump_config,
755 /* PFC ranges -> pinctrl pin descs */
756 static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
760 /* Allocate and initialize the pins and configs arrays. */
761 pmx->pins = devm_kcalloc(pfc->dev,
762 pfc->info->nr_pins, sizeof(*pmx->pins),
764 if (unlikely(!pmx->pins))
767 pmx->configs = devm_kcalloc(pfc->dev,
768 pfc->info->nr_pins, sizeof(*pmx->configs),
770 if (unlikely(!pmx->configs))
773 for (i = 0; i < pfc->info->nr_pins; ++i) {
774 const struct sh_pfc_pin *info = &pfc->info->pins[i];
775 struct pinctrl_pin_desc *pin = &pmx->pins[i];
777 /* If the pin number is equal to -1 all pins are considered */
778 pin->number = info->pin != (u16)-1 ? info->pin : i;
779 pin->name = info->name;
785 int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
787 struct sh_pfc_pinctrl *pmx;
790 pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
796 ret = sh_pfc_map_pins(pfc, pmx);
800 pmx->pctl_desc.name = DRV_NAME;
801 pmx->pctl_desc.owner = THIS_MODULE;
802 pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops;
803 pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops;
804 pmx->pctl_desc.confops = &sh_pfc_pinconf_ops;
805 pmx->pctl_desc.pins = pmx->pins;
806 pmx->pctl_desc.npins = pfc->info->nr_pins;
808 ret = devm_pinctrl_register_and_init(pfc->dev, &pmx->pctl_desc, pmx,
811 dev_err(pfc->dev, "could not register: %i\n", ret);
816 return pinctrl_enable(pmx->pctl);
819 const struct pinmux_bias_reg *
820 rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
825 for (i = 0; info->bias_regs[i].puen || info->bias_regs[i].pud; i++) {
826 for (j = 0; j < ARRAY_SIZE(info->bias_regs[i].pins); j++) {
827 if (info->bias_regs[i].pins[j] == pin) {
829 return &info->bias_regs[i];
834 WARN_ONCE(1, "Pin %u is not in bias info list\n", pin);
839 unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
841 const struct pinmux_bias_reg *reg;
844 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
846 return PIN_CONFIG_BIAS_DISABLE;
849 if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
850 return PIN_CONFIG_BIAS_DISABLE;
851 else if (!reg->pud || (sh_pfc_read(pfc, reg->pud) & BIT(bit)))
852 return PIN_CONFIG_BIAS_PULL_UP;
854 return PIN_CONFIG_BIAS_PULL_DOWN;
856 if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
857 return PIN_CONFIG_BIAS_PULL_DOWN;
859 return PIN_CONFIG_BIAS_DISABLE;
863 void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
866 const struct pinmux_bias_reg *reg;
870 reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
875 enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
876 if (bias != PIN_CONFIG_BIAS_DISABLE) {
880 updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
881 if (bias == PIN_CONFIG_BIAS_PULL_UP)
884 sh_pfc_write(pfc, reg->pud, updown);
887 sh_pfc_write(pfc, reg->puen, enable);
889 enable = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
890 if (bias == PIN_CONFIG_BIAS_PULL_DOWN)
893 sh_pfc_write(pfc, reg->pud, enable);
897 #define PORTnCR_PULMD_OFF (0 << 6)
898 #define PORTnCR_PULMD_DOWN (2 << 6)
899 #define PORTnCR_PULMD_UP (3 << 6)
900 #define PORTnCR_PULMD_MASK (3 << 6)
902 unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
904 void __iomem *reg = pfc->windows->virt +
905 pfc->info->ops->pin_to_portcr(pin);
906 u32 value = ioread8(reg) & PORTnCR_PULMD_MASK;
909 case PORTnCR_PULMD_UP:
910 return PIN_CONFIG_BIAS_PULL_UP;
911 case PORTnCR_PULMD_DOWN:
912 return PIN_CONFIG_BIAS_PULL_DOWN;
913 case PORTnCR_PULMD_OFF:
915 return PIN_CONFIG_BIAS_DISABLE;
919 void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
922 void __iomem *reg = pfc->windows->virt +
923 pfc->info->ops->pin_to_portcr(pin);
924 u32 value = ioread8(reg) & ~PORTnCR_PULMD_MASK;
927 case PIN_CONFIG_BIAS_PULL_UP:
928 value |= PORTnCR_PULMD_UP;
930 case PIN_CONFIG_BIAS_PULL_DOWN:
931 value |= PORTnCR_PULMD_DOWN;
935 iowrite8(value, reg);