cregit-Linux how code gets into the kernel

Release 4.14 drivers/pinctrl/devicetree.c

Directory: drivers/pinctrl
/*
 * Device tree integration for the pin control subsystem
 *
 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/device.h>
#include <linux/of.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/slab.h>

#include "core.h"
#include "devicetree.h"

/**
 * struct pinctrl_dt_map - mapping table chunk parsed from device tree
 * @node: list node for struct pinctrl's @dt_maps field
 * @pctldev: the pin controller that allocated this struct, and will free it
 * @maps: the mapping table entries
 */

struct pinctrl_dt_map {
	
struct list_head node;
	
struct pinctrl_dev *pctldev;
	
struct pinctrl_map *map;
	
unsigned num_maps;
};


static void dt_free_map(struct pinctrl_dev *pctldev, struct pinctrl_map *map, unsigned num_maps) { if (pctldev) { const struct pinctrl_ops *ops = pctldev->desc->pctlops; if (ops->dt_free_map) ops->dt_free_map(pctldev, map, num_maps); } else { /* There is no pctldev for PIN_MAP_TYPE_DUMMY_STATE */ kfree(map); } }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren5688.89%133.33%
Tony Lindgren69.52%133.33%
Laurent Pinchart11.59%133.33%
Total63100.00%3100.00%


void pinctrl_dt_free_maps(struct pinctrl *p) { struct pinctrl_dt_map *dt_map, *n1; list_for_each_entry_safe(dt_map, n1, &p->dt_maps, node) { pinctrl_unregister_map(dt_map->map); list_del(&dt_map->node); dt_free_map(dt_map->pctldev, dt_map->map, dt_map->num_maps); kfree(dt_map); } of_node_put(p->dev->of_node); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren74100.00%1100.00%
Total74100.00%1100.00%


static int dt_remember_or_free_map(struct pinctrl *p, const char *statename, struct pinctrl_dev *pctldev, struct pinctrl_map *map, unsigned num_maps) { int i; struct pinctrl_dt_map *dt_map; /* Initialize common mapping table entry fields */ for (i = 0; i < num_maps; i++) { map[i].dev_name = dev_name(p->dev); map[i].name = statename; if (pctldev) map[i].ctrl_dev_name = dev_name(pctldev->dev); } /* Remember the converted mapping table entries */ dt_map = kzalloc(sizeof(*dt_map), GFP_KERNEL); if (!dt_map) { dt_free_map(pctldev, map, num_maps); return -ENOMEM; } dt_map->pctldev = pctldev; dt_map->map = map; dt_map->num_maps = num_maps; list_add_tail(&dt_map->node, &p->dt_maps); return pinctrl_register_map(map, num_maps, false); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren169100.00%1100.00%
Total169100.00%1100.00%


struct pinctrl_dev *of_pinctrl_get(struct device_node *np) { return get_pinctrl_dev_from_of_node(np); }

Contributors

PersonTokensPropCommitsCommitProp
Shiraz Hashim1583.33%125.00%
Linus Walleij15.56%125.00%
Patrice Chotard15.56%125.00%
Masahiro Yamada15.56%125.00%
Total18100.00%4100.00%


static int dt_to_map_one_config(struct pinctrl *p, struct pinctrl_dev *pctldev, const char *statename, struct device_node *np_config) { struct device_node *np_pctldev; const struct pinctrl_ops *ops; int ret; struct pinctrl_map *map; unsigned num_maps; /* Find the pin controller containing np_config */ np_pctldev = of_node_get(np_config); for (;;) { np_pctldev = of_get_next_parent(np_pctldev); if (!np_pctldev || of_node_is_root(np_pctldev)) { dev_info(p->dev, "could not find pctldev for node %pOF, deferring probe\n", np_config); of_node_put(np_pctldev); /* OK let's just assume this will appear later then */ return -EPROBE_DEFER; } if (!pctldev) pctldev = get_pinctrl_dev_from_of_node(np_pctldev); if (pctldev) break; /* Do not defer probing of hogs (circular loop) */ if (np_pctldev == p->dev->of_node) { of_node_put(np_pctldev); return -ENODEV; } } of_node_put(np_pctldev); /* * Call pinctrl driver to parse device tree node, and * generate mapping table entries */ ops = pctldev->desc->pctlops; if (!ops->dt_node_to_map) { dev_err(p->dev, "pctldev %s doesn't support DT\n", dev_name(pctldev->dev)); return -ENODEV; } ret = ops->dt_node_to_map(pctldev, np_config, &map, &num_maps); if (ret < 0) return ret; /* Stash the mapping table chunk away for later use */ return dt_remember_or_free_map(p, statename, pctldev, map, num_maps); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren18883.19%114.29%
Linus Walleij2511.06%228.57%
Tony Lindgren104.42%114.29%
Patrice Chotard10.44%114.29%
Rob Herring10.44%114.29%
Laurent Pinchart10.44%114.29%
Total226100.00%7100.00%


static int dt_remember_dummy_state(struct pinctrl *p, const char *statename) { struct pinctrl_map *map; map = kzalloc(sizeof(*map), GFP_KERNEL); if (!map) return -ENOMEM; /* There is no pctldev for PIN_MAP_TYPE_DUMMY_STATE */ map->type = PIN_MAP_TYPE_DUMMY_STATE; return dt_remember_or_free_map(p, statename, NULL, map, 1); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren64100.00%1100.00%
Total64100.00%1100.00%


bool pinctrl_dt_has_hogs(struct pinctrl_dev *pctldev) { struct device_node *np; struct property *prop; int size; np = pctldev->dev->of_node; if (!np) return false; prop = of_find_property(np, "pinctrl-0", &size); return prop ? true : false; }

Contributors

PersonTokensPropCommitsCommitProp
Tony Lindgren58100.00%1100.00%
Total58100.00%1100.00%


int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev) { struct device_node *np = p->dev->of_node; int state, ret; char *propname; struct property *prop; const char *statename; const __be32 *list; int size, config; phandle phandle; struct device_node *np_config; /* CONFIG_OF enabled, p->dev not instantiated from DT */ if (!np) { if (of_have_populated_dt()) dev_dbg(p->dev, "no of_node; not parsing pinctrl DT\n"); return 0; } /* We may store pointers to property names within the node */ of_node_get(np); /* For each defined state ID */ for (state = 0; ; state++) { /* Retrieve the pinctrl-* property */ propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state); prop = of_find_property(np, propname, &size); kfree(propname); if (!prop) { if (state == 0) { of_node_put(np); return -ENODEV; } break; } list = prop->value; size /= sizeof(*list); /* Determine whether pinctrl-names property names the state */ ret = of_property_read_string_index(np, "pinctrl-names", state, &statename); /* * If not, statename is just the integer state ID. But rather * than dynamically allocate it and have to free it later, * just point part way into the property name for the string. */ if (ret < 0) { /* strlen("pinctrl-") == 8 */ statename = prop->name + 8; } /* For every referenced pin configuration node in it */ for (config = 0; config < size; config++) { phandle = be32_to_cpup(list++); /* Look up the pin configuration node */ np_config = of_find_node_by_phandle(phandle); if (!np_config) { dev_err(p->dev, "prop %s index %i invalid phandle\n", prop->name, config); ret = -EINVAL; goto err; } /* Parse the node */ ret = dt_to_map_one_config(p, pctldev, statename, np_config); of_node_put(np_config); if (ret < 0) goto err; } /* No entries in DT? Generate a dummy state table entry */ if (!size) { ret = dt_remember_dummy_state(p, statename); if (ret < 0) goto err; } } return 0; err: pinctrl_dt_free_maps(p); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren30690.80%125.00%
Jon Hunter195.64%125.00%
Tony Lindgren72.08%125.00%
Mark Brown51.48%125.00%
Total337100.00%4100.00%

/* * For pinctrl binding, typically #pinctrl-cells is for the pin controller * device, so either parent or grandparent. See pinctrl-bindings.txt. */
static int pinctrl_find_cells_size(const struct device_node *np) { const char *cells_name = "#pinctrl-cells"; int cells_size, error; error = of_property_read_u32(np->parent, cells_name, &cells_size); if (error) { error = of_property_read_u32(np->parent->parent, cells_name, &cells_size); if (error) return -ENOENT; } return cells_size; }

Contributors

PersonTokensPropCommitsCommitProp
Tony Lindgren71100.00%1100.00%
Total71100.00%1100.00%

/** * pinctrl_get_list_and_count - Gets the list and it's cell size and number * @np: pointer to device node with the property * @list_name: property that contains the list * @list: pointer for the list found * @cells_size: pointer for the cell size found * @nr_elements: pointer for the number of elements found * * Typically np is a single pinctrl entry containing the list. */
static int pinctrl_get_list_and_count(const struct device_node *np, const char *list_name, const __be32 **list, int *cells_size, int *nr_elements) { int size; *cells_size = 0; *nr_elements = 0; *list = of_get_property(np, list_name, &size); if (!*list) return -ENOENT; *cells_size = pinctrl_find_cells_size(np); if (*cells_size < 0) return -ENOENT; /* First element is always the index within the pinctrl device */ *nr_elements = (size / sizeof(**list)) / (*cells_size + 1); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tony Lindgren111100.00%1100.00%
Total111100.00%1100.00%

/** * pinctrl_count_index_with_args - Count number of elements in a pinctrl entry * @np: pointer to device node with the property * @list_name: property that contains the list * * Counts the number of elements in a pinctrl array consisting of an index * within the controller and a number of u32 entries specified for each * entry. Note that device_node is always for the parent pin controller device. */
int pinctrl_count_index_with_args(const struct device_node *np, const char *list_name) { const __be32 *list; int size, nr_cells, error; error = pinctrl_get_list_and_count(np, list_name, &list, &nr_cells, &size); if (error) return error; return size; }

Contributors

PersonTokensPropCommitsCommitProp
Tony Lindgren56100.00%1100.00%
Total56100.00%1100.00%

EXPORT_SYMBOL_GPL(pinctrl_count_index_with_args); /** * pinctrl_copy_args - Populates of_phandle_args based on index * @np: pointer to device node with the property * @list: pointer to a list with the elements * @index: entry within the list of elements * @nr_cells: number of cells in the list * @nr_elem: number of elements for each entry in the list * @out_args: returned values * * Populates the of_phandle_args based on the index in the list. */
static int pinctrl_copy_args(const struct device_node *np, const __be32 *list, int index, int nr_cells, int nr_elem, struct of_phandle_args *out_args) { int i; memset(out_args, 0, sizeof(*out_args)); out_args->np = (struct device_node *)np; out_args->args_count = nr_cells + 1; if (index >= nr_elem) return -EINVAL; list += index * (nr_cells + 1); for (i = 0; i < nr_cells + 1; i++) out_args->args[i] = be32_to_cpup(list++); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tony Lindgren117100.00%1100.00%
Total117100.00%1100.00%

/** * pinctrl_parse_index_with_args - Find a node pointed by index in a list * @np: pointer to device node with the property * @list_name: property that contains the list * @index: index within the list * @out_arts: entries in the list pointed by index * * Finds the selected element in a pinctrl array consisting of an index * within the controller and a number of u32 entries specified for each * entry. Note that device_node is always for the parent pin controller device. */
int pinctrl_parse_index_with_args(const struct device_node *np, const char *list_name, int index, struct of_phandle_args *out_args) { const __be32 *list; int nr_elem, nr_cells, error; error = pinctrl_get_list_and_count(np, list_name, &list, &nr_cells, &nr_elem); if (error || !nr_cells) return error; error = pinctrl_copy_args(np, list, index, nr_cells, nr_elem, out_args); if (error) return error; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Tony Lindgren91100.00%1100.00%
Total91100.00%1100.00%

EXPORT_SYMBOL_GPL(pinctrl_parse_index_with_args);

Overall Contributors

PersonTokensPropCommitsCommitProp
Stephen Warren89959.46%17.14%
Tony Lindgren54235.85%321.43%
Linus Walleij261.72%321.43%
Jon Hunter191.26%17.14%
Shiraz Hashim150.99%17.14%
Mark Brown50.33%17.14%
Patrice Chotard20.13%17.14%
Laurent Pinchart20.13%17.14%
Masahiro Yamada10.07%17.14%
Rob Herring10.07%17.14%
Total1512100.00%14100.00%
Directory: drivers/pinctrl
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.