Blame SOURCES/0007-detect-sound-devices.patch

33b0a4
From 1cc52cac74ea735faae92dc963d10292608d7a4d Mon Sep 17 00:00:00 2001
33b0a4
From: Lyonel Vincent <lyonel@ezix.org>
33b0a4
Date: Thu, 2 Apr 2020 13:39:42 +0200
33b0a4
Subject: [PATCH 07/17] detect sound devices
33b0a4
33b0a4
---
33b0a4
 src/core/main.cc  |  4 ++++
33b0a4
 src/core/sound.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++++
33b0a4
 src/core/sound.h  |  8 +++++++
33b0a4
 src/core/sysfs.cc |  5 +++++
33b0a4
 src/core/sysfs.h  |  1 +
33b0a4
 5 files changed, 71 insertions(+)
33b0a4
 create mode 100644 src/core/sound.cc
33b0a4
 create mode 100644 src/core/sound.h
33b0a4
33b0a4
diff --git a/src/core/main.cc b/src/core/main.cc
33b0a4
index ad0e586ef549..e35258c56141 100644
33b0a4
--- a/src/core/main.cc
33b0a4
+++ b/src/core/main.cc
33b0a4
@@ -46,6 +46,7 @@
33b0a4
 #include "nvme.h"
33b0a4
 #include "mmc.h"
33b0a4
 #include "input.h"
33b0a4
+#include "sound.h"
33b0a4
 #include "smp.h"
33b0a4
 #include "abi.h"
33b0a4
 #include "s390.h"
33b0a4
@@ -141,6 +142,9 @@ bool scan_system(hwNode & system)
33b0a4
     status("MMC");
33b0a4
     if (enabled("mmc"))
33b0a4
       scan_mmc(computer);
33b0a4
+    status("sound");
33b0a4
+    if (enabled("sound"))
33b0a4
+      scan_sound(computer);
33b0a4
     status("input");
33b0a4
     if (enabled("input"))
33b0a4
       scan_input(computer);
33b0a4
diff --git a/src/core/sound.cc b/src/core/sound.cc
33b0a4
new file mode 100644
33b0a4
index 000000000000..05edf2352267
33b0a4
--- /dev/null
33b0a4
+++ b/src/core/sound.cc
33b0a4
@@ -0,0 +1,53 @@
33b0a4
+#include "version.h"
33b0a4
+#include "hw.h"
33b0a4
+#include "sysfs.h"
33b0a4
+#include "osutils.h"
33b0a4
+#include "sound.h"
33b0a4
+#include "heuristics.h"
33b0a4
+
33b0a4
+#include <vector>
33b0a4
+#include <iostream>
33b0a4
+
33b0a4
+__ID("@(#) $Id$");
33b0a4
+
33b0a4
+using namespace std;
33b0a4
+
33b0a4
+bool scan_sound(hwNode & n)
33b0a4
+{
33b0a4
+  vector < sysfs::entry > entries = sysfs::entries_by_class("sound");
33b0a4
+
33b0a4
+  if (entries.empty())
33b0a4
+    return false;
33b0a4
+
33b0a4
+  for (vector < sysfs::entry >::iterator it = entries.begin();
33b0a4
+      it != entries.end(); ++it)
33b0a4
+  {
33b0a4
+    const sysfs::entry & e = *it;
33b0a4
+    string id = e.string_attr("id");
33b0a4
+    if(id!="")
33b0a4
+    {
33b0a4
+      hwNode *device = n.findChildByBusInfo(e.leaf().businfo());
33b0a4
+      if(!device)
33b0a4
+        device = n.addChild(hwNode("sound", hw::multimedia));
33b0a4
+      device->claim();
33b0a4
+      if(device->getDescription() == "") device->setDescription(id);
33b0a4
+      //device->setPhysId(e.hex_attr("number"));
33b0a4
+      //device->setBusInfo("sound@"+e.string_attr("number"));
33b0a4
+      device->setLogicalName("snd/"+e.name());
33b0a4
+      if(device->getProduct() == "") device->setProduct(e.string_attr("name"));
33b0a4
+      device->setModalias(e.modalias());
33b0a4
+
33b0a4
+      vector < sysfs::entry > events = e.devices();
33b0a4
+      for(vector < sysfs::entry >::iterator i = events.begin(); i != events.end(); ++i)
33b0a4
+      {
33b0a4
+        const sysfs::entry & d = *i;
33b0a4
+	if(d.subsystem() == "sound")
33b0a4
+	{
33b0a4
+          device->setLogicalName("snd/"+d.name());
33b0a4
+	}
33b0a4
+      }
33b0a4
+    }
33b0a4
+  }
33b0a4
+
33b0a4
+  return true;
33b0a4
+}
33b0a4
diff --git a/src/core/sound.h b/src/core/sound.h
33b0a4
new file mode 100644
33b0a4
index 000000000000..c2caf04687bf
33b0a4
--- /dev/null
33b0a4
+++ b/src/core/sound.h
33b0a4
@@ -0,0 +1,8 @@
33b0a4
+#ifndef _SOUND_H_
33b0a4
+#define _SOUND_H_
33b0a4
+
33b0a4
+#include "hw.h"
33b0a4
+
33b0a4
+bool scan_sound(hwNode &);
33b0a4
+
33b0a4
+#endif
33b0a4
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
33b0a4
index 32d65642f157..ee8b1da06c78 100644
33b0a4
--- a/src/core/sysfs.cc
33b0a4
+++ b/src/core/sysfs.cc
33b0a4
@@ -343,6 +343,11 @@ string entry::classname() const
33b0a4
   return basename(dirname(This->devpath).c_str());
33b0a4
 }
33b0a4
 
33b0a4
+string entry::subsystem() const
33b0a4
+{
33b0a4
+  return basename(realpath(This->devpath+"/subsystem").c_str());
33b0a4
+}
33b0a4
+
33b0a4
 bool entry::isvirtual() const
33b0a4
 {
33b0a4
   return string(basename(dirname(dirname(This->devpath)).c_str())) == "virtual";
33b0a4
diff --git a/src/core/sysfs.h b/src/core/sysfs.h
33b0a4
index 9cc1b2b0a500..c25430b834df 100644
33b0a4
--- a/src/core/sysfs.h
33b0a4
+++ b/src/core/sysfs.h
33b0a4
@@ -26,6 +26,7 @@ namespace sysfs
33b0a4
       bool hassubdir(const string &) const;
33b0a4
       string name() const;
33b0a4
       string classname() const;
33b0a4
+      string subsystem() const;
33b0a4
       bool isvirtual() const;
33b0a4
       string businfo() const;
33b0a4
       string driver() const;
33b0a4
-- 
33b0a4
2.17.1
33b0a4