brcm2708: update to latest patches from RPi foundation
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.19 / 950-0454-staging-bcm2835-audio-Use-card-private_data.patch
1 From af0ded6e9dd38f08a9ee621066e583b5cf972926 Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:50 +0200
4 Subject: [PATCH 454/806] staging: bcm2835-audio: Use card->private_data
5
6 commit 898001a0c845cefe5d47d133485712412853f0a8 upstream.
7
8 Instead of allocating a separate snd_device object, let snd_card_new()
9 allocate the private resource. This simplifies the code.
10
11 Signed-off-by: Takashi Iwai <tiwai@suse.de>
12 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 ---
15 .../vc04_services/bcm2835-audio/bcm2835.c | 91 +++----------------
16 1 file changed, 13 insertions(+), 78 deletions(-)
17
18 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
19 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
20 @@ -86,9 +86,6 @@ static int bcm2835_devm_add_vchi_ctx(str
21
22 static void snd_bcm2835_release(struct device *dev)
23 {
24 - struct bcm2835_chip *chip = dev_get_drvdata(dev);
25 -
26 - kfree(chip);
27 }
28
29 static struct device *
30 @@ -117,69 +114,6 @@ snd_create_device(struct device *parent,
31 return device;
32 }
33
34 -/* component-destructor
35 - * (see "Management of Cards and Components")
36 - */
37 -static int snd_bcm2835_dev_free(struct snd_device *device)
38 -{
39 - struct bcm2835_chip *chip = device->device_data;
40 - struct snd_card *card = chip->card;
41 -
42 - snd_device_free(card, chip);
43 -
44 - return 0;
45 -}
46 -
47 -/* chip-specific constructor
48 - * (see "Management of Cards and Components")
49 - */
50 -static int snd_bcm2835_create(struct snd_card *card,
51 - struct bcm2835_chip **rchip)
52 -{
53 - struct bcm2835_chip *chip;
54 - int err;
55 - static struct snd_device_ops ops = {
56 - .dev_free = snd_bcm2835_dev_free,
57 - };
58 -
59 - *rchip = NULL;
60 -
61 - chip = kzalloc(sizeof(*chip), GFP_KERNEL);
62 - if (!chip)
63 - return -ENOMEM;
64 -
65 - chip->card = card;
66 - mutex_init(&chip->audio_mutex);
67 -
68 - chip->vchi_ctx = devres_find(card->dev->parent,
69 - bcm2835_devm_free_vchi_ctx, NULL, NULL);
70 - if (!chip->vchi_ctx) {
71 - kfree(chip);
72 - return -ENODEV;
73 - }
74 -
75 - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
76 - if (err) {
77 - kfree(chip);
78 - return err;
79 - }
80 -
81 - *rchip = chip;
82 - return 0;
83 -}
84 -
85 -static struct snd_card *snd_bcm2835_card_new(struct device *dev)
86 -{
87 - struct snd_card *card;
88 - int ret;
89 -
90 - ret = snd_card_new(dev, -1, NULL, THIS_MODULE, 0, &card);
91 - if (ret)
92 - return ERR_PTR(ret);
93 -
94 - return card;
95 -}
96 -
97 typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip,
98 const char *name,
99 enum snd_bcm2835_route route,
100 @@ -292,25 +226,26 @@ static int snd_add_child_device(struct d
101 return PTR_ERR(child);
102 }
103
104 - card = snd_bcm2835_card_new(child);
105 - if (IS_ERR(card)) {
106 + err = snd_card_new(child, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
107 + if (err < 0) {
108 dev_err(child, "Failed to create card");
109 - return PTR_ERR(card);
110 + return err;
111 }
112
113 - snd_card_set_dev(card, child);
114 + chip = card->private_data;
115 + chip->card = card;
116 + chip->dev = child;
117 + mutex_init(&chip->audio_mutex);
118 +
119 + chip->vchi_ctx = devres_find(device,
120 + bcm2835_devm_free_vchi_ctx, NULL, NULL);
121 + if (!chip->vchi_ctx)
122 + return -ENODEV;
123 +
124 strcpy(card->driver, audio_driver->driver.name);
125 strcpy(card->shortname, audio_driver->shortname);
126 strcpy(card->longname, audio_driver->longname);
127
128 - err = snd_bcm2835_create(card, &chip);
129 - if (err) {
130 - dev_err(child, "Failed to create chip, error %d\n", err);
131 - return err;
132 - }
133 -
134 - chip->dev = child;
135 -
136 err = audio_driver->newpcm(chip, audio_driver->shortname,
137 audio_driver->route,
138 numchans);