2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/device.h>
23 #include <linux/string.h>
24 #include <linux/slab.h>
26 #include <linux/platform_device.h>
28 #include <linux/of_address.h>
29 #include <linux/firmware.h>
34 #ifdef CONFIG_B4860G100
35 static struct gpiobus gbus;
36 #endif /* CONFIG_B4860G100 */
38 static inline void byte0_out(unsigned char data);
39 static inline void byte1_out(unsigned char data);
40 static inline void xl_cclk_b(int32_t i);
43 /* Assert and Deassert CCLK */
44 void xl_shift_cclk(int count)
47 for (i = 0; i < count; i++) {
53 int xl_supported_prog_bus_width(enum wbus bus_bytes)
61 pr_err("unsupported program bus width %d\n",
69 /* Serialize byte and clock each bit on target's DIN and CCLK pins */
70 void xl_shift_bytes_out(enum wbus bus_byte, unsigned char *pdata)
73 * supports 1 and 2 bytes programming mode
75 if (likely(bus_byte == bus_2byte))
83 * generic bit swap for xilinx SYSTEMMAP FPGA programming
85 static inline unsigned char bitswap(unsigned char s)
88 d = (((s&0x80)>>7) | ((s&0x40)>>5) | ((s&0x20)>>3) | ((s&0x10)>>1) |
89 ((s&0x08)<<1) | ((s&0x04)<<3) | ((s&0x02)<<5) | ((s&0x01)<<7));
93 #ifdef CONFIG_B4860G100
95 * ======================================================================
96 * board specific configuration
99 static inline void mpc85xx_gpio_set_dir(
104 dir |= (in_be32(gbus.r[port]+GPDIR) & ~mask);
105 out_be32(gbus.r[port]+GPDIR, dir);
108 static inline void mpc85xx_gpio_set(int32_t port, uint32_t mask, uint32_t val)
110 /* First mask off the unwanted parts of "dir" and "val" */
113 /* Now read in the values we're supposed to preserve */
114 val |= (in_be32(gbus.r[port]+GPDAT) & ~mask);
116 out_be32(gbus.r[port]+GPDAT, val);
119 static inline uint32_t mpc85xx_gpio_get(int32_t port, uint32_t mask)
121 /* Read the requested values */
122 return in_be32(gbus.r[port]+GPDAT) & mask;
125 static inline void mpc85xx_gpio_set_low(int32_t port, uint32_t gpios)
127 mpc85xx_gpio_set(port, gpios, 0x00000000);
130 static inline void mpc85xx_gpio_set_high(int32_t port, uint32_t gpios)
132 mpc85xx_gpio_set(port, gpios, 0xFFFFFFFF);
135 static inline void gpio_set_value(int32_t port, uint32_t gpio, uint32_t value)
140 mpc85xx_gpio_set_high(port, 1U << g);
142 mpc85xx_gpio_set_low(port, 1U << g);
145 static inline int gpio_get_value(int32_t port, uint32_t gpio)
149 return !!mpc85xx_gpio_get(port, 1U << g);
152 static inline void xl_cclk_b(int32_t i)
154 gpio_set_value(XL_CCLK_PORT, XL_CCLK_PIN, i);
157 void xl_program_b(int32_t i)
159 gpio_set_value(XL_PROGN_PORT, XL_PROGN_PIN, i);
162 void xl_rdwr_b(int32_t i)
164 gpio_set_value(XL_RDWRN_PORT, XL_RDWRN_PIN, i);
167 void xl_csi_b(int32_t i)
169 gpio_set_value(XL_CSIN_PORT, XL_CSIN_PIN, i);
172 int xl_get_init_b(void)
174 return gpio_get_value(XL_INITN_PORT, XL_INITN_PIN);
177 int xl_get_done_b(void)
179 return gpio_get_value(XL_DONE_PORT, XL_DONE_PIN);
183 /* G100 specific bit swap and remmap (to gpio pins) for byte 0 */
184 static inline uint32_t bit_remap_byte0(uint32_t s)
187 d = (((s&0x80)>>7) | ((s&0x40)>>5) | ((s&0x20)>>3) | ((s&0x10)>>1) |
188 ((s&0x08)<<1) | ((s&0x04)<<3) | ((s&0x02)<<6) | ((s&0x01)<<9));
193 * G100 specific MSB, in this order [byte0 | byte1], out
195 static inline void byte0_out(unsigned char data)
198 swap32 = bit_remap_byte0((uint32_t) data) << 8;
200 mpc85xx_gpio_set(0, 0x0002BF00, (uint32_t) swap32);
204 * G100 specific LSB, in this order [byte0 | byte1], out
206 static inline void byte1_out(unsigned char data)
208 mpc85xx_gpio_set(0, 0x000000FF, (uint32_t) bitswap(data));
212 * configurable per device type for different I/O config
216 struct device_node *np;
221 memset(&gbus, 0, sizeof(struct gpiobus));
222 for_each_compatible_node(np, NULL, "fsl,qoriq-gpio") {
223 p_reg = of_get_property(np, "reg", NULL);
227 gbus.r[cnt] = of_iomap(np, 0);
230 pr_err("not findding gpio cell-index %d\n", cnt);
235 mpc85xx_gpio_set_dir(0, 0x0002BFFF, 0x0002BFFF);
236 mpc85xx_gpio_set_dir(1, 0x00240060, 0x00240060);
244 #else /* placeholder for boards with different config */
246 void xl_program_b(int32_t i)
251 void xl_rdwr_b(int32_t i)
256 void xl_csi_b(int32_t i)
261 int xl_get_init_b(void)
266 int xl_get_done_b(void)
271 static inline void byte0_out(unsigned char data)
276 static inline void byte1_out(unsigned char data)
281 static inline void xl_cclk_b(int32_t i)
287 * configurable per device type for different I/O config
294 #endif /* CONFIG_B4860G100 */