^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for NXP Fxas21002c Gyroscope - SPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2019 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "fxas21002c.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static const struct regmap_config fxas21002c_regmap_spi_conf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) .max_register = FXAS21002C_REG_CTRL3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int fxas21002c_spi_probe(struct spi_device *spi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) const struct spi_device_id *id = spi_get_device_id(spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) regmap = devm_regmap_init_spi(spi, &fxas21002c_regmap_spi_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) dev_err(&spi->dev, "Failed to register spi regmap: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) PTR_ERR(regmap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return fxas21002c_core_probe(&spi->dev, regmap, spi->irq, id->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int fxas21002c_spi_remove(struct spi_device *spi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) fxas21002c_core_remove(&spi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct spi_device_id fxas21002c_spi_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { "fxas21002c", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) MODULE_DEVICE_TABLE(spi, fxas21002c_spi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static const struct of_device_id fxas21002c_spi_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) { .compatible = "nxp,fxas21002c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) MODULE_DEVICE_TABLE(of, fxas21002c_spi_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static struct spi_driver fxas21002c_spi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .name = "fxas21002c_spi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .pm = &fxas21002c_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .of_match_table = fxas21002c_spi_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .probe = fxas21002c_spi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .remove = fxas21002c_spi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .id_table = fxas21002c_spi_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) module_spi_driver(fxas21002c_spi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) MODULE_DESCRIPTION("FXAS21002C SPI Gyro driver");