mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 19:26:25 +00:00
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. Signed-off-by: Rodolfo Giometti <giometti@linux.it> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e0a29382c6
commit
4e17e1db96
8 changed files with 1273 additions and 0 deletions
88
Documentation/ABI/testing/sysfs-c2port
Normal file
88
Documentation/ABI/testing/sysfs-c2port
Normal file
|
@ -0,0 +1,88 @@
|
|||
What: /sys/class/c2port/
|
||||
Date: October 2008
|
||||
Contact: Rodolfo Giometti <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
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 <giometti@linux.it>
|
||||
Description:
|
||||
The /sys/class/c2port/c2portX/rev_id file show the revision ID
|
||||
of the connected micro.
|
90
Documentation/c2port.txt
Normal file
90
Documentation/c2port.txt
Normal file
|
@ -0,0 +1,90 @@
|
|||
C2 port support
|
||||
---------------
|
||||
|
||||
(C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
This driver implements the support for Linux of Silicon Labs (Silabs)
|
||||
C2 Interface used for in-system programming of micro controllers.
|
||||
|
||||
By using this driver you can reprogram the in-system flash without EC2
|
||||
or EC3 debug adapter. This solution is also useful in those systems
|
||||
where the micro controller is connected via special GPIOs pins.
|
||||
|
||||
References
|
||||
----------
|
||||
|
||||
The C2 Interface main references are at (http://www.silabs.com)
|
||||
Silicon Laboratories site], see:
|
||||
|
||||
- AN127: FLASH Programming via the C2 Interface at
|
||||
http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Small_Form_Factor/en/an127.pdf, and
|
||||
|
||||
- C2 Specification at
|
||||
http://www.silabs.com/public/documents/tpub_doc/spec/Microcontrollers/en/C2spec.pdf,
|
||||
|
||||
however it 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 but extensions are easy to
|
||||
add.
|
||||
|
||||
Using the driver
|
||||
----------------
|
||||
|
||||
Once the driver is loaded you can use sysfs support to get C2port's
|
||||
info or read/write in-system flash.
|
||||
|
||||
# ls /sys/class/c2port/c2port0/
|
||||
access flash_block_size flash_erase rev_id
|
||||
dev_id flash_blocks_num flash_size subsystem/
|
||||
flash_access flash_data reset uevent
|
||||
|
||||
Initially the C2port access is disabled since you hardware may have
|
||||
such lines multiplexed with other devices so, to get access to the
|
||||
C2port, you need the command:
|
||||
|
||||
# echo 1 > /sys/class/c2port/c2port0/access
|
||||
|
||||
after that you should read the device ID and revision ID of the
|
||||
connected micro controller:
|
||||
|
||||
# cat /sys/class/c2port/c2port0/dev_id
|
||||
8
|
||||
# cat /sys/class/c2port/c2port0/rev_id
|
||||
1
|
||||
|
||||
However, for security reasons, the in-system flash access in not
|
||||
enabled yet, to do so you need the command:
|
||||
|
||||
# echo 1 > /sys/class/c2port/c2port0/flash_access
|
||||
|
||||
After that you can read the whole flash:
|
||||
|
||||
# cat /sys/class/c2port/c2port0/flash_data > image
|
||||
|
||||
erase it:
|
||||
|
||||
# echo 1 > /sys/class/c2port/c2port0/flash_erase
|
||||
|
||||
and write it:
|
||||
|
||||
# cat image > /sys/class/c2port/c2port0/flash_data
|
||||
|
||||
after writing you have to reset the device to execute the new code:
|
||||
|
||||
# echo 1 > /sys/class/c2port/c2port0/reset
|
|
@ -498,4 +498,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
|
||||
|
|
|
@ -32,3 +32,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/
|
||||
|
|
24
drivers/misc/c2port/Kconfig
Normal file
24
drivers/misc/c2port/Kconfig
Normal file
|
@ -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
|
1
drivers/misc/c2port/Makefile
Normal file
1
drivers/misc/c2port/Makefile
Normal file
|
@ -0,0 +1 @@
|
|||
obj-$(CONFIG_C2PORT) += core.o
|
1002
drivers/misc/c2port/core.c
Normal file
1002
drivers/misc/c2port/core.c
Normal file
File diff suppressed because it is too large
Load diff
65
include/linux/c2port.h
Normal file
65
include/linux/c2port.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Silicon Labs C2 port Linux support
|
||||
*
|
||||
* Copyright (c) 2007 Rodolfo Giometti <giometti@linux.it>
|
||||
* Copyright (c) 2007 Eurotech S.p.A. <info@eurotech.it>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published by
|
||||
* the Free Software Foundation
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
|
||||
#define C2PORT_NAME_LEN 32
|
||||
|
||||
/*
|
||||
* C2 port basic structs
|
||||
*/
|
||||
|
||||
/* Main struct */
|
||||
struct c2port_ops;
|
||||
struct c2port_device {
|
||||
unsigned int access:1;
|
||||
unsigned int flash_access:1;
|
||||
|
||||
int id;
|
||||
char name[C2PORT_NAME_LEN];
|
||||
struct c2port_ops *ops;
|
||||
struct mutex mutex; /* prevent races during read/write */
|
||||
|
||||
struct device *dev;
|
||||
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
/* Basic operations */
|
||||
struct c2port_ops {
|
||||
/* Flash layout */
|
||||
unsigned short block_size; /* flash block size in bytes */
|
||||
unsigned short blocks_num; /* flash blocks number */
|
||||
|
||||
/* Enable or disable the access to C2 port */
|
||||
void (*access)(struct c2port_device *dev, int status);
|
||||
|
||||
/* Set C2D data line as input/output */
|
||||
void (*c2d_dir)(struct c2port_device *dev, int dir);
|
||||
|
||||
/* Read/write C2D data line */
|
||||
int (*c2d_get)(struct c2port_device *dev);
|
||||
void (*c2d_set)(struct c2port_device *dev, int status);
|
||||
|
||||
/* Write C2CK clock line */
|
||||
void (*c2ck_set)(struct c2port_device *dev, int status);
|
||||
};
|
||||
|
||||
/*
|
||||
* Exported functions
|
||||
*/
|
||||
|
||||
#define to_class_dev(obj) container_of((obj), struct class_device, kobj)
|
||||
#define to_c2port_device(obj) container_of((obj), struct c2port_device, class)
|
||||
|
||||
extern struct c2port_device *c2port_device_register(char *name,
|
||||
struct c2port_ops *ops, void *devdata);
|
||||
extern void c2port_device_unregister(struct c2port_device *dev);
|
Loading…
Reference in a new issue