Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge series "Patches to update for rockchip pdm" from Sugar Zhang <sugar.zhang@rock-chips.com>:

These patches fixup or update for rockchip pdm.

Changes in v4:
- Acked by Rob Herring

Changes in v3:
- Fix property 'path-map' suggested by Rob Herring.

Changes in v2:
- Fix yamllint errors.

Sugar Zhang (7):
ASoC: rockchip: Add support for rv1126 pdm
ASoC: dt-bindings: rockchip: Add binding for rv1126 pdm
ASoC: rockchip: pdm: Add support for rk3568 pdm
ASoC: dt-bindings: rockchip: Add binding for rk3568 pdm
ASoC: rockchip: pdm: Add support for path map
ASoC: dt-bindings: rockchip: pdm: Document property
'rockchip,path-map'
ASoC: dt-bindings: rockchip: Convert pdm bindings to yaml

.../devicetree/bindings/sound/rockchip,pdm.txt | 46 --------
.../devicetree/bindings/sound/rockchip,pdm.yaml | 120 +++++++++++++++++++++
sound/soc/rockchip/rockchip_pdm.c | 112 +++++++++++++++++--
sound/soc/rockchip/rockchip_pdm.h | 6 ++
4 files changed, 232 insertions(+), 52 deletions(-)
delete mode 100644 Documentation/devicetree/bindings/sound/rockchip,pdm.txt
create mode 100644 Documentation/devicetree/bindings/sound/rockchip,pdm.yaml

--
2.7.4

+232 -52
-46
Documentation/devicetree/bindings/sound/rockchip,pdm.txt
··· 1 - * Rockchip PDM controller 2 - 3 - Required properties: 4 - 5 - - compatible: "rockchip,pdm" 6 - - "rockchip,px30-pdm" 7 - - "rockchip,rk1808-pdm" 8 - - "rockchip,rk3308-pdm" 9 - - reg: physical base address of the controller and length of memory mapped 10 - region. 11 - - dmas: DMA specifiers for rx dma. See the DMA client binding, 12 - Documentation/devicetree/bindings/dma/dma.txt 13 - - dma-names: should include "rx". 14 - - clocks: a list of phandle + clock-specifer pairs, one for each entry in clock-names. 15 - - clock-names: should contain following: 16 - - "pdm_hclk": clock for PDM BUS 17 - - "pdm_clk" : clock for PDM controller 18 - - resets: a list of phandle + reset-specifer paris, one for each entry in reset-names. 19 - - reset-names: reset names, should include "pdm-m". 20 - - pinctrl-names: Must contain a "default" entry. 21 - - pinctrl-N: One property must exist for each entry in 22 - pinctrl-names. See ../pinctrl/pinctrl-bindings.txt 23 - for details of the property values. 24 - 25 - Example for rk3328 PDM controller: 26 - 27 - pdm: pdm@ff040000 { 28 - compatible = "rockchip,pdm"; 29 - reg = <0x0 0xff040000 0x0 0x1000>; 30 - clocks = <&clk_pdm>, <&clk_gates28 0>; 31 - clock-names = "pdm_clk", "pdm_hclk"; 32 - dmas = <&pdma 16>; 33 - #dma-cells = <1>; 34 - dma-names = "rx"; 35 - pinctrl-names = "default", "sleep"; 36 - pinctrl-0 = <&pdmm0_clk 37 - &pdmm0_sdi0 38 - &pdmm0_sdi1 39 - &pdmm0_sdi2 40 - &pdmm0_sdi3>; 41 - pinctrl-1 = <&pdmm0_clk_sleep 42 - &pdmm0_sdi0_sleep 43 - &pdmm0_sdi1_sleep 44 - &pdmm0_sdi2_sleep 45 - &pdmm0_sdi3_sleep>; 46 - };
+120
Documentation/devicetree/bindings/sound/rockchip,pdm.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/sound/rockchip,pdm.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Rockchip PDM controller 8 + 9 + description: 10 + The Pulse Density Modulation Interface Controller (PDMC) is 11 + a PDM interface controller and decoder that support PDM format. 12 + It integrates a clock generator driving the PDM microphone 13 + and embeds filters which decimate the incoming bit stream to 14 + obtain most common audio rates. 15 + 16 + maintainers: 17 + - Heiko Stuebner <heiko@sntech.de> 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - rockchip,pdm 23 + - rockchip,px30-pdm 24 + - rockchip,rk1808-pdm 25 + - rockchip,rk3308-pdm 26 + - rockchip,rk3568-pdm 27 + - rockchip,rv1126-pdm 28 + 29 + reg: 30 + maxItems: 1 31 + 32 + interrupts: 33 + maxItems: 1 34 + 35 + clocks: 36 + items: 37 + - description: clock for PDM controller 38 + - description: clock for PDM BUS 39 + 40 + clock-names: 41 + items: 42 + - const: pdm_clk 43 + - const: pdm_hclk 44 + 45 + dmas: 46 + maxItems: 1 47 + 48 + dma-names: 49 + items: 50 + - const: rx 51 + 52 + power-domains: 53 + maxItems: 1 54 + 55 + resets: 56 + items: 57 + - description: reset for PDM controller 58 + 59 + reset-names: 60 + items: 61 + - const: pdm-m 62 + 63 + rockchip,path-map: 64 + $ref: /schemas/types.yaml#/definitions/uint32-array 65 + description: 66 + Defines the mapping of PDM SDIx to PDM PATHx. 67 + By default, they are mapped one-to-one. 68 + maxItems: 4 69 + uniqueItems: true 70 + items: 71 + enum: [ 0, 1, 2, 3 ] 72 + 73 + "#sound-dai-cells": 74 + const: 0 75 + 76 + required: 77 + - compatible 78 + - reg 79 + - interrupts 80 + - clocks 81 + - clock-names 82 + - dmas 83 + - dma-names 84 + - "#sound-dai-cells" 85 + 86 + additionalProperties: false 87 + 88 + examples: 89 + - | 90 + #include <dt-bindings/clock/rk3328-cru.h> 91 + #include <dt-bindings/interrupt-controller/arm-gic.h> 92 + #include <dt-bindings/interrupt-controller/irq.h> 93 + #include <dt-bindings/pinctrl/rockchip.h> 94 + 95 + bus { 96 + #address-cells = <2>; 97 + #size-cells = <2>; 98 + 99 + pdm@ff040000 { 100 + compatible = "rockchip,pdm"; 101 + reg = <0x0 0xff040000 0x0 0x1000>; 102 + interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>; 103 + clocks = <&cru SCLK_PDM>, <&cru HCLK_PDM>; 104 + clock-names = "pdm_clk", "pdm_hclk"; 105 + dmas = <&dmac 16>; 106 + dma-names = "rx"; 107 + #sound-dai-cells = <0>; 108 + pinctrl-names = "default", "sleep"; 109 + pinctrl-0 = <&pdmm0_clk 110 + &pdmm0_sdi0 111 + &pdmm0_sdi1 112 + &pdmm0_sdi2 113 + &pdmm0_sdi3>; 114 + pinctrl-1 = <&pdmm0_clk_sleep 115 + &pdmm0_sdi0_sleep 116 + &pdmm0_sdi1_sleep 117 + &pdmm0_sdi2_sleep 118 + &pdmm0_sdi3_sleep>; 119 + }; 120 + };
+106 -6
sound/soc/rockchip/rockchip_pdm.c
··· 20 20 21 21 #define PDM_DMA_BURST_SIZE (8) /* size * width: 8*4 = 32 bytes */ 22 22 #define PDM_SIGNOFF_CLK_RATE (100000000) 23 + #define PDM_PATH_MAX (4) 23 24 24 25 enum rk_pdm_version { 25 26 RK_PDM_RK3229, 26 27 RK_PDM_RK3308, 28 + RK_PDM_RV1126, 27 29 }; 28 30 29 31 struct rk_pdm_dev { ··· 123 121 return ratio; 124 122 } 125 123 124 + static unsigned int get_pdm_cic_ratio(unsigned int clk) 125 + { 126 + switch (clk) { 127 + case 4096000: 128 + case 5644800: 129 + case 6144000: 130 + return 0; 131 + case 2048000: 132 + case 2822400: 133 + case 3072000: 134 + return 1; 135 + case 1024000: 136 + case 1411200: 137 + case 1536000: 138 + return 2; 139 + default: 140 + return 1; 141 + } 142 + } 143 + 144 + static unsigned int samplerate_to_bit(unsigned int samplerate) 145 + { 146 + switch (samplerate) { 147 + case 8000: 148 + case 11025: 149 + case 12000: 150 + return 0; 151 + case 16000: 152 + case 22050: 153 + case 24000: 154 + return 1; 155 + case 32000: 156 + return 2; 157 + case 44100: 158 + case 48000: 159 + return 3; 160 + case 64000: 161 + case 88200: 162 + case 96000: 163 + return 4; 164 + case 128000: 165 + case 176400: 166 + case 192000: 167 + return 5; 168 + default: 169 + return 1; 170 + } 171 + } 172 + 126 173 static inline struct rk_pdm_dev *to_info(struct snd_soc_dai *dai) 127 174 { 128 175 return snd_soc_dai_get_drvdata(dai); ··· 217 166 if (ret) 218 167 return -EINVAL; 219 168 220 - if (pdm->version == RK_PDM_RK3308) { 169 + if (pdm->version == RK_PDM_RK3308 || 170 + pdm->version == RK_PDM_RV1126) { 221 171 rational_best_approximation(clk_out, clk_src, 222 172 GENMASK(16 - 1, 0), 223 173 GENMASK(16 - 1, 0), ··· 246 194 PDM_CLK_FD_RATIO_MSK, 247 195 val); 248 196 } 249 - val = get_pdm_ds_ratio(samplerate); 250 - regmap_update_bits(pdm->regmap, PDM_CLK_CTRL, PDM_DS_RATIO_MSK, val); 197 + 198 + if (pdm->version == RK_PDM_RV1126) { 199 + val = get_pdm_cic_ratio(clk_out); 200 + regmap_update_bits(pdm->regmap, PDM_CLK_CTRL, PDM_CIC_RATIO_MSK, val); 201 + val = samplerate_to_bit(samplerate); 202 + regmap_update_bits(pdm->regmap, PDM_CTRL0, 203 + PDM_SAMPLERATE_MSK, PDM_SAMPLERATE(val)); 204 + } else { 205 + val = get_pdm_ds_ratio(samplerate); 206 + regmap_update_bits(pdm->regmap, PDM_CLK_CTRL, PDM_DS_RATIO_MSK, val); 207 + } 208 + 251 209 regmap_update_bits(pdm->regmap, PDM_HPF_CTRL, 252 210 PDM_HPF_CF_MSK, PDM_HPF_60HZ); 253 211 regmap_update_bits(pdm->regmap, PDM_HPF_CTRL, ··· 503 441 } 504 442 505 443 static const struct reg_default rockchip_pdm_reg_defaults[] = { 506 - {0x04, 0x78000017}, 507 - {0x08, 0x0bb8ea60}, 508 - {0x18, 0x0000001f}, 444 + { PDM_CTRL0, 0x78000017 }, 445 + { PDM_CTRL1, 0x0bb8ea60 }, 446 + { PDM_CLK_CTRL, 0x0000e401 }, 447 + { PDM_DMA_CTRL, 0x0000001f }, 509 448 }; 510 449 511 450 static const struct regmap_config rockchip_pdm_regmap_config = { ··· 532 469 .data = (void *)RK_PDM_RK3308 }, 533 470 { .compatible = "rockchip,rk3308-pdm", 534 471 .data = (void *)RK_PDM_RK3308 }, 472 + { .compatible = "rockchip,rk3568-pdm", 473 + .data = (void *)RK_PDM_RV1126 }, 474 + { .compatible = "rockchip,rv1126-pdm", 475 + .data = (void *)RK_PDM_RV1126 }, 535 476 {}, 536 477 }; 537 478 MODULE_DEVICE_TABLE(of, rockchip_pdm_match); 538 479 480 + static int rockchip_pdm_path_parse(struct rk_pdm_dev *pdm, struct device_node *node) 481 + { 482 + unsigned int path[PDM_PATH_MAX]; 483 + int cnt = 0, ret = 0, i = 0, val = 0, msk = 0; 484 + 485 + cnt = of_count_phandle_with_args(node, "rockchip,path-map", 486 + NULL); 487 + if (cnt != PDM_PATH_MAX) 488 + return cnt; 489 + 490 + ret = of_property_read_u32_array(node, "rockchip,path-map", 491 + path, cnt); 492 + if (ret) 493 + return ret; 494 + 495 + for (i = 0; i < cnt; i++) { 496 + if (path[i] >= PDM_PATH_MAX) 497 + return -EINVAL; 498 + msk |= PDM_PATH_MASK(i); 499 + val |= PDM_PATH(i, path[i]); 500 + } 501 + 502 + regmap_update_bits(pdm->regmap, PDM_CLK_CTRL, msk, val); 503 + 504 + return 0; 505 + } 506 + 539 507 static int rockchip_pdm_probe(struct platform_device *pdev) 540 508 { 509 + struct device_node *node = pdev->dev.of_node; 541 510 const struct of_device_id *match; 542 511 struct rk_pdm_dev *pdm; 543 512 struct resource *res; ··· 635 540 } 636 541 637 542 rockchip_pdm_rxctrl(pdm, 0); 543 + 544 + ret = rockchip_pdm_path_parse(pdm, node); 545 + if (ret != 0 && ret != -ENOENT) 546 + goto err_suspend; 547 + 638 548 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 639 549 if (ret) { 640 550 dev_err(&pdev->dev, "could not register pcm: %d\n", ret);
+6
sound/soc/rockchip/rockchip_pdm.h
··· 41 41 #define PDM_PATH1_EN BIT(28) 42 42 #define PDM_PATH0_EN BIT(27) 43 43 #define PDM_HWT_EN BIT(26) 44 + #define PDM_SAMPLERATE_MSK GENMASK(7, 5) 45 + #define PDM_SAMPLERATE(x) ((x) << 5) 44 46 #define PDM_VDW_MSK (0x1f << 0) 45 47 #define PDM_VDW(X) ((X - 1) << 0) 46 48 ··· 53 51 #define PDM_FD_DENOMINATOR_MSK GENMASK(15, 0) 54 52 55 53 /* PDM CLK CTRL */ 54 + #define PDM_PATH_SHIFT(x) (8 + (x) * 2) 55 + #define PDM_PATH_MASK(x) (0x3 << PDM_PATH_SHIFT(x)) 56 + #define PDM_PATH(x, v) ((v) << PDM_PATH_SHIFT(x)) 56 57 #define PDM_CLK_FD_RATIO_MSK BIT(6) 57 58 #define PDM_CLK_FD_RATIO_40 (0X0 << 6) 58 59 #define PDM_CLK_FD_RATIO_35 BIT(6) ··· 71 66 #define PDM_CLK_1280FS (0x2 << 0) 72 67 #define PDM_CLK_2560FS (0x3 << 0) 73 68 #define PDM_CLK_5120FS (0x4 << 0) 69 + #define PDM_CIC_RATIO_MSK (0x3 << 0) 74 70 75 71 /* PDM HPF CTRL */ 76 72 #define PDM_HPF_LE BIT(3)