Lines Matching +full:int +full:- +full:map +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0
19 #include <linux/pinctrl/pinconf-generic.h>
22 #include "../pinctrl-utils.h"
26 #include "pinctrl-sophgo.h"
33 static int sophgo_cmp_pin(const void *key, const void *pivot) in sophgo_cmp_pin()
36 int pin_id = (long)key; in sophgo_cmp_pin()
37 int pivid = pin->id; in sophgo_cmp_pin()
39 return pin_id - pivid; in sophgo_cmp_pin()
45 return bsearch((void *)pin_id, pctrl->data->pindata, pctrl->data->npins, in sophgo_get_pin()
46 pctrl->data->pinsize, sophgo_cmp_pin); in sophgo_get_pin()
49 static int sophgo_verify_pinmux_config(struct sophgo_pinctrl *pctrl, in sophgo_verify_pinmux_config()
52 if (pctrl->data->cfg_ops->verify_pinmux_config) in sophgo_verify_pinmux_config()
53 return pctrl->data->cfg_ops->verify_pinmux_config(config); in sophgo_verify_pinmux_config()
57 static int sophgo_verify_pin_group(struct sophgo_pinctrl *pctrl, in sophgo_verify_pin_group()
59 unsigned int npins) in sophgo_verify_pin_group()
61 if (pctrl->data->cfg_ops->verify_pin_group) in sophgo_verify_pin_group()
62 return pctrl->data->cfg_ops->verify_pin_group(config, npins); in sophgo_verify_pin_group()
66 static int sophgo_dt_node_to_map_post(struct device_node *cur, in sophgo_dt_node_to_map_post()
69 unsigned int npins) in sophgo_dt_node_to_map_post()
71 if (pctrl->data->cfg_ops->dt_node_to_map_post) in sophgo_dt_node_to_map_post()
72 return pctrl->data->cfg_ops->dt_node_to_map_post(cur, pctrl, in sophgo_dt_node_to_map_post()
77 int sophgo_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node *np, in sophgo_pctrl_dt_node_to_map()
78 struct pinctrl_map **maps, unsigned int *num_maps) in sophgo_pctrl_dt_node_to_map()
81 struct device *dev = pctrl->dev; in sophgo_pctrl_dt_node_to_map()
83 struct pinctrl_map *map; in sophgo_pctrl_dt_node_to_map() local
86 int ngroups = 0; in sophgo_pctrl_dt_node_to_map()
87 int nmaps = 0; in sophgo_pctrl_dt_node_to_map()
88 int ret; in sophgo_pctrl_dt_node_to_map()
95 return -ENOMEM; in sophgo_pctrl_dt_node_to_map()
97 map = kcalloc(ngroups * 2, sizeof(*map), GFP_KERNEL); in sophgo_pctrl_dt_node_to_map()
98 if (!map) in sophgo_pctrl_dt_node_to_map()
99 return -ENOMEM; in sophgo_pctrl_dt_node_to_map()
102 guard(mutex)(&pctrl->mutex); in sophgo_pctrl_dt_node_to_map()
104 int npins = of_property_count_u32_elems(child, "pinmux"); in sophgo_pctrl_dt_node_to_map()
105 unsigned int *pins; in sophgo_pctrl_dt_node_to_map()
108 int i; in sophgo_pctrl_dt_node_to_map()
113 ret = -EINVAL; in sophgo_pctrl_dt_node_to_map()
120 ret = -ENOMEM; in sophgo_pctrl_dt_node_to_map()
128 ret = -ENOMEM; in sophgo_pctrl_dt_node_to_map()
134 ret = -ENOMEM; in sophgo_pctrl_dt_node_to_map()
150 ret = -ENODEV; in sophgo_pctrl_dt_node_to_map()
172 map[nmaps].type = PIN_MAP_TYPE_MUX_GROUP; in sophgo_pctrl_dt_node_to_map()
173 map[nmaps].data.mux.function = np->name; in sophgo_pctrl_dt_node_to_map()
174 map[nmaps].data.mux.group = grpname; in sophgo_pctrl_dt_node_to_map()
178 &map[nmaps].data.configs.configs, in sophgo_pctrl_dt_node_to_map()
179 &map[nmaps].data.configs.num_configs); in sophgo_pctrl_dt_node_to_map()
193 /* don't create a map if there are no pinconf settings */ in sophgo_pctrl_dt_node_to_map()
194 if (map[nmaps].data.configs.num_configs == 0) in sophgo_pctrl_dt_node_to_map()
197 map[nmaps].type = PIN_MAP_TYPE_CONFIGS_GROUP; in sophgo_pctrl_dt_node_to_map()
198 map[nmaps].data.configs.group_or_pin = grpname; in sophgo_pctrl_dt_node_to_map()
202 ret = pinmux_generic_add_function(pctldev, np->name, in sophgo_pctrl_dt_node_to_map()
205 dev_err(dev, "error adding function %s: %d\n", np->name, ret); in sophgo_pctrl_dt_node_to_map()
209 *maps = map; in sophgo_pctrl_dt_node_to_map()
217 pinctrl_utils_free_map(pctldev, map, nmaps); in sophgo_pctrl_dt_node_to_map()
221 int sophgo_pmx_set_mux(struct pinctrl_dev *pctldev, in sophgo_pmx_set_mux()
222 unsigned int fsel, unsigned int gsel) in sophgo_pmx_set_mux()
227 unsigned int i; in sophgo_pmx_set_mux()
231 return -EINVAL; in sophgo_pmx_set_mux()
233 configs = group->data; in sophgo_pmx_set_mux()
235 for (i = 0; i < group->grp.npins; i++) { in sophgo_pmx_set_mux()
239 guard(raw_spinlock_irqsave)(&pctrl->lock); in sophgo_pmx_set_mux()
241 pctrl->data->cfg_ops->set_pinmux_config(pctrl, pin, value); in sophgo_pmx_set_mux()
247 static int sophgo_pin_set_config(struct sophgo_pinctrl *pctrl, in sophgo_pin_set_config()
248 unsigned int pin_id, in sophgo_pin_set_config()
249 u32 value, u32 mask) in sophgo_pin_set_config() argument
254 return -EINVAL; in sophgo_pin_set_config()
256 guard(raw_spinlock_irqsave)(&pctrl->lock); in sophgo_pin_set_config()
258 return pctrl->data->cfg_ops->set_pinconf_config(pctrl, pin, value, mask); in sophgo_pin_set_config()
261 int sophgo_pconf_set(struct pinctrl_dev *pctldev, unsigned int pin_id, in sophgo_pconf_set()
262 unsigned long *configs, unsigned int num_configs) in sophgo_pconf_set()
266 u32 value, mask; in sophgo_pconf_set() local
269 return -ENODEV; in sophgo_pconf_set()
271 if (pctrl->data->cfg_ops->compute_pinconf_config(pctrl, pin, in sophgo_pconf_set()
273 &value, &mask)) in sophgo_pconf_set()
274 return -ENOTSUPP; in sophgo_pconf_set()
276 return sophgo_pin_set_config(pctrl, pin_id, value, mask); in sophgo_pconf_set()
279 int sophgo_pconf_group_set(struct pinctrl_dev *pctldev, unsigned int gsel, in sophgo_pconf_group_set()
280 unsigned long *configs, unsigned int num_configs) in sophgo_pconf_group_set()
285 u32 value, mask; in sophgo_pconf_group_set() local
286 int i; in sophgo_pconf_group_set()
290 return -EINVAL; in sophgo_pconf_group_set()
292 pinmuxs = group->data; in sophgo_pconf_group_set()
294 if (pctrl->data->cfg_ops->compute_pinconf_config(pctrl, pinmuxs[0].pin, in sophgo_pconf_group_set()
296 &value, &mask)) in sophgo_pconf_group_set()
297 return -ENOTSUPP; in sophgo_pconf_group_set()
299 for (i = 0; i < group->grp.npins; i++) in sophgo_pconf_group_set()
300 sophgo_pin_set_config(pctrl, group->grp.pins[i], value, mask); in sophgo_pconf_group_set()
309 return pctrl->data->vddio_ops->get_pull_down(pin, power_cfg); in sophgo_pinctrl_typical_pull_down()
316 return pctrl->data->vddio_ops->get_pull_up(pin, power_cfg); in sophgo_pinctrl_typical_pull_up()
319 int sophgo_pinctrl_oc2reg(struct sophgo_pinctrl *pctrl, in sophgo_pinctrl_oc2reg()
323 const u32 *map; in sophgo_pinctrl_oc2reg() local
324 int i, len; in sophgo_pinctrl_oc2reg()
326 if (!pctrl->data->vddio_ops->get_oc_map) in sophgo_pinctrl_oc2reg()
327 return -ENOTSUPP; in sophgo_pinctrl_oc2reg()
329 len = pctrl->data->vddio_ops->get_oc_map(pin, power_cfg, &map); in sophgo_pinctrl_oc2reg()
334 if (map[i] >= target) in sophgo_pinctrl_oc2reg()
338 return -EINVAL; in sophgo_pinctrl_oc2reg()
341 int sophgo_pinctrl_reg2oc(struct sophgo_pinctrl *pctrl, in sophgo_pinctrl_reg2oc()
345 const u32 *map; in sophgo_pinctrl_reg2oc() local
346 int len; in sophgo_pinctrl_reg2oc()
348 if (!pctrl->data->vddio_ops->get_oc_map) in sophgo_pinctrl_reg2oc()
349 return -ENOTSUPP; in sophgo_pinctrl_reg2oc()
351 len = pctrl->data->vddio_ops->get_oc_map(pin, power_cfg, &map); in sophgo_pinctrl_reg2oc()
356 return -EINVAL; in sophgo_pinctrl_reg2oc()
358 return map[reg]; in sophgo_pinctrl_reg2oc()
361 int sophgo_pinctrl_schmitt2reg(struct sophgo_pinctrl *pctrl, in sophgo_pinctrl_schmitt2reg()
365 const u32 *map; in sophgo_pinctrl_schmitt2reg() local
366 int i, len; in sophgo_pinctrl_schmitt2reg()
368 if (!pctrl->data->vddio_ops->get_schmitt_map) in sophgo_pinctrl_schmitt2reg()
369 return -ENOTSUPP; in sophgo_pinctrl_schmitt2reg()
371 len = pctrl->data->vddio_ops->get_schmitt_map(pin, power_cfg, &map); in sophgo_pinctrl_schmitt2reg()
376 if (map[i] == target) in sophgo_pinctrl_schmitt2reg()
380 return -EINVAL; in sophgo_pinctrl_schmitt2reg()
383 int sophgo_pinctrl_reg2schmitt(struct sophgo_pinctrl *pctrl, in sophgo_pinctrl_reg2schmitt()
387 const u32 *map; in sophgo_pinctrl_reg2schmitt() local
388 int len; in sophgo_pinctrl_reg2schmitt()
390 if (!pctrl->data->vddio_ops->get_schmitt_map) in sophgo_pinctrl_reg2schmitt()
391 return -ENOTSUPP; in sophgo_pinctrl_reg2schmitt()
393 len = pctrl->data->vddio_ops->get_schmitt_map(pin, power_cfg, &map); in sophgo_pinctrl_reg2schmitt()
398 return -EINVAL; in sophgo_pinctrl_reg2schmitt()
400 return map[reg]; in sophgo_pinctrl_reg2schmitt()
403 int sophgo_pinctrl_probe(struct platform_device *pdev) in sophgo_pinctrl_probe()
405 struct device *dev = &pdev->dev; in sophgo_pinctrl_probe()
408 int ret; in sophgo_pinctrl_probe()
412 return -ENODEV; in sophgo_pinctrl_probe()
414 if (pctrl_data->npins == 0) in sophgo_pinctrl_probe()
415 return dev_err_probe(dev, -EINVAL, "invalid pin data\n"); in sophgo_pinctrl_probe()
419 return -ENOMEM; in sophgo_pinctrl_probe()
421 pctrl->pdesc.name = dev_name(dev); in sophgo_pinctrl_probe()
422 pctrl->pdesc.pins = pctrl_data->pins; in sophgo_pinctrl_probe()
423 pctrl->pdesc.npins = pctrl_data->npins; in sophgo_pinctrl_probe()
424 pctrl->pdesc.pctlops = pctrl_data->pctl_ops; in sophgo_pinctrl_probe()
425 pctrl->pdesc.pmxops = pctrl_data->pmx_ops; in sophgo_pinctrl_probe()
426 pctrl->pdesc.confops = pctrl_data->pconf_ops; in sophgo_pinctrl_probe()
427 pctrl->pdesc.owner = THIS_MODULE; in sophgo_pinctrl_probe()
429 pctrl->data = pctrl_data; in sophgo_pinctrl_probe()
430 pctrl->dev = dev; in sophgo_pinctrl_probe()
431 raw_spin_lock_init(&pctrl->lock); in sophgo_pinctrl_probe()
432 mutex_init(&pctrl->mutex); in sophgo_pinctrl_probe()
434 ret = pctrl->data->cfg_ops->pctrl_init(pdev, pctrl); in sophgo_pinctrl_probe()
440 ret = devm_pinctrl_register_and_init(dev, &pctrl->pdesc, in sophgo_pinctrl_probe()
441 pctrl, &pctrl->pctrl_dev); in sophgo_pinctrl_probe()
446 return pinctrl_enable(pctrl->pctrl_dev); in sophgo_pinctrl_probe()