adau7118-i2c.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Analog Devices ADAU7118 8 channel PDM-to-I2S/TDM Converter driver over I2C
  4. //
  5. // Copyright 2019 Analog Devices Inc.
  6. #include <linux/i2c.h>
  7. #include <linux/module.h>
  8. #include <linux/regmap.h>
  9. #include "adau7118.h"
  10. static const struct reg_default adau7118_reg_defaults[] = {
  11. { ADAU7118_REG_VENDOR_ID, 0x41 },
  12. { ADAU7118_REG_DEVICE_ID1, 0x71 },
  13. { ADAU7118_REG_DEVICE_ID2, 0x18 },
  14. { ADAU7118_REG_REVISION_ID, 0x00 },
  15. { ADAU7118_REG_ENABLES, 0x3F },
  16. { ADAU7118_REG_DEC_RATIO_CLK_MAP, 0xC0 },
  17. { ADAU7118_REG_HPF_CONTROL, 0xD0 },
  18. { ADAU7118_REG_SPT_CTRL1, 0x41 },
  19. { ADAU7118_REG_SPT_CTRL2, 0x00 },
  20. { ADAU7118_REG_SPT_CX(0), 0x01 },
  21. { ADAU7118_REG_SPT_CX(1), 0x11 },
  22. { ADAU7118_REG_SPT_CX(2), 0x21 },
  23. { ADAU7118_REG_SPT_CX(3), 0x31 },
  24. { ADAU7118_REG_SPT_CX(4), 0x41 },
  25. { ADAU7118_REG_SPT_CX(5), 0x51 },
  26. { ADAU7118_REG_SPT_CX(6), 0x61 },
  27. { ADAU7118_REG_SPT_CX(7), 0x71 },
  28. { ADAU7118_REG_DRIVE_STRENGTH, 0x2a },
  29. { ADAU7118_REG_RESET, 0x00 },
  30. };
  31. static bool adau7118_volatile(struct device *dev, unsigned int reg)
  32. {
  33. return (reg == ADAU7118_REG_RESET);
  34. }
  35. static const struct regmap_config adau7118_regmap_config = {
  36. .reg_bits = 8,
  37. .val_bits = 8,
  38. .reg_defaults = adau7118_reg_defaults,
  39. .num_reg_defaults = ARRAY_SIZE(adau7118_reg_defaults),
  40. .cache_type = REGCACHE_RBTREE,
  41. .max_register = ADAU7118_REG_RESET,
  42. .volatile_reg = adau7118_volatile,
  43. };
  44. static int adau7118_probe_i2c(struct i2c_client *i2c)
  45. {
  46. struct regmap *map;
  47. map = devm_regmap_init_i2c(i2c, &adau7118_regmap_config);
  48. if (IS_ERR(map)) {
  49. dev_err(&i2c->dev, "Failed to init regmap %ld\n", PTR_ERR(map));
  50. return PTR_ERR(map);
  51. }
  52. return adau7118_probe(&i2c->dev, map, false);
  53. }
  54. static const struct of_device_id adau7118_of_match[] = {
  55. { .compatible = "adi,adau7118" },
  56. {}
  57. };
  58. MODULE_DEVICE_TABLE(of, adau7118_of_match);
  59. static const struct i2c_device_id adau7118_id[] = {
  60. {"adau7118", 0},
  61. {}
  62. };
  63. MODULE_DEVICE_TABLE(i2c, adau7118_id);
  64. static struct i2c_driver adau7118_driver = {
  65. .driver = {
  66. .name = "adau7118",
  67. .of_match_table = adau7118_of_match,
  68. },
  69. .probe_new = adau7118_probe_i2c,
  70. .id_table = adau7118_id,
  71. };
  72. module_i2c_driver(adau7118_driver);
  73. MODULE_AUTHOR("Nuno Sa <[email protected]>");
  74. MODULE_DESCRIPTION("ADAU7118 8 channel PDM-to-I2S/TDM Converter driver over I2C");
  75. MODULE_LICENSE("GPL");