Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2024 Inochi Amaoto <inochiama@outlook.com>
4 */
5
6#ifndef _PINCTRL_SOPHGO_CV18XX_H
7#define _PINCTRL_SOPHGO_CV18XX_H
8
9#include <linux/bitfield.h>
10#include <linux/pinctrl/pinctrl.h>
11#include <linux/pinctrl/pinconf.h>
12
13#include "pinctrl-sophgo.h"
14
15enum cv1800_pin_io_type {
16 IO_TYPE_1V8_ONLY = 0,
17 IO_TYPE_1V8_OR_3V3 = 1,
18 IO_TYPE_AUDIO = 2,
19 IO_TYPE_ETH = 3
20};
21
22#define CV1800_PINCONF_AREA_SYS 0
23#define CV1800_PINCONF_AREA_RTC 1
24
25struct cv1800_pinmux {
26 u16 offset;
27 u8 area;
28 u8 max;
29};
30
31struct cv1800_pinmux2 {
32 u16 offset;
33 u8 area;
34 u8 max;
35 u8 pfunc;
36};
37
38struct cv1800_pinconf {
39 u16 offset;
40 u8 area;
41};
42
43#define CV1800_PIN_HAVE_MUX2 BIT(0)
44#define CV1800_PIN_IO_TYPE GENMASK(2, 1)
45
46#define CV1800_PIN_FLAG_IO_TYPE(type) \
47 FIELD_PREP_CONST(CV1800_PIN_IO_TYPE, type)
48struct cv1800_pin {
49 struct sophgo_pin pin;
50 u8 power_domain;
51 struct cv1800_pinmux mux;
52 struct cv1800_pinmux2 mux2;
53 struct cv1800_pinconf conf;
54};
55
56#define sophgo_to_cv1800_pin(_pin) \
57 container_of((_pin), struct cv1800_pin, pin)
58
59#define PIN_POWER_STATE_1V8 1800
60#define PIN_POWER_STATE_3V3 3300
61
62static inline enum cv1800_pin_io_type cv1800_pin_io_type(const struct cv1800_pin *pin)
63{
64 return FIELD_GET(CV1800_PIN_IO_TYPE, pin->pin.flags);
65};
66
67extern const struct pinctrl_ops cv1800_pctrl_ops;
68extern const struct pinmux_ops cv1800_pmx_ops;
69extern const struct pinconf_ops cv1800_pconf_ops;
70extern const struct sophgo_cfg_ops cv1800_cfg_ops;
71
72#define CV1800_FUNC_PIN(_id, _power_domain, _type, \
73 _mux_area, _mux_offset, _mux_func_max) \
74 { \
75 .pin = { \
76 .id = (_id), \
77 .flags = CV1800_PIN_FLAG_IO_TYPE(_type), \
78 }, \
79 .power_domain = (_power_domain), \
80 .mux = { \
81 .area = (_mux_area), \
82 .offset = (_mux_offset), \
83 .max = (_mux_func_max), \
84 }, \
85 }
86
87#define CV1800_GENERAL_PIN(_id, _power_domain, _type, \
88 _mux_area, _mux_offset, _mux_func_max, \
89 _conf_area, _conf_offset) \
90 { \
91 .pin = { \
92 .id = (_id), \
93 .flags = CV1800_PIN_FLAG_IO_TYPE(_type), \
94 }, \
95 .power_domain = (_power_domain), \
96 .mux = { \
97 .area = (_mux_area), \
98 .offset = (_mux_offset), \
99 .max = (_mux_func_max), \
100 }, \
101 .conf = { \
102 .area = (_conf_area), \
103 .offset = (_conf_offset), \
104 }, \
105 }
106
107#define CV1800_GENERATE_PIN_MUX2(_id, _power_domain, _type, \
108 _mux_area, _mux_offset, _mux_func_max, \
109 _mux2_area, _mux2_offset, \
110 _mux2_func_max, \
111 _conf_area, _conf_offset) \
112 { \
113 .pin = { \
114 .id = (_id), \
115 .flags = CV1800_PIN_FLAG_IO_TYPE(_type) | \
116 CV1800_PIN_HAVE_MUX2, \
117 }, \
118 .power_domain = (_power_domain), \
119 .mux = { \
120 .area = (_mux_area), \
121 .offset = (_mux_offset), \
122 .max = (_mux_func_max), \
123 }, \
124 .mux2 = { \
125 .area = (_mux2_area), \
126 .offset = (_mux2_offset), \
127 .max = (_mux2_func_max), \
128 }, \
129 .conf = { \
130 .area = (_conf_area), \
131 .offset = (_conf_offset), \
132 }, \
133 }
134
135#endif