usbdcore-multiple_configs.patch
[u-boot-openmoko/mini2440.git] / common / cmd_portio.c
bloba06cac01663b914038a4ef90ac83159f84f0d798
1 /*
2 * (C) Copyright 2003
3 * Marc Singer, elf@buici.com
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
25 * Port I/O Functions
27 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
30 #include <common.h>
31 #include <command.h>
33 extern int cmd_get_data_size (char *arg, int default_size);
35 /* Display values from last command.
36 * Memory modify remembered values are different from display memory.
38 static uint in_last_addr, in_last_size;
39 static uint out_last_addr, out_last_size, out_last_value;
42 int do_portio_out (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
44 uint addr = out_last_addr;
45 uint size = out_last_size;
46 uint value = out_last_value;
48 if (argc != 3) {
49 printf ("Usage:\n%s\n", cmdtp->usage);
50 return 1;
53 if ((flag & CMD_FLAG_REPEAT) == 0) {
54 /* New command specified. Check for a size specification.
55 * Defaults to long if no or incorrect specification.
57 size = cmd_get_data_size (argv[0], 1);
58 addr = simple_strtoul (argv[1], NULL, 16);
59 value = simple_strtoul (argv[2], NULL, 16);
61 #if defined (CONFIG_X86)
64 unsigned short port = addr;
66 switch (size) {
67 default:
68 case 1:
70 unsigned char ch = value;
71 __asm__ volatile ("out %0, %%dx"::"a" (ch), "d" (port));
73 break;
74 case 2:
76 unsigned short w = value;
77 __asm__ volatile ("out %0, %%dx"::"a" (w), "d" (port));
79 break;
80 case 4:
81 __asm__ volatile ("out %0, %%dx"::"a" (value), "d" (port));
83 break;
87 #endif /* CONFIG_X86 */
89 out_last_addr = addr;
90 out_last_size = size;
91 out_last_value = value;
93 return 0;
96 U_BOOT_CMD(
97 out, 3, 1, do_portio_out,
98 "out - write datum to IO port\n",
99 "[.b, .w, .l] port value\n - output to IO port\n"
102 int do_portio_in (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
104 uint addr = in_last_addr;
105 uint size = in_last_size;
107 if (argc != 2) {
108 printf ("Usage:\n%s\n", cmdtp->usage);
109 return 1;
112 if ((flag & CMD_FLAG_REPEAT) == 0) {
113 /* New command specified. Check for a size specification.
114 * Defaults to long if no or incorrect specification.
116 size = cmd_get_data_size (argv[0], 1);
117 addr = simple_strtoul (argv[1], NULL, 16);
119 #if defined (CONFIG_X86)
122 unsigned short port = addr;
124 switch (size) {
125 default:
126 case 1:
128 unsigned char ch;
129 __asm__ volatile ("in %%dx, %0":"=a" (ch):"d" (port));
131 printf (" %02x\n", ch);
133 break;
134 case 2:
136 unsigned short w;
137 __asm__ volatile ("in %%dx, %0":"=a" (w):"d" (port));
139 printf (" %04x\n", w);
141 break;
142 case 4:
144 unsigned long l;
145 __asm__ volatile ("in %%dx, %0":"=a" (l):"d" (port));
147 printf (" %08lx\n", l);
149 break;
152 #endif /* CONFIG_X86 */
154 in_last_addr = addr;
155 in_last_size = size;
157 return 0;
160 U_BOOT_CMD(
161 in, 2, 1, do_portio_in,
162 "in - read data from an IO port\n",
163 "[.b, .w, .l] port\n"
164 " - read datum from IO port\n"