xref: /linux/Documentation/misc-devices/c2port.rst (revision e999db587312e5b798421d803495f41d1283d7d7)
1.. SPDX-License-Identifier: GPL-2.0
2.. include:: <isonum.txt>
3
4===============
5C2 port support
6===============
7
8(C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18GNU General Public License for more details.
19
20
21
22Overview
23--------
24
25This driver implements the support for Linux of Silicon Labs (Silabs)
26C2 Interface used for in-system programming of micro controllers.
27
28By using this driver you can reprogram the in-system flash without EC2
29or EC3 debug adapter. This solution is also useful in those systems
30where the micro controller is connected via special GPIOs pins.
31
32References
33----------
34
35The C2 Interface main references are at (https://www.silabs.com)
36Silicon Laboratories site], see:
37
38- AN127: FLASH Programming via the C2 Interface at
39  https://www.silabs.com/Support Documents/TechnicalDocs/an127.pdf
40
41- C2 Specification at
42  https://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support%20Documents/TechnicalDocs/an127.pdf&src=SearchResults
43
44however it implements a two wire serial communication protocol (bit
45banging) designed to enable in-system programming, debugging, and
46boundary-scan testing on low pin-count Silicon Labs devices. Currently
47this code supports only flash programming but extensions are easy to
48add.
49
50Using the driver
51----------------
52
53Once the driver is loaded you can use sysfs support to get C2port's
54info or read/write in-system flash::
55
56  # ls /sys/class/c2port/c2port0/
57  access            flash_block_size  flash_erase       rev_id
58  dev_id            flash_blocks_num  flash_size        subsystem/
59  flash_access      flash_data        reset             uevent
60
61Initially the C2port access is disabled since you hardware may have
62such lines multiplexed with other devices so, to get access to the
63C2port, you need the command::
64
65  # echo 1 > /sys/class/c2port/c2port0/access
66
67after that you should read the device ID and revision ID of the
68connected micro controller::
69
70  # cat /sys/class/c2port/c2port0/dev_id
71  8
72  # cat /sys/class/c2port/c2port0/rev_id
73  1
74
75However, for security reasons, the in-system flash access in not
76enabled yet, to do so you need the command::
77
78  # echo 1 > /sys/class/c2port/c2port0/flash_access
79
80After that you can read the whole flash::
81
82  # cat /sys/class/c2port/c2port0/flash_data > image
83
84erase it::
85
86  # echo 1 > /sys/class/c2port/c2port0/flash_erase
87
88and write it::
89
90  # cat image > /sys/class/c2port/c2port0/flash_data
91
92after writing you have to reset the device to execute the new code::
93
94  # echo 1 > /sys/class/c2port/c2port0/reset
95