2019-05-27 08:55:01 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-03-11 19:33:54 -04:00
|
|
|
/*
|
|
|
|
* Broadcom BCM590xx PMU
|
|
|
|
*
|
|
|
|
* Copyright 2014 Linaro Limited
|
|
|
|
* Author: Matt Porter <mporter@linaro.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mfd/bcm590xx.h>
|
|
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
2025-05-15 16:16:31 +02:00
|
|
|
/* Under primary I2C address: */
|
|
|
|
#define BCM590XX_REG_PMUID 0x1e
|
|
|
|
|
|
|
|
#define BCM590XX_REG_PMUREV 0x1f
|
|
|
|
#define BCM590XX_PMUREV_DIG_MASK 0xF
|
|
|
|
#define BCM590XX_PMUREV_DIG_SHIFT 0
|
|
|
|
#define BCM590XX_PMUREV_ANA_MASK 0xF0
|
|
|
|
#define BCM590XX_PMUREV_ANA_SHIFT 4
|
|
|
|
|
2014-03-11 19:33:54 -04:00
|
|
|
static const struct mfd_cell bcm590xx_devs[] = {
|
|
|
|
{
|
|
|
|
.name = "bcm590xx-vregs",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
static const struct regmap_config bcm590xx_regmap_config_pri = {
|
2014-03-11 19:33:54 -04:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
2014-04-23 19:21:31 -04:00
|
|
|
.max_register = BCM590XX_MAX_REGISTER_PRI,
|
2024-02-06 02:13:01 -05:00
|
|
|
.cache_type = REGCACHE_MAPLE,
|
2014-03-11 19:33:54 -04:00
|
|
|
};
|
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
static const struct regmap_config bcm590xx_regmap_config_sec = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
.max_register = BCM590XX_MAX_REGISTER_SEC,
|
2024-02-06 02:13:01 -05:00
|
|
|
.cache_type = REGCACHE_MAPLE,
|
2014-04-23 19:21:31 -04:00
|
|
|
};
|
|
|
|
|
2025-05-15 16:16:31 +02:00
|
|
|
/* Map PMU ID value to model name string */
|
|
|
|
static const char * const bcm590xx_names[] = {
|
|
|
|
[BCM590XX_PMUID_BCM59054] = "BCM59054",
|
|
|
|
[BCM590XX_PMUID_BCM59056] = "BCM59056",
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm590xx_parse_version(struct bcm590xx *bcm590xx)
|
|
|
|
{
|
|
|
|
unsigned int id, rev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get PMU ID and verify that it matches compatible */
|
|
|
|
ret = regmap_read(bcm590xx->regmap_pri, BCM590XX_REG_PMUID, &id);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(bcm590xx->dev, "failed to read PMU ID: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id != bcm590xx->pmu_id) {
|
|
|
|
dev_err(bcm590xx->dev, "Incorrect ID for %s: expected %x, got %x.\n",
|
|
|
|
bcm590xx_names[bcm590xx->pmu_id], bcm590xx->pmu_id, id);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get PMU revision and store it in the info struct */
|
|
|
|
ret = regmap_read(bcm590xx->regmap_pri, BCM590XX_REG_PMUREV, &rev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(bcm590xx->dev, "failed to read PMU revision: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcm590xx->rev_digital = (rev & BCM590XX_PMUREV_DIG_MASK) >> BCM590XX_PMUREV_DIG_SHIFT;
|
|
|
|
|
|
|
|
bcm590xx->rev_analog = (rev & BCM590XX_PMUREV_ANA_MASK) >> BCM590XX_PMUREV_ANA_SHIFT;
|
|
|
|
|
|
|
|
dev_dbg(bcm590xx->dev, "PMU ID 0x%x (%s), revision: digital %d, analog %d",
|
|
|
|
id, bcm590xx_names[id], bcm590xx->rev_digital, bcm590xx->rev_analog);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-18 23:42:37 +01:00
|
|
|
static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri)
|
2014-03-11 19:33:54 -04:00
|
|
|
{
|
|
|
|
struct bcm590xx *bcm590xx;
|
|
|
|
int ret;
|
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL);
|
2014-03-11 19:33:54 -04:00
|
|
|
if (!bcm590xx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
i2c_set_clientdata(i2c_pri, bcm590xx);
|
|
|
|
bcm590xx->dev = &i2c_pri->dev;
|
|
|
|
bcm590xx->i2c_pri = i2c_pri;
|
2014-03-11 19:33:54 -04:00
|
|
|
|
2025-05-15 16:16:30 +02:00
|
|
|
bcm590xx->pmu_id = (uintptr_t) of_device_get_match_data(bcm590xx->dev);
|
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri,
|
|
|
|
&bcm590xx_regmap_config_pri);
|
|
|
|
if (IS_ERR(bcm590xx->regmap_pri)) {
|
|
|
|
ret = PTR_ERR(bcm590xx->regmap_pri);
|
|
|
|
dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret);
|
2014-03-11 19:33:54 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
/* Secondary I2C slave address is the base address with A(2) asserted */
|
2019-07-22 19:26:11 +02:00
|
|
|
bcm590xx->i2c_sec = i2c_new_dummy_device(i2c_pri->adapter,
|
2014-04-23 19:21:31 -04:00
|
|
|
i2c_pri->addr | BIT(2));
|
2019-07-22 19:26:11 +02:00
|
|
|
if (IS_ERR(bcm590xx->i2c_sec)) {
|
2014-04-23 19:21:31 -04:00
|
|
|
dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n");
|
2019-07-22 19:26:11 +02:00
|
|
|
return PTR_ERR(bcm590xx->i2c_sec);
|
2014-04-23 19:21:31 -04:00
|
|
|
}
|
|
|
|
i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx);
|
|
|
|
|
|
|
|
bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec,
|
|
|
|
&bcm590xx_regmap_config_sec);
|
|
|
|
if (IS_ERR(bcm590xx->regmap_sec)) {
|
|
|
|
ret = PTR_ERR(bcm590xx->regmap_sec);
|
|
|
|
dev_err(&bcm590xx->i2c_sec->dev,
|
|
|
|
"secondary regmap init failed: %d\n", ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-05-15 16:16:31 +02:00
|
|
|
ret = bcm590xx_parse_version(bcm590xx);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2016-04-08 00:13:00 +05:30
|
|
|
ret = devm_mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs,
|
|
|
|
ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL);
|
2014-04-23 19:21:31 -04:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-03-11 19:33:54 -04:00
|
|
|
|
2014-04-23 19:21:31 -04:00
|
|
|
err:
|
|
|
|
i2c_unregister_device(bcm590xx->i2c_sec);
|
2014-03-11 19:33:54 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id bcm590xx_of_match[] = {
|
2025-05-15 16:16:30 +02:00
|
|
|
{
|
|
|
|
.compatible = "brcm,bcm59054",
|
|
|
|
.data = (void *)BCM590XX_PMUID_BCM59054,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "brcm,bcm59056",
|
|
|
|
.data = (void *)BCM590XX_PMUID_BCM59056,
|
|
|
|
},
|
2014-03-11 19:33:54 -04:00
|
|
|
{ }
|
|
|
|
};
|
2014-03-15 09:24:50 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, bcm590xx_of_match);
|
2014-03-11 19:33:54 -04:00
|
|
|
|
|
|
|
static const struct i2c_device_id bcm590xx_i2c_id[] = {
|
2025-05-15 16:16:30 +02:00
|
|
|
{ "bcm59054" },
|
2014-03-11 19:33:54 -04:00
|
|
|
{ "bcm59056" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id);
|
|
|
|
|
|
|
|
static struct i2c_driver bcm590xx_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "bcm590xx",
|
2020-11-20 17:21:18 +01:00
|
|
|
.of_match_table = bcm590xx_of_match,
|
2014-03-11 19:33:54 -04:00
|
|
|
},
|
2023-05-15 20:27:52 +02:00
|
|
|
.probe = bcm590xx_i2c_probe,
|
2014-03-11 19:33:54 -04:00
|
|
|
.id_table = bcm590xx_i2c_id,
|
|
|
|
};
|
|
|
|
module_i2c_driver(bcm590xx_i2c_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
|
|
|
|
MODULE_DESCRIPTION("BCM590xx multi-function driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|