2017-12-12 07:43:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Copyright (c) 2017, Linaro Ltd.
|
|
|
|
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/slimbus.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2018-07-06 23:05:27 +08:00
|
|
|
static int regmap_slimbus_write(void *context, const void *data, size_t count)
|
2017-12-12 07:43:02 +08:00
|
|
|
{
|
|
|
|
struct slim_device *sdev = context;
|
|
|
|
|
2018-07-06 23:05:27 +08:00
|
|
|
return slim_write(sdev, *(u16 *)data, count - 2, (u8 *)data + 2);
|
2017-12-12 07:43:02 +08:00
|
|
|
}
|
|
|
|
|
2018-07-06 23:05:27 +08:00
|
|
|
static int regmap_slimbus_read(void *context, const void *reg, size_t reg_size,
|
|
|
|
void *val, size_t val_size)
|
2017-12-12 07:43:02 +08:00
|
|
|
{
|
|
|
|
struct slim_device *sdev = context;
|
|
|
|
|
2018-07-06 23:05:27 +08:00
|
|
|
return slim_read(sdev, *(u16 *)reg, val_size, val);
|
2017-12-12 07:43:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct regmap_bus regmap_slimbus_bus = {
|
2018-07-06 23:05:27 +08:00
|
|
|
.write = regmap_slimbus_write,
|
|
|
|
.read = regmap_slimbus_read,
|
2017-12-12 07:43:02 +08:00
|
|
|
.reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
|
|
|
|
.val_format_endian_default = REGMAP_ENDIAN_LITTLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_bus *regmap_get_slimbus(struct slim_device *slim,
|
|
|
|
const struct regmap_config *config)
|
|
|
|
{
|
2018-05-25 21:50:37 +08:00
|
|
|
if (config->val_bits == 8 && config->reg_bits == 16)
|
2017-12-12 07:43:02 +08:00
|
|
|
return ®map_slimbus_bus;
|
|
|
|
|
|
|
|
return ERR_PTR(-ENOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
|
|
|
|
const struct regmap_config *config,
|
|
|
|
struct lock_class_key *lock_key,
|
|
|
|
const char *lock_name)
|
|
|
|
{
|
|
|
|
const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config);
|
|
|
|
|
|
|
|
if (IS_ERR(bus))
|
|
|
|
return ERR_CAST(bus);
|
|
|
|
|
|
|
|
return __regmap_init(&slimbus->dev, bus, &slimbus->dev, config,
|
|
|
|
lock_key, lock_name);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__regmap_init_slimbus);
|
|
|
|
|
|
|
|
struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
|
|
|
|
const struct regmap_config *config,
|
|
|
|
struct lock_class_key *lock_key,
|
|
|
|
const char *lock_name)
|
|
|
|
{
|
|
|
|
const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config);
|
|
|
|
|
|
|
|
if (IS_ERR(bus))
|
|
|
|
return ERR_CAST(bus);
|
|
|
|
|
|
|
|
return __devm_regmap_init(&slimbus->dev, bus, &slimbus, config,
|
|
|
|
lock_key, lock_name);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__devm_regmap_init_slimbus);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|