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

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