Skip to contentSkip to conversation

ASoC: add RT286 CODEC driver

PATCH Superseded [email protected] 4 participants 20 messages Apr 14, 2014 – Jun 4, 2014

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 ASoC: add RT286 CODEC driver

From: Bard Liao <[email protected]>

ALC286 is a dual mode codec, which can run as HD-A or I2S mode. It is controlled by HD-A verb commands via I2C protocol.
The following is the I/O difference between ALC286 and general I2S codecs.
1. A HD-A verb command contains three parts, NID, VID, and PID. And an I2S command contains only two parts: address and data.
2. Not only the register address is written, but the read command also includes the entire write command.
3. rt286 uses different registers for read and write the same bits.

As a result, regmap is difficult to be used on ALC286.
We don't request a standard I/O by snd_soc_codec_set_cache_io anymore. Now we have specific write and read functions for ALC286's I/O. A verb command contains three part: NID, VID, and PID.
We combine NID and VID as reg address, and PID as reg value. And do corresponding change in rt286_hw_read to get the data properly.

---
The jack detection function is done by Lewandowski Gustaw. So I add Gustaw's Signed-off-by line in this patch

The difference between this version and previous version is listed below.
* Implement specific read/write functions rather than use regmap.
* Use dapm widget to control power bit instead of setting it in _event
* Add device ID check

Verb command use two bit to set power state(D0, D1, D2, D3). But dapm widget use only one bit to set power up/down. So we use dapm widget to switch each node between D0 and D1 power state. And will set audio group to D3 when bias level = STANDBY.

---
 include/sound/rt286.h     |   19 +
 sound/soc/codecs/Kconfig  |    4 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/rt286.c  | 1054 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt286.h  |  186 ++++++++
 5 files changed, 1265 insertions(+)
 create mode 100644 include/sound/rt286.h
 create mode 100644 sound/soc/codecs/rt286.c
 create mode 100644 sound/soc/codecs/rt286.h
include/sound/rt286.h new file +19 -0
new file mode 100644
index 0000000..eb773d1
@@ -0,0 +1,19 @@
+/*
+ * linux/sound/rt286.h -- Platform data for RT286
+ *
+ * Copyright 2013 Realtek Microelectronics
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_SND_RT286_H
+#define __LINUX_SND_RT286_H
+
+struct rt286_platform_data {
+	bool cbj_en; /*combo jack enable*/
+	bool gpio2_en; /*GPIO2 enable*/
+};
+
+#endif
sound/soc/codecs/Kconfig +4 -0
index f0e8401..5818391 100644
@@ -69,6 +69,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_PCM3008
 	select SND_SOC_PCM512x_I2C if I2C
 	select SND_SOC_PCM512x_SPI if SPI_MASTER
+	select SND_SOC_RT286 if I2C
 	select SND_SOC_RT5631 if I2C
 	select SND_SOC_RT5640 if I2C
 	select SND_SOC_SGTL5000 if I2C
@@ -390,6 +391,9 @@ config SND_SOC_PCM512x_SPI
 	select SND_SOC_PCM512x
 	select REGMAP_SPI
 
+config SND_SOC_RT286
+	tristate
+
 config SND_SOC_RT5631
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 3c4d275..5ef8adc 100644
@@ -58,6 +58,7 @@ snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-pcm512x-objs := pcm512x.o
 snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
 snd-soc-pcm512x-spi-objs := pcm512x-spi.o
+snd-soc-rt286-objs := rt286.o
 snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
 snd-soc-sgtl5000-objs := sgtl5000.o
@@ -209,6 +210,7 @@ obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_PCM512x)	+= snd-soc-pcm512x.o
 obj-$(CONFIG_SND_SOC_PCM512x_I2C)	+= snd-soc-pcm512x-i2c.o
 obj-$(CONFIG_SND_SOC_PCM512x_SPI)	+= snd-soc-pcm512x-spi.o
+obj-$(CONFIG_SND_SOC_RT286)	+= snd-soc-rt286.o
 obj-$(CONFIG_SND_SOC_RT5631)	+= snd-soc-rt5631.o
 obj-$(CONFIG_SND_SOC_RT5640)	+= snd-soc-rt5640.o
 obj-$(CONFIG_SND_SOC_SGTL5000)  += snd-soc-sgtl5000.o
sound/soc/codecs/rt286.c new file +1054 -0

1,054 lines not on this page · raw message

sound/soc/codecs/rt286.h new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
1.8.1.1.439.g50a6b54
maintainer
#1 lore raw

sound/soc/codecs/rt286.c line 108

Quoted 7 lines · On Mon, Apr 14, 2014 at 01:59:30PM +0800, [email protected] wrote:
sound/soc/codecs/rt286.c new file +6 -0
+static unsigned int rt286_hw_read(struct snd_soc_codec *codec,
+						unsigned int reg)
+{
 
+static int rt286_hw_write(struct snd_soc_codec *codec,
+				unsigned int reg, unsigned int value)
+{

To repeat what's been said before if you are implementing register I/O you *MUST* use regmap to do this. What's not been clear is if this device has a control interface that looks enough like a register map to be implemented like one but since we're just guessing based on a combination of the code and the HDA spec it's not entirely clear.

author
#2 lore raw
Quoted 14 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, April 15, 2014 8:04 PM
To: Bard Liao
Cc: [email protected]; [email protected]; [email protected]; Flove; Oder Chiou; Gustaw Lewandowski
Subject: Re: [PATCH v6] ASoC: add RT286 CODEC driver

Quoted 3 lines · On Mon, Apr 14, 2014 at 01:59:30PM +0800, [email protected] wrote:
sound/soc/codecs/rt286.c new file +3 -0
+static unsigned int rt286_hw_read(struct snd_soc_codec *codec,
+						unsigned int reg)
+{
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static int rt286_hw_write(struct snd_soc_codec *codec,
+				unsigned int reg, unsigned int value) {

To repeat what's been said before if you are implementing register I/O you *MUST* use regmap to do this. What's not been clear is if this device has a control interface that looks enough like a register map to be implemented like one but since we're just guessing based on a combination of the code and the HDA spec it's not entirely clear.

I am a little bit confused about it. I thought you told me not using regmap. Actually, I don't know how to use dapm without implementing register I/O. Can I just convert rt286_hw_read/write to regmap?

Quoted 2 lines

------Please consider the environment before printing this e-mail.

maintainer
#3 lore raw
Quoted 8 lines · Bard Liao
Quoted 4 lines

*MUST* use regmap to do this. What's not been clear is if this device has a control interface that looks enough like a register map to be implemented like one but since we're just guessing based on a combination of the code and the HDA spec it's not entirely clear.

I am a little bit confused about it. I thought you told me not using regmap. Actually, I don't know how to use dapm without implementing register I/O. Can I just convert rt286_hw_read/write to regmap?

As far as we've been able to tell thus far (based on inferring stuff from the HDA spec) you shouldn't be doing register I/O at all, the device doesn't really have things that look enough like registers.

You can implement non-register DAPM widgets - look at the virtual controls in the core, or things using SND_SOC_NOPM.

author
#4 lore raw
Quoted 19 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Thursday, April 17, 2014 5:12 AM
To: Bard Liao
Cc: [email protected]; [email protected]; [email protected]; Flove; Oder Chiou; Gustaw Lewandowski
Subject: Re: [PATCH v6] ASoC: add RT286 CODEC driver

Quoted 8 lines · Bard Liao
Quoted 4 lines

*MUST* use regmap to do this. What's not been clear is if this device has a control interface that looks enough like a register map to be implemented like one but since we're just guessing based on a combination of the code and the HDA spec it's not entirely clear.

I am a little bit confused about it. I thought you told me not using regmap. Actually, I don't know how to use dapm without implementing register I/O. Can I just convert rt286_hw_read/write to regmap?

Quoted 6 lines

As far as we've been able to tell thus far (based on inferring stuff from the HDA spec) you shouldn't be doing register I/O at all, the device doesn't really have things that look enough like registers.

You can implement non-register DAPM widgets - look at the virtual controls in the core, or things using SND_SOC_NOPM.

It means dapm widget will not control the codec directly, right? I.e. Everything will be done by _event?
For simplest the driver, can I not define .dapm_widgets and .dapm_routes? All controls will be done in .controls.

Quoted 2 lines

------Please consider the environment before printing this e-mail.

maintainer
#5 lore raw
Quoted 5 lines · Bard Liao
Quoted 2 lines

You can implement non-register DAPM widgets - look at the virtual controls in the core, or things using SND_SOC_NOPM.

It means dapm widget will not control the codec directly, right? I.e. Everything will be done by _event?

The framework won't do anything directly, yes.

Quoted 2 lines

For simplest the driver, can I not define .dapm_widgets and .dapm_routes? All controls will be done in .controls.

It is mandatory to have at least some DAPM support, not having DAPM was such a constant source of bugs that we stopped supporting it.

author
#6 lore raw
Quoted 10 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, April 18, 2014 6:37 PM
To: Bard Liao
Cc: [email protected]; [email protected]; [email protected]; Flove; Oder Chiou; Gustaw Lewandowski
Subject: Re: [PATCH v6] ASoC: add RT286 CODEC driver

On Thu, Apr 17, 2014 at 05:39:08AM +0000, Bard Liao wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

You can implement non-register DAPM widgets - look at the virtual controls in the core, or things using SND_SOC_NOPM.

It means dapm widget will not control the codec directly, right? I.e. Everything will be done by _event?

The framework won't do anything directly, yes.

I have a question about the virtual controls.

Virtual controls assume there is no related register related to the controls, so codec doesn't need to set anything when the control's value is changed in general cases. But rt286 need to do something when the control's value is changed especially mux settings.

I have no idea when should codec driver set the corresponding registers of the controls. The SND_SOC_DAPM_POST_REG event seems not works in virtual controls. Also, I didn't find a suitable API to get a virtual control's value. Look like dapm_kcontrol_get_value can do that, but dapm_kcontrol_get_value is not exported.

I am trying to define a .put function in snd_kcontrol_new, so that I can set corresponding registers to the control. But I don't know how to update dapm path's connect status. I don't know if snd_soc_dapm_mux_update_power can do that.

Do you have any suggestion for setting corresponding registers of a virtual control?

Thanks.

Quoted 2 lines

------Please consider the environment before printing this e-mail.

maintainer
#7 lore raw
Quoted 2 lines · Bard Liao
Quoted 2 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]

As I'm fairly sure has been requested before please fix your mailer to word wrap within paragraphs, it is very hard to read your mails since the lines are longer than 80 columns.

Quoted 4 lines

Virtual controls assume there is no related register related to the controls, so codec doesn't need to set anything when the control's value is changed in general cases. But rt286 need to do something when the control's value is changed especially mux settings.

...

Quoted 2 lines

Do you have any suggestion for setting corresponding registers of a virtual control?

Please extend the APIs for virtual controls if you find they are missing things you need, they've not been widely used in this sort of context - I think this is the first substantial device anyone has tried to merge without a register map so it's likely there are gaps.

#8 lore raw
Quoted 15 lines · Mark Brown
Quoted 2 lines · Bard Liao
Quoted 2 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]

As I'm fairly sure has been requested before please fix your mailer to word wrap within paragraphs, it is very hard to read your mails since the lines are longer than 80 columns.

Quoted 4 lines

Virtual controls assume there is no related register related to the controls, so codec doesn't need to set anything when the control's value is changed in general cases. But rt286 need to do something when the control's value is changed especially mux settings.

...

Quoted 7 lines
Quoted 2 lines

Do you have any suggestion for setting corresponding registers of a virtual control?

Please extend the APIs for virtual controls if you find they are missing things you need, they've not been widely used in this sort of context - I think this is the first substantial device anyone has tried to merge without a register map so it's likely there are gaps.

I don't think virtual controls are the right approach here. Virtual controls are for controls where the state is completely in software, but here the state is still in hardware. It's just that there is no uniform hardware map. But there is still some structure. So you'd have controls with custom put and get handlers and for DAPM widgets use the event handler.

But I still think that the best and easiest solution is to have custom regmap read/write function that do the translation of logical registers to physical read/write operations.

- Lars

maintainer
#9 lore raw
Quoted 5 lines · Lars-Peter Clausen

I don't think virtual controls are the right approach here. Virtual controls are for controls where the state is completely in software, but here the state is still in hardware. It's just that there is no uniform hardware map. But there is still some structure. So you'd have controls with custom put and get handlers and for DAPM widgets use the event handler.

What you just described is what I'd consider a virtual control - I don't consider the fact that the put callbacks end up writing to the hardware particularly substantial, as far as the framework is concerned some driver specific thing goes off and does something but it could be setting a variable just as well as writing to hardware.

Quoted 3 lines

But I still think that the best and easiest solution is to have custom regmap read/write function that do the translation of logical registers to physical read/write operations.

That's the first time this idea has been mentioned that I recall. I have to say I'm really not keen on pushing non-physical registers through regmap, all the drivers that have done that previously have ended up causing problems though if the registers were *all* fake then there would be less issue (most of the issues have been due to having extra registers that don't really exist). It does still feel like it's a layering problem though.

#10 lore raw
Quoted 8 lines · Mark Brown
Quoted 5 lines · Lars-Peter Clausen

I don't think virtual controls are the right approach here. Virtual controls are for controls where the state is completely in software, but here the state is still in hardware. It's just that there is no uniform hardware map. But there is still some structure. So you'd have controls with custom put and get handlers and for DAPM widgets use the event handler.

Quoted 5 lines

What you just described is what I'd consider a virtual control - I don't consider the fact that the put callbacks end up writing to the hardware particularly substantial, as far as the framework is concerned some driver specific thing goes off and does something but it could be setting a variable just as well as writing to hardware.

Ok, but we have controls that have virtual in their name, so I think it should be made clear that you are not talking about those.

Quoted 5 lines
Quoted 4 lines

But I still think that the best and easiest solution is to have custom regmap read/write function that do the translation of logical registers to physical read/write operations.

Quoted 7 lines

That's the first time this idea has been mentioned that I recall. I have to say I'm really not keen on pushing non-physical registers through regmap, all the drivers that have done that previously have ended up causing problems though if the registers were *all* fake then there would be less issue (most of the issues have been due to having extra registers that don't really exist). It does still feel like it's a layering problem though.

I think the drivers you are thinking of are those which had physical register which were backed by hardware and virtual register which were backed by software. For the later we introduced the virtual controls, so that such hacks are no longer necessary in driver. But in the case of the RT286 all the register all still backed by hardware except that the way they are accessed is not very uniform (different types of registers use a different message format, there is a asymmetry between reading and writing the same data). In a sense this is similar to devices which have registers with different sizes, we also support these with custom regmap callbacks.

- Lars

maintainer
#11 lore raw
Quoted 10 lines · Lars-Peter Clausen
Quoted 5 lines · Mark Brown

What you just described is what I'd consider a virtual control - I don't consider the fact that the put callbacks end up writing to the hardware particularly substantial, as far as the framework is concerned some driver specific thing goes off and does something but it could be setting a variable just as well as writing to hardware.

Ok, but we have controls that have virtual in their name, so I think it should be made clear that you are not talking about those.

My first thought would be to extend those so we have callbacks when required, to be honest I'd forgotten they weren't there already.

Quoted 7 lines

I think the drivers you are thinking of are those which had physical register which were backed by hardware and virtual register which were backed by software. For the later we introduced the virtual controls, so that such hacks are no longer necessary in driver. But in the case of the RT286 all the register all still backed by hardware except that the way they are accessed is not very uniform (different types of registers use a different message format, there is a asymmetry between reading and writing

Right, to me that's not actually a register map at all since it's missing so many of the assumptions that back up register maps.

Quoted 2 lines

the same data). In a sense this is similar to devices which have registers with different sizes, we also support these with custom regmap callbacks.

But those are only breaking that one assumption so they fit into the idea of a register map much more readily - it's really only the physical I/O code that actually notices anything, all the cache and other operations can carry on uninterrupted.

#12 lore raw
Quoted 9 lines · Mark Brown
Quoted 7 lines · Lars-Peter Clausen
Quoted 5 lines · Mark Brown

What you just described is what I'd consider a virtual control - I don't consider the fact that the put callbacks end up writing to the hardware particularly substantial, as far as the framework is concerned some driver specific thing goes off and does something but it could be setting a variable just as well as writing to hardware.

Quoted 5 lines
Quoted 2 lines

Ok, but we have controls that have virtual in their name, so I think it should be made clear that you are not talking about those.

My first thought would be to extend those so we have callbacks when required, to be honest I'd forgotten they weren't there already.

But that's just the normal ..._EXT() controls with custom put/get handlers.

Having virtual controls with custom put/get handlers makes no sense, since the virtual controls already have put/get function in which virtual-ness of the control is implemented.

Quoted 9 lines
Quoted 8 lines

I think the drivers you are thinking of are those which had physical register which were backed by hardware and virtual register which were backed by software. For the later we introduced the virtual controls, so that such hacks are no longer necessary in driver. But in the case of the RT286 all the register all still backed by hardware except that the way they are accessed is not very uniform (different types of registers use a different message format, there is a asymmetry between reading and writing

Quoted 3 lines

Right, to me that's not actually a register map at all since it's missing so many of the assumptions that back up register maps.

Well there is a register map, there is just no linear address space. It's more hierarchical, but you can still map that hierarchical addressing scheme to a linear one. I think what best describes HDA is object oriented RPC. You have your objects, called nodes, each node has a unique identifier, called the node ID (NID). Then you have functions, called verbs, each verb has a specific ID. A node can support a certain set of verbs. And each verb has a verb specific payload, which is the functions signature. Most of the verbs are some kind of read/write register functions.

E.g. you have the set amplifier gain verb, whose payload looks like:

bool output, bool input, bool left, bool right, int index, bool mute, int gain

output, input, left, right, index select for which amplifier to set the parameters and mute and gain are the parameters that should be set.

So the address of the register in which the amplifier gain is stored is the NID + It's a amplifier you want to access + whether it's a input or output amplifier + whether it's left or right amplifier + amplifier index. You can map that onto a linear address space and in the regmap read/write callback do the mapping to the appropriate verb payload layout.

Quoted 8 lines
Quoted 2 lines

the same data). In a sense this is similar to devices which have registers with different sizes, we also support these with custom regmap callbacks.

But those are only breaking that one assumption so they fit into the idea of a register map much more readily - it's really only the physical I/O code that actually notices anything, all the cache and other operations can carry on uninterrupted.

This is one of the reasons why I suggest using regmap. You probably still want caching, you probably still be able to sync the register cache, etc. If you don't use regmap you'd have to implement this on your own.

maintainer
#13 lore raw
Quoted 6 lines · Lars-Peter Clausen
Quoted 2 lines · Mark Brown

My first thought would be to extend those so we have callbacks when required, to be honest I'd forgotten they weren't there already.

But that's just the normal ..._EXT() controls with custom put/get handlers.

Hrm, yes. That's the issue - I have never really differentiated between virtual and external enums here, the external controls are (as far as DAPM is concerned) also virtual. To be honest I'd forgotten that there were external controls in DAPM, there's only one user.

Quoted 6 lines
Quoted 2 lines

Right, to me that's not actually a register map at all since it's missing so many of the assumptions that back up register maps.

Well there is a register map, there is just no linear address space. It's more hierarchical, but you can still map that hierarchical addressing scheme to a linear one. I think what best describes HDA is object oriented RPC. You

The non-linear addressing isn't the worst bit, I'd say the worst bit is that the read and write formats for the data aren't consistent with each other. That's really the fundamental assumption here.

Quoted 5 lines

have your objects, called nodes, each node has a unique identifier, called the node ID (NID). Then you have functions, called verbs, each verb has a specific ID. A node can support a certain set of verbs. And each verb has a verb specific payload, which is the functions signature. Most of the verbs are some kind of read/write register functions.

Yes, it makes sense as RPC (and hence as external controls as I have been suggesting).

Quoted 5 lines

So the address of the register in which the amplifier gain is stored is the NID + It's a amplifier you want to access + whether it's a input or output amplifier + whether it's left or right amplifier + amplifier index. You can map that onto a linear address space and in the regmap read/write callback do the mapping to the appropriate verb payload layout.

It is of course always going to be possible to map any set of settings onto a register map, the question is if it accomplishes anything to do so. Once you're talking about having a mapping function like that which understands the contents of all the registers it sounds like the contortions to fit into a register map are more effort than is being saved and doing nothing for comprehensibility.

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

the same data). In a sense this is similar to devices which have registers with different sizes, we also support these with custom regmap callbacks.

But those are only breaking that one assumption so they fit into the idea of a register map much more readily - it's really only the physical I/O code that actually notices anything, all the cache and other operations can carry on uninterrupted.

This is one of the reasons why I suggest using regmap. You probably still want caching, you probably still be able to sync the register cache, etc. If you don't use regmap you'd have to implement this on your own.

So how does HDA handle this? We can obviously keep recording settings in the same way as we do for virtual enums, writing them out shouldn't
be so hard. The cache code isn't going to buy us much if we have to
write things out control by control anyway, it essentially just boils down to a fancy list walk.

If you really want to reuse regmap having a write only regmap internal to the driver (not presented to ASoC) which just remembers the last value written to every NID/VID combination might work and at least avoids the ugly bits with trying to convince ASoC there are registers since you don't need to worry about reading the data back and can just pretend that read values match written values since we never look at them except to write them back out.

#14 lore raw

On 05/08/2014 10:00 AM, Mark Brown wrote:
[...]

Quoted 6 lines
Quoted 5 lines

So the address of the register in which the amplifier gain is stored is the NID + It's a amplifier you want to access + whether it's a input or output amplifier + whether it's left or right amplifier + amplifier index. You can map that onto a linear address space and in the regmap read/write callback do the mapping to the appropriate verb payload layout.

Quoted 6 lines

It is of course always going to be possible to map any set of settings onto a register map, the question is if it accomplishes anything to do so. Once you're talking about having a mapping function like that which understands the contents of all the registers it sounds like the contortions to fit into a register map are more effort than is being saved and doing nothing for comprehensibility.

There is still structure, the mapping function does not have to understand each register it only has to understand each verb and the driver uses maybe 6-7 different verbs, so it is not that bad. The code would basically look like this:

write_reg(addr, val)

{
	verb = EXTRACT_VERB(addr);
	nid = EXTRACT_NID(addr);
	pid = EXTRACT_PID(addr);

	switch (verb) {
	case VERB1:
		return write_verb1(nid, pid, val):
	case VERB2:
		return write_verb2(nid, pid, val):
	....
	}
}

Where pid is verb specific additional addressing information that is used in the verbs payload.

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

the same data). In a sense this is similar to devices which have registers with different sizes, we also support these with custom regmap callbacks.

Quoted 8 lines
Quoted 4 lines

But those are only breaking that one assumption so they fit into the idea of a register map much more readily - it's really only the physical I/O code that actually notices anything, all the cache and other operations can carry on uninterrupted.

This is one of the reasons why I suggest using regmap. You probably still want caching, you probably still be able to sync the register cache, etc. If you don't use regmap you'd have to implement this on your own.

Quoted 5 lines

So how does HDA handle this? We can obviously keep recording settings in the same way as we do for virtual enums, writing them out shouldn't
be so hard. The cache code isn't going to buy us much if we have to
write things out control by control anyway, it essentially just boils down to a fancy list walk.

It's not just the DAPM stuff, but also the normal controls, for which we do not have per control caching.

Quoted 8 lines

If you really want to reuse regmap having a write only regmap internal to the driver (not presented to ASoC) which just remembers the last value written to every NID/VID combination might work and at least avoids the ugly bits with trying to convince ASoC there are registers since you don't need to worry about reading the data back and can just pretend that read values match written values since we never look at them except to write them back out.

Yes kind of.

#15 lore raw

2014-05-08 16:57 GMT+08:00 Lars-Peter Clausen <[email protected]>:

Quoted 1 line · Mark Brown

[...]

Just for confirm.

Quoted 1 line

From the mail thread, what I need to to are:

1. Don't present register map to alsa, use virtrul controls instead. I may need to extend the APIs to accomplish the goal.
2. I can (or should?) use regmap internal to codec driver to set the codec physically.
Did I miss anything?

Thanks.

Quoted 2 lines

------Please consider the environment before printing this e-mail.

#16 lore raw
Quoted 9 lines · Bard Liao

2014-05-08 16:57 GMT+08:00 Lars-Peter Clausen <[email protected]>:

Quoted 1 line · Mark Brown

[...]

Just for confirm.
From the mail thread, what I need to to are:
1. Don't present register map to alsa, use virtrul controls instead. I may need to extend the APIs to accomplish the goal.

To avoid confusion we should not call them virtual controls, but controls with custom put/get handlers.

Quoted 3 lines

2. I can (or should?) use regmap internal to codec driver to set the codec physically.
Did I miss anything?

There are essentially two options.

a) Have custom put/get handlers for different types of verbs. This means you'll re-implement things like caching.

b) Have a mapping that maps the hierarchical HDA register addressing structure onto a linear address map and use regmap.

- Lars

maintainer
#17 lore raw
In reply to Lars-Peter Clausen
Quoted 20 lines · Lars-Peter Clausen

There is still structure, the mapping function does not have to understand each register it only has to understand each verb and the driver uses maybe 6-7 different verbs, so it is not that bad. The code would basically look like this:

write_reg(addr, val)

{
	verb = EXTRACT_VERB(addr);
	nid = EXTRACT_NID(addr);
	pid = EXTRACT_PID(addr);

	switch (verb) {
	case VERB1:
		return write_verb1(nid, pid, val):
	case VERB2:
		return write_verb2(nid, pid, val):
	....
	}
}
Quoted 2 lines

Where pid is verb specific additional addressing information that is used in the verbs payload.

Yeah, it's not exactly a model of niceness though. It's looking an awful lot like we didn't manage to abstract things properly and setting off alarm bells as a result.

Quoted 8 lines
Quoted 5 lines

So how does HDA handle this? We can obviously keep recording settings in the same way as we do for virtual enums, writing them out shouldn't
be so hard. The cache code isn't going to buy us much if we have to
write things out control by control anyway, it essentially just boils down to a fancy list walk.

It's not just the DAPM stuff, but also the normal controls, for which we do not have per control caching.

That seems like a simple matter of programming to resolve.

Quoted 9 lines
Quoted 7 lines

If you really want to reuse regmap having a write only regmap internal to the driver (not presented to ASoC) which just remembers the last value written to every NID/VID combination might work and at least avoids the ugly bits with trying to convince ASoC there are registers since you don't need to worry about reading the data back and can just pretend that read values match written values since we never look at them except to write them back out.

Yes kind of.

Kind of? It solves the cache sync case and if it's write only then we won't need to go to the register map for reads anyway (outside of interrupt handling and so on).

author
#18 lore raw
Quoted 17 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, May 13, 2014 4:29 AM
To: Lars-Peter Clausen
Cc: Bard Liao; [email protected]; [email protected]; Flove; Oder Chiou; Gustaw Lewandowski
Subject: Re: [PATCH v6] ASoC: add RT286 CODEC driver

Quoted 7 lines
Quoted 7 lines

If you really want to reuse regmap having a write only regmap internal to the driver (not presented to ASoC) which just remembers the last value written to every NID/VID combination might work and at least avoids the ugly bits with trying to convince ASoC there are registers since you don't need to worry about reading the data back and can just pretend that read values match written values since we never look at them except to write them back out.

Quoted 4 lines
Quoted 1 line

Yes kind of.

Kind of? It solves the cache sync case and if it's write only then we won't need to go to the register map for reads anyway (outside of interrupt handling and so on).

Does "write only regmap" mean read (almost) everything from cache? If so, we don't need to care about the asymmetry read/write issue. In that case, can we use regmap for mixer/mux controls just like other drivers do?

Quoted 2 lines

------Please consider the environment before printing this e-mail.

maintainer
#19 lore raw
Quoted 6 lines · Bard Liao
Quoted 2 lines

Kind of? It solves the cache sync case and if it's write only then we won't need to go to the register map for reads anyway (outside of interrupt handling and so on).

Does "write only regmap" mean read (almost) everything from cache? If so, we don't need to care about the asymmetry read/write issue. In that case, can we use regmap for mixer/mux controls just like other drivers do?

Yes, exactly - most things should be able to get away with only using the cache I'd expect.