pcm186x-i2c.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Texas Instruments PCM186x Universal Audio ADC - I2C
  4. *
  5. * Copyright (C) 2015-2017 Texas Instruments Incorporated - https://www.ti.com
  6. * Andreas Dannenberg <[email protected]>
  7. * Andrew F. Davis <[email protected]>
  8. */
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/i2c.h>
  12. #include "pcm186x.h"
  13. static const struct of_device_id pcm186x_of_match[] = {
  14. { .compatible = "ti,pcm1862", .data = (void *)PCM1862 },
  15. { .compatible = "ti,pcm1863", .data = (void *)PCM1863 },
  16. { .compatible = "ti,pcm1864", .data = (void *)PCM1864 },
  17. { .compatible = "ti,pcm1865", .data = (void *)PCM1865 },
  18. { }
  19. };
  20. MODULE_DEVICE_TABLE(of, pcm186x_of_match);
  21. static const struct i2c_device_id pcm186x_i2c_id[] = {
  22. { "pcm1862", PCM1862 },
  23. { "pcm1863", PCM1863 },
  24. { "pcm1864", PCM1864 },
  25. { "pcm1865", PCM1865 },
  26. { }
  27. };
  28. MODULE_DEVICE_TABLE(i2c, pcm186x_i2c_id);
  29. static int pcm186x_i2c_probe(struct i2c_client *i2c)
  30. {
  31. const struct i2c_device_id *id = i2c_match_id(pcm186x_i2c_id, i2c);
  32. const enum pcm186x_type type = (enum pcm186x_type)id->driver_data;
  33. int irq = i2c->irq;
  34. struct regmap *regmap;
  35. regmap = devm_regmap_init_i2c(i2c, &pcm186x_regmap);
  36. if (IS_ERR(regmap))
  37. return PTR_ERR(regmap);
  38. return pcm186x_probe(&i2c->dev, type, irq, regmap);
  39. }
  40. static struct i2c_driver pcm186x_i2c_driver = {
  41. .probe_new = pcm186x_i2c_probe,
  42. .id_table = pcm186x_i2c_id,
  43. .driver = {
  44. .name = "pcm186x",
  45. .of_match_table = pcm186x_of_match,
  46. },
  47. };
  48. module_i2c_driver(pcm186x_i2c_driver);
  49. MODULE_AUTHOR("Andreas Dannenberg <[email protected]>");
  50. MODULE_AUTHOR("Andrew F. Davis <[email protected]>");
  51. MODULE_DESCRIPTION("PCM186x Universal Audio ADC I2C Interface Driver");
  52. MODULE_LICENSE("GPL v2");