18e8e69d6SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2dfe66a18SJeeja KP /*
3dfe66a18SJeeja KP * hdac-ext-bus.c - HD-audio extended core bus functions.
4dfe66a18SJeeja KP *
5dfe66a18SJeeja KP * Copyright (C) 2014-2015 Intel Corp
6dfe66a18SJeeja KP * Author: Jeeja KP <jeeja.kp@intel.com>
7dfe66a18SJeeja KP * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8dfe66a18SJeeja KP *
9dfe66a18SJeeja KP * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10dfe66a18SJeeja KP */
11dfe66a18SJeeja KP
12dfe66a18SJeeja KP #include <linux/module.h>
13dfe66a18SJeeja KP #include <linux/slab.h>
1442f2bb1cSVinod Koul #include <linux/io.h>
15dfe66a18SJeeja KP #include <sound/hdaudio_ext.h>
16dfe66a18SJeeja KP
17dfe66a18SJeeja KP MODULE_DESCRIPTION("HDA extended core");
18dfe66a18SJeeja KP MODULE_LICENSE("GPL v2");
19dfe66a18SJeeja KP
20dfe66a18SJeeja KP /**
21dfe66a18SJeeja KP * snd_hdac_ext_bus_init - initialize a HD-audio extended bus
22*6e57188fSKeyon Jie * @bus: the pointer to HDAC bus object
23dfe66a18SJeeja KP * @dev: device pointer
24dfe66a18SJeeja KP * @ops: bus verb operators
25*6e57188fSKeyon Jie * @ext_ops: operators used for ASoC HDA codec drivers
26dfe66a18SJeeja KP *
27dfe66a18SJeeja KP * Returns 0 if successful, or a negative error code.
28dfe66a18SJeeja KP */
snd_hdac_ext_bus_init(struct hdac_bus * bus,struct device * dev,const struct hdac_bus_ops * ops,const struct hdac_ext_bus_ops * ext_ops)2976f56faeSRakesh Ughreja int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
30dfe66a18SJeeja KP const struct hdac_bus_ops *ops,
31cb04ba33SRakesh Ughreja const struct hdac_ext_bus_ops *ext_ops)
32dfe66a18SJeeja KP {
33dfe66a18SJeeja KP int ret;
34dfe66a18SJeeja KP
3519abfefdSTakashi Iwai ret = snd_hdac_bus_init(bus, dev, ops);
36dfe66a18SJeeja KP if (ret < 0)
37dfe66a18SJeeja KP return ret;
38dfe66a18SJeeja KP
39cb04ba33SRakesh Ughreja bus->ext_ops = ext_ops;
408a5b0177SAmadeusz Sławiński /* FIXME:
418a5b0177SAmadeusz Sławiński * Currently only one bus is supported, if there is device with more
428a5b0177SAmadeusz Sławiński * buses, bus->idx should be greater than 0, but there needs to be a
438a5b0177SAmadeusz Sławiński * reliable way to always assign same number.
448a5b0177SAmadeusz Sławiński */
458a5b0177SAmadeusz Sławiński bus->idx = 0;
4676f56faeSRakesh Ughreja bus->cmd_dma_state = true;
474446085dSVinod Koul
48dfe66a18SJeeja KP return 0;
49dfe66a18SJeeja KP }
50dfe66a18SJeeja KP EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_init);
51dfe66a18SJeeja KP
52dfe66a18SJeeja KP /**
53dfe66a18SJeeja KP * snd_hdac_ext_bus_exit - clean up a HD-audio extended bus
54*6e57188fSKeyon Jie * @bus: the pointer to HDAC bus object
55dfe66a18SJeeja KP */
snd_hdac_ext_bus_exit(struct hdac_bus * bus)5676f56faeSRakesh Ughreja void snd_hdac_ext_bus_exit(struct hdac_bus *bus)
57dfe66a18SJeeja KP {
5876f56faeSRakesh Ughreja snd_hdac_bus_exit(bus);
5976f56faeSRakesh Ughreja WARN_ON(!list_empty(&bus->hlink_list));
60dfe66a18SJeeja KP }
61dfe66a18SJeeja KP EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_exit);
62dfe66a18SJeeja KP
63ee2d51b3SVinod Koul /**
64ee2d51b3SVinod Koul * snd_hdac_ext_bus_device_remove - remove HD-audio extended codec base devices
65ee2d51b3SVinod Koul *
66*6e57188fSKeyon Jie * @bus: the pointer to HDAC bus object
67ee2d51b3SVinod Koul */
snd_hdac_ext_bus_device_remove(struct hdac_bus * bus)6876f56faeSRakesh Ughreja void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus)
69ee2d51b3SVinod Koul {
70ee2d51b3SVinod Koul struct hdac_device *codec, *__codec;
71ee2d51b3SVinod Koul /*
72ee2d51b3SVinod Koul * we need to remove all the codec devices objects created in the
73ee2d51b3SVinod Koul * snd_hdac_ext_bus_device_init
74ee2d51b3SVinod Koul */
7576f56faeSRakesh Ughreja list_for_each_entry_safe(codec, __codec, &bus->codec_list, list) {
76ee2d51b3SVinod Koul snd_hdac_device_unregister(codec);
77ee2d51b3SVinod Koul put_device(&codec->dev);
78ee2d51b3SVinod Koul }
79ee2d51b3SVinod Koul }
80ee2d51b3SVinod Koul EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_remove);
81d51783c1SVinod Koul #define dev_to_hdac(dev) (container_of((dev), \
82d51783c1SVinod Koul struct hdac_device, dev))
83d51783c1SVinod Koul
get_hdrv(struct device * dev)84e1df9317SRakesh Ughreja static inline struct hdac_driver *get_hdrv(struct device *dev)
85d51783c1SVinod Koul {
86d51783c1SVinod Koul struct hdac_driver *hdrv = drv_to_hdac_driver(dev->driver);
87e1df9317SRakesh Ughreja return hdrv;
88d51783c1SVinod Koul }
89d51783c1SVinod Koul
get_hdev(struct device * dev)903787a398SRakesh Ughreja static inline struct hdac_device *get_hdev(struct device *dev)
91d51783c1SVinod Koul {
92d51783c1SVinod Koul struct hdac_device *hdev = dev_to_hdac_dev(dev);
933787a398SRakesh Ughreja return hdev;
94d51783c1SVinod Koul }
95d51783c1SVinod Koul
hda_ext_drv_probe(struct device * dev)96d51783c1SVinod Koul static int hda_ext_drv_probe(struct device *dev)
97d51783c1SVinod Koul {
98e1df9317SRakesh Ughreja return (get_hdrv(dev))->probe(get_hdev(dev));
99d51783c1SVinod Koul }
100d51783c1SVinod Koul
hdac_ext_drv_remove(struct device * dev)101d51783c1SVinod Koul static int hdac_ext_drv_remove(struct device *dev)
102d51783c1SVinod Koul {
103e1df9317SRakesh Ughreja return (get_hdrv(dev))->remove(get_hdev(dev));
104d51783c1SVinod Koul }
105d51783c1SVinod Koul
hdac_ext_drv_shutdown(struct device * dev)106d51783c1SVinod Koul static void hdac_ext_drv_shutdown(struct device *dev)
107d51783c1SVinod Koul {
108e1df9317SRakesh Ughreja return (get_hdrv(dev))->shutdown(get_hdev(dev));
109d51783c1SVinod Koul }
110d51783c1SVinod Koul
111d51783c1SVinod Koul /**
112d51783c1SVinod Koul * snd_hda_ext_driver_register - register a driver for ext hda devices
113d51783c1SVinod Koul *
114d51783c1SVinod Koul * @drv: ext hda driver structure
115d51783c1SVinod Koul */
snd_hda_ext_driver_register(struct hdac_driver * drv)116e1df9317SRakesh Ughreja int snd_hda_ext_driver_register(struct hdac_driver *drv)
117d51783c1SVinod Koul {
118e1df9317SRakesh Ughreja drv->type = HDA_DEV_ASOC;
119e1df9317SRakesh Ughreja drv->driver.bus = &snd_hda_bus_type;
120d51783c1SVinod Koul /* we use default match */
121d51783c1SVinod Koul
122d51783c1SVinod Koul if (drv->probe)
123e1df9317SRakesh Ughreja drv->driver.probe = hda_ext_drv_probe;
124d51783c1SVinod Koul if (drv->remove)
125e1df9317SRakesh Ughreja drv->driver.remove = hdac_ext_drv_remove;
126d51783c1SVinod Koul if (drv->shutdown)
127e1df9317SRakesh Ughreja drv->driver.shutdown = hdac_ext_drv_shutdown;
128d51783c1SVinod Koul
129e1df9317SRakesh Ughreja return driver_register(&drv->driver);
130d51783c1SVinod Koul }
131d51783c1SVinod Koul EXPORT_SYMBOL_GPL(snd_hda_ext_driver_register);
132d51783c1SVinod Koul
133d51783c1SVinod Koul /**
134d51783c1SVinod Koul * snd_hda_ext_driver_unregister - unregister a driver for ext hda devices
135d51783c1SVinod Koul *
136d51783c1SVinod Koul * @drv: ext hda driver structure
137d51783c1SVinod Koul */
snd_hda_ext_driver_unregister(struct hdac_driver * drv)138e1df9317SRakesh Ughreja void snd_hda_ext_driver_unregister(struct hdac_driver *drv)
139d51783c1SVinod Koul {
140e1df9317SRakesh Ughreja driver_unregister(&drv->driver);
141d51783c1SVinod Koul }
142d51783c1SVinod Koul EXPORT_SYMBOL_GPL(snd_hda_ext_driver_unregister);
143