Commit 0254a8f4 authored by Philipp Zabel's avatar Philipp Zabel Committed by Samuel Ortiz

mfd: convert PASIC3 to use MFD core

This patch makes htc-pasic3 register the DS1WM and LED cell drivers
through the MFD core infrastructure instead of allocating the platform
devices manually. It also calculates the bus_shift parameter from the
memory resource size.
Signed-off-by: default avatarPhilipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@openedhand.com>
parent a23a1757
...@@ -52,6 +52,7 @@ config HTC_EGPIO ...@@ -52,6 +52,7 @@ config HTC_EGPIO
config HTC_PASIC3 config HTC_PASIC3
tristate "HTC PASIC3 LED/DS1WM chip support" tristate "HTC PASIC3 LED/DS1WM chip support"
select MFD_CORE
help help
This core driver provides register access for the LED/DS1WM This core driver provides register access for the LED/DS1WM
chips labeled "AIC2" and "AIC3", found on HTC Blueangel and chips labeled "AIC2" and "AIC3", found on HTC Blueangel and
......
...@@ -12,18 +12,17 @@ ...@@ -12,18 +12,17 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/ds1wm.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/mfd/core.h>
#include <linux/mfd/ds1wm.h>
#include <linux/mfd/htc-pasic3.h> #include <linux/mfd/htc-pasic3.h>
struct pasic3_data { struct pasic3_data {
void __iomem *mapping; void __iomem *mapping;
unsigned int bus_shift; unsigned int bus_shift;
struct platform_device *ds1wm_pdev;
struct platform_device *led_pdev;
}; };
#define REG_ADDR 5 #define REG_ADDR 5
...@@ -65,46 +64,15 @@ EXPORT_SYMBOL(pasic3_read_register); /* for leds-pasic3 */ ...@@ -65,46 +64,15 @@ EXPORT_SYMBOL(pasic3_read_register); /* for leds-pasic3 */
* LEDs * LEDs
*/ */
static int led_device_add(struct device *pasic3_dev, static struct mfd_cell led_cell __initdata = {
const struct pasic3_leds_machinfo *pdata) .name = "leds-pasic3",
{ };
struct pasic3_data *asic = pasic3_dev->driver_data;
struct platform_device *pdev;
int ret;
pdev = platform_device_alloc("pasic3-led", -1);
if (!pdev) {
dev_dbg(pasic3_dev, "failed to allocate LED platform device\n");
return -ENOMEM;
}
ret = platform_device_add_data(pdev, pdata,
sizeof(struct pasic3_leds_machinfo));
if (ret < 0) {
dev_dbg(pasic3_dev, "failed to add LED platform data\n");
goto exit_pdev_put;
}
pdev->dev.parent = pasic3_dev;
ret = platform_device_add(pdev);
if (ret < 0) {
dev_dbg(pasic3_dev, "failed to add LED platform device\n");
goto exit_pdev_put;
}
asic->led_pdev = pdev;
return 0;
exit_pdev_put:
platform_device_put(pdev);
return ret;
}
/* /*
* DS1WM * DS1WM
*/ */
static void ds1wm_enable(struct platform_device *pdev) static int ds1wm_enable(struct platform_device *pdev)
{ {
struct device *dev = pdev->dev.parent; struct device *dev = pdev->dev.parent;
int c; int c;
...@@ -113,9 +81,10 @@ static void ds1wm_enable(struct platform_device *pdev) ...@@ -113,9 +81,10 @@ static void ds1wm_enable(struct platform_device *pdev)
pasic3_write_register(dev, 0x28, c & 0x7f); pasic3_write_register(dev, 0x28, c & 0x7f);
dev_dbg(dev, "DS1WM OWM_EN low (active) %02x\n", c & 0x7f); dev_dbg(dev, "DS1WM OWM_EN low (active) %02x\n", c & 0x7f);
return 0;
} }
static void ds1wm_disable(struct platform_device *pdev) static int ds1wm_disable(struct platform_device *pdev)
{ {
struct device *dev = pdev->dev.parent; struct device *dev = pdev->dev.parent;
int c; int c;
...@@ -124,56 +93,33 @@ static void ds1wm_disable(struct platform_device *pdev) ...@@ -124,56 +93,33 @@ static void ds1wm_disable(struct platform_device *pdev)
pasic3_write_register(dev, 0x28, c | 0x80); pasic3_write_register(dev, 0x28, c | 0x80);
dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02x\n", c | 0x80); dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02x\n", c | 0x80);
return 0;
} }
static struct ds1wm_platform_data ds1wm_pdata = { static struct ds1wm_driver_data ds1wm_pdata = {
.bus_shift = 2, .active_high = 0,
.enable = ds1wm_enable,
.disable = ds1wm_disable,
}; };
static int ds1wm_device_add(struct platform_device *pasic3_pdev, int bus_shift) static struct resource ds1wm_resources[] __initdata = {
{ [0] = {
struct device *pasic3_dev = &pasic3_pdev->dev; .start = 0,
struct pasic3_data *asic = pasic3_dev->driver_data; .flags = IORESOURCE_MEM,
struct platform_device *pdev; },
int ret; [1] = {
.start = 0,
pdev = platform_device_alloc("ds1wm", -1); .end = 0,
if (!pdev) { .flags = IORESOURCE_IRQ,
dev_dbg(pasic3_dev, "failed to allocate DS1WM platform device\n"); },
return -ENOMEM; };
}
ret = platform_device_add_resources(pdev, pasic3_pdev->resource,
pasic3_pdev->num_resources);
if (ret < 0) {
dev_dbg(pasic3_dev, "failed to add DS1WM resources\n");
goto exit_pdev_put;
}
ds1wm_pdata.bus_shift = asic->bus_shift;
ret = platform_device_add_data(pdev, &ds1wm_pdata,
sizeof(struct ds1wm_platform_data));
if (ret < 0) {
dev_dbg(pasic3_dev, "failed to add DS1WM platform data\n");
goto exit_pdev_put;
}
pdev->dev.parent = pasic3_dev;
ret = platform_device_add(pdev);
if (ret < 0) {
dev_dbg(pasic3_dev, "failed to add DS1WM platform device\n");
goto exit_pdev_put;
}
asic->ds1wm_pdev = pdev;
return 0;
exit_pdev_put: static struct mfd_cell ds1wm_cell __initdata = {
platform_device_put(pdev); .name = "ds1wm",
return ret; .enable = ds1wm_enable,
} .disable = ds1wm_disable,
.driver_data = &ds1wm_pdata,
.num_resources = 2,
.resources = ds1wm_resources,
};
static int __init pasic3_probe(struct platform_device *pdev) static int __init pasic3_probe(struct platform_device *pdev)
{ {
...@@ -182,12 +128,27 @@ static int __init pasic3_probe(struct platform_device *pdev) ...@@ -182,12 +128,27 @@ static int __init pasic3_probe(struct platform_device *pdev)
struct pasic3_data *asic; struct pasic3_data *asic;
struct resource *r; struct resource *r;
int ret; int ret;
int irq = 0;
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (r) {
ds1wm_resources[1].flags = IORESOURCE_IRQ | (r->flags &
(IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE));
irq = r->start;
}
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (r) {
ds1wm_resources[1].flags = IORESOURCE_IRQ | (r->flags &
(IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE));
irq = r->start;
}
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) if (!r)
return -ENXIO; return -ENXIO;
if (!request_mem_region(r->start, r->end - r->start + 1, "pasic3")) if (!request_mem_region(r->start, resource_size(r), "pasic3"))
return -EBUSY; return -EBUSY;
asic = kzalloc(sizeof(struct pasic3_data), GFP_KERNEL); asic = kzalloc(sizeof(struct pasic3_data), GFP_KERNEL);
...@@ -196,24 +157,29 @@ static int __init pasic3_probe(struct platform_device *pdev) ...@@ -196,24 +157,29 @@ static int __init pasic3_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, asic); platform_set_drvdata(pdev, asic);
if (pdata && pdata->bus_shift) asic->mapping = ioremap(r->start, resource_size(r));
asic->bus_shift = pdata->bus_shift;
else
asic->bus_shift = 2;
asic->mapping = ioremap(r->start, r->end - r->start + 1);
if (!asic->mapping) { if (!asic->mapping) {
dev_err(dev, "couldn't ioremap PASIC3\n"); dev_err(dev, "couldn't ioremap PASIC3\n");
kfree(asic); kfree(asic);
return -ENOMEM; return -ENOMEM;
} }
ret = ds1wm_device_add(pdev, asic->bus_shift); /* calculate bus shift from mem resource */
asic->bus_shift = (resource_size(r) - 5) >> 3;
/* the first 5 PASIC3 registers control the DS1WM */
ds1wm_resources[0].end = (5 << asic->bus_shift) - 1;
ds1wm_cell.platform_data = &ds1wm_cell;
ds1wm_cell.data_size = sizeof(ds1wm_cell);
ret = mfd_add_devices(&pdev->dev, pdev->id, &ds1wm_cell, 1, r, irq);
if (ret < 0) if (ret < 0)
dev_warn(dev, "failed to register DS1WM\n"); dev_warn(dev, "failed to register DS1WM\n");
if (pdata->led_pdata) { if (pdata->led_pdata) {
ret = led_device_add(dev, pdata->led_pdata); led_cell.driver_data = pdata->led_pdata;
led_cell.platform_data = &led_cell;
led_cell.data_size = sizeof(ds1wm_cell);
ret = mfd_add_devices(&pdev->dev, pdev->id, &led_cell, 1, r, 0);
if (ret < 0) if (ret < 0)
dev_warn(dev, "failed to register LED device\n"); dev_warn(dev, "failed to register LED device\n");
} }
...@@ -226,14 +192,11 @@ static int pasic3_remove(struct platform_device *pdev) ...@@ -226,14 +192,11 @@ static int pasic3_remove(struct platform_device *pdev)
struct pasic3_data *asic = platform_get_drvdata(pdev); struct pasic3_data *asic = platform_get_drvdata(pdev);
struct resource *r; struct resource *r;
if (asic->led_pdev) mfd_remove_devices(&pdev->dev);
platform_device_unregister(asic->led_pdev);
if (asic->ds1wm_pdev)
platform_device_unregister(asic->ds1wm_pdev);
iounmap(asic->mapping); iounmap(asic->mapping);
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(r->start, r->end - r->start + 1); release_mem_region(r->start, resource_size(r));
kfree(asic); kfree(asic);
return 0; return 0;
} }
......
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