xref: /linux/arch/arm/mach-s3c/gpio-cfg-helpers.h (revision 58d416351e6df1a41d415958ccdd8eb9c2173fed)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2008 Openmoko, Inc.
4  * Copyright 2008 Simtec Electronics
5  *	http://armlinux.simtec.co.uk/
6  *	Ben Dooks <ben@simtec.co.uk>
7  *
8  * Samsung Platform - GPIO pin configuration helper definitions
9  */
10 
11 /* This is meant for core cpu support, machine or other driver files
12  * should not be including this header.
13  */
14 
15 #ifndef __PLAT_GPIO_CFG_HELPERS_H
16 #define __PLAT_GPIO_CFG_HELPERS_H __FILE__
17 
18 /* As a note, all gpio configuration functions are entered exclusively, either
19  * with the relevant lock held or the system prevented from doing anything else
20  * by disabling interrupts.
21 */
22 
23 static inline int samsung_gpio_do_setcfg(struct samsung_gpio_chip *chip,
24 					 unsigned int off, unsigned int config)
25 {
26 	return (chip->config->set_config)(chip, off, config);
27 }
28 
29 static inline unsigned samsung_gpio_do_getcfg(struct samsung_gpio_chip *chip,
30 					      unsigned int off)
31 {
32 	return (chip->config->get_config)(chip, off);
33 }
34 
35 static inline int samsung_gpio_do_setpull(struct samsung_gpio_chip *chip,
36 					  unsigned int off, samsung_gpio_pull_t pull)
37 {
38 	return (chip->config->set_pull)(chip, off, pull);
39 }
40 
41 static inline samsung_gpio_pull_t samsung_gpio_do_getpull(struct samsung_gpio_chip *chip,
42 							  unsigned int off)
43 {
44 	return chip->config->get_pull(chip, off);
45 }
46 
47 /* Pull-{up,down} resistor controls.
48  *
49  * S3C2410,S3C2440 = Pull-UP,
50  * S3C2412,S3C2413 = Pull-Down
51  * S3C6400,S3C6410 = Pull-Both [None,Down,Up,Undef]
52  * S3C2443 = Pull-Both [not same as S3C6400]
53  */
54 
55 /**
56  * s3c24xx_gpio_setpull_1up() - Pull configuration for choice of up or none.
57  * @chip: The gpio chip that is being configured.
58  * @off: The offset for the GPIO being configured.
59  * @param: pull: The pull mode being requested.
60  *
61  * This is a helper function for the case where we have GPIOs with one
62  * bit configuring the presence of a pull-up resistor.
63  */
64 extern int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip,
65 				    unsigned int off, samsung_gpio_pull_t pull);
66 
67 /**
68  * s3c24xx_gpio_setpull_1down() - Pull configuration for choice of down or none
69  * @chip: The gpio chip that is being configured
70  * @off: The offset for the GPIO being configured
71  * @param: pull: The pull mode being requested
72  *
73  * This is a helper function for the case where we have GPIOs with one
74  * bit configuring the presence of a pull-down resistor.
75  */
76 extern int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip,
77 				      unsigned int off, samsung_gpio_pull_t pull);
78 
79 /**
80  * samsung_gpio_setpull_upown() - Pull configuration for choice of up,
81  * down or none
82  *
83  * @chip: The gpio chip that is being configured.
84  * @off: The offset for the GPIO being configured.
85  * @param: pull: The pull mode being requested.
86  *
87  * This is a helper function for the case where we have GPIOs with two
88  * bits configuring the presence of a pull resistor, in the following
89  * order:
90  *	00 = No pull resistor connected
91  *	01 = Pull-up resistor connected
92  *	10 = Pull-down resistor connected
93  */
94 extern int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip,
95 				       unsigned int off, samsung_gpio_pull_t pull);
96 
97 /**
98  * samsung_gpio_getpull_updown() - Get configuration for choice of up,
99  * down or none
100  *
101  * @chip: The gpio chip that the GPIO pin belongs to
102  * @off: The offset to the pin to get the configuration of.
103  *
104  * This helper function reads the state of the pull-{up,down} resistor
105  * for the given GPIO in the same case as samsung_gpio_setpull_upown.
106 */
107 extern samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip,
108 						       unsigned int off);
109 
110 /**
111  * s3c24xx_gpio_getpull_1up() - Get configuration for choice of up or none
112  * @chip: The gpio chip that the GPIO pin belongs to
113  * @off: The offset to the pin to get the configuration of.
114  *
115  * This helper function reads the state of the pull-up resistor for the
116  * given GPIO in the same case as s3c24xx_gpio_setpull_1up.
117 */
118 extern samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip,
119 						    unsigned int off);
120 
121 /**
122  * s3c24xx_gpio_getpull_1down() - Get configuration for choice of down or none
123  * @chip: The gpio chip that the GPIO pin belongs to
124  * @off: The offset to the pin to get the configuration of.
125  *
126  * This helper function reads the state of the pull-down resistor for the
127  * given GPIO in the same case as s3c24xx_gpio_setpull_1down.
128 */
129 extern samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip,
130 						      unsigned int off);
131 
132 /**
133  * s3c2443_gpio_setpull() - Pull configuration for s3c2443.
134  * @chip: The gpio chip that is being configured.
135  * @off: The offset for the GPIO being configured.
136  * @param: pull: The pull mode being requested.
137  *
138  * This is a helper function for the case where we have GPIOs with two
139  * bits configuring the presence of a pull resistor, in the following
140  * order:
141  *	00 = Pull-up resistor connected
142  *	10 = Pull-down resistor connected
143  *	x1 = No pull up resistor
144  */
145 extern int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip,
146 				unsigned int off, samsung_gpio_pull_t pull);
147 
148 /**
149  * s3c2443_gpio_getpull() - Get configuration for s3c2443 pull resistors
150  * @chip: The gpio chip that the GPIO pin belongs to.
151  * @off: The offset to the pin to get the configuration of.
152  *
153  * This helper function reads the state of the pull-{up,down} resistor for the
154  * given GPIO in the same case as samsung_gpio_setpull_upown.
155 */
156 extern samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip,
157 						unsigned int off);
158 
159 #endif /* __PLAT_GPIO_CFG_HELPERS_H */
160