u-boot/drivers/pinctrl/mtmips/pinctrl-mtmips-common.c
Simon Glass 336d4615f8 dm: core: Create a new header file for 'compat' features
At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-02-05 19:33:46 -07:00

88 lines
1.9 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc. All Rights Reserved.
*
* Author: Weijie Gao <weijie.gao@mediatek.com>
*/
#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <dm/pinctrl.h>
#include <linux/io.h>
#include "pinctrl-mtmips-common.h"
static void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
u32 reg, u32 shift, u32 mask, u32 value)
{
u32 val;
val = readl(priv->base + reg);
val &= ~(mask << shift);
val |= value << shift;
writel(val, priv->base + reg);
}
int mtmips_get_functions_count(struct udevice *dev)
{
struct mtmips_pinctrl_priv *priv = dev_get_priv(dev);
return priv->nfuncs;
}
const char *mtmips_get_function_name(struct udevice *dev, unsigned int selector)
{
struct mtmips_pinctrl_priv *priv = dev_get_priv(dev);
return priv->funcs[selector]->name;
}
int mtmips_pinmux_group_set(struct udevice *dev, unsigned int group_selector,
unsigned int func_selector)
{
struct mtmips_pinctrl_priv *priv = dev_get_priv(dev);
const struct mtmips_pmx_group *grp = &priv->groups[group_selector];
const struct mtmips_pmx_func *func = priv->funcs[func_selector];
int i;
if (!grp->nfuncs)
return 0;
for (i = 0; i < grp->nfuncs; i++) {
if (!strcmp(grp->funcs[i].name, func->name)) {
mtmips_pinctrl_reg_set(priv, grp->reg, grp->shift,
grp->mask, grp->funcs[i].value);
return 0;
}
}
return -EINVAL;
}
int mtmips_pinctrl_probe(struct mtmips_pinctrl_priv *priv, u32 ngroups,
const struct mtmips_pmx_group *groups)
{
int i, j, n;
priv->ngroups = ngroups;
priv->groups = groups;
priv->nfuncs = 0;
for (i = 0; i < ngroups; i++)
priv->nfuncs += groups[i].nfuncs;
priv->funcs = malloc(priv->nfuncs * sizeof(*priv->funcs));
if (!priv->funcs)
return -ENOMEM;
n = 0;
for (i = 0; i < ngroups; i++) {
for (j = 0; j < groups[i].nfuncs; j++)
priv->funcs[n++] = &groups[i].funcs[j];
}
return 0;
}