blob: 535f03a70d630f7f37b0fda73c3e39da92c28c73 [file] [log] [blame]
Josef Gajdusekd3f16212014-07-22 16:03:00 +01001/*
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.
Cristina Moraru4630adb2016-02-08 00:21:50 +02009 */
Josef Gajdusekd3f16212014-07-22 16:03:00 +010010
11#include <linux/module.h>
12#include <linux/spi/spi.h>
13#include <linux/iio/iio.h>
14
15#include "hmc5843.h"
16
17static const struct regmap_range hmc5843_readable_ranges[] = {
18 regmap_reg_range(0, HMC5843_ID_END),
19};
20
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010021static const struct regmap_access_table hmc5843_readable_table = {
Josef Gajdusekd3f16212014-07-22 16:03:00 +010022 .yes_ranges = hmc5843_readable_ranges,
23 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
24};
25
26static const struct regmap_range hmc5843_writable_ranges[] = {
27 regmap_reg_range(0, HMC5843_MODE_REG),
28};
29
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010030static const struct regmap_access_table hmc5843_writable_table = {
Josef Gajdusekd3f16212014-07-22 16:03:00 +010031 .yes_ranges = hmc5843_writable_ranges,
32 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
33};
34
35static const struct regmap_range hmc5843_volatile_ranges[] = {
36 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
37};
38
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010039static const struct regmap_access_table hmc5843_volatile_table = {
Josef Gajdusekd3f16212014-07-22 16:03:00 +010040 .yes_ranges = hmc5843_volatile_ranges,
41 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
42};
43
Krzysztof Kozlowski15313302015-02-24 10:41:48 +010044static const struct regmap_config hmc5843_spi_regmap_config = {
Josef Gajdusekd3f16212014-07-22 16:03:00 +010045 .reg_bits = 8,
46 .val_bits = 8,
47
48 .rd_table = &hmc5843_readable_table,
49 .wr_table = &hmc5843_writable_table,
50 .volatile_table = &hmc5843_volatile_table,
51
52 /* Autoincrement address pointer */
53 .read_flag_mask = 0xc0,
54
55 .cache_type = REGCACHE_RBTREE,
56};
57
58static int hmc5843_spi_probe(struct spi_device *spi)
59{
60 int ret;
Yong Li70b27372015-08-12 21:25:46 +080061 const struct spi_device_id *id = spi_get_device_id(spi);
Josef Gajdusekd3f16212014-07-22 16:03:00 +010062
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),
Yong Li70b27372015-08-12 21:25:46 +080072 id->driver_data, id->name);
Josef Gajdusekd3f16212014-07-22 16:03:00 +010073}
74
75static int hmc5843_spi_remove(struct spi_device *spi)
76{
77 return hmc5843_common_remove(&spi->dev);
78}
79
80static const struct spi_device_id hmc5843_id[] = {
81 { "hmc5983", HMC5983_ID },
82 { }
83};
Javier Martinez Canillas45ef12b2015-08-20 09:07:15 +020084MODULE_DEVICE_TABLE(spi, hmc5843_id);
Josef Gajdusekd3f16212014-07-22 16:03:00 +010085
86static struct spi_driver hmc5843_driver = {
87 .driver = {
88 .name = "hmc5843",
89 .pm = HMC5843_PM_OPS,
Josef Gajdusekd3f16212014-07-22 16:03:00 +010090 },
91 .id_table = hmc5843_id,
92 .probe = hmc5843_spi_probe,
93 .remove = hmc5843_spi_remove,
94};
95
96module_spi_driver(hmc5843_driver);
97
98MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
99MODULE_DESCRIPTION("HMC5983 SPI driver");
100MODULE_LICENSE("GPL");