2 * wm0010.c -- WM0010 DSP Driver
4 * Copyright 2012 Wolfson Microelectronics PLC.
6 * Authors: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 * Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
8 * Scott Ling <sl@opensource.wolfsonmicro.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/interrupt.h>
18 #include <linux/irqreturn.h>
19 #include <linux/init.h>
20 #include <linux/spi/spi.h>
21 #include <linux/firmware.h>
22 #include <linux/delay.h>
24 #include <linux/miscdevice.h>
25 #include <linux/gpio.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/mutex.h>
28 #include <linux/workqueue.h>
30 #include <sound/soc.h>
31 #include <sound/wm0010.h>
33 #define DEVICE_ID_WM0010 10
35 /* We only support v1 of the .dfw INFO record */
36 #define INFO_VERSION 1
55 u8 tool_major_version
;
56 u8 tool_minor_version
;
72 static struct pll_clock_map
{
74 int max_pll_spi_speed
;
76 } pll_clock_map
[] = { /* Dividers */
77 { 22000000, 26000000, 0x00201f11 }, /* 2,32,2 */
78 { 18000000, 26000000, 0x00203f21 }, /* 2,64,4 */
79 { 14000000, 26000000, 0x00202620 }, /* 1,39,4 */
80 { 10000000, 22000000, 0x00203120 }, /* 1,50,4 */
81 { 6500000, 22000000, 0x00204520 }, /* 1,70,4 */
82 { 5500000, 22000000, 0x00103f10 }, /* 1,64,2 */
94 struct snd_soc_codec
*codec
;
99 struct wm0010_pdata pdata
;
102 int gpio_reset_value
;
104 struct regulator_bulk_data core_supplies
[2];
105 struct regulator
*dbvdd
;
109 enum wm0010_state state
;
114 int board_max_spi_speed
;
120 struct completion boot_completion
;
123 struct wm0010_spi_msg
{
124 struct spi_message m
;
125 struct spi_transfer t
;
131 static const struct snd_soc_dapm_widget wm0010_dapm_widgets
[] = {
132 SND_SOC_DAPM_SUPPLY("CLKIN", SND_SOC_NOPM
, 0, 0, NULL
, 0),
135 static const struct snd_soc_dapm_route wm0010_dapm_routes
[] = {
136 { "SDI2 Capture", NULL
, "SDI1 Playback" },
137 { "SDI1 Capture", NULL
, "SDI2 Playback" },
139 { "SDI1 Capture", NULL
, "CLKIN" },
140 { "SDI2 Capture", NULL
, "CLKIN" },
141 { "SDI1 Playback", NULL
, "CLKIN" },
142 { "SDI2 Playback", NULL
, "CLKIN" },
145 static const char *wm0010_state_to_str(enum wm0010_state state
)
147 const char *state_to_str
[] = {
155 if (state
< 0 || state
>= ARRAY_SIZE(state_to_str
))
157 return state_to_str
[state
];
160 /* Called with wm0010->lock held */
161 static void wm0010_halt(struct snd_soc_codec
*codec
)
163 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
165 enum wm0010_state state
;
167 /* Fetch the wm0010 state */
168 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
169 state
= wm0010
->state
;
170 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
173 case WM0010_POWER_OFF
:
174 /* If there's nothing to do, bail out */
176 case WM0010_OUT_OF_RESET
:
179 case WM0010_FIRMWARE
:
180 /* Remember to put chip back into reset */
181 gpio_set_value_cansleep(wm0010
->gpio_reset
,
182 wm0010
->gpio_reset_value
);
183 /* Disable the regulators */
184 regulator_disable(wm0010
->dbvdd
);
185 regulator_bulk_disable(ARRAY_SIZE(wm0010
->core_supplies
),
186 wm0010
->core_supplies
);
190 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
191 wm0010
->state
= WM0010_POWER_OFF
;
192 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
195 struct wm0010_boot_xfer
{
196 struct list_head list
;
197 struct snd_soc_codec
*codec
;
198 struct completion
*done
;
199 struct spi_message m
;
200 struct spi_transfer t
;
203 /* Called with wm0010->lock held */
204 static void wm0010_mark_boot_failure(struct wm0010_priv
*wm0010
)
206 enum wm0010_state state
;
209 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
210 state
= wm0010
->state
;
211 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
213 dev_err(wm0010
->dev
, "Failed to transition from `%s' state to `%s' state\n",
214 wm0010_state_to_str(state
), wm0010_state_to_str(state
+ 1));
216 wm0010
->boot_failed
= true;
219 static void wm0010_boot_xfer_complete(void *data
)
221 struct wm0010_boot_xfer
*xfer
= data
;
222 struct snd_soc_codec
*codec
= xfer
->codec
;
223 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
224 u32
*out32
= xfer
->t
.rx_buf
;
227 if (xfer
->m
.status
!= 0) {
228 dev_err(codec
->dev
, "SPI transfer failed: %d\n",
230 wm0010_mark_boot_failure(wm0010
);
232 complete(xfer
->done
);
236 for (i
= 0; i
< xfer
->t
.len
/ 4; i
++) {
237 dev_dbg(codec
->dev
, "%d: %04x\n", i
, out32
[i
]);
239 switch (be32_to_cpu(out32
[i
])) {
242 "%d: ROM error reported in stage 2\n", i
);
243 wm0010_mark_boot_failure(wm0010
);
247 if (wm0010
->state
< WM0010_STAGE2
)
250 "%d: ROM bootloader running in stage 2\n", i
);
251 wm0010_mark_boot_failure(wm0010
);
255 dev_dbg(codec
->dev
, "Stage2 loader running\n");
259 dev_dbg(codec
->dev
, "CODE_HDR packet received\n");
263 dev_dbg(codec
->dev
, "CODE_DATA packet received\n");
267 dev_dbg(codec
->dev
, "Download complete\n");
271 dev_dbg(codec
->dev
, "Application start\n");
275 dev_dbg(codec
->dev
, "PLL packet received\n");
276 wm0010
->pll_running
= true;
280 dev_err(codec
->dev
, "Device reports image too long\n");
281 wm0010_mark_boot_failure(wm0010
);
285 dev_err(codec
->dev
, "Device reports bad SPI packet\n");
286 wm0010_mark_boot_failure(wm0010
);
290 dev_err(codec
->dev
, "Device reports SPI read overflow\n");
291 wm0010_mark_boot_failure(wm0010
);
295 dev_err(codec
->dev
, "Device reports SPI underclock\n");
296 wm0010_mark_boot_failure(wm0010
);
300 dev_err(codec
->dev
, "Device reports bad header packet\n");
301 wm0010_mark_boot_failure(wm0010
);
305 dev_err(codec
->dev
, "Device reports invalid packet type\n");
306 wm0010_mark_boot_failure(wm0010
);
310 dev_err(codec
->dev
, "Device reports data before header error\n");
311 wm0010_mark_boot_failure(wm0010
);
315 dev_err(codec
->dev
, "Device reports invalid PLL packet\n");
319 dev_err(codec
->dev
, "Device reports packet alignment error\n");
320 wm0010_mark_boot_failure(wm0010
);
324 dev_err(codec
->dev
, "Unrecognised return 0x%x\n",
325 be32_to_cpu(out32
[i
]));
326 wm0010_mark_boot_failure(wm0010
);
330 if (wm0010
->boot_failed
)
335 complete(xfer
->done
);
338 static void byte_swap_64(u64
*data_in
, u64
*data_out
, u32 len
)
342 for (i
= 0; i
< len
/ 8; i
++)
343 data_out
[i
] = cpu_to_be64(le64_to_cpu(data_in
[i
]));
346 static int wm0010_firmware_load(const char *name
, struct snd_soc_codec
*codec
)
348 struct spi_device
*spi
= to_spi_device(codec
->dev
);
349 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
350 struct list_head xfer_list
;
351 struct wm0010_boot_xfer
*xfer
;
353 struct completion done
;
354 const struct firmware
*fw
;
355 const struct dfw_binrec
*rec
;
356 const struct dfw_inforec
*inforec
;
361 INIT_LIST_HEAD(&xfer_list
);
363 ret
= request_firmware(&fw
, name
, codec
->dev
);
365 dev_err(codec
->dev
, "Failed to request application(%s): %d\n",
370 rec
= (const struct dfw_binrec
*)fw
->data
;
371 inforec
= (const struct dfw_inforec
*)rec
->data
;
373 dsp
= inforec
->dsp_target
;
374 wm0010
->boot_failed
= false;
375 if (WARN_ON(!list_empty(&xfer_list
)))
377 init_completion(&done
);
379 /* First record should be INFO */
380 if (rec
->command
!= DFW_CMD_INFO
) {
381 dev_err(codec
->dev
, "First record not INFO\r\n");
386 if (inforec
->info_version
!= INFO_VERSION
) {
388 "Unsupported version (%02d) of INFO record\r\n",
389 inforec
->info_version
);
394 dev_dbg(codec
->dev
, "Version v%02d INFO record found\r\n",
395 inforec
->info_version
);
397 /* Check it's a DSP file */
398 if (dsp
!= DEVICE_ID_WM0010
) {
399 dev_err(codec
->dev
, "Not a WM0010 firmware file.\r\n");
404 /* Skip the info record as we don't need to send it */
405 offset
+= ((rec
->length
) + 8);
406 rec
= (void *)&rec
->data
[rec
->length
];
408 while (offset
< fw
->size
) {
410 "Packet: command %d, data length = 0x%x\r\n",
411 rec
->command
, rec
->length
);
412 len
= rec
->length
+ 8;
414 xfer
= kzalloc(sizeof(*xfer
), GFP_KERNEL
);
416 dev_err(codec
->dev
, "Failed to allocate xfer\n");
422 list_add_tail(&xfer
->list
, &xfer_list
);
424 out
= kzalloc(len
, GFP_KERNEL
| GFP_DMA
);
427 "Failed to allocate RX buffer\n");
431 xfer
->t
.rx_buf
= out
;
433 img
= kzalloc(len
, GFP_KERNEL
| GFP_DMA
);
436 "Failed to allocate image buffer\n");
440 xfer
->t
.tx_buf
= img
;
442 byte_swap_64((u64
*)&rec
->command
, img
, len
);
444 spi_message_init(&xfer
->m
);
445 xfer
->m
.complete
= wm0010_boot_xfer_complete
;
446 xfer
->m
.context
= xfer
;
448 xfer
->t
.bits_per_word
= 8;
450 if (!wm0010
->pll_running
) {
451 xfer
->t
.speed_hz
= wm0010
->sysclk
/ 6;
453 xfer
->t
.speed_hz
= wm0010
->max_spi_freq
;
455 if (wm0010
->board_max_spi_speed
&&
456 (wm0010
->board_max_spi_speed
< wm0010
->max_spi_freq
))
457 xfer
->t
.speed_hz
= wm0010
->board_max_spi_speed
;
460 /* Store max usable spi frequency for later use */
461 wm0010
->max_spi_freq
= xfer
->t
.speed_hz
;
463 spi_message_add_tail(&xfer
->t
, &xfer
->m
);
465 offset
+= ((rec
->length
) + 8);
466 rec
= (void *)&rec
->data
[rec
->length
];
468 if (offset
>= fw
->size
) {
469 dev_dbg(codec
->dev
, "All transfers scheduled\n");
473 ret
= spi_async(spi
, &xfer
->m
);
475 dev_err(codec
->dev
, "Write failed: %d\n", ret
);
479 if (wm0010
->boot_failed
) {
480 dev_dbg(codec
->dev
, "Boot fail!\n");
486 wait_for_completion(&done
);
491 while (!list_empty(&xfer_list
)) {
492 xfer
= list_first_entry(&xfer_list
, struct wm0010_boot_xfer
,
494 kfree(xfer
->t
.rx_buf
);
495 kfree(xfer
->t
.tx_buf
);
496 list_del(&xfer
->list
);
501 release_firmware(fw
);
505 static int wm0010_stage2_load(struct snd_soc_codec
*codec
)
507 struct spi_device
*spi
= to_spi_device(codec
->dev
);
508 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
509 const struct firmware
*fw
;
510 struct spi_message m
;
511 struct spi_transfer t
;
517 ret
= request_firmware(&fw
, "wm0010_stage2.bin", codec
->dev
);
519 dev_err(codec
->dev
, "Failed to request stage2 loader: %d\n",
524 dev_dbg(codec
->dev
, "Downloading %zu byte stage 2 loader\n", fw
->size
);
526 /* Copy to local buffer first as vmalloc causes problems for dma */
527 img
= kzalloc(fw
->size
, GFP_KERNEL
| GFP_DMA
);
529 dev_err(codec
->dev
, "Failed to allocate image buffer\n");
534 out
= kzalloc(fw
->size
, GFP_KERNEL
| GFP_DMA
);
536 dev_err(codec
->dev
, "Failed to allocate output buffer\n");
541 memcpy(img
, &fw
->data
[0], fw
->size
);
543 spi_message_init(&m
);
544 memset(&t
, 0, sizeof(t
));
549 t
.speed_hz
= wm0010
->sysclk
/ 10;
550 spi_message_add_tail(&t
, &m
);
552 dev_dbg(codec
->dev
, "Starting initial download at %dHz\n",
555 ret
= spi_sync(spi
, &m
);
557 dev_err(codec
->dev
, "Initial download failed: %d\n", ret
);
561 /* Look for errors from the boot ROM */
562 for (i
= 0; i
< fw
->size
; i
++) {
563 if (out
[i
] != 0x55) {
564 dev_err(codec
->dev
, "Boot ROM error: %x in %d\n",
566 wm0010_mark_boot_failure(wm0010
);
576 release_firmware(fw
);
581 static int wm0010_boot(struct snd_soc_codec
*codec
)
583 struct spi_device
*spi
= to_spi_device(codec
->dev
);
584 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
587 const struct firmware
*fw
;
588 struct spi_message m
;
589 struct spi_transfer t
;
590 struct dfw_pllrec pll_rec
;
596 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
597 if (wm0010
->state
!= WM0010_POWER_OFF
)
598 dev_warn(wm0010
->dev
, "DSP already powered up!\n");
599 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
601 if (wm0010
->sysclk
> 26000000) {
602 dev_err(codec
->dev
, "Max DSP clock frequency is 26MHz\n");
607 mutex_lock(&wm0010
->lock
);
608 wm0010
->pll_running
= false;
610 dev_dbg(codec
->dev
, "max_spi_freq: %d\n", wm0010
->max_spi_freq
);
612 ret
= regulator_bulk_enable(ARRAY_SIZE(wm0010
->core_supplies
),
613 wm0010
->core_supplies
);
615 dev_err(&spi
->dev
, "Failed to enable core supplies: %d\n",
617 mutex_unlock(&wm0010
->lock
);
621 ret
= regulator_enable(wm0010
->dbvdd
);
623 dev_err(&spi
->dev
, "Failed to enable DBVDD: %d\n", ret
);
628 gpio_set_value_cansleep(wm0010
->gpio_reset
, !wm0010
->gpio_reset_value
);
629 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
630 wm0010
->state
= WM0010_OUT_OF_RESET
;
631 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
633 /* First the bootloader */
634 ret
= request_firmware(&fw
, "wm0010_stage2.bin", codec
->dev
);
636 dev_err(codec
->dev
, "Failed to request stage2 loader: %d\n",
641 if (!wait_for_completion_timeout(&wm0010
->boot_completion
,
642 msecs_to_jiffies(20)))
643 dev_err(codec
->dev
, "Failed to get interrupt from DSP\n");
645 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
646 wm0010
->state
= WM0010_BOOTROM
;
647 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
649 ret
= wm0010_stage2_load(codec
);
653 if (!wait_for_completion_timeout(&wm0010
->boot_completion
,
654 msecs_to_jiffies(20)))
655 dev_err(codec
->dev
, "Failed to get interrupt from DSP loader.\n");
657 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
658 wm0010
->state
= WM0010_STAGE2
;
659 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
661 /* Only initialise PLL if max_spi_freq initialised */
662 if (wm0010
->max_spi_freq
) {
664 /* Initialise a PLL record */
665 memset(&pll_rec
, 0, sizeof(pll_rec
));
666 pll_rec
.command
= DFW_CMD_PLL
;
667 pll_rec
.length
= (sizeof(pll_rec
) - 8);
669 /* On wm0010 only the CLKCTRL1 value is used */
670 pll_rec
.clkctrl1
= wm0010
->pll_clkctrl1
;
673 len
= pll_rec
.length
+ 8;
674 out
= kzalloc(len
, GFP_KERNEL
| GFP_DMA
);
677 "Failed to allocate RX buffer\n");
681 img_swap
= kzalloc(len
, GFP_KERNEL
| GFP_DMA
);
684 "Failed to allocate image buffer\n");
688 /* We need to re-order for 0010 */
689 byte_swap_64((u64
*)&pll_rec
, img_swap
, len
);
691 spi_message_init(&m
);
692 memset(&t
, 0, sizeof(t
));
697 t
.speed_hz
= wm0010
->sysclk
/ 6;
698 spi_message_add_tail(&t
, &m
);
700 ret
= spi_sync(spi
, &m
);
702 dev_err(codec
->dev
, "First PLL write failed: %d\n", ret
);
706 /* Use a second send of the message to get the return status */
707 ret
= spi_sync(spi
, &m
);
709 dev_err(codec
->dev
, "Second PLL write failed: %d\n", ret
);
715 /* Look for PLL active code from the DSP */
716 for (i
= 0; i
< len
/ 4; i
++) {
717 if (*p
== 0x0e00ed0f) {
718 dev_dbg(codec
->dev
, "PLL packet received\n");
719 wm0010
->pll_running
= true;
728 dev_dbg(codec
->dev
, "Not enabling DSP PLL.");
730 ret
= wm0010_firmware_load("wm0010.dfw", codec
);
735 spin_lock_irqsave(&wm0010
->irq_lock
, flags
);
736 wm0010
->state
= WM0010_FIRMWARE
;
737 spin_unlock_irqrestore(&wm0010
->irq_lock
, flags
);
739 mutex_unlock(&wm0010
->lock
);
744 /* Put the chip back into reset */
746 mutex_unlock(&wm0010
->lock
);
750 mutex_unlock(&wm0010
->lock
);
751 regulator_bulk_disable(ARRAY_SIZE(wm0010
->core_supplies
),
752 wm0010
->core_supplies
);
757 static int wm0010_set_bias_level(struct snd_soc_codec
*codec
,
758 enum snd_soc_bias_level level
)
760 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
763 case SND_SOC_BIAS_ON
:
764 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_PREPARE
)
767 case SND_SOC_BIAS_PREPARE
:
769 case SND_SOC_BIAS_STANDBY
:
770 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_PREPARE
) {
771 mutex_lock(&wm0010
->lock
);
773 mutex_unlock(&wm0010
->lock
);
776 case SND_SOC_BIAS_OFF
:
780 codec
->dapm
.bias_level
= level
;
785 static int wm0010_set_sysclk(struct snd_soc_codec
*codec
, int source
,
786 int clk_id
, unsigned int freq
, int dir
)
788 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
791 wm0010
->sysclk
= freq
;
793 if (freq
< pll_clock_map
[ARRAY_SIZE(pll_clock_map
)-1].max_sysclk
) {
794 wm0010
->max_spi_freq
= 0;
796 for (i
= 0; i
< ARRAY_SIZE(pll_clock_map
); i
++)
797 if (freq
>= pll_clock_map
[i
].max_sysclk
) {
798 wm0010
->max_spi_freq
= pll_clock_map
[i
].max_pll_spi_speed
;
799 wm0010
->pll_clkctrl1
= pll_clock_map
[i
].pll_clkctrl1
;
807 static int wm0010_probe(struct snd_soc_codec
*codec
);
809 static struct snd_soc_codec_driver soc_codec_dev_wm0010
= {
810 .probe
= wm0010_probe
,
811 .set_bias_level
= wm0010_set_bias_level
,
812 .set_sysclk
= wm0010_set_sysclk
,
813 .idle_bias_off
= true,
815 .dapm_widgets
= wm0010_dapm_widgets
,
816 .num_dapm_widgets
= ARRAY_SIZE(wm0010_dapm_widgets
),
817 .dapm_routes
= wm0010_dapm_routes
,
818 .num_dapm_routes
= ARRAY_SIZE(wm0010_dapm_routes
),
821 #define WM0010_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
822 #define WM0010_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
823 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |\
824 SNDRV_PCM_FMTBIT_S32_LE)
826 static struct snd_soc_dai_driver wm0010_dai
[] = {
828 .name
= "wm0010-sdi1",
830 .stream_name
= "SDI1 Playback",
833 .rates
= WM0010_RATES
,
834 .formats
= WM0010_FORMATS
,
837 .stream_name
= "SDI1 Capture",
840 .rates
= WM0010_RATES
,
841 .formats
= WM0010_FORMATS
,
845 .name
= "wm0010-sdi2",
847 .stream_name
= "SDI2 Playback",
850 .rates
= WM0010_RATES
,
851 .formats
= WM0010_FORMATS
,
854 .stream_name
= "SDI2 Capture",
857 .rates
= WM0010_RATES
,
858 .formats
= WM0010_FORMATS
,
863 static irqreturn_t
wm0010_irq(int irq
, void *data
)
865 struct wm0010_priv
*wm0010
= data
;
867 switch (wm0010
->state
) {
868 case WM0010_OUT_OF_RESET
:
871 spin_lock(&wm0010
->irq_lock
);
872 complete(&wm0010
->boot_completion
);
873 spin_unlock(&wm0010
->irq_lock
);
882 static int wm0010_probe(struct snd_soc_codec
*codec
)
884 struct wm0010_priv
*wm0010
= snd_soc_codec_get_drvdata(codec
);
886 wm0010
->codec
= codec
;
891 static int wm0010_spi_probe(struct spi_device
*spi
)
893 unsigned long gpio_flags
;
897 struct wm0010_priv
*wm0010
;
899 wm0010
= devm_kzalloc(&spi
->dev
, sizeof(*wm0010
),
904 mutex_init(&wm0010
->lock
);
905 spin_lock_init(&wm0010
->irq_lock
);
907 spi_set_drvdata(spi
, wm0010
);
908 wm0010
->dev
= &spi
->dev
;
910 if (dev_get_platdata(&spi
->dev
))
911 memcpy(&wm0010
->pdata
, dev_get_platdata(&spi
->dev
),
912 sizeof(wm0010
->pdata
));
914 init_completion(&wm0010
->boot_completion
);
916 wm0010
->core_supplies
[0].supply
= "AVDD";
917 wm0010
->core_supplies
[1].supply
= "DCVDD";
918 ret
= devm_regulator_bulk_get(wm0010
->dev
, ARRAY_SIZE(wm0010
->core_supplies
),
919 wm0010
->core_supplies
);
921 dev_err(wm0010
->dev
, "Failed to obtain core supplies: %d\n",
926 wm0010
->dbvdd
= devm_regulator_get(wm0010
->dev
, "DBVDD");
927 if (IS_ERR(wm0010
->dbvdd
)) {
928 ret
= PTR_ERR(wm0010
->dbvdd
);
929 dev_err(wm0010
->dev
, "Failed to obtain DBVDD: %d\n", ret
);
933 if (wm0010
->pdata
.gpio_reset
) {
934 wm0010
->gpio_reset
= wm0010
->pdata
.gpio_reset
;
936 if (wm0010
->pdata
.reset_active_high
)
937 wm0010
->gpio_reset_value
= 1;
939 wm0010
->gpio_reset_value
= 0;
941 if (wm0010
->gpio_reset_value
)
942 gpio_flags
= GPIOF_OUT_INIT_HIGH
;
944 gpio_flags
= GPIOF_OUT_INIT_LOW
;
946 ret
= devm_gpio_request_one(wm0010
->dev
, wm0010
->gpio_reset
,
947 gpio_flags
, "wm0010 reset");
950 "Failed to request GPIO for DSP reset: %d\n",
955 dev_err(wm0010
->dev
, "No reset GPIO configured\n");
959 wm0010
->state
= WM0010_POWER_OFF
;
962 if (wm0010
->pdata
.irq_flags
)
963 trigger
= wm0010
->pdata
.irq_flags
;
965 trigger
= IRQF_TRIGGER_FALLING
;
966 trigger
|= IRQF_ONESHOT
;
968 ret
= request_threaded_irq(irq
, NULL
, wm0010_irq
, trigger
| IRQF_ONESHOT
,
971 dev_err(wm0010
->dev
, "Failed to request IRQ %d: %d\n",
977 ret
= irq_set_irq_wake(irq
, 1);
979 dev_err(wm0010
->dev
, "Failed to set IRQ %d as wake source: %d\n",
984 if (spi
->max_speed_hz
)
985 wm0010
->board_max_spi_speed
= spi
->max_speed_hz
;
987 wm0010
->board_max_spi_speed
= 0;
989 ret
= snd_soc_register_codec(&spi
->dev
,
990 &soc_codec_dev_wm0010
, wm0010_dai
,
991 ARRAY_SIZE(wm0010_dai
));
998 static int wm0010_spi_remove(struct spi_device
*spi
)
1000 struct wm0010_priv
*wm0010
= spi_get_drvdata(spi
);
1002 snd_soc_unregister_codec(&spi
->dev
);
1004 gpio_set_value_cansleep(wm0010
->gpio_reset
,
1005 wm0010
->gpio_reset_value
);
1007 irq_set_irq_wake(wm0010
->irq
, 0);
1010 free_irq(wm0010
->irq
, wm0010
);
1015 static struct spi_driver wm0010_spi_driver
= {
1018 .bus
= &spi_bus_type
,
1019 .owner
= THIS_MODULE
,
1021 .probe
= wm0010_spi_probe
,
1022 .remove
= wm0010_spi_remove
,
1025 module_spi_driver(wm0010_spi_driver
);
1027 MODULE_DESCRIPTION("ASoC WM0010 driver");
1028 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1029 MODULE_LICENSE("GPL");