cfg: ftdi icdi enable srst open drain config
[fw/openocd] / src / jtag / stlink / stlink_layout.c
1 /***************************************************************************
2  *   Copyright (C) 2011 by Mathias Kuester                                 *
3  *   Mathias Kuester <kesmtp@freenet.de>                                   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 /* project specific includes */
26 #include <jtag/interface.h>
27 #include <transport/transport.h>
28 #include <helper/time_support.h>
29
30 #include <jtag/stlink/stlink_layout.h>
31 #include <jtag/stlink/stlink_tcl.h>
32 #include <jtag/stlink/stlink_transport.h>
33 #include <jtag/stlink/stlink_interface.h>
34
35 #define STLINK_LAYOUT_UNKNOWN   0
36 #define STLINK_LAYOUT_SG        1
37 #define STLINK_LAYOUT_USB       2
38
39 static int stlink_layout_open(struct stlink_interface_s *stlink_if)
40 {
41         int res;
42
43         LOG_DEBUG("stlink_layout_open");
44
45         stlink_if->fd = NULL;
46
47         res = stlink_if->layout->api->open(&stlink_if->param, &stlink_if->fd);
48
49         if (res != ERROR_OK) {
50                 LOG_DEBUG("failed");
51                 return res;
52         }
53
54         return ERROR_OK;
55 }
56
57 static int stlink_layout_close(struct stlink_interface_s *stlink_if)
58 {
59         return ERROR_OK;
60 }
61
62 static const struct stlink_layout stlink_layouts[] = {
63         {
64          .name = "usb",
65          .type = STLINK_LAYOUT_USB,
66          .open = stlink_layout_open,
67          .close = stlink_layout_close,
68          .api = &stlink_usb_layout_api,
69          },
70         {
71          .name = "sg",
72          .type = STLINK_LAYOUT_SG,
73          .open = stlink_layout_open,
74          .close = stlink_layout_close,
75          .api = &stlink_usb_layout_api,
76          },
77         {.name = NULL, /* END OF TABLE */ },
78 };
79
80 /** */
81 const struct stlink_layout *stlink_layout_get_list(void)
82 {
83         return stlink_layouts;
84 }
85
86 int stlink_layout_init(struct stlink_interface_s *stlink_if)
87 {
88         LOG_DEBUG("stlink_layout_init");
89
90         if (stlink_if->layout == NULL) {
91                 LOG_ERROR("no layout specified");
92                 return ERROR_FAIL;
93         }
94         return ERROR_OK;
95 }