linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [HACK] remotely powering on a OMAP5 uEVM over the debug port
@ 2013-12-05 17:56 Olof Johansson
  2013-12-05 18:01 ` Tony Lindgren
  0 siblings, 1 reply; 2+ messages in thread
From: Olof Johansson @ 2013-12-05 17:56 UTC (permalink / raw)
  To: linux-omap; +Cc: olof

Here's a tiny hack I came up with to remote-power on an OMAP5 uEVM. I
have mine in an unattended setup where I can cycle power, but it still
needs a power button press to start.

Luckily two GPIO lines on the secondary FTDI channel are routed to the same
buttons, so it can be done via software. It requires your board to have U37
populated though, so make sure you have it (mine did already).

The below little hack uses libmpsse, available at
https://code.google.com/p/libmpsse/.

To use it, give it the path of the FTDI device. I.e. on my system the uEVM is
at 3-1.3.3. Check dmesg and lsusb (it's bus number + path).


Anyway, I figured this could be useful for others as well, so I'm posting just
for that purpose. No warranties, don't come to me if you break your board with
this, etc, etc.



This pulses the power button for 1 second (GPIOH5). If you want to pulse
the reset instead, use GPIOH6.


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <usb.h>
#include <mpsse.h>

void usage(char *p)
{
	printf("Usage: %s <busnr>-<devpath>\n", p);
}

void fill_busdev(char *usbpath, int *bus, int *dev)
{
	char udir[PATH_MAX+1];
	FILE *fp;

	sprintf(udir, "/sys/bus/usb/devices/%s/busnum", usbpath);
	
	fp = fopen(udir, "r");
	if (!fp) {
		printf("can't open %s to find usb info\n", udir);
		exit(1);
	}
	fscanf(fp, "%d", bus);
	fclose(fp);

	sprintf(udir, "/sys/bus/usb/devices/%s/devnum", usbpath);
	
	fp = fopen(udir, "r");
	if (!fp) {
		printf("can't open %s to find usb info\n", udir);
		exit(1);
	}
	fscanf(fp, "%d", dev);
	fclose(fp);

}
int main(int argc, char **argv)
{
	struct mpsse_context *io = NULL;
	int i = 0;
	int bus, dev;

	if (argc < 1) {
		usage(argv[0]);
		exit(1);
	}

	fill_busdev(argv[1], &bus, &dev);

	while (1) {
		struct usb_device *ud;
		io = OpenIndex(0x0403, 0x6010, GPIO, 0, 0, 2, NULL, NULL, i++);
		if (!io || !io->open) {
			printf("Failed to open device %s\n", argv[1]);
			exit(1);
		}
		ud = usb_device(io->ftdi.usb_dev);
		if (ud->devnum == dev && ud->bus->location == bus) {
			printf("found: %s/%s %d\n", ud->bus->dirname, ud->filename, ud->bus->location);
			break;
		} else {
			printf("skipped: %s/%s %d\n", ud->bus->dirname, ud->filename, ud->bus->location);
		}
		Close(io);
	}

	/* Default is high */
	PinHigh(io, GPIOH5);
	PinHigh(io, GPIOH6);

	sleep(1);
	/* Pulse power */
	PinLow(io, GPIOH5);
	sleep(1);
	PinHigh(io, GPIOH5);

	Close(io);

	exit(0);
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-05 18:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05 17:56 [HACK] remotely powering on a OMAP5 uEVM over the debug port Olof Johansson
2013-12-05 18:01 ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).