Esempio n. 1
0
/**
 * extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
 * 						char *drvname);
 *
 * flag:
 * 	0 	: bus -> valid, drvname -> valid
 * 	1 	: bus -> valid, drvname -> invalid
 * 	2 	: bus -> valid, drvname -> NULL
 * 	3 	: bus -> NULL, drvname -> valid
 * 	4 	: bus -> NULL, drvname -> invalid
 * 	5 	: bus -> NULL, drvname -> NULL
 */
int test_sysfs_get_bus_driver(int flag)
{
	struct sysfs_bus *bus = NULL;
	struct sysfs_driver *drv = NULL;
	char *drvname = NULL;
	char *bus_name = NULL;

	switch(flag) {
	case 0:
		bus_name = val_drv_bus_name;
		bus = sysfs_open_bus(bus_name);
		if (bus == NULL) {
			dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__);
			return 0;
		}
		drvname = val_drv_name;
		break;
	case 1:
		bus_name = val_drv_bus_name;
		bus = sysfs_open_bus(bus_name);
		if (bus == NULL) {
			dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__);
			return 0;
		}
		drvname = inval_name;
		break;
	case 2:
		bus_name = val_drv_bus_name;
		bus = sysfs_open_bus(bus_name);
		if (bus == NULL) {
			dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__);
			return 0;
		}
		drvname = NULL;
		break;
	case 3:
		bus = NULL;
		drvname = val_drv_name;
		break;
	case 4:
		bus = NULL;
		drvname = inval_name;
		break;
	case 5:
		bus = NULL;
		drvname = NULL;
		break;
	default:
		return -1;
	}
	drv = sysfs_get_bus_driver(bus, drvname);

	switch (flag) {
	case 0:
		if (drv == NULL) {
			if (errno == 0)
				dbg_print("%s: Driver %s not on bus %s\n",
						__FUNCTION__, drvname, bus_name);
			else
				dbg_print("%s: FAILED with flag = %d errno = %d\n",
						__FUNCTION__, flag, errno);
		} else {
			dbg_print("%s: SUCCEEDED with flag = %d\n\n",
					__FUNCTION__, flag);
			show_driver(drv);
			dbg_print("\n");
		}
		break;
	case 1:
	case 2:
	case 3:
	case 4:
	case 5:
		if (drv != NULL)
			dbg_print("%s: FAILED with flag = %d errno = %d\n",
						__FUNCTION__, flag, errno);
		else
			dbg_print("%s: SUCCEEDED with flag = %d\n",
					__FUNCTION__, flag);
		break;
	default:
		break;
	}

	if (bus != NULL)
		sysfs_close_bus(bus);

	return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
   struct timespec ts,ts1;
   int i,ncpu;
   int idcpu;
   unsigned long freq[8];
   XEvent event;
   char gov[20];
   char drv[20],*ptr,*endptr;
   char prg[LN_PATH];
   ts.tv_sec=0;
   ts.tv_nsec=DELAY;
   prg[0]=0;
   idcpu=0;

   for(i=0;i<MAX_CPU;i++)
     freq[i]=0;
   if(argc >1)
     {
	for (i=1; i<=argc; i++)
	  {
	     if (!strcmp(argv[i], "-v"))
	       {
		  printf(WMCPUFREQ_VERSION);
		  exit(0);
	       }
	     if (!strcmp(argv[i], "-exe"))
	       {
		  if(strlen(argv[i+1]) < LN_PATH )
		    strcpy(prg,argv[i+1]);
		  break;
	       }
	     if (!strcmp(argv[i], "-cpuid"))
	       {
		 if(strlen(argv[i+1]) < LN_PATH )
		   idcpu=strtol(argv[i+1],&endptr,0);
		 printf("cpuid= %d \n",idcpu);
		 break;
	       }
	     printf("only -v, -exe, -cpuid supported \n");
	     exit(0);
	  }
     }

   /* basic checks */
   if ( idcpu < 0 )
     {
       printf("cpuid < 0 \n");
       exit(-1);
     }

   /* get driver name (guess all cpu have the same driver) */
   ptr=cpufreq_get_driver(cpu);
   if(!ptr)
     {
	printf("no driver found \n");
	exit(-1);
     }
   strcpy(drv,ptr);
   cpufreq_put_driver(ptr);


   /* get number of cpu (0=cpu0, 1=cpu1 ...) */

   ncpu=-1;

   for(i=0;i<MAX_CPU;i++)
     {
       if( cpufreq_cpu_exists(idcpu+i) ==0)
	 {
	   printf("cpuid %d found\n",idcpu+i);
	   ncpu=i;
	 }
     }

   switch ( ncpu ) {
   case -1:
     printf("no cpuid found \n");
     exit(-1);
   case 0:
     wm_xpm=wmcpufreq_master_xpm_1;
     wm_bits=wmcpufreq_mask_bits_1;
     break;
   case 1:
     wm_xpm=wmcpufreq_master_xpm_2;
     wm_bits=wmcpufreq_mask_bits_2;
     break;
   case 2:
     wm_xpm=wmcpufreq_master_3;
     wm_bits=wmcpufreq_mask_3_bits;
     break;
   case 3:
     wm_xpm=wmcpufreq_master_3;
     wm_bits=wmcpufreq_mask_3_bits;
     break;
   default:
     printf("no yet implemented: cpuid %d \n",ncpu);
     exit(-1);
     break;
   }

   /* guess every cpu has the same limits */
   if(cpufreq_get_hardware_limits(cpu, &f_min, &f_max))
     {
	printf("can't determine hardware limits \n");
	exit(-1);
     }
   openXwindow(argc,argv,
	       wm_xpm,
	       (char*)wm_bits,
	       wmcpufreq_mask_width,
               wmcpufreq_mask_height);
   while(1)
     {
	/* Process any pending X events */
	while(XPending(display))
	  {
	     XNextEvent(display, &event);
	     switch(event.type)
	       {
		case Expose:
		  RedrawWindow();
		  break;
		case ButtonPress:
		  if(strlen(prg))
		    execCommand(prg);
		  break;
		case ButtonRelease:
		  break;
	       }
	  }
	RedrawWindow();
	/* get info */
	for(i=0;i<=ncpu;i++)
	  freq[i]=cpufreq_get_freq_kernel(i+idcpu);
	policy=cpufreq_get_policy(cpu);
	strcpy(gov,policy->governor);
	max=policy->max;
	min=policy->min;
	cpufreq_put_policy(policy);
	/* show info */
	show_mhz(freq,ncpu);
	if (ncpu==0)
	  show_driver(drv);
	show_governor(gov);
	/* delay */
	nanosleep(&ts,&ts1);
     }
}