mfd: cpcap: implement irq sense helper
Subsystems (4)
PATCH v3 1/2 mfd: cpcap: implement irq sense helper
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
---
Changes since PATCHv2:
- Collect Acked-by/Tested-by
- Fix typo in EXPORT_SYMBOL_GPL
--- drivers/mfd/motorola-cpcap.c | 25 +++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 27 insertions(+)
drivers/mfd/motorola-cpcap.c +25 -0
@@ -32,6 +32,31 @@ struct cpcap_ddata {struct regmap *regmap; }; +static int cpcap_sense_irq (struct regmap *regmap,int irq) +{ +int reg =CPCAP_REG_INTS1 + (irq /16 ) *4 ; +int mask =1 << (irq %16 ); +int err, val; + +if (irq <0 || irq >64 ) +return -EINVAL ; + + err =regmap_read (regmap, reg, &val); +if (err) +return err; + +return !!(val & mask); +} + +int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int base =regmap_irq_chip_get_base (d); + +return cpcap_sense_irq (regmap, virq - base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq); +static int cpcap_check_revision (struct cpcap_ddata *cpcap) {u16 vendor, rev;
include/linux/mfd/motorola-cpcap.h +2 -0
@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,return 0 ; } + +int cpcap_sense_virq (struct regmap *regmap,int virq);
Signature · 1 line
2.11.0
PATCH v3 2/2 input: cpcap-pwrbutton: new driver
Motorola CPCAP is a PMIC found in multiple smartphones. This driver adds support for the power/on button and has been tested in Droid 4.
---
Changes since PATCHv2:
- Collect Acked-by/Tested-by
As merge strategy I suggest, that Lee takes the first patch and provides a immutable branch with for the input subsystem, which can pull in the immutable branch + the second patch. Alternatively both can go through mfd of course and Dmitry gave his Ack for that strategy in PATCHv2.
--- .../devicetree/bindings/input/cpcap-pwrbutton.txt | 20 ++++ drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/cpcap-pwrbutton.c | 117 +++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cpcap-pwrbutton.txt create mode 100644 drivers/input/misc/cpcap-pwrbutton.c
Documentation/devicetree/bindings/input/cpcap-pwrbutton.txt new file +20 -0
@@ -0,0 +1,20 @@ +Motorola CPCAP on key + +This module is part of the CPCAP. For more details about the whole +chip see Documentation/devicetree/bindings/mfd/motorola-cpcap.txt. + +This module provides a simple power button event via an Interrupt. + +Required properties: +- compatible: should be one of the following + - "motorola,cpcap-pwrbutton" +- interrupts: irq specifier for CPCAP's ON IRQ + +Example: + +&cpcap { + cpcap_pwrbutton: pwrbutton { + compatible = "motorola,cpcap-pwrbutton"; + interrupts = <23 IRQ_TYPE_NONE>; + }; +};
drivers/input/misc/Kconfig +10 -0
@@ -316,6 +316,16 @@ config INPUT_COBALT_BTNS To compile this driver as a module, choose M here: the module will be called cobalt_btns. +config INPUT_CPCAP_PWRBUTTON + tristate "CPCAP OnKey" + depends on MFD_CPCAP + help + Say Y here if you want to enable power key reporting via the + Motorola CPCAP chip. + + To compile this driver as a module, choose M here. The module will + be called cpcap-pwrbutton. + config INPUT_WISTRON_BTNS tristate "x86 Wistron laptop button interface" depends on X86_32
drivers/input/misc/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_INPUT_CM109) += cm109.o obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o +obj-$(CONFIG_INPUT_CPCAP_PWRBUTTON) += cpcap-pwrbutton.o obj-$(CONFIG_INPUT_DA9052_ONKEY) += da9052_onkey.o obj-$(CONFIG_INPUT_DA9055_ONKEY) += da9055_onkey.o obj-$(CONFIG_INPUT_DA9063_ONKEY) += da9063_onkey.o
drivers/input/misc/cpcap-pwrbutton.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 20 lines · Sebastian Reichel
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
Acked-by Tony Lindgren <[email protected]>Signed-off-by Sebastian Reichel <[email protected]>---
Changes since PATCHv2:
- Collect Acked-by/Tested-by
- Fix typo inEXPORT_SYMBOL_GPL--- drivers/mfd/motorola-cpcap.c | 25 +++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 27 insertions(+)drivers/mfd/motorola-cpcap.c +0
-0
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 38
Quoted 7 lines
drivers/mfd/motorola-cpcap.c +4
-0@@ -32,6 +32,31 @@ struct cpcap_ddata {struct regmap *regmap; }; +static int cpcap_sense_irq (struct regmap *regmap,int irq) +{ +int reg =CPCAP_REG_INTS1 + (irq /16 ) *4 ; +int mask =1 << (irq %16 );
Can you place all this bit-wise hoop jumping in macros please?
Also please use the BIT() macro.
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 42
Quoted 4 lines
drivers/mfd/motorola-cpcap.c +4
-0+int err, val; + +if (irq <0 || irq >64 ) +return -EINVAL ;
What's wrong with IRQ 65?
I'm *guessing* there isn't one.
You can make this clearer by defining CPCAP_SENSE_IRQ_MAX.
Quoted 24 lines
drivers/mfd/motorola-cpcap.c +16
-0+ err =regmap_read (regmap, reg, &val); +if (err) +return err; + +return !!(val & mask); +} + +int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int base =regmap_irq_chip_get_base (d); + +return cpcap_sense_irq (regmap, virq - base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq); +static int cpcap_check_revision (struct cpcap_ddata *cpcap) {u16 vendor, rev;include/linux/mfd/motorola-cpcap.h +0
-0
include/linux/mfd/motorola-cpcap.h static inline int cpcap_get_vendor(struct device *dev, · line 294
Quoted 5 lines
include/linux/mfd/motorola-cpcap.h +2
-0@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,return 0 ; } + +int cpcap_sense_virq (struct regmap *regmap,int virq);
extern?
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 1/1 mfd: cpcap: implement irq sense helper
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
---
Hi Lee,
I hope this is fine with you. I tried to come up with a sensible macro for reg, but everything I came up with actually reduced readability.
-- Sebastian
Changes since PATCHv3:
- add explicit extern to function definition
- use BIT macro for mask variable
- avoid magic numbers
--- drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 30 insertions(+)
drivers/mfd/motorola-cpcap.c +28 -0
@@ -23,6 +23,8 @@#define CPCAP_NR_IRQ_REG_BANKS 6#define CPCAP_NR_IRQ_CHIPS 3 +#define CPCAP_REGISTER_SIZE 4 +#define CPCAP_REGISTER_BITS 16struct cpcap_ddata {struct spi_device *spi;
@@ -32,6 +34,32 @@ struct cpcap_ddata {struct regmap *regmap; }; +static int cpcap_sense_irq (struct regmap *regmap,int irq) +{ +int regnum = irq /CPCAP_REGISTER_BITS ; +int mask =BIT (irq %CPCAP_REGISTER_BITS ); +int reg =CPCAP_REG_INTS1 + (regnum *CPCAP_REGISTER_SIZE ); +int err, val; + +if (reg <CPCAP_REG_INTS1 || reg >CPCAP_REG_INTS4 ) +return -EINVAL ; + + err =regmap_read (regmap, reg, &val); +if (err) +return err; + +return !!(val & mask); +} + +int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int base =regmap_irq_chip_get_base (d); + +return cpcap_sense_irq (regmap, virq - base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq); +static int cpcap_check_revision (struct cpcap_ddata *cpcap) {u16 vendor, rev;
include/linux/mfd/motorola-cpcap.h +2 -0
@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,return 0 ; } + +extern int cpcap_sense_virq (struct regmap *regmap,int virq);
Signature · 1 line
2.11.0
Quoted 53 lines · Sebastian Reichel
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
Acked-by Tony Lindgren <[email protected]>Signed-off-by Sebastian Reichel <[email protected]>---
Hi Lee,I hope this is fine with you. I tried to come up with a sensible macro for reg, but everything I came up with actually reduced readability.
-- Sebastian
Changes since PATCHv3:
- add explicit extern to function definition
- use BIT macro for mask variable
- avoid magic numbers--- drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 30 insertions(+)drivers/mfd/motorola-cpcap.c +13
-0@@ -23,6 +23,8 @@#define CPCAP_NR_IRQ_REG_BANKS 6#define CPCAP_NR_IRQ_CHIPS 3 +#define CPCAP_REGISTER_SIZE 4 +#define CPCAP_REGISTER_BITS 16struct cpcap_ddata {struct spi_device *spi;@@ -32,6 +34,32 @@ struct cpcap_ddata {struct regmap *regmap; }; +static int cpcap_sense_irq (struct regmap *regmap,int irq) +{ +int regnum = irq /CPCAP_REGISTER_BITS ; +int mask =BIT (irq %CPCAP_REGISTER_BITS ); +int reg =CPCAP_REG_INTS1 + (regnum *CPCAP_REGISTER_SIZE ); +int err, val; + +if (reg <CPCAP_REG_INTS1 || reg >CPCAP_REG_INTS4 ) +return -EINVAL ; + + err =regmap_read (regmap, reg, &val);
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 57
Quoted 10 lines
drivers/mfd/motorola-cpcap.c +10
-0+if (err) +return err; + +return !!(val & mask); +} + +int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int base =regmap_irq_chip_get_base (d);
What base is this? Could it be used to avoid some calculations in cpcap_sense_irq()?
Quoted 17 lines
drivers/mfd/motorola-cpcap.c +4
-0+return cpcap_sense_irq (regmap, virq - base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq); +static int cpcap_check_revision (struct cpcap_ddata *cpcap) {u16 vendor, rev;include/linux/mfd/motorola-cpcap.h +2
-0@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,return 0 ; } + +extern int cpcap_sense_virq (struct regmap *regmap,int virq);
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Hi Lee,
Quoted 6 lines · Lee Jones
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 57
Quoted 4 lines
drivers/mfd/motorola-cpcap.c +4
-0+int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int base =regmap_irq_chip_get_base (d);What base is this?
This function takes an Linux irq number. That number is a virtual irq number, which has nothing to do with the hardware. For example a platform could look like this:
linux irq device base device irq
---------------------------------------------
0-63 SoC 0 0-63 64-127 SoC-GPIO 64 0-63 128-191 CPCAP 128 0-63
For the above example the function would map 128-191 to 0-63 as used by the device.
Quoted 1 line
Could it be used to avoid some calculations in
cpcap_sense_irq()?
No.
Quoted 3 lines
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 61
Quoted 3 lines
drivers/mfd/motorola-cpcap.c +3
-0+return cpcap_sense_irq (regmap, virq - base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq);
-- Sebastian
Quoted 14 lines · Sebastian Reichel
Hi Lee,
Quoted 6 lines · Lee Jones
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 57
Quoted 4 lines
drivers/mfd/motorola-cpcap.c +4
-0+int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int base =regmap_irq_chip_get_base (d);What base is this?
This function takes an Linux irq number. That number is a virtual irq number, which has nothing to do with the hardware. For example a platform could look like this:
Quoted 8 lines
linux irq device base device irq
---------------------------------------------0-63 SoC 0 0-63 64-127 SoC-GPIO 64 0-63 128-191 CPCAP 128 0-63For the above example the function would map 128-191 to 0-63 as used by the device.
In which case may I suggest that you rename the variable, since 'base' is commonly used in the kernel to mean base of a particular IP's memory block.
Quoted 9 lines
Quoted 1 line
Could it be used to avoid some calculations in
cpcap_sense_irq()?No.
Quoted 3 lines
drivers/mfd/motorola-cpcap.c struct cpcap_ddata { · line 61
Quoted 3 lines
drivers/mfd/motorola-cpcap.c +3
-0+return cpcap_sense_irq (regmap, virq - base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq);-- Sebastian
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v5 1/1 mfd: cpcap: implement irq sense helper
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
---
Changes since PATCHv3:
- add extern to function definition
- use BIT macro for mask variable
- avoid magic numbers
Changes since PATCHv4:
- rename base to irq_base
--- drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 30 insertions(+)
drivers/mfd/motorola-cpcap.c +28 -0
@@ -23,6 +23,8 @@#define CPCAP_NR_IRQ_REG_BANKS 6#define CPCAP_NR_IRQ_CHIPS 3 +#define CPCAP_REGISTER_SIZE 4 +#define CPCAP_REGISTER_BITS 16struct cpcap_ddata {struct spi_device *spi;
@@ -32,6 +34,32 @@ struct cpcap_ddata {struct regmap *regmap; }; +static int cpcap_sense_irq (struct regmap *regmap,int irq) +{ +int regnum = irq /CPCAP_REGISTER_BITS ; +int mask =BIT (irq %CPCAP_REGISTER_BITS ); +int reg =CPCAP_REG_INTS1 + (regnum *CPCAP_REGISTER_SIZE ); +int err, val; + +if (reg <CPCAP_REG_INTS1 || reg >CPCAP_REG_INTS4 ) +return -EINVAL ; + + err =regmap_read (regmap, reg, &val); +if (err) +return err; + +return !!(val & mask); +} + +int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int irq_base =regmap_irq_chip_get_base (d); + +return cpcap_sense_irq (regmap, virq - irq_base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq); +static int cpcap_check_revision (struct cpcap_ddata *cpcap) {u16 vendor, rev;
include/linux/mfd/motorola-cpcap.h +2 -0
@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,return 0 ; } + +extern int cpcap_sense_virq (struct regmap *regmap,int virq);
Signature · 1 line
2.11.0
Lee Jones
AppliedQuoted 13 lines · Sebastian Reichel
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
Acked-by Tony Lindgren <[email protected]>Signed-off-by Sebastian Reichel <[email protected]>---
Changes since PATCHv3:
- add extern to function definition
- use BIT macro for mask variable
- avoid magic numbers
Changes since PATCHv4:
- rename base toirq_base
Quoted 4 lines
--- drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 30 insertions(+)
Applied, thanks.
Quoted 56 lines
drivers/mfd/motorola-cpcap.c +28
-0@@ -23,6 +23,8 @@#define CPCAP_NR_IRQ_REG_BANKS 6#define CPCAP_NR_IRQ_CHIPS 3 +#define CPCAP_REGISTER_SIZE 4 +#define CPCAP_REGISTER_BITS 16struct cpcap_ddata {struct spi_device *spi;@@ -32,6 +34,32 @@ struct cpcap_ddata {struct regmap *regmap; }; +static int cpcap_sense_irq (struct regmap *regmap,int irq) +{ +int regnum = irq /CPCAP_REGISTER_BITS ; +int mask =BIT (irq %CPCAP_REGISTER_BITS ); +int reg =CPCAP_REG_INTS1 + (regnum *CPCAP_REGISTER_SIZE ); +int err, val; + +if (reg <CPCAP_REG_INTS1 || reg >CPCAP_REG_INTS4 ) +return -EINVAL ; + + err =regmap_read (regmap, reg, &val); +if (err) +return err; + +return !!(val & mask); +} + +int cpcap_sense_virq (struct regmap *regmap,int virq) +{ +struct regmap_irq_chip_data *d =irq_get_chip_data (virq); +int irq_base =regmap_irq_chip_get_base (d); + +return cpcap_sense_irq (regmap, virq - irq_base); +} +EXPORT_SYMBOL_GPL (cpcap_sense_virq); +static int cpcap_check_revision (struct cpcap_ddata *cpcap) {u16 vendor, rev;include/linux/mfd/motorola-cpcap.h +2
-0@@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev,return 0 ; } + +extern int cpcap_sense_virq (struct regmap *regmap,int virq);
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Hi Lee,
Quoted 20 lines · Lee Jones
Quoted 13 lines · Sebastian Reichel
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
Acked-by Tony Lindgren <[email protected]>Signed-off-by Sebastian Reichel <[email protected]>---
Changes since PATCHv3:
- add extern to function definition
- use BIT macro for mask variable
- avoid magic numbers
Changes since PATCHv4:
- rename base toirq_baseQuoted 4 lines
--- drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 30 insertions(+)
Quoted 1 line
Applied, thanks.
Thanks, will you also pick up the input patch?
https://patchwork.kernel.org/patch/9637807/
-- Sebastian
Quoted 21 lines · Sebastian Reichel
Quoted 20 lines · Lee Jones
Quoted 17 lines · Sebastian Reichel
CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules.
Acked-by Tony Lindgren <[email protected]>Signed-off-by Sebastian Reichel <[email protected]>---
Changes since PATCHv3:
- add extern to function definition
- use BIT macro for mask variable
- avoid magic numbers
Changes since PATCHv4:
- rename base toirq_base--- drivers/mfd/motorola-cpcap.c | 28 ++++++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 30 insertions(+)
Quoted 5 lines
Quoted 1 line
Applied, thanks.
Thanks, will you also pick up the input patch?
Done, and pull-request sent.
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL] Immutable branch between MFD and Input due for the v4.12 merge window
In reply to Sebastian ReichelDmitry,
Enjoy!
The following changes since commit c1ae3cfa0e89fa1a7ecc4c99031f5e9ae99d9201:
Linux 4.11-rc1 (2017-03-05 12:59:56 -0800)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git ib-mfd-input-v4.12
for you to fetch changes up to 6d99971842f6b0779738d8c168d9ed92ef1ff5fc:
input: cpcap-pwrbutton: New driver (2017-04-11 15:18:09 +0100)
----------------------------------------------------------------
Immutable branch between MFD and Input due for the v4.12 merge window
----------------------------------------------------------------
Sebastian Reichel (2):
mfd: cpcap: Implement IRQ sense helper
input: cpcap-pwrbutton: New driver
.../devicetree/bindings/input/cpcap-pwrbutton.txt | 20 ++++ drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/cpcap-pwrbutton.c | 117 +++++++++++++++++++++ drivers/mfd/motorola-cpcap.c | 28 +++++ include/linux/mfd/motorola-cpcap.h | 2 + 6 files changed, 178 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cpcap-pwrbutton.txt create mode 100644 drivers/input/misc/cpcap-pwrbutton.c
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog