xref: /openbmc/linux/drivers/iio/magnetometer/bmc150_magn_spi.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
136edc939SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2534536acSDaniel Baluta /*
3534536acSDaniel Baluta  * 3-axis magnetometer driver support following SPI Bosch-Sensortec chips:
4534536acSDaniel Baluta  *  - BMC150
5534536acSDaniel Baluta  *  - BMC156
69d75db36SDaniel Baluta  *  - BMM150
7534536acSDaniel Baluta  *
8534536acSDaniel Baluta  * Copyright (c) 2016, Intel Corporation.
9534536acSDaniel Baluta  */
10534536acSDaniel Baluta #include <linux/module.h>
11534536acSDaniel Baluta #include <linux/mod_devicetable.h>
12534536acSDaniel Baluta #include <linux/spi/spi.h>
13534536acSDaniel Baluta #include <linux/acpi.h>
14534536acSDaniel Baluta #include <linux/regmap.h>
15534536acSDaniel Baluta 
16534536acSDaniel Baluta #include "bmc150_magn.h"
17534536acSDaniel Baluta 
bmc150_magn_spi_probe(struct spi_device * spi)18534536acSDaniel Baluta static int bmc150_magn_spi_probe(struct spi_device *spi)
19534536acSDaniel Baluta {
20534536acSDaniel Baluta 	struct regmap *regmap;
21534536acSDaniel Baluta 	const struct spi_device_id *id = spi_get_device_id(spi);
22534536acSDaniel Baluta 
23534536acSDaniel Baluta 	regmap = devm_regmap_init_spi(spi, &bmc150_magn_regmap_config);
24534536acSDaniel Baluta 	if (IS_ERR(regmap)) {
259623473cSNishant Malpani 		dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
269623473cSNishant Malpani 			regmap);
27534536acSDaniel Baluta 		return PTR_ERR(regmap);
28534536acSDaniel Baluta 	}
29534536acSDaniel Baluta 	return bmc150_magn_probe(&spi->dev, regmap, spi->irq, id->name);
30534536acSDaniel Baluta }
31534536acSDaniel Baluta 
bmc150_magn_spi_remove(struct spi_device * spi)32a0386bbaSUwe Kleine-König static void bmc150_magn_spi_remove(struct spi_device *spi)
33534536acSDaniel Baluta {
34534536acSDaniel Baluta 	bmc150_magn_remove(&spi->dev);
35534536acSDaniel Baluta }
36534536acSDaniel Baluta 
37534536acSDaniel Baluta static const struct spi_device_id bmc150_magn_spi_id[] = {
38534536acSDaniel Baluta 	{"bmc150_magn", 0},
39534536acSDaniel Baluta 	{"bmc156_magn", 0},
409d75db36SDaniel Baluta 	{"bmm150_magn", 0},
41534536acSDaniel Baluta 	{}
42534536acSDaniel Baluta };
43534536acSDaniel Baluta MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id);
44534536acSDaniel Baluta 
45534536acSDaniel Baluta static const struct acpi_device_id bmc150_magn_acpi_match[] = {
46534536acSDaniel Baluta 	{"BMC150B", 0},
47534536acSDaniel Baluta 	{"BMC156B", 0},
489d75db36SDaniel Baluta 	{"BMM150B", 0},
49534536acSDaniel Baluta 	{},
50534536acSDaniel Baluta };
51534536acSDaniel Baluta MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
52534536acSDaniel Baluta 
53534536acSDaniel Baluta static struct spi_driver bmc150_magn_spi_driver = {
54534536acSDaniel Baluta 	.probe		= bmc150_magn_spi_probe,
55534536acSDaniel Baluta 	.remove		= bmc150_magn_spi_remove,
56534536acSDaniel Baluta 	.id_table	= bmc150_magn_spi_id,
57534536acSDaniel Baluta 	.driver = {
58534536acSDaniel Baluta 		.acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
59534536acSDaniel Baluta 		.name	= "bmc150_magn_spi",
60534536acSDaniel Baluta 	},
61534536acSDaniel Baluta };
62534536acSDaniel Baluta module_spi_driver(bmc150_magn_spi_driver);
63534536acSDaniel Baluta 
64534536acSDaniel Baluta MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
65534536acSDaniel Baluta MODULE_DESCRIPTION("BMC150 magnetometer SPI driver");
66534536acSDaniel Baluta MODULE_LICENSE("GPL v2");
67*47d6cae0SJonathan Cameron MODULE_IMPORT_NS(IIO_BMC150_MAGN);
68