]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_portio.c
3 * Marc Singer, elf@buici.com
5 * See file CREDITS for list of people who contributed to this
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,
27 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
33 /* Display values from last command.
34 * Memory modify remembered values are different from display memory.
36 static uint in_last_addr
, in_last_size
;
37 static uint out_last_addr
, out_last_size
, out_last_value
;
40 int do_portio_out (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
42 uint addr
= out_last_addr
;
43 uint size
= out_last_size
;
44 uint value
= out_last_value
;
51 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
52 /* New command specified. Check for a size specification.
53 * Defaults to long if no or incorrect specification.
55 size
= cmd_get_data_size (argv
[0], 1);
56 addr
= simple_strtoul (argv
[1], NULL
, 16);
57 value
= simple_strtoul (argv
[2], NULL
, 16);
59 #if defined (CONFIG_X86)
62 unsigned short port
= addr
;
68 unsigned char ch
= value
;
69 __asm__
volatile ("out %0, %%dx"::"a" (ch
), "d" (port
));
74 unsigned short w
= value
;
75 __asm__
volatile ("out %0, %%dx"::"a" (w
), "d" (port
));
79 __asm__
volatile ("out %0, %%dx"::"a" (value
), "d" (port
));
85 #endif /* CONFIG_X86 */
89 out_last_value
= value
;
95 out
, 3, 1, do_portio_out
,
96 "write datum to IO port",
97 "[.b, .w, .l] port value\n - output to IO port"
100 int do_portio_in (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
102 uint addr
= in_last_addr
;
103 uint size
= in_last_size
;
110 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
111 /* New command specified. Check for a size specification.
112 * Defaults to long if no or incorrect specification.
114 size
= cmd_get_data_size (argv
[0], 1);
115 addr
= simple_strtoul (argv
[1], NULL
, 16);
117 #if defined (CONFIG_X86)
120 unsigned short port
= addr
;
127 __asm__
volatile ("in %%dx, %0":"=a" (ch
):"d" (port
));
129 printf (" %02x\n", ch
);
135 __asm__
volatile ("in %%dx, %0":"=a" (w
):"d" (port
));
137 printf (" %04x\n", w
);
143 __asm__
volatile ("in %%dx, %0":"=a" (l
):"d" (port
));
145 printf (" %08lx\n", l
);
150 #endif /* CONFIG_X86 */
159 in
, 2, 1, do_portio_in
,
160 "read data from an IO port",
161 "[.b, .w, .l] port\n"
162 " - read datum from IO port"