Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * Dave Liu <daveliu@freescale.com> |
| 5 | * based on source code of Shlomi Gridish |
| 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include "common.h" |
| 11 | #include "asm/errno.h" |
| 12 | #include "asm/io.h" |
| 13 | #include "asm/immap_83xx.h" |
| 14 | |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 15 | #define NUM_OF_PINS 32 |
| 16 | void qe_config_iopin(u8 port, u8 pin, int dir, int open_drain, int assign) |
| 17 | { |
| 18 | u32 pin_2bit_mask; |
| 19 | u32 pin_2bit_dir; |
| 20 | u32 pin_2bit_assign; |
| 21 | u32 pin_1bit_mask; |
| 22 | u32 tmp_val; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | e080313 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 24 | volatile qepio83xx_t *par_io = (volatile qepio83xx_t *)&im->qepio; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 25 | |
| 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)); |
| 29 | |
| 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); |
| 34 | |
| 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); |
| 38 | } else { |
| 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); |
| 41 | } |
| 42 | |
| 43 | /* Calculate pin location for 1bit mask */ |
| 44 | pin_1bit_mask = (u32)(1 << (NUM_OF_PINS - (pin+1))); |
| 45 | |
| 46 | /* Setup the open drain */ |
| 47 | tmp_val = in_be32(&par_io->ioport[port].podr); |
| 48 | if (open_drain) { |
| 49 | out_be32(&par_io->ioport[port].podr, pin_1bit_mask | tmp_val); |
| 50 | } else { |
| 51 | out_be32(&par_io->ioport[port].podr, ~pin_1bit_mask & tmp_val); |
| 52 | } |
| 53 | |
| 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)); |
| 60 | |
| 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); |
| 65 | } else { |
| 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); |
| 68 | } |
| 69 | } |