mmc: rtsx_pci: Enable MMC_CAP_ERASE to allow erase/discard/trim requests
[linux/fpc-iii.git] / drivers / iio / magnetometer / hmc5843_spi.c
blob535f03a70d630f7f37b0fda73c3e39da92c28c73
1 /*
2 * SPI driver for hmc5983
4 * Copyright (C) Josef Gajdusek <atx@atx.name>
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 */
11 #include <linux/module.h>
12 #include <linux/spi/spi.h>
13 #include <linux/iio/iio.h>
15 #include "hmc5843.h"
17 static const struct regmap_range hmc5843_readable_ranges[] = {
18 regmap_reg_range(0, HMC5843_ID_END),
21 static const struct regmap_access_table hmc5843_readable_table = {
22 .yes_ranges = hmc5843_readable_ranges,
23 .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
26 static const struct regmap_range hmc5843_writable_ranges[] = {
27 regmap_reg_range(0, HMC5843_MODE_REG),
30 static const struct regmap_access_table hmc5843_writable_table = {
31 .yes_ranges = hmc5843_writable_ranges,
32 .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
35 static const struct regmap_range hmc5843_volatile_ranges[] = {
36 regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
39 static const struct regmap_access_table hmc5843_volatile_table = {
40 .yes_ranges = hmc5843_volatile_ranges,
41 .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
44 static const struct regmap_config hmc5843_spi_regmap_config = {
45 .reg_bits = 8,
46 .val_bits = 8,
48 .rd_table = &hmc5843_readable_table,
49 .wr_table = &hmc5843_writable_table,
50 .volatile_table = &hmc5843_volatile_table,
52 /* Autoincrement address pointer */
53 .read_flag_mask = 0xc0,
55 .cache_type = REGCACHE_RBTREE,
58 static int hmc5843_spi_probe(struct spi_device *spi)
60 int ret;
61 const struct spi_device_id *id = spi_get_device_id(spi);
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;
70 return hmc5843_common_probe(&spi->dev,
71 devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
72 id->driver_data, id->name);
75 static int hmc5843_spi_remove(struct spi_device *spi)
77 return hmc5843_common_remove(&spi->dev);
80 static const struct spi_device_id hmc5843_id[] = {
81 { "hmc5983", HMC5983_ID },
82 { }
84 MODULE_DEVICE_TABLE(spi, hmc5843_id);
86 static struct spi_driver hmc5843_driver = {
87 .driver = {
88 .name = "hmc5843",
89 .pm = HMC5843_PM_OPS,
91 .id_table = hmc5843_id,
92 .probe = hmc5843_spi_probe,
93 .remove = hmc5843_spi_remove,
96 module_spi_driver(hmc5843_driver);
98 MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
99 MODULE_DESCRIPTION("HMC5983 SPI driver");
100 MODULE_LICENSE("GPL");