18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
38c2ecf20Sopenharmony_ci#include <linux/regmap.h>
48c2ecf20Sopenharmony_ci#include <linux/iio/iio.h>
58c2ecf20Sopenharmony_ci#include <linux/module.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "bmg160.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistatic const struct regmap_config bmg160_regmap_spi_conf = {
108c2ecf20Sopenharmony_ci	.reg_bits = 8,
118c2ecf20Sopenharmony_ci	.val_bits = 8,
128c2ecf20Sopenharmony_ci	.max_register = 0x3f,
138c2ecf20Sopenharmony_ci};
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic int bmg160_spi_probe(struct spi_device *spi)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	struct regmap *regmap;
188c2ecf20Sopenharmony_ci	const struct spi_device_id *id = spi_get_device_id(spi);
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
218c2ecf20Sopenharmony_ci	if (IS_ERR(regmap)) {
228c2ecf20Sopenharmony_ci		dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
238c2ecf20Sopenharmony_ci			regmap);
248c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
258c2ecf20Sopenharmony_ci	}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
288c2ecf20Sopenharmony_ci}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic int bmg160_spi_remove(struct spi_device *spi)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	bmg160_core_remove(&spi->dev);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	return 0;
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic const struct spi_device_id bmg160_spi_id[] = {
388c2ecf20Sopenharmony_ci	{"bmg160", 0},
398c2ecf20Sopenharmony_ci	{"bmi055_gyro", 0},
408c2ecf20Sopenharmony_ci	{"bmi088_gyro", 0},
418c2ecf20Sopenharmony_ci	{}
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(spi, bmg160_spi_id);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic struct spi_driver bmg160_spi_driver = {
478c2ecf20Sopenharmony_ci	.driver = {
488c2ecf20Sopenharmony_ci		.name	= "bmg160_spi",
498c2ecf20Sopenharmony_ci		.pm	= &bmg160_pm_ops,
508c2ecf20Sopenharmony_ci	},
518c2ecf20Sopenharmony_ci	.probe		= bmg160_spi_probe,
528c2ecf20Sopenharmony_ci	.remove		= bmg160_spi_remove,
538c2ecf20Sopenharmony_ci	.id_table	= bmg160_spi_id,
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_cimodule_spi_driver(bmg160_spi_driver);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciMODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
588c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
598c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("BMG160 SPI Gyro driver");
60