]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/scx200_gpio.h
mm/hotplug: invalid PFNs from pfn_to_online_page()
[mirror_ubuntu-bionic-kernel.git] / include / linux / scx200_gpio.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
55b8c045 2u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
1da177e4
LT
3
4extern unsigned scx200_gpio_base;
64b33619 5extern unsigned long scx200_gpio_shadow[2];
58012cd7 6extern struct nsc_gpio_ops scx200_gpio_ops;
1da177e4
LT
7
8#define scx200_gpio_present() (scx200_gpio_base!=0)
9
10/* Definitions to make sure I do the same thing in all functions */
11#define __SCx200_GPIO_BANK unsigned bank = index>>5
12#define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank
64b33619 13#define __SCx200_GPIO_SHADOW unsigned long *shadow = scx200_gpio_shadow+bank
1da177e4
LT
14#define __SCx200_GPIO_INDEX index &= 31
15
16#define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
17
18/* returns the value of the GPIO pin */
19
55b8c045 20static inline int scx200_gpio_get(unsigned index) {
1da177e4
LT
21 __SCx200_GPIO_BANK;
22 __SCx200_GPIO_IOADDR + 0x04;
23 __SCx200_GPIO_INDEX;
24
25 return (inl(ioaddr) & (1<<index)) ? 1 : 0;
26}
27
28/* return the value driven on the GPIO signal (the value that will be
29 driven if the GPIO is configured as an output, it might not be the
30 state of the GPIO right now if the GPIO is configured as an input) */
31
55b8c045 32static inline int scx200_gpio_current(unsigned index) {
1da177e4
LT
33 __SCx200_GPIO_BANK;
34 __SCx200_GPIO_INDEX;
35
36 return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
37}
38
39/* drive the GPIO signal high */
40
55b8c045 41static inline void scx200_gpio_set_high(unsigned index) {
1da177e4
LT
42 __SCx200_GPIO_BANK;
43 __SCx200_GPIO_IOADDR;
44 __SCx200_GPIO_SHADOW;
45 __SCx200_GPIO_INDEX;
64b33619 46 set_bit(index, shadow); /* __set_bit()? */
1da177e4
LT
47 __SCx200_GPIO_OUT;
48}
49
50/* drive the GPIO signal low */
51
55b8c045 52static inline void scx200_gpio_set_low(unsigned index) {
1da177e4
LT
53 __SCx200_GPIO_BANK;
54 __SCx200_GPIO_IOADDR;
55 __SCx200_GPIO_SHADOW;
56 __SCx200_GPIO_INDEX;
64b33619 57 clear_bit(index, shadow); /* __clear_bit()? */
1da177e4
LT
58 __SCx200_GPIO_OUT;
59}
60
61/* drive the GPIO signal to state */
62
55b8c045 63static inline void scx200_gpio_set(unsigned index, int state) {
1da177e4
LT
64 __SCx200_GPIO_BANK;
65 __SCx200_GPIO_IOADDR;
66 __SCx200_GPIO_SHADOW;
67 __SCx200_GPIO_INDEX;
68 if (state)
69 set_bit(index, shadow);
70 else
71 clear_bit(index, shadow);
72 __SCx200_GPIO_OUT;
73}
74
75/* toggle the GPIO signal */
55b8c045 76static inline void scx200_gpio_change(unsigned index) {
1da177e4
LT
77 __SCx200_GPIO_BANK;
78 __SCx200_GPIO_IOADDR;
79 __SCx200_GPIO_SHADOW;
80 __SCx200_GPIO_INDEX;
81 change_bit(index, shadow);
82 __SCx200_GPIO_OUT;
83}
84
85#undef __SCx200_GPIO_BANK
86#undef __SCx200_GPIO_IOADDR
87#undef __SCx200_GPIO_SHADOW
88#undef __SCx200_GPIO_INDEX
89#undef __SCx200_GPIO_OUT