summaryrefslogtreecommitdiff
path: root/drivers/pinctrl/mscc/pinctrl-ocelot.c
blob: 49e026bc98b8ee786210968c4bd70b15b05e4e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
 * Microsemi SoCs pinctrl driver
 *
 * Author: <alexandre.belloni@free-electrons.com>
 * Author: <gregory.clement@bootlin.com>
 * License: Dual MIT/GPL
 * Copyright (c) 2017 Microsemi Corporation
 */

#include <asm/gpio.h>
#include <asm/system.h>
#include <common.h>
#include <config.h>
#include <dm.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dm/pinctrl.h>
#include <dm/root.h>
#include <errno.h>
#include <fdtdec.h>
#include <linux/io.h>
#include "mscc-common.h"

enum {
	FUNC_NONE,
	FUNC_GPIO,
	FUNC_IRQ0_IN,
	FUNC_IRQ0_OUT,
	FUNC_IRQ1_IN,
	FUNC_IRQ1_OUT,
	FUNC_MIIM1,
	FUNC_PCI_WAKE,
	FUNC_PTP0,
	FUNC_PTP1,
	FUNC_PTP2,
	FUNC_PTP3,
	FUNC_PWM,
	FUNC_RECO_CLK0,
	FUNC_RECO_CLK1,
	FUNC_SFP0,
	FUNC_SFP1,
	FUNC_SFP2,
	FUNC_SFP3,
	FUNC_SFP4,
	FUNC_SFP5,
	FUNC_SG0,
	FUNC_SI,
	FUNC_TACHO,
	FUNC_TWI,
	FUNC_TWI_SCL_M,
	FUNC_UART,
	FUNC_UART2,
	FUNC_MAX
};

static char * const ocelot_function_names[] = {
	[FUNC_NONE]		= "none",
	[FUNC_GPIO]		= "gpio",
	[FUNC_IRQ0_IN]		= "irq0_in",
	[FUNC_IRQ0_OUT]		= "irq0_out",
	[FUNC_IRQ1_IN]		= "irq1_in",
	[FUNC_IRQ1_OUT]		= "irq1_out",
	[FUNC_MIIM1]		= "miim1",
	[FUNC_PCI_WAKE]		= "pci_wake",
	[FUNC_PTP0]		= "ptp0",
	[FUNC_PTP1]		= "ptp1",
	[FUNC_PTP2]		= "ptp2",
	[FUNC_PTP3]		= "ptp3",
	[FUNC_PWM]		= "pwm",
	[FUNC_RECO_CLK0]	= "reco_clk0",
	[FUNC_RECO_CLK1]	= "reco_clk1",
	[FUNC_SFP0]		= "sfp0",
	[FUNC_SFP1]		= "sfp1",
	[FUNC_SFP2]		= "sfp2",
	[FUNC_SFP3]		= "sfp3",
	[FUNC_SFP4]		= "sfp4",
	[FUNC_SFP5]		= "sfp5",
	[FUNC_SG0]		= "sg0",
	[FUNC_SI]		= "si",
	[FUNC_TACHO]		= "tacho",
	[FUNC_TWI]		= "twi",
	[FUNC_TWI_SCL_M]	= "twi_scl_m",
	[FUNC_UART]		= "uart",
	[FUNC_UART2]		= "uart2",
};

MSCC_P(0,  SG0,       NONE,      NONE);
MSCC_P(1,  SG0,       NONE,      NONE);
MSCC_P(2,  SG0,       NONE,      NONE);
MSCC_P(3,  SG0,       NONE,      NONE);
MSCC_P(4,  IRQ0_IN,   IRQ0_OUT,  TWI);
MSCC_P(5,  IRQ1_IN,   IRQ1_OUT,  PCI_WAKE);
MSCC_P(6,  UART,      TWI_SCL_M, NONE);
MSCC_P(7,  UART,      TWI_SCL_M, NONE);
MSCC_P(8,  SI,        TWI_SCL_M, IRQ0_OUT);
MSCC_P(9,  SI,        TWI_SCL_M, IRQ1_OUT);
MSCC_P(10, PTP2,      TWI_SCL_M, SFP0);
MSCC_P(11, PTP3,      TWI_SCL_M, SFP1);
MSCC_P(12, UART2,     TWI_SCL_M, SFP2);
MSCC_P(13, UART2,     TWI_SCL_M, SFP3);
MSCC_P(14, MIIM1,     TWI_SCL_M, SFP4);
MSCC_P(15, MIIM1,     TWI_SCL_M, SFP5);
MSCC_P(16, TWI,       NONE,      SI);
MSCC_P(17, TWI,       TWI_SCL_M, SI);
MSCC_P(18, PTP0,      TWI_SCL_M, NONE);
MSCC_P(19, PTP1,      TWI_SCL_M, NONE);
MSCC_P(20, RECO_CLK0, TACHO,     NONE);
MSCC_P(21, RECO_CLK1, PWM,       NONE);

#define OCELOT_PIN(n) {						\
	.name = "GPIO_"#n,					\
	.drv_data = &mscc_pin_##n				\
}

static const struct mscc_pin_data ocelot_pins[] = {
	OCELOT_PIN(0),
	OCELOT_PIN(1),
	OCELOT_PIN(2),
	OCELOT_PIN(3),
	OCELOT_PIN(4),
	OCELOT_PIN(5),
	OCELOT_PIN(6),
	OCELOT_PIN(7),
	OCELOT_PIN(8),
	OCELOT_PIN(9),
	OCELOT_PIN(10),
	OCELOT_PIN(11),
	OCELOT_PIN(12),
	OCELOT_PIN(13),
	OCELOT_PIN(14),
	OCELOT_PIN(15),
	OCELOT_PIN(16),
	OCELOT_PIN(17),
	OCELOT_PIN(18),
	OCELOT_PIN(19),
	OCELOT_PIN(20),
	OCELOT_PIN(21),
};

static const unsigned long ocelot_gpios[] = {
	[MSCC_GPIO_OUT_SET] = 0x00,
	[MSCC_GPIO_OUT_CLR] = 0x04,
	[MSCC_GPIO_OUT] = 0x08,
	[MSCC_GPIO_IN] = 0x0c,
	[MSCC_GPIO_OE] = 0x10,
	[MSCC_GPIO_INTR] = 0x14,
	[MSCC_GPIO_INTR_ENA] = 0x18,
	[MSCC_GPIO_INTR_IDENT] = 0x1c,
	[MSCC_GPIO_ALT0] = 0x20,
	[MSCC_GPIO_ALT1] = 0x24,
};

static int ocelot_gpio_probe(struct udevice *dev)
{
	struct gpio_dev_priv *uc_priv;

	uc_priv = dev_get_uclass_priv(dev);
	uc_priv->bank_name = "ocelot-gpio";
	uc_priv->gpio_count = ARRAY_SIZE(ocelot_pins);

	return 0;
}

static struct driver ocelot_gpio_driver = {
	.name	= "ocelot-gpio",
	.id	= UCLASS_GPIO,
	.probe	= ocelot_gpio_probe,
	.ops	= &mscc_gpio_ops,
};

int ocelot_pinctrl_probe(struct udevice *dev)
{
	int ret;

	ret = mscc_pinctrl_probe(dev, FUNC_MAX, ocelot_pins,
				 ARRAY_SIZE(ocelot_pins),
				 ocelot_function_names,
				 ocelot_gpios);

	if (ret)
		return ret;

	ret = device_bind(dev, &ocelot_gpio_driver, "ocelot-gpio", NULL,
			  dev_of_offset(dev), NULL);

	return ret;
}

static const struct udevice_id ocelot_pinctrl_of_match[] = {
	{.compatible = "mscc,ocelot-pinctrl"},
	{},
};

U_BOOT_DRIVER(ocelot_pinctrl) = {
	.name = "ocelot-pinctrl",
	.id = UCLASS_PINCTRL,
	.of_match = of_match_ptr(ocelot_pinctrl_of_match),
	.probe = ocelot_pinctrl_probe,
	.priv_auto_alloc_size = sizeof(struct mscc_pinctrl),
	.ops = &mscc_pinctrl_ops,
};