From: Ashish Chavan <ashish.chavan@kpitcummins.com>
To: alsa-devel <alsa-devel@alsa-project.org>
Subject: How to handle special SPI read/write for ASoC codec driver?
Date: Thu, 25 Aug 2011 16:33:36 +0530 [thread overview]
Message-ID: <1314270216.16158.82.camel@matrix> (raw)
Hi,
I am working on updating ASoC codec driver for Dialog's DA7210 codec
(sound/soc/codec/da7210.c). I am planning to add SPI support and have a
query.
DA7210 codec has total 136, 8 bit registers (0x88). It supports 8 bit
address and 8 bit data format for SPI. One out of eight address bits is
used to indicate read/write operation, so effectively there are only
seven bits to represent address. So, directly we can only address 128 (0
to 127) registers.
In order to make other upper registers (128 to 136) addressable, DA7210
provides a special PAGE1 register addressed at (0x00 / 0x80). This PAGE1
register basically acts as an offset to normal registers addresses. If
PAGE1 register's value is "0x0" then, register address "0" actually maps
to 0th register. But if page register's value is "0x80", then register
address "0" actually maps to 128th register, register "2" maps to 129th
reg, and so on.
While adding support for SPI, I need to add this logic of setting
correct page while reading and writing. AFAIK, the proper place to add
this extra logic is read/write functions on codec. i.e. something
similar to,
@@ -208,6 +208,38 @@ static int da7210_write(struct snd_soc_codec *codec, u32 reg, u32 value)
BUG_ON(codec->driver->volatile_register);
+#if defined(CONFIG_SPI_MASTER)
+ /*
+ * spi_page member of private data stores current status of page
+ * register. 0 => page 0 selected, 1 => page 1 selected
+ */
+ struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
+ if(reg >= 80){
+ /* We are writing register in page 1 */
+ if(!da7210->spi_page){
+ /* Need to set page register first */
+ data[0] = 0x00;
+ data[1] = 0x80; /* need to set seventh bit */
+ if (2 != codec->hw_write(codec->control_data, data, 2))
+ return -EIO;
+ cache[0] = 0x80; /* Update cache */
+ da7210->spi_page = 1; /* Update local status */
+ }
+
+ }else {
+ /* We are writing register in page 0 */
+ if(da7210->spi_page){
+ /* Need to reset page register first */
+ data[0] = 0x80;
+ data[1] = 0x00; /* need to reset seventh bit */
+ if (2 != codec->hw_write(codec->control_data, data, 2))
+ return -EIO;
+ cache[80] = 0x00; /* Update cache */
+ da7210->spi_page = 0; /* Update local status */
+ }
+ }
+#endif
+
data[0] = reg & 0xff;
data[1] = value & 0xff;
Any comments on this code?
Is there any better place to put this extra logic? Any way to accommodate this in to generic soc-io functions?
Thanks,
-- Ashish
next reply other threads:[~2011-08-25 10:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-25 11:03 Ashish Chavan [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-08-25 11:09 How to handle special SPI read/write for ASoC codec driver? Ashish Chavan
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=1314270216.16158.82.camel@matrix \
--to=ashish.chavan@kpitcummins.com \
--cc=alsa-devel@alsa-project.org \
/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;
as well as URLs for NNTP newsgroup(s).