PCF50633 support
Subsystems (4)
cover PCF50633 support
[Dropped LKML accidently - resending]
The following series implements support for NXP PCF50633. It's basically an I2C device with 9 regulators, an ADC, a PMIC, a Battery Charger and a RTC.
This chip is used in Openmoko Neo Freerunner mobile phone.
Driver for a similar chip PCF50606, used in Openmoko Neo 1973 device will follow soon.
The specs are open and are available at
http://people.openmoko.org/tony_tu/GTA02/datasheet/PMU/PCF50633DS_02.pdf
---
Balaji Rao (7):
mfd: PCF50633 core driver
mfd: PCF50633 adc driver
mfd: PCF50633 gpio support
rtc: PCF50633 rtc driver
power_supply: PCF50633 battery charger driver
input: PCF50633 input driver
regulator: PCF50633 pmic driver
drivers/input/misc/Kconfig | 6 drivers/input/misc/Makefile | 1 drivers/input/misc/pcf50633-input.c | 119 ++++++ drivers/mfd/Kconfig | 23 + drivers/mfd/Makefile | 6 drivers/mfd/pcf50633-adc.c | 263 ++++++++++++ drivers/mfd/pcf50633-core.c | 681 ++++++++++++++++++++++++++++++++ drivers/mfd/pcf50633-gpio.c | 86 ++++ drivers/power/Kconfig | 6 drivers/power/Makefile | 2 drivers/power/pcf50633-charger.c | 285 +++++++++++++ drivers/regulator/Kconfig | 7 drivers/regulator/Makefile | 1 drivers/regulator/pcf50633-regulator.c | 338 ++++++++++++++++ drivers/rtc/Kconfig | 6 drivers/rtc/Makefile | 1 drivers/rtc/rtc-pcf50633.c | 302 ++++++++++++++ include/linux/mfd/pcf50633/adc.h | 88 ++++ include/linux/mfd/pcf50633/core.h | 212 ++++++++++ include/linux/mfd/pcf50633/gpio.h | 52 ++ include/linux/mfd/pcf50633/input.h | 29 + include/linux/mfd/pcf50633/led.h | 24 + include/linux/mfd/pcf50633/mbc.h | 137 ++++++ include/linux/mfd/pcf50633/pmic.h | 75 ++++ include/linux/mfd/pcf50633/rtc.h | 43 ++ 25 files changed, 2792 insertions(+), 1 deletions(-) create mode 100644 drivers/input/misc/pcf50633-input.c create mode 100644 drivers/mfd/pcf50633-adc.c create mode 100644 drivers/mfd/pcf50633-core.c create mode 100644 drivers/mfd/pcf50633-gpio.c create mode 100644 drivers/power/pcf50633-charger.c create mode 100644 drivers/regulator/pcf50633-regulator.c create mode 100644 drivers/rtc/rtc-pcf50633.c create mode 100644 include/linux/mfd/pcf50633/adc.h create mode 100644 include/linux/mfd/pcf50633/core.h create mode 100644 include/linux/mfd/pcf50633/gpio.h create mode 100644 include/linux/mfd/pcf50633/input.h create mode 100644 include/linux/mfd/pcf50633/led.h create mode 100644 include/linux/mfd/pcf50633/mbc.h create mode 100644 include/linux/mfd/pcf50633/pmic.h create mode 100644 include/linux/mfd/pcf50633/rtc.h
Signature · 1 line
Balaji Rao
PATCH 1/7 mfd: PCF50633 core driver
This patch implements the core of the PCF50633 driver. This core driver has generic register read/write functions and does interrupt management for its sub devices.
This patch is against linux-2.6.git
--- drivers/mfd/Kconfig | 9 drivers/mfd/Makefile | 4 drivers/mfd/pcf50633-core.c | 681 ++++++++++++++++++++++++++++++++++++ include/linux/mfd/pcf50633/adc.h | 88 +++++ include/linux/mfd/pcf50633/core.h | 212 +++++++++++ include/linux/mfd/pcf50633/gpio.h | 52 +++ include/linux/mfd/pcf50633/input.h | 29 ++ include/linux/mfd/pcf50633/led.h | 24 + include/linux/mfd/pcf50633/mbc.h | 137 +++++++ include/linux/mfd/pcf50633/pmic.h | 75 ++++ include/linux/mfd/pcf50633/rtc.h | 43 ++ 11 files changed, 1353 insertions(+), 1 deletions(-) create mode 100644 drivers/mfd/pcf50633-core.c create mode 100644 include/linux/mfd/pcf50633/adc.h create mode 100644 include/linux/mfd/pcf50633/core.h create mode 100644 include/linux/mfd/pcf50633/gpio.h create mode 100644 include/linux/mfd/pcf50633/input.h create mode 100644 include/linux/mfd/pcf50633/led.h create mode 100644 include/linux/mfd/pcf50633/mbc.h create mode 100644 include/linux/mfd/pcf50633/pmic.h create mode 100644 include/linux/mfd/pcf50633/rtc.h
drivers/mfd/Kconfig +9 -0
@@ -153,6 +153,15 @@ config MFD_WM8350_I2C I2C as the control interface. Additional options must be selected to enable support for the functionality of the chip. +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. + endmenu menu "Multimedia Capabilities Port drivers"
drivers/mfd/Makefile +3 -1
@@ -31,4 +31,6 @@ obj-$(CONFIG_MCP_UCB1200) += ucb1x00-assabet.o endif obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o -obj-$(CONFIG_PMIC_DA903X) += da903x.o +obj-$(CONFIG_PMIC_DA903X) += da903x.o + +obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o
drivers/mfd/pcf50633-core.c new file +681 -0
681 lines not on this page · raw message
include/linux/mfd/pcf50633/adc.h new file +88 -0
88 lines not on this page · raw message
include/linux/mfd/pcf50633/core.h new file +212 -0
212 lines not on this page · raw message
include/linux/mfd/pcf50633/gpio.h new file +52 -0
52 lines not on this page · raw message
include/linux/mfd/pcf50633/input.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* input.h -- Input driver for NXP PCF50633 +* +* (C) 2006-2008 by Openmoko, Inc. +* 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. +*/ + +#ifndef __LINUX_MFD_PCF50633_INPUT_H +#define __LINUX_MFD_PCF50633_INPUT_H + +#include <linux/platform_device.h> +#include <linux/input.h> + +#define PCF50633_OOCSTAT_ONKEY 0x01 +#define PCF50633_REG_OOCSTAT 0x12 +#define PCF50633_REG_OOCMODE 0x10 + +struct pcf50633_input { +struct input_dev *input_dev; +struct platform_device *pdev; +}; + +#endif +
include/linux/mfd/pcf50633/led.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* led.h -- LED driver for NXP PCF50633 +* +* (C) 2006-2008 by Openmoko, Inc. +* 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. +*/ + +#ifndef __LINUX_MFD_PCF50633_LED_H +#define __LINUX_MFD_PCF50633_LED_H + +#include <linux/platform_device.h> + +#define PCF50633_REG_LEDOUT 0x28 +#define PCF50633_REG_LEDENA 0x29 +#define PCF50633_REG_LEDCTL 0x2a +#define PCF50633_REG_LEDDIM 0x2b + +#endif +
include/linux/mfd/pcf50633/mbc.h new file +137 -0
137 lines not on this page · raw message
include/linux/mfd/pcf50633/pmic.h new file +75 -0
75 lines not on this page · raw message
include/linux/mfd/pcf50633/rtc.h new file +43 -0
43 lines not on this page · raw message
PATCH 2/7 mfd: PCF50633 adc driver
In reply to Balaji RaoThis patch adds basic support for the PCF50633 ADC. The subtractive mode is not supported yet.
Since we don't have adc subsystem, it currently lives in drivers/mfd.
--- drivers/mfd/Kconfig | 7 + drivers/mfd/Makefile | 1 drivers/mfd/pcf50633-adc.c | 263 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/pcf50633-adc.c
drivers/mfd/Kconfig +7 -0
@@ -162,6 +162,13 @@ config MFD_PCF50633 facilities, and registers devices for the various functions so that function-specific drivers can bind to them. +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. + endmenu menu "Multimedia Capabilities Port drivers"
drivers/mfd/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o obj-$(CONFIG_PMIC_DA903X) += da903x.o obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o +obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o
drivers/mfd/pcf50633-adc.c new file +263 -0
263 lines not on this page · raw message
PATCH 3/7 mfd: PCF50633 gpio support
In reply to Balaji RaoWhat the PCF05633 calls as a 'GPIO' is much more than the GPIO in the linux sense and there are only 4 of them - which means, the gpiolib is not used here.
--- drivers/mfd/Kconfig | 7 ++++ drivers/mfd/Makefile | 1 + drivers/mfd/pcf50633-gpio.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/pcf50633-gpio.c
drivers/mfd/Kconfig +7 -0
@@ -169,6 +169,13 @@ config PCF50633_ADC Say yes here if you want to include support for ADC in the NXP PCF50633 chip. +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. + endmenu menu "Multimedia Capabilities Port drivers"
drivers/mfd/Makefile +1 -0
@@ -35,3 +35,4 @@ obj-$(CONFIG_PMIC_DA903X) += da903x.o obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o +obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
drivers/mfd/pcf50633-gpio.c new file +86 -0
86 lines not on this page · raw message
PATCH 4/7 rtc: PCF50633 rtc driver
In reply to Balaji Rao--- drivers/rtc/Kconfig | 6 + drivers/rtc/Makefile | 1 drivers/rtc/rtc-pcf50633.c | 302 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-pcf50633.c
drivers/rtc/Kconfig +6 -0
@@ -497,6 +497,12 @@ config RTC_DRV_WM8350 This driver can also be built as a module. If so, the module will be called "rtc-wm8350". +config RTC_DRV_PCF50633 + depends on MFD_PCF50633 + tristate "NXP PCF50633 RTC" + help + If you say yes here you get support for the NXP PCF50633 RTC. + comment "on-CPU RTC drivers" config RTC_DRV_OMAP
drivers/rtc/Makefile +1 -0
@@ -70,3 +70,4 @@ obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o +obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o
drivers/rtc/rtc-pcf50633.c new file +302 -0
302 lines not on this page · raw message
Re: [PATCH 4/7] rtc: PCF50633 rtc driver
On Sun, 14 Dec 2008 16:33:05 +0530
Balaji Rao <[email protected]> wrote:
Hello,
first review below. Please always add the rtc-linux mailing
list in cc so that patchwork[1] can track your submission.
[1]
http://patchwork.ozlabs.org/project/rtc-linux/list/?state=*
Quoted 56 lines
Signed-off-by Balaji Rao <[email protected]>Cc Andy Green <[email protected]>Cc Alessandro Zummo <[email protected]>Cc Paul Gortmaker <[email protected]>--- drivers/rtc/Kconfig | 6 + drivers/rtc/Makefile | 1 drivers/rtc/rtc-pcf50633.c | 302 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-pcf50633.cdrivers/rtc/Kconfig +6
-0@@ -497,6 +497,12 @@ config RTC_DRV_WM8350 This driver can also be built as a module. If so, the module will be called "rtc-wm8350". +config RTC_DRV_PCF50633 + depends on MFD_PCF50633 + tristate "NXP PCF50633 RTC" + help + If you say yes here you get support for the NXP PCF50633 RTC. + comment "on-CPU RTC drivers" config RTC_DRV_OMAPdrivers/rtc/Makefile +1
-0@@ -70,3 +70,4 @@ obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o +obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.odrivers/rtc/rtc-pcf50633.c new file +13
-0@@ -0,0 +1,302 @@ +/* NXP PCF50633 RTC Driver +* +* (C) 2006-2008 by Openmoko, Inc. +* Author: Balaji Rao <[email protected]> +* All rights reserved. +* +* Broken down from monstrous PCF50633 driver mainly by +* Harald Welte, Andy Green and Werner Almesberger +* +* 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.
drivers/rtc/rtc-pcf50633.c line 23
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+* +* 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
I believe the shorter form of the GPL could be good as well.
drivers/rtc/rtc-pcf50633.c line 31
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c new file +8
-0+*/ + +#include <linux/rtc.h> +#include <linux/platform_device.h> +#include <linux/bcd.h> + +#include <linux/mfd/pcf50633/core.h> +#include <linux/mfd/pcf50633/rtc.h>
this file should be included with the patch.
Quoted 27 lines
drivers/rtc/rtc-pcf50633.c new file +27
-0+ +enum pcf50633_time_indexes { +PCF50633_TI_SEC , +PCF50633_TI_MIN , +PCF50633_TI_HOUR , +PCF50633_TI_WKDAY , +PCF50633_TI_DAY , +PCF50633_TI_MONTH , +PCF50633_TI_YEAR , +PCF50633_TI_EXTENT /* always last */ +}; + + +struct pcf50633_time { +u_int8_t time[PCF50633_TI_EXTENT ]; +}; + +static void pcf2rtc_time (struct rtc_time *rtc,struct pcf50633_time *pcf) +{ + rtc->tm_sec =bcd2bin (pcf->time[PCF50633_TI_SEC ]); + rtc->tm_min =bcd2bin (pcf->time[PCF50633_TI_MIN ]); + rtc->tm_hour =bcd2bin (pcf->time[PCF50633_TI_HOUR ]); + rtc->tm_wday =bcd2bin (pcf->time[PCF50633_TI_WKDAY ]); + rtc->tm_mday =bcd2bin (pcf->time[PCF50633_TI_DAY ]); + rtc->tm_mon =bcd2bin (pcf->time[PCF50633_TI_MONTH ]); + rtc->tm_year =bcd2bin (pcf->time[PCF50633_TI_YEAR ]) +100 ; +}
drivers/rtc/rtc-pcf50633.c line 68
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+ +static void rtc2pcf_time (struct pcf50633_time *pcf,struct rtc_time *rtc) +{ + pcf->time[PCF50633_TI_SEC ] =bin2bcd (rtc->tm_sec); + pcf->time[PCF50633_TI_MIN ] =bin2bcd (rtc->tm_min); + pcf->time[PCF50633_TI_HOUR ] =bin2bcd (rtc->tm_hour); + pcf->time[PCF50633_TI_WKDAY ] =bin2bcd (rtc->tm_wday); + pcf->time[PCF50633_TI_DAY ] =bin2bcd (rtc->tm_mday); + pcf->time[PCF50633_TI_MONTH ] =bin2bcd (rtc->tm_mon); + pcf->time[PCF50633_TI_YEAR ] =bin2bcd (rtc->tm_year -100 );
you should add a check in the caller for tm_year < 100
drivers/rtc/rtc-pcf50633.c line 76
Quoted 8 lines
drivers/rtc/rtc-pcf50633.c new file +8
-0+} + +static int +pcf50633_rtc_ioctl (struct device *dev,unsigned int cmd,unsigned long arg) +{ +struct pcf50633 *pcf; + + pcf =dev_get_drvdata (dev);
this could be an one-liner (not mandatory).
Quoted 8 lines
drivers/rtc/rtc-pcf50633.c new file +8
-0+switch (cmd) { +case RTC_AIE_OFF : + pcf->rtc.alarm_enabled =0 ; +pcf50633_irq_mask (pcf,PCF50633_IRQ_ALARM ); +return 0 ; +case RTC_AIE_ON : + pcf->rtc.alarm_enabled =1 ; +pcf50633_irq_unmask (pcf,PCF50633_IRQ_ALARM );
drivers/rtc/rtc-pcf50633.c line 95
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+return 0 ; +case RTC_PIE_OFF : + pcf->rtc.second_enabled =0 ; +pcf50633_irq_mask (pcf,PCF50633_IRQ_SECOND ); +return 0 ; +case RTC_PIE_ON : + pcf->rtc.second_enabled =1 ; +pcf50633_irq_unmask (pcf,PCF50633_IRQ_SECOND ); +return 0 ; + }
we have recently improved the API for interrupts handling. the patch is now in -mm and you can check it here:
http://patchwork.ozlabs.org/patch/10039/
that involves AIE and UIE.
the API for PIE was always there and it's implemented by ops->irq_set_state and ops->irq_set_freq
Is your PIE a real PIE or an UIE?
Quoted 6 lines
drivers/rtc/rtc-pcf50633.c new file +6
-0+return -ENOIOCTLCMD ; +} + +static int pcf50633_rtc_read_time (struct device *dev,struct rtc_time *tm) +{ +struct pcf50633 *pcf;
drivers/rtc/rtc-pcf50633.c line 112
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+struct pcf50633_time pcf_tm; +int ret; + + pcf =dev_get_drvdata (dev); + + 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" );
so return -EIO or something to that effect.
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +5
-0+ dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n", + pcf_tm.time[PCF50633_TI_DAY], + pcf_tm.time[PCF50633_TI_MONTH], + pcf_tm.time[PCF50633_TI_YEAR], + pcf_tm.time[PCF50633_TI_HOUR],
drivers/rtc/rtc-pcf50633.c line 128
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+ pcf_tm.time[PCF50633_TI_MIN ], + pcf_tm.time[PCF50633_TI_SEC]); + +pcf2rtc_time (tm, &pcf_tm); + +dev_dbg (dev,"RTC_TIME: %u.%u.%u %u:%u:%u\n" , + tm->tm_mday, tm->tm_mon, tm->tm_year, + tm->tm_hour, tm->tm_min, tm->tm_sec); + +return 0 ;
nope. always return rtc_valid_tm(tm);
Quoted 35 lines
drivers/rtc/rtc-pcf50633.c new file +35
-0+} + +static int pcf50633_rtc_set_time (struct device *dev,struct rtc_time *tm) +{ +struct pcf50633 *pcf; +struct pcf50633_time pcf_tm; +int second_masked, alarm_masked, ret =0 ; + + 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, + tm->tm_hour, tm->tm_min, tm->tm_sec); + +rtc2pcf_time (&pcf_tm, tm); + +dev_dbg (dev,"PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n" , + pcf_tm.time[PCF50633_TI_DAY ], + pcf_tm.time[PCF50633_TI_MONTH ], + pcf_tm.time[PCF50633_TI_YEAR ], + pcf_tm.time[PCF50633_TI_HOUR ], + pcf_tm.time[PCF50633_TI_MIN ], + pcf_tm.time[PCF50633_TI_SEC ]); + + + 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,
drivers/rtc/rtc-pcf50633.c line 173
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+ &pcf_tm.time[0]); +if (ret) +dev_err (dev,"Failed to set time %d\n" , ret); + +if (!second_masked) +pcf50633_irq_unmask (pcf,PCF50633_IRQ_SECOND ); +if (!alarm_masked) +pcf50633_irq_unmask (pcf,PCF50633_IRQ_ALARM ); + +return ret;
is this ret an appropriate error code?
Quoted 11 lines
drivers/rtc/rtc-pcf50633.c new file +11
-0+} + +static int pcf50633_rtc_read_alarm (struct device *dev,struct rtc_wkalrm *alrm) +{ +struct pcf50633 *pcf; +struct pcf50633_time pcf_tm; +int ret =0 ; + + pcf =dev_get_drvdata (dev); + + alrm->enabled = pcf->rtc.alarm_enabled;
drivers/rtc/rtc-pcf50633.c line 194
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+ + 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 %d\n" , ret); + +pcf2rtc_time (&alrm->time, &pcf_tm); + +return ret;
probably wrong, ret must be 0 on success.
Quoted 20 lines
drivers/rtc/rtc-pcf50633.c new file +20
-0+} + +static int pcf50633_rtc_set_alarm (struct device *dev,struct rtc_wkalrm *alrm) +{ +struct pcf50633 *pcf; +struct pcf50633_time pcf_tm; +int alarm_masked, ret =0 ; + + pcf =dev_get_drvdata (dev); + +rtc2pcf_time (&pcf_tm, &alrm->time); + +/* do like mktime does and ignore tm_wday */ + pcf_tm.time[PCF50633_TI_WKDAY ] =7 ; + + alarm_masked =pcf50633_irq_mask_get (pcf,PCF50633_IRQ_ALARM ); + +/* disable alarm interrupt */ +if (!alarm_masked) +pcf50633_irq_mask (pcf,PCF50633_IRQ_ALARM );
drivers/rtc/rtc-pcf50633.c line 224
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+ + 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 (!alarm_masked) +pcf50633_irq_unmask (pcf,PCF50633_IRQ_ALARM ); + +return ret;
ditto?
Quoted 20 lines
drivers/rtc/rtc-pcf50633.c new file +20
-0+} +static struct rtc_class_ops pcf50633_rtc_ops = { + .ioctl = pcf50633_rtc_ioctl, + .read_time = pcf50633_rtc_read_time, + .set_time = pcf50633_rtc_set_time, + .read_alarm = pcf50633_rtc_read_alarm, + .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 ; +case PCF50633_IRQ_SECOND : +rtc_update_irq (pcf->rtc.rtc_dev,1 ,RTC_PF |RTC_IRQF ); +break ; + } +}
drivers/rtc/rtc-pcf50633.c line 254
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+ +static int pcf50633_rtc_probe (struct platform_device *pdev) +{ +struct rtc_device *rtc; +struct pcf50633 *pcf; + + rtc =rtc_device_register ("pcf50633-rtc" , &pdev->dev, + &pcf50633_rtc_ops,THIS_MODULE ); +if (IS_ERR (rtc)) +return -ENODEV ;
nope. if IS_ERR means that the rtc pointer has a valid error code that you should return to the caller.
drivers/rtc/rtc-pcf50633.c
Quoted 1 line
drivers/rtc/rtc-pcf50633.c new file +1
-0+ pcf =platform_get_drvdata (pdev);
uh? where did you set up the pointer?
drivers/rtc/rtc-pcf50633.c line 262
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +5
-0+/* 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;
??
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+return 0 ; +} + +static int pcf50633_rtc_remove (struct platform_device *pdev) +{ +struct pcf50633 *pcf; + + pcf =platform_get_drvdata (pdev); +rtc_device_unregister (pcf->rtc.rtc_dev); +
drivers/rtc/rtc-pcf50633.c line 283
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c new file +10
-0+return 0 ; +} + + +static struct platform_driver pcf50633_rtc_driver = { + .driver = { + .name ="pcf50633-rtc" , + }, + .probe = pcf50633_rtc_probe, + .remove =__devexit_p (pcf50633_rtc_remove),
you marked __devexit_p but forgot to mark the function
itself.
drivers/rtc/rtc-pcf50633.c line 288
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +5
-0+}; + +static int __init pcf50633_rtc_init (void ) +{ +return platform_driver_register (&pcf50633_rtc_driver);
can't you use platform_driver_probe ?
Quoted 15 lines
drivers/rtc/rtc-pcf50633.c new file +14
-0+} +module_init (pcf50633_rtc_init); + +static void __exit pcf50633_rtc_exit(void) +{ +platform_driver_unregister (&pcf50633_rtc_driver); +} +module_exit (pcf50633_rtc_exit); + + +MODULE_DESCRIPTION ("PCF50633 RTC driver" ); +MODULE_AUTHOR ("Balaji Rao <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +
Signature · 6 lines
Best regards, Alessandro Zummo, Tower Technologies - Torino, Italy http://www.towertech.it
Re: [PATCH 4/7] rtc: PCF50633 rtc driver
Quoted 11 lines · Alessandro Zummo
On Sun, 14 Dec 2008 16:33:05 +0530
Balaji Rao <[email protected]> wrote:Hello,
first review below. Please always add the rtc-linux mailing
list in cc so that patchwork[1] can track your submission.[1]
http://patchwork.ozlabs.org/project/rtc-linux/list/?state=*
OK, noted,
Quoted 8 lines
drivers/rtc/rtc-pcf50633.c line 31
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +4
-0+#include <linux/bcd.h> + +#include <linux/mfd/pcf50633/core.h> +#include <linux/mfd/pcf50633/rtc.h> this file should be included with the patch.
Hmm. This patch is included in [PATCH 1/7] of the series - which implements the core driver. This core driver needs this file to compile and not including there is going to break the bisectability of the series. Isn't this what I'm supposed to do ? Please correct me if I'm wrong.
Quoted 12 lines
drivers/rtc/rtc-pcf50633.c line 68
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c new file +9
-0+static void rtc2pcf_time (struct pcf50633_time *pcf,struct rtc_time *rtc) +{ + pcf->time[PCF50633_TI_SEC ] =bin2bcd (rtc->tm_sec); + pcf->time[PCF50633_TI_MIN ] =bin2bcd (rtc->tm_min); + pcf->time[PCF50633_TI_HOUR ] =bin2bcd (rtc->tm_hour); + pcf->time[PCF50633_TI_WKDAY ] =bin2bcd (rtc->tm_wday); + pcf->time[PCF50633_TI_DAY ] =bin2bcd (rtc->tm_mday); + pcf->time[PCF50633_TI_MONTH ] =bin2bcd (rtc->tm_mon); + pcf->time[PCF50633_TI_YEAR ] =bin2bcd (rtc->tm_year -100 );you should add a check in the caller for
tm_year< 100
OK.
Quoted 14 lines
drivers/rtc/rtc-pcf50633.c line 95
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c new file +9
-0+case RTC_PIE_OFF : + pcf->rtc.second_enabled =0 ; +pcf50633_irq_mask (pcf,PCF50633_IRQ_SECOND ); +return 0 ; +case RTC_PIE_ON : + pcf->rtc.second_enabled =1 ; +pcf50633_irq_unmask (pcf,PCF50633_IRQ_SECOND ); +return 0 ; + }we have recently improved the API for interrupts handling. the patch is now in -mm and you can check it here:
http://patchwork.ozlabs.org/patch/10039/
Quoted 7 lines
that involves AIE and UIE.
the API for PIE was always there and it's implemented by
ops->irq_set_stateandops->irq_set_freqIs your PIE a real PIE or an UIE?
OK.
Oh.. yes, it's actually an UIE! Sorry about that - will change.
Quoted 10 lines
drivers/rtc/rtc-pcf50633.c line 112
Quoted 7 lines
drivers/rtc/rtc-pcf50633.c new file +7
-0+ pcf =dev_get_drvdata (dev); + + 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" );so return
-EIOor something to that effect.
OK.
Quoted 9 lines
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c new file +9
-0+dev_dbg (dev,"PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n" , + pcf_tm.time[PCF50633_TI_DAY ], + pcf_tm.time[PCF50633_TI_MONTH ], + pcf_tm.time[PCF50633_TI_YEAR ], + pcf_tm.time[PCF50633_TI_HOUR ], + pcf_tm.time[PCF50633_TI_MIN ], + pcf_tm.time[PCF50633_TI_SEC ]); + +pcf2rtc_time (tm, &pcf_tm);
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c line 128
Quoted 6 lines
drivers/rtc/rtc-pcf50633.c new file +6
-0+ +dev_dbg (dev,"RTC_TIME: %u.%u.%u %u:%u:%u\n" , + tm->tm_mday, tm->tm_mon, tm->tm_year, + tm->tm_hour, tm->tm_min, tm->tm_sec); + +return 0 ;nope. always return
rtc_valid_tm(tm);
OK.
Quoted 7 lines
Quoted 7 lines
drivers/rtc/rtc-pcf50633.c new file +7
-0+ + 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); +
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c line 173
Quoted 6 lines
drivers/rtc/rtc-pcf50633.c new file +6
-0+if (!second_masked) +pcf50633_irq_unmask (pcf,PCF50633_IRQ_SECOND ); +if (!alarm_masked) +pcf50633_irq_unmask (pcf,PCF50633_IRQ_ALARM ); + +return ret;is this ret an appropriate error code?
Oops! No, it's wrong. Will fix.
Quoted 12 lines
drivers/rtc/rtc-pcf50633.c line 194
Quoted 9 lines
drivers/rtc/rtc-pcf50633.c new file +9
-0+ 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 %d\n" , ret); + +pcf2rtc_time (&alrm->time, &pcf_tm); + +return ret;probably wrong, ret must be 0 on success.
Right. Will fix.
Quoted 11 lines
drivers/rtc/rtc-pcf50633.c line 254
Quoted 7 lines
drivers/rtc/rtc-pcf50633.c new file +7
-0+struct rtc_device *rtc; +struct pcf50633 *pcf; + + rtc =rtc_device_register ("pcf50633-rtc" , &pdev->dev, + &pcf50633_rtc_ops,THIS_MODULE ); +if (IS_ERR (rtc)) +return -ENODEV ;nope. if
IS_ERRmeans that the rtc pointer has a valid error code that you should return to the caller.
Fine. Will change.
Quoted 5 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ pcf = platform_get_drvdata(pdev);uh? where did you set up the pointer?
Quoted 8 lines
drivers/rtc/rtc-pcf50633.c line 262
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +5
-0+/* 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;??
It's done in the core driver - [PATCH 1/7] of this series.
Quoted 6 lines
drivers/rtc/rtc-pcf50633.c line 283
Quoted 2 lines
drivers/rtc/rtc-pcf50633.c new file +2
-0+ .probe = pcf50633_rtc_probe, + .remove = __devexit_p(pcf50633_rtc_remove),you marked
__devexit_pbut forgot to mark the function
itself.
Oh! will fix.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + return platform_driver_register(&pcf50633_rtc_driver);can't you use
platform_driver_probe?
Yes, I probably can. Will change.
Thank you for the review. Will send again after resolving the issues.
- Balaji
Re: [rtc-linux] Re: [PATCH 4/7] rtc: PCF50633 rtc driver
Quoted 5 lines · On Mon, 15 Dec 2008 03:34:30 +0530 Balaji Rao <[email protected]> wrote:
Hmm. This patch is included in [PATCH 1/7] of the series - which implements the core driver. This core driver needs this file to compile and not including there is going to break the bisectability of the series. Isn't this what I'm supposed to do ? Please correct me if I'm wrong.
ok, then don't break.
Quoted 14 lines
Quoted 5 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ pcf = platform_get_drvdata(pdev);uh? where did you set up the pointer?
Quoted 8 lines
drivers/rtc/rtc-pcf50633.c line 262
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +5
-0+/* 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;??
Quoted 1 line
It's done in the core driver - [PATCH 1/7] of this series.
mm. that's strange. a platform driver is supposed to receive informational structures (regions, irqs, ...) and init driver data by itself. you shouldn't need to mess with the drvdata pointer.
I do not also feel fine with the irq handlers setup. Your core should export a function for irq registration.
Quoted 1 line
Thank you for the review. Will send again after resolving the issues.
thanks for your contribution. you are doing great things at openmoko.
Signature · 6 lines
Best regards, Alessandro Zummo, Tower Technologies - Torino, Italy http://www.towertech.it
Re: [rtc-linux] Re: [PATCH 4/7] rtc: PCF50633 rtc driver
Quoted 11 lines · Alessandro Zummo
Quoted 5 lines · On Mon, 15 Dec 2008 03:34:30 +0530 Balaji Rao <[email protected]> wrote:
Hmm. This patch is included in [PATCH 1/7] of the series - which implements the core driver. This core driver needs this file to compile and not including there is going to break the bisectability of the series. Isn't this what I'm supposed to do ? Please correct me if I'm wrong.
ok, then don't break.
OK, thinking more about this, I realised that this series, has to be taken in together, as rtc-pcf50633.c alone wouldn't compile for you..
Probably it could be taken into the MFD tree once you ACK this ? I don't know.. If this is not a problem at all, please feel free to ignore me!
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ pcf = platform_get_drvdata(pdev);uh? where did you set up the pointer?
drivers/rtc/rtc-pcf50633.c line 262
Quoted 5 lines
drivers/rtc/rtc-pcf50633.c new file +5
-0+/* 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;??
Quoted 6 lines
Quoted 1 line
It's done in the core driver - [PATCH 1/7] of this series.
mm. that's strange. a platform driver is supposed to receive informational structures (regions, irqs, ...) and init driver data by itself. you shouldn't need to mess with the drvdata pointer.
Oh, ok. I now see how I can do better. Will wait for comments for the rest of the series and post a improved version.
Quoted 3 lines
I do not also feel fine with the irq handlers setup. Your core should export a function for irq registration.
Yes, ok.
Quoted 4 lines
Quoted 1 line
Thank you for the review. Will send again after resolving the issues.
thanks for your contribution. you are doing great things at openmoko.
You're welcome.
- Balaji
Re: [rtc-linux] Re: [PATCH 4/7] rtc: PCF50633 rtc driver
Quoted 5 lines · On Mon, 15 Dec 2008 04:59:46 +0530 Balaji Rao <[email protected]> wrote:
OK, thinking more about this, I realised that this series, has to be taken in together, as
rtc-pcf50633.calone wouldn't compile for you..Probably it could be taken into the MFD tree once you ACK this ? I don't know.. If this is not a problem at all, please feel free to ignore me!
Any tree is good for me
Signature · 6 lines
Best regards, Alessandro Zummo, Tower Technologies - Torino, Italy http://www.towertech.it
PATCH 5/7 power_supply: PCF50633 battery charger driver
In reply to Balaji Rao--- drivers/power/Kconfig | 6 + drivers/power/Makefile | 2 drivers/power/pcf50633-charger.c | 285 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 0 deletions(-) create mode 100644 drivers/power/pcf50633-charger.c
drivers/power/Kconfig +6 -0
@@ -75,4 +75,10 @@ config BATTERY_BQ27x00 help Say Y here to enable support for batteries with BQ27200(I2C) chip. +config CHARGER_PCF50633 + tristate "NXP PCF50633 MBC" + depends on MFD_PCF50633 + help + Say Y to include support for NXP PCF50633 Main Battery Charger. + endif # POWER_SUPPLY
drivers/power/Makefile +2 -0
@@ -24,3 +24,5 @@ obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o + +obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
drivers/power/pcf50633-charger.c new file +285 -0
285 lines not on this page · raw message
Re: [PATCH 5/7] power_supply: PCF50633 battery charger driver
Quoted 4 lines · Balaji Rao
drivers/power/pcf50633-charger.c new file +4
-0+ +static int __devexit pcf50633_mbc_remove(struct platform_device *pdev) +{ +struct pcf50633 *pcf;
drivers/power/pcf50633-charger.c line 261
Quoted 10 lines
drivers/power/pcf50633-charger.c new file +10
-0+ + pcf =platform_get_drvdata (pdev); + +/* Remove IRQ handlers */ +for (i =0 ; i <ARRAY_SIZE (mbc_irq_handlers); i++) + pcf->irq_handler[mbc_irq_handlers[i]] =NULL ; + +return 0 ; +} +
Whoops! 'i not declared'. Oh., These last minute changes..
Will wait for more comments before sending a fixed version.
- Balaji
Quoted 1 line
Re: [PATCH 5/7] power_supply: PCF50633 battery charger driver
In reply to Balaji RaoHello Balaji,
It's great to see OpenMoko patches submitted, much thanks for your work!
You can find few comments below.
Quoted 58 lines · Balaji Rao
Signed-off-by Balaji Rao <[email protected]>Cc Andy Green <[email protected]>Cc Anton Vorontsov <[email protected]>Cc David Woodhouse <[email protected]>--- drivers/power/Kconfig | 6 + drivers/power/Makefile | 2 drivers/power/pcf50633-charger.c | 285 ++++++++++++++++++++++++++++++++++++++3 files changed, 293 insertions(+), 0 deletions(-) create mode 100644 drivers/power/pcf50633-charger.cdrivers/power/Kconfig +6
-0@@ -75,4 +75,10 @@ config BATTERY_BQ27x00 help Say Y here to enable support for batteries with BQ27200(I2C) chip. +config CHARGER_PCF50633 + tristate "NXP PCF50633 MBC" + depends on MFD_PCF50633 + help + Say Y to include support for NXP PCF50633 Main Battery Charger. + endif # POWER_SUPPLYdrivers/power/Makefile +2
-0@@ -24,3 +24,5 @@ obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o + +obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.odrivers/power/pcf50633-charger.c new file +15
-0@@ -0,0 +1,285 @@ +/* NXP PCF50633 Main Battery Charger Driver +* +* (C) 2006-2008 by Openmoko, Inc. +* Author: Balaji Rao <[email protected]> +* All rights reserved. +* +* Broken down from monstrous PCF50633 driver mainly by +* Harald Welte, Andy Green and Werner Almesberger +* +* 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,
drivers/power/pcf50633-charger.c line 25
Quoted 10 lines
drivers/power/pcf50633-charger.c new file +10
-0+* 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 +*/ +
The code should explicitly include all the needed headers.
#include <linux/kernel.h> (for container_of, sprintf, ...) #include <linux/module.h> (MODULE_, EXPORT_SYMBOL macros) #include <linux/init.h> (initcalls)
#include <linux/types.h> (ssize_t)
#include <linux/device.h> (dev_info e.t.c.) #include <linux/platform_device.h>
#include <linux/power_supply.h>
Quoted 23 lines
drivers/power/pcf50633-charger.c new file +23
-0+#include <linux/mfd/pcf50633/core.h> +#include <linux/mfd/pcf50633/mbc.h> + +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);
drivers/power/pcf50633-charger.c line 58
Quoted 10 lines
drivers/power/pcf50633-charger.c new file +10
-0+ +power_supply_changed (&pcf->mbc.usb); +} +EXPORT_SYMBOL_GPL (pcf50633_mbc_usb_curlim_set); + +static ssize_t +show_chgmode (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct pcf50633 *pcf =dev_get_drvdata (dev); +
Stray empty line.
Quoted 52 lines
drivers/power/pcf50633-charger.c new file +52
-0+u8 mbcs2 =pcf50633_reg_read (pcf,PCF50633_REG_MBCS2 ); +u8 chgmod = (mbcs2 &PCF50633_MBCS2_MBC_MASK ); + +return sprintf (buf,"%d\n" , chgmod); +} +static DEVICE_ATTR(chgmode, S_IRUGO, 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 ssize_t set_usblim (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) +{ +struct pcf50633 *pcf =dev_get_drvdata (dev); +unsigned long ma; +int ret; + + ret =strict_strtoul (buf,10 , &ma); +if (ret) +return -EINVAL ; + +pcf50633_mbc_usb_curlim_set (pcf, ma); + +return count; +} + +static DEVICE_ATTR(usb_curlim, S_IRUGO | S_IWUSR, show_usblim, set_usblim); + +static struct attribute *pcf50633_mbc_sysfs_entries[] = { + &dev_attr_chgmode.attr, + &dev_attr_usb_curlim.attr, +NULL , +}; + +static struct attribute_group mbc_attr_group = {
drivers/power/pcf50633-charger.c line 120
Quoted 10 lines
drivers/power/pcf50633-charger.c new file +10
-0+ .name = NULL, /* put in device directory */ + .attrs = pcf50633_mbc_sysfs_entries, +}; + +static void +pcf50633_mbc_irq_handler (struct pcf50633 *pcf,int irq,void *unused) +{ +struct pcf50633_mbc *mbc; + + mbc = &pcf->mbc;
struct pcf50633_mbc *mbc = &pcf->mbc; would save us two lines.
Quoted 81 lines
drivers/power/pcf50633-charger.c new file +81
-0+ +/* 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 , +}; + +static const u8 mbc_irq_handlers[] = { +PCF50633_IRQ_ADPINS , +PCF50633_IRQ_ADPREM , +PCF50633_IRQ_USBINS , +PCF50633_IRQ_USBREM , +PCF50633_IRQ_BATFULL , +PCF50633_IRQ_CHGHALT , +PCF50633_IRQ_THLIMON , +PCF50633_IRQ_THLIMOFF , +PCF50633_IRQ_USBLIMON ,
drivers/power/pcf50633-charger.c line 211
Quoted 10 lines
drivers/power/pcf50633-charger.c new file +10
-0+PCF50633_IRQ_USBLIMOFF , +PCF50633_IRQ_LOWSYS , + PCF50633_IRQ_LOWBAT, +}; + +int __init pcf50633_mbc_probe (struct platform_device *pdev) +{ +struct pcf50633 *pcf; +struct pcf50633_mbc *mbc; +int ret, i;
int ret;
int i;
drivers/power/pcf50633-charger.c line 214
Quoted 3 lines
drivers/power/pcf50633-charger.c new file +3
-0+ + pcf =platform_get_drvdata (pdev); + mbc = &pcf->mbc;
The two lines can be placed on the same lines with variables definitions.
drivers/power/pcf50633-charger.c line 219
Quoted 5 lines
drivers/power/pcf50633-charger.c new file +5
-0+ +/* Set up IRQ handlers */ +for (i =0 ; i <ARRAY_SIZE (mbc_irq_handlers); i++) + pcf->irq_handler[mbc_irq_handlers[i]] = + pcf50633_mbc_irq_handler;
Ugh. Is there any particular reason why you don't implement a chained interrupt controller in the PCF core? (as in drivers/mfd/asic3.c, for example).
That way you could do ordinary request_irq() for the MFD devices' interrupts.
(I can only guess: you didn't make it because PCF is on the I2C bus, and it's just easier to handle devices via single workqueue in the core driver?)
Quoted 16 lines
drivers/power/pcf50633-charger.c new file +16
-0+/* 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;
drivers/power/pcf50633-charger.c line 246
Quoted 10 lines
drivers/power/pcf50633-charger.c new file +10
-0+ + 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);
If this fail we'll leak two registered power supplies...
drivers/power/pcf50633-charger.c line 253
Quoted 7 lines
drivers/power/pcf50633-charger.c new file +7
-0+} + +static int __devexit pcf50633_mbc_remove(struct platform_device *pdev) +{ +struct pcf50633 *pcf; + + pcf =platform_get_drvdata (pdev);
This could be placed on a single line.
drivers/power/pcf50633-charger.c line 259
Quoted 6 lines
drivers/power/pcf50633-charger.c new file +6
-0+ +/* Remove IRQ handlers */ +for (i =0 ; i <ARRAY_SIZE (mbc_irq_handlers); i++) + pcf->irq_handler[mbc_irq_handlers[i]] =NULL ; + +return 0 ;
The function doesn't handle power supplies unregistration?
drivers/power/pcf50633-charger.c line 272
Quoted 13 lines
drivers/power/pcf50633-charger.c new file +13
-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);
One tab is enough.
drivers/power/pcf50633-charger.c line 278
Quoted 6 lines
drivers/power/pcf50633-charger.c new file +6
-0+} +module_init (pcf50633_mbc_init); + +static void __exit pcf50633_mbc_exit(void) +{ +platform_driver_unregister (&pcf50633_mbc_driver);
Ditto.
drivers/power/pcf50633-charger.c line 285
Quoted 7 lines
drivers/power/pcf50633-charger.c new file +7
-0+} +module_exit (pcf50633_mbc_exit); + +MODULE_AUTHOR ("Balaji Rao <[email protected]>" ); +MODULE_DESCRIPTION ("PCF50633 mbc driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:pcf50633-mbc" );
Thanks again,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Re: [PATCH 5/7] power_supply: PCF50633 battery charger driver
Quoted 5 lines · Anton Vorontsov
Hello Balaji,
It's great to see OpenMoko patches submitted, much thanks for your work!
Hi Anton,
You are welcome!
Quoted 10 lines
drivers/power/pcf50633-charger.c line 219
Quoted 5 lines
drivers/power/pcf50633-charger.c new file +5
-0+ +/* Set up IRQ handlers */ +for (i =0 ; i <ARRAY_SIZE (mbc_irq_handlers); i++) + pcf->irq_handler[mbc_irq_handlers[i]] = + pcf50633_mbc_irq_handler;Ugh. Is there any particular reason why you don't implement a chained interrupt controller in the PCF core? (as in
drivers/mfd/asic3.c, for example).
Quoted 7 lines
That way you could do ordinary
request_irq()for the MFD devices' interrupts.(I can only guess: you didn't make it because PCF is on the I2C bus, and it's just easier to handle devices via single workqueue in the core driver?)
Since we have a fixed number of irq consumers, it's much simpler doing chained interrupts this way. Using an irq_chip is going to introduce unnecessary complezity, I feel.
The V2, of the series (about to be sent) changes how irq managemt is done - pcf50633_request_irq and pcf50633_free_irq are used.
Thank you for the review.
Will send a new version soon.
- Balaji
PATCH 6/7 input: PCF50633 input driver
In reply to Balaji Rao--- drivers/input/misc/Kconfig | 6 ++ drivers/input/misc/Makefile | 1 drivers/input/misc/pcf50633-input.c | 119 +++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/pcf50633-input.c
drivers/input/misc/Kconfig +6 -0
@@ -220,4 +220,10 @@ config HP_SDC_RTC Say Y here if you want to support the built-in real time clock of the HP SDC controller. +config INPUT_PCF50633_PMU + tristate "PCF50633 PMU events" + depends on MFD_PCF50633 + help + Say Y to include support for input events on NXP PCF50633. + endif
drivers/input/misc/Makefile +1 -0
@@ -21,3 +21,4 @@ obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o obj-$(CONFIG_INPUT_UINPUT) += uinput.o obj-$(CONFIG_INPUT_APANEL) += apanel.o obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o +obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
drivers/input/misc/pcf50633-input.c new file +119 -0
119 lines not on this page · raw message
Dmitry Torokhov
maintainerRe: [PATCH 6/7] input: PCF50633 input driver
Hi Balaji,
Quoted 1 line · Balaji Rao
Signed-off-by Balaji Rao <[email protected]>
Looks good, some small nitpicks:
drivers/input/misc/Kconfig config HP_SDC_RTC · line 228
Quoted 7 lines
drivers/input/misc/Kconfig +6
-0+config INPUT_PCF50633_PMU + tristate "PCF50633 PMU events" + depends on MFD_PCF50633 + help + Say Y to include support for input events on NXP PCF50633. +
I'd like to see something like ".. support for deliveing PMU events via input layer on NXP PCF50633".
Quoted 55 lines
endif
drivers/input/misc/Makefile +1
-0@@ -21,3 +21,4 @@ obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o obj-$(CONFIG_INPUT_UINPUT) += uinput.o obj-$(CONFIG_INPUT_APANEL) += apanel.o obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o +obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.odrivers/input/misc/pcf50633-input.c new file +39
-0@@ -0,0 +1,119 @@ +/* NXP PCF50633 Input Driver +* +* (C) 2006-2008 by Openmoko, Inc. +* Author: Balaji Rao <[email protected]> +* All rights reserved. +* +* Broken down from monstrous PCF50633 driver mainly by +* Harald Welte, Andy Green and Werner Almesberger +* +* 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 <linux/input.h> + +#include <linux/mfd/pcf50633/core.h> +#include <linux/mfd/pcf50633/input.h> + +static void +pcf50633_input_irq (struct pcf50633 *pcf,int irq,void *unused) +{ +struct input_dev *input_dev = pcf->input.input_dev; +int onkey_released; + +/* We report only one event depending on the key press status */ + onkey_released =pcf50633_reg_read (pcf,PCF50633_REG_OOCSTAT ) + &PCF50633_OOCSTAT_ONKEY ;
drivers/input/misc/pcf50633-input.c line 49
Quoted 10 lines
drivers/input/misc/pcf50633-input.c new file +10
-0+ +if (irq ==PCF50633_IRQ_ONKEYF && !onkey_released) +input_report_key (input_dev,KEY_POWER ,1 ); +else if (irq ==PCF50633_IRQ_ONKEYR && onkey_released) +input_report_key (input_dev,KEY_POWER ,0 ); + +input_sync (input_dev); +} + +int __init pcf50633_input_probe (struct platform_device *pdev)
Static? __devinit?
Quoted 32 lines
drivers/input/misc/pcf50633-input.c new file +32
-0+{ +struct pcf50633 *pcf; +struct input_dev *input_dev; +int ret; + + pcf =platform_get_drvdata (pdev); + + input_dev =input_allocate_device (); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="PCF50633 PMU events" ; + input_dev->id.bustype =BUS_I2C ; + + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_PWR ); +set_bit (KEY_POWER , input_dev->keybit); + + ret =input_register_device (input_dev); +if (ret) + goto out; + + pcf->input.input_dev = input_dev; + +/* Set up interrupt handlers */ + pcf->irq_handler[PCF50633_IRQ_ONKEYR ].handler = pcf50633_input_irq; + pcf->irq_handler[PCF50633_IRQ_ONKEYF ].handler = pcf50633_input_irq; + +return 0 ; + +out: +input_free_device (input_dev); +return ret;
drivers/input/misc/pcf50633-input.c line 91
Quoted 10 lines
drivers/input/misc/pcf50633-input.c new file +10
-0+} + +static int __devexit pcf50633_input_remove(struct platform_device *pdev) +{ +struct pcf50633 *pcf; + + pcf =platform_get_drvdata (pdev); + +input_unregister_device (pcf->input.input_dev); +input_free_device (pcf->input.input_dev);
Don't call input_free_device() after input_unregister_device(), it will lead to double free.
Quoted 5 lines
drivers/input/misc/pcf50633-input.c new file +5
-0+ +return 0 ; +} + +struct platform_driver pcf50633_input_driver = {
drivers/input/misc/pcf50633-input.c line 106
Quoted 10 lines
drivers/input/misc/pcf50633-input.c new file +10
-0+ .driver = { + .name = "pcf50633-input", + }, + .probe = pcf50633_input_probe, + .remove = __devexit_p(pcf50633_input_remove), +}; + +static int __init pcf50633_input_init (void ) +{ +return platform_driver_register (&pcf50633_input_driver);
Just one tab should be enough.
drivers/input/misc/pcf50633-input.c line 112
Quoted 6 lines
drivers/input/misc/pcf50633-input.c new file +6
-0+} +module_init (pcf50633_input_init); + +static void __exit pcf50633_input_exit(void) +{ +platform_driver_unregister (&pcf50633_input_driver);
Same here.
Quoted 8 lines
drivers/input/misc/pcf50633-input.c new file +7
-0+} +module_exit (pcf50633_input_exit); + +MODULE_AUTHOR ("Balaji Rao <[email protected]>" ); +MODULE_DESCRIPTION ("PCF50633 input driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:pcf50633-input" );
Signature · 1 line
Dmitry
Re: [PATCH 6/7] input: PCF50633 input driver
Quoted 7 lines · Dmitry Torokhov
Hi Balaji,
Quoted 1 line · Balaji Rao
Signed-off-by Balaji Rao <[email protected]>Looks good, some small nitpicks:
Hi Dmitry,
I've incorporated the fixes and will send a V2 shortly.
Thank you for the review!
- Balaji
PATCH 7/7 regulator: PCF50633 pmic driver
In reply to Balaji Rao--- drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 drivers/regulator/pcf50633-regulator.c | 338 ++++++++++++++++++++++++++++++++ 3 files changed, 346 insertions(+), 0 deletions(-) create mode 100644 drivers/regulator/pcf50633-regulator.c
drivers/regulator/Kconfig +7 -0
@@ -73,4 +73,11 @@ config REGULATOR_DA903X Say y here to support the BUCKs and LDOs regulators found on Dialog Semiconductor DA9030/DA9034 PMIC. +config REGULATOR_PCF50633 + tristate "PCF50633 regulator driver" + depends on MFD_PCF50633 + help + Say Y here to support the voltage regulators and convertors + on PCF50633 + endif
drivers/regulator/Makefile +1 -0
@@ -11,5 +11,6 @@ obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o obj-$(CONFIG_REGULATOR_DA903X) += da903x.o +obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
drivers/regulator/pcf50633-regulator.c new file +338 -0
338 lines not on this page · raw message
Re: [PATCH 7/7] regulator: PCF50633 pmic driver
drivers/regulator/pcf50633-regulator.c line 262
Quoted 9 lines · Balaji Rao
drivers/regulator/pcf50633-regulator.c new file +9
-0+struct regulator_ops pcf50633_regulator_ops = { + .set_voltage = pcf50633_regulator_set_voltage, + .get_voltage = pcf50633_regulator_get_voltage, + .enable = pcf50633_regulator_enable, + .disable = pcf50633_regulator_disable, + .is_enabled = pcf50633_regulator_is_enabled, + .set_suspend_enable = pcf50633_regulator_enable, + .set_suspend_disable = pcf50633_regulator_disable, +};
Are you sure that the suspend variants of the operations should be the same as the regular versions?
drivers/regulator/pcf50633-regulator.c line 321
Quoted 7 lines
drivers/regulator/pcf50633-regulator.c new file +7
-0+struct platform_driver pcf50633_regulator_driver = { + .driver = { + .name ="pcf50633-regltr" , + }, + .probe = pcf50633_regulator_probe, + .remove =__devexit_p (pcf50633_regulator_remove), +};
Not that it matters too much but I have a hard time liking "regltr".
Re: [PATCH 7/7] regulator: PCF50633 pmic driver
Quoted 15 lines · Mark Brown
drivers/regulator/pcf50633-regulator.c line 262
Quoted 9 lines · Balaji Rao
drivers/regulator/pcf50633-regulator.c new file +9
-0+struct regulator_ops pcf50633_regulator_ops = { + .set_voltage = pcf50633_regulator_set_voltage, + .get_voltage = pcf50633_regulator_get_voltage, + .enable = pcf50633_regulator_enable, + .disable = pcf50633_regulator_disable, + .is_enabled = pcf50633_regulator_is_enabled, + .set_suspend_enable = pcf50633_regulator_enable, + .set_suspend_disable = pcf50633_regulator_disable, +};Are you sure that the suspend variants of the operations should be the same as the regular versions?
Yes, basically the chip doesn't change state during suspend/resume. We just enable or disable them the usual way.
Quoted 9 lines
drivers/regulator/pcf50633-regulator.c line 321
Quoted 7 lines
drivers/regulator/pcf50633-regulator.c new file +7
-0+struct platform_driver pcf50633_regulator_driver = { + .driver = { + .name ="pcf50633-regltr" , + }, + .probe = pcf50633_regulator_probe, + .remove =__devexit_p (pcf50633_regulator_remove), +};Not that it matters too much but I have a hard time liking "regltr".
Ha! The name pcf50633-regulator exceeds 20 chars and there is no space remaining for the ".0" or ".1" at the end. This gave me a sysfs warning and so I changed it.
- Balaji
Re: [PATCH 7/7] regulator: PCF50633 pmic driver
Quoted 11 lines · Balaji Rao
Quoted 7 lines · Mark Brown
drivers/regulator/pcf50633-regulator.c line 261
Quoted 2 lines · Balaji Rao
drivers/regulator/pcf50633-regulator.c new file +2
-0+ .set_suspend_enable = pcf50633_regulator_enable, + .set_suspend_disable = pcf50633_regulator_disable,Are you sure that the suspend variants of the operations should be the same as the regular versions?
Yes, basically the chip doesn't change state during suspend/resume. We just enable or disable them the usual way.
In that case you shouldn't be providing these variants - they are for configuring alternative settings which can be switched to in hardware when the system suspends. If the regular functions should be used then the code to do this should be in the core since the same thing will be needed for all regulators that don't have the hardware support.