blob: 88aa689551110ef061454285957b393e12140066 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dave Liue732e9c2006-11-03 12:11:15 -06002/*
3 * Copyright (C) 2006 Freescale Semiconductor, Inc.
4 *
5 * Dave Liu <daveliu@freescale.com>
6 * based on source code of Shlomi Gridish
Dave Liue732e9c2006-11-03 12:11:15 -06007 */
8
Masahiro Yamadaadae2ec2016-09-21 11:28:53 +09009#include <common.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090010#include <linux/errno.h>
Masahiro Yamadaadae2ec2016-09-21 11:28:53 +090011#include <asm/io.h>
12#include <asm/immap_83xx.h>
Dave Liue732e9c2006-11-03 12:11:15 -060013
Dave Liue732e9c2006-11-03 12:11:15 -060014#define NUM_OF_PINS 32
15void 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-VILLARD03836942008-10-16 15:01:15 +020022 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
Dave Liu0b6bc772006-12-07 21:11:58 +080023 volatile qepio83xx_t *par_io = (volatile qepio83xx_t *)&im->qepio;
Dave Liue732e9c2006-11-03 12:11:15 -060024
Robert P. J. Daycbd618f2015-12-16 12:25:42 -050025 /* Calculate pin location and 2bit mask and dir */
Dave Liue732e9c2006-11-03 12:11:15 -060026 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}