Commit 5a47c0fb authored by Lee Jones's avatar Lee Jones

mfd: mfd-core: Remove usage counting for .{en,dis}able() call-backs

The MFD implementation for reference counting was complex and unnecessary.
There was only one bona fide user which has now been converted to handle
the process in a different way. Any future resource protection, shared
enablement functions should be handed by the parent device, rather than
through the MFD subsystem API.
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: default avatarMark Brown <broonie@kernel.org>
parent 504c3fad
...@@ -26,53 +26,31 @@ static struct device_type mfd_dev_type = { ...@@ -26,53 +26,31 @@ static struct device_type mfd_dev_type = {
int mfd_cell_enable(struct platform_device *pdev) int mfd_cell_enable(struct platform_device *pdev)
{ {
const struct mfd_cell *cell = mfd_get_cell(pdev); const struct mfd_cell *cell = mfd_get_cell(pdev);
int err = 0;
if (!cell->enable) { if (!cell->enable) {
dev_dbg(&pdev->dev, "No .enable() call-back registered\n"); dev_dbg(&pdev->dev, "No .enable() call-back registered\n");
return 0; return 0;
} }
/* only call enable hook if the cell wasn't previously enabled */ return cell->enable(pdev);
if (atomic_inc_return(cell->usage_count) == 1)
err = cell->enable(pdev);
/* if the enable hook failed, decrement counter to allow retries */
if (err)
atomic_dec(cell->usage_count);
return err;
} }
EXPORT_SYMBOL(mfd_cell_enable); EXPORT_SYMBOL(mfd_cell_enable);
int mfd_cell_disable(struct platform_device *pdev) int mfd_cell_disable(struct platform_device *pdev)
{ {
const struct mfd_cell *cell = mfd_get_cell(pdev); const struct mfd_cell *cell = mfd_get_cell(pdev);
int err = 0;
if (!cell->disable) { if (!cell->disable) {
dev_dbg(&pdev->dev, "No .disable() call-back registered\n"); dev_dbg(&pdev->dev, "No .disable() call-back registered\n");
return 0; return 0;
} }
/* only disable if no other clients are using it */ return cell->disable(pdev);
if (atomic_dec_return(cell->usage_count) == 0)
err = cell->disable(pdev);
/* if the disable hook failed, increment to allow retries */
if (err)
atomic_inc(cell->usage_count);
/* sanity check; did someone call disable too many times? */
WARN_ON(atomic_read(cell->usage_count) < 0);
return err;
} }
EXPORT_SYMBOL(mfd_cell_disable); EXPORT_SYMBOL(mfd_cell_disable);
static int mfd_platform_add_cell(struct platform_device *pdev, static int mfd_platform_add_cell(struct platform_device *pdev,
const struct mfd_cell *cell, const struct mfd_cell *cell)
atomic_t *usage_count)
{ {
if (!cell) if (!cell)
return 0; return 0;
...@@ -81,7 +59,6 @@ static int mfd_platform_add_cell(struct platform_device *pdev, ...@@ -81,7 +59,6 @@ static int mfd_platform_add_cell(struct platform_device *pdev,
if (!pdev->mfd_cell) if (!pdev->mfd_cell)
return -ENOMEM; return -ENOMEM;
pdev->mfd_cell->usage_count = usage_count;
return 0; return 0;
} }
...@@ -144,7 +121,7 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell, ...@@ -144,7 +121,7 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
#endif #endif
static int mfd_add_device(struct device *parent, int id, static int mfd_add_device(struct device *parent, int id,
const struct mfd_cell *cell, atomic_t *usage_count, const struct mfd_cell *cell,
struct resource *mem_base, struct resource *mem_base,
int irq_base, struct irq_domain *domain) int irq_base, struct irq_domain *domain)
{ {
...@@ -206,7 +183,7 @@ static int mfd_add_device(struct device *parent, int id, ...@@ -206,7 +183,7 @@ static int mfd_add_device(struct device *parent, int id,
goto fail_alias; goto fail_alias;
} }
ret = mfd_platform_add_cell(pdev, cell, usage_count); ret = mfd_platform_add_cell(pdev, cell);
if (ret) if (ret)
goto fail_alias; goto fail_alias;
...@@ -296,16 +273,9 @@ int mfd_add_devices(struct device *parent, int id, ...@@ -296,16 +273,9 @@ int mfd_add_devices(struct device *parent, int id,
{ {
int i; int i;
int ret; int ret;
atomic_t *cnts;
/* initialize reference counting for all cells */
cnts = kcalloc(n_devs, sizeof(*cnts), GFP_KERNEL);
if (!cnts)
return -ENOMEM;
for (i = 0; i < n_devs; i++) { for (i = 0; i < n_devs; i++) {
atomic_set(&cnts[i], 0); ret = mfd_add_device(parent, id, cells + i, mem_base,
ret = mfd_add_device(parent, id, cells + i, cnts + i, mem_base,
irq_base, domain); irq_base, domain);
if (ret) if (ret)
goto fail; goto fail;
...@@ -316,17 +286,15 @@ int mfd_add_devices(struct device *parent, int id, ...@@ -316,17 +286,15 @@ int mfd_add_devices(struct device *parent, int id,
fail: fail:
if (i) if (i)
mfd_remove_devices(parent); mfd_remove_devices(parent);
else
kfree(cnts);
return ret; return ret;
} }
EXPORT_SYMBOL(mfd_add_devices); EXPORT_SYMBOL(mfd_add_devices);
static int mfd_remove_devices_fn(struct device *dev, void *c) static int mfd_remove_devices_fn(struct device *dev, void *data)
{ {
struct platform_device *pdev; struct platform_device *pdev;
const struct mfd_cell *cell; const struct mfd_cell *cell;
atomic_t **usage_count = c;
if (dev->type != &mfd_dev_type) if (dev->type != &mfd_dev_type)
return 0; return 0;
...@@ -337,20 +305,13 @@ static int mfd_remove_devices_fn(struct device *dev, void *c) ...@@ -337,20 +305,13 @@ static int mfd_remove_devices_fn(struct device *dev, void *c)
regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies, regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
cell->num_parent_supplies); cell->num_parent_supplies);
/* find the base address of usage_count pointers (for freeing) */
if (!*usage_count || (cell->usage_count < *usage_count))
*usage_count = cell->usage_count;
platform_device_unregister(pdev); platform_device_unregister(pdev);
return 0; return 0;
} }
void mfd_remove_devices(struct device *parent) void mfd_remove_devices(struct device *parent)
{ {
atomic_t *cnts = NULL; device_for_each_child_reverse(parent, NULL, mfd_remove_devices_fn);
device_for_each_child_reverse(parent, &cnts, mfd_remove_devices_fn);
kfree(cnts);
} }
EXPORT_SYMBOL(mfd_remove_devices); EXPORT_SYMBOL(mfd_remove_devices);
......
...@@ -59,8 +59,6 @@ struct mfd_cell { ...@@ -59,8 +59,6 @@ struct mfd_cell {
const char *name; const char *name;
int id; int id;
/* refcounting for multiple drivers to use a single cell */
atomic_t *usage_count;
int (*enable)(struct platform_device *dev); int (*enable)(struct platform_device *dev);
int (*disable)(struct platform_device *dev); int (*disable)(struct platform_device *dev);
......
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