Hi,
I just received a RPi3B+ and decided to have a go at fixing stuff in the
audio driver. The changes are mostly cosmetic. I also took the liberty
to update the TODO file.
The series was developed on top of linux-next and tested on a RPi2B and
RPi3B+. Sadly I don't have an HDMI monitor with sound so I only tested
the mini jack output.
Thanks,
Nicolas
v2: Removes the device tree related patches, updates TODO accordingly
and adds suggestions from Takashi.
----
Nicolas Saenz Julienne (7):
staging: bcm2835-audio: unify FOURCC command definitions
staging: bcm2835-audio: don't initialize memory twice
staging: bcm2835-audio: reorder variable declarations & remove trivial
comments
staging: bcm2835-audio: use anonymous union in struct vc_audio_msg
staging: bcm2835-audio: more generic probe function name
staging: bcm2835-audio: rename platform_driver structure
staging: bcm2835-audio: update TODO
.../staging/vc04_services/bcm2835-audio/TODO | 25 ++----------
.../vc04_services/bcm2835-audio/bcm2835-pcm.c | 10 +----
.../bcm2835-audio/bcm2835-vchiq.c | 39 ++++++++-----------
.../vc04_services/bcm2835-audio/bcm2835.c | 26 ++++++-------
.../bcm2835-audio/vc_vchi_audioserv_defs.h | 6 ++-
5 files changed, 38 insertions(+), 68 deletions(-)
--
2.19.1
The following tasks were completed or not the right solution:
1/2- Not the proper solution, we should register a platform device in
vchiq the same way it's done with bcm2835-camera as commented here:
https://lkml.org/lkml/2018/10/16/1131
2/3- Fixed by Takashi Iwai here: https://lkml.org/lkml/2018/9/4/587
Also, adds a new task as per mailing list conversation.
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
---
.../staging/vc04_services/bcm2835-audio/TODO | 25 +++----------------
1 file changed, 3 insertions(+), 22 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/TODO b/drivers/staging/vc04_services/bcm2835-audio/TODO
index 73d41fa631ac..cb8ead3e9108 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/TODO
+++ b/drivers/staging/vc04_services/bcm2835-audio/TODO
@@ -4,26 +4,7 @@
* *
*****************************************************************************
+1) Revisit multi-cards options and PCM route mixer control (as per comment
+https://lkml.org/lkml/2018/9/8/200)
-1) Document the device tree node
-
-The downstream tree(the tree that the driver was imported from) at
-http://www.github.com/raspberrypi/linux uses this node:
-
-audio: audio {
- compatible = "brcm,bcm2835-audio";
- brcm,pwm-channels = <8>;
-};
-
-Since the driver requires the use of VCHIQ, it may be useful to have a link
-in the device tree to the VCHIQ driver.
-
-2) Gracefully handle the case where VCHIQ is missing from the device tree or
-it has not been initialized yet.
-
-3) Review error handling and remove duplicate code.
-
-4) Cleanup the logging mechanism. The driver should probably be using the
-standard kernel logging mechanisms such as dev_info, dev_dbg, and friends.
-
-5) Fix the remaining checkpatch.pl errors and warnings.
+2) Fix the remaining checkpatch.pl errors and warnings.
--
2.19.1
When it comes to declaring variables it's preferred, when possible, to
use an inverted tree organization scheme.
Also, removes some comments that were useless.
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Acked-by: Stefan Wahren <[email protected]>
---
.../vc04_services/bcm2835-audio/bcm2835-pcm.c | 10 ++--------
.../vc04_services/bcm2835-audio/bcm2835-vchiq.c | 4 ++--
.../staging/vc04_services/bcm2835-audio/bcm2835.c | 14 +++++++-------
3 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
index e66da11af5cf..98b6977bdce7 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
@@ -164,14 +164,11 @@ static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
return snd_bcm2835_playback_open_generic(substream, 1);
}
-/* close callback */
static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
{
- /* the hardware-specific codes will be here */
-
- struct bcm2835_chip *chip;
- struct snd_pcm_runtime *runtime;
struct bcm2835_alsa_stream *alsa_stream;
+ struct snd_pcm_runtime *runtime;
+ struct bcm2835_chip *chip;
chip = snd_pcm_substream_chip(substream);
mutex_lock(&chip->audio_mutex);
@@ -195,20 +192,17 @@ static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
return 0;
}
-/* hw_params callback */
static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
}
-/* hw_free callback */
static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
{
return snd_pcm_lib_free_pages(substream);
}
-/* prepare callback */
static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
{
struct bcm2835_chip *chip = snd_pcm_substream_chip(substream);
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
index aca7008e1921..932ef12ac5d2 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
@@ -94,9 +94,9 @@ static void audio_vchi_callback(void *param,
void *msg_handle)
{
struct bcm2835_audio_instance *instance = param;
- int status;
- int msg_len;
struct vc_audio_msg m;
+ int msg_len;
+ int status;
if (reason != VCHI_CALLBACK_MSG_AVAILABLE)
return;
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 0efae7068fef..6ee8334dfc81 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -161,8 +161,8 @@ static int snd_add_child_device(struct device *dev,
struct bcm2835_audio_driver *audio_driver,
u32 numchans)
{
- struct snd_card *card;
struct bcm2835_chip *chip;
+ struct snd_card *card;
int err;
err = snd_card_new(dev, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
@@ -225,12 +225,12 @@ static int snd_add_child_device(struct device *dev,
static int snd_add_child_devices(struct device *device, u32 numchans)
{
- int i;
- int count_devices = 0;
- int minchannels = 0;
- int extrachannels = 0;
int extrachannels_per_driver = 0;
int extrachannels_remainder = 0;
+ int count_devices = 0;
+ int extrachannels = 0;
+ int minchannels = 0;
+ int i;
for (i = 0; i < ARRAY_SIZE(children_devices); i++)
if (*children_devices[i].is_enabled)
@@ -258,9 +258,9 @@ static int snd_add_child_devices(struct device *device, u32 numchans)
extrachannels_remainder);
for (i = 0; i < ARRAY_SIZE(children_devices); i++) {
- int err;
- int numchannels_this_device;
struct bcm2835_audio_driver *audio_driver;
+ int numchannels_this_device;
+ int err;
if (!*children_devices[i].is_enabled)
continue;
--
2.19.1
There will only be one probe function, there is no use for appendig
"_dt" the end of the name.
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Acked-by: Stefan Wahren <[email protected]>
---
drivers/staging/vc04_services/bcm2835-audio/bcm2835.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 6ee8334dfc81..039565311d10 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -291,7 +291,7 @@ static int snd_add_child_devices(struct device *device, u32 numchans)
return 0;
}
-static int snd_bcm2835_alsa_probe_dt(struct platform_device *pdev)
+static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
u32 numchans;
@@ -344,7 +344,7 @@ static const struct of_device_id snd_bcm2835_of_match_table[] = {
MODULE_DEVICE_TABLE(of, snd_bcm2835_of_match_table);
static struct platform_driver bcm2835_alsa0_driver = {
- .probe = snd_bcm2835_alsa_probe_dt,
+ .probe = snd_bcm2835_alsa_probe,
#ifdef CONFIG_PM
.suspend = snd_bcm2835_alsa_suspend,
.resume = snd_bcm2835_alsa_resume,
--
2.19.1
It was called bcm2835_alsa0_driver, that "0" didn't mean much.
Suggested-by: Takashi Iwai <[email protected]>
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
---
drivers/staging/vc04_services/bcm2835-audio/bcm2835.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 039565311d10..e14b7c5aa07c 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -343,7 +343,7 @@ static const struct of_device_id snd_bcm2835_of_match_table[] = {
};
MODULE_DEVICE_TABLE(of, snd_bcm2835_of_match_table);
-static struct platform_driver bcm2835_alsa0_driver = {
+static struct platform_driver bcm2835_alsa_driver = {
.probe = snd_bcm2835_alsa_probe,
#ifdef CONFIG_PM
.suspend = snd_bcm2835_alsa_suspend,
@@ -359,7 +359,7 @@ static int bcm2835_alsa_device_init(void)
{
int retval;
- retval = platform_driver_register(&bcm2835_alsa0_driver);
+ retval = platform_driver_register(&bcm2835_alsa_driver);
if (retval)
pr_err("Error registering bcm2835_audio driver %d .\n", retval);
@@ -368,7 +368,7 @@ static int bcm2835_alsa_device_init(void)
static void bcm2835_alsa_device_exit(void)
{
- platform_driver_unregister(&bcm2835_alsa0_driver);
+ platform_driver_unregister(&bcm2835_alsa_driver);
}
late_initcall(bcm2835_alsa_device_init);
--
2.19.1
In this case explicitly naming the union doesn't help overall code
comprehension and clutters it.
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Acked-by: Stefan Wahren <[email protected]>
---
.../bcm2835-audio/bcm2835-vchiq.c | 30 +++++++++----------
.../bcm2835-audio/vc_vchi_audioserv_defs.h | 2 +-
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
index 932ef12ac5d2..0db412fd7c55 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
@@ -104,15 +104,15 @@ static void audio_vchi_callback(void *param,
status = vchi_msg_dequeue(instance->vchi_handle,
&m, sizeof(m), &msg_len, VCHI_FLAGS_NONE);
if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
- instance->result = m.u.result.success;
+ instance->result = m.result.success;
complete(&instance->msg_avail_comp);
} else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
- if (m.u.complete.cookie1 != VC_AUDIO_WRITE_COOKIE1 ||
- m.u.complete.cookie2 != VC_AUDIO_WRITE_COOKIE2)
+ if (m.complete.cookie1 != VC_AUDIO_WRITE_COOKIE1 ||
+ m.complete.cookie2 != VC_AUDIO_WRITE_COOKIE2)
dev_err(instance->dev, "invalid cookie\n");
else
bcm2835_playback_fifo(instance->alsa_stream,
- m.u.complete.count);
+ m.complete.count);
} else {
dev_err(instance->dev, "unexpected callback type=%d\n", m.type);
}
@@ -249,11 +249,11 @@ int bcm2835_audio_set_ctls(struct bcm2835_alsa_stream *alsa_stream)
struct vc_audio_msg m = {};
m.type = VC_AUDIO_MSG_TYPE_CONTROL;
- m.u.control.dest = chip->dest;
+ m.control.dest = chip->dest;
if (!chip->mute)
- m.u.control.volume = CHIP_MIN_VOLUME;
+ m.control.volume = CHIP_MIN_VOLUME;
else
- m.u.control.volume = alsa2chip(chip->volume);
+ m.control.volume = alsa2chip(chip->volume);
return bcm2835_audio_send_msg(alsa_stream->instance, &m, true);
}
@@ -264,9 +264,9 @@ int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
{
struct vc_audio_msg m = {
.type = VC_AUDIO_MSG_TYPE_CONFIG,
- .u.config.channels = channels,
- .u.config.samplerate = samplerate,
- .u.config.bps = bps,
+ .config.channels = channels,
+ .config.samplerate = samplerate,
+ .config.bps = bps,
};
int err;
@@ -294,7 +294,7 @@ int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream)
{
struct vc_audio_msg m = {
.type = VC_AUDIO_MSG_TYPE_STOP,
- .u.stop.draining = 1,
+ .stop.draining = 1,
};
return bcm2835_audio_send_msg(alsa_stream->instance, &m, false);
@@ -322,10 +322,10 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
struct bcm2835_audio_instance *instance = alsa_stream->instance;
struct vc_audio_msg m = {
.type = VC_AUDIO_MSG_TYPE_WRITE,
- .u.write.count = size,
- .u.write.max_packet = instance->max_packet,
- .u.write.cookie1 = VC_AUDIO_WRITE_COOKIE1,
- .u.write.cookie2 = VC_AUDIO_WRITE_COOKIE2,
+ .write.count = size,
+ .write.max_packet = instance->max_packet,
+ .write.cookie1 = VC_AUDIO_WRITE_COOKIE1,
+ .write.cookie2 = VC_AUDIO_WRITE_COOKIE2,
};
unsigned int count;
int err, status;
diff --git a/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h b/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
index dc62875cfdca..d6401e914ac9 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
+++ b/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
@@ -93,7 +93,7 @@ struct vc_audio_msg {
struct vc_audio_write write;
struct vc_audio_result result;
struct vc_audio_complete complete;
- } u;
+ };
};
#endif /* _VC_AUDIO_DEFS_H_ */
--
2.19.1
The device communicates with the audio core using FOURCC codes. The
driver was generating them using different macros/expressions. We now
use the same macro to create them and centralize all the definitions.
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Acked-by: Stefan Wahren <[email protected]>
---
.../vc04_services/bcm2835-audio/bcm2835-vchiq.c | 13 ++++---------
.../bcm2835-audio/vc_vchi_audioserv_defs.h | 4 +++-
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
index 781754f36da7..aca7008e1921 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
@@ -89,11 +89,6 @@ static int bcm2835_audio_send_simple(struct bcm2835_audio_instance *instance,
return bcm2835_audio_send_msg(instance, &m, wait);
}
-static const u32 BCM2835_AUDIO_WRITE_COOKIE1 = ('B' << 24 | 'C' << 16 |
- 'M' << 8 | 'A');
-static const u32 BCM2835_AUDIO_WRITE_COOKIE2 = ('D' << 24 | 'A' << 16 |
- 'T' << 8 | 'A');
-
static void audio_vchi_callback(void *param,
const VCHI_CALLBACK_REASON_T reason,
void *msg_handle)
@@ -112,8 +107,8 @@ static void audio_vchi_callback(void *param,
instance->result = m.u.result.success;
complete(&instance->msg_avail_comp);
} else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
- if (m.u.complete.cookie1 != BCM2835_AUDIO_WRITE_COOKIE1 ||
- m.u.complete.cookie2 != BCM2835_AUDIO_WRITE_COOKIE2)
+ if (m.u.complete.cookie1 != VC_AUDIO_WRITE_COOKIE1 ||
+ m.u.complete.cookie2 != VC_AUDIO_WRITE_COOKIE2)
dev_err(instance->dev, "invalid cookie\n");
else
bcm2835_playback_fifo(instance->alsa_stream,
@@ -329,8 +324,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
.type = VC_AUDIO_MSG_TYPE_WRITE,
.u.write.count = size,
.u.write.max_packet = instance->max_packet,
- .u.write.cookie1 = BCM2835_AUDIO_WRITE_COOKIE1,
- .u.write.cookie2 = BCM2835_AUDIO_WRITE_COOKIE2,
+ .u.write.cookie1 = VC_AUDIO_WRITE_COOKIE1,
+ .u.write.cookie2 = VC_AUDIO_WRITE_COOKIE2,
};
unsigned int count;
int err, status;
diff --git a/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h b/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
index 1a7f0884ac9c..dc62875cfdca 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
+++ b/drivers/staging/vc04_services/bcm2835-audio/vc_vchi_audioserv_defs.h
@@ -7,8 +7,10 @@
#define VC_AUDIOSERV_MIN_VER 1
#define VC_AUDIOSERV_VER 2
-/* FourCC code used for VCHI connection */
+/* FourCC codes used for VCHI communication */
#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
+#define VC_AUDIO_WRITE_COOKIE1 MAKE_FOURCC("BCMA")
+#define VC_AUDIO_WRITE_COOKIE2 MAKE_FOURCC("DATA")
/*
* List of screens that are currently supported
--
2.19.1
The memory is being allocated with devres_alloc(), wich ultimately uses
__GFP_ZERO to call kmalloc. We don't need to zero the memory area again
in bcm2835-audio.
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Acked-by: Stefan Wahren <[email protected]>
---
drivers/staging/vc04_services/bcm2835-audio/bcm2835.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 87d56ab1ffa0..0efae7068fef 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -39,8 +39,6 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev)
if (!vchi_ctx)
return -ENOMEM;
- memset(vchi_ctx, 0, sizeof(*vchi_ctx));
-
ret = bcm2835_new_vchi_ctx(dev, vchi_ctx);
if (ret) {
devres_free(vchi_ctx);
--
2.19.1
> Nicolas Saenz Julienne <[email protected]> hat am 17. Oktober 2018 um 21:01 geschrieben:
>
>
> Hi,
>
> I just received a RPi3B+ and decided to have a go at fixing stuff in the
> audio driver. The changes are mostly cosmetic. I also took the liberty
> to update the TODO file.
>
> The series was developed on top of linux-next and tested on a RPi2B and
> RPi3B+. Sadly I don't have an HDMI monitor with sound so I only tested
> the mini jack output.
>
> Thanks,
> Nicolas
>
> v2: Removes the device tree related patches, updates TODO accordingly
> and adds suggestions from Takashi.
>
Acked-by: Stefan Wahren <[email protected]>
for the rest of the series