blob: 6b01f47657cab2ba7bcef1f289f179b60b021a83 [file] [log] [blame]
Stefan Bosch8d393b22020-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>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Stefan Bosch8d393b22020-07-10 19:07:30 +020012#include <asm/io.h>
13#include "pinctrl-nexell.h"
14#include "pinctrl-s5pxx18.h"
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/* given a pin-name, return the address of pin config registers */
19unsigned long pin_to_bank_base(struct udevice *dev, const char *pin_name,
20 u32 *pin)
21{
22 struct nexell_pinctrl_priv *priv = dev_get_priv(dev);
23 const struct nexell_pin_ctrl *pin_ctrl = priv->pin_ctrl;
24 const struct nexell_pin_bank_data *bank_data = pin_ctrl->pin_banks;
25 u32 nr_banks = pin_ctrl->nr_banks, idx = 0;
26 char bank[10];
27
28 /*
29 * The format of the pin name is <bank name>-<pin_number>.
30 * Example: gpioa-4 (gpioa is the bank name and 4 is the pin number)
31 */
32 while (pin_name[idx] != '-') {
33 bank[idx] = pin_name[idx];
34 idx++;
35 }
36 bank[idx] = '\0';
37 *pin = (u32)simple_strtoul(&pin_name[++idx], NULL, 10);
38
39 /* lookup the pin bank data using the pin bank name */
40 for (idx = 0; idx < nr_banks; idx++)
41 if (!strcmp(bank, bank_data[idx].name))
42 break;
43
44 return priv->base + bank_data[idx].offset;
45}
46
47int nexell_pinctrl_probe(struct udevice *dev)
48{
49 struct nexell_pinctrl_priv *priv;
50 fdt_addr_t base;
51
52 priv = dev_get_priv(dev);
53 if (!priv)
54 return -EINVAL;
55
56 base = devfdt_get_addr(dev);
57 if (base == FDT_ADDR_T_NONE)
58 return -EINVAL;
59
60 priv->base = base;
61
62 priv->pin_ctrl = (struct nexell_pin_ctrl *)dev_get_driver_data(dev);
63
64 s5pxx18_pinctrl_init(dev);
65
66 return 0;
67}