linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Olof Johansson <olof@lixom.net>
To: linux-omap@vger.kernel.org
Cc: olof@lixom.net
Subject: [HACK] remotely powering on a OMAP5 uEVM over the debug port
Date: Thu, 5 Dec 2013 09:56:25 -0800	[thread overview]
Message-ID: <20131205175625.GA15019@quad.lixom.net> (raw)

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);
}

             reply	other threads:[~2013-12-05 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05 17:56 Olof Johansson [this message]
2013-12-05 18:01 ` [HACK] remotely powering on a OMAP5 uEVM over the debug port Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131205175625.GA15019@quad.lixom.net \
    --to=olof@lixom.net \
    --cc=linux-omap@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).