2 * Copyright (C) 2006 Freescale Semiconductor, Inc.
4 * Dave Liu <daveliu@freescale.com>
5 * based on source code of Shlomi Gridish
7 * SPDX-License-Identifier: GPL-2.0+
11 #include "asm/errno.h"
13 #include "asm/immap_83xx.h"
15 #define NUM_OF_PINS 32
16 void qe_config_iopin(u8 port, u8 pin, int dir, int open_drain, int assign)
23 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
24 volatile qepio83xx_t *par_io = (volatile qepio83xx_t *)&im->qepio;
26 /* Caculate pin location and 2bit mask and dir */
27 pin_2bit_mask = (u32)(0x3 << (NUM_OF_PINS-(pin%(NUM_OF_PINS/2)+1)*2));
28 pin_2bit_dir = (u32)(dir << (NUM_OF_PINS-(pin%(NUM_OF_PINS/2)+1)*2));
30 /* Setup the direction */
31 tmp_val = (pin > (NUM_OF_PINS/2) - 1) ? \
32 in_be32(&par_io->ioport[port].dir2) :
33 in_be32(&par_io->ioport[port].dir1);
35 if (pin > (NUM_OF_PINS/2) -1) {
36 out_be32(&par_io->ioport[port].dir2, ~pin_2bit_mask & tmp_val);
37 out_be32(&par_io->ioport[port].dir2, pin_2bit_dir | tmp_val);
39 out_be32(&par_io->ioport[port].dir1, ~pin_2bit_mask & tmp_val);
40 out_be32(&par_io->ioport[port].dir1, pin_2bit_dir | tmp_val);
43 /* Calculate pin location for 1bit mask */
44 pin_1bit_mask = (u32)(1 << (NUM_OF_PINS - (pin+1)));
46 /* Setup the open drain */
47 tmp_val = in_be32(&par_io->ioport[port].podr);
49 out_be32(&par_io->ioport[port].podr, pin_1bit_mask | tmp_val);
51 out_be32(&par_io->ioport[port].podr, ~pin_1bit_mask & tmp_val);
54 /* Setup the assignment */
55 tmp_val = (pin > (NUM_OF_PINS/2) - 1) ?
56 in_be32(&par_io->ioport[port].ppar2):
57 in_be32(&par_io->ioport[port].ppar1);
58 pin_2bit_assign = (u32)(assign
59 << (NUM_OF_PINS - (pin%(NUM_OF_PINS/2)+1)*2));
61 /* Clear and set 2 bits mask */
62 if (pin > (NUM_OF_PINS/2) - 1) {
63 out_be32(&par_io->ioport[port].ppar2, ~pin_2bit_mask & tmp_val);
64 out_be32(&par_io->ioport[port].ppar2, pin_2bit_assign | tmp_val);
66 out_be32(&par_io->ioport[port].ppar1, ~pin_2bit_mask & tmp_val);
67 out_be32(&par_io->ioport[port].ppar1, pin_2bit_assign | tmp_val);