a319720b8d822a4d998544d770bf0360851e6623
[platform/kernel/linux-starfive.git] / drivers / pinctrl / starfive / pinctrl-starfive.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Pinctrl / GPIO driver for StarFive JH7110 SoC
4  *
5  * Copyright (C) 2022 Shanghai StarFive Technology Co., Ltd.
6  */
7
8 #ifndef __DRIVERS_PINCTRL_STARFIVE_H
9 #define __DRIVERS_PINCTRL_STARFIVE_H
10
11 #include <linux/pinctrl/pinconf-generic.h>
12 #include <linux/pinctrl/pinmux.h>
13
14 #define MAX_GPIO                                64
15
16 #define STARFIVE_PINS_SIZE                      4
17
18 #define STARFIVE_USE_SCU                        BIT(0)
19
20 struct platform_device;
21
22 extern const struct pinmux_ops starfive_pmx_ops;
23
24 struct starfive_pin_config {
25         unsigned long io_config;
26         u32 pinmux_func;
27         u32 gpio_num;
28         u32 gpio_dout;
29         u32 gpio_doen;
30         u32 gpio_din_num;
31         s32 *gpio_din_reg;
32         s32 syscon;
33         s32 padmux_func;
34 };
35
36 struct starfive_pin {
37         unsigned int pin;
38         struct starfive_pin_config pin_config;
39 };
40
41 struct starfive_pin_reg {
42         s32 io_conf_reg;
43         s32 gpo_dout_reg;
44         s32 gpo_doen_reg;
45         s32 func_sel_reg;
46         s32 func_sel_shift;
47         s32 func_sel_mask;
48         s32 syscon_reg;
49         s32 pad_sel_reg;
50         s32 pad_sel_shift;
51         s32 pad_sel_mask;
52 };
53
54 struct starfive_iopad_sel_func_inf {
55         unsigned int padctl_gpio_base;
56         unsigned int padctl_gpio0;
57 };
58
59 struct starfive_pinctrl {
60         struct device *dev;
61         struct pinctrl_dev *pctl_dev;
62         void __iomem *padctl_base;
63         void __iomem *gpio_base;
64         unsigned int padctl_gpio_base;
65         unsigned int padctl_gpio0;
66         const struct starfive_pinctrl_soc_info *info;
67         struct starfive_pin_reg *pin_regs;
68         unsigned int group_index;
69
70         struct mutex mutex;
71         raw_spinlock_t lock;
72
73         struct gpio_chip gc;
74         struct pinctrl_gpio_range gpios;
75         unsigned long enabled;
76         unsigned int trigger[MAX_GPIO];
77 };
78
79 struct starfive_pinctrl_soc_info {
80         const struct pinctrl_pin_desc *pins;
81         unsigned int npins;
82         unsigned int flags;
83
84         /*gpio dout/doen/din register*/
85         unsigned int dout_reg_base;
86         unsigned int dout_reg_offset;
87         unsigned int doen_reg_base;
88         unsigned int doen_reg_offset;
89         unsigned int din_reg_base;
90         unsigned int din_reg_offset;
91
92         /* sel-function */
93         int (*starfive_iopad_sel_func)(struct platform_device *pdev,
94                                         struct starfive_pinctrl *ipctl,
95                                         unsigned int func_id);
96         /* generic pinconf */
97         int (*starfive_pinconf_get)(struct pinctrl_dev *pctldev, unsigned int pin_id,
98                                unsigned long *config);
99         int (*starfive_pinconf_set)(struct pinctrl_dev *pctldev,
100                                 unsigned int pin_id, unsigned long *configs,
101                                 unsigned int num_configs);
102
103         /* generic pinmux */
104         int (*starfive_pmx_set_one_pin_mux)(struct starfive_pinctrl *ipctl,
105                                 struct starfive_pin *pin);
106         /* gpio chip */
107         int (*starfive_gpio_register)(struct platform_device *pdev,
108                                 struct starfive_pinctrl *ipctl);
109         void (*starfive_pinctrl_parse_pin)(struct starfive_pinctrl *ipctl,
110                                         unsigned int *pins_id, struct starfive_pin *pin_data,
111                                         const __be32 *list_p,
112                                         struct device_node *np);
113 };
114
115 #define STARFIVE_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin)
116
117 int starfive_pinctrl_probe(struct platform_device *pdev,
118                         const struct starfive_pinctrl_soc_info *info);
119
120 #endif /* __DRIVERS_PINCTRL_STARFIVE_H */