Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 1 | /* |
Josef Gajdusek | 5a059bd | 2014-07-22 16:02:00 +0100 | [diff] [blame] | 2 | * i2c driver for hmc5843/5843/5883/5883l/5983 |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 3 | * |
| 4 | * Split from hmc5843.c |
| 5 | * Copyright (C) Josef Gajdusek <atx@atx.name> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
Cristina Moraru | 4630adb | 2016-02-08 00:21:50 +0200 | [diff] [blame] | 10 | */ |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/i2c.h> |
| 14 | #include <linux/regmap.h> |
| 15 | #include <linux/iio/iio.h> |
| 16 | #include <linux/iio/triggered_buffer.h> |
| 17 | |
| 18 | #include "hmc5843.h" |
| 19 | |
| 20 | static const struct regmap_range hmc5843_readable_ranges[] = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 21 | regmap_reg_range(0, HMC5843_ID_END), |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 22 | }; |
| 23 | |
Krzysztof Kozlowski | 1531330 | 2015-02-24 10:41:48 +0100 | [diff] [blame] | 24 | static const struct regmap_access_table hmc5843_readable_table = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 25 | .yes_ranges = hmc5843_readable_ranges, |
| 26 | .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges), |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static const struct regmap_range hmc5843_writable_ranges[] = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 30 | regmap_reg_range(0, HMC5843_MODE_REG), |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
Krzysztof Kozlowski | 1531330 | 2015-02-24 10:41:48 +0100 | [diff] [blame] | 33 | static const struct regmap_access_table hmc5843_writable_table = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 34 | .yes_ranges = hmc5843_writable_ranges, |
| 35 | .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges), |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static const struct regmap_range hmc5843_volatile_ranges[] = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 39 | regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG), |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
Krzysztof Kozlowski | 1531330 | 2015-02-24 10:41:48 +0100 | [diff] [blame] | 42 | static const struct regmap_access_table hmc5843_volatile_table = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 43 | .yes_ranges = hmc5843_volatile_ranges, |
| 44 | .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges), |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Krzysztof Kozlowski | 1531330 | 2015-02-24 10:41:48 +0100 | [diff] [blame] | 47 | static const struct regmap_config hmc5843_i2c_regmap_config = { |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 48 | .reg_bits = 8, |
| 49 | .val_bits = 8, |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 50 | |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 51 | .rd_table = &hmc5843_readable_table, |
| 52 | .wr_table = &hmc5843_writable_table, |
| 53 | .volatile_table = &hmc5843_volatile_table, |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 54 | |
Tolga Ceylan | 98a3d2e | 2015-02-08 00:04:53 -0800 | [diff] [blame] | 55 | .cache_type = REGCACHE_RBTREE, |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Cristina Opriceana | aa6432f | 2015-03-19 21:07:51 +0200 | [diff] [blame] | 58 | static int hmc5843_i2c_probe(struct i2c_client *cli, |
Cristina Opriceana | 7079f21 | 2015-03-19 21:06:42 +0200 | [diff] [blame] | 59 | const struct i2c_device_id *id) |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 60 | { |
Cristina Opriceana | aa6432f | 2015-03-19 21:07:51 +0200 | [diff] [blame] | 61 | return hmc5843_common_probe(&cli->dev, |
| 62 | devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config), |
Yong Li | 70b2737 | 2015-08-12 21:25:46 +0800 | [diff] [blame] | 63 | id->driver_data, id->name); |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static int hmc5843_i2c_remove(struct i2c_client *client) |
| 67 | { |
| 68 | return hmc5843_common_remove(&client->dev); |
| 69 | } |
| 70 | |
| 71 | static const struct i2c_device_id hmc5843_id[] = { |
| 72 | { "hmc5843", HMC5843_ID }, |
| 73 | { "hmc5883", HMC5883_ID }, |
| 74 | { "hmc5883l", HMC5883L_ID }, |
Josef Gajdusek | 5a059bd | 2014-07-22 16:02:00 +0100 | [diff] [blame] | 75 | { "hmc5983", HMC5983_ID }, |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 76 | { } |
| 77 | }; |
| 78 | MODULE_DEVICE_TABLE(i2c, hmc5843_id); |
| 79 | |
| 80 | static const struct of_device_id hmc5843_of_match[] = { |
| 81 | { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID }, |
| 82 | { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID }, |
| 83 | { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID }, |
Josef Gajdusek | 5a059bd | 2014-07-22 16:02:00 +0100 | [diff] [blame] | 84 | { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID }, |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 85 | {} |
| 86 | }; |
| 87 | MODULE_DEVICE_TABLE(of, hmc5843_of_match); |
| 88 | |
| 89 | static struct i2c_driver hmc5843_driver = { |
| 90 | .driver = { |
| 91 | .name = "hmc5843", |
| 92 | .pm = HMC5843_PM_OPS, |
| 93 | .of_match_table = hmc5843_of_match, |
| 94 | }, |
| 95 | .id_table = hmc5843_id, |
| 96 | .probe = hmc5843_i2c_probe, |
| 97 | .remove = hmc5843_i2c_remove, |
| 98 | }; |
| 99 | module_i2c_driver(hmc5843_driver); |
| 100 | |
| 101 | MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>"); |
Josef Gajdusek | 5a059bd | 2014-07-22 16:02:00 +0100 | [diff] [blame] | 102 | MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver"); |
Josef Gajdusek | fc35a91 | 2014-07-22 16:01:00 +0100 | [diff] [blame] | 103 | MODULE_LICENSE("GPL"); |