* Re: [PATCH] ARM: mach-shmobile: sh7372 A3RV power domain prototype
2011-06-24 5:54 [PATCH] ARM: mach-shmobile: sh7372 A3RV power domain prototype Magnus Damm
@ 2011-06-24 6:07 ` Magnus Damm
0 siblings, 0 replies; 2+ messages in thread
From: Magnus Damm @ 2011-06-24 6:07 UTC (permalink / raw)
To: linux-sh
[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]
On Fri, Jun 24, 2011 at 3:02 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
> From: Magnus Damm <damm@opensource.se>
>
> This somewhat messy prototype patch adds A3RV power domain
> control support for sh7372. The A3RV power domain contains
> the VPU video encoder/decoder which is exported through UIO.
>
> The prototype serves as an example of a simple power domain
> that needs to be turned off during boot. The default setting
> after hardware reset is to keep A3RV powered on. The UIO driver
> uio_pdrv_genirq.c does not access the VPU hardware at ->probe()
> time but instead relies 100% on user space. So the VPU device
> and A3RV will always be unused during boot.
Also, people may want to use the attached test program to give this a go.
Without this patch, when "vpu-test" is executed twice then the second
run will produce this message:
"VPU5HG state kept since last open"
The message above is outputted when the state of a certain VPU
register is kept over UIO close->open.
With this patch applied the state of the VPU is always lost between
the UIO close->open, so the above message will never appear - at least
until there is a governor in place that prevents the power from being
turned off based on QoS information.
Cheers,
/ magnus
[-- Attachment #2: vpu-test-20110622.c --]
[-- Type: text/x-csrc, Size: 4223 bytes --]
/*
* vpu-test - AP4 VPU test program, 20110622 Magnus Damm
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
static int fgets_with_openclose(char *fname, char *buf, size_t maxlen) {
FILE *fp;
if ((fp = fopen(fname, "r")) != NULL) {
fgets(buf, maxlen, fp);
fclose(fp);
return strlen(buf);
} else {
return -1;
}
}
struct uio_device {
char *name;
char *path;
int fd;
};
#define MAXUIOIDS 100
#define MAXNAMELEN 256
static int locate_uio_device(char *name, struct uio_device *udp)
{
char fname[MAXNAMELEN], buf[MAXNAMELEN];
int uio_id, i;
for (uio_id = 0; uio_id < MAXUIOIDS; uio_id++) {
sprintf(fname, "/sys/class/uio/uio%d/name", uio_id);
if (fgets_with_openclose(fname, buf, MAXNAMELEN) < 0)
continue;
if (strncmp(name, buf, strlen(name)) == 0)
break;
}
if (uio_id >= MAXUIOIDS)
return -1;
udp->name = strdup(buf);
udp->path = strdup(fname);
udp->path[strlen(udp->path) - 4] = '\0';
sprintf(buf, "/dev/uio%d", uio_id);
udp->fd = open(buf, O_RDWR|O_SYNC /*| O_NONBLOCK*/);
if (udp->fd < 0) {
perror("open");
return -1;
}
return 0;
}
struct uio_map {
unsigned long address;
unsigned long size;
void *iomem;
};
static int setup_uio_map(struct uio_device *udp, int nr, struct uio_map *ump)
{
char fname[MAXNAMELEN], buf[MAXNAMELEN];
sprintf(fname, "%s/maps/map%d/addr", udp->path, nr);
if (fgets_with_openclose(fname, buf, MAXNAMELEN) <= 0)
return -1;
ump->address = strtoul(buf, NULL, 0);
sprintf(fname, "%s/maps/map%d/size", udp->path, nr);
if (fgets_with_openclose(fname, buf, MAXNAMELEN) <= 0)
return -1;
ump->size = strtoul(buf, NULL, 0);
ump->iomem = mmap(0, ump->size,
PROT_READ|PROT_WRITE, MAP_SHARED,
udp->fd, nr * getpagesize());
if (ump->iomem == MAP_FAILED)
return -1;
return 0;
}
struct uio_device uio_dev;
struct uio_map uio_mmio;
int main(int argc, char *argv[])
{
int ret;
ret = locate_uio_device("VPU5HG", &uio_dev);
if (ret < 0) {
fprintf(stderr, "unable to locate UIO device\n");
return 1;
}
ret = setup_uio_map(&uio_dev, 0, &uio_mmio);
if (ret < 0) {
fprintf(stderr, "unable to setup UIO memory map\n");
return 1;
}
{
unsigned long *ph = (uio_mmio.iomem + 0x00); /* VCRH */
unsigned long *pl = (uio_mmio.iomem + 0x04); /* VCRL */
unsigned long *pc = (uio_mmio.iomem + 0x08); /* CMD */
unsigned long *pm = (uio_mmio.iomem + 0x80); /* MBA */
int k;
if ((*ph & 0xffff) == 0x55f4) {
printf("detected VPU5HG with VCRH:VCRL 0x%08lx:%08lx\n",
*ph, *pl);
if (*pm == 0xdeadbeef) {
printf("VPU5HG state kept since last open\n");
}
*pc = 1 << 10; /* set MRST bit to force reset */
for (k = 0; k < 5; k++) {
if (!(*pc & (1 << 10))) {
printf("VPU5HG reset check OK\n");
*pm = 0xdeadbeef;
printf("Sleeping 5 seconds...\n");
sleep(5);
return 0;
}
sleep(1);
}
}
}
fprintf(stderr, "unable to detect/reset VPU5HG\n");
return 1;
}
^ permalink raw reply [flat|nested] 2+ messages in thread