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

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