2 * hda_i915.c - routines for Haswell HDA controller power well support
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/component.h>
23 #include <drm/i915_component.h>
24 #include <sound/core.h>
26 #include "hda_intel.h"
28 /* Intel HSW/BDW display HDA controller Extended Mode registers.
29 * EM4 (M value) and EM5 (N Value) are used to convert CDClk (Core Display
30 * Clock) to 24MHz BCLK: BCLK = CDCLK * M / N
31 * The values will be lost when the display power well is disabled.
33 #define AZX_REG_EM4 0x100c
34 #define AZX_REG_EM5 0x1010
36 int hda_display_power(struct hda_intel *hda, bool enable)
38 struct i915_audio_component *acomp = &hda->audio_component;
43 dev_dbg(&hda->chip.pci->dev, "display power %s\n",
44 enable ? "enable" : "disable");
46 acomp->ops->get_power(acomp->dev);
48 acomp->ops->put_power(acomp->dev);
53 void haswell_set_bclk(struct hda_intel *hda)
56 unsigned int bclk_m, bclk_n;
57 struct i915_audio_component *acomp = &hda->audio_component;
62 cdclk_freq = acomp->ops->get_cdclk_freq(acomp->dev);
70 default: /* default CDCLK 450MHz */
86 azx_writew(&hda->chip, EM4, bclk_m);
87 azx_writew(&hda->chip, EM5, bclk_n);
90 static int hda_component_master_bind(struct device *dev)
92 struct snd_card *card = dev_get_drvdata(dev);
93 struct azx *chip = card->private_data;
94 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
95 struct i915_audio_component *acomp = &hda->audio_component;
98 ret = component_bind_all(dev, acomp);
102 if (WARN_ON(!(acomp->dev && acomp->ops && acomp->ops->get_power &&
103 acomp->ops->put_power && acomp->ops->get_cdclk_freq))) {
109 * Atm, we don't support dynamic unbinding initiated by the child
110 * component, so pin its containing module until we unbind.
112 if (!try_module_get(acomp->ops->owner)) {
120 component_unbind_all(dev, acomp);
125 static void hda_component_master_unbind(struct device *dev)
127 struct snd_card *card = dev_get_drvdata(dev);
128 struct azx *chip = card->private_data;
129 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
130 struct i915_audio_component *acomp = &hda->audio_component;
132 module_put(acomp->ops->owner);
133 component_unbind_all(dev, acomp);
134 WARN_ON(acomp->ops || acomp->dev);
137 static const struct component_master_ops hda_component_master_ops = {
138 .bind = hda_component_master_bind,
139 .unbind = hda_component_master_unbind,
142 static int hda_component_master_match(struct device *dev, void *data)
144 /* i915 is the only supported component */
145 return !strcmp(dev->driver->name, "i915");
148 int hda_i915_init(struct hda_intel *hda)
150 struct component_match *match = NULL;
151 struct device *dev = &hda->chip.pci->dev;
152 struct i915_audio_component *acomp = &hda->audio_component;
155 component_match_add(dev, &match, hda_component_master_match, hda);
156 ret = component_master_add_with_match(dev, &hda_component_master_ops,
162 * Atm, we don't support deferring the component binding, so make sure
163 * i915 is loaded and that the binding successfully completes.
165 request_module("i915");
172 dev_dbg(dev, "bound to i915 component master\n");
176 component_master_del(dev, &hda_component_master_ops);
178 dev_err(dev, "failed to add i915 component master (%d)\n", ret);
183 int hda_i915_exit(struct hda_intel *hda)
185 struct device *dev = &hda->chip.pci->dev;
187 component_master_del(dev, &hda_component_master_ops);