Skip to contentSkip to conversation

pinctrl: rockchip: add rk3188 support

PATCH Superseded Heiko Stübner 2 participants 9 messages Oct 15, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Heiko Stübner

author maintainer
#0 lore raw

cover pinctrl: rockchip: add rk3188 support

A patch series, finalizing support for the pin controller in the rk3188.

As mentioned in the individual patches, the rk3188 makes it even more complex due to its strange pull setting configuration. Therefore a bit of reordering needed to take place to accomodate this.

Heiko Stuebner (6):
pinctrl: rockchip: separate different sub-types more
of: add function to check against a list of compatible strings
pinctrl: rockchip: add support for multiple bank types
pinctrl: rockchip: remove redundant check
pinctrl: rockchip: add rk3188 specifics
pinctrl: rockchip: emulate both edge triggered interrupts

 .../bindings/pinctrl/rockchip,pinctrl.txt          |   46 +++-
 drivers/of/base.c                                  |   21 ++
 drivers/pinctrl/pinctrl-rockchip.c                 |  290 +++++++++++++++-----
 include/linux/of.h                                 |    2 +
 4 files changed, 295 insertions(+), 64 deletions(-)
Signature · 1 line
1.7.10.4
author maintainer
#1 lore raw

PATCH 1/6 pinctrl: rockchip: separate different sub-types more

Further investigation of the different Rockchip SoCs showed that the differences especially in the pull settings are quite deep. As further patches will show, the register layout for the pulls of the rk3188 is quite strange. Also it is to assume, that later Rockchip SoCs may introduce even more quirks in this regard, making it hard to support all of those using the current generic pull_* variables.

Therefore move the driver to hold the type of controller in an enum and do the handling according to it in the necessary places. Also instead of calculating the register in the get and set pull functions move it to a type-specific callback.

---
 drivers/pinctrl/pinctrl-rockchip.c |  105 +++++++++++++++++++-----------------
 1 file changed, 57 insertions(+), 48 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +57 -48
index e0718b7..df155f9 100644
@@ -56,6 +56,12 @@
 #define GPIO_EXT_PORT		0x50
 #define GPIO_LS_SYNC		0x60
 
+enum rockchip_pinctrl_type {
+	RK2928,
+	RK3066B,
+	RK3188,
+};
+
 /**
  * @reg_base: register base of the gpio bank
  * @clk: clock of the gpio bank
@@ -98,18 +104,16 @@ struct rockchip_pin_bank {
 	}
 
 /**
- * @pull_auto: some SoCs don't allow pulls to be specified as up or down, but
- *	       instead decide this automatically based on the pad-type.
  */
 struct rockchip_pin_ctrl {
 	struct rockchip_pin_bank	*pin_banks;
 	u32				nr_banks;
 	u32				nr_pins;
 	char				*label;
+	enum rockchip_pinctrl_type	type;
 	int				mux_offset;
-	int				pull_offset;
-	bool				pull_auto;
-	int				pull_bank_stride;
+	void	(*pull_calc_reg)(struct rockchip_pin_bank *bank, int pin_num,
+				 void __iomem **reg, u8 *bit);
 };
 
 struct rockchip_pin_config {
@@ -354,6 +358,22 @@ static void rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
 	spin_unlock_irqrestore(&bank->slock, flags);
 }
 
+#define RK2928_PULL_OFFSET		0x118
+#define RK2928_PULL_PINS_PER_REG	16
+#define RK2928_PULL_BANK_STRIDE		8
+
+static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
+				    int pin_num, void __iomem **reg, u8 *bit)
+{
+	struct rockchip_pinctrl *info = bank->drvdata;
+
+	*reg = info->reg_base + RK2928_PULL_OFFSET;
+	*reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
+	*reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
+
+	*bit = pin_num % RK2928_PULL_PINS_PER_REG;
+};
+
 static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
 {
 	struct rockchip_pinctrl *info = bank->drvdata;
@@ -362,23 +382,22 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
 	u8 bit;
 
 	/* rk3066b does support any pulls */
-	if (!ctrl->pull_offset)
+	if (ctrl->type == RK3066B)
 		return PIN_CONFIG_BIAS_DISABLE;
 
-	reg = info->reg_base + ctrl->pull_offset;
-
-	if (ctrl->pull_auto) {
-		reg += bank->bank_num * ctrl->pull_bank_stride;
-		reg += (pin_num / 16) * 4;
-		bit = pin_num % 16;
-
+	switch (ctrl->type) {
+	case RK2928:
+		ctrl->pull_calc_reg(bank, pin_num, &reg, &bit);
 		return !(readl_relaxed(reg) & BIT(bit))
 				? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
 				: PIN_CONFIG_BIAS_DISABLE;
-	} else {
+	case RK3188:
 		dev_err(info->dev, "pull support for rk31xx not implemented\n");
 		return -EIO;
-	}
+	default:
+		dev_err(info->dev, "unsupported pinctrl type\n");
+		return -EINVAL;
+	};
 }
 
 static int rockchip_set_pull(struct rockchip_pin_bank *bank,
@@ -395,21 +414,18 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,
 		 bank->bank_num, pin_num, pull);
 
 	/* rk3066b does support any pulls */
-	if (!ctrl->pull_offset)
+	if (ctrl->type == RK3066B)
 		return pull ? -EINVAL : 0;
 
-	reg = info->reg_base + ctrl->pull_offset;
-
-	if (ctrl->pull_auto) {
+	switch (ctrl->type) {
+	case RK2928:
 		if (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT &&
 					pull != PIN_CONFIG_BIAS_DISABLE) {
 			dev_err(info->dev, "only PIN_DEFAULT and DISABLE allowed\n");
 			return -EINVAL;
 		}
 
-		reg += bank->bank_num * ctrl->pull_bank_stride;
-		reg += (pin_num / 16) * 4;
-		bit = pin_num % 16;
+		ctrl->pull_calc_reg(bank, pin_num, &reg, &bit);
 
 		spin_lock_irqsave(&bank->slock, flags);
 
@@ -419,14 +435,13 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,
 		writel(data, reg);
 
 		spin_unlock_irqrestore(&bank->slock, flags);
-	} else {
-		if (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT) {
-			dev_err(info->dev, "pull direction (up/down) needs to be specified\n");
-			return -EINVAL;
-		}
-
+		break;
+	case RK3188:
 		dev_err(info->dev, "pull support for rk31xx not implemented\n");
 		return -EIO;
+	default:
+		dev_err(info->dev, "unsupported pinctrl type\n");
+		return -EINVAL;
 	}
 
 	return 0;
@@ -556,20 +571,17 @@ static const struct pinmux_ops rockchip_pmx_ops = {
 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
 					enum pin_config_param pull)
 {
-	/* rk3066b does support any pulls */
-	if (!ctrl->pull_offset)
+	switch (ctrl->type) {
+	case RK2928:
+		return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
+					pull == PIN_CONFIG_BIAS_DISABLE);
+	case RK3066B:
 		return pull ? false : true;
-
-	if (ctrl->pull_auto) {
-		if (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT &&
-					pull != PIN_CONFIG_BIAS_DISABLE)
-			return false;
-	} else {
-		if (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT)
-			return false;
+	case RK3188:
+		return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
 	}
 
-	return true;
+	return false;
 }
 
 /* set the pin config settings for a specified pin */
@@ -1315,10 +1327,9 @@ static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
 		.pin_banks		= rk2928_pin_banks,
 		.nr_banks		= ARRAY_SIZE(rk2928_pin_banks),
 		.label			= "RK2928-GPIO",
+		.type			= RK2928,
 		.mux_offset		= 0xa8,
-		.pull_offset		= 0x118,
-		.pull_auto		= 1,
-		.pull_bank_stride	= 8,
+		.pull_calc_reg		= rk2928_calc_pull_reg_and_bit,
 };
 
 static struct rockchip_pin_bank rk3066a_pin_banks[] = {
@@ -1334,10 +1345,9 @@ static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
 		.pin_banks		= rk3066a_pin_banks,
 		.nr_banks		= ARRAY_SIZE(rk3066a_pin_banks),
 		.label			= "RK3066a-GPIO",
+		.type			= RK2928,
 		.mux_offset		= 0xa8,
-		.pull_offset		= 0x118,
-		.pull_auto		= 1,
-		.pull_bank_stride	= 8,
+		.pull_calc_reg		= rk2928_calc_pull_reg_and_bit,
 };
 
 static struct rockchip_pin_bank rk3066b_pin_banks[] = {
@@ -1351,8 +1361,8 @@ static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
 		.pin_banks	= rk3066b_pin_banks,
 		.nr_banks	= ARRAY_SIZE(rk3066b_pin_banks),
 		.label		= "RK3066b-GPIO",
+		.type		= RK3066B,
 		.mux_offset	= 0x60,
-		.pull_offset	= -EINVAL,
 };
 
 static struct rockchip_pin_bank rk3188_pin_banks[] = {
@@ -1366,9 +1376,8 @@ static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
 		.pin_banks		= rk3188_pin_banks,
 		.nr_banks		= ARRAY_SIZE(rk3188_pin_banks),
 		.label			= "RK3188-GPIO",
+		.type			= RK3188,
 		.mux_offset		= 0x68,
-		.pull_offset		= 0x164,
-		.pull_bank_stride	= 16,
 };
 
 static const struct of_device_id rockchip_pinctrl_dt_match[] = {
Signature · 1 line
1.7.10.4
author maintainer
#2 lore raw

PATCH 2/6 of: add function to check against a list of compatible strings

In reply to Heiko Stübner

The basic of functions already provide a of_device_is_compatible to check if a device's compatible property contains a specific one. But sometimes it's also necessary to check if the device is compatible to one out of a list of compatible devices.

Therefore add of_device_is_any_of that reuses the compatible check of of_device_is_compatible but checks against a list of compatible strings without the locking overhead of calling of_device_is_compatible multiple times.

---
 drivers/of/base.c  |   21 +++++++++++++++++++++
 include/linux/of.h |    2 ++
 2 files changed, 23 insertions(+)
drivers/of/base.c +21 -0
index 865d3f6..589f43e 100644
@@ -366,6 +366,27 @@ int of_device_is_compatible(const struct device_node *device,
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
+ * Checks if any of the given "compat" strings matches one of the strings
+ * in the device's "compatible" property.
+ */
+int of_device_is_any_of(const struct device_node *device,
+			const char * const *compat, int num) {
+	unsigned long flags;
+	int res = 0, i;
+
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	for (i = 0; i < num; i++) {
+		if (__of_device_is_compatible(device, compat[i])) {
+			res = 1;
+			break;
+		}
+	}
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	return res;
+}
+EXPORT_SYMBOL(of_device_is_any_of);
+
+/**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
  * @compat: compatible string to look for in root node's compatible property.
  *
include/linux/of.h +2 -0
index f95aee3..5bf7c9a 100644
@@ -262,6 +262,8 @@ extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 extern int of_device_is_compatible(const struct device_node *device,
 				   const char *);
+extern int of_device_is_any_of(const struct device_node *device,
+			       const char * const *compat, int num);
 extern int of_device_is_available(const struct device_node *device);
 extern const void *of_get_property(const struct device_node *node,
 				const char *name,
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/6 of: add function to check against a list of compatible strings

Hi Heiko,

Quoted 9 lines · Heiko St?bner

The basic of functions already provide a of_device_is_compatible to check if a device's compatible property contains a specific one. But sometimes it's also necessary to check if the device is compatible to one out of a list of compatible devices.

Therefore add of_device_is_any_of that reuses the compatible check of of_device_is_compatible but checks against a list of compatible strings without the locking overhead of calling of_device_is_compatible multiple times.

I don't think we need this -- we already have of_match_node, and you can use it to achieve the same result.

Thanks,
Mark.

Quoted 60 lines
---
 drivers/of/base.c  |   21 +++++++++++++++++++++
 include/linux/of.h |    2 ++
 2 files changed, 23 insertions(+)
drivers/of/base.c +21 -0
index 865d3f6..589f43e 100644
@@ -366,6 +366,27 @@ int of_device_is_compatible(const struct device_node *device,
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
+ * Checks if any of the given "compat" strings matches one of the strings
+ * in the device's "compatible" property.
+ */
+int of_device_is_any_of(const struct device_node *device,
+			const char * const *compat, int num) {
+	unsigned long flags;
+	int res = 0, i;
+
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	for (i = 0; i < num; i++) {
+		if (__of_device_is_compatible(device, compat[i])) {
+			res = 1;
+			break;
+		}
+	}
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	return res;
+}
+EXPORT_SYMBOL(of_device_is_any_of);
+
+/**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
  * @compat: compatible string to look for in root node's compatible property.
  *
include/linux/of.h +2 -0
index f95aee3..5bf7c9a 100644
@@ -262,6 +262,8 @@ extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 extern int of_device_is_compatible(const struct device_node *device,
 				   const char *);
+extern int of_device_is_any_of(const struct device_node *device,
+			       const char * const *compat, int num);
 extern int of_device_is_available(const struct device_node *device);
 extern const void *of_get_property(const struct device_node *node,
 				const char *name,
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#4 lore raw

PATCH 2/6 of: add function to check against a list of compatible strings

Am Dienstag, 15. Oktober 2013, 13:11:46 schrieb Mark Rutland:

Quoted 8 lines

Hi Heiko,

Quoted 5 lines · Heiko St?bner

The basic of functions already provide a of_device_is_compatible to check if a device's compatible property contains a specific one. But sometimes it's also necessary to check if the device is compatible to one out of a list of compatible devices.

Quoted 7 lines
Quoted 4 lines

Therefore add of_device_is_any_of that reuses the compatible check of of_device_is_compatible but checks against a list of compatible strings without the locking overhead of calling of_device_is_compatible multiple times.

I don't think we need this -- we already have of_match_node, and you can use it to achieve the same result.

You are right of course, of_match_node does exactly what needed.

Thanks
Heiko

Quoted 64 lines
Quoted 64 lines

---

 drivers/of/base.c  |   21 +++++++++++++++++++++
 include/linux/of.h |    2 ++
 2 files changed, 23 insertions(+)
drivers/of/base.c +1 -0
index 865d3f6..589f43e 100644
@@ -366,6 +366,27 @@ int of_device_is_compatible(const struct device_node
 *device,
 
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
 
+ * Checks if any of the given "compat" strings matches one of the

strings + * in the device's "compatible" property.
+ */

drivers/of/base.c +18 -0
+int of_device_is_any_of(const struct device_node *device,
+			const char * const *compat, int num) {
+	unsigned long flags;
+	int res = 0, i;
+
+	raw_spin_lock_irqsave(&devtree_lock, flags);
+	for (i = 0; i < num; i++) {
+		if (__of_device_is_compatible(device, compat[i])) {
+			res = 1;
+			break;
+		}
+	}
+	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	return res;
+}
+EXPORT_SYMBOL(of_device_is_any_of);
+
+/**
 
  * of_machine_is_compatible - Test root of device tree for a given
  compatible value * @compat: compatible string to look for in root
  node's compatible property. *
include/linux/of.h +2 -0
index f95aee3..5bf7c9a 100644
@@ -262,6 +262,8 @@ extern int of_property_count_strings(struct
 device_node *np,
 
 				     const char *propname);
 
 extern int of_device_is_compatible(const struct device_node *device,
 
 				   const char *);
 
+extern int of_device_is_any_of(const struct device_node *device,
+			       const char * const *compat, int num);
 
 extern int of_device_is_available(const struct device_node *device);
 extern const void *of_get_property(const struct device_node *node,
 
 				const char *name,
author maintainer
#5 lore raw

PATCH 3/6 pinctrl: rockchip: add support for multiple bank types

In reply to Heiko Stübner

There are Rockchip SoCs, namely the rk3188, that combine a set of regular banks with banks that need special handling for some settings.

Therefore add the possibility for the driver to handle more than one bank type.

---
 drivers/pinctrl/pinctrl-rockchip.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +14 -3
index df155f9..bfa3abe 100644
@@ -62,6 +62,10 @@ enum rockchip_pinctrl_type {
 	RK3188,
 };
 
+enum rockchip_pin_bank_type {
+	COMMON_BANK,
+};
+
 /**
  * @reg_base: register base of the gpio bank
  * @clk: clock of the gpio bank
@@ -86,6 +90,7 @@ struct rockchip_pin_bank {
 	u8				nr_pins;
 	char				*name;
 	u8				bank_num;
+	enum rockchip_pin_bank_type	bank_type;
 	bool				valid;
 	struct device_node		*of_node;
 	struct rockchip_pinctrl		*drvdata;
@@ -668,7 +673,9 @@ static const struct pinconf_ops rockchip_pinconf_ops = {
 	.pin_config_set			= rockchip_pinconf_set,
 };
 
-static const char *gpio_compat = "rockchip,gpio-bank";
+static const char * const gpio_compat[] = {
+	"rockchip,gpio-bank",
+};
 
 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
 						struct device_node *np)
@@ -676,7 +683,8 @@ static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
 	struct device_node *child;
 
 	for_each_child_of_node(np, child) {
-		if (of_device_is_compatible(child, gpio_compat))
+		if (of_device_is_any_of(child, gpio_compat,
+					ARRAY_SIZE(gpio_compat)))
 			continue;
 
 		info->nfunctions++;
@@ -819,7 +827,8 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
 	i = 0;
 
 	for_each_child_of_node(np, child) {
-		if (of_device_is_compatible(child, gpio_compat))
+		if (of_device_is_any_of(child, gpio_compat,
+					ARRAY_SIZE(gpio_compat)))
 			continue;
 		ret = rockchip_pinctrl_parse_functions(child, info, i++);
 		if (ret) {
@@ -1217,6 +1226,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
 	if (IS_ERR(bank->reg_base))
 		return PTR_ERR(bank->reg_base);
 
+	bank->bank_type = COMMON_BANK;
+
 	bank->irq = irq_of_parse_and_map(bank->of_node, 0);
 
 	bank->clk = of_clk_get(bank->of_node, 0);
Signature · 1 line
1.7.10.4
author maintainer
#6 lore raw

PATCH 4/6 pinctrl: rockchip: remove redundant check

In reply to Heiko Stübner

The check limiting bias options to supported ones is already done thru rockchip_pinconf_pull_valid. Therefore this check is redundant and can be removed.

---
 drivers/pinctrl/pinctrl-rockchip.c |    6 ------
 1 file changed, 6 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +0 -6
index bfa3abe..c5bbd24 100644
@@ -424,12 +424,6 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,
 
 	switch (ctrl->type) {
 	case RK2928:
-		if (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT &&
-					pull != PIN_CONFIG_BIAS_DISABLE) {
-			dev_err(info->dev, "only PIN_DEFAULT and DISABLE allowed\n");
-			return -EINVAL;
-		}
-
 		ctrl->pull_calc_reg(bank, pin_num, &reg, &bit);
 
 		spin_lock_irqsave(&bank->slock, flags);
Signature · 1 line
1.7.10.4
author maintainer
#7 lore raw

PATCH 5/6 pinctrl: rockchip: add rk3188 specifics

In reply to Heiko Stübner

Besides the pull registers sitting in a separate place, the rk3188 also has the peculiarity that the pull registers of the first bank are split and the first half is sitting in the register space of the pmu.

Therefore this adds a special bank-type for the first bank, to handle the two register sources.

---
 .../bindings/pinctrl/rockchip,pinctrl.txt          |   46 +++++++-
 drivers/pinctrl/pinctrl-rockchip.c                 |  117 ++++++++++++++++++--
 2 files changed, 155 insertions(+), 8 deletions(-)
Documentation/devicetree/bindings/pinctrl/rockchip,pinctrl.txt +45 -1
index b0fb101..f378d34 100644
@@ -21,10 +21,13 @@ defined as gpio sub-nodes of the pinmux controller.
 Required properties for iomux controller:
   - compatible: one of "rockchip,rk2928-pinctrl", "rockchip,rk3066a-pinctrl"
 		       "rockchip,rk3066b-pinctrl", "rockchip,rk3188-pinctrl"
+  - reg: first element is the general register space of the iomux controller
+	 second element is the separate pull register space of the rk3188
 
 Required properties for gpio sub nodes:
-  - compatible: "rockchip,gpio-bank"
+  - compatible: "rockchip,gpio-bank", "rockchip,rk3188-gpio-bank0"
   - reg: register of the gpio bank (different than the iomux registerset)
+         second element: separate pull register for rk3188 bank0
   - interrupts: base interrupt of the gpio bank in the interrupt controller
   - clocks: clock that drives this bank
   - gpio-controller: identifies the node as a gpio controller and pin bank.
@@ -95,3 +98,44 @@ uart2: serial at 20064000 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart2_xfer>;
 };
+
+Example for rk3188:
+
+	pinctrl at 20008000 {
+		compatible = "rockchip,rk3188-pinctrl";
+		reg = <0x20008000 0xa0>,
+		      <0x20008164 0x1a0>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		gpio0: gpio0 at 0x2000a000 {
+			compatible = "rockchip,rk3188-gpio-bank0";
+			reg = <0x2000a000 0x100>,
+			      <0x20004064 0x8>;
+			interrupts = <GIC_SPI 54 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk_gates8 9>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
+
+		gpio1: gpio1 at 0x2003c000 {
+			compatible = "rockchip,gpio-bank";
+			reg = <0x2003c000 0x100>;
+			interrupts = <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk_gates8 10>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
+
+		...
+
+	};
drivers/pinctrl/pinctrl-rockchip.c +112 -7

214 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author maintainer
#8 lore raw

PATCH 6/6 pinctrl: rockchip: emulate both edge triggered interrupts

In reply to Heiko Stübner

The gpio interrupt controller on Rockchip socs can do edge triggers only for single edges but not both. Nevertheless a lot of gpio users rely on the availability of both-edge triggered interrupts - i.e. gpio-keys.

Therefore implement a solution similar to pinctrl-coh901 re-setting the triggering edge depending on the gpio value in the interrupt demuxer.

---
 drivers/pinctrl/pinctrl-rockchip.c |   61 +++++++++++++++++++++++++++++++-----
 1 file changed, 54 insertions(+), 7 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +54 -7
index 4db286c..e8988a1 100644
@@ -101,7 +101,7 @@ struct rockchip_pin_bank {
 	struct gpio_chip		gpio_chip;
 	struct pinctrl_gpio_range	grange;
 	spinlock_t			slock;
-
+	u32				toggle_edge_mode;
 };
 
 #define PIN_BANK(id, pins, label)			\
@@ -1076,7 +1076,9 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc)
 {
 	struct irq_chip *chip = irq_get_chip(irq);
 	struct rockchip_pin_bank *bank = irq_get_handler_data(irq);
+	u32 polarity = 0, data = 0;
 	u32 pend;
+	bool edge_changed = false;
 
 	dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name);
 
@@ -1084,6 +1086,12 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc)
 
 	pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS);
 
+	if (bank->toggle_edge_mode) {
+		polarity = readl_relaxed(bank->reg_base +
+					 GPIO_INT_POLARITY);
+		data = readl_relaxed(bank->reg_base + GPIO_EXT_PORT);
+	}
+
 	while (pend) {
 		unsigned int virq;
 
@@ -1098,9 +1106,30 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc)
 
 		dev_dbg(bank->drvdata->dev, "handling irq %d\n", irq);
 
+		/*
+		 * Triggering IRQ on both rising and falling edge
+		 * needs manual intervention.
+		 */
+		if (bank->toggle_edge_mode & BIT(irq)) {
+			if (data & BIT(irq))
+				polarity &= ~BIT(irq);
+			else
+				polarity |= BIT(irq);
+
+			edge_changed = true;
+		}
+
 		generic_handle_irq(virq);
 	}
 
+	if (bank->toggle_edge_mode && edge_changed) {
+		/* Interrupt params should only be set with ints disabled */
+		data = readl_relaxed(bank->reg_base + GPIO_INTEN);
+		writel_relaxed(0, bank->reg_base + GPIO_INTEN);
+		writel(polarity, bank->reg_base + GPIO_INT_POLARITY);
+		writel(data, bank->reg_base + GPIO_INTEN);
+	}
+
 	chained_irq_exit(chip, desc);
 }
 
@@ -1113,6 +1142,12 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
 	u32 level;
 	u32 data;
 
+	/* make sure the pin is configured as gpio input */
+	rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
+	data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
+	data &= ~mask;
+	writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
+
 	if (type & IRQ_TYPE_EDGE_BOTH)
 		__irq_set_handler_locked(d->irq, handle_edge_irq);
 	else
@@ -1124,19 +1159,37 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
 	polarity = readl_relaxed(gc->reg_base + GPIO_INT_POLARITY);
 
 	switch (type) {
+	case IRQ_TYPE_EDGE_BOTH:
+		bank->toggle_edge_mode |= mask;
+		level |= mask;
+
+		/*
+		 * Determine gpio state. If 1 next interrupt should be falling
+		 * otherwise rising.
+		 */
+		data = readl(bank->reg_base + GPIO_EXT_PORT);
+		if (data & mask)
+			polarity &= ~mask;
+		else
+			polarity |= mask;
+		break;
 	case IRQ_TYPE_EDGE_RISING:
+		bank->toggle_edge_mode &= ~mask;
 		level |= mask;
 		polarity |= mask;
 		break;
 	case IRQ_TYPE_EDGE_FALLING:
+		bank->toggle_edge_mode &= ~mask;
 		level |= mask;
 		polarity &= ~mask;
 		break;
 	case IRQ_TYPE_LEVEL_HIGH:
+		bank->toggle_edge_mode &= ~mask;
 		level &= ~mask;
 		polarity |= mask;
 		break;
 	case IRQ_TYPE_LEVEL_LOW:
+		bank->toggle_edge_mode &= ~mask;
 		level &= ~mask;
 		polarity &= ~mask;
 		break;
@@ -1150,12 +1203,6 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
 
 	irq_gc_unlock(gc);
 
-	/* make sure the pin is configured as gpio input */
-	rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
-	data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
-	data &= ~mask;
-	writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
-
 	return 0;
 }
 
Signature · 1 line
1.7.10.4