Add basic support for mini2440 board to barebox.
[barebox-mini2440.git] / commands / gpio.c
blob2575c1e50e4882265daf3ae606a2e6c291da266b
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
15 * MA 02111-1307 USA
18 #include <common.h>
19 #include <command.h>
20 #include <errno.h>
21 #include <gpio.h>
23 static int do_gpio_get_value(struct command *cmdtp, int argc, char *argv[])
25 int gpio, value;
27 if (argc < 2)
28 return COMMAND_ERROR_USAGE;
30 gpio = simple_strtoul(argv[1], NULL, 0);
32 value = gpio_get_value(gpio);
33 if (value < 0)
34 return 1;
36 return value;
39 static const __maybe_unused char cmd_gpio_get_value_help[] =
40 "Usage: gpio_set_value <gpio>\n";
42 BAREBOX_CMD_START(gpio_get_value)
43 .cmd = do_gpio_get_value,
44 .usage = "return a gpio's value",
45 BAREBOX_CMD_HELP(cmd_gpio_get_value_help)
46 BAREBOX_CMD_END
48 static int do_gpio_set_value(struct command *cmdtp, int argc, char *argv[])
50 int gpio, value;
52 if (argc < 3)
53 return COMMAND_ERROR_USAGE;
55 gpio = simple_strtoul(argv[1], NULL, 0);
56 value = simple_strtoul(argv[2], NULL, 0);
58 gpio_set_value(gpio, value);
60 return 0;
63 static const __maybe_unused char cmd_gpio_set_value_help[] =
64 "Usage: gpio_set_value <gpio> <value>\n";
66 BAREBOX_CMD_START(gpio_set_value)
67 .cmd = do_gpio_set_value,
68 .usage = "set a gpio's output value",
69 BAREBOX_CMD_HELP(cmd_gpio_set_value_help)
70 BAREBOX_CMD_END
72 static int do_gpio_direction_input(struct command *cmdtp, int argc, char *argv[])
74 int gpio, ret;
76 if (argc < 2)
77 return COMMAND_ERROR_USAGE;
79 gpio = simple_strtoul(argv[1], NULL, 0);
81 ret = gpio_direction_input(gpio);
82 if (ret)
83 return 1;
85 return 0;
88 static const __maybe_unused char cmd_do_gpio_direction_input_help[] =
89 "Usage: gpio_direction_input <gpio>\n";
91 BAREBOX_CMD_START(gpio_direction_input)
92 .cmd = do_gpio_direction_input,
93 .usage = "set a gpio as output",
94 BAREBOX_CMD_HELP(cmd_do_gpio_direction_input_help)
95 BAREBOX_CMD_END
97 static int do_gpio_direction_output(struct command *cmdtp, int argc, char *argv[])
99 int gpio, value, ret;
101 if (argc < 3)
102 return COMMAND_ERROR_USAGE;
104 gpio = simple_strtoul(argv[1], NULL, 0);
105 value = simple_strtoul(argv[2], NULL, 0);
107 ret = gpio_direction_output(gpio, value);
108 if (ret)
109 return 1;
111 return 0;
114 static const __maybe_unused char cmd_gpio_direction_output_help[] =
115 "Usage: gpio_direction_output <gpio> <value>\n";
117 BAREBOX_CMD_START(gpio_direction_output)
118 .cmd = do_gpio_direction_output,
119 .usage = "set a gpio as output",
120 BAREBOX_CMD_HELP(cmd_gpio_direction_output_help)
121 BAREBOX_CMD_END