diff options
author | Josh Cartwright <joshc@codeaurora.org> | 2013-10-28 14:12:35 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-10-28 15:51:43 -0400 |
commit | a01779f89fc8a2225cb82dca0fc7b8451851cb7b (patch) | |
tree | afaa05d2b1bbd58462a2fcdc2425c133a38eb44c /drivers/base | |
parent | 959f58544b7f20c92d5eb43d1232c96c15c01bfb (diff) |
regmap: add SPMI support
Add basic support for the System Power Management Interface (SPMI) bus.
This is a simple implementation which only implements register accesses
via the Extended Register Read/Write Long commands.
Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/regmap/Kconfig | 5 | ||||
-rw-r--r-- | drivers/base/regmap/Makefile | 1 | ||||
-rw-r--r-- | drivers/base/regmap/regmap-spmi.c | 90 |
3 files changed, 95 insertions, 1 deletions
diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index f0d30543fcce..4251570610c9 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig | |||
@@ -3,7 +3,7 @@ | |||
3 | # subsystems should select the appropriate symbols. | 3 | # subsystems should select the appropriate symbols. |
4 | 4 | ||
5 | config REGMAP | 5 | config REGMAP |
6 | default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_MMIO || REGMAP_IRQ) | 6 | default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_MMIO || REGMAP_IRQ) |
7 | select LZO_COMPRESS | 7 | select LZO_COMPRESS |
8 | select LZO_DECOMPRESS | 8 | select LZO_DECOMPRESS |
9 | select IRQ_DOMAIN if REGMAP_IRQ | 9 | select IRQ_DOMAIN if REGMAP_IRQ |
@@ -15,6 +15,9 @@ config REGMAP_I2C | |||
15 | config REGMAP_SPI | 15 | config REGMAP_SPI |
16 | tristate | 16 | tristate |
17 | 17 | ||
18 | config REGMAP_SPMI | ||
19 | tristate | ||
20 | |||
18 | config REGMAP_MMIO | 21 | config REGMAP_MMIO |
19 | tristate | 22 | tristate |
20 | 23 | ||
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile index cf129980abd0..a7c670b4123a 100644 --- a/drivers/base/regmap/Makefile +++ b/drivers/base/regmap/Makefile | |||
@@ -3,5 +3,6 @@ obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o regcache-flat.o | |||
3 | obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o | 3 | obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o |
4 | obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o | 4 | obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o |
5 | obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o | 5 | obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o |
6 | obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o | ||
6 | obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o | 7 | obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o |
7 | obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o | 8 | obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o |
diff --git a/drivers/base/regmap/regmap-spmi.c b/drivers/base/regmap/regmap-spmi.c new file mode 100644 index 000000000000..ac2391013db1 --- /dev/null +++ b/drivers/base/regmap/regmap-spmi.c | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | * Register map access API - SPMI support | ||
3 | * | ||
4 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. | ||
5 | * | ||
6 | * Based on regmap-i2c.c: | ||
7 | * Copyright 2011 Wolfson Microelectronics plc | ||
8 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 and | ||
12 | * only version 2 as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | */ | ||
20 | #include <linux/regmap.h> | ||
21 | #include <linux/spmi.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | |||
25 | static int regmap_spmi_read(void *context, | ||
26 | const void *reg, size_t reg_size, | ||
27 | void *val, size_t val_size) | ||
28 | { | ||
29 | BUG_ON(reg_size != 2); | ||
30 | return spmi_ext_register_readl(context, *(u16 *)reg, | ||
31 | val, val_size); | ||
32 | } | ||
33 | |||
34 | static int regmap_spmi_gather_write(void *context, | ||
35 | const void *reg, size_t reg_size, | ||
36 | const void *val, size_t val_size) | ||
37 | { | ||
38 | BUG_ON(reg_size != 2); | ||
39 | return spmi_ext_register_writel(context, *(u16 *)reg, val, val_size); | ||
40 | } | ||
41 | |||
42 | static int regmap_spmi_write(void *context, const void *data, | ||
43 | size_t count) | ||
44 | { | ||
45 | BUG_ON(count < 2); | ||
46 | return regmap_spmi_gather_write(context, data, 2, data + 2, count - 2); | ||
47 | } | ||
48 | |||
49 | static struct regmap_bus regmap_spmi = { | ||
50 | .read = regmap_spmi_read, | ||
51 | .write = regmap_spmi_write, | ||
52 | .gather_write = regmap_spmi_gather_write, | ||
53 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
54 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
55 | }; | ||
56 | |||
57 | /** | ||
58 | * regmap_init_spmi(): Initialize register map | ||
59 | * | ||
60 | * @sdev: Device that will be interacted with | ||
61 | * @config: Configuration for register map | ||
62 | * | ||
63 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
64 | * a struct regmap. | ||
65 | */ | ||
66 | struct regmap *regmap_init_spmi(struct spmi_device *sdev, | ||
67 | const struct regmap_config *config) | ||
68 | { | ||
69 | return regmap_init(&sdev->dev, ®map_spmi, sdev, config); | ||
70 | } | ||
71 | EXPORT_SYMBOL_GPL(regmap_init_spmi); | ||
72 | |||
73 | /** | ||
74 | * devm_regmap_init_spmi(): Initialise managed register map | ||
75 | * | ||
76 | * @sdev: Device that will be interacted with | ||
77 | * @config: Configuration for register map | ||
78 | * | ||
79 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
80 | * to a struct regmap. The regmap will be automatically freed by the | ||
81 | * device management code. | ||
82 | */ | ||
83 | struct regmap *devm_regmap_init_spmi(struct spmi_device *sdev, | ||
84 | const struct regmap_config *config) | ||
85 | { | ||
86 | return devm_regmap_init(&sdev->dev, ®map_spmi, sdev, config); | ||
87 | } | ||
88 | EXPORT_SYMBOL_GPL(devm_regmap_init_spmi); | ||
89 | |||
90 | MODULE_LICENSE("GPL"); | ||