summaryrefslogtreecommitdiffstats
path: root/board/goldelico/gta04/commands.c
blob: f4b237e9a4fabe58c9dac358e74ae7cab58e164e (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/* u-boot extended commands for flash
 *
 * Copyright (C) 2010 by Golden Delicious Computers GmbH&Co. KG
 * Author: H. Nikolaus Schaller <hns@goldelico.com>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

#include <common.h>
#include <command.h>
#include <asm/errno.h>
#include <asm/io.h>
#include <asm/arch/mux.h>
#include <asm/arch/sys_proto.h>
#include <asm/arch/gpio.h>
#include <asm/mach-types.h>

#include "backlight.h"
#include "dssfb.h"
#include "jbt6k74.h"
#include "status.h"
#include "gps.h"
#include "tsc2007.h"
#include "shutdown.h"
#include "systest.h"
#include "twl4030-additions.h"

/* LCM commands */

static int do_lcd_color(int argc, char *const argv[])
{
	unsigned int color;
	if (argc < 3) {
		printf ("lcm color: missing color (0..ffffff).\n");
		return (-1);
	}
	color=simple_strtoul(argv[2], NULL, 16);
	omap3_set_color(color);
	return 0;
}

static int do_lcd_framebuffer(int argc, char *const argv[])
{
	void *addr;
	if (argc < 3) {
		printf ("lcm fb: missing address.\n");
		return (-1);
	}
	addr=(void *) simple_strtoul(argv[2], NULL, 16);
	omap3_dss_set_fb(addr);
	return 0;
}

static int do_lcd_backlight(int argc, char *const argv[])
{
	unsigned char level;
	if (argc < 3) {
		printf ("lcm backlight: missing level (0..255).\n");
		return (-1);
	}
	level=simple_strtoul(argv[2], NULL, 10);
	backlight_set_level(level);
	return 0;
}

static char *lcdmodel="td028";

static int do_lcd_power(int argc, char *const argv[])
{
	if(strcmp(lcdmodel, "td028") == 0)
		{
		int state=JBT_STATE_NORMAL;
		if (argc < 3)
			{
			printf ("lcm power: missing state (0..2).\n");
			return (-1);
			}
		state=simple_strtoul(argv[2], NULL, 10);
		if(state > 2)
			{
			printf ("lcm power: invalid state (0..2).\n");
			return (-1);
			}
		jbt6k74_enter_state(state);
		printf("lcm state set to %s\n", jbt_state());	
		}
	return 0;
}

static int do_lcd_onoff(int argc, char *const argv[], int flag)
{
	if(strcmp(lcdmodel, "td028") == 0)
		jbt6k74_display_onoff(flag);
	else
		jbt6k74_display_onoff(flag);
	printf("display power %s\n", flag?"on":"off");
	return 0;
}

static int do_lcd_init(int argc, char *const argv[])
{
	// check argv for user specified lcdmodel
	return board_video_init(NULL);
}

static int do_lcd_start(int argc, char *const argv[])
{
	// check argv for user specified lcdmodel
	if(board_video_init(NULL))
		return 1;
	if(strcmp(lcdmodel, "td028") == 0)
		{
		jbt6k74_enter_state(2);
		jbt6k74_display_onoff(1);
		backlight_set_level(255);		
		}
	return 0;
}

static int do_lcd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	int len;
	
	if (argc < 2) {
		printf ("lcm: missing subcommand.\n");
		return (-1);
	}
	
	len = strlen (argv[1]);
	if (strncmp ("ba", argv[1], 2) == 0) {
		return do_lcd_backlight (argc, argv);
	} else if (strncmp ("po", argv[1], 2) == 0) {
		return do_lcd_power (argc, argv);
	} else if (strncmp ("of", argv[1], 2) == 0) {
		return do_lcd_onoff (argc, argv, 0);
	} else if (strncmp ("on", argv[1], 2) == 0) {
		return do_lcd_onoff (argc, argv, 1);
	} else if (strncmp ("in", argv[1], 2) == 0) {
		return do_lcd_init (argc, argv);
	} else if (strncmp ("co", argv[1], 2) == 0) {
		return do_lcd_color (argc, argv);
	} else if (strncmp ("fb", argv[1], 2) == 0) {
		return do_lcd_framebuffer (argc, argv);
	} else if (strncmp ("st", argv[1], 2) == 0) {
		return do_lcd_start (argc, argv);
	} else {
		printf ("lcm: unknown operation: %s\n", argv[1]);
	}
	
	return (0);
}

U_BOOT_CMD(lcm, 3, 0, do_lcd, "LCM sub-system",
		   "init [model] - initialize DSS, GPIOs and LCM controller\n"
		   "backlight level - set backlight level\n"
		   "off - switch off\n"
		   "on - switch on\n"
		   "power mode - set power mode\n"
		   "start [model] - initialize, switch on power and enable backlight\n"
		   "color hhhhhh - switch color (can be used without init)\n"
		   "fb address - set framebuffer address (can be used without init)\n"
		   );

/* TSC commands */

static int do_tsc_init(int argc, char *const argv[])
{
	tsc2007_init();
	return 0;
}

static int do_tsc_get(int argc, char *const argv[])
{
	print_adc();
	printf("\n");
	return 0;
}

static int do_tsc_loop(int argc, char *const argv[])
{
	printf("permanently reading ADCs of TSC.\n"
		   "Press any key to stop\n\n");
	while (!tstc() && (status_get_buttons()&0x09) == 0)
		{
			print_adc();
			printf("\r");
		}
	if(tstc())
		getc();
	printf("\n");
	return 0;
}

static int do_tsc_gloop(int argc, char *const argv[])
{
	unsigned short *fb=(void *) 0x81000000;	// base address to be used as RGB16 framebuffer
	printf("permanently reading ADCs of TSC to framebuffer.\n"
		   "Press any key to stop\n\n");
	omap3_dss_set_fb(fb);
	while (!tstc() && (status_get_buttons()&0x09) == 0)
		{
		int i;
		for(i=0; i<8; i++)
			{
			int val=(480*read_adc(i))/4096;
			int x, y;
			printf("%d: %d\n", i, val);
			for(y=16*i; y<16*i+16; y++)
				{ // draw colored bar depending on current value
					for(x=0; x<480; x++)
						fb[x+480*y]=(x < val)?0xfc00:0x03ff;
				}
			}
		}
	if(tstc())
		getc();
	printf("\n");
	return 0;
}



static int tsc_choice=0;

static int do_tsc_selection(int argc, char *const argv[])
{ // tsc selection number
	if (argc != 3)
		{
			printf ("tsc selection: missing number of selection to check for.\n");
			return (-1);
		}
	return tsc_choice == simple_strtoul(argv[2], NULL, 10)?0:1;
}

static int do_tsc_choose(int argc, char *const argv[])
{ // tsc choose cols rows
	int cols;
	int rows;
	int x;
	int y;
	tsc_choice=0;	// reset choice
	if (argc != 4)
		{
			printf ("tsc choose: missing number of cols and rows.\n");
			return (-1);
		}
	cols=simple_strtoul(argv[2], NULL, 10);
	rows=simple_strtoul(argv[3], NULL, 10);
	printf("Choosing by waiting for touch.\n");
	for(y=0; y<rows; y++)
		for(x=0; x<cols; x++)
			printf("%d%s", 1+x+y*cols, (x+1==cols)?"\n":" ");
	printf("Press touch or any key to stop\n\n");
	while (!tstc())
		{
			if(pendown(NULL, NULL) && pendown(&x, &y))
				{ // still pressed - should now be stable
#if 0
					printf("xy: %d/%d\n", x, y);
					printf("xy: %d/%d\n", x*cols, y*rows);
#endif
					x=(x*cols)/4096;
					y=((4095-y)*rows)/4096;	// (0,0) is lower left corner in our hardware
					tsc_choice=1+x+y*cols;	// return 1..rows*cols
#if 0
					while(pendown(NULL, NULL))
						{ // wait for pen-up
							if(tstc())
								break;
						}
#endif
					if(tstc())
						break;
#if 1
					printf("did choose %d/%d -> %d\n", x, y, tsc_choice);
#endif
					return 0;
				}
		}
	if(tstc())
		getc();
	return 0;
}

static int do_tsc(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	int len;
	
	if (argc < 2) {
		printf ("tsc: missing subcommand.\n");
		return (-1);
	}
	
	len = strlen (argv[1]);
	if (strncmp ("ge", argv[1], 2) == 0) {
		return do_tsc_get (argc, argv);
	} else if (strncmp ("lo", argv[1], 2) == 0) {
		return do_tsc_loop (argc, argv);
	} else if (strncmp ("gl", argv[1], 2) == 0) {
		return do_tsc_gloop (argc, argv);
	} else if (strncmp ("ch", argv[1], 2) == 0) {
		return do_tsc_choose (argc, argv);
	} else if (strncmp ("se", argv[1], 2) == 0) {
		return do_tsc_selection (argc, argv);
	} else if (strncmp ("in", argv[1], 2) == 0) {
		return do_tsc_init (argc, argv);
	} else {
		printf ("tsc: unknown operation: %s\n", argv[1]);
	}
	
	return (0);
}


U_BOOT_CMD(tsc, 4, 0, do_tsc, "TSC2007 sub-system",
		   "in[it] - initialize TSC2007\n"
		   "ge[t] - read ADCs\n"
		   "lo[op] - loop and display x/y coordinates\n"
		   "gl[oop] - loop and draw to framebuffer\n"
		   "ch[oose] cols rows - choose item\n"
		   "se[lection] p - check if item p (1 .. cols*rows) was selected\n"
		   );

/** Status commands */

static int do_status_init(int argc, char *const argv[])
{
	status_init();
	return 0;
}

static void print_buttons(int status)
{
	printf("AUX: %s Power: %s Antenna: %s Pen: %s", (status&0x01)?"on":"off", (status&0x08)?"on":"off", (status&0x02)?"EXT":"INT", (status&0x10)?"1":"0");
}

static int do_status_check(int argc, char *const argv[])
{ // can be used in if construct
	int state=status_get_buttons();
	if (argc < 3)
		{
			printf ("status check: missing mask.\n");
			return (-1);
		}
	state &= simple_strtoul(argv[2], NULL, 16);
	return (state != 0)?0:1;
}

static int do_status_get(int argc, char *const argv[])
{
	int status=status_get_buttons();
	printf("button status: %02x\n", status);
	print_buttons(status);
	printf("\n");
	return 0;
}

static int do_status_set(int argc, char *const argv[])
{ // status set hh
	static int state;
	if(argc == 2)
		state++;
	else
		state=simple_strtoul(argv[2], NULL, 16);
	status_set_status(state);
	return 0;
}

static int do_status_loop(int argc, char *const argv[])
{
	printf("mirroring buttons to LEDs.\n"
		   "Press any key to stop\n\n");
	while (!tstc() && !pendown(NULL, NULL))
		{
			int state=status_get_buttons();
			print_buttons(state);
			printf("\r");
			status_set_status(state);	// mirror to LEDs
			udelay(100000);	// 0.1 seconds
		}
	if(tstc())
		getc();
	printf("\n");
	return 0;
}

static int do_status_blink(int argc, char *const argv[])
{
	int value=0;
	printf("blinking LEDs.\n"
		   "Press any key to stop\n\n");
	while (!tstc() && !pendown(NULL, NULL))
		{
			status_set_status(value++);	// mirror to LEDs
			udelay(100000);	// 0.1 seconds
		}
	if(tstc())
		getc();
	return 0;
}

static int do_status_flash(int argc, char *const argv[])
{
	int len;
	
	if (argc < 3) {
		printf ("status flash: missing subcommand.\n");
		return (-1);
	}
	
	len = strlen (argv[2]);
	if (strncmp ("of", argv[2], 2) == 0) {
		return status_set_flash (0);
	} else if (strncmp ("on", argv[2], 2) == 0) {
		return status_set_flash (1);
	} else if (strncmp ("fl", argv[2], 2) == 0) {
		return status_set_flash (2);
	} else {
		printf ("status: unknown operation: %s\n", argv[1]);
		return 1;
	}
	return (0);
}

static int do_status_vibra(int argc, char *const argv[])
{
	static int value;
	if (argc < 3) {
		printf ("status vibra: missing value.\n");
		return (-1);
	}
	value=simple_strtol(argv[2], NULL, 10);
	return status_set_vibra(value);
}

static int do_status(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	int len;
	
	if (argc < 2) {
		printf ("status: missing subcommand.\n");
		return (-1);
	}
	
	len = strlen (argv[1]);
	if (strncmp ("ge", argv[1], 2) == 0) {
		return do_status_get (argc, argv);
	} else if (strncmp ("se", argv[1], 2) == 0) {
		return do_status_set (argc, argv);
	} else if (strncmp ("mi", argv[1], 2) == 0) {
		return do_status_loop (argc, argv);
	} else if (strncmp ("bl", argv[1], 2) == 0) {
		return do_status_blink (argc, argv);
	} else if (strncmp ("in", argv[1], 2) == 0) {
		return do_status_init (argc, argv);
	} else if (strncmp ("ch", argv[1], 2) == 0) {
		return do_status_check (argc, argv);
	} else if (strncmp ("fl", argv[1], 2) == 0) {
		return do_status_flash (argc, argv);
	} else if (strncmp ("vi", argv[1], 2) == 0) {
		return do_status_vibra (argc, argv);
	} else {
		printf ("status: unknown operation: %s\n", argv[1]);
	}
	
	return (0);
}


U_BOOT_CMD(status, 3, 0, do_status, "LED and Buttons sub-system",
		   "in[it] - initialize GPIOs\n"
		   "ge[t] - print button status\n"
		   "ch[eck] - check button status\n"
		   "se[t] value - set LEDs state\n"
		   "mi[rror] - read buttons and mirror to LEDs\n"
		   "bl[ink] - blink LEDs\n"
		   "fl[ash] of[f] | on | fl[ash] - control torch / flashlight\n"
		   "vi[bra] -256..256 - run vibracall motor\n"
		   );

/** GPS commands */

static int do_gps_init(int argc, char *const argv[])
{
	return gps_init();
}

static int do_gps_on(int argc, char *const argv[])
{
	// should we better send a single ongoing pulse of at least 2 32 kHz cycles?
	gps_on();
	printf("GPS on\n");
	return 0;
}

static int do_gps_off(int argc, char *const argv[])
{
	gps_off();
	printf("GPS off\n");
	return 0;
}

static int do_gps_echo(int argc, char *const argv[])
{
	gps_echo();
	return 0;
}

// FIXME: "gps cmd" to send a string

static int do_gps(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	int len;
	
	if (argc < 2) {
		printf ("gps: missing subcommand.\n");
		return (-1);
	}
	
	len = strlen (argv[1]);
	if (strncmp ("on", argv[1], 2) == 0) {
		return do_gps_on (argc, argv);
	} else if (strncmp ("of", argv[1], 2) == 0) {
		return do_gps_off (argc, argv);
	} else if (strncmp ("in", argv[1], 2) == 0) {
		return do_gps_init (argc, argv);
	} else if (strncmp ("ec", argv[1], 2) == 0) {
		return do_gps_echo (argc, argv);
	} else {
		printf ("gps: unknown operation: %s\n", argv[1]);
	}
	
	return (0);
}


U_BOOT_CMD(gps, 3, 0, do_gps, "GPS sub-system",
		   "init - initialize GPIOs\n"
		   "on - enable GPS\n"
		   "off - disable GPS\n"
		   "cmd string - send string\n"
		   "echo - echo GPS out to console\n"
		   );

#include "ulpi-phy.h"

static int do_systest_all(int argc, char *const argv[])
{
	unsigned short *fb=(void *) 0x81000000;	// base address to be used as RGB16 framebuffer
	printf("permanently doing complete systest.\n"
		   "Press any key to stop\n\n");
	omap3_dss_set_fb(fb);
	audiotest_init(0);
	while (!tstc() && (status_get_buttons()&0x09) == 0)
		{
		int i;
		for(i=0; i<8; i++)
			{
			int val=(480*read_adc(i))/4096;
			int x, y;
			printf("%d: %d\n", i, val);
			for(y=16*i; y<16*i+16; y++)
				{ // draw colored bar depending on current value
					for(x=0; x<480; x++)
						fb[x+480*y]=(x < val)?0xfc00:0x03ff;
				}
			}
		// show hardware test results (chip availability)
		// continue to play some sound every loop...
		}
	if(tstc())
		getc();
	printf("\n");
	return 0;
}

static int do_systest(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	if(argc >= 2) {
		if (strncmp ("au", argv[1], 2) == 0) {
			return audiotest(0);
		}
		if (strncmp ("al", argv[1], 2) == 0) {
			return do_systest_all (argc, argv);
		}
		if (strncmp ("ir", argv[1], 2) == 0) {
			return irdatest();
		}
		if (strncmp ("wl", argv[1], 2) == 0) {
			return wlanbttest(1);
		}
		if (strncmp ("wp", argv[1], 2) == 0) {
			return wlanbttest(0);	// just power on
		}
		if (strncmp ("ch", argv[1], 2) == 0) {
			return twl4030_init_battery_charging();
		}
	}
	if(argc == 3) {
		if (strncmp ("ot", argv[1], 2) == 0) {
			return OTGchargepump(simple_strtoul(argv[2], NULL, 10));			
		}
		if (strncmp ("ul", argv[1], 2) == 0) {
			int port=simple_strtoul(argv[2], NULL, 10);	/* 0, 1, ... */
			int reg;
			for(reg=0; reg <= 0x3f; reg++)
				printf("ulpi reg %02x: %02x\n", reg, ulpi_direct_access(port, reg, 0, 0));
		}
	}
	return systest();
}

U_BOOT_CMD(systest, 3, 0, do_systest, "System Test",
		   "all - graphical test mode\n"
		   "audio - test audio\n"
		   "irda - test IrDA\n"
		   "wlanbt - test WLAN/BT module\n"
		   "wp - apply power to WLAN/BT module\n"
		   "charging - init and test BCI/BKBAT\n"
		   "otg n - enable/disable OTG charge pump\n"
		   );


static int do_powerdown(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	backlight_set_level(0);
	jbt6k74_enter_state(0);
	jbt6k74_display_onoff(0);
	shutdown();	// finally shut down power
	printf ("failed to power down\n");
	return (0);
}

U_BOOT_CMD(powerdown, 2, 0, do_powerdown, "Powerdown",
		   "");

static int do_suspend(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	backlight_set_level(0);
	jbt6k74_enter_state(0);
	jbt6k74_display_onoff(0);
	suspend();	// put CPU in sleep mode so that it can be waked up by pressing the AUX button or other events
	printf ("suspend finished\n");
	return (0);
}

U_BOOT_CMD(suspend, 2, 0, do_suspend, "Suspend",
		   "");


static int do_mux(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	int cols=0;
	char *addr=(char *) 0x48002030;
	printf("PADCONF [0:15] [16:31]\n");
	while(addr < (char *) 0x48002A28) {
		u16 mux=*(u16 *) addr;
		if(cols == 0)
			printf("%08x", (unsigned int) addr);			
		printf(" %c%d%c", (mux&8)?((mux&0x10?'U':'D')):' ', (mux&7), (mux&0x100)?'I':'O');
		addr+=2;
		if(addr == (char *) 0x48002262)
			addr= (char *) 0x480025D8, cols=1;	// skip block and force new line
		if(addr == (char *) 0x480025FC)
			addr= (char *) 0x48002A00, cols=1;	// skip block and force new line
		if(++cols == 2) {
			printf("\n");
			cols=0;
		}
	}
	if(cols != 0)
		printf("\n");
	return (0);
}

U_BOOT_CMD(mux, 2, 0, do_mux, "Pinmux", "");


static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	int g;
	if(argc == 3) {
		if (strncmp ("on", argv[1], 2) == 0) {
			g=simple_strtoul(argv[2], NULL, 10);
			omap_request_gpio(g);
			omap_set_gpio_dataout(g, 1);
			//			omap_free_gpio(g); - switches back to input
			return 0;
		}
		else if (strncmp ("of", argv[1], 2) == 0) {
			g=simple_strtoul(argv[2], NULL, 10);
			omap_request_gpio(g);
			omap_set_gpio_dataout(g, 0);
			//			omap_free_gpio(g); - switches back to input
			return 0;
		}
		else if (strncmp ("in", argv[1], 2) == 0) {
			g=simple_strtoul(argv[2], NULL, 10);
			omap_request_gpio(g);
			omap_set_gpio_direction(g, 1);
			//			omap_free_gpio(g); - switches back to input
			return 0;
		}
		else if (strncmp ("ou", argv[1], 2) == 0) {
			g=simple_strtoul(argv[2], NULL, 10);
			omap_request_gpio(g);
			omap_set_gpio_direction(g, 0);
			//			omap_free_gpio(g); - switches back to input
			return 0;
		}
	}
	if(argc == 1 || argc == 3)
		{ // no arguments or from..to
			int i=0;
			int end=6*32;
			int n=10;	// number of columns
			int col=0;
			if(argc == 3) {
				i=simple_strtoul(argv[1], NULL, 10);
				end=simple_strtoul(argv[2], NULL, 10)+1;	// include
			}
			for(; i<end; i++)
				{
				if(col == 0)
					printf("%03d", i);
				printf(" %d", omap_get_gpio_datain(i));
				if(++col == n)
					printf("\n"), col=0;
				}
			if(col != 0)
				printf("\n");	// last line		
		}
	else if(argc == 2) { // n only
		if(omap_get_gpio_datain(simple_strtoul(argv[1], NULL, 10)))
			{
			printf("1\n");
			return 1;
			}
		else
			{
			printf("0\n");
			return 0;
			}
		}
	else {
		printf ("gpio: unknown subcommand.\n");
		return (-1);
	}

	return (0);
}

U_BOOT_CMD(gpio, 3, 0, do_gpio, "GPIO sub-system",
		   " - print all\n"
		   "n - print and return state\n"
		   "m n - print state in given range\n"
		   "on n - set to 1\n"
		   "of[f] n - set to 0\n"
		   "in n - switch to input\n"
		   "ou[t] n - switch to out (does not change pinmux!)\n"
		   );