c2port (Version 2): support for Silicon C2 Interface.
Subsystems (2)
C2 port implements a two wire serial communication protocol (bit banging) designed to enable in-system programming, debugging, and boundary-scan testing on low pin-count Silicon Labs devices.
Main references are at Silicon Laboratories site:
* AN127: FLASH Programming via the C2 Interface
http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Small_Form_Factor/en/an127.pdf
* C2 Specification
http://www.silabs.com/public/documents/tpub_doc/spec/Microcontrollers/en/C2spec.pdf
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
Changelog
---------
Version 1 -> 2:
* Documentation added.
* One client added.
Rodolfo
--
b/Documentation/ABI/testing/sysfs-c2port | 88 ++ b/Documentation/c2port.txt | 90 ++ b/drivers/misc/Kconfig | 2 b/drivers/misc/Makefile | 1 b/drivers/misc/c2port/Kconfig | 24 b/drivers/misc/c2port/Makefile | 1 b/drivers/misc/c2port/c2port-duramar2150.c | 160 ++++ b/drivers/misc/c2port/core.c | 996 +++++++++++++++++++++++++++++ b/include/linux/c2port.h | 65 + drivers/misc/c2port/Kconfig | 11 drivers/misc/c2port/Makefile | 2 11 files changed, 1440 insertions(+)
PATCH 1/2 Add c2 port support.
C2port implements a two wire serial communication protocol (bit banging) designed to enable in-system programming, debugging, and boundary-scan testing on low pin-count Silicon Labs devices.
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
--- Documentation/ABI/testing/sysfs-c2port | 88 +++ Documentation/c2port.txt | 90 +++ drivers/misc/Kconfig | 2 + drivers/misc/Makefile | 1 + drivers/misc/c2port/Kconfig | 24 + drivers/misc/c2port/Makefile | 1 + drivers/misc/c2port/core.c | 996 ++++++++++++++++++++++++++++++++ include/linux/c2port.h | 65 ++ 8 files changed, 1267 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-c2port create mode 100644 Documentation/c2port.txt create mode 100644 drivers/misc/c2port/Kconfig create mode 100644 drivers/misc/c2port/Makefile create mode 100644 drivers/misc/c2port/core.c create mode 100644 include/linux/c2port.h
Documentation/ABI/testing/sysfs-c2port new file +88 -0
@@ -0,0 +1,88 @@ +What: /sys/class/c2port/ +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/ directory will contain files and + directories that will provide a unified interface to + the C2 port interface. + +What: /sys/class/c2port/c2portX +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/ directory is related to X-th + C2 port into the system. Each directory will contain files to + manage and control its C2 port. + +What: /sys/class/c2port/c2portX/access +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/access file enable the access + to the C2 port from the system. No commands can be sent + till this entry is set to 0. + +What: /sys/class/c2port/c2portX/dev_id +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/dev_id file show the device ID + of the connected micro. + +What: /sys/class/c2port/c2portX/flash_access +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/flash_access file enable the + access to the on-board flash of the connected micro. + No commands can be sent till this entry is set to 0. + +What: /sys/class/c2port/c2portX/flash_block_size +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/flash_block_size file show + the on-board flash block size of the connected micro. + +What: /sys/class/c2port/c2portX/flash_blocks_num +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/flash_blocks_num file show + the on-board flash blocks number of the connected micro. + +What: /sys/class/c2port/c2portX/flash_data +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/flash_data file export + the content of the on-board flash of the connected micro. + +What: /sys/class/c2port/c2portX/flash_erase +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/flash_erase file execute + the "erase" command on the on-board flash of the connected + micro. + +What: /sys/class/c2port/c2portX/flash_erase +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/flash_erase file show the + on-board flash size of the connected micro. + +What: /sys/class/c2port/c2portX/reset +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/reset file execute a "reset" + command on the connected micro. + +What: /sys/class/c2port/c2portX/rev_id +Date: October 2008 +Contact: Rodolfo Giometti <[email protected]> +Description: + The /sys/class/c2port/c2portX/rev_id file show the revision ID + of the connected micro.
Documentation/c2port.txt new file +90 -0
90 lines not on this page · raw message
drivers/misc/Kconfig +2 -0
@@ -475,4 +475,6 @@ config SGI_GRU_DEBUG This option enables addition debugging code for the SGI GRU driver. If you are unsure, say N. +source "drivers/misc/c2port/Kconfig" + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -30,3 +30,4 @@ obj-$(CONFIG_KGDB_TESTS) += kgdbts.o obj-$(CONFIG_SGI_XP) += sgi-xp/ obj-$(CONFIG_SGI_GRU) += sgi-gru/ obj-$(CONFIG_HP_ILO) += hpilo.o +obj-$(CONFIG_C2PORT) += c2port/
drivers/misc/c2port/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +# +# C2 port devices +# + +menuconfig C2PORT + tristate "Silicon Labs C2 port support (EXPERIMENTAL)" + depends on EXPERIMENTAL + default no + help + This option enables support for Silicon Labs C2 port used to + program Silicon micro controller chips (and other 8051 compatible). + + If your board have no such micro controllers you don't need this + interface at all. + + To compile this driver as a module, choose M here: the module will + be called c2port_core. Note that you also need a client module + usually called c2port-*. + + If you are not sure, say N here. + +if C2PORT + +endif # C2PORT
drivers/misc/c2port/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_C2PORT) += core.o
drivers/misc/c2port/core.c new file +996 -0
996 lines not on this page · raw message
include/linux/c2port.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.5.4.3
PATCH 2/2 c2port: add c2port support for Eurotech Duramar 2150.
--- drivers/misc/c2port/Kconfig | 11 ++ drivers/misc/c2port/Makefile | 2 + drivers/misc/c2port/c2port-duramar2150.c | 160 ++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/c2port/c2port-duramar2150.c
drivers/misc/c2port/Kconfig +11 -0
@@ -21,4 +21,15 @@ menuconfig C2PORT if C2PORT +config C2PORT_DURAMAR_2150 + tristate "C2 port support for Eurotech's Duramar 2150 (EXPERIMENTAL)" + depends on X86 && C2PORT + default no + help + This option enables C2 support for the Eurotech's Duramar 2150 + on board micro controller. + + To compile this driver as a module, choose M here: the module will + be called c2port-duramar2150. + endif # C2PORT
drivers/misc/c2port/Makefile +2 -0
@@ -1 +1,3 @@ obj-$(CONFIG_C2PORT) += core.o + +obj-$(CONFIG_C2PORT_DURAMAR_2150) += c2port-duramar2150.o
drivers/misc/c2port/c2port-duramar2150.c new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
1.5.4.3
Re: [PATCH 2/2] c2port: add c2port support for Eurotech Duramar 2150.
Quoted 1 line · Rodolfo Giometti
Signed-off-by Rodolfo Giometti <[email protected]>
Re: [PATCH 1/2] Add c2 port support.
In reply to Rodolfo GiomettiQuoted 8 lines · Rodolfo Giometti
C2port implements a two wire serial communication protocol (bit banging) designed to enable in-system programming, debugging, and boundary-scan testing on low pin-count Silicon Labs devices.
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
Signed-off-by Rodolfo Giometti <[email protected]>
Nice job.
Andrew, no reason why these 2 patches can't go into 2.6.28, they are self-contained and are new drivers.
Do you want to send them to Linus, or want me to?
thanks,
greg k-h
Re: [PATCH 1/2] Add c2 port support.
Quoted 9 lines · On Wed, 22 Oct 2008 10:40:04 -0700 Greg KH <[email protected]> wrote:
Quoted 8 lines · Rodolfo Giometti
C2port implements a two wire serial communication protocol (bit banging) designed to enable in-system programming, debugging, and boundary-scan testing on low pin-count Silicon Labs devices.
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
Signed-off-by Rodolfo Giometti <[email protected]>
Quoted 9 lines
Nice job.
Andrew, no reason why these 2 patches can't go into 2.6.28, they are self-contained and are new drivers.
Do you want to send them to Linus, or want me to?
No opinion yet - I haven't review them.
<looks>
<wonders why c2port_idr_lock and c2port_idr are kernel-wide symbols>
<wonders what local_irq_disable() is supposed to achieve on SMP>
<spots an error-path memory leak in c2port_device_register>
<spots a stray semicolon in c2port_device_register>
<suggests that update_lock be initialised at compile-time, not at runtime>
What I haven't yet got my head around is this:
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
is that really what we want to use sysfs for? As the prime interface to a device driver (or is it a bus driver?) Didn't we used to use device nodes for that sort of thing?
Re: [PATCH 1/2] Add c2 port support.
Quoted 5 lines · Andrew Morton
No opinion yet - I haven't review them.
<looks>
<wonders why
c2port_idr_lockandc2port_idrare kernel-wide symbols>
Fixed.
Quoted 1 line
<wonders what
local_irq_disable()is supposed to achieve on SMP>
The SMP is achieved by mutex_lock(), the local_irq_disable() is used to avoid interructions in code execution. C2 port has very stringent timings.
Quoted 3 lines
<spots an error-path memory leak in
c2port_device_register><spots a stray semicolon in
c2port_device_register>
Can you please explain these two points?
Quoted 1 line
<suggests that
update_lockbe initialised at compile-time, not at runtime>
Fixed.
Quoted 9 lines
What I haven't yet got my head around is this:
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
is that really what we want to use sysfs for? As the prime interface to a device driver (or is it a bus driver?) Didn't we used to use device nodes for that sort of thing?
I decided to use this interface since the C2 ports are simple and very easy to manage with such files abstraction.
Whould you like I repropose the code with the fixed issues for your review?
Thanks for your suggestions,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti
Re: [PATCH 1/2] Add c2 port support.
Quoted 8 lines · On Wed, 22 Oct 2008 21:52:46 +0200 Rodolfo Giometti <[email protected]>…
Quoted 5 lines · Andrew Morton
No opinion yet - I haven't review them.
<looks>
<wonders why
c2port_idr_lockandc2port_idrare kernel-wide symbols>
Quoted 7 lines
Fixed.
Quoted 1 line
<wonders what
local_irq_disable()is supposed to achieve on SMP>The SMP is achieved by
mutex_lock(), thelocal_irq_disable()is used to avoid interructions in code execution. C2 port has very stringent timings.
Please add code comments explaning this (unless I missed them).
Quoted 14 lines
Quoted 3 lines
<spots an error-path memory leak in
c2port_device_register><spots a stray semicolon in
c2port_device_register>Can you please explain these two points?
drivers/misc/c2port/core.c new file +8
-0+struct c2port_device *c2port_device_register (char *name, +struct c2port_ops *ops,void *devdata) +{ +struct c2port_device *c2dev; +int id, ret; + + if (unlikely(!ops) || unlikely(!ops->access) || \ + unlikely(!ops->c2d_dir) || unlikely(!ops->c2ck_set) || \
drivers/misc/c2port/core.c line 894
Quoted 10 lines
drivers/misc/c2port/core.c new file +10
-0+ unlikely(!ops->c2d_get) || unlikely(!ops->c2d_set)) +return ERR_PTR (-EINVAL ); + + c2dev =kmalloc (sizeof (struct c2port_device ),GFP_KERNEL ); +if (unlikely (!c2dev)) +return ERR_PTR (-ENOMEM ); + + ret =idr_pre_get (&c2port_idr,GFP_KERNEL ); +if (!ret) +return ERR_PTR (-ENOMEM );
^^ leaks c2dev
Quoted 4 lines
drivers/misc/c2port/core.c new file +4
-0+spin_lock_irq (&c2port_idr_lock); + ret =idr_get_new (&c2port_idr, c2dev, &id); +spin_unlock_irq (&c2port_idr_lock); +
drivers/misc/c2port/core.c line 909
Quoted 10 lines
drivers/misc/c2port/core.c new file +10
-0+if (ret <0 ) + goto error_idr_get_new; + c2dev->id = id; + + c2dev->dev =device_create (c2port_class,NULL ,0 , c2dev, +"c2port%d" , id); +if (unlikely (!c2dev->dev)) { + ret = -ENOMEM ; + goto error_device_create; + };
^
Quoted 10 lines
Quoted 1 line
Quoted 1 line
<suggests that
update_lockbe initialised at compile-time, not at runtime>Fixed.
Quoted 6 lines
What I haven't yet got my head around is this:
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
Quoted 6 lines
Quoted 3 lines
is that really what we want to use sysfs for? As the prime interface to a device driver (or is it a bus driver?) Didn't we used to use device nodes for that sort of thing?
I decided to use this interface since the C2 ports are simple and very easy to manage with such files abstraction.
well.. what _is_ the implemented interface? What alternatives were considered and why were they judged inappropriate? What interfaces do any similar in-tree drivers use?
Quoted 2 lines
Whould you like I repropose the code with the fixed issues for your review?
yup
Re: [PATCH 1/2] Add c2 port support.
Quoted 7 lines · Andrew Morton
Quoted 5 lines
Quoted 1 line
<wonders what
local_irq_disable()is supposed to achieve on SMP>The SMP is achieved by
mutex_lock(), thelocal_irq_disable()is used to avoid interructions in code execution. C2 port has very stringent timings.Please add code comments explaning this (unless I missed them).
Ok.
Quoted 4 lines
drivers/misc/c2port/core.c line 894
Quoted 2 lines
drivers/misc/c2port/core.c new file +2
-0+if (!ret) +return ERR_PTR (-ENOMEM );^^ leaks c2dev
Fixed.
Quoted 6 lines
drivers/misc/c2port/core.c line 909
Quoted 4 lines
drivers/misc/c2port/core.c new file +4
-0+if (unlikely (!c2dev->dev)) { + ret = -ENOMEM ; + goto error_device_create; + };^
Fixed.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
What I haven't yet got my head around is this:
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
is that really what we want to use sysfs for? As the prime interface to a device driver (or is it a bus driver?) Didn't we used to use device nodes for that sort of thing?
Quoted 6 lines
Quoted 2 lines
I decided to use this interface since the C2 ports are simple and very easy to manage with such files abstraction.
well.. what _is_ the implemented interface? What alternatives were considered and why were they judged inappropriate? What interfaces do any similar in-tree drivers use?
Well... main reasons in using sysfs support are:
* no more char devices and new ioctls to define,
* the microcontrollers on-board flash can be easily programmed by using only the "echo" and "cat" commands, so no more tools are needed and even simply busybox can be used.
Quoted 2 lines
Quoted 2 lines
Whould you like I repropose the code with the fixed issues for your review?
I repost the code.
Thanks,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti
Re: [PATCH 1/2] Add c2 port support.
Quoted 12 lines · On Wed, 22 Oct 2008 22:48:01 +0200 Rodolfo Giometti <[email protected]>…
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
What I haven't yet got my head around is this:
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
is that really what we want to use sysfs for? As the prime interface to a device driver (or is it a bus driver?) Didn't we used to use device nodes for that sort of thing?
I decided to use this interface since the C2 ports are simple and very easy to manage with such files abstraction.
Quoted 8 lines
Quoted 3 lines
well.. what _is_ the implemented interface? What alternatives were considered and why were they judged inappropriate? What interfaces do any similar in-tree drivers use?
Well... main reasons in using sysfs support are:
* no more char devices and new ioctls to define,
Why is that good? We have hundreds and hundreds of drivers which use a device node interface and they work OK.
sysfs was never intended for use as the sole interface between device drivers and userspace. Using it that way is somewhat unconventional. At the very least I do think it needs more justification and explanation than we're being provded here.
Device nodes and ioctls and such do have a number of problems, and perhaps we should sit down and invent a new way of wiring drivers up to userspace. But whether that would end up being identical to the present sysfs code is not obvious.
Quoted 3 lines
* the microcontrollers on-board flash can be easily programmed by using only the "echo" and "cat" commands, so no more tools are needed and even simply busybox can be used.
A system which is using busybox might want to set CONFIG_SYSFS=n for memory savings. Now what?
Re: [PATCH 1/2] Add c2 port support.
Quoted 24 lines · Andrew Morton
Quoted 12 lines · On Wed, 22 Oct 2008 22:48:01 +0200 Rodolfo Giometti <[email protected]>…
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
What I haven't yet got my head around is this:
Currently this code supports only flash programming through sysfs interface but extensions shoud be easy to add.
is that really what we want to use sysfs for? As the prime interface to a device driver (or is it a bus driver?) Didn't we used to use device nodes for that sort of thing?
I decided to use this interface since the C2 ports are simple and very easy to manage with such files abstraction.
Quoted 8 lines
Quoted 3 lines
well.. what _is_ the implemented interface? What alternatives were considered and why were they judged inappropriate? What interfaces do any similar in-tree drivers use?
Well... main reasons in using sysfs support are:
* no more char devices and new ioctls to define,
Quoted 7 lines
Why is that good? We have hundreds and hundreds of drivers which use a device node interface and they work OK.
sysfs was never intended for use as the sole interface between device drivers and userspace. Using it that way is somewhat unconventional. At the very least I do think it needs more justification and explanation than we're being provded here.
For firmware download to devices, using sysfs is the "normal" interface these days, that is what the firmware class is for.
Which reminds me, Rodolfo, why didn't you just use that interface for your firmware downloading instead of rolling your own here?
Quoted 11 lines
Device nodes and ioctls and such do have a number of problems, and perhaps we should sit down and invent a new way of wiring drivers up to userspace. But whether that would end up being identical to the present sysfs code is not obvious.
Quoted 3 lines
* the microcontrollers on-board flash can be easily programmed by using only the "echo" and "cat" commands, so no more tools are needed and even simply busybox can be used.
A system which is using busybox might want to set
CONFIG_SYSFS=nfor memory savings. Now what?
My daughter's phone (the #1 selling handset last year in the US) has sysfs enabled, I think this argument can be put to rest as not a valid one.
thanks,
greg k-h
Re: [PATCH 1/2] Add c2 port support.
Quoted 8 lines · Greg KH
Quoted 7 lines
Why is that good? We have hundreds and hundreds of drivers which use a device node interface and they work OK.
sysfs was never intended for use as the sole interface between device drivers and userspace. Using it that way is somewhat unconventional. At the very least I do think it needs more justification and explanation than we're being provded here.
Quoted 5 lines
For firmware download to devices, using sysfs is the "normal" interface these days, that is what the firmware class is for.
Which reminds me, Rodolfo, why didn't you just use that interface for your firmware downloading instead of rolling your own here?
Because I need also to know revision ID, device ID and other minor info from the microcontroller. Also I can reset the microcontroller when I need it without downloading any new firmware.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti
Re: [PATCH 1/2] Add c2 port support.
Quoted 10 lines · Rodolfo Giometti
Quoted 8 lines · Greg KH
Quoted 7 lines
Why is that good? We have hundreds and hundreds of drivers which use a device node interface and they work OK.
sysfs was never intended for use as the sole interface between device drivers and userspace. Using it that way is somewhat unconventional. At the very least I do think it needs more justification and explanation than we're being provded here.
Quoted 8 lines
Quoted 5 lines
For firmware download to devices, using sysfs is the "normal" interface these days, that is what the firmware class is for.
Which reminds me, Rodolfo, why didn't you just use that interface for your firmware downloading instead of rolling your own here?
Because I need also to know revision ID, device ID and other minor info from the microcontroller.
You can still use sysfs for that, no problems there.
Quoted 2 lines
Also I can reset the microcontroller when I need it without downloading any new firmware.
And again, you can still use sysfs for that as well. I was just referring to the binary sysfs file that you use for the firmware download, it would make more sense for you to use the standard kernel firmware download interface instead of rolling your own here.
thanks,
greg k-h
Re: [PATCH 1/2] Add c2 port support.
Quoted 4 lines · Greg KH
And again, you can still use sysfs for that as well. I was just referring to the binary sysfs file that you use for the firmware download, it would make more sense for you to use the standard kernel firmware download interface instead of rolling your own here.
If I well understand the firmware class it works starting the firmware download from the kernel side, that is into the kernel we should call request_firmware() and then the files will /sys/class/firmware/xxx/{loading,data} appear.
This solution doesn't fit C2 port needs since the firmware download is decided from userland erasing and then writing into the microcontroller on-board flash.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming skype: rodolfo.giometti
Re: [PATCH 1/2] Add c2 port support.
Quoted 11 lines · Rodolfo Giometti
Quoted 4 lines · Greg KH
And again, you can still use sysfs for that as well. I was just referring to the binary sysfs file that you use for the firmware download, it would make more sense for you to use the standard kernel firmware download interface instead of rolling your own here.
If I well understand the firmware class it works starting the firmware download from the kernel side, that is into the kernel we should call
request_firmware()and then the files will/sys/class/firmware/xxx/{loading,data}appear.
Yes, that is true, but userspace doesn't have to write to those files until it feels like it.
Quoted 3 lines
This solution doesn't fit C2 port needs since the firmware download is decided from userland erasing and then writing into the microcontroller on-board flash.
That's fine, you can still use the same interface, no problems. Just use the "async" version of the firmware interfae and you will be fine.
thanks,
greg k-h