Quote:
By the way, I was trying to configure PSC6 as a UART with a forth script...this should be a piece of cake. ;)
It is :)
Quote:
Does it is necessary to modify kernel code too?
The kernel only requires that it's described in the device tree properly, you can copy the PSC1 serial port entry for that (make sure you set cell-index to n - 1 though where n = PSCn or the kernel driver will probably have a hissy fit).
Quote:
I wonder if a fully functional driver in OF is needed in such case
No, but you don't get to use the PSC for OF output and boot stuff. Of course the early boot (everything before the (b) logo) will always go to PSC1 as it's the guaranteed available failsafe serial port.
Quote:
Wasn't there a machine code instruction to instruct the CPU to use the PSC6 as UART?
No :)
Here's the script for the PSC6 UART configuration;
Code:
\ FORTH
hex
0xF0002C00 VALUE psc6_base
\ fipbi (133Mhz / 32) in hex
3EF148 VALUE psc6_fipbid32
0x00 VALUE psc6_ctur_val
0x24 VALUE psc6_ctlr_val
0x0024 VALUE psc6_divider
\ 115200 -> 0x1C200
0x1C200 VALUE psc6_baudrate
0 VALUE psc6_var
0 VALUE psc6_var2
: psc6_config
\ Copy the baud rate if provided
depth
0<> IF
TO psc6_baudrate THEN
\ correct bad baud rate
psc6_baudrate
0= IF
0x1C200 TO psc6_baudrate THEN
psc6_fipbid32 psc6_baudrate / TO psc6_divider
psc6_divider 0x00ff AND TO psc6_ctlr_val
psc6_divider 8 >>a 0x00ff AND TO psc6_ctur_val
hex
0x0a psc6_base 0x08 + c!
0x00000000 psc6_base 0x40 + l! \ SICR set all to 0
0xDD00 psc6_base 0x04 + w!
psc6_ctur_val psc6_base 0x18 + c!
psc6_ctlr_val psc6_base 0x1C + c!
0x20 psc6_base 0x08 + c!
0x30 psc6_base 0x08 + c!
0x40 psc6_base 0x08 + c!
0x50 psc6_base 0x08 + c!
0x10 psc6_base 0x08 + c!
0x00 psc6_base 0x10 + c!
0x73 psc6_base 0x00 + c! \ MR1
0x13 psc6_base 0x00 + c! \ MR2
0x01 psc6_base 0x38 + c!
0x0000 psc6_base 0x14 + w!
0x00F8 psc6_base 0x6E + w!
0x00F8 psc6_base 0x8E + w!
0x001551124 0xf0000b00 l!
0x05 psc6_base 0x08 + c!
;
: psc6_putchar
depth
0<> IF
psc6_base 0x0c + c!
1 ms
THEN
;
: psc6_write
depth
1 > IF
TO psc6_var
TO psc6_var2
psc6_var 0 DO
psc6_var2 I + c@ psc6_putchar
LOOP
THEN
;
psc6_config
This was written by bplan. All this does is implement enough features to set the port up. The rest is up to you (although adding a device tree node here would mean it's already set to 115200)
What I tried to do in a derived version was implement a generic PSC serial driver the "proper" OF way (see the end of the IEEE 1275 documentation for a SCSI driver done "right", it's very similar in structure - with structures and functions etc. - to a C driver, just.. stack based)
However it's harder than it looks. This is all I can find right now (some very early version) with a structure for easier access to the registers, and an example device-tree entry;
Code:
\ FORTH
struct ( psc-registers )
1 field >mode
3 + 2 field >statusclock
2 + 1 field >command
3 + 4 field >txrxbuf
1 field >ipcracr
3 + 2 field >isrimr
2 + 1 field >ctur
3 + 1 field >ctlr
3 + 4 field >ac97slots
4 field >ac97cmd
4 field >ac97data
1 field >ivr-reserved
3 + 1 field >inport
3 + 1 field >outport1
3 + 1 field >outport0
3 + 4 field >sicr
1 field >ircr1
3 + 1 field >ircr2
3 + 1 field >irsdr
3 + 1 field >irmdr
3 + 1 field >irfdr
3 + 2 field >rfnum
2 + 2 field >tfnum
2 + 4 field >rfdata
2 field >rfstat
2 + 1 field >rfcntl
5 + 2 field >rfalarm
2 + 2 field >rfrptr
2 + 2 field >rfwptr
2 + 2 field >rflrfptr
2 + 2 field >rflwfptr
2 + 4 field >tfdata
2 field >tfstat
2 + 1 field >tfcntl
5 + 2 field >tfalarm
2 + 2 field >tfrptr
2 + 2 field >tfwptr
2 + 2 field >tflrfptr
2 + 2 field >tflwfptr
2 field >padding
constant /psc-regs
s" /builtin" find-device
new-device
0xf0002c00 instance value regs
s" serial" 2dup device-type device-name
s" 2-wire Serial on PSC6" encode-string s" .description" property
0xf0002c00 0x100 reg
s" mpc5200-psc-uart" encode-string
s" mpc5200b-psc-uart" encode-string
encode+
s" compatible" property
5 encode-int s" cell-index" property
finish-device