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>
23 #include <sound/hdaudio_ext.h>
25 MODULE_DESCRIPTION("HDA extended core");
26 MODULE_LICENSE("GPL v2");
28 static void hdac_ext_writel(u32 value
, u32 __iomem
*addr
)
33 static u32
hdac_ext_readl(u32 __iomem
*addr
)
38 static void hdac_ext_writew(u16 value
, u16 __iomem
*addr
)
43 static u16
hdac_ext_readw(u16 __iomem
*addr
)
48 static void hdac_ext_writeb(u8 value
, u8 __iomem
*addr
)
53 static u8
hdac_ext_readb(u8 __iomem
*addr
)
58 static int hdac_ext_dma_alloc_pages(struct hdac_bus
*bus
, int type
,
59 size_t size
, struct snd_dma_buffer
*buf
)
61 return snd_dma_alloc_pages(type
, bus
->dev
, size
, buf
);
64 static void hdac_ext_dma_free_pages(struct hdac_bus
*bus
, struct snd_dma_buffer
*buf
)
66 snd_dma_free_pages(buf
);
69 static const struct hdac_io_ops hdac_ext_default_io
= {
70 .reg_writel
= hdac_ext_writel
,
71 .reg_readl
= hdac_ext_readl
,
72 .reg_writew
= hdac_ext_writew
,
73 .reg_readw
= hdac_ext_readw
,
74 .reg_writeb
= hdac_ext_writeb
,
75 .reg_readb
= hdac_ext_readb
,
76 .dma_alloc_pages
= hdac_ext_dma_alloc_pages
,
77 .dma_free_pages
= hdac_ext_dma_free_pages
,
81 * snd_hdac_ext_bus_init - initialize a HD-audio extended bus
82 * @ebus: the pointer to extended bus object
83 * @dev: device pointer
84 * @ops: bus verb operators
85 * @io_ops: lowlevel I/O operators, can be NULL. If NULL core will use
88 * Returns 0 if successful, or a negative error code.
90 int snd_hdac_ext_bus_init(struct hdac_bus
*bus
, struct device
*dev
,
91 const struct hdac_bus_ops
*ops
,
92 const struct hdac_io_ops
*io_ops
,
93 const struct hdac_ext_bus_ops
*ext_ops
)
98 /* check if io ops are provided, if not load the defaults */
100 io_ops
= &hdac_ext_default_io
;
102 ret
= snd_hdac_bus_init(bus
, dev
, ops
, io_ops
);
106 bus
->ext_ops
= ext_ops
;
107 INIT_LIST_HEAD(&bus
->hlink_list
);
110 bus
->cmd_dma_state
= true;
114 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_init
);
117 * snd_hdac_ext_bus_exit - clean up a HD-audio extended bus
118 * @ebus: the pointer to extended bus object
120 void snd_hdac_ext_bus_exit(struct hdac_bus
*bus
)
122 snd_hdac_bus_exit(bus
);
123 WARN_ON(!list_empty(&bus
->hlink_list
));
125 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_exit
);
127 static void default_release(struct device
*dev
)
129 snd_hdac_ext_bus_device_exit(container_of(dev
, struct hdac_device
, dev
));
133 * snd_hdac_ext_bus_device_init - initialize the HDA extended codec base device
134 * @ebus: hdac extended bus to attach to
135 * @addr: codec address
137 * Returns zero for success or a negative error code.
139 int snd_hdac_ext_bus_device_init(struct hdac_bus
*bus
, int addr
,
140 struct hdac_device
*hdev
)
147 snprintf(name
, sizeof(name
), "ehdaudio%dD%d", bus
->idx
, addr
);
149 ret
= snd_hdac_device_init(hdev
, bus
, name
, addr
);
151 dev_err(bus
->dev
, "device init failed for hdac device\n");
154 hdev
->type
= HDA_DEV_ASOC
;
155 hdev
->dev
.release
= default_release
;
157 ret
= snd_hdac_device_register(hdev
);
159 dev_err(bus
->dev
, "failed to register hdac device\n");
160 snd_hdac_ext_bus_device_exit(hdev
);
166 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_init
);
169 * snd_hdac_ext_bus_device_exit - clean up a HD-audio extended codec base device
170 * @hdev: hdac device to clean up
172 void snd_hdac_ext_bus_device_exit(struct hdac_device
*hdev
)
174 snd_hdac_device_exit(hdev
);
177 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_exit
);
180 * snd_hdac_ext_bus_device_remove - remove HD-audio extended codec base devices
182 * @ebus: HD-audio extended bus
184 void snd_hdac_ext_bus_device_remove(struct hdac_bus
*bus
)
186 struct hdac_device
*codec
, *__codec
;
188 * we need to remove all the codec devices objects created in the
189 * snd_hdac_ext_bus_device_init
191 list_for_each_entry_safe(codec
, __codec
, &bus
->codec_list
, list
) {
192 snd_hdac_device_unregister(codec
);
193 put_device(&codec
->dev
);
196 EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_remove
);
197 #define dev_to_hdac(dev) (container_of((dev), \
198 struct hdac_device, dev))
200 static inline struct hdac_driver
*get_hdrv(struct device
*dev
)
202 struct hdac_driver
*hdrv
= drv_to_hdac_driver(dev
->driver
);
206 static inline struct hdac_device
*get_hdev(struct device
*dev
)
208 struct hdac_device
*hdev
= dev_to_hdac_dev(dev
);
212 static int hda_ext_drv_probe(struct device
*dev
)
214 return (get_hdrv(dev
))->probe(get_hdev(dev
));
217 static int hdac_ext_drv_remove(struct device
*dev
)
219 return (get_hdrv(dev
))->remove(get_hdev(dev
));
222 static void hdac_ext_drv_shutdown(struct device
*dev
)
224 return (get_hdrv(dev
))->shutdown(get_hdev(dev
));
228 * snd_hda_ext_driver_register - register a driver for ext hda devices
230 * @drv: ext hda driver structure
232 int snd_hda_ext_driver_register(struct hdac_driver
*drv
)
234 drv
->type
= HDA_DEV_ASOC
;
235 drv
->driver
.bus
= &snd_hda_bus_type
;
236 /* we use default match */
239 drv
->driver
.probe
= hda_ext_drv_probe
;
241 drv
->driver
.remove
= hdac_ext_drv_remove
;
243 drv
->driver
.shutdown
= hdac_ext_drv_shutdown
;
245 return driver_register(&drv
->driver
);
247 EXPORT_SYMBOL_GPL(snd_hda_ext_driver_register
);
250 * snd_hda_ext_driver_unregister - unregister a driver for ext hda devices
252 * @drv: ext hda driver structure
254 void snd_hda_ext_driver_unregister(struct hdac_driver
*drv
)
256 driver_unregister(&drv
->driver
);
258 EXPORT_SYMBOL_GPL(snd_hda_ext_driver_unregister
);