]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/iio/magnetometer/hmc5843_spi.c
staging: iio: hmc5843: Set iio name dynamically
[karo-tx-linux.git] / drivers / staging / iio / magnetometer / hmc5843_spi.c
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 const 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 const 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 const 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 const 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         const struct spi_device_id *id = spi_get_device_id(spi);
63
64         spi->mode = SPI_MODE_3;
65         spi->max_speed_hz = 8000000;
66         spi->bits_per_word = 8;
67         ret = spi_setup(spi);
68         if (ret)
69                 return ret;
70
71         return hmc5843_common_probe(&spi->dev,
72                         devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
73                         id->driver_data, id->name);
74 }
75
76 static int hmc5843_spi_remove(struct spi_device *spi)
77 {
78         return hmc5843_common_remove(&spi->dev);
79 }
80
81 static const struct spi_device_id hmc5843_id[] = {
82         { "hmc5983", HMC5983_ID },
83         { }
84 };
85
86 static struct spi_driver hmc5843_driver = {
87                 .driver = {
88                                 .name = "hmc5843",
89                                 .pm = HMC5843_PM_OPS,
90                                 .owner = THIS_MODULE,
91                 },
92                 .id_table = hmc5843_id,
93                 .probe = hmc5843_spi_probe,
94                 .remove = hmc5843_spi_remove,
95 };
96
97 module_spi_driver(hmc5843_driver);
98
99 MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
100 MODULE_DESCRIPTION("HMC5983 SPI driver");
101 MODULE_LICENSE("GPL");