All times are UTC-06:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri May 30, 2008 5:36 am 
Offline

Joined: Mon Mar 31, 2008 11:15 am
Posts: 17
Location: Bari, Italy
How it is possible to configure PSC6 as a UART? Must it be done with a OF script?

Moreover, it is possible to redirect the OF output to an output different from PSC0?

(I wish it could be done on my usb-to-serial adapter, but i'm afraid not...)

Thx

Giammarco


Top
   
PostPosted: Fri May 30, 2008 10:46 am 
Offline
Site Admin

Joined: Fri Sep 24, 2004 1:39 am
Posts: 1589
Location: Austin, TX
Quote:
How it is possible to configure PSC6 as a UART? Must it be done with a OF script?
Yes, and yes.
Quote:
Moreover, it is possible to redirect the OF output to an output different from PSC0?
With a full enough serial driver, it is. I was writing one but got sidetracked. Writing Forth drivers is kind of difficult because there is very little documentation or example code, so it's a lot of trial and error from my point of view. But the serial driver is one of the simpler ones; since the PSC has simple FIFO operation you just write the values into a register as they are passed through, and read them out when asked. Setting the baud rate is simple enough too.

What you need to do is start from the Efika Device Tree Supplement - it contains most of what you need.
Code:
s" /builtin" find-device
new-device
s" serial" 2dup device-name device-type
0xf0002c00 0xff reg
s" MPC52xx UART on PSC6" encode-string " .description" property
s" mpc5200b-psc-uart" encode-string " compatible" property
5 encode-int " cell-index" property

\ interrupts here

: open ( ?? -- )
\ open function
;

: read ( ?? -- #bytes-read )
;
device-end
You get the gist. You need to play a lot with packages and parents, you have to read and parse the serial device arguments properly (I forget right now what the word is for "read next char from the input buffer") to make it work, but in the end, it will work for redirection (s" /builtin/serial@2c00" io)
Quote:
(I wish it could be done on my usb-to-serial adapter, but i'm afraid not...)
It's possible but it's probably 1,000 lines of Forth just to use the USB port properly, not to mention the adapter. I believe the OLPC firmware does include a driver though (for both traditional UART and USB one I think?), perhaps it could be adapted?

_________________
Matt Sealey


Top
   
PostPosted: Wed Jun 04, 2008 11:28 am 
Offline

Joined: Mon Mar 31, 2008 11:15 am
Posts: 17
Location: Bari, Italy
Thanks Neko, I'll take a look in the next weeks. Hope I will understand something of this Forth thing... :-)


Top
   
PostPosted: Thu Jun 05, 2008 5:33 am 
Offline
Site Admin

Joined: Fri Sep 24, 2004 1:39 am
Posts: 1589
Location: Austin, TX
Quote:
Thanks Neko, I'll take a look in the next weeks. Hope I will understand something of this Forth thing... :-)
It's really very simple when you get down to it; everything is a stack push or pop, or a direct write to memory (usually pulling from the stack) or read from memory (usually pushing to the stack)

I have some example code for PSC6 if you need it but it's not much more than setting the baud rate to 115200 and being able to put/get characters. It is certainly not an io redirectable driver, that is what I was attempting to fix.

If we can work together on this that'd be great, although I have little hardware around to test such a thing..

_________________
Matt Sealey


Top
   
 Post subject:
PostPosted: Tue Jun 17, 2008 7:38 am 
Offline

Joined: Mon Mar 31, 2008 11:15 am
Posts: 17
Location: Bari, Italy
Of course, I would be very happy to give my contribution. You can send the code by email and I'll try to make something useful on it. Of course, I promise I will try :)

By the way, I was trying to configure PSC6 as a UART with a forth script...this should be a piece of cake. ;)
At the moment this would be enough for us.

Does it is necessary to modify kernel code too? I wonder if a fully functional driver in OF is needed in such case
Wasn't there a machine code instruction to instruct the CPU to use the PSC6 as UART?

Thank you

Giammarco


Top
   
 Post subject:
PostPosted: Tue Jun 17, 2008 10:50 am 
Offline
Site Admin

Joined: Fri Sep 24, 2004 1:39 am
Posts: 1589
Location: Austin, TX
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

_________________
Matt Sealey


Top
   
 Post subject:
PostPosted: Tue Jul 08, 2008 8:40 am 
Offline

Joined: Mon Mar 31, 2008 11:15 am
Posts: 17
Location: Bari, Italy
If anyone is interested, this makes psc6 work as UART under Linux. It is actually renamed as ttyPSC1, and it works great. Probably lots of things are useless for this purpose, as the driver initializes the port again...by the way, it works.
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

s" /builtin" find-device
new-device
0xf0002c00 instance value regs
s" uart" device-name
s" serial" device-type
s" 2-wire Serial on PSC6" encode-string s" .description" property
0xf0002c00 0x100 reg
s" mpc5200-psc-uart" encode-string s" compatible" property
2 encode-int 4 encode-int encode+ 3 encode-int encode+ s" interrupts" property
\ 5 encode-int s" cell-index" property
finish-device
Matt, thanks for your always great support.

Giammarco


Top
   
 Post subject:
PostPosted: Tue Jul 08, 2008 2:43 pm 
Offline
Site Admin

Joined: Fri Sep 24, 2004 1:39 am
Posts: 1589
Location: Austin, TX
Quote:
If anyone is interested, this makes psc6 work as UART under Linux. It is actually renamed as ttyPSC1
Very nice!!!

I'm a little disappointed that Linux is too stupid to name the ttyPSCn after the PSC number. That said, saying it's ttyPSCn instead of the standard ttySn is stupid anyway.

Great work though :)

It's not much work to roll this into a real OF driver and allow redirection. Anyone up for it? :)

_________________
Matt Sealey


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 8 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
PowerDeveloper.org: Copyright © 2004-2012, Genesi USA, Inc. The Power Architecture and Power.org wordmarks and the Power and Power.org logos and related marks are trademarks and service marks licensed by Power.org.
All other names and trademarks used are property of their respective owners. Privacy Policy
Powered by phpBB® Forum Software © phpBB Group