^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/ac97/codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/ac97/controller.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/ac97/regs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "ac97_core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Protects ac97_controllers and each ac97_controller structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static DEFINE_MUTEX(ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static DEFINE_IDR(ac97_adapter_idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static LIST_HEAD(ac97_controllers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static struct bus_type ac97_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static inline struct ac97_controller*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) to_ac97_controller(struct device *ac97_adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return container_of(ac97_adapter, struct ac97_controller, adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int ac97_unbound_ctrl_write(struct ac97_controller *adrv, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned short reg, unsigned short val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int ac97_unbound_ctrl_read(struct ac97_controller *adrv, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned short reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static const struct ac97_controller_ops ac97_unbound_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .write = ac97_unbound_ctrl_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .read = ac97_unbound_ctrl_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static struct ac97_controller ac97_unbound_ctrl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .ops = &ac97_unbound_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static struct ac97_codec_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ac97_codec_find(struct ac97_controller *ac97_ctrl, unsigned int codec_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (codec_num >= AC97_BUS_MAX_CODECS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return ac97_ctrl->codecs[codec_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static struct device_node *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ac97_of_get_child_device(struct ac97_controller *ac97_ctrl, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned int vendor_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u32 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) char compat[] = "ac97,0000,0000";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) snprintf(compat, sizeof(compat), "ac97,%04x,%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) vendor_id >> 16, vendor_id & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) for_each_child_of_node(ac97_ctrl->parent->of_node, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if ((idx != of_property_read_u32(node, "reg", ®)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) !of_device_is_compatible(node, compat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static void ac97_codec_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct ac97_codec_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct ac97_controller *ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) adev = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ac97_ctrl = adev->ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ac97_ctrl->codecs[adev->num] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) of_node_put(dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) kfree(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int vendor_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ac97_codec_device *codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) codec = kzalloc(sizeof(*codec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (!codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ac97_ctrl->codecs[idx] = codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) codec->vendor_id = vendor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) codec->dev.release = ac97_codec_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) codec->dev.bus = &ac97_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) codec->dev.parent = &ac97_ctrl->adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) codec->num = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) codec->ac97_ctrl = ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) device_initialize(&codec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) dev_set_name(&codec->dev, "%s:%u", dev_name(ac97_ctrl->parent), idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) codec->dev.of_node = ac97_of_get_child_device(ac97_ctrl, idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) vendor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ret = device_add(&codec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) put_device(&codec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned int snd_ac97_bus_scan_one(struct ac97_controller *adrv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned int codec_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) unsigned short vid1, vid2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ret = adrv->ops->read(adrv, codec_num, AC97_VENDOR_ID1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) vid1 = (ret & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ret = adrv->ops->read(adrv, codec_num, AC97_VENDOR_ID2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) vid2 = (ret & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev_dbg(&adrv->adap, "%s(codec_num=%u): vendor_id=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) __func__, codec_num, AC97_ID(vid1, vid2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return AC97_ID(vid1, vid2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int ac97_bus_scan(struct ac97_controller *ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) unsigned int vendor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) for (i = 0; i < AC97_BUS_MAX_CODECS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (ac97_codec_find(ac97_ctrl, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (!(ac97_ctrl->slots_available & BIT(i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) vendor_id = snd_ac97_bus_scan_one(ac97_ctrl, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (!vendor_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ret = ac97_codec_add(ac97_ctrl, i, vendor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int ac97_bus_reset(struct ac97_controller *ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ac97_ctrl->ops->reset(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * snd_ac97_codec_driver_register - register an AC97 codec driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @dev: AC97 driver codec to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * Register an AC97 codec driver to the ac97 bus driver, aka. the AC97 digital
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * Returns 0 on success or error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int snd_ac97_codec_driver_register(struct ac97_codec_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) drv->driver.bus = &ac97_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return driver_register(&drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) EXPORT_SYMBOL_GPL(snd_ac97_codec_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * snd_ac97_codec_driver_unregister - unregister an AC97 codec driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * @dev: AC97 codec driver to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * Unregister a previously registered ac97 codec driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) void snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) driver_unregister(&drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) EXPORT_SYMBOL_GPL(snd_ac97_codec_driver_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * snd_ac97_codec_get_platdata - get platform_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * @adev: the ac97 codec device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * For legacy platforms, in order to have platform_data in codec drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * available, while ac97 device are auto-created upon probe, this retrieves the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * platdata which was setup on ac97 controller registration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * Returns the platform data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void *snd_ac97_codec_get_platdata(const struct ac97_codec_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct ac97_controller *ac97_ctrl = adev->ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return ac97_ctrl->codecs_pdata[adev->num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) EXPORT_SYMBOL_GPL(snd_ac97_codec_get_platdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void ac97_ctrl_codecs_unregister(struct ac97_controller *ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) for (i = 0; i < AC97_BUS_MAX_CODECS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (ac97_ctrl->codecs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ac97_ctrl->codecs[i]->ac97_ctrl = &ac97_unbound_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) device_unregister(&ac97_ctrl->codecs[i]->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static ssize_t cold_reset_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct ac97_controller *ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) mutex_lock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ac97_ctrl = to_ac97_controller(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ac97_ctrl->ops->reset(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) mutex_unlock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static DEVICE_ATTR_WO(cold_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static ssize_t warm_reset_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct ac97_controller *ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) mutex_lock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ac97_ctrl = to_ac97_controller(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ac97_ctrl->ops->warm_reset(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) mutex_unlock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static DEVICE_ATTR_WO(warm_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static struct attribute *ac97_controller_device_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) &dev_attr_cold_reset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) &dev_attr_warm_reset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static struct attribute_group ac97_adapter_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .name = "ac97_operations",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .attrs = ac97_controller_device_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static const struct attribute_group *ac97_adapter_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) &ac97_adapter_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void ac97_del_adapter(struct ac97_controller *ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) mutex_lock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ac97_ctrl_codecs_unregister(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) list_del(&ac97_ctrl->controllers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) mutex_unlock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) device_unregister(&ac97_ctrl->adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void ac97_adapter_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct ac97_controller *ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ac97_ctrl = to_ac97_controller(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) idr_remove(&ac97_adapter_idr, ac97_ctrl->nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) dev_dbg(&ac97_ctrl->adap, "adapter unregistered by %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) dev_name(ac97_ctrl->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static const struct device_type ac97_adapter_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .groups = ac97_adapter_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .release = ac97_adapter_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) mutex_lock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) ret = idr_alloc(&ac97_adapter_idr, ac97_ctrl, 0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ac97_ctrl->nr = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) dev_set_name(&ac97_ctrl->adap, "ac97-%d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ac97_ctrl->adap.type = &ac97_adapter_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ac97_ctrl->adap.parent = ac97_ctrl->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ret = device_register(&ac97_ctrl->adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) put_device(&ac97_ctrl->adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) list_add(&ac97_ctrl->controllers, &ac97_controllers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) mutex_unlock(&ac97_controllers_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev_dbg(&ac97_ctrl->adap, "adapter registered by %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) dev_name(ac97_ctrl->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * snd_ac97_controller_register - register an ac97 controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * @ops: the ac97 bus operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * @dev: the device providing the ac97 DC function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * @slots_available: mask of the ac97 codecs that can be scanned and probed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * bit0 => codec 0, bit1 => codec 1 ... bit 3 => codec 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * Register a digital controller which can control up to 4 ac97 codecs. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * the controller side of the AC97 AC-link, while the slave side are the codecs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * Returns a valid controller upon success, negative pointer value upon error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct ac97_controller *snd_ac97_controller_register(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) const struct ac97_controller_ops *ops, struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) unsigned short slots_available, void **codecs_pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct ac97_controller *ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ac97_ctrl = kzalloc(sizeof(*ac97_ctrl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) for (i = 0; i < AC97_BUS_MAX_CODECS && codecs_pdata; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ac97_ctrl->codecs_pdata[i] = codecs_pdata[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ac97_ctrl->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ac97_ctrl->slots_available = slots_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ac97_ctrl->parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ret = ac97_add_adapter(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ac97_bus_reset(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ac97_bus_scan(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return ac97_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) kfree(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) EXPORT_SYMBOL_GPL(snd_ac97_controller_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * snd_ac97_controller_unregister - unregister an ac97 controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * @ac97_ctrl: the device previously provided to ac97_controller_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) void snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ac97_del_adapter(ac97_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) EXPORT_SYMBOL_GPL(snd_ac97_controller_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int ac97_pm_runtime_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct ac97_codec_device *codec = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int ret = pm_generic_runtime_suspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (ret == 0 && dev->driver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (pm_runtime_is_irq_safe(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) clk_disable(codec->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) clk_disable_unprepare(codec->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static int ac97_pm_runtime_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct ac97_codec_device *codec = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (dev->driver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (pm_runtime_is_irq_safe(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ret = clk_enable(codec->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ret = clk_prepare_enable(codec->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return pm_generic_runtime_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static const struct dev_pm_ops ac97_pm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .suspend = pm_generic_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .resume = pm_generic_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .freeze = pm_generic_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .thaw = pm_generic_thaw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .poweroff = pm_generic_poweroff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .restore = pm_generic_restore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) SET_RUNTIME_PM_OPS(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) ac97_pm_runtime_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ac97_pm_runtime_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int ac97_get_enable_clk(struct ac97_codec_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) adev->clk = clk_get(&adev->dev, "ac97_clk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (IS_ERR(adev->clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return PTR_ERR(adev->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ret = clk_prepare_enable(adev->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) clk_put(adev->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static void ac97_put_disable_clk(struct ac97_codec_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) clk_disable_unprepare(adev->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) clk_put(adev->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static ssize_t vendor_id_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct ac97_codec_device *codec = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return sprintf(buf, "%08x", codec->vendor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) DEVICE_ATTR_RO(vendor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static struct attribute *ac97_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) &dev_attr_vendor_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ATTRIBUTE_GROUPS(ac97_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static int ac97_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct ac97_codec_device *adev = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct ac97_codec_driver *adrv = to_ac97_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) const struct ac97_id *id = adrv->id_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (adev->vendor_id == 0x0 || adev->vendor_id == 0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (ac97_ids_match(id[i].id, adev->vendor_id, id[i].mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) } while (id[i++].id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static int ac97_bus_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct ac97_codec_device *adev = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct ac97_codec_driver *adrv = to_ac97_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) ret = ac97_get_enable_clk(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) pm_runtime_get_noresume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) pm_runtime_set_active(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) ret = adrv->probe(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) pm_runtime_set_suspended(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) pm_runtime_put_noidle(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ac97_put_disable_clk(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static int ac97_bus_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct ac97_codec_device *adev = to_ac97_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct ac97_codec_driver *adrv = to_ac97_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) ret = pm_runtime_resume_and_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) ret = adrv->remove(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) pm_runtime_put_noidle(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) ac97_put_disable_clk(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static struct bus_type ac97_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) .name = "ac97bus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .dev_groups = ac97_dev_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .match = ac97_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) .pm = &ac97_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .probe = ac97_bus_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .remove = ac97_bus_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static int __init ac97_bus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return bus_register(&ac97_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) subsys_initcall(ac97_bus_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static void __exit ac97_bus_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) bus_unregister(&ac97_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) module_exit(ac97_bus_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");