Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  *  Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
0004  */
0005 
0006 #ifndef __SOUND_AC97_CODEC2_H
0007 #define __SOUND_AC97_CODEC2_H
0008 
0009 #include <linux/device.h>
0010 
0011 #define AC97_ID(vendor_id1, vendor_id2) \
0012     ((((vendor_id1) & 0xffff) << 16) | ((vendor_id2) & 0xffff))
0013 #define AC97_DRIVER_ID(vendor_id1, vendor_id2, mask_id1, mask_id2, _data) \
0014     { .id = (((vendor_id1) & 0xffff) << 16) | ((vendor_id2) & 0xffff), \
0015       .mask = (((mask_id1) & 0xffff) << 16) | ((mask_id2) & 0xffff), \
0016       .data = (_data) }
0017 
0018 struct ac97_controller;
0019 struct clk;
0020 
0021 /**
0022  * struct ac97_id - matches a codec device and driver on an ac97 bus
0023  * @id: The significant bits if the codec vendor ID1 and ID2
0024  * @mask: Bitmask specifying which bits of the id field are significant when
0025  *    matching. A driver binds to a device when :
0026  *        ((vendorID1 << 8 | vendorID2) & (mask_id1 << 8 | mask_id2)) == id.
0027  * @data: Private data used by the driver.
0028  */
0029 struct ac97_id {
0030     unsigned int        id;
0031     unsigned int        mask;
0032     void            *data;
0033 };
0034 
0035 /**
0036  * ac97_codec_device - a ac97 codec
0037  * @dev: the core device
0038  * @vendor_id: the vendor_id of the codec, as sensed on the AC-link
0039  * @num: the codec number, 0 is primary, 1 is first slave, etc ...
0040  * @clk: the clock BIT_CLK provided by the codec
0041  * @ac97_ctrl: ac97 digital controller on the same AC-link
0042  *
0043  * This is the device instantiated for each codec living on a AC-link. There are
0044  * normally 0 to 4 codec devices per AC-link, and all of them are controlled by
0045  * an AC97 digital controller.
0046  */
0047 struct ac97_codec_device {
0048     struct device       dev;
0049     unsigned int        vendor_id;
0050     unsigned int        num;
0051     struct clk      *clk;
0052     struct ac97_controller  *ac97_ctrl;
0053 };
0054 
0055 /**
0056  * ac97_codec_driver - a ac97 codec driver
0057  * @driver: the device driver structure
0058  * @probe: the function called when a ac97_codec_device is matched
0059  * @remove: the function called when the device is unbound/removed
0060  * @shutdown: shutdown function (might be NULL)
0061  * @id_table: ac97 vendor_id match table, { } member terminated
0062  */
0063 struct ac97_codec_driver {
0064     struct device_driver    driver;
0065     int         (*probe)(struct ac97_codec_device *);
0066     int         (*remove)(struct ac97_codec_device *);
0067     void            (*shutdown)(struct ac97_codec_device *);
0068     const struct ac97_id    *id_table;
0069 };
0070 
0071 static inline struct ac97_codec_device *to_ac97_device(struct device *d)
0072 {
0073     return container_of(d, struct ac97_codec_device, dev);
0074 }
0075 
0076 static inline struct ac97_codec_driver *to_ac97_driver(struct device_driver *d)
0077 {
0078     return container_of(d, struct ac97_codec_driver, driver);
0079 }
0080 
0081 #if IS_ENABLED(CONFIG_AC97_BUS_NEW)
0082 int snd_ac97_codec_driver_register(struct ac97_codec_driver *drv);
0083 void snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv);
0084 #else
0085 static inline int
0086 snd_ac97_codec_driver_register(struct ac97_codec_driver *drv)
0087 {
0088     return 0;
0089 }
0090 static inline void
0091 snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv)
0092 {
0093 }
0094 #endif
0095 
0096 
0097 static inline struct device *
0098 ac97_codec_dev2dev(struct ac97_codec_device *adev)
0099 {
0100     return &adev->dev;
0101 }
0102 
0103 static inline void *ac97_get_drvdata(struct ac97_codec_device *adev)
0104 {
0105     return dev_get_drvdata(ac97_codec_dev2dev(adev));
0106 }
0107 
0108 static inline void ac97_set_drvdata(struct ac97_codec_device *adev,
0109                     void *data)
0110 {
0111     dev_set_drvdata(ac97_codec_dev2dev(adev), data);
0112 }
0113 
0114 void *snd_ac97_codec_get_platdata(const struct ac97_codec_device *adev);
0115 
0116 #endif