18 #include <linux/module.h>
25 #include <linux/slab.h>
29 #define DRIVER_NAME "spear-pinmux"
38 writel_relaxed(val, pmx->
vbase + reg);
50 for (i = 0; i < pmx->
machdata->npmx_modes; i++) {
51 if (pmx->
machdata->pmx_modes[i]->mode == (1 << mode)) {
60 val = pmx_readl(pmx, pmx_mode->
reg);
61 val &= ~pmx_mode->
mask;
63 pmx_writel(pmx, val, pmx_mode->
reg);
66 dev_info(pmx->
dev,
"Configured Mode: %s with id: %x\n\n",
67 pmx_mode->
name ? pmx_mode->
name :
"no_name",
79 for (group = 0; group < machdata->
ngroups; group++) {
85 for (j = 0; j < modemux->
nmuxregs; j++)
86 if (modemux->
muxregs[j].reg == 0xFFFF)
92 static int spear_pinctrl_get_groups_cnt(
struct pinctrl_dev *pctldev)
99 static const char *spear_pinctrl_get_group_name(
struct pinctrl_dev *pctldev,
107 static int spear_pinctrl_get_group_pins(
struct pinctrl_dev *pctldev,
108 unsigned group,
const unsigned **
pins,
unsigned *num_pins)
118 static void spear_pinctrl_pin_dbg_show(
struct pinctrl_dev *pctldev,
131 const char *
function, *
group;
148 dev_err(pmx->
dev,
"No child nodes passed via DT\n");
161 (*map)[
index].data.mux.function =
function;
177 static struct pinctrl_ops spear_pinctrl_ops = {
178 .get_groups_count = spear_pinctrl_get_groups_cnt,
179 .get_group_name = spear_pinctrl_get_group_name,
180 .get_group_pins = spear_pinctrl_get_group_pins,
181 .pin_dbg_show = spear_pinctrl_pin_dbg_show,
186 static int spear_pinctrl_get_funcs_count(
struct pinctrl_dev *pctldev)
193 static const char *spear_pinctrl_get_func_name(
struct pinctrl_dev *pctldev,
198 return pmx->
machdata->functions[
function]->name;
201 static int spear_pinctrl_get_func_groups(
struct pinctrl_dev *pctldev,
202 unsigned function,
const char *
const **groups,
203 unsigned *
const ngroups)
207 *groups = pmx->
machdata->functions[
function]->groups;
208 *ngroups = pmx->
machdata->functions[
function]->ngroups;
213 static int spear_pinctrl_endisable(
struct pinctrl_dev *pctldev,
226 for (i = 0; i < pgroup->
nmodemuxs; i++) {
230 if (pmx->
machdata->modes_supported) {
236 for (j = 0; j < modemux->
nmuxregs; j++) {
239 val = pmx_readl(pmx, muxreg->
reg);
240 val &= ~muxreg->
mask;
248 pmx_writel(pmx, val, muxreg->
reg);
253 dev_err(pmx->
dev,
"pinmux group: %s not supported\n",
261 static int spear_pinctrl_enable(
struct pinctrl_dev *pctldev,
unsigned function,
264 return spear_pinctrl_endisable(pctldev,
function, group,
true);
267 static void spear_pinctrl_disable(
struct pinctrl_dev *pctldev,
268 unsigned function,
unsigned group)
270 spear_pinctrl_endisable(pctldev,
function, group,
false);
273 static struct pinmux_ops spear_pinmux_ops = {
274 .get_functions_count = spear_pinctrl_get_funcs_count,
275 .get_function_name = spear_pinctrl_get_func_name,
276 .get_function_groups = spear_pinctrl_get_func_groups,
277 .enable = spear_pinctrl_enable,
278 .disable = spear_pinctrl_disable,
281 static struct pinctrl_desc spear_pinctrl_desc = {
283 .pctlops = &spear_pinctrl_ops,
284 .pmxops = &spear_pinmux_ops,
304 dev_err(&pdev->
dev,
"Can't alloc spear_pmx\n");
310 dev_err(&pdev->
dev,
"Couldn't ioremap at index 0\n");
321 if (of_property_read_u32(np,
"st,pinmux-mode", &mode)) {
322 dev_err(&pdev->
dev,
"OF: pinmux mode not passed\n");
327 dev_err(&pdev->
dev,
"OF: Couldn't configure mode: %x\n",
333 platform_set_drvdata(pdev, pmx);
335 spear_pinctrl_desc.pins = machdata->
pins;
336 spear_pinctrl_desc.npins = machdata->
npins;
340 dev_err(&pdev->
dev,
"Couldn't register pinctrl driver\n");
349 struct spear_pmx *pmx = platform_get_drvdata(pdev);