Skip to contentSkip to conversation

AM437x SK: Add power-button support

PATCH New Felipe Balbi 4 participants 21 messages Dec 26, 2014 – Jan 19, 2015

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover AM437x SK: Add power-button support

Hi,

the following patches add tps65218 power button support and make it usable with AM437x SK.

Developed and tested on top of v3.19-rc1. Logs at [1]

[1] http://hastebin.com/ecopenuqot

Felipe Balbi (5):
mfd: tps65218: make INT[12] and STATUS registers volatile
mfd: tps65218: make INT1 our status_base register
input: misc: add tps65218 power button driver
arm: boot: dts: am437x-sk: add power button binding
arm: omap2plus_defconfig: enable TPS65218 power button

 arch/arm/boot/dts/am437x-sk-evm.dts     |   5 ++
 arch/arm/configs/omap2plus_defconfig    |   1 +
 drivers/input/misc/Kconfig              |  10 +++
 drivers/input/misc/Makefile             |   1 +
 drivers/input/misc/tps65218-pwrbutton.c | 135 ++++++++++++++++++++++++++++++++
 drivers/mfd/tps65218.c                  |  12 +++
 6 files changed, 164 insertions(+)
 create mode 100644 drivers/input/misc/tps65218-pwrbutton.c
Signature · 1 line
2.2.0
#1 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65218.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mfd/tps65218.c +11 -0
index 0d256cb..2243f75 100644
@@ -125,10 +125,21 @@ int tps65218_clear_bits(struct tps65218 *tps, unsigned int reg,
 }
 EXPORT_SYMBOL_GPL(tps65218_clear_bits);
 
+static const struct regmap_range tps65218_yes_ranges[] = {
+	regmap_reg_range(TPS65218_REG_INT1, TPS65218_REG_INT2),
+	regmap_reg_range(TPS65218_REG_STATUS, TPS65218_REG_STATUS),
+};
+
+static const struct regmap_access_table tps65218_volatile_table = {
+	.yes_ranges = tps65218_yes_ranges,
+	.n_yes_ranges = ARRAY_SIZE(tps65218_yes_ranges),
+};
+
 static struct regmap_config tps65218_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
 	.cache_type = REGCACHE_RBTREE,
+	.volatile_table = &tps65218_volatile_table,
 };
 
 static const struct regmap_irq tps65218_irqs[] = {
Signature · 1 line
2.2.0
#2 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

Quoted 9 lines · Felipe Balbi

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Quoted 5 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>

ping

Quoted 33 lines
---
 drivers/mfd/tps65218.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mfd/tps65218.c +11 -0
index 0d256cb..2243f75 100644
@@ -125,10 +125,21 @@ int tps65218_clear_bits(struct tps65218 *tps, unsigned int reg,
 }
 EXPORT_SYMBOL_GPL(tps65218_clear_bits);
 
+static const struct regmap_range tps65218_yes_ranges[] = {
+	regmap_reg_range(TPS65218_REG_INT1, TPS65218_REG_INT2),
+	regmap_reg_range(TPS65218_REG_STATUS, TPS65218_REG_STATUS),
+};
+
+static const struct regmap_access_table tps65218_volatile_table = {
+	.yes_ranges = tps65218_yes_ranges,
+	.n_yes_ranges = ARRAY_SIZE(tps65218_yes_ranges),
+};
+
 static struct regmap_config tps65218_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
 	.cache_type = REGCACHE_RBTREE,
+	.volatile_table = &tps65218_volatile_table,
 };
 
 static const struct regmap_irq tps65218_irqs[] = {
Signature · 1 line
2.2.0
Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150106/bc31b617/attachment-0001.sig>
#3 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

Quoted 10 lines · Felipe Balbi
Quoted 9 lines · Felipe Balbi

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Quoted 7 lines
Quoted 5 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>

ping

another ping. Without this and the following patch TPS65218 power button driver which was already applied by Dmitry, won't work.

Quoted 36 lines
Quoted 33 lines
---
 drivers/mfd/tps65218.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mfd/tps65218.c +11 -0
index 0d256cb..2243f75 100644
@@ -125,10 +125,21 @@ int tps65218_clear_bits(struct tps65218 *tps, unsigned int reg,
 }
 EXPORT_SYMBOL_GPL(tps65218_clear_bits);
 
+static const struct regmap_range tps65218_yes_ranges[] = {
+	regmap_reg_range(TPS65218_REG_INT1, TPS65218_REG_INT2),
+	regmap_reg_range(TPS65218_REG_STATUS, TPS65218_REG_STATUS),
+};
+
+static const struct regmap_access_table tps65218_volatile_table = {
+	.yes_ranges = tps65218_yes_ranges,
+	.n_yes_ranges = ARRAY_SIZE(tps65218_yes_ranges),
+};
+
 static struct regmap_config tps65218_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
 	.cache_type = REGCACHE_RBTREE,
+	.volatile_table = &tps65218_volatile_table,
 };
 
 static const struct regmap_irq tps65218_irqs[] = {
Signature · 1 line
2.2.0
Signature · 1 line
balbi
Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150108/b6f478c2/attachment.sig>
#4 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

Hi,

Quoted 17 lines · Felipe Balbi
Quoted 16 lines · Felipe Balbi
Quoted 14 lines · Felipe Balbi

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>
Quoted 4 lines
Quoted 1 line

ping

another ping. Without this and the following patch TPS65218 power button driver which was already applied by Dmitry, won't work.

Anybody ? -rc4 is out and tps65218 is still broken because nobody has acted on these two patches. All other patches which are meant for 3.20 merge window are applied and because of these pending, those patches won't work.

Quoted 41 lines
Quoted 36 lines
Quoted 33 lines
---
 drivers/mfd/tps65218.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mfd/tps65218.c +11 -0
index 0d256cb..2243f75 100644
@@ -125,10 +125,21 @@ int tps65218_clear_bits(struct tps65218 *tps, unsigned int reg,
 }
 EXPORT_SYMBOL_GPL(tps65218_clear_bits);
 
+static const struct regmap_range tps65218_yes_ranges[] = {
+	regmap_reg_range(TPS65218_REG_INT1, TPS65218_REG_INT2),
+	regmap_reg_range(TPS65218_REG_STATUS, TPS65218_REG_STATUS),
+};
+
+static const struct regmap_access_table tps65218_volatile_table = {
+	.yes_ranges = tps65218_yes_ranges,
+	.n_yes_ranges = ARRAY_SIZE(tps65218_yes_ranges),
+};
+
 static struct regmap_config tps65218_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
 	.cache_type = REGCACHE_RBTREE,
+	.volatile_table = &tps65218_volatile_table,
 };
 
 static const struct regmap_irq tps65218_irqs[] = {
Signature · 1 line
2.2.0
Signature · 1 line
balbi
Signature · 1 line
balbi
Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150112/f003e95c/attachment.sig>
maintainer
#5 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

Quoted 22 lines · Felipe Balbi

Hi,

Quoted 19 lines · Felipe Balbi
Quoted 17 lines · Felipe Balbi
Quoted 9 lines · Felipe Balbi

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Quoted 5 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>

ping

Quoted 7 lines
Quoted 2 lines

another ping. Without this and the following patch TPS65218 power button driver which was already applied by Dmitry, won't work.

Anybody ? -rc4 is out and tps65218 is still broken because nobody has acted on these two patches. All other patches which are meant for 3.20 merge window are applied and because of these pending, those patches won't work.

Lee, are you planning to pick these two drivers/mfd patches?

Regards,

Tony

#6 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

Hi,

Quoted 20 lines · Tony Lindgren
Quoted 20 lines
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Quoted 7 lines
Quoted 5 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>

ping

another ping. Without this and the following patch TPS65218 power button driver which was already applied by Dmitry, won't work.

Quoted 6 lines
Quoted 4 lines

Anybody ? -rc4 is out and tps65218 is still broken because nobody has acted on these two patches. All other patches which are meant for 3.20 merge window are applied and because of these pending, those patches won't work.

Lee, are you planning to pick these two drivers/mfd patches?

Samuel, Lee, is someone planning on picking these two patches up ? v3.19 remains broken.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150116/5feee76e/attachment.sig>
#7 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

In reply to Felipe Balbi
Quoted 9 lines · Felipe Balbi

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Quoted 8 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65218.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Sorry for the delay. It's difficult to get a WiFi signal 2000m up in an Austrian mountain. :)

Applied now, thanks.

Quoted 26 lines
drivers/mfd/tps65218.c +11 -0
index 0d256cb..2243f75 100644
@@ -125,10 +125,21 @@ int tps65218_clear_bits(struct tps65218 *tps, unsigned int reg,
 }
 EXPORT_SYMBOL_GPL(tps65218_clear_bits);
 
+static const struct regmap_range tps65218_yes_ranges[] = {
+	regmap_reg_range(TPS65218_REG_INT1, TPS65218_REG_INT2),
+	regmap_reg_range(TPS65218_REG_STATUS, TPS65218_REG_STATUS),
+};
+
+static const struct regmap_access_table tps65218_volatile_table = {
+	.yes_ranges = tps65218_yes_ranges,
+	.n_yes_ranges = ARRAY_SIZE(tps65218_yes_ranges),
+};
+
 static struct regmap_config tps65218_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
 	.cache_type = REGCACHE_RBTREE,
+	.volatile_table = &tps65218_volatile_table,
 };
 
 static const struct regmap_irq tps65218_irqs[] = {
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#8 lore raw

PATCH 1/5 mfd: tps65218: make INT[12] and STATUS registers volatile

Quoted 20 lines · Lee Jones
Quoted 9 lines · Felipe Balbi

STATUS register can be modified by the HW, so we
should bypass cache because of that.

In the case of INT[12] registers, they are the ones that actually clear the IRQ source at the time they are read. If we rely on the cache for them, we will never be able to clear the interrupt, which will cause our IRQ line to be disabled due to IRQ throttling.

Quoted 8 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65218.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Quoted 2 lines

Sorry for the delay. It's difficult to get a WiFi signal 2000m up in an Austrian mountain. :)

now you're just making excuses ;-)

Quoted 1 line

Applied now, thanks.

thanks :-)

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150119/92854f0d/attachment.sig>
#9 lore raw

PATCH 2/5 mfd: tps65218: make INT1 our status_base register

In reply to Felipe Balbi

If we don't tell regmap-irq that our first status register is at offset 1, it will try to read offset zero, which is the chipid register.

Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65218.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mfd/tps65218.c +1 -0
index 2243f75..d6b7643 100644
@@ -204,6 +204,7 @@ static struct regmap_irq_chip tps65218_irq_chip = {
 
 	.num_regs = 2,
 	.mask_base = TPS65218_REG_INT_MASK1,
+	.status_base = TPS65218_REG_INT1,
 };
 
 static const struct of_device_id of_tps65218_match_table[] = {
Signature · 1 line
2.2.0
#10 lore raw

PATCH 2/5 mfd: tps65218: make INT1 our status_base register

Quoted 9 lines · Felipe Balbi

If we don't tell regmap-irq that our first status register is at offset 1, it will try to read offset zero, which is the chipid register.

Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>

ping

Quoted 19 lines
---
 drivers/mfd/tps65218.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mfd/tps65218.c +1 -0
index 2243f75..d6b7643 100644
@@ -204,6 +204,7 @@ static struct regmap_irq_chip tps65218_irq_chip = {
 
 	.num_regs = 2,
 	.mask_base = TPS65218_REG_INT_MASK1,
+	.status_base = TPS65218_REG_INT1,
 };
 
 static const struct of_device_id of_tps65218_match_table[] = {
Signature · 1 line
2.2.0
Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150106/1074b56b/attachment-0001.sig>
#11 lore raw

PATCH 2/5 mfd: tps65218: make INT1 our status_base register

In reply to Felipe Balbi
Quoted 4 lines · Felipe Balbi

If we don't tell regmap-irq that our first status register is at offset 1, it will try to read offset zero, which is the chipid register.

Quoted 8 lines
Fixes 44b4dc6 mfd: tps65218: Add driver for the TPS65218 PMIC
Cc <[email protected]> # v3.15+
Cc Keerthy <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/tps65218.c | 1 +
 1 file changed, 1 insertion(+)

Sorry for the delay. It's difficult to get a WiFi signal 2000m up in an Austrian mountain. :)

Applied now, thanks.

Quoted 12 lines
drivers/mfd/tps65218.c +1 -0
index 2243f75..d6b7643 100644
@@ -204,6 +204,7 @@ static struct regmap_irq_chip tps65218_irq_chip = {
 
 	.num_regs = 2,
 	.mask_base = TPS65218_REG_INT_MASK1,
+	.status_base = TPS65218_REG_INT1,
 };
 
 static const struct of_device_id of_tps65218_match_table[] = {
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#12 lore raw

PATCH 3/5 input: misc: add tps65218 power button driver

In reply to Felipe Balbi

With this driver, we can report KEY_POWER on
AM437x SK. This patch has been tested with said
board.

---
 drivers/input/misc/Kconfig              |  10 +++
 drivers/input/misc/Makefile             |   1 +
 drivers/input/misc/tps65218-pwrbutton.c | 135 ++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/input/misc/tps65218-pwrbutton.c
drivers/input/misc/Kconfig +10 -0
index 23297ab..364cfb8 100644
@@ -404,6 +404,16 @@ config INPUT_RETU_PWRBUTTON
 	  To compile this driver as a module, choose M here. The module will
 	  be called retu-pwrbutton.
 
+config INPUT_TPS65218_PWRBUTTON
+	tristate "TPS65218 Power button driver"
+	depends on MFD_TPS65218
+	help
+	  Say Y here if you want to enable power buttong reporting for
+	  the TPS65218 Power Management IC device.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called tps65218-pwrbutton.
+
 config INPUT_TWL4030_PWRBUTTON
 	tristate "TWL4030 Power button Driver"
 	depends on TWL4030_CORE
drivers/input/misc/Makefile +1 -0
index 19c7603..a923753 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)		+= sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)	+= sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)	+= soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)		+= sparcspkr.o
+obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON)	+= tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)	+= twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)	+= twl4030-vibra.o
 obj-$(CONFIG_INPUT_TWL6040_VIBRA)	+= twl6040-vibra.o
drivers/input/misc/tps65218-pwrbutton.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.2.0
#13 lore raw

PATCH 3/5 input: misc: add tps65218 power button driver

Hi,

drivers/input/misc/tps65218-pwrbutton.c line 118

Quoted 2 lines · Felipe Balbi
drivers/input/misc/tps65218-pwrbutton.c new file +2 -0
+static struct of_device_id of_tps65218_pwr_match[] = {
+	{ .compatible = "ti,tps65218-pwrbutton" },

forgot to document this compatible. I'll add it localy but still wait a a few days before resending so people have time to review.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141226/0d6d889b/attachment.sig>
maintainer
#14 lore raw

PATCH 3/5 input: misc: add tps65218 power button driver

In reply to Felipe Balbi

Hi Felipe,

Quoted 72 lines · Felipe Balbi

With this driver, we can report KEY_POWER on
AM437x SK. This patch has been tested with said
board.

---
 drivers/input/misc/Kconfig              |  10 +++
 drivers/input/misc/Makefile             |   1 +
 drivers/input/misc/tps65218-pwrbutton.c | 135 ++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/input/misc/tps65218-pwrbutton.c
drivers/input/misc/Kconfig +10 -0
index 23297ab..364cfb8 100644
@@ -404,6 +404,16 @@ config INPUT_RETU_PWRBUTTON
 	  To compile this driver as a module, choose M here. The module will
 	  be called retu-pwrbutton.
 
+config INPUT_TPS65218_PWRBUTTON
+	tristate "TPS65218 Power button driver"
+	depends on MFD_TPS65218
+	help
+	  Say Y here if you want to enable power buttong reporting for
+	  the TPS65218 Power Management IC device.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called tps65218-pwrbutton.
+
 config INPUT_TWL4030_PWRBUTTON
 	tristate "TWL4030 Power button Driver"
 	depends on TWL4030_CORE
drivers/input/misc/Makefile +1 -0
index 19c7603..a923753 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)		+= sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)	+= sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)	+= soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)		+= sparcspkr.o
+obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON)	+= tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)	+= twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)	+= twl4030-vibra.o
 obj-$(CONFIG_INPUT_TWL6040_VIBRA)	+= twl6040-vibra.o
drivers/input/misc/tps65218-pwrbutton.c new file +21 -0
new file mode 100644
index 0000000..a1f8a19
@@ -0,0 +1,135 @@
+/*
+ * Texas Instruments' TPS65218 Power Button Input Driver
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ * Author: Felipe Balbi <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/tps65218.h>

drivers/input/misc/tps65218-pwrbutton.c line 31

Quoted 10 lines
drivers/input/misc/tps65218-pwrbutton.c new file +10 -0
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+struct tps65218_pwrbutton {
+	struct device *dev;
+	struct tps65218 *tps;
+	struct input_dev *idev;
+	int irq;

You do not need to store IRQ since you are not using it outside of probe().

drivers/input/misc/tps65218-pwrbutton.c line 33

Quoted 2 lines
drivers/input/misc/tps65218-pwrbutton.c new file +2 -0
+
+	unsigned int pressed:1;

You probably can remove 'pressed' as well and send events directly to input core and rely on it to filter out duplicates so there won't be release event without press event. If you prefer to keep it please use bool instead of bit field.

Quoted 58 lines
drivers/input/misc/tps65218-pwrbutton.c new file +58 -0
+};
+
+static irqreturn_t tps65218_pwr_irq(int irq, void *_pwr)
+{
+	struct tps65218_pwrbutton *pwr = _pwr;
+	unsigned int reg;
+	int ret;
+
+	ret = tps65218_reg_read(pwr->tps, TPS65218_REG_STATUS, &reg);
+	if (ret) {
+		dev_err(pwr->dev, "can't read register --> %d\n", ret);
+		goto out;
+	}
+
+	if (reg & TPS65218_STATUS_PB_STATE) {
+		input_report_key(pwr->idev, KEY_POWER, 1);
+		pm_wakeup_event(pwr->dev, 0);
+		pwr->pressed = true;
+	} else {
+		/*
+		 * we don't want to report KEY_POWER releases on any of the
+		 * other IRQ sources. Only when button was previously pressed
+		 */
+		if (pwr->pressed) {
+			input_report_key(pwr->idev, KEY_POWER, 0);
+			pwr->pressed = false;
+		}
+	}
+
+	input_sync(pwr->idev);
+
+out:
+	return IRQ_HANDLED;
+}
+
+static int tps65218_pwron_probe(struct platform_device *pdev)
+{
+	struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct tps65218_pwrbutton *pwr;
+	struct input_dev *idev;
+	int ret;
+
+	pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL);
+	if (!pwr)
+		return -ENOMEM;
+
+	idev = devm_input_allocate_device(dev);
+	if (!idev)
+		return -ENOMEM;
+
+	idev->name = "tps65218_pwrbutton";
+	idev->phys = "tps65218_pwrbutton/input0";
+	idev->dev.parent = dev;
+	idev->id.bustype = BUS_I2C;
+
+	input_set_capability(idev, EV_KEY, KEY_POWER);
+

drivers/input/misc/tps65218-pwrbutton.c line 101

Quoted 10 lines
drivers/input/misc/tps65218-pwrbutton.c new file +10 -0
+	pwr->tps = tps;
+	pwr->dev = dev;
+	pwr->idev = idev;
+	pwr->irq = platform_get_irq(pdev, 0);
+	platform_set_drvdata(pdev, pwr);
+	device_init_wakeup(dev, true);
+
+	ret = devm_request_threaded_irq(dev, pwr->irq, NULL, tps65218_pwr_irq,
+			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+			dev_name(dev), pwr);

I am very fond of calling variables that hold error codes "error", Then you have:

	error = f();
	if (error) {
		/* handle error */
	}
Quoted 37 lines
drivers/input/misc/tps65218-pwrbutton.c new file +34 -0
+	if (ret) {
+		dev_err(dev, "failed to request IRQ #%d --> %d\n",
+				pwr->irq, ret);
+		return ret;
+	}
+
+	ret = input_register_device(idev);
+	if (ret) {
+		dev_err(dev, "Can't register power button --> %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static struct of_device_id of_tps65218_pwr_match[] = {
+	{ .compatible = "ti,tps65218-pwrbutton" },
+	{ },
+};
+
+MODULE_DEVICE_TABLE(of, of_tps65218_pwr_match);
+
+static struct platform_driver tps65218_pwron_driver = {
+	.probe	= tps65218_pwron_probe,
+	.driver	= {
+		.name	= "tps65218_pwrbutton",
+		.of_match_table = of_tps65218_pwr_match,
+	},
+};
+module_platform_driver(tps65218_pwron_driver);
+
+MODULE_DESCRIPTION("TPS65218 Power Button");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Felipe Balbi <[email protected]>");
Signature · 1 line
2.2.0

Thanks!

Signature · 1 line
Dmitry
#15 lore raw

PATCH v2 3/5 input: misc: add tps65218 power button driver

With this driver, we can report KEY_POWER on
AM437x SK. This patch has been tested with said
board.

---

Changes since v1:
- Add device tree documentation
- s/ret/error
- removed 'pressed' as input core will filter events
- use a saner name when requesting IRQ. dev_name(dev) will return $i2c_bus_address.i2c-omap:0-0024:tps65218-pwrbutton
- remove blank line before MODULE_DEVICE_TABLE()

 .../bindings/input/tps65218-pwrbutton.txt          |  17 +++
 drivers/input/misc/Kconfig                         |  10 ++
 drivers/input/misc/Makefile                        |   1 +
 drivers/input/misc/tps65218-pwrbutton.c            | 124 +++++++++++++++++++++
 4 files changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt
 create mode 100644 drivers/input/misc/tps65218-pwrbutton.c
Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt new file +17 -0
new file mode 100644
index 0000000..e30e0b9
@@ -0,0 +1,17 @@
+Texas Instruments TPS65218 power button
+
+This driver provides a simple power button event via an Interrupt.
+
+Required properties:
+- compatible: should be "ti,tps65218-pwrbutton"
+- interrupts: should be one of the following
+   - <3 IRQ_TYPE_EDGE_BOTH>: For controllers compatible with tps65218
+
+Example:
+
+&tps {
+	power-button {
+		compatible = "ti,tps65218-pwrbutton";
+		interrupts = <3 IRQ_TYPE_EDGE_BOTH>;
+	};
+};
drivers/input/misc/Kconfig +10 -0
index 23297ab..364cfb8 100644
@@ -404,6 +404,16 @@ config INPUT_RETU_PWRBUTTON
 	  To compile this driver as a module, choose M here. The module will
 	  be called retu-pwrbutton.
 
+config INPUT_TPS65218_PWRBUTTON
+	tristate "TPS65218 Power button driver"
+	depends on MFD_TPS65218
+	help
+	  Say Y here if you want to enable power buttong reporting for
+	  the TPS65218 Power Management IC device.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called tps65218-pwrbutton.
+
 config INPUT_TWL4030_PWRBUTTON
 	tristate "TWL4030 Power button Driver"
 	depends on TWL4030_CORE
drivers/input/misc/Makefile +1 -0
index 19c7603..a923753 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)		+= sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)	+= sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)	+= soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)		+= sparcspkr.o
+obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON)	+= tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)	+= twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)	+= twl4030-vibra.o
 obj-$(CONFIG_INPUT_TWL6040_VIBRA)	+= twl6040-vibra.o
drivers/input/misc/tps65218-pwrbutton.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.2.0
maintainer Applied
#16 lore raw

PATCH v2 3/5 input: misc: add tps65218 power button driver

Quoted 5 lines · Felipe Balbi

With this driver, we can report KEY_POWER on
AM437x SK. This patch has been tested with said
board.

Applied, thank you.

Quoted 207 lines

---

Changes since v1:
- Add device tree documentation
- s/ret/error
- removed 'pressed' as input core will filter events
- use a saner name when requesting IRQ. dev_name(dev) will return $i2c_bus_address.i2c-omap:0-0024:tps65218-pwrbutton
- remove blank line before MODULE_DEVICE_TABLE()

 .../bindings/input/tps65218-pwrbutton.txt          |  17 +++
 drivers/input/misc/Kconfig                         |  10 ++
 drivers/input/misc/Makefile                        |   1 +
 drivers/input/misc/tps65218-pwrbutton.c            | 124 +++++++++++++++++++++
 4 files changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt
 create mode 100644 drivers/input/misc/tps65218-pwrbutton.c
Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt new file +17 -0
new file mode 100644
index 0000000..e30e0b9
@@ -0,0 +1,17 @@
+Texas Instruments TPS65218 power button
+
+This driver provides a simple power button event via an Interrupt.
+
+Required properties:
+- compatible: should be "ti,tps65218-pwrbutton"
+- interrupts: should be one of the following
+   - <3 IRQ_TYPE_EDGE_BOTH>: For controllers compatible with tps65218
+
+Example:
+
+&tps {
+	power-button {
+		compatible = "ti,tps65218-pwrbutton";
+		interrupts = <3 IRQ_TYPE_EDGE_BOTH>;
+	};
+};
drivers/input/misc/Kconfig +10 -0
index 23297ab..364cfb8 100644
@@ -404,6 +404,16 @@ config INPUT_RETU_PWRBUTTON
 	  To compile this driver as a module, choose M here. The module will
 	  be called retu-pwrbutton.
 
+config INPUT_TPS65218_PWRBUTTON
+	tristate "TPS65218 Power button driver"
+	depends on MFD_TPS65218
+	help
+	  Say Y here if you want to enable power buttong reporting for
+	  the TPS65218 Power Management IC device.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called tps65218-pwrbutton.
+
 config INPUT_TWL4030_PWRBUTTON
 	tristate "TWL4030 Power button Driver"
 	depends on TWL4030_CORE
drivers/input/misc/Makefile +1 -0
index 19c7603..a923753 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)		+= sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)	+= sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)	+= soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)		+= sparcspkr.o
+obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON)	+= tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)	+= twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)	+= twl4030-vibra.o
 obj-$(CONFIG_INPUT_TWL6040_VIBRA)	+= twl6040-vibra.o
drivers/input/misc/tps65218-pwrbutton.c new file +124 -0
new file mode 100644
index 0000000..2f85e2e
@@ -0,0 +1,124 @@
+/*
+ * Texas Instruments' TPS65218 Power Button Input Driver
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ * Author: Felipe Balbi <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/tps65218.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+struct tps65218_pwrbutton {
+	struct device *dev;
+	struct tps65218 *tps;
+	struct input_dev *idev;
+};
+
+static irqreturn_t tps65218_pwr_irq(int irq, void *_pwr)
+{
+	struct tps65218_pwrbutton *pwr = _pwr;
+	unsigned int reg;
+	int error;
+
+	error = tps65218_reg_read(pwr->tps, TPS65218_REG_STATUS, &reg);
+	if (error) {
+		dev_err(pwr->dev, "can't read register --> %d\n", error);
+		goto out;
+	}
+
+	if (reg & TPS65218_STATUS_PB_STATE) {
+		input_report_key(pwr->idev, KEY_POWER, 1);
+		pm_wakeup_event(pwr->dev, 0);
+	} else {
+		input_report_key(pwr->idev, KEY_POWER, 0);
+	}
+
+	input_sync(pwr->idev);
+
+out:
+	return IRQ_HANDLED;
+}
+
+static int tps65218_pwron_probe(struct platform_device *pdev)
+{
+	struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct tps65218_pwrbutton *pwr;
+	struct input_dev *idev;
+	int error;
+	int irq;
+
+	pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL);
+	if (!pwr)
+		return -ENOMEM;
+
+	idev = devm_input_allocate_device(dev);
+	if (!idev)
+		return -ENOMEM;
+
+	idev->name = "tps65218_pwrbutton";
+	idev->phys = "tps65218_pwrbutton/input0";
+	idev->dev.parent = dev;
+	idev->id.bustype = BUS_I2C;
+
+	input_set_capability(idev, EV_KEY, KEY_POWER);
+
+	pwr->tps = tps;
+	pwr->dev = dev;
+	pwr->idev = idev;
+	platform_set_drvdata(pdev, pwr);
+	device_init_wakeup(dev, true);
+
+	irq = platform_get_irq(pdev, 0);
+	error = devm_request_threaded_irq(dev, irq, NULL, tps65218_pwr_irq,
+			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+			"tps65218-pwrbutton", pwr);
+	if (error) {
+		dev_err(dev, "failed to request IRQ #%d --> %d\n",
+				irq, error);
+		return error;
+	}
+
+	error= input_register_device(idev);
+	if (error) {
+		dev_err(dev, "Can't register power button --> %d\n", error);
+		return error;
+	}
+
+	return 0;
+}
+
+static struct of_device_id of_tps65218_pwr_match[] = {
+	{ .compatible = "ti,tps65218-pwrbutton" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, of_tps65218_pwr_match);
+
+static struct platform_driver tps65218_pwron_driver = {
+	.probe	= tps65218_pwron_probe,
+	.driver	= {
+		.name	= "tps65218_pwrbutton",
+		.of_match_table = of_tps65218_pwr_match,
+	},
+};
+module_platform_driver(tps65218_pwron_driver);
+
+MODULE_DESCRIPTION("TPS65218 Power Button");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Felipe Balbi <[email protected]>");
Signature · 1 line
2.2.0
Signature · 1 line
Dmitry
#17 lore raw

PATCH 4/5 arm: boot: dts: am437x-sk: add power button binding

In reply to Felipe Balbi

Let this board report KEY_POWER so upper layers can decide what to do when power button is pressed.

---
 arch/arm/boot/dts/am437x-sk-evm.dts | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/boot/dts/am437x-sk-evm.dts +5 -0
index 53bbfc9..c53840c 100644
@@ -386,6 +386,11 @@
 			regulator-always-on;
 		};
 
+		power-button {
+			compatible = "ti,tps65218-pwrbutton";
+			status = "okay";
+			interrupts = <3 IRQ_TYPE_EDGE_BOTH>;
+		};
 	};
 
 	at24 at 50 {
Signature · 1 line
2.2.0
maintainer
#18 lore raw

PATCH 4/5 arm: boot: dts: am437x-sk: add power button binding

Quoted 4 lines · Felipe Balbi

Let this board report KEY_POWER so upper layers can decide what to do when power button is pressed.

Applying this one into omap-for-v3.20/dt thanks.

Tony

Quoted 23 lines
---
 arch/arm/boot/dts/am437x-sk-evm.dts | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/boot/dts/am437x-sk-evm.dts +5 -0
index 53bbfc9..c53840c 100644
@@ -386,6 +386,11 @@
 			regulator-always-on;
 		};
 
+		power-button {
+			compatible = "ti,tps65218-pwrbutton";
+			status = "okay";
+			interrupts = <3 IRQ_TYPE_EDGE_BOTH>;
+		};
 	};
 
 	at24 at 50 {
Signature · 1 line
2.2.0
#19 lore raw

PATCH 5/5 arm: omap2plus_defconfig: enable TPS65218 power button

In reply to Felipe Balbi

Enable tps65218 power button driver by default as a dynamically linked module so AM437x SK can report power button presses.

---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
index c2c3a85..f4a4b2f 100644
@@ -183,6 +183,7 @@ CONFIG_TOUCHSCREEN_EDT_FT5X06=m
 CONFIG_TOUCHSCREEN_TSC2005=m
 CONFIG_TOUCHSCREEN_TSC2007=m
 CONFIG_INPUT_MISC=y
+CONFIG_INPUT_TPS65218_PWRBUTTON=m
 CONFIG_INPUT_TWL4030_PWRBUTTON=y
 # CONFIG_LEGACY_PTYS is not set
 CONFIG_SERIAL_8250=y
Signature · 1 line
2.2.0
maintainer
#20 lore raw

PATCH 5/5 arm: omap2plus_defconfig: enable TPS65218 power button

Quoted 5 lines · Felipe Balbi

Enable tps65218 power button driver by default as a dynamically linked module so AM437x SK can report power button presses.

Applying this into omap-for-v3.20/defconfig thanks.

Tony

Quoted 19 lines
---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
index c2c3a85..f4a4b2f 100644
@@ -183,6 +183,7 @@ CONFIG_TOUCHSCREEN_EDT_FT5X06=m
 CONFIG_TOUCHSCREEN_TSC2005=m
 CONFIG_TOUCHSCREEN_TSC2007=m
 CONFIG_INPUT_MISC=y
+CONFIG_INPUT_TPS65218_PWRBUTTON=m
 CONFIG_INPUT_TWL4030_PWRBUTTON=y
 # CONFIG_LEGACY_PTYS is not set
 CONFIG_SERIAL_8250=y
Signature · 1 line
2.2.0