2011-04-13 14:55:56

by Haojian Zhuang

[permalink] [raw]
Subject: 1. Replace mfd_data with platform_data for 88pm860x since mfd tree is upgraded.

-


2011-04-13 14:55:58

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x

Measuring point on touchscreen with IRQ mode can only monitor pen-down
event. If finger is moving on touchscreen, it can't be monitored by
IRQ pen-down event. So switch to polling mode after pen-down event.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
---
drivers/input/touchscreen/88pm860x-ts.c | 82 +++++++++++++++++++++++-------
1 files changed, 63 insertions(+), 19 deletions(-)

diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c
index b3aebc2..fe12f61 100644
--- a/drivers/input/touchscreen/88pm860x-ts.c
+++ b/drivers/input/touchscreen/88pm860x-ts.c
@@ -12,13 +12,25 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#include <linux/input.h>
#include <linux/mfd/88pm860x.h>
-#include <linux/slab.h>

#define MEAS_LEN (8)
#define ACCURATE_BIT (12)

+/*
+ * While 32KHz hardware timer is used for scheduler, we always assign HZ
+ * to 128. It means that 1 tick costs 7.8msec.
+ */
+#define MEASURE_INTERVAL_MS (7)
+
+/* debounce register */
+#define DEBOUNCE (0x0A)
+
+#define PD_DEBOUNCE_0MSEC (0)
+#define PD_DEBOUNCE_MASK (3)
+
/* touch register */
#define MEAS_EN3 (0x52)

@@ -39,22 +51,27 @@
#define MEAS_TSIZ2_EN (1 << 7)

struct pm860x_touch {
- struct input_dev *idev;
- struct i2c_client *i2c;
- struct pm860x_chip *chip;
- int irq;
- int res_x; /* resistor of Xplate */
+ struct input_dev *idev;
+ struct i2c_client *i2c;
+ struct pm860x_chip *chip;
+ struct delayed_work poll_work;
+ struct mutex lock;
+
+ int irq;
+ int res_x; /* resistor of Xplate */
};

-static irqreturn_t pm860x_touch_handler(int irq, void *data)
+static void pm860x_poll_work(struct work_struct *work)
{
- struct pm860x_touch *touch = data;
+ struct pm860x_touch *touch = container_of(work, struct pm860x_touch,
+ poll_work.work);
struct pm860x_chip *chip = touch->chip;
+ int x, y, z1, z2, rt = 0;
+ int ret, pen_down, interval;
unsigned char buf[MEAS_LEN];
- int x, y, pen_down;
- int z1, z2, rt = 0;
- int ret;
+ struct timeval start, end;

+ do_gettimeofday(&start);
ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
if (ret < 0)
goto out;
@@ -77,30 +94,54 @@ static irqreturn_t pm860x_touch_handler(int irq, void *data)
input_report_abs(touch->idev, ABS_PRESSURE, rt);
input_report_key(touch->idev, BTN_TOUCH, 1);
dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
+
+ do_gettimeofday(&end);
+ interval = (end.tv_sec - start.tv_sec) * 1000000 +
+ (end.tv_usec - start.tv_usec) / 1000;
+ interval = (interval < MEASURE_INTERVAL_MS)
+ ? (MEASURE_INTERVAL_MS - interval) : 0;
+ schedule_delayed_work(&touch->poll_work,
+ msecs_to_jiffies(interval));
} else {
input_report_abs(touch->idev, ABS_PRESSURE, 0);
input_report_key(touch->idev, BTN_TOUCH, 0);
dev_dbg(chip->dev, "pen release\n");
+ mutex_unlock(&touch->lock);
}
input_sync(touch->idev);

out:
+ return;
+}
+
+static irqreturn_t pm860x_touch_handler(int irq, void *data)
+{
+ struct pm860x_touch *touch = data;
+ int ret;
+
+ ret = pm860x_reg_read(touch->i2c, PM8607_STATUS_1);
+ dev_dbg(touch->chip->dev, "pen status:%d\n", (ret & PM8607_STATUS_PEN)
+ ? 1 : 0);
+ if ((ret & PM8607_STATUS_PEN) == 0)
+ return IRQ_HANDLED;
+
+ mutex_lock(&touch->lock);
+ pm860x_poll_work(&touch->poll_work.work);
return IRQ_HANDLED;
}

static int pm860x_touch_open(struct input_dev *dev)
{
struct pm860x_touch *touch = input_get_drvdata(dev);
- int data, ret;
+ int data;

+ /* set debounce time with 0ms */
+ pm860x_set_bits(touch->i2c, DEBOUNCE, PD_DEBOUNCE_MASK,
+ PD_DEBOUNCE_0MSEC);
data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
| MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
- ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
- if (ret < 0)
- goto out;
+ pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
return 0;
-out:
- return ret;
}

static void pm860x_touch_close(struct input_dev *dev)
@@ -152,16 +193,17 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev)
}

touch->idev->name = "88pm860x-touch";
- touch->idev->phys = "88pm860x/input0";
+ touch->idev->phys = "88pm860x/input1";
touch->idev->id.bustype = BUS_I2C;
touch->idev->dev.parent = &pdev->dev;
touch->idev->open = pm860x_touch_open;
touch->idev->close = pm860x_touch_close;
touch->chip = chip;
touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
- touch->irq = irq + chip->irq_base;
+ touch->irq = irq;
touch->res_x = pdata->res_x;
input_set_drvdata(touch->idev, touch);
+ mutex_init(&touch->lock);

ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
IRQF_ONESHOT, "touch", touch);
@@ -188,6 +230,7 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev)
}

platform_set_drvdata(pdev, touch);
+ INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
return 0;
out_rg:
free_irq(touch->irq, touch);
@@ -202,6 +245,7 @@ static int __devexit pm860x_touch_remove(struct platform_device *pdev)
{
struct pm860x_touch *touch = platform_get_drvdata(pdev);

+ flush_scheduled_work();
input_unregister_device(touch->idev);
free_irq(touch->irq, touch);
platform_set_drvdata(pdev, NULL);
--
1.5.6.5

2011-04-13 14:56:13

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 08/13] mfd: use platform_data in max8925

Use platform_data to pass parameters to client driver.

Signed-off-by: Haojian Zhuang <[email protected]>
---
drivers/mfd/max8925-core.c | 467 +++++++++++++++++++++++++------------------
include/linux/mfd/max8925.h | 9 +-
2 files changed, 274 insertions(+), 202 deletions(-)

diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
index 58cc5fd..044801c 100644
--- a/drivers/mfd/max8925-core.c
+++ b/drivers/mfd/max8925-core.c
@@ -17,169 +17,141 @@
#include <linux/platform_device.h>
#include <linux/mfd/core.h>
#include <linux/mfd/max8925.h>
+#include <linux/regulator/machine.h>

-static struct resource backlight_resources[] = {
- {
- .name = "max8925-backlight",
- .start = MAX8925_WLED_MODE_CNTL,
- .end = MAX8925_WLED_CNTL,
- .flags = IORESOURCE_IO,
- },
+static struct resource bk_resources[] __devinitdata = {
+ {0, 0, "max8925-backlight", IORESOURCE_IO,},
};

-static struct mfd_cell backlight_devs[] = {
- {
- .name = "max8925-backlight",
- .num_resources = 1,
- .resources = &backlight_resources[0],
- .id = -1,
- },
+static struct resource touch_resources[] __devinitdata = {
+ {MAX8925_IRQ_TSC_STICK, MAX8925_IRQ_TSC_STICK, "touch stick",
+ IORESOURCE_IRQ,},
+ {MAX8925_IRQ_TSC_NSTICK, MAX8925_IRQ_TSC_NSTICK, "touch nstick",
+ IORESOURCE_IRQ,},
};

-static struct resource touch_resources[] = {
- {
- .name = "max8925-tsc",
- .start = MAX8925_TSC_IRQ,
- .end = MAX8925_ADC_RES_END,
- .flags = IORESOURCE_IO,
- },
+static struct resource power_resources[] __devinitdata = {
+ {MAX8925_IRQ_VCHG_DC_OVP, MAX8925_IRQ_VCHG_DC_OVP, \
+ "dc overvoltage", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_DC_F, MAX8925_IRQ_VCHG_DC_F, \
+ "dc falling", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_DC_R, MAX8925_IRQ_VCHG_DC_R, \
+ "dc rising", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_USB_OVP, MAX8925_IRQ_VCHG_USB_OVP, \
+ "usb overvoltage", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_USB_F, MAX8925_IRQ_VCHG_USB_F, \
+ "usb falling", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_USB_R, MAX8925_IRQ_VCHG_USB_R, \
+ "usb rising", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_THM_OK_R, MAX8925_IRQ_VCHG_THM_OK_R, \
+ "bat temp valid", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_THM_OK_F, MAX8925_IRQ_VCHG_THM_OK_F, \
+ "bat temp invalid", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_SYSLOW_F, MAX8925_IRQ_VCHG_SYSLOW_F, \
+ "VSYSLOW falling", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_SYSLOW_R, MAX8925_IRQ_VCHG_SYSLOW_R, \
+ "VSYSLOW rising", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_RST, MAX8925_IRQ_VCHG_RST, \
+ "charger restart", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_DONE, MAX8925_IRQ_VCHG_DONE, \
+ "charger done", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_TOPOFF, MAX8925_IRQ_VCHG_TOPOFF, \
+ "charger topoff", IORESOURCE_IRQ,},
+ {MAX8925_IRQ_VCHG_TMR_FAULT, MAX8925_IRQ_VCHG_TMR_FAULT, \
+ "charger expire", IORESOURCE_IRQ,},
};

-static struct mfd_cell touch_devs[] = {
- {
- .name = "max8925-touch",
- .num_resources = 1,
- .resources = &touch_resources[0],
- .id = -1,
- },
+static struct resource rtc_resources[] __devinitdata = {
+ {MAX8925_IRQ_RTC_ALARM0, MAX8925_IRQ_RTC_ALARM0, "rtc-alarm0",
+ IORESOURCE_IRQ,},
+ {MAX8925_IRQ_RTC_ALARM1, MAX8925_IRQ_RTC_ALARM1, "rtc-alarm1",
+ IORESOURCE_IRQ,},
};

-static struct resource power_supply_resources[] = {
- {
- .name = "max8925-power",
- .start = MAX8925_CHG_IRQ1,
- .end = MAX8925_CHG_IRQ1_MASK,
- .flags = IORESOURCE_IO,
- },
+static struct resource onkey_resources[] __devinitdata = {
+ {MAX8925_IRQ_GPM_SW_R, MAX8925_IRQ_GPM_SW_R, "onkey R",
+ IORESOURCE_IRQ,},
+ {MAX8925_IRQ_GPM_SW_F, MAX8925_IRQ_GPM_SW_F, "onkey F",
+ IORESOURCE_IRQ,},
};

-static struct mfd_cell power_devs[] = {
- {
- .name = "max8925-power",
- .num_resources = 1,
- .resources = &power_supply_resources[0],
- .id = -1,
- },
+static struct resource regulator_resources[] __devinitdata = {
+ {MAX8925_ID_SD1, MAX8925_ID_SD1, "SD1", IORESOURCE_IO,},
+ {MAX8925_ID_SD2, MAX8925_ID_SD2, "SD2", IORESOURCE_IO,},
+ {MAX8925_ID_SD3, MAX8925_ID_SD3, "SD3", IORESOURCE_IO,},
+ {MAX8925_ID_LDO1, MAX8925_ID_LDO1, "LDO01", IORESOURCE_IO,},
+ {MAX8925_ID_LDO2, MAX8925_ID_LDO2, "LDO02", IORESOURCE_IO,},
+ {MAX8925_ID_LDO3, MAX8925_ID_LDO3, "LDO03", IORESOURCE_IO,},
+ {MAX8925_ID_LDO4, MAX8925_ID_LDO4, "LDO04", IORESOURCE_IO,},
+ {MAX8925_ID_LDO5, MAX8925_ID_LDO5, "LDO05", IORESOURCE_IO,},
+ {MAX8925_ID_LDO6, MAX8925_ID_LDO6, "LDO06", IORESOURCE_IO,},
+ {MAX8925_ID_LDO7, MAX8925_ID_LDO7, "LDO07", IORESOURCE_IO,},
+ {MAX8925_ID_LDO8, MAX8925_ID_LDO8, "LDO08", IORESOURCE_IO,},
+ {MAX8925_ID_LDO9, MAX8925_ID_LDO9, "LDO09", IORESOURCE_IO,},
+ {MAX8925_ID_LDO10, MAX8925_ID_LDO10, "LDO10", IORESOURCE_IO,},
+ {MAX8925_ID_LDO11, MAX8925_ID_LDO11, "LDO11", IORESOURCE_IO,},
+ {MAX8925_ID_LDO12, MAX8925_ID_LDO12, "LDO12", IORESOURCE_IO,},
+ {MAX8925_ID_LDO13, MAX8925_ID_LDO13, "LDO13", IORESOURCE_IO,},
+ {MAX8925_ID_LDO14, MAX8925_ID_LDO14, "LDO14", IORESOURCE_IO,},
+ {MAX8925_ID_LDO15, MAX8925_ID_LDO15, "LDO15", IORESOURCE_IO,},
+ {MAX8925_ID_LDO16, MAX8925_ID_LDO16, "LDO16", IORESOURCE_IO,},
+ {MAX8925_ID_LDO17, MAX8925_ID_LDO17, "LDO17", IORESOURCE_IO,},
+ {MAX8925_ID_LDO18, MAX8925_ID_LDO18, "LDO18", IORESOURCE_IO,},
+ {MAX8925_ID_LDO19, MAX8925_ID_LDO19, "LDO19", IORESOURCE_IO,},
+ {MAX8925_ID_LDO20, MAX8925_ID_LDO20, "LDO20", IORESOURCE_IO,},
};

-static struct resource rtc_resources[] = {
- {
- .name = "max8925-rtc",
- .start = MAX8925_RTC_IRQ,
- .end = MAX8925_RTC_IRQ_MASK,
- .flags = IORESOURCE_IO,
- },
+static struct mfd_cell bk_devs[] = {
+ {"max8925-backlight", -1,},
};

-static struct mfd_cell rtc_devs[] = {
- {
- .name = "max8925-rtc",
- .num_resources = 1,
- .resources = &rtc_resources[0],
- .id = -1,
- },
+static struct mfd_cell touch_devs[] = {
+ {"max8925-touch", -1,},
};

-static struct resource onkey_resources[] = {
- {
- .name = "max8925-onkey",
- .start = MAX8925_IRQ_GPM_SW_R,
- .end = MAX8925_IRQ_GPM_SW_R,
- .flags = IORESOURCE_IRQ,
- }, {
- .name = "max8925-onkey",
- .start = MAX8925_IRQ_GPM_SW_F,
- .end = MAX8925_IRQ_GPM_SW_F,
- .flags = IORESOURCE_IRQ,
- },
+static struct mfd_cell power_devs[] = {
+ {"max8925-power", -1,},
};

-static struct mfd_cell onkey_devs[] = {
- {
- .name = "max8925-onkey",
- .num_resources = 2,
- .resources = &onkey_resources[0],
- .id = -1,
- },
+static struct mfd_cell rtc_devs[] = {
+ {"max8925-rtc", -1,},
};

-#define MAX8925_REG_RESOURCE(_start, _end) \
-{ \
- .start = MAX8925_##_start, \
- .end = MAX8925_##_end, \
- .flags = IORESOURCE_IO, \
-}
-
-static struct resource regulator_resources[] = {
- MAX8925_REG_RESOURCE(SDCTL1, SDCTL1),
- MAX8925_REG_RESOURCE(SDCTL2, SDCTL2),
- MAX8925_REG_RESOURCE(SDCTL3, SDCTL3),
- MAX8925_REG_RESOURCE(LDOCTL1, LDOCTL1),
- MAX8925_REG_RESOURCE(LDOCTL2, LDOCTL2),
- MAX8925_REG_RESOURCE(LDOCTL3, LDOCTL3),
- MAX8925_REG_RESOURCE(LDOCTL4, LDOCTL4),
- MAX8925_REG_RESOURCE(LDOCTL5, LDOCTL5),
- MAX8925_REG_RESOURCE(LDOCTL6, LDOCTL6),
- MAX8925_REG_RESOURCE(LDOCTL7, LDOCTL7),
- MAX8925_REG_RESOURCE(LDOCTL8, LDOCTL8),
- MAX8925_REG_RESOURCE(LDOCTL9, LDOCTL9),
- MAX8925_REG_RESOURCE(LDOCTL10, LDOCTL10),
- MAX8925_REG_RESOURCE(LDOCTL11, LDOCTL11),
- MAX8925_REG_RESOURCE(LDOCTL12, LDOCTL12),
- MAX8925_REG_RESOURCE(LDOCTL13, LDOCTL13),
- MAX8925_REG_RESOURCE(LDOCTL14, LDOCTL14),
- MAX8925_REG_RESOURCE(LDOCTL15, LDOCTL15),
- MAX8925_REG_RESOURCE(LDOCTL16, LDOCTL16),
- MAX8925_REG_RESOURCE(LDOCTL17, LDOCTL17),
- MAX8925_REG_RESOURCE(LDOCTL18, LDOCTL18),
- MAX8925_REG_RESOURCE(LDOCTL19, LDOCTL19),
- MAX8925_REG_RESOURCE(LDOCTL20, LDOCTL20),
+static struct mfd_cell onkey_devs[] = {
+ {"max8925-onkey", -1,},
};

-#define MAX8925_REG_DEVS(_id) \
-{ \
- .name = "max8925-regulator", \
- .num_resources = 1, \
- .resources = &regulator_resources[MAX8925_ID_##_id], \
- .id = MAX8925_ID_##_id, \
-}
-
static struct mfd_cell regulator_devs[] = {
- MAX8925_REG_DEVS(SD1),
- MAX8925_REG_DEVS(SD2),
- MAX8925_REG_DEVS(SD3),
- MAX8925_REG_DEVS(LDO1),
- MAX8925_REG_DEVS(LDO2),
- MAX8925_REG_DEVS(LDO3),
- MAX8925_REG_DEVS(LDO4),
- MAX8925_REG_DEVS(LDO5),
- MAX8925_REG_DEVS(LDO6),
- MAX8925_REG_DEVS(LDO7),
- MAX8925_REG_DEVS(LDO8),
- MAX8925_REG_DEVS(LDO9),
- MAX8925_REG_DEVS(LDO10),
- MAX8925_REG_DEVS(LDO11),
- MAX8925_REG_DEVS(LDO12),
- MAX8925_REG_DEVS(LDO13),
- MAX8925_REG_DEVS(LDO14),
- MAX8925_REG_DEVS(LDO15),
- MAX8925_REG_DEVS(LDO16),
- MAX8925_REG_DEVS(LDO17),
- MAX8925_REG_DEVS(LDO18),
- MAX8925_REG_DEVS(LDO19),
- MAX8925_REG_DEVS(LDO20),
+ {"max8925-regulator", 0,},
+ {"max8925-regulator", 1,},
+ {"max8925-regulator", 2,},
+ {"max8925-regulator", 3,},
+ {"max8925-regulator", 4,},
+ {"max8925-regulator", 5,},
+ {"max8925-regulator", 6,},
+ {"max8925-regulator", 7,},
+ {"max8925-regulator", 8,},
+ {"max8925-regulator", 9,},
+ {"max8925-regulator", 10,},
+ {"max8925-regulator", 11,},
+ {"max8925-regulator", 12,},
+ {"max8925-regulator", 13,},
+ {"max8925-regulator", 14,},
+ {"max8925-regulator", 15,},
+ {"max8925-regulator", 16,},
+ {"max8925-regulator", 17,},
+ {"max8925-regulator", 18,},
+ {"max8925-regulator", 19,},
+ {"max8925-regulator", 20,},
+ {"max8925-regulator", 21,},
+ {"max8925-regulator", 22,},
};

+static struct max8925_backlight_pdata bk_pdata;
+static struct max8925_touch_pdata touch_pdata;
+static struct max8925_power_pdata power_pdata;
+static struct regulator_init_data regulator_pdata[ARRAY_SIZE(regulator_devs)];
+
enum {
FLAGS_ADC = 1, /* register in ADC component */
FLAGS_RTC, /* register in RTC component */
@@ -588,6 +560,159 @@ tsc_irq:
return 0;
}

+static void __devinit device_bk_init(struct max8925_chip *chip,
+ struct i2c_client *i2c,
+ struct max8925_platform_data *pdata)
+{
+ int ret;
+
+ if ((pdata == NULL) || (pdata->backlight == NULL))
+ return;
+
+ memcpy(&bk_pdata, pdata->backlight,
+ sizeof(struct max8925_backlight_pdata));
+ bk_devs[0].platform_data = &bk_pdata;
+ bk_devs[0].pdata_size = sizeof(bk_pdata);
+
+ bk_devs[0].num_resources = 1;
+ bk_devs[0].resources = &bk_resources[0];
+ ret = mfd_add_devices(chip->dev, 0, &bk_devs[0], 1,
+ &bk_resources[0], 0);
+ if (ret < 0)
+ dev_err(chip->dev, "Failed to add backlight subdev\n");
+}
+
+static void __devinit device_rtc_init(struct max8925_chip *chip,
+ struct i2c_client *i2c,
+ struct max8925_platform_data *pdata)
+{
+ int ret;
+
+ rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources);
+ rtc_devs[0].resources = &rtc_resources[0];
+ ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], 1,
+ &rtc_resources[0], chip->irq_base);
+ if (ret < 0)
+ dev_err(chip->dev, "Failed to add rtc subdev\n");
+}
+
+static void __devinit device_touch_init(struct max8925_chip *chip,
+ struct i2c_client *i2c,
+ struct max8925_platform_data *pdata)
+{
+ int ret;
+
+ if ((pdata == NULL) || (pdata->touch == NULL))
+ return;
+
+ memcpy(&touch_pdata, pdata->touch,
+ sizeof(struct max8925_touch_pdata));
+ touch_devs[0].platform_data = &touch_pdata;
+ touch_devs[0].pdata_size = sizeof(touch_pdata);
+ touch_devs[0].num_resources = ARRAY_SIZE(touch_resources);
+ touch_devs[0].resources = &touch_resources[0];
+ ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
+ ARRAY_SIZE(touch_devs),
+ &touch_resources[0], chip->irq_base);
+ if (ret < 0)
+ dev_err(chip->dev, "Failed to add touch subdev\n");
+}
+
+static void __devinit device_power_init(struct max8925_chip *chip,
+ struct i2c_client *i2c,
+ struct max8925_platform_data *pdata)
+{
+ int ret;
+
+ if ((pdata == NULL) || (pdata->power == NULL))
+ return;
+
+ memcpy(&power_pdata, pdata->power,
+ sizeof(struct max8925_power_pdata));
+ power_devs[0].platform_data = &power_pdata;
+ power_devs[0].pdata_size = sizeof(power_pdata);
+ power_devs[0].num_resources = ARRAY_SIZE(power_resources);
+ power_devs[0].resources = &power_resources[0];
+ ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
+ ARRAY_SIZE(power_devs),
+ &power_resources[0], chip->irq_base);
+ if (ret < 0)
+ dev_err(chip->dev, "Failed to add power supply subdev\n");
+}
+
+static void __devinit device_onkey_init(struct max8925_chip *chip,
+ struct i2c_client *i2c,
+ struct max8925_platform_data *pdata)
+{
+ int ret;
+
+ onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources);
+ onkey_devs[0].resources = &onkey_resources[0];
+ ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
+ ARRAY_SIZE(onkey_devs),
+ &onkey_resources[0], chip->irq_base);
+ if (ret < 0)
+ dev_err(chip->dev, "Failed to add onkey subdev\n");
+}
+
+static void __devinit device_regulator_init(struct max8925_chip *chip,
+ struct i2c_client *i2c,
+ struct max8925_platform_data *pdata)
+{
+ struct regulator_init_data *initdata;
+ int ret, i, j;
+
+ if ((pdata == NULL) || (pdata->regulator == NULL))
+ return;
+
+ if (pdata->num_regulators > ARRAY_SIZE(regulator_devs))
+ pdata->num_regulators = ARRAY_SIZE(regulator_devs);
+
+ for (i = 0, j = -1; i < pdata->num_regulators; i++) {
+ initdata = &pdata->regulator[i];
+ if (strstr(initdata->constraints.name, "SD")) {
+ sscanf(initdata->constraints.name, "SD%d", &j);
+ /* SD1 ~ SD3 */
+ if ((j < 1) || (j > 3)) {
+ dev_err(chip->dev, "Failed to add constraint "
+ "(%s)\n", initdata->constraints.name);
+ goto out;
+ }
+ j = (j - 1) + MAX8925_ID_SD1;
+ }
+ if (strstr(initdata->constraints.name, "LDO")) {
+ sscanf(initdata->constraints.name, "LDO%d", &j);
+ /* LDO01 ~ LDO20 */
+ if ((j < 1) || (j > 20)) {
+ dev_err(chip->dev, "Failed to add constraint "
+ "(%s)\n", initdata->constraints.name);
+ goto out;
+ }
+ j = (j - 1) + MAX8925_ID_LDO1;
+ }
+ if (j == -1) {
+ dev_err(chip->dev, "Failed to add constraint (%s)\n",
+ initdata->constraints.name);
+ goto out;
+ }
+ memcpy(&regulator_pdata[i], &pdata->regulator[i],
+ sizeof(struct regulator_init_data));
+ regulator_devs[i].platform_data = &regulator_pdata[i];
+ regulator_devs[i].pdata_size = sizeof(regulator_pdata[i]);
+ regulator_devs[i].num_resources = 1;
+ regulator_devs[i].resources = &regulator_resources[j];
+
+ ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1,
+ &regulator_resources[j], 0);
+ if (ret < 0) {
+ dev_err(chip->dev, "Failed to add regulator subdev\n");
+ goto out;
+ }
+ }
+out:
+ return;
+}
+
int __devinit max8925_device_init(struct max8925_chip *chip,
struct max8925_platform_data *pdata)
{
@@ -604,75 +729,21 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
do {
ret = max8925_reg_read(chip->adc, MAX8925_TSC_IRQ);
} while (ret & MAX8925_NREF_OK);
- /* enaable ADC scheduler, interval is 1 second */
+ /* enable ADC scheduler, interval is 1 second */
max8925_set_bits(chip->adc, MAX8925_ADC_SCHED, 3, 2);
}

/* enable Momentary Power Loss */
max8925_set_bits(chip->rtc, MAX8925_MPL_CNTL, 1 << 4, 1 << 4);

- ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
- ARRAY_SIZE(rtc_devs),
- &rtc_resources[0], 0);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to add rtc subdev\n");
- goto out;
- }
-
- ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
- ARRAY_SIZE(onkey_devs),
- &onkey_resources[0], 0);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to add onkey subdev\n");
- goto out_dev;
- }
-
- if (pdata && pdata->regulator[0]) {
- ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
- ARRAY_SIZE(regulator_devs),
- &regulator_resources[0], 0);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to add regulator subdev\n");
- goto out_dev;
- }
- }
-
- if (pdata && pdata->backlight) {
- ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
- ARRAY_SIZE(backlight_devs),
- &backlight_resources[0], 0);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to add backlight subdev\n");
- goto out_dev;
- }
- }
-
- if (pdata && pdata->power) {
- ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
- ARRAY_SIZE(power_devs),
- &power_supply_resources[0], 0);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to add power supply "
- "subdev\n");
- goto out_dev;
- }
- }
-
- if (pdata && pdata->touch) {
- ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
- ARRAY_SIZE(touch_devs),
- &touch_resources[0], 0);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to add touch subdev\n");
- goto out_dev;
- }
- }
+ device_bk_init(chip, chip->i2c, pdata);
+ device_rtc_init(chip, chip->rtc, pdata);
+ device_touch_init(chip, chip->adc, pdata);
+ device_power_init(chip, chip->adc, pdata);
+ device_onkey_init(chip, chip->i2c, pdata);
+ device_regulator_init(chip, chip->i2c, pdata);

return 0;
-out_dev:
- mfd_remove_devices(chip->dev);
-out:
- return ret;
}

void __devexit max8925_device_exit(struct max8925_chip *chip)
diff --git a/include/linux/mfd/max8925.h b/include/linux/mfd/max8925.h
index 5259dfe..51578e2 100644
--- a/include/linux/mfd/max8925.h
+++ b/include/linux/mfd/max8925.h
@@ -209,9 +209,9 @@ struct max8925_chip {
};

struct max8925_backlight_pdata {
- int lxw_scl; /* 0/1 -- 0.8Ohm/0.4Ohm */
- int lxw_freq; /* 700KHz ~ 1400KHz */
- int dual_string; /* 0/1 -- single/dual string */
+ int lxw_scl; /* 0/1 -- 0.8Ohm/0.4Ohm */
+ int lxw_freq; /* 700KHz ~ 1400KHz */
+ int dual_string; /* 0/1 -- single/dual string */
};

struct max8925_touch_pdata {
@@ -233,10 +233,11 @@ struct max8925_platform_data {
struct max8925_backlight_pdata *backlight;
struct max8925_touch_pdata *touch;
struct max8925_power_pdata *power;
- struct regulator_init_data *regulator[MAX8925_MAX_REGULATOR];
+ struct regulator_init_data *regulator;

int irq_base;
int tsc_irq;
+ int num_regulators;
};

extern int max8925_reg_read(struct i2c_client *, int);
--
1.5.6.5

2011-04-13 14:56:05

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 03/13] rtc: add 88pm860x rtc

Support RTC component in 88PM860x. Also support synchronize time from
88PM860x RTC to another RTC device. It should be implemented in
sync callback API.

While 88PM860x RTC is enabled, it can do RTC calibration to gurantee
enough power is supplied on VRTC domain of 88PM860x.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Alessandro Zummo <[email protected]>
---
drivers/mfd/88pm860x-core.c | 31 +++
drivers/rtc/Kconfig | 10 +
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-88pm860x.c | 426 ++++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/88pm860x.h | 6 +
5 files changed, 474 insertions(+), 0 deletions(-)
create mode 100644 drivers/rtc/rtc-88pm860x.c

diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index b03cdd3..f114ec7 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -57,6 +57,10 @@ static struct resource regulator_resources[] __initdata = {
{PM8607_ID_LDO15, PM8607_ID_LDO15, "ldo-15", IORESOURCE_IO,},
};

+static struct resource rtc_resources[] __devinitdata = {
+ {PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,},
+};
+
static struct resource touch_resources[] __initdata = {
{PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,},
};
@@ -126,6 +130,10 @@ static struct mfd_cell regulator_devs[] __initdata = {
{"88pm860x-regulator", 17,},
};

+static struct mfd_cell rtc_devs[] = {
+ {"88pm860x-rtc", -1,},
+};
+
static struct mfd_cell touch_devs[] __initdata = {
{"88pm860x-touch", -1,},
};
@@ -148,6 +156,7 @@ static struct pm860x_led_pdata led_pdata[ARRAY_SIZE(led_devs)];
static struct regulator_init_data regulator_pdata[ARRAY_SIZE(regulator_devs)];
static struct pm860x_touch_pdata touch_pdata;
static struct pm860x_power_pdata power_pdata;
+static struct pm860x_rtc_pdata rtc_pdata;

struct pm860x_irq_data {
int reg;
@@ -588,6 +597,27 @@ out:
return;
}

+static void __devinit device_rtc_init(struct pm860x_chip *chip,
+ struct i2c_client *i2c,
+ struct pm860x_platform_data *pdata)
+{
+ int ret;
+
+ if ((pdata == NULL) || (pdata->rtc == NULL))
+ return;
+
+ memcpy(&rtc_pdata, pdata->rtc, sizeof(struct pm860x_rtc_pdata));
+ rtc_devs[0].platform_data = &rtc_pdata;
+ rtc_devs[0].pdata_size = sizeof(rtc_pdata);
+ rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources);
+ rtc_devs[0].resources = &rtc_resources[0];
+ ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
+ ARRAY_SIZE(rtc_devs), &rtc_resources[0],
+ chip->irq_base);
+ if (ret < 0)
+ dev_err(chip->dev, "Failed to add rtc subdev\n");
+}
+
static void __devinit device_touch_init(struct pm860x_chip *chip,
struct i2c_client *i2c,
struct pm860x_platform_data *pdata)
@@ -719,6 +749,7 @@ static void __devinit device_8607_init(struct pm860x_chip *chip,
goto out;

device_regulator_init(chip, i2c, pdata);
+ device_rtc_init(chip, i2c, pdata);
device_onkey_init(chip, i2c, pdata);
device_touch_init(chip, i2c, pdata);
device_power_init(chip, i2c, pdata);
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e187887..286f51e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -128,6 +128,16 @@ comment "I2C RTC drivers"

if I2C

+config RTC_DRV_88PM860X
+ tristate "Marvell 88PM860x"
+ depends on RTC_CLASS && I2C && MFD_88PM860X
+ help
+ If you say yes here you get support for RTC function in Marvell
+ 88PM860x chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-88pm860x.
+
config RTC_DRV_DS1307
tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index ca91c3c..e3d6fb0 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -15,6 +15,7 @@ rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o

# Keep the list ordered.

+obj-$(CONFIG_RTC_DRV_88PM860X) += rtc-88pm860x.o
obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o
obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o
obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
new file mode 100644
index 0000000..864e6c4
--- /dev/null
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -0,0 +1,426 @@
+/*
+ * Real Time Clock driver for Marvell 88PM860x PMIC
+ *
+ * Copyright (c) 2010 Marvell International Ltd.
+ * Author: Haojian Zhuang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/mutex.h>
+#include <linux/rtc.h>
+#include <linux/delay.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/88pm860x.h>
+
+#define VRTC_CALIBRATION
+
+struct pm860x_rtc_info {
+ struct pm860x_chip *chip;
+ struct i2c_client *i2c;
+ struct rtc_device *rtc_dev;
+ struct device *dev;
+ struct delayed_work calib_work;
+
+ int irq;
+ int vrtc;
+ int (*sync)(unsigned int ticks);
+};
+
+#define REG_VRTC_MEAS1 0x7D
+
+#define REG0_ADDR 0xB0
+#define REG1_ADDR 0xB2
+#define REG2_ADDR 0xB4
+#define REG3_ADDR 0xB6
+
+#define REG0_DATA 0xB1
+#define REG1_DATA 0xB3
+#define REG2_DATA 0xB5
+#define REG3_DATA 0xB7
+
+/* bit definitions of Measurement Enable Register 2 (0x51) */
+#define MEAS2_VRTC (1 << 0)
+
+/* bit definitions of RTC Register 1 (0xA0) */
+#define ALARM_EN (1 << 3)
+#define ALARM_WAKEUP (1 << 4)
+#define ALARM (1 << 5)
+#define RTC1_USE_XO (1 << 7)
+
+#define VRTC_CALIB_INTERVAL (HZ * 60 * 10) /* 10 minutes */
+
+static irqreturn_t rtc_update_handler(int irq, void *data)
+{
+ struct pm860x_rtc_info *info = (struct pm860x_rtc_info *)data;
+ int mask;
+
+ mask = ALARM | ALARM_WAKEUP;
+ pm860x_set_bits(info->i2c, PM8607_RTC1, mask | ALARM_EN, mask);
+ rtc_update_irq(info->rtc_dev, 1, RTC_AF);
+ return IRQ_HANDLED;
+}
+
+static int pm860x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+ struct pm860x_rtc_info *info = dev_get_drvdata(dev);
+
+ if (enabled)
+ pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM, ALARM);
+ else
+ pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM, 0);
+ return 0;
+}
+
+/*
+ * Calculate the next alarm time given the requested alarm time mask
+ * and the current time.
+ */
+static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
+ struct rtc_time *alrm)
+{
+ unsigned long next_time;
+ unsigned long now_time;
+
+ next->tm_year = now->tm_year;
+ next->tm_mon = now->tm_mon;
+ next->tm_mday = now->tm_mday;
+ next->tm_hour = alrm->tm_hour;
+ next->tm_min = alrm->tm_min;
+ next->tm_sec = alrm->tm_sec;
+
+ rtc_tm_to_time(now, &now_time);
+ rtc_tm_to_time(next, &next_time);
+
+ if (next_time < now_time) {
+ /* Advance one day */
+ next_time += 60 * 60 * 24;
+ rtc_time_to_tm(next_time, next);
+ }
+}
+
+static int pm860x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+ struct pm860x_rtc_info *info = dev_get_drvdata(dev);
+ unsigned char buf[8];
+ unsigned long ticks, base, data;
+
+ pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf);
+ dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1],
+ buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ base = (buf[1] << 24) | (buf[3] << 16) | (buf[5] << 8) | buf[7];
+
+ /* load 32-bit read-only counter */
+ pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf);
+ data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+ ticks = base + data;
+ dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ base, data, ticks);
+
+ rtc_time_to_tm(ticks, tm);
+
+ return 0;
+}
+
+static int pm860x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct pm860x_rtc_info *info = dev_get_drvdata(dev);
+ unsigned char buf[4];
+ unsigned long ticks, base, data;
+
+ if ((tm->tm_year < 70) || (tm->tm_year > 138)) {
+ dev_dbg(info->dev, "Set time %d out of range. "
+ "Please set time between 1970 to 2038.\n",
+ 1900 + tm->tm_year);
+ return -EINVAL;
+ }
+ rtc_tm_to_time(tm, &ticks);
+
+ /* load 32-bit read-only counter */
+ pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf);
+ data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+ base = ticks - data;
+ dev_dbg(info->dev, "set base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ base, data, ticks);
+
+ pm860x_page_reg_write(info->i2c, REG0_DATA, (base >> 24) & 0xFF);
+ pm860x_page_reg_write(info->i2c, REG1_DATA, (base >> 16) & 0xFF);
+ pm860x_page_reg_write(info->i2c, REG2_DATA, (base >> 8) & 0xFF);
+ pm860x_page_reg_write(info->i2c, REG3_DATA, base & 0xFF);
+
+ if (info->sync)
+ info->sync(ticks);
+ return 0;
+}
+
+static int pm860x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ struct pm860x_rtc_info *info = dev_get_drvdata(dev);
+ unsigned char buf[8];
+ unsigned long ticks, base, data;
+ int ret;
+
+ pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf);
+ dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1],
+ buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ base = (buf[1] << 24) | (buf[3] << 16) | (buf[5] << 8) | buf[7];
+
+ pm860x_bulk_read(info->i2c, PM8607_RTC_EXPIRE1, 4, buf);
+ data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+ ticks = base + data;
+ dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ base, data, ticks);
+
+ rtc_time_to_tm(ticks, &alrm->time);
+ ret = pm860x_reg_read(info->i2c, PM8607_RTC1);
+ alrm->enabled = (ret & ALARM_EN) ? 1 : 0;
+ alrm->pending = (ret & (ALARM | ALARM_WAKEUP)) ? 1 : 0;
+ return 0;
+}
+
+static int pm860x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ struct pm860x_rtc_info *info = dev_get_drvdata(dev);
+ struct rtc_time now_tm, alarm_tm;
+ unsigned long ticks, base, data;
+ unsigned char buf[8];
+ int mask;
+
+ pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM_EN, 0);
+
+ pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf);
+ dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1],
+ buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ base = (buf[1] << 24) | (buf[3] << 16) | (buf[5] << 8) | buf[7];
+
+ /* load 32-bit read-only counter */
+ pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf);
+ data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+ ticks = base + data;
+ dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ base, data, ticks);
+
+ rtc_time_to_tm(ticks, &now_tm);
+ rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time);
+ /* get new ticks for alarm in 24 hours */
+ rtc_tm_to_time(&alarm_tm, &ticks);
+ data = ticks - base;
+
+ buf[0] = data & 0xff;
+ buf[1] = (data >> 8) & 0xff;
+ buf[2] = (data >> 16) & 0xff;
+ buf[3] = (data >> 24) & 0xff;
+ pm860x_bulk_write(info->i2c, PM8607_RTC_EXPIRE1, 4, buf);
+ if (alrm->enabled) {
+ mask = ALARM | ALARM_WAKEUP | ALARM_EN;
+ pm860x_set_bits(info->i2c, PM8607_RTC1, mask, mask);
+ } else {
+ mask = ALARM | ALARM_WAKEUP | ALARM_EN;
+ pm860x_set_bits(info->i2c, PM8607_RTC1, mask,
+ ALARM | ALARM_WAKEUP);
+ }
+ return 0;
+}
+
+static const struct rtc_class_ops pm860x_rtc_ops = {
+ .read_time = pm860x_rtc_read_time,
+ .set_time = pm860x_rtc_set_time,
+ .read_alarm = pm860x_rtc_read_alarm,
+ .set_alarm = pm860x_rtc_set_alarm,
+ .alarm_irq_enable = pm860x_rtc_alarm_irq_enable,
+};
+
+#ifdef VRTC_CALIBRATION
+static void calibrate_vrtc_work(struct work_struct *work)
+{
+ struct pm860x_rtc_info *info = container_of(work,
+ struct pm860x_rtc_info, calib_work.work);
+ unsigned char buf[2];
+ unsigned int sum, data, mean, vrtc_set;
+ int i;
+
+ for (i = 0, sum = 0; i < 16; i++) {
+ msleep(100);
+ pm860x_bulk_read(info->i2c, REG_VRTC_MEAS1, 2, buf);
+ data = (buf[0] << 4) | buf[1];
+ data = (data * 5400) >> 12; /* convert to mv */
+ sum += data;
+ }
+ mean = sum >> 4;
+ vrtc_set = 2700 + (info->vrtc & 0x3) * 200;
+ dev_dbg(info->dev, "mean:%d, vrtc_set:%d\n", mean, vrtc_set);
+
+ sum = pm860x_reg_read(info->i2c, PM8607_RTC_MISC1);
+ data = sum & 0x3;
+ if ((mean + 200) < vrtc_set) {
+ /* try higher voltage */
+ if (++data == 4)
+ goto out;
+ data = (sum & 0xf8) | (data & 0x3);
+ pm860x_reg_write(info->i2c, PM8607_RTC_MISC1, data);
+ } else if ((mean - 200) > vrtc_set) {
+ /* try lower voltage */
+ if (data-- == 0)
+ goto out;
+ data = (sum & 0xf8) | (data & 0x3);
+ pm860x_reg_write(info->i2c, PM8607_RTC_MISC1, data);
+ } else
+ goto out;
+ dev_dbg(info->dev, "set 0x%x to RTC_MISC1\n", data);
+ /* trigger next calibration since VRTC is updated */
+ schedule_delayed_work(&info->calib_work, VRTC_CALIB_INTERVAL);
+ return;
+out:
+ /* disable measurement */
+ pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
+ dev_dbg(info->dev, "finish VRTC calibration\n");
+ return;
+}
+#endif
+
+static int __devinit pm860x_rtc_probe(struct platform_device *pdev)
+{
+ struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
+ struct pm860x_rtc_pdata *pdata = NULL;
+ struct pm860x_rtc_info *info;
+ struct rtc_time tm;
+ unsigned long ticks = 0;
+ int ret;
+
+ pdata = pdev->dev.platform_data;
+ if (pdata == NULL) {
+ dev_err(&pdev->dev, "No platform data!\n");
+ return -EINVAL;
+ }
+
+ info = kzalloc(sizeof(struct pm860x_rtc_info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+ info->irq = platform_get_irq(pdev, 0);
+ if (info->irq < 0) {
+ dev_err(&pdev->dev, "No IRQ resource!\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ info->chip = chip;
+ info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
+ info->dev = &pdev->dev;
+ dev_set_drvdata(&pdev->dev, info);
+
+ ret = request_threaded_irq(info->irq, NULL, rtc_update_handler,
+ IRQF_ONESHOT, "rtc", info);
+ if (ret < 0) {
+ dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
+ info->irq, ret);
+ goto out;
+ }
+
+ /* set addresses of 32-bit base value for RTC time */
+ pm860x_page_reg_write(info->i2c, REG0_ADDR, REG0_DATA);
+ pm860x_page_reg_write(info->i2c, REG1_ADDR, REG1_DATA);
+ pm860x_page_reg_write(info->i2c, REG2_ADDR, REG2_DATA);
+ pm860x_page_reg_write(info->i2c, REG3_ADDR, REG3_DATA);
+
+ ret = pm860x_rtc_read_time(&pdev->dev, &tm);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Failed to read initial time.\n");
+ goto out_rtc;
+ }
+ if ((tm.tm_year < 70) || (tm.tm_year > 138)) {
+ tm.tm_year = 70;
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ ret = pm860x_rtc_set_time(&pdev->dev, &tm);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Failed to set initial time.\n");
+ goto out_rtc;
+ }
+ }
+ rtc_tm_to_time(&tm, &ticks);
+ if (pdata->sync) {
+ pdata->sync(ticks);
+ info->sync = pdata->sync;
+ }
+
+ info->rtc_dev = rtc_device_register("88pm860x-rtc", &pdev->dev,
+ &pm860x_rtc_ops, THIS_MODULE);
+ ret = PTR_ERR(info->rtc_dev);
+ if (IS_ERR(info->rtc_dev)) {
+ dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
+ goto out_rtc;
+ }
+
+ /*
+ * enable internal XO instead of internal 3.25MHz clock since it can
+ * free running in PMIC power-down state.
+ */
+ pm860x_set_bits(info->i2c, PM8607_RTC1, RTC1_USE_XO, RTC1_USE_XO);
+
+#ifdef VRTC_CALIBRATION
+ /* <00> -- 2.7V, <01> -- 2.9V, <10> -- 3.1V, <11> -- 3.3V */
+ info->vrtc = pdata->vrtc & 0x3;
+ pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC);
+
+ /* calibrate VRTC */
+ INIT_DELAYED_WORK(&info->calib_work, calibrate_vrtc_work);
+ schedule_delayed_work(&info->calib_work, VRTC_CALIB_INTERVAL);
+#endif /* VRTC_CALIBRATION */
+ return 0;
+out_rtc:
+ free_irq(info->irq, info);
+out:
+ kfree(info);
+ return ret;
+}
+
+static int __devexit pm860x_rtc_remove(struct platform_device *pdev)
+{
+ struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
+
+#ifdef VRTC_CALIBRATION
+ flush_scheduled_work();
+ /* disable measurement */
+ pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
+#endif /* VRTC_CALIBRATION */
+
+ platform_set_drvdata(pdev, NULL);
+ rtc_device_unregister(info->rtc_dev);
+ free_irq(info->irq, info);
+ kfree(info);
+ return 0;
+}
+
+static struct platform_driver pm860x_rtc_driver = {
+ .driver = {
+ .name = "88pm860x-rtc",
+ .owner = THIS_MODULE,
+ },
+ .probe = pm860x_rtc_probe,
+ .remove = __devexit_p(pm860x_rtc_remove),
+};
+
+static int __init pm860x_rtc_init(void)
+{
+ return platform_driver_register(&pm860x_rtc_driver);
+}
+module_init(pm860x_rtc_init);
+
+static void __exit pm860x_rtc_exit(void)
+{
+ platform_driver_unregister(&pm860x_rtc_driver);
+}
+module_exit(pm860x_rtc_exit);
+
+MODULE_DESCRIPTION("Marvell 88PM860x RTC driver");
+MODULE_AUTHOR("Haojian Zhuang <[email protected]>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/88pm860x.h b/include/linux/mfd/88pm860x.h
index 8fba797..63b4fb8 100644
--- a/include/linux/mfd/88pm860x.h
+++ b/include/linux/mfd/88pm860x.h
@@ -330,6 +330,11 @@ struct pm860x_led_pdata {
unsigned long flags;
};

+struct pm860x_rtc_pdata {
+ int (*sync)(unsigned int ticks);
+ int vrtc;
+};
+
struct pm860x_touch_pdata {
int gpadc_prebias;
int slot_cycle;
@@ -349,6 +354,7 @@ struct pm860x_power_pdata {
struct pm860x_platform_data {
struct pm860x_backlight_pdata *backlight;
struct pm860x_led_pdata *led;
+ struct pm860x_rtc_pdata *rtc;
struct pm860x_touch_pdata *touch;
struct pm860x_power_pdata *power;
struct regulator_init_data *regulator;
--
1.5.6.5

2011-04-13 14:56:18

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 13/13] regulator: max8925: enable i2c sequence for control

Force to enable i2c as power up/down sequence. Otherwise, SD/LDO can't
be enabled or disabled via accessing i2c bus.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
---
drivers/regulator/max8925-regulator.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index ce821e4..2dd2fd9 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -23,6 +23,10 @@
#define SD1_DVM_SHIFT 5 /* SDCTL1 bit5 */
#define SD1_DVM_EN 6 /* SDV1 bit 6 */

+/* bit definitions in SD & LDO control registers */
+#define OUT_ENABLE 0x1f /* Power U/D sequence as I2C */
+#define OUT_DISABLE 0x1e /* Power U/D sequence as I2C */
+
struct max8925_regulator_info {
struct regulator_desc desc;
struct regulator_dev *regulator;
@@ -93,8 +97,8 @@ static int max8925_enable(struct regulator_dev *rdev)
struct max8925_regulator_info *info = rdev_get_drvdata(rdev);

return max8925_set_bits(info->i2c, info->enable_reg,
- 1 << info->enable_bit,
- 1 << info->enable_bit);
+ OUT_ENABLE << info->enable_bit,
+ OUT_ENABLE << info->enable_bit);
}

static int max8925_disable(struct regulator_dev *rdev)
@@ -102,7 +106,8 @@ static int max8925_disable(struct regulator_dev *rdev)
struct max8925_regulator_info *info = rdev_get_drvdata(rdev);

return max8925_set_bits(info->i2c, info->enable_reg,
- 1 << info->enable_bit, 0);
+ OUT_ENABLE << info->enable_bit,
+ OUT_DISABLE << info->enable_bit);
}

static int max8925_is_enabled(struct regulator_dev *rdev)
--
1.5.6.5

2011-04-13 14:56:45

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 11/13] power_supply: max8925: use platform_data from cell

Avoid to get platform_data from parent device. Get it from mfd cell
device instead.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
---
drivers/power/max8925_power.c | 16 +++++-----------
1 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
index 8e5aec2..359c53c 100644
--- a/drivers/power/max8925_power.c
+++ b/drivers/power/max8925_power.c
@@ -425,21 +425,16 @@ static __devexit int max8925_deinit_charger(struct max8925_power_info *info)
static __devinit int max8925_power_probe(struct platform_device *pdev)
{
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
- struct max8925_platform_data *max8925_pdata;
struct max8925_power_pdata *pdata = NULL;
struct max8925_power_info *info;
- int ret;
-
- if (pdev->dev.parent->platform_data) {
- max8925_pdata = pdev->dev.parent->platform_data;
- pdata = max8925_pdata->power;
- }
+ int ret = -EINVAL;

- if (!pdata) {
+ pdata = pdev->dev.platform_data;
+ if (pdata == NULL) {
dev_err(&pdev->dev, "platform data isn't assigned to "
"power supply\n");
return -EINVAL;
- }
+ };

info = kzalloc(sizeof(struct max8925_power_info), GFP_KERNEL);
if (!info)
@@ -447,6 +442,7 @@ static __devinit int max8925_power_probe(struct platform_device *pdev)
info->chip = chip;
info->gpm = chip->i2c;
info->adc = chip->adc;
+ dev_set_drvdata(&pdev->dev, info);

info->ac.name = "max8925-ac";
info->ac.type = POWER_SUPPLY_TYPE_MAINS;
@@ -482,8 +478,6 @@ static __devinit int max8925_power_probe(struct platform_device *pdev)
info->topoff_threshold = pdata->topoff_threshold;
info->fast_charge = pdata->fast_charge;
info->set_charger = pdata->set_charger;
- dev_set_drvdata(&pdev->dev, info);
- platform_set_drvdata(pdev, info);

max8925_init_charger(chip, info);
return 0;
--
1.5.6.5

2011-04-13 14:56:33

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 12/13] regulator: check name in initialization of max8925

Check name in initialization of max8925 regulator driver.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
---
drivers/regulator/max8925-regulator.c | 37 +++++++++++++++-----------------
1 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index 8ae1475..ce821e4 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -169,7 +169,7 @@ static struct regulator_ops max8925_regulator_ldo_ops = {
#define MAX8925_SDV(_id, min, max, step) \
{ \
.desc = { \
- .name = "SDV" #_id, \
+ .name = "SD" #_id, \
.ops = &max8925_regulator_sdv_ops, \
.type = REGULATOR_VOLTAGE, \
.id = MAX8925_ID_SD##_id, \
@@ -231,39 +231,36 @@ static struct max8925_regulator_info max8925_regulator_info[] = {
MAX8925_LDO(20, 750, 3900, 50),
};

-static struct max8925_regulator_info * __devinit find_regulator_info(int id)
+static int __devinit max8925_regulator_probe(struct platform_device *pdev)
{
- struct max8925_regulator_info *ri;
+ struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
+ struct max8925_regulator_info *ri = NULL;
+ struct regulator_init_data *pdata;
+ struct regulator_dev *rdev;
int i;

+ pdata = pdev->dev.platform_data;
+ if (pdata == NULL)
+ return -EINVAL;
+
for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
ri = &max8925_regulator_info[i];
- if (ri->desc.id == id)
- return ri;
+ if (!strcmp(ri->desc.name, pdata->constraints.name))
+ break;
}
- return NULL;
-}
-
-static int __devinit max8925_regulator_probe(struct platform_device *pdev)
-{
- struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
- struct max8925_platform_data *pdata = chip->dev->platform_data;
- struct max8925_regulator_info *ri;
- struct regulator_dev *rdev;
-
- ri = find_regulator_info(pdev->id);
- if (ri == NULL) {
- dev_err(&pdev->dev, "invalid regulator ID specified\n");
+ if (i > ARRAY_SIZE(max8925_regulator_info)) {
+ dev_err(&pdev->dev, "Failed to find regulator %s\n",
+ pdata->constraints.name);
return -EINVAL;
}
ri->i2c = chip->i2c;
ri->chip = chip;

rdev = regulator_register(&ri->desc, &pdev->dev,
- pdata->regulator[pdev->id], ri);
+ pdata, ri);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
- ri->desc.name);
+ ri->desc.name);
return PTR_ERR(rdev);
}

--
1.5.6.5

2011-04-13 14:56:09

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 07/13] mfd: fix build warning on 88pm860x

WARNING: vmlinux.o(.devinit.text+0x6c4): Section mismatch in reference
from the function device_onkey_init() to the (unknown reference)
.init.data:(unknown)
The function __devinit device_onkey_init() references a (unknown reference)
__initdata (unknown).
If (unknown) is only used by device_onkey_init then annotate (unknown)
with a matching annotation.

It's caused by using __initdata on mfd cell resources. Replace __initdata
with __devinitdata.

Signed-off-by: Haojian Zhuang <[email protected]>
---
drivers/mfd/88pm860x-core.c | 28 ++++++++++++++--------------
1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index f114ec7..4fbc69b 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -21,13 +21,13 @@

#define INT_STATUS_NUM 3

-static struct resource bk_resources[] __initdata = {
+static struct resource bk_resources[] __devinitdata = {
{PM8606_BACKLIGHT1, PM8606_BACKLIGHT1, "backlight-0", IORESOURCE_IO,},
{PM8606_BACKLIGHT2, PM8606_BACKLIGHT2, "backlight-1", IORESOURCE_IO,},
{PM8606_BACKLIGHT3, PM8606_BACKLIGHT3, "backlight-2", IORESOURCE_IO,},
};

-static struct resource led_resources[] __initdata = {
+static struct resource led_resources[] __devinitdata = {
{PM8606_LED1_RED, PM8606_LED1_RED, "led0-red", IORESOURCE_IO,},
{PM8606_LED1_GREEN, PM8606_LED1_GREEN, "led0-green", IORESOURCE_IO,},
{PM8606_LED1_BLUE, PM8606_LED1_BLUE, "led0-blue", IORESOURCE_IO,},
@@ -36,7 +36,7 @@ static struct resource led_resources[] __initdata = {
{PM8606_LED2_BLUE, PM8606_LED2_BLUE, "led1-blue", IORESOURCE_IO,},
};

-static struct resource regulator_resources[] __initdata = {
+static struct resource regulator_resources[] __devinitdata = {
{PM8607_ID_BUCK1, PM8607_ID_BUCK1, "buck-1", IORESOURCE_IO,},
{PM8607_ID_BUCK2, PM8607_ID_BUCK2, "buck-2", IORESOURCE_IO,},
{PM8607_ID_BUCK3, PM8607_ID_BUCK3, "buck-3", IORESOURCE_IO,},
@@ -61,15 +61,15 @@ static struct resource rtc_resources[] __devinitdata = {
{PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,},
};

-static struct resource touch_resources[] __initdata = {
+static struct resource touch_resources[] __devinitdata = {
{PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,},
};

-static struct resource onkey_resources[] __initdata = {
+static struct resource onkey_resources[] __devinitdata = {
{PM8607_IRQ_ONKEY, PM8607_IRQ_ONKEY, "onkey", IORESOURCE_IRQ,},
};

-static struct resource codec_resources[] __initdata = {
+static struct resource codec_resources[] __devinitdata = {
/* Headset microphone insertion or removal */
{PM8607_IRQ_MICIN, PM8607_IRQ_MICIN, "micin", IORESOURCE_IRQ,},
/* Hook-switch press or release */
@@ -80,12 +80,12 @@ static struct resource codec_resources[] __initdata = {
{PM8607_IRQ_AUDIO_SHORT, PM8607_IRQ_AUDIO_SHORT, "audio-short", IORESOURCE_IRQ,},
};

-static struct resource battery_resources[] __initdata = {
+static struct resource battery_resources[] __devinitdata = {
{PM8607_IRQ_CC, PM8607_IRQ_CC, "columb counter", IORESOURCE_IRQ,},
{PM8607_IRQ_BAT, PM8607_IRQ_BAT, "battery", IORESOURCE_IRQ,},
};

-static struct resource charger_resources[] __initdata = {
+static struct resource charger_resources[] __devinitdata = {
{PM8607_IRQ_CHG, PM8607_IRQ_CHG, "charger detect", IORESOURCE_IRQ,},
{PM8607_IRQ_CHG_DONE, PM8607_IRQ_CHG_DONE, "charging done", IORESOURCE_IRQ,},
{PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging timeout", IORESOURCE_IRQ,},
@@ -94,13 +94,13 @@ static struct resource charger_resources[] __initdata = {
{PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage", IORESOURCE_IRQ,},
};

-static struct mfd_cell bk_devs[] __initdata = {
+static struct mfd_cell bk_devs[] = {
{"88pm860x-backlight", 0,},
{"88pm860x-backlight", 1,},
{"88pm860x-backlight", 2,},
};

-static struct mfd_cell led_devs[] __initdata = {
+static struct mfd_cell led_devs[] = {
{"88pm860x-led", 0,},
{"88pm860x-led", 1,},
{"88pm860x-led", 2,},
@@ -109,7 +109,7 @@ static struct mfd_cell led_devs[] __initdata = {
{"88pm860x-led", 5,},
};

-static struct mfd_cell regulator_devs[] __initdata = {
+static struct mfd_cell regulator_devs[] = {
{"88pm860x-regulator", 0,},
{"88pm860x-regulator", 1,},
{"88pm860x-regulator", 2,},
@@ -134,15 +134,15 @@ static struct mfd_cell rtc_devs[] = {
{"88pm860x-rtc", -1,},
};

-static struct mfd_cell touch_devs[] __initdata = {
+static struct mfd_cell touch_devs[] = {
{"88pm860x-touch", -1,},
};

-static struct mfd_cell onkey_devs[] __initdata = {
+static struct mfd_cell onkey_devs[] = {
{"88pm860x-onkey", -1,},
};

-static struct mfd_cell codec_devs[] __initdata = {
+static struct mfd_cell codec_devs[] = {
{"88pm860x-codec", -1,},
};

--
1.5.6.5

2011-04-13 14:56:58

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 10/13] rtc: avoid to use hardcoding irq number in max8925

Avoid to use hardcoding irq number in max8925 rtc driver. Use irq number
from resources instead.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Alessandro Zummo <[email protected]>
---
drivers/rtc/rtc-max8925.c | 22 +++++++++++++---------
1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
index 174036d..c460152 100644
--- a/drivers/rtc/rtc-max8925.c
+++ b/drivers/rtc/rtc-max8925.c
@@ -69,6 +69,7 @@ struct max8925_rtc_info {
struct max8925_chip *chip;
struct i2c_client *rtc;
struct device *dev;
+ int irq;
};

static irqreturn_t rtc_update_handler(int irq, void *data)
@@ -239,7 +240,7 @@ static int __devinit max8925_rtc_probe(struct platform_device *pdev)
{
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct max8925_rtc_info *info;
- int irq, ret;
+ int ret = -EINVAL;

info = kzalloc(sizeof(struct max8925_rtc_info), GFP_KERNEL);
if (!info)
@@ -247,16 +248,22 @@ static int __devinit max8925_rtc_probe(struct platform_device *pdev)
info->chip = chip;
info->rtc = chip->rtc;
info->dev = &pdev->dev;
- irq = chip->irq_base + MAX8925_IRQ_RTC_ALARM0;
+ info->irq = platform_get_irq(pdev, 0);
+ if (info->irq < 0) {
+ dev_err(chip->dev, "Failed to get IRQ resource\n");
+ goto out_irq;
+ }

- ret = request_threaded_irq(irq, NULL, rtc_update_handler,
+ ret = request_threaded_irq(info->irq, NULL, rtc_update_handler,
IRQF_ONESHOT, "rtc-alarm0", info);
if (ret < 0) {
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
- irq, ret);
+ info->irq, ret);
goto out_irq;
}

+ dev_set_drvdata(&pdev->dev, info);
+ platform_set_drvdata(pdev, info);
info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev,
&max8925_rtc_ops, THIS_MODULE);
ret = PTR_ERR(info->rtc_dev);
@@ -265,12 +272,9 @@ static int __devinit max8925_rtc_probe(struct platform_device *pdev)
goto out_rtc;
}

- dev_set_drvdata(&pdev->dev, info);
- platform_set_drvdata(pdev, info);
-
return 0;
out_rtc:
- free_irq(chip->irq_base + MAX8925_IRQ_RTC_ALARM0, info);
+ free_irq(info->irq, info);
out_irq:
kfree(info);
return ret;
@@ -281,7 +285,7 @@ static int __devexit max8925_rtc_remove(struct platform_device *pdev)
struct max8925_rtc_info *info = platform_get_drvdata(pdev);

if (info) {
- free_irq(info->chip->irq_base + MAX8925_IRQ_RTC_ALARM0, info);
+ free_irq(info->irq, info);
rtc_device_unregister(info->rtc_dev);
kfree(info);
}
--
1.5.6.5

2011-04-13 14:57:29

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 09/13] input: get irq from resource in max8925 onkey

Avoid to use hardcoding irq numbers in max8925 onkey driver. Get irq
from resources instead.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
---
drivers/input/misc/max8925_onkey.c | 36 ++++++++++++++++--------------------
1 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c
index 7de0ded..835cc2a 100644
--- a/drivers/input/misc/max8925_onkey.c
+++ b/drivers/input/misc/max8925_onkey.c
@@ -69,18 +69,7 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev)
{
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct max8925_onkey_info *info;
- int irq[2], error;
-
- irq[0] = platform_get_irq(pdev, 0);
- if (irq[0] < 0) {
- dev_err(&pdev->dev, "No IRQ resource!\n");
- return -EINVAL;
- }
- irq[1] = platform_get_irq(pdev, 1);
- if (irq[1] < 0) {
- dev_err(&pdev->dev, "No IRQ resource!\n");
- return -EINVAL;
- }
+ int error = -EINVAL;

info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL);
if (!info)
@@ -88,21 +77,30 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev)

info->i2c = chip->i2c;
info->dev = &pdev->dev;
- irq[0] += chip->irq_base;
- irq[1] += chip->irq_base;

- error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler,
+ info->irq[0] = platform_get_irq(pdev, 0);
+ if (info->irq[0] < 0) {
+ dev_err(&pdev->dev, "No IRQ resource!\n");
+ goto out;
+ }
+ info->irq[1] = platform_get_irq(pdev, 1);
+ if (info->irq[1] < 0) {
+ dev_err(&pdev->dev, "No IRQ resource!\n");
+ goto out;
+ }
+
+ error = request_threaded_irq(info->irq[0], NULL, max8925_onkey_handler,
IRQF_ONESHOT, "onkey-down", info);
if (error < 0) {
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
- irq[0], error);
+ info->irq[0], error);
goto out;
}
- error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler,
+ error = request_threaded_irq(info->irq[1], NULL, max8925_onkey_handler,
IRQF_ONESHOT, "onkey-up", info);
if (error < 0) {
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
- irq[1], error);
+ info->irq[1], error);
goto out_irq;
}

@@ -117,8 +115,6 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev)
info->idev->phys = "max8925_on/input0";
info->idev->id.bustype = BUS_I2C;
info->idev->dev.parent = &pdev->dev;
- info->irq[0] = irq[0];
- info->irq[1] = irq[1];
info->idev->evbit[0] = BIT_MASK(EV_KEY);
info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);

--
1.5.6.5

2011-04-13 14:56:04

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 04/13] input: set the long press detection in 88pm860x onkey

Move the long-press detection from onkey handler to probe function. Avoid
unnecessary I2C operation in onkey handler.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
---
drivers/input/misc/88pm860x_onkey.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/input/misc/88pm860x_onkey.c b/drivers/input/misc/88pm860x_onkey.c
index 3dca3c1..1abc77e 100644
--- a/drivers/input/misc/88pm860x_onkey.c
+++ b/drivers/input/misc/88pm860x_onkey.c
@@ -50,9 +50,6 @@ static irqreturn_t pm860x_onkey_handler(int irq, void *data)
ret &= ONKEY_STATUS;
input_report_key(info->idev, KEY_POWER, ret);
input_sync(info->idev);
-
- /* Enable 8-second long onkey detection */
- pm860x_set_bits(info->i2c, PM8607_WAKEUP, 3, LONG_ONKEY_EN);
return IRQ_HANDLED;
}

@@ -105,6 +102,9 @@ static int __devinit pm860x_onkey_probe(struct platform_device *pdev)
}

platform_set_drvdata(pdev, info);
+
+ /* Enable 8-second long onkey detection */
+ pm860x_set_bits(info->i2c, PM8607_WAKEUP, 3, LONG_ONKEY_EN);
return 0;

out_irq:
--
1.5.6.5

2011-04-13 14:57:46

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 06/13] mfd: pxa-w1: MFD driver for PXA 1wire control + DS1WM chip

This driver provides registers and IRQ of PXA3xx chips to the ds1wm driver.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Evgeniy Polyakov <[email protected]>
---
drivers/mfd/Kconfig | 7 ++
drivers/mfd/Makefile | 1 +
drivers/mfd/pxa-w1.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 158 insertions(+), 0 deletions(-)
create mode 100644 drivers/mfd/pxa-w1.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index e2fea58..b6ecf90 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -34,6 +34,13 @@ config MFD_88PM860X
select individual components like voltage regulators, RTC and
battery-charger under the corresponding menus.

+config MFD_PXA_DS1WM
+ tristate "Support DS1WM chip on Marvell silicons"
+ select MFD_CORE
+ help
+ This core driver provides register access for PXA_DS1WM.
+ Actual functionality is handled by the ds1wm drivers.
+
config MFD_SM501
tristate "Support for Silicon Motion SM501"
---help---
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 419caa9..4f8d1d2 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -4,6 +4,7 @@

88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o
obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o
+obj-$(CONFIG_MFD_PXA_DS1WM) += pxa-w1.o
obj-$(CONFIG_MFD_SM501) += sm501.o
obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o

diff --git a/drivers/mfd/pxa-w1.c b/drivers/mfd/pxa-w1.c
new file mode 100644
index 0000000..98074ff
--- /dev/null
+++ b/drivers/mfd/pxa-w1.c
@@ -0,0 +1,150 @@
+/*
+ * Core driver for PXA DS1WM chip.
+ *
+ * Copyright (C) 2010 Marvell <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/ds1wm.h>
+
+struct pxa_w1_info {
+ struct clk *clk;
+};
+
+static int ds1wm_enable(struct platform_device *pdev)
+{
+ struct device *dev = pdev->dev.parent;
+ struct pxa_w1_info *info = dev_get_drvdata(dev);
+
+ clk_enable(info->clk);
+ dev_dbg(dev, "pxa DS1WM clk (active)\n");
+ return 0;
+}
+
+static int ds1wm_disable(struct platform_device *pdev)
+{
+ struct device *dev = pdev->dev.parent;
+ struct pxa_w1_info *info = dev_get_drvdata(dev);
+
+ clk_disable(info->clk);
+ dev_dbg(dev, "pxa DS1WM clk (in-active)\n");
+ return 0;
+}
+
+static struct resource ds1wm_resources[] __devinitdata = {
+ {0, 0, "ds1wm-mem", IORESOURCE_MEM,},
+ {0, 0, "ds1wm-irq", IORESOURCE_IRQ,},
+};
+
+static struct ds1wm_driver_data ds1wm_pdata;
+
+static struct mfd_cell ds1wm_cell __devinitdata = {
+ .name = "ds1wm",
+ .enable = ds1wm_enable,
+ .disable = ds1wm_disable,
+ .platform_data = &ds1wm_pdata,
+ .pdata_size = sizeof(ds1wm_pdata),
+ .num_resources = ARRAY_SIZE(ds1wm_resources),
+ .resources = ds1wm_resources,
+};
+
+static int __devinit pxa_w1_probe(struct platform_device *pdev)
+{
+ struct ds1wm_driver_data *pdata = pdev->dev.platform_data;
+ struct pxa_w1_info *info;
+ struct resource *r;
+ int ret, irq;
+
+ info = kzalloc(sizeof(struct pxa_w1_info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
+ r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+ if (r == NULL) {
+ ret = -ENXIO;
+ goto out;
+ }
+ irq = r->start;
+ if (pdata)
+ ds1wm_pdata.active_high = pdata->active_high;
+ if (ds1wm_pdata.active_high)
+ ds1wm_resources[1].flags |= IORESOURCE_IRQ_HIGHEDGE;
+ else
+ ds1wm_resources[1].flags |= IORESOURCE_IRQ_LOWEDGE;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (r == NULL) {
+ ret = -ENXIO;
+ goto out;
+ }
+ ds1wm_resources[0].end = resource_size(r) - 1;
+
+ info->clk = clk_get(&pdev->dev, NULL);
+ if (IS_ERR(info->clk)) {
+ ret = PTR_ERR(info->clk);
+ goto out;
+ }
+ platform_set_drvdata(pdev, info);
+
+ ds1wm_pdata.clock_rate = clk_get_rate(info->clk);
+ ret = mfd_add_devices(&pdev->dev, pdev->id, &ds1wm_cell, 1, r, irq);
+ if (ret < 0)
+ dev_err(&pdev->dev, "failed to register pxa DS1WM\n");
+
+ return 0;
+out:
+ kfree(info);
+ return ret;
+}
+
+static int __devexit pxa_w1_remove(struct platform_device *pdev)
+{
+ struct pxa_w1_info *info = platform_get_drvdata(pdev);
+
+ mfd_remove_devices(&pdev->dev);
+ clk_put(info->clk);
+ kfree(info);
+ platform_set_drvdata(pdev, NULL);
+ return 0;
+}
+
+static struct platform_driver pxa_w1_driver = {
+ .driver = {
+ .name = "pxa3xx-w1",
+ .owner = THIS_MODULE,
+ },
+ .probe = pxa_w1_probe,
+ .remove = __devexit_p(pxa_w1_remove),
+};
+
+static int __init pxa_w1_base_init(void)
+{
+ return platform_driver_register(&pxa_w1_driver);
+}
+
+static void __exit pxa_w1_base_exit(void)
+{
+ platform_driver_unregister(&pxa_w1_driver);
+}
+
+module_init(pxa_w1_base_init);
+module_exit(pxa_w1_base_exit);
+
+MODULE_AUTHOR("Jett Zhou <[email protected]>");
+MODULE_DESCRIPTION("one wire driver for PXA");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pxa-w1");
--
1.5.6.5

2011-04-13 14:58:10

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 05/13] w1: add DS278x slave driver

Append DS278x slave driver.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Evgeniy Polyakov <[email protected]>
---
drivers/w1/slaves/Kconfig | 13 +++
drivers/w1/slaves/Makefile | 1 +
drivers/w1/slaves/w1_ds278x.c | 184 +++++++++++++++++++++++++++++++++++++++++
drivers/w1/w1_family.h | 3 +
4 files changed, 201 insertions(+), 0 deletions(-)
create mode 100644 drivers/w1/slaves/w1_ds278x.c

diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index f0c9096..d737aa9 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -61,6 +61,19 @@ config W1_SLAVE_DS2760

If you are unsure, say N.

+config W1_SLAVE_DS278x
+ tristate "Dallas 278x battery monitor chip"
+ depends on W1
+ help
+ If you enable this you will have the DS278x battery monitor
+ chip support.
+
+ The battery monitor chip is used in many batteries/devices
+ as the one who is responsible for charging/discharging/monitoring
+ Li+ batteries.
+
+ If you are unsure, say N.
+
config W1_SLAVE_BQ27000
tristate "BQ27000 slave support"
depends on W1
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
index 3c76350..bcc134b 100644
--- a/drivers/w1/slaves/Makefile
+++ b/drivers/w1/slaves/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_W1_SLAVE_DS2423) += w1_ds2423.o
obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o
obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o
obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o
+obj-$(CONFIG_W1_SLAVE_DS278x) += w1_ds278x.o
obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o
diff --git a/drivers/w1/slaves/w1_ds278x.c b/drivers/w1/slaves/w1_ds278x.c
new file mode 100644
index 0000000..9da94bb
--- /dev/null
+++ b/drivers/w1/slaves/w1_ds278x.c
@@ -0,0 +1,184 @@
+/*
+ * w1_ds278x.c - w1 family 27 (DS2780/DS2781) driver
+ *
+ * Copyright (c) Intel 2006 Stanley Cai <[email protected]>
+ * Copyright (c) Marvell 2007 Paul Shen <[email protected]>
+ *
+ * Modified from w1_ds2433 driver
+ *
+ * Copyright (c) 2005 Ben Gardner <[email protected]>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/device.h>
+#include <linux/types.h>
+#include <linux/delay.h>
+
+#include "../w1.h"
+#include "../w1_int.h"
+#include "../w1_family.h"
+
+#define W1_REG_SIZE 256
+
+#define W1_F27_READ_REG 0x69
+#define W1_F27_WRITE_REG 0x6C
+#define W1_F27_COPY_REG 0x48
+#define W1_F27_RECALL_REG 0xB8
+#define W1_F27_LOCK_REG 0x6A
+
+struct w1_f27_data {
+ u8 memory[W1_REG_SIZE];
+ u32 validcrc;
+};
+
+/**
+ * Check the file size bounds and adjusts count as needed.
+ * This would not be needed if the file size didn't reset to 0 after a write.
+ */
+static inline size_t w1_f27_fix_count(loff_t off, size_t count,
+ size_t size)
+{
+ if (off > size)
+ return 0;
+
+ if ((off + count) > size)
+ return (size - off);
+
+ return count;
+}
+
+static ssize_t w1_f27_read_bin(struct file *fp, struct kobject *kobj,
+ struct bin_attribute *bin_attr,
+ char *buf, loff_t off, size_t count)
+{
+ struct w1_slave *sl = kobj_to_w1_slave(kobj);
+ u8 wrbuf[2];
+
+ count = w1_f27_fix_count(off, count, W1_REG_SIZE);
+ if (count == 0)
+ return 0;
+
+ atomic_inc(&sl->refcnt);
+ mutex_lock(&sl->master->mutex);
+
+ /* read directly from the REG */
+ if (w1_reset_select_slave(sl)) {
+ count = -EIO;
+ goto out_mutex_unlock;
+ }
+
+ wrbuf[0] = W1_F27_READ_REG;
+ wrbuf[1] = off & 0xff;
+ w1_write_block(sl->master, wrbuf, 2);
+ w1_read_block(sl->master, buf, count);
+
+out_mutex_unlock:
+ mutex_unlock(&sl->master->mutex);
+ atomic_dec(&sl->refcnt);
+
+ return count;
+}
+
+static ssize_t w1_f27_write_bin(struct file *fp, struct kobject *kobj,
+ struct bin_attribute *bin_attr,
+ char *buf, loff_t off, size_t count)
+{
+ struct w1_slave *sl = kobj_to_w1_slave(kobj);
+ char wrbuf[2];
+
+ count = w1_f27_fix_count(off, count, W1_REG_SIZE);
+ if (count == 0)
+ return 0;
+
+ atomic_inc(&sl->refcnt);
+ mutex_lock(&sl->master->mutex);
+
+ if (w1_reset_select_slave(sl)) {
+ count = -EIO;
+ goto out_mutex_unlock;
+ }
+
+ wrbuf[0] = W1_F27_WRITE_REG;
+ wrbuf[1] = off & 0xff;
+ w1_write_block(sl->master, wrbuf, 2);
+ w1_write_block(sl->master, buf, count);
+
+out_mutex_unlock:
+ mutex_unlock(&sl->master->mutex);
+ atomic_dec(&sl->refcnt);
+
+ return count;
+}
+
+static struct bin_attribute w1_f27_bin_attr = {
+ .attr = {
+ .name = "registers",
+ .mode = S_IRUGO | S_IWUSR,
+ },
+ .size = W1_REG_SIZE,
+ .read = w1_f27_read_bin,
+ .write = w1_f27_write_bin,
+};
+
+static int w1_f27_add_slave(struct w1_slave *sl)
+{
+ int err;
+
+ err = sysfs_create_bin_file(&sl->dev.kobj, &w1_f27_bin_attr);
+
+ return err;
+}
+
+static void w1_f27_remove_slave(struct w1_slave *sl)
+{
+ sysfs_remove_bin_file(&sl->dev.kobj, &w1_f27_bin_attr);
+}
+
+static struct w1_family_ops w1_f27_fops = {
+ .add_slave = w1_f27_add_slave,
+ .remove_slave = w1_f27_remove_slave,
+};
+
+static struct w1_family w1_family_2780 = {
+ .fid = W1_BATTMON_DS2780,
+ .fops = &w1_f27_fops,
+};
+
+static struct w1_family w1_family_2781 = {
+ .fid = W1_BATTMON_DS2781,
+ .fops = &w1_f27_fops,
+};
+
+static struct w1_family w1_family_2783 = {
+ .fid = W1_BATTMON_DS2783,
+ .fops = &w1_f27_fops,
+};
+
+
+static int __init w1_f27_init(void)
+{
+ pr_info("1-Wire driver for the DS278x battery monitor...\n");
+ return (w1_register_family(&w1_family_2780) |
+ w1_register_family(&w1_family_2781) |
+ w1_register_family(&w1_family_2783));
+}
+
+static void __exit w1_f27_fini(void)
+{
+ w1_unregister_family(&w1_family_2781);
+ w1_unregister_family(&w1_family_2780);
+ w1_unregister_family(&w1_family_2783);
+}
+
+module_init(w1_f27_init);
+module_exit(w1_f27_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Paul Shen <[email protected]>");
+MODULE_DESCRIPTION("w1 family 27 driver for DS2780 & DS2781,"
+ " Stand-Alone Fuel Gauge IC");
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h
index f3b636d..0f0b58c 100644
--- a/drivers/w1/w1_family.h
+++ b/drivers/w1/w1_family.h
@@ -36,6 +36,9 @@
#define W1_THERM_DS18B20 0x28
#define W1_EEPROM_DS2431 0x2D
#define W1_FAMILY_DS2760 0x30
+#define W1_BATTMON_DS2780 0x32
+#define W1_BATTMON_DS2781 0x3D
+#define W1_BATTMON_DS2783 0x34

#define MAXNAMELEN 32

--
1.5.6.5

2011-04-13 14:58:29

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 02/13] input: touchscreen: move initialization in 88pm860x

Move the GPADC initialization code from mfd driver to touch driver.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
---
drivers/input/touchscreen/88pm860x-ts.c | 44 +++++++++++++++++++++-----
drivers/mfd/88pm860x-core.c | 51 -------------------------------
2 files changed, 35 insertions(+), 60 deletions(-)

diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c
index fe12f61..d2e1451 100644
--- a/drivers/input/touchscreen/88pm860x-ts.c
+++ b/drivers/input/touchscreen/88pm860x-ts.c
@@ -14,6 +14,7 @@
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/input.h>
+#include <linux/mfd/core.h>
#include <linux/mfd/88pm860x.h>

#define MEAS_LEN (8)
@@ -154,11 +155,40 @@ static void pm860x_touch_close(struct input_dev *dev)
pm860x_set_bits(touch->i2c, MEAS_EN3, data, 0);
}

+static void __devinit pm860x_gpadc_init(struct i2c_client *i2c,
+ struct pm860x_touch_pdata *pdata)
+{
+ int data;
+
+ /* set GPADC MISC1 register */
+ data = 0;
+ data |= (pdata->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
+ data |= (pdata->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
+ data |= (pdata->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
+ data |= (pdata->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
+ if (data)
+ pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
+
+ /* set tsi prebias time */
+ if (pdata->tsi_prebias) {
+ data = pdata->tsi_prebias;
+ pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
+ }
+
+ /* set prebias & prechg time of pen detect */
+ data = 0;
+ data |= pdata->pen_prebias & PM8607_PD_PREBIAS_MASK;
+ data |= (pdata->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
+ if (data)
+ pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
+
+ pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
+ PM8607_GPADC_EN, PM8607_GPADC_EN);
+}
+
static int __devinit pm860x_touch_probe(struct platform_device *pdev)
{
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
- struct pm860x_platform_data *pm860x_pdata = \
- pdev->dev.parent->platform_data;
struct pm860x_touch_pdata *pdata = NULL;
struct pm860x_touch *touch;
int irq, ret;
@@ -169,13 +199,8 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev)
return -EINVAL;
}

- if (!pm860x_pdata) {
- dev_err(&pdev->dev, "platform data is missing\n");
- return -EINVAL;
- }
-
- pdata = pm860x_pdata->touch;
- if (!pdata) {
+ pdata = pdev->dev.platform_data;
+ if (pdata == NULL) {
dev_err(&pdev->dev, "touchscreen data is missing\n");
return -EINVAL;
}
@@ -229,6 +254,7 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev)
goto out_rg;
}

+ pm860x_gpadc_init(touch->i2c, pdata);
platform_set_drvdata(pdev, touch);
INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
return 0;
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 801aff7..b03cdd3 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -362,53 +362,6 @@ static struct irq_chip pm860x_irq_chip = {
.irq_disable = pm860x_irq_disable,
};

-static int __devinit device_gpadc_init(struct pm860x_chip *chip,
- struct pm860x_platform_data *pdata)
-{
- struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
- : chip->companion;
- int data;
- int ret;
-
- /* initialize GPADC without activating it */
-
- if (!pdata || !pdata->touch)
- return -EINVAL;
-
- /* set GPADC MISC1 register */
- data = 0;
- data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
- data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
- data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
- data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
- if (data) {
- ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
- if (ret < 0)
- goto out;
- }
- /* set tsi prebias time */
- if (pdata->touch->tsi_prebias) {
- data = pdata->touch->tsi_prebias;
- ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
- if (ret < 0)
- goto out;
- }
- /* set prebias & prechg time of pen detect */
- data = 0;
- data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
- data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
- if (data) {
- ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
- if (ret < 0)
- goto out;
- }
-
- ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
- PM8607_GPADC_EN, PM8607_GPADC_EN);
-out:
- return ret;
-}
-
static int __devinit device_irq_init(struct pm860x_chip *chip,
struct pm860x_platform_data *pdata)
{
@@ -761,10 +714,6 @@ static void __devinit device_8607_init(struct pm860x_chip *chip,
goto out;
}

- ret = device_gpadc_init(chip, pdata);
- if (ret < 0)
- goto out;
-
ret = device_irq_init(chip, pdata);
if (ret < 0)
goto out;
--
1.5.6.5

2011-04-13 15:04:31

by Anton Vorontsov

[permalink] [raw]
Subject: Re: [PATCH 11/13] power_supply: max8925: use platform_data from cell

On Wed, Apr 13, 2011 at 10:51:02PM +0800, Haojian Zhuang wrote:
> Avoid to get platform_data from parent device. Get it from mfd cell
> device instead.
>
> Signed-off-by: Haojian Zhuang <[email protected]>
> Cc: Anton Vorontsov <[email protected]>
> Cc: David Woodhouse <[email protected]>
> ---

I don't see the whole series, but I hope the patch doesn't break any
existing in-tree users of that driver?

> drivers/power/max8925_power.c | 16 +++++-----------
> 1 files changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
> index 8e5aec2..359c53c 100644
> --- a/drivers/power/max8925_power.c
> +++ b/drivers/power/max8925_power.c
> @@ -425,21 +425,16 @@ static __devexit int max8925_deinit_charger(struct max8925_power_info *info)
> static __devinit int max8925_power_probe(struct platform_device *pdev)
> {
> struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
> - struct max8925_platform_data *max8925_pdata;
> struct max8925_power_pdata *pdata = NULL;
> struct max8925_power_info *info;
> - int ret;
> -
> - if (pdev->dev.parent->platform_data) {
> - max8925_pdata = pdev->dev.parent->platform_data;
> - pdata = max8925_pdata->power;
> - }
> + int ret = -EINVAL;

I guess you don't need the initializer.

>
> - if (!pdata) {
> + pdata = pdev->dev.platform_data;
> + if (pdata == NULL) {

I'd prefer to keep '!pdata'.

> dev_err(&pdev->dev, "platform data isn't assigned to "
> "power supply\n");
> return -EINVAL;
> - }
> + };

No need for the semicolon.

>
> info = kzalloc(sizeof(struct max8925_power_info), GFP_KERNEL);
> if (!info)
> @@ -447,6 +442,7 @@ static __devinit int max8925_power_probe(struct platform_device *pdev)
> info->chip = chip;
> info->gpm = chip->i2c;
> info->adc = chip->adc;
> + dev_set_drvdata(&pdev->dev, info);

As this is a platform driver, you'd better do platform_set_drvdata(pdev, info),
not dev_set_drvdata(). In the end, it's the same thing.

>
> info->ac.name = "max8925-ac";
> info->ac.type = POWER_SUPPLY_TYPE_MAINS;
> @@ -482,8 +478,6 @@ static __devinit int max8925_power_probe(struct platform_device *pdev)
> info->topoff_threshold = pdata->topoff_threshold;
> info->fast_charge = pdata->fast_charge;
> info->set_charger = pdata->set_charger;
> - dev_set_drvdata(&pdev->dev, info);
> - platform_set_drvdata(pdev, info);
>
> max8925_init_charger(chip, info);
> return 0;

Thanks,

--
Anton Vorontsov
Email: [email protected]

2011-04-14 02:21:18

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 11/13] power_supply: max8925: use platform_data from cell

Avoid to get platform_data from parent device. Get it from mfd cell
device instead.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
---
drivers/power/max8925_power.c | 10 ++--------
1 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
index 8e5aec2..a70e16d 100644
--- a/drivers/power/max8925_power.c
+++ b/drivers/power/max8925_power.c
@@ -425,16 +425,11 @@ static __devexit int max8925_deinit_charger(struct max8925_power_info *info)
static __devinit int max8925_power_probe(struct platform_device *pdev)
{
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
- struct max8925_platform_data *max8925_pdata;
struct max8925_power_pdata *pdata = NULL;
struct max8925_power_info *info;
int ret;

- if (pdev->dev.parent->platform_data) {
- max8925_pdata = pdev->dev.parent->platform_data;
- pdata = max8925_pdata->power;
- }
-
+ pdata = pdev->dev.platform_data;
if (!pdata) {
dev_err(&pdev->dev, "platform data isn't assigned to "
"power supply\n");
@@ -447,6 +442,7 @@ static __devinit int max8925_power_probe(struct platform_device *pdev)
info->chip = chip;
info->gpm = chip->i2c;
info->adc = chip->adc;
+ platform_set_drvdata(pdev, info);

info->ac.name = "max8925-ac";
info->ac.type = POWER_SUPPLY_TYPE_MAINS;
@@ -482,8 +478,6 @@ static __devinit int max8925_power_probe(struct platform_device *pdev)
info->topoff_threshold = pdata->topoff_threshold;
info->fast_charge = pdata->fast_charge;
info->set_charger = pdata->set_charger;
- dev_set_drvdata(&pdev->dev, info);
- platform_set_drvdata(pdev, info);

max8925_init_charger(chip, info);
return 0;
--
1.5.6.5

2011-04-14 02:30:41

by Haojian Zhuang

[permalink] [raw]
Subject: RE: [PATCH 11/13] power_supply: max8925: use platform_data from cell



>-----Original Message-----
>From: Anton Vorontsov [mailto:[email protected]]
>Sent: 2011年4月13日 11:03 PM
>To: Haojian Zhuang
>Cc: [email protected]; [email protected]; linux-
>[email protected]; David Woodhouse
>Subject: Re: [PATCH 11/13] power_supply: max8925: use platform_data from
>cell
>
>On Wed, Apr 13, 2011 at 10:51:02PM +0800, Haojian Zhuang wrote:
>> Avoid to get platform_data from parent device. Get it from mfd cell
>> device instead.
>>
>> Signed-off-by: Haojian Zhuang <[email protected]>
>> Cc: Anton Vorontsov <[email protected]>
>> Cc: David Woodhouse <[email protected]>
>> ---
>
>I don't see the whole series, but I hope the patch doesn't break any
>existing in-tree users of that driver?
>
Excuse me for not include you in the whole series. I checked that it won't
break existing code.

The fix for this patch is already sent. Please help to review.

>> drivers/power/max8925_power.c | 16 +++++-----------
>> 1 files changed, 5 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/power/max8925_power.c
>b/drivers/power/max8925_power.c
>> index 8e5aec2..359c53c 100644
>> --- a/drivers/power/max8925_power.c
>> +++ b/drivers/power/max8925_power.c
>> @@ -425,21 +425,16 @@ static __devexit int
>max8925_deinit_charger(struct max8925_power_info *info)
>> static __devinit int max8925_power_probe(struct platform_device *pdev)
>> {
>> struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
>> - struct max8925_platform_data *max8925_pdata;
>> struct max8925_power_pdata *pdata = NULL;
>> struct max8925_power_info *info;
>> - int ret;
>> -
>> - if (pdev->dev.parent->platform_data) {
>> - max8925_pdata = pdev->dev.parent->platform_data;
>> - pdata = max8925_pdata->power;
>> - }
>> + int ret = -EINVAL;
>
>I guess you don't need the initializer.
>
OK

>>
>> - if (!pdata) {
>> + pdata = pdev->dev.platform_data;
>> + if (pdata == NULL) {
>
>I'd prefer to keep '!pdata'.
>
OK

>> dev_err(&pdev->dev, "platform data isn't assigned to "
>> "power supply\n");
>> return -EINVAL;
>> - }
>> + };
>
>No need for the semicolon.
OK

>
>>
>> info = kzalloc(sizeof(struct max8925_power_info), GFP_KERNEL);
>> if (!info)
>> @@ -447,6 +442,7 @@ static __devinit int max8925_power_probe(struct
>platform_device *pdev)
>> info->chip = chip;
>> info->gpm = chip->i2c;
>> info->adc = chip->adc;
>> + dev_set_drvdata(&pdev->dev, info);
>
>As this is a platform driver, you'd better do platform_set_drvdata(pdev,
>info),
>not dev_set_drvdata(). In the end, it's the same thing.
>
Got it.

>>
>> info->ac.name = "max8925-ac";
>> info->ac.type = POWER_SUPPLY_TYPE_MAINS;
>> @@ -482,8 +478,6 @@ static __devinit int max8925_power_probe(struct
>platform_device *pdev)
>> info->topoff_threshold = pdata->topoff_threshold;
>> info->fast_charge = pdata->fast_charge;
>> info->set_charger = pdata->set_charger;
>> - dev_set_drvdata(&pdev->dev, info);
>> - platform_set_drvdata(pdev, info);
>>
>> max8925_init_charger(chip, info);
>> return 0;
>
>Thanks,
>
>--
>Anton Vorontsov
>Email: [email protected]
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2011-04-14 14:02:26

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x

On 4/13/11, Haojian Zhuang <[email protected]> wrote:
> Measuring point on touchscreen with IRQ mode can only monitor pen-down
> event. If finger is moving on touchscreen, it can't be monitored by
> IRQ pen-down event. So switch to polling mode after pen-down event.
>
> Signed-off-by: Haojian Zhuang <[email protected]>
> Cc: Dmitry Torokhov <[email protected]>
> ---
> drivers/input/touchscreen/88pm860x-ts.c | 82
> +++++++++++++++++++++++-------
> 1 files changed, 63 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/input/touchscreen/88pm860x-ts.c
> b/drivers/input/touchscreen/88pm860x-ts.c
> index b3aebc2..fe12f61 100644
> --- a/drivers/input/touchscreen/88pm860x-ts.c
> +++ b/drivers/input/touchscreen/88pm860x-ts.c
> @@ -12,13 +12,25 @@
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/i2c.h>
> +#include <linux/slab.h>
> #include <linux/input.h>
> #include <linux/mfd/88pm860x.h>
> -#include <linux/slab.h>
>
> #define MEAS_LEN (8)
> #define ACCURATE_BIT (12)
>
> +/*
> + * While 32KHz hardware timer is used for scheduler, we always assign HZ
> + * to 128. It means that 1 tick costs 7.8msec.
> + */
> +#define MEASURE_INTERVAL_MS (7)
> +
> +/* debounce register */
> +#define DEBOUNCE (0x0A)
> +
> +#define PD_DEBOUNCE_0MSEC (0)
> +#define PD_DEBOUNCE_MASK (3)
> +
> /* touch register */
> #define MEAS_EN3 (0x52)
>
> @@ -39,22 +51,27 @@
> #define MEAS_TSIZ2_EN (1 << 7)
>
> struct pm860x_touch {
> - struct input_dev *idev;
> - struct i2c_client *i2c;
> - struct pm860x_chip *chip;
> - int irq;
> - int res_x; /* resistor of Xplate */
> + struct input_dev *idev;
> + struct i2c_client *i2c;
> + struct pm860x_chip *chip;
> + struct delayed_work poll_work;
> + struct mutex lock;
> +
> + int irq;
> + int res_x; /* resistor of Xplate */
> };
>
> -static irqreturn_t pm860x_touch_handler(int irq, void *data)
> +static void pm860x_poll_work(struct work_struct *work)
> {
> - struct pm860x_touch *touch = data;
> + struct pm860x_touch *touch = container_of(work, struct pm860x_touch,
> + poll_work.work);
> struct pm860x_chip *chip = touch->chip;
> + int x, y, z1, z2, rt = 0;
> + int ret, pen_down, interval;
> unsigned char buf[MEAS_LEN];
> - int x, y, pen_down;
> - int z1, z2, rt = 0;
> - int ret;
> + struct timeval start, end;
>
> + do_gettimeofday(&start);
> ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
> if (ret < 0)
> goto out;
> @@ -77,30 +94,54 @@ static irqreturn_t pm860x_touch_handler(int irq, void
> *data)
> input_report_abs(touch->idev, ABS_PRESSURE, rt);
> input_report_key(touch->idev, BTN_TOUCH, 1);
> dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
> +
> + do_gettimeofday(&end);
> + interval = (end.tv_sec - start.tv_sec) * 1000000 +
> + (end.tv_usec - start.tv_usec) / 1000;
Is the interval you calibrated right ?
> + interval = (interval < MEASURE_INTERVAL_MS)
> + ? (MEASURE_INTERVAL_MS - interval) : 0;
> + schedule_delayed_work(&touch->poll_work,
> + msecs_to_jiffies(interval));
> } else {
> input_report_abs(touch->idev, ABS_PRESSURE, 0);
> input_report_key(touch->idev, BTN_TOUCH, 0);
> dev_dbg(chip->dev, "pen release\n");
> + mutex_unlock(&touch->lock);
> }
> input_sync(touch->idev);
>
> out:
> + return;
> +}
> +
> +static irqreturn_t pm860x_touch_handler(int irq, void *data)
> +{
> + struct pm860x_touch *touch = data;
> + int ret;
> +
> + ret = pm860x_reg_read(touch->i2c, PM8607_STATUS_1);
> + dev_dbg(touch->chip->dev, "pen status:%d\n", (ret & PM8607_STATUS_PEN)
> + ? 1 : 0);
> + if ((ret & PM8607_STATUS_PEN) == 0)
prefer to !(ret & PM8607_STATUS_PEN) ?
> + return IRQ_HANDLED;
> +
> + mutex_lock(&touch->lock);
> + pm860x_poll_work(&touch->poll_work.work);
> return IRQ_HANDLED;
> }
>
> static int pm860x_touch_open(struct input_dev *dev)
> {
> struct pm860x_touch *touch = input_get_drvdata(dev);
> - int data, ret;
> + int data;
>
> + /* set debounce time with 0ms */
> + pm860x_set_bits(touch->i2c, DEBOUNCE, PD_DEBOUNCE_MASK,
> + PD_DEBOUNCE_0MSEC);
> data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
> | MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
> - ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
> - if (ret < 0)
> - goto out;
> + pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
Why not check the return value now ?
> return 0;
> -out:
> - return ret;
> }
>
> static void pm860x_touch_close(struct input_dev *dev)
> @@ -152,16 +193,17 @@ static int __devinit pm860x_touch_probe(struct
> platform_device *pdev)
> }
>
> touch->idev->name = "88pm860x-touch";
> - touch->idev->phys = "88pm860x/input0";
> + touch->idev->phys = "88pm860x/input1";
> touch->idev->id.bustype = BUS_I2C;
> touch->idev->dev.parent = &pdev->dev;
> touch->idev->open = pm860x_touch_open;
> touch->idev->close = pm860x_touch_close;
> touch->chip = chip;
> touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
> - touch->irq = irq + chip->irq_base;
> + touch->irq = irq;
> touch->res_x = pdata->res_x;
> input_set_drvdata(touch->idev, touch);
> + mutex_init(&touch->lock);
>
> ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
> IRQF_ONESHOT, "touch", touch);
> @@ -188,6 +230,7 @@ static int __devinit pm860x_touch_probe(struct
> platform_device *pdev)
> }
>
> platform_set_drvdata(pdev, touch);
> + INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
> return 0;
> out_rg:
> free_irq(touch->irq, touch);
> @@ -202,6 +245,7 @@ static int __devexit pm860x_touch_remove(struct
> platform_device *pdev)
> {
> struct pm860x_touch *touch = platform_get_drvdata(pdev);
>
> + flush_scheduled_work();
> input_unregister_device(touch->idev);
> free_irq(touch->irq, touch);
> platform_set_drvdata(pdev, NULL);
> --
> 1.5.6.5
>
Best regards
Thanks
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-04-14 14:17:57

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 06/13] mfd: pxa-w1: MFD driver for PXA 1wire control + DS1WM chip

On 4/13/11, Haojian Zhuang <[email protected]> wrote:
> This driver provides registers and IRQ of PXA3xx chips to the ds1wm driver.
>
> Signed-off-by: Haojian Zhuang <[email protected]>
> Cc: Evgeniy Polyakov <[email protected]>
> ---
> drivers/mfd/Kconfig | 7 ++
> drivers/mfd/Makefile | 1 +
> drivers/mfd/pxa-w1.c | 150
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 158 insertions(+), 0 deletions(-)
> create mode 100644 drivers/mfd/pxa-w1.c
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index e2fea58..b6ecf90 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -34,6 +34,13 @@ config MFD_88PM860X
> select individual components like voltage regulators, RTC and
> battery-charger under the corresponding menus.
>
> +config MFD_PXA_DS1WM
> + tristate "Support DS1WM chip on Marvell silicons"
> + select MFD_CORE
> + help
> + This core driver provides register access for PXA_DS1WM.
> + Actual functionality is handled by the ds1wm drivers.
> +
> config MFD_SM501
> tristate "Support for Silicon Motion SM501"
> ---help---
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 419caa9..4f8d1d2 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -4,6 +4,7 @@
>
> 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o
> obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o
> +obj-$(CONFIG_MFD_PXA_DS1WM) += pxa-w1.o
> obj-$(CONFIG_MFD_SM501) += sm501.o
> obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
>
> diff --git a/drivers/mfd/pxa-w1.c b/drivers/mfd/pxa-w1.c
> new file mode 100644
> index 0000000..98074ff
> --- /dev/null
> +++ b/drivers/mfd/pxa-w1.c
> @@ -0,0 +1,150 @@
> +/*
> + * Core driver for PXA DS1WM chip.
> + *
> + * Copyright (C) 2010 Marvell <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + */
> +
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/platform_device.h>
> +#include <linux/gpio.h>
> +#include <linux/io.h>
> +#include <linux/irq.h>
> +#include <linux/clk.h>
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/ds1wm.h>
> +
> +struct pxa_w1_info {
> + struct clk *clk;
> +};
> +
> +static int ds1wm_enable(struct platform_device *pdev)
> +{
> + struct device *dev = pdev->dev.parent;
> + struct pxa_w1_info *info = dev_get_drvdata(dev);
> +
> + clk_enable(info->clk);
> + dev_dbg(dev, "pxa DS1WM clk (active)\n");
> + return 0;
> +}
> +
> +static int ds1wm_disable(struct platform_device *pdev)
> +{
> + struct device *dev = pdev->dev.parent;
> + struct pxa_w1_info *info = dev_get_drvdata(dev);
> +
> + clk_disable(info->clk);
> + dev_dbg(dev, "pxa DS1WM clk (in-active)\n");
> + return 0;
> +}
> +
> +static struct resource ds1wm_resources[] __devinitdata = {
> + {0, 0, "ds1wm-mem", IORESOURCE_MEM,},
> + {0, 0, "ds1wm-irq", IORESOURCE_IRQ,},
> +};
> +
> +static struct ds1wm_driver_data ds1wm_pdata;
> +
> +static struct mfd_cell ds1wm_cell __devinitdata = {
> + .name = "ds1wm",
> + .enable = ds1wm_enable,
> + .disable = ds1wm_disable,
> + .platform_data = &ds1wm_pdata,
> + .pdata_size = sizeof(ds1wm_pdata),
> + .num_resources = ARRAY_SIZE(ds1wm_resources),
> + .resources = ds1wm_resources,
> +};
> +
> +static int __devinit pxa_w1_probe(struct platform_device *pdev)
> +{
> + struct ds1wm_driver_data *pdata = pdev->dev.platform_data;
> + struct pxa_w1_info *info;
> + struct resource *r;
> + int ret, irq;
> +
> + info = kzalloc(sizeof(struct pxa_w1_info), GFP_KERNEL);
> + if (!info)
> + return -ENOMEM;
> +
> + r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> + if (r == NULL) {
Prefer to (!r) ?
> + ret = -ENXIO;
> + goto out;
> + }
> + irq = r->start;
> + if (pdata)
> + ds1wm_pdata.active_high = pdata->active_high;
> + if (ds1wm_pdata.active_high)
> + ds1wm_resources[1].flags |= IORESOURCE_IRQ_HIGHEDGE;
> + else
> + ds1wm_resources[1].flags |= IORESOURCE_IRQ_LOWEDGE;
> +
> + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (r == NULL) {
The same ?
> + ret = -ENXIO;
> + goto out;
> + }
> + ds1wm_resources[0].end = resource_size(r) - 1;
> +
> + info->clk = clk_get(&pdev->dev, NULL);
> + if (IS_ERR(info->clk)) {
> + ret = PTR_ERR(info->clk);
> + goto out;
> + }
> + platform_set_drvdata(pdev, info);
> +
> + ds1wm_pdata.clock_rate = clk_get_rate(info->clk);
> + ret = mfd_add_devices(&pdev->dev, pdev->id, &ds1wm_cell, 1, r, irq);
> + if (ret < 0)
> + dev_err(&pdev->dev, "failed to register pxa DS1WM\n");
> +
> + return 0;
> +out:
> + kfree(info);
> + return ret;
> +}
> +
> +static int __devexit pxa_w1_remove(struct platform_device *pdev)
> +{
> + struct pxa_w1_info *info = platform_get_drvdata(pdev);
> +
> + mfd_remove_devices(&pdev->dev);
> + clk_put(info->clk);
> + kfree(info);
> + platform_set_drvdata(pdev, NULL);
> + return 0;
> +}
> +
> +static struct platform_driver pxa_w1_driver = {
> + .driver = {
> + .name = "pxa3xx-w1",
> + .owner = THIS_MODULE,
> + },
> + .probe = pxa_w1_probe,
> + .remove = __devexit_p(pxa_w1_remove),
> +};
> +
> +static int __init pxa_w1_base_init(void)
> +{
> + return platform_driver_register(&pxa_w1_driver);
> +}
> +
> +static void __exit pxa_w1_base_exit(void)
> +{
> + platform_driver_unregister(&pxa_w1_driver);
> +}
> +
> +module_init(pxa_w1_base_init);
> +module_exit(pxa_w1_base_exit);
> +
> +MODULE_AUTHOR("Jett Zhou <[email protected]>");
> +MODULE_DESCRIPTION("one wire driver for PXA");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:pxa-w1");

Best regards ,
Thanks
> --
> 1.5.6.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-04-14 14:22:20

by Haojian Zhuang

[permalink] [raw]
Subject: RE: [PATCH 06/13] mfd: pxa-w1: MFD driver for PXA 1wire control + DS1WM chip



>-----Original Message-----
>From: [email protected] [mailto:[email protected]] On Behalf Of
>Wanlong Gao
>Sent: 2011??4??14?? 10:18 PM
>To: Haojian Zhuang
>Cc: [email protected]; [email protected]; linux-
>[email protected]; Evgeniy Polyakov
>Subject: Re: [PATCH 06/13] mfd: pxa-w1: MFD driver for PXA 1wire control
>+ DS1WM chip
>
>On 4/13/11, Haojian Zhuang <[email protected]> wrote:
>> This driver provides registers and IRQ of PXA3xx chips to the ds1wm
>driver.
>>
>> Signed-off-by: Haojian Zhuang <[email protected]>
>> Cc: Evgeniy Polyakov <[email protected]>
>> ---
>> drivers/mfd/Kconfig | 7 ++
>> drivers/mfd/Makefile | 1 +
>> drivers/mfd/pxa-w1.c | 150
>> ++++++++++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 158 insertions(+), 0 deletions(-)
>> create mode 100644 drivers/mfd/pxa-w1.c
>>
>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>> index e2fea58..b6ecf90 100644
>> --- a/drivers/mfd/Kconfig
>> +++ b/drivers/mfd/Kconfig
>> @@ -34,6 +34,13 @@ config MFD_88PM860X
>> select individual components like voltage regulators, RTC and
>> battery-charger under the corresponding menus.
>>
>> +config MFD_PXA_DS1WM
>> + tristate "Support DS1WM chip on Marvell silicons"
>> + select MFD_CORE
>> + help
>> + This core driver provides register access for PXA_DS1WM.
>> + Actual functionality is handled by the ds1wm drivers.
>> +
>> config MFD_SM501
>> tristate "Support for Silicon Motion SM501"
>> ---help---
>> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
>> index 419caa9..4f8d1d2 100644
>> --- a/drivers/mfd/Makefile
>> +++ b/drivers/mfd/Makefile
>> @@ -4,6 +4,7 @@
>>
>> 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o
>> obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o
>> +obj-$(CONFIG_MFD_PXA_DS1WM) += pxa-w1.o
>> obj-$(CONFIG_MFD_SM501) += sm501.o
>> obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
>>
>> diff --git a/drivers/mfd/pxa-w1.c b/drivers/mfd/pxa-w1.c
>> new file mode 100644
>> index 0000000..98074ff
>> --- /dev/null
>> +++ b/drivers/mfd/pxa-w1.c
>> @@ -0,0 +1,150 @@
>> +/*
>> + * Core driver for PXA DS1WM chip.
>> + *
>> + * Copyright (C) 2010 Marvell <[email protected]>
>> + *
>> + * This program is free software; you can redistribute it and/or
>modify
>> + * it under the terms of the GNU General Public License as published
>by
>> + * the Free Software Foundation; version 2 of the License.
>> + */
>> +
>> +#include <linux/init.h>
>> +#include <linux/module.h>
>> +#include <linux/slab.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/gpio.h>
>> +#include <linux/io.h>
>> +#include <linux/irq.h>
>> +#include <linux/clk.h>
>> +#include <linux/err.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/mfd/core.h>
>> +#include <linux/mfd/ds1wm.h>
>> +
>> +struct pxa_w1_info {
>> + struct clk *clk;
>> +};
>> +
>> +static int ds1wm_enable(struct platform_device *pdev)
>> +{
>> + struct device *dev = pdev->dev.parent;
>> + struct pxa_w1_info *info = dev_get_drvdata(dev);
>> +
>> + clk_enable(info->clk);
>> + dev_dbg(dev, "pxa DS1WM clk (active)\n");
>> + return 0;
>> +}
>> +
>> +static int ds1wm_disable(struct platform_device *pdev)
>> +{
>> + struct device *dev = pdev->dev.parent;
>> + struct pxa_w1_info *info = dev_get_drvdata(dev);
>> +
>> + clk_disable(info->clk);
>> + dev_dbg(dev, "pxa DS1WM clk (in-active)\n");
>> + return 0;
>> +}
>> +
>> +static struct resource ds1wm_resources[] __devinitdata = {
>> + {0, 0, "ds1wm-mem", IORESOURCE_MEM,},
>> + {0, 0, "ds1wm-irq", IORESOURCE_IRQ,},
>> +};
>> +
>> +static struct ds1wm_driver_data ds1wm_pdata;
>> +
>> +static struct mfd_cell ds1wm_cell __devinitdata = {
>> + .name = "ds1wm",
>> + .enable = ds1wm_enable,
>> + .disable = ds1wm_disable,
>> + .platform_data = &ds1wm_pdata,
>> + .pdata_size = sizeof(ds1wm_pdata),
>> + .num_resources = ARRAY_SIZE(ds1wm_resources),
>> + .resources = ds1wm_resources,
>> +};
>> +
>> +static int __devinit pxa_w1_probe(struct platform_device *pdev)
>> +{
>> + struct ds1wm_driver_data *pdata = pdev->dev.platform_data;
>> + struct pxa_w1_info *info;
>> + struct resource *r;
>> + int ret, irq;
>> +
>> + info = kzalloc(sizeof(struct pxa_w1_info), GFP_KERNEL);
>> + if (!info)
>> + return -ENOMEM;
>> +
>> + r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>> + if (r == NULL) {
>Prefer to (!r) ?

Why do you always stick to use !r? I like to use NULL since it's clear to me.

>> + ret = -ENXIO;
>> + goto out;
>> + }
>> + irq = r->start;
>> + if (pdata)
>> + ds1wm_pdata.active_high = pdata->active_high;
>> + if (ds1wm_pdata.active_high)
>> + ds1wm_resources[1].flags |= IORESOURCE_IRQ_HIGHEDGE;
>> + else
>> + ds1wm_resources[1].flags |= IORESOURCE_IRQ_LOWEDGE;
>> +
>> + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> + if (r == NULL) {
>The same ?
>> + ret = -ENXIO;
>> + goto out;
>> + }
>> + ds1wm_resources[0].end = resource_size(r) - 1;
>> +
>> + info->clk = clk_get(&pdev->dev, NULL);
>> + if (IS_ERR(info->clk)) {
>> + ret = PTR_ERR(info->clk);
>> + goto out;
>> + }
>> + platform_set_drvdata(pdev, info);
>> +
>> + ds1wm_pdata.clock_rate = clk_get_rate(info->clk);
>> + ret = mfd_add_devices(&pdev->dev, pdev->id, &ds1wm_cell, 1, r,
>irq);
>> + if (ret < 0)
>> + dev_err(&pdev->dev, "failed to register pxa DS1WM\n");
>> +
>> + return 0;
>> +out:
>> + kfree(info);
>> + return ret;
>> +}
>> +
>> +static int __devexit pxa_w1_remove(struct platform_device *pdev)
>> +{
>> + struct pxa_w1_info *info = platform_get_drvdata(pdev);
>> +
>> + mfd_remove_devices(&pdev->dev);
>> + clk_put(info->clk);
>> + kfree(info);
>> + platform_set_drvdata(pdev, NULL);
>> + return 0;
>> +}
>> +
>> +static struct platform_driver pxa_w1_driver = {
>> + .driver = {
>> + .name = "pxa3xx-w1",
>> + .owner = THIS_MODULE,
>> + },
>> + .probe = pxa_w1_probe,
>> + .remove = __devexit_p(pxa_w1_remove),
>> +};
>> +
>> +static int __init pxa_w1_base_init(void)
>> +{
>> + return platform_driver_register(&pxa_w1_driver);
>> +}
>> +
>> +static void __exit pxa_w1_base_exit(void)
>> +{
>> + platform_driver_unregister(&pxa_w1_driver);
>> +}
>> +
>> +module_init(pxa_w1_base_init);
>> +module_exit(pxa_w1_base_exit);
>> +
>> +MODULE_AUTHOR("Jett Zhou <[email protected]>");
>> +MODULE_DESCRIPTION("one wire driver for PXA");
>> +MODULE_LICENSE("GPL");
>> +MODULE_ALIAS("platform:pxa-w1");
>
>Best regards ,
>Thanks
>> --
>> 1.5.6.5
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-
>kernel" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>>
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2011-04-14 14:29:33

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 06/13] mfd: pxa-w1: MFD driver for PXA 1wire control + DS1WM chip

?? 2011-4-14 22:21, Haojian Zhuang д??:
>
>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On Behalf Of
>> Wanlong Gao
>> Sent: 2011??4??14?? 10:18 PM
>> To: Haojian Zhuang
>> Cc: [email protected]; [email protected]; linux-
>> [email protected]; Evgeniy Polyakov
>> Subject: Re: [PATCH 06/13] mfd: pxa-w1: MFD driver for PXA 1wire control
>> + DS1WM chip
>>
>> On 4/13/11, Haojian Zhuang<[email protected]> wrote:
>>> This driver provides registers and IRQ of PXA3xx chips to the ds1wm
>> driver.
>>>
>>> Signed-off-by: Haojian Zhuang<[email protected]>
>>> Cc: Evgeniy Polyakov<[email protected]>
>>> ---
>>> drivers/mfd/Kconfig | 7 ++
>>> drivers/mfd/Makefile | 1 +
>>> drivers/mfd/pxa-w1.c | 150
>>> ++++++++++++++++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 158 insertions(+), 0 deletions(-)
>>> create mode 100644 drivers/mfd/pxa-w1.c
>>>
>>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>>> index e2fea58..b6ecf90 100644
>>> --- a/drivers/mfd/Kconfig
>>> +++ b/drivers/mfd/Kconfig
>>> @@ -34,6 +34,13 @@ config MFD_88PM860X
>>> select individual components like voltage regulators, RTC and
>>> battery-charger under the corresponding menus.
>>>
>>> +config MFD_PXA_DS1WM
>>> + tristate "Support DS1WM chip on Marvell silicons"
>>> + select MFD_CORE
>>> + help
>>> + This core driver provides register access for PXA_DS1WM.
>>> + Actual functionality is handled by the ds1wm drivers.
>>> +
>>> config MFD_SM501
>>> tristate "Support for Silicon Motion SM501"
>>> ---help---
>>> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
>>> index 419caa9..4f8d1d2 100644
>>> --- a/drivers/mfd/Makefile
>>> +++ b/drivers/mfd/Makefile
>>> @@ -4,6 +4,7 @@
>>>
>>> 88pm860x-objs := 88pm860x-core.o 88pm860x-i2c.o
>>> obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o
>>> +obj-$(CONFIG_MFD_PXA_DS1WM) += pxa-w1.o
>>> obj-$(CONFIG_MFD_SM501) += sm501.o
>>> obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
>>>
>>> diff --git a/drivers/mfd/pxa-w1.c b/drivers/mfd/pxa-w1.c
>>> new file mode 100644
>>> index 0000000..98074ff
>>> --- /dev/null
>>> +++ b/drivers/mfd/pxa-w1.c
>>> @@ -0,0 +1,150 @@
>>> +/*
>>> + * Core driver for PXA DS1WM chip.
>>> + *
>>> + * Copyright (C) 2010 Marvell<[email protected]>
>>> + *
>>> + * This program is free software; you can redistribute it and/or
>> modify
>>> + * it under the terms of the GNU General Public License as published
>> by
>>> + * the Free Software Foundation; version 2 of the License.
>>> + */
>>> +
>>> +#include<linux/init.h>
>>> +#include<linux/module.h>
>>> +#include<linux/slab.h>
>>> +#include<linux/platform_device.h>
>>> +#include<linux/gpio.h>
>>> +#include<linux/io.h>
>>> +#include<linux/irq.h>
>>> +#include<linux/clk.h>
>>> +#include<linux/err.h>
>>> +#include<linux/interrupt.h>
>>> +#include<linux/mfd/core.h>
>>> +#include<linux/mfd/ds1wm.h>
>>> +
>>> +struct pxa_w1_info {
>>> + struct clk *clk;
>>> +};
>>> +
>>> +static int ds1wm_enable(struct platform_device *pdev)
>>> +{
>>> + struct device *dev = pdev->dev.parent;
>>> + struct pxa_w1_info *info = dev_get_drvdata(dev);
>>> +
>>> + clk_enable(info->clk);
>>> + dev_dbg(dev, "pxa DS1WM clk (active)\n");
>>> + return 0;
>>> +}
>>> +
>>> +static int ds1wm_disable(struct platform_device *pdev)
>>> +{
>>> + struct device *dev = pdev->dev.parent;
>>> + struct pxa_w1_info *info = dev_get_drvdata(dev);
>>> +
>>> + clk_disable(info->clk);
>>> + dev_dbg(dev, "pxa DS1WM clk (in-active)\n");
>>> + return 0;
>>> +}
>>> +
>>> +static struct resource ds1wm_resources[] __devinitdata = {
>>> + {0, 0, "ds1wm-mem", IORESOURCE_MEM,},
>>> + {0, 0, "ds1wm-irq", IORESOURCE_IRQ,},
>>> +};
>>> +
>>> +static struct ds1wm_driver_data ds1wm_pdata;
>>> +
>>> +static struct mfd_cell ds1wm_cell __devinitdata = {
>>> + .name = "ds1wm",
>>> + .enable = ds1wm_enable,
>>> + .disable = ds1wm_disable,
>>> + .platform_data =&ds1wm_pdata,
>>> + .pdata_size = sizeof(ds1wm_pdata),
>>> + .num_resources = ARRAY_SIZE(ds1wm_resources),
>>> + .resources = ds1wm_resources,
>>> +};
>>> +
>>> +static int __devinit pxa_w1_probe(struct platform_device *pdev)
>>> +{
>>> + struct ds1wm_driver_data *pdata = pdev->dev.platform_data;
>>> + struct pxa_w1_info *info;
>>> + struct resource *r;
>>> + int ret, irq;
>>> +
>>> + info = kzalloc(sizeof(struct pxa_w1_info), GFP_KERNEL);
>>> + if (!info)
>>> + return -ENOMEM;
>>> +
>>> + r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>>> + if (r == NULL) {
>> Prefer to (!r) ?
>
> Why do you always stick to use !r? I like to use NULL since it's clear to me.
>
Use your habits and I just make a noise .
Thanks


>>> + ret = -ENXIO;
>>> + goto out;
>>> + }
>>> + irq = r->start;
>>> + if (pdata)
>>> + ds1wm_pdata.active_high = pdata->active_high;
>>> + if (ds1wm_pdata.active_high)
>>> + ds1wm_resources[1].flags |= IORESOURCE_IRQ_HIGHEDGE;
>>> + else
>>> + ds1wm_resources[1].flags |= IORESOURCE_IRQ_LOWEDGE;
>>> +
>>> + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>> + if (r == NULL) {
>> The same ?
>>> + ret = -ENXIO;
>>> + goto out;
>>> + }
>>> + ds1wm_resources[0].end = resource_size(r) - 1;
>>> +
>>> + info->clk = clk_get(&pdev->dev, NULL);
>>> + if (IS_ERR(info->clk)) {
>>> + ret = PTR_ERR(info->clk);
>>> + goto out;
>>> + }
>>> + platform_set_drvdata(pdev, info);
>>> +
>>> + ds1wm_pdata.clock_rate = clk_get_rate(info->clk);
>>> + ret = mfd_add_devices(&pdev->dev, pdev->id,&ds1wm_cell, 1, r,
>> irq);
>>> + if (ret< 0)
>>> + dev_err(&pdev->dev, "failed to register pxa DS1WM\n");
>>> +
>>> + return 0;
>>> +out:
>>> + kfree(info);
>>> + return ret;
>>> +}
>>> +
>>> +static int __devexit pxa_w1_remove(struct platform_device *pdev)
>>> +{
>>> + struct pxa_w1_info *info = platform_get_drvdata(pdev);
>>> +
>>> + mfd_remove_devices(&pdev->dev);
>>> + clk_put(info->clk);
>>> + kfree(info);
>>> + platform_set_drvdata(pdev, NULL);
>>> + return 0;
>>> +}
>>> +
>>> +static struct platform_driver pxa_w1_driver = {
>>> + .driver = {
>>> + .name = "pxa3xx-w1",
>>> + .owner = THIS_MODULE,
>>> + },
>>> + .probe = pxa_w1_probe,
>>> + .remove = __devexit_p(pxa_w1_remove),
>>> +};
>>> +
>>> +static int __init pxa_w1_base_init(void)
>>> +{
>>> + return platform_driver_register(&pxa_w1_driver);
>>> +}
>>> +
>>> +static void __exit pxa_w1_base_exit(void)
>>> +{
>>> + platform_driver_unregister(&pxa_w1_driver);
>>> +}
>>> +
>>> +module_init(pxa_w1_base_init);
>>> +module_exit(pxa_w1_base_exit);
>>> +
>>> +MODULE_AUTHOR("Jett Zhou<[email protected]>");
>>> +MODULE_DESCRIPTION("one wire driver for PXA");
>>> +MODULE_LICENSE("GPL");
>>> +MODULE_ALIAS("platform:pxa-w1");
>>
>> Best regards ,
>> Thanks
>>> --
>>> 1.5.6.5
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-
>> kernel" in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>> Please read the FAQ at http://www.tux.org/lkml/
>>>

2011-04-14 14:44:05

by Haojian Zhuang

[permalink] [raw]
Subject: RE: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x



>-----Original Message-----
>From: [email protected] [mailto:[email protected]] On Behalf Of
>Wanlong Gao
>Sent: 2011??4??14?? 10:02 PM
>To: Haojian Zhuang
>Cc: [email protected]; [email protected]; linux-
>[email protected]; Dmitry Torokhov
>Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in
>88pm860x
>
>On 4/13/11, Haojian Zhuang <[email protected]> wrote:
>> Measuring point on touchscreen with IRQ mode can only monitor pen-down
>> event. If finger is moving on touchscreen, it can't be monitored by
>> IRQ pen-down event. So switch to polling mode after pen-down event.
>>
>> Signed-off-by: Haojian Zhuang <[email protected]>
>> Cc: Dmitry Torokhov <[email protected]>
>> ---
>> drivers/input/touchscreen/88pm860x-ts.c | 82
>> +++++++++++++++++++++++-------
>> 1 files changed, 63 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/88pm860x-ts.c
>> b/drivers/input/touchscreen/88pm860x-ts.c
>> index b3aebc2..fe12f61 100644
>> --- a/drivers/input/touchscreen/88pm860x-ts.c
>> +++ b/drivers/input/touchscreen/88pm860x-ts.c
>> @@ -12,13 +12,25 @@
>> #include <linux/module.h>
>> #include <linux/platform_device.h>
>> #include <linux/i2c.h>
>> +#include <linux/slab.h>
>> #include <linux/input.h>
>> #include <linux/mfd/88pm860x.h>
>> -#include <linux/slab.h>
>>
>> #define MEAS_LEN (8)
>> #define ACCURATE_BIT (12)
>>
>> +/*
>> + * While 32KHz hardware timer is used for scheduler, we always assign
>HZ
>> + * to 128. It means that 1 tick costs 7.8msec.
>> + */
>> +#define MEASURE_INTERVAL_MS (7)
>> +
>> +/* debounce register */
>> +#define DEBOUNCE (0x0A)
>> +
>> +#define PD_DEBOUNCE_0MSEC (0)
>> +#define PD_DEBOUNCE_MASK (3)
>> +
>> /* touch register */
>> #define MEAS_EN3 (0x52)
>>
>> @@ -39,22 +51,27 @@
>> #define MEAS_TSIZ2_EN (1 << 7)
>>
>> struct pm860x_touch {
>> - struct input_dev *idev;
>> - struct i2c_client *i2c;
>> - struct pm860x_chip *chip;
>> - int irq;
>> - int res_x; /* resistor of Xplate */
>> + struct input_dev *idev;
>> + struct i2c_client *i2c;
>> + struct pm860x_chip *chip;
>> + struct delayed_work poll_work;
>> + struct mutex lock;
>> +
>> + int irq;
>> + int res_x; /* resistor of Xplate */
>> };
>>
>> -static irqreturn_t pm860x_touch_handler(int irq, void *data)
>> +static void pm860x_poll_work(struct work_struct *work)
>> {
>> - struct pm860x_touch *touch = data;
>> + struct pm860x_touch *touch = container_of(work, struct
>pm860x_touch,
>> + poll_work.work);
>> struct pm860x_chip *chip = touch->chip;
>> + int x, y, z1, z2, rt = 0;
>> + int ret, pen_down, interval;
>> unsigned char buf[MEAS_LEN];
>> - int x, y, pen_down;
>> - int z1, z2, rt = 0;
>> - int ret;
>> + struct timeval start, end;
>>
>> + do_gettimeofday(&start);
>> ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
>> if (ret < 0)
>> goto out;
>> @@ -77,30 +94,54 @@ static irqreturn_t pm860x_touch_handler(int irq,
>void
>> *data)
>> input_report_abs(touch->idev, ABS_PRESSURE, rt);
>> input_report_key(touch->idev, BTN_TOUCH, 1);
>> dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
>> +
>> + do_gettimeofday(&end);
>> + interval = (end.tv_sec - start.tv_sec) * 1000000 +
>> + (end.tv_usec - start.tv_usec) / 1000;
>Is the interval you calibrated right ?

Good catch. I'll fix it.

>> + interval = (interval < MEASURE_INTERVAL_MS)
>> + ? (MEASURE_INTERVAL_MS - interval) : 0;
>> + schedule_delayed_work(&touch->poll_work,
>> + msecs_to_jiffies(interval));
>> } else {
>> input_report_abs(touch->idev, ABS_PRESSURE, 0);
>> input_report_key(touch->idev, BTN_TOUCH, 0);
>> dev_dbg(chip->dev, "pen release\n");
>> + mutex_unlock(&touch->lock);
>> }
>> input_sync(touch->idev);
>>
>> out:
>> + return;
>> +}
>> +
>> +static irqreturn_t pm860x_touch_handler(int irq, void *data)
>> +{
>> + struct pm860x_touch *touch = data;
>> + int ret;
>> +
>> + ret = pm860x_reg_read(touch->i2c, PM8607_STATUS_1);
>> + dev_dbg(touch->chip->dev, "pen status:%d\n", (ret &
>PM8607_STATUS_PEN)
>> + ? 1 : 0);
>> + if ((ret & PM8607_STATUS_PEN) == 0)
>prefer to !(ret & PM8607_STATUS_PEN) ?
>> + return IRQ_HANDLED;
>> +
>> + mutex_lock(&touch->lock);
>> + pm860x_poll_work(&touch->poll_work.work);
>> return IRQ_HANDLED;
>> }
>>
>> static int pm860x_touch_open(struct input_dev *dev)
>> {
>> struct pm860x_touch *touch = input_get_drvdata(dev);
>> - int data, ret;
>> + int data;
>>
>> + /* set debounce time with 0ms */
>> + pm860x_set_bits(touch->i2c, DEBOUNCE, PD_DEBOUNCE_MASK,
>> + PD_DEBOUNCE_0MSEC);
>> data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
>> | MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
>> - ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
>> - if (ret < 0)
>> - goto out;
>> + pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
>Why not check the return value now ?

Seems checking is better in open(). I'll fix it.

>> return 0;
>> -out:
>> - return ret;
>> }
>>
>> static void pm860x_touch_close(struct input_dev *dev)
>> @@ -152,16 +193,17 @@ static int __devinit pm860x_touch_probe(struct
>> platform_device *pdev)
>> }
>>
>> touch->idev->name = "88pm860x-touch";
>> - touch->idev->phys = "88pm860x/input0";
>> + touch->idev->phys = "88pm860x/input1";
>> touch->idev->id.bustype = BUS_I2C;
>> touch->idev->dev.parent = &pdev->dev;
>> touch->idev->open = pm860x_touch_open;
>> touch->idev->close = pm860x_touch_close;
>> touch->chip = chip;
>> touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip-
>>companion;
>> - touch->irq = irq + chip->irq_base;
>> + touch->irq = irq;
>> touch->res_x = pdata->res_x;
>> input_set_drvdata(touch->idev, touch);
>> + mutex_init(&touch->lock);
>>
>> ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
>> IRQF_ONESHOT, "touch", touch);
>> @@ -188,6 +230,7 @@ static int __devinit pm860x_touch_probe(struct
>> platform_device *pdev)
>> }
>>
>> platform_set_drvdata(pdev, touch);
>> + INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
>> return 0;
>> out_rg:
>> free_irq(touch->irq, touch);
>> @@ -202,6 +245,7 @@ static int __devexit pm860x_touch_remove(struct
>> platform_device *pdev)
>> {
>> struct pm860x_touch *touch = platform_get_drvdata(pdev);
>>
>> + flush_scheduled_work();
>> input_unregister_device(touch->idev);
>> free_irq(touch->irq, touch);
>> platform_set_drvdata(pdev, NULL);
>> --
>> 1.5.6.5
>>
>Best regards
>Thanks
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-
>kernel" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>>
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2011-04-14 14:52:34

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x

2011-4-14 22:41, Haojian Zhuang wroted:
>
>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On Behalf Of
>> Wanlong Gao
>> Sent: 2011??4??14?? 10:02 PM
>> To: Haojian Zhuang
>> Cc: [email protected]; [email protected]; linux-
>> [email protected]; Dmitry Torokhov
>> Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in
>> 88pm860x
>>
>> On 4/13/11, Haojian Zhuang<[email protected]> wrote:
>>> Measuring point on touchscreen with IRQ mode can only monitor pen-down
>>> event. If finger is moving on touchscreen, it can't be monitored by
>>> IRQ pen-down event. So switch to polling mode after pen-down event.
>>>
>>> Signed-off-by: Haojian Zhuang<[email protected]>
Reviewed-by:Wanlong Gao<[email protected]>
>>> Cc: Dmitry Torokhov<[email protected]>
>>> ---
>>> drivers/input/touchscreen/88pm860x-ts.c | 82
>>> +++++++++++++++++++++++-------
>>> 1 files changed, 63 insertions(+), 19 deletions(-)
>>>
>>> diff --git a/drivers/input/touchscreen/88pm860x-ts.c
>>> b/drivers/input/touchscreen/88pm860x-ts.c
>>> index b3aebc2..fe12f61 100644
>>> --- a/drivers/input/touchscreen/88pm860x-ts.c
>>> +++ b/drivers/input/touchscreen/88pm860x-ts.c
>>> @@ -12,13 +12,25 @@
>>> #include<linux/module.h>
>>> #include<linux/platform_device.h>
>>> #include<linux/i2c.h>
>>> +#include<linux/slab.h>
>>> #include<linux/input.h>
>>> #include<linux/mfd/88pm860x.h>
>>> -#include<linux/slab.h>
>>>
>>> #define MEAS_LEN (8)
>>> #define ACCURATE_BIT (12)
>>>
>>> +/*
>>> + * While 32KHz hardware timer is used for scheduler, we always assign
>> HZ
>>> + * to 128. It means that 1 tick costs 7.8msec.
>>> + */
>>> +#define MEASURE_INTERVAL_MS (7)
>>> +
>>> +/* debounce register */
>>> +#define DEBOUNCE (0x0A)
>>> +
>>> +#define PD_DEBOUNCE_0MSEC (0)
>>> +#define PD_DEBOUNCE_MASK (3)
>>> +
>>> /* touch register */
>>> #define MEAS_EN3 (0x52)
>>>
>>> @@ -39,22 +51,27 @@
>>> #define MEAS_TSIZ2_EN (1<< 7)
>>>
>>> struct pm860x_touch {
>>> - struct input_dev *idev;
>>> - struct i2c_client *i2c;
>>> - struct pm860x_chip *chip;
>>> - int irq;
>>> - int res_x; /* resistor of Xplate */
>>> + struct input_dev *idev;
>>> + struct i2c_client *i2c;
>>> + struct pm860x_chip *chip;
>>> + struct delayed_work poll_work;
>>> + struct mutex lock;
>>> +
>>> + int irq;
>>> + int res_x; /* resistor of Xplate */
>>> };
>>>
>>> -static irqreturn_t pm860x_touch_handler(int irq, void *data)
>>> +static void pm860x_poll_work(struct work_struct *work)
>>> {
>>> - struct pm860x_touch *touch = data;
>>> + struct pm860x_touch *touch = container_of(work, struct
>> pm860x_touch,
>>> + poll_work.work);
>>> struct pm860x_chip *chip = touch->chip;
>>> + int x, y, z1, z2, rt = 0;
>>> + int ret, pen_down, interval;
>>> unsigned char buf[MEAS_LEN];
>>> - int x, y, pen_down;
>>> - int z1, z2, rt = 0;
>>> - int ret;
>>> + struct timeval start, end;
>>>
>>> + do_gettimeofday(&start);
>>> ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
>>> if (ret< 0)
>>> goto out;
>>> @@ -77,30 +94,54 @@ static irqreturn_t pm860x_touch_handler(int irq,
>> void
>>> *data)
>>> input_report_abs(touch->idev, ABS_PRESSURE, rt);
>>> input_report_key(touch->idev, BTN_TOUCH, 1);
>>> dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
>>> +
>>> + do_gettimeofday(&end);
>>> + interval = (end.tv_sec - start.tv_sec) * 1000000 +
>>> + (end.tv_usec - start.tv_usec) / 1000;
>> Is the interval you calibrated right ?
>
> Good catch. I'll fix it.
Glad.
>
>>> + interval = (interval< MEASURE_INTERVAL_MS)
>>> + ? (MEASURE_INTERVAL_MS - interval) : 0;
>>> + schedule_delayed_work(&touch->poll_work,
>>> + msecs_to_jiffies(interval));
>>> } else {
>>> input_report_abs(touch->idev, ABS_PRESSURE, 0);
>>> input_report_key(touch->idev, BTN_TOUCH, 0);
>>> dev_dbg(chip->dev, "pen release\n");
>>> + mutex_unlock(&touch->lock);
>>> }
>>> input_sync(touch->idev);
>>>
>>> out:
>>> + return;
>>> +}
>>> +
>>> +static irqreturn_t pm860x_touch_handler(int irq, void *data)
>>> +{
>>> + struct pm860x_touch *touch = data;
>>> + int ret;
>>> +
>>> + ret = pm860x_reg_read(touch->i2c, PM8607_STATUS_1);
>>> + dev_dbg(touch->chip->dev, "pen status:%d\n", (ret&
>> PM8607_STATUS_PEN)
>>> + ? 1 : 0);
>>> + if ((ret& PM8607_STATUS_PEN) == 0)
>> prefer to !(ret& PM8607_STATUS_PEN) ?
>>> + return IRQ_HANDLED;
>>> +
>>> + mutex_lock(&touch->lock);
>>> + pm860x_poll_work(&touch->poll_work.work);
>>> return IRQ_HANDLED;
>>> }
>>>
>>> static int pm860x_touch_open(struct input_dev *dev)
>>> {
>>> struct pm860x_touch *touch = input_get_drvdata(dev);
>>> - int data, ret;
>>> + int data;
>>>
>>> + /* set debounce time with 0ms */
>>> + pm860x_set_bits(touch->i2c, DEBOUNCE, PD_DEBOUNCE_MASK,
>>> + PD_DEBOUNCE_0MSEC);
>>> data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
>>> | MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
>>> - ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
>>> - if (ret< 0)
>>> - goto out;
>>> + pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
>> Why not check the return value now ?
>
> Seems checking is better in open(). I'll fix it.
Glad.
>
>>> return 0;
>>> -out:
>>> - return ret;
>>> }
>>>
>>> static void pm860x_touch_close(struct input_dev *dev)
>>> @@ -152,16 +193,17 @@ static int __devinit pm860x_touch_probe(struct
>>> platform_device *pdev)
>>> }
>>>
>>> touch->idev->name = "88pm860x-touch";
>>> - touch->idev->phys = "88pm860x/input0";
>>> + touch->idev->phys = "88pm860x/input1";
>>> touch->idev->id.bustype = BUS_I2C;
>>> touch->idev->dev.parent =&pdev->dev;
>>> touch->idev->open = pm860x_touch_open;
>>> touch->idev->close = pm860x_touch_close;
>>> touch->chip = chip;
>>> touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip-
>>> companion;
>>> - touch->irq = irq + chip->irq_base;
>>> + touch->irq = irq;
>>> touch->res_x = pdata->res_x;
>>> input_set_drvdata(touch->idev, touch);
>>> + mutex_init(&touch->lock);
>>>
>>> ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
>>> IRQF_ONESHOT, "touch", touch);
>>> @@ -188,6 +230,7 @@ static int __devinit pm860x_touch_probe(struct
>>> platform_device *pdev)
>>> }
>>>
>>> platform_set_drvdata(pdev, touch);
>>> + INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
>>> return 0;
>>> out_rg:
>>> free_irq(touch->irq, touch);
>>> @@ -202,6 +245,7 @@ static int __devexit pm860x_touch_remove(struct
>>> platform_device *pdev)
>>> {
>>> struct pm860x_touch *touch = platform_get_drvdata(pdev);
>>>
>>> + flush_scheduled_work();
>>> input_unregister_device(touch->idev);
>>> free_irq(touch->irq, touch);
>>> platform_set_drvdata(pdev, NULL);
>>> --
>>> 1.5.6.5
>>>
>> Best regards
>> Thanks
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-
>> kernel" in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>> Please read the FAQ at http://www.tux.org/lkml/
>>>

2011-04-15 00:35:28

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 08/13] mfd: use platform_data in max8925

On 4/13/11, Haojian Zhuang <[email protected]> wrote:
> Use platform_data to pass parameters to client driver.
>
> Signed-off-by: Haojian Zhuang <[email protected]>
Acked-by: Wanlong Gao<[email protected]>
> ---
> drivers/mfd/max8925-core.c | 467
> +++++++++++++++++++++++++------------------
> include/linux/mfd/max8925.h | 9 +-
> 2 files changed, 274 insertions(+), 202 deletions(-)
>
> diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
> index 58cc5fd..044801c 100644
> --- a/drivers/mfd/max8925-core.c
> +++ b/drivers/mfd/max8925-core.c
> @@ -17,169 +17,141 @@
> #include <linux/platform_device.h>
> #include <linux/mfd/core.h>
> #include <linux/mfd/max8925.h>
> +#include <linux/regulator/machine.h>
>
> -static struct resource backlight_resources[] = {
> - {
> - .name = "max8925-backlight",
> - .start = MAX8925_WLED_MODE_CNTL,
> - .end = MAX8925_WLED_CNTL,
> - .flags = IORESOURCE_IO,
> - },
> +static struct resource bk_resources[] __devinitdata = {
> + {0, 0, "max8925-backlight", IORESOURCE_IO,},
> };
>
> -static struct mfd_cell backlight_devs[] = {
> - {
> - .name = "max8925-backlight",
> - .num_resources = 1,
> - .resources = &backlight_resources[0],
> - .id = -1,
> - },
> +static struct resource touch_resources[] __devinitdata = {
> + {MAX8925_IRQ_TSC_STICK, MAX8925_IRQ_TSC_STICK, "touch stick",
> + IORESOURCE_IRQ,},
> + {MAX8925_IRQ_TSC_NSTICK, MAX8925_IRQ_TSC_NSTICK, "touch nstick",
> + IORESOURCE_IRQ,},
> };
>
> -static struct resource touch_resources[] = {
> - {
> - .name = "max8925-tsc",
> - .start = MAX8925_TSC_IRQ,
> - .end = MAX8925_ADC_RES_END,
> - .flags = IORESOURCE_IO,
> - },
> +static struct resource power_resources[] __devinitdata = {
> + {MAX8925_IRQ_VCHG_DC_OVP, MAX8925_IRQ_VCHG_DC_OVP, \
> + "dc overvoltage", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_DC_F, MAX8925_IRQ_VCHG_DC_F, \
> + "dc falling", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_DC_R, MAX8925_IRQ_VCHG_DC_R, \
> + "dc rising", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_USB_OVP, MAX8925_IRQ_VCHG_USB_OVP, \
> + "usb overvoltage", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_USB_F, MAX8925_IRQ_VCHG_USB_F, \
> + "usb falling", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_USB_R, MAX8925_IRQ_VCHG_USB_R, \
> + "usb rising", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_THM_OK_R, MAX8925_IRQ_VCHG_THM_OK_R, \
> + "bat temp valid", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_THM_OK_F, MAX8925_IRQ_VCHG_THM_OK_F, \
> + "bat temp invalid", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_SYSLOW_F, MAX8925_IRQ_VCHG_SYSLOW_F, \
> + "VSYSLOW falling", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_SYSLOW_R, MAX8925_IRQ_VCHG_SYSLOW_R, \
> + "VSYSLOW rising", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_RST, MAX8925_IRQ_VCHG_RST, \
> + "charger restart", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_DONE, MAX8925_IRQ_VCHG_DONE, \
> + "charger done", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_TOPOFF, MAX8925_IRQ_VCHG_TOPOFF, \
> + "charger topoff", IORESOURCE_IRQ,},
> + {MAX8925_IRQ_VCHG_TMR_FAULT, MAX8925_IRQ_VCHG_TMR_FAULT, \
> + "charger expire", IORESOURCE_IRQ,},
> };
>
> -static struct mfd_cell touch_devs[] = {
> - {
> - .name = "max8925-touch",
> - .num_resources = 1,
> - .resources = &touch_resources[0],
> - .id = -1,
> - },
> +static struct resource rtc_resources[] __devinitdata = {
> + {MAX8925_IRQ_RTC_ALARM0, MAX8925_IRQ_RTC_ALARM0, "rtc-alarm0",
> + IORESOURCE_IRQ,},
> + {MAX8925_IRQ_RTC_ALARM1, MAX8925_IRQ_RTC_ALARM1, "rtc-alarm1",
> + IORESOURCE_IRQ,},
> };
>
> -static struct resource power_supply_resources[] = {
> - {
> - .name = "max8925-power",
> - .start = MAX8925_CHG_IRQ1,
> - .end = MAX8925_CHG_IRQ1_MASK,
> - .flags = IORESOURCE_IO,
> - },
> +static struct resource onkey_resources[] __devinitdata = {
> + {MAX8925_IRQ_GPM_SW_R, MAX8925_IRQ_GPM_SW_R, "onkey R",
> + IORESOURCE_IRQ,},
> + {MAX8925_IRQ_GPM_SW_F, MAX8925_IRQ_GPM_SW_F, "onkey F",
> + IORESOURCE_IRQ,},
> };
>
> -static struct mfd_cell power_devs[] = {
> - {
> - .name = "max8925-power",
> - .num_resources = 1,
> - .resources = &power_supply_resources[0],
> - .id = -1,
> - },
> +static struct resource regulator_resources[] __devinitdata = {
> + {MAX8925_ID_SD1, MAX8925_ID_SD1, "SD1", IORESOURCE_IO,},
> + {MAX8925_ID_SD2, MAX8925_ID_SD2, "SD2", IORESOURCE_IO,},
> + {MAX8925_ID_SD3, MAX8925_ID_SD3, "SD3", IORESOURCE_IO,},
> + {MAX8925_ID_LDO1, MAX8925_ID_LDO1, "LDO01", IORESOURCE_IO,},
> + {MAX8925_ID_LDO2, MAX8925_ID_LDO2, "LDO02", IORESOURCE_IO,},
> + {MAX8925_ID_LDO3, MAX8925_ID_LDO3, "LDO03", IORESOURCE_IO,},
> + {MAX8925_ID_LDO4, MAX8925_ID_LDO4, "LDO04", IORESOURCE_IO,},
> + {MAX8925_ID_LDO5, MAX8925_ID_LDO5, "LDO05", IORESOURCE_IO,},
> + {MAX8925_ID_LDO6, MAX8925_ID_LDO6, "LDO06", IORESOURCE_IO,},
> + {MAX8925_ID_LDO7, MAX8925_ID_LDO7, "LDO07", IORESOURCE_IO,},
> + {MAX8925_ID_LDO8, MAX8925_ID_LDO8, "LDO08", IORESOURCE_IO,},
> + {MAX8925_ID_LDO9, MAX8925_ID_LDO9, "LDO09", IORESOURCE_IO,},
> + {MAX8925_ID_LDO10, MAX8925_ID_LDO10, "LDO10", IORESOURCE_IO,},
> + {MAX8925_ID_LDO11, MAX8925_ID_LDO11, "LDO11", IORESOURCE_IO,},
> + {MAX8925_ID_LDO12, MAX8925_ID_LDO12, "LDO12", IORESOURCE_IO,},
> + {MAX8925_ID_LDO13, MAX8925_ID_LDO13, "LDO13", IORESOURCE_IO,},
> + {MAX8925_ID_LDO14, MAX8925_ID_LDO14, "LDO14", IORESOURCE_IO,},
> + {MAX8925_ID_LDO15, MAX8925_ID_LDO15, "LDO15", IORESOURCE_IO,},
> + {MAX8925_ID_LDO16, MAX8925_ID_LDO16, "LDO16", IORESOURCE_IO,},
> + {MAX8925_ID_LDO17, MAX8925_ID_LDO17, "LDO17", IORESOURCE_IO,},
> + {MAX8925_ID_LDO18, MAX8925_ID_LDO18, "LDO18", IORESOURCE_IO,},
> + {MAX8925_ID_LDO19, MAX8925_ID_LDO19, "LDO19", IORESOURCE_IO,},
> + {MAX8925_ID_LDO20, MAX8925_ID_LDO20, "LDO20", IORESOURCE_IO,},
> };
>
> -static struct resource rtc_resources[] = {
> - {
> - .name = "max8925-rtc",
> - .start = MAX8925_RTC_IRQ,
> - .end = MAX8925_RTC_IRQ_MASK,
> - .flags = IORESOURCE_IO,
> - },
> +static struct mfd_cell bk_devs[] = {
> + {"max8925-backlight", -1,},
> };
>
> -static struct mfd_cell rtc_devs[] = {
> - {
> - .name = "max8925-rtc",
> - .num_resources = 1,
> - .resources = &rtc_resources[0],
> - .id = -1,
> - },
> +static struct mfd_cell touch_devs[] = {
> + {"max8925-touch", -1,},
> };
>
> -static struct resource onkey_resources[] = {
> - {
> - .name = "max8925-onkey",
> - .start = MAX8925_IRQ_GPM_SW_R,
> - .end = MAX8925_IRQ_GPM_SW_R,
> - .flags = IORESOURCE_IRQ,
> - }, {
> - .name = "max8925-onkey",
> - .start = MAX8925_IRQ_GPM_SW_F,
> - .end = MAX8925_IRQ_GPM_SW_F,
> - .flags = IORESOURCE_IRQ,
> - },
> +static struct mfd_cell power_devs[] = {
> + {"max8925-power", -1,},
> };
>
> -static struct mfd_cell onkey_devs[] = {
> - {
> - .name = "max8925-onkey",
> - .num_resources = 2,
> - .resources = &onkey_resources[0],
> - .id = -1,
> - },
> +static struct mfd_cell rtc_devs[] = {
> + {"max8925-rtc", -1,},
> };
>
> -#define MAX8925_REG_RESOURCE(_start, _end) \
> -{ \
> - .start = MAX8925_##_start, \
> - .end = MAX8925_##_end, \
> - .flags = IORESOURCE_IO, \
> -}
> -
> -static struct resource regulator_resources[] = {
> - MAX8925_REG_RESOURCE(SDCTL1, SDCTL1),
> - MAX8925_REG_RESOURCE(SDCTL2, SDCTL2),
> - MAX8925_REG_RESOURCE(SDCTL3, SDCTL3),
> - MAX8925_REG_RESOURCE(LDOCTL1, LDOCTL1),
> - MAX8925_REG_RESOURCE(LDOCTL2, LDOCTL2),
> - MAX8925_REG_RESOURCE(LDOCTL3, LDOCTL3),
> - MAX8925_REG_RESOURCE(LDOCTL4, LDOCTL4),
> - MAX8925_REG_RESOURCE(LDOCTL5, LDOCTL5),
> - MAX8925_REG_RESOURCE(LDOCTL6, LDOCTL6),
> - MAX8925_REG_RESOURCE(LDOCTL7, LDOCTL7),
> - MAX8925_REG_RESOURCE(LDOCTL8, LDOCTL8),
> - MAX8925_REG_RESOURCE(LDOCTL9, LDOCTL9),
> - MAX8925_REG_RESOURCE(LDOCTL10, LDOCTL10),
> - MAX8925_REG_RESOURCE(LDOCTL11, LDOCTL11),
> - MAX8925_REG_RESOURCE(LDOCTL12, LDOCTL12),
> - MAX8925_REG_RESOURCE(LDOCTL13, LDOCTL13),
> - MAX8925_REG_RESOURCE(LDOCTL14, LDOCTL14),
> - MAX8925_REG_RESOURCE(LDOCTL15, LDOCTL15),
> - MAX8925_REG_RESOURCE(LDOCTL16, LDOCTL16),
> - MAX8925_REG_RESOURCE(LDOCTL17, LDOCTL17),
> - MAX8925_REG_RESOURCE(LDOCTL18, LDOCTL18),
> - MAX8925_REG_RESOURCE(LDOCTL19, LDOCTL19),
> - MAX8925_REG_RESOURCE(LDOCTL20, LDOCTL20),
> +static struct mfd_cell onkey_devs[] = {
> + {"max8925-onkey", -1,},
> };
>
> -#define MAX8925_REG_DEVS(_id) \
> -{ \
> - .name = "max8925-regulator", \
> - .num_resources = 1, \
> - .resources = &regulator_resources[MAX8925_ID_##_id], \
> - .id = MAX8925_ID_##_id, \
> -}
> -
> static struct mfd_cell regulator_devs[] = {
> - MAX8925_REG_DEVS(SD1),
> - MAX8925_REG_DEVS(SD2),
> - MAX8925_REG_DEVS(SD3),
> - MAX8925_REG_DEVS(LDO1),
> - MAX8925_REG_DEVS(LDO2),
> - MAX8925_REG_DEVS(LDO3),
> - MAX8925_REG_DEVS(LDO4),
> - MAX8925_REG_DEVS(LDO5),
> - MAX8925_REG_DEVS(LDO6),
> - MAX8925_REG_DEVS(LDO7),
> - MAX8925_REG_DEVS(LDO8),
> - MAX8925_REG_DEVS(LDO9),
> - MAX8925_REG_DEVS(LDO10),
> - MAX8925_REG_DEVS(LDO11),
> - MAX8925_REG_DEVS(LDO12),
> - MAX8925_REG_DEVS(LDO13),
> - MAX8925_REG_DEVS(LDO14),
> - MAX8925_REG_DEVS(LDO15),
> - MAX8925_REG_DEVS(LDO16),
> - MAX8925_REG_DEVS(LDO17),
> - MAX8925_REG_DEVS(LDO18),
> - MAX8925_REG_DEVS(LDO19),
> - MAX8925_REG_DEVS(LDO20),
> + {"max8925-regulator", 0,},
> + {"max8925-regulator", 1,},
> + {"max8925-regulator", 2,},
> + {"max8925-regulator", 3,},
> + {"max8925-regulator", 4,},
> + {"max8925-regulator", 5,},
> + {"max8925-regulator", 6,},
> + {"max8925-regulator", 7,},
> + {"max8925-regulator", 8,},
> + {"max8925-regulator", 9,},
> + {"max8925-regulator", 10,},
> + {"max8925-regulator", 11,},
> + {"max8925-regulator", 12,},
> + {"max8925-regulator", 13,},
> + {"max8925-regulator", 14,},
> + {"max8925-regulator", 15,},
> + {"max8925-regulator", 16,},
> + {"max8925-regulator", 17,},
> + {"max8925-regulator", 18,},
> + {"max8925-regulator", 19,},
> + {"max8925-regulator", 20,},
> + {"max8925-regulator", 21,},
> + {"max8925-regulator", 22,},
> };
>
> +static struct max8925_backlight_pdata bk_pdata;
> +static struct max8925_touch_pdata touch_pdata;
> +static struct max8925_power_pdata power_pdata;
> +static struct regulator_init_data
> regulator_pdata[ARRAY_SIZE(regulator_devs)];
> +
> enum {
> FLAGS_ADC = 1, /* register in ADC component */
> FLAGS_RTC, /* register in RTC component */
> @@ -588,6 +560,159 @@ tsc_irq:
> return 0;
> }
>
> +static void __devinit device_bk_init(struct max8925_chip *chip,
> + struct i2c_client *i2c,
> + struct max8925_platform_data *pdata)
> +{
> + int ret;
> +
> + if ((pdata == NULL) || (pdata->backlight == NULL))
> + return;
> +
> + memcpy(&bk_pdata, pdata->backlight,
> + sizeof(struct max8925_backlight_pdata));
> + bk_devs[0].platform_data = &bk_pdata;
> + bk_devs[0].pdata_size = sizeof(bk_pdata);
> +
> + bk_devs[0].num_resources = 1;
> + bk_devs[0].resources = &bk_resources[0];
> + ret = mfd_add_devices(chip->dev, 0, &bk_devs[0], 1,
> + &bk_resources[0], 0);
> + if (ret < 0)
> + dev_err(chip->dev, "Failed to add backlight subdev\n");
> +}
> +
> +static void __devinit device_rtc_init(struct max8925_chip *chip,
> + struct i2c_client *i2c,
> + struct max8925_platform_data *pdata)
> +{
> + int ret;
> +
> + rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources);
> + rtc_devs[0].resources = &rtc_resources[0];
> + ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], 1,
> + &rtc_resources[0], chip->irq_base);
> + if (ret < 0)
> + dev_err(chip->dev, "Failed to add rtc subdev\n");
> +}
> +
> +static void __devinit device_touch_init(struct max8925_chip *chip,
> + struct i2c_client *i2c,
> + struct max8925_platform_data *pdata)
> +{
> + int ret;
> +
> + if ((pdata == NULL) || (pdata->touch == NULL))
> + return;
> +
> + memcpy(&touch_pdata, pdata->touch,
> + sizeof(struct max8925_touch_pdata));
> + touch_devs[0].platform_data = &touch_pdata;
> + touch_devs[0].pdata_size = sizeof(touch_pdata);
> + touch_devs[0].num_resources = ARRAY_SIZE(touch_resources);
> + touch_devs[0].resources = &touch_resources[0];
> + ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
> + ARRAY_SIZE(touch_devs),
> + &touch_resources[0], chip->irq_base);
> + if (ret < 0)
> + dev_err(chip->dev, "Failed to add touch subdev\n");
> +}
> +
> +static void __devinit device_power_init(struct max8925_chip *chip,
> + struct i2c_client *i2c,
> + struct max8925_platform_data *pdata)
> +{
> + int ret;
> +
> + if ((pdata == NULL) || (pdata->power == NULL))
> + return;
> +
> + memcpy(&power_pdata, pdata->power,
> + sizeof(struct max8925_power_pdata));
> + power_devs[0].platform_data = &power_pdata;
> + power_devs[0].pdata_size = sizeof(power_pdata);
> + power_devs[0].num_resources = ARRAY_SIZE(power_resources);
> + power_devs[0].resources = &power_resources[0];
> + ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
> + ARRAY_SIZE(power_devs),
> + &power_resources[0], chip->irq_base);
> + if (ret < 0)
> + dev_err(chip->dev, "Failed to add power supply subdev\n");
> +}
> +
> +static void __devinit device_onkey_init(struct max8925_chip *chip,
> + struct i2c_client *i2c,
> + struct max8925_platform_data *pdata)
> +{
> + int ret;
> +
> + onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources);
> + onkey_devs[0].resources = &onkey_resources[0];
> + ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
> + ARRAY_SIZE(onkey_devs),
> + &onkey_resources[0], chip->irq_base);
> + if (ret < 0)
> + dev_err(chip->dev, "Failed to add onkey subdev\n");
> +}
> +
> +static void __devinit device_regulator_init(struct max8925_chip *chip,
> + struct i2c_client *i2c,
> + struct max8925_platform_data *pdata)
> +{
> + struct regulator_init_data *initdata;
> + int ret, i, j;
> +
> + if ((pdata == NULL) || (pdata->regulator == NULL))
> + return;
> +
> + if (pdata->num_regulators > ARRAY_SIZE(regulator_devs))
> + pdata->num_regulators = ARRAY_SIZE(regulator_devs);
> +
> + for (i = 0, j = -1; i < pdata->num_regulators; i++) {
> + initdata = &pdata->regulator[i];
> + if (strstr(initdata->constraints.name, "SD")) {
> + sscanf(initdata->constraints.name, "SD%d", &j);
> + /* SD1 ~ SD3 */
> + if ((j < 1) || (j > 3)) {
> + dev_err(chip->dev, "Failed to add constraint "
> + "(%s)\n", initdata->constraints.name);
> + goto out;
> + }
> + j = (j - 1) + MAX8925_ID_SD1;
> + }
> + if (strstr(initdata->constraints.name, "LDO")) {
> + sscanf(initdata->constraints.name, "LDO%d", &j);
> + /* LDO01 ~ LDO20 */
> + if ((j < 1) || (j > 20)) {
> + dev_err(chip->dev, "Failed to add constraint "
> + "(%s)\n", initdata->constraints.name);
> + goto out;
> + }
> + j = (j - 1) + MAX8925_ID_LDO1;
> + }
> + if (j == -1) {
> + dev_err(chip->dev, "Failed to add constraint (%s)\n",
> + initdata->constraints.name);
> + goto out;
> + }
> + memcpy(&regulator_pdata[i], &pdata->regulator[i],
> + sizeof(struct regulator_init_data));
> + regulator_devs[i].platform_data = &regulator_pdata[i];
> + regulator_devs[i].pdata_size = sizeof(regulator_pdata[i]);
> + regulator_devs[i].num_resources = 1;
> + regulator_devs[i].resources = &regulator_resources[j];
> +
> + ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1,
> + &regulator_resources[j], 0);
> + if (ret < 0) {
> + dev_err(chip->dev, "Failed to add regulator subdev\n");
> + goto out;
> + }
> + }
> +out:
> + return;
> +}
> +
> int __devinit max8925_device_init(struct max8925_chip *chip,
> struct max8925_platform_data *pdata)
> {
> @@ -604,75 +729,21 @@ int __devinit max8925_device_init(struct max8925_chip
> *chip,
> do {
> ret = max8925_reg_read(chip->adc, MAX8925_TSC_IRQ);
> } while (ret & MAX8925_NREF_OK);
> - /* enaable ADC scheduler, interval is 1 second */
> + /* enable ADC scheduler, interval is 1 second */
> max8925_set_bits(chip->adc, MAX8925_ADC_SCHED, 3, 2);
> }
>
> /* enable Momentary Power Loss */
> max8925_set_bits(chip->rtc, MAX8925_MPL_CNTL, 1 << 4, 1 << 4);
>
> - ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
> - ARRAY_SIZE(rtc_devs),
> - &rtc_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add rtc subdev\n");
> - goto out;
> - }
> -
> - ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
> - ARRAY_SIZE(onkey_devs),
> - &onkey_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add onkey subdev\n");
> - goto out_dev;
> - }
> -
> - if (pdata && pdata->regulator[0]) {
> - ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
> - ARRAY_SIZE(regulator_devs),
> - &regulator_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add regulator subdev\n");
> - goto out_dev;
> - }
> - }
> -
> - if (pdata && pdata->backlight) {
> - ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
> - ARRAY_SIZE(backlight_devs),
> - &backlight_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add backlight subdev\n");
> - goto out_dev;
> - }
> - }
> -
> - if (pdata && pdata->power) {
> - ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
> - ARRAY_SIZE(power_devs),
> - &power_supply_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add power supply "
> - "subdev\n");
> - goto out_dev;
> - }
> - }
> -
> - if (pdata && pdata->touch) {
> - ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
> - ARRAY_SIZE(touch_devs),
> - &touch_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add touch subdev\n");
> - goto out_dev;
> - }
> - }
> + device_bk_init(chip, chip->i2c, pdata);
> + device_rtc_init(chip, chip->rtc, pdata);
> + device_touch_init(chip, chip->adc, pdata);
> + device_power_init(chip, chip->adc, pdata);
> + device_onkey_init(chip, chip->i2c, pdata);
> + device_regulator_init(chip, chip->i2c, pdata);
>
> return 0;
> -out_dev:
> - mfd_remove_devices(chip->dev);
> -out:
> - return ret;
> }
>
> void __devexit max8925_device_exit(struct max8925_chip *chip)
> diff --git a/include/linux/mfd/max8925.h b/include/linux/mfd/max8925.h
> index 5259dfe..51578e2 100644
> --- a/include/linux/mfd/max8925.h
> +++ b/include/linux/mfd/max8925.h
> @@ -209,9 +209,9 @@ struct max8925_chip {
> };
>
> struct max8925_backlight_pdata {
> - int lxw_scl; /* 0/1 -- 0.8Ohm/0.4Ohm */
> - int lxw_freq; /* 700KHz ~ 1400KHz */
> - int dual_string; /* 0/1 -- single/dual string */
> + int lxw_scl; /* 0/1 -- 0.8Ohm/0.4Ohm */
> + int lxw_freq; /* 700KHz ~ 1400KHz */
> + int dual_string; /* 0/1 -- single/dual string */
> };
>
> struct max8925_touch_pdata {
> @@ -233,10 +233,11 @@ struct max8925_platform_data {
> struct max8925_backlight_pdata *backlight;
> struct max8925_touch_pdata *touch;
> struct max8925_power_pdata *power;
> - struct regulator_init_data *regulator[MAX8925_MAX_REGULATOR];
> + struct regulator_init_data *regulator;
>
> int irq_base;
> int tsc_irq;
> + int num_regulators;
> };
>
> extern int max8925_reg_read(struct i2c_client *, int);
More nice code than before to me .
Cheers
Best regards .
> --
> 1.5.6.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-04-15 00:41:35

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 10/13] rtc: avoid to use hardcoding irq number in max8925

On 4/13/11, Haojian Zhuang <[email protected]> wrote:
> Avoid to use hardcoding irq number in max8925 rtc driver. Use irq number
> from resources instead.
>
> Signed-off-by: Haojian Zhuang <[email protected]>
Acked-by:Wanlong Gao<[email protected]>
> Cc: Alessandro Zummo <[email protected]>
> ---
> drivers/rtc/rtc-max8925.c | 22 +++++++++++++---------
> 1 files changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
> index 174036d..c460152 100644
> --- a/drivers/rtc/rtc-max8925.c
> +++ b/drivers/rtc/rtc-max8925.c
> @@ -69,6 +69,7 @@ struct max8925_rtc_info {
> struct max8925_chip *chip;
> struct i2c_client *rtc;
> struct device *dev;
> + int irq;
> };
>
> static irqreturn_t rtc_update_handler(int irq, void *data)
> @@ -239,7 +240,7 @@ static int __devinit max8925_rtc_probe(struct
> platform_device *pdev)
> {
> struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
> struct max8925_rtc_info *info;
> - int irq, ret;
> + int ret = -EINVAL;
>
> info = kzalloc(sizeof(struct max8925_rtc_info), GFP_KERNEL);
> if (!info)
> @@ -247,16 +248,22 @@ static int __devinit max8925_rtc_probe(struct
> platform_device *pdev)
> info->chip = chip;
> info->rtc = chip->rtc;
> info->dev = &pdev->dev;
> - irq = chip->irq_base + MAX8925_IRQ_RTC_ALARM0;
> + info->irq = platform_get_irq(pdev, 0);
> + if (info->irq < 0) {
> + dev_err(chip->dev, "Failed to get IRQ resource\n");
> + goto out_irq;
> + }
>
> - ret = request_threaded_irq(irq, NULL, rtc_update_handler,
> + ret = request_threaded_irq(info->irq, NULL, rtc_update_handler,
> IRQF_ONESHOT, "rtc-alarm0", info);
> if (ret < 0) {
> dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
> - irq, ret);
> + info->irq, ret);
> goto out_irq;
> }
>
> + dev_set_drvdata(&pdev->dev, info);
> + platform_set_drvdata(pdev, info);
> info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev,
> &max8925_rtc_ops, THIS_MODULE);
> ret = PTR_ERR(info->rtc_dev);
> @@ -265,12 +272,9 @@ static int __devinit max8925_rtc_probe(struct
> platform_device *pdev)
> goto out_rtc;
> }
>
> - dev_set_drvdata(&pdev->dev, info);
> - platform_set_drvdata(pdev, info);
> -
> return 0;
> out_rtc:
> - free_irq(chip->irq_base + MAX8925_IRQ_RTC_ALARM0, info);
> + free_irq(info->irq, info);
> out_irq:
> kfree(info);
> return ret;
> @@ -281,7 +285,7 @@ static int __devexit max8925_rtc_remove(struct
> platform_device *pdev)
> struct max8925_rtc_info *info = platform_get_drvdata(pdev);
>
> if (info) {
> - free_irq(info->chip->irq_base + MAX8925_IRQ_RTC_ALARM0, info);
> + free_irq(info->irq, info);
> rtc_device_unregister(info->rtc_dev);
> kfree(info);
> }
Added the irq to the info , Hmm.........,seems like all good to me .
Thanks
Best regards
> --
> 1.5.6.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-04-16 12:51:37

by Haojian Zhuang

[permalink] [raw]
Subject: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x

Measuring point on touchscreen with IRQ mode can only monitor pen-down
event. If finger is moving on touchscreen, it can't be monitored by
IRQ pen-down event. So switch to polling mode after pen-down event.

Signed-off-by: Haojian Zhuang <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
---
drivers/input/touchscreen/88pm860x-ts.c | 79 ++++++++++++++++++++++++------
1 files changed, 63 insertions(+), 16 deletions(-)

diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c
index b3aebc2..dbb3435 100644
--- a/drivers/input/touchscreen/88pm860x-ts.c
+++ b/drivers/input/touchscreen/88pm860x-ts.c
@@ -12,13 +12,25 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
+#include <linux/slab.h>
#include <linux/input.h>
#include <linux/mfd/88pm860x.h>
-#include <linux/slab.h>

#define MEAS_LEN (8)
#define ACCURATE_BIT (12)

+/*
+ * While 32KHz hardware timer is used for scheduler, we always assign HZ
+ * to 128. It means that 1 tick costs 7.8msec.
+ */
+#define MEASURE_INTERVAL_MS (7)
+
+/* debounce register */
+#define DEBOUNCE (0x0A)
+
+#define PD_DEBOUNCE_0MSEC (0)
+#define PD_DEBOUNCE_MASK (3)
+
/* touch register */
#define MEAS_EN3 (0x52)

@@ -39,22 +51,27 @@
#define MEAS_TSIZ2_EN (1 << 7)

struct pm860x_touch {
- struct input_dev *idev;
- struct i2c_client *i2c;
- struct pm860x_chip *chip;
- int irq;
- int res_x; /* resistor of Xplate */
+ struct input_dev *idev;
+ struct i2c_client *i2c;
+ struct pm860x_chip *chip;
+ struct delayed_work poll_work;
+ struct mutex lock;
+
+ int irq;
+ int res_x; /* resistor of Xplate */
};

-static irqreturn_t pm860x_touch_handler(int irq, void *data)
+static void pm860x_poll_work(struct work_struct *work)
{
- struct pm860x_touch *touch = data;
+ struct pm860x_touch *touch = container_of(work, struct pm860x_touch,
+ poll_work.work);
struct pm860x_chip *chip = touch->chip;
+ int x, y, z1, z2, rt = 0;
+ int ret, pen_down, interval;
unsigned char buf[MEAS_LEN];
- int x, y, pen_down;
- int z1, z2, rt = 0;
- int ret;
+ struct timeval start, end;

+ do_gettimeofday(&start);
ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
if (ret < 0)
goto out;
@@ -77,14 +94,39 @@ static irqreturn_t pm860x_touch_handler(int irq, void *data)
input_report_abs(touch->idev, ABS_PRESSURE, rt);
input_report_key(touch->idev, BTN_TOUCH, 1);
dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
+
+ do_gettimeofday(&end);
+ interval = ((end.tv_sec - start.tv_sec) * 1000000 +
+ (end.tv_usec - start.tv_usec)) / 1000;
+ interval = (interval < MEASURE_INTERVAL_MS)
+ ? (MEASURE_INTERVAL_MS - interval) : 0;
+ schedule_delayed_work(&touch->poll_work,
+ msecs_to_jiffies(interval));
} else {
input_report_abs(touch->idev, ABS_PRESSURE, 0);
input_report_key(touch->idev, BTN_TOUCH, 0);
dev_dbg(chip->dev, "pen release\n");
+ mutex_unlock(&touch->lock);
}
input_sync(touch->idev);

out:
+ return;
+}
+
+static irqreturn_t pm860x_touch_handler(int irq, void *data)
+{
+ struct pm860x_touch *touch = data;
+ int ret;
+
+ ret = pm860x_reg_read(touch->i2c, PM8607_STATUS_1);
+ dev_dbg(touch->chip->dev, "pen status:%d\n", (ret & PM8607_STATUS_PEN)
+ ? 1 : 0);
+ if ((ret & PM8607_STATUS_PEN) == 0)
+ return IRQ_HANDLED;
+
+ mutex_lock(&touch->lock);
+ pm860x_poll_work(&touch->poll_work.work);
return IRQ_HANDLED;
}

@@ -93,12 +135,14 @@ static int pm860x_touch_open(struct input_dev *dev)
struct pm860x_touch *touch = input_get_drvdata(dev);
int data, ret;

+ /* set debounce time with 0ms */
+ ret = pm860x_set_bits(touch->i2c, DEBOUNCE, PD_DEBOUNCE_MASK,
+ PD_DEBOUNCE_0MSEC);
+ if (ret < 0)
+ goto out;
data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
| MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
- if (ret < 0)
- goto out;
- return 0;
out:
return ret;
}
@@ -152,16 +196,17 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev)
}

touch->idev->name = "88pm860x-touch";
- touch->idev->phys = "88pm860x/input0";
+ touch->idev->phys = "88pm860x/input1";
touch->idev->id.bustype = BUS_I2C;
touch->idev->dev.parent = &pdev->dev;
touch->idev->open = pm860x_touch_open;
touch->idev->close = pm860x_touch_close;
touch->chip = chip;
touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
- touch->irq = irq + chip->irq_base;
+ touch->irq = irq;
touch->res_x = pdata->res_x;
input_set_drvdata(touch->idev, touch);
+ mutex_init(&touch->lock);

ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
IRQF_ONESHOT, "touch", touch);
@@ -188,6 +233,7 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev)
}

platform_set_drvdata(pdev, touch);
+ INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
return 0;
out_rg:
free_irq(touch->irq, touch);
@@ -202,6 +248,7 @@ static int __devexit pm860x_touch_remove(struct platform_device *pdev)
{
struct pm860x_touch *touch = platform_get_drvdata(pdev);

+ flush_scheduled_work();
input_unregister_device(touch->idev);
free_irq(touch->irq, touch);
platform_set_drvdata(pdev, NULL);
--
1.5.6.5

2011-04-16 13:17:17

by Wanlong Gao

[permalink] [raw]
Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x

On 4/16/11, Haojian Zhuang <[email protected]> wrote:
> Measuring point on touchscreen with IRQ mode can only monitor pen-down
> event. If finger is moving on touchscreen, it can't be monitored by
> IRQ pen-down event. So switch to polling mode after pen-down event.
>
> Signed-off-by: Haojian Zhuang <[email protected]>
> Cc: Dmitry Torokhov <[email protected]>
> Acked-by: Wanlong Gao <[email protected]>
> ---
> drivers/input/touchscreen/88pm860x-ts.c | 79
> ++++++++++++++++++++++++------
> 1 files changed, 63 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/input/touchscreen/88pm860x-ts.c
> b/drivers/input/touchscreen/88pm860x-ts.c
> index b3aebc2..dbb3435 100644
> --- a/drivers/input/touchscreen/88pm860x-ts.c
> +++ b/drivers/input/touchscreen/88pm860x-ts.c
> @@ -12,13 +12,25 @@
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/i2c.h>
> +#include <linux/slab.h>
> #include <linux/input.h>
> #include <linux/mfd/88pm860x.h>
> -#include <linux/slab.h>
>
> #define MEAS_LEN (8)
> #define ACCURATE_BIT (12)
>
> +/*
> + * While 32KHz hardware timer is used for scheduler, we always assign HZ
> + * to 128. It means that 1 tick costs 7.8msec.
> + */
> +#define MEASURE_INTERVAL_MS (7)
> +
> +/* debounce register */
> +#define DEBOUNCE (0x0A)
> +
> +#define PD_DEBOUNCE_0MSEC (0)
> +#define PD_DEBOUNCE_MASK (3)
> +
> /* touch register */
> #define MEAS_EN3 (0x52)
>
> @@ -39,22 +51,27 @@
> #define MEAS_TSIZ2_EN (1 << 7)
>
> struct pm860x_touch {
> - struct input_dev *idev;
> - struct i2c_client *i2c;
> - struct pm860x_chip *chip;
> - int irq;
> - int res_x; /* resistor of Xplate */
> + struct input_dev *idev;
> + struct i2c_client *i2c;
> + struct pm860x_chip *chip;
> + struct delayed_work poll_work;
> + struct mutex lock;
> +
> + int irq;
> + int res_x; /* resistor of Xplate */
> };
>
> -static irqreturn_t pm860x_touch_handler(int irq, void *data)
> +static void pm860x_poll_work(struct work_struct *work)
> {
> - struct pm860x_touch *touch = data;
> + struct pm860x_touch *touch = container_of(work, struct pm860x_touch,
> + poll_work.work);
> struct pm860x_chip *chip = touch->chip;
> + int x, y, z1, z2, rt = 0;
> + int ret, pen_down, interval;
> unsigned char buf[MEAS_LEN];
> - int x, y, pen_down;
> - int z1, z2, rt = 0;
> - int ret;
> + struct timeval start, end;
>
> + do_gettimeofday(&start);
> ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
> if (ret < 0)
> goto out;
> @@ -77,14 +94,39 @@ static irqreturn_t pm860x_touch_handler(int irq, void
> *data)
> input_report_abs(touch->idev, ABS_PRESSURE, rt);
> input_report_key(touch->idev, BTN_TOUCH, 1);
> dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
> +
> + do_gettimeofday(&end);
> + interval = ((end.tv_sec - start.tv_sec) * 1000000 +
> + (end.tv_usec - start.tv_usec)) / 1000;
> + interval = (interval < MEASURE_INTERVAL_MS)
> + ? (MEASURE_INTERVAL_MS - interval) : 0;
> + schedule_delayed_work(&touch->poll_work,
> + msecs_to_jiffies(interval));
> } else {
> input_report_abs(touch->idev, ABS_PRESSURE, 0);
> input_report_key(touch->idev, BTN_TOUCH, 0);
> dev_dbg(chip->dev, "pen release\n");
> + mutex_unlock(&touch->lock);
> }
> input_sync(touch->idev);
>
> out:
> + return;
> +}
> +
> +static irqreturn_t pm860x_touch_handler(int irq, void *data)
> +{
> + struct pm860x_touch *touch = data;
> + int ret;
> +
> + ret = pm860x_reg_read(touch->i2c, PM8607_STATUS_1);
> + dev_dbg(touch->chip->dev, "pen status:%d\n", (ret & PM8607_STATUS_PEN)
> + ? 1 : 0);
> + if ((ret & PM8607_STATUS_PEN) == 0)
> + return IRQ_HANDLED;
> +
> + mutex_lock(&touch->lock);
> + pm860x_poll_work(&touch->poll_work.work);
> return IRQ_HANDLED;
> }
>
> @@ -93,12 +135,14 @@ static int pm860x_touch_open(struct input_dev *dev)
> struct pm860x_touch *touch = input_get_drvdata(dev);
> int data, ret;
>
> + /* set debounce time with 0ms */
> + ret = pm860x_set_bits(touch->i2c, DEBOUNCE, PD_DEBOUNCE_MASK,
> + PD_DEBOUNCE_0MSEC);
> + if (ret < 0)
> + goto out;
> data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
> | MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
> ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
> - if (ret < 0)
> - goto out;
> - return 0;
> out:
> return ret;
> }
> @@ -152,16 +196,17 @@ static int __devinit pm860x_touch_probe(struct
> platform_device *pdev)
> }
>
> touch->idev->name = "88pm860x-touch";
> - touch->idev->phys = "88pm860x/input0";
> + touch->idev->phys = "88pm860x/input1";
> touch->idev->id.bustype = BUS_I2C;
> touch->idev->dev.parent = &pdev->dev;
> touch->idev->open = pm860x_touch_open;
> touch->idev->close = pm860x_touch_close;
> touch->chip = chip;
> touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
> - touch->irq = irq + chip->irq_base;
> + touch->irq = irq;
> touch->res_x = pdata->res_x;
> input_set_drvdata(touch->idev, touch);
> + mutex_init(&touch->lock);
>
> ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
> IRQF_ONESHOT, "touch", touch);
> @@ -188,6 +233,7 @@ static int __devinit pm860x_touch_probe(struct
> platform_device *pdev)
> }
>
> platform_set_drvdata(pdev, touch);
> + INIT_DELAYED_WORK(&touch->poll_work, pm860x_poll_work);
> return 0;
> out_rg:
> free_irq(touch->irq, touch);
> @@ -202,6 +248,7 @@ static int __devexit pm860x_touch_remove(struct
> platform_device *pdev)
> {
> struct pm860x_touch *touch = platform_get_drvdata(pdev);
>
> + flush_scheduled_work();
> input_unregister_device(touch->idev);
> free_irq(touch->irq, touch);
> platform_set_drvdata(pdev, NULL);
> --
> 1.5.6.5
>
It looks all good to me now .
Thanks for your great work .

Best regards .
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-04-16 14:17:27

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x

On Sat, 16 Apr 2011 20:46:20 +0800, Haojian Zhuang said:
> Measuring point on touchscreen with IRQ mode can only monitor pen-down
> event. If finger is moving on touchscreen, it can't be monitored by
> IRQ pen-down event. So switch to polling mode after pen-down event.

> drivers/input/touchscreen/88pm860x-ts.c | 79 ++++++++++++++++++++++++------

> +/*
> + * While 32KHz hardware timer is used for scheduler, we always assign HZ
> + * to 128. It means that 1 tick costs 7.8msec.
> + */
> +#define MEASURE_INTERVAL_MS (7)

Is it guaranteed that this hardware part will only ever be used on systems
where this is true? How big a bug would it be if somebody tried to glue this
touchscreen into some random embedded-ARM where HZ was something else, and
should this be computed as a function of HZ instead of hardcoding 7?

It *looks* like the intent of the schedule_delayed_work() call is "let's run
this once a tick when we're awake *anyhow*" - but looking at the code, I can't
convince myself a rounding error in computing 'interval' won't schedule 1ms
before or after the next tick would have been. Isn't there a better API with
slack timers or something that would do a better "next tick" job?




Attachments:
(No filename) (227.00 B)

2011-04-16 18:01:39

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 12/13] regulator: check name in initialization of max8925

On Wed, Apr 13, 2011 at 10:51:03PM +0800, Haojian Zhuang wrote:
> Check name in initialization of max8925 regulator driver.

> + if (!strcmp(ri->desc.name, pdata->constraints.name))
> + break;

This isn't a good change - the whole point of the name in the
constraints is that it allows the user to assign an arbatrary string
which is useful for the board. The driver should never be looking
inside the constraints at all, the core will apply the constraints for
you.

2011-04-16 18:02:50

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 13/13] regulator: max8925: enable i2c sequence for control

On Wed, Apr 13, 2011 at 10:51:04PM +0800, Haojian Zhuang wrote:
> Force to enable i2c as power up/down sequence. Otherwise, SD/LDO can't
> be enabled or disabled via accessing i2c bus.

Acked-by: Mark Brown <[email protected]>

2011-04-18 13:12:39

by Haojian Zhuang

[permalink] [raw]
Subject: RE: [PATCH 01/13] input: touchscreen: use polling mode in 88pm860x



>-----Original Message-----
>From: [email protected] [mailto:[email protected]]
>Sent: 2011??4??16?? 10:17 PM
>To: Haojian Zhuang
>Cc: [email protected]; [email protected]; linux-
>[email protected]; Dmitry Torokhov
>Subject: Re: [PATCH 01/13] input: touchscreen: use polling mode in
>88pm860x
>
>On Sat, 16 Apr 2011 20:46:20 +0800, Haojian Zhuang said:
>> Measuring point on touchscreen with IRQ mode can only monitor pen-down
>> event. If finger is moving on touchscreen, it can't be monitored by
>> IRQ pen-down event. So switch to polling mode after pen-down event.
>
>> drivers/input/touchscreen/88pm860x-ts.c | 79
>++++++++++++++++++++++++------
>
>> +/*
>> + * While 32KHz hardware timer is used for scheduler, we always assign
>HZ
>> + * to 128. It means that 1 tick costs 7.8msec.
>> + */
>> +#define MEASURE_INTERVAL_MS (7)
>
>Is it guaranteed that this hardware part will only ever be used on
>systems
>where this is true? How big a bug would it be if somebody tried to glue
>this
>touchscreen into some random embedded-ARM where HZ was something else,
>and
>should this be computed as a function of HZ instead of hardcoding 7?
It's 7msec whatever you choose any silicon. So it's not a problem.

>
>It *looks* like the intent of the schedule_delayed_work() call is "let's
>run
>this once a tick when we're awake *anyhow*" - but looking at the code, I
>can't
>convince myself a rounding error in computing 'interval' won't schedule
>1ms
>before or after the next tick would have been. Isn't there a better API
>with
>slack timers or something that would do a better "next tick" job?
>
>

????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2011-04-18 13:53:11

by Haojian Zhuang

[permalink] [raw]
Subject: RE: [PATCH 12/13] regulator: check name in initialization of max8925



>-----Original Message-----
>From: Mark Brown [mailto:[email protected]]
>Sent: 2011??4??17?? 2:02 AM
>To: Haojian Zhuang
>Cc: [email protected]; [email protected]; linux-
>[email protected]; Liam Girdwood
>Subject: Re: [PATCH 12/13] regulator: check name in initialization of
>max8925
>
>On Wed, Apr 13, 2011 at 10:51:03PM +0800, Haojian Zhuang wrote:
>> Check name in initialization of max8925 regulator driver.
>
>> + if (!strcmp(ri->desc.name, pdata->constraints.name))
>> + break;
>
>This isn't a good change - the whole point of the name in the
>constraints is that it allows the user to assign an arbatrary string
>which is useful for the board. The driver should never be looking
>inside the constraints at all, the core will apply the constraints for
>you.

I'll move the name of regulator into regulator_init_data->driver_data.

Thanks
Haojian
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?