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

ASoC: cs35l45: Support for GPIO pins configuration.

Adds device tree configuration for cs35l45 GPIOs

Signed-off-by: Vlad Karpovich <vkarpovi@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20230315154722.3911463-1-vkarpovi@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Vlad.Karpovich and committed by
Mark Brown
fa8c052b 00a7ef32

+152 -2
+57
include/dt-bindings/sound/cs35l45.h
··· 17 17 #define CS35L45_ASP_TX_HIZ_UNUSED 0x1 18 18 #define CS35L45_ASP_TX_HIZ_DISABLED 0x2 19 19 20 + /* 21 + * Optional GPIOX Sub-nodes: 22 + * The cs35l45 node can have up to three "cirrus,gpio-ctrlX" ('X' = [1,2,3]) 23 + * sub-nodes for configuring the GPIO pins. 24 + * 25 + * - gpio-dir : GPIO pin direction. Valid only when 'gpio-ctrl' 26 + * is 1. 27 + * 0 = Output 28 + * 1 = Input (Default) 29 + * 30 + * - gpio-lvl : GPIO level. Valid only when 'gpio-ctrl' is 1 and 'gpio-dir' is 0. 31 + * 32 + * 0 = Low (Default) 33 + * 1 = High 34 + * 35 + * - gpio-op-cfg : GPIO output configuration. Valid only when 'gpio-ctrl' is 1 36 + * and 'gpio-dir' is 0. 37 + * 38 + * 0 = CMOS (Default) 39 + * 1 = Open Drain 40 + * 41 + * - gpio-pol : GPIO output polarity select. Valid only when 'gpio-ctrl' is 1 42 + * and 'gpio-dir' is 0. 43 + * 44 + * 0 = Non-inverted, Active High (Default) 45 + * 1 = Inverted, Active Low 46 + * 47 + * - gpio-invert : Defines the polarity of the GPIO pin if configured 48 + * as input. 49 + * 50 + * 0 = Not inverted (Default) 51 + * 1 = Inverted 52 + * 53 + * - gpio-ctrl : Defines the function of the GPIO pin. 54 + * 55 + * GPIO1: 56 + * 0 = High impedance input (Default) 57 + * 1 = Pin acts as a GPIO, direction controlled by 'gpio-dir' 58 + * 2 = Pin acts as MDSYNC, direction controlled by MDSYNC 59 + * 3-7 = Reserved 60 + * 61 + * GPIO2: 62 + * 0 = High impedance input (Default) 63 + * 1 = Pin acts as a GPIO, direction controlled by 'gpio-dir' 64 + * 2 = Pin acts as open drain INT 65 + * 3 = Reserved 66 + * 4 = Pin acts as push-pull output INT. Active low. 67 + * 5 = Pin acts as push-pull output INT. Active high. 68 + * 6,7 = Reserved 69 + * 70 + * GPIO3: 71 + * 0 = High impedance input (Default) 72 + * 1 = Pin acts as a GPIO, direction controlled by 'gpio-dir' 73 + * 2-7 = Reserved 74 + */ 75 + #define CS35L45_NUM_GPIOS 0x3 76 + 20 77 #endif /* DT_CS35L45_H */
+14
sound/soc/codecs/cs35l45-tables.c
··· 43 43 static const struct reg_default cs35l45_defaults[] = { 44 44 { CS35L45_BLOCK_ENABLES, 0x00003323 }, 45 45 { CS35L45_BLOCK_ENABLES2, 0x00000010 }, 46 + { CS35L45_SYNC_GPIO1, 0x00000007 }, 47 + { CS35L45_INTB_GPIO2_MCLK_REF, 0x00000005 }, 48 + { CS35L45_GPIO3, 0x00000005 }, 46 49 { CS35L45_REFCLK_INPUT, 0x00000510 }, 47 50 { CS35L45_GLOBAL_SAMPLE_RATE, 0x00000003 }, 48 51 { CS35L45_ASP_ENABLES1, 0x00000000 }, ··· 64 61 { CS35L45_ASPTX4_INPUT, 0x00000028 }, 65 62 { CS35L45_ASPTX5_INPUT, 0x00000048 }, 66 63 { CS35L45_AMP_PCM_CONTROL, 0x00100000 }, 64 + { CS35L45_GPIO1_CTRL1, 0x81000001 }, 65 + { CS35L45_GPIO2_CTRL1, 0x81000001 }, 66 + { CS35L45_GPIO3_CTRL1, 0x81000001 }, 67 67 }; 68 68 69 69 static bool cs35l45_readable_reg(struct device *dev, unsigned int reg) ··· 78 72 case CS35L45_BLOCK_ENABLES: 79 73 case CS35L45_BLOCK_ENABLES2: 80 74 case CS35L45_ERROR_RELEASE: 75 + case CS35L45_SYNC_GPIO1: 76 + case CS35L45_INTB_GPIO2_MCLK_REF: 77 + case CS35L45_GPIO3: 81 78 case CS35L45_REFCLK_INPUT: 82 79 case CS35L45_GLOBAL_SAMPLE_RATE: 83 80 case CS35L45_ASP_ENABLES1: ··· 101 92 case CS35L45_AMP_PCM_CONTROL: 102 93 case CS35L45_AMP_PCM_HPF_TST: 103 94 case CS35L45_IRQ1_EINT_4: 95 + case CS35L45_GPIO_STATUS1: 96 + case CS35L45_GPIO1_CTRL1: 97 + case CS35L45_GPIO2_CTRL1: 98 + case CS35L45_GPIO3_CTRL1: 104 99 return true; 105 100 default: 106 101 return false; ··· 120 107 case CS35L45_ERROR_RELEASE: 121 108 case CS35L45_AMP_PCM_HPF_TST: /* not cachable */ 122 109 case CS35L45_IRQ1_EINT_4: 110 + case CS35L45_GPIO_STATUS1: 123 111 return true; 124 112 default: 125 113 return false;
+56
sound/soc/codecs/cs35l45.c
··· 536 536 537 537 static int cs35l45_apply_property_config(struct cs35l45_private *cs35l45) 538 538 { 539 + struct device_node *node = cs35l45->dev->of_node; 540 + unsigned int gpio_regs[] = {CS35L45_GPIO1_CTRL1, CS35L45_GPIO2_CTRL1, 541 + CS35L45_GPIO3_CTRL1}; 542 + unsigned int pad_regs[] = {CS35L45_SYNC_GPIO1, 543 + CS35L45_INTB_GPIO2_MCLK_REF, CS35L45_GPIO3}; 544 + struct device_node *child; 539 545 unsigned int val; 546 + char of_name[32]; 547 + int ret, i; 548 + 549 + if (!node) 550 + return 0; 551 + 552 + for (i = 0; i < CS35L45_NUM_GPIOS; i++) { 553 + sprintf(of_name, "cirrus,gpio-ctrl%d", i + 1); 554 + child = of_get_child_by_name(node, of_name); 555 + if (!child) 556 + continue; 557 + 558 + ret = of_property_read_u32(child, "gpio-dir", &val); 559 + if (!ret) 560 + regmap_update_bits(cs35l45->regmap, gpio_regs[i], 561 + CS35L45_GPIO_DIR_MASK, 562 + val << CS35L45_GPIO_DIR_SHIFT); 563 + 564 + ret = of_property_read_u32(child, "gpio-lvl", &val); 565 + if (!ret) 566 + regmap_update_bits(cs35l45->regmap, gpio_regs[i], 567 + CS35L45_GPIO_LVL_MASK, 568 + val << CS35L45_GPIO_LVL_SHIFT); 569 + 570 + ret = of_property_read_u32(child, "gpio-op-cfg", &val); 571 + if (!ret) 572 + regmap_update_bits(cs35l45->regmap, gpio_regs[i], 573 + CS35L45_GPIO_OP_CFG_MASK, 574 + val << CS35L45_GPIO_OP_CFG_SHIFT); 575 + 576 + ret = of_property_read_u32(child, "gpio-pol", &val); 577 + if (!ret) 578 + regmap_update_bits(cs35l45->regmap, gpio_regs[i], 579 + CS35L45_GPIO_POL_MASK, 580 + val << CS35L45_GPIO_POL_SHIFT); 581 + 582 + ret = of_property_read_u32(child, "gpio-ctrl", &val); 583 + if (!ret) 584 + regmap_update_bits(cs35l45->regmap, pad_regs[i], 585 + CS35L45_GPIO_CTRL_MASK, 586 + val << CS35L45_GPIO_CTRL_SHIFT); 587 + 588 + ret = of_property_read_u32(child, "gpio-invert", &val); 589 + if (!ret) 590 + regmap_update_bits(cs35l45->regmap, pad_regs[i], 591 + CS35L45_GPIO_INVERT_MASK, 592 + val << CS35L45_GPIO_INVERT_SHIFT); 593 + 594 + of_node_put(child); 595 + } 540 596 541 597 if (device_property_read_u32(cs35l45->dev, 542 598 "cirrus,asp-sdout-hiz-ctrl", &val) == 0) {
+25 -2
sound/soc/codecs/cs35l45.h
··· 14 14 #include <linux/pm_runtime.h> 15 15 #include <linux/regmap.h> 16 16 #include <linux/regulator/consumer.h> 17 + #include <dt-bindings/sound/cs35l45.h> 17 18 18 19 #define CS35L45_DEVID 0x00000000 19 20 #define CS35L45_REVID 0x00000004 ··· 25 24 #define CS35L45_BLOCK_ENABLES 0x00002018 26 25 #define CS35L45_BLOCK_ENABLES2 0x0000201C 27 26 #define CS35L45_ERROR_RELEASE 0x00002034 27 + #define CS35L45_SYNC_GPIO1 0x00002430 28 + #define CS35L45_INTB_GPIO2_MCLK_REF 0x00002434 29 + #define CS35L45_GPIO3 0x00002438 28 30 #define CS35L45_REFCLK_INPUT 0x00002C04 29 31 #define CS35L45_GLOBAL_SAMPLE_RATE 0x00002C0C 30 32 #define CS35L45_BOOST_CCM_CFG 0x00003808 ··· 52 48 #define CS35L45_AMP_PCM_CONTROL 0x00007000 53 49 #define CS35L45_AMP_PCM_HPF_TST 0x00007004 54 50 #define CS35L45_IRQ1_EINT_4 0x0000E01C 55 - #define CS35L45_LASTREG 0x0000E01C 56 - 51 + #define CS35L45_GPIO_STATUS1 0x0000F000 52 + #define CS35L45_GPIO1_CTRL1 0x0000F008 53 + #define CS35L45_GPIO2_CTRL1 0x0000F00C 54 + #define CS35L45_GPIO3_CTRL1 0x0000F010 55 + #define CS35L45_LASTREG 0x0000F010 57 56 /* SFT_RESET */ 58 57 #define CS35L45_SOFT_RESET_TRIGGER 0x5A000000 59 58 ··· 171 164 /* IRQ1_EINT_4 */ 172 165 #define CS35L45_OTP_BOOT_DONE_STS_MASK BIT(1) 173 166 #define CS35L45_OTP_BUSY_MASK BIT(0) 167 + 168 + /* GPIOX_CTRL1 */ 169 + #define CS35L45_GPIO_DIR_SHIFT 31 170 + #define CS35L45_GPIO_DIR_MASK BIT(31) 171 + #define CS35L45_GPIO_LVL_SHIFT 15 172 + #define CS35L45_GPIO_LVL_MASK BIT(15) 173 + #define CS35L45_GPIO_OP_CFG_SHIFT 14 174 + #define CS35L45_GPIO_OP_CFG_MASK BIT(14) 175 + #define CS35L45_GPIO_POL_SHIFT 12 176 + #define CS35L45_GPIO_POL_MASK BIT(12) 177 + 178 + /* SYNC_GPIO1, INTB_GPIO2_MCLK_REF, GPIO3 */ 179 + #define CS35L45_GPIO_CTRL_SHIFT 20 180 + #define CS35L45_GPIO_CTRL_MASK GENMASK(22, 20) 181 + #define CS35L45_GPIO_INVERT_SHIFT 19 182 + #define CS35L45_GPIO_INVERT_MASK BIT(19) 174 183 175 184 /* Mixer sources */ 176 185 #define CS35L45_PCM_SRC_MASK 0x7F