2 * Copyright 2010 eXMeritus, A Boeing Company
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 #ifndef POWERPC_ASM_MPC85XX_GPIO_H_
21 #define POWERPC_ASM_MPC85XX_GPIO_H_
23 # include <asm/immap_85xx.h>
26 * The following internal functions are an MPC85XX-specific GPIO API which
27 * allows setting and querying multiple GPIOs in a single operation.
29 * All of these look relatively large, but the arguments are almost always
30 * constants, so they compile down to just a few instructions and a
31 * memory-mapped IO operation or two.
33 static inline void mpc85xx_gpio_set(unsigned int mask,
34 unsigned int dir, unsigned int val)
36 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xc00);
38 /* First mask off the unwanted parts of "dir" and "val" */
42 /* Now read in the values we're supposed to preserve */
43 dir |= (in_be32(&gpio->gpdir) & ~mask);
44 val |= (in_be32(&gpio->gpdat) & ~mask);
47 * Poke the new output values first, then set the direction. This
48 * helps to avoid transient data when switching from input to output
51 out_be32(&gpio->gpdat, val);
52 out_be32(&gpio->gpdir, dir);
55 static inline void mpc85xx_gpio_set_in(unsigned int gpios)
57 mpc85xx_gpio_set(gpios, 0x00000000, 0x00000000);
60 static inline void mpc85xx_gpio_set_low(unsigned int gpios)
62 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0x00000000);
65 static inline void mpc85xx_gpio_set_high(unsigned int gpios)
67 mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0xFFFFFFFF);
70 static inline unsigned int mpc85xx_gpio_get(unsigned int mask)
72 ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xc00);
74 /* Read the requested values */
75 return in_be32(&gpio->gpdat) & mask;
79 * These implement the generic Linux GPIO API on top of the other functions
82 static inline int gpio_request(unsigned gpio, const char *label)
84 /* Compatibility shim */
88 static inline void gpio_free(unsigned gpio)
90 /* Compatibility shim */
93 static inline int gpio_direction_input(unsigned gpio)
95 mpc85xx_gpio_set_in(1U << gpio);
99 static inline int gpio_direction_output(unsigned gpio, int value)
102 mpc85xx_gpio_set_high(1U << gpio);
104 mpc85xx_gpio_set_low(1U << gpio);
108 static inline int gpio_get_value(unsigned gpio)
110 return !!mpc85xx_gpio_get(1U << gpio);
113 static inline void gpio_set_value(unsigned gpio, int value)
116 mpc85xx_gpio_set_high(1U << gpio);
118 mpc85xx_gpio_set_low(1U << gpio);
121 static inline int gpio_is_valid(int gpio)
123 return (gpio >= 0) && (gpio < 32);
126 #endif /* not POWERPC_ASM_MPC85XX_GPIO_H_ */