cs35l41-i2c.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // cs35l41-i2c.c -- CS35l41 I2C driver
  4. //
  5. // Copyright 2017-2021 Cirrus Logic, Inc.
  6. //
  7. // Author: David Rhodes <[email protected]>
  8. #include <linux/acpi.h>
  9. #include <linux/delay.h>
  10. #include <linux/i2c.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/of_device.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include "cs35l41.h"
  19. static const struct i2c_device_id cs35l41_id_i2c[] = {
  20. { "cs35l40", 0 },
  21. { "cs35l41", 0 },
  22. { "cs35l51", 0 },
  23. { "cs35l53", 0 },
  24. {}
  25. };
  26. MODULE_DEVICE_TABLE(i2c, cs35l41_id_i2c);
  27. static int cs35l41_i2c_probe(struct i2c_client *client)
  28. {
  29. struct cs35l41_private *cs35l41;
  30. struct device *dev = &client->dev;
  31. struct cs35l41_hw_cfg *hw_cfg = dev_get_platdata(dev);
  32. const struct regmap_config *regmap_config = &cs35l41_regmap_i2c;
  33. int ret;
  34. cs35l41 = devm_kzalloc(dev, sizeof(struct cs35l41_private), GFP_KERNEL);
  35. if (!cs35l41)
  36. return -ENOMEM;
  37. cs35l41->dev = dev;
  38. cs35l41->irq = client->irq;
  39. i2c_set_clientdata(client, cs35l41);
  40. cs35l41->regmap = devm_regmap_init_i2c(client, regmap_config);
  41. if (IS_ERR(cs35l41->regmap)) {
  42. ret = PTR_ERR(cs35l41->regmap);
  43. dev_err(cs35l41->dev, "Failed to allocate register map: %d\n", ret);
  44. return ret;
  45. }
  46. return cs35l41_probe(cs35l41, hw_cfg);
  47. }
  48. static void cs35l41_i2c_remove(struct i2c_client *client)
  49. {
  50. struct cs35l41_private *cs35l41 = i2c_get_clientdata(client);
  51. cs35l41_remove(cs35l41);
  52. }
  53. #ifdef CONFIG_OF
  54. static const struct of_device_id cs35l41_of_match[] = {
  55. { .compatible = "cirrus,cs35l40" },
  56. { .compatible = "cirrus,cs35l41" },
  57. {},
  58. };
  59. MODULE_DEVICE_TABLE(of, cs35l41_of_match);
  60. #endif
  61. #ifdef CONFIG_ACPI
  62. static const struct acpi_device_id cs35l41_acpi_match[] = {
  63. { "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
  64. {},
  65. };
  66. MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
  67. #endif
  68. static struct i2c_driver cs35l41_i2c_driver = {
  69. .driver = {
  70. .name = "cs35l41",
  71. .pm = &cs35l41_pm_ops,
  72. .of_match_table = of_match_ptr(cs35l41_of_match),
  73. .acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
  74. },
  75. .id_table = cs35l41_id_i2c,
  76. .probe_new = cs35l41_i2c_probe,
  77. .remove = cs35l41_i2c_remove,
  78. };
  79. module_i2c_driver(cs35l41_i2c_driver);
  80. MODULE_DESCRIPTION("I2C CS35L41 driver");
  81. MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <[email protected]>");
  82. MODULE_LICENSE("GPL");