2 * hdac-ext-bus.c - HD-audio extended core bus functions.
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 #include <linux/module.h>
21 #include <linux/slab.h>
22 #include <sound/hdaudio_ext.h>
24 MODULE_DESCRIPTION("HDA extended core");
25 MODULE_LICENSE("GPL v2");
27 static void hdac_ext_writel(u32 value, u32 __iomem *addr)
32 static u32 hdac_ext_readl(u32 __iomem *addr)
37 static void hdac_ext_writew(u16 value, u16 __iomem *addr)
42 static u16 hdac_ext_readw(u16 __iomem *addr)
47 static void hdac_ext_writeb(u8 value, u8 __iomem *addr)
52 static u8 hdac_ext_readb(u8 __iomem *addr)
57 static int hdac_ext_dma_alloc_pages(struct hdac_bus *bus, int type,
58 size_t size, struct snd_dma_buffer *buf)
60 return snd_dma_alloc_pages(type, bus->dev, size, buf);
63 static void hdac_ext_dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
65 snd_dma_free_pages(buf);
68 static const struct hdac_io_ops hdac_ext_default_io = {
69 .reg_writel = hdac_ext_writel,
70 .reg_readl = hdac_ext_readl,
71 .reg_writew = hdac_ext_writew,
72 .reg_readw = hdac_ext_readw,
73 .reg_writeb = hdac_ext_writeb,
74 .reg_readb = hdac_ext_readb,
75 .dma_alloc_pages = hdac_ext_dma_alloc_pages,
76 .dma_free_pages = hdac_ext_dma_free_pages,
80 * snd_hdac_ext_bus_init - initialize a HD-audio extended bus
81 * @ebus: the pointer to extended bus object
82 * @dev: device pointer
83 * @ops: bus verb operators
84 * @io_ops: lowlevel I/O operators, can be NULL. If NULL core will use
87 * Returns 0 if successful, or a negative error code.
89 int snd_hdac_ext_bus_init(struct hdac_ext_bus *ebus, struct device *dev,
90 const struct hdac_bus_ops *ops,
91 const struct hdac_io_ops *io_ops)
96 /* check if io ops are provided, if not load the defaults */
98 io_ops = &hdac_ext_default_io;
100 ret = snd_hdac_bus_init(&ebus->bus, dev, ops, io_ops);
104 INIT_LIST_HEAD(&ebus->hlink_list);
109 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_init);
112 * snd_hdac_ext_bus_exit - clean up a HD-audio extended bus
113 * @ebus: the pointer to extended bus object
115 void snd_hdac_ext_bus_exit(struct hdac_ext_bus *ebus)
117 snd_hdac_bus_exit(&ebus->bus);
118 WARN_ON(!list_empty(&ebus->hlink_list));
120 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_exit);
122 static void default_release(struct device *dev)
124 snd_hdac_ext_bus_device_exit(container_of(dev, struct hdac_device, dev));
128 * snd_hdac_ext_device_init - initialize the HDA extended codec base device
129 * @ebus: hdac extended bus to attach to
130 * @addr: codec address
132 * Returns zero for success or a negative error code.
134 int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *ebus, int addr)
136 struct hdac_device *hdev = NULL;
137 struct hdac_bus *bus = ebus_to_hbus(ebus);
141 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
145 snprintf(name, sizeof(name), "ehdaudio%dD%d", ebus->idx, addr);
147 ret = snd_hdac_device_init(hdev, bus, name, addr);
149 dev_err(bus->dev, "device init failed for hdac device\n");
152 hdev->type = HDA_DEV_ASOC;
153 hdev->dev.release = default_release;
155 ret = snd_hdac_device_register(hdev);
157 dev_err(bus->dev, "failed to register hdac device\n");
158 snd_hdac_ext_bus_device_exit(hdev);
163 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_init);
166 * snd_hdac_ext_bus_device_exit - clean up a HD-audio extended codec base device
167 * @hdev: hdac device to clean up
169 void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev)
171 snd_hdac_device_exit(hdev);
174 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_exit);