2 * This file is part of the flashrom project.
4 * Copyright (C) 2012 Virgil-Adrian Teaca
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /* Driver for the SI-Prog like hardware by Lancos.com.
21 * See http://www.lancos.com/siprogsch.html for schematics and instructions.
28 #include "programmer.h"
45 /* The hardware programmer used. */
46 static enum pony_type pony_type = TYPE_SI_PROG;
48 static void pony_bitbang_set_cs(int val)
50 if (pony_type == TYPE_SI_PROG)
52 /* CS# is negated by the SI-Prog programmer. */
55 sp_set_pin(PIN_TXD, val);
58 static void pony_bitbang_set_sck(int val)
60 sp_set_pin(PIN_RTS, val);
63 static void pony_bitbang_set_mosi(int val)
65 sp_set_pin(PIN_DTR, val);
68 static int pony_bitbang_get_miso(void)
72 tmp = sp_get_pin(PIN_CTS);
74 if (pony_type == TYPE_SERBANG)
76 /* MISO is negated by the SERBANG programmer. */
82 static const struct bitbang_spi_master bitbang_spi_master_pony = {
83 .type = BITBANG_SPI_MASTER_PONY,
84 .set_cs = pony_bitbang_set_cs,
85 .set_sck = pony_bitbang_set_sck,
86 .set_mosi = pony_bitbang_set_mosi,
87 .get_miso = pony_bitbang_get_miso,
91 int pony_spi_init(void)
94 int i, data_in, data_out, have_device = 0;
97 /* The parameter is on format "dev=/dev/device,type=serbang" */
98 arg = extract_programmer_param("dev");
100 if (arg && strlen(arg)) {
101 sp_fd = sp_openserport( arg, 9600 );
111 msg_perr("Error: No valid device specified.\n"
112 "Use flashrom -p pony_spi:dev=/dev/device\n");
116 /* Register the shutdown callback. */
117 if (register_shutdown(serialport_shutdown, NULL)) {
120 arg = extract_programmer_param("type");
123 if (!strcasecmp( arg, "serbang")) {
124 pony_type = TYPE_SERBANG;
125 } else if (!strcasecmp( arg, "si_prog") ) {
126 pony_type = TYPE_SI_PROG;
128 msg_perr("Error: Invalid programmer type specified.\n");
135 msg_pdbg("Using the %s programmer.\n", ((pony_type == TYPE_SI_PROG ) ? "SI-Prog" : "SERBANG"));
137 * Detect if there is a SI-Prog compatible programmer connected.
139 pony_bitbang_set_cs(1);
140 pony_bitbang_set_mosi(1);
142 /* We toggle SCK while we keep MOSI and CS# on. */
143 for (i = 1; i <= 10; ++i) {
145 sp_set_pin(PIN_RTS, data_out);
146 programmer_delay( 1000 );
147 data_in = sp_get_pin(PIN_DSR);
149 if (data_out != data_in) {
156 msg_perr( "No SI-Prog compatible hardware detected.\n" );
160 if (bitbang_spi_init(&bitbang_spi_master_pony)) {