| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * wm8958-dsp2.c -- WM8958 DSP2 support |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2011 Wolfson Microelectronics plc |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | 10 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 27 | 24 | #include <linux/mfd/wm8994/registers.h> |
|---|
| 28 | 25 | #include <linux/mfd/wm8994/pdata.h> |
|---|
| 29 | 26 | #include <linux/mfd/wm8994/gpio.h> |
|---|
| 27 | + |
|---|
| 28 | +#include <asm/unaligned.h> |
|---|
| 30 | 29 | |
|---|
| 31 | 30 | #include "wm8994.h" |
|---|
| 32 | 31 | |
|---|
| .. | .. |
|---|
| 61 | 60 | } |
|---|
| 62 | 61 | |
|---|
| 63 | 62 | if (memcmp(fw->data, "WMFW", 4) != 0) { |
|---|
| 64 | | - memcpy(&data32, fw->data, sizeof(data32)); |
|---|
| 65 | | - data32 = be32_to_cpu(data32); |
|---|
| 63 | + data32 = get_unaligned_be32(fw->data); |
|---|
| 66 | 64 | dev_err(component->dev, "%s: firmware has bad file magic %08x\n", |
|---|
| 67 | 65 | name, data32); |
|---|
| 68 | 66 | goto err; |
|---|
| 69 | 67 | } |
|---|
| 70 | 68 | |
|---|
| 71 | | - memcpy(&data32, fw->data + 4, sizeof(data32)); |
|---|
| 72 | | - len = be32_to_cpu(data32); |
|---|
| 69 | + len = get_unaligned_be32(fw->data + 4); |
|---|
| 70 | + data32 = get_unaligned_be32(fw->data + 8); |
|---|
| 73 | 71 | |
|---|
| 74 | | - memcpy(&data32, fw->data + 8, sizeof(data32)); |
|---|
| 75 | | - data32 = be32_to_cpu(data32); |
|---|
| 76 | 72 | if ((data32 >> 24) & 0xff) { |
|---|
| 77 | 73 | dev_err(component->dev, "%s: unsupported firmware version %d\n", |
|---|
| 78 | 74 | name, (data32 >> 24) & 0xff); |
|---|
| .. | .. |
|---|
| 90 | 86 | } |
|---|
| 91 | 87 | |
|---|
| 92 | 88 | if (check) { |
|---|
| 93 | | - memcpy(&data64, fw->data + 24, sizeof(u64)); |
|---|
| 94 | | - dev_info(component->dev, "%s timestamp %llx\n", |
|---|
| 95 | | - name, be64_to_cpu(data64)); |
|---|
| 89 | + data64 = get_unaligned_be64(fw->data + 24); |
|---|
| 90 | + dev_info(component->dev, "%s timestamp %llx\n", name, data64); |
|---|
| 96 | 91 | } else { |
|---|
| 97 | 92 | snd_soc_component_write(component, 0x102, 0x2); |
|---|
| 98 | 93 | snd_soc_component_write(component, 0x900, 0x2); |
|---|
| .. | .. |
|---|
| 107 | 102 | goto err; |
|---|
| 108 | 103 | } |
|---|
| 109 | 104 | |
|---|
| 110 | | - memcpy(&data32, data + 4, sizeof(data32)); |
|---|
| 111 | | - block_len = be32_to_cpu(data32); |
|---|
| 105 | + block_len = get_unaligned_be32(data + 4); |
|---|
| 112 | 106 | if (block_len + 8 > len) { |
|---|
| 113 | 107 | dev_err(component->dev, "%zd byte block longer than file\n", |
|---|
| 114 | 108 | block_len); |
|---|
| .. | .. |
|---|
| 119 | 113 | goto err; |
|---|
| 120 | 114 | } |
|---|
| 121 | 115 | |
|---|
| 122 | | - memcpy(&data32, data, sizeof(data32)); |
|---|
| 123 | | - data32 = be32_to_cpu(data32); |
|---|
| 116 | + data32 = get_unaligned_be32(data); |
|---|
| 124 | 117 | |
|---|
| 125 | 118 | switch ((data32 >> 24) & 0xff) { |
|---|
| 126 | 119 | case WM_FW_BLOCK_INFO: |
|---|
| .. | .. |
|---|
| 199 | 192 | int i; |
|---|
| 200 | 193 | |
|---|
| 201 | 194 | /* If the DSP is already running then noop */ |
|---|
| 202 | | - if (snd_soc_component_read32(component, WM8958_DSP2_PROGRAM) & WM8958_DSP2_ENA) |
|---|
| 195 | + if (snd_soc_component_read(component, WM8958_DSP2_PROGRAM) & WM8958_DSP2_ENA) |
|---|
| 203 | 196 | return; |
|---|
| 204 | 197 | |
|---|
| 205 | 198 | /* If we have MBC firmware download it */ |
|---|
| .. | .. |
|---|
| 331 | 324 | static void wm8958_dsp_apply(struct snd_soc_component *component, int path, int start) |
|---|
| 332 | 325 | { |
|---|
| 333 | 326 | struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component); |
|---|
| 334 | | - int pwr_reg = snd_soc_component_read32(component, WM8994_POWER_MANAGEMENT_5); |
|---|
| 327 | + int pwr_reg = snd_soc_component_read(component, WM8994_POWER_MANAGEMENT_5); |
|---|
| 335 | 328 | int ena, reg, aif; |
|---|
| 336 | 329 | |
|---|
| 337 | 330 | switch (path) { |
|---|
| .. | .. |
|---|
| 359 | 352 | if (!pwr_reg) |
|---|
| 360 | 353 | ena = 0; |
|---|
| 361 | 354 | |
|---|
| 362 | | - reg = snd_soc_component_read32(component, WM8958_DSP2_PROGRAM); |
|---|
| 355 | + reg = snd_soc_component_read(component, WM8958_DSP2_PROGRAM); |
|---|
| 363 | 356 | |
|---|
| 364 | 357 | dev_dbg(component->dev, "DSP path %d %d startup: %d, power: %x, DSP: %x\n", |
|---|
| 365 | 358 | path, wm8994->dsp_active, start, pwr_reg, reg); |
|---|
| .. | .. |
|---|
| 370 | 363 | return; |
|---|
| 371 | 364 | |
|---|
| 372 | 365 | /* If either AIFnCLK is not yet enabled postpone */ |
|---|
| 373 | | - if (!(snd_soc_component_read32(component, WM8994_AIF1_CLOCKING_1) |
|---|
| 366 | + if (!(snd_soc_component_read(component, WM8994_AIF1_CLOCKING_1) |
|---|
| 374 | 367 | & WM8994_AIF1CLK_ENA_MASK) && |
|---|
| 375 | | - !(snd_soc_component_read32(component, WM8994_AIF2_CLOCKING_1) |
|---|
| 368 | + !(snd_soc_component_read(component, WM8994_AIF2_CLOCKING_1) |
|---|
| 376 | 369 | & WM8994_AIF2CLK_ENA_MASK)) |
|---|
| 377 | 370 | return; |
|---|
| 378 | 371 | |
|---|
| .. | .. |
|---|
| 467 | 460 | int reg; |
|---|
| 468 | 461 | |
|---|
| 469 | 462 | /* Don't allow on the fly reconfiguration */ |
|---|
| 470 | | - reg = snd_soc_component_read32(component, WM8994_CLOCKING_1); |
|---|
| 463 | + reg = snd_soc_component_read(component, WM8994_CLOCKING_1); |
|---|
| 471 | 464 | if (reg < 0 || reg & WM8958_DSP2CLK_ENA) |
|---|
| 472 | 465 | return -EBUSY; |
|---|
| 473 | 466 | |
|---|
| .. | .. |
|---|
| 537 | 530 | |
|---|
| 538 | 531 | wm8958_dsp_apply(component, mbc, wm8994->mbc_ena[mbc]); |
|---|
| 539 | 532 | |
|---|
| 540 | | - return 0; |
|---|
| 533 | + return 1; |
|---|
| 541 | 534 | } |
|---|
| 542 | 535 | |
|---|
| 543 | 536 | #define WM8958_MBC_SWITCH(xname, xval) {\ |
|---|
| .. | .. |
|---|
| 557 | 550 | int reg; |
|---|
| 558 | 551 | |
|---|
| 559 | 552 | /* Don't allow on the fly reconfiguration */ |
|---|
| 560 | | - reg = snd_soc_component_read32(component, WM8994_CLOCKING_1); |
|---|
| 553 | + reg = snd_soc_component_read(component, WM8994_CLOCKING_1); |
|---|
| 561 | 554 | if (reg < 0 || reg & WM8958_DSP2CLK_ENA) |
|---|
| 562 | 555 | return -EBUSY; |
|---|
| 563 | 556 | |
|---|
| .. | .. |
|---|
| 590 | 583 | int reg; |
|---|
| 591 | 584 | |
|---|
| 592 | 585 | /* Don't allow on the fly reconfiguration */ |
|---|
| 593 | | - reg = snd_soc_component_read32(component, WM8994_CLOCKING_1); |
|---|
| 586 | + reg = snd_soc_component_read(component, WM8994_CLOCKING_1); |
|---|
| 594 | 587 | if (reg < 0 || reg & WM8958_DSP2CLK_ENA) |
|---|
| 595 | 588 | return -EBUSY; |
|---|
| 596 | 589 | |
|---|
| .. | .. |
|---|
| 663 | 656 | |
|---|
| 664 | 657 | wm8958_dsp_apply(component, vss, wm8994->vss_ena[vss]); |
|---|
| 665 | 658 | |
|---|
| 666 | | - return 0; |
|---|
| 659 | + return 1; |
|---|
| 667 | 660 | } |
|---|
| 668 | 661 | |
|---|
| 669 | 662 | |
|---|
| .. | .. |
|---|
| 737 | 730 | |
|---|
| 738 | 731 | wm8958_dsp_apply(component, hpf % 3, ucontrol->value.integer.value[0]); |
|---|
| 739 | 732 | |
|---|
| 740 | | - return 0; |
|---|
| 733 | + return 1; |
|---|
| 741 | 734 | } |
|---|
| 742 | 735 | |
|---|
| 743 | 736 | #define WM8958_HPF_SWITCH(xname, xval) {\ |
|---|
| .. | .. |
|---|
| 757 | 750 | int reg; |
|---|
| 758 | 751 | |
|---|
| 759 | 752 | /* Don't allow on the fly reconfiguration */ |
|---|
| 760 | | - reg = snd_soc_component_read32(component, WM8994_CLOCKING_1); |
|---|
| 753 | + reg = snd_soc_component_read(component, WM8994_CLOCKING_1); |
|---|
| 761 | 754 | if (reg < 0 || reg & WM8958_DSP2CLK_ENA) |
|---|
| 762 | 755 | return -EBUSY; |
|---|
| 763 | 756 | |
|---|
| .. | .. |
|---|
| 831 | 824 | |
|---|
| 832 | 825 | wm8958_dsp_apply(component, eq, ucontrol->value.integer.value[0]); |
|---|
| 833 | 826 | |
|---|
| 834 | | - return 0; |
|---|
| 827 | + return 1; |
|---|
| 835 | 828 | } |
|---|
| 836 | 829 | |
|---|
| 837 | 830 | #define WM8958_ENH_EQ_SWITCH(xname, xval) {\ |
|---|