spi: spi-fsl-qspi: Fix return value check of devm_ioremap() in probe
[linux/fpc-iii.git] / sound / hda / ext / hdac_ext_bus.c
blob73bfa71845f667a04b81daa40cfff09f46971c98
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * hdac-ext-bus.c - HD-audio extended core bus functions.
5 * Copyright (C) 2014-2015 Intel Corp
6 * Author: Jeeja KP <jeeja.kp@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/io.h>
15 #include <sound/hdaudio_ext.h>
17 MODULE_DESCRIPTION("HDA extended core");
18 MODULE_LICENSE("GPL v2");
20 /**
21 * snd_hdac_ext_bus_init - initialize a HD-audio extended bus
22 * @bus: the pointer to HDAC bus object
23 * @dev: device pointer
24 * @ops: bus verb operators
25 * @ext_ops: operators used for ASoC HDA codec drivers
27 * Returns 0 if successful, or a negative error code.
29 int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
30 const struct hdac_bus_ops *ops,
31 const struct hdac_ext_bus_ops *ext_ops)
33 int ret;
35 ret = snd_hdac_bus_init(bus, dev, ops);
36 if (ret < 0)
37 return ret;
39 bus->ext_ops = ext_ops;
40 /* FIXME:
41 * Currently only one bus is supported, if there is device with more
42 * buses, bus->idx should be greater than 0, but there needs to be a
43 * reliable way to always assign same number.
45 bus->idx = 0;
46 bus->cmd_dma_state = true;
48 return 0;
50 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_init);
52 /**
53 * snd_hdac_ext_bus_exit - clean up a HD-audio extended bus
54 * @bus: the pointer to HDAC bus object
56 void snd_hdac_ext_bus_exit(struct hdac_bus *bus)
58 snd_hdac_bus_exit(bus);
59 WARN_ON(!list_empty(&bus->hlink_list));
61 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_exit);
63 static void default_release(struct device *dev)
65 snd_hdac_ext_bus_device_exit(container_of(dev, struct hdac_device, dev));
68 /**
69 * snd_hdac_ext_bus_device_init - initialize the HDA extended codec base device
70 * @bus: hdac bus to attach to
71 * @addr: codec address
72 * @hdev: hdac device to init
74 * Returns zero for success or a negative error code.
76 int snd_hdac_ext_bus_device_init(struct hdac_bus *bus, int addr,
77 struct hdac_device *hdev)
79 char name[15];
80 int ret;
82 hdev->bus = bus;
84 snprintf(name, sizeof(name), "ehdaudio%dD%d", bus->idx, addr);
86 ret = snd_hdac_device_init(hdev, bus, name, addr);
87 if (ret < 0) {
88 dev_err(bus->dev, "device init failed for hdac device\n");
89 return ret;
91 hdev->type = HDA_DEV_ASOC;
92 hdev->dev.release = default_release;
94 ret = snd_hdac_device_register(hdev);
95 if (ret) {
96 dev_err(bus->dev, "failed to register hdac device\n");
97 snd_hdac_ext_bus_device_exit(hdev);
98 return ret;
101 return 0;
103 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_init);
106 * snd_hdac_ext_bus_device_exit - clean up a HD-audio extended codec base device
107 * @hdev: hdac device to clean up
109 void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev)
111 snd_hdac_device_exit(hdev);
113 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_exit);
116 * snd_hdac_ext_bus_device_remove - remove HD-audio extended codec base devices
118 * @bus: the pointer to HDAC bus object
120 void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus)
122 struct hdac_device *codec, *__codec;
124 * we need to remove all the codec devices objects created in the
125 * snd_hdac_ext_bus_device_init
127 list_for_each_entry_safe(codec, __codec, &bus->codec_list, list) {
128 snd_hdac_device_unregister(codec);
129 put_device(&codec->dev);
132 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_remove);
133 #define dev_to_hdac(dev) (container_of((dev), \
134 struct hdac_device, dev))
136 static inline struct hdac_driver *get_hdrv(struct device *dev)
138 struct hdac_driver *hdrv = drv_to_hdac_driver(dev->driver);
139 return hdrv;
142 static inline struct hdac_device *get_hdev(struct device *dev)
144 struct hdac_device *hdev = dev_to_hdac_dev(dev);
145 return hdev;
148 static int hda_ext_drv_probe(struct device *dev)
150 return (get_hdrv(dev))->probe(get_hdev(dev));
153 static int hdac_ext_drv_remove(struct device *dev)
155 return (get_hdrv(dev))->remove(get_hdev(dev));
158 static void hdac_ext_drv_shutdown(struct device *dev)
160 return (get_hdrv(dev))->shutdown(get_hdev(dev));
164 * snd_hda_ext_driver_register - register a driver for ext hda devices
166 * @drv: ext hda driver structure
168 int snd_hda_ext_driver_register(struct hdac_driver *drv)
170 drv->type = HDA_DEV_ASOC;
171 drv->driver.bus = &snd_hda_bus_type;
172 /* we use default match */
174 if (drv->probe)
175 drv->driver.probe = hda_ext_drv_probe;
176 if (drv->remove)
177 drv->driver.remove = hdac_ext_drv_remove;
178 if (drv->shutdown)
179 drv->driver.shutdown = hdac_ext_drv_shutdown;
181 return driver_register(&drv->driver);
183 EXPORT_SYMBOL_GPL(snd_hda_ext_driver_register);
186 * snd_hda_ext_driver_unregister - unregister a driver for ext hda devices
188 * @drv: ext hda driver structure
190 void snd_hda_ext_driver_unregister(struct hdac_driver *drv)
192 driver_unregister(&drv->driver);
194 EXPORT_SYMBOL_GPL(snd_hda_ext_driver_unregister);