1 /*
2  * Driver header file for pin controller driver
3  * Copyright (C) 2017 Spreadtrum  - http://www.spreadtrum.com
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14 
15 #ifndef __PINCTRL_SPRD_H__
16 #define __PINCTRL_SPRD_H__
17 
18 struct platform_device;
19 
20 #define NUM_OFFSET	(20)
21 #define TYPE_OFFSET	(16)
22 #define BIT_OFFSET	(8)
23 #define WIDTH_OFFSET	(4)
24 
25 #define SPRD_PIN_INFO(num, type, offset, width, reg)	\
26 		(((num) & 0xFFF) << NUM_OFFSET |	\
27 		 ((type) & 0xF) << TYPE_OFFSET |	\
28 		 ((offset) & 0xFF) << BIT_OFFSET |	\
29 		 ((width) & 0xF) << WIDTH_OFFSET |	\
30 		 ((reg) & 0xF))
31 
32 #define SPRD_PINCTRL_PIN(pin)	SPRD_PINCTRL_PIN_DATA(pin, #pin)
33 
34 #define SPRD_PINCTRL_PIN_DATA(a, b)				\
35 	{							\
36 		.name = b,					\
37 		.num = (((a) >> NUM_OFFSET) & 0xfff),		\
38 		.type = (((a) >> TYPE_OFFSET) & 0xf),		\
39 		.bit_offset = (((a) >> BIT_OFFSET) & 0xff),	\
40 		.bit_width = ((a) >> WIDTH_OFFSET & 0xf),	\
41 		.reg = ((a) & 0xf)				\
42 	}
43 
44 enum pin_type {
45 	GLOBAL_CTRL_PIN,
46 	COMMON_PIN,
47 	MISC_PIN,
48 };
49 
50 struct sprd_pins_info {
51 	const char *name;
52 	unsigned int num;
53 	enum pin_type type;
54 
55 	/* for global control pins configuration */
56 	unsigned long bit_offset;
57 	unsigned long bit_width;
58 	unsigned int reg;
59 };
60 
61 int sprd_pinctrl_core_probe(struct platform_device *pdev,
62 			    struct sprd_pins_info *sprd_soc_pin_info,
63 			    int pins_cnt);
64 int sprd_pinctrl_remove(struct platform_device *pdev);
65 void sprd_pinctrl_shutdown(struct platform_device *pdev);
66 
67 #endif /* __PINCTRL_SPRD_H__ */
68