All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] Documentation about RS485 serial communications
@ 2010-08-11 20:23 ` Randy Dunlap
  0 siblings, 0 replies; 64+ messages in thread
From: Randy Dunlap @ 2010-08-11 20:20 UTC (permalink / raw)
  To: claudio
  Cc: alan, jiri.prchal, rick, akpm, ryan, w.sang, rmk, nicolas.ferre,
	br, gregkh, Sebastian.Heutling, hskinnemoen, linux-arm-kernel,
	elektrolot, mattheis, linux-kernel, john, phdm

----- Original Message -----
From: claudio@evidence.eu.com
To: randy.dunlap@oracle.com
Sent: Wednesday, August 11, 2010 12:59:08 PM GMT -08:00 US/Canada Pacific
Subject: Re: [PATCH] Documentation about RS485 serial communications

Hi Randy,

	thank you for the feedback.

[...]

> 
> TIOC[SG]RS485 are #defined in <asm-generic/ioctls.h>, so
> #include <asm-generic/ioctls.h>
> here and/or below (in userspace program).
> 

I noticed that for some architectures (e.g., cris) these ioctls are defined also in arch/cris/include/asm/ioctls.h, and with different values with respect to the values defined on asm-generic/ioctls.h.

Therefore, I wasn't completely sure that the values defined in asm-generic are being used in every driver...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oh, OK, I see.  Thanks for the info.

~Randy

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-11 20:23 ` Randy Dunlap
  0 siblings, 0 replies; 64+ messages in thread
From: Randy Dunlap @ 2010-08-11 20:23 UTC (permalink / raw)
  To: linux-arm-kernel

----- Original Message -----
From: claudio@evidence.eu.com
To: randy.dunlap at oracle.com
Sent: Wednesday, August 11, 2010 12:59:08 PM GMT -08:00 US/Canada Pacific
Subject: Re: [PATCH] Documentation about RS485 serial communications

Hi Randy,

	thank you for the feedback.

[...]

> 
> TIOC[SG]RS485 are #defined in <asm-generic/ioctls.h>, so
> #include <asm-generic/ioctls.h>
> here and/or below (in userspace program).
> 

I noticed that for some architectures (e.g., cris) these ioctls are defined also in arch/cris/include/asm/ioctls.h, and with different values with respect to the values defined on asm-generic/ioctls.h.

Therefore, I wasn't completely sure that the values defined in asm-generic are being used in every driver...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oh, OK, I see.  Thanks for the info.

~Randy

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 20:04                                                         ` Alan Cox
@ 2010-11-30 19:19                                                           ` Pavel Machek
  -1 siblings, 0 replies; 64+ messages in thread
From: Pavel Machek @ 2010-11-30 19:19 UTC (permalink / raw)
  To: Alan Cox; +Cc: Grant Edwards, linux-kernel, linux-serial, linux-arm-kernel

On Tue 2010-11-16 20:04:26, Alan Cox wrote:
> > Comtrol, Moxa, B&B, Sealevel, and others all sell PCI cards and
> > Ethernet attached serial ports that have selectable interfaces
> > (typically RS-232/422/485).  Comtrol and Moxa have had drivers in the
> > kernel tree for ages, but they've always had to use custom ioctl calls
> > for things like configuring 232/485/422 mode and half/full-duplex
> > mode.
> 
> Ok so what is needed that isn't covered by the current termiox and
> TIOCG/SRS485 ioctls ?

IIRC selection of 232/485/422 mode was missing from proposed api.

> > Having a standard API for things like interface mode, half-full
> > duplex, inter-character timeout, 9-bit mode, and so on would be life a
> > lot easier for those of us who maintain Linux serial drivers...
> 
> 9bit mode is a real problem with the tty layer defined in terms of 8bit
> streams but yes.

Well, if you wanted to have some fun... kontron card is able to
timestamp incoming characters, and saves state of the control signals
when character is received...
								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-30 19:19                                                           ` Pavel Machek
  0 siblings, 0 replies; 64+ messages in thread
From: Pavel Machek @ 2010-11-30 19:19 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue 2010-11-16 20:04:26, Alan Cox wrote:
> > Comtrol, Moxa, B&B, Sealevel, and others all sell PCI cards and
> > Ethernet attached serial ports that have selectable interfaces
> > (typically RS-232/422/485).  Comtrol and Moxa have had drivers in the
> > kernel tree for ages, but they've always had to use custom ioctl calls
> > for things like configuring 232/485/422 mode and half/full-duplex
> > mode.
> 
> Ok so what is needed that isn't covered by the current termiox and
> TIOCG/SRS485 ioctls ?

IIRC selection of 232/485/422 mode was missing from proposed api.

> > Having a standard API for things like interface mode, half-full
> > duplex, inter-character timeout, 9-bit mode, and so on would be life a
> > lot easier for those of us who maintain Linux serial drivers...
> 
> 9bit mode is a real problem with the tty layer defined in terms of 8bit
> streams but yes.

Well, if you wanted to have some fun... kontron card is able to
timestamp incoming characters, and saves state of the control signals
when character is received...
								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 18:03                                                     ` Grant Edwards
@ 2010-11-16 20:04                                                         ` Alan Cox
  0 siblings, 0 replies; 64+ messages in thread
From: Alan Cox @ 2010-11-16 20:04 UTC (permalink / raw)
  To: Grant Edwards; +Cc: linux-kernel, linux-serial, linux-arm-kernel

> Comtrol, Moxa, B&B, Sealevel, and others all sell PCI cards and
> Ethernet attached serial ports that have selectable interfaces
> (typically RS-232/422/485).  Comtrol and Moxa have had drivers in the
> kernel tree for ages, but they've always had to use custom ioctl calls
> for things like configuring 232/485/422 mode and half/full-duplex
> mode.

Ok so what is needed that isn't covered by the current termiox and
TIOCG/SRS485 ioctls ?

> Having a standard API for things like interface mode, half-full
> duplex, inter-character timeout, 9-bit mode, and so on would be life a
> lot easier for those of us who maintain Linux serial drivers...

9bit mode is a real problem with the tty layer defined in terms of 8bit
streams but yes.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 20:04                                                         ` Alan Cox
  0 siblings, 0 replies; 64+ messages in thread
From: Alan Cox @ 2010-11-16 20:04 UTC (permalink / raw)
  To: linux-arm-kernel

> Comtrol, Moxa, B&B, Sealevel, and others all sell PCI cards and
> Ethernet attached serial ports that have selectable interfaces
> (typically RS-232/422/485).  Comtrol and Moxa have had drivers in the
> kernel tree for ages, but they've always had to use custom ioctl calls
> for things like configuring 232/485/422 mode and half/full-duplex
> mode.

Ok so what is needed that isn't covered by the current termiox and
TIOCG/SRS485 ioctls ?

> Having a standard API for things like interface mode, half-full
> duplex, inter-character timeout, 9-bit mode, and so on would be life a
> lot easier for those of us who maintain Linux serial drivers...

9bit mode is a real problem with the tty layer defined in terms of 8bit
streams but yes.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 18:41                                                       ` Matt Schulte
  (?)
  (?)
@ 2010-11-16 19:29                                                       ` Grant Edwards
  -1 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-11-16 19:29 UTC (permalink / raw)
  To: linux-serial; +Cc: linux-arm-kernel, linux-kernel

On 2010-11-16, Matt Schulte <matts@commtech-fastcom.com> wrote:

>>> In my opinion this type of card is not that common. ?Generally
>>> speaking the achievable baud rates for this type of multi-protocol
>>> card are very limited because of limitations of the transceiver
>>> chips.
>>
>> I'm curious which selectable interface cards you're talking about
>> that are slow? ?The ones I'm familiar with generally support baud
>> rates up to either 460K bps or 921K bps
>>
>>> It seems that most of the time people would rather have a faster
>>> serial port than one that does several different voltages.
>>
>> Where did you find a selectable interface serial card that couldn't
>> support high baud rates?
>
> In my world 460kbps for an RS422 card is slow.  RS422 cards generally
> push multi megabit/s rates.

Ah, I see.  That's a completely different market than the markets
served by the multi-interface cards that typically max out at 921K.
I've support multi-interface cards for years and years, and I find it
very rare that anybody uses anything much faster than 19.2K.

-- 
Grant Edwards               grant.b.edwards        Yow! TAILFINS!! ... click
                                  at               ...
                              gmail.com            


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 16:28                                                   ` Grant Edwards
  2010-11-16 18:41                                                       ` Matt Schulte
@ 2010-11-16 18:41                                                       ` Matt Schulte
  0 siblings, 0 replies; 64+ messages in thread
From: Matt Schulte @ 2010-11-16 18:41 UTC (permalink / raw)
  To: Grant Edwards; +Cc: linux-serial, linux-arm-kernel, linux-kernel

On Tue, Nov 16, 2010 at 10:28 AM, Grant Edwards
<grant.b.edwards@gmail.com> wrote:
> On 2010-11-16, Matt Schulte <matts@commtech-fastcom.com> wrote:
>> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
>>> Hi!
>>>
>>>> Documentation about RS485 serial communications
>>>
>>> I have seen hardware (kontron pmc-6l) that was capable of switching
>>> between RS232, RS485 and one other standard by software.
>>>
>>> Is such hw common? If so, should we have standard interface?
>>
>> In my opinion this type of card is not that common.  Generally
>> speaking the achievable baud rates for this type of multi-protocol
>> card are very limited because of limitations of the transceiver chips.
>
> I'm curious which selectable interface cards you're talking about that
> are slow?  The ones I'm familiar with generally support baud rates up
> to either 460K bps or 921K bps
>
>> It seems that most of the time people would rather have a faster
>> serial port than one that does several different voltages.
>
> Where did you find a selectable interface serial card that couldn't
> support high baud rates?

In my world 460kbps for an RS422 card is slow.  RS422 cards generally
push multi megabit/s rates.

Matt Schulte

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 18:41                                                       ` Matt Schulte
  0 siblings, 0 replies; 64+ messages in thread
From: Matt Schulte @ 2010-11-16 18:41 UTC (permalink / raw)
  To: Grant Edwards; +Cc: linux-serial, linux-arm-kernel, linux-kernel

On Tue, Nov 16, 2010 at 10:28 AM, Grant Edwards
<grant.b.edwards@gmail.com> wrote:
> On 2010-11-16, Matt Schulte <matts@commtech-fastcom.com> wrote:
>> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
>>> Hi!
>>>
>>>> Documentation about RS485 serial communications
>>>
>>> I have seen hardware (kontron pmc-6l) that was capable of switching
>>> between RS232, RS485 and one other standard by software.
>>>
>>> Is such hw common? If so, should we have standard interface?
>>
>> In my opinion this type of card is not that common.  Generally
>> speaking the achievable baud rates for this type of multi-protocol
>> card are very limited because of limitations of the transceiver chips.
>
> I'm curious which selectable interface cards you're talking about that
> are slow?  The ones I'm familiar with generally support baud rates up
> to either 460K bps or 921K bps
>
>> It seems that most of the time people would rather have a faster
>> serial port than one that does several different voltages.
>
> Where did you find a selectable interface serial card that couldn't
> support high baud rates?

In my world 460kbps for an RS422 card is slow.  RS422 cards generally
push multi megabit/s rates.

Matt Schulte
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 18:41                                                       ` Matt Schulte
  0 siblings, 0 replies; 64+ messages in thread
From: Matt Schulte @ 2010-11-16 18:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Nov 16, 2010 at 10:28 AM, Grant Edwards
<grant.b.edwards@gmail.com> wrote:
> On 2010-11-16, Matt Schulte <matts@commtech-fastcom.com> wrote:
>> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
>>> Hi!
>>>
>>>> Documentation about RS485 serial communications
>>>
>>> I have seen hardware (kontron pmc-6l) that was capable of switching
>>> between RS232, RS485 and one other standard by software.
>>>
>>> Is such hw common? If so, should we have standard interface?
>>
>> In my opinion this type of card is not that common. ?Generally
>> speaking the achievable baud rates for this type of multi-protocol
>> card are very limited because of limitations of the transceiver chips.
>
> I'm curious which selectable interface cards you're talking about that
> are slow? ?The ones I'm familiar with generally support baud rates up
> to either 460K bps or 921K bps
>
>> It seems that most of the time people would rather have a faster
>> serial port than one that does several different voltages.
>
> Where did you find a selectable interface serial card that couldn't
> support high baud rates?

In my world 460kbps for an RS422 card is slow.  RS422 cards generally
push multi megabit/s rates.

Matt Schulte

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 17:20                                                     ` Alan Cox
  (?)
@ 2010-11-16 18:03                                                     ` Grant Edwards
  2010-11-16 20:04                                                         ` Alan Cox
  -1 siblings, 1 reply; 64+ messages in thread
From: Grant Edwards @ 2010-11-16 18:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-serial, linux-arm-kernel

On 2010-11-16, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> On Tue, 16 Nov 2010 10:13:22 -0600
> Matt Schulte <matts@commtech-fastcom.com> wrote:
>
>> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
>> > Hi!
>> >
>> >> Documentation about RS485 serial communications
>> >
>> > I have seen hardware (kontron pmc-6l) that was capable of switching
>> > between RS232, RS485 and one other standard by software.
>> >
>> > Is such hw common? If so, should we have standard interface?
>> 
>> In my opinion this type of card is not that common.  Generally
>> speaking the achievable baud rates for this type of multi-protocol
>> card are very limited because of limitations of the transceiver chips.
>>  It seems that most of the time people would rather have a faster
>> serial port than one that does several different voltages
>
> If there are two types in common use then thats enough to say we should
> have a common interface IMHO

Comtrol, Moxa, B&B, Sealevel, and others all sell PCI cards and
Ethernet attached serial ports that have selectable interfaces
(typically RS-232/422/485).  Comtrol and Moxa have had drivers in the
kernel tree for ages, but they've always had to use custom ioctl calls
for things like configuring 232/485/422 mode and half/full-duplex
mode.

There are also tons of small Linux-based industrial server appliances
from Comtrol, Silex, Digi, Moxa, and others that have selectable
interface serial ports.

Having a standard API for things like interface mode, half-full
duplex, inter-character timeout, 9-bit mode, and so on would be life a
lot easier for those of us who maintain Linux serial drivers...

-- 
Grant Edwards               grant.b.edwards        Yow! I always have fun
                                  at               because I'm out of my
                              gmail.com            mind!!!


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 16:13                                                   ` Matt Schulte
@ 2010-11-16 17:20                                                     ` Alan Cox
  -1 siblings, 0 replies; 64+ messages in thread
From: Alan Cox @ 2010-11-16 17:20 UTC (permalink / raw)
  To: Matt Schulte
  Cc: Pavel Machek, Claudio Scordino, Greg KH, Nicolas Ferre,
	linux-serial, Grant Edwards, linux-arm-kernel, linux-kernel

On Tue, 16 Nov 2010 10:13:22 -0600
Matt Schulte <matts@commtech-fastcom.com> wrote:

> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
> > Hi!
> >
> >> Documentation about RS485 serial communications
> >
> > I have seen hardware (kontron pmc-6l) that was capable of switching
> > between RS232, RS485 and one other standard by software.
> >
> > Is such hw common? If so, should we have standard interface?
> 
> In my opinion this type of card is not that common.  Generally
> speaking the achievable baud rates for this type of multi-protocol
> card are very limited because of limitations of the transceiver chips.
>  It seems that most of the time people would rather have a faster
> serial port than one that does several different voltages

If there are two types in common use then thats enough to say we should
have a common interface IMHO

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 17:20                                                     ` Alan Cox
  0 siblings, 0 replies; 64+ messages in thread
From: Alan Cox @ 2010-11-16 17:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 16 Nov 2010 10:13:22 -0600
Matt Schulte <matts@commtech-fastcom.com> wrote:

> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
> > Hi!
> >
> >> Documentation about RS485 serial communications
> >
> > I have seen hardware (kontron pmc-6l) that was capable of switching
> > between RS232, RS485 and one other standard by software.
> >
> > Is such hw common? If so, should we have standard interface?
> 
> In my opinion this type of card is not that common.  Generally
> speaking the achievable baud rates for this type of multi-protocol
> card are very limited because of limitations of the transceiver chips.
>  It seems that most of the time people would rather have a faster
> serial port than one that does several different voltages

If there are two types in common use then thats enough to say we should
have a common interface IMHO

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 16:13                                                   ` Matt Schulte
  (?)
@ 2010-11-16 16:28                                                   ` Grant Edwards
  2010-11-16 18:41                                                       ` Matt Schulte
  -1 siblings, 1 reply; 64+ messages in thread
From: Grant Edwards @ 2010-11-16 16:28 UTC (permalink / raw)
  To: linux-serial; +Cc: linux-arm-kernel, linux-kernel

On 2010-11-16, Matt Schulte <matts@commtech-fastcom.com> wrote:
> On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
>> Hi!
>>
>>> Documentation about RS485 serial communications
>>
>> I have seen hardware (kontron pmc-6l) that was capable of switching
>> between RS232, RS485 and one other standard by software.
>>
>> Is such hw common? If so, should we have standard interface?
>
> In my opinion this type of card is not that common.  Generally
> speaking the achievable baud rates for this type of multi-protocol
> card are very limited because of limitations of the transceiver chips.

I'm curious which selectable interface cards you're talking about that
are slow?  The ones I'm familiar with generally support baud rates up
to either 460K bps or 921K bps

> It seems that most of the time people would rather have a faster
> serial port than one that does several different voltages.

Where did you find a selectable interface serial card that couldn't
support high baud rates?

-- 
Grant Edwards               grant.b.edwards        Yow! Well, O.K.
                                  at               I'll compromise with my
                              gmail.com            principles because of
                                                   EXISTENTIAL DESPAIR!


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 14:30                                                 ` Pavel Machek
@ 2010-11-16 16:13                                                   ` Matt Schulte
  -1 siblings, 0 replies; 64+ messages in thread
From: Matt Schulte @ 2010-11-16 16:13 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Claudio Scordino, Greg KH, Nicolas Ferre, linux-serial,
	Grant Edwards, linux-arm-kernel, linux-kernel, Alan Cox

On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> Documentation about RS485 serial communications
>
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.
>
> Is such hw common? If so, should we have standard interface?

In my opinion this type of card is not that common.  Generally
speaking the achievable baud rates for this type of multi-protocol
card are very limited because of limitations of the transceiver chips.
 It seems that most of the time people would rather have a faster
serial port than one that does several different voltages.

Matt Schulte

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 16:13                                                   ` Matt Schulte
  0 siblings, 0 replies; 64+ messages in thread
From: Matt Schulte @ 2010-11-16 16:13 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Nov 16, 2010 at 8:30 AM, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> Documentation about RS485 serial communications
>
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.
>
> Is such hw common? If so, should we have standard interface?

In my opinion this type of card is not that common.  Generally
speaking the achievable baud rates for this type of multi-protocol
card are very limited because of limitations of the transceiver chips.
 It seems that most of the time people would rather have a faster
serial port than one that does several different voltages.

Matt Schulte

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 14:58                                                 ` Tosoni
@ 2010-11-16 15:52                                                   ` Grant Edwards
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-11-16 15:52 UTC (permalink / raw)
  To: linux-serial

On 2010-11-16, Tosoni <jp.tosoni@acksys.fr> wrote:

>> I have seen hardware (kontron pmc-6l) that was capable of switching
>> between RS232, RS485 and one other standard by software.
>>
>> Is such hw common? If so, should we have standard interface?
>
> I believe it is neither common nor a good thing.

People who need multiple interface types disagree with you as to
whether it's a good thing or not.

> Dynamically switching between electrical levels means that the remote
> device must be capable of handling both electrical levels, else it
> might be damaged (i.e., when the serial card is configured to RS485
> but switches to RS232 when reset).

Nobody said anything about doing it "dynamically", and if you read the
manuals for the cards in question, it specifically says not to do
that. [Though if you look at the electrical specs for any reputable
RS485/422/232 driver/receiver you'll see that they're all spec'ed to
withstand that sort of thing without damage.]

The way it's done is that the card is installed, the ports are
configured, and then the cabling is hooked up.

> Or, different pins must be used for RS232 and RS485 (then software
> switching is not really useful).

That's not usually how it's done.

-- 
Grant Edwards               grant.b.edwards        Yow! Don't hit me!!  I'm in
                                  at               the Twilight Zone!!!
                              gmail.com            


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 14:30                                                 ` Pavel Machek
@ 2010-11-16 15:28                                                   ` Alexander Stein
  -1 siblings, 0 replies; 64+ messages in thread
From: Alexander Stein @ 2010-11-16 15:28 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Pavel Machek, Claudio Scordino, Grant Edwards, Greg KH,
	Nicolas Ferre, linux-kernel, Alan Cox, linux-serial

Hello,

On Tuesday 16 November 2010, 15:30:16 Pavel Machek wrote:
> > Documentation about RS485 serial communications
> 
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.

Maybe you mean RS422 here.

> Is such hw common? If so, should we have standard interface?

Especially in industrial system, you may have RS485 or RS422 additionally to 
RS232. This also often means switching some GPIO to change the external signal 
levels. Any the drivers must also be capable of turning on and off the 
transmitter.

Best regards,
Alexander

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 15:28                                                   ` Alexander Stein
  0 siblings, 0 replies; 64+ messages in thread
From: Alexander Stein @ 2010-11-16 15:28 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

On Tuesday 16 November 2010, 15:30:16 Pavel Machek wrote:
> > Documentation about RS485 serial communications
> 
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.

Maybe you mean RS422 here.

> Is such hw common? If so, should we have standard interface?

Especially in industrial system, you may have RS485 or RS422 additionally to 
RS232. This also often means switching some GPIO to change the external signal 
levels. Any the drivers must also be capable of turning on and off the 
transmitter.

Best regards,
Alexander

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-16 14:30                                                 ` Pavel Machek
@ 2010-11-16 15:23                                                   ` Grant Edwards
  -1 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-11-16 15:23 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: linux-kernel, linux-serial

On 2010-11-16, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> Documentation about RS485 serial communications
>
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.
>
> Is such hw common? If so, should we have standard interface?

I wouldn't say it's common, but it's not all that rare either.  I
could probably name a half-dozen companies that make serial cards that
have software selectable interface types (my employer makes quite a
few).

-- 
Grant Edwards               grant.b.edwards        Yow! I'm dressing up in
                                  at               an ill-fitting IVY-LEAGUE
                              gmail.com            SUIT!!  Too late...

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 15:23                                                   ` Grant Edwards
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-11-16 15:23 UTC (permalink / raw)
  To: linux-arm-kernel

On 2010-11-16, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> Documentation about RS485 serial communications
>
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.
>
> Is such hw common? If so, should we have standard interface?

I wouldn't say it's common, but it's not all that rare either.  I
could probably name a half-dozen companies that make serial cards that
have software selectable interface types (my employer makes quite a
few).

-- 
Grant Edwards               grant.b.edwards        Yow! I'm dressing up in
                                  at               an ill-fitting IVY-LEAGUE
                              gmail.com            SUIT!!  Too late...

^ permalink raw reply	[flat|nested] 64+ messages in thread

* RE: [PATCH] Documentation about RS485 serial communications
  2010-11-16 14:30                                                 ` Pavel Machek
  (?)
  (?)
@ 2010-11-16 14:58                                                 ` Tosoni
  2010-11-16 15:52                                                   ` Grant Edwards
  -1 siblings, 1 reply; 64+ messages in thread
From: Tosoni @ 2010-11-16 14:58 UTC (permalink / raw)
  To: 'Pavel Machek', 'Claudio Scordino'
  Cc: linux-serial, 'Greg KH'

Hi,

> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.
>
> Is such hw common? If so, should we have standard interface?

I believe it is neither common nor a good thing.

Dynamically switching between electrical levels means that the remote device
must be capable of handling both electrical levels, else it might be damaged
(i.e., when the serial card is configured to RS485 but switches to RS232
when reset).

Or, different pins must be used for RS232 and RS485 (then software switching
is not really useful).

Jean-Pierre Tosoni

> -----Original Message-----
> From: linux-serial-owner@vger.kernel.org
> [mailto:linux-serial-owner@vger.kernel.org]On Behalf Of Pavel Machek
> Sent: Tuesday, November 16, 2010 3:30 PM
> To: Claudio Scordino
> Cc: Greg KH; Nicolas Ferre; linux-serial@vger.kernel.org;
> Grant Edwards;
> linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org; Alan
> Cox
> Subject: Re: [PATCH] Documentation about RS485 serial communications
>
>
> Hi!
>
> > Documentation about RS485 serial communications
>
> I have seen hardware (kontron pmc-6l) that was capable of switching
> between RS232, RS485 and one other standard by software.
>
> Is such hw common? If so, should we have standard interface?
>
> > +   From user-level, RS485 configuration can be get/set
> using the previous
> > +   ioctls. For instance, to set RS485 you can use the
> following code:
> > +
> > +	#include <linux/serial.h>
> > +
> > +	/* Driver-specific ioctls: */
> > +	#define TIOCGRS485      0x542E
> > +	#define TIOCSRS485      0x542F
> > +
> > +	/* Open your specific device (e.g., /dev/mydevice): */
> > +	int fd = open ("/dev/mydevice", O_RDWR);
> > +	if (fd < 0) {
> > +		/* Error handling. See errno. */
> > +	}
> > +
> > +	struct serial_rs485 rs485conf;
> > +
> > +	/* Set RS485 mode: */
> > +	rs485conf.flags |= SER_RS485_ENABLED;
>
> IOW... is this supposed to switch electrical levels?
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures)
> http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-serial" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-11 10:22                                               ` Claudio Scordino
  (?)
@ 2010-11-16 14:30                                                 ` Pavel Machek
  -1 siblings, 0 replies; 64+ messages in thread
From: Pavel Machek @ 2010-11-16 14:30 UTC (permalink / raw)
  To: Claudio Scordino
  Cc: Greg KH, Nicolas Ferre, linux-serial, Grant Edwards,
	linux-arm-kernel, linux-kernel, Alan Cox

Hi!

> Documentation about RS485 serial communications

I have seen hardware (kontron pmc-6l) that was capable of switching
between RS232, RS485 and one other standard by software.

Is such hw common? If so, should we have standard interface?

> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	if (fd < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;

IOW... is this supposed to switch electrical levels?

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 14:30                                                 ` Pavel Machek
  0 siblings, 0 replies; 64+ messages in thread
From: Pavel Machek @ 2010-11-16 14:30 UTC (permalink / raw)
  To: Claudio Scordino
  Cc: Grant Edwards, Greg KH, Nicolas Ferre, linux-kernel, Alan Cox,
	linux-serial, linux-arm-kernel

Hi!

> Documentation about RS485 serial communications

I have seen hardware (kontron pmc-6l) that was capable of switching
between RS232, RS485 and one other standard by software.

Is such hw common? If so, should we have standard interface?

> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	if (fd < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;

IOW... is this supposed to switch electrical levels?

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-16 14:30                                                 ` Pavel Machek
  0 siblings, 0 replies; 64+ messages in thread
From: Pavel Machek @ 2010-11-16 14:30 UTC (permalink / raw)
  To: linux-arm-kernel

Hi!

> Documentation about RS485 serial communications

I have seen hardware (kontron pmc-6l) that was capable of switching
between RS232, RS485 and one other standard by software.

Is such hw common? If so, should we have standard interface?

> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	if (fd < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;

IOW... is this supposed to switch electrical levels?

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-10 17:28                                             ` Greg KH
@ 2010-11-11 10:22                                               ` Claudio Scordino
  -1 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-11-11 10:22 UTC (permalink / raw)
  To: Greg KH
  Cc: Nicolas Ferre, linux-serial, Grant Edwards, linux-arm-kernel,
	linux-kernel, Alan Cox

Greg KH ha scritto:
> On Wed, Nov 10, 2010 at 10:17:03AM +0100, Nicolas Ferre wrote:
>> Le 24/10/2010 13:29, Claudio Scordino :
>>
>> [..]
>>
>>> Hi all,
>>>
>>> 	sorry for the misuse of the term "transceiver", and thank you
>>> for your corrections.
>>>
>>> Hopefully, this new version of the document is slightly better.
>> Hi all,
>>
>> This documentation is floating around for some time now. Claudio has
>> enhanced it and it is maybe time to merge it in mainline...
>>
>> So, can serial people include it in their tree (Greg?) or should it go
>> through another path?
> 
> I can take it, if someone resends it with the accumulated acks that I
> think it gathered over the review cycle.

Here it is.

Thanks,

	Claudio


Documentation about RS485 serial communications

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Russell King <linux@arm.linux.org.uk>
Acked-by: Grant Edwards <grant.b.edwards@gmail.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  119 +++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..40f09c6
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,119 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a built-in half-duplex mode capable of
+   automatically controlling line direction by toggling RTS. That can used to
+   control external half-duplex hardware like an RS485 transceiver or any
+   RS232-connected half-duplex device like some modems.
+
+   For these microcontrollers, the Linux driver should be made capable of
+   working in both modes, and proper ioctls (see later) should be made
+   available at user-level to allow switching from one mode to the other, and
+   vice versa.
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	if (fd < 0) {
+		/* Error handling. See errno. */
+	}
+
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
+		/* Error handling. See errno. */
+	}
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	if (close (fd) < 0) {
+		/* Error handling. See errno. */
+	}
+
+5. REFERENCES
+
+ [1]	include/linux/serial.h
-- 
1.6.0.4



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-11 10:22                                               ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-11-11 10:22 UTC (permalink / raw)
  To: linux-arm-kernel

Greg KH ha scritto:
> On Wed, Nov 10, 2010 at 10:17:03AM +0100, Nicolas Ferre wrote:
>> Le 24/10/2010 13:29, Claudio Scordino :
>>
>> [..]
>>
>>> Hi all,
>>>
>>> 	sorry for the misuse of the term "transceiver", and thank you
>>> for your corrections.
>>>
>>> Hopefully, this new version of the document is slightly better.
>> Hi all,
>>
>> This documentation is floating around for some time now. Claudio has
>> enhanced it and it is maybe time to merge it in mainline...
>>
>> So, can serial people include it in their tree (Greg?) or should it go
>> through another path?
> 
> I can take it, if someone resends it with the accumulated acks that I
> think it gathered over the review cycle.

Here it is.

Thanks,

	Claudio


Documentation about RS485 serial communications

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Russell King <linux@arm.linux.org.uk>
Acked-by: Grant Edwards <grant.b.edwards@gmail.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  119 +++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..40f09c6
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,119 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a built-in half-duplex mode capable of
+   automatically controlling line direction by toggling RTS. That can used to
+   control external half-duplex hardware like an RS485 transceiver or any
+   RS232-connected half-duplex device like some modems.
+
+   For these microcontrollers, the Linux driver should be made capable of
+   working in both modes, and proper ioctls (see later) should be made
+   available at user-level to allow switching from one mode to the other, and
+   vice versa.
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	if (fd < 0) {
+		/* Error handling. See errno. */
+	}
+
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
+		/* Error handling. See errno. */
+	}
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	if (close (fd) < 0) {
+		/* Error handling. See errno. */
+	}
+
+5. REFERENCES
+
+ [1]	include/linux/serial.h
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-11-10  9:17                                           ` Nicolas Ferre
@ 2010-11-10 17:28                                             ` Greg KH
  -1 siblings, 0 replies; 64+ messages in thread
From: Greg KH @ 2010-11-10 17:28 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Claudio Scordino, linux-serial, Grant Edwards, linux-arm-kernel,
	linux-kernel, Alan Cox

On Wed, Nov 10, 2010 at 10:17:03AM +0100, Nicolas Ferre wrote:
> Le 24/10/2010 13:29, Claudio Scordino :
> 
> [..]
> 
> > Hi all,
> > 
> > 	sorry for the misuse of the term "transceiver", and thank you
> > for your corrections.
> > 
> > Hopefully, this new version of the document is slightly better.
> 
> Hi all,
> 
> This documentation is floating around for some time now. Claudio has
> enhanced it and it is maybe time to merge it in mainline...
> 
> So, can serial people include it in their tree (Greg?) or should it go
> through another path?

I can take it, if someone resends it with the accumulated acks that I
think it gathered over the review cycle.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-10 17:28                                             ` Greg KH
  0 siblings, 0 replies; 64+ messages in thread
From: Greg KH @ 2010-11-10 17:28 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Nov 10, 2010 at 10:17:03AM +0100, Nicolas Ferre wrote:
> Le 24/10/2010 13:29, Claudio Scordino :
> 
> [..]
> 
> > Hi all,
> > 
> > 	sorry for the misuse of the term "transceiver", and thank you
> > for your corrections.
> > 
> > Hopefully, this new version of the document is slightly better.
> 
> Hi all,
> 
> This documentation is floating around for some time now. Claudio has
> enhanced it and it is maybe time to merge it in mainline...
> 
> So, can serial people include it in their tree (Greg?) or should it go
> through another path?

I can take it, if someone resends it with the accumulated acks that I
think it gathered over the review cycle.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-24 11:29                                         ` Claudio Scordino
@ 2010-11-10  9:17                                           ` Nicolas Ferre
  -1 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2010-11-10  9:17 UTC (permalink / raw)
  To: Claudio Scordino, linux-serial, Greg Kroah-Hartman
  Cc: Grant Edwards, linux-arm-kernel, linux-kernel, Alan Cox

Le 24/10/2010 13:29, Claudio Scordino :

[..]

> Hi all,
> 
> 	sorry for the misuse of the term "transceiver", and thank you
> for your corrections.
> 
> Hopefully, this new version of the document is slightly better.

Hi all,

This documentation is floating around for some time now. Claudio has
enhanced it and it is maybe time to merge it in mainline...

So, can serial people include it in their tree (Greg?) or should it go
through another path?

Thanks to all of you.

Best regards,

> Many thanks,
> 
> 	Claudio	
> 
> 
> Documentation about RS485 serial communications
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  119 +++++++++++++++++++++++++++++++++
>  2 files changed, 121 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt
> 
> diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
> index 07dcdb0..e09468a 100644
> --- a/Documentation/serial/00-INDEX
> +++ b/Documentation/serial/00-INDEX
> @@ -14,6 +14,8 @@ riscom8.txt
>  	- notes on using the RISCom/8 multi-port serial driver.
>  rocket.txt
>  	- info on the Comtrol RocketPort multiport serial driver.
> +serial-rs485.txt
> +	- info about RS485 structures and support in the kernel.
>  specialix.txt
>  	- info on hardware/driver for specialix IO8+ multiport serial card.
>  stallion.txt
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..40f09c6
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,119 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
> +1. INTRODUCTION
> +
> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> +   electrical characteristics of drivers and receivers for use in balanced
> +   digital multipoint systems.
> +   This standard is widely used for communications in industrial automation
> +   because it can be used effectively over long distances and in electrically
> +   noisy environments.
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a built-in half-duplex mode capable of
> +   automatically controlling line direction by toggling RTS. That can used to
> +   control external half-duplex hardware like an RS485 transceiver or any
> +   RS232-connected half-duplex device like some modems.
> +
> +   For these microcontrollers, the Linux driver should be made capable of
> +   working in both modes, and proper ioctls (see later) should be made
> +   available at user-level to allow switching from one mode to the other, and
> +   vice versa.
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.
> +
> +   In other words, the serial driver should contain a code similar to the next
> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +		case TIOCSRS485:
> +			if (copy_from_user(&rs485conf,
> +				(struct serial_rs485 *) arg,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +
> +			/* ... */
> +			break;
> +
> +		case TIOCGRS485:
> +			if (copy_to_user((struct serial_rs485 *) arg,
> +				...,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +			/* ... */
> +			break;
> +
> +		/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	if (fd < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;
> +
> +	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	/* Use read() and write() syscalls here... */
> +
> +	/* Close the device when finished: */
> +	if (close (fd) < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +5. REFERENCES
> +
> + [1]	include/linux/serial.h


-- 
Nicolas Ferre


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-11-10  9:17                                           ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2010-11-10  9:17 UTC (permalink / raw)
  To: linux-arm-kernel

Le 24/10/2010 13:29, Claudio Scordino :

[..]

> Hi all,
> 
> 	sorry for the misuse of the term "transceiver", and thank you
> for your corrections.
> 
> Hopefully, this new version of the document is slightly better.

Hi all,

This documentation is floating around for some time now. Claudio has
enhanced it and it is maybe time to merge it in mainline...

So, can serial people include it in their tree (Greg?) or should it go
through another path?

Thanks to all of you.

Best regards,

> Many thanks,
> 
> 	Claudio	
> 
> 
> Documentation about RS485 serial communications
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  119 +++++++++++++++++++++++++++++++++
>  2 files changed, 121 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt
> 
> diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
> index 07dcdb0..e09468a 100644
> --- a/Documentation/serial/00-INDEX
> +++ b/Documentation/serial/00-INDEX
> @@ -14,6 +14,8 @@ riscom8.txt
>  	- notes on using the RISCom/8 multi-port serial driver.
>  rocket.txt
>  	- info on the Comtrol RocketPort multiport serial driver.
> +serial-rs485.txt
> +	- info about RS485 structures and support in the kernel.
>  specialix.txt
>  	- info on hardware/driver for specialix IO8+ multiport serial card.
>  stallion.txt
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..40f09c6
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,119 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
> +1. INTRODUCTION
> +
> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> +   electrical characteristics of drivers and receivers for use in balanced
> +   digital multipoint systems.
> +   This standard is widely used for communications in industrial automation
> +   because it can be used effectively over long distances and in electrically
> +   noisy environments.
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a built-in half-duplex mode capable of
> +   automatically controlling line direction by toggling RTS. That can used to
> +   control external half-duplex hardware like an RS485 transceiver or any
> +   RS232-connected half-duplex device like some modems.
> +
> +   For these microcontrollers, the Linux driver should be made capable of
> +   working in both modes, and proper ioctls (see later) should be made
> +   available at user-level to allow switching from one mode to the other, and
> +   vice versa.
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.
> +
> +   In other words, the serial driver should contain a code similar to the next
> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +		case TIOCSRS485:
> +			if (copy_from_user(&rs485conf,
> +				(struct serial_rs485 *) arg,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +
> +			/* ... */
> +			break;
> +
> +		case TIOCGRS485:
> +			if (copy_to_user((struct serial_rs485 *) arg,
> +				...,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +			/* ... */
> +			break;
> +
> +		/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	if (fd < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;
> +
> +	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	/* Use read() and write() syscalls here... */
> +
> +	/* Close the device when finished: */
> +	if (close (fd) < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +5. REFERENCES
> +
> + [1]	include/linux/serial.h


-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
  2010-10-28 15:31                                           ` Claudio Scordino
@ 2010-10-28 16:30                                             ` Chris Down
  0 siblings, 0 replies; 64+ messages in thread
From: Chris Down @ 2010-10-28 16:30 UTC (permalink / raw)
  To: linux-arm-kernel

On 28/10/2010 16:31, Claudio Scordino wrote:
> Chris Down ha scritto:
>> Just a minor issue.
>>
>> On 24/10/2010 12:29, Claudio Scordino wrote:
>>> +4. USAGE FROM USER-LEVEL
>>> +
>>> +   From user-level, RS485 configuration can be get/set using the previous
>>> +   ioctls. For instance, to set RS485 you can use the following code:
>>> +
>>> +	#include <linux/serial.h>
>>> +
>>> +	/* Driver-specific ioctls: */
>>> +	#define TIOCGRS485      0x542E
>>> +	#define TIOCSRS485      0x542F
>>> +
>>> +	/* Open your specific device (e.g., /dev/mydevice): */
>>> +	int fd = open ("/dev/mydevice", O_RDWR);
>>> +	if (fd < 0) {
>>> +		/* Error handling. See errno. */
>>> +	}
>>> +
>>> +	struct serial_rs485 rs485conf;
>>> +
>>> +	/* Set RS485 mode: */
>>> +	rs485conf.flags |= SER_RS485_ENABLED;
>>> +
>>> +	/* Set rts delay before send, if needed: */
>> This comment is misleading as the delay must be set regardless.
>> If it is not used it should be set to 0.
>>
>>> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
>>> +	rs485conf.delay_rts_before_send = ...;
> 
> Hi.
> 
> What do you mean ?
> 
> The delay has not to be set regardless: if the
> SER_RS485_RTS_BEFORE_SEND flag is not set, then the value of
> delay_rts_before_send is ignored, whatever value is contained.
> 
> In other words, the value of delay_rts_before_send is used only when
> SER_RS485_RTS_BEFORE_SEND is set.
> 
> If you don't need a delay, you have to unset the
> SER_RS485_RTS_BEFORE_SEND flag rather than setting a delay equal to 0...
> 
> Best regards,
> 
> 	Claudio
 

In that case perhaps it is best to mention that in the comment.
i.e. if the delay is not needed unset the flag as it defaults to set.


Best regards

Chris

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
  2010-10-28 15:10                                         ` Chris Down
@ 2010-10-28 15:31                                           ` Claudio Scordino
  2010-10-28 16:30                                             ` Chris Down
  0 siblings, 1 reply; 64+ messages in thread
From: Claudio Scordino @ 2010-10-28 15:31 UTC (permalink / raw)
  To: linux-arm-kernel

Chris Down ha scritto:
> Just a minor issue.
> 
> On 24/10/2010 12:29, Claudio Scordino wrote:
>> +4. USAGE FROM USER-LEVEL
>> +
>> +   From user-level, RS485 configuration can be get/set using the previous
>> +   ioctls. For instance, to set RS485 you can use the following code:
>> +
>> +	#include <linux/serial.h>
>> +
>> +	/* Driver-specific ioctls: */
>> +	#define TIOCGRS485      0x542E
>> +	#define TIOCSRS485      0x542F
>> +
>> +	/* Open your specific device (e.g., /dev/mydevice): */
>> +	int fd = open ("/dev/mydevice", O_RDWR);
>> +	if (fd < 0) {
>> +		/* Error handling. See errno. */
>> +	}
>> +
>> +	struct serial_rs485 rs485conf;
>> +
>> +	/* Set RS485 mode: */
>> +	rs485conf.flags |= SER_RS485_ENABLED;
>> +
>> +	/* Set rts delay before send, if needed: */
> This comment is misleading as the delay must be set regardless.
> If it is not used it should be set to 0.
> 
>> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
>> +	rs485conf.delay_rts_before_send = ...;

Hi.

What do you mean ?

The delay has not to be set regardless: if the
SER_RS485_RTS_BEFORE_SEND flag is not set, then the value of
delay_rts_before_send is ignored, whatever value is contained.

In other words, the value of delay_rts_before_send is used only when
SER_RS485_RTS_BEFORE_SEND is set.

If you don't need a delay, you have to unset the
SER_RS485_RTS_BEFORE_SEND flag rather than setting a delay equal to 0...

Best regards,

	Claudio

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
  2010-10-24 11:29                                         ` Claudio Scordino
  (?)
@ 2010-10-28 15:10                                         ` Chris Down
  2010-10-28 15:31                                           ` Claudio Scordino
  -1 siblings, 1 reply; 64+ messages in thread
From: Chris Down @ 2010-10-28 15:10 UTC (permalink / raw)
  To: linux-arm-kernel

Just a minor issue.

On 24/10/2010 12:29, Claudio Scordino wrote:
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	if (fd < 0) {
> +		/* Error handling. See errno. */
> +	}
> +
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
This comment is misleading as the delay must be set regardless.
If it is not used it should be set to 0.

> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
The same applies here.

> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;

Chris

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-19 17:22                                       ` Grant Edwards
@ 2010-10-24 11:29                                         ` Claudio Scordino
  -1 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-10-24 11:29 UTC (permalink / raw)
  To: Grant Edwards
  Cc: linux-arm-kernel, linux-kernel, linux-serial, Nicolas Ferre, Alan Cox

Grant Edwards ha scritto:
> On 2010-10-19, Alexander Stein <alexander.stein@systec-electronic.com> wrote:
>> On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
>>> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
>>>> +2. HARDWARE-RELATED CONSIDERATIONS
>>>> +
>>>> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
>>>> both +   as RS232 and RS485.
>>> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
>>> never seen on with an internal transceiver -- nor does Google seem
>>> able to find any.
>>>
>>> Frankly, I'd be pretty surprised, since it would be very difficult
>>> (fab-wise), to build a mircoprocessor with I/O cells capable of
>>> withstanding the voltage levels specified in RS232.
>>>
>>> Can you specify to which parts you're referring?
>> I doubt the AT91 do have an internal transceiver but it has a
>> dedicated pin feature (RTS or CTS or something) which can be used to
>> switch between RS232 and RS485 by setting a bit in the USART provided
>> the pin is connected properly.
> 
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.
> 
> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Hi all,

	sorry for the misuse of the term "transceiver", and thank you
for your corrections.

Hopefully, this new version of the document is slightly better.

Many thanks,

	Claudio	


Documentation about RS485 serial communications

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  119 +++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..40f09c6
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,119 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a built-in half-duplex mode capable of
+   automatically controlling line direction by toggling RTS. That can used to
+   control external half-duplex hardware like an RS485 transceiver or any
+   RS232-connected half-duplex device like some modems.
+
+   For these microcontrollers, the Linux driver should be made capable of
+   working in both modes, and proper ioctls (see later) should be made
+   available at user-level to allow switching from one mode to the other, and
+   vice versa.
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	if (fd < 0) {
+		/* Error handling. See errno. */
+	}
+
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
+		/* Error handling. See errno. */
+	}
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	if (close (fd) < 0) {
+		/* Error handling. See errno. */
+	}
+
+5. REFERENCES
+
+ [1]	include/linux/serial.h
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-24 11:29                                         ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-10-24 11:29 UTC (permalink / raw)
  To: linux-arm-kernel

Grant Edwards ha scritto:
> On 2010-10-19, Alexander Stein <alexander.stein@systec-electronic.com> wrote:
>> On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
>>> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
>>>> +2. HARDWARE-RELATED CONSIDERATIONS
>>>> +
>>>> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
>>>> both +   as RS232 and RS485.
>>> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
>>> never seen on with an internal transceiver -- nor does Google seem
>>> able to find any.
>>>
>>> Frankly, I'd be pretty surprised, since it would be very difficult
>>> (fab-wise), to build a mircoprocessor with I/O cells capable of
>>> withstanding the voltage levels specified in RS232.
>>>
>>> Can you specify to which parts you're referring?
>> I doubt the AT91 do have an internal transceiver but it has a
>> dedicated pin feature (RTS or CTS or something) which can be used to
>> switch between RS232 and RS485 by setting a bit in the USART provided
>> the pin is connected properly.
> 
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.
> 
> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Hi all,

	sorry for the misuse of the term "transceiver", and thank you
for your corrections.

Hopefully, this new version of the document is slightly better.

Many thanks,

	Claudio	


Documentation about RS485 serial communications

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  119 +++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..40f09c6
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,119 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a built-in half-duplex mode capable of
+   automatically controlling line direction by toggling RTS. That can used to
+   control external half-duplex hardware like an RS485 transceiver or any
+   RS232-connected half-duplex device like some modems.
+
+   For these microcontrollers, the Linux driver should be made capable of
+   working in both modes, and proper ioctls (see later) should be made
+   available at user-level to allow switching from one mode to the other, and
+   vice versa.
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	if (fd < 0) {
+		/* Error handling. See errno. */
+	}
+
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
+		/* Error handling. See errno. */
+	}
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	if (close (fd) < 0) {
+		/* Error handling. See errno. */
+	}
+
+5. REFERENCES
+
+ [1]	include/linux/serial.h
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-20  8:00                                         ` Alexander Stein
@ 2010-10-20 18:56                                           ` Alan Cox
  -1 siblings, 0 replies; 64+ messages in thread
From: Alan Cox @ 2010-10-20 18:56 UTC (permalink / raw)
  To: Alexander Stein
  Cc: linux-arm-kernel, Grant Edwards, linux-kernel, linux-serial

On Wed, 20 Oct 2010 10:00:14 +0200
Alexander Stein <alexander.stein@systec-electronic.com> wrote:

> On Tuesday 19 October 2010, 19:22:32 Grant Edwards wrote:
> > Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> > automatically control line direction by toggling RTS.
> > 
> > That can used to control external half-duplex hardware like an RS485
> > transceiver or any RS232-connected half-duplex device like some
> > modems.
> > 
> > Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> > transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> > to RS485 - it can be used with any external half-duplex hardware.
> 
> Out of curiosity, how can I add RS485 (or whatever) support for other serial 
> devices like e.g. i.mx serial? Is there some driver independent interface 
> which only gets filled in board configs like setting some GPIO pins?

Several devices support RS485 and the like

There are two interfaces

1.	termiox	which is used in the old Unix world for sync and
other stuff on serial world. Linux now supports a bit of this interface
and has the flags so we can grow it as needed. It covers one way flow
control

2.	TIOCGSRS485/TIOCSRS486 plus struct serial_rs485 which is Linux
specific but also allows for pre/post send delays in hardware that some
chips can do.

And nothing stops you supporting both interfaces when it makes sense

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-20 18:56                                           ` Alan Cox
  0 siblings, 0 replies; 64+ messages in thread
From: Alan Cox @ 2010-10-20 18:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 20 Oct 2010 10:00:14 +0200
Alexander Stein <alexander.stein@systec-electronic.com> wrote:

> On Tuesday 19 October 2010, 19:22:32 Grant Edwards wrote:
> > Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> > automatically control line direction by toggling RTS.
> > 
> > That can used to control external half-duplex hardware like an RS485
> > transceiver or any RS232-connected half-duplex device like some
> > modems.
> > 
> > Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> > transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> > to RS485 - it can be used with any external half-duplex hardware.
> 
> Out of curiosity, how can I add RS485 (or whatever) support for other serial 
> devices like e.g. i.mx serial? Is there some driver independent interface 
> which only gets filled in board configs like setting some GPIO pins?

Several devices support RS485 and the like

There are two interfaces

1.	termiox	which is used in the old Unix world for sync and
other stuff on serial world. Linux now supports a bit of this interface
and has the flags so we can grow it as needed. It covers one way flow
control

2.	TIOCGSRS485/TIOCSRS486 plus struct serial_rs485 which is Linux
specific but also allows for pre/post send delays in hardware that some
chips can do.

And nothing stops you supporting both interfaces when it makes sense

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-19 17:22                                       ` Grant Edwards
@ 2010-10-20  8:00                                         ` Alexander Stein
  -1 siblings, 0 replies; 64+ messages in thread
From: Alexander Stein @ 2010-10-20  8:00 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Grant Edwards, linux-kernel, linux-serial

On Tuesday 19 October 2010, 19:22:32 Grant Edwards wrote:
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.
> 
> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Out of curiosity, how can I add RS485 (or whatever) support for other serial 
devices like e.g. i.mx serial? Is there some driver independent interface 
which only gets filled in board configs like setting some GPIO pins?

Alexander

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-20  8:00                                         ` Alexander Stein
  0 siblings, 0 replies; 64+ messages in thread
From: Alexander Stein @ 2010-10-20  8:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 19 October 2010, 19:22:32 Grant Edwards wrote:
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.
> 
> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Out of curiosity, how can I add RS485 (or whatever) support for other serial 
devices like e.g. i.mx serial? Is there some driver independent interface 
which only gets filled in board configs like setting some GPIO pins?

Alexander

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
  2010-10-19 17:22                                       ` Grant Edwards
  (?)
@ 2010-10-20  7:36                                       ` Nicolas Ferre
  -1 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2010-10-20  7:36 UTC (permalink / raw)
  To: linux-arm-kernel

Le 19/10/2010 19:22, Grant Edwards :
> On 2010-10-19, Alexander Stein <alexander.stein@systec-electronic.com> wrote:
>> On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
>>> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
>>>> +2. HARDWARE-RELATED CONSIDERATIONS
>>>> +
>>>> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
>>>> both +   as RS232 and RS485.
>>>
>>> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
>>> never seen on with an internal transceiver -- nor does Google seem
>>> able to find any.
>>>
>>> Frankly, I'd be pretty surprised, since it would be very difficult
>>> (fab-wise), to build a mircoprocessor with I/O cells capable of
>>> withstanding the voltage levels specified in RS232.
>>>
>>> Can you specify to which parts you're referring?
>>
>> I doubt the AT91 do have an internal transceiver but it has a
>> dedicated pin feature (RTS or CTS or something) which can be used to
>> switch between RS232 and RS485 by setting a bit in the USART provided
>> the pin is connected properly.
> 
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.

Yes, that is a vocabulary misuse to talk about "transceiver" but the
idea of Claudio's documentation is that the USART can work in both full
and half duplex and then can comply with RS-232 and RS-485 modes like
you describe precisely in your post.

> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Yes, for sure you will have to use an external transceiver.

Thanks for clarifications.

Best regards,
-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-19 15:27                                     ` Alexander Stein
@ 2010-10-19 17:22                                       ` Grant Edwards
  -1 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-10-19 17:22 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: linux-kernel, linux-serial

On 2010-10-19, Alexander Stein <alexander.stein@systec-electronic.com> wrote:
> On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
>> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
>> > +2. HARDWARE-RELATED CONSIDERATIONS
>> > +
>> > +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
>> > both +   as RS232 and RS485.
>> 
>> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
>> never seen on with an internal transceiver -- nor does Google seem
>> able to find any.
>> 
>> Frankly, I'd be pretty surprised, since it would be very difficult
>> (fab-wise), to build a mircoprocessor with I/O cells capable of
>> withstanding the voltage levels specified in RS232.
>> 
>> Can you specify to which parts you're referring?
>
> I doubt the AT91 do have an internal transceiver but it has a
> dedicated pin feature (RTS or CTS or something) which can be used to
> switch between RS232 and RS485 by setting a bit in the USART provided
> the pin is connected properly.

Yes, the AT91 UARTs do have a built-in half-duplex mode that will
automatically control line direction by toggling RTS.

That can used to control external half-duplex hardware like an RS485
transceiver or any RS232-connected half-duplex device like some
modems.

Though the Atmel docs refer to it as "RS485 mode" there is no RS485
transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
to RS485 - it can be used with any external half-duplex hardware.

-- 
Grant Edwards               grant.b.edwards        Yow! I Know A Joke!!
                                  at               
                              gmail.com            

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-19 17:22                                       ` Grant Edwards
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-10-19 17:22 UTC (permalink / raw)
  To: linux-arm-kernel

On 2010-10-19, Alexander Stein <alexander.stein@systec-electronic.com> wrote:
> On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
>> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
>> > +2. HARDWARE-RELATED CONSIDERATIONS
>> > +
>> > +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
>> > both +   as RS232 and RS485.
>> 
>> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
>> never seen on with an internal transceiver -- nor does Google seem
>> able to find any.
>> 
>> Frankly, I'd be pretty surprised, since it would be very difficult
>> (fab-wise), to build a mircoprocessor with I/O cells capable of
>> withstanding the voltage levels specified in RS232.
>> 
>> Can you specify to which parts you're referring?
>
> I doubt the AT91 do have an internal transceiver but it has a
> dedicated pin feature (RTS or CTS or something) which can be used to
> switch between RS232 and RS485 by setting a bit in the USART provided
> the pin is connected properly.

Yes, the AT91 UARTs do have a built-in half-duplex mode that will
automatically control line direction by toggling RTS.

That can used to control external half-duplex hardware like an RS485
transceiver or any RS232-connected half-duplex device like some
modems.

Though the Atmel docs refer to it as "RS485 mode" there is no RS485
transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
to RS485 - it can be used with any external half-duplex hardware.

-- 
Grant Edwards               grant.b.edwards        Yow! I Know A Joke!!
                                  at               
                              gmail.com            

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-19 14:29                                   ` Grant Edwards
@ 2010-10-19 15:27                                     ` Alexander Stein
  -1 siblings, 0 replies; 64+ messages in thread
From: Alexander Stein @ 2010-10-19 15:27 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Grant Edwards, linux-kernel, linux-serial

On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
> > +2. HARDWARE-RELATED CONSIDERATIONS
> > +
> > +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
> > both +   as RS232 and RS485.
> 
> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
> never seen on with an internal transceiver -- nor does Google seem
> able to find any.
> 
> Frankly, I'd be pretty surprised, since it would be very difficult
> (fab-wise), to build a mircoprocessor with I/O cells capable of
> withstanding the voltage levels specified in RS232.
> 
> Can you specify to which parts you're referring?

I doubt the AT91 do have an internal transceiver but it has a dedicated pin 
feature (RTS or CTS or something) which can be used to switch between RS232 
and RS485 by setting a bit in the USART provided the pin is connected 
properly.

Regards,
Alexander

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-19 15:27                                     ` Alexander Stein
  0 siblings, 0 replies; 64+ messages in thread
From: Alexander Stein @ 2010-10-19 15:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 19 October 2010, 16:29:48 Grant Edwards wrote:
> On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:
> > +2. HARDWARE-RELATED CONSIDERATIONS
> > +
> > +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working
> > both +   as RS232 and RS485.
> 
> Pardon my curiosity, but I've looked at a few AT91 parts, and I've
> never seen on with an internal transceiver -- nor does Google seem
> able to find any.
> 
> Frankly, I'd be pretty surprised, since it would be very difficult
> (fab-wise), to build a mircoprocessor with I/O cells capable of
> withstanding the voltage levels specified in RS232.
> 
> Can you specify to which parts you're referring?

I doubt the AT91 do have an internal transceiver but it has a dedicated pin 
feature (RTS or CTS or something) which can be used to switch between RS232 
and RS485 by setting a bit in the USART provided the pin is connected 
properly.

Regards,
Alexander

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-10-19 12:28                                 ` Claudio Scordino
  (?)
@ 2010-10-19 14:29                                   ` Grant Edwards
  -1 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-10-19 14:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-serial, linux-arm-kernel, linux-serial, linux-kernel

On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:

> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485.

Pardon my curiosity, but I've looked at a few AT91 parts, and I've
never seen on with an internal transceiver -- nor does Google seem
able to find any.

Frankly, I'd be pretty surprised, since it would be very difficult
(fab-wise), to build a mircoprocessor with I/O cells capable of
withstanding the voltage levels specified in RS232.

Can you specify to which parts you're referring?

-- 
Grant Edwards               grant.b.edwards        Yow! I have the power to
                                  at               HALT PRODUCTION on all
                              gmail.com            TEENAGE SEX COMEDIES!!


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
@ 2010-10-19 14:29                                   ` Grant Edwards
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-10-19 14:29 UTC (permalink / raw)
  To: linux-serial; +Cc: linux-arm-kernel, linux-kernel

On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:

> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485.

Pardon my curiosity, but I've looked at a few AT91 parts, and I've
never seen on with an internal transceiver -- nor does Google seem
able to find any.

Frankly, I'd be pretty surprised, since it would be very difficult
(fab-wise), to build a mircoprocessor with I/O cells capable of
withstanding the voltage levels specified in RS232.

Can you specify to which parts you're referring?

-- 
Grant Edwards               grant.b.edwards        Yow! I have the power to
                                  at               HALT PRODUCTION on all
                              gmail.com            TEENAGE SEX COMEDIES!!


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-19 14:29                                   ` Grant Edwards
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Edwards @ 2010-10-19 14:29 UTC (permalink / raw)
  To: linux-arm-kernel

On 2010-10-19, Claudio Scordino <claudio@evidence.eu.com> wrote:

> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485.

Pardon my curiosity, but I've looked at a few AT91 parts, and I've
never seen on with an internal transceiver -- nor does Google seem
able to find any.

Frankly, I'd be pretty surprised, since it would be very difficult
(fab-wise), to build a mircoprocessor with I/O cells capable of
withstanding the voltage levels specified in RS232.

Can you specify to which parts you're referring?

-- 
Grant Edwards               grant.b.edwards        Yow! I have the power to
                                  at               HALT PRODUCTION on all
                              gmail.com            TEENAGE SEX COMEDIES!!

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-15 22:19                               ` Russell King - ARM Linux
@ 2010-10-19 12:28                                 ` Claudio Scordino
  -1 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-10-19 12:28 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Randy Dunlap, linux-arm-kernel, gregkh, Rick Bronson,
	Konrad Mattheis, hskinnemoen, John Nicholls, Nicolas Ferre,
	Linux Kernel, Wolfram Sang, Sebastian Heutling, Ryan Mallon,
	Elektrolot, Philippe De Muyter, Prchal Jiří,
	Andrew Morton, Bernhard Roth, Alan Cox, linux-serial

Russell King - ARM Linux ha scritto:
> On Sun, Aug 15, 2010 at 03:02:57PM -0700, Randy Dunlap wrote:
>> On 08/14/10 05:50, Claudio Scordino wrote:
>>> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
>>> new file mode 100644
>>> index 0000000..93b029e
>>> --- /dev/null
>>> +++ b/Documentation/serial/serial-rs485.txt
>>> @@ -0,0 +1,126 @@
>>> +                        RS485 SERIAL COMMUNICATIONS
>>> +
>>> +1. INTRODUCTION
>>> +
>>> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
>>> +   electrical characteristics of drivers and receivers for use in balanced
>>> +   digital multipoint systems.
>>> +   This standard is widely used for communications in industrial automation
>>> +   because it can be used effectively over long distances and in electrically
>>> +   noisy environments.
>>> +   Even though the data is transmitted over a 2-wire twisted pair bus, all
>>> +   EIA-485 transceivers interpret the voltage levels of the differential
>>> +   signals with respect to a third common voltage. Without this common
>>> +   reference, a set of transceivers may interpret the differential signals
>>> +   incorrectly.
>>> +   See [1] for more information.
> 
> There are devices on the market which are fully isolating RS485
> transceivers which just take the A/B connections, measuring the
> differential voltage, and provide you with the TXD/RXD TTL signals
> for your UART.
> 
> Also note that [1] appears a little confused about the number of pins
> required for RS485 - it says two, and then lists three pins.  I don't
> think you can use this as being supportive of the requirement for three
> connections - and as there are these fully isolating transceivers...
> 
>>> +4. USAGE FROM USER-LEVEL
>>> +
>>> +   From user-level, RS485 configuration can be get/set using the previous
>>> +   ioctls. For instance, to set RS485 you can use the following code:
>>> +
>>> +	#include <linux/serial.h>
>>> +
>>> +	/* Driver-specific ioctls: */
>>> +	#define TIOCGRS485      0x542E
>>> +	#define TIOCSRS485      0x542F
>>> +
>>> +	/* Open your specific device (e.g., /dev/mydevice): */
>>> +	int fd = open ("/dev/mydevice", O_RDWR);
>>> +	struct serial_rs485 rs485conf;
>>> +
>>> +	/* Set RS485 mode: */
>>> +	rs485conf.flags |= SER_RS485_ENABLED;
>>> +
>>> +	/* Set rts delay before send, if needed: */
>>> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
>>> +	rs485conf.delay_rts_before_send = ...;
>>> +
>>> +	/* Set rts delay after send, if needed: */
>>> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
>>> +	rs485conf.delay_rts_after_send = ...;
>>> +
>>> +	ioctl (fd, TIOCSRS485, &rs485conf);
> 
> Example code really should do things right, such as check for error
> conditions - otherwise people will copy'n'paste this and assume that
> the ioctl never fails.

Here is the new document containing the changed you've proposed.

If OK, somebody please provide for commit (the merge window is opening...).

Cheers,

	Claudio


Documentation about RS485 serial communications

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  126 +++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..82ebc86
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,126 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
+   as RS232 and RS485. For these microcontrollers, the Linux driver should be
+   made capable of working in both modes, and proper ioctls (see later) should
+   be made available at user-level to allow switching from one mode to the
+   other, and vice versa.
+
+   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
+   integrated inside the microcontroller itself. Therefore, manufacturers who
+   use these microcontrollers to produce embedded boards need to connect an
+   external transceiver to some pin of the CPU.
+   On these architectures, therefore, no assumptions can be done at the
+   CPU-level about the presence of a RS485 transceiver, because the connection
+   (if any) is done outside the microcontroller. Moreover, even in case of
+   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
+   the connection.
+
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	if (fd < 0) {
+		/* Error handling. See errno. */
+	}
+
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
+		/* Error handling. See errno. */
+	}
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	if (close (fd) < 0) {
+		/* Error handling. See errno. */
+	}
+
+5. REFERENCES
+
+ [1]	include/linux/serial.h

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-10-19 12:28                                 ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-10-19 12:28 UTC (permalink / raw)
  To: linux-arm-kernel

Russell King - ARM Linux ha scritto:
> On Sun, Aug 15, 2010 at 03:02:57PM -0700, Randy Dunlap wrote:
>> On 08/14/10 05:50, Claudio Scordino wrote:
>>> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
>>> new file mode 100644
>>> index 0000000..93b029e
>>> --- /dev/null
>>> +++ b/Documentation/serial/serial-rs485.txt
>>> @@ -0,0 +1,126 @@
>>> +                        RS485 SERIAL COMMUNICATIONS
>>> +
>>> +1. INTRODUCTION
>>> +
>>> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
>>> +   electrical characteristics of drivers and receivers for use in balanced
>>> +   digital multipoint systems.
>>> +   This standard is widely used for communications in industrial automation
>>> +   because it can be used effectively over long distances and in electrically
>>> +   noisy environments.
>>> +   Even though the data is transmitted over a 2-wire twisted pair bus, all
>>> +   EIA-485 transceivers interpret the voltage levels of the differential
>>> +   signals with respect to a third common voltage. Without this common
>>> +   reference, a set of transceivers may interpret the differential signals
>>> +   incorrectly.
>>> +   See [1] for more information.
> 
> There are devices on the market which are fully isolating RS485
> transceivers which just take the A/B connections, measuring the
> differential voltage, and provide you with the TXD/RXD TTL signals
> for your UART.
> 
> Also note that [1] appears a little confused about the number of pins
> required for RS485 - it says two, and then lists three pins.  I don't
> think you can use this as being supportive of the requirement for three
> connections - and as there are these fully isolating transceivers...
> 
>>> +4. USAGE FROM USER-LEVEL
>>> +
>>> +   From user-level, RS485 configuration can be get/set using the previous
>>> +   ioctls. For instance, to set RS485 you can use the following code:
>>> +
>>> +	#include <linux/serial.h>
>>> +
>>> +	/* Driver-specific ioctls: */
>>> +	#define TIOCGRS485      0x542E
>>> +	#define TIOCSRS485      0x542F
>>> +
>>> +	/* Open your specific device (e.g., /dev/mydevice): */
>>> +	int fd = open ("/dev/mydevice", O_RDWR);
>>> +	struct serial_rs485 rs485conf;
>>> +
>>> +	/* Set RS485 mode: */
>>> +	rs485conf.flags |= SER_RS485_ENABLED;
>>> +
>>> +	/* Set rts delay before send, if needed: */
>>> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
>>> +	rs485conf.delay_rts_before_send = ...;
>>> +
>>> +	/* Set rts delay after send, if needed: */
>>> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
>>> +	rs485conf.delay_rts_after_send = ...;
>>> +
>>> +	ioctl (fd, TIOCSRS485, &rs485conf);
> 
> Example code really should do things right, such as check for error
> conditions - otherwise people will copy'n'paste this and assume that
> the ioctl never fails.

Here is the new document containing the changed you've proposed.

If OK, somebody please provide for commit (the merge window is opening...).

Cheers,

	Claudio


Documentation about RS485 serial communications

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  126 +++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..82ebc86
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,126 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
+   as RS232 and RS485. For these microcontrollers, the Linux driver should be
+   made capable of working in both modes, and proper ioctls (see later) should
+   be made available at user-level to allow switching from one mode to the
+   other, and vice versa.
+
+   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
+   integrated inside the microcontroller itself. Therefore, manufacturers who
+   use these microcontrollers to produce embedded boards need to connect an
+   external transceiver to some pin of the CPU.
+   On these architectures, therefore, no assumptions can be done at the
+   CPU-level about the presence of a RS485 transceiver, because the connection
+   (if any) is done outside the microcontroller. Moreover, even in case of
+   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
+   the connection.
+
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [1]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	if (fd < 0) {
+		/* Error handling. See errno. */
+	}
+
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
+		/* Error handling. See errno. */
+	}
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	if (close (fd) < 0) {
+		/* Error handling. See errno. */
+	}
+
+5. REFERENCES
+
+ [1]	include/linux/serial.h

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-15 22:02                             ` Randy Dunlap
@ 2010-08-15 22:19                               ` Russell King - ARM Linux
  -1 siblings, 0 replies; 64+ messages in thread
From: Russell King - ARM Linux @ 2010-08-15 22:19 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Claudio Scordino, Philippe De Muyter, Wolfram Sang, Linux Kernel,
	Nicolas Ferre, Alan Cox, hskinnemoen, linux-arm-kernel,
	Rick Bronson, John Nicholls, Sebastian Heutling, Ryan Mallon,
	Bernhard Roth, Konrad Mattheis, Elektrolot, Prchal Jiří,
	gregkh, Andrew Morton

On Sun, Aug 15, 2010 at 03:02:57PM -0700, Randy Dunlap wrote:
> On 08/14/10 05:50, Claudio Scordino wrote:
> > diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> > new file mode 100644
> > index 0000000..93b029e
> > --- /dev/null
> > +++ b/Documentation/serial/serial-rs485.txt
> > @@ -0,0 +1,126 @@
> > +                        RS485 SERIAL COMMUNICATIONS
> > +
> > +1. INTRODUCTION
> > +
> > +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> > +   electrical characteristics of drivers and receivers for use in balanced
> > +   digital multipoint systems.
> > +   This standard is widely used for communications in industrial automation
> > +   because it can be used effectively over long distances and in electrically
> > +   noisy environments.
> > +   Even though the data is transmitted over a 2-wire twisted pair bus, all
> > +   EIA-485 transceivers interpret the voltage levels of the differential
> > +   signals with respect to a third common voltage. Without this common
> > +   reference, a set of transceivers may interpret the differential signals
> > +   incorrectly.
> > +   See [1] for more information.

There are devices on the market which are fully isolating RS485
transceivers which just take the A/B connections, measuring the
differential voltage, and provide you with the TXD/RXD TTL signals
for your UART.

Also note that [1] appears a little confused about the number of pins
required for RS485 - it says two, and then lists three pins.  I don't
think you can use this as being supportive of the requirement for three
connections - and as there are these fully isolating transceivers...

> > +4. USAGE FROM USER-LEVEL
> > +
> > +   From user-level, RS485 configuration can be get/set using the previous
> > +   ioctls. For instance, to set RS485 you can use the following code:
> > +
> > +	#include <linux/serial.h>
> > +
> > +	/* Driver-specific ioctls: */
> > +	#define TIOCGRS485      0x542E
> > +	#define TIOCSRS485      0x542F
> > +
> > +	/* Open your specific device (e.g., /dev/mydevice): */
> > +	int fd = open ("/dev/mydevice", O_RDWR);
> > +	struct serial_rs485 rs485conf;
> > +
> > +	/* Set RS485 mode: */
> > +	rs485conf.flags |= SER_RS485_ENABLED;
> > +
> > +	/* Set rts delay before send, if needed: */
> > +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> > +	rs485conf.delay_rts_before_send = ...;
> > +
> > +	/* Set rts delay after send, if needed: */
> > +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> > +	rs485conf.delay_rts_after_send = ...;
> > +
> > +	ioctl (fd, TIOCSRS485, &rs485conf);

Example code really should do things right, such as check for error
conditions - otherwise people will copy'n'paste this and assume that
the ioctl never fails.

> > +
> > +	/* Use read() and write() syscalls here... */
> > +
> > +	/* Close the device when finished: */
> > +	close (fd);
> > +
> > +5. REFERENCES
> > +
> > + [1]	http://en.wikipedia.org/wiki/Rs485
> > + [2]	include/linux/serial.h

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-15 22:19                               ` Russell King - ARM Linux
  0 siblings, 0 replies; 64+ messages in thread
From: Russell King - ARM Linux @ 2010-08-15 22:19 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Aug 15, 2010 at 03:02:57PM -0700, Randy Dunlap wrote:
> On 08/14/10 05:50, Claudio Scordino wrote:
> > diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> > new file mode 100644
> > index 0000000..93b029e
> > --- /dev/null
> > +++ b/Documentation/serial/serial-rs485.txt
> > @@ -0,0 +1,126 @@
> > +                        RS485 SERIAL COMMUNICATIONS
> > +
> > +1. INTRODUCTION
> > +
> > +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> > +   electrical characteristics of drivers and receivers for use in balanced
> > +   digital multipoint systems.
> > +   This standard is widely used for communications in industrial automation
> > +   because it can be used effectively over long distances and in electrically
> > +   noisy environments.
> > +   Even though the data is transmitted over a 2-wire twisted pair bus, all
> > +   EIA-485 transceivers interpret the voltage levels of the differential
> > +   signals with respect to a third common voltage. Without this common
> > +   reference, a set of transceivers may interpret the differential signals
> > +   incorrectly.
> > +   See [1] for more information.

There are devices on the market which are fully isolating RS485
transceivers which just take the A/B connections, measuring the
differential voltage, and provide you with the TXD/RXD TTL signals
for your UART.

Also note that [1] appears a little confused about the number of pins
required for RS485 - it says two, and then lists three pins.  I don't
think you can use this as being supportive of the requirement for three
connections - and as there are these fully isolating transceivers...

> > +4. USAGE FROM USER-LEVEL
> > +
> > +   From user-level, RS485 configuration can be get/set using the previous
> > +   ioctls. For instance, to set RS485 you can use the following code:
> > +
> > +	#include <linux/serial.h>
> > +
> > +	/* Driver-specific ioctls: */
> > +	#define TIOCGRS485      0x542E
> > +	#define TIOCSRS485      0x542F
> > +
> > +	/* Open your specific device (e.g., /dev/mydevice): */
> > +	int fd = open ("/dev/mydevice", O_RDWR);
> > +	struct serial_rs485 rs485conf;
> > +
> > +	/* Set RS485 mode: */
> > +	rs485conf.flags |= SER_RS485_ENABLED;
> > +
> > +	/* Set rts delay before send, if needed: */
> > +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> > +	rs485conf.delay_rts_before_send = ...;
> > +
> > +	/* Set rts delay after send, if needed: */
> > +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> > +	rs485conf.delay_rts_after_send = ...;
> > +
> > +	ioctl (fd, TIOCSRS485, &rs485conf);

Example code really should do things right, such as check for error
conditions - otherwise people will copy'n'paste this and assume that
the ioctl never fails.

> > +
> > +	/* Use read() and write() syscalls here... */
> > +
> > +	/* Close the device when finished: */
> > +	close (fd);
> > +
> > +5. REFERENCES
> > +
> > + [1]	http://en.wikipedia.org/wiki/Rs485
> > + [2]	include/linux/serial.h

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-14 12:50                           ` Claudio Scordino
@ 2010-08-15 22:02                             ` Randy Dunlap
  -1 siblings, 0 replies; 64+ messages in thread
From: Randy Dunlap @ 2010-08-15 22:02 UTC (permalink / raw)
  To: Claudio Scordino
  Cc: Philippe De Muyter, Wolfram Sang, Linux Kernel, Nicolas Ferre,
	Alan Cox, hskinnemoen, linux-arm-kernel, Rick Bronson,
	John Nicholls, Sebastian Heutling, Ryan Mallon, rmk,
	Bernhard Roth, Konrad Mattheis, Elektrolot, Prchal Jiří,
	gregkh, Andrew Morton

On 08/14/10 05:50, Claudio Scordino wrote:
> Randy Dunlap ha scritto:
>> On Wed, 11 Aug 2010 11:26:23 +0200 Claudio Scordino wrote:
>>
>>> Hi all,
>>>
>>> 	some time ago I've been asked (by both Wolfram and Philippe) to
>>> provide some minimal documentation about the usage of the RS485
>>> interface.
>>>
> 
> [...]
>  
>>
>> Thanks for the addition.
>>
> 
> Hi all,
> 
> 	here is the document about RS485 with the requested additions.
> 
> If OK, somebody please provide for merging.

I would expect GregKH to merge it.

Acked-by: Randy Dunlap <randy.dunlap@oracle.com>

Thanks.


> Best regards,
> 
> 	Claudio
> 
> 
> Documentation about RS485 serial communications.
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  126 +++++++++++++++++++++++++++++++++
>  2 files changed, 128 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt
> 
> diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
> index 07dcdb0..e09468a 100644
> --- a/Documentation/serial/00-INDEX
> +++ b/Documentation/serial/00-INDEX
> @@ -14,6 +14,8 @@ riscom8.txt
>  	- notes on using the RISCom/8 multi-port serial driver.
>  rocket.txt
>  	- info on the Comtrol RocketPort multiport serial driver.
> +serial-rs485.txt
> +	- info about RS485 structures and support in the kernel.
>  specialix.txt
>  	- info on hardware/driver for specialix IO8+ multiport serial card.
>  stallion.txt
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..93b029e
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,126 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
> +1. INTRODUCTION
> +
> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> +   electrical characteristics of drivers and receivers for use in balanced
> +   digital multipoint systems.
> +   This standard is widely used for communications in industrial automation
> +   because it can be used effectively over long distances and in electrically
> +   noisy environments.
> +   Even though the data is transmitted over a 2-wire twisted pair bus, all
> +   EIA-485 transceivers interpret the voltage levels of the differential
> +   signals with respect to a third common voltage. Without this common
> +   reference, a set of transceivers may interpret the differential signals
> +   incorrectly.
> +   See [1] for more information.
> +
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485. For these microcontrollers, the Linux driver should be
> +   made capable of working in both modes, and proper ioctls (see later) should
> +   be made available at user-level to allow switching from one mode to the
> +   other, and vice versa.
> +
> +   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
> +   integrated inside the microcontroller itself. Therefore, manufacturers who
> +   use these microcontrollers to produce embedded boards need to connect an
> +   external transceiver to some pin of the CPU.
> +   On these architectures, therefore, no assumptions can be done at the
> +   CPU-level about the presence of a RS485 transceiver, because the connection
> +   (if any) is done outside the microcontroller. Moreover, even in case of
> +   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
> +   the connection.
> +
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.
> +
> +   In other words, the serial driver should contain a code similar to the next
> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +		case TIOCSRS485:
> +			if (copy_from_user(&rs485conf,
> +				(struct serial_rs485 *) arg,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +
> +			/* ... */
> +			break;
> +
> +		case TIOCGRS485:
> +			if (copy_to_user((struct serial_rs485 *) arg,
> +				...,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +			/* ... */
> +			break;
> +
> +		/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;
> +
> +	ioctl (fd, TIOCSRS485, &rs485conf);
> +
> +	/* Use read() and write() syscalls here... */
> +
> +	/* Close the device when finished: */
> +	close (fd);
> +
> +5. REFERENCES
> +
> + [1]	http://en.wikipedia.org/wiki/Rs485
> + [2]	include/linux/serial.h


-- 
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-15 22:02                             ` Randy Dunlap
  0 siblings, 0 replies; 64+ messages in thread
From: Randy Dunlap @ 2010-08-15 22:02 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/14/10 05:50, Claudio Scordino wrote:
> Randy Dunlap ha scritto:
>> On Wed, 11 Aug 2010 11:26:23 +0200 Claudio Scordino wrote:
>>
>>> Hi all,
>>>
>>> 	some time ago I've been asked (by both Wolfram and Philippe) to
>>> provide some minimal documentation about the usage of the RS485
>>> interface.
>>>
> 
> [...]
>  
>>
>> Thanks for the addition.
>>
> 
> Hi all,
> 
> 	here is the document about RS485 with the requested additions.
> 
> If OK, somebody please provide for merging.

I would expect GregKH to merge it.

Acked-by: Randy Dunlap <randy.dunlap@oracle.com>

Thanks.


> Best regards,
> 
> 	Claudio
> 
> 
> Documentation about RS485 serial communications.
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  126 +++++++++++++++++++++++++++++++++
>  2 files changed, 128 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt
> 
> diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
> index 07dcdb0..e09468a 100644
> --- a/Documentation/serial/00-INDEX
> +++ b/Documentation/serial/00-INDEX
> @@ -14,6 +14,8 @@ riscom8.txt
>  	- notes on using the RISCom/8 multi-port serial driver.
>  rocket.txt
>  	- info on the Comtrol RocketPort multiport serial driver.
> +serial-rs485.txt
> +	- info about RS485 structures and support in the kernel.
>  specialix.txt
>  	- info on hardware/driver for specialix IO8+ multiport serial card.
>  stallion.txt
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..93b029e
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,126 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
> +1. INTRODUCTION
> +
> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> +   electrical characteristics of drivers and receivers for use in balanced
> +   digital multipoint systems.
> +   This standard is widely used for communications in industrial automation
> +   because it can be used effectively over long distances and in electrically
> +   noisy environments.
> +   Even though the data is transmitted over a 2-wire twisted pair bus, all
> +   EIA-485 transceivers interpret the voltage levels of the differential
> +   signals with respect to a third common voltage. Without this common
> +   reference, a set of transceivers may interpret the differential signals
> +   incorrectly.
> +   See [1] for more information.
> +
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485. For these microcontrollers, the Linux driver should be
> +   made capable of working in both modes, and proper ioctls (see later) should
> +   be made available at user-level to allow switching from one mode to the
> +   other, and vice versa.
> +
> +   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
> +   integrated inside the microcontroller itself. Therefore, manufacturers who
> +   use these microcontrollers to produce embedded boards need to connect an
> +   external transceiver to some pin of the CPU.
> +   On these architectures, therefore, no assumptions can be done at the
> +   CPU-level about the presence of a RS485 transceiver, because the connection
> +   (if any) is done outside the microcontroller. Moreover, even in case of
> +   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
> +   the connection.
> +
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.
> +
> +   In other words, the serial driver should contain a code similar to the next
> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +		case TIOCSRS485:
> +			if (copy_from_user(&rs485conf,
> +				(struct serial_rs485 *) arg,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +
> +			/* ... */
> +			break;
> +
> +		case TIOCGRS485:
> +			if (copy_to_user((struct serial_rs485 *) arg,
> +				...,
> +				sizeof(rs485conf)))
> +					return -EFAULT;
> +			/* ... */
> +			break;
> +
> +		/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
> +	/* Open your specific device (e.g., /dev/mydevice): */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;
> +
> +	ioctl (fd, TIOCSRS485, &rs485conf);
> +
> +	/* Use read() and write() syscalls here... */
> +
> +	/* Close the device when finished: */
> +	close (fd);
> +
> +5. REFERENCES
> +
> + [1]	http://en.wikipedia.org/wiki/Rs485
> + [2]	include/linux/serial.h


-- 
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-11 15:32                         ` Randy Dunlap
@ 2010-08-14 12:50                           ` Claudio Scordino
  -1 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-08-14 12:50 UTC (permalink / raw)
  To: Randy Dunlap, Philippe De Muyter
  Cc: Wolfram Sang, Linux Kernel, Nicolas Ferre, Alan Cox, hskinnemoen,
	linux-arm-kernel, Rick Bronson, John Nicholls,
	Sebastian Heutling, Ryan Mallon, rmk, Bernhard Roth,
	Konrad Mattheis, Elektrolot, Prchal Jiří,
	gregkh, Andrew Morton

Randy Dunlap ha scritto:
> On Wed, 11 Aug 2010 11:26:23 +0200 Claudio Scordino wrote:
> 
>> Hi all,
>>
>> 	some time ago I've been asked (by both Wolfram and Philippe) to
>> provide some minimal documentation about the usage of the RS485
>> interface.
>>

[...]
 
> 
> Thanks for the addition.
> 

Hi all,

	here is the document about RS485 with the requested additions.

If OK, somebody please provide for merging.

Best regards,

	Claudio


Documentation about RS485 serial communications.

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  126 +++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..93b029e
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,126 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+   Even though the data is transmitted over a 2-wire twisted pair bus, all
+   EIA-485 transceivers interpret the voltage levels of the differential
+   signals with respect to a third common voltage. Without this common
+   reference, a set of transceivers may interpret the differential signals
+   incorrectly.
+   See [1] for more information.
+
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
+   as RS232 and RS485. For these microcontrollers, the Linux driver should be
+   made capable of working in both modes, and proper ioctls (see later) should
+   be made available at user-level to allow switching from one mode to the
+   other, and vice versa.
+
+   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
+   integrated inside the microcontroller itself. Therefore, manufacturers who
+   use these microcontrollers to produce embedded boards need to connect an
+   external transceiver to some pin of the CPU.
+   On these architectures, therefore, no assumptions can be done at the
+   CPU-level about the presence of a RS485 transceiver, because the connection
+   (if any) is done outside the microcontroller. Moreover, even in case of
+   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
+   the connection.
+
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	ioctl (fd, TIOCSRS485, &rs485conf);
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	close (fd);
+
+5. REFERENCES
+
+ [1]	http://en.wikipedia.org/wiki/Rs485
+ [2]	include/linux/serial.h
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-14 12:50                           ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-08-14 12:50 UTC (permalink / raw)
  To: linux-arm-kernel

Randy Dunlap ha scritto:
> On Wed, 11 Aug 2010 11:26:23 +0200 Claudio Scordino wrote:
> 
>> Hi all,
>>
>> 	some time ago I've been asked (by both Wolfram and Philippe) to
>> provide some minimal documentation about the usage of the RS485
>> interface.
>>

[...]
 
> 
> Thanks for the addition.
> 

Hi all,

	here is the document about RS485 with the requested additions.

If OK, somebody please provide for merging.

Best regards,

	Claudio


Documentation about RS485 serial communications.

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  126 +++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..93b029e
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,126 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+   Even though the data is transmitted over a 2-wire twisted pair bus, all
+   EIA-485 transceivers interpret the voltage levels of the differential
+   signals with respect to a third common voltage. Without this common
+   reference, a set of transceivers may interpret the differential signals
+   incorrectly.
+   See [1] for more information.
+
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
+   as RS232 and RS485. For these microcontrollers, the Linux driver should be
+   made capable of working in both modes, and proper ioctls (see later) should
+   be made available at user-level to allow switching from one mode to the
+   other, and vice versa.
+
+   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
+   integrated inside the microcontroller itself. Therefore, manufacturers who
+   use these microcontrollers to produce embedded boards need to connect an
+   external transceiver to some pin of the CPU.
+   On these architectures, therefore, no assumptions can be done at the
+   CPU-level about the presence of a RS485 transceiver, because the connection
+   (if any) is done outside the microcontroller. Moreover, even in case of
+   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
+   the connection.
+
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+		case TIOCSRS485:
+			if (copy_from_user(&rs485conf,
+				(struct serial_rs485 *) arg,
+				sizeof(rs485conf)))
+					return -EFAULT;
+
+			/* ... */
+			break;
+
+		case TIOCGRS485:
+			if (copy_to_user((struct serial_rs485 *) arg,
+				...,
+				sizeof(rs485conf)))
+					return -EFAULT;
+			/* ... */
+			break;
+
+		/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open your specific device (e.g., /dev/mydevice): */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	ioctl (fd, TIOCSRS485, &rs485conf);
+
+	/* Use read() and write() syscalls here... */
+
+	/* Close the device when finished: */
+	close (fd);
+
+5. REFERENCES
+
+ [1]	http://en.wikipedia.org/wiki/Rs485
+ [2]	include/linux/serial.h
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-11 15:32                         ` Randy Dunlap
@ 2010-08-11 19:58                           ` Claudio Scordino
  -1 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-08-11 19:58 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Wolfram Sang, Philippe De Muyter, Linux Kernel, Nicolas Ferre,
	Alan Cox, hskinnemoen, linux-arm-kernel, Rick Bronson,
	John Nicholls, Sebastian Heutling, Ryan Mallon, rmk,
	Bernhard Roth, Konrad Mattheis, Elektrolot, Prchal Jiří,
	gregkh, Andrew Morton

Hi Randy,

	thank you for the feedback.

[...]

> 
> TIOC[SG]RS485 are #defined in <asm-generic/ioctls.h>, so
> #include <asm-generic/ioctls.h>
> here and/or below (in userspace program).
> 

I noticed that for some architectures (e.g., cris) these ioctls are defined also in arch/cris/include/asm/ioctls.h, and with different values with respect to the values defined on asm-generic/ioctls.h.

Therefore, I wasn't completely sure that the values defined in asm-generic are being used in every driver...

Best regards,

	Claudio

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-11 19:58                           ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-08-11 19:58 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Randy,

	thank you for the feedback.

[...]

> 
> TIOC[SG]RS485 are #defined in <asm-generic/ioctls.h>, so
> #include <asm-generic/ioctls.h>
> here and/or below (in userspace program).
> 

I noticed that for some architectures (e.g., cris) these ioctls are defined also in arch/cris/include/asm/ioctls.h, and with different values with respect to the values defined on asm-generic/ioctls.h.

Therefore, I wasn't completely sure that the values defined in asm-generic are being used in every driver...

Best regards,

	Claudio

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-11  9:26                       ` Claudio Scordino
@ 2010-08-11 15:32                         ` Randy Dunlap
  -1 siblings, 0 replies; 64+ messages in thread
From: Randy Dunlap @ 2010-08-11 15:32 UTC (permalink / raw)
  To: Claudio Scordino
  Cc: Wolfram Sang, Philippe De Muyter, Linux Kernel, Nicolas Ferre,
	Alan Cox, hskinnemoen, linux-arm-kernel, Rick Bronson,
	John Nicholls, Sebastian Heutling, Ryan Mallon, rmk,
	Bernhard Roth, Konrad Mattheis, Elektrolot, Prchal Jiří,
	gregkh, Andrew Morton

On Wed, 11 Aug 2010 11:26:23 +0200 Claudio Scordino wrote:

> Hi all,
> 
> 	some time ago I've been asked (by both Wolfram and Philippe) to
> provide some minimal documentation about the usage of the RS485
> interface.
> 
> Here is the document (updated with the very last changes in the
> interface).
> 
> Best regards,
> 
> 	Claudio
> 
> 
> Documentation about RS485 serial communications.
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  123 +++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt


> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..f594831
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,123 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
...
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485. For these microcontrollers, the Linux driver should be
> +   able of working in both modes, and proper ioctls (see later) should be made

      should be able to work in both modes
or
      should be made capable of working in both modes

> +   available at user-level to allow switching from one mode to the other, and
> +   viceversa.

      vice versa.

> +
> +   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
> +   integrated inside the microcontroller itself. Therefore, manufacturers who
> +   use these microcontrollers to produce embedded boards need to connect an
> +   external transceiver to some pin of the CPU.
> +   On these architectures, therefore, no assumptions can be done at the
> +   CPU-level about the presence of a RS485 transceiver, because the connection
> +   (if any) is done outside the microcontroller. Moreover, even in case of
> +   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
> +   the connection.
> +
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.

TIOC[SG]RS485 are #defined in <asm-generic/ioctls.h>, so
#include <asm-generic/ioctls.h>
here and/or below (in userspace program).

> +   In other words, the serial driver should contain a code similar to the next

                                               contain code similar to this:

> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +			case TIOCSRS485:

Coding style: we put switch and case at the same indent level.

> +				if (copy_from_user(&rs485conf,
> +					(struct serial_rs485 *) arg,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +
> +				/* ... */
> +				break;
> +
> +			case TIOCGRS485:
> +				if (copy_to_user((struct serial_rs485 *) arg,
> +					...,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +				/* ... */
> +				break;
> +
> +			/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
...
> +
> +5. REFERENCES
> +
> + [1]	http://en.wikipedia.org/wiki/Rs485
> + [2]	include/linux/serial.h


Thanks for the addition.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-11 15:32                         ` Randy Dunlap
  0 siblings, 0 replies; 64+ messages in thread
From: Randy Dunlap @ 2010-08-11 15:32 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 11 Aug 2010 11:26:23 +0200 Claudio Scordino wrote:

> Hi all,
> 
> 	some time ago I've been asked (by both Wolfram and Philippe) to
> provide some minimal documentation about the usage of the RS485
> interface.
> 
> Here is the document (updated with the very last changes in the
> interface).
> 
> Best regards,
> 
> 	Claudio
> 
> 
> Documentation about RS485 serial communications.
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  123 +++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt


> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..f594831
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,123 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
...
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485. For these microcontrollers, the Linux driver should be
> +   able of working in both modes, and proper ioctls (see later) should be made

      should be able to work in both modes
or
      should be made capable of working in both modes

> +   available at user-level to allow switching from one mode to the other, and
> +   viceversa.

      vice versa.

> +
> +   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
> +   integrated inside the microcontroller itself. Therefore, manufacturers who
> +   use these microcontrollers to produce embedded boards need to connect an
> +   external transceiver to some pin of the CPU.
> +   On these architectures, therefore, no assumptions can be done at the
> +   CPU-level about the presence of a RS485 transceiver, because the connection
> +   (if any) is done outside the microcontroller. Moreover, even in case of
> +   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
> +   the connection.
> +
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.

TIOC[SG]RS485 are #defined in <asm-generic/ioctls.h>, so
#include <asm-generic/ioctls.h>
here and/or below (in userspace program).

> +   In other words, the serial driver should contain a code similar to the next

                                               contain code similar to this:

> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +			case TIOCSRS485:

Coding style: we put switch and case at the same indent level.

> +				if (copy_from_user(&rs485conf,
> +					(struct serial_rs485 *) arg,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +
> +				/* ... */
> +				break;
> +
> +			case TIOCGRS485:
> +				if (copy_to_user((struct serial_rs485 *) arg,
> +					...,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +				/* ... */
> +				break;
> +
> +			/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F
> +
...
> +
> +5. REFERENCES
> +
> + [1]	http://en.wikipedia.org/wiki/Rs485
> + [2]	include/linux/serial.h


Thanks for the addition.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH] Documentation about RS485 serial communications
  2010-08-11  9:26                       ` Claudio Scordino
@ 2010-08-11 10:02                         ` Philippe De Muyter
  -1 siblings, 0 replies; 64+ messages in thread
From: Philippe De Muyter @ 2010-08-11 10:02 UTC (permalink / raw)
  To: Claudio Scordino
  Cc: Wolfram Sang, Linux Kernel, Nicolas Ferre, Alan Cox, hskinnemoen,
	linux-arm-kernel, Rick Bronson, John Nicholls,
	Sebastian Heutling, Ryan Mallon, rmk, Bernhard Roth,
	Konrad Mattheis, Elektrolot, Prchal Jiří,
	gregkh, Andrew Morton

On Wed, Aug 11, 2010 at 11:26:23AM +0200, Claudio Scordino wrote:
> Hi all,
> 
> 	some time ago I've been asked (by both Wolfram and Philippe) to
> provide some minimal documentation about the usage of the RS485
> interface.
> 
> Here is the document (updated with the very last changes in the
> interface).

Thanks

> 
> Best regards,
> 
> 	Claudio
> 
> 
> Documentation about RS485 serial communications.
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  123 +++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt
> 
> diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
> index 07dcdb0..e09468a 100644
> --- a/Documentation/serial/00-INDEX
> +++ b/Documentation/serial/00-INDEX
> @@ -14,6 +14,8 @@ riscom8.txt
>  	- notes on using the RISCom/8 multi-port serial driver.
>  rocket.txt
>  	- info on the Comtrol RocketPort multiport serial driver.
> +serial-rs485.txt
> +	- info about RS485 structures and support in the kernel.
>  specialix.txt
>  	- info on hardware/driver for specialix IO8+ multiport serial card.
>  stallion.txt
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..f594831
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,123 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
> +1. INTRODUCTION
> +
> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> +   electrical characteristics of drivers and receivers for use in balanced
> +   digital multipoint systems.
> +   This standard is widely used for communications in industrial automation
> +   because it can be used effectively over long distances and in electrically
> +   noisy environments.
> +   Even though the data is transmitted over a 2-wire twisted pair bus, all
> +   EIA-485 transceivers interpret the voltage levels of the differential
> +   signals with respect to a third common voltage. Without this common
> +   reference, a set of transceivers may interpret the differential signals
> +   incorrectly.
> +   See [1] for more information.
> +
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485. For these microcontrollers, the Linux driver should be
> +   able of working in both modes, and proper ioctls (see later) should be made
> +   available at user-level to allow switching from one mode to the other, and
> +   viceversa.
> +
> +   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
> +   integrated inside the microcontroller itself. Therefore, manufacturers who
> +   use these microcontrollers to produce embedded boards need to connect an
> +   external transceiver to some pin of the CPU.
> +   On these architectures, therefore, no assumptions can be done at the
> +   CPU-level about the presence of a RS485 transceiver, because the connection
> +   (if any) is done outside the microcontroller. Moreover, even in case of
> +   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
> +   the connection.
> +
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.
> +
> +   In other words, the serial driver should contain a code similar to the next
> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +			case TIOCSRS485:
> +				if (copy_from_user(&rs485conf,
> +					(struct serial_rs485 *) arg,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +
> +				/* ... */
> +				break;
> +
> +			case TIOCGRS485:
> +				if (copy_to_user((struct serial_rs485 *) arg,
> +					...,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +				/* ... */
> +				break;
> +
> +			/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F

Should those defines not come from a linux header file ?

> +
> +	/* Open specific device: */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;
> +
> +	ioctl (fd, TIOCSRS485, &rs485conf);

I surmise that all the real work, the read() and write() system calls,
must come here, before the close() system call.

> +
> +	close (fd);
> +
> +5. REFERENCES
> +
> + [1]	http://en.wikipedia.org/wiki/Rs485
> + [2]	include/linux/serial.h
> -- 
> 1.6.0.4
> 

-- 
Philippe De Muyter  phdm at macqel dot be  Tel +32 27029044
Macq Electronique SA  rue de l'Aeronef 2  B-1140 Bruxelles  Fax +32 27029077

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-11 10:02                         ` Philippe De Muyter
  0 siblings, 0 replies; 64+ messages in thread
From: Philippe De Muyter @ 2010-08-11 10:02 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Aug 11, 2010 at 11:26:23AM +0200, Claudio Scordino wrote:
> Hi all,
> 
> 	some time ago I've been asked (by both Wolfram and Philippe) to
> provide some minimal documentation about the usage of the RS485
> interface.
> 
> Here is the document (updated with the very last changes in the
> interface).

Thanks

> 
> Best regards,
> 
> 	Claudio
> 
> 
> Documentation about RS485 serial communications.
> 
> Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
> ---
>  Documentation/serial/00-INDEX         |    2 +
>  Documentation/serial/serial-rs485.txt |  123 +++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/serial/serial-rs485.txt
> 
> diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
> index 07dcdb0..e09468a 100644
> --- a/Documentation/serial/00-INDEX
> +++ b/Documentation/serial/00-INDEX
> @@ -14,6 +14,8 @@ riscom8.txt
>  	- notes on using the RISCom/8 multi-port serial driver.
>  rocket.txt
>  	- info on the Comtrol RocketPort multiport serial driver.
> +serial-rs485.txt
> +	- info about RS485 structures and support in the kernel.
>  specialix.txt
>  	- info on hardware/driver for specialix IO8+ multiport serial card.
>  stallion.txt
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> new file mode 100644
> index 0000000..f594831
> --- /dev/null
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -0,0 +1,123 @@
> +                        RS485 SERIAL COMMUNICATIONS
> +
> +1. INTRODUCTION
> +
> +   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
> +   electrical characteristics of drivers and receivers for use in balanced
> +   digital multipoint systems.
> +   This standard is widely used for communications in industrial automation
> +   because it can be used effectively over long distances and in electrically
> +   noisy environments.
> +   Even though the data is transmitted over a 2-wire twisted pair bus, all
> +   EIA-485 transceivers interpret the voltage levels of the differential
> +   signals with respect to a third common voltage. Without this common
> +   reference, a set of transceivers may interpret the differential signals
> +   incorrectly.
> +   See [1] for more information.
> +
> +
> +2. HARDWARE-RELATED CONSIDERATIONS
> +
> +   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
> +   as RS232 and RS485. For these microcontrollers, the Linux driver should be
> +   able of working in both modes, and proper ioctls (see later) should be made
> +   available at user-level to allow switching from one mode to the other, and
> +   viceversa.
> +
> +   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
> +   integrated inside the microcontroller itself. Therefore, manufacturers who
> +   use these microcontrollers to produce embedded boards need to connect an
> +   external transceiver to some pin of the CPU.
> +   On these architectures, therefore, no assumptions can be done at the
> +   CPU-level about the presence of a RS485 transceiver, because the connection
> +   (if any) is done outside the microcontroller. Moreover, even in case of
> +   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
> +   the connection.
> +
> +
> +3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
> +
> +   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
> +   RS485 communications. This data structure is used to set and configure RS485
> +   parameters in the platform data and in ioctls.
> +
> +   Any driver for devices capable of working both as RS232 and RS485 should
> +   provide at least the following ioctls:
> +
> +    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
> +      to enable/disable RS485 mode from user-space
> +
> +    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
> +      to get RS485 mode from kernel-space (i.e., driver) to user-space.
> +
> +   In other words, the serial driver should contain a code similar to the next
> +   one:
> +
> +	static struct uart_ops atmel_pops = {
> +		/* ... */
> +		.ioctl		= handle_ioctl,
> +	};
> +
> +	static int handle_ioctl(struct uart_port *port,
> +		unsigned int cmd,
> +		unsigned long arg)
> +	{
> +		struct serial_rs485 rs485conf;
> +
> +		switch (cmd) {
> +			case TIOCSRS485:
> +				if (copy_from_user(&rs485conf,
> +					(struct serial_rs485 *) arg,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +
> +				/* ... */
> +				break;
> +
> +			case TIOCGRS485:
> +				if (copy_to_user((struct serial_rs485 *) arg,
> +					...,
> +					sizeof(rs485conf)))
> +						return -EFAULT;
> +				/* ... */
> +				break;
> +
> +			/* ... */
> +		}
> +	}
> +
> +
> +4. USAGE FROM USER-LEVEL
> +
> +   From user-level, RS485 configuration can be get/set using the previous
> +   ioctls. For instance, to set RS485 you can use the following code:
> +
> +	#include <linux/serial.h>
> +
> +	/* Driver-specific ioctls: */
> +	#define TIOCGRS485      0x542E
> +	#define TIOCSRS485      0x542F

Should those defines not come from a linux header file ?

> +
> +	/* Open specific device: */
> +	int fd = open ("/dev/mydevice", O_RDWR);
> +	struct serial_rs485 rs485conf;
> +
> +	/* Set RS485 mode: */
> +	rs485conf.flags |= SER_RS485_ENABLED;
> +
> +	/* Set rts delay before send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
> +	rs485conf.delay_rts_before_send = ...;
> +
> +	/* Set rts delay after send, if needed: */
> +	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
> +	rs485conf.delay_rts_after_send = ...;
> +
> +	ioctl (fd, TIOCSRS485, &rs485conf);

I surmise that all the real work, the read() and write() system calls,
must come here, before the close() system call.

> +
> +	close (fd);
> +
> +5. REFERENCES
> +
> + [1]	http://en.wikipedia.org/wiki/Rs485
> + [2]	include/linux/serial.h
> -- 
> 1.6.0.4
> 

-- 
Philippe De Muyter  phdm at macqel dot be  Tel +32 27029044
Macq Electronique SA  rue de l'Aeronef 2  B-1140 Bruxelles  Fax +32 27029077

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
  2010-05-27 10:29                   ` Wolfram Sang
@ 2010-08-11  9:26                       ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-08-11  9:26 UTC (permalink / raw)
  To: Wolfram Sang, Philippe De Muyter, Linux Kernel
  Cc: Nicolas Ferre, Alan Cox, hskinnemoen, linux-arm-kernel,
	Rick Bronson, John Nicholls, Sebastian Heutling, Ryan Mallon,
	rmk, Bernhard Roth, Konrad Mattheis, Elektrolot,
	Prchal Jiří,
	gregkh, Andrew Morton

Hi all,

	some time ago I've been asked (by both Wolfram and Philippe) to
provide some minimal documentation about the usage of the RS485
interface.

Here is the document (updated with the very last changes in the
interface).

Best regards,

	Claudio


Documentation about RS485 serial communications.

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  123 +++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..f594831
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,123 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+   Even though the data is transmitted over a 2-wire twisted pair bus, all
+   EIA-485 transceivers interpret the voltage levels of the differential
+   signals with respect to a third common voltage. Without this common
+   reference, a set of transceivers may interpret the differential signals
+   incorrectly.
+   See [1] for more information.
+
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
+   as RS232 and RS485. For these microcontrollers, the Linux driver should be
+   able of working in both modes, and proper ioctls (see later) should be made
+   available at user-level to allow switching from one mode to the other, and
+   viceversa.
+
+   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
+   integrated inside the microcontroller itself. Therefore, manufacturers who
+   use these microcontrollers to produce embedded boards need to connect an
+   external transceiver to some pin of the CPU.
+   On these architectures, therefore, no assumptions can be done at the
+   CPU-level about the presence of a RS485 transceiver, because the connection
+   (if any) is done outside the microcontroller. Moreover, even in case of
+   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
+   the connection.
+
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+			case TIOCSRS485:
+				if (copy_from_user(&rs485conf,
+					(struct serial_rs485 *) arg,
+					sizeof(rs485conf)))
+						return -EFAULT;
+
+				/* ... */
+				break;
+
+			case TIOCGRS485:
+				if (copy_to_user((struct serial_rs485 *) arg,
+					...,
+					sizeof(rs485conf)))
+						return -EFAULT;
+				/* ... */
+				break;
+
+			/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open specific device: */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	ioctl (fd, TIOCSRS485, &rs485conf);
+
+	close (fd);
+
+5. REFERENCES
+
+ [1]	http://en.wikipedia.org/wiki/Rs485
+ [2]	include/linux/serial.h
-- 
1.6.0.4



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH] Documentation about RS485 serial communications
@ 2010-08-11  9:26                       ` Claudio Scordino
  0 siblings, 0 replies; 64+ messages in thread
From: Claudio Scordino @ 2010-08-11  9:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi all,

	some time ago I've been asked (by both Wolfram and Philippe) to
provide some minimal documentation about the usage of the RS485
interface.

Here is the document (updated with the very last changes in the
interface).

Best regards,

	Claudio


Documentation about RS485 serial communications.

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
---
 Documentation/serial/00-INDEX         |    2 +
 Documentation/serial/serial-rs485.txt |  123 +++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/serial/serial-rs485.txt

diff --git a/Documentation/serial/00-INDEX b/Documentation/serial/00-INDEX
index 07dcdb0..e09468a 100644
--- a/Documentation/serial/00-INDEX
+++ b/Documentation/serial/00-INDEX
@@ -14,6 +14,8 @@ riscom8.txt
 	- notes on using the RISCom/8 multi-port serial driver.
 rocket.txt
 	- info on the Comtrol RocketPort multiport serial driver.
+serial-rs485.txt
+	- info about RS485 structures and support in the kernel.
 specialix.txt
 	- info on hardware/driver for specialix IO8+ multiport serial card.
 stallion.txt
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
new file mode 100644
index 0000000..f594831
--- /dev/null
+++ b/Documentation/serial/serial-rs485.txt
@@ -0,0 +1,123 @@
+                        RS485 SERIAL COMMUNICATIONS
+
+1. INTRODUCTION
+
+   EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining the
+   electrical characteristics of drivers and receivers for use in balanced
+   digital multipoint systems.
+   This standard is widely used for communications in industrial automation
+   because it can be used effectively over long distances and in electrically
+   noisy environments.
+   Even though the data is transmitted over a 2-wire twisted pair bus, all
+   EIA-485 transceivers interpret the voltage levels of the differential
+   signals with respect to a third common voltage. Without this common
+   reference, a set of transceivers may interpret the differential signals
+   incorrectly.
+   See [1] for more information.
+
+
+2. HARDWARE-RELATED CONSIDERATIONS
+
+   Some CPUs (e.g., Atmel AT91) contain a transceiver capable of working both
+   as RS232 and RS485. For these microcontrollers, the Linux driver should be
+   able of working in both modes, and proper ioctls (see later) should be made
+   available at user-level to allow switching from one mode to the other, and
+   viceversa.
+
+   On some other CPUs (e.g., Freescale imx25) the RS485 transceiver is not
+   integrated inside the microcontroller itself. Therefore, manufacturers who
+   use these microcontrollers to produce embedded boards need to connect an
+   external transceiver to some pin of the CPU.
+   On these architectures, therefore, no assumptions can be done at the
+   CPU-level about the presence of a RS485 transceiver, because the connection
+   (if any) is done outside the microcontroller. Moreover, even in case of
+   RS485 transceiver, the manufacturer is free to choose the CPU pin used for
+   the connection.
+
+
+3. DATA STRUCTURES ALREADY AVAILABLE IN THE KERNEL
+
+   The Linux kernel provides the serial_rs485 structure (see [2]) to handle
+   RS485 communications. This data structure is used to set and configure RS485
+   parameters in the platform data and in ioctls.
+
+   Any driver for devices capable of working both as RS232 and RS485 should
+   provide at least the following ioctls:
+
+    - TIOCSRS485 (typically associated with number 0x542F). This ioctl is used
+      to enable/disable RS485 mode from user-space
+
+    - TIOCGRS485 (typically associated with number 0x542E). This ioctl is used
+      to get RS485 mode from kernel-space (i.e., driver) to user-space.
+
+   In other words, the serial driver should contain a code similar to the next
+   one:
+
+	static struct uart_ops atmel_pops = {
+		/* ... */
+		.ioctl		= handle_ioctl,
+	};
+
+	static int handle_ioctl(struct uart_port *port,
+		unsigned int cmd,
+		unsigned long arg)
+	{
+		struct serial_rs485 rs485conf;
+
+		switch (cmd) {
+			case TIOCSRS485:
+				if (copy_from_user(&rs485conf,
+					(struct serial_rs485 *) arg,
+					sizeof(rs485conf)))
+						return -EFAULT;
+
+				/* ... */
+				break;
+
+			case TIOCGRS485:
+				if (copy_to_user((struct serial_rs485 *) arg,
+					...,
+					sizeof(rs485conf)))
+						return -EFAULT;
+				/* ... */
+				break;
+
+			/* ... */
+		}
+	}
+
+
+4. USAGE FROM USER-LEVEL
+
+   From user-level, RS485 configuration can be get/set using the previous
+   ioctls. For instance, to set RS485 you can use the following code:
+
+	#include <linux/serial.h>
+
+	/* Driver-specific ioctls: */
+	#define TIOCGRS485      0x542E
+	#define TIOCSRS485      0x542F
+
+	/* Open specific device: */
+	int fd = open ("/dev/mydevice", O_RDWR);
+	struct serial_rs485 rs485conf;
+
+	/* Set RS485 mode: */
+	rs485conf.flags |= SER_RS485_ENABLED;
+
+	/* Set rts delay before send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_BEFORE_SEND;
+	rs485conf.delay_rts_before_send = ...;
+
+	/* Set rts delay after send, if needed: */
+	rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
+	rs485conf.delay_rts_after_send = ...;
+
+	ioctl (fd, TIOCSRS485, &rs485conf);
+
+	close (fd);
+
+5. REFERENCES
+
+ [1]	http://en.wikipedia.org/wiki/Rs485
+ [2]	include/linux/serial.h
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2010-11-30 19:19 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-11 20:20 [PATCH] Documentation about RS485 serial communications Randy Dunlap
2010-08-11 20:23 ` Randy Dunlap
  -- strict thread matches above, loose matches on Subject: below --
2010-03-29  7:16 [PATCH] atmel_serial: Atmel RS485 support v2 Claudio Scordino
2010-03-29 19:44 ` Ryan Mallon
2010-03-30  9:07   ` Claudio Scordino
2010-03-30 19:37     ` Ryan Mallon
2010-04-08  7:58       ` Claudio Scordino
2010-04-08 10:13         ` Alan Cox
2010-04-08 13:16           ` Claudio Scordino
2010-05-26 13:18             ` Nicolas Ferre
2010-05-27  8:37               ` Claudio Scordino
2010-05-27  9:57                 ` Nicolas Ferre
2010-05-27 10:29                   ` Wolfram Sang
2010-08-11  9:26                     ` [PATCH] Documentation about RS485 serial communications Claudio Scordino
2010-08-11  9:26                       ` Claudio Scordino
2010-08-11 10:02                       ` Philippe De Muyter
2010-08-11 10:02                         ` Philippe De Muyter
2010-08-11 15:32                       ` Randy Dunlap
2010-08-11 15:32                         ` Randy Dunlap
2010-08-11 19:58                         ` Claudio Scordino
2010-08-11 19:58                           ` Claudio Scordino
2010-08-14 12:50                         ` Claudio Scordino
2010-08-14 12:50                           ` Claudio Scordino
2010-08-15 22:02                           ` Randy Dunlap
2010-08-15 22:02                             ` Randy Dunlap
2010-08-15 22:19                             ` Russell King - ARM Linux
2010-08-15 22:19                               ` Russell King - ARM Linux
2010-10-19 12:28                               ` Claudio Scordino
2010-10-19 12:28                                 ` Claudio Scordino
2010-10-19 14:29                                 ` Grant Edwards
2010-10-19 14:29                                   ` Grant Edwards
2010-10-19 14:29                                   ` Grant Edwards
2010-10-19 15:27                                   ` Alexander Stein
2010-10-19 15:27                                     ` Alexander Stein
2010-10-19 17:22                                     ` Grant Edwards
2010-10-19 17:22                                       ` Grant Edwards
2010-10-20  7:36                                       ` Nicolas Ferre
2010-10-20  8:00                                       ` Alexander Stein
2010-10-20  8:00                                         ` Alexander Stein
2010-10-20 18:56                                         ` Alan Cox
2010-10-20 18:56                                           ` Alan Cox
2010-10-24 11:29                                       ` Claudio Scordino
2010-10-24 11:29                                         ` Claudio Scordino
2010-10-28 15:10                                         ` Chris Down
2010-10-28 15:31                                           ` Claudio Scordino
2010-10-28 16:30                                             ` Chris Down
2010-11-10  9:17                                         ` Nicolas Ferre
2010-11-10  9:17                                           ` Nicolas Ferre
2010-11-10 17:28                                           ` Greg KH
2010-11-10 17:28                                             ` Greg KH
2010-11-11 10:22                                             ` Claudio Scordino
2010-11-11 10:22                                               ` Claudio Scordino
2010-11-16 14:30                                               ` Pavel Machek
2010-11-16 14:30                                                 ` Pavel Machek
2010-11-16 14:30                                                 ` Pavel Machek
2010-11-16 14:58                                                 ` Tosoni
2010-11-16 15:52                                                   ` Grant Edwards
2010-11-16 15:23                                                 ` Grant Edwards
2010-11-16 15:23                                                   ` Grant Edwards
2010-11-16 15:28                                                 ` Alexander Stein
2010-11-16 15:28                                                   ` Alexander Stein
2010-11-16 16:13                                                 ` Matt Schulte
2010-11-16 16:13                                                   ` Matt Schulte
2010-11-16 16:28                                                   ` Grant Edwards
2010-11-16 18:41                                                     ` Matt Schulte
2010-11-16 18:41                                                       ` Matt Schulte
2010-11-16 18:41                                                       ` Matt Schulte
2010-11-16 19:29                                                       ` Grant Edwards
2010-11-16 17:20                                                   ` Alan Cox
2010-11-16 17:20                                                     ` Alan Cox
2010-11-16 18:03                                                     ` Grant Edwards
2010-11-16 20:04                                                       ` Alan Cox
2010-11-16 20:04                                                         ` Alan Cox
2010-11-30 19:19                                                         ` Pavel Machek
2010-11-30 19:19                                                           ` Pavel Machek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.