a0dfb996e646a78d2c750a0621962dbf73440cb2
[fw/openocd] / src / jtag / drivers / versaloon / usbtoxxx / usbtopwr.c
1 /***************************************************************************
2  *   Copyright (C) 2009 - 2010 by Simon Qian <SimonQian@SimonQian.com>     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
18  ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <string.h>
25
26 #include "../versaloon_include.h"
27 #include "../versaloon.h"
28 #include "../versaloon_internal.h"
29 #include "usbtoxxx.h"
30 #include "usbtoxxx_internal.h"
31
32 RESULT usbtopwr_init(uint8_t interface_index)
33 {
34         return usbtoxxx_init_command(USB_TO_POWER, interface_index);
35 }
36
37 RESULT usbtopwr_fini(uint8_t interface_index)
38 {
39         return usbtoxxx_fini_command(USB_TO_POWER, interface_index);
40 }
41
42 RESULT usbtopwr_config(uint8_t interface_index)
43 {
44 #if PARAM_CHECK
45         if (interface_index > 7) {
46                 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
47                 return ERROR_FAIL;
48         }
49 #endif
50
51         return usbtoxxx_conf_command(USB_TO_POWER, interface_index, NULL, 0);
52 }
53
54 RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV)
55 {
56 #if PARAM_CHECK
57         if (interface_index > 7) {
58                 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
59                 return ERROR_FAIL;
60         }
61 #endif
62
63         return usbtoxxx_out_command(USB_TO_POWER, interface_index, (uint8_t *)&mV,
64                 2, 0);
65 }