aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorBalaji Rao <balajirrao@openmoko.org>2008-11-20 19:46:51 +0000
committerAndy Green <agreen@pads.home.warmcat.com>2008-11-20 19:46:51 +0000
commitad1e78fb2babc9cf9acd62923d62389ea28b1df2 (patch)
treedd37e7a75e654d38e601342cacd57a6b30cded8c /drivers
parent5557b3223d35dd25366d6ef047299b1dc94b17e6 (diff)
pcf50633_mdc_related_changes.patch
Changes related to pcf50633_mfd.patch
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/bq27000_battery.c97
-rw-r--r--drivers/regulator/pcf50633-regulator.c28
-rw-r--r--drivers/rtc/rtc-pcf50633.c147
3 files changed, 89 insertions, 183 deletions
diff --git a/drivers/power/bq27000_battery.c b/drivers/power/bq27000_battery.c
index ccd56ea137c..dbbcdb379aa 100644
--- a/drivers/power/bq27000_battery.c
+++ b/drivers/power/bq27000_battery.c
@@ -125,8 +125,6 @@ struct bq27000_bat_regs {
struct bq27000_device_info {
struct device *dev;
struct power_supply bat;
- struct power_supply ac;
- struct power_supply usb;
struct delayed_work work;
struct bq27000_platform_data *pdata;
@@ -172,6 +170,7 @@ static void bq27000_battery_external_power_changed(struct power_supply *psy)
{
struct bq27000_device_info *di = container_of(psy, struct bq27000_device_info, bat);
+ power_supply_changed(&di->bat);
dev_dbg(di->dev, "%s\n", __FUNCTION__);
}
@@ -336,54 +335,6 @@ static void bq27000_battery_work(struct work_struct *work)
dev_err(di->dev, "battery service reschedule failed\n");
}
-static int ac_get_property(struct power_supply *psy,
- enum power_supply_property psp,
- union power_supply_propval *val)
-{
- int ret = 0;
- struct bq27000_device_info *di = container_of(psy, struct bq27000_device_info, ac);
-
- if (!(di->pdata->hdq_initialized)())
- return -EINVAL;
-
- switch (psp) {
- case POWER_SUPPLY_PROP_ONLINE:
- if (di->pdata->get_charger_online_status)
- val->intval = (di->pdata->get_charger_online_status)();
- else
- return -EINVAL;
- break;
- default:
- ret = -EINVAL;
- break;
- }
- return ret;
-}
-
-static int usb_get_property(struct power_supply *psy,
- enum power_supply_property psp,
- union power_supply_propval *val)
-{
- int ret = 0;
- struct bq27000_device_info *di = container_of(psy, struct bq27000_device_info, usb);
-
- if (!(di->pdata->hdq_initialized)())
- return -EINVAL;
-
- switch (psp) {
- case POWER_SUPPLY_PROP_ONLINE:
- if (di->pdata->get_charger_online_status)
- val->intval = (di->pdata->get_charger_online_status)();
- else
- return -EINVAL;
- break;
- default:
- ret = -EINVAL;
- break;
- }
- return ret;
-}
-
static enum power_supply_property bq27000_battery_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
@@ -399,10 +350,6 @@ static enum power_supply_property bq27000_battery_props[] = {
POWER_SUPPLY_PROP_ONLINE
};
-static enum power_supply_property power_props[] = {
- POWER_SUPPLY_PROP_ONLINE,
-};
-
static int bq27000_battery_probe(struct platform_device *pdev)
{
int retval = 0;
@@ -432,36 +379,12 @@ static int bq27000_battery_probe(struct platform_device *pdev)
di->bat.use_for_apm = 1;
di->pdata = pdata;
- di->ac.name = "ac";
- di->ac.type = POWER_SUPPLY_TYPE_MAINS;
- di->ac.properties = power_props;
- di->ac.num_properties = ARRAY_SIZE(power_props);
- di->ac.get_property = ac_get_property;
-
- di->usb.name = "usb";
- di->usb.type = POWER_SUPPLY_TYPE_USB;
- di->usb.properties = power_props;
- di->usb.num_properties = ARRAY_SIZE(power_props);
- di->usb.get_property = usb_get_property;
-
retval = power_supply_register(&pdev->dev, &di->bat);
if (retval) {
dev_err(di->dev, "failed to register battery\n");
goto batt_failed;
}
- retval = power_supply_register(&pdev->dev, &di->ac);
- if (retval) {
- dev_err(di->dev, "failed to register ac\n");
- goto ac_failed;
- }
-
- retval = power_supply_register(&pdev->dev, &di->usb);
- if (retval) {
- dev_err(di->dev, "failed to register usb\n");
- goto usb_failed;
- }
-
INIT_DELAYED_WORK(&di->work, bq27000_battery_work);
if (!schedule_delayed_work(&di->work, 0))
@@ -469,10 +392,6 @@ static int bq27000_battery_probe(struct platform_device *pdev)
return 0;
-usb_failed:
- power_supply_unregister(&di->ac);
-ac_failed:
- power_supply_unregister(&di->bat);
batt_failed:
kfree(di);
di_alloc_failed:
@@ -486,24 +405,10 @@ static int bq27000_battery_remove(struct platform_device *pdev)
cancel_delayed_work(&di->work);
power_supply_unregister(&di->bat);
- power_supply_unregister(&di->ac);
- power_supply_unregister(&di->usb);
return 0;
}
-void bq27000_charging_state_change(struct platform_device *pdev)
-{
- struct bq27000_device_info *di = platform_get_drvdata(pdev);
-
- if (!di)
- return;
-
- power_supply_changed(&di->ac);
- power_supply_changed(&di->usb);
-}
-EXPORT_SYMBOL_GPL(bq27000_charging_state_change);
-
#ifdef CONFIG_PM
static int bq27000_battery_suspend(struct platform_device *pdev,
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index c7082d857d0..ef4165ae560 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -4,9 +4,11 @@
#include <linux/regulator/driver.h>
#include <linux/platform_device.h>
-#include <linux/pcf50633.h>
#include <linux/err.h>
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/pmic.h>
+
#define PCF50633_REGULATOR(_name, _id) \
{ \
.name = _name, \
@@ -16,7 +18,7 @@
.owner = THIS_MODULE, \
}
-static const u_int8_t regulator_registers[__NUM_PCF50633_REGULATORS] = {
+static const u_int8_t regulator_registers[PCF50633_NUM_REGULATORS] = {
[PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
[PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
[PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
@@ -93,11 +95,11 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
uint8_t regnr;
int regulator_id;
int millivolts;
- struct pcf50633_data *pcf = rdev_get_drvdata(rdev);;
+ struct pcf50633 *pcf = rdev_get_drvdata(rdev);;
regulator_id = rdev_get_id(rdev);
- if (regulator_id >= __NUM_PCF50633_REGULATORS)
+ if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
millivolts = min_uV / 1000;
@@ -136,9 +138,9 @@ static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev)
uint8_t regnr;
unsigned int rc = 0;
int regulator_id = rdev_get_id(rdev);
- struct pcf50633_data *pcf = rdev_get_drvdata(rdev);
+ struct pcf50633 *pcf = rdev_get_drvdata(rdev);
- if (regulator_id >= __NUM_PCF50633_REGULATORS)
+ if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
regnr = regulator_registers[regulator_id];
@@ -174,9 +176,9 @@ static int pcf50633_regulator_enable(struct regulator_dev *rdev)
{
uint8_t regnr;
int regulator_id = rdev_get_id(rdev);
- struct pcf50633_data *pcf = rdev_get_drvdata(rdev);
+ struct pcf50633 *pcf = rdev_get_drvdata(rdev);
- if (regulator_id >= __NUM_PCF50633_REGULATORS)
+ if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
@@ -192,9 +194,9 @@ static int pcf50633_regulator_disable(struct regulator_dev *rdev)
{
uint8_t regnr;
int regulator_id = rdev_get_id(rdev);
- struct pcf50633_data *pcf = rdev_get_drvdata(rdev);
+ struct pcf50633 *pcf = rdev_get_drvdata(rdev);
- if (regulator_id >= __NUM_PCF50633_REGULATORS)
+ if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
@@ -209,9 +211,9 @@ static int pcf50633_regulator_is_enabled(struct regulator_dev *rdev)
{
uint8_t val, regnr;
int regulator_id = rdev_get_id(rdev);
- struct pcf50633_data *pcf = rdev_get_drvdata(rdev);
+ struct pcf50633 *pcf = rdev_get_drvdata(rdev);
- if (regulator_id >= __NUM_PCF50633_REGULATORS)
+ if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
@@ -259,7 +261,7 @@ struct regulator_desc regulators[] = {
int __init pcf50633_regulator_probe(struct platform_device *pdev)
{
struct regulator_dev *rdev;
- struct pcf50633_data *pcf;
+ struct pcf50633 *pcf;
pcf = pdev->dev.driver_data;
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index 74b7e569d39..6b8ef2f4b8a 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -1,9 +1,9 @@
#include <linux/rtc.h>
#include <linux/platform_device.h>
#include <linux/bcd.h>
-#include <linux/pcf50633.h>
-#include <linux/rtc/pcf50633.h>
-#include <linux/i2c.h>
+
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/rtc.h>
enum pcf50633_time_indexes {
PCF50633_TI_SEC = 0,
@@ -46,69 +46,48 @@ static void rtc2pcf_time(struct pcf50633_time *pcf, struct rtc_time *rtc)
static int pcf50633_rtc_ioctl(struct device *dev, unsigned int cmd,
unsigned long arg)
{
- struct pcf50633_data *pcf = dev->platform_data;
+ struct pcf50633 *pcf;
+
+ pcf = dev_get_drvdata(dev);
switch (cmd) {
case RTC_AIE_OFF:
/* disable the alarm interrupt */
- pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_INT1M,
- PCF50633_INT1_ALARM, PCF50633_INT1_ALARM);
+ pcf->rtc.alarm_enabled = 0;
+ pcf50633_irq_mask(pcf, PCF50633_IRQ_ALARM);
return 0;
case RTC_AIE_ON:
/* enable the alarm interrupt */
- pcf50633_reg_clear_bits(pcf, PCF50633_REG_INT1M, PCF50633_INT1_ALARM);
+ pcf->rtc.alarm_enabled = 1;
+ pcf50633_irq_unmask(pcf, PCF50633_IRQ_ALARM);
return 0;
case RTC_PIE_OFF:
/* disable periodic interrupt (hz tick) */
- pcf->flags &= ~PCF50633_F_RTC_SECOND;
- pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_INT1M,
- PCF50633_INT1_SECOND, PCF50633_INT1_SECOND);
+ pcf->rtc.second_enabled = 0;
+ pcf50633_irq_mask(pcf, PCF50633_IRQ_SECOND);
return 0;
case RTC_PIE_ON:
/* ensable periodic interrupt (hz tick) */
- pcf->flags |= PCF50633_F_RTC_SECOND;
- pcf50633_reg_clear_bits(pcf, PCF50633_REG_INT1M, PCF50633_INT1_SECOND);
+ pcf->rtc.second_enabled = 1;
+ pcf50633_irq_unmask(pcf, PCF50633_IRQ_SECOND);
return 0;
}
return -ENOIOCTLCMD;
}
-#ifdef PCF50633_RTC
-void pcf50633_rtc_handle_event(struct pcf50633_data *pcf,
- enum pcf50633_rtc_event evt)
-{
- switch(evt) {
- case PCF50633_RTC_EVENT_ALARM:
- rtc_update_irq(pcf->rtc, 1, RTC_AF | RTC_IRQF);
- break;
- case PCF50633_RTC_EVENT_SECOND:
- rtc_update_irq(pcf->rtc, 1, RTC_PF | RTC_IRQF);
- }
-}
-#else
-void pcf50633_rtc_handle_event(struct pcf50633_data *pcf,
- enum pcf50633_rtc_event evt)
-{
-
-}
-#endif
-
static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
- struct pcf50633_data *pcf = dev->platform_data;
+ struct pcf50633 *pcf;
struct pcf50633_time pcf_tm;
int ret;
- mutex_lock(&pcf->lock);
+ pcf = dev_get_drvdata(dev);
- ret = i2c_smbus_read_i2c_block_data(pcf->client,
- PCF50633_REG_RTCSC,
+ ret = pcf50633_read_block(pcf, PCF50633_REG_RTCSC,
PCF50633_TI_EXTENT,
&pcf_tm.time[0]);
if (ret != PCF50633_TI_EXTENT)
- dev_err(dev, "Failed to read time :-(\n");
-
- mutex_unlock(&pcf->lock);
+ dev_err(dev, "Failed to read time\n");
dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
pcf_tm.time[PCF50633_TI_DAY],
@@ -129,9 +108,12 @@ static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
- struct pcf50633_data *pcf = dev->platform_data;
+ struct pcf50633 *pcf;
struct pcf50633_time pcf_tm;
int ret;
+ int second_masked, alarm_masked;
+
+ pcf = dev_get_drvdata(dev);
dev_dbg(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
tm->tm_mday, tm->tm_mon, tm->tm_year,
@@ -145,42 +127,46 @@ static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm)
pcf_tm.time[PCF50633_TI_MIN],
pcf_tm.time[PCF50633_TI_SEC]);
- mutex_lock(&pcf->lock);
- /* FIXME: disable second interrupt */
- ret = i2c_smbus_write_i2c_block_data(pcf->client,
- PCF50633_REG_RTCSC,
+ second_masked = pcf50633_irq_mask_get(pcf, PCF50633_IRQ_SECOND);
+ alarm_masked = pcf50633_irq_mask_get(pcf, PCF50633_IRQ_ALARM);
+
+ if (!second_masked)
+ pcf50633_irq_mask(pcf, PCF50633_IRQ_SECOND);
+ if (!alarm_masked)
+ pcf50633_irq_mask(pcf, PCF50633_IRQ_ALARM);
+
+ ret = pcf50633_write_block(pcf, PCF50633_REG_RTCSC,
PCF50633_TI_EXTENT,
&pcf_tm.time[0]);
if (ret)
dev_err(dev, "Failed to set time %d\n", ret);
- /* FIXME: re-enable second interrupt */
- mutex_unlock(&pcf->lock);
+ if (!second_masked)
+ pcf50633_irq_unmask(pcf, PCF50633_IRQ_SECOND);
+ if (!alarm_masked)
+ pcf50633_irq_unmask(pcf, PCF50633_IRQ_ALARM);
+
return 0;
}
static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
- struct pcf50633_data *pcf = dev->platform_data;
+ struct pcf50633 *pcf;
struct pcf50633_time pcf_tm;
int ret;
- u_int8_t reg;
- mutex_lock(&pcf->lock);
-
- pcf50633_read(pcf, PCF50633_REG_INT1M, 1, &reg);
- alrm->enabled = reg & PCF50633_INT1_ALARM ? 0 : 1;
+ pcf = dev_get_drvdata(dev);
- ret = pcf50633_read(pcf, PCF50633_REG_RTCSCA,
+ alrm->enabled = pcf->rtc.alarm_enabled;
+
+ ret = pcf50633_read_block(pcf, PCF50633_REG_RTCSCA,
PCF50633_TI_EXTENT, &pcf_tm.time[0]);
if (ret != PCF50633_TI_EXTENT)
dev_err(dev, "Failed to read Alarm time :-(\n");
- mutex_unlock(&pcf->lock);
-
pcf2rtc_time(&alrm->time, &pcf_tm);
return 0;
@@ -188,35 +174,31 @@ static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
- struct pcf50633_data *pcf = dev->platform_data;
+ struct pcf50633 *pcf;
struct pcf50633_time pcf_tm;
- u_int8_t irqmask;
- int ret;
+ int ret, alarm_masked;
+
+ pcf = dev_get_drvdata(dev);
rtc2pcf_time(&pcf_tm, &alrm->time);
- mutex_lock(&pcf->lock);
+ printk("wkday is %x\n", alrm->time.tm_wday);
+ printk("wkday is %x\n", pcf_tm.time[PCF50633_TI_WKDAY]);
+
+ alarm_masked = pcf50633_irq_mask_get(pcf, PCF50633_IRQ_ALARM);
/* disable alarm interrupt */
- pcf50633_read(pcf, PCF50633_REG_INT1M, 1, &irqmask);
- irqmask |= PCF50633_INT1_ALARM;
- pcf50633_write(pcf, PCF50633_REG_INT1M, 1, &irqmask);
+ if (!alarm_masked)
+ pcf50633_irq_mask(pcf, PCF50633_IRQ_ALARM);
- ret = pcf50633_write(pcf, PCF50633_REG_RTCSCA,
+ ret = pcf50633_write_block(pcf, PCF50633_REG_RTCSCA,
PCF50633_TI_EXTENT, &pcf_tm.time[0]);
if (ret)
- dev_err(dev, "Failed to write alarm time :-( %d\n", ret);
-
- if (alrm->enabled) {
- /* (re-)enaable alarm interrupt */
- pcf50633_read(pcf, PCF50633_REG_INT1M, 1, &irqmask);
- irqmask &= ~PCF50633_INT1_ALARM;
- pcf50633_write(pcf, PCF50633_REG_INT1M, 1, &irqmask);
- }
+ dev_err(dev, "Failed to write alarm time %d\n", ret);
- mutex_unlock(&pcf->lock);
+ if (!alarm_masked)
+ pcf50633_irq_unmask(pcf, PCF50633_IRQ_ALARM);
- /* FIXME */
return 0;
}
static struct rtc_class_ops pcf50633_rtc_ops = {
@@ -227,15 +209,32 @@ static struct rtc_class_ops pcf50633_rtc_ops = {
.set_alarm = pcf50633_rtc_set_alarm,
};
+static void pcf50633_rtc_irq(struct pcf50633 *pcf, int irq, void *unused)
+{
+ switch(irq) {
+ case PCF50633_IRQ_ALARM:
+ rtc_update_irq(pcf->rtc.rtc_dev, 1, RTC_AF | RTC_IRQF);
+ break;
+ }
+}
+
static int pcf50633_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
-
+ struct pcf50633 *pcf;
+
rtc = rtc_device_register("pcf50633", &pdev->dev,
&pcf50633_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc))
return -ENODEV;
+ pcf = platform_get_drvdata(pdev);
+
+ /* Set up IRQ handlers */
+ pcf->irq_handler[PCF50633_IRQ_ALARM].handler = pcf50633_rtc_irq;
+ pcf->irq_handler[PCF50633_IRQ_SECOND].handler = pcf50633_rtc_irq;
+
+ pcf->rtc.rtc_dev = rtc;
return 0;
}