167468Snon.. SPDX-License-Identifier: GPL-2.0
267468Snon.. include:: <isonum.txt>
367468Snon
467468Snon===============
567468SnonC2 port support
667468Snon===============
767468Snon
867468Snon(C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
967468Snon
1067468SnonThis program is free software; you can redistribute it and/or modify
1167468Snonit under the terms of the GNU General Public License as published by
1267468Snonthe Free Software Foundation; either version 2 of the License, or
1367468Snon(at your option) any later version.
1467468Snon
1567468SnonThis program is distributed in the hope that it will be useful,
1667468Snonbut WITHOUT ANY WARRANTY; without even the implied warranty of
1767468SnonMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1867468SnonGNU General Public License for more details.
1967468Snon
2067468Snon
2167468Snon
2267468SnonOverview
2367468Snon--------
2467468Snon
2567468SnonThis driver implements the support for Linux of Silicon Labs (Silabs)
2667468SnonC2 Interface used for in-system programming of micro controllers.
2767468Snon
2867468SnonBy using this driver you can reprogram the in-system flash without EC2
2967468Snonor EC3 debug adapter. This solution is also useful in those systems
3067468Snonwhere the micro controller is connected via special GPIOs pins.
3167468Snon
3267468SnonReferences
3367468Snon----------
3467468Snon
3567468SnonThe C2 Interface main references are at (https://www.silabs.com)
3667468SnonSilicon Laboratories site], see:
3767468Snon
3867468Snon- AN127: FLASH Programming via the C2 Interface at
3967468Snon  https://www.silabs.com/Support Documents/TechnicalDocs/an127.pdf
4067468Snon
4167468Snon- C2 Specification at
4267468Snon  https://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support%20Documents/TechnicalDocs/an127.pdf&src=SearchResults
4367468Snon
4467468Snonhowever it implements a two wire serial communication protocol (bit
4567468Snonbanging) designed to enable in-system programming, debugging, and
4667468Snonboundary-scan testing on low pin-count Silicon Labs devices. Currently
4767468Snonthis code supports only flash programming but extensions are easy to
4867468Snonadd.
4967468Snon
5067468SnonUsing the driver
5167468Snon----------------
5267468Snon
5367468SnonOnce the driver is loaded you can use sysfs support to get C2port's
5467468Snoninfo or read/write in-system flash::
5567468Snon
5667468Snon  # ls /sys/class/c2port/c2port0/
5767468Snon  access            flash_block_size  flash_erase       rev_id
5867468Snon  dev_id            flash_blocks_num  flash_size        subsystem/
5967468Snon  flash_access      flash_data        reset             uevent
6067468Snon
6167468SnonInitially the C2port access is disabled since you hardware may have
6267468Snonsuch lines multiplexed with other devices so, to get access to the
6367468SnonC2port, you need the command::
6467468Snon
6567468Snon  # echo 1 > /sys/class/c2port/c2port0/access
6667468Snon
6767468Snonafter that you should read the device ID and revision ID of the
6867468Snonconnected micro controller::
6967468Snon
7067468Snon  # cat /sys/class/c2port/c2port0/dev_id
7167468Snon  8
7267468Snon  # cat /sys/class/c2port/c2port0/rev_id
7367468Snon  1
7467468Snon
7567468SnonHowever, for security reasons, the in-system flash access in not
7667468Snonenabled yet, to do so you need the command::
7767468Snon
7867468Snon  # echo 1 > /sys/class/c2port/c2port0/flash_access
7967468Snon
8067468SnonAfter that you can read the whole flash::
8167468Snon
8267468Snon  # cat /sys/class/c2port/c2port0/flash_data > image
8367468Snon
8467468Snonerase it::
8567468Snon
8667468Snon  # echo 1 > /sys/class/c2port/c2port0/flash_erase
8767468Snon
8867468Snonand write it::
8967468Snon
9067468Snon  # cat image > /sys/class/c2port/c2port0/flash_data
9167468Snon
9267468Snonafter writing you have to reset the device to execute the new code::
9367468Snon
9467468Snon  # echo 1 > /sys/class/c2port/c2port0/reset
9567468Snon