Linux RTC
 help / color / mirror / Atom feed
* [RFCv2] rtc: ds1307: add square wave output from ds1308
From: Sean Nyekjaer @ 2017-08-02  5:27 UTC (permalink / raw)
  To: linux-rtc; +Cc: Sean Nyekjaer, linux-clk, alexandre.belloni

Add square wave output to generic clock framework

Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
---
This contains some code duplication(of my opinion) I guess it could be done more
generic together with the ds3231.

Changes from v1:
- Removed explicit disabling of square wave output when running from battery.
  When the clock is disabled using the SQWE bit it's also disabled when running
  from battery.

 drivers/rtc/rtc-ds1307.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 165 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 1cedb21ba792..0c0484260411 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -79,6 +79,7 @@ enum ds_type {
 #	define DS1307_BIT_OUT		0x80
 #	define DS1338_BIT_OSF		0x20
 #	define DS1307_BIT_SQWE		0x10
+#	define DS1308_BIT_BBCLK		0x04
 #	define DS1307_BIT_RS1		0x02
 #	define DS1307_BIT_RS0		0x01
 #define DS1337_REG_CONTROL	0x0e
@@ -1056,6 +1057,13 @@ enum {
 #define clk_32khz_to_ds1307(clk)	\
 	container_of(clk, struct ds1307, clks[DS3231_CLK_32KHZ])
 
+static int ds1308_clk_sqw_rates[] = {
+	1,
+	4096,
+	8192,
+	32768,
+};
+
 static int ds3231_clk_sqw_rates[] = {
 	1,
 	1024,
@@ -1063,6 +1071,19 @@ static int ds3231_clk_sqw_rates[] = {
 	8192,
 };
 
+static int ds1308_write_control(struct ds1307 *ds1307, u8 mask, u8 value)
+{
+	struct mutex *lock = &ds1307->rtc->ops_lock;
+	int ret;
+
+	mutex_lock(lock);
+	ret = regmap_update_bits(ds1307->regmap, DS1307_REG_CONTROL,
+				 mask, value);
+	mutex_unlock(lock);
+
+	return ret;
+}
+
 static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value)
 {
 	struct mutex *lock = &ds1307->rtc->ops_lock;
@@ -1076,6 +1097,24 @@ static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value)
 	return ret;
 }
 
+static unsigned long ds1308_clk_sqw_recalc_rate(struct clk_hw *hw,
+						unsigned long parent_rate)
+{
+	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
+	int control, ret;
+	int rate_sel = 0;
+
+	ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &control);
+	if (ret)
+		return ret;
+	if (control & DS1307_BIT_RS0)
+		rate_sel += 1;
+	if (control & DS1307_BIT_RS1)
+		rate_sel += 2;
+
+	return ds1308_clk_sqw_rates[rate_sel];
+}
+
 static unsigned long ds3231_clk_sqw_recalc_rate(struct clk_hw *hw,
 						unsigned long parent_rate)
 {
@@ -1094,6 +1133,19 @@ static unsigned long ds3231_clk_sqw_recalc_rate(struct clk_hw *hw,
 	return ds3231_clk_sqw_rates[rate_sel];
 }
 
+static long ds1308_clk_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long *prate)
+{
+	int i;
+
+	for (i = ARRAY_SIZE(ds1308_clk_sqw_rates) - 1; i >= 0; i--) {
+		if (ds1308_clk_sqw_rates[i] <= rate)
+			return ds1308_clk_sqw_rates[i];
+	}
+
+	return 0;
+}
+
 static long ds3231_clk_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
 					unsigned long *prate)
 {
@@ -1107,6 +1159,31 @@ static long ds3231_clk_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
 	return 0;
 }
 
+static int ds1308_clk_sqw_set_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long parent_rate)
+{
+	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
+	int control = 0;
+	int rate_sel;
+
+	for (rate_sel = 0; rate_sel < ARRAY_SIZE(ds1308_clk_sqw_rates);
+			rate_sel++) {
+		if (ds1308_clk_sqw_rates[rate_sel] == rate)
+			break;
+	}
+
+	if (rate_sel == ARRAY_SIZE(ds1308_clk_sqw_rates))
+		return -EINVAL;
+
+	if (rate_sel & 1)
+		control |= DS1307_BIT_RS0;
+	if (rate_sel & 2)
+		control |= DS1307_BIT_RS1;
+
+	return ds1337_write_control(ds1307, DS1307_BIT_RS0 | DS1307_BIT_RS1,
+				control);
+}
+
 static int ds3231_clk_sqw_set_rate(struct clk_hw *hw, unsigned long rate,
 					unsigned long parent_rate)
 {
@@ -1132,6 +1209,13 @@ static int ds3231_clk_sqw_set_rate(struct clk_hw *hw, unsigned long rate,
 				control);
 }
 
+static int ds1308_clk_sqw_prepare(struct clk_hw *hw)
+{
+	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
+
+	return ds1308_write_control(ds1307, DS1307_BIT_SQWE, 1);
+}
+
 static int ds3231_clk_sqw_prepare(struct clk_hw *hw)
 {
 	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
@@ -1139,6 +1223,13 @@ static int ds3231_clk_sqw_prepare(struct clk_hw *hw)
 	return ds1337_write_control(ds1307, DS1337_BIT_INTCN, 0);
 }
 
+static void ds1308_clk_sqw_unprepare(struct clk_hw *hw)
+{
+	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
+
+	ds1308_write_control(ds1307, DS1307_BIT_SQWE, 0);
+}
+
 static void ds3231_clk_sqw_unprepare(struct clk_hw *hw)
 {
 	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
@@ -1146,6 +1237,18 @@ static void ds3231_clk_sqw_unprepare(struct clk_hw *hw)
 	ds1337_write_control(ds1307, DS1337_BIT_INTCN, DS1337_BIT_INTCN);
 }
 
+static int ds1308_clk_sqw_is_prepared(struct clk_hw *hw)
+{
+	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
+	int control, ret;
+
+	ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &control);
+	if (ret)
+		return ret;
+
+	return control & DS1307_BIT_SQWE;
+}
+
 static int ds3231_clk_sqw_is_prepared(struct clk_hw *hw)
 {
 	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
@@ -1158,6 +1261,15 @@ static int ds3231_clk_sqw_is_prepared(struct clk_hw *hw)
 	return !(control & DS1337_BIT_INTCN);
 }
 
+static const struct clk_ops ds1308_clk_sqw_ops = {
+	.prepare = ds1308_clk_sqw_prepare,
+	.unprepare = ds1308_clk_sqw_unprepare,
+	.is_prepared = ds1308_clk_sqw_is_prepared,
+	.recalc_rate = ds1308_clk_sqw_recalc_rate,
+	.round_rate = ds1308_clk_sqw_round_rate,
+	.set_rate = ds1308_clk_sqw_set_rate,
+};
+
 static const struct clk_ops ds3231_clk_sqw_ops = {
 	.prepare = ds3231_clk_sqw_prepare,
 	.unprepare = ds3231_clk_sqw_unprepare,
@@ -1220,6 +1332,13 @@ static const struct clk_ops ds3231_clk_32khz_ops = {
 	.recalc_rate = ds3231_clk_32khz_recalc_rate,
 };
 
+static struct clk_init_data ds1308_clks_init[] = {
+	{
+		.name = "ds1308_clk_sqw",
+		.ops = &ds1308_clk_sqw_ops,
+	},
+};
+
 static struct clk_init_data ds3231_clks_init[] = {
 	[DS3231_CLK_SQW] = {
 		.name = "ds3231_clk_sqw",
@@ -1231,6 +1350,44 @@ static struct clk_init_data ds3231_clks_init[] = {
 	},
 };
 
+static int ds1308_clks_register(struct ds1307 *ds1307)
+{
+	struct device_node *node = ds1307->dev->of_node;
+	struct clk_onecell_data	*onecell;
+	int i;
+
+	onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL);
+	if (!onecell)
+		return -ENOMEM;
+
+	onecell->clk_num = ARRAY_SIZE(ds1308_clks_init);
+	onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num,
+				     sizeof(onecell->clks[0]), GFP_KERNEL);
+	if (!onecell->clks)
+		return -ENOMEM;
+
+	for (i = 0; i < ARRAY_SIZE(ds1308_clks_init); i++) {
+		struct clk_init_data init = ds1308_clks_init[i];
+
+		/* optional override of the clockname */
+		of_property_read_string_index(node, "clock-output-names", i,
+						&init.name);
+		ds1307->clks[i].init = &init;
+
+		onecell->clks[i] = devm_clk_register(ds1307->dev,
+						     &ds1307->clks[i]);
+		if (IS_ERR(onecell->clks[i]))
+			return PTR_ERR(onecell->clks[i]);
+	}
+
+	if (!node)
+		return 0;
+
+	of_clk_add_provider(node, of_clk_src_onecell_get, onecell);
+
+	return 0;
+}
+
 static int ds3231_clks_register(struct ds1307 *ds1307)
 {
 	struct device_node *node = ds1307->dev->of_node;
@@ -1280,10 +1437,16 @@ static void ds1307_clks_register(struct ds1307 *ds1307)
 {
 	int ret;
 
-	if (ds1307->type != ds_3231)
+	switch (ds1307->type) {
+	case ds_1308:
+		ret = ds1308_clks_register(ds1307);
+	case ds_3231:
+		ret = ds3231_clks_register(ds1307);
+		break;
+	default:
 		return;
+	}
 
-	ret = ds3231_clks_register(ds1307);
 	if (ret) {
 		dev_warn(ds1307->dev, "unable to register clock device %d\n",
 			 ret);
-- 
2.13.3

^ permalink raw reply related

* [PATCH] rtc: add const to bin_attribute structures
From: Bhumika Goyal @ 2017-08-02  8:35 UTC (permalink / raw)
  To: julia.lawall, a.zummo, alexandre.belloni, linux-rtc, linux-kernel
  Cc: Bhumika Goyal

Add const to bin_attribute structures as they are only passed to the
functions sysfs_{remove/create}_bin_file or
device_{remove/create}_bin_file. The arguments passed are of
type const, so declare the structures to be const.

Done using Coccinelle:

@m disable optional_qualifier@
identifier s;
position p;
@@
static struct bin_attribute s@p={...};

@okay1@
position p;
identifier m.s;
@@
(
sysfs_create_bin_file(...,&s@p,...)
|
sysfs_remove_bin_file(...,&s@p,...)
)

@bad@
position p!={m.p,okay1.p};
identifier m.s;
@@
s@p

@change depends on !bad disable optional_qualifier@
identifier m.s;
@@
static
+const
struct bin_attribute s={...};

Same script was modified for device_{create/remove}_bin_file functions.
Cross compiled drivers/rtc/rtc-tx4939.o file for mips architecture.

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
 drivers/rtc/rtc-ds1305.c   | 2 +-
 drivers/rtc/rtc-ds1343.c   | 2 +-
 drivers/rtc/rtc-stk17ta8.c | 2 +-
 drivers/rtc/rtc-tx4939.c   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index 72b2293..148e746 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -558,7 +558,7 @@ static void msg_init(struct spi_message *m, struct spi_transfer *x,
 	return (status < 0) ? status : count;
 }
 
-static struct bin_attribute nvram = {
+static const struct bin_attribute nvram = {
 	.attr.name	= "nvram",
 	.attr.mode	= S_IRUGO | S_IWUSR,
 	.read		= ds1305_nvram_read,
diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index 895fbee..61d4254 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -191,7 +191,7 @@ static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj,
 }
 
 
-static struct bin_attribute nvram_attr = {
+static const struct bin_attribute nvram_attr = {
 	.attr.name	= "nvram",
 	.attr.mode	= S_IRUGO | S_IWUSR,
 	.read		= ds1343_nvram_read,
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index a456cb6..b84c83a 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -272,7 +272,7 @@ static ssize_t stk17ta8_nvram_write(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute stk17ta8_nvram_attr = {
+static const struct bin_attribute stk17ta8_nvram_attr = {
 	.attr = {
 		.name = "nvram",
 		.mode = S_IRUGO | S_IWUSR,
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 560d9a5..83fbfa5a 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -225,7 +225,7 @@ static ssize_t tx4939_rtc_nvram_write(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute tx4939_rtc_nvram_attr = {
+static const struct bin_attribute tx4939_rtc_nvram_attr = {
 	.attr = {
 		.name = "nvram",
 		.mode = S_IRUGO | S_IWUSR,
-- 
1.9.1

^ permalink raw reply related

* Re: [PATCH 1/4] rtc: pl031: constify amba_ids
From: Linus Walleij @ 2017-08-02 12:30 UTC (permalink / raw)
  To: Russell King
  Cc: Alessandro Zummo, Alexandre Belloni,
	linux-arm-kernel@lists.infradead.org, linux-rtc
In-Reply-To: <E1dYKi9-0001kK-RQ@rmk-PC.armlinux.org.uk>

On Fri, Jul 21, 2017 at 1:18 AM, Russell King
<rmk+kernel@armlinux.org.uk> wrote:

> The AMBA device IDs should be marked const.  Make that so.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply

* Re: [PATCH 2/4] rtc: pl031: use devm_* for allocating memory and mapping resource
From: Linus Walleij @ 2017-08-02 12:31 UTC (permalink / raw)
  To: Russell King
  Cc: Alessandro Zummo, Alexandre Belloni,
	linux-arm-kernel@lists.infradead.org, linux-rtc
In-Reply-To: <E1dYKiF-0001kS-1w@rmk-PC.armlinux.org.uk>

On Fri, Jul 21, 2017 at 1:18 AM, Russell King
<rmk+kernel@armlinux.org.uk> wrote:

> Use the devm_* APIs for allocating memory and mapping the memory in
> the probe function to relieve the driver from having to deal with
> this in the cleanup paths.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply

* Re: [PATCH 3/4] rtc: pl031: avoid exposing alarm if no interrupt
From: Linus Walleij @ 2017-08-02 12:32 UTC (permalink / raw)
  To: Russell King
  Cc: Alessandro Zummo, Alexandre Belloni,
	linux-arm-kernel@lists.infradead.org, linux-rtc
In-Reply-To: <E1dYKiK-0001kZ-6E@rmk-PC.armlinux.org.uk>

On Fri, Jul 21, 2017 at 1:18 AM, Russell King
<rmk+kernel@armlinux.org.uk> wrote:

> If the RTC has no interrupt, there is little point in exposing the RTC
> alarm capabilities, as it can't be used as a wakeup source nor can it
> deliver an event to userspace.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

This makes all kind of sense.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply

* Re: [PATCH 4/4] rtc: pl031: make interrupt optional
From: Linus Walleij @ 2017-08-02 12:33 UTC (permalink / raw)
  To: Russell King
  Cc: Alessandro Zummo, Alexandre Belloni,
	linux-arm-kernel@lists.infradead.org, linux-rtc
In-Reply-To: <E1dYKiP-0001kg-BQ@rmk-PC.armlinux.org.uk>

On Fri, Jul 21, 2017 at 1:18 AM, Russell King
<rmk+kernel@armlinux.org.uk> wrote:

> On some platforms, the interrupt for the PL031 is optional.  Avoid
> trying to claim the interrupt if it's not specified.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply

* Re: [RFCv2] rtc: ds1307: add square wave output from ds1308
From: Stephen Boyd @ 2017-08-02 16:19 UTC (permalink / raw)
  To: Sean Nyekjaer; +Cc: linux-rtc, linux-clk, alexandre.belloni
In-Reply-To: <20170802052727.18289-1-sean.nyekjaer@prevas.dk>

On 08/02, Sean Nyekjaer wrote:
> Add square wave output to generic clock framework

s/to/via the/

perhaps? This makes it sound like we're adding square wave output
support in the generic clock framework by some new clk API or
something.

> 
> Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
> @@ -1056,6 +1057,13 @@ enum {
>  #define clk_32khz_to_ds1307(clk)	\
>  	container_of(clk, struct ds1307, clks[DS3231_CLK_32KHZ])
>  
> +static int ds1308_clk_sqw_rates[] = {

const?

> +	1,
> +	4096,
> +	8192,
> +	32768,
> +};
> +
>  static int ds3231_clk_sqw_rates[] = {
>  	1,
>  	1024,
> @@ -1076,6 +1097,24 @@ static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value)
>  	return ret;
>  }
>  
> +static unsigned long ds1308_clk_sqw_recalc_rate(struct clk_hw *hw,
> +						unsigned long parent_rate)
> +{
> +	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
> +	int control, ret;
> +	int rate_sel = 0;
> +
> +	ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &control);
> +	if (ret)
> +		return ret;
> +	if (control & DS1307_BIT_RS0)
> +		rate_sel += 1;
> +	if (control & DS1307_BIT_RS1)
> +		rate_sel += 2;
> +
> +	return ds1308_clk_sqw_rates[rate_sel];

rate_sel can't be out of bounds on the array here, right?

> +}
> +
>  static unsigned long ds3231_clk_sqw_recalc_rate(struct clk_hw *hw,
>  						unsigned long parent_rate)
>  {
> @@ -1146,6 +1237,18 @@ static void ds3231_clk_sqw_unprepare(struct clk_hw *hw)
>  	ds1337_write_control(ds1307, DS1337_BIT_INTCN, DS1337_BIT_INTCN);
>  }
>  
> +static int ds1308_clk_sqw_is_prepared(struct clk_hw *hw)
> +{
> +	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
> +	int control, ret;
> +
> +	ret = regmap_read(ds1307->regmap, DS1307_REG_CONTROL, &control);
> +	if (ret)
> +		return ret;

This should return 0 on failure? The is_prepared() clk op has an
int return value, but the return value is interpreted as a bool.

> +
> +	return control & DS1307_BIT_SQWE;
> +}
> +
>  static int ds3231_clk_sqw_is_prepared(struct clk_hw *hw)
>  {
>  	struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw);
> @@ -1231,6 +1350,44 @@ static struct clk_init_data ds3231_clks_init[] = {
>  	},
>  };
>  
> +static int ds1308_clks_register(struct ds1307 *ds1307)
> +{
> +	struct device_node *node = ds1307->dev->of_node;
> +	struct clk_onecell_data	*onecell;
> +	int i;
> +
> +	onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL);
> +	if (!onecell)
> +		return -ENOMEM;
> +
> +	onecell->clk_num = ARRAY_SIZE(ds1308_clks_init);
> +	onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num,
> +				     sizeof(onecell->clks[0]), GFP_KERNEL);
> +	if (!onecell->clks)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < ARRAY_SIZE(ds1308_clks_init); i++) {
> +		struct clk_init_data init = ds1308_clks_init[i];
> +
> +		/* optional override of the clockname */
> +		of_property_read_string_index(node, "clock-output-names", i,
> +						&init.name);
> +		ds1307->clks[i].init = &init;
> +
> +		onecell->clks[i] = devm_clk_register(ds1307->dev,
> +						     &ds1307->clks[i]);

Can you please use devm_clk_hw_register() instead?

> +		if (IS_ERR(onecell->clks[i]))
> +			return PTR_ERR(onecell->clks[i]);
> +	}
> +
> +	if (!node)
> +		return 0;
> +
> +	of_clk_add_provider(node, of_clk_src_onecell_get, onecell);

And of_clk_add_hw_provider()?

> +
> +	return 0;
> +}

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply

* [PATCH v2 0/5] Add MediaTek PMIC keys support
From: Chen Zhong @ 2017-08-07  1:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Chen Zhong, Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc

MediaTek PMIC are multi-function devices that can handle key interrupts,
typically there are two keys attached to PMIC, which called pwrkey
and homekey. PWRKEY usually used to wake up system from sleep. Homekey
can used as volume down key due to board design. Long press keys can
shutdown PMIC, the mode can be choose to be one key only or two keys
together.

This series add support for key functions for MediaTek PMIC MT6397/MT6323.

Chen Zhong (5):
  mfd: mt6397: create irq mappings in mfd core driver
  dt-bindings: input: Add document bindings for mtk-pmic-keys
  dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
  input: Add MediaTek PMIC keys support
  mfd: mt6397: Add PMIC keys support to MT6397 driver

 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   36 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |    6 +
 drivers/input/keyboard/Kconfig                     |    9 +
 drivers/input/keyboard/Makefile                    |    1 +
 drivers/input/keyboard/mtk-pmic-keys.c             |  331 ++++++++++++++++++++
 drivers/mfd/mt6397-core.c                          |   40 ++-
 drivers/rtc/rtc-mt6397.c                           |    2 +-
 7 files changed, 421 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

-- 
1.7.9.5
 

^ permalink raw reply

* [PATCH v2 2/5] dt-bindings: input: Add document bindings for mtk-pmic-keys
From: Chen Zhong @ 2017-08-07  1:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Chen Zhong, Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-1-git-send-email-chen.zhong@mediatek.com>

This patch adds the device tree binding documentation for the MediaTek
pmic keys found on PMIC MT6397/MT6323.

Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
---
 .../devicetree/bindings/input/mtk-pmic-keys.txt    |   36 ++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

diff --git a/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
new file mode 100644
index 0000000..c5b230f
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
@@ -0,0 +1,36 @@
+MediaTek MT6397/MT6323 PMIC Keys Device Driver
+
+There are two key functions provided by MT6397/MT6323 PMIC, pwrkey
+and homekey. The key functions are defined as the subnode of the function
+node provided by MT6397/MT6323 PMIC that is being defined as one kind
+of Muti-Function Device (MFD)
+
+For MT6397/MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+
+Required properties:
+- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+- mediatek,pwrkey-code: Keycode of pwrkey
+
+Optional Properties:
+- mediatek,homekey-code: Keycode of homekey
+- mediatek,long-press-mode: Long press key shutdown setting, 1 for
+	pwrkey only, 2 for pwrkey/homekey together, others for disabled.
+- mediatek,long-press-duration: Long press key shutdown duration setting,
+	0/1/2/3 for 8/11/14/5 seconds.
+
+Example:
+
+	pmic: mt6397 {
+		compatible = "mediatek,mt6397";
+
+		...
+
+		mt6397keys: mt6397keys {
+			compatible = "mediatek,mt6397-keys";
+			mediatek,pwrkey-code = <116>;
+			mediatek,homekey-code = <114>;
+			mediatek,long-press-mode = <1>;
+			mediatek,long-press-duration = <0>;
+		};
+	};
\ No newline at end of file
-- 
1.7.9.5

^ permalink raw reply related

* [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
From: Chen Zhong @ 2017-08-07  1:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Chen Zhong, Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-1-git-send-email-chen.zhong@mediatek.com>

The core driver should create and manage irq mappings instead of
leaf drivers. This patch change to pass irq domain to
devm_mfd_add_devices() and it will create mapping for irq resources
automatically. And remove irq mapping in rtc driver since this has
been done in core driver.

Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
---
 drivers/mfd/mt6397-core.c |    4 ++--
 drivers/rtc/rtc-mt6397.c  |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 04a601f..6546d7f 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
 		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6323_devs,
 					   ARRAY_SIZE(mt6323_devs), NULL,
-					   0, NULL);
+					   0, pmic->irq_domain);
 		break;
 
 	case MT6397_CID_CODE:
@@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
 
 		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6397_devs,
 					   ARRAY_SIZE(mt6397_devs), NULL,
-					   0, NULL);
+					   0, pmic->irq_domain);
 		break;
 
 	default:
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1a61fa5..22c52f7 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 	rtc->addr_base = res->start;
 
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-	rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
+	rtc->irq = res->start;
 	if (rtc->irq <= 0)
 		return -EINVAL;
 
-- 
1.7.9.5

^ permalink raw reply related

* [PATCH v2 3/5] dt-bindings: mfd: Add bindings for the keys as subnode of PMIC
From: Chen Zhong @ 2017-08-07  1:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Chen Zhong, Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-1-git-send-email-chen.zhong@mediatek.com>

This patch adds documentation for device tree bindings for keys support
as the subnode of MT6397/MT6323 PMIC.

Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
---
 Documentation/devicetree/bindings/mfd/mt6397.txt |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 522a3bb..d1df77f 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -7,6 +7,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
 - GPIO
 - Clock
 - LED
+- Keys
 
 It is interfaced to host controller using SPI interface by a proprietary hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -40,6 +41,11 @@ Optional subnodes:
 		- compatible: "mediatek,mt6323-led"
 	see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
+- keys
+	Required properties:
+		- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
+	see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+
 Example:
 	pwrap: pwrap@1000f000 {
 		compatible = "mediatek,mt8135-pwrap";
-- 
1.7.9.5

^ permalink raw reply related

* [PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver
From: Chen Zhong @ 2017-08-07  1:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Chen Zhong, Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-1-git-send-email-chen.zhong@mediatek.com>

This patch adds compatible strings and interrupts for pmic keys
which serves as child device of MFD.

Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
---
 drivers/mfd/mt6397-core.c |   36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 6546d7f..3c6a765 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -43,6 +43,30 @@
 	},
 };
 
+static const struct resource mt6323_keys_resources[] = {
+	{
+		.start = MT6323_IRQ_STATUS_PWRKEY,
+		.end   = MT6323_IRQ_STATUS_PWRKEY,
+		.flags = IORESOURCE_IRQ,
+	}, {
+		.start = MT6323_IRQ_STATUS_FCHRKEY,
+		.end   = MT6323_IRQ_STATUS_FCHRKEY,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static const struct resource mt6397_keys_resources[] = {
+	{
+		.start = MT6397_IRQ_PWRKEY,
+		.end   = MT6397_IRQ_PWRKEY,
+		.flags = IORESOURCE_IRQ,
+	}, {
+		.start = MT6397_IRQ_HOMEKEY,
+		.end   = MT6397_IRQ_HOMEKEY,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
 static const struct mfd_cell mt6323_devs[] = {
 	{
 		.name = "mt6323-regulator",
@@ -50,6 +74,11 @@
 	}, {
 		.name = "mt6323-led",
 		.of_compatible = "mediatek,mt6323-led"
+	}, {
+		.name = "mtk-pmic-keys",
+		.num_resources = ARRAY_SIZE(mt6323_keys_resources),
+		.resources = mt6323_keys_resources,
+		.of_compatible = "mediatek,mt6323-keys"
 	},
 };
 
@@ -71,7 +100,12 @@
 	}, {
 		.name = "mt6397-pinctrl",
 		.of_compatible = "mediatek,mt6397-pinctrl",
-	},
+	}, {
+		.name = "mtk-pmic-keys",
+		.num_resources = ARRAY_SIZE(mt6397_keys_resources),
+		.resources = mt6397_keys_resources,
+		.of_compatible = "mediatek,mt6397-keys"
+	}
 };
 
 static void mt6397_irq_lock(struct irq_data *data)
-- 
1.7.9.5

^ permalink raw reply related

* [PATCH v2 4/5] input: Add MediaTek PMIC keys support
From: Chen Zhong @ 2017-08-07  1:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Chen Zhong, Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-1-git-send-email-chen.zhong@mediatek.com>

This patch add support to handle MediaTek PMIC MT6397/MT6323 key
interrupts including pwrkey and homekey, also add setting for
long press key shutdown behavior.

Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
---
 drivers/input/keyboard/Kconfig         |    9 +
 drivers/input/keyboard/Makefile        |    1 +
 drivers/input/keyboard/mtk-pmic-keys.c |  331 ++++++++++++++++++++++++++++++++
 3 files changed, 341 insertions(+)
 create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4c4ab1c..730d9b5 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -756,4 +756,13 @@ config KEYBOARD_BCM
 	  To compile this driver as a module, choose M here: the
 	  module will be called bcm-keypad.
 
+config KEYBOARD_MTK_PMIC
+	tristate "MediaTek PMIC keys support"
+	depends on MFD_MT6397
+	help
+	  Say Y here if you want to use the pmic keys (pwrkey/homekey).
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pmic-keys.
+
 endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index d2338ba..20c0b98 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS)		+= mcs_touchkey.o
 obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
+obj-$(CONFIG_KEYBOARD_MTK_PMIC) 	+= mtk-pmic-keys.o
 obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK)		+= nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)		+= nspire-keypad.o
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
new file mode 100644
index 0000000..5d1f133
--- /dev/null
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2017 MediaTek, Inc.
+ *
+ * Author: Chen Zhong <chen.zhong@mediatek.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+#include <linux/mfd/mt6323/registers.h>
+#include <linux/mfd/mt6397/registers.h>
+#include <linux/mfd/mt6397/core.h>
+#include <linux/slab.h>
+#include <linux/irqdomain.h>
+
+#define PWRKEY_RST_EN_MASK	0x1
+#define PWRKEY_RST_EN_SHIFT	6
+#define HOMEKEY_RST_EN_MASK	0x1
+#define HOMEKEY_RST_EN_SHIFT	5
+#define RST_DU_MASK		0x3
+#define RST_DU_SHIFT		8
+
+struct pmic_keys_regs {
+	u32 deb_reg;
+	u32 deb_mask;
+	u32 intsel_reg;
+	u32 intsel_mask;
+};
+
+#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask)	\
+{									\
+	.deb_reg		= _deb_reg,				\
+	.deb_mask		= _deb_mask,				\
+	.intsel_reg		= _intsel_reg,				\
+	.intsel_mask		= _intsel_mask,				\
+}
+
+struct pmic_regs {
+	const struct pmic_keys_regs pwrkey_regs;
+	const struct pmic_keys_regs homekey_regs;
+	u32 pmic_rst_reg;
+};
+
+static const struct pmic_regs mt6397_regs = {
+	.pwrkey_regs = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
+		0x8, MT6397_INT_RSV, 0x10),
+	.homekey_regs = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
+		0x10, MT6397_INT_RSV, 0x8),
+	.pmic_rst_reg = MT6397_TOP_RST_MISC,
+};
+
+static const struct pmic_regs mt6323_regs = {
+	.pwrkey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+		0x2, MT6323_INT_MISC_CON, 0x10),
+	.homekey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
+		0x4, MT6323_INT_MISC_CON, 0x8),
+	.pmic_rst_reg = MT6323_TOP_RST_MISC,
+};
+
+struct pmic_keys_info {
+	struct mtk_pmic_keys *keys;
+	const struct pmic_keys_regs *regs;
+	int keycode;
+	int irq;
+};
+
+struct mtk_pmic_keys {
+	struct input_dev *input_dev;
+	struct device *dev;
+	struct regmap *regmap;
+	struct irq_domain *irq_domain;
+	struct pmic_keys_info pwrkey, homekey;
+};
+
+enum long_press_mode {
+	LP_DISABLE,
+	LP_ONEKEY,
+	LP_TWOKEY,
+};
+
+static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 pmic_rst_reg)
+{
+	int ret;
+	u32 long_press_mode, long_press_duration;
+
+	ret = of_property_read_u32(keys->dev->of_node,
+		"mediatek,long-press-duration", &long_press_duration);
+	if (ret)
+		long_press_duration = 0;
+
+	regmap_update_bits(keys->regmap, pmic_rst_reg,
+			   RST_DU_MASK << RST_DU_SHIFT,
+			   long_press_duration << RST_DU_SHIFT);
+
+	ret = of_property_read_u32(keys->dev->of_node,
+		"mediatek,long-press-mode", &long_press_mode);
+	if (ret)
+		long_press_mode = LP_DISABLE;
+
+	switch (long_press_mode) {
+	case LP_ONEKEY:
+		regmap_update_bits(keys->regmap, pmic_rst_reg,
+				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
+				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT);
+		regmap_update_bits(keys->regmap, pmic_rst_reg,
+				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
+				   0);
+		break;
+	case LP_TWOKEY:
+		regmap_update_bits(keys->regmap, pmic_rst_reg,
+				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
+				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT);
+		regmap_update_bits(keys->regmap, pmic_rst_reg,
+				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
+				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT);
+		break;
+	case LP_DISABLE:
+		regmap_update_bits(keys->regmap, pmic_rst_reg,
+				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
+				   0);
+		regmap_update_bits(keys->regmap, pmic_rst_reg,
+				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
+				   0);
+		break;
+	default:
+		break;
+	}
+}
+
+static irqreturn_t mtk_pmic_keys_irq_handler_thread(int irq, void *data)
+{
+	struct pmic_keys_info *info = data;
+	u32 key_deb, pressed;
+
+	regmap_read(info->keys->regmap, info->regs->deb_reg, &key_deb);
+
+	key_deb &= info->regs->deb_mask;
+
+	pressed = !key_deb;
+
+	input_report_key(info->keys->input_dev, info->keycode, pressed);
+	input_sync(info->keys->input_dev);
+
+	dev_dbg(info->keys->dev, "[PMICKEYS] (%s) key =%d using PMIC\n",
+		 pressed ? "pressed" : "released", info->keycode);
+
+	return IRQ_HANDLED;
+}
+
+static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys,
+		const char *propname, struct pmic_keys_info *info, bool wakeup)
+{
+	int ret;
+
+	ret = of_property_read_u32(keys->dev->of_node,
+		propname, &info->keycode);
+	if (ret)
+		return 0;
+
+	if (!info->keycode)
+		return 0;
+
+	info->keys = keys;
+
+	ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg,
+				 info->regs->intsel_mask,
+				 info->regs->intsel_mask);
+	if (ret < 0)
+		return ret;
+
+	ret = devm_request_threaded_irq(keys->dev, info->irq, NULL,
+					mtk_pmic_keys_irq_handler_thread,
+					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
+					"mtk-pmic-keys", info);
+	if (ret) {
+		dev_err(keys->dev, "Failed to request IRQ: %d: %d\n",
+			info->irq, ret);
+		return ret;
+	}
+
+	if (wakeup)
+		irq_set_irq_wake(info->irq, 1);
+
+	input_set_capability(keys->input_dev, EV_KEY, info->keycode);
+
+	return 0;
+}
+
+static void mtk_pmic_keys_dispose_irq(struct mtk_pmic_keys *keys)
+{
+	if (keys->pwrkey.irq)
+		irq_dispose_mapping(keys->pwrkey.irq);
+
+	if (keys->homekey.irq)
+		irq_dispose_mapping(keys->homekey.irq);
+}
+
+static const struct of_device_id of_pmic_keys_match_tbl[] = {
+	{
+		.compatible = "mediatek,mt6397-keys",
+		.data = &mt6397_regs,
+	}, {
+		.compatible = "mediatek,mt6323-keys",
+		.data = &mt6323_regs,
+	}, {
+		/* sentinel */
+	}
+};
+MODULE_DEVICE_TABLE(of, of_pmic_keys_match_tbl);
+
+static int mtk_pmic_keys_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct resource *res_pwrkey, *res_homekey;
+	struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent);
+	struct mtk_pmic_keys *keys;
+	const struct pmic_regs *pmic_regs;
+	struct input_dev *input_dev;
+	const struct of_device_id *of_id =
+		of_match_device(of_pmic_keys_match_tbl, &pdev->dev);
+
+	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
+	if (!keys)
+		return -ENOMEM;
+
+	keys->dev = &pdev->dev;
+	keys->regmap = pmic_chip->regmap;
+	keys->irq_domain = pmic_chip->irq_domain;
+
+	pmic_regs = of_id->data;
+	keys->pwrkey.regs = &pmic_regs->pwrkey_regs;
+	keys->homekey.regs = &pmic_regs->homekey_regs;
+
+	res_pwrkey = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!res_pwrkey) {
+		dev_err(&pdev->dev, "no IRQ resource\n");
+		return -ENODEV;
+	}
+
+	keys->pwrkey.irq = res_pwrkey->start;
+	if (keys->pwrkey.irq <= 0)
+		return -EINVAL;
+
+	res_homekey = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
+	if (!res_homekey) {
+		dev_err(&pdev->dev, "no IRQ resource\n");
+		return -ENODEV;
+	}
+
+	keys->homekey.irq = res_homekey->start;
+	if (keys->homekey.irq <= 0)
+		return -EINVAL;
+
+	keys->input_dev = input_dev = devm_input_allocate_device(keys->dev);
+	if (!input_dev) {
+		dev_err(&pdev->dev, "[PMICKEYS] input allocate device fail.\n");
+		return -ENOMEM;
+	}
+
+	input_dev->name = "mtk-pmic-keys";
+	input_dev->id.bustype = BUS_HOST;
+	input_dev->id.vendor = 0x0001;
+	input_dev->id.product = 0x0001;
+	input_dev->id.version = 0x0001;
+	input_dev->dev.parent = &pdev->dev;
+
+	ret = mtk_pmic_key_setup(keys, "mediatek,pwrkey-code",
+				 &keys->pwrkey, true);
+	if (ret)
+		goto out_dispose_irq;
+
+	ret = mtk_pmic_key_setup(keys, "mediatek,homekey-code",
+				 &keys->homekey, false);
+	if (ret)
+		goto out_dispose_irq;
+
+	ret = input_register_device(input_dev);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"[PMICKEYS] register input device failed (%d)\n", ret);
+		return ret;
+	}
+
+	long_press_reset_setup(keys, pmic_regs->pmic_rst_reg);
+
+	return 0;
+
+out_dispose_irq:
+	mtk_pmic_keys_dispose_irq(keys);
+	return ret;
+}
+
+static int mtk_pmic_keys_remove(struct platform_device *pdev)
+{
+	struct mtk_pmic_keys *keys = platform_get_drvdata(pdev);
+
+	mtk_pmic_keys_dispose_irq(keys);
+
+	return 0;
+}
+
+static struct platform_driver pmic_keys_pdrv = {
+	.probe = mtk_pmic_keys_probe,
+	.remove = mtk_pmic_keys_remove,
+	.driver = {
+		   .name = "mtk-pmic-keys",
+		   .of_match_table = of_pmic_keys_match_tbl,
+	},
+};
+
+module_platform_driver(pmic_keys_pdrv);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>");
+MODULE_DESCRIPTION("MTK pmic-keys driver v0.1");
-- 
1.7.9.5

^ permalink raw reply related

* Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
From: Alexandre Belloni @ 2017-08-07 21:32 UTC (permalink / raw)
  To: Chen Zhong
  Cc: Dmitry Torokhov, Rob Herring, Mark Rutland, Matthias Brugger,
	Lee Jones, Eddie Huang, Alessandro Zummo, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-2-git-send-email-chen.zhong@mediatek.com>

On 07/08/2017 at 09:57:41 +0800, Chen Zhong wrote:
> The core driver should create and manage irq mappings instead of
> leaf drivers. This patch change to pass irq domain to
> devm_mfd_add_devices() and it will create mapping for irq resources
> automatically. And remove irq mapping in rtc driver since this has
> been done in core driver.
> 
> Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>

For the RTC part:
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
>  drivers/mfd/mt6397-core.c |    4 ++--
>  drivers/rtc/rtc-mt6397.c  |    2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> index 04a601f..6546d7f 100644
> --- a/drivers/mfd/mt6397-core.c
> +++ b/drivers/mfd/mt6397-core.c
> @@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
>  
>  		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6323_devs,
>  					   ARRAY_SIZE(mt6323_devs), NULL,
> -					   0, NULL);
> +					   0, pmic->irq_domain);
>  		break;
>  
>  	case MT6397_CID_CODE:
> @@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
>  
>  		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6397_devs,
>  					   ARRAY_SIZE(mt6397_devs), NULL,
> -					   0, NULL);
> +					   0, pmic->irq_domain);
>  		break;
>  
>  	default:
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index 1a61fa5..22c52f7 100644
> --- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
>  	rtc->addr_base = res->start;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> -	rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
> +	rtc->irq = res->start;
>  	if (rtc->irq <= 0)
>  		return -EINVAL;
>  
> -- 
> 1.7.9.5
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply

* Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
From: Dmitry Torokhov @ 2017-08-08  2:53 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Chen Zhong, Rob Herring, Mark Rutland, Matthias Brugger,
	Lee Jones, Eddie Huang, Alessandro Zummo, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <20170807213244.7hrd3isq5jj44dgd@piout.net>

On Mon, Aug 07, 2017 at 11:32:44PM +0200, Alexandre Belloni wrote:
> On 07/08/2017 at 09:57:41 +0800, Chen Zhong wrote:
> > The core driver should create and manage irq mappings instead of
> > leaf drivers. This patch change to pass irq domain to
> > devm_mfd_add_devices() and it will create mapping for irq resources
> > automatically. And remove irq mapping in rtc driver since this has
> > been done in core driver.
> > 
> > Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
> 
> For the RTC part:
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> 
> > ---
> >  drivers/mfd/mt6397-core.c |    4 ++--
> >  drivers/rtc/rtc-mt6397.c  |    2 +-
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> > index 04a601f..6546d7f 100644
> > --- a/drivers/mfd/mt6397-core.c
> > +++ b/drivers/mfd/mt6397-core.c
> > @@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
> >  
> >  		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6323_devs,
> >  					   ARRAY_SIZE(mt6323_devs), NULL,
> > -					   0, NULL);
> > +					   0, pmic->irq_domain);
> >  		break;
> >  
> >  	case MT6397_CID_CODE:
> > @@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
> >  
> >  		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6397_devs,
> >  					   ARRAY_SIZE(mt6397_devs), NULL,
> > -					   0, NULL);
> > +					   0, pmic->irq_domain);
> >  		break;
> >  
> >  	default:
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index 1a61fa5..22c52f7 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> >  	rtc->addr_base = res->start;
> >  
> >  	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > -	rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
> > +	rtc->irq = res->start;

Why not

	rtc->irq = platform_get_irq(pdev, 0);
	if (rtc->irq < 0)
		return rtc->irq;
?

This way you propagate error properly.

Thanks.

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH v2 4/5] input: Add MediaTek PMIC keys support
From: Dmitry Torokhov @ 2017-08-08  3:03 UTC (permalink / raw)
  To: Chen Zhong
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-5-git-send-email-chen.zhong@mediatek.com>

Hi Chen,

On Mon, Aug 07, 2017 at 09:57:44AM +0800, Chen Zhong wrote:
> This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> interrupts including pwrkey and homekey, also add setting for
> long press key shutdown behavior.
> 
> Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
> ---
>  drivers/input/keyboard/Kconfig         |    9 +
>  drivers/input/keyboard/Makefile        |    1 +
>  drivers/input/keyboard/mtk-pmic-keys.c |  331 ++++++++++++++++++++++++++++++++
>  3 files changed, 341 insertions(+)
>  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> 
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index 4c4ab1c..730d9b5 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -756,4 +756,13 @@ config KEYBOARD_BCM
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called bcm-keypad.
>  
> +config KEYBOARD_MTK_PMIC
> +	tristate "MediaTek PMIC keys support"
> +	depends on MFD_MT6397
> +	help
> +	  Say Y here if you want to use the pmic keys (pwrkey/homekey).
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called pmic-keys.
> +
>  endif
> diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
> index d2338ba..20c0b98 100644
> --- a/drivers/input/keyboard/Makefile
> +++ b/drivers/input/keyboard/Makefile
> @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
>  obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
>  obj-$(CONFIG_KEYBOARD_MCS)		+= mcs_touchkey.o
>  obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
> +obj-$(CONFIG_KEYBOARD_MTK_PMIC) 	+= mtk-pmic-keys.o
>  obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
>  obj-$(CONFIG_KEYBOARD_NOMADIK)		+= nomadik-ske-keypad.o
>  obj-$(CONFIG_KEYBOARD_NSPIRE)		+= nspire-keypad.o
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> new file mode 100644
> index 0000000..5d1f133
> --- /dev/null
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -0,0 +1,331 @@
> +/*
> + * Copyright (C) 2017 MediaTek, Inc.
> + *
> + * Author: Chen Zhong <chen.zhong@mediatek.com>
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * 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.
> + *
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/kernel.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/regmap.h>
> +#include <linux/mfd/mt6323/registers.h>
> +#include <linux/mfd/mt6397/registers.h>
> +#include <linux/mfd/mt6397/core.h>
> +#include <linux/slab.h>
> +#include <linux/irqdomain.h>

Not needed.

> +
> +#define PWRKEY_RST_EN_MASK	0x1
> +#define PWRKEY_RST_EN_SHIFT	6
> +#define HOMEKEY_RST_EN_MASK	0x1
> +#define HOMEKEY_RST_EN_SHIFT	5
> +#define RST_DU_MASK		0x3
> +#define RST_DU_SHIFT		8
> +
> +struct pmic_keys_regs {
> +	u32 deb_reg;
> +	u32 deb_mask;
> +	u32 intsel_reg;
> +	u32 intsel_mask;
> +};
> +
> +#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask)	\
> +{									\
> +	.deb_reg		= _deb_reg,				\
> +	.deb_mask		= _deb_mask,				\
> +	.intsel_reg		= _intsel_reg,				\
> +	.intsel_mask		= _intsel_mask,				\
> +}
> +
> +struct pmic_regs {
> +	const struct pmic_keys_regs pwrkey_regs;
> +	const struct pmic_keys_regs homekey_regs;
> +	u32 pmic_rst_reg;
> +};
> +
> +static const struct pmic_regs mt6397_regs = {
> +	.pwrkey_regs = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
> +		0x8, MT6397_INT_RSV, 0x10),
> +	.homekey_regs = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
> +		0x10, MT6397_INT_RSV, 0x8),
> +	.pmic_rst_reg = MT6397_TOP_RST_MISC,
> +};
> +
> +static const struct pmic_regs mt6323_regs = {
> +	.pwrkey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
> +		0x2, MT6323_INT_MISC_CON, 0x10),
> +	.homekey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
> +		0x4, MT6323_INT_MISC_CON, 0x8),
> +	.pmic_rst_reg = MT6323_TOP_RST_MISC,
> +};
> +
> +struct pmic_keys_info {
> +	struct mtk_pmic_keys *keys;
> +	const struct pmic_keys_regs *regs;
> +	int keycode;
> +	int irq;
> +};
> +
> +struct mtk_pmic_keys {
> +	struct input_dev *input_dev;
> +	struct device *dev;
> +	struct regmap *regmap;
> +	struct irq_domain *irq_domain;

Not needed.

> +	struct pmic_keys_info pwrkey, homekey;
> +};
> +
> +enum long_press_mode {
> +	LP_DISABLE,
> +	LP_ONEKEY,
> +	LP_TWOKEY,
> +};
> +
> +static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 pmic_rst_reg)
> +{
> +	int ret;
> +	u32 long_press_mode, long_press_duration;
> +
> +	ret = of_property_read_u32(keys->dev->of_node,
> +		"mediatek,long-press-duration", &long_press_duration);
> +	if (ret)
> +		long_press_duration = 0;
> +
> +	regmap_update_bits(keys->regmap, pmic_rst_reg,
> +			   RST_DU_MASK << RST_DU_SHIFT,
> +			   long_press_duration << RST_DU_SHIFT);
> +
> +	ret = of_property_read_u32(keys->dev->of_node,
> +		"mediatek,long-press-mode", &long_press_mode);
> +	if (ret)
> +		long_press_mode = LP_DISABLE;
> +
> +	switch (long_press_mode) {
> +	case LP_ONEKEY:
> +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
> +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT);
> +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
> +				   0);
> +		break;
> +	case LP_TWOKEY:
> +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
> +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT);
> +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
> +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT);
> +		break;
> +	case LP_DISABLE:
> +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
> +				   0);
> +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
> +				   0);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
> +static irqreturn_t mtk_pmic_keys_irq_handler_thread(int irq, void *data)
> +{
> +	struct pmic_keys_info *info = data;
> +	u32 key_deb, pressed;
> +
> +	regmap_read(info->keys->regmap, info->regs->deb_reg, &key_deb);
> +
> +	key_deb &= info->regs->deb_mask;
> +
> +	pressed = !key_deb;
> +
> +	input_report_key(info->keys->input_dev, info->keycode, pressed);
> +	input_sync(info->keys->input_dev);
> +
> +	dev_dbg(info->keys->dev, "[PMICKEYS] (%s) key =%d using PMIC\n",
> +		 pressed ? "pressed" : "released", info->keycode);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys,
> +		const char *propname, struct pmic_keys_info *info, bool wakeup)
> +{
> +	int ret;
> +
> +	ret = of_property_read_u32(keys->dev->of_node,
> +		propname, &info->keycode);
> +	if (ret)
> +		return 0;
> +
> +	if (!info->keycode)
> +		return 0;
> +
> +	info->keys = keys;
> +
> +	ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg,
> +				 info->regs->intsel_mask,
> +				 info->regs->intsel_mask);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = devm_request_threaded_irq(keys->dev, info->irq, NULL,
> +					mtk_pmic_keys_irq_handler_thread,
> +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> +					"mtk-pmic-keys", info);
> +	if (ret) {
> +		dev_err(keys->dev, "Failed to request IRQ: %d: %d\n",
> +			info->irq, ret);
> +		return ret;
> +	}
> +
> +	if (wakeup)
> +		irq_set_irq_wake(info->irq, 1);
> +
> +	input_set_capability(keys->input_dev, EV_KEY, info->keycode);
> +
> +	return 0;
> +}
> +
> +static void mtk_pmic_keys_dispose_irq(struct mtk_pmic_keys *keys)
> +{
> +	if (keys->pwrkey.irq)
> +		irq_dispose_mapping(keys->pwrkey.irq);
> +
> +	if (keys->homekey.irq)
> +		irq_dispose_mapping(keys->homekey.irq);

You did not create the mapping, you should not destroy it.

> +}
> +
> +static const struct of_device_id of_pmic_keys_match_tbl[] = {
> +	{
> +		.compatible = "mediatek,mt6397-keys",
> +		.data = &mt6397_regs,
> +	}, {
> +		.compatible = "mediatek,mt6323-keys",
> +		.data = &mt6323_regs,
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +MODULE_DEVICE_TABLE(of, of_pmic_keys_match_tbl);
> +
> +static int mtk_pmic_keys_probe(struct platform_device *pdev)
> +{
> +	int ret;
> +	struct resource *res_pwrkey, *res_homekey;
> +	struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent);
> +	struct mtk_pmic_keys *keys;
> +	const struct pmic_regs *pmic_regs;
> +	struct input_dev *input_dev;
> +	const struct of_device_id *of_id =
> +		of_match_device(of_pmic_keys_match_tbl, &pdev->dev);
> +
> +	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
> +	if (!keys)
> +		return -ENOMEM;
> +
> +	keys->dev = &pdev->dev;
> +	keys->regmap = pmic_chip->regmap;
> +	keys->irq_domain = pmic_chip->irq_domain;

Not needed.

> +
> +	pmic_regs = of_id->data;
> +	keys->pwrkey.regs = &pmic_regs->pwrkey_regs;
> +	keys->homekey.regs = &pmic_regs->homekey_regs;
> +
> +	res_pwrkey = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> +	if (!res_pwrkey) {
> +		dev_err(&pdev->dev, "no IRQ resource\n");
> +		return -ENODEV;
> +	}
> +
> +	keys->pwrkey.irq = res_pwrkey->start;
> +	if (keys->pwrkey.irq <= 0)
> +		return -EINVAL;

Please do

	keys->pwrkey.irq = platform_get_irq(pdev, 0);
	if (keys->pwrkey.irq < 0)
		return keys->pwrkey.irq;

> +
> +	res_homekey = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
> +	if (!res_homekey) {
> +		dev_err(&pdev->dev, "no IRQ resource\n");
> +		return -ENODEV;
> +	}
> +
> +	keys->homekey.irq = res_homekey->start;
> +	if (keys->homekey.irq <= 0)
> +		return -EINVAL;

Same as above.

> +
> +	keys->input_dev = input_dev = devm_input_allocate_device(keys->dev);
> +	if (!input_dev) {
> +		dev_err(&pdev->dev, "[PMICKEYS] input allocate device fail.\n");
> +		return -ENOMEM;
> +	}
> +
> +	input_dev->name = "mtk-pmic-keys";
> +	input_dev->id.bustype = BUS_HOST;
> +	input_dev->id.vendor = 0x0001;
> +	input_dev->id.product = 0x0001;
> +	input_dev->id.version = 0x0001;
> +	input_dev->dev.parent = &pdev->dev;

Not needed, devm_input_allocate_device() already does this. 

> +
> +	ret = mtk_pmic_key_setup(keys, "mediatek,pwrkey-code",
> +				 &keys->pwrkey, true);
> +	if (ret)
> +		goto out_dispose_irq;

Can you please call this variable "error" and do

	if (error)
		return error;

You are using devm and no longer creating mappings, so you can return
directly and rely on devm infrastructure to unwind.

> +
> +	ret = mtk_pmic_key_setup(keys, "mediatek,homekey-code",
> +				 &keys->homekey, false);
> +	if (ret)
> +		goto out_dispose_irq;
> +
> +	ret = input_register_device(input_dev);
> +	if (ret) {
> +		dev_err(&pdev->dev,
> +			"[PMICKEYS] register input device failed (%d)\n", ret);

No need for [PMICKEYS] prefix, dev_err prints device and driver already.

> +		return ret;
> +	}
> +
> +	long_press_reset_setup(keys, pmic_regs->pmic_rst_reg);
> +
> +	return 0;
> +
> +out_dispose_irq:
> +	mtk_pmic_keys_dispose_irq(keys);
> +	return ret;
> +}
> +
> +static int mtk_pmic_keys_remove(struct platform_device *pdev)
> +{
> +	struct mtk_pmic_keys *keys = platform_get_drvdata(pdev);
> +
> +	mtk_pmic_keys_dispose_irq(keys);

Not needed. The whole function is not needed.

> +
> +	return 0;
> +}
> +
> +static struct platform_driver pmic_keys_pdrv = {
> +	.probe = mtk_pmic_keys_probe,
> +	.remove = mtk_pmic_keys_remove,
> +	.driver = {
> +		   .name = "mtk-pmic-keys",
> +		   .of_match_table = of_pmic_keys_match_tbl,
> +	},
> +};
> +
> +module_platform_driver(pmic_keys_pdrv);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>");
> +MODULE_DESCRIPTION("MTK pmic-keys driver v0.1");
> -- 
> 1.7.9.5
> 

Thanks.

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
From: Chen Zhong @ 2017-08-08  9:09 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Alexandre Belloni, Rob Herring, Mark Rutland, Matthias Brugger,
	Lee Jones, Eddie Huang, Alessandro Zummo, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <20170808025328.GB12328@dtor-ws>

On Mon, 2017-08-07 at 19:53 -0700, Dmitry Torokhov wrote:
> On Mon, Aug 07, 2017 at 11:32:44PM +0200, Alexandre Belloni wrote:
> > On 07/08/2017 at 09:57:41 +0800, Chen Zhong wrote:
> > > The core driver should create and manage irq mappings instead of
> > > leaf drivers. This patch change to pass irq domain to
> > > devm_mfd_add_devices() and it will create mapping for irq resources
> > > automatically. And remove irq mapping in rtc driver since this has
> > > been done in core driver.
> > > 
> > > Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
> > 
> > For the RTC part:
> > Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> > 
> > > ---
> > >  drivers/mfd/mt6397-core.c |    4 ++--
> > >  drivers/rtc/rtc-mt6397.c  |    2 +-
> > >  2 files changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> > > index 04a601f..6546d7f 100644
> > > --- a/drivers/mfd/mt6397-core.c
> > > +++ b/drivers/mfd/mt6397-core.c
> > > @@ -289,7 +289,7 @@ static int mt6397_probe(struct platform_device *pdev)
> > >  
> > >  		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6323_devs,
> > >  					   ARRAY_SIZE(mt6323_devs), NULL,
> > > -					   0, NULL);
> > > +					   0, pmic->irq_domain);
> > >  		break;
> > >  
> > >  	case MT6397_CID_CODE:
> > > @@ -304,7 +304,7 @@ static int mt6397_probe(struct platform_device *pdev)
> > >  
> > >  		ret = devm_mfd_add_devices(&pdev->dev, -1, mt6397_devs,
> > >  					   ARRAY_SIZE(mt6397_devs), NULL,
> > > -					   0, NULL);
> > > +					   0, pmic->irq_domain);
> > >  		break;
> > >  
> > >  	default:
> > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > > index 1a61fa5..22c52f7 100644
> > > --- a/drivers/rtc/rtc-mt6397.c
> > > +++ b/drivers/rtc/rtc-mt6397.c
> > > @@ -323,7 +323,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> > >  	rtc->addr_base = res->start;
> > >  
> > >  	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > > -	rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
> > > +	rtc->irq = res->start;
> 
> Why not
> 
> 	rtc->irq = platform_get_irq(pdev, 0);
> 	if (rtc->irq < 0)
> 		return rtc->irq;
> ?
> 
> This way you propagate error properly.
> 
> Thanks.
> 

Hi Dmitry,

	I'll modify it to get irq number via this way.

Thank you.

^ permalink raw reply

* Re: [PATCH v2 4/5] input: Add MediaTek PMIC keys support
From: Chen Zhong @ 2017-08-08  9:22 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rob Herring, Mark Rutland, Matthias Brugger, Lee Jones,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Linus Walleij, Beomho Seo, linux-input,
	devicetree, linux-arm-kernel, linux-mediatek, linux-kernel,
	linux-rtc
In-Reply-To: <20170808030318.GC12328@dtor-ws>

Hi Dmitry,

	Thanks for your suggestions. I'll modify them and send the next version
later.

On Mon, 2017-08-07 at 20:03 -0700, Dmitry Torokhov wrote:
> Hi Chen,
> 
> On Mon, Aug 07, 2017 at 09:57:44AM +0800, Chen Zhong wrote:
> > This patch add support to handle MediaTek PMIC MT6397/MT6323 key
> > interrupts including pwrkey and homekey, also add setting for
> > long press key shutdown behavior.
> > 
> > Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
> > ---
> >  drivers/input/keyboard/Kconfig         |    9 +
> >  drivers/input/keyboard/Makefile        |    1 +
> >  drivers/input/keyboard/mtk-pmic-keys.c |  331 ++++++++++++++++++++++++++++++++
> >  3 files changed, 341 insertions(+)
> >  create mode 100644 drivers/input/keyboard/mtk-pmic-keys.c
> > 
> > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> > index 4c4ab1c..730d9b5 100644
> > --- a/drivers/input/keyboard/Kconfig
> > +++ b/drivers/input/keyboard/Kconfig
> > @@ -756,4 +756,13 @@ config KEYBOARD_BCM
> >  	  To compile this driver as a module, choose M here: the
> >  	  module will be called bcm-keypad.
> >  
> > +config KEYBOARD_MTK_PMIC
> > +	tristate "MediaTek PMIC keys support"
> > +	depends on MFD_MT6397
> > +	help
> > +	  Say Y here if you want to use the pmic keys (pwrkey/homekey).
> > +
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called pmic-keys.
> > +
> >  endif
> > diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
> > index d2338ba..20c0b98 100644
> > --- a/drivers/input/keyboard/Makefile
> > +++ b/drivers/input/keyboard/Makefile
> > @@ -40,6 +40,7 @@ obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
> >  obj-$(CONFIG_KEYBOARD_MCS)		+= mcs_touchkey.o
> >  obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
> > +obj-$(CONFIG_KEYBOARD_MTK_PMIC) 	+= mtk-pmic-keys.o
> >  obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
> >  obj-$(CONFIG_KEYBOARD_NOMADIK)		+= nomadik-ske-keypad.o
> >  obj-$(CONFIG_KEYBOARD_NSPIRE)		+= nspire-keypad.o
> > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> > new file mode 100644
> > index 0000000..5d1f133
> > --- /dev/null
> > +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> > @@ -0,0 +1,331 @@
> > +/*
> > + * Copyright (C) 2017 MediaTek, Inc.
> > + *
> > + * Author: Chen Zhong <chen.zhong@mediatek.com>
> > + *
> > + * This software is licensed under the terms of the GNU General Public
> > + * License version 2, as published by the Free Software Foundation, and
> > + * may be copied, distributed, and modified under those terms.
> > + *
> > + * 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.
> > + *
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/input.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/kernel.h>
> > +#include <linux/of.h>
> > +#include <linux/of_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/mfd/mt6323/registers.h>
> > +#include <linux/mfd/mt6397/registers.h>
> > +#include <linux/mfd/mt6397/core.h>
> > +#include <linux/slab.h>
> > +#include <linux/irqdomain.h>
> 
> Not needed.

Sorry for that. All not needed parts will be removed.
> 
> > +
> > +#define PWRKEY_RST_EN_MASK	0x1
> > +#define PWRKEY_RST_EN_SHIFT	6
> > +#define HOMEKEY_RST_EN_MASK	0x1
> > +#define HOMEKEY_RST_EN_SHIFT	5
> > +#define RST_DU_MASK		0x3
> > +#define RST_DU_SHIFT		8
> > +
> > +struct pmic_keys_regs {
> > +	u32 deb_reg;
> > +	u32 deb_mask;
> > +	u32 intsel_reg;
> > +	u32 intsel_mask;
> > +};
> > +
> > +#define PMIC_KEYS_REGS(_deb_reg, _deb_mask, _intsel_reg, _intsel_mask)	\
> > +{									\
> > +	.deb_reg		= _deb_reg,				\
> > +	.deb_mask		= _deb_mask,				\
> > +	.intsel_reg		= _intsel_reg,				\
> > +	.intsel_mask		= _intsel_mask,				\
> > +}
> > +
> > +struct pmic_regs {
> > +	const struct pmic_keys_regs pwrkey_regs;
> > +	const struct pmic_keys_regs homekey_regs;
> > +	u32 pmic_rst_reg;
> > +};
> > +
> > +static const struct pmic_regs mt6397_regs = {
> > +	.pwrkey_regs = PMIC_KEYS_REGS(MT6397_CHRSTATUS,
> > +		0x8, MT6397_INT_RSV, 0x10),
> > +	.homekey_regs = PMIC_KEYS_REGS(MT6397_OCSTATUS2,
> > +		0x10, MT6397_INT_RSV, 0x8),
> > +	.pmic_rst_reg = MT6397_TOP_RST_MISC,
> > +};
> > +
> > +static const struct pmic_regs mt6323_regs = {
> > +	.pwrkey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
> > +		0x2, MT6323_INT_MISC_CON, 0x10),
> > +	.homekey_regs = PMIC_KEYS_REGS(MT6323_CHRSTATUS,
> > +		0x4, MT6323_INT_MISC_CON, 0x8),
> > +	.pmic_rst_reg = MT6323_TOP_RST_MISC,
> > +};
> > +
> > +struct pmic_keys_info {
> > +	struct mtk_pmic_keys *keys;
> > +	const struct pmic_keys_regs *regs;
> > +	int keycode;
> > +	int irq;
> > +};
> > +
> > +struct mtk_pmic_keys {
> > +	struct input_dev *input_dev;
> > +	struct device *dev;
> > +	struct regmap *regmap;
> > +	struct irq_domain *irq_domain;
> 
> Not needed.
> 
> > +	struct pmic_keys_info pwrkey, homekey;
> > +};
> > +
> > +enum long_press_mode {
> > +	LP_DISABLE,
> > +	LP_ONEKEY,
> > +	LP_TWOKEY,
> > +};
> > +
> > +static void long_press_reset_setup(struct mtk_pmic_keys *keys, u32 pmic_rst_reg)
> > +{
> > +	int ret;
> > +	u32 long_press_mode, long_press_duration;
> > +
> > +	ret = of_property_read_u32(keys->dev->of_node,
> > +		"mediatek,long-press-duration", &long_press_duration);
> > +	if (ret)
> > +		long_press_duration = 0;
> > +
> > +	regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +			   RST_DU_MASK << RST_DU_SHIFT,
> > +			   long_press_duration << RST_DU_SHIFT);
> > +
> > +	ret = of_property_read_u32(keys->dev->of_node,
> > +		"mediatek,long-press-mode", &long_press_mode);
> > +	if (ret)
> > +		long_press_mode = LP_DISABLE;
> > +
> > +	switch (long_press_mode) {
> > +	case LP_ONEKEY:
> > +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
> > +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT);
> > +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
> > +				   0);
> > +		break;
> > +	case LP_TWOKEY:
> > +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
> > +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT);
> > +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
> > +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT);
> > +		break;
> > +	case LP_DISABLE:
> > +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +				   PWRKEY_RST_EN_MASK << PWRKEY_RST_EN_SHIFT,
> > +				   0);
> > +		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > +				   HOMEKEY_RST_EN_MASK << HOMEKEY_RST_EN_SHIFT,
> > +				   0);
> > +		break;
> > +	default:
> > +		break;
> > +	}
> > +}
> > +
> > +static irqreturn_t mtk_pmic_keys_irq_handler_thread(int irq, void *data)
> > +{
> > +	struct pmic_keys_info *info = data;
> > +	u32 key_deb, pressed;
> > +
> > +	regmap_read(info->keys->regmap, info->regs->deb_reg, &key_deb);
> > +
> > +	key_deb &= info->regs->deb_mask;
> > +
> > +	pressed = !key_deb;
> > +
> > +	input_report_key(info->keys->input_dev, info->keycode, pressed);
> > +	input_sync(info->keys->input_dev);
> > +
> > +	dev_dbg(info->keys->dev, "[PMICKEYS] (%s) key =%d using PMIC\n",
> > +		 pressed ? "pressed" : "released", info->keycode);
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> > +static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys,
> > +		const char *propname, struct pmic_keys_info *info, bool wakeup)
> > +{
> > +	int ret;
> > +
> > +	ret = of_property_read_u32(keys->dev->of_node,
> > +		propname, &info->keycode);
> > +	if (ret)
> > +		return 0;
> > +
> > +	if (!info->keycode)
> > +		return 0;
> > +
> > +	info->keys = keys;
> > +
> > +	ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg,
> > +				 info->regs->intsel_mask,
> > +				 info->regs->intsel_mask);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	ret = devm_request_threaded_irq(keys->dev, info->irq, NULL,
> > +					mtk_pmic_keys_irq_handler_thread,
> > +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > +					"mtk-pmic-keys", info);
> > +	if (ret) {
> > +		dev_err(keys->dev, "Failed to request IRQ: %d: %d\n",
> > +			info->irq, ret);
> > +		return ret;
> > +	}
> > +
> > +	if (wakeup)
> > +		irq_set_irq_wake(info->irq, 1);
> > +
> > +	input_set_capability(keys->input_dev, EV_KEY, info->keycode);
> > +
> > +	return 0;
> > +}
> > +
> > +static void mtk_pmic_keys_dispose_irq(struct mtk_pmic_keys *keys)
> > +{
> > +	if (keys->pwrkey.irq)
> > +		irq_dispose_mapping(keys->pwrkey.irq);
> > +
> > +	if (keys->homekey.irq)
> > +		irq_dispose_mapping(keys->homekey.irq);
> 
> You did not create the mapping, you should not destroy it.

OK.

> 
> > +}
> > +
> > +static const struct of_device_id of_pmic_keys_match_tbl[] = {
> > +	{
> > +		.compatible = "mediatek,mt6397-keys",
> > +		.data = &mt6397_regs,
> > +	}, {
> > +		.compatible = "mediatek,mt6323-keys",
> > +		.data = &mt6323_regs,
> > +	}, {
> > +		/* sentinel */
> > +	}
> > +};
> > +MODULE_DEVICE_TABLE(of, of_pmic_keys_match_tbl);
> > +
> > +static int mtk_pmic_keys_probe(struct platform_device *pdev)
> > +{
> > +	int ret;
> > +	struct resource *res_pwrkey, *res_homekey;
> > +	struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent);
> > +	struct mtk_pmic_keys *keys;
> > +	const struct pmic_regs *pmic_regs;
> > +	struct input_dev *input_dev;
> > +	const struct of_device_id *of_id =
> > +		of_match_device(of_pmic_keys_match_tbl, &pdev->dev);
> > +
> > +	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
> > +	if (!keys)
> > +		return -ENOMEM;
> > +
> > +	keys->dev = &pdev->dev;
> > +	keys->regmap = pmic_chip->regmap;
> > +	keys->irq_domain = pmic_chip->irq_domain;
> 
> Not needed.
> 
> > +
> > +	pmic_regs = of_id->data;
> > +	keys->pwrkey.regs = &pmic_regs->pwrkey_regs;
> > +	keys->homekey.regs = &pmic_regs->homekey_regs;
> > +
> > +	res_pwrkey = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > +	if (!res_pwrkey) {
> > +		dev_err(&pdev->dev, "no IRQ resource\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	keys->pwrkey.irq = res_pwrkey->start;
> > +	if (keys->pwrkey.irq <= 0)
> > +		return -EINVAL;
> 
> Please do
> 
> 	keys->pwrkey.irq = platform_get_irq(pdev, 0);
> 	if (keys->pwrkey.irq < 0)
> 		return keys->pwrkey.irq;
> 

OK, I'll do this way.Thank you.

> > +
> > +	res_homekey = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
> > +	if (!res_homekey) {
> > +		dev_err(&pdev->dev, "no IRQ resource\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	keys->homekey.irq = res_homekey->start;
> > +	if (keys->homekey.irq <= 0)
> > +		return -EINVAL;
> 
> Same as above.
> 
> > +
> > +	keys->input_dev = input_dev = devm_input_allocate_device(keys->dev);
> > +	if (!input_dev) {
> > +		dev_err(&pdev->dev, "[PMICKEYS] input allocate device fail.\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	input_dev->name = "mtk-pmic-keys";
> > +	input_dev->id.bustype = BUS_HOST;
> > +	input_dev->id.vendor = 0x0001;
> > +	input_dev->id.product = 0x0001;
> > +	input_dev->id.version = 0x0001;
> > +	input_dev->dev.parent = &pdev->dev;
> 
> Not needed, devm_input_allocate_device() already does this. 
> 
> > +
> > +	ret = mtk_pmic_key_setup(keys, "mediatek,pwrkey-code",
> > +				 &keys->pwrkey, true);
> > +	if (ret)
> > +		goto out_dispose_irq;
> 
> Can you please call this variable "error" and do
> 
> 	if (error)
> 		return error;
> 

OK, I'll change that naming.

> You are using devm and no longer creating mappings, so you can return
> directly and rely on devm infrastructure to unwind.
> 
> > +
> > +	ret = mtk_pmic_key_setup(keys, "mediatek,homekey-code",
> > +				 &keys->homekey, false);
> > +	if (ret)
> > +		goto out_dispose_irq;
> > +
> > +	ret = input_register_device(input_dev);
> > +	if (ret) {
> > +		dev_err(&pdev->dev,
> > +			"[PMICKEYS] register input device failed (%d)\n", ret);
> 
> No need for [PMICKEYS] prefix, dev_err prints device and driver already.
> 
> > +		return ret;
> > +	}
> > +
> > +	long_press_reset_setup(keys, pmic_regs->pmic_rst_reg);
> > +
> > +	return 0;
> > +
> > +out_dispose_irq:
> > +	mtk_pmic_keys_dispose_irq(keys);
> > +	return ret;
> > +}
> > +
> > +static int mtk_pmic_keys_remove(struct platform_device *pdev)
> > +{
> > +	struct mtk_pmic_keys *keys = platform_get_drvdata(pdev);
> > +
> > +	mtk_pmic_keys_dispose_irq(keys);
> 
> Not needed. The whole function is not needed.
> 
> > +
> > +	return 0;
> > +}
> > +
> > +static struct platform_driver pmic_keys_pdrv = {
> > +	.probe = mtk_pmic_keys_probe,
> > +	.remove = mtk_pmic_keys_remove,
> > +	.driver = {
> > +		   .name = "mtk-pmic-keys",
> > +		   .of_match_table = of_pmic_keys_match_tbl,
> > +	},
> > +};
> > +
> > +module_platform_driver(pmic_keys_pdrv);
> > +
> > +MODULE_LICENSE("GPL v2");
> > +MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>");
> > +MODULE_DESCRIPTION("MTK pmic-keys driver v0.1");
> > -- 
> > 1.7.9.5
> > 
> 
> Thanks.
> 

^ permalink raw reply

* Re: [PATCH v2 1/5] mfd: mt6397: create irq mappings in mfd core driver
From: Lee Jones @ 2017-08-08 11:14 UTC (permalink / raw)
  To: Chen Zhong
  Cc: Dmitry Torokhov, Rob Herring, Mark Rutland, Matthias Brugger,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-2-git-send-email-chen.zhong@mediatek.com>

On Mon, 07 Aug 2017, Chen Zhong wrote:

> The core driver should create and manage irq mappings instead of
> leaf drivers. This patch change to pass irq domain to
> devm_mfd_add_devices() and it will create mapping for irq resources
> automatically. And remove irq mapping in rtc driver since this has
> been done in core driver.
> 
> Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
> ---
>  drivers/mfd/mt6397-core.c |    4 ++--
>  drivers/rtc/rtc-mt6397.c  |    2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)

Once you've fixed Dmitry's comment:

For my own reference:
  Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply

* Re: [PATCH v2 5/5] mfd: mt6397: Add PMIC keys support to MT6397 driver
From: Lee Jones @ 2017-08-08 11:15 UTC (permalink / raw)
  To: Chen Zhong
  Cc: Dmitry Torokhov, Rob Herring, Mark Rutland, Matthias Brugger,
	Eddie Huang, Alessandro Zummo, Alexandre Belloni, Jaechul Lee,
	Jonathan Cameron, Javier Martinez Canillas, Linus Walleij,
	Beomho Seo, linux-input, devicetree, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-rtc
In-Reply-To: <1502071065-6745-6-git-send-email-chen.zhong@mediatek.com>

On Mon, 07 Aug 2017, Chen Zhong wrote:

> This patch adds compatible strings and interrupts for pmic keys
> which serves as child device of MFD.
> 
> Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
> ---
>  drivers/mfd/mt6397-core.c |   36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> index 6546d7f..3c6a765 100644
> --- a/drivers/mfd/mt6397-core.c
> +++ b/drivers/mfd/mt6397-core.c
> @@ -43,6 +43,30 @@
>  	},
>  };
>  
> +static const struct resource mt6323_keys_resources[] = {
> +	{
> +		.start = MT6323_IRQ_STATUS_PWRKEY,
> +		.end   = MT6323_IRQ_STATUS_PWRKEY,
> +		.flags = IORESOURCE_IRQ,
> +	}, {
> +		.start = MT6323_IRQ_STATUS_FCHRKEY,
> +		.end   = MT6323_IRQ_STATUS_FCHRKEY,
> +		.flags = IORESOURCE_IRQ,
> +	},
> +};
> +
> +static const struct resource mt6397_keys_resources[] = {
> +	{
> +		.start = MT6397_IRQ_PWRKEY,
> +		.end   = MT6397_IRQ_PWRKEY,
> +		.flags = IORESOURCE_IRQ,
> +	}, {
> +		.start = MT6397_IRQ_HOMEKEY,
> +		.end   = MT6397_IRQ_HOMEKEY,
> +		.flags = IORESOURCE_IRQ,
> +	},
> +};

We have better ways to define these now.

Please grep for "DEFINE_RES_"

>  static const struct mfd_cell mt6323_devs[] = {
>  	{
>  		.name = "mt6323-regulator",
> @@ -50,6 +74,11 @@
>  	}, {
>  		.name = "mt6323-led",
>  		.of_compatible = "mediatek,mt6323-led"
> +	}, {
> +		.name = "mtk-pmic-keys",
> +		.num_resources = ARRAY_SIZE(mt6323_keys_resources),
> +		.resources = mt6323_keys_resources,
> +		.of_compatible = "mediatek,mt6323-keys"
>  	},
>  };
>  
> @@ -71,7 +100,12 @@
>  	}, {
>  		.name = "mt6397-pinctrl",
>  		.of_compatible = "mediatek,mt6397-pinctrl",
> -	},
> +	}, {
> +		.name = "mtk-pmic-keys",
> +		.num_resources = ARRAY_SIZE(mt6397_keys_resources),
> +		.resources = mt6397_keys_resources,
> +		.of_compatible = "mediatek,mt6397-keys"
> +	}
>  };
>  
>  static void mt6397_irq_lock(struct irq_data *data)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply

* [PATCH] rtc: at91rm9200: fix error return code in at91_rtc_probe()
From: Gustavo A. R. Silva @ 2017-08-09 15:52 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: linux-rtc, linux-kernel, Gustavo A. R. Silva

platform_get_irq() returns an error code, but the at91rm9200 driver
ignores it and always returns -ENXIO. This is not correct and,
prevents -EPROBE_DEFER from being propagated properly.

Print and propagate the return value of platform_get_irq on failure.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/rtc/rtc-at91rm9200.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index e221b78..09bc2e0 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -398,8 +398,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
-		dev_err(&pdev->dev, "no irq resource defined\n");
-		return -ENXIO;
+		dev_err(&pdev->dev, "no irq resource defined: %d\n", irq);
+		return irq;
 	}
 
 	at91_rtc_regs = devm_ioremap(&pdev->dev, regs->start,
-- 
2.5.0

^ permalink raw reply related

* [rtc-linux] Add me to your contacts
From: Current Bench @ 2017-08-09 16:24 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 720 bytes --]

Hi,

please add me to your contacts and share me your all requirements and HOT
list.

Thanks

*Pradeep*

SUMMITWORKS TECHNOLOGIES INC.

P: 908-922-4225 <(908)%20922-4225>

E: Pradeep.kumar@summitworks.com

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 1663 bytes --]

^ permalink raw reply

* [rtc-linux] Add me to your contact..
From: Current Bench @ 2017-08-09 16:28 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

Please add me ( Pradeep.kumar@summitworks.com ) to your contact and share
me your requirements and hot list on daily basis

Thanks

*-*

*Pradeep*

SUMMITWORKS TECHNOLOGIES INC.

P: 908-922-4225 <(908)%20922-4225>

E: Pradeep.kumar@summitworks.com

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 2258 bytes --]

^ permalink raw reply

* [rtc-linux] Job offer for JBPM Consultant at Dallas, TX
From: Chaitanya Puvvada @ 2017-08-09 21:49 UTC (permalink / raw)
  To: Chaitanya Puvvada

[-- Attachment #1: Type: text/plain, Size: 2474 bytes --]

Hi,

Hope you are doing great,
My Self,* Chaitanya* from R2 Technologies. We have a requirement for "*JBPM
Consultant *“at *Dallas, TX*. Please review the Job description below and
if you’d like to pursue this, please include a word copy of your latest
resume along with a daytime phone number and rate in your response. You can
also reach me at *470-242-7345 Ex-304*, Drop the suitable profiles on
*chaitu@r2techcorp.com
<chaitu@r2techcorp.com>*.



*Position: JBPM Consultant *

*Location: Dallas, TX*

*Contract: Long Term*



* Must have*



   - 8+ years in IT sector
   - 3+ years’ experience with jBPM
   - Implementing Business Processes on jBPM and designing integrated
   solution using jBPM as a middleware.
   - Experience defining & modeling BPMN 2.0 based Business processes on
   jBPM platform
   - Familiar with the forms design & development that's offered in the
   jBPM product.
   - Java based web-services & service tasks and batch oriented automation.
   - Experience working with Rule engines like Drools/JBoss BRMS
   - Java/J2EE Client/Server architecture and development  (Java, JBoss,
   Teiid)
   - Experience on Web Services Development including (REST/SOAP, WSDL/XML,
   and JSON)



*Nice to have:*

   - Experience in the MEAN stack, JavaScript, CSS, Bootstrap, JQuery  etc.
   is definitely a plus
   - Exposure to Continuous Integration, using tools like GIT (or
   equivalent Version Control System) and Jenkins (or equivalent) for change,
   Release & deployment of software packages on a distributed SOA environment
   is a strong plus
   - Understanding of Agile design, development and delivery concepts



Thanks,

*Chaitanya*

*Technical Recruiter*

Desk:*470-242-7345 Ex-304*

*Chaitu@r2techcorp.com <Chaitu@r2techcorp.com>*

Office: 248-522-7855 |Fax: (248) 479-5559
*R2 Technologies*

6515 Shiloh Rd, Unit 110, Alpharetta,GA 30005

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 13532 bytes --]

^ permalink raw reply

* Re: [PATCH v3 2/8] MIPS: ranchu: Add Goldfish RTC driver
From: Alexandre Belloni @ 2017-08-10 20:34 UTC (permalink / raw)
  To: Aleksandar Markovic
  Cc: linux-mips, Miodrag Dinic, Goran Ferenc, Aleksandar Markovic,
	Alessandro Zummo, Bo Hu, David S. Miller, Douglas Leung,
	Greg Kroah-Hartman, James Hogan, Jin Qian, linux-kernel,
	linux-rtc, Mauro Carvalho Chehab, Paul Burton, Petar Jovanovic,
	Raghu Gandham
In-Reply-To: <1500656111-9520-3-git-send-email-aleksandar.markovic@rt-rk.com>

Hi,

On 21/07/2017 at 18:53:31 +0200, Aleksandar Markovic wrote:
> From: Miodrag Dinic <miodrag.dinic@imgtec.com>
> 
> Add device driver for a virtual Goldfish RTC clock.
> 
> The driver can be built only if CONFIG_MIPS and CONFIG_GOLDFISH are
> set. The compatible string used by OS for binding the driver is
> defined as "google,goldfish-rtc".
> 
> Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
> Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
> ---
>  MAINTAINERS                |   1 +
>  drivers/rtc/Kconfig        |   8 ++
>  drivers/rtc/Makefile       |   1 +
>  drivers/rtc/rtc-goldfish.c | 233 +++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 243 insertions(+)
>  create mode 100644 drivers/rtc/rtc-goldfish.c
> 

Do you mind fixing the remaining checkpatch --strict issues, the two
kbuild errors and the warning reported by Julia?

Thanks!


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox