forked from jumpnow/meta-bbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/Power_down_button'
- Loading branch information
Showing
7 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ CORE_OS = " \ | |
psplash \ | ||
term-prompt \ | ||
tzdata \ | ||
acpid \ | ||
" | ||
|
||
KERNEL_EXTRA_INSTALL = " \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FILESEXTRAPATHS_prepend := "${THISDIR}/files:" | ||
|
||
SRC_URI += "file://powerbtn-acpi-support.sh \ | ||
file://events/powerbtn-acpi-support \ | ||
file://init \ | ||
" | ||
|
||
|
||
do_install_append() { | ||
install -d ${D}/etc/acpi/ | ||
install -m 0755 ${WORKDIR}/powerbtn-acpi-support.sh ${D}/etc/acpi/ | ||
install -m 0644 ${WORKDIR}/events/powerbtn-acpi-support ${D}/etc/acpi/events/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
event=button[ /]power | ||
action=/etc/acpi/powerbtn-acpi-support.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#! /bin/sh -e | ||
|
||
test -x /usr/sbin/acpid || exit 0 | ||
# NO test -d /proc/acpi || exit 0 | ||
mkdir -p /etc/acpi/events | ||
|
||
case "$1" in | ||
start) | ||
echo -n "Starting Advanced Configuration and Power Interface daemon: " | ||
if [ ! -d /etc/acpi/events ]; then | ||
echo "There is not any rule configuration file." | ||
else | ||
start-stop-daemon -o -S -x /usr/sbin/acpid -- -c /etc/acpi/events | ||
echo "acpid." | ||
fi | ||
;; | ||
stop) | ||
echo -n "Stopping Advanced Configuration and Power Interface daemon: " | ||
start-stop-daemon -o -K -x /usr/sbin/acpid | ||
echo "acpid." | ||
;; | ||
restart|force-reload) | ||
$0 stop | ||
$0 start | ||
;; | ||
*) | ||
echo "Usage: /etc/init.d/acpid {start|stop|restart|force-reload}" | ||
exit 1 | ||
esac | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
# Normal handling. | ||
/sbin/shutdown -h -P now "Power button pressed" |
215 changes: 215 additions & 0 deletions
215
...rnel/linux/linux-stable-4.4/0008-tps65217-Enable-KEY_POWER-press-on-AC-loss-PWR_BUT.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
From ad67322beba1d1014e318463fbca30c0de0477cc Mon Sep 17 00:00:00 2001 | ||
From: Robert Nelson <[email protected]> | ||
Date: Mon, 26 Oct 2015 11:42:13 -0500 | ||
Subject: [PATCH 8/8] tps65217: Enable KEY_POWER press on AC loss / PWR_BUT | ||
|
||
This is an adaption to v3.14.x of the original patch by Andrew Bradford <[email protected]> | ||
Some minor devm_* changes and DT support done by Pantelis Antoniou <[email protected]> for 3.8.x | ||
|
||
Signed-off-by: Robert Nelson <[email protected]> | ||
--- | ||
arch/arm/boot/dts/am335x-bone-common.dtsi | 3 + | ||
drivers/mfd/tps65217.c | 122 +++++++++++++++++++++++++++++- | ||
include/linux/mfd/tps65217.h | 5 ++ | ||
3 files changed, 128 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/arch/arm/boot/dts/am335x-bone-common.dtsi b/arch/arm/boot/dts/am335x-bone-common.dtsi | ||
index 29c0c7e..393af39 100644 | ||
--- a/arch/arm/boot/dts/am335x-bone-common.dtsi | ||
+++ b/arch/arm/boot/dts/am335x-bone-common.dtsi | ||
@@ -330,6 +330,9 @@ | ||
*/ | ||
ti,pmic-shutdown-controller; | ||
|
||
+ interrupt-parent = <&intc>; | ||
+ interrupts = <7>; /* NNMI */ | ||
+ | ||
regulators { | ||
dcdc1_reg: regulator@0 { | ||
regulator-name = "vdds_dpr"; | ||
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c | ||
index 7d1cfc1..0730431 100644 | ||
--- a/drivers/mfd/tps65217.c | ||
+++ b/drivers/mfd/tps65217.c | ||
@@ -24,8 +24,12 @@ | ||
#include <linux/slab.h> | ||
#include <linux/regmap.h> | ||
#include <linux/err.h> | ||
+#include <linux/input.h> | ||
#include <linux/of.h> | ||
#include <linux/of_device.h> | ||
+#include <linux/of_irq.h> | ||
+#include <linux/of_gpio.h> | ||
+#include <linux/interrupt.h> | ||
|
||
#include <linux/mfd/core.h> | ||
#include <linux/mfd/tps65217.h> | ||
@@ -157,6 +161,82 @@ static const struct of_device_id tps65217_of_match[] = { | ||
{ /* sentinel */ }, | ||
}; | ||
|
||
+static irqreturn_t tps65217_irq(int irq, void *irq_data) | ||
+{ | ||
+ struct tps65217 *tps = irq_data; | ||
+ unsigned int int_reg = 0, status_reg = 0; | ||
+ | ||
+ tps65217_reg_read(tps, TPS65217_REG_INT, &int_reg); | ||
+ tps65217_reg_read(tps, TPS65217_REG_STATUS, &status_reg); | ||
+ if (status_reg) | ||
+ dev_dbg(tps->dev, "status now: 0x%X\n", status_reg); | ||
+ | ||
+ if (!int_reg) | ||
+ return IRQ_NONE; | ||
+ | ||
+ if (int_reg & TPS65217_INT_PBI) { | ||
+ /* Handle push button */ | ||
+ dev_dbg(tps->dev, "power button status change\n"); | ||
+ input_report_key(tps->pwr_but, KEY_POWER, | ||
+ status_reg & TPS65217_STATUS_PB); | ||
+ input_sync(tps->pwr_but); | ||
+ } | ||
+ if (int_reg & TPS65217_INT_ACI) { | ||
+ /* Handle AC power status change */ | ||
+ dev_dbg(tps->dev, "AC power status change\n"); | ||
+ /* Press KEY_POWER when AC not present */ | ||
+ input_report_key(tps->pwr_but, KEY_POWER, | ||
+ ~status_reg & TPS65217_STATUS_ACPWR); | ||
+ input_sync(tps->pwr_but); | ||
+ } | ||
+ if (int_reg & TPS65217_INT_USBI) { | ||
+ /* Handle USB power status change */ | ||
+ dev_dbg(tps->dev, "USB power status change\n"); | ||
+ } | ||
+ | ||
+ return IRQ_HANDLED; | ||
+} | ||
+ | ||
+static int tps65217_probe_pwr_but(struct tps65217 *tps) | ||
+{ | ||
+ int ret; | ||
+ unsigned int int_reg; | ||
+ | ||
+ tps->pwr_but = devm_input_allocate_device(tps->dev); | ||
+ if (!tps->pwr_but) { | ||
+ dev_err(tps->dev, | ||
+ "Failed to allocated pwr_but input device\n"); | ||
+ return -ENOMEM; | ||
+ } | ||
+ | ||
+ tps->pwr_but->evbit[0] = BIT_MASK(EV_KEY); | ||
+ tps->pwr_but->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); | ||
+ tps->pwr_but->name = "tps65217_pwr_but"; | ||
+ ret = input_register_device(tps->pwr_but); | ||
+ if (ret) { | ||
+ /* NOTE: devm managed device */ | ||
+ dev_err(tps->dev, "Failed to register button device\n"); | ||
+ return ret; | ||
+ } | ||
+ ret = devm_request_threaded_irq(tps->dev, | ||
+ tps->irq, NULL, tps65217_irq, IRQF_TRIGGER_LOW | IRQF_ONESHOT, | ||
+ "tps65217", tps); | ||
+ if (ret != 0) { | ||
+ dev_err(tps->dev, "Failed to request IRQ %d\n", tps->irq); | ||
+ return ret; | ||
+ } | ||
+ | ||
+ /* enable the power button interrupt */ | ||
+ ret = tps65217_reg_read(tps, TPS65217_REG_INT, &int_reg); | ||
+ if (ret < 0) { | ||
+ dev_err(tps->dev, "Failed to read INT reg\n"); | ||
+ return ret; | ||
+ } | ||
+ int_reg &= ~TPS65217_INT_PBM; | ||
+ tps65217_reg_write(tps, TPS65217_REG_INT, int_reg, TPS65217_PROTECT_NONE); | ||
+ return 0; | ||
+} | ||
+ | ||
static int tps65217_probe(struct i2c_client *client, | ||
const struct i2c_device_id *ids) | ||
{ | ||
@@ -164,10 +244,13 @@ static int tps65217_probe(struct i2c_client *client, | ||
unsigned int version; | ||
unsigned long chip_id = ids->driver_data; | ||
const struct of_device_id *match; | ||
+ struct device_node *node; | ||
bool status_off = false; | ||
+ int irq = -1, irq_gpio = -1; | ||
int ret; | ||
|
||
- if (client->dev.of_node) { | ||
+ node = client->dev.of_node; | ||
+ if (node) { | ||
match = of_match_device(tps65217_of_match, &client->dev); | ||
if (!match) { | ||
dev_err(&client->dev, | ||
@@ -175,8 +258,31 @@ static int tps65217_probe(struct i2c_client *client, | ||
return -EINVAL; | ||
} | ||
chip_id = (unsigned long)match->data; | ||
- status_off = of_property_read_bool(client->dev.of_node, | ||
+ status_off = of_property_read_bool(node, | ||
"ti,pmic-shutdown-controller"); | ||
+ | ||
+ /* at first try to get irq via OF method */ | ||
+ irq = irq_of_parse_and_map(node, 0); | ||
+ if (irq <= 0) { | ||
+ irq = -1; | ||
+ irq_gpio = of_get_named_gpio(node, "irq-gpio", 0); | ||
+ if (irq_gpio >= 0) { | ||
+ /* valid gpio; convert to irq */ | ||
+ ret = devm_gpio_request_one(&client->dev, | ||
+ irq_gpio, GPIOF_DIR_IN, | ||
+ "tps65217-gpio-irq"); | ||
+ if (ret != 0) | ||
+ dev_warn(&client->dev, "Failed to " | ||
+ "request gpio #%d\n", irq_gpio); | ||
+ irq = gpio_to_irq(irq_gpio); | ||
+ if (irq <= 0) { | ||
+ dev_warn(&client->dev, "Failed to " | ||
+ "convert gpio #%d to irq\n", | ||
+ irq_gpio); | ||
+ irq = -1; | ||
+ } | ||
+ } | ||
+ } | ||
} | ||
|
||
if (!chip_id) { | ||
@@ -200,6 +306,18 @@ static int tps65217_probe(struct i2c_client *client, | ||
return ret; | ||
} | ||
|
||
+ tps->irq = irq; | ||
+ tps->irq_gpio = irq_gpio; | ||
+ | ||
+ /* we got an irq, request it */ | ||
+ if (tps->irq >= 0) { | ||
+ ret = tps65217_probe_pwr_but(tps); | ||
+ if (ret < 0) { | ||
+ dev_err(tps->dev, "Failed to probe pwr_but\n"); | ||
+ return ret; | ||
+ } | ||
+ } | ||
+ | ||
ret = mfd_add_devices(tps->dev, -1, tps65217s, | ||
ARRAY_SIZE(tps65217s), NULL, 0, NULL); | ||
if (ret < 0) { | ||
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h | ||
index ac7fba4..05d24a6 100644 | ||
--- a/include/linux/mfd/tps65217.h | ||
+++ b/include/linux/mfd/tps65217.h | ||
@@ -257,6 +257,11 @@ struct tps65217 { | ||
unsigned long id; | ||
struct regulator_desc desc[TPS65217_NUM_REGULATOR]; | ||
struct regmap *regmap; | ||
+ | ||
+ /* Power button and IRQ handling */ | ||
+ int irq_gpio; /* might not be set */ | ||
+ int irq; | ||
+ struct input_dev *pwr_but; | ||
}; | ||
|
||
static inline struct tps65217 *dev_to_tps65217(struct device *dev) | ||
-- | ||
2.6.4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters