cregit-Linux how code gets into the kernel

Release 4.7 drivers/pinctrl/sunxi/pinctrl-sunxi.c

/*
 * Allwinner A1X SoCs pinctrl driver.
 *
 * Copyright (C) 2012 Maxime Ripard
 *
 * Maxime Ripard <maxime.ripard@free-electrons.com>
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

#include <linux/io.h>
#include <linux/clk.h>
#include <linux/gpio/driver.h>
#include <linux/irqdomain.h>
#include <linux/irqchip/chained_irq.h>
#include <linux/export.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/pinctrl/consumer.h>
#include <linux/pinctrl/machine.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/pinctrl/pinconf-generic.h>
#include <linux/pinctrl/pinmux.h>
#include <linux/platform_device.h>
#include <linux/slab.h>

#include "../core.h"
#include "../../gpio/gpiolib.h"
#include "pinctrl-sunxi.h"


static struct irq_chip sunxi_pinctrl_edge_irq_chip;

static struct irq_chip sunxi_pinctrl_level_irq_chip;


static struct sunxi_pinctrl_group * sunxi_pinctrl_find_group_by_name(struct sunxi_pinctrl *pctl, const char *group) { int i; for (i = 0; i < pctl->ngroups; i++) { struct sunxi_pinctrl_group *grp = pctl->groups + i; if (!strcmp(grp->name, group)) return grp; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard67100.00%1100.00%
Total67100.00%1100.00%


static struct sunxi_pinctrl_function * sunxi_pinctrl_find_function_by_name(struct sunxi_pinctrl *pctl, const char *name) { struct sunxi_pinctrl_function *func = pctl->functions; int i; for (i = 0; i < pctl->nfunctions; i++) { if (!func[i].name) break; if (!strcmp(func[i].name, name)) return func + i; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard81100.00%1100.00%
Total81100.00%1100.00%


static struct sunxi_desc_function * sunxi_pinctrl_desc_find_function_by_name(struct sunxi_pinctrl *pctl, const char *pin_name, const char *func_name) { int i; for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; if (!strcmp(pin->pin.name, pin_name)) { struct sunxi_desc_function *func = pin->functions; while (func->name) { if (!strcmp(func->name, func_name)) return func; func++; } } } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard113100.00%1100.00%
Total113100.00%1100.00%


static struct sunxi_desc_function * sunxi_pinctrl_desc_find_function_by_pin(struct sunxi_pinctrl *pctl, const u16 pin_num, const char *func_name) { int i; for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; if (pin->pin.number == pin_num) { struct sunxi_desc_function *func = pin->functions; while (func->name) { if (!strcmp(func->name, func_name)) return func; func++; } } } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard108100.00%1100.00%
Total108100.00%1100.00%


static int sunxi_pctrl_get_groups_count(struct pinctrl_dev *pctldev) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); return pctl->ngroups; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard26100.00%1100.00%
Total26100.00%1100.00%


static const char *sunxi_pctrl_get_group_name(struct pinctrl_dev *pctldev, unsigned group) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); return pctl->groups[group].name; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard36100.00%1100.00%
Total36100.00%1100.00%


static int sunxi_pctrl_get_group_pins(struct pinctrl_dev *pctldev, unsigned group, const unsigned **pins, unsigned *num_pins) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); *pins = (unsigned *)&pctl->groups[group].pin; *num_pins = 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard59100.00%1100.00%
Total59100.00%1100.00%


static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node *node, struct pinctrl_map **map, unsigned *num_maps) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); unsigned long *pinconfig; struct property *prop; const char *function; const char *group; int ret, nmaps, i = 0; u32 val; *map = NULL; *num_maps = 0; ret = of_property_read_string(node, "allwinner,function", &function); if (ret) { dev_err(pctl->dev, "missing allwinner,function property in node %s\n", node->name); return -EINVAL; } nmaps = of_property_count_strings(node, "allwinner,pins") * 2; if (nmaps < 0) { dev_err(pctl->dev, "missing allwinner,pins property in node %s\n", node->name); return -EINVAL; } *map = kmalloc(nmaps * sizeof(struct pinctrl_map), GFP_KERNEL); if (!*map) return -ENOMEM; of_property_for_each_string(node, "allwinner,pins", prop, group) { struct sunxi_pinctrl_group *grp = sunxi_pinctrl_find_group_by_name(pctl, group); int j = 0, configlen = 0; if (!grp) { dev_err(pctl->dev, "unknown pin %s", group); continue; } if (!sunxi_pinctrl_desc_find_function_by_name(pctl, grp->name, function)) { dev_err(pctl->dev, "unsupported function %s on pin %s", function, group); continue; } (*map)[i].type = PIN_MAP_TYPE_MUX_GROUP; (*map)[i].data.mux.group = group; (*map)[i].data.mux.function = function; i++; (*map)[i].type = PIN_MAP_TYPE_CONFIGS_GROUP; (*map)[i].data.configs.group_or_pin = group; if (of_find_property(node, "allwinner,drive", NULL)) configlen++; if (of_find_property(node, "allwinner,pull", NULL)) configlen++; pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL); if (!pinconfig) { kfree(*map); return -ENOMEM; } if (!of_property_read_u32(node, "allwinner,drive", &val)) { u16 strength = (val + 1) * 10; pinconfig[j++] = pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH, strength); } if (!of_property_read_u32(node, "allwinner,pull", &val)) { enum pin_config_param pull = PIN_CONFIG_END; if (val == 1) pull = PIN_CONFIG_BIAS_PULL_UP; else if (val == 2) pull = PIN_CONFIG_BIAS_PULL_DOWN; pinconfig[j++] = pinconf_to_config_packed(pull, 0); } (*map)[i].data.configs.configs = pinconfig; (*map)[i].data.configs.num_configs = configlen; i++; } *num_maps = nmaps; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard51196.60%133.33%
sachin kamatsachin kamat183.40%266.67%
Total529100.00%3100.00%


static void sunxi_pctrl_dt_free_map(struct pinctrl_dev *pctldev, struct pinctrl_map *map, unsigned num_maps) { int i; for (i = 0; i < num_maps; i++) { if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP) kfree(map[i].data.configs.configs); } kfree(map); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard67100.00%1100.00%
Total67100.00%1100.00%

static const struct pinctrl_ops sunxi_pctrl_ops = { .dt_node_to_map = sunxi_pctrl_dt_node_to_map, .dt_free_map = sunxi_pctrl_dt_free_map, .get_groups_count = sunxi_pctrl_get_groups_count, .get_group_name = sunxi_pctrl_get_group_name, .get_group_pins = sunxi_pctrl_get_group_pins, };
static int sunxi_pconf_group_get(struct pinctrl_dev *pctldev, unsigned group, unsigned long *config) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); *config = pctl->groups[group].config; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard44100.00%1100.00%
Total44100.00%1100.00%


static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, unsigned long *configs, unsigned num_configs) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); struct sunxi_pinctrl_group *g = &pctl->groups[group]; unsigned long flags; unsigned pin = g->pin - pctl->desc->pin_base; u32 val, mask; u16 strength; u8 dlevel; int i; spin_lock_irqsave(&pctl->lock, flags); for (i = 0; i < num_configs; i++) { switch (pinconf_to_config_param(configs[i])) { case PIN_CONFIG_DRIVE_STRENGTH: strength = pinconf_to_config_argument(configs[i]); if (strength > 40) { spin_unlock_irqrestore(&pctl->lock, flags); return -EINVAL; } /* * We convert from mA to what the register expects: * 0: 10mA * 1: 20mA * 2: 30mA * 3: 40mA */ dlevel = strength / 10 - 1; val = readl(pctl->membase + sunxi_dlevel_reg(pin)); mask = DLEVEL_PINS_MASK << sunxi_dlevel_offset(pin); writel((val & ~mask) | dlevel << sunxi_dlevel_offset(pin), pctl->membase + sunxi_dlevel_reg(pin)); break; case PIN_CONFIG_BIAS_PULL_UP: val = readl(pctl->membase + sunxi_pull_reg(pin)); mask = PULL_PINS_MASK << sunxi_pull_offset(pin); writel((val & ~mask) | 1 << sunxi_pull_offset(pin), pctl->membase + sunxi_pull_reg(pin)); break; case PIN_CONFIG_BIAS_PULL_DOWN: val = readl(pctl->membase + sunxi_pull_reg(pin)); mask = PULL_PINS_MASK << sunxi_pull_offset(pin); writel((val & ~mask) | 2 << sunxi_pull_offset(pin), pctl->membase + sunxi_pull_reg(pin)); break; default: break; } /* cache the config value */ g->config = configs[i]; } /* for each config */ spin_unlock_irqrestore(&pctl->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard25876.11%233.33%
sherman yinsherman yin3710.91%116.67%
linus walleijlinus walleij319.14%233.33%
chen-yu tsaichen-yu tsai133.83%116.67%
Total339100.00%6100.00%

static const struct pinconf_ops sunxi_pconf_ops = { .pin_config_group_get = sunxi_pconf_group_get, .pin_config_group_set = sunxi_pconf_group_set, };
static int sunxi_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); return pctl->nfunctions; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard26100.00%1100.00%
Total26100.00%1100.00%


static const char *sunxi_pmx_get_func_name(struct pinctrl_dev *pctldev, unsigned function) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); return pctl->functions[function].name; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard36100.00%1100.00%
Total36100.00%1100.00%


static int sunxi_pmx_get_func_groups(struct pinctrl_dev *pctldev, unsigned function, const char * const **groups, unsigned * const num_groups) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); *groups = pctl->functions[function].groups; *num_groups = pctl->functions[function].ngroups; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard64100.00%1100.00%
Total64100.00%1100.00%


static void sunxi_pmx_set(struct pinctrl_dev *pctldev, unsigned pin, u8 config) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); unsigned long flags; u32 val, mask; spin_lock_irqsave(&pctl->lock, flags); pin -= pctl->desc->pin_base; val = readl(pctl->membase + sunxi_mux_reg(pin)); mask = MUX_PINS_MASK << sunxi_mux_offset(pin); writel((val & ~mask) | config << sunxi_mux_offset(pin), pctl->membase + sunxi_mux_reg(pin)); spin_unlock_irqrestore(&pctl->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard10592.92%266.67%
chen-yu tsaichen-yu tsai87.08%133.33%
Total113100.00%3100.00%


static int sunxi_pmx_set_mux(struct pinctrl_dev *pctldev, unsigned function, unsigned group) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); struct sunxi_pinctrl_group *g = pctl->groups + group; struct sunxi_pinctrl_function *func = pctl->functions + function; struct sunxi_desc_function *desc = sunxi_pinctrl_desc_find_function_by_name(pctl, g->name, func->name); if (!desc) return -EINVAL; sunxi_pmx_set(pctldev, g->pin, desc->muxval); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard9198.91%150.00%
linus walleijlinus walleij11.09%150.00%
Total92100.00%2100.00%


static int sunxi_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned offset, bool input) { struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); struct sunxi_desc_function *desc; const char *func; if (input) func = "gpio_in"; else func = "gpio_out"; desc = sunxi_pinctrl_desc_find_function_by_pin(pctl, offset, func); if (!desc) return -EINVAL; sunxi_pmx_set(pctldev, offset, desc->muxval); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard89100.00%2100.00%
Total89100.00%2100.00%

static const struct pinmux_ops sunxi_pmx_ops = { .get_functions_count = sunxi_pmx_get_funcs_cnt, .get_function_name = sunxi_pmx_get_func_name, .get_function_groups = sunxi_pmx_get_func_groups, .set_mux = sunxi_pmx_set_mux, .gpio_set_direction = sunxi_pmx_gpio_set_direction, };
static int sunxi_pinctrl_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { return pinctrl_gpio_direction_input(chip->base + offset); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard24100.00%2100.00%
Total24100.00%2100.00%


static int sunxi_pinctrl_gpio_get(struct gpio_chip *chip, unsigned offset) { struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); u32 reg = sunxi_data_reg(offset); u8 index = sunxi_data_offset(offset); bool set_mux = pctl->desc->irq_read_needs_mux && gpiochip_line_is_irq(chip, offset); u32 pin = offset + chip->base; u32 val; if (set_mux) sunxi_pmx_set(pctl->pctl_dev, pin, SUN4I_FUNC_INPUT); val = (readl(pctl->membase + reg) >> index) & DATA_PINS_MASK; if (set_mux) sunxi_pmx_set(pctl->pctl_dev, pin, SUN4I_FUNC_IRQ); return !!val; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard5747.50%116.67%
hans de goedehans de goede4638.33%116.67%
krzysztof adamskikrzysztof adamski119.17%116.67%
linus walleijlinus walleij65.00%350.00%
Total120100.00%6100.00%


static void sunxi_pinctrl_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); u32 reg = sunxi_data_reg(offset); u8 index = sunxi_data_offset(offset); unsigned long flags; u32 regval; spin_lock_irqsave(&pctl->lock, flags); regval = readl(pctl->membase + reg); if (value) regval |= BIT(index); else regval &= ~(BIT(index)); writel(regval, pctl->membase + reg); spin_unlock_irqrestore(&pctl->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard11399.12%375.00%
linus walleijlinus walleij10.88%125.00%
Total114100.00%4100.00%


static int sunxi_pinctrl_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { sunxi_pinctrl_gpio_set(chip, offset, value); return pinctrl_gpio_direction_output(chip->base + offset); }

Contributors

PersonTokensPropCommitsCommitProp
chen-yu tsaichen-yu tsai36100.00%1100.00%
Total36100.00%1100.00%


static int sunxi_pinctrl_gpio_of_xlate(struct gpio_chip *gc, const struct of_phandle_args *gpiospec, u32 *flags) { int pin, base; base = PINS_PER_BANK * gpiospec->args[0]; pin = base + gpiospec->args[1]; if (pin > gc->ngpio) return -EINVAL; if (flags) *flags = gpiospec->args[2]; return pin; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard77100.00%1100.00%
Total77100.00%1100.00%


static int sunxi_pinctrl_gpio_to_irq(struct gpio_chip *chip, unsigned offset) { struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); struct sunxi_desc_function *desc; unsigned pinnum = pctl->desc->pin_base + offset; unsigned irqnum; if (offset >= chip->ngpio) return -ENXIO; desc = sunxi_pinctrl_desc_find_function_by_pin(pctl, pinnum, "irq"); if (!desc) return -EINVAL; irqnum = desc->irqbank * IRQ_PER_BANK + desc->irqnum; dev_dbg(chip->parent, "%s: request IRQ for GPIO %d, return %d\n", chip->label, offset + chip->base, irqnum); return irq_find_mapping(pctl->domain, irqnum); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard8874.58%116.67%
chen-yu tsaichen-yu tsai2722.88%233.33%
linus walleijlinus walleij21.69%233.33%
axel linaxel lin10.85%116.67%
Total118100.00%6100.00%


static int sunxi_pinctrl_irq_request_resources(struct irq_data *d) { struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); struct sunxi_desc_function *func; int ret; func = sunxi_pinctrl_desc_find_function_by_pin(pctl, pctl->irq_array[d->hwirq], "irq"); if (!func) return -EINVAL; ret = gpiochip_lock_as_irq(pctl->chip, pctl->irq_array[d->hwirq] - pctl->desc->pin_base); if (ret) { dev_err(pctl->dev, "unable to lock HW IRQ %lu for IRQ\n", irqd_to_hwirq(d)); return ret; } /* Change muxing to INT mode */ sunxi_pmx_set(pctl->pctl_dev, pctl->irq_array[d->hwirq], func->muxval); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
hans de goedehans de goede7458.27%120.00%
chen-yu tsaichen-yu tsai4737.01%240.00%
maxime ripardmaxime ripard53.94%120.00%
alexandre courbotalexandre courbot10.79%120.00%
Total127100.00%5100.00%


static void sunxi_pinctrl_irq_release_resources(struct irq_data *d) { struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); gpiochip_unlock_as_irq(pctl->chip, pctl->irq_array[d->hwirq] - pctl->desc->pin_base); }

Contributors

PersonTokensPropCommitsCommitProp
chen-yu tsaichen-yu tsai4297.67%266.67%
alexandre courbotalexandre courbot12.33%133.33%
Total43100.00%3100.00%


static int sunxi_pinctrl_irq_set_type(struct irq_data *d, unsigned int type) { struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); u32 reg = sunxi_irq_cfg_reg(d->hwirq, pctl->desc->irq_bank_base); u8 index = sunxi_irq_cfg_offset(d->hwirq); unsigned long flags; u32 regval; u8 mode; switch (type) { case IRQ_TYPE_EDGE_RISING: mode = IRQ_EDGE_RISING; break; case IRQ_TYPE_EDGE_FALLING: mode = IRQ_EDGE_FALLING; break; case IRQ_TYPE_EDGE_BOTH: mode = IRQ_EDGE_BOTH; break; case IRQ_TYPE_LEVEL_HIGH: mode = IRQ_LEVEL_HIGH; break; case IRQ_TYPE_LEVEL_LOW: mode = IRQ_LEVEL_LOW; break; default: return -EINVAL; } spin_lock_irqsave(&pctl->lock, flags); if (type & IRQ_TYPE_LEVEL_MASK) irq_set_chip_handler_name_locked(d, &sunxi_pinctrl_level_irq_chip, handle_fasteoi_irq, NULL); else irq_set_chip_handler_name_locked(d, &sunxi_pinctrl_edge_irq_chip, handle_edge_irq, NULL); regval = readl(pctl->membase + reg); regval &= ~(IRQ_CFG_IRQ_MASK << index); writel(regval | (mode << index), pctl->membase + reg); spin_unlock_irqrestore(&pctl->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard17586.21%555.56%
hans de goedehans de goede2612.81%333.33%
thomas gleixnerthomas gleixner20.99%111.11%
Total203100.00%9100.00%


static void sunxi_pinctrl_irq_ack(struct irq_data *d) { struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); u32 status_reg = sunxi_irq_status_reg(d->hwirq, pctl->desc->irq_bank_base); u8 status_idx = sunxi_irq_status_offset(d->hwirq); /* Clear the IRQ */ writel(1 << status_idx, pctl->membase + status_reg); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard5590.16%266.67%
hans de goedehans de goede69.84%133.33%
Total61100.00%3100.00%


static void sunxi_pinctrl_irq_mask(struct irq_data *d) { struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); u32 reg = sunxi_irq_ctrl_reg(d->hwirq, pctl->desc->irq_bank_base); u8 idx = sunxi_irq_ctrl_offset(d->hwirq); unsigned long flags; u32 val; spin_lock_irqsave(&pctl->lock, flags); /* Mask the IRQ */ val = readl(pctl->membase + reg); writel(val & ~(1 << idx), pctl->membase + reg); spin_unlock_irqrestore(&pctl->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard9894.23%266.67%
hans de goedehans de goede65.77%133.33%
Total104100.00%3100.00%


static void sunxi_pinctrl_irq_unmask(struct irq_data *d) { struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d); u32 reg = sunxi_irq_ctrl_reg(d->hwirq, pctl->desc->irq_bank_base); u8 idx = sunxi_irq_ctrl_offset(d->hwirq); unsigned long flags; u32 val; spin_lock_irqsave(&pctl->lock, flags); /* Unmask the IRQ */ val = readl(pctl->membase + reg); writel(val | (1 << idx), pctl->membase + reg); spin_unlock_irqrestore(&pctl->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard9794.17%266.67%
hans de goedehans de goede65.83%133.33%
Total103100.00%3100.00%


static void sunxi_pinctrl_irq_ack_unmask(struct irq_data *d) { sunxi_pinctrl_irq_ack(d); sunxi_pinctrl_irq_unmask(d); }

Contributors

PersonTokensPropCommitsCommitProp
hans de goedehans de goede21100.00%1100.00%
Total21100.00%1100.00%

static struct irq_chip sunxi_pinctrl_edge_irq_chip = { .name = "sunxi_pio_edge", .irq_ack = sunxi_pinctrl_irq_ack, .irq_mask = sunxi_pinctrl_irq_mask, .irq_unmask = sunxi_pinctrl_irq_unmask, .irq_request_resources = sunxi_pinctrl_irq_request_resources, .irq_release_resources = sunxi_pinctrl_irq_release_resources, .irq_set_type = sunxi_pinctrl_irq_set_type, .flags = IRQCHIP_SKIP_SET_WAKE, }; static struct irq_chip sunxi_pinctrl_level_irq_chip = { .name = "sunxi_pio_level", .irq_eoi = sunxi_pinctrl_irq_ack, .irq_mask = sunxi_pinctrl_irq_mask, .irq_unmask = sunxi_pinctrl_irq_unmask, /* Define irq_enable / disable to avoid spurious irqs for drivers * using these to suppress irqs while they clear the irq source */ .irq_enable = sunxi_pinctrl_irq_ack_unmask, .irq_disable = sunxi_pinctrl_irq_mask, .irq_request_resources = sunxi_pinctrl_irq_request_resources, .irq_release_resources = sunxi_pinctrl_irq_release_resources, .irq_set_type = sunxi_pinctrl_irq_set_type, .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED, };
static int sunxi_pinctrl_irq_of_xlate(struct irq_domain *d, struct device_node *node, const u32 *intspec, unsigned int intsize, unsigned long *out_hwirq, unsigned int *out_type) { struct sunxi_pinctrl *pctl = d->host_data; struct sunxi_desc_function *desc; int pin, base; if (intsize < 3) return -EINVAL; base = PINS_PER_BANK * intspec[0]; pin = pctl->desc->pin_base + base + intspec[1]; desc = sunxi_pinctrl_desc_find_function_by_pin(pctl, pin, "irq"); if (!desc) return -EINVAL; *out_hwirq = desc->irqbank * PINS_PER_BANK + desc->irqnum; *out_type = intspec[2]; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard11687.88%150.00%
hans de goedehans de goede1612.12%150.00%
Total132100.00%2100.00%

static struct irq_domain_ops sunxi_pinctrl_irq_domain_ops = { .xlate = sunxi_pinctrl_irq_of_xlate, };
static void sunxi_pinctrl_irq_handler(struct irq_desc *desc) { unsigned int irq = irq_desc_get_irq(desc); struct irq_chip *chip = irq_desc_get_chip(desc); struct sunxi_pinctrl *pctl = irq_desc_get_handler_data(desc); unsigned long bank, reg, val; for (bank = 0; bank < pctl->desc->irq_banks; bank++) if (irq == pctl->irq[bank]) break; if (bank == pctl->desc->irq_banks) return; reg = sunxi_irq_status_reg_from_bank(bank, pctl->desc->irq_bank_base); val = readl(pctl->membase + reg); if (val) { int irqoffset; chained_irq_enter(chip, desc); for_each_set_bit(irqoffset, &val, IRQ_PER_BANK) { int pin_irq = irq_find_mapping(pctl->domain, bank * IRQ_PER_BANK + irqoffset); generic_handle_irq(pin_irq); } chained_irq_exit(chip, desc); } }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard12575.30%233.33%
chen-yu tsaichen-yu tsai2213.25%116.67%
thomas gleixnerthomas gleixner95.42%116.67%
hans de goedehans de goede63.61%116.67%
jiang liujiang liu42.41%116.67%
Total166100.00%6100.00%


static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl, const char *name) { struct sunxi_pinctrl_function *func = pctl->functions; while (func->name) { /* function already there */ if (strcmp(func->name, name) == 0) { func->ngroups++; return -EEXIST; } func++; } func->name = name; func->ngroups = 1; pctl->nfunctions++; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard81100.00%2100.00%
Total81100.00%2100.00%


static int sunxi_pinctrl_build_state(struct platform_device *pdev) { struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev); int i; pctl->ngroups = pctl->desc->npins; /* Allocate groups */ pctl->groups = devm_kzalloc(&pdev->dev, pctl->ngroups * sizeof(*pctl->groups), GFP_KERNEL); if (!pctl->groups) return -ENOMEM; for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; struct sunxi_pinctrl_group *group = pctl->groups + i; group->name = pin->pin.name; group->pin = pin->pin.number; } /* * We suppose that we won't have any more functions than pins, * we'll reallocate that later anyway */ pctl->functions = devm_kzalloc(&pdev->dev, pctl->desc->npins * sizeof(*pctl->functions), GFP_KERNEL); if (!pctl->functions) return -ENOMEM; /* Count functions and their associated groups */ for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; struct sunxi_desc_function *func = pin->functions; while (func->name) { /* Create interrupt mapping while we're at it */ if (!strcmp(func->name, "irq")) { int irqnum = func->irqnum + func->irqbank * IRQ_PER_BANK; pctl->irq_array[irqnum] = pin->pin.number; } sunxi_pinctrl_add_function(pctl, func->name); func++; } } pctl->functions = krealloc(pctl->functions, pctl->nfunctions * sizeof(*pctl->functions), GFP_KERNEL); for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; struct sunxi_desc_function *func = pin->functions; while (func->name) { struct sunxi_pinctrl_function *func_item; const char **func_grp; func_item = sunxi_pinctrl_find_function_by_name(pctl, func->name); if (!func_item) return -EINVAL; if (!func_item->groups) { func_item->groups = devm_kzalloc(&pdev->dev, func_item->ngroups * sizeof(*func_item->groups), GFP_KERNEL); if (!func_item->groups) return -ENOMEM; } func_grp = func_item->groups; while (*func_grp) func_grp++; *func_grp = pin->pin.name; func++; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard43594.36%375.00%
chen-yu tsaichen-yu tsai265.64%125.00%
Total461100.00%4100.00%


int sunxi_pinctrl_init(struct platform_device *pdev, const struct sunxi_pinctrl_desc *desc) { struct device_node *node = pdev->dev.of_node; struct pinctrl_desc *pctrl_desc; struct pinctrl_pin_desc *pins; struct sunxi_pinctrl *pctl; struct resource *res; int i, ret, last_pin; struct clk *clk; pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); if (!pctl) return -ENOMEM; platform_set_drvdata(pdev, pctl); spin_lock_init(&pctl->lock); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); pctl->membase = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(pctl->membase)) return PTR_ERR(pctl->membase); pctl->dev = &pdev->dev; pctl->desc = desc; pctl->irq_array = devm_kcalloc(&pdev->dev, IRQ_PER_BANK * pctl->desc->irq_banks, sizeof(*pctl->irq_array), GFP_KERNEL); if (!pctl->irq_array) return -ENOMEM; ret = sunxi_pinctrl_build_state(pdev); if (ret) { dev_err(&pdev->dev, "dt probe failed: %d\n", ret); return ret; } pins = devm_kzalloc(&pdev->dev, pctl->desc->npins * sizeof(*pins), GFP_KERNEL); if (!pins) return -ENOMEM; for (i = 0; i < pctl->desc->npins; i++) pins[i] = pctl->desc->pins[i].pin; pctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctrl_desc), GFP_KERNEL); if (!pctrl_desc) return -ENOMEM; pctrl_desc->name = dev_name(&pdev->dev); pctrl_desc->owner = THIS_MODULE; pctrl_desc->pins = pins; pctrl_desc->npins = pctl->desc->npins; pctrl_desc->confops = &sunxi_pconf_ops; pctrl_desc->pctlops = &sunxi_pctrl_ops; pctrl_desc->pmxops = &sunxi_pmx_ops; pctl->pctl_dev = devm_pinctrl_register(&pdev->dev, pctrl_desc, pctl); if (IS_ERR(pctl->pctl_dev)) { dev_err(&pdev->dev, "couldn't register pinctrl driver\n"); return PTR_ERR(pctl->pctl_dev); } pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); if (!pctl->chip) return -ENOMEM; last_pin = pctl->desc->pins[pctl->desc->npins - 1].pin.number; pctl->chip->owner = THIS_MODULE; pctl->chip->request = gpiochip_generic_request, pctl->chip->free = gpiochip_generic_free, pctl->chip->direction_input = sunxi_pinctrl_gpio_direction_input, pctl->chip->direction_output = sunxi_pinctrl_gpio_direction_output, pctl->chip->get = sunxi_pinctrl_gpio_get, pctl->chip->set = sunxi_pinctrl_gpio_set, pctl->chip->of_xlate = sunxi_pinctrl_gpio_of_xlate, pctl->chip->to_irq = sunxi_pinctrl_gpio_to_irq, pctl->chip->of_gpio_n_cells = 3, pctl->chip->can_sleep = false, pctl->chip->ngpio = round_up(last_pin, PINS_PER_BANK) - pctl->desc->pin_base; pctl->chip->label = dev_name(&pdev->dev); pctl->chip->parent = &pdev->dev; pctl->chip->base = pctl->desc->pin_base; ret = gpiochip_add_data(pctl->chip, pctl); if (ret) return ret; for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; ret = gpiochip_add_pin_range(pctl->chip, dev_name(&pdev->dev), pin->pin.number - pctl->desc->pin_base, pin->pin.number, 1); if (ret) goto gpiochip_error; } clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { ret = PTR_ERR(clk); goto gpiochip_error; } ret = clk_prepare_enable(clk); if (ret) goto gpiochip_error; pctl->irq = devm_kcalloc(&pdev->dev, pctl->desc->irq_banks, sizeof(*pctl->irq), GFP_KERNEL); if (!pctl->irq) { ret = -ENOMEM; goto clk_error; } for (i = 0; i < pctl->desc->irq_banks; i++) { pctl->irq[i] = platform_get_irq(pdev, i); if (pctl->irq[i] < 0) { ret = pctl->irq[i]; goto clk_error; } } pctl->domain = irq_domain_add_linear(node, pctl->desc->irq_banks * IRQ_PER_BANK, &sunxi_pinctrl_irq_domain_ops, pctl); if (!pctl->domain) { dev_err(&pdev->dev, "Couldn't register IRQ domain\n"); ret = -ENOMEM; goto clk_error; } for (i = 0; i < (pctl->desc->irq_banks * IRQ_PER_BANK); i++) { int irqno = irq_create_mapping(pctl->domain, i); irq_set_chip_and_handler(irqno, &sunxi_pinctrl_edge_irq_chip, handle_edge_irq); irq_set_chip_data(irqno, pctl); } for (i = 0; i < pctl->desc->irq_banks; i++) { /* Mask and clear all IRQs before registering a handler */ writel(0, pctl->membase + sunxi_irq_ctrl_reg_from_bank(i, pctl->desc->irq_bank_base)); writel(0xffffffff, pctl->membase + sunxi_irq_status_reg_from_bank(i, pctl->desc->irq_bank_base)); irq_set_chained_handler_and_data(pctl->irq[i], sunxi_pinctrl_irq_handler, pctl); } dev_info(&pdev->dev, "initialized sunXi PIO driver\n"); return 0; clk_error: clk_disable_unprepare(clk); gpiochip_error: gpiochip_remove(pctl->chip); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard84579.12%1040.00%
boris brezillonboris brezillon10910.21%416.00%
hans de goedehans de goede434.03%28.00%
emilio lopezemilio lopez323.00%14.00%
masahiro yamadamasahiro yamada90.84%14.00%
wei yongjunwei yongjun90.84%14.00%
laxman dewanganlaxman dewangan80.75%14.00%
chen-yu tsaichen-yu tsai60.56%14.00%
linus walleijlinus walleij40.37%28.00%
jonas gorskijonas gorski20.19%14.00%
thomas gleixnerthomas gleixner10.09%14.00%
Total1068100.00%25100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
maxime ripardmaxime ripard436283.50%1829.51%
hans de goedehans de goede3095.92%711.48%
chen-yu tsaichen-yu tsai2444.67%813.11%
boris brezillonboris brezillon1092.09%46.56%
linus walleijlinus walleij480.92%711.48%
sherman yinsherman yin370.71%11.64%
emilio lopezemilio lopez350.67%11.64%
sachin kamatsachin kamat180.34%23.28%
thomas gleixnerthomas gleixner120.23%34.92%
krzysztof adamskikrzysztof adamski110.21%11.64%
wei yongjunwei yongjun90.17%11.64%
masahiro yamadamasahiro yamada90.17%11.64%
laxman dewanganlaxman dewangan80.15%11.64%
jiang liujiang liu40.08%11.64%
laurent pinchartlaurent pinchart30.06%11.64%
jonas gorskijonas gorski20.04%11.64%
alexandre courbotalexandre courbot20.04%11.64%
axel linaxel lin10.02%11.64%
paul gortmakerpaul gortmaker10.02%11.64%
Total5224100.00%61100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}