Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // Analog Devices ADAU7118 8 channel PDM-to-I2S/TDM Converter driver over I2C
0004 //
0005 // Copyright 2019 Analog Devices Inc.
0006 
0007 #include <linux/i2c.h>
0008 #include <linux/module.h>
0009 #include <linux/regmap.h>
0010 
0011 #include "adau7118.h"
0012 
0013 static const struct reg_default adau7118_reg_defaults[] = {
0014     { ADAU7118_REG_VENDOR_ID, 0x41 },
0015     { ADAU7118_REG_DEVICE_ID1, 0x71 },
0016     { ADAU7118_REG_DEVICE_ID2, 0x18 },
0017     { ADAU7118_REG_REVISION_ID, 0x00 },
0018     { ADAU7118_REG_ENABLES, 0x3F },
0019     { ADAU7118_REG_DEC_RATIO_CLK_MAP, 0xC0 },
0020     { ADAU7118_REG_HPF_CONTROL, 0xD0 },
0021     { ADAU7118_REG_SPT_CTRL1, 0x41 },
0022     { ADAU7118_REG_SPT_CTRL2, 0x00 },
0023     { ADAU7118_REG_SPT_CX(0), 0x01 },
0024     { ADAU7118_REG_SPT_CX(1), 0x11 },
0025     { ADAU7118_REG_SPT_CX(2), 0x21 },
0026     { ADAU7118_REG_SPT_CX(3), 0x31 },
0027     { ADAU7118_REG_SPT_CX(4), 0x41 },
0028     { ADAU7118_REG_SPT_CX(5), 0x51 },
0029     { ADAU7118_REG_SPT_CX(6), 0x61 },
0030     { ADAU7118_REG_SPT_CX(7), 0x71 },
0031     { ADAU7118_REG_DRIVE_STRENGTH, 0x2a },
0032     { ADAU7118_REG_RESET, 0x00 },
0033 };
0034 
0035 static bool adau7118_volatile(struct device *dev, unsigned int reg)
0036 {
0037     return (reg == ADAU7118_REG_RESET);
0038 }
0039 
0040 
0041 static const struct regmap_config adau7118_regmap_config = {
0042     .reg_bits = 8,
0043     .val_bits = 8,
0044     .reg_defaults = adau7118_reg_defaults,
0045     .num_reg_defaults = ARRAY_SIZE(adau7118_reg_defaults),
0046     .cache_type = REGCACHE_RBTREE,
0047     .max_register = ADAU7118_REG_RESET,
0048     .volatile_reg = adau7118_volatile,
0049 };
0050 
0051 static int adau7118_probe_i2c(struct i2c_client *i2c)
0052 {
0053     struct regmap *map;
0054 
0055     map = devm_regmap_init_i2c(i2c, &adau7118_regmap_config);
0056     if (IS_ERR(map)) {
0057         dev_err(&i2c->dev, "Failed to init regmap %ld\n", PTR_ERR(map));
0058         return PTR_ERR(map);
0059     }
0060 
0061     return adau7118_probe(&i2c->dev, map, false);
0062 }
0063 
0064 static const struct of_device_id adau7118_of_match[] = {
0065     { .compatible = "adi,adau7118" },
0066     {}
0067 };
0068 MODULE_DEVICE_TABLE(of, adau7118_of_match);
0069 
0070 static const struct i2c_device_id adau7118_id[] = {
0071     {"adau7118", 0},
0072     {}
0073 };
0074 MODULE_DEVICE_TABLE(i2c, adau7118_id);
0075 
0076 static struct i2c_driver adau7118_driver = {
0077     .driver = {
0078         .name = "adau7118",
0079         .of_match_table = adau7118_of_match,
0080     },
0081     .probe_new = adau7118_probe_i2c,
0082     .id_table = adau7118_id,
0083 };
0084 module_i2c_driver(adau7118_driver);
0085 
0086 MODULE_AUTHOR("Nuno Sa <nuno.sa@analog.com>");
0087 MODULE_DESCRIPTION("ADAU7118 8 channel PDM-to-I2S/TDM Converter driver over I2C");
0088 MODULE_LICENSE("GPL");