2 * Control GPIO pins on the fly
4 * Copyright (c) 2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
12 #include <asm/blackfin.h>
14 int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
18 printf("Usage:\n%s\n", cmdtp->usage);
22 /* parse the behavior */
26 case 's': port_cmd = (PORTFIO_SET - PORTFIO); break;
27 case 'c': port_cmd = (PORTFIO_CLEAR - PORTFIO); break;
28 case 't': port_cmd = (PORTFIO_TOGGLE - PORTFIO); break;
29 default: goto show_usage;
32 /* parse the pin with format: [p]<fgh><#> */
33 const char *str_pin = argv[2];
35 /* grab the [p]<fgh> portion */
37 if (*str_pin == 'p') ++str_pin;
39 case 'f': port_base = PORTFIO; break;
40 case 'g': port_base = PORTGIO; break;
41 case 'h': port_base = PORTHIO; break;
42 default: goto show_usage;
45 /* grab the <#> portion */
46 ulong pin = simple_strtoul(str_pin+1, NULL, 10);
47 ulong pin_mask = (1 << pin);
51 /* finally, let's do it: set direction and exec command */
53 case 'f': bfin_write_PORTF_FER(bfin_read_PORTF_FER() & ~pin_mask); break;
54 case 'g': bfin_write_PORTG_FER(bfin_read_PORTG_FER() & ~pin_mask); break;
55 case 'h': bfin_write_PORTH_FER(bfin_read_PORTH_FER() & ~pin_mask); break;
58 ulong port_dir = port_base + (PORTFIO_DIR - PORTFIO);
59 if (argv[1][0] == 'i')
60 bfin_write16(port_dir, bfin_read16(port_dir) & ~pin_mask);
62 bfin_write16(port_dir, bfin_read16(port_dir) | pin_mask);
63 bfin_write16(port_base + port_cmd, pin_mask);
66 printf("gpio: pin %li on port %c has been %c\n", pin, *str_pin, argv[1][0]);
71 U_BOOT_CMD(gpio, 3, 0, do_gpio,
72 "gpio - set/clear/toggle gpio output pins\n",
73 "<s|c|t> <port><pin>\n"
74 " - set/clear/toggle the specified pin\n");