From: Connor McAdams <conmanx360@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: conmanx360@gmail.com, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] ALSA: hda/ca0132 - Add 8051 exram helper functions.
Date: Tue, 8 Dec 2020 16:25:43 -0500 [thread overview]
Message-ID: <20201208212546.428392-4-conmanx360@gmail.com> (raw)
In-Reply-To: <20201208212546.428392-1-conmanx360@gmail.com>
Add functions for both reading and writing to the 8051's exram. Also,
add a little bit of documentation on how the addresses are segmented.
Signed-off-by: Connor McAdams <conmanx360@gmail.com>
---
sound/pci/hda/patch_ca0132.c | 138 ++++++++++++++++++++---------------
1 file changed, 80 insertions(+), 58 deletions(-)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 650a7e2bd311..cb725586d38b 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -1901,6 +1901,71 @@ static void chipio_8051_write_direct(struct hda_codec *codec,
snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, verb, addr);
}
+/*
+ * Writes to the 8051's exram, which has 16-bits of address space.
+ * Data at addresses 0x2000-0x7fff is mirrored to 0x8000-0xdfff.
+ * Data at 0x8000-0xdfff can also be used as program memory for the 8051 by
+ * setting the pmem bank selection SFR.
+ * 0xe000-0xffff is always mapped as program memory, with only 0xf000-0xffff
+ * being writable.
+ */
+static void chipio_8051_write_exram(struct hda_codec *codec,
+ unsigned int addr, unsigned int data, bool use_mutex)
+{
+ struct ca0132_spec *spec = codec->spec;
+ unsigned int tmp;
+
+ if (use_mutex)
+ mutex_lock(&spec->chipio_mutex);
+
+ /* Lower 8-bits. */
+ tmp = addr & 0xff;
+ snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
+ VENDOR_CHIPIO_8051_ADDRESS_LOW, tmp);
+
+ /* Upper 8-bits. */
+ tmp = (addr >> 8) & 0xff;
+ snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
+ VENDOR_CHIPIO_8051_ADDRESS_HIGH, tmp);
+
+ /* 8-bits of data. */
+ tmp = data & 0xff;
+ snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
+ VENDOR_CHIPIO_8051_DATA_WRITE, tmp);
+
+ if (use_mutex)
+ mutex_unlock(&spec->chipio_mutex);
+}
+
+/* Readback data from the 8051's exram. */
+static void chipio_8051_read_exram(struct hda_codec *codec,
+ unsigned int addr, unsigned int *data, bool use_mutex)
+{
+ struct ca0132_spec *spec = codec->spec;
+ unsigned int tmp;
+
+ if (use_mutex)
+ mutex_lock(&spec->chipio_mutex);
+
+ /* Lower 8-bits. */
+ tmp = addr & 0xff;
+ snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
+ VENDOR_CHIPIO_8051_ADDRESS_LOW, tmp);
+
+ /* Upper 8-bits. */
+ tmp = (addr >> 8) & 0xff;
+ snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
+ VENDOR_CHIPIO_8051_ADDRESS_HIGH, tmp);
+
+ /* 8-bits of data. */
+ *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
+ VENDOR_CHIPIO_8051_DATA_READ,
+ 0);
+
+ if (use_mutex)
+ mutex_unlock(&spec->chipio_mutex);
+}
+
/*
* Enable clocks.
*/
@@ -7422,18 +7487,10 @@ static void ca0132_init_analog_mic2(struct hda_codec *codec)
struct ca0132_spec *spec = codec->spec;
mutex_lock(&spec->chipio_mutex);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
+
+ chipio_8051_write_exram(codec, 0x1920, 0x00, false);
+ chipio_8051_write_exram(codec, 0x192d, 0x00, false);
+
mutex_unlock(&spec->chipio_mutex);
}
@@ -7504,18 +7561,11 @@ static void ca0132_refresh_widget_caps(struct hda_codec *codec)
static void chipio_remap_stream(struct hda_codec *codec,
const struct chipio_stream_remap_data *remap_data)
{
- unsigned int i, stream_offset, tmp;
+ unsigned int i, stream_offset;
/* Get the starting port for the stream to be remapped. */
- tmp = 0x1578 + remap_data->stream_id;
- for (i = 0; i < 2; i++) {
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW + i,
- ((tmp >> (i * 8)) & 0xff));
- }
-
- stream_offset = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_READ, 0);
+ chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
+ &stream_offset, false);
/*
* Check if the stream's port value is 0xff, because the 8051 may not
@@ -7526,9 +7576,8 @@ static void chipio_remap_stream(struct hda_codec *codec,
for (i = 0; i < 5; i++) {
msleep(25);
- stream_offset = snd_hda_codec_read(codec,
- WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_READ, 0);
+ chipio_8051_read_exram(codec, 0x1578 + remap_data->stream_id,
+ &stream_offset, false);
if (stream_offset != 0xff)
break;
@@ -7863,12 +7912,7 @@ static void ae5_post_dsp_param_setup(struct hda_codec *codec)
snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 0x724, 0x83);
chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
+ chipio_8051_write_exram(codec, 0xfa92, 0x22, true);
}
static void ae5_post_dsp_pll_setup(struct hda_codec *codec)
@@ -8134,12 +8178,7 @@ static void ae7_post_dsp_asi_setup(struct hda_codec *codec)
chipio_set_control_param(codec, CONTROL_PARAM_ASI, 0);
snd_hda_codec_write(codec, 0x17, 0, 0x794, 0x00);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x92);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0xfa);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x22);
+ chipio_8051_write_exram(codec, 0xfa92, 0x22, true);
ae7_post_dsp_pll_setup(codec);
ae7_post_dsp_asi_stream_setup(codec);
@@ -9133,12 +9172,7 @@ static void r3d_pre_dsp_setup(struct hda_codec *codec)
{
chipio_write(codec, 0x18b0a4, 0x000000c2);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
+ chipio_8051_write_exram(codec, 0x1c1e, 0x5b, true);
snd_hda_codec_write(codec, 0x11, 0,
AC_VERB_SET_PIN_WIDGET_CONTROL, 0x44);
@@ -9148,21 +9182,9 @@ static void r3di_pre_dsp_setup(struct hda_codec *codec)
{
chipio_write(codec, 0x18b0a4, 0x000000c2);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x1E);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x1C);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x5B);
-
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
- snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
- VENDOR_CHIPIO_8051_DATA_WRITE, 0x40);
+ chipio_8051_write_exram(codec, 0x1c1e, 0x5b, true);
+ chipio_8051_write_exram(codec, 0x1920, 0x00, true);
+ chipio_8051_write_exram(codec, 0x1921, 0x40, true);
snd_hda_codec_write(codec, 0x11, 0,
AC_VERB_SET_PIN_WIDGET_CONTROL, 0x04);
--
2.25.1
next prev parent reply other threads:[~2020-12-08 21:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-08 21:25 [PATCH 0/5] ALSA: hda/ca0132 - Fix no-audio issues and add documentation Connor McAdams
2020-12-08 21:25 ` [PATCH 1/5] ALSA: hda/ca0132 - Reset codec upon initialization Connor McAdams
2020-12-08 21:25 ` [PATCH 2/5] ALSA: hda/ca0132 - Add stream port remapping function Connor McAdams
2020-12-08 21:25 ` Connor McAdams [this message]
2020-12-09 8:33 ` [PATCH 3/5] ALSA: hda/ca0132 - Add 8051 exram helper functions Takashi Iwai
2020-12-08 21:25 ` [PATCH 4/5] ALSA: hda/ca0132 - Ensure DSP is properly setup post-firmware download Connor McAdams
2020-12-08 21:25 ` [PATCH 5/5] ALSA: hda/ca0132 - Remove now unnecessary DSP setup functions Connor McAdams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201208212546.428392-4-conmanx360@gmail.com \
--to=conmanx360@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®