Re: [igt-dev] [PATCH i-g-t v2 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Quoting Tvrtko Ursulin (2018-07-23 13:46:49)
> @@ -130,36 +132,77 @@ static void strchomp(char *str)
>   */
>  void igt_pm_enable_audio_runtime_pm(void)
>  {
> +       char *path = NULL;
> +       struct dirent *de;
> +       DIR *dir;
>         int fd;
>  
>         /* Check if already enabled. */
>         if (__igt_pm_audio_runtime_power_save[0])
>                 return;
>  
> -       fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
> -       if (fd >= 0) {
> -               igt_assert(read(fd, __igt_pm_audio_runtime_power_save,
> -                               sizeof(__igt_pm_audio_runtime_power_save)) > 0);
> -               strchomp(__igt_pm_audio_runtime_power_save);
> -               igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
> -               igt_assert_eq(write(fd, "1\n", 2), 2);
> -               close(fd);
> -       }
> -       fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_RDWR);
> -       if (fd >= 0) {
> -               igt_assert(read(fd, __igt_pm_audio_runtime_control,
> -                               sizeof(__igt_pm_audio_runtime_control)) > 0);
> -               strchomp(__igt_pm_audio_runtime_control);
> -               igt_assert_eq(write(fd, "auto\n", 5), 5);
> -               close(fd);
> +       dir = opendir("/sys/bus/pci/drivers/snd_hda_intel");
> +       if (!dir)
> +               return;
> +
> +       while ((de = readdir(dir))) {
> +               const char *prefix = "/sys/bus/pci/devices/";
> +               const char *suffix = "/power/control";
> +               const char *match = "0000:00:";
> +
> +               if (strncmp(de->d_name, match, strlen(match)))
> +                       continue;
> +
> +               path = malloc(strlen(prefix) +
> +                             strlen(de->d_name) +
> +                             strlen(suffix) +
> +                             1);
> +               if (!path)
> +                       goto err;
> +
> +               strcpy(path, prefix);
> +               strcat(path, de->d_name);
> +               strcat(path, suffix);

if (asprintf(&path, "/sys/bus/pci/devices/%s/power/control", de->d_name) < 0)
	goto err;
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux