ALSA: hdac: add extended device driver registration
authorVinod Koul <vinod.koul@intel.com>
Fri, 21 Aug 2015 10:17:42 +0000 (15:47 +0530)
committerTakashi Iwai <tiwai@suse.de>
Fri, 21 Aug 2015 10:34:02 +0000 (12:34 +0200)
This adds new extended driver objects and API for registering the
extended devices.

Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/hdaudio_ext.h
sound/hda/ext/hdac_ext_bus.c

index 0641d00e2a949aa53495de12bf4cb88945790a55..55e2fc36177feedea9968a19b51c004815071377 100644 (file)
@@ -173,5 +173,20 @@ struct hdac_ext_device {
 
 #define to_ehdac_device(dev) (container_of((dev), \
                                 struct hdac_ext_device, hdac))
+/*
+ * HD-audio codec base driver
+ */
+struct hdac_ext_driver {
+       struct hdac_driver hdac;
+
+       int     (*probe)(struct hdac_ext_device *dev);
+       int     (*remove)(struct hdac_ext_device *dev);
+       void    (*shutdown)(struct hdac_ext_device *dev);
+};
+
+int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
+void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
+
+#define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
 
 #endif /* __SOUND_HDAUDIO_EXT_H */
index 94fb9878f5cb4420f30ade44cfa6feeed1ce5110..8544e4fb1cd3be3cf231ddf998ce38b686a25034 100644 (file)
@@ -196,3 +196,69 @@ void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus)
        }
 }
 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_remove);
+#define dev_to_hdac(dev) (container_of((dev), \
+                       struct hdac_device, dev))
+
+static inline struct hdac_ext_driver *get_edrv(struct device *dev)
+{
+       struct hdac_driver *hdrv = drv_to_hdac_driver(dev->driver);
+       struct hdac_ext_driver *edrv = to_ehdac_driver(hdrv);
+
+       return edrv;
+}
+
+static inline struct hdac_ext_device *get_edev(struct device *dev)
+{
+       struct hdac_device *hdev = dev_to_hdac_dev(dev);
+       struct hdac_ext_device *edev = to_ehdac_device(hdev);
+
+       return edev;
+}
+
+static int hda_ext_drv_probe(struct device *dev)
+{
+       return (get_edrv(dev))->probe(get_edev(dev));
+}
+
+static int hdac_ext_drv_remove(struct device *dev)
+{
+       return (get_edrv(dev))->remove(get_edev(dev));
+}
+
+static void hdac_ext_drv_shutdown(struct device *dev)
+{
+       return (get_edrv(dev))->shutdown(get_edev(dev));
+}
+
+/**
+ * snd_hda_ext_driver_register - register a driver for ext hda devices
+ *
+ * @drv: ext hda driver structure
+ */
+int snd_hda_ext_driver_register(struct hdac_ext_driver *drv)
+{
+       drv->hdac.type = HDA_DEV_ASOC;
+       drv->hdac.driver.bus = &snd_hda_bus_type;
+       /* we use default match */
+
+       if (drv->probe)
+               drv->hdac.driver.probe = hda_ext_drv_probe;
+       if (drv->remove)
+               drv->hdac.driver.remove = hdac_ext_drv_remove;
+       if (drv->shutdown)
+               drv->hdac.driver.shutdown = hdac_ext_drv_shutdown;
+
+       return driver_register(&drv->hdac.driver);
+}
+EXPORT_SYMBOL_GPL(snd_hda_ext_driver_register);
+
+/**
+ * snd_hda_ext_driver_unregister - unregister a driver for ext hda devices
+ *
+ * @drv: ext hda driver structure
+ */
+void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv)
+{
+       driver_unregister(&drv->hdac.driver);
+}
+EXPORT_SYMBOL_GPL(snd_hda_ext_driver_unregister);