Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2006 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * Dave Liu <daveliu@freescale.com> |
| 6 | * based on source code of Shlomi Gridish |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
Masahiro Yamada | adae2ec | 2016-09-21 11:28:53 +0900 | [diff] [blame] | 9 | #include <common.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 10 | #include <linux/errno.h> |
Masahiro Yamada | adae2ec | 2016-09-21 11:28:53 +0900 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/immap_83xx.h> |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 13 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 14 | #define NUM_OF_PINS 32 |
| 15 | void qe_config_iopin(u8 port, u8 pin, int dir, int open_drain, int assign) |
| 16 | { |
| 17 | u32 pin_2bit_mask; |
| 18 | u32 pin_2bit_dir; |
| 19 | u32 pin_2bit_assign; |
| 20 | u32 pin_1bit_mask; |
| 21 | u32 tmp_val; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 22 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | 0b6bc77 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 23 | volatile qepio83xx_t *par_io = (volatile qepio83xx_t *)&im->qepio; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 24 | |
Robert P. J. Day | cbd618f | 2015-12-16 12:25:42 -0500 | [diff] [blame] | 25 | /* Calculate pin location and 2bit mask and dir */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 26 | pin_2bit_mask = (u32)(0x3 << (NUM_OF_PINS-(pin%(NUM_OF_PINS/2)+1)*2)); |
| 27 | pin_2bit_dir = (u32)(dir << (NUM_OF_PINS-(pin%(NUM_OF_PINS/2)+1)*2)); |
| 28 | |
| 29 | /* Setup the direction */ |
| 30 | tmp_val = (pin > (NUM_OF_PINS/2) - 1) ? \ |
| 31 | in_be32(&par_io->ioport[port].dir2) : |
| 32 | in_be32(&par_io->ioport[port].dir1); |
| 33 | |
| 34 | if (pin > (NUM_OF_PINS/2) -1) { |
| 35 | out_be32(&par_io->ioport[port].dir2, ~pin_2bit_mask & tmp_val); |
| 36 | out_be32(&par_io->ioport[port].dir2, pin_2bit_dir | tmp_val); |
| 37 | } else { |
| 38 | out_be32(&par_io->ioport[port].dir1, ~pin_2bit_mask & tmp_val); |
| 39 | out_be32(&par_io->ioport[port].dir1, pin_2bit_dir | tmp_val); |
| 40 | } |
| 41 | |
| 42 | /* Calculate pin location for 1bit mask */ |
| 43 | pin_1bit_mask = (u32)(1 << (NUM_OF_PINS - (pin+1))); |
| 44 | |
| 45 | /* Setup the open drain */ |
| 46 | tmp_val = in_be32(&par_io->ioport[port].podr); |
| 47 | if (open_drain) { |
| 48 | out_be32(&par_io->ioport[port].podr, pin_1bit_mask | tmp_val); |
| 49 | } else { |
| 50 | out_be32(&par_io->ioport[port].podr, ~pin_1bit_mask & tmp_val); |
| 51 | } |
| 52 | |
| 53 | /* Setup the assignment */ |
| 54 | tmp_val = (pin > (NUM_OF_PINS/2) - 1) ? |
| 55 | in_be32(&par_io->ioport[port].ppar2): |
| 56 | in_be32(&par_io->ioport[port].ppar1); |
| 57 | pin_2bit_assign = (u32)(assign |
| 58 | << (NUM_OF_PINS - (pin%(NUM_OF_PINS/2)+1)*2)); |
| 59 | |
| 60 | /* Clear and set 2 bits mask */ |
| 61 | if (pin > (NUM_OF_PINS/2) - 1) { |
| 62 | out_be32(&par_io->ioport[port].ppar2, ~pin_2bit_mask & tmp_val); |
| 63 | out_be32(&par_io->ioport[port].ppar2, pin_2bit_assign | tmp_val); |
| 64 | } else { |
| 65 | out_be32(&par_io->ioport[port].ppar1, ~pin_2bit_mask & tmp_val); |
| 66 | out_be32(&par_io->ioport[port].ppar1, pin_2bit_assign | tmp_val); |
| 67 | } |
| 68 | } |