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 int bmg160_spi_remove(struct spi_device *spi) 31 { 32 bmg160_core_remove(&spi->dev); 33 34 return 0; 35 } 36 37 static const struct spi_device_id bmg160_spi_id[] = { 38 {"bmg160", 0}, 39 {"bmi055_gyro", 0}, 40 {"bmi088_gyro", 0}, 41 {} 42 }; 43 44 MODULE_DEVICE_TABLE(spi, bmg160_spi_id); 45 46 static struct spi_driver bmg160_spi_driver = { 47 .driver = { 48 .name = "bmg160_spi", 49 .pm = &bmg160_pm_ops, 50 }, 51 .probe = bmg160_spi_probe, 52 .remove = bmg160_spi_remove, 53 .id_table = bmg160_spi_id, 54 }; 55 module_spi_driver(bmg160_spi_driver); 56 57 MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>"); 58 MODULE_LICENSE("GPL v2"); 59 MODULE_DESCRIPTION("BMG160 SPI Gyro driver"); 60