From 4a922dc8ab2915b61ff6adfe8e0a01069893b52b Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 21 Nov 2008 16:40:58 +0000 Subject: MERGE-via-balaji-tracking-balaji-updates Signed-off-by: Andy Green --- drivers/mfd/Kconfig | 20 ++- drivers/mfd/Makefile | 5 +- drivers/mfd/pcf50633-adc.c | 27 +++- drivers/mfd/pcf50633-core.c | 24 +++- drivers/mfd/pcf50633-gpio.c | 109 +++++++++++------ drivers/mfd/pcf50633-mbc.c | 292 -------------------------------------------- 6 files changed, 137 insertions(+), 340 deletions(-) delete mode 100644 drivers/mfd/pcf50633-mbc.c (limited to 'drivers/mfd') diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 84920f60757..6509719237d 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -156,18 +156,26 @@ config MFD_WM8350_I2C config MFD_PCF50633 tristate "Support for NXP PCF50633" depends on I2C + help + Say yes here if you have NXP PCF50633 chip on your board. + This core driver provides register access and IRQ handling + facilities, and registers devices for the various functions + so that function-specific drivers can bind to them. -config MFD_PCF50633_ADC - tristate "Support for NXP PCF50633 ADC" - depends on MFD_PCF50633 -config MFD_PCF50633_MBC - tristate "Support for NXP PCF50633 MBC" +config PCF50633_ADC + tristate "Support for NXP PCF50633 ADC" depends on MFD_PCF50633 + help + Say yes here if you want to include support for ADC in the + NXP PCF50633 chip. -config MFD_PCF50633_GPIO +config PCF50633_GPIO tristate "Support for NXP PCF50633 GPIO" depends on MFD_PCF50633 + help + Say yes here if you want to include support GPIO for pins on + the PCF50633 chip. source "drivers/mfd/glamo/Kconfig" diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 30f1091072b..c515325b4b2 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -35,6 +35,5 @@ obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o obj-$(CONFIG_PMIC_DA903X) += da903x.o obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o -obj-$(CONFIG_MFD_PCF50633_ADC) += pcf50633-adc.o -obj-$(CONFIG_MFD_PCF50633_MBC) += pcf50633-mbc.o -obj-$(CONFIG_MFD_PCF50633_GPIO) += pcf50633-gpio.o +obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o +obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o diff --git a/drivers/mfd/pcf50633-adc.c b/drivers/mfd/pcf50633-adc.c index 208c1f87e5d..39bdbae67da 100644 --- a/drivers/mfd/pcf50633-adc.c +++ b/drivers/mfd/pcf50633-adc.c @@ -1,3 +1,28 @@ +/* Philips PCF50633 ADC Driver + * + * (C) 2006-2008 by Openmoko, Inc. + * Author: Balaji Rao + * All rights reserved. + * + * Broken down from monstrous PCF50633 driver mainly by + * Harald Welte and Andy Green + * + * 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; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + #include #include @@ -22,7 +47,7 @@ static void adc_read_setup(struct pcf50633 *pcf, pcf50633_reg_write(pcf, PCF50633_REG_ADCC2, 0x00); pcf50633_reg_write(pcf, PCF50633_REG_ADCC3, 0x01); - /* start ADC conversion of selected channel */ + /* start ADC conversion on selected channel */ pcf50633_reg_write(pcf, PCF50633_REG_ADCC1, channel | avg | PCF50633_ADCC1_ADCSTART | PCF50633_ADCC1_RES_10BIT); diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c index 0d44f37df08..6d66b526bc2 100644 --- a/drivers/mfd/pcf50633-core.c +++ b/drivers/mfd/pcf50633-core.c @@ -1,3 +1,25 @@ +/* Philips PCF50633 Power Management Unit (PMU) driver + * + * (C) 2006-2008 by Openmoko, Inc. + * Author: Harald Welte + * All rights reserved. + * + * 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; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ #include #include #include @@ -506,8 +528,6 @@ static int pcf50633_probe(struct i2c_client *client, &pcf->mbc.pdev); pcf50633_client_dev_register(pcf, "pcf50633-adc", &pcf->adc.pdev); - pcf50633_client_dev_register(pcf, "pcf50633-gpio", - &pcf->gpio.pdev); for (i = 0; i < PCF50633_NUM_REGULATORS; i++) { struct platform_device *pdev; diff --git a/drivers/mfd/pcf50633-gpio.c b/drivers/mfd/pcf50633-gpio.c index f71acbd6dbc..a5b978c4e3c 100644 --- a/drivers/mfd/pcf50633-gpio.c +++ b/drivers/mfd/pcf50633-gpio.c @@ -1,62 +1,99 @@ +/* Philips PCF50633 GPIO Driver + * + * (C) 2006-2008 by Openmoko, Inc. + * Author: Balaji Rao + * All rights reserved. + * + * Broken down from monstrous PCF50633 driver mainly by + * Harald Welte and Andy Green + * + * 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; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + #include #include +#include -void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int on) +void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int val) { - u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG; + u8 reg; + + reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG; - if (on) - pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x07); - else - pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x00); + pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val); } EXPORT_SYMBOL_GPL(pcf50633_gpio_set); int pcf50633_gpio_get(struct pcf50633 *pcf, int gpio) { - u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG; - u8 val = pcf50633_reg_read(pcf, reg) & 0x0f; + u8 reg, val; - if (val == PCF50633_GPOCFG_GPOSEL_1 || - val == (PCF50633_GPOCFG_GPOSEL_0|PCF50633_GPOCFG_GPOSEL_INVERSE)) - return 1; + reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG; + val = pcf50633_reg_read(pcf, reg); - return 0; + return val; } EXPORT_SYMBOL_GPL(pcf50633_gpio_get); -int __init pcf50633_gpio_probe(struct platform_device *pdev) +void pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert) { - return 0; + u8 val, reg; + + reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG; + val = !!invert << 3; + + pcf50633_reg_set_bit_mask(pcf, reg, val, val); } +EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set); -static int __devexit pcf50633_gpio_remove(struct platform_device *pdev) +int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio) { - return 0; -} + u8 reg, val; -struct platform_driver pcf50633_gpio_driver = { - .driver = { - .name = "pcf50633-gpio", - }, - .probe = pcf50633_gpio_probe, - .remove = __devexit_p(pcf50633_gpio_remove), -}; + reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG; + val = pcf50633_reg_read(pcf, reg); -static int __init pcf50633_gpio_init(void) -{ - return platform_driver_register(&pcf50633_gpio_driver); + return val & (1 << 3); } -module_init(pcf50633_gpio_init); +EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get); + +static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = { + [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT, + [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT, + [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT, + [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT, + [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT, + [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT, + [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT, + [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT, + [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT, + [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT, + [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT, +}; -static void __exit pcf50633_gpio_exit(void) +void pcf50633_gpio_power_supply_set(struct pcf50633 *pcf, + int gpio, int regulator, int on) { - platform_driver_unregister(&pcf50633_gpio_driver); -} -module_exit(pcf50633_gpio_exit); + u8 reg, val; -MODULE_AUTHOR("Balaji Rao "); -MODULE_DESCRIPTION("PCF50633 gpio driver"); -MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:pcf50633-gpio"); + /* the *ENA register is always one after the *OUT register */ + reg = pcf50633_regulator_registers[regulator] + 1; + + val = (!!on << (gpio - PCF50633_GPIO1)); + pcf50633_reg_set_bit_mask(pcf, reg, val, val); +} +EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set); diff --git a/drivers/mfd/pcf50633-mbc.c b/drivers/mfd/pcf50633-mbc.c deleted file mode 100644 index 8e3eb4f7a57..00000000000 --- a/drivers/mfd/pcf50633-mbc.c +++ /dev/null @@ -1,292 +0,0 @@ -#include -#include - - -/* -#if CONFIG_INPUT_PCF50633_PMU = -extern static void pcf50633_input_irq(struct pcf50633 *, int, void *); - -static void pcf50633_input_report(struct pcf50633 *pcf, int key) -{ - pcf50633_input_irq(pcf, key, NULL); -} -#else -static void pcf50633_input_report(struct pcf50633 *pcf, int key) -{ -} -#endif -*/ - -void pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma) -{ - int ret; - u8 bits; - - if (ma >= 1000) - bits = PCF50633_MBCC7_USB_1000mA; - else if (ma >= 500) - bits = PCF50633_MBCC7_USB_500mA; - else if (ma >= 100) - bits = PCF50633_MBCC7_USB_100mA; - else - bits = PCF50633_MBCC7_USB_SUSPEND; - - ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7, - PCF50633_MBCC7_USB_MASK, bits); - if (ret) - dev_err(pcf->dev, "error setting usb curlim to %d mA\n", ma); - else - dev_info(pcf->dev, "usb curlim to %d mA\n", ma); - - power_supply_changed(&pcf->mbc.usb); -} -EXPORT_SYMBOL(pcf50633_mbc_usb_curlim_set); - -static const char *chgmode_names[] = { - [PCF50633_MBCS2_MBC_PLAY] = "play-only", - [PCF50633_MBCS2_MBC_USB_PRE] = "pre", - [PCF50633_MBCS2_MBC_ADP_PRE] = "pre", - [PCF50633_MBCS2_MBC_USB_PRE_WAIT] = "pre-wait", - [PCF50633_MBCS2_MBC_ADP_PRE_WAIT] = "pre-wait", - [PCF50633_MBCS2_MBC_USB_FAST] = "fast", - [PCF50633_MBCS2_MBC_ADP_FAST] = "fast", - [PCF50633_MBCS2_MBC_USB_FAST_WAIT] = "fast-wait", - [PCF50633_MBCS2_MBC_ADP_FAST_WAIT] = "fast-wait", - [PCF50633_MBCS2_MBC_BAT_FULL] = "bat-full", -}; - -static ssize_t show_chgmode(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct pcf50633 *pcf = dev_get_drvdata(dev); - - u8 mbcs2 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2); - u8 chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK); - - return sprintf(buf, "%s %d\n", chgmode_names[chgmod], chgmod); -} -static DEVICE_ATTR(chgmode, S_IRUGO | S_IWUSR, show_chgmode, NULL); - -static ssize_t show_usblim(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct pcf50633 *pcf = dev_get_drvdata(dev); - u8 usblim = pcf50633_reg_read(pcf, PCF50633_REG_MBCC7) & - PCF50633_MBCC7_USB_MASK; - unsigned int ma; - - if (usblim == PCF50633_MBCC7_USB_1000mA) - ma = 1000; - else if (usblim == PCF50633_MBCC7_USB_500mA) - ma = 500; - else if (usblim == PCF50633_MBCC7_USB_100mA) - ma = 100; - else - ma = 0; - - return sprintf(buf, "%u\n", ma); -} -static DEVICE_ATTR(usb_curlim, S_IRUGO | S_IWUSR, show_usblim, NULL); - -static ssize_t force_usb_limit_dangerous(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct pcf50633 *pcf = dev_get_drvdata(dev); - unsigned long ma; - - strict_strtoul(buf, 10, &ma); - - pcf50633_mbc_usb_curlim_set(pcf, ma); - - return count; -} - -static DEVICE_ATTR(force_usb_limit_dangerous, 0600, - NULL, force_usb_limit_dangerous); - -static struct attribute *mbc_sysfs_entries[] = { - &dev_attr_chgmode.attr, - &dev_attr_usb_curlim.attr, - &dev_attr_force_usb_limit_dangerous.attr, - NULL, -}; - -static struct attribute_group mbc_attr_group = { - .name = NULL, /* put in device directory */ - .attrs = mbc_sysfs_entries, -}; - -static void pcf50633_mbc_irq_handler(struct pcf50633 *pcf, int irq, void *data) -{ - struct pcf50633_mbc *mbc; - - mbc = &pcf->mbc; - - /* USB */ - if (irq == PCF50633_IRQ_USBINS) - mbc->usb_online = 1; - else if (irq == PCF50633_IRQ_USBREM) { - mbc->usb_online = 0; - mbc->usb_active = 0; - pcf50633_mbc_usb_curlim_set(pcf, 0); - } - - /* Adapter */ - if (irq == PCF50633_IRQ_ADPINS) { - pcf->mbc.adapter_online = 1; - pcf->mbc.adapter_active = 1; - } else if (irq == PCF50633_IRQ_ADPREM) { - mbc->adapter_online = 0; - mbc->adapter_active = 0; - } - - if (irq == PCF50633_IRQ_BATFULL) { - mbc->usb_active = 0; - mbc->adapter_active = 0; - } - - power_supply_changed(&mbc->usb); - power_supply_changed(&mbc->adapter); - - if (pcf->pdata->mbc_event_callback) - pcf->pdata->mbc_event_callback(pcf, irq); -} - -static int adapter_get_property(struct power_supply *psy, - enum power_supply_property psp, - union power_supply_propval *val) -{ - int ret = 0; - struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb); - - switch (psp) { - case POWER_SUPPLY_PROP_ONLINE: - val->intval = mbc->adapter_online; - 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 pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb); - - switch (psp) { - case POWER_SUPPLY_PROP_ONLINE: - val->intval = mbc->usb_online; - break; - default: - ret = -EINVAL; - break; - } - return ret; -} - -static enum power_supply_property power_props[] = { - POWER_SUPPLY_PROP_ONLINE, -}; - -int __init pcf50633_mbc_probe(struct platform_device *pdev) -{ - struct pcf50633 *pcf; - struct pcf50633_mbc *mbc; - int ret; - - pcf = platform_get_drvdata(pdev); - mbc = &pcf->mbc; - - /* Set up IRQ handlers */ - pcf->irq_handler[PCF50633_IRQ_ADPINS].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_ADPREM].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_USBINS].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_USBREM].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_BATFULL].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_CHGHALT].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_THLIMON].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_THLIMOFF].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_USBLIMON].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_USBLIMOFF].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_LOWSYS].handler = - pcf50633_mbc_irq_handler; - pcf->irq_handler[PCF50633_IRQ_LOWBAT].handler = - pcf50633_mbc_irq_handler; - - /* Create power supplies */ - - mbc->adapter.name = "adapter"; - mbc->adapter.type = POWER_SUPPLY_TYPE_MAINS; - mbc->adapter.properties = power_props; - mbc->adapter.num_properties = ARRAY_SIZE(power_props); - mbc->adapter.get_property = &adapter_get_property; - mbc->adapter.supplied_to = pcf->pdata->batteries; - mbc->adapter.num_supplicants = pcf->pdata->num_batteries; - - mbc->usb.name = "usb"; - mbc->usb.type = POWER_SUPPLY_TYPE_USB; - mbc->usb.properties = power_props; - mbc->usb.num_properties = ARRAY_SIZE(power_props); - mbc->usb.get_property = usb_get_property; - mbc->usb.supplied_to = pcf->pdata->batteries; - mbc->usb.num_supplicants = pcf->pdata->num_batteries; - - ret = power_supply_register(&pdev->dev, &mbc->adapter); - if (ret) - dev_err(pcf->dev, "failed to register adapter\n"); - - ret = power_supply_register(&pdev->dev, &mbc->usb); - if (ret) - dev_err(pcf->dev, "failed to register usb\n"); - - return sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group); -} - -static int __devexit pcf50633_mbc_remove(struct platform_device *pdev) -{ - struct pcf50633 *pcf; - - pcf = platform_get_drvdata(pdev); - - return 0; -} - -struct platform_driver pcf50633_mbc_driver = { - .driver = { - .name = "pcf50633-mbc", - }, - .probe = pcf50633_mbc_probe, - .remove = __devexit_p(pcf50633_mbc_remove), -}; - -static int __init pcf50633_mbc_init(void) -{ - return platform_driver_register(&pcf50633_mbc_driver); -} -module_init(pcf50633_mbc_init); - -static void __exit pcf50633_mbc_exit(void) -{ - platform_driver_unregister(&pcf50633_mbc_driver); -} -module_exit(pcf50633_mbc_exit); - -MODULE_AUTHOR("Balaji Rao "); -MODULE_DESCRIPTION("PCF50633 mbc driver"); -MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:pcf50633-mbc"); - -- cgit v1.2.3