Commit 5ab3a89a authored by Alexander Shiyan's avatar Alexander Shiyan Committed by Samuel Ortiz

mfd: syscon: Add non-DT support

This patch allow using syscon driver from the platform data, i.e.
possibility using driver on systems without oftree support.
For search syscon device from the client drivers,
"syscon_regmap_lookup_by_pdevname" function was added.
Signed-off-by: default avatarAlexander Shiyan <shc_work@mail.ru>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent ed21465a
...@@ -1100,7 +1100,6 @@ config MFD_STA2X11 ...@@ -1100,7 +1100,6 @@ config MFD_STA2X11
config MFD_SYSCON config MFD_SYSCON
bool "System Controller Register R/W Based on Regmap" bool "System Controller Register R/W Based on Regmap"
depends on OF
select REGMAP_MMIO select REGMAP_MMIO
help help
Select this option to enable accessing system control registers Select this option to enable accessing system control registers
......
...@@ -29,7 +29,7 @@ struct syscon { ...@@ -29,7 +29,7 @@ struct syscon {
struct regmap *regmap; struct regmap *regmap;
}; };
static int syscon_match(struct device *dev, void *data) static int syscon_match_node(struct device *dev, void *data)
{ {
struct device_node *dn = data; struct device_node *dn = data;
...@@ -42,7 +42,7 @@ struct regmap *syscon_node_to_regmap(struct device_node *np) ...@@ -42,7 +42,7 @@ struct regmap *syscon_node_to_regmap(struct device_node *np)
struct device *dev; struct device *dev;
dev = driver_find_device(&syscon_driver.driver, NULL, np, dev = driver_find_device(&syscon_driver.driver, NULL, np,
syscon_match); syscon_match_node);
if (!dev) if (!dev)
return ERR_PTR(-EPROBE_DEFER); return ERR_PTR(-EPROBE_DEFER);
...@@ -68,6 +68,34 @@ struct regmap *syscon_regmap_lookup_by_compatible(const char *s) ...@@ -68,6 +68,34 @@ struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
} }
EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_compatible); EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_compatible);
static int syscon_match_pdevname(struct device *dev, void *data)
{
struct platform_device *pdev = to_platform_device(dev);
const struct platform_device_id *id = platform_get_device_id(pdev);
if (id)
if (!strcmp(id->name, (const char *)data))
return 1;
return !strcmp(dev_name(dev), (const char *)data);
}
struct regmap *syscon_regmap_lookup_by_pdevname(const char *s)
{
struct device *dev;
struct syscon *syscon;
dev = driver_find_device(&syscon_driver.driver, NULL, (void *)s,
syscon_match_pdevname);
if (!dev)
return ERR_PTR(-EPROBE_DEFER);
syscon = dev_get_drvdata(dev);
return syscon->regmap;
}
EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_pdevname);
struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np, struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
const char *property) const char *property)
{ {
...@@ -99,28 +127,22 @@ static struct regmap_config syscon_regmap_config = { ...@@ -99,28 +127,22 @@ static struct regmap_config syscon_regmap_config = {
static int syscon_probe(struct platform_device *pdev) static int syscon_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct syscon *syscon; struct syscon *syscon;
struct resource res; struct resource *res;
int ret;
if (!np)
return -ENOENT;
syscon = devm_kzalloc(dev, sizeof(struct syscon), syscon = devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL);
GFP_KERNEL);
if (!syscon) if (!syscon)
return -ENOMEM; return -ENOMEM;
syscon->base = of_iomap(np, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!syscon->base) if (!res)
return -EADDRNOTAVAIL; return -ENOENT;
ret = of_address_to_resource(np, 0, &res); syscon->base = devm_ioremap(dev, res->start, resource_size(res));
if (ret) if (!syscon->base)
return ret; return -ENOMEM;
syscon_regmap_config.max_register = res.end - res.start - 3; syscon_regmap_config.max_register = res->end - res->start - 3;
syscon->regmap = devm_regmap_init_mmio(dev, syscon->base, syscon->regmap = devm_regmap_init_mmio(dev, syscon->base,
&syscon_regmap_config); &syscon_regmap_config);
if (IS_ERR(syscon->regmap)) { if (IS_ERR(syscon->regmap)) {
...@@ -130,22 +152,15 @@ static int syscon_probe(struct platform_device *pdev) ...@@ -130,22 +152,15 @@ static int syscon_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, syscon); platform_set_drvdata(pdev, syscon);
dev_info(dev, "syscon regmap start 0x%x end 0x%x registered\n", dev_info(dev, "regmap 0x%x-0x%x registered\n", res->start, res->end);
res.start, res.end);
return 0; return 0;
} }
static int syscon_remove(struct platform_device *pdev) static const struct platform_device_id syscon_ids[] = {
{ { "syscon", },
struct syscon *syscon; { }
};
syscon = platform_get_drvdata(pdev);
iounmap(syscon->base);
platform_set_drvdata(pdev, NULL);
return 0;
}
static struct platform_driver syscon_driver = { static struct platform_driver syscon_driver = {
.driver = { .driver = {
...@@ -154,7 +169,7 @@ static struct platform_driver syscon_driver = { ...@@ -154,7 +169,7 @@ static struct platform_driver syscon_driver = {
.of_match_table = of_syscon_match, .of_match_table = of_syscon_match,
}, },
.probe = syscon_probe, .probe = syscon_probe,
.remove = syscon_remove, .id_table = syscon_ids,
}; };
static int __init syscon_init(void) static int __init syscon_init(void)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
extern struct regmap *syscon_node_to_regmap(struct device_node *np); extern struct regmap *syscon_node_to_regmap(struct device_node *np);
extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s); extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s);
extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s);
extern struct regmap *syscon_regmap_lookup_by_phandle( extern struct regmap *syscon_regmap_lookup_by_phandle(
struct device_node *np, struct device_node *np,
const char *property); const char *property);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment