#!/usr/bin/perl -w
#
# Copyright (C) 2002 M&N Logistik-Lösungen Online GmbH
# written by H.Schurig
# Released unter the GNU GPL, comes as-is, without any warranty
#
use strict;
sub ShowReg($$$)
{
my ($reg, $val, $page) = @_;
printf "%-8s 0xx = ", $reg . ':', $val;
my $i = 31;
my $mask = 0x80000000;
while ($i>=0) {
print $val & $mask ? '1' : '0';
print " " if $i == 8;
print " " if $i == 16;
print " " if $i == 24;
$i--;
$mask = $mask >> 1;
}
print " (Page $page)\n";
}
my @usage;
my ($gpdr0, $gpdr1, $gpdr2, $gafr0l, $gafr0h, $gafr1l, $gafr1h, $gafr2l, $gafr2h, $gpsr0, $gpsr1, $gpsr2, $gpcr0, $gpcr1, $gpcr2, $pgsr0, $pgsr1, $pgsr2);
my ($pwer, $prer, $pfer, $pcfr);
# values from dcpxa250.cfg
$gpdr0 = 0x00008000;
$gpdr1 = 0x00FF0002;
$gpdr2 = 0x0001C000;
$gafr0l = 0x98400000;
$gafr0h = 0x00002950;
$gafr1l = 0x000A9558;
$gafr1h = 0x0005AAAA;
$gafr2l = 0xA0000000;
$gafr2h = 0x00000002;
# Ipaq H3900:
$gpdr0 = 0xffd18804;
$gpdr1 = 0xfcffab93;
$gpdr2 = 0x0001ffff;
$gafr0l = 0x80400000;
$gafr0h = 0x00000010;
$gafr1l = 0x999a8458;
$gafr1h = 0xaaa50000;
$gafr2l = 0xaaaaaaaa;
$gafr2h = 0x00000002;
$gpsr0 = 0x00218104;
$gpsr1 = 0xfcbf0112;
$gpsr2 = 0x001fffff;
$pgsr0 = 0x0004b3b9;
$pgsr1 = 0x03bf0132;
$pgsr2 = 0x0001c000;
# Ramses (U-Boot);
$gpsr0 = 0x00008000 | (1<<17);
$gpsr1 = 0x00020002;
$gpsr2 = 0x0001c000;
$gpcr0 = 0x00000000;
$gpcr1 = 0x00000380;
$gpcr2 = 0x00000000;
$gafr0l = 0x88401000;
$gafr0h = 0xA600001a & ~ (3 << 2);
$gafr1l = 0x999a9558;
$gafr1h = 0xaaa5aaaa;
$gafr2l = 0xaaaaaaaa;
$gafr2h = 0x00000002;
$gpdr0 = 0xd003a840;
$gpdr1 = 0xfcffab82;
$gpdr2 = 0x0001ffff;
$pgsr0 = 0x00028000;
$pgsr1 = 0x00020002;
$pgsr2 = 0x0001c000;
$pwer = 0x00000008;
$prer = 0x00000008;
$pfer = 0x00000000;
$pcfr = 0x00000007;
@usage = ("nc", "nPFI", "BAT_DATA", "IRQ_KEY", "IRQ_ETH", # 0.. 4
"nc", "MMC_CLK", "IRQ_GSM", "nPCC_S1_CD","nMMC_CD", # 5.. 9
"IRQ_RTC", "nc 3M6", "nc", "IRQ_DOCK", "nc", # 10..14
"nc nCS1", "PWM0", "PWM1", "RDY", "nPCC_S0_IRQ", # 15..19
"nc", "AC97_IRQ", "nPCC_S1_IRQ","nc IRQ_GSM","UART_INTB", # 20..24
"UART_INTC", "UART_INTD","nc cpld free","AUD_BITCLK","AUD_SDIN0", # 25..29
"AUD_SDOUT", "AUD_SYNC", "USB_INT", "nCS5", "FF_RXD", # 30..34
"FF_CTS", "FF_DCD", "FF_DSR", "FF_RI", "FF_TXD", # 35..39
"FF_DTR", "FF_RTS", "BT_RXD", "BT_TXD", "BT_CTS", # 40..44
"BT_RTS", "IR_RXD", "IR_TXD", "nPOE", "nPWE", # 45..49
"nPIOR", "nPIOW", "nPCE1", "nPCE2", "nPKTSEL", # 50..54
"nPREG", "nPWAIT", "nIOIS16", "LDD0", "LDD1", # 55..59
"LDD2", "LDD3", "LDD4", "LDD5", "LDD6", # 60..64
"LDD7", "nc", "nc", "nc", "nc", # 65..69
"nc", "nc", "nc", "nc", "FCLK", # 70..74
"LCLK", "PCLK", "BIAS", "nCS2", "nCS3", # 75..79
"nCS4", "nc", "nc", "nc", "nc"); # 80..84
=for penkey
# Penkey 760
$gpdr0 = 0xc3e18042;
$gpdr1 = 0xfcffabc2;
$gpdr2 = 0x1ffff;
$gafr0l = 0x1000;
$gafr0h = 0xa51a8112;
$gafr1l = 0x699a8558;
$gafr1h = 0xaaa5aaaa;
$gafr2l = 0xaa2aaaaa;
$gafr2h = 0x0;
$gpsr0 = 0x9240515;
$gpsr1 = 0xfdffcfbe;
$gpsr2 = 0x1efff;
$gpcr0 = 0;
$gpcr1 = 0;
$gpcr2 = 0;
$pgsr0 = 0;
$pgsr1 = 0;
$pgsr2 = 0;
$pwer = 0;
$prer = 0;
$pfer = 0;
@usage = ("", "", "", "", "", # 0.. 4
"", "", "", "", "", # 5.. 9
"", "", "", "", "", # 10..14
"", "", "", "", "", # 15..19
"", "", "", "", "", # 20..24
"", "", "", "", "", # 25..29
"", "", "", "", "", # 30..34
"", "", "", "", "", # 35..39
"", "", "", "", "", # 40..44
"", "", "", "", "", # 45..49
"", "", "", "", "", # 50..54
"", "", "", "", "", # 55..59
"", "", "", "", "", # 60..64
"", "", "", "", "", # 65..69
"", "", "", "", "", # 70..74
"", "", "", "", "", # 75..79
"", "", "", "", ""); # 80..84
=cut
print " 33222222 22221111 11111100 00000000\n";
print " 10987654 32109876 54321098 76543210\n";
ShowReg('GPDR0', $gpdr0, '4-9');
ShowReg('GPDR1', $gpdr1, '4-9');
ShowReg('GPDR2', $gpdr2, '4-9');
ShowReg('GAFR0L', $gafr0l, '4-17');
ShowReg('GAFR0U', $gafr0h, '4-18');
ShowReg('GAFR1L', $gafr1l, '4-18');
ShowReg('GAFR1U', $gafr2l, '4-19');
ShowReg('GAFR2L', $gafr2l, '4-19');
ShowReg('GAFR2H', $gafr2h, '4-20');
ShowReg('GPSR0', $gpsr0, '4-10');
ShowReg('GPSR1', $gpsr1, '4-10');
ShowReg('GPSR2', $gpsr2, '4-11');
ShowReg('GPCR0', $gpcr0, '?');
ShowReg('GPCR1', $gpcr1, '?');
ShowReg('GPCR2', $gpcr2, '?');
ShowReg('PGSR0', $pgsr0, '255 3-31');
ShowReg('PGSR1', $pgsr1, '255 3-31');
ShowReg('PGSR2', $pgsr2, '255 3-31');
ShowReg('PWER', $pwer, '255 3-25');
ShowReg('PRER', $prer, '255 3-26');
ShowReg('PFER', $pfer, '255 3-27');
ShowReg('PCFR', $pcfr, '255 3-24');
my @func = (
# See Table 4-1 in PXA255 Processor Developer's Manual
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #0
['GP_RST', 'afo2', 'afi2', 'afo2', 'afi3', 'afo3' ], #1
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #2
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #3
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #4
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #5
['afi1', 'MMC_CLK', 'afi2', 'afo2', 'afi3', 'afo3' ], #6
['afi1', '48 MHz', 'afi2', 'afo2', 'afi3', 'afo3' ], #7
['afi1', 'MMC_CS0', 'afi2', 'afo2', 'afi3', 'afo3' ], #8
['afi1', 'MMC_CS1', 'afi2', 'afo2', 'afi3', 'afo3' ], #9
['afi1', 'RTCCLK', 'afi2', 'afo2', 'afi3', 'afo3' ], #10
['afi1', '3.6 MHz', 'afi2', 'afo2', 'afi3', 'afo3' ], #11
['afi1', '32 kHz', 'afi2', 'afo2', 'afi3', 'afo3' ], #12
['afi1', 'afo1', 'afi2', 'MBGNT', 'afi3', 'afo3' ], #13
['MBREQ', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #14
['afi1', 'afo1', 'afi2', 'nCS1', 'afi3', 'afo3' ], #15
['afi1', 'afo1', 'afi2', 'PWM0', 'afi3', 'afo3' ], #16
['afi1', 'afo1', 'afi2', 'PWM1', 'afi3', 'afo3' ], #17
['RDY', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #18
['DREQ1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #19
['DREQ0', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #20
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #21
['afi1', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #22
['afi1', 'afo1', 'afi2', 'SSP_CLK', 'afi3', 'afo3' ], #23
['afi1', 'afo1', 'afi2', 'SSP_FRM', 'afi3', 'afo3' ], #24
['afi1', 'afo1', 'afi2', 'SSP_TXD', 'afi3', 'afo3' ], #25
['SSP_RXD', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #26
['SSP_EXTCLK', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #27
['97_BITCLK', 'I2S_BITCLK', 'I2S_BITCLK', 'afo2', 'afi3', 'afo3' ], #28
['97_SDATAIN0','afo1', 'I2S_SDATAIN','afo2', 'afi3', 'afo3' ], #29
['afi1', 'I2S_SDATAOUT','afi2', '97_SDATAOUT','afi3', 'afo3' ], #30
['afi1', 'I2S_SYNC', 'afi2', '97_SYNC', 'afi3', 'afo3' ], #31
['97_SDATAIN1','I2S_SYSCLK', 'afi2', 'afo2', 'afi3', 'afo3' ], #32
['afi1', 'afo1', 'afi2', 'nCS5', 'afi3', 'afo3' ], #33
['FF_RXD', 'afo1', 'afi2', 'MMC_CS0', 'afi3', 'afo3' ], #34
['FF_CTS', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #35
['FF_DCD', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #36
['FF_DSR', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #37
['FF_RI', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #38
['afi1', 'MMC_CS1', 'afi2', 'FF_TXD', 'afi3', 'afo3' ], #39
['afi1', 'afo1', 'afi2', 'FF_DTR', 'afi3', 'afo3' ], #40
['afi1', 'afo1', 'afi2', 'FF_RTS', 'afi3', 'afo3' ], #41
['BT_RXD', 'afo1', 'afi2', 'afo2', 'HW_RXD', 'afo3' ], #42
['afi1', 'afo1', 'afi2', 'BT_TXD', 'afi3', 'HW_TXD' ], #43
['BT_CTS', 'afo1', 'afi2', 'afo2', 'HW_CTS', 'afo3' ], #44
['afi1', 'afo1', 'afi2', 'BT_RTS', 'afi3', 'HW_RTS' ], #45
['ICP_RXD', 'afo1', 'ST_RXD', 'afo2', 'afi3', 'afo3' ], #46
['afi1', 'ST_TXD', 'afi2', 'ICP_TXD', 'afi3', 'afo3' ], #47
['afi1', 'HW_TXD', 'afi2', 'nPOE', 'afi3', 'afo3' ], #48
['HW_RXD', 'afo1', 'afi2', 'nPWE', 'afi3', 'afo3' ], #49
['HW_CTS', 'afo1', 'afi2', 'nPIOR', 'afi3', 'afo3' ], #50
['afi1', 'HW_RTS', 'afi2', 'nPIOW', 'afi3', 'afo3' ], #51
['afi1', 'afo1', 'afi2', 'nPCE1', 'afi3', 'afo3' ], #52
['afi1', 'MMC_CLK', 'afi2', 'nPCE2', 'afi3', 'afo3' ], #53
['afi1', 'MMC_CLK', 'afi2', 'nPKTSEL', 'afi3', 'afo3' ], #54
['afi1', 'afo1', 'afi2', 'nPREG', 'afi3', 'afo3' ], #55
['nPWAIT', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #56
['nIOI16', 'afo1', 'afi2', 'afo2', 'afi3', 'afo3' ], #57
['afi1', 'afo1', 'afi2', 'LDD0', 'afi3', 'afo3' ], #58
['afi1', 'afo1', 'afi2', 'LDD1', 'afi3', 'afo3' ], #59
['afi1', 'afo1', 'afi2', 'LDD2', 'afi3', 'afo3' ], #60
['afi1', 'afo1', 'afi2', 'LDD3', 'afi3', 'afo3' ], #61
['afi1', 'afo1', 'afi2', 'LDD4', 'afi3', 'afo3' ], #62
['afi1', 'afo1', 'afi2', 'LDD5', 'afi3', 'afo3' ], #63
['afi1', 'afo1', 'afi2', 'LDD6', 'afi3', 'afo3' ], #64
['afi1', 'afo1', 'afi2', 'LDD7', 'afi3', 'afo3' ], #65
['MBREQ', 'afo1', 'afi2', 'LDD8', 'afi3', 'afo3' ], #66
['afi1', 'MMC_CS0', 'afi2', 'LDD9', 'afi3', 'afo3' ], #67
['afi1', 'MMC_CS1', 'afi2', 'LDD10', 'afi3', 'afo3' ], #68
['afi1', 'MMC_CLK', 'afi2', 'LDD11', 'afi3', 'afo3' ], #69
['afi1', 'RTC_CLK', 'afi2', 'LDD12', 'afi3', 'afo3' ], #70
['afi1', '3.6 MHz', 'afi2', 'LDD13', 'afi3', 'afo3' ], #71
['afi1', '32 kHz', 'afi2', 'LDD14', 'afi3', 'afo3' ], #72
['afi1', 'MBGNT', 'afi2', 'LDD15', 'afi3', 'afo3' ], #73
['afi1', 'afo1', 'afi2', 'FCLK', 'afi3', 'afo3' ], #74
['afi1', 'afo1', 'afi2', 'LCLK', 'afi3', 'afo3' ], #75
['afi1', 'afo1', 'afi2', 'PCLK', 'afi3', 'afo3' ], #76
['afi1', 'afo1', 'afi2', 'ACBIAS', 'afi3', 'afo3' ], #77
['afi1', 'afo1', 'afi2', 'nCS2', 'afi3', 'afo3' ], #78
['afi1', 'afo1', 'afi2', 'nCS3', 'afi3', 'afo3' ], #79
['afi1', 'afo1', 'afi2', 'nCS4', 'afi3', 'afo3' ], #80
['NSSP_SCLK', 'NSSP_SCLK', 'afi2', 'afo2', 'afi3', 'afo3' ], #81
['NSSP_SFRM', 'NSSP_SFRM', 'afi2', 'afo2', 'afi3', 'afo3' ], #82
['afi1', 'NSSP_TXD', 'NSSP_RXD', 'afo2', 'afi3', 'afo3' ], #83
['afi1', 'NSSP_TXD', 'NSSP_RXD', 'afo2', 'afi3', 'afo3' ], #84
);
my $i;
my (@dir,@set,@clr,@af,@sleep);
$i = 0;
while ($i<32) {
$dir[$i] = (($gpdr0 >> $i) & 1) ? 1 : 0;
$dir[$i+32] = (($gpdr1 >> $i) & 1) ? 1 : 0;
$dir[$i+64] = (($gpdr2 >> $i) & 1) ? 1 : 0;
$set[$i] = (($gpsr0 >> $i) & 1) ? 1 : 0;
$set[$i+32] = (($gpsr1 >> $i) & 1) ? 1 : 0;
$set[$i+64] = (($gpsr2 >> $i) & 1) ? 1 : 0;
$clr[$i] = (($gpcr0 >> $i) & 1) ? 1 : 0;
$clr[$i+32] = (($gpcr1 >> $i) & 1) ? 1 : 0;
$clr[$i+64] = (($gpcr2 >> $i) & 1) ? 1 : 0;
$sleep[$i] = (($pgsr0 >> $i) & 1) ? 1 : 0;
$sleep[$i+32] = (($pgsr1 >> $i) & 1) ? 1 : 0;
$sleep[$i+64] = (($pgsr2 >> $i) & 1) ? 1 : 0;
$i++;
}
$i = 0;
while ($i<16) {
$af[$i] = ($gafr0l >> ($i*2)) & 3;
$af[$i+16] = ($gafr0h >> ($i*2)) & 3;
$af[$i+32] = ($gafr1l >> ($i*2)) & 3;
$af[$i+48] = ($gafr1h >> ($i*2)) & 3;
$af[$i+64] = ($gafr2l >> ($i*2)) & 3;
$af[$i+80] = ($gafr2h >> ($i*2)) & 3;
$i++;
}
if ($pcfr & 2) { # PCFR_FP
$sleep[48] = 'f'; # nPOE
$sleep[49] = 'f'; # nPWE
$sleep[50] = 'f'; # nIOR
$sleep[51] = 'f'; # nOIW
$sleep[52] = 'f'; # nPCE1
$sleep[53] = 'f'; # nPCE2
}
if ($pcfr & 4) { # PCFR_FS
$sleep[15] = 'f'; # nCS1
$sleep[78] = 'f'; # nCS2
$sleep[79] = 'f'; # nCS3
$sleep[80] = 'f'; # nCS4
$sleep[33] = 'f'; # nCS5
}
print "\nGPIO Usage Dir Alternate Function Set Clr Sleep PWER PRER PFER\n";
$i = 0;
while ($i<=84) {
my ($f, @pwer_arr, @prer_arr, @pfer_arr);
if ($af[$i]) {
my $n = ($af[$i]-1)*2 + $dir[$i];
$f = $func[$i][$n];
} else {
$f = sprintf("gpio - ", $i);
}
if ($i<=15) {
$pwer_arr[$i] = ($pwer & (1 << $i)) ? '1' : '0';
$prer_arr[$i] = ($prer & (1 << $i)) ? '1' : '0';
$pfer_arr[$i] = ($pfer & (1 << $i)) ? '1' : '0';
} else {
$pwer_arr[$i] = '-';
$prer_arr[$i] = '-';
$pfer_arr[$i] = '-';
}
printf "M %-12s %-3s %d %-17s %-3d %-3d %-5s %-4s %-4s %-4s\n",
$i, $usage[$i], $dir[$i] ? 'out' : 'in', $af[$i], $f, $set[$i], $clr[$i],
$sleep[$i], $pwer_arr[$i], $prer_arr[$i], $pfer_arr[$i];
$i++;
}