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