pcm512x-i2c.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for the PCM512x CODECs
  4. *
  5. * Author: Mark Brown <broonie@kernel.org>
  6. * Copyright 2014 Linaro Ltd
  7. */
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/i2c.h>
  11. #include <linux/acpi.h>
  12. #include "pcm512x.h"
  13. static int pcm512x_i2c_probe(struct i2c_client *i2c,
  14. const struct i2c_device_id *id)
  15. {
  16. struct regmap *regmap;
  17. struct regmap_config config = pcm512x_regmap;
  18. /* msb needs to be set to enable auto-increment of addresses */
  19. config.read_flag_mask = 0x80;
  20. config.write_flag_mask = 0x80;
  21. regmap = devm_regmap_init_i2c(i2c, &config);
  22. if (IS_ERR(regmap))
  23. return PTR_ERR(regmap);
  24. return pcm512x_probe(&i2c->dev, regmap);
  25. }
  26. static int pcm512x_i2c_remove(struct i2c_client *i2c)
  27. {
  28. pcm512x_remove(&i2c->dev);
  29. return 0;
  30. }
  31. static const struct i2c_device_id pcm512x_i2c_id[] = {
  32. { "pcm5121", },
  33. { "pcm5122", },
  34. { "pcm5141", },
  35. { "pcm5142", },
  36. { }
  37. };
  38. MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  39. #if defined(CONFIG_OF)
  40. static const struct of_device_id pcm512x_of_match[] = {
  41. { .compatible = "ti,pcm5121", },
  42. { .compatible = "ti,pcm5122", },
  43. { .compatible = "ti,pcm5141", },
  44. { .compatible = "ti,pcm5142", },
  45. { }
  46. };
  47. MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  48. #endif
  49. #ifdef CONFIG_ACPI
  50. static const struct acpi_device_id pcm512x_acpi_match[] = {
  51. { "104C5121", 0 },
  52. { "104C5122", 0 },
  53. { "104C5141", 0 },
  54. { "104C5142", 0 },
  55. { },
  56. };
  57. MODULE_DEVICE_TABLE(acpi, pcm512x_acpi_match);
  58. #endif
  59. static struct i2c_driver pcm512x_i2c_driver = {
  60. .probe = pcm512x_i2c_probe,
  61. .remove = pcm512x_i2c_remove,
  62. .id_table = pcm512x_i2c_id,
  63. .driver = {
  64. .name = "pcm512x",
  65. .of_match_table = of_match_ptr(pcm512x_of_match),
  66. .acpi_match_table = ACPI_PTR(pcm512x_acpi_match),
  67. .pm = &pcm512x_pm_ops,
  68. },
  69. };
  70. module_i2c_driver(pcm512x_i2c_driver);
  71. MODULE_DESCRIPTION("ASoC PCM512x codec driver - I2C");
  72. MODULE_AUTHOR("Mark Brown <broonie@kernel.org>");
  73. MODULE_LICENSE("GPL v2");