blob: 4518c05d46859d70e1c5426ad9c0a2bb346b970f [file] [log] [blame]
Stefan Boschbe278c12020-07-10 19:07:30 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Pinctrl driver for Nexell SoCs
4 * (C) Copyright 2016 Nexell
5 * Bongyu, KOO <freestyle@nexell.co.kr>
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <errno.h>
11#include <asm/io.h>
12#include "pinctrl-nexell.h"
13#include "pinctrl-s5pxx18.h"
14
15DECLARE_GLOBAL_DATA_PTR;
16
17/* given a pin-name, return the address of pin config registers */
18unsigned long pin_to_bank_base(struct udevice *dev, const char *pin_name,
19 u32 *pin)
20{
21 struct nexell_pinctrl_priv *priv = dev_get_priv(dev);
22 const struct nexell_pin_ctrl *pin_ctrl = priv->pin_ctrl;
23 const struct nexell_pin_bank_data *bank_data = pin_ctrl->pin_banks;
24 u32 nr_banks = pin_ctrl->nr_banks, idx = 0;
25 char bank[10];
26
27 /*
28 * The format of the pin name is <bank name>-<pin_number>.
29 * Example: gpioa-4 (gpioa is the bank name and 4 is the pin number)
30 */
31 while (pin_name[idx] != '-') {
32 bank[idx] = pin_name[idx];
33 idx++;
34 }
35 bank[idx] = '\0';
36 *pin = (u32)simple_strtoul(&pin_name[++idx], NULL, 10);
37
38 /* lookup the pin bank data using the pin bank name */
39 for (idx = 0; idx < nr_banks; idx++)
40 if (!strcmp(bank, bank_data[idx].name))
41 break;
42
43 return priv->base + bank_data[idx].offset;
44}
45
46int nexell_pinctrl_probe(struct udevice *dev)
47{
48 struct nexell_pinctrl_priv *priv;
49 fdt_addr_t base;
50
51 priv = dev_get_priv(dev);
52 if (!priv)
53 return -EINVAL;
54
55 base = devfdt_get_addr(dev);
56 if (base == FDT_ADDR_T_NONE)
57 return -EINVAL;
58
59 priv->base = base;
60
61 priv->pin_ctrl = (struct nexell_pin_ctrl *)dev_get_driver_data(dev);
62
63 s5pxx18_pinctrl_init(dev);
64
65 return 0;
66}