1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2010 eXMeritus, A Boeing Company
6 #ifndef POWERPC_ASM_MPC85XX_GPIO_H_
7 #define POWERPC_ASM_MPC85XX_GPIO_H_
9 # include <asm/immap_85xx.h>
12 * The following internal functions are an MPC85XX-specific GPIO API which
13 * allows setting and querying multiple GPIOs in a single operation.
15 * All of these look relatively large, but the arguments are almost always
16 * constants, so they compile down to just a few instructions and a
17 * memory-mapped IO operation or two.
19 static inline void mpc85xx_gpio_set(unsigned int mask,
20 unsigned int dir, unsigned int val)
22 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
24 /* First mask off the unwanted parts of "dir" and "val" */
28 /* Now read in the values we're supposed to preserve */
29 dir |= (in_be32(&gpio->gpdir) & ~mask);
30 val |= (in_be32(&gpio->gpdat) & ~mask);
33 * Poke the new output values first, then set the direction. This
34 * helps to avoid transient data when switching from input to output
37 out_be32(&gpio->gpdat, val);
38 out_be32(&gpio->gpdir, dir);
41 static inline void mpc85xx_gpio_set_in(unsigned int gpios)
43 mpc85xx_gpio_set(gpios, 0x00000000, 0x00000000);
46 static inline void mpc85xx_gpio_set_low(unsigned int gpios)
48 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0x00000000);
51 static inline void mpc85xx_gpio_set_high(unsigned int gpios)
53 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0xFFFFFFFF);
56 static inline unsigned int mpc85xx_gpio_get(unsigned int mask)
58 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
60 /* Read the requested values */
61 return in_be32(&gpio->gpdat) & mask;
65 * These implement the generic Linux GPIO API on top of the other functions
68 static inline int gpio_request(unsigned gpio, const char *label)
70 /* Compatibility shim */
74 static inline int gpio_free(unsigned gpio)
76 /* Compatibility shim */
80 static inline int gpio_direction_input(unsigned gpio)
82 mpc85xx_gpio_set_in(1U << gpio);
86 static inline int gpio_direction_output(unsigned gpio, int value)
89 mpc85xx_gpio_set_high(1U << gpio);
91 mpc85xx_gpio_set_low(1U << gpio);
95 static inline int gpio_get_value(unsigned gpio)
97 return !!mpc85xx_gpio_get(1U << gpio);
100 static inline int gpio_set_value(unsigned gpio, int value)
103 mpc85xx_gpio_set_high(1U << gpio);
105 mpc85xx_gpio_set_low(1U << gpio);
109 static inline int gpio_is_valid(int gpio)
111 return (gpio >= 0) && (gpio < 32);
114 #endif /* not POWERPC_ASM_MPC85XX_GPIO_H_ */