kionix-kx022a-spi.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2022 ROHM Semiconductors
  4. *
  5. * ROHM/KIONIX accelerometer driver
  6. */
  7. #include <linux/interrupt.h>
  8. #include <linux/module.h>
  9. #include <linux/regmap.h>
  10. #include <linux/spi/spi.h>
  11. #include "kionix-kx022a.h"
  12. static int kx022a_spi_probe(struct spi_device *spi)
  13. {
  14. struct device *dev = &spi->dev;
  15. const struct kx022a_chip_info *chip_info;
  16. struct regmap *regmap;
  17. if (!spi->irq) {
  18. dev_err(dev, "No IRQ configured\n");
  19. return -EINVAL;
  20. }
  21. chip_info = spi_get_device_match_data(spi);
  22. if (!chip_info)
  23. return -EINVAL;
  24. regmap = devm_regmap_init_spi(spi, chip_info->regmap_config);
  25. if (IS_ERR(regmap))
  26. return dev_err_probe(dev, PTR_ERR(regmap),
  27. "Failed to initialize Regmap\n");
  28. return kx022a_probe_internal(dev, chip_info);
  29. }
  30. static const struct spi_device_id kx022a_id[] = {
  31. { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info },
  32. { .name = "kx132-1211", .driver_data = (kernel_ulong_t)&kx132_chip_info },
  33. { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
  34. { }
  35. };
  36. MODULE_DEVICE_TABLE(spi, kx022a_id);
  37. static const struct of_device_id kx022a_of_match[] = {
  38. { .compatible = "kionix,kx022a", .data = &kx022a_chip_info },
  39. { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info },
  40. { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
  41. { }
  42. };
  43. MODULE_DEVICE_TABLE(of, kx022a_of_match);
  44. static struct spi_driver kx022a_spi_driver = {
  45. .driver = {
  46. .name = "kx022a-spi",
  47. .of_match_table = kx022a_of_match,
  48. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  49. },
  50. .probe = kx022a_spi_probe,
  51. .id_table = kx022a_id,
  52. };
  53. module_spi_driver(kx022a_spi_driver);
  54. MODULE_DESCRIPTION("ROHM/Kionix kx022A accelerometer driver");
  55. MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
  56. MODULE_LICENSE("GPL");
  57. MODULE_IMPORT_NS(IIO_KX022A);