2 * Register map access API - SPMI support
4 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
6 * Based on regmap-i2c.c:
7 * Copyright 2011 Wolfson Microelectronics plc
8 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
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.
20 #include <linux/regmap.h>
21 #include <linux/spmi.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
25 static int regmap_spmi_read(void *context
,
26 const void *reg
, size_t reg_size
,
27 void *val
, size_t val_size
)
29 BUG_ON(reg_size
!= 2);
30 return spmi_ext_register_readl(context
, *(u16
*)reg
,
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
)
38 BUG_ON(reg_size
!= 2);
39 return spmi_ext_register_writel(context
, *(u16
*)reg
, val
, val_size
);
42 static int regmap_spmi_write(void *context
, const void *data
,
46 return regmap_spmi_gather_write(context
, data
, 2, data
+ 2, count
- 2);
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
,
58 * regmap_init_spmi(): Initialize register map
60 * @sdev: Device that will be interacted with
61 * @config: Configuration for register map
63 * The return value will be an ERR_PTR() on error or a valid pointer to
66 struct regmap
*regmap_init_spmi(struct spmi_device
*sdev
,
67 const struct regmap_config
*config
)
69 return regmap_init(&sdev
->dev
, ®map_spmi
, sdev
, config
);
71 EXPORT_SYMBOL_GPL(regmap_init_spmi
);
74 * devm_regmap_init_spmi(): Initialise managed register map
76 * @sdev: Device that will be interacted with
77 * @config: Configuration for register map
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.
83 struct regmap
*devm_regmap_init_spmi(struct spmi_device
*sdev
,
84 const struct regmap_config
*config
)
86 return devm_regmap_init(&sdev
->dev
, ®map_spmi
, sdev
, config
);
88 EXPORT_SYMBOL_GPL(devm_regmap_init_spmi
);
90 MODULE_LICENSE("GPL");