1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <common.h>
31#include <command.h>
32
33extern int cmd_get_data_size (char *arg, int default_size);
34
35
36
37
38static uint in_last_addr, in_last_size;
39static uint out_last_addr, out_last_size, out_last_value;
40
41
42int do_portio_out (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
43{
44 uint addr = out_last_addr;
45 uint size = out_last_size;
46 uint value = out_last_value;
47
48 if (argc != 3) {
49 printf ("Usage:\n%s\n", cmdtp->usage);
50 return 1;
51 }
52
53 if ((flag & CMD_FLAG_REPEAT) == 0) {
54
55
56
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);
60 }
61#if defined (CONFIG_X86)
62
63 {
64 unsigned short port = addr;
65
66 switch (size) {
67 default:
68 case 1:
69 {
70 unsigned char ch = value;
71 __asm__ volatile ("out %0, %%dx"::"a" (ch), "d" (port));
72 }
73 break;
74 case 2:
75 {
76 unsigned short w = value;
77 __asm__ volatile ("out %0, %%dx"::"a" (w), "d" (port));
78 }
79 break;
80 case 4:
81 __asm__ volatile ("out %0, %%dx"::"a" (value), "d" (port));
82
83 break;
84 }
85 }
86
87#endif
88
89 out_last_addr = addr;
90 out_last_size = size;
91 out_last_value = value;
92
93 return 0;
94}
95
96U_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"
100);
101
102int do_portio_in (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
103{
104 uint addr = in_last_addr;
105 uint size = in_last_size;
106
107 if (argc != 2) {
108 printf ("Usage:\n%s\n", cmdtp->usage);
109 return 1;
110 }
111
112 if ((flag & CMD_FLAG_REPEAT) == 0) {
113
114
115
116 size = cmd_get_data_size (argv[0], 1);
117 addr = simple_strtoul (argv[1], NULL, 16);
118 }
119#if defined (CONFIG_X86)
120
121 {
122 unsigned short port = addr;
123
124 switch (size) {
125 default:
126 case 1:
127 {
128 unsigned char ch;
129 __asm__ volatile ("in %%dx, %0":"=a" (ch):"d" (port));
130
131 printf (" %02x\n", ch);
132 }
133 break;
134 case 2:
135 {
136 unsigned short w;
137 __asm__ volatile ("in %%dx, %0":"=a" (w):"d" (port));
138
139 printf (" %04x\n", w);
140 }
141 break;
142 case 4:
143 {
144 unsigned long l;
145 __asm__ volatile ("in %%dx, %0":"=a" (l):"d" (port));
146
147 printf (" %08lx\n", l);
148 }
149 break;
150 }
151 }
152#endif
153
154 in_last_addr = addr;
155 in_last_size = size;
156
157 return 0;
158}
159
160U_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"
165);
166