goodix_berlin_i2c.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Goodix Berlin Touchscreen Driver
  4. *
  5. * Copyright (C) 2020 - 2021 Goodix, Inc.
  6. * Copyright (C) 2023 Linaro Ltd.
  7. *
  8. * Based on goodix_ts_berlin driver.
  9. */
  10. #include <linux/i2c.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/regmap.h>
  14. #include <linux/input.h>
  15. #include "goodix_berlin.h"
  16. #define I2C_MAX_TRANSFER_SIZE 256
  17. static const struct regmap_config goodix_berlin_i2c_regmap_conf = {
  18. .reg_bits = 32,
  19. .val_bits = 8,
  20. .max_raw_read = I2C_MAX_TRANSFER_SIZE,
  21. .max_raw_write = I2C_MAX_TRANSFER_SIZE,
  22. };
  23. /* vendor & product left unassigned here, should probably be updated from fw info */
  24. static const struct input_id goodix_berlin_i2c_input_id = {
  25. .bustype = BUS_I2C,
  26. };
  27. static int goodix_berlin_i2c_probe(struct i2c_client *client)
  28. {
  29. const struct goodix_berlin_ic_data *ic_data =
  30. i2c_get_match_data(client);
  31. struct regmap *regmap;
  32. int error;
  33. regmap = devm_regmap_init_i2c(client, &goodix_berlin_i2c_regmap_conf);
  34. if (IS_ERR(regmap))
  35. return PTR_ERR(regmap);
  36. error = goodix_berlin_probe(&client->dev, client->irq,
  37. &goodix_berlin_i2c_input_id, regmap,
  38. ic_data);
  39. if (error)
  40. return error;
  41. return 0;
  42. }
  43. static const struct goodix_berlin_ic_data gt9916_data = {
  44. .fw_version_info_addr = GOODIX_BERLIN_FW_VERSION_INFO_ADDR_D,
  45. .ic_info_addr = GOODIX_BERLIN_IC_INFO_ADDR_D,
  46. };
  47. static const struct i2c_device_id goodix_berlin_i2c_id[] = {
  48. { .name = "gt9916", .driver_data = (long)&gt9916_data },
  49. { }
  50. };
  51. MODULE_DEVICE_TABLE(i2c, goodix_berlin_i2c_id);
  52. static const struct of_device_id goodix_berlin_i2c_of_match[] = {
  53. { .compatible = "goodix,gt9916", .data = &gt9916_data },
  54. { }
  55. };
  56. MODULE_DEVICE_TABLE(of, goodix_berlin_i2c_of_match);
  57. static struct i2c_driver goodix_berlin_i2c_driver = {
  58. .driver = {
  59. .name = "goodix-berlin-i2c",
  60. .of_match_table = goodix_berlin_i2c_of_match,
  61. .pm = pm_sleep_ptr(&goodix_berlin_pm_ops),
  62. .dev_groups = goodix_berlin_groups,
  63. },
  64. .probe = goodix_berlin_i2c_probe,
  65. .id_table = goodix_berlin_i2c_id,
  66. };
  67. module_i2c_driver(goodix_berlin_i2c_driver);
  68. MODULE_LICENSE("GPL");
  69. MODULE_DESCRIPTION("Goodix Berlin I2C Touchscreen driver");
  70. MODULE_AUTHOR("Neil Armstrong <neil.armstrong@linaro.org>");