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

ASoC: codecs: adau1373: drop platform data

Merge series from Nuno Sa <nuno.sa@analog.com>:

Support the powerdown GPIO on ADAU1373.

+272 -83
+111
Documentation/devicetree/bindings/sound/adi,adau1373.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/adi,adau1373.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices ADAU1373 CODEC 8 + 9 + maintainers: 10 + - Nuno Sá <nuno.sa@analog.com> 11 + 12 + description: | 13 + Analog Devices ADAU1373 Low power codec with speaker and headphone amplifiers. 14 + https://www.analog.com/media/en/technical-documentation/data-sheets/ADAU1373.pdf 15 + 16 + allOf: 17 + - $ref: dai-common.yaml# 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - adi,adau1373 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + "#sound-dai-cells": 28 + const: 0 29 + 30 + powerdown-gpios: 31 + description: GPIO used for hardware power-down. 32 + maxItems: 1 33 + 34 + adi,micbias1-microvolt: 35 + description: 36 + This property sets the microphone bias voltage for the first microphone. 37 + enum: [1800000, 2200000, 2600000, 2900000] 38 + default: 2900000 39 + 40 + adi,micbias2-microvolt: 41 + description: 42 + This property sets the microphone bias voltage for the second microphone. 43 + enum: [1800000, 2200000, 2600000, 2900000] 44 + default: 2900000 45 + 46 + adi,input1-differential: 47 + description: This property sets the first analog input as differential. 48 + type: boolean 49 + 50 + adi,input2-differential: 51 + description: This property sets the second analog input as differential. 52 + type: boolean 53 + 54 + adi,input3-differential: 55 + description: This property sets the third analog input as differential. 56 + type: boolean 57 + 58 + adi,input4-differential: 59 + description: This property sets the fourth analog input as differential. 60 + type: boolean 61 + 62 + adi,lineout-differential: 63 + description: This property sets the line output as differential. 64 + type: boolean 65 + 66 + adi,lineout-gnd-sense: 67 + description: This property enables the line output ground sense control. 68 + type: boolean 69 + 70 + adi,drc-settings: 71 + description: 72 + This setting is used to control the dynamic range of the signal. The 73 + device provides a maximum of three full band DRCs with 13 entries each. 74 + $ref: /schemas/types.yaml#/definitions/uint8-array 75 + oneOf: 76 + - minItems: 13 77 + maxItems: 13 78 + - minItems: 26 79 + maxItems: 26 80 + - minItems: 39 81 + maxItems: 39 82 + 83 + required: 84 + - "#sound-dai-cells" 85 + - compatible 86 + - reg 87 + 88 + unevaluatedProperties: false 89 + 90 + examples: 91 + - | 92 + #include <dt-bindings/gpio/gpio.h> 93 + 94 + i2c { 95 + #address-cells = <1>; 96 + #size-cells = <0>; 97 + audio-codec@1a { 98 + compatible = "adi,adau1373"; 99 + reg = <0x1a>; 100 + #sound-dai-cells = <0>; 101 + powerdown-gpios = <&gpio 100 GPIO_ACTIVE_LOW>; 102 + adi,input2-differential; 103 + adi,input1-differential; 104 + adi,lineout-differential; 105 + adi,micbias2-microvolt = <1800000>; 106 + adi,drc-settings = /bits/ 8 < 107 + 0xff 0xff 0x1 0x2 0xa 0xa 0xd 0x1 0xff 0xff 0x5 0xd 0xff 108 + >; 109 + }; 110 + }; 111 + ...
+1
MAINTAINERS
··· 1521 1521 S: Supported 1522 1522 W: http://wiki.analog.com/ 1523 1523 W: https://ez.analog.com/linux-software-drivers 1524 + F: Documentation/devicetree/bindings/sound/adi,* 1524 1525 F: sound/soc/codecs/ad1* 1525 1526 F: sound/soc/codecs/ad7* 1526 1527 F: sound/soc/codecs/adau*
-33
include/sound/adau1373.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * Analog Devices ADAU1373 Audio Codec drive 4 - * 5 - * Copyright 2011 Analog Devices Inc. 6 - * Author: Lars-Peter Clausen <lars@metafoo.de> 7 - */ 8 - 9 - #ifndef __SOUND_ADAU1373_H__ 10 - #define __SOUND_ADAU1373_H__ 11 - 12 - enum adau1373_micbias_voltage { 13 - ADAU1373_MICBIAS_2_9V = 0, 14 - ADAU1373_MICBIAS_2_2V = 1, 15 - ADAU1373_MICBIAS_2_6V = 2, 16 - ADAU1373_MICBIAS_1_8V = 3, 17 - }; 18 - 19 - #define ADAU1373_DRC_SIZE 13 20 - 21 - struct adau1373_platform_data { 22 - bool input_differential[4]; 23 - bool lineout_differential; 24 - bool lineout_ground_sense; 25 - 26 - unsigned int num_drc; 27 - uint8_t drc_setting[3][ADAU1373_DRC_SIZE]; 28 - 29 - enum adau1373_micbias_voltage micbias1; 30 - enum adau1373_micbias_voltage micbias2; 31 - }; 32 - 33 - #endif
+1 -1
sound/soc/codecs/Kconfig
··· 465 465 select REGMAP_SPI 466 466 467 467 config SND_SOC_ADAU1373 468 - tristate 468 + tristate "Analog Devices ADAU1373 CODEC" 469 469 depends on I2C 470 470 select SND_SOC_ADAU_UTILS 471 471
+159 -49
sound/soc/codecs/adau1373.c
··· 8 8 9 9 #include <linux/module.h> 10 10 #include <linux/init.h> 11 + #include <linux/gpio/consumer.h> 11 12 #include <linux/delay.h> 12 13 #include <linux/pm.h> 14 + #include <linux/property.h> 13 15 #include <linux/i2c.h> 14 16 #include <linux/slab.h> 15 17 ··· 20 18 #include <sound/pcm_params.h> 21 19 #include <sound/tlv.h> 22 20 #include <sound/soc.h> 23 - #include <sound/adau1373.h> 24 21 25 22 #include "adau1373.h" 26 23 #include "adau-utils.h" ··· 31 30 bool clock_provider; 32 31 }; 33 32 33 + enum adau1373_micbias_voltage { 34 + ADAU1373_MICBIAS_2_9V, 35 + ADAU1373_MICBIAS_2_2V, 36 + ADAU1373_MICBIAS_2_6V, 37 + ADAU1373_MICBIAS_1_8V, 38 + }; 39 + 40 + #define ADAU1373_DRC_SIZE 13 41 + 34 42 struct adau1373 { 35 43 struct regmap *regmap; 36 44 struct adau1373_dai dais[3]; 45 + 46 + bool input_differential[4]; 47 + bool lineout_differential; 48 + bool lineout_ground_sense; 49 + 50 + unsigned int num_drc; 51 + u8 drc_setting[3][ADAU1373_DRC_SIZE]; 52 + 53 + enum adau1373_micbias_voltage micbias1; 54 + enum adau1373_micbias_voltage micbias2; 37 55 }; 38 56 39 57 #define ADAU1373_INPUT_MODE 0x00 ··· 1352 1332 regmap_write(adau1373->regmap, ADAU1373_DRC(nr) + i, drc[i]); 1353 1333 } 1354 1334 1355 - static bool adau1373_valid_micbias(enum adau1373_micbias_voltage micbias) 1335 + static int adau1373_get_micbias(unsigned int val, 1336 + enum adau1373_micbias_voltage *micbias) 1356 1337 { 1357 - switch (micbias) { 1358 - case ADAU1373_MICBIAS_2_9V: 1359 - case ADAU1373_MICBIAS_2_2V: 1360 - case ADAU1373_MICBIAS_2_6V: 1361 - case ADAU1373_MICBIAS_1_8V: 1362 - return true; 1338 + switch (val) { 1339 + case 2900000: 1340 + *micbias = ADAU1373_MICBIAS_2_9V; 1341 + return 0; 1342 + case 2200000: 1343 + *micbias = ADAU1373_MICBIAS_2_2V; 1344 + return 0; 1345 + case 2600000: 1346 + *micbias = ADAU1373_MICBIAS_2_6V; 1347 + return 0; 1348 + case 1800000: 1349 + *micbias = ADAU1373_MICBIAS_1_8V; 1350 + return 0; 1363 1351 default: 1364 - break; 1352 + return -EINVAL; 1365 1353 } 1366 - return false; 1367 1354 } 1368 1355 1369 1356 static int adau1373_probe(struct snd_soc_component *component) 1370 1357 { 1371 1358 struct adau1373 *adau1373 = snd_soc_component_get_drvdata(component); 1372 - struct adau1373_platform_data *pdata = component->dev->platform_data; 1373 - bool lineout_differential = false; 1374 1359 unsigned int val; 1375 1360 int i; 1376 1361 1377 - if (pdata) { 1378 - if (pdata->num_drc > ARRAY_SIZE(pdata->drc_setting)) 1379 - return -EINVAL; 1380 - 1381 - if (!adau1373_valid_micbias(pdata->micbias1) || 1382 - !adau1373_valid_micbias(pdata->micbias2)) 1383 - return -EINVAL; 1384 - 1385 - for (i = 0; i < pdata->num_drc; ++i) { 1386 - adau1373_load_drc_settings(adau1373, i, 1387 - pdata->drc_setting[i]); 1388 - } 1389 - 1390 - snd_soc_add_component_controls(component, adau1373_drc_controls, 1391 - pdata->num_drc); 1392 - 1393 - val = 0; 1394 - for (i = 0; i < 4; ++i) { 1395 - if (pdata->input_differential[i]) 1396 - val |= BIT(i); 1397 - } 1398 - regmap_write(adau1373->regmap, ADAU1373_INPUT_MODE, val); 1399 - 1400 - val = 0; 1401 - if (pdata->lineout_differential) 1402 - val |= ADAU1373_OUTPUT_CTRL_LDIFF; 1403 - if (pdata->lineout_ground_sense) 1404 - val |= ADAU1373_OUTPUT_CTRL_LNFBEN; 1405 - regmap_write(adau1373->regmap, ADAU1373_OUTPUT_CTRL, val); 1406 - 1407 - lineout_differential = pdata->lineout_differential; 1408 - 1409 - regmap_write(adau1373->regmap, ADAU1373_EP_CTRL, 1410 - (pdata->micbias1 << ADAU1373_EP_CTRL_MICBIAS1_OFFSET) | 1411 - (pdata->micbias2 << ADAU1373_EP_CTRL_MICBIAS2_OFFSET)); 1362 + for (i = 0; i < adau1373->num_drc; ++i) { 1363 + adau1373_load_drc_settings(adau1373, i, 1364 + adau1373->drc_setting[i]); 1412 1365 } 1413 1366 1414 - if (!lineout_differential) { 1367 + snd_soc_add_component_controls(component, adau1373_drc_controls, 1368 + adau1373->num_drc); 1369 + 1370 + val = 0; 1371 + for (i = 0; i < ARRAY_SIZE(adau1373->input_differential); ++i) { 1372 + if (adau1373->input_differential[i]) 1373 + val |= BIT(i); 1374 + } 1375 + regmap_write(adau1373->regmap, ADAU1373_INPUT_MODE, val); 1376 + 1377 + val = 0; 1378 + if (adau1373->lineout_differential) 1379 + val |= ADAU1373_OUTPUT_CTRL_LDIFF; 1380 + if (adau1373->lineout_ground_sense) 1381 + val |= ADAU1373_OUTPUT_CTRL_LNFBEN; 1382 + 1383 + regmap_write(adau1373->regmap, ADAU1373_OUTPUT_CTRL, val); 1384 + 1385 + regmap_write(adau1373->regmap, ADAU1373_EP_CTRL, 1386 + (adau1373->micbias1 << ADAU1373_EP_CTRL_MICBIAS1_OFFSET) | 1387 + (adau1373->micbias2 << ADAU1373_EP_CTRL_MICBIAS2_OFFSET)); 1388 + 1389 + if (!adau1373->lineout_differential) { 1415 1390 snd_soc_add_component_controls(component, adau1373_lineout2_controls, 1416 1391 ARRAY_SIZE(adau1373_lineout2_controls)); 1417 1392 } ··· 1486 1471 .endianness = 1, 1487 1472 }; 1488 1473 1474 + static void adau1373_reset(void *reset_gpio) 1475 + { 1476 + gpiod_set_value_cansleep(reset_gpio, 1); 1477 + } 1478 + 1479 + static int adau1373_parse_fw(struct device *dev, struct adau1373 *adau1373) 1480 + { 1481 + int ret, drc_count; 1482 + unsigned int val; 1483 + 1484 + if (device_property_present(dev, "adi,input1-differential")) 1485 + adau1373->input_differential[0] = true; 1486 + if (device_property_present(dev, "adi,input2-differential")) 1487 + adau1373->input_differential[1] = true; 1488 + if (device_property_present(dev, "adi,input3-differential")) 1489 + adau1373->input_differential[2] = true; 1490 + if (device_property_present(dev, "adi,input4-differential")) 1491 + adau1373->input_differential[3] = true; 1492 + 1493 + if (device_property_present(dev, "adi,lineout-differential")) 1494 + adau1373->lineout_differential = true; 1495 + if (device_property_present(dev, "adi,lineout-gnd-sense")) 1496 + adau1373->lineout_ground_sense = true; 1497 + 1498 + ret = device_property_read_u32(dev, "adi,micbias1-microvolt", &val); 1499 + if (!ret) { 1500 + ret = adau1373_get_micbias(val, &adau1373->micbias1); 1501 + if (ret) 1502 + return dev_err_probe(dev, ret, 1503 + "Failed to get micbias1(%u)\n", val); 1504 + } 1505 + 1506 + ret = device_property_read_u32(dev, "adi,micbias2-microvolt", &val); 1507 + if (!ret) { 1508 + ret = adau1373_get_micbias(val, &adau1373->micbias2); 1509 + if (ret) 1510 + return dev_err_probe(dev, ret, 1511 + "Failed to get micbias2(%u)\n", val); 1512 + } 1513 + 1514 + drc_count = device_property_count_u8(dev, "adi,drc-settings"); 1515 + if (drc_count < 0) 1516 + return 0; 1517 + if (drc_count % ADAU1373_DRC_SIZE != 0) 1518 + return dev_err_probe(dev, -EINVAL, 1519 + "DRC count(%u) not multiple of %u\n", 1520 + drc_count, ADAU1373_DRC_SIZE); 1521 + 1522 + adau1373->num_drc = drc_count / ADAU1373_DRC_SIZE; 1523 + if (adau1373->num_drc > ARRAY_SIZE(adau1373->drc_setting)) 1524 + return dev_err_probe(dev, -EINVAL, 1525 + "Too many DRC settings(%u)\n", 1526 + adau1373->num_drc); 1527 + 1528 + ret = device_property_read_u8_array(dev, "adi,drc-settings", 1529 + (u8 *)&adau1373->drc_setting[0], 1530 + drc_count); 1531 + if (ret) 1532 + return dev_err_probe(dev, ret, 1533 + "Failed to read DRC settings\n"); 1534 + 1535 + return 0; 1536 + } 1537 + 1489 1538 static int adau1373_i2c_probe(struct i2c_client *client) 1490 1539 { 1491 1540 struct adau1373 *adau1373; 1541 + struct gpio_desc *gpiod; 1492 1542 int ret; 1493 1543 1494 1544 adau1373 = devm_kzalloc(&client->dev, sizeof(*adau1373), GFP_KERNEL); ··· 1565 1485 if (IS_ERR(adau1373->regmap)) 1566 1486 return PTR_ERR(adau1373->regmap); 1567 1487 1568 - regmap_write(adau1373->regmap, ADAU1373_SOFT_RESET, 0x00); 1488 + /* 1489 + * If the powerdown GPIO is specified, we use it for reset. Otherwise 1490 + * a software reset is done. 1491 + */ 1492 + gpiod = devm_gpiod_get_optional(&client->dev, "powerdown", 1493 + GPIOD_OUT_HIGH); 1494 + if (IS_ERR(gpiod)) 1495 + return PTR_ERR(gpiod); 1496 + 1497 + if (gpiod) { 1498 + gpiod_set_value_cansleep(gpiod, 0); 1499 + fsleep(10); 1500 + 1501 + ret = devm_add_action_or_reset(&client->dev, adau1373_reset, 1502 + gpiod); 1503 + if (ret) 1504 + return ret; 1505 + } else { 1506 + regmap_write(adau1373->regmap, ADAU1373_SOFT_RESET, 0x00); 1507 + } 1569 1508 1570 1509 dev_set_drvdata(&client->dev, adau1373); 1510 + 1511 + ret = adau1373_parse_fw(&client->dev, adau1373); 1512 + if (ret) 1513 + return ret; 1571 1514 1572 1515 ret = devm_snd_soc_register_component(&client->dev, 1573 1516 &adau1373_component_driver, ··· 1604 1501 }; 1605 1502 MODULE_DEVICE_TABLE(i2c, adau1373_i2c_id); 1606 1503 1504 + static const struct of_device_id adau1373_of_match[] = { 1505 + { .compatible = "adi,adau1373", }, 1506 + { } 1507 + }; 1508 + MODULE_DEVICE_TABLE(of, adau1373_of_match); 1509 + 1607 1510 static struct i2c_driver adau1373_i2c_driver = { 1608 1511 .driver = { 1609 1512 .name = "adau1373", 1513 + .of_match_table = adau1373_of_match, 1610 1514 }, 1611 1515 .probe = adau1373_i2c_probe, 1612 1516 .id_table = adau1373_i2c_id,