Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * i2c driver for hmc5843/5843/5883/5883l/5983
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Split from hmc5843.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) Josef Gajdusek <atx@atx.name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/iio/iio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/iio/triggered_buffer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "hmc5843.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static const struct regmap_range hmc5843_readable_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	regmap_reg_range(0, HMC5843_ID_END),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static const struct regmap_access_table hmc5843_readable_table = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	.yes_ranges = hmc5843_readable_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	.n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const struct regmap_range hmc5843_writable_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	regmap_reg_range(0, HMC5843_MODE_REG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static const struct regmap_access_table hmc5843_writable_table = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.yes_ranges = hmc5843_writable_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static const struct regmap_range hmc5843_volatile_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static const struct regmap_access_table hmc5843_volatile_table = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.yes_ranges = hmc5843_volatile_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static const struct regmap_config hmc5843_i2c_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.rd_table = &hmc5843_readable_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.wr_table = &hmc5843_writable_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.volatile_table = &hmc5843_volatile_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int hmc5843_i2c_probe(struct i2c_client *cli,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			     const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct regmap *regmap = devm_regmap_init_i2c(cli,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			&hmc5843_i2c_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (IS_ERR(regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return hmc5843_common_probe(&cli->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			id->driver_data, id->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static int hmc5843_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return hmc5843_common_remove(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static const struct i2c_device_id hmc5843_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	{ "hmc5843", HMC5843_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	{ "hmc5883", HMC5883_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	{ "hmc5883l", HMC5883L_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	{ "hmc5983", HMC5983_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) MODULE_DEVICE_TABLE(i2c, hmc5843_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static const struct of_device_id hmc5843_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	{ .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	{ .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	{ .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	{ .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) MODULE_DEVICE_TABLE(of, hmc5843_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static struct i2c_driver hmc5843_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		.name	= "hmc5843",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		.pm	= HMC5843_PM_OPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		.of_match_table = hmc5843_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.id_table	= hmc5843_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	.probe		= hmc5843_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.remove		= hmc5843_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) module_i2c_driver(hmc5843_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) MODULE_LICENSE("GPL");