···11+/*22+ * Register map access API - SPMI support33+ *44+ * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.55+ *66+ * Based on regmap-i2c.c:77+ * Copyright 2011 Wolfson Microelectronics plc88+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>99+ *1010+ * This program is free software; you can redistribute it and/or modify1111+ * it under the terms of the GNU General Public License version 2 and1212+ * only version 2 as published by the Free Software Foundation.1313+ *1414+ * This program is distributed in the hope that it will be useful,1515+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1616+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1717+ * GNU General Public License for more details.1818+ *1919+ */2020+#include <linux/regmap.h>2121+#include <linux/spmi.h>2222+#include <linux/module.h>2323+#include <linux/init.h>2424+2525+static int regmap_spmi_read(void *context,2626+ const void *reg, size_t reg_size,2727+ void *val, size_t val_size)2828+{2929+ BUG_ON(reg_size != 2);3030+ return spmi_ext_register_readl(context, *(u16 *)reg,3131+ val, val_size);3232+}3333+3434+static int regmap_spmi_gather_write(void *context,3535+ const void *reg, size_t reg_size,3636+ const void *val, size_t val_size)3737+{3838+ BUG_ON(reg_size != 2);3939+ return spmi_ext_register_writel(context, *(u16 *)reg, val, val_size);4040+}4141+4242+static int regmap_spmi_write(void *context, const void *data,4343+ size_t count)4444+{4545+ BUG_ON(count < 2);4646+ return regmap_spmi_gather_write(context, data, 2, data + 2, count - 2);4747+}4848+4949+static struct regmap_bus regmap_spmi = {5050+ .read = regmap_spmi_read,5151+ .write = regmap_spmi_write,5252+ .gather_write = regmap_spmi_gather_write,5353+ .reg_format_endian_default = REGMAP_ENDIAN_NATIVE,5454+ .val_format_endian_default = REGMAP_ENDIAN_NATIVE,5555+};5656+5757+/**5858+ * regmap_init_spmi(): Initialize register map5959+ *6060+ * @sdev: Device that will be interacted with6161+ * @config: Configuration for register map6262+ *6363+ * The return value will be an ERR_PTR() on error or a valid pointer to6464+ * a struct regmap.6565+ */6666+struct regmap *regmap_init_spmi(struct spmi_device *sdev,6767+ const struct regmap_config *config)6868+{6969+ return regmap_init(&sdev->dev, ®map_spmi, sdev, config);7070+}7171+EXPORT_SYMBOL_GPL(regmap_init_spmi);7272+7373+/**7474+ * devm_regmap_init_spmi(): Initialise managed register map7575+ *7676+ * @sdev: Device that will be interacted with7777+ * @config: Configuration for register map7878+ *7979+ * The return value will be an ERR_PTR() on error or a valid pointer8080+ * to a struct regmap. The regmap will be automatically freed by the8181+ * device management code.8282+ */8383+struct regmap *devm_regmap_init_spmi(struct spmi_device *sdev,8484+ const struct regmap_config *config)8585+{8686+ return devm_regmap_init(&sdev->dev, ®map_spmi, sdev, config);8787+}8888+EXPORT_SYMBOL_GPL(devm_regmap_init_spmi);8989+9090+MODULE_LICENSE("GPL");