mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
nvmem: qcom-spmi-sdam: Migrate to devm_spmi_subdevice_alloc_and_add()
Some Qualcomm PMICs integrate a SDAM device, internally located in a specific address range reachable through SPMI communication. Instead of using the parent SPMI device (the main PMIC) as a kind of syscon in this driver, register a new SPMI sub-device for SDAM and initialize its own regmap with this sub-device's specific base address, retrieved from the devicetree. This allows to stop manually adding the register base address to every R/W call in this driver, as this can be, and is now, handled by the regmap API instead. Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-QRD Acked-by: Srinivas Kandagatla <srini@kernel.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
939e80cef9
commit
1e048fe290
|
|
@ -468,6 +468,7 @@ config NVMEM_SNVS_LPGPR
|
|||
config NVMEM_SPMI_SDAM
|
||||
tristate "SPMI SDAM Support"
|
||||
depends on SPMI
|
||||
select REGMAP_SPMI
|
||||
help
|
||||
This driver supports the Shared Direct Access Memory Module on
|
||||
Qualcomm Technologies, Inc. PMICs. It provides the clients
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <linux/nvmem-provider.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/spmi.h>
|
||||
|
||||
#define SDAM_MEM_START 0x40
|
||||
#define REGISTER_MAP_ID 0x40
|
||||
|
|
@ -20,7 +21,6 @@
|
|||
struct sdam_chip {
|
||||
struct regmap *regmap;
|
||||
struct nvmem_config sdam_config;
|
||||
unsigned int base;
|
||||
unsigned int size;
|
||||
};
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ static int sdam_read(void *priv, unsigned int offset, void *val,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = regmap_bulk_read(sdam->regmap, sdam->base + offset, val, bytes);
|
||||
rc = regmap_bulk_read(sdam->regmap, offset, val, bytes);
|
||||
if (rc < 0)
|
||||
dev_err(dev, "Failed to read SDAM offset %#x len=%zd, rc=%d\n",
|
||||
offset, bytes, rc);
|
||||
|
|
@ -100,7 +100,7 @@ static int sdam_write(void *priv, unsigned int offset, void *val,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = regmap_bulk_write(sdam->regmap, sdam->base + offset, val, bytes);
|
||||
rc = regmap_bulk_write(sdam->regmap, offset, val, bytes);
|
||||
if (rc < 0)
|
||||
dev_err(dev, "Failed to write SDAM offset %#x len=%zd, rc=%d\n",
|
||||
offset, bytes, rc);
|
||||
|
|
@ -110,8 +110,17 @@ static int sdam_write(void *priv, unsigned int offset, void *val,
|
|||
|
||||
static int sdam_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct regmap_config sdam_regmap_config = {
|
||||
.reg_bits = 16,
|
||||
.val_bits = 8,
|
||||
.max_register = 0xff,
|
||||
.fast_io = true,
|
||||
};
|
||||
struct sdam_chip *sdam;
|
||||
struct nvmem_device *nvmem;
|
||||
struct spmi_device *sparent;
|
||||
struct spmi_subdevice *sub_sdev;
|
||||
struct device *dev = &pdev->dev;
|
||||
unsigned int val;
|
||||
int rc;
|
||||
|
||||
|
|
@ -119,19 +128,26 @@ static int sdam_probe(struct platform_device *pdev)
|
|||
if (!sdam)
|
||||
return -ENOMEM;
|
||||
|
||||
sdam->regmap = dev_get_regmap(pdev->dev.parent, NULL);
|
||||
if (!sdam->regmap) {
|
||||
dev_err(&pdev->dev, "Failed to get regmap handle\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
sparent = spmi_get_parent_spmi_device(dev);
|
||||
if (!sparent)
|
||||
return -ENODEV;
|
||||
|
||||
rc = of_property_read_u32(pdev->dev.of_node, "reg", &sdam->base);
|
||||
sub_sdev = devm_spmi_subdevice_alloc_and_add(dev, sparent);
|
||||
if (IS_ERR(sub_sdev))
|
||||
return PTR_ERR(sub_sdev);
|
||||
|
||||
rc = device_property_read_u32(dev, "reg", &sdam_regmap_config.reg_base);
|
||||
if (rc < 0) {
|
||||
dev_err(&pdev->dev, "Failed to get SDAM base, rc=%d\n", rc);
|
||||
dev_err(dev, "Failed to get SDAM base, rc=%d\n", rc);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = regmap_read(sdam->regmap, sdam->base + SDAM_SIZE, &val);
|
||||
sdam->regmap = devm_regmap_init_spmi_ext(&sub_sdev->sdev, &sdam_regmap_config);
|
||||
if (IS_ERR(sdam->regmap))
|
||||
return dev_err_probe(dev, PTR_ERR(sdam->regmap),
|
||||
"Failed to get regmap handle\n");
|
||||
|
||||
rc = regmap_read(sdam->regmap, SDAM_SIZE, &val);
|
||||
if (rc < 0) {
|
||||
dev_err(&pdev->dev, "Failed to read SDAM_SIZE rc=%d\n", rc);
|
||||
return -EINVAL;
|
||||
|
|
@ -159,7 +175,7 @@ static int sdam_probe(struct platform_device *pdev)
|
|||
}
|
||||
dev_dbg(&pdev->dev,
|
||||
"SDAM base=%#x size=%u registered successfully\n",
|
||||
sdam->base, sdam->size);
|
||||
sdam_regmap_config.reg_base, sdam->size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -181,3 +197,4 @@ module_platform_driver(sdam_driver);
|
|||
|
||||
MODULE_DESCRIPTION("QCOM SPMI SDAM driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_IMPORT_NS("SPMI");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user