162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips:
462306a36Sopenharmony_ci *  - BMC150
562306a36Sopenharmony_ci *  - BMC156
662306a36Sopenharmony_ci *  - BMM150
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Copyright (c) 2016, Intel Corporation.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci#include <linux/device.h>
1162306a36Sopenharmony_ci#include <linux/mod_devicetable.h>
1262306a36Sopenharmony_ci#include <linux/i2c.h>
1362306a36Sopenharmony_ci#include <linux/module.h>
1462306a36Sopenharmony_ci#include <linux/acpi.h>
1562306a36Sopenharmony_ci#include <linux/regmap.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include "bmc150_magn.h"
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistatic int bmc150_magn_i2c_probe(struct i2c_client *client)
2062306a36Sopenharmony_ci{
2162306a36Sopenharmony_ci	const struct i2c_device_id *id = i2c_client_get_device_id(client);
2262306a36Sopenharmony_ci	struct regmap *regmap;
2362306a36Sopenharmony_ci	const char *name = NULL;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	regmap = devm_regmap_init_i2c(client, &bmc150_magn_regmap_config);
2662306a36Sopenharmony_ci	if (IS_ERR(regmap)) {
2762306a36Sopenharmony_ci		dev_err(&client->dev, "Failed to initialize i2c regmap\n");
2862306a36Sopenharmony_ci		return PTR_ERR(regmap);
2962306a36Sopenharmony_ci	}
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci	if (id)
3262306a36Sopenharmony_ci		name = id->name;
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci	return bmc150_magn_probe(&client->dev, regmap, client->irq, name);
3562306a36Sopenharmony_ci}
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistatic void bmc150_magn_i2c_remove(struct i2c_client *client)
3862306a36Sopenharmony_ci{
3962306a36Sopenharmony_ci	bmc150_magn_remove(&client->dev);
4062306a36Sopenharmony_ci}
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistatic const struct acpi_device_id bmc150_magn_acpi_match[] = {
4362306a36Sopenharmony_ci	{"BMC150B", 0},
4462306a36Sopenharmony_ci	{"BMC156B", 0},
4562306a36Sopenharmony_ci	{"BMM150B", 0},
4662306a36Sopenharmony_ci	{},
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistatic const struct i2c_device_id bmc150_magn_i2c_id[] = {
5162306a36Sopenharmony_ci	{"bmc150_magn",	0},
5262306a36Sopenharmony_ci	{"bmc156_magn", 0},
5362306a36Sopenharmony_ci	{"bmm150_magn", 0},
5462306a36Sopenharmony_ci	{}
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id);
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistatic const struct of_device_id bmc150_magn_of_match[] = {
5962306a36Sopenharmony_ci	{ .compatible = "bosch,bmc150_magn" },
6062306a36Sopenharmony_ci	{ .compatible = "bosch,bmc156_magn" },
6162306a36Sopenharmony_ci	{ .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */
6262306a36Sopenharmony_ci	{ .compatible = "bosch,bmm150" },
6362306a36Sopenharmony_ci	{ }
6462306a36Sopenharmony_ci};
6562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, bmc150_magn_of_match);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cistatic struct i2c_driver bmc150_magn_driver = {
6862306a36Sopenharmony_ci	.driver = {
6962306a36Sopenharmony_ci		.name	= "bmc150_magn_i2c",
7062306a36Sopenharmony_ci		.of_match_table = bmc150_magn_of_match,
7162306a36Sopenharmony_ci		.acpi_match_table = ACPI_PTR(bmc150_magn_acpi_match),
7262306a36Sopenharmony_ci		.pm	= &bmc150_magn_pm_ops,
7362306a36Sopenharmony_ci	},
7462306a36Sopenharmony_ci	.probe		= bmc150_magn_i2c_probe,
7562306a36Sopenharmony_ci	.remove		= bmc150_magn_i2c_remove,
7662306a36Sopenharmony_ci	.id_table	= bmc150_magn_i2c_id,
7762306a36Sopenharmony_ci};
7862306a36Sopenharmony_cimodule_i2c_driver(bmc150_magn_driver);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciMODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
8162306a36Sopenharmony_ciMODULE_LICENSE("GPL v2");
8262306a36Sopenharmony_ciMODULE_DESCRIPTION("BMC150 I2C magnetometer driver");
8362306a36Sopenharmony_ciMODULE_IMPORT_NS(IIO_BMC150_MAGN);
84