]>
Commit | Line | Data |
---|---|---|
d3f16219 JG |
1 | /* |
2 | * SPI driver for hmc5983 | |
3 | * | |
4 | * Copyright (C) Josef Gajdusek <atx@atx.name> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * */ | |
11 | ||
12 | #include <linux/module.h> | |
13 | #include <linux/spi/spi.h> | |
14 | #include <linux/iio/iio.h> | |
15 | ||
16 | #include "hmc5843.h" | |
17 | ||
18 | static const struct regmap_range hmc5843_readable_ranges[] = { | |
19 | regmap_reg_range(0, HMC5843_ID_END), | |
20 | }; | |
21 | ||
22 | static struct regmap_access_table hmc5843_readable_table = { | |
23 | .yes_ranges = hmc5843_readable_ranges, | |
24 | .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges), | |
25 | }; | |
26 | ||
27 | static const struct regmap_range hmc5843_writable_ranges[] = { | |
28 | regmap_reg_range(0, HMC5843_MODE_REG), | |
29 | }; | |
30 | ||
31 | static struct regmap_access_table hmc5843_writable_table = { | |
32 | .yes_ranges = hmc5843_writable_ranges, | |
33 | .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges), | |
34 | }; | |
35 | ||
36 | static const struct regmap_range hmc5843_volatile_ranges[] = { | |
37 | regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG), | |
38 | }; | |
39 | ||
40 | static struct regmap_access_table hmc5843_volatile_table = { | |
41 | .yes_ranges = hmc5843_volatile_ranges, | |
42 | .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges), | |
43 | }; | |
44 | ||
45 | static struct regmap_config hmc5843_spi_regmap_config = { | |
46 | .reg_bits = 8, | |
47 | .val_bits = 8, | |
48 | ||
49 | .rd_table = &hmc5843_readable_table, | |
50 | .wr_table = &hmc5843_writable_table, | |
51 | .volatile_table = &hmc5843_volatile_table, | |
52 | ||
53 | /* Autoincrement address pointer */ | |
54 | .read_flag_mask = 0xc0, | |
55 | ||
56 | .cache_type = REGCACHE_RBTREE, | |
57 | }; | |
58 | ||
59 | static int hmc5843_spi_probe(struct spi_device *spi) | |
60 | { | |
61 | int ret; | |
62 | ||
63 | spi->mode = SPI_MODE_3; | |
64 | spi->max_speed_hz = 8000000; | |
65 | spi->bits_per_word = 8; | |
66 | ret = spi_setup(spi); | |
67 | if (ret) | |
68 | return ret; | |
69 | ||
70 | return hmc5843_common_probe(&spi->dev, | |
71 | devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config), | |
72 | HMC5983_ID); | |
73 | } | |
74 | ||
75 | static int hmc5843_spi_remove(struct spi_device *spi) | |
76 | { | |
77 | return hmc5843_common_remove(&spi->dev); | |
78 | } | |
79 | ||
80 | static const struct spi_device_id hmc5843_id[] = { | |
81 | { "hmc5983", HMC5983_ID }, | |
82 | { } | |
83 | }; | |
84 | ||
85 | static struct spi_driver hmc5843_driver = { | |
86 | .driver = { | |
87 | .name = "hmc5843", | |
88 | .pm = HMC5843_PM_OPS, | |
89 | .owner = THIS_MODULE, | |
90 | }, | |
91 | .id_table = hmc5843_id, | |
92 | .probe = hmc5843_spi_probe, | |
93 | .remove = hmc5843_spi_remove, | |
94 | }; | |
95 | ||
96 | module_spi_driver(hmc5843_driver); | |
97 | ||
98 | MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>"); | |
99 | MODULE_DESCRIPTION("HMC5983 SPI driver"); | |
100 | MODULE_LICENSE("GPL"); |