1 // SPDX-License-Identifier: GPL-2.0-only 2 #include <linux/spi/spi.h> 3 #include <linux/regmap.h> 4 #include <linux/iio/iio.h> 5 #include <linux/module.h> 6 7 #include "bmg160.h" 8 9 static const struct regmap_config bmg160_regmap_spi_conf = { 10 .reg_bits = 8, 11 .val_bits = 8, 12 .max_register = 0x3f, 13 }; 14 15 static int bmg160_spi_probe(struct spi_device *spi) 16 { 17 struct regmap *regmap; 18 const struct spi_device_id *id = spi_get_device_id(spi); 19 20 regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf); 21 if (IS_ERR(regmap)) { 22 dev_err(&spi->dev, "Failed to register spi regmap: %pe\n", 23 regmap); 24 return PTR_ERR(regmap); 25 } 26 27 return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name); 28 } 29 30 static void bmg160_spi_remove(struct spi_device *spi) 31 { 32 bmg160_core_remove(&spi->dev); 33 } 34 35 static const struct spi_device_id bmg160_spi_id[] = { 36 {"bmg160", 0}, 37 {"bmi055_gyro", 0}, 38 {"bmi088_gyro", 0}, 39 {} 40 }; 41 42 MODULE_DEVICE_TABLE(spi, bmg160_spi_id); 43 44 static struct spi_driver bmg160_spi_driver = { 45 .driver = { 46 .name = "bmg160_spi", 47 .pm = &bmg160_pm_ops, 48 }, 49 .probe = bmg160_spi_probe, 50 .remove = bmg160_spi_remove, 51 .id_table = bmg160_spi_id, 52 }; 53 module_spi_driver(bmg160_spi_driver); 54 55 MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>"); 56 MODULE_LICENSE("GPL v2"); 57 MODULE_DESCRIPTION("BMG160 SPI Gyro driver"); 58