2 * Copyright 2010 eXMeritus, A Boeing Company
4 * SPDX-License-Identifier: GPL-2.0+
7 #ifndef POWERPC_ASM_MPC85XX_GPIO_H_
8 #define POWERPC_ASM_MPC85XX_GPIO_H_
10 # include <asm/immap_85xx.h>
13 * The following internal functions are an MPC85XX-specific GPIO API which
14 * allows setting and querying multiple GPIOs in a single operation.
16 * All of these look relatively large, but the arguments are almost always
17 * constants, so they compile down to just a few instructions and a
18 * memory-mapped IO operation or two.
20 static inline void mpc85xx_gpio_set(unsigned int mask,
21 unsigned int dir, unsigned int val)
23 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
25 /* First mask off the unwanted parts of "dir" and "val" */
29 /* Now read in the values we're supposed to preserve */
30 dir |= (in_be32(&gpio->gpdir) & ~mask);
31 val |= (in_be32(&gpio->gpdat) & ~mask);
34 * Poke the new output values first, then set the direction. This
35 * helps to avoid transient data when switching from input to output
38 out_be32(&gpio->gpdat, val);
39 out_be32(&gpio->gpdir, dir);
42 static inline void mpc85xx_gpio_set_in(unsigned int gpios)
44 mpc85xx_gpio_set(gpios, 0x00000000, 0x00000000);
47 static inline void mpc85xx_gpio_set_low(unsigned int gpios)
49 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0x00000000);
52 static inline void mpc85xx_gpio_set_high(unsigned int gpios)
54 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0xFFFFFFFF);
57 static inline unsigned int mpc85xx_gpio_get(unsigned int mask)
59 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
61 /* Read the requested values */
62 return in_be32(&gpio->gpdat) & mask;
66 * These implement the generic Linux GPIO API on top of the other functions
69 static inline int gpio_request(unsigned gpio, const char *label)
71 /* Compatibility shim */
75 static inline void gpio_free(unsigned gpio)
77 /* 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 void gpio_set_value(unsigned gpio, int value)
103 mpc85xx_gpio_set_high(1U << gpio);
105 mpc85xx_gpio_set_low(1U << gpio);
108 static inline int gpio_is_valid(int gpio)
110 return (gpio >= 0) && (gpio < 32);
113 #endif /* not POWERPC_ASM_MPC85XX_GPIO_H_ */