18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Driver for NXP Fxas21002c Gyroscope - SPI
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2019 Linaro Ltd.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/err.h>
98c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h>
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/regmap.h>
128c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "fxas21002c.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic const struct regmap_config fxas21002c_regmap_spi_conf = {
178c2ecf20Sopenharmony_ci	.reg_bits = 8,
188c2ecf20Sopenharmony_ci	.val_bits = 8,
198c2ecf20Sopenharmony_ci	.max_register = FXAS21002C_REG_CTRL3,
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic int fxas21002c_spi_probe(struct spi_device *spi)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	const struct spi_device_id *id = spi_get_device_id(spi);
258c2ecf20Sopenharmony_ci	struct regmap *regmap;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	regmap = devm_regmap_init_spi(spi, &fxas21002c_regmap_spi_conf);
288c2ecf20Sopenharmony_ci	if (IS_ERR(regmap)) {
298c2ecf20Sopenharmony_ci		dev_err(&spi->dev, "Failed to register spi regmap: %ld\n",
308c2ecf20Sopenharmony_ci			PTR_ERR(regmap));
318c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
328c2ecf20Sopenharmony_ci	}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	return fxas21002c_core_probe(&spi->dev, regmap, spi->irq, id->name);
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic int fxas21002c_spi_remove(struct spi_device *spi)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	fxas21002c_core_remove(&spi->dev);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	return 0;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic const struct spi_device_id fxas21002c_spi_id[] = {
458c2ecf20Sopenharmony_ci	{ "fxas21002c", 0 },
468c2ecf20Sopenharmony_ci	{ }
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(spi, fxas21002c_spi_id);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic const struct of_device_id fxas21002c_spi_of_match[] = {
518c2ecf20Sopenharmony_ci	{ .compatible = "nxp,fxas21002c", },
528c2ecf20Sopenharmony_ci	{ }
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, fxas21002c_spi_of_match);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic struct spi_driver fxas21002c_spi_driver = {
578c2ecf20Sopenharmony_ci	.driver = {
588c2ecf20Sopenharmony_ci		.name = "fxas21002c_spi",
598c2ecf20Sopenharmony_ci		.pm = &fxas21002c_pm_ops,
608c2ecf20Sopenharmony_ci		.of_match_table = fxas21002c_spi_of_match,
618c2ecf20Sopenharmony_ci	},
628c2ecf20Sopenharmony_ci	.probe		= fxas21002c_spi_probe,
638c2ecf20Sopenharmony_ci	.remove		= fxas21002c_spi_remove,
648c2ecf20Sopenharmony_ci	.id_table	= fxas21002c_spi_id,
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_cimodule_spi_driver(fxas21002c_spi_driver);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciMODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
698c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
708c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("FXAS21002C SPI Gyro driver");
71