15 #include <linux/slab.h>
16 #include <linux/export.h>
18 #include <linux/module.h>
27 #include <lantiq_soc.h>
30 #define LTQ_PADC_MUX(x) (x * 0x4)
32 #define LTQ_PADC_PUEN 0x80
34 #define LTQ_PADC_PDEN 0x84
36 #define LTQ_PADC_SRC 0x88
38 #define LTQ_PADC_DCC 0x8C
40 #define LTQ_PADC_AVAIL 0xF0
42 #define pad_r32(p, reg) ltq_r32(p + reg)
43 #define pad_w32(p, val, reg) ltq_w32(val, p + reg)
44 #define pad_w32_mask(c, clear, set, reg) \
45 pad_w32(c, (pad_r32(c, reg) & ~(clear)) | (set), reg)
47 #define pad_getbit(m, r, p) (!!(ltq_r32(m + r) & (1 << p)))
51 #define PORT(x) (x / PINS)
52 #define PORT_PIN(x) (x % PINS)
54 #define MFP_FALCON(a, f0, f1, f2, f3) \
66 #define GRP_MUX(a, m, p) \
69 .mux = FALCON_MUX_##m, \
71 .npins = ARRAY_SIZE(p), \
92 static struct pinctrl_pin_desc falcon_pads[
PORTS *
PINS];
93 static int pad_count[
PORTS];
95 static void lantiq_load_pin_desc(
struct pinctrl_pin_desc *
d,
int bank,
int len)
100 for (i = 0; i < len; i++) {
103 snprintf(name, 6,
"io%d", base + i);
104 d[
i].number = base +
i;
107 pad_count[bank] = len;
168 static const unsigned pins_por[] = {
GPIO0};
169 static const unsigned pins_ntr[] = {
GPIO4};
170 static const unsigned pins_ntr8k[] = {
GPIO5};
171 static const unsigned pins_hrst[] = {
GPIO6};
172 static const unsigned pins_mdio[] = {
GPIO7,
GPIO8};
177 static const unsigned pins_spi_cs0[] = {
GPIO37};
178 static const unsigned pins_spi_cs1[] = {
GPIO38};
180 static const unsigned pins_jtag[] = {
GPIO41};
188 GRP_MUX(
"ntr8k", NTR, pins_ntr8k),
197 GRP_MUX(
"jtag", JTAG, pins_jtag),
198 GRP_MUX(
"slic", SLIC, pins_slic),
203 static const char *
const ltq_rst_grps[] = {
"por",
"hrst"};
204 static const char *
const ltq_ntr_grps[] = {
"ntr",
"ntr8k"};
205 static const char *
const ltq_mdio_grps[] = {
"mdio"};
206 static const char *
const ltq_bled_grps[] = {
"bootled"};
207 static const char *
const ltq_asc_grps[] = {
"asc0",
"asc1"};
208 static const char *
const ltq_spi_grps[] = {
"spi",
"spi cs0",
"spi cs1"};
209 static const char *
const ltq_i2c_grps[] = {
"i2c"};
210 static const char *
const ltq_jtag_grps[] = {
"jtag"};
211 static const char *
const ltq_slic_grps[] = {
"slic"};
212 static const char *
const ltq_pcm_grps[] = {
"pcm"};
231 static int falcon_pinconf_group_get(
struct pinctrl_dev *pctrldev,
237 static int falcon_pinconf_group_set(
struct pinctrl_dev *pctrldev,
243 static int falcon_pinconf_get(
struct pinctrl_dev *pctrldev,
278 static int falcon_pinconf_set(
struct pinctrl_dev *pctrldev,
279 unsigned pin,
unsigned long config)
304 pr_err(
"%s: Invalid config param %04x\n",
315 static void falcon_pinconf_dbg_show(
struct pinctrl_dev *pctrldev,
320 static void falcon_pinconf_group_dbg_show(
struct pinctrl_dev *pctrldev,
326 .pin_config_get = falcon_pinconf_get,
327 .pin_config_set = falcon_pinconf_set,
328 .pin_config_group_get = falcon_pinconf_group_get,
329 .pin_config_group_set = falcon_pinconf_group_set,
330 .pin_config_dbg_show = falcon_pinconf_dbg_show,
331 .pin_config_group_dbg_show = falcon_pinconf_group_dbg_show,
334 static struct pinctrl_desc falcon_pctrl_desc = {
340 static inline int falcon_mux_apply(
struct pinctrl_dev *pctrldev,
361 .desc = &falcon_pctrl_desc,
362 .apply_mux = falcon_mux_apply,
394 for_each_compatible_node(np,
NULL,
"lantiq,pad-falcon") {
402 dev_err(&pdev->
dev,
"failed to find pad pdev\n");
405 if (!bank || *bank >=
PORTS)
410 if (IS_ERR(falcon_info.
clk[*bank])) {
411 dev_err(&ppdev->
dev,
"failed to get clock\n");
412 return PTR_ERR(falcon_info.
clk[*bank]);
416 if (!falcon_info.
membase[*bank]) {
418 "Failed to remap memory for bank %d\n",
425 lantiq_load_pin_desc(&falcon_pads[pad_count], *bank, pins);
428 dev_dbg(&pdev->
dev,
"found %s with %d pads\n",
431 dev_dbg(&pdev->
dev,
"found a total of %d pads\n", pad_count);
432 falcon_pctrl_desc.name = dev_name(&pdev->
dev);
433 falcon_pctrl_desc.npins = pad_count;
435 falcon_info.
mfp = falcon_mfp;
437 falcon_info.
grps = falcon_grps;
439 falcon_info.
funcs = falcon_funcs;
449 { .compatible =
"lantiq,pinctrl-falcon" },
455 .probe = pinctrl_falcon_probe,
457 .name =
"pinctrl-falcon",
459 .of_match_table = falcon_match,