cs35l43-i2c.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * cs35l43-i2c.c -- CS35l41 I2C driver
  4. *
  5. * Copyright 2020 Cirrus Logic, Inc.
  6. *
  7. * Author: David Rhodes <[email protected]>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/version.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/delay.h>
  20. #include <linux/i2c.h>
  21. #include <linux/slab.h>
  22. #include <linux/workqueue.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/gpio/consumer.h>
  26. #include <linux/of_device.h>
  27. #include <linux/of_gpio.h>
  28. #include <linux/regmap.h>
  29. #include <linux/gpio.h>
  30. #include "wm_adsp.h"
  31. #include "cs35l43.h"
  32. #include <sound/cs35l43.h>
  33. static struct regmap_config cs35l43_regmap_i2c = {
  34. .reg_bits = 32,
  35. .val_bits = 32,
  36. .reg_stride = 4,
  37. .reg_format_endian = REGMAP_ENDIAN_BIG,
  38. .val_format_endian = REGMAP_ENDIAN_BIG,
  39. .max_register = CS35L43_DSP1_PMEM_5114,
  40. .reg_defaults = cs35l43_reg,
  41. .num_reg_defaults = CS35L43_NUM_DEFAULTS,
  42. .volatile_reg = cs35l43_volatile_reg,
  43. .readable_reg = cs35l43_readable_reg,
  44. .precious_reg = cs35l43_precious_reg,
  45. .cache_type = REGCACHE_RBTREE,
  46. };
  47. static const struct i2c_device_id cs35l43_id_i2c[] = {
  48. {"cs35l43", 0},
  49. {}
  50. };
  51. MODULE_DEVICE_TABLE(i2c, cs35l43_id_i2c);
  52. static int cs35l43_i2c_probe(struct i2c_client *client,
  53. const struct i2c_device_id *id)
  54. {
  55. struct cs35l43_private *cs35l43;
  56. struct device *dev = &client->dev;
  57. struct cs35l43_platform_data *pdata = dev_get_platdata(dev);
  58. const struct regmap_config *regmap_config = &cs35l43_regmap_i2c;
  59. int ret;
  60. cs35l43 = devm_kzalloc(dev, sizeof(struct cs35l43_private), GFP_KERNEL);
  61. if (cs35l43 == NULL)
  62. return -ENOMEM;
  63. cs35l43->dev = dev;
  64. cs35l43->irq = client->irq;
  65. i2c_set_clientdata(client, cs35l43);
  66. cs35l43->regmap = devm_regmap_init_i2c(client, regmap_config);
  67. if (IS_ERR(cs35l43->regmap)) {
  68. ret = PTR_ERR(cs35l43->regmap);
  69. dev_err(cs35l43->dev, "Failed to allocate register map: %d\n",
  70. ret);
  71. return ret;
  72. }
  73. return cs35l43_probe(cs35l43, pdata);
  74. }
  75. static void cs35l43_i2c_remove(struct i2c_client *client)
  76. {
  77. struct cs35l43_private *cs35l43 = i2c_get_clientdata(client);
  78. cs35l43_remove(cs35l43);
  79. }
  80. static const struct of_device_id cs35l43_of_match[] = {
  81. {.compatible = "cirrus,cs35l43"},
  82. {},
  83. };
  84. MODULE_DEVICE_TABLE(of, cs35l43_of_match);
  85. static struct i2c_driver cs35l43_i2c_driver = {
  86. .driver = {
  87. .name = "cs35l43",
  88. .of_match_table = cs35l43_of_match,
  89. .pm = &cs35l43_pm_ops,
  90. },
  91. .id_table = cs35l43_id_i2c,
  92. .probe = cs35l43_i2c_probe,
  93. .remove = cs35l43_i2c_remove,
  94. };
  95. module_i2c_driver(cs35l43_i2c_driver);
  96. MODULE_DESCRIPTION("I2C CS35L43 driver");
  97. MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <[email protected]>");
  98. MODULE_LICENSE("GPL");