tlv320aic32x4-i2c.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright 2011-2019 NW Digital Radio
  4. *
  5. * Author: Annaliese McDermond <[email protected]>
  6. *
  7. * Based on sound/soc/codecs/wm8974 and TI driver for kernel 2.6.27.
  8. *
  9. */
  10. #include <linux/i2c.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include <sound/soc.h>
  15. #include "tlv320aic32x4.h"
  16. static const struct of_device_id aic32x4_of_id[];
  17. static const struct i2c_device_id aic32x4_i2c_id[];
  18. static int aic32x4_i2c_probe(struct i2c_client *i2c)
  19. {
  20. struct regmap *regmap;
  21. struct regmap_config config;
  22. config = aic32x4_regmap_config;
  23. config.reg_bits = 8;
  24. config.val_bits = 8;
  25. regmap = devm_regmap_init_i2c(i2c, &config);
  26. if (i2c->dev.of_node) {
  27. const struct of_device_id *oid;
  28. oid = of_match_node(aic32x4_of_id, i2c->dev.of_node);
  29. dev_set_drvdata(&i2c->dev, (void *)oid->data);
  30. } else {
  31. const struct i2c_device_id *id;
  32. id = i2c_match_id(aic32x4_i2c_id, i2c);
  33. dev_set_drvdata(&i2c->dev, (void *)id->driver_data);
  34. }
  35. return aic32x4_probe(&i2c->dev, regmap);
  36. }
  37. static void aic32x4_i2c_remove(struct i2c_client *i2c)
  38. {
  39. aic32x4_remove(&i2c->dev);
  40. }
  41. static const struct i2c_device_id aic32x4_i2c_id[] = {
  42. { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 },
  43. { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 },
  44. { "tas2505", (kernel_ulong_t)AIC32X4_TYPE_TAS2505 },
  45. { /* sentinel */ }
  46. };
  47. MODULE_DEVICE_TABLE(i2c, aic32x4_i2c_id);
  48. static const struct of_device_id aic32x4_of_id[] = {
  49. { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 },
  50. { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 },
  51. { .compatible = "ti,tas2505", .data = (void *)AIC32X4_TYPE_TAS2505 },
  52. { /* senitel */ }
  53. };
  54. MODULE_DEVICE_TABLE(of, aic32x4_of_id);
  55. static struct i2c_driver aic32x4_i2c_driver = {
  56. .driver = {
  57. .name = "tlv320aic32x4",
  58. .of_match_table = aic32x4_of_id,
  59. },
  60. .probe_new = aic32x4_i2c_probe,
  61. .remove = aic32x4_i2c_remove,
  62. .id_table = aic32x4_i2c_id,
  63. };
  64. module_i2c_driver(aic32x4_i2c_driver);
  65. MODULE_DESCRIPTION("ASoC TLV320AIC32x4 codec driver I2C");
  66. MODULE_AUTHOR("Annaliese McDermond <[email protected]>");
  67. MODULE_LICENSE("GPL");