blob: 8f83ecae7dbabcd31a21f6e3f3beedf0544d1707 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Masahiro Yamada847e618b82015-09-11 20:17:32 +09002/*
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09003 * Copyright (C) 2015-2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada847e618b82015-09-11 20:17:32 +09005 */
6
7#ifndef __PINCTRL_UNIPHIER_H__
8#define __PINCTRL_UNIPHIER_H__
9
Masahiro Yamada7a629ef2016-03-24 22:32:44 +090010#include <linux/bitops.h>
Masahiro Yamada17ca7f22018-05-05 19:53:53 +090011#include <linux/build_bug.h>
Masahiro Yamada847e618b82015-09-11 20:17:32 +090012#include <linux/kernel.h>
13#include <linux/types.h>
14
Masahiro Yamadae5299ed2018-05-05 19:53:55 +090015/* drive strength control register number */
16#define UNIPHIER_PIN_DRVCTRL_SHIFT 0
17#define UNIPHIER_PIN_DRVCTRL_BITS 9
18#define UNIPHIER_PIN_DRVCTRL_MASK ((1U << (UNIPHIER_PIN_DRVCTRL_BITS)) \
19 - 1)
Masahiro Yamada847e618b82015-09-11 20:17:32 +090020
Masahiro Yamadae5299ed2018-05-05 19:53:55 +090021/* drive control type */
22#define UNIPHIER_PIN_DRV_TYPE_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \
23 (UNIPHIER_PIN_DRVCTRL_BITS))
24#define UNIPHIER_PIN_DRV_TYPE_BITS 2
25#define UNIPHIER_PIN_DRV_TYPE_MASK ((1U << (UNIPHIER_PIN_DRV_TYPE_BITS)) \
26 - 1)
27
28/* drive control type */
29enum uniphier_pin_drv_type {
30 UNIPHIER_PIN_DRV_1BIT, /* 2 level control: 4/8 mA */
31 UNIPHIER_PIN_DRV_2BIT, /* 4 level control: 8/12/16/20 mA */
32 UNIPHIER_PIN_DRV_3BIT, /* 8 level control: 4/5/7/9/11/12/14/16 mA */
33};
34
35#define UNIPHIER_PIN_DRVCTRL(x) \
36 (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT))
37#define UNIPHIER_PIN_DRV_TYPE(x) \
38 (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT))
39
40#define UNIPHIER_PIN_ATTR_PACKED(drvctrl, drv_type) \
41 UNIPHIER_PIN_DRVCTRL(drvctrl) | \
42 UNIPHIER_PIN_DRV_TYPE(drv_type)
43
44static inline unsigned int uniphier_pin_get_drvctrl(unsigned int data)
45{
46 return (data >> UNIPHIER_PIN_DRVCTRL_SHIFT) & UNIPHIER_PIN_DRVCTRL_MASK;
47}
48
49static inline unsigned int uniphier_pin_get_drv_type(unsigned int data)
Masahiro Yamada847e618b82015-09-11 20:17:32 +090050{
Masahiro Yamadae5299ed2018-05-05 19:53:55 +090051 return (data >> UNIPHIER_PIN_DRV_TYPE_SHIFT) &
52 UNIPHIER_PIN_DRV_TYPE_MASK;
Masahiro Yamada847e618b82015-09-11 20:17:32 +090053}
54
55/**
56 * struct uniphier_pinctrl_pin - pin data for UniPhier SoC
57 *
58 * @number: pin number
59 * @data: additional per-pin data
60 */
61struct uniphier_pinctrl_pin {
62 unsigned number;
Masahiro Yamada914b5712018-05-05 19:53:54 +090063 const char *name;
64 unsigned int data;
Masahiro Yamada847e618b82015-09-11 20:17:32 +090065};
66
67/**
68 * struct uniphier_pinctrl_group - pin group data for UniPhier SoC
69 *
70 * @name: pin group name
71 * @pins: array of pins that belong to the group
72 * @num_pins: number of pins in the group
73 * @muxvals: array of values to be set to pinmux registers
74 */
75struct uniphier_pinctrl_group {
76 const char *name;
77 const unsigned *pins;
78 unsigned num_pins;
Masahiro Yamada9447e132016-06-29 19:38:59 +090079 const int *muxvals;
Masahiro Yamada847e618b82015-09-11 20:17:32 +090080};
81
82/**
83 * struct uniphier_pinctrl_socdata - SoC data for UniPhier pin controller
84 *
85 * @pins: array of pin data
86 * @pins_count: number of pin data
87 * @groups: array of pin group data
88 * @groups_count: number of pin group data
89 * @functions: array of pinmux function names
90 * @functions_count: number of pinmux functions
91 * @mux_bits: bit width of each pinmux register
92 * @reg_stride: stride of pinmux register address
Masahiro Yamada7a629ef2016-03-24 22:32:44 +090093 * @caps: SoC-specific capability flag
Masahiro Yamada847e618b82015-09-11 20:17:32 +090094 */
95struct uniphier_pinctrl_socdata {
96 const struct uniphier_pinctrl_pin *pins;
97 int pins_count;
98 const struct uniphier_pinctrl_group *groups;
99 int groups_count;
100 const char * const *functions;
101 int functions_count;
Masahiro Yamada7a629ef2016-03-24 22:32:44 +0900102 unsigned caps;
Masahiro Yamada140e9f12017-02-12 18:21:15 +0900103#define UNIPHIER_PINCTRL_CAPS_PUPD_SIMPLE BIT(3)
Masahiro Yamadac3380ed2016-09-17 03:32:58 +0900104#define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(2)
105#define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(1)
106#define UNIPHIER_PINCTRL_CAPS_MUX_4BIT BIT(0)
Masahiro Yamada847e618b82015-09-11 20:17:32 +0900107};
108
Masahiro Yamadae5299ed2018-05-05 19:53:55 +0900109#define UNIPHIER_PINCTRL_PIN(a, b, c, d) \
Masahiro Yamada847e618b82015-09-11 20:17:32 +0900110{ \
111 .number = a, \
Masahiro Yamadae5299ed2018-05-05 19:53:55 +0900112 .name = b, \
113 .data = UNIPHIER_PIN_ATTR_PACKED(c, d), \
Masahiro Yamada847e618b82015-09-11 20:17:32 +0900114}
115
Masahiro Yamada65ef4f72016-06-29 19:39:00 +0900116#define __UNIPHIER_PINCTRL_GROUP(grp) \
Masahiro Yamada847e618b82015-09-11 20:17:32 +0900117 { \
118 .name = #grp, \
119 .pins = grp##_pins, \
120 .num_pins = ARRAY_SIZE(grp##_pins), \
121 .muxvals = grp##_muxvals + \
122 BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
123 ARRAY_SIZE(grp##_muxvals)), \
124 }
125
Masahiro Yamada65ef4f72016-06-29 19:39:00 +0900126#define __UNIPHIER_PINMUX_FUNCTION(func) #func
127
128#ifdef CONFIG_SPL_BUILD
Masahiro Yamada945c4702016-10-09 23:52:57 +0900129 /*
130 * a tricky way to drop unneeded *_pins and *_muxvals arrays from SPL,
131 * suppressing "defined but not used" warnings.
132 */
133#define UNIPHIER_PINCTRL_GROUP(grp) \
134 { .num_pins = ARRAY_SIZE(grp##_pins) + ARRAY_SIZE(grp##_muxvals) }
Masahiro Yamada65ef4f72016-06-29 19:39:00 +0900135#define UNIPHIER_PINMUX_FUNCTION(func) NULL
136#else
137#define UNIPHIER_PINCTRL_GROUP(grp) __UNIPHIER_PINCTRL_GROUP(grp)
138#define UNIPHIER_PINMUX_FUNCTION(func) __UNIPHIER_PINMUX_FUNCTION(func)
139#endif
140
141#define UNIPHIER_PINCTRL_GROUP_SPL(grp) __UNIPHIER_PINCTRL_GROUP(grp)
142#define UNIPHIER_PINMUX_FUNCTION_SPL(func) __UNIPHIER_PINMUX_FUNCTION(func)
143
Masahiro Yamada847e618b82015-09-11 20:17:32 +0900144/**
145 * struct uniphier_pinctrl_priv - private data for UniPhier pinctrl driver
146 *
147 * @base: base address of the pinctrl device
148 * @socdata: SoC specific data
149 */
150struct uniphier_pinctrl_priv {
151 void __iomem *base;
152 struct uniphier_pinctrl_socdata *socdata;
153};
154
155extern const struct pinctrl_ops uniphier_pinctrl_ops;
156
157int uniphier_pinctrl_probe(struct udevice *dev,
158 struct uniphier_pinctrl_socdata *socdata);
159
Masahiro Yamada847e618b82015-09-11 20:17:32 +0900160#endif /* __PINCTRL_UNIPHIER_H__ */