0030-ASoC-Add-support-for-BCM2708.patch 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. From ec589c88e88452a80a20ad4ebc90e8fe5d80e7cd Mon Sep 17 00:00:00 2001
  2. From: Florian Meier <florian.meier@koalo.de>
  3. Date: Fri, 22 Nov 2013 14:33:38 +0100
  4. Subject: [PATCH 030/114] ASoC: Add support for BCM2708
  5. This driver adds support for digital audio (I2S)
  6. for the BCM2708 SoC that is used by the
  7. Raspberry Pi. External audio codecs can be
  8. connected to the Raspberry Pi via P5 header.
  9. It relies on cyclic DMA engine support for BCM2708.
  10. Signed-off-by: Florian Meier <florian.meier@koalo.de>
  11. ASoC: BCM2708: Add 24 bit support
  12. This adds 24 bit support to the I2S driver of the BCM2708.
  13. Besides enabling the 24 bit flags, it includes two bug fixes:
  14. MMAP is not supported. Claiming this leads to strange issues
  15. when the format of driver and file do not match.
  16. The datasheet states that the width extension bit should be set
  17. for widths greater than 24, but greater or equal would be correct.
  18. This follows from the definition of the width field.
  19. Signed-off-by: Florian Meier <florian.meier@koalo.de>
  20. bcm2708-i2s: Update bclk_ratio to more correct values
  21. Move GPIO setup to hw_params.
  22. This is used to stop the I2S driver from breaking
  23. the GPIO setup for other uses of the PCM interface
  24. Configure GPIOs for I2S based on revision/card settings
  25. With RPi model B+, assignment of the I2S GPIO pins has changed.
  26. This patch uses the board revision to auto-detect the GPIOs used
  27. for I2S. It also allows sound card drivers to set the GPIOs that
  28. should be used. This is especially important with the Compute
  29. Module.
  30. bcm2708-i2s: Avoid leak from iomap when accessing gpio
  31. bcm2708: Eliminate i2s debugfs directory error
  32. Qualify the two regmap ranges uses by bcm2708-i2s ('-i2s' and '-clk')
  33. to avoid the name clash when registering debugfs entries.
  34. ---
  35. sound/soc/bcm/Kconfig | 11 +
  36. sound/soc/bcm/Makefile | 4 +
  37. sound/soc/bcm/bcm2708-i2s.c | 998 ++++++++++++++++++++++++++++++++++++++++++++
  38. sound/soc/bcm/bcm2708-i2s.h | 35 ++
  39. 4 files changed, 1048 insertions(+)
  40. create mode 100644 sound/soc/bcm/bcm2708-i2s.c
  41. create mode 100644 sound/soc/bcm/bcm2708-i2s.h
  42. --- a/sound/soc/bcm/Kconfig
  43. +++ b/sound/soc/bcm/Kconfig
  44. @@ -7,3 +7,14 @@ config SND_BCM2835_SOC_I2S
  45. Say Y or M if you want to add support for codecs attached to
  46. the BCM2835 I2S interface. You will also need
  47. to select the audio interfaces to support below.
  48. +
  49. +config SND_BCM2708_SOC_I2S
  50. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  51. + depends on MACH_BCM2708
  52. + select REGMAP_MMIO
  53. + select SND_SOC_DMAENGINE_PCM
  54. + select SND_SOC_GENERIC_DMAENGINE_PCM
  55. + help
  56. + Say Y or M if you want to add support for codecs attached to
  57. + the BCM2708 I2S interface. You will also need
  58. + to select the audio interfaces to support below.
  59. --- a/sound/soc/bcm/Makefile
  60. +++ b/sound/soc/bcm/Makefile
  61. @@ -3,3 +3,7 @@ snd-soc-bcm2835-i2s-objs := bcm2835-i2s.
  62. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  63. +# BCM2708 Platform Support
  64. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  65. +
  66. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  67. --- /dev/null
  68. +++ b/sound/soc/bcm/bcm2708-i2s.c
  69. @@ -0,0 +1,998 @@
  70. +/*
  71. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  72. + *
  73. + * Author: Florian Meier <florian.meier@koalo.de>
  74. + * Copyright 2013
  75. + *
  76. + * Based on
  77. + * Raspberry Pi PCM I2S ALSA Driver
  78. + * Copyright (c) by Phil Poole 2013
  79. + *
  80. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  81. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  82. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  83. + *
  84. + * OMAP ALSA SoC DAI driver using McBSP port
  85. + * Copyright (C) 2008 Nokia Corporation
  86. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  87. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  88. + *
  89. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  90. + * Author: Timur Tabi <timur@freescale.com>
  91. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  92. + *
  93. + * This program is free software; you can redistribute it and/or
  94. + * modify it under the terms of the GNU General Public License
  95. + * version 2 as published by the Free Software Foundation.
  96. + *
  97. + * This program is distributed in the hope that it will be useful, but
  98. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  99. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100. + * General Public License for more details.
  101. + */
  102. +
  103. +#include "bcm2708-i2s.h"
  104. +
  105. +#include <linux/init.h>
  106. +#include <linux/module.h>
  107. +#include <linux/device.h>
  108. +#include <linux/slab.h>
  109. +#include <linux/delay.h>
  110. +#include <linux/io.h>
  111. +#include <linux/clk.h>
  112. +#include <mach/gpio.h>
  113. +
  114. +#include <sound/core.h>
  115. +#include <sound/pcm.h>
  116. +#include <sound/pcm_params.h>
  117. +#include <sound/initval.h>
  118. +#include <sound/soc.h>
  119. +#include <sound/dmaengine_pcm.h>
  120. +
  121. +#include <asm/system_info.h>
  122. +
  123. +/* Clock registers */
  124. +#define BCM2708_CLK_PCMCTL_REG 0x00
  125. +#define BCM2708_CLK_PCMDIV_REG 0x04
  126. +
  127. +/* Clock register settings */
  128. +#define BCM2708_CLK_PASSWD (0x5a000000)
  129. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  130. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  131. +#define BCM2708_CLK_FLIP BIT(8)
  132. +#define BCM2708_CLK_BUSY BIT(7)
  133. +#define BCM2708_CLK_KILL BIT(5)
  134. +#define BCM2708_CLK_ENAB BIT(4)
  135. +#define BCM2708_CLK_SRC(v) (v)
  136. +
  137. +#define BCM2708_CLK_SHIFT (12)
  138. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  139. +#define BCM2708_CLK_DIVF(v) (v)
  140. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  141. +
  142. +enum {
  143. + BCM2708_CLK_MASH_0 = 0,
  144. + BCM2708_CLK_MASH_1,
  145. + BCM2708_CLK_MASH_2,
  146. + BCM2708_CLK_MASH_3,
  147. +};
  148. +
  149. +enum {
  150. + BCM2708_CLK_SRC_GND = 0,
  151. + BCM2708_CLK_SRC_OSC,
  152. + BCM2708_CLK_SRC_DBG0,
  153. + BCM2708_CLK_SRC_DBG1,
  154. + BCM2708_CLK_SRC_PLLA,
  155. + BCM2708_CLK_SRC_PLLC,
  156. + BCM2708_CLK_SRC_PLLD,
  157. + BCM2708_CLK_SRC_HDMI,
  158. +};
  159. +
  160. +/* Most clocks are not useable (freq = 0) */
  161. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  162. + [BCM2708_CLK_SRC_GND] = 0,
  163. + [BCM2708_CLK_SRC_OSC] = 19200000,
  164. + [BCM2708_CLK_SRC_DBG0] = 0,
  165. + [BCM2708_CLK_SRC_DBG1] = 0,
  166. + [BCM2708_CLK_SRC_PLLA] = 0,
  167. + [BCM2708_CLK_SRC_PLLC] = 0,
  168. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  169. + [BCM2708_CLK_SRC_HDMI] = 0,
  170. +};
  171. +
  172. +/* I2S registers */
  173. +#define BCM2708_I2S_CS_A_REG 0x00
  174. +#define BCM2708_I2S_FIFO_A_REG 0x04
  175. +#define BCM2708_I2S_MODE_A_REG 0x08
  176. +#define BCM2708_I2S_RXC_A_REG 0x0c
  177. +#define BCM2708_I2S_TXC_A_REG 0x10
  178. +#define BCM2708_I2S_DREQ_A_REG 0x14
  179. +#define BCM2708_I2S_INTEN_A_REG 0x18
  180. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  181. +#define BCM2708_I2S_GRAY_REG 0x20
  182. +
  183. +/* I2S register settings */
  184. +#define BCM2708_I2S_STBY BIT(25)
  185. +#define BCM2708_I2S_SYNC BIT(24)
  186. +#define BCM2708_I2S_RXSEX BIT(23)
  187. +#define BCM2708_I2S_RXF BIT(22)
  188. +#define BCM2708_I2S_TXE BIT(21)
  189. +#define BCM2708_I2S_RXD BIT(20)
  190. +#define BCM2708_I2S_TXD BIT(19)
  191. +#define BCM2708_I2S_RXR BIT(18)
  192. +#define BCM2708_I2S_TXW BIT(17)
  193. +#define BCM2708_I2S_CS_RXERR BIT(16)
  194. +#define BCM2708_I2S_CS_TXERR BIT(15)
  195. +#define BCM2708_I2S_RXSYNC BIT(14)
  196. +#define BCM2708_I2S_TXSYNC BIT(13)
  197. +#define BCM2708_I2S_DMAEN BIT(9)
  198. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  199. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  200. +#define BCM2708_I2S_RXCLR BIT(4)
  201. +#define BCM2708_I2S_TXCLR BIT(3)
  202. +#define BCM2708_I2S_TXON BIT(2)
  203. +#define BCM2708_I2S_RXON BIT(1)
  204. +#define BCM2708_I2S_EN (1)
  205. +
  206. +#define BCM2708_I2S_CLKDIS BIT(28)
  207. +#define BCM2708_I2S_PDMN BIT(27)
  208. +#define BCM2708_I2S_PDME BIT(26)
  209. +#define BCM2708_I2S_FRXP BIT(25)
  210. +#define BCM2708_I2S_FTXP BIT(24)
  211. +#define BCM2708_I2S_CLKM BIT(23)
  212. +#define BCM2708_I2S_CLKI BIT(22)
  213. +#define BCM2708_I2S_FSM BIT(21)
  214. +#define BCM2708_I2S_FSI BIT(20)
  215. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  216. +#define BCM2708_I2S_FSLEN(v) (v)
  217. +
  218. +#define BCM2708_I2S_CHWEX BIT(15)
  219. +#define BCM2708_I2S_CHEN BIT(14)
  220. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  221. +#define BCM2708_I2S_CHWID(v) (v)
  222. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  223. +#define BCM2708_I2S_CH2(v) (v)
  224. +
  225. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  226. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  227. +#define BCM2708_I2S_TX(v) ((v) << 8)
  228. +#define BCM2708_I2S_RX(v) (v)
  229. +
  230. +#define BCM2708_I2S_INT_RXERR BIT(3)
  231. +#define BCM2708_I2S_INT_TXERR BIT(2)
  232. +#define BCM2708_I2S_INT_RXR BIT(1)
  233. +#define BCM2708_I2S_INT_TXW BIT(0)
  234. +
  235. +/* I2S DMA interface */
  236. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  237. +#define BCM2708_DMA_DREQ_PCM_TX 2
  238. +#define BCM2708_DMA_DREQ_PCM_RX 3
  239. +
  240. +/* I2S pin configuration */
  241. +static int bcm2708_i2s_gpio=BCM2708_I2S_GPIO_AUTO;
  242. +
  243. +/* General device struct */
  244. +struct bcm2708_i2s_dev {
  245. + struct device *dev;
  246. + struct snd_dmaengine_dai_dma_data dma_data[2];
  247. + unsigned int fmt;
  248. + unsigned int bclk_ratio;
  249. +
  250. + struct regmap *i2s_regmap;
  251. + struct regmap *clk_regmap;
  252. +};
  253. +
  254. +void bcm2708_i2s_set_gpio(int gpio) {
  255. + bcm2708_i2s_gpio=gpio;
  256. +}
  257. +EXPORT_SYMBOL(bcm2708_i2s_set_gpio);
  258. +
  259. +
  260. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  261. +{
  262. + /* Start the clock if in master mode */
  263. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  264. +
  265. + switch (master) {
  266. + case SND_SOC_DAIFMT_CBS_CFS:
  267. + case SND_SOC_DAIFMT_CBS_CFM:
  268. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  269. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  270. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  271. + break;
  272. + default:
  273. + break;
  274. + }
  275. +}
  276. +
  277. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  278. +{
  279. + uint32_t clkreg;
  280. + int timeout = 1000;
  281. +
  282. + /* Stop clock */
  283. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  284. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  285. + BCM2708_CLK_PASSWD);
  286. +
  287. + /* Wait for the BUSY flag going down */
  288. + while (--timeout) {
  289. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  290. + if (!(clkreg & BCM2708_CLK_BUSY))
  291. + break;
  292. + }
  293. +
  294. + if (!timeout) {
  295. + /* KILL the clock */
  296. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  297. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  298. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  299. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  300. + }
  301. +}
  302. +
  303. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  304. + bool tx, bool rx)
  305. +{
  306. + int timeout = 1000;
  307. + uint32_t syncval;
  308. + uint32_t csreg;
  309. + uint32_t i2s_active_state;
  310. + uint32_t clkreg;
  311. + uint32_t clk_active_state;
  312. + uint32_t off;
  313. + uint32_t clr;
  314. +
  315. + off = tx ? BCM2708_I2S_TXON : 0;
  316. + off |= rx ? BCM2708_I2S_RXON : 0;
  317. +
  318. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  319. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  320. +
  321. + /* Backup the current state */
  322. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  323. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  324. +
  325. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  326. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  327. +
  328. + /* Start clock if not running */
  329. + if (!clk_active_state) {
  330. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  331. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  332. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  333. + }
  334. +
  335. + /* Stop I2S module */
  336. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  337. +
  338. + /*
  339. + * Clear the FIFOs
  340. + * Requires at least 2 PCM clock cycles to take effect
  341. + */
  342. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  343. +
  344. + /* Wait for 2 PCM clock cycles */
  345. +
  346. + /*
  347. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  348. + * FIXME: This does not seem to work for slave mode!
  349. + */
  350. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  351. + syncval &= BCM2708_I2S_SYNC;
  352. +
  353. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  354. + BCM2708_I2S_SYNC, ~syncval);
  355. +
  356. + /* Wait for the SYNC flag changing it's state */
  357. + while (--timeout) {
  358. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  359. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  360. + break;
  361. + }
  362. +
  363. + if (!timeout)
  364. + dev_err(dev->dev, "I2S SYNC error!\n");
  365. +
  366. + /* Stop clock if it was not running before */
  367. + if (!clk_active_state)
  368. + bcm2708_i2s_stop_clock(dev);
  369. +
  370. + /* Restore I2S state */
  371. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  372. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  373. +}
  374. +
  375. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  376. + unsigned int fmt)
  377. +{
  378. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  379. + dev->fmt = fmt;
  380. + return 0;
  381. +}
  382. +
  383. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  384. + unsigned int ratio)
  385. +{
  386. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  387. + dev->bclk_ratio = ratio;
  388. + return 0;
  389. +}
  390. +
  391. +
  392. +static int bcm2708_i2s_set_function(unsigned offset, int function)
  393. +{
  394. + #define GPIOFSEL(x) (0x00+(x)*4)
  395. + void __iomem *gpio = __io_address(GPIO_BASE);
  396. + unsigned alt = function <= 3 ? function + 4: function == 4 ? 3 : 2;
  397. + unsigned gpiodir;
  398. + unsigned gpio_bank = offset / 10;
  399. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  400. +
  401. + if (offset >= BCM2708_NR_GPIOS)
  402. + return -EINVAL;
  403. +
  404. + gpiodir = readl(gpio + GPIOFSEL(gpio_bank));
  405. + gpiodir &= ~(7 << gpio_field_offset);
  406. + gpiodir |= alt << gpio_field_offset;
  407. + writel(gpiodir, gpio + GPIOFSEL(gpio_bank));
  408. + return 0;
  409. +}
  410. +
  411. +static void bcm2708_i2s_setup_gpio(void)
  412. +{
  413. + /*
  414. + * This is the common way to handle the GPIO pins for
  415. + * the Raspberry Pi.
  416. + * TODO Better way would be to handle
  417. + * this in the device tree!
  418. + */
  419. + int pin,pinconfig,startpin,alt;
  420. +
  421. + /* SPI is on different GPIOs on different boards */
  422. + /* for Raspberry Pi B+, this is pin GPIO18-21, for original on 28-31 */
  423. + if (bcm2708_i2s_gpio==BCM2708_I2S_GPIO_AUTO) {
  424. + if ((system_rev & 0xffffff) >= 0x10) {
  425. + /* Model B+ */
  426. + pinconfig=BCM2708_I2S_GPIO_PIN18;
  427. + } else {
  428. + /* original */
  429. + pinconfig=BCM2708_I2S_GPIO_PIN28;
  430. + }
  431. + } else {
  432. + pinconfig=bcm2708_i2s_gpio;
  433. + }
  434. +
  435. + if (pinconfig==BCM2708_I2S_GPIO_PIN18) {
  436. + startpin=18;
  437. + alt=BCM2708_I2S_GPIO_PIN18_ALT;
  438. + } else if (pinconfig==BCM2708_I2S_GPIO_PIN28) {
  439. + startpin=28;
  440. + alt=BCM2708_I2S_GPIO_PIN28_ALT;
  441. + } else {
  442. + printk(KERN_INFO "Can't configure I2S GPIOs, unknown pin mode for I2S: %i\n",pinconfig);
  443. + return;
  444. + }
  445. +
  446. + /* configure I2S pins to correct ALT mode */
  447. + for (pin = startpin; pin <= startpin+3; pin++) {
  448. + bcm2708_i2s_set_function(pin, alt);
  449. + }
  450. +}
  451. +
  452. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  453. + struct snd_pcm_hw_params *params,
  454. + struct snd_soc_dai *dai)
  455. +{
  456. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  457. +
  458. + unsigned int sampling_rate = params_rate(params);
  459. + unsigned int data_length, data_delay, bclk_ratio;
  460. + unsigned int ch1pos, ch2pos, mode, format;
  461. + unsigned int mash = BCM2708_CLK_MASH_1;
  462. + unsigned int divi, divf, target_frequency;
  463. + int clk_src = -1;
  464. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  465. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  466. + || master == SND_SOC_DAIFMT_CBS_CFM);
  467. +
  468. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  469. + || master == SND_SOC_DAIFMT_CBM_CFS);
  470. + uint32_t csreg;
  471. +
  472. + /*
  473. + * If a stream is already enabled,
  474. + * the registers are already set properly.
  475. + */
  476. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  477. +
  478. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  479. + return 0;
  480. +
  481. +
  482. + bcm2708_i2s_setup_gpio();
  483. +
  484. + /*
  485. + * Adjust the data length according to the format.
  486. + * We prefill the half frame length with an integer
  487. + * divider of 2400 as explained at the clock settings.
  488. + * Maybe it is overwritten there, if the Integer mode
  489. + * does not apply.
  490. + */
  491. + switch (params_format(params)) {
  492. + case SNDRV_PCM_FORMAT_S16_LE:
  493. + data_length = 16;
  494. + bclk_ratio = 50;
  495. + break;
  496. + case SNDRV_PCM_FORMAT_S24_LE:
  497. + data_length = 24;
  498. + bclk_ratio = 50;
  499. + break;
  500. + case SNDRV_PCM_FORMAT_S32_LE:
  501. + data_length = 32;
  502. + bclk_ratio = 100;
  503. + break;
  504. + default:
  505. + return -EINVAL;
  506. + }
  507. +
  508. + /* If bclk_ratio already set, use that one. */
  509. + if (dev->bclk_ratio)
  510. + bclk_ratio = dev->bclk_ratio;
  511. +
  512. + /*
  513. + * Clock Settings
  514. + *
  515. + * The target frequency of the bit clock is
  516. + * sampling rate * frame length
  517. + *
  518. + * Integer mode:
  519. + * Sampling rates that are multiples of 8000 kHz
  520. + * can be driven by the oscillator of 19.2 MHz
  521. + * with an integer divider as long as the frame length
  522. + * is an integer divider of 19200000/8000=2400 as set up above.
  523. + * This is no longer possible if the sampling rate
  524. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  525. + *
  526. + * MASH mode:
  527. + * For all other sampling rates, it is not possible to
  528. + * have an integer divider. Approximate the clock
  529. + * with the MASH module that induces a slight frequency
  530. + * variance. To minimize that it is best to have the fastest
  531. + * clock here. That is PLLD with 500 MHz.
  532. + */
  533. + target_frequency = sampling_rate * bclk_ratio;
  534. + clk_src = BCM2708_CLK_SRC_OSC;
  535. + mash = BCM2708_CLK_MASH_0;
  536. +
  537. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  538. + && bit_master && frame_master) {
  539. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  540. + divf = 0;
  541. + } else {
  542. + uint64_t dividend;
  543. +
  544. + if (!dev->bclk_ratio) {
  545. + /*
  546. + * Overwrite bclk_ratio, because the
  547. + * above trick is not needed or can
  548. + * not be used.
  549. + */
  550. + bclk_ratio = 2 * data_length;
  551. + }
  552. +
  553. + target_frequency = sampling_rate * bclk_ratio;
  554. +
  555. + clk_src = BCM2708_CLK_SRC_PLLD;
  556. + mash = BCM2708_CLK_MASH_1;
  557. +
  558. + dividend = bcm2708_clk_freq[clk_src];
  559. + dividend <<= BCM2708_CLK_SHIFT;
  560. + do_div(dividend, target_frequency);
  561. + divi = dividend >> BCM2708_CLK_SHIFT;
  562. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  563. + }
  564. +
  565. + /* Set clock divider */
  566. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  567. + | BCM2708_CLK_DIVI(divi)
  568. + | BCM2708_CLK_DIVF(divf));
  569. +
  570. + /* Setup clock, but don't start it yet */
  571. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  572. + | BCM2708_CLK_MASH(mash)
  573. + | BCM2708_CLK_SRC(clk_src));
  574. +
  575. + /* Setup the frame format */
  576. + format = BCM2708_I2S_CHEN;
  577. +
  578. + if (data_length >= 24)
  579. + format |= BCM2708_I2S_CHWEX;
  580. +
  581. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  582. +
  583. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  584. + case SND_SOC_DAIFMT_I2S:
  585. + data_delay = 1;
  586. + break;
  587. + default:
  588. + /*
  589. + * TODO
  590. + * Others are possible but are not implemented at the moment.
  591. + */
  592. + dev_err(dev->dev, "%s:bad format\n", __func__);
  593. + return -EINVAL;
  594. + }
  595. +
  596. + ch1pos = data_delay;
  597. + ch2pos = bclk_ratio / 2 + data_delay;
  598. +
  599. + switch (params_channels(params)) {
  600. + case 2:
  601. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  602. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  603. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  604. + break;
  605. + default:
  606. + return -EINVAL;
  607. + }
  608. +
  609. + /*
  610. + * Set format for both streams.
  611. + * We cannot set another frame length
  612. + * (and therefore word length) anyway,
  613. + * so the format will be the same.
  614. + */
  615. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  616. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  617. +
  618. + /* Setup the I2S mode */
  619. + mode = 0;
  620. +
  621. + if (data_length <= 16) {
  622. + /*
  623. + * Use frame packed mode (2 channels per 32 bit word)
  624. + * We cannot set another frame length in the second stream
  625. + * (and therefore word length) anyway,
  626. + * so the format will be the same.
  627. + */
  628. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  629. + }
  630. +
  631. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  632. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  633. +
  634. + /* Master or slave? */
  635. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  636. + case SND_SOC_DAIFMT_CBS_CFS:
  637. + /* CPU is master */
  638. + break;
  639. + case SND_SOC_DAIFMT_CBM_CFS:
  640. + /*
  641. + * CODEC is bit clock master
  642. + * CPU is frame master
  643. + */
  644. + mode |= BCM2708_I2S_CLKM;
  645. + break;
  646. + case SND_SOC_DAIFMT_CBS_CFM:
  647. + /*
  648. + * CODEC is frame master
  649. + * CPU is bit clock master
  650. + */
  651. + mode |= BCM2708_I2S_FSM;
  652. + break;
  653. + case SND_SOC_DAIFMT_CBM_CFM:
  654. + /* CODEC is master */
  655. + mode |= BCM2708_I2S_CLKM;
  656. + mode |= BCM2708_I2S_FSM;
  657. + break;
  658. + default:
  659. + dev_err(dev->dev, "%s:bad master\n", __func__);
  660. + return -EINVAL;
  661. + }
  662. +
  663. + /*
  664. + * Invert clocks?
  665. + *
  666. + * The BCM approach seems to be inverted to the classical I2S approach.
  667. + */
  668. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  669. + case SND_SOC_DAIFMT_NB_NF:
  670. + /* None. Therefore, both for BCM */
  671. + mode |= BCM2708_I2S_CLKI;
  672. + mode |= BCM2708_I2S_FSI;
  673. + break;
  674. + case SND_SOC_DAIFMT_IB_IF:
  675. + /* Both. Therefore, none for BCM */
  676. + break;
  677. + case SND_SOC_DAIFMT_NB_IF:
  678. + /*
  679. + * Invert only frame sync. Therefore,
  680. + * invert only bit clock for BCM
  681. + */
  682. + mode |= BCM2708_I2S_CLKI;
  683. + break;
  684. + case SND_SOC_DAIFMT_IB_NF:
  685. + /*
  686. + * Invert only bit clock. Therefore,
  687. + * invert only frame sync for BCM
  688. + */
  689. + mode |= BCM2708_I2S_FSI;
  690. + break;
  691. + default:
  692. + return -EINVAL;
  693. + }
  694. +
  695. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  696. +
  697. + /* Setup the DMA parameters */
  698. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  699. + BCM2708_I2S_RXTHR(1)
  700. + | BCM2708_I2S_TXTHR(1)
  701. + | BCM2708_I2S_DMAEN, 0xffffffff);
  702. +
  703. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  704. + BCM2708_I2S_TX_PANIC(0x10)
  705. + | BCM2708_I2S_RX_PANIC(0x30)
  706. + | BCM2708_I2S_TX(0x30)
  707. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  708. +
  709. + /* Clear FIFOs */
  710. + bcm2708_i2s_clear_fifos(dev, true, true);
  711. +
  712. + return 0;
  713. +}
  714. +
  715. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  716. + struct snd_soc_dai *dai)
  717. +{
  718. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  719. + uint32_t cs_reg;
  720. +
  721. + bcm2708_i2s_start_clock(dev);
  722. +
  723. + /*
  724. + * Clear both FIFOs if the one that should be started
  725. + * is not empty at the moment. This should only happen
  726. + * after overrun. Otherwise, hw_params would have cleared
  727. + * the FIFO.
  728. + */
  729. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  730. +
  731. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  732. + && !(cs_reg & BCM2708_I2S_TXE))
  733. + bcm2708_i2s_clear_fifos(dev, true, false);
  734. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  735. + && (cs_reg & BCM2708_I2S_RXD))
  736. + bcm2708_i2s_clear_fifos(dev, false, true);
  737. +
  738. + return 0;
  739. +}
  740. +
  741. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  742. + struct snd_pcm_substream *substream,
  743. + struct snd_soc_dai *dai)
  744. +{
  745. + uint32_t mask;
  746. +
  747. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  748. + mask = BCM2708_I2S_RXON;
  749. + else
  750. + mask = BCM2708_I2S_TXON;
  751. +
  752. + regmap_update_bits(dev->i2s_regmap,
  753. + BCM2708_I2S_CS_A_REG, mask, 0);
  754. +
  755. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  756. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  757. + bcm2708_i2s_stop_clock(dev);
  758. +}
  759. +
  760. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  761. + struct snd_soc_dai *dai)
  762. +{
  763. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  764. + uint32_t mask;
  765. +
  766. + switch (cmd) {
  767. + case SNDRV_PCM_TRIGGER_START:
  768. + case SNDRV_PCM_TRIGGER_RESUME:
  769. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  770. + bcm2708_i2s_start_clock(dev);
  771. +
  772. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  773. + mask = BCM2708_I2S_RXON;
  774. + else
  775. + mask = BCM2708_I2S_TXON;
  776. +
  777. + regmap_update_bits(dev->i2s_regmap,
  778. + BCM2708_I2S_CS_A_REG, mask, mask);
  779. + break;
  780. +
  781. + case SNDRV_PCM_TRIGGER_STOP:
  782. + case SNDRV_PCM_TRIGGER_SUSPEND:
  783. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  784. + bcm2708_i2s_stop(dev, substream, dai);
  785. + break;
  786. + default:
  787. + return -EINVAL;
  788. + }
  789. +
  790. + return 0;
  791. +}
  792. +
  793. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  794. + struct snd_soc_dai *dai)
  795. +{
  796. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  797. +
  798. + if (dai->active)
  799. + return 0;
  800. +
  801. + /* Should this still be running stop it */
  802. + bcm2708_i2s_stop_clock(dev);
  803. +
  804. + /* Enable PCM block */
  805. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  806. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  807. +
  808. + /*
  809. + * Disable STBY.
  810. + * Requires at least 4 PCM clock cycles to take effect.
  811. + */
  812. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  813. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  814. +
  815. + return 0;
  816. +}
  817. +
  818. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  819. + struct snd_soc_dai *dai)
  820. +{
  821. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  822. +
  823. + bcm2708_i2s_stop(dev, substream, dai);
  824. +
  825. + /* If both streams are stopped, disable module and clock */
  826. + if (dai->active)
  827. + return;
  828. +
  829. + /* Disable the module */
  830. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  831. + BCM2708_I2S_EN, 0);
  832. +
  833. + /*
  834. + * Stopping clock is necessary, because stop does
  835. + * not stop the clock when SND_SOC_DAIFMT_CONT
  836. + */
  837. + bcm2708_i2s_stop_clock(dev);
  838. +}
  839. +
  840. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  841. + .startup = bcm2708_i2s_startup,
  842. + .shutdown = bcm2708_i2s_shutdown,
  843. + .prepare = bcm2708_i2s_prepare,
  844. + .trigger = bcm2708_i2s_trigger,
  845. + .hw_params = bcm2708_i2s_hw_params,
  846. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  847. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  848. +};
  849. +
  850. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  851. +{
  852. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  853. +
  854. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  855. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  856. +
  857. + return 0;
  858. +}
  859. +
  860. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  861. + .name = "bcm2708-i2s",
  862. + .probe = bcm2708_i2s_dai_probe,
  863. + .playback = {
  864. + .channels_min = 2,
  865. + .channels_max = 2,
  866. + .rates = SNDRV_PCM_RATE_8000_192000,
  867. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  868. + | SNDRV_PCM_FMTBIT_S24_LE
  869. + | SNDRV_PCM_FMTBIT_S32_LE
  870. + },
  871. + .capture = {
  872. + .channels_min = 2,
  873. + .channels_max = 2,
  874. + .rates = SNDRV_PCM_RATE_8000_192000,
  875. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  876. + | SNDRV_PCM_FMTBIT_S24_LE
  877. + | SNDRV_PCM_FMTBIT_S32_LE
  878. + },
  879. + .ops = &bcm2708_i2s_dai_ops,
  880. + .symmetric_rates = 1
  881. +};
  882. +
  883. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  884. +{
  885. + switch (reg) {
  886. + case BCM2708_I2S_CS_A_REG:
  887. + case BCM2708_I2S_FIFO_A_REG:
  888. + case BCM2708_I2S_INTSTC_A_REG:
  889. + case BCM2708_I2S_GRAY_REG:
  890. + return true;
  891. + default:
  892. + return false;
  893. + };
  894. +}
  895. +
  896. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  897. +{
  898. + switch (reg) {
  899. + case BCM2708_I2S_FIFO_A_REG:
  900. + return true;
  901. + default:
  902. + return false;
  903. + };
  904. +}
  905. +
  906. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  907. +{
  908. + switch (reg) {
  909. + case BCM2708_CLK_PCMCTL_REG:
  910. + return true;
  911. + default:
  912. + return false;
  913. + };
  914. +}
  915. +
  916. +static const struct regmap_config bcm2708_regmap_config[] = {
  917. + {
  918. + .reg_bits = 32,
  919. + .reg_stride = 4,
  920. + .val_bits = 32,
  921. + .max_register = BCM2708_I2S_GRAY_REG,
  922. + .precious_reg = bcm2708_i2s_precious_reg,
  923. + .volatile_reg = bcm2708_i2s_volatile_reg,
  924. + .cache_type = REGCACHE_RBTREE,
  925. + .name = "i2s",
  926. + },
  927. + {
  928. + .reg_bits = 32,
  929. + .reg_stride = 4,
  930. + .val_bits = 32,
  931. + .max_register = BCM2708_CLK_PCMDIV_REG,
  932. + .volatile_reg = bcm2708_clk_volatile_reg,
  933. + .cache_type = REGCACHE_RBTREE,
  934. + .name = "clk",
  935. + },
  936. +};
  937. +
  938. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  939. + .name = "bcm2708-i2s-comp",
  940. +};
  941. +
  942. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  943. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  944. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  945. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  946. + SNDRV_PCM_FMTBIT_S24_LE |
  947. + SNDRV_PCM_FMTBIT_S32_LE,
  948. + .period_bytes_min = 32,
  949. + .period_bytes_max = 64 * PAGE_SIZE,
  950. + .periods_min = 2,
  951. + .periods_max = 255,
  952. + .buffer_bytes_max = 128 * PAGE_SIZE,
  953. +};
  954. +
  955. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  956. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  957. + .pcm_hardware = &bcm2708_pcm_hardware,
  958. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  959. +};
  960. +
  961. +
  962. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  963. +{
  964. + struct bcm2708_i2s_dev *dev;
  965. + int i;
  966. + int ret;
  967. + struct regmap *regmap[2];
  968. + struct resource *mem[2];
  969. +
  970. + /* Request both ioareas */
  971. + for (i = 0; i <= 1; i++) {
  972. + void __iomem *base;
  973. +
  974. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  975. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  976. + if (IS_ERR(base))
  977. + return PTR_ERR(base);
  978. +
  979. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  980. + &bcm2708_regmap_config[i]);
  981. + if (IS_ERR(regmap[i])) {
  982. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  983. + return PTR_ERR(regmap[i]);
  984. + }
  985. + }
  986. +
  987. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  988. + GFP_KERNEL);
  989. + if (IS_ERR(dev))
  990. + return PTR_ERR(dev);
  991. +
  992. + dev->i2s_regmap = regmap[0];
  993. + dev->clk_regmap = regmap[1];
  994. +
  995. + /* Set the DMA address */
  996. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  997. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  998. +
  999. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  1000. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  1001. +
  1002. + /* Set the DREQ */
  1003. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  1004. + BCM2708_DMA_DREQ_PCM_TX;
  1005. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  1006. + BCM2708_DMA_DREQ_PCM_RX;
  1007. +
  1008. + /* Set the bus width */
  1009. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  1010. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  1011. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  1012. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  1013. +
  1014. + /* Set burst */
  1015. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  1016. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  1017. +
  1018. + /* BCLK ratio - use default */
  1019. + dev->bclk_ratio = 0;
  1020. +
  1021. + /* Store the pdev */
  1022. + dev->dev = &pdev->dev;
  1023. + dev_set_drvdata(&pdev->dev, dev);
  1024. +
  1025. + ret = snd_soc_register_component(&pdev->dev,
  1026. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  1027. +
  1028. + if (ret) {
  1029. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  1030. + ret = -ENOMEM;
  1031. + return ret;
  1032. + }
  1033. +
  1034. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  1035. + &bcm2708_dmaengine_pcm_config,
  1036. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  1037. + if (ret) {
  1038. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  1039. + snd_soc_unregister_component(&pdev->dev);
  1040. + return ret;
  1041. + }
  1042. +
  1043. + return 0;
  1044. +}
  1045. +
  1046. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  1047. +{
  1048. + snd_dmaengine_pcm_unregister(&pdev->dev);
  1049. + snd_soc_unregister_component(&pdev->dev);
  1050. + return 0;
  1051. +}
  1052. +
  1053. +static struct platform_driver bcm2708_i2s_driver = {
  1054. + .probe = bcm2708_i2s_probe,
  1055. + .remove = bcm2708_i2s_remove,
  1056. + .driver = {
  1057. + .name = "bcm2708-i2s",
  1058. + .owner = THIS_MODULE,
  1059. + },
  1060. +};
  1061. +
  1062. +module_platform_driver(bcm2708_i2s_driver);
  1063. +
  1064. +MODULE_ALIAS("platform:bcm2708-i2s");
  1065. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  1066. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  1067. +MODULE_LICENSE("GPL v2");
  1068. --- /dev/null
  1069. +++ b/sound/soc/bcm/bcm2708-i2s.h
  1070. @@ -0,0 +1,35 @@
  1071. +/*
  1072. + * I2S configuration for sound cards.
  1073. + *
  1074. + * Copyright (c) 2014 Daniel Matuschek <daniel@hifiberry.com>
  1075. + *
  1076. + * This program is free software; you can redistribute it and/or modify
  1077. + * it under the terms of the GNU General Public License as published by
  1078. + * the Free Software Foundation; either version 2 of the License, or
  1079. + * (at your option) any later version.
  1080. + *
  1081. + * This program is distributed in the hope that it will be useful,
  1082. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1083. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1084. + * GNU General Public License for more details.
  1085. + *
  1086. + * You should have received a copy of the GNU General Public License
  1087. + * along with this program; if not, write to the Free Software
  1088. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  1089. + */
  1090. +
  1091. +#ifndef BCM2708_I2S_H
  1092. +#define BCM2708_I2S_H
  1093. +
  1094. +/* I2S pin assignment */
  1095. +#define BCM2708_I2S_GPIO_AUTO 0
  1096. +#define BCM2708_I2S_GPIO_PIN18 1
  1097. +#define BCM2708_I2S_GPIO_PIN28 2
  1098. +
  1099. +/* Alt mode to enable I2S */
  1100. +#define BCM2708_I2S_GPIO_PIN18_ALT 0
  1101. +#define BCM2708_I2S_GPIO_PIN28_ALT 2
  1102. +
  1103. +extern void bcm2708_i2s_set_gpio(int gpio);
  1104. +
  1105. +#endif