0035-bcm2708-alsa-sound-driver.patch 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678
  1. From b7b8ef3806db931be95bddf47946e27facc6d5dd Mon Sep 17 00:00:00 2001
  2. From: popcornmix <popcornmix@gmail.com>
  3. Date: Mon, 26 Mar 2012 22:15:50 +0100
  4. Subject: [PATCH 035/381] bcm2708: alsa sound driver
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Signed-off-by: popcornmix <popcornmix@gmail.com>
  9. alsa: add mmap support and some cleanups to bcm2835 ALSA driver
  10. snd-bcm2835: Add support for spdif/hdmi passthrough
  11. This adds a dedicated subdevice which can be used for passthrough of non-audio
  12. formats (ie encoded a52) through the hdmi audio link. In addition to this
  13. driver extension an appropriate card config is required to make alsa-lib
  14. support the AES parameters for this device.
  15. snd-bcm2708: Add mutex, improve logging
  16. Fix for ALSA driver crash
  17. Avoids an issue when closing and opening vchiq where a message can arrive before service handle has been written
  18. alsa: reduce severity of expected warning message
  19. snd-bcm2708: Fix dmesg spam for non-error case
  20. alsa: Ensure mutexes are released through error paths
  21. alsa: Make interrupted close paths quieter
  22. BCM270x: Add onboard sound device to Device Tree
  23. Add Device Tree support to alsa driver.
  24. Add device to Device Tree.
  25. Don't add platform devices when booting in DT mode.
  26. Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
  27. ---
  28. sound/arm/Kconfig | 8 +
  29. sound/arm/Makefile | 5 +
  30. sound/arm/bcm2835-ctl.c | 323 +++++++++++++
  31. sound/arm/bcm2835-pcm.c | 557 +++++++++++++++++++++++
  32. sound/arm/bcm2835-vchiq.c | 902 +++++++++++++++++++++++++++++++++++++
  33. sound/arm/bcm2835.c | 511 +++++++++++++++++++++
  34. sound/arm/bcm2835.h | 167 +++++++
  35. sound/arm/vc_vchi_audioserv_defs.h | 116 +++++
  36. 8 files changed, 2589 insertions(+)
  37. create mode 100755 sound/arm/bcm2835-ctl.c
  38. create mode 100755 sound/arm/bcm2835-pcm.c
  39. create mode 100755 sound/arm/bcm2835-vchiq.c
  40. create mode 100644 sound/arm/bcm2835.c
  41. create mode 100755 sound/arm/bcm2835.h
  42. create mode 100644 sound/arm/vc_vchi_audioserv_defs.h
  43. --- a/sound/arm/Kconfig
  44. +++ b/sound/arm/Kconfig
  45. @@ -40,5 +40,13 @@ config SND_PXA2XX_AC97
  46. Say Y or M if you want to support any AC97 codec attached to
  47. the PXA2xx AC97 interface.
  48. +config SND_BCM2835
  49. + tristate "BCM2835 ALSA driver"
  50. + depends on (ARCH_BCM2708 || ARCH_BCM2709 || ARCH_BCM2835) \
  51. + && BCM2708_VCHIQ && SND
  52. + select SND_PCM
  53. + help
  54. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  55. +
  56. endif # SND_ARM
  57. --- a/sound/arm/Makefile
  58. +++ b/sound/arm/Makefile
  59. @@ -14,3 +14,8 @@ snd-pxa2xx-lib-$(CONFIG_SND_PXA2XX_LIB_A
  60. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  61. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  62. +
  63. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  64. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  65. +
  66. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  67. --- /dev/null
  68. +++ b/sound/arm/bcm2835-ctl.c
  69. @@ -0,0 +1,323 @@
  70. +/*****************************************************************************
  71. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  72. +*
  73. +* Unless you and Broadcom execute a separate written software license
  74. +* agreement governing use of this software, this software is licensed to you
  75. +* under the terms of the GNU General Public License version 2, available at
  76. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  77. +*
  78. +* Notwithstanding the above, under no circumstances may you combine this
  79. +* software in any way with any other Broadcom software provided under a
  80. +* license other than the GPL, without Broadcom's express prior written
  81. +* consent.
  82. +*****************************************************************************/
  83. +
  84. +#include <linux/platform_device.h>
  85. +#include <linux/init.h>
  86. +#include <linux/io.h>
  87. +#include <linux/jiffies.h>
  88. +#include <linux/slab.h>
  89. +#include <linux/time.h>
  90. +#include <linux/wait.h>
  91. +#include <linux/delay.h>
  92. +#include <linux/moduleparam.h>
  93. +#include <linux/sched.h>
  94. +
  95. +#include <sound/core.h>
  96. +#include <sound/control.h>
  97. +#include <sound/pcm.h>
  98. +#include <sound/pcm_params.h>
  99. +#include <sound/rawmidi.h>
  100. +#include <sound/initval.h>
  101. +#include <sound/tlv.h>
  102. +#include <sound/asoundef.h>
  103. +
  104. +#include "bcm2835.h"
  105. +
  106. +/* volume maximum and minimum in terms of 0.01dB */
  107. +#define CTRL_VOL_MAX 400
  108. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  109. +
  110. +
  111. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  112. + struct snd_ctl_elem_info *uinfo)
  113. +{
  114. + audio_info(" ... IN\n");
  115. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  116. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  117. + uinfo->count = 1;
  118. + uinfo->value.integer.min = CTRL_VOL_MIN;
  119. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  120. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  121. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  122. + uinfo->count = 1;
  123. + uinfo->value.integer.min = 0;
  124. + uinfo->value.integer.max = 1;
  125. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  126. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  127. + uinfo->count = 1;
  128. + uinfo->value.integer.min = 0;
  129. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  130. + }
  131. + audio_info(" ... OUT\n");
  132. + return 0;
  133. +}
  134. +
  135. +/* toggles mute on or off depending on the value of nmute, and returns
  136. + * 1 if the mute value was changed, otherwise 0
  137. + */
  138. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  139. +{
  140. + /* if settings are ok, just return 0 */
  141. + if(chip->mute == nmute)
  142. + return 0;
  143. +
  144. + /* if the sound is muted then we need to unmute */
  145. + if(chip->mute == CTRL_VOL_MUTE)
  146. + {
  147. + chip->volume = chip->old_volume; /* copy the old volume back */
  148. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  149. + }
  150. + else /* otherwise we mute */
  151. + {
  152. + chip->old_volume = chip->volume;
  153. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  154. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  155. + }
  156. +
  157. + chip->mute = nmute;
  158. + return 1;
  159. +}
  160. +
  161. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  162. + struct snd_ctl_elem_value *ucontrol)
  163. +{
  164. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  165. +
  166. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  167. +
  168. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  169. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  170. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  171. + ucontrol->value.integer.value[0] = chip->mute;
  172. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  173. + ucontrol->value.integer.value[0] = chip->dest;
  174. +
  175. + return 0;
  176. +}
  177. +
  178. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  179. + struct snd_ctl_elem_value *ucontrol)
  180. +{
  181. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  182. + int changed = 0;
  183. +
  184. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  185. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  186. + if (chip->mute == CTRL_VOL_MUTE) {
  187. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  188. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  189. + }
  190. + if (changed
  191. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  192. +
  193. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  194. + changed = 1;
  195. + }
  196. +
  197. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  198. + /* Now implemented */
  199. + audio_info(" Mute attempted\n");
  200. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  201. +
  202. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  203. + if (ucontrol->value.integer.value[0] != chip->dest) {
  204. + chip->dest = ucontrol->value.integer.value[0];
  205. + changed = 1;
  206. + }
  207. + }
  208. +
  209. + if (changed) {
  210. + if (bcm2835_audio_set_ctls(chip))
  211. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  212. + }
  213. +
  214. + return changed;
  215. +}
  216. +
  217. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  218. +
  219. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  220. + {
  221. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  222. + .name = "PCM Playback Volume",
  223. + .index = 0,
  224. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  225. + .private_value = PCM_PLAYBACK_VOLUME,
  226. + .info = snd_bcm2835_ctl_info,
  227. + .get = snd_bcm2835_ctl_get,
  228. + .put = snd_bcm2835_ctl_put,
  229. + .count = 1,
  230. + .tlv = {.p = snd_bcm2835_db_scale}
  231. + },
  232. + {
  233. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  234. + .name = "PCM Playback Switch",
  235. + .index = 0,
  236. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  237. + .private_value = PCM_PLAYBACK_MUTE,
  238. + .info = snd_bcm2835_ctl_info,
  239. + .get = snd_bcm2835_ctl_get,
  240. + .put = snd_bcm2835_ctl_put,
  241. + .count = 1,
  242. + },
  243. + {
  244. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  245. + .name = "PCM Playback Route",
  246. + .index = 0,
  247. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  248. + .private_value = PCM_PLAYBACK_DEVICE,
  249. + .info = snd_bcm2835_ctl_info,
  250. + .get = snd_bcm2835_ctl_get,
  251. + .put = snd_bcm2835_ctl_put,
  252. + .count = 1,
  253. + },
  254. +};
  255. +
  256. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  257. + struct snd_ctl_elem_info *uinfo)
  258. +{
  259. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  260. + uinfo->count = 1;
  261. + return 0;
  262. +}
  263. +
  264. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  265. + struct snd_ctl_elem_value *ucontrol)
  266. +{
  267. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  268. + int i;
  269. +
  270. + for (i = 0; i < 4; i++)
  271. + ucontrol->value.iec958.status[i] =
  272. + (chip->spdif_status >> (i * 8)) && 0xff;
  273. +
  274. + return 0;
  275. +}
  276. +
  277. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  278. + struct snd_ctl_elem_value *ucontrol)
  279. +{
  280. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  281. + unsigned int val = 0;
  282. + int i, change;
  283. +
  284. + for (i = 0; i < 4; i++)
  285. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  286. +
  287. + change = val != chip->spdif_status;
  288. + chip->spdif_status = val;
  289. +
  290. + return change;
  291. +}
  292. +
  293. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  294. + struct snd_ctl_elem_info *uinfo)
  295. +{
  296. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  297. + uinfo->count = 1;
  298. + return 0;
  299. +}
  300. +
  301. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  302. + struct snd_ctl_elem_value *ucontrol)
  303. +{
  304. + /* bcm2835 supports only consumer mode and sets all other format flags
  305. + * automatically. So the only thing left is signalling non-audio
  306. + * content */
  307. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  308. + return 0;
  309. +}
  310. +
  311. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  312. + struct snd_ctl_elem_info *uinfo)
  313. +{
  314. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  315. + uinfo->count = 1;
  316. + return 0;
  317. +}
  318. +
  319. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  320. + struct snd_ctl_elem_value *ucontrol)
  321. +{
  322. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  323. + int i;
  324. +
  325. + for (i = 0; i < 4; i++)
  326. + ucontrol->value.iec958.status[i] =
  327. + (chip->spdif_status >> (i * 8)) & 0xff;
  328. + return 0;
  329. +}
  330. +
  331. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  332. + struct snd_ctl_elem_value *ucontrol)
  333. +{
  334. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  335. + unsigned int val = 0;
  336. + int i, change;
  337. +
  338. + for (i = 0; i < 4; i++)
  339. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  340. + change = val != chip->spdif_status;
  341. + chip->spdif_status = val;
  342. +
  343. + return change;
  344. +}
  345. +
  346. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  347. + {
  348. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  349. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  350. + .info = snd_bcm2835_spdif_default_info,
  351. + .get = snd_bcm2835_spdif_default_get,
  352. + .put = snd_bcm2835_spdif_default_put
  353. + },
  354. + {
  355. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  356. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  357. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  358. + .info = snd_bcm2835_spdif_mask_info,
  359. + .get = snd_bcm2835_spdif_mask_get,
  360. + },
  361. + {
  362. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  363. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  364. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  365. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  366. + .info = snd_bcm2835_spdif_stream_info,
  367. + .get = snd_bcm2835_spdif_stream_get,
  368. + .put = snd_bcm2835_spdif_stream_put,
  369. + },
  370. +};
  371. +
  372. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  373. +{
  374. + int err;
  375. + unsigned int idx;
  376. +
  377. + strcpy(chip->card->mixername, "Broadcom Mixer");
  378. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  379. + err =
  380. + snd_ctl_add(chip->card,
  381. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  382. + if (err < 0)
  383. + return err;
  384. + }
  385. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  386. + err = snd_ctl_add(chip->card,
  387. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  388. + if (err < 0)
  389. + return err;
  390. + }
  391. + return 0;
  392. +}
  393. --- /dev/null
  394. +++ b/sound/arm/bcm2835-pcm.c
  395. @@ -0,0 +1,557 @@
  396. +/*****************************************************************************
  397. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  398. +*
  399. +* Unless you and Broadcom execute a separate written software license
  400. +* agreement governing use of this software, this software is licensed to you
  401. +* under the terms of the GNU General Public License version 2, available at
  402. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  403. +*
  404. +* Notwithstanding the above, under no circumstances may you combine this
  405. +* software in any way with any other Broadcom software provided under a
  406. +* license other than the GPL, without Broadcom's express prior written
  407. +* consent.
  408. +*****************************************************************************/
  409. +
  410. +#include <linux/interrupt.h>
  411. +#include <linux/slab.h>
  412. +
  413. +#include <sound/asoundef.h>
  414. +
  415. +#include "bcm2835.h"
  416. +
  417. +/* hardware definition */
  418. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  419. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  420. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  421. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  422. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  423. + .rate_min = 8000,
  424. + .rate_max = 48000,
  425. + .channels_min = 1,
  426. + .channels_max = 2,
  427. + .buffer_bytes_max = 128 * 1024,
  428. + .period_bytes_min = 1 * 1024,
  429. + .period_bytes_max = 128 * 1024,
  430. + .periods_min = 1,
  431. + .periods_max = 128,
  432. +};
  433. +
  434. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  435. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  436. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  437. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  438. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  439. + SNDRV_PCM_RATE_48000,
  440. + .rate_min = 44100,
  441. + .rate_max = 48000,
  442. + .channels_min = 2,
  443. + .channels_max = 2,
  444. + .buffer_bytes_max = 128 * 1024,
  445. + .period_bytes_min = 1 * 1024,
  446. + .period_bytes_max = 128 * 1024,
  447. + .periods_min = 1,
  448. + .periods_max = 128,
  449. +};
  450. +
  451. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  452. +{
  453. + audio_info("Freeing up alsa stream here ..\n");
  454. + if (runtime->private_data)
  455. + kfree(runtime->private_data);
  456. + runtime->private_data = NULL;
  457. +}
  458. +
  459. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  460. +{
  461. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  462. + uint32_t consumed = 0;
  463. + int new_period = 0;
  464. +
  465. + audio_info(" .. IN\n");
  466. +
  467. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  468. + alsa_stream ? alsa_stream->substream : 0);
  469. +
  470. + if (alsa_stream->open)
  471. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  472. +
  473. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  474. + * each iteration are the buffers that have been played out already
  475. + */
  476. +
  477. + if (alsa_stream->period_size) {
  478. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  479. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  480. + new_period = 1;
  481. + }
  482. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  483. + alsa_stream->pos,
  484. + consumed,
  485. + alsa_stream->buffer_size,
  486. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  487. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  488. + new_period);
  489. + if (alsa_stream->buffer_size) {
  490. + alsa_stream->pos += consumed &~ (1<<30);
  491. + alsa_stream->pos %= alsa_stream->buffer_size;
  492. + }
  493. +
  494. + if (alsa_stream->substream) {
  495. + if (new_period)
  496. + snd_pcm_period_elapsed(alsa_stream->substream);
  497. + } else {
  498. + audio_warning(" unexpected NULL substream\n");
  499. + }
  500. + audio_info(" .. OUT\n");
  501. +
  502. + return IRQ_HANDLED;
  503. +}
  504. +
  505. +/* open callback */
  506. +static int snd_bcm2835_playback_open_generic(
  507. + struct snd_pcm_substream *substream, int spdif)
  508. +{
  509. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  510. + struct snd_pcm_runtime *runtime = substream->runtime;
  511. + bcm2835_alsa_stream_t *alsa_stream;
  512. + int idx;
  513. + int err;
  514. +
  515. + audio_info(" .. IN (%d)\n", substream->number);
  516. +
  517. + if(mutex_lock_interruptible(&chip->audio_mutex))
  518. + {
  519. + audio_error("Interrupted whilst waiting for lock\n");
  520. + return -EINTR;
  521. + }
  522. + audio_info("Alsa open (%d)\n", substream->number);
  523. + idx = substream->number;
  524. +
  525. + if (spdif && chip->opened != 0) {
  526. + err = -EBUSY;
  527. + goto out;
  528. + }
  529. + else if (!spdif && (chip->opened & (1 << idx))) {
  530. + err = -EBUSY;
  531. + goto out;
  532. + }
  533. + if (idx > MAX_SUBSTREAMS) {
  534. + audio_error
  535. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  536. + idx, MAX_SUBSTREAMS);
  537. + err = -ENODEV;
  538. + goto out;
  539. + }
  540. +
  541. + /* Check if we are ready */
  542. + if (!(chip->avail_substreams & (1 << idx))) {
  543. + /* We are not ready yet */
  544. + audio_error("substream(%d) device is not ready yet\n", idx);
  545. + err = -EAGAIN;
  546. + goto out;
  547. + }
  548. +
  549. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  550. + if (alsa_stream == NULL) {
  551. + err = -ENOMEM;
  552. + goto out;
  553. + }
  554. +
  555. + /* Initialise alsa_stream */
  556. + alsa_stream->chip = chip;
  557. + alsa_stream->substream = substream;
  558. + alsa_stream->idx = idx;
  559. +
  560. + sema_init(&alsa_stream->buffers_update_sem, 0);
  561. + sema_init(&alsa_stream->control_sem, 0);
  562. + spin_lock_init(&alsa_stream->lock);
  563. +
  564. + /* Enabled in start trigger, called on each "fifo irq" after that */
  565. + alsa_stream->enable_fifo_irq = 0;
  566. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  567. +
  568. + err = bcm2835_audio_open(alsa_stream);
  569. + if (err != 0) {
  570. + kfree(alsa_stream);
  571. + goto out;
  572. + }
  573. + runtime->private_data = alsa_stream;
  574. + runtime->private_free = snd_bcm2835_playback_free;
  575. + if (spdif) {
  576. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  577. + } else {
  578. + /* clear spdif status, as we are not in spdif mode */
  579. + chip->spdif_status = 0;
  580. + runtime->hw = snd_bcm2835_playback_hw;
  581. + }
  582. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  583. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  584. + 16);
  585. +
  586. + chip->alsa_stream[idx] = alsa_stream;
  587. +
  588. + chip->opened |= (1 << idx);
  589. + alsa_stream->open = 1;
  590. + alsa_stream->draining = 1;
  591. +
  592. +out:
  593. + mutex_unlock(&chip->audio_mutex);
  594. +
  595. + audio_info(" .. OUT =%d\n", err);
  596. +
  597. + return err;
  598. +}
  599. +
  600. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  601. +{
  602. + return snd_bcm2835_playback_open_generic(substream, 0);
  603. +}
  604. +
  605. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  606. +{
  607. + return snd_bcm2835_playback_open_generic(substream, 1);
  608. +}
  609. +
  610. +/* close callback */
  611. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  612. +{
  613. + /* the hardware-specific codes will be here */
  614. +
  615. + bcm2835_chip_t *chip;
  616. + struct snd_pcm_runtime *runtime;
  617. + bcm2835_alsa_stream_t *alsa_stream;
  618. +
  619. + audio_info(" .. IN\n");
  620. +
  621. + chip = snd_pcm_substream_chip(substream);
  622. + if(mutex_lock_interruptible(&chip->audio_mutex))
  623. + {
  624. + audio_error("Interrupted whilst waiting for lock\n");
  625. + return -EINTR;
  626. + }
  627. + runtime = substream->runtime;
  628. + alsa_stream = runtime->private_data;
  629. +
  630. + audio_info("Alsa close\n");
  631. +
  632. + /*
  633. + * Call stop if it's still running. This happens when app
  634. + * is force killed and we don't get a stop trigger.
  635. + */
  636. + if (alsa_stream->running) {
  637. + int err;
  638. + err = bcm2835_audio_stop(alsa_stream);
  639. + alsa_stream->running = 0;
  640. + if (err != 0)
  641. + audio_error(" Failed to STOP alsa device\n");
  642. + }
  643. +
  644. + alsa_stream->period_size = 0;
  645. + alsa_stream->buffer_size = 0;
  646. +
  647. + if (alsa_stream->open) {
  648. + alsa_stream->open = 0;
  649. + bcm2835_audio_close(alsa_stream);
  650. + }
  651. + if (alsa_stream->chip)
  652. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  653. + /*
  654. + * Do not free up alsa_stream here, it will be freed up by
  655. + * runtime->private_free callback we registered in *_open above
  656. + */
  657. +
  658. + chip->opened &= ~(1 << substream->number);
  659. +
  660. + mutex_unlock(&chip->audio_mutex);
  661. + audio_info(" .. OUT\n");
  662. +
  663. + return 0;
  664. +}
  665. +
  666. +/* hw_params callback */
  667. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  668. + struct snd_pcm_hw_params *params)
  669. +{
  670. + struct snd_pcm_runtime *runtime = substream->runtime;
  671. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  672. + int err;
  673. +
  674. + audio_info(" .. IN\n");
  675. +
  676. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  677. + if (err < 0) {
  678. + audio_error
  679. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  680. + return err;
  681. + }
  682. +
  683. + alsa_stream->channels = params_channels(params);
  684. + alsa_stream->params_rate = params_rate(params);
  685. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  686. + audio_info(" .. OUT\n");
  687. +
  688. + return err;
  689. +}
  690. +
  691. +/* hw_free callback */
  692. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  693. +{
  694. + audio_info(" .. IN\n");
  695. + return snd_pcm_lib_free_pages(substream);
  696. +}
  697. +
  698. +/* prepare callback */
  699. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  700. +{
  701. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  702. + struct snd_pcm_runtime *runtime = substream->runtime;
  703. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  704. + int channels;
  705. + int err;
  706. +
  707. + audio_info(" .. IN\n");
  708. +
  709. + /* notify the vchiq that it should enter spdif passthrough mode by
  710. + * setting channels=0 (see
  711. + * https://github.com/raspberrypi/linux/issues/528) */
  712. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  713. + channels = 0;
  714. + else
  715. + channels = alsa_stream->channels;
  716. +
  717. + err = bcm2835_audio_set_params(alsa_stream, channels,
  718. + alsa_stream->params_rate,
  719. + alsa_stream->pcm_format_width);
  720. + if (err < 0) {
  721. + audio_error(" error setting hw params\n");
  722. + }
  723. +
  724. + bcm2835_audio_setup(alsa_stream);
  725. +
  726. + /* in preparation of the stream, set the controls (volume level) of the stream */
  727. + bcm2835_audio_set_ctls(alsa_stream->chip);
  728. +
  729. +
  730. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  731. +
  732. + alsa_stream->pcm_indirect.hw_buffer_size =
  733. + alsa_stream->pcm_indirect.sw_buffer_size =
  734. + snd_pcm_lib_buffer_bytes(substream);
  735. +
  736. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  737. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  738. + alsa_stream->pos = 0;
  739. +
  740. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  741. + alsa_stream->buffer_size, alsa_stream->period_size,
  742. + alsa_stream->pos, runtime->frame_bits);
  743. +
  744. + audio_info(" .. OUT\n");
  745. + return 0;
  746. +}
  747. +
  748. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  749. + struct snd_pcm_indirect *rec, size_t bytes)
  750. +{
  751. + struct snd_pcm_runtime *runtime = substream->runtime;
  752. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  753. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  754. + int err;
  755. +
  756. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  757. + if (err)
  758. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  759. +
  760. +}
  761. +
  762. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  763. +{
  764. + struct snd_pcm_runtime *runtime = substream->runtime;
  765. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  766. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  767. +
  768. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  769. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  770. + snd_bcm2835_pcm_transfer);
  771. + return 0;
  772. +}
  773. +
  774. +/* trigger callback */
  775. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  776. +{
  777. + struct snd_pcm_runtime *runtime = substream->runtime;
  778. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  779. + int err = 0;
  780. +
  781. + audio_info(" .. IN\n");
  782. +
  783. + switch (cmd) {
  784. + case SNDRV_PCM_TRIGGER_START:
  785. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  786. + alsa_stream->running);
  787. + if (!alsa_stream->running) {
  788. + err = bcm2835_audio_start(alsa_stream);
  789. + if (err == 0) {
  790. + alsa_stream->pcm_indirect.hw_io =
  791. + alsa_stream->pcm_indirect.hw_data =
  792. + bytes_to_frames(runtime,
  793. + alsa_stream->pos);
  794. + substream->ops->ack(substream);
  795. + alsa_stream->running = 1;
  796. + alsa_stream->draining = 1;
  797. + } else {
  798. + audio_error(" Failed to START alsa device (%d)\n", err);
  799. + }
  800. + }
  801. + break;
  802. + case SNDRV_PCM_TRIGGER_STOP:
  803. + audio_debug
  804. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  805. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  806. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  807. + audio_info("DRAINING\n");
  808. + alsa_stream->draining = 1;
  809. + } else {
  810. + audio_info("DROPPING\n");
  811. + alsa_stream->draining = 0;
  812. + }
  813. + if (alsa_stream->running) {
  814. + err = bcm2835_audio_stop(alsa_stream);
  815. + if (err != 0)
  816. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  817. + alsa_stream->running = 0;
  818. + }
  819. + break;
  820. + default:
  821. + err = -EINVAL;
  822. + }
  823. +
  824. + audio_info(" .. OUT\n");
  825. + return err;
  826. +}
  827. +
  828. +/* pointer callback */
  829. +static snd_pcm_uframes_t
  830. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  831. +{
  832. + struct snd_pcm_runtime *runtime = substream->runtime;
  833. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  834. +
  835. + audio_info(" .. IN\n");
  836. +
  837. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  838. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  839. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  840. + alsa_stream->pos);
  841. +
  842. + audio_info(" .. OUT\n");
  843. + return snd_pcm_indirect_playback_pointer(substream,
  844. + &alsa_stream->pcm_indirect,
  845. + alsa_stream->pos);
  846. +}
  847. +
  848. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  849. + unsigned int cmd, void *arg)
  850. +{
  851. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  852. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  853. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  854. + return ret;
  855. +}
  856. +
  857. +/* operators */
  858. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  859. + .open = snd_bcm2835_playback_open,
  860. + .close = snd_bcm2835_playback_close,
  861. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  862. + .hw_params = snd_bcm2835_pcm_hw_params,
  863. + .hw_free = snd_bcm2835_pcm_hw_free,
  864. + .prepare = snd_bcm2835_pcm_prepare,
  865. + .trigger = snd_bcm2835_pcm_trigger,
  866. + .pointer = snd_bcm2835_pcm_pointer,
  867. + .ack = snd_bcm2835_pcm_ack,
  868. +};
  869. +
  870. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  871. + .open = snd_bcm2835_playback_spdif_open,
  872. + .close = snd_bcm2835_playback_close,
  873. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  874. + .hw_params = snd_bcm2835_pcm_hw_params,
  875. + .hw_free = snd_bcm2835_pcm_hw_free,
  876. + .prepare = snd_bcm2835_pcm_prepare,
  877. + .trigger = snd_bcm2835_pcm_trigger,
  878. + .pointer = snd_bcm2835_pcm_pointer,
  879. + .ack = snd_bcm2835_pcm_ack,
  880. +};
  881. +
  882. +/* create a pcm device */
  883. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  884. +{
  885. + struct snd_pcm *pcm;
  886. + int err;
  887. +
  888. + audio_info(" .. IN\n");
  889. + mutex_init(&chip->audio_mutex);
  890. + if(mutex_lock_interruptible(&chip->audio_mutex))
  891. + {
  892. + audio_error("Interrupted whilst waiting for lock\n");
  893. + return -EINTR;
  894. + }
  895. + err =
  896. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  897. + if (err < 0)
  898. + goto out;
  899. + pcm->private_data = chip;
  900. + strcpy(pcm->name, "bcm2835 ALSA");
  901. + chip->pcm = pcm;
  902. + chip->dest = AUDIO_DEST_AUTO;
  903. + chip->volume = alsa2chip(0);
  904. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  905. + /* set operators */
  906. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  907. + &snd_bcm2835_playback_ops);
  908. +
  909. + /* pre-allocation of buffers */
  910. + /* NOTE: this may fail */
  911. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  912. + snd_dma_continuous_data
  913. + (GFP_KERNEL), 64 * 1024,
  914. + 64 * 1024);
  915. +
  916. +out:
  917. + mutex_unlock(&chip->audio_mutex);
  918. + audio_info(" .. OUT\n");
  919. +
  920. + return 0;
  921. +}
  922. +
  923. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  924. +{
  925. + struct snd_pcm *pcm;
  926. + int err;
  927. +
  928. + audio_info(" .. IN\n");
  929. + if(mutex_lock_interruptible(&chip->audio_mutex))
  930. + {
  931. + audio_error("Interrupted whilst waiting for lock\n");
  932. + return -EINTR;
  933. + }
  934. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  935. + if (err < 0)
  936. + goto out;
  937. +
  938. + pcm->private_data = chip;
  939. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  940. + chip->pcm_spdif = pcm;
  941. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  942. + &snd_bcm2835_playback_spdif_ops);
  943. +
  944. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  945. + snd_dma_continuous_data (GFP_KERNEL),
  946. + 64 * 1024, 64 * 1024);
  947. +out:
  948. + mutex_unlock(&chip->audio_mutex);
  949. + audio_info(" .. OUT\n");
  950. +
  951. + return 0;
  952. +}
  953. --- /dev/null
  954. +++ b/sound/arm/bcm2835-vchiq.c
  955. @@ -0,0 +1,902 @@
  956. +/*****************************************************************************
  957. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  958. +*
  959. +* Unless you and Broadcom execute a separate written software license
  960. +* agreement governing use of this software, this software is licensed to you
  961. +* under the terms of the GNU General Public License version 2, available at
  962. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  963. +*
  964. +* Notwithstanding the above, under no circumstances may you combine this
  965. +* software in any way with any other Broadcom software provided under a
  966. +* license other than the GPL, without Broadcom's express prior written
  967. +* consent.
  968. +*****************************************************************************/
  969. +
  970. +#include <linux/device.h>
  971. +#include <sound/core.h>
  972. +#include <sound/initval.h>
  973. +#include <sound/pcm.h>
  974. +#include <linux/io.h>
  975. +#include <linux/interrupt.h>
  976. +#include <linux/fs.h>
  977. +#include <linux/file.h>
  978. +#include <linux/mm.h>
  979. +#include <linux/syscalls.h>
  980. +#include <asm/uaccess.h>
  981. +#include <linux/slab.h>
  982. +#include <linux/delay.h>
  983. +#include <linux/atomic.h>
  984. +#include <linux/module.h>
  985. +#include <linux/completion.h>
  986. +
  987. +#include "bcm2835.h"
  988. +
  989. +/* ---- Include Files -------------------------------------------------------- */
  990. +
  991. +#include "interface/vchi/vchi.h"
  992. +#include "vc_vchi_audioserv_defs.h"
  993. +
  994. +/* ---- Private Constants and Types ------------------------------------------ */
  995. +
  996. +#define BCM2835_AUDIO_STOP 0
  997. +#define BCM2835_AUDIO_START 1
  998. +#define BCM2835_AUDIO_WRITE 2
  999. +
  1000. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  1001. +#ifdef AUDIO_DEBUG_ENABLE
  1002. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  1003. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  1004. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  1005. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  1006. +#else
  1007. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  1008. + #define LOG_WARN( fmt, arg... )
  1009. + #define LOG_INFO( fmt, arg... )
  1010. + #define LOG_DBG( fmt, arg... )
  1011. +#endif
  1012. +
  1013. +typedef struct opaque_AUDIO_INSTANCE_T {
  1014. + uint32_t num_connections;
  1015. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  1016. + struct completion msg_avail_comp;
  1017. + struct mutex vchi_mutex;
  1018. + bcm2835_alsa_stream_t *alsa_stream;
  1019. + int32_t result;
  1020. + short peer_version;
  1021. +} AUDIO_INSTANCE_T;
  1022. +
  1023. +bool force_bulk = false;
  1024. +
  1025. +/* ---- Private Variables ---------------------------------------------------- */
  1026. +
  1027. +/* ---- Private Function Prototypes ------------------------------------------ */
  1028. +
  1029. +/* ---- Private Functions ---------------------------------------------------- */
  1030. +
  1031. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  1032. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  1033. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  1034. + uint32_t count, void *src);
  1035. +
  1036. +typedef struct {
  1037. + struct work_struct my_work;
  1038. + bcm2835_alsa_stream_t *alsa_stream;
  1039. + int cmd;
  1040. + void *src;
  1041. + uint32_t count;
  1042. +} my_work_t;
  1043. +
  1044. +static void my_wq_function(struct work_struct *work)
  1045. +{
  1046. + my_work_t *w = (my_work_t *) work;
  1047. + int ret = -9;
  1048. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  1049. + switch (w->cmd) {
  1050. + case BCM2835_AUDIO_START:
  1051. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  1052. + break;
  1053. + case BCM2835_AUDIO_STOP:
  1054. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  1055. + break;
  1056. + case BCM2835_AUDIO_WRITE:
  1057. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  1058. + w->src);
  1059. + break;
  1060. + default:
  1061. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  1062. + break;
  1063. + }
  1064. + kfree((void *)work);
  1065. + LOG_DBG(" .. OUT %d\n", ret);
  1066. +}
  1067. +
  1068. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  1069. +{
  1070. + int ret = -1;
  1071. + LOG_DBG(" .. IN\n");
  1072. + if (alsa_stream->my_wq) {
  1073. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  1074. + /*--- Queue some work (item 1) ---*/
  1075. + if (work) {
  1076. + INIT_WORK((struct work_struct *)work, my_wq_function);
  1077. + work->alsa_stream = alsa_stream;
  1078. + work->cmd = BCM2835_AUDIO_START;
  1079. + if (queue_work
  1080. + (alsa_stream->my_wq, (struct work_struct *)work))
  1081. + ret = 0;
  1082. + } else
  1083. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  1084. + }
  1085. + LOG_DBG(" .. OUT %d\n", ret);
  1086. + return ret;
  1087. +}
  1088. +
  1089. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  1090. +{
  1091. + int ret = -1;
  1092. + LOG_DBG(" .. IN\n");
  1093. + if (alsa_stream->my_wq) {
  1094. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  1095. + /*--- Queue some work (item 1) ---*/
  1096. + if (work) {
  1097. + INIT_WORK((struct work_struct *)work, my_wq_function);
  1098. + work->alsa_stream = alsa_stream;
  1099. + work->cmd = BCM2835_AUDIO_STOP;
  1100. + if (queue_work
  1101. + (alsa_stream->my_wq, (struct work_struct *)work))
  1102. + ret = 0;
  1103. + } else
  1104. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  1105. + }
  1106. + LOG_DBG(" .. OUT %d\n", ret);
  1107. + return ret;
  1108. +}
  1109. +
  1110. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  1111. + uint32_t count, void *src)
  1112. +{
  1113. + int ret = -1;
  1114. + LOG_DBG(" .. IN\n");
  1115. + if (alsa_stream->my_wq) {
  1116. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  1117. + /*--- Queue some work (item 1) ---*/
  1118. + if (work) {
  1119. + INIT_WORK((struct work_struct *)work, my_wq_function);
  1120. + work->alsa_stream = alsa_stream;
  1121. + work->cmd = BCM2835_AUDIO_WRITE;
  1122. + work->src = src;
  1123. + work->count = count;
  1124. + if (queue_work
  1125. + (alsa_stream->my_wq, (struct work_struct *)work))
  1126. + ret = 0;
  1127. + } else
  1128. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  1129. + }
  1130. + LOG_DBG(" .. OUT %d\n", ret);
  1131. + return ret;
  1132. +}
  1133. +
  1134. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  1135. +{
  1136. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  1137. + return;
  1138. +}
  1139. +
  1140. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  1141. +{
  1142. + if (alsa_stream->my_wq) {
  1143. + flush_workqueue(alsa_stream->my_wq);
  1144. + destroy_workqueue(alsa_stream->my_wq);
  1145. + alsa_stream->my_wq = NULL;
  1146. + }
  1147. + return;
  1148. +}
  1149. +
  1150. +static void audio_vchi_callback(void *param,
  1151. + const VCHI_CALLBACK_REASON_T reason,
  1152. + void *msg_handle)
  1153. +{
  1154. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  1155. + int32_t status;
  1156. + int32_t msg_len;
  1157. + VC_AUDIO_MSG_T m;
  1158. + LOG_DBG(" .. IN instance=%p, handle=%p, alsa=%p, reason=%d, handle=%p\n",
  1159. + instance, instance ? instance->vchi_handle[0] : NULL, instance ? instance->alsa_stream : NULL, reason, msg_handle);
  1160. +
  1161. + if (reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  1162. + return;
  1163. + }
  1164. + if (!instance) {
  1165. + LOG_ERR(" .. instance is null\n");
  1166. + BUG();
  1167. + return;
  1168. + }
  1169. + if (!instance->vchi_handle[0]) {
  1170. + LOG_ERR(" .. instance->vchi_handle[0] is null\n");
  1171. + BUG();
  1172. + return;
  1173. + }
  1174. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  1175. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  1176. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  1177. + LOG_DBG
  1178. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  1179. + instance, m.u.result.success);
  1180. + instance->result = m.u.result.success;
  1181. + complete(&instance->msg_avail_comp);
  1182. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  1183. + bcm2835_alsa_stream_t *alsa_stream = instance->alsa_stream;
  1184. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  1185. + LOG_DBG
  1186. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  1187. + instance, m.u.complete.count);
  1188. + if (alsa_stream && callback) {
  1189. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  1190. + callback(0, alsa_stream);
  1191. + } else {
  1192. + LOG_ERR(" .. unexpected alsa_stream=%p, callback=%p\n",
  1193. + alsa_stream, callback);
  1194. + }
  1195. + } else {
  1196. + LOG_ERR(" .. unexpected m.type=%d\n", m.type);
  1197. + }
  1198. + LOG_DBG(" .. OUT\n");
  1199. +}
  1200. +
  1201. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  1202. + VCHI_CONNECTION_T **
  1203. + vchi_connections,
  1204. + uint32_t num_connections)
  1205. +{
  1206. + uint32_t i;
  1207. + AUDIO_INSTANCE_T *instance;
  1208. + int status;
  1209. +
  1210. + LOG_DBG("%s: start", __func__);
  1211. +
  1212. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  1213. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  1214. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  1215. +
  1216. + return NULL;
  1217. + }
  1218. + /* Allocate memory for this instance */
  1219. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  1220. + if (!instance)
  1221. + return NULL;
  1222. +
  1223. + memset(instance, 0, sizeof(*instance));
  1224. + instance->num_connections = num_connections;
  1225. +
  1226. + /* Create a lock for exclusive, serialized VCHI connection access */
  1227. + mutex_init(&instance->vchi_mutex);
  1228. + /* Open the VCHI service connections */
  1229. + for (i = 0; i < num_connections; i++) {
  1230. + SERVICE_CREATION_T params = {
  1231. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  1232. + VC_AUDIO_SERVER_NAME, // 4cc service code
  1233. + vchi_connections[i], // passed in fn pointers
  1234. + 0, // rx fifo size (unused)
  1235. + 0, // tx fifo size (unused)
  1236. + audio_vchi_callback, // service callback
  1237. + instance, // service callback parameter
  1238. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  1239. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  1240. + 0 // want crc check on bulk transfers
  1241. + };
  1242. +
  1243. + LOG_DBG("%s: about to open %i\n", __func__, i);
  1244. + status = vchi_service_open(vchi_instance, &params,
  1245. + &instance->vchi_handle[i]);
  1246. + LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
  1247. + if (status) {
  1248. + LOG_ERR
  1249. + ("%s: failed to open VCHI service connection (status=%d)\n",
  1250. + __func__, status);
  1251. +
  1252. + goto err_close_services;
  1253. + }
  1254. + /* Finished with the service for now */
  1255. + vchi_service_release(instance->vchi_handle[i]);
  1256. + }
  1257. +
  1258. + LOG_DBG("%s: okay\n", __func__);
  1259. + return instance;
  1260. +
  1261. +err_close_services:
  1262. + for (i = 0; i < instance->num_connections; i++) {
  1263. + LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]);
  1264. + if (instance->vchi_handle[i])
  1265. + vchi_service_close(instance->vchi_handle[i]);
  1266. + }
  1267. +
  1268. + kfree(instance);
  1269. + LOG_ERR("%s: error\n", __func__);
  1270. +
  1271. + return NULL;
  1272. +}
  1273. +
  1274. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  1275. +{
  1276. + uint32_t i;
  1277. +
  1278. + LOG_DBG(" .. IN\n");
  1279. +
  1280. + if (instance == NULL) {
  1281. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  1282. +
  1283. + return -1;
  1284. + }
  1285. +
  1286. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  1287. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1288. + {
  1289. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1290. + return -EINTR;
  1291. + }
  1292. +
  1293. + /* Close all VCHI service connections */
  1294. + for (i = 0; i < instance->num_connections; i++) {
  1295. + int32_t success;
  1296. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  1297. + vchi_service_use(instance->vchi_handle[i]);
  1298. +
  1299. + success = vchi_service_close(instance->vchi_handle[i]);
  1300. + if (success != 0) {
  1301. + LOG_DBG
  1302. + ("%s: failed to close VCHI service connection (status=%d)\n",
  1303. + __func__, success);
  1304. + }
  1305. + }
  1306. +
  1307. + mutex_unlock(&instance->vchi_mutex);
  1308. +
  1309. + kfree(instance);
  1310. +
  1311. + LOG_DBG(" .. OUT\n");
  1312. +
  1313. + return 0;
  1314. +}
  1315. +
  1316. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  1317. +{
  1318. + static VCHI_INSTANCE_T vchi_instance;
  1319. + static VCHI_CONNECTION_T *vchi_connection;
  1320. + static int initted;
  1321. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1322. + int ret;
  1323. + LOG_DBG(" .. IN\n");
  1324. +
  1325. + LOG_INFO("%s: start\n", __func__);
  1326. + BUG_ON(instance);
  1327. + if (instance) {
  1328. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  1329. + __func__, instance);
  1330. + instance->alsa_stream = alsa_stream;
  1331. + alsa_stream->instance = instance;
  1332. + ret = 0; // xxx todo -1;
  1333. + goto err_free_mem;
  1334. + }
  1335. +
  1336. + /* Initialize and create a VCHI connection */
  1337. + if (!initted) {
  1338. + ret = vchi_initialise(&vchi_instance);
  1339. + if (ret != 0) {
  1340. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  1341. + __func__, ret);
  1342. +
  1343. + ret = -EIO;
  1344. + goto err_free_mem;
  1345. + }
  1346. + ret = vchi_connect(NULL, 0, vchi_instance);
  1347. + if (ret != 0) {
  1348. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  1349. + __func__, ret);
  1350. +
  1351. + ret = -EIO;
  1352. + goto err_free_mem;
  1353. + }
  1354. + initted = 1;
  1355. + }
  1356. +
  1357. + /* Initialize an instance of the audio service */
  1358. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  1359. +
  1360. + if (instance == NULL) {
  1361. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  1362. +
  1363. + ret = -EPERM;
  1364. + goto err_free_mem;
  1365. + }
  1366. +
  1367. + instance->alsa_stream = alsa_stream;
  1368. + alsa_stream->instance = instance;
  1369. +
  1370. + LOG_DBG(" success !\n");
  1371. +err_free_mem:
  1372. + LOG_DBG(" .. OUT\n");
  1373. +
  1374. + return ret;
  1375. +}
  1376. +
  1377. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  1378. +{
  1379. + AUDIO_INSTANCE_T *instance;
  1380. + VC_AUDIO_MSG_T m;
  1381. + int32_t success;
  1382. + int ret;
  1383. + LOG_DBG(" .. IN\n");
  1384. +
  1385. + my_workqueue_init(alsa_stream);
  1386. +
  1387. + ret = bcm2835_audio_open_connection(alsa_stream);
  1388. + if (ret != 0) {
  1389. + ret = -1;
  1390. + goto exit;
  1391. + }
  1392. + instance = alsa_stream->instance;
  1393. + LOG_DBG(" instance (%p)\n", instance);
  1394. +
  1395. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1396. + {
  1397. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1398. + return -EINTR;
  1399. + }
  1400. + vchi_service_use(instance->vchi_handle[0]);
  1401. +
  1402. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  1403. +
  1404. + /* Send the message to the videocore */
  1405. + success = vchi_msg_queue(instance->vchi_handle[0],
  1406. + &m, sizeof m,
  1407. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1408. +
  1409. + if (success != 0) {
  1410. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1411. + __func__, success);
  1412. +
  1413. + ret = -1;
  1414. + goto unlock;
  1415. + }
  1416. +
  1417. + ret = 0;
  1418. +
  1419. +unlock:
  1420. + vchi_service_release(instance->vchi_handle[0]);
  1421. + mutex_unlock(&instance->vchi_mutex);
  1422. +exit:
  1423. + LOG_DBG(" .. OUT\n");
  1424. + return ret;
  1425. +}
  1426. +
  1427. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  1428. + bcm2835_chip_t * chip)
  1429. +{
  1430. + VC_AUDIO_MSG_T m;
  1431. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1432. + int32_t success;
  1433. + int ret;
  1434. + LOG_DBG(" .. IN\n");
  1435. +
  1436. + LOG_INFO
  1437. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  1438. +
  1439. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1440. + {
  1441. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1442. + return -EINTR;
  1443. + }
  1444. + vchi_service_use(instance->vchi_handle[0]);
  1445. +
  1446. + instance->result = -1;
  1447. +
  1448. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  1449. + m.u.control.dest = chip->dest;
  1450. + m.u.control.volume = chip->volume;
  1451. +
  1452. + /* Create the message available completion */
  1453. + init_completion(&instance->msg_avail_comp);
  1454. +
  1455. + /* Send the message to the videocore */
  1456. + success = vchi_msg_queue(instance->vchi_handle[0],
  1457. + &m, sizeof m,
  1458. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1459. +
  1460. + if (success != 0) {
  1461. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1462. + __func__, success);
  1463. +
  1464. + ret = -1;
  1465. + goto unlock;
  1466. + }
  1467. +
  1468. + /* We are expecting a reply from the videocore */
  1469. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  1470. + if (ret) {
  1471. + LOG_DBG("%s: failed on waiting for event (status=%d)\n",
  1472. + __func__, success);
  1473. + goto unlock;
  1474. + }
  1475. +
  1476. + if (instance->result != 0) {
  1477. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  1478. +
  1479. + ret = -1;
  1480. + goto unlock;
  1481. + }
  1482. +
  1483. + ret = 0;
  1484. +
  1485. +unlock:
  1486. + vchi_service_release(instance->vchi_handle[0]);
  1487. + mutex_unlock(&instance->vchi_mutex);
  1488. +
  1489. + LOG_DBG(" .. OUT\n");
  1490. + return ret;
  1491. +}
  1492. +
  1493. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  1494. +{
  1495. + int i;
  1496. + int ret = 0;
  1497. + LOG_DBG(" .. IN\n");
  1498. + LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  1499. +
  1500. + /* change ctls for all substreams */
  1501. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  1502. + if (chip->avail_substreams & (1 << i)) {
  1503. + if (!chip->alsa_stream[i])
  1504. + {
  1505. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  1506. + ret = 0;
  1507. + }
  1508. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  1509. + (chip->alsa_stream[i], chip) != 0)
  1510. + {
  1511. + LOG_ERR("Couldn't set the controls for stream %d\n", i);
  1512. + ret = -1;
  1513. + }
  1514. + else LOG_DBG(" Controls set for stream %d\n", i);
  1515. + }
  1516. + }
  1517. + LOG_DBG(" .. OUT ret=%d\n", ret);
  1518. + return ret;
  1519. +}
  1520. +
  1521. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  1522. + uint32_t channels, uint32_t samplerate,
  1523. + uint32_t bps)
  1524. +{
  1525. + VC_AUDIO_MSG_T m;
  1526. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1527. + int32_t success;
  1528. + int ret;
  1529. + LOG_DBG(" .. IN\n");
  1530. +
  1531. + LOG_INFO
  1532. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  1533. + channels, samplerate, bps);
  1534. +
  1535. + /* resend ctls - alsa_stream may not have been open when first send */
  1536. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  1537. + if (ret != 0) {
  1538. + LOG_ERR(" Alsa controls not supported\n");
  1539. + return -EINVAL;
  1540. + }
  1541. +
  1542. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1543. + {
  1544. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1545. + return -EINTR;
  1546. + }
  1547. + vchi_service_use(instance->vchi_handle[0]);
  1548. +
  1549. + instance->result = -1;
  1550. +
  1551. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  1552. + m.u.config.channels = channels;
  1553. + m.u.config.samplerate = samplerate;
  1554. + m.u.config.bps = bps;
  1555. +
  1556. + /* Create the message available completion */
  1557. + init_completion(&instance->msg_avail_comp);
  1558. +
  1559. + /* Send the message to the videocore */
  1560. + success = vchi_msg_queue(instance->vchi_handle[0],
  1561. + &m, sizeof m,
  1562. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1563. +
  1564. + if (success != 0) {
  1565. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1566. + __func__, success);
  1567. +
  1568. + ret = -1;
  1569. + goto unlock;
  1570. + }
  1571. +
  1572. + /* We are expecting a reply from the videocore */
  1573. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  1574. + if (ret) {
  1575. + LOG_DBG("%s: failed on waiting for event (status=%d)\n",
  1576. + __func__, success);
  1577. + goto unlock;
  1578. + }
  1579. +
  1580. + if (instance->result != 0) {
  1581. + LOG_ERR("%s: result=%d", __func__, instance->result);
  1582. +
  1583. + ret = -1;
  1584. + goto unlock;
  1585. + }
  1586. +
  1587. + ret = 0;
  1588. +
  1589. +unlock:
  1590. + vchi_service_release(instance->vchi_handle[0]);
  1591. + mutex_unlock(&instance->vchi_mutex);
  1592. +
  1593. + LOG_DBG(" .. OUT\n");
  1594. + return ret;
  1595. +}
  1596. +
  1597. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  1598. +{
  1599. + LOG_DBG(" .. IN\n");
  1600. +
  1601. + LOG_DBG(" .. OUT\n");
  1602. +
  1603. + return 0;
  1604. +}
  1605. +
  1606. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  1607. +{
  1608. + VC_AUDIO_MSG_T m;
  1609. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1610. + int32_t success;
  1611. + int ret;
  1612. + LOG_DBG(" .. IN\n");
  1613. +
  1614. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1615. + {
  1616. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1617. + return -EINTR;
  1618. + }
  1619. + vchi_service_use(instance->vchi_handle[0]);
  1620. +
  1621. + m.type = VC_AUDIO_MSG_TYPE_START;
  1622. +
  1623. + /* Send the message to the videocore */
  1624. + success = vchi_msg_queue(instance->vchi_handle[0],
  1625. + &m, sizeof m,
  1626. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1627. +
  1628. + if (success != 0) {
  1629. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1630. + __func__, success);
  1631. +
  1632. + ret = -1;
  1633. + goto unlock;
  1634. + }
  1635. +
  1636. + ret = 0;
  1637. +
  1638. +unlock:
  1639. + vchi_service_release(instance->vchi_handle[0]);
  1640. + mutex_unlock(&instance->vchi_mutex);
  1641. + LOG_DBG(" .. OUT\n");
  1642. + return ret;
  1643. +}
  1644. +
  1645. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  1646. +{
  1647. + VC_AUDIO_MSG_T m;
  1648. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1649. + int32_t success;
  1650. + int ret;
  1651. + LOG_DBG(" .. IN\n");
  1652. +
  1653. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1654. + {
  1655. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1656. + return -EINTR;
  1657. + }
  1658. + vchi_service_use(instance->vchi_handle[0]);
  1659. +
  1660. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  1661. + m.u.stop.draining = alsa_stream->draining;
  1662. +
  1663. + /* Send the message to the videocore */
  1664. + success = vchi_msg_queue(instance->vchi_handle[0],
  1665. + &m, sizeof m,
  1666. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1667. +
  1668. + if (success != 0) {
  1669. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1670. + __func__, success);
  1671. +
  1672. + ret = -1;
  1673. + goto unlock;
  1674. + }
  1675. +
  1676. + ret = 0;
  1677. +
  1678. +unlock:
  1679. + vchi_service_release(instance->vchi_handle[0]);
  1680. + mutex_unlock(&instance->vchi_mutex);
  1681. + LOG_DBG(" .. OUT\n");
  1682. + return ret;
  1683. +}
  1684. +
  1685. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  1686. +{
  1687. + VC_AUDIO_MSG_T m;
  1688. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1689. + int32_t success;
  1690. + int ret;
  1691. + LOG_DBG(" .. IN\n");
  1692. +
  1693. + my_workqueue_quit(alsa_stream);
  1694. +
  1695. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1696. + {
  1697. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1698. + return -EINTR;
  1699. + }
  1700. + vchi_service_use(instance->vchi_handle[0]);
  1701. +
  1702. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  1703. +
  1704. + /* Create the message available completion */
  1705. + init_completion(&instance->msg_avail_comp);
  1706. +
  1707. + /* Send the message to the videocore */
  1708. + success = vchi_msg_queue(instance->vchi_handle[0],
  1709. + &m, sizeof m,
  1710. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1711. +
  1712. + if (success != 0) {
  1713. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1714. + __func__, success);
  1715. + ret = -1;
  1716. + goto unlock;
  1717. + }
  1718. +
  1719. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  1720. + if (ret) {
  1721. + LOG_DBG("%s: failed on waiting for event (status=%d)\n",
  1722. + __func__, success);
  1723. + goto unlock;
  1724. + }
  1725. + if (instance->result != 0) {
  1726. + LOG_ERR("%s: failed result (status=%d)\n",
  1727. + __func__, instance->result);
  1728. +
  1729. + ret = -1;
  1730. + goto unlock;
  1731. + }
  1732. +
  1733. + ret = 0;
  1734. +
  1735. +unlock:
  1736. + vchi_service_release(instance->vchi_handle[0]);
  1737. + mutex_unlock(&instance->vchi_mutex);
  1738. +
  1739. + /* Stop the audio service */
  1740. + if (instance) {
  1741. + vc_vchi_audio_deinit(instance);
  1742. + alsa_stream->instance = NULL;
  1743. + }
  1744. + LOG_DBG(" .. OUT\n");
  1745. + return ret;
  1746. +}
  1747. +
  1748. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  1749. + uint32_t count, void *src)
  1750. +{
  1751. + VC_AUDIO_MSG_T m;
  1752. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  1753. + int32_t success;
  1754. + int ret;
  1755. +
  1756. + LOG_DBG(" .. IN\n");
  1757. +
  1758. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  1759. +
  1760. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  1761. + {
  1762. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  1763. + return -EINTR;
  1764. + }
  1765. + vchi_service_use(instance->vchi_handle[0]);
  1766. +
  1767. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  1768. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  1769. + }
  1770. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  1771. + m.u.write.count = count;
  1772. + // old version uses bulk, new version uses control
  1773. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  1774. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  1775. + m.u.write.cookie = alsa_stream;
  1776. + m.u.write.silence = src == NULL;
  1777. +
  1778. + /* Send the message to the videocore */
  1779. + success = vchi_msg_queue(instance->vchi_handle[0],
  1780. + &m, sizeof m,
  1781. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1782. +
  1783. + if (success != 0) {
  1784. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  1785. + __func__, success);
  1786. +
  1787. + ret = -1;
  1788. + goto unlock;
  1789. + }
  1790. + if (!m.u.write.silence) {
  1791. + if (m.u.write.max_packet == 0) {
  1792. + /* Send the message to the videocore */
  1793. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  1794. + src, count,
  1795. + 0 *
  1796. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  1797. + +
  1798. + 1 *
  1799. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  1800. + NULL);
  1801. + } else {
  1802. + while (count > 0) {
  1803. + int bytes = min((int)m.u.write.max_packet, (int)count);
  1804. + success = vchi_msg_queue(instance->vchi_handle[0],
  1805. + src, bytes,
  1806. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  1807. + src = (char *)src + bytes;
  1808. + count -= bytes;
  1809. + }
  1810. + }
  1811. + if (success != 0) {
  1812. + LOG_ERR
  1813. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)\n",
  1814. + __func__, success);
  1815. +
  1816. + ret = -1;
  1817. + goto unlock;
  1818. + }
  1819. + }
  1820. + ret = 0;
  1821. +
  1822. +unlock:
  1823. + vchi_service_release(instance->vchi_handle[0]);
  1824. + mutex_unlock(&instance->vchi_mutex);
  1825. + LOG_DBG(" .. OUT\n");
  1826. + return ret;
  1827. +}
  1828. +
  1829. +/**
  1830. + * Returns all buffers from arm->vc
  1831. + */
  1832. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  1833. +{
  1834. + LOG_DBG(" .. IN\n");
  1835. + LOG_DBG(" .. OUT\n");
  1836. + return;
  1837. +}
  1838. +
  1839. +/**
  1840. + * Forces VC to flush(drop) its filled playback buffers and
  1841. + * return them the us. (VC->ARM)
  1842. + */
  1843. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  1844. +{
  1845. + LOG_DBG(" .. IN\n");
  1846. + LOG_DBG(" .. OUT\n");
  1847. +}
  1848. +
  1849. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  1850. +{
  1851. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  1852. + atomic_sub(count, &alsa_stream->retrieved);
  1853. + return count;
  1854. +}
  1855. +
  1856. +module_param(force_bulk, bool, 0444);
  1857. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  1858. --- /dev/null
  1859. +++ b/sound/arm/bcm2835.c
  1860. @@ -0,0 +1,511 @@
  1861. +/*****************************************************************************
  1862. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  1863. +*
  1864. +* Unless you and Broadcom execute a separate written software license
  1865. +* agreement governing use of this software, this software is licensed to you
  1866. +* under the terms of the GNU General Public License version 2, available at
  1867. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  1868. +*
  1869. +* Notwithstanding the above, under no circumstances may you combine this
  1870. +* software in any way with any other Broadcom software provided under a
  1871. +* license other than the GPL, without Broadcom's express prior written
  1872. +* consent.
  1873. +*****************************************************************************/
  1874. +
  1875. +#include <linux/platform_device.h>
  1876. +
  1877. +#include <linux/init.h>
  1878. +#include <linux/slab.h>
  1879. +#include <linux/module.h>
  1880. +#include <linux/of.h>
  1881. +
  1882. +#include "bcm2835.h"
  1883. +
  1884. +/* module parameters (see "Module Parameters") */
  1885. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  1886. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  1887. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  1888. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  1889. +
  1890. +/* HACKY global pointers needed for successive probes to work : ssp
  1891. + * But compared against the changes we will have to do in VC audio_ipc code
  1892. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  1893. + * four devices in a thread, this gets things done quickly and should be easier
  1894. + * to debug if we run into issues
  1895. + */
  1896. +
  1897. +static struct snd_card *g_card = NULL;
  1898. +static bcm2835_chip_t *g_chip = NULL;
  1899. +
  1900. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  1901. +{
  1902. + kfree(chip);
  1903. + return 0;
  1904. +}
  1905. +
  1906. +/* component-destructor
  1907. + * (see "Management of Cards and Components")
  1908. + */
  1909. +static int snd_bcm2835_dev_free(struct snd_device *device)
  1910. +{
  1911. + return snd_bcm2835_free(device->device_data);
  1912. +}
  1913. +
  1914. +/* chip-specific constructor
  1915. + * (see "Management of Cards and Components")
  1916. + */
  1917. +static int snd_bcm2835_create(struct snd_card *card,
  1918. + struct platform_device *pdev,
  1919. + bcm2835_chip_t ** rchip)
  1920. +{
  1921. + bcm2835_chip_t *chip;
  1922. + int err;
  1923. + static struct snd_device_ops ops = {
  1924. + .dev_free = snd_bcm2835_dev_free,
  1925. + };
  1926. +
  1927. + *rchip = NULL;
  1928. +
  1929. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1930. + if (chip == NULL)
  1931. + return -ENOMEM;
  1932. +
  1933. + chip->card = card;
  1934. +
  1935. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  1936. + if (err < 0) {
  1937. + snd_bcm2835_free(chip);
  1938. + return err;
  1939. + }
  1940. +
  1941. + *rchip = chip;
  1942. + return 0;
  1943. +}
  1944. +
  1945. +static int snd_bcm2835_alsa_probe_dt(struct platform_device *pdev)
  1946. +{
  1947. + struct device *dev = &pdev->dev;
  1948. + bcm2835_chip_t *chip;
  1949. + struct snd_card *card;
  1950. + u32 numchans;
  1951. + int err, i;
  1952. +
  1953. + err = of_property_read_u32(dev->of_node, "brcm,pwm-channels",
  1954. + &numchans);
  1955. + if (err) {
  1956. + dev_err(dev, "Failed to get DT property 'brcm,pwm-channels'");
  1957. + return err;
  1958. + }
  1959. +
  1960. + if (numchans == 0 || numchans > MAX_SUBSTREAMS) {
  1961. + numchans = MAX_SUBSTREAMS;
  1962. + dev_warn(dev, "Illegal 'brcm,pwm-channels' value, will use %u\n",
  1963. + numchans);
  1964. + }
  1965. +
  1966. + err = snd_card_new(NULL, -1, NULL, THIS_MODULE, 0, &card);
  1967. + if (err) {
  1968. + dev_err(dev, "Failed to create soundcard structure\n");
  1969. + return err;
  1970. + }
  1971. +
  1972. + snd_card_set_dev(card, dev);
  1973. + strcpy(card->driver, "bcm2835");
  1974. + strcpy(card->shortname, "bcm2835 ALSA");
  1975. + sprintf(card->longname, "%s", card->shortname);
  1976. +
  1977. + err = snd_bcm2835_create(card, pdev, &chip);
  1978. + if (err < 0) {
  1979. + dev_err(dev, "Failed to create bcm2835 chip\n");
  1980. + goto err_free;
  1981. + }
  1982. +
  1983. + err = snd_bcm2835_new_pcm(chip);
  1984. + if (err < 0) {
  1985. + dev_err(dev, "Failed to create new bcm2835 pcm device\n");
  1986. + goto err_free;
  1987. + }
  1988. +
  1989. + err = snd_bcm2835_new_spdif_pcm(chip);
  1990. + if (err < 0) {
  1991. + dev_err(dev, "Failed to create new bcm2835 spdif pcm device\n");
  1992. + goto err_free;
  1993. + }
  1994. +
  1995. + err = snd_bcm2835_new_ctl(chip);
  1996. + if (err < 0) {
  1997. + dev_err(dev, "Failed to create new bcm2835 ctl\n");
  1998. + goto err_free;
  1999. + }
  2000. +
  2001. + for (i = 0; i < numchans; i++) {
  2002. + chip->avail_substreams |= (1 << i);
  2003. + chip->pdev[i] = pdev;
  2004. + }
  2005. +
  2006. + err = snd_card_register(card);
  2007. + if (err) {
  2008. + dev_err(dev, "Failed to register bcm2835 ALSA card \n");
  2009. + goto err_free;
  2010. + }
  2011. +
  2012. + g_card = card;
  2013. + g_chip = chip;
  2014. + platform_set_drvdata(pdev, card);
  2015. + audio_info("bcm2835 ALSA card created with %u channels\n", numchans);
  2016. +
  2017. + return 0;
  2018. +
  2019. +err_free:
  2020. + snd_card_free(card);
  2021. +
  2022. + return err;
  2023. +}
  2024. +
  2025. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  2026. +{
  2027. + static int dev;
  2028. + bcm2835_chip_t *chip;
  2029. + struct snd_card *card;
  2030. + int err;
  2031. +
  2032. + if (pdev->dev.of_node)
  2033. + return snd_bcm2835_alsa_probe_dt(pdev);
  2034. +
  2035. + if (dev >= MAX_SUBSTREAMS)
  2036. + return -ENODEV;
  2037. +
  2038. + if (!enable[dev]) {
  2039. + dev++;
  2040. + return -ENOENT;
  2041. + }
  2042. +
  2043. + if (dev > 0)
  2044. + goto add_register_map;
  2045. +
  2046. + err = snd_card_new(NULL, index[dev], id[dev], THIS_MODULE, 0, &g_card);
  2047. + if (err < 0)
  2048. + goto out;
  2049. +
  2050. + snd_card_set_dev(g_card, &pdev->dev);
  2051. + strcpy(g_card->driver, "bcm2835");
  2052. + strcpy(g_card->shortname, "bcm2835 ALSA");
  2053. + sprintf(g_card->longname, "%s", g_card->shortname);
  2054. +
  2055. + err = snd_bcm2835_create(g_card, pdev, &chip);
  2056. + if (err < 0) {
  2057. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  2058. + goto out_bcm2835_create;
  2059. + }
  2060. +
  2061. + g_chip = chip;
  2062. + err = snd_bcm2835_new_pcm(chip);
  2063. + if (err < 0) {
  2064. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  2065. + goto out_bcm2835_new_pcm;
  2066. + }
  2067. +
  2068. + err = snd_bcm2835_new_spdif_pcm(chip);
  2069. + if (err < 0) {
  2070. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  2071. + goto out_bcm2835_new_spdif;
  2072. + }
  2073. +
  2074. + err = snd_bcm2835_new_ctl(chip);
  2075. + if (err < 0) {
  2076. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  2077. + goto out_bcm2835_new_ctl;
  2078. + }
  2079. +
  2080. +add_register_map:
  2081. + card = g_card;
  2082. + chip = g_chip;
  2083. +
  2084. + BUG_ON(!(card && chip));
  2085. +
  2086. + chip->avail_substreams |= (1 << dev);
  2087. + chip->pdev[dev] = pdev;
  2088. +
  2089. + if (dev == 0) {
  2090. + err = snd_card_register(card);
  2091. + if (err < 0) {
  2092. + dev_err(&pdev->dev,
  2093. + "Failed to register bcm2835 ALSA card \n");
  2094. + goto out_card_register;
  2095. + }
  2096. + platform_set_drvdata(pdev, card);
  2097. + audio_info("bcm2835 ALSA card created!\n");
  2098. + } else {
  2099. + audio_info("bcm2835 ALSA chip created!\n");
  2100. + platform_set_drvdata(pdev, (void *)dev);
  2101. + }
  2102. +
  2103. + dev++;
  2104. +
  2105. + return 0;
  2106. +
  2107. +out_card_register:
  2108. +out_bcm2835_new_ctl:
  2109. +out_bcm2835_new_spdif:
  2110. +out_bcm2835_new_pcm:
  2111. +out_bcm2835_create:
  2112. + BUG_ON(!g_card);
  2113. + if (snd_card_free(g_card))
  2114. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  2115. + g_card = NULL;
  2116. +out:
  2117. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  2118. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  2119. + return err;
  2120. +}
  2121. +
  2122. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  2123. +{
  2124. + uint32_t idx;
  2125. + void *drv_data;
  2126. +
  2127. + drv_data = platform_get_drvdata(pdev);
  2128. +
  2129. + if (drv_data == (void *)g_card) {
  2130. + /* This is the card device */
  2131. + snd_card_free((struct snd_card *)drv_data);
  2132. + g_card = NULL;
  2133. + g_chip = NULL;
  2134. + } else {
  2135. + idx = (uint32_t) drv_data;
  2136. + if (g_card != NULL) {
  2137. + BUG_ON(!g_chip);
  2138. + /* We pass chip device numbers in audio ipc devices
  2139. + * other than the one we registered our card with
  2140. + */
  2141. + idx = (uint32_t) drv_data;
  2142. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  2143. + g_chip->avail_substreams &= ~(1 << idx);
  2144. + /* There should be atleast one substream registered
  2145. + * after we are done here, as it wil be removed when
  2146. + * the *remove* is called for the card device
  2147. + */
  2148. + BUG_ON(!g_chip->avail_substreams);
  2149. + }
  2150. + }
  2151. +
  2152. + platform_set_drvdata(pdev, NULL);
  2153. +
  2154. + return 0;
  2155. +}
  2156. +
  2157. +#ifdef CONFIG_PM
  2158. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  2159. + pm_message_t state)
  2160. +{
  2161. + return 0;
  2162. +}
  2163. +
  2164. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  2165. +{
  2166. + return 0;
  2167. +}
  2168. +
  2169. +#endif
  2170. +
  2171. +static const struct of_device_id snd_bcm2835_of_match_table[] = {
  2172. + { .compatible = "brcm,bcm2835-audio", },
  2173. + {},
  2174. +};
  2175. +MODULE_DEVICE_TABLE(of, snd_bcm2835_of_match_table);
  2176. +
  2177. +static struct platform_driver bcm2835_alsa0_driver = {
  2178. + .probe = snd_bcm2835_alsa_probe,
  2179. + .remove = snd_bcm2835_alsa_remove,
  2180. +#ifdef CONFIG_PM
  2181. + .suspend = snd_bcm2835_alsa_suspend,
  2182. + .resume = snd_bcm2835_alsa_resume,
  2183. +#endif
  2184. + .driver = {
  2185. + .name = "bcm2835_AUD0",
  2186. + .owner = THIS_MODULE,
  2187. + .of_match_table = snd_bcm2835_of_match_table,
  2188. + },
  2189. +};
  2190. +
  2191. +static struct platform_driver bcm2835_alsa1_driver = {
  2192. + .probe = snd_bcm2835_alsa_probe,
  2193. + .remove = snd_bcm2835_alsa_remove,
  2194. +#ifdef CONFIG_PM
  2195. + .suspend = snd_bcm2835_alsa_suspend,
  2196. + .resume = snd_bcm2835_alsa_resume,
  2197. +#endif
  2198. + .driver = {
  2199. + .name = "bcm2835_AUD1",
  2200. + .owner = THIS_MODULE,
  2201. + },
  2202. +};
  2203. +
  2204. +static struct platform_driver bcm2835_alsa2_driver = {
  2205. + .probe = snd_bcm2835_alsa_probe,
  2206. + .remove = snd_bcm2835_alsa_remove,
  2207. +#ifdef CONFIG_PM
  2208. + .suspend = snd_bcm2835_alsa_suspend,
  2209. + .resume = snd_bcm2835_alsa_resume,
  2210. +#endif
  2211. + .driver = {
  2212. + .name = "bcm2835_AUD2",
  2213. + .owner = THIS_MODULE,
  2214. + },
  2215. +};
  2216. +
  2217. +static struct platform_driver bcm2835_alsa3_driver = {
  2218. + .probe = snd_bcm2835_alsa_probe,
  2219. + .remove = snd_bcm2835_alsa_remove,
  2220. +#ifdef CONFIG_PM
  2221. + .suspend = snd_bcm2835_alsa_suspend,
  2222. + .resume = snd_bcm2835_alsa_resume,
  2223. +#endif
  2224. + .driver = {
  2225. + .name = "bcm2835_AUD3",
  2226. + .owner = THIS_MODULE,
  2227. + },
  2228. +};
  2229. +
  2230. +static struct platform_driver bcm2835_alsa4_driver = {
  2231. + .probe = snd_bcm2835_alsa_probe,
  2232. + .remove = snd_bcm2835_alsa_remove,
  2233. +#ifdef CONFIG_PM
  2234. + .suspend = snd_bcm2835_alsa_suspend,
  2235. + .resume = snd_bcm2835_alsa_resume,
  2236. +#endif
  2237. + .driver = {
  2238. + .name = "bcm2835_AUD4",
  2239. + .owner = THIS_MODULE,
  2240. + },
  2241. +};
  2242. +
  2243. +static struct platform_driver bcm2835_alsa5_driver = {
  2244. + .probe = snd_bcm2835_alsa_probe,
  2245. + .remove = snd_bcm2835_alsa_remove,
  2246. +#ifdef CONFIG_PM
  2247. + .suspend = snd_bcm2835_alsa_suspend,
  2248. + .resume = snd_bcm2835_alsa_resume,
  2249. +#endif
  2250. + .driver = {
  2251. + .name = "bcm2835_AUD5",
  2252. + .owner = THIS_MODULE,
  2253. + },
  2254. +};
  2255. +
  2256. +static struct platform_driver bcm2835_alsa6_driver = {
  2257. + .probe = snd_bcm2835_alsa_probe,
  2258. + .remove = snd_bcm2835_alsa_remove,
  2259. +#ifdef CONFIG_PM
  2260. + .suspend = snd_bcm2835_alsa_suspend,
  2261. + .resume = snd_bcm2835_alsa_resume,
  2262. +#endif
  2263. + .driver = {
  2264. + .name = "bcm2835_AUD6",
  2265. + .owner = THIS_MODULE,
  2266. + },
  2267. +};
  2268. +
  2269. +static struct platform_driver bcm2835_alsa7_driver = {
  2270. + .probe = snd_bcm2835_alsa_probe,
  2271. + .remove = snd_bcm2835_alsa_remove,
  2272. +#ifdef CONFIG_PM
  2273. + .suspend = snd_bcm2835_alsa_suspend,
  2274. + .resume = snd_bcm2835_alsa_resume,
  2275. +#endif
  2276. + .driver = {
  2277. + .name = "bcm2835_AUD7",
  2278. + .owner = THIS_MODULE,
  2279. + },
  2280. +};
  2281. +
  2282. +static int bcm2835_alsa_device_init(void)
  2283. +{
  2284. + int err;
  2285. + err = platform_driver_register(&bcm2835_alsa0_driver);
  2286. + if (err) {
  2287. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2288. + goto out;
  2289. + }
  2290. +
  2291. + err = platform_driver_register(&bcm2835_alsa1_driver);
  2292. + if (err) {
  2293. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2294. + goto unregister_0;
  2295. + }
  2296. +
  2297. + err = platform_driver_register(&bcm2835_alsa2_driver);
  2298. + if (err) {
  2299. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2300. + goto unregister_1;
  2301. + }
  2302. +
  2303. + err = platform_driver_register(&bcm2835_alsa3_driver);
  2304. + if (err) {
  2305. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2306. + goto unregister_2;
  2307. + }
  2308. +
  2309. + err = platform_driver_register(&bcm2835_alsa4_driver);
  2310. + if (err) {
  2311. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2312. + goto unregister_3;
  2313. + }
  2314. +
  2315. + err = platform_driver_register(&bcm2835_alsa5_driver);
  2316. + if (err) {
  2317. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2318. + goto unregister_4;
  2319. + }
  2320. +
  2321. + err = platform_driver_register(&bcm2835_alsa6_driver);
  2322. + if (err) {
  2323. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2324. + goto unregister_5;
  2325. + }
  2326. +
  2327. + err = platform_driver_register(&bcm2835_alsa7_driver);
  2328. + if (err) {
  2329. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  2330. + goto unregister_6;
  2331. + }
  2332. +
  2333. + return 0;
  2334. +
  2335. +unregister_6:
  2336. + platform_driver_unregister(&bcm2835_alsa6_driver);
  2337. +unregister_5:
  2338. + platform_driver_unregister(&bcm2835_alsa5_driver);
  2339. +unregister_4:
  2340. + platform_driver_unregister(&bcm2835_alsa4_driver);
  2341. +unregister_3:
  2342. + platform_driver_unregister(&bcm2835_alsa3_driver);
  2343. +unregister_2:
  2344. + platform_driver_unregister(&bcm2835_alsa2_driver);
  2345. +unregister_1:
  2346. + platform_driver_unregister(&bcm2835_alsa1_driver);
  2347. +unregister_0:
  2348. + platform_driver_unregister(&bcm2835_alsa0_driver);
  2349. +out:
  2350. + return err;
  2351. +}
  2352. +
  2353. +static void bcm2835_alsa_device_exit(void)
  2354. +{
  2355. + platform_driver_unregister(&bcm2835_alsa0_driver);
  2356. + platform_driver_unregister(&bcm2835_alsa1_driver);
  2357. + platform_driver_unregister(&bcm2835_alsa2_driver);
  2358. + platform_driver_unregister(&bcm2835_alsa3_driver);
  2359. + platform_driver_unregister(&bcm2835_alsa4_driver);
  2360. + platform_driver_unregister(&bcm2835_alsa5_driver);
  2361. + platform_driver_unregister(&bcm2835_alsa6_driver);
  2362. + platform_driver_unregister(&bcm2835_alsa7_driver);
  2363. +}
  2364. +
  2365. +late_initcall(bcm2835_alsa_device_init);
  2366. +module_exit(bcm2835_alsa_device_exit);
  2367. +
  2368. +MODULE_AUTHOR("Dom Cobley");
  2369. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  2370. +MODULE_LICENSE("GPL");
  2371. +MODULE_ALIAS("platform:bcm2835_alsa");
  2372. --- /dev/null
  2373. +++ b/sound/arm/bcm2835.h
  2374. @@ -0,0 +1,167 @@
  2375. +/*****************************************************************************
  2376. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  2377. +*
  2378. +* Unless you and Broadcom execute a separate written software license
  2379. +* agreement governing use of this software, this software is licensed to you
  2380. +* under the terms of the GNU General Public License version 2, available at
  2381. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  2382. +*
  2383. +* Notwithstanding the above, under no circumstances may you combine this
  2384. +* software in any way with any other Broadcom software provided under a
  2385. +* license other than the GPL, without Broadcom's express prior written
  2386. +* consent.
  2387. +*****************************************************************************/
  2388. +
  2389. +#ifndef __SOUND_ARM_BCM2835_H
  2390. +#define __SOUND_ARM_BCM2835_H
  2391. +
  2392. +#include <linux/device.h>
  2393. +#include <linux/list.h>
  2394. +#include <linux/interrupt.h>
  2395. +#include <linux/wait.h>
  2396. +#include <sound/core.h>
  2397. +#include <sound/initval.h>
  2398. +#include <sound/pcm.h>
  2399. +#include <sound/pcm_params.h>
  2400. +#include <sound/pcm-indirect.h>
  2401. +#include <linux/workqueue.h>
  2402. +
  2403. +/*
  2404. +#define AUDIO_DEBUG_ENABLE
  2405. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  2406. +*/
  2407. +
  2408. +/* Debug macros */
  2409. +
  2410. +#ifdef AUDIO_DEBUG_ENABLE
  2411. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  2412. +
  2413. +#define audio_debug(fmt, arg...) \
  2414. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  2415. +
  2416. +#define audio_info(fmt, arg...) \
  2417. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  2418. +
  2419. +#else
  2420. +
  2421. +#define audio_debug(fmt, arg...)
  2422. +
  2423. +#define audio_info(fmt, arg...)
  2424. +
  2425. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  2426. +
  2427. +#else
  2428. +
  2429. +#define audio_debug(fmt, arg...)
  2430. +
  2431. +#define audio_info(fmt, arg...)
  2432. +
  2433. +#endif /* AUDIO_DEBUG_ENABLE */
  2434. +
  2435. +#define audio_error(fmt, arg...) \
  2436. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  2437. +
  2438. +#define audio_warning(fmt, arg...) \
  2439. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  2440. +
  2441. +#define audio_alert(fmt, arg...) \
  2442. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  2443. +
  2444. +#define MAX_SUBSTREAMS (8)
  2445. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  2446. +enum {
  2447. + CTRL_VOL_MUTE,
  2448. + CTRL_VOL_UNMUTE
  2449. +};
  2450. +
  2451. +/* macros for alsa2chip and chip2alsa, instead of functions */
  2452. +
  2453. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  2454. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  2455. +
  2456. +/* Some constants for values .. */
  2457. +typedef enum {
  2458. + AUDIO_DEST_AUTO = 0,
  2459. + AUDIO_DEST_HEADPHONES = 1,
  2460. + AUDIO_DEST_HDMI = 2,
  2461. + AUDIO_DEST_MAX,
  2462. +} SND_BCM2835_ROUTE_T;
  2463. +
  2464. +typedef enum {
  2465. + PCM_PLAYBACK_VOLUME,
  2466. + PCM_PLAYBACK_MUTE,
  2467. + PCM_PLAYBACK_DEVICE,
  2468. +} SND_BCM2835_CTRL_T;
  2469. +
  2470. +/* definition of the chip-specific record */
  2471. +typedef struct bcm2835_chip {
  2472. + struct snd_card *card;
  2473. + struct snd_pcm *pcm;
  2474. + struct snd_pcm *pcm_spdif;
  2475. + /* Bitmat for valid reg_base and irq numbers */
  2476. + uint32_t avail_substreams;
  2477. + struct platform_device *pdev[MAX_SUBSTREAMS];
  2478. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  2479. +
  2480. + int volume;
  2481. + int old_volume; /* stores the volume value whist muted */
  2482. + int dest;
  2483. + int mute;
  2484. +
  2485. + unsigned int opened;
  2486. + unsigned int spdif_status;
  2487. + struct mutex audio_mutex;
  2488. +} bcm2835_chip_t;
  2489. +
  2490. +typedef struct bcm2835_alsa_stream {
  2491. + bcm2835_chip_t *chip;
  2492. + struct snd_pcm_substream *substream;
  2493. + struct snd_pcm_indirect pcm_indirect;
  2494. +
  2495. + struct semaphore buffers_update_sem;
  2496. + struct semaphore control_sem;
  2497. + spinlock_t lock;
  2498. + volatile uint32_t control;
  2499. + volatile uint32_t status;
  2500. +
  2501. + int open;
  2502. + int running;
  2503. + int draining;
  2504. +
  2505. + int channels;
  2506. + int params_rate;
  2507. + int pcm_format_width;
  2508. +
  2509. + unsigned int pos;
  2510. + unsigned int buffer_size;
  2511. + unsigned int period_size;
  2512. +
  2513. + uint32_t enable_fifo_irq;
  2514. + irq_handler_t fifo_irq_handler;
  2515. +
  2516. + atomic_t retrieved;
  2517. + struct opaque_AUDIO_INSTANCE_T *instance;
  2518. + struct workqueue_struct *my_wq;
  2519. + int idx;
  2520. +} bcm2835_alsa_stream_t;
  2521. +
  2522. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  2523. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  2524. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  2525. +
  2526. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  2527. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  2528. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  2529. + uint32_t channels, uint32_t samplerate,
  2530. + uint32_t bps);
  2531. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  2532. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  2533. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  2534. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  2535. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  2536. + void *src);
  2537. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  2538. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  2539. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  2540. +
  2541. +#endif /* __SOUND_ARM_BCM2835_H */
  2542. --- /dev/null
  2543. +++ b/sound/arm/vc_vchi_audioserv_defs.h
  2544. @@ -0,0 +1,116 @@
  2545. +/*****************************************************************************
  2546. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  2547. +*
  2548. +* Unless you and Broadcom execute a separate written software license
  2549. +* agreement governing use of this software, this software is licensed to you
  2550. +* under the terms of the GNU General Public License version 2, available at
  2551. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  2552. +*
  2553. +* Notwithstanding the above, under no circumstances may you combine this
  2554. +* software in any way with any other Broadcom software provided under a
  2555. +* license other than the GPL, without Broadcom's express prior written
  2556. +* consent.
  2557. +*****************************************************************************/
  2558. +
  2559. +#ifndef _VC_AUDIO_DEFS_H_
  2560. +#define _VC_AUDIO_DEFS_H_
  2561. +
  2562. +#define VC_AUDIOSERV_MIN_VER 1
  2563. +#define VC_AUDIOSERV_VER 2
  2564. +
  2565. +// FourCC code used for VCHI connection
  2566. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  2567. +
  2568. +// Maximum message length
  2569. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  2570. +
  2571. +// List of screens that are currently supported
  2572. +// All message types supported for HOST->VC direction
  2573. +typedef enum {
  2574. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  2575. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  2576. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  2577. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  2578. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  2579. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  2580. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  2581. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  2582. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  2583. + VC_AUDIO_MSG_TYPE_MAX
  2584. +} VC_AUDIO_MSG_TYPE;
  2585. +
  2586. +// configure the audio
  2587. +typedef struct {
  2588. + uint32_t channels;
  2589. + uint32_t samplerate;
  2590. + uint32_t bps;
  2591. +
  2592. +} VC_AUDIO_CONFIG_T;
  2593. +
  2594. +typedef struct {
  2595. + uint32_t volume;
  2596. + uint32_t dest;
  2597. +
  2598. +} VC_AUDIO_CONTROL_T;
  2599. +
  2600. +// audio
  2601. +typedef struct {
  2602. + uint32_t dummy;
  2603. +
  2604. +} VC_AUDIO_OPEN_T;
  2605. +
  2606. +// audio
  2607. +typedef struct {
  2608. + uint32_t dummy;
  2609. +
  2610. +} VC_AUDIO_CLOSE_T;
  2611. +// audio
  2612. +typedef struct {
  2613. + uint32_t dummy;
  2614. +
  2615. +} VC_AUDIO_START_T;
  2616. +// audio
  2617. +typedef struct {
  2618. + uint32_t draining;
  2619. +
  2620. +} VC_AUDIO_STOP_T;
  2621. +
  2622. +// configure the write audio samples
  2623. +typedef struct {
  2624. + uint32_t count; // in bytes
  2625. + void *callback;
  2626. + void *cookie;
  2627. + uint16_t silence;
  2628. + uint16_t max_packet;
  2629. +} VC_AUDIO_WRITE_T;
  2630. +
  2631. +// Generic result for a request (VC->HOST)
  2632. +typedef struct {
  2633. + int32_t success; // Success value
  2634. +
  2635. +} VC_AUDIO_RESULT_T;
  2636. +
  2637. +// Generic result for a request (VC->HOST)
  2638. +typedef struct {
  2639. + int32_t count; // Success value
  2640. + void *callback;
  2641. + void *cookie;
  2642. +} VC_AUDIO_COMPLETE_T;
  2643. +
  2644. +// Message header for all messages in HOST->VC direction
  2645. +typedef struct {
  2646. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  2647. + union {
  2648. + VC_AUDIO_CONFIG_T config;
  2649. + VC_AUDIO_CONTROL_T control;
  2650. + VC_AUDIO_OPEN_T open;
  2651. + VC_AUDIO_CLOSE_T close;
  2652. + VC_AUDIO_START_T start;
  2653. + VC_AUDIO_STOP_T stop;
  2654. + VC_AUDIO_WRITE_T write;
  2655. + VC_AUDIO_RESULT_T result;
  2656. + VC_AUDIO_COMPLETE_T complete;
  2657. + } u;
  2658. +} VC_AUDIO_MSG_T;
  2659. +
  2660. +#endif // _VC_AUDIO_DEFS_H_