blob: a0eccf8d4a80c7145ac6943e52cc03e833471258 [file] [log] [blame]
Masahiro Yamada5dc626f2015-09-11 20:17:32 +09001/*
Masahiro Yamada4e3d8402016-07-19 21:56:13 +09002 * Copyright (C) 2015-2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada5dc626f2015-09-11 20:17:32 +09004 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#ifndef __PINCTRL_UNIPHIER_H__
9#define __PINCTRL_UNIPHIER_H__
10
Masahiro Yamada8cc92b92016-03-24 22:32:44 +090011#include <linux/bitops.h>
Masahiro Yamada84b8bf62016-01-24 23:27:48 +090012#include <linux/bug.h>
Masahiro Yamada5dc626f2015-09-11 20:17:32 +090013#include <linux/kernel.h>
14#include <linux/types.h>
15
Masahiro Yamada5dc626f2015-09-11 20:17:32 +090016#define UNIPHIER_PIN_ATTR_PACKED(iectrl) (iectrl)
17
18static inline unsigned int uniphier_pin_get_iectrl(unsigned long data)
19{
20 return data;
21}
22
23/**
24 * struct uniphier_pinctrl_pin - pin data for UniPhier SoC
25 *
26 * @number: pin number
27 * @data: additional per-pin data
28 */
29struct uniphier_pinctrl_pin {
30 unsigned number;
31 unsigned long data;
32};
33
34/**
35 * struct uniphier_pinctrl_group - pin group data for UniPhier SoC
36 *
37 * @name: pin group name
38 * @pins: array of pins that belong to the group
39 * @num_pins: number of pins in the group
40 * @muxvals: array of values to be set to pinmux registers
41 */
42struct uniphier_pinctrl_group {
43 const char *name;
44 const unsigned *pins;
45 unsigned num_pins;
Masahiro Yamada5e25b9d2016-06-29 19:38:59 +090046 const int *muxvals;
Masahiro Yamada5dc626f2015-09-11 20:17:32 +090047};
48
49/**
50 * struct uniphier_pinctrl_socdata - SoC data for UniPhier pin controller
51 *
52 * @pins: array of pin data
53 * @pins_count: number of pin data
54 * @groups: array of pin group data
55 * @groups_count: number of pin group data
56 * @functions: array of pinmux function names
57 * @functions_count: number of pinmux functions
58 * @mux_bits: bit width of each pinmux register
59 * @reg_stride: stride of pinmux register address
Masahiro Yamada8cc92b92016-03-24 22:32:44 +090060 * @caps: SoC-specific capability flag
Masahiro Yamada5dc626f2015-09-11 20:17:32 +090061 */
62struct uniphier_pinctrl_socdata {
63 const struct uniphier_pinctrl_pin *pins;
64 int pins_count;
65 const struct uniphier_pinctrl_group *groups;
66 int groups_count;
67 const char * const *functions;
68 int functions_count;
Masahiro Yamada8cc92b92016-03-24 22:32:44 +090069 unsigned caps;
Masahiro Yamada6a6b9d52017-02-12 18:21:15 +090070#define UNIPHIER_PINCTRL_CAPS_PUPD_SIMPLE BIT(3)
Masahiro Yamadabbb11982016-09-17 03:32:58 +090071#define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(2)
72#define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(1)
73#define UNIPHIER_PINCTRL_CAPS_MUX_4BIT BIT(0)
Masahiro Yamada5dc626f2015-09-11 20:17:32 +090074};
75
76#define UNIPHIER_PINCTRL_PIN(a, b) \
77{ \
78 .number = a, \
79 .data = UNIPHIER_PIN_ATTR_PACKED(b), \
80}
81
Masahiro Yamada64c1cc42016-06-29 19:39:00 +090082#define __UNIPHIER_PINCTRL_GROUP(grp) \
Masahiro Yamada5dc626f2015-09-11 20:17:32 +090083 { \
84 .name = #grp, \
85 .pins = grp##_pins, \
86 .num_pins = ARRAY_SIZE(grp##_pins), \
87 .muxvals = grp##_muxvals + \
88 BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
89 ARRAY_SIZE(grp##_muxvals)), \
90 }
91
Masahiro Yamada64c1cc42016-06-29 19:39:00 +090092#define __UNIPHIER_PINMUX_FUNCTION(func) #func
93
94#ifdef CONFIG_SPL_BUILD
Masahiro Yamada935e09c2016-10-09 23:52:57 +090095 /*
96 * a tricky way to drop unneeded *_pins and *_muxvals arrays from SPL,
97 * suppressing "defined but not used" warnings.
98 */
99#define UNIPHIER_PINCTRL_GROUP(grp) \
100 { .num_pins = ARRAY_SIZE(grp##_pins) + ARRAY_SIZE(grp##_muxvals) }
Masahiro Yamada64c1cc42016-06-29 19:39:00 +0900101#define UNIPHIER_PINMUX_FUNCTION(func) NULL
102#else
103#define UNIPHIER_PINCTRL_GROUP(grp) __UNIPHIER_PINCTRL_GROUP(grp)
104#define UNIPHIER_PINMUX_FUNCTION(func) __UNIPHIER_PINMUX_FUNCTION(func)
105#endif
106
107#define UNIPHIER_PINCTRL_GROUP_SPL(grp) __UNIPHIER_PINCTRL_GROUP(grp)
108#define UNIPHIER_PINMUX_FUNCTION_SPL(func) __UNIPHIER_PINMUX_FUNCTION(func)
109
Masahiro Yamada5dc626f2015-09-11 20:17:32 +0900110/**
111 * struct uniphier_pinctrl_priv - private data for UniPhier pinctrl driver
112 *
113 * @base: base address of the pinctrl device
114 * @socdata: SoC specific data
115 */
116struct uniphier_pinctrl_priv {
117 void __iomem *base;
118 struct uniphier_pinctrl_socdata *socdata;
119};
120
121extern const struct pinctrl_ops uniphier_pinctrl_ops;
122
123int uniphier_pinctrl_probe(struct udevice *dev,
124 struct uniphier_pinctrl_socdata *socdata);
125
Masahiro Yamada5dc626f2015-09-11 20:17:32 +0900126#endif /* __PINCTRL_UNIPHIER_H__ */