linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: bc2835: Add brcm,level property
@ 2018-02-22 17:44 Matheus Castello
  2018-02-23 14:54 ` Eric Anholt
                   ` (2 more replies)
  0 siblings, 3 replies; 49+ messages in thread
From: Matheus Castello @ 2018-02-22 17:44 UTC (permalink / raw)
  To: stefan.wahren; +Cc: eric, linus.walleij, linux-kernel, Matheus Castello

Property to set initial value of pin output buffer.

Signed-off-by: Matheus Castello <matheus@castello.eng.br>
---
 .../bindings/pinctrl/brcm,bcm2835-gpio.txt         |  5 +-
 drivers/pinctrl/bcm/pinctrl-bcm2835.c              | 90 +++++++++++++++++-----
 2 files changed, 75 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
index 2569866..6834f1d 100644
--- a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
+++ b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
@@ -54,8 +54,11 @@ Optional subnode-properties:
   0: none
   1: down
   2: up
+- brcm,level: Integer, representing the value of output buffer to apply to the pin(s):
+  0: low
+  1: high
 
-Each of brcm,function and brcm,pull may contain either a single value which
+Each of brcm,function, brcm,pull and brcm,level may contain either a single value which
 will be applied to all pins in brcm,pins, or 1 value for each entry in
 brcm,pins.
 
diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index 785c366..0ace548 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
@@ -73,6 +73,8 @@
 enum bcm2835_pinconf_param {
 	/* argument: bcm2835_pinconf_pull */
 	BCM2835_PINCONF_PARAM_PULL,
+	/* argument: bcm2835_pinconf_level */
+	BCM2835_PINCONF_PARAM_LEVEL,
 };
 
 #define BCM2835_PINCONF_PACK(_param_, _arg_) ((_param_) << 16 | (_arg_))
@@ -725,16 +727,42 @@ static int bcm2835_pctl_dt_node_to_map_pull(struct bcm2835_pinctrl *pc,
 	return 0;
 }
 
+static int bcm2835_pctl_dt_node_to_map_level(struct bcm2835_pinctrl *pc,
+		struct device_node *np, u32 pin, u32 level,
+		struct pinctrl_map **maps)
+{
+	struct pinctrl_map *map = *maps;
+	unsigned long *configs;
+
+	if (level > 2) {
+		dev_err(pc->dev, "%pOF: invalid brcm,level %d\n", np, level);
+		return -EINVAL;
+	}
+
+	configs = kzalloc(sizeof(*configs), GFP_KERNEL);
+	if (!configs)
+		return -ENOMEM;
+	configs[0] = BCM2835_PINCONF_PACK(BCM2835_PINCONF_PARAM_LEVEL, level);
+
+	map->type = PIN_MAP_TYPE_CONFIGS_PIN;
+	map->data.configs.group_or_pin = bcm2835_gpio_pins[pin].name;
+	map->data.configs.configs = configs;
+	map->data.configs.num_configs = 1;
+	(*maps)++;
+
+	return 0;
+}
+
 static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 		struct device_node *np,
 		struct pinctrl_map **map, unsigned *num_maps)
 {
 	struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
-	struct property *pins, *funcs, *pulls;
-	int num_pins, num_funcs, num_pulls, maps_per_pin;
+	struct property *pins, *funcs, *pulls, *levels;
+	int num_pins, num_funcs, num_pulls, num_levels, maps_per_pin;
 	struct pinctrl_map *maps, *cur_map;
 	int i, err;
-	u32 pin, func, pull;
+	u32 pin, func, pull, level;
 
 	pins = of_find_property(np, "brcm,pins", NULL);
 	if (!pins) {
@@ -744,6 +772,7 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 
 	funcs = of_find_property(np, "brcm,function", NULL);
 	pulls = of_find_property(np, "brcm,pull", NULL);
+	levels = of_find_property(np, "brcm,level", NULL);
 
 	if (!funcs && !pulls) {
 		dev_err(pc->dev,
@@ -755,6 +784,7 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 	num_pins = pins->length / 4;
 	num_funcs = funcs ? (funcs->length / 4) : 0;
 	num_pulls = pulls ? (pulls->length / 4) : 0;
+	num_levels = levels ? (levels->length / 4) : 0;
 
 	if (num_funcs > 1 && num_funcs != num_pins) {
 		dev_err(pc->dev,
@@ -770,11 +800,20 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 		return -EINVAL;
 	}
 
+	if (num_levels > 1 && num_levels != num_pins) {
+		dev_err(pc->dev,
+			"%pOF: brcm,level must have 1 or %d entries\n",
+			np, num_pins);
+		return -EINVAL;
+	}
+
 	maps_per_pin = 0;
 	if (num_funcs)
 		maps_per_pin++;
 	if (num_pulls)
 		maps_per_pin++;
+	if (num_levels)
+		maps_per_pin++;
 	cur_map = maps = kzalloc(num_pins * maps_per_pin * sizeof(*maps),
 				GFP_KERNEL);
 	if (!maps)
@@ -811,6 +850,17 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 			if (err)
 				goto out;
 		}
+		if (num_levels) {
+			err = of_property_read_u32_index(np, "brcm,level",
+					(num_levels > 1) ? i : 0, &level);
+			if (err)
+				goto out;
+
+			err = bcm2835_pctl_dt_node_to_map_level(pc, np, pin,
+							level, &cur_map);
+			if (err)
+				goto out;
+		}
 	}
 
 	*map = maps;
@@ -931,23 +981,25 @@ static int bcm2835_pinconf_set(struct pinctrl_dev *pctldev,
 		param = BCM2835_PINCONF_UNPACK_PARAM(configs[i]);
 		arg = BCM2835_PINCONF_UNPACK_ARG(configs[i]);
 
-		if (param != BCM2835_PINCONF_PARAM_PULL)
+		if (param == BCM2835_PINCONF_PARAM_PULL) {
+			off = GPIO_REG_OFFSET(pin);
+			bit = GPIO_REG_SHIFT(pin);
+
+			bcm2835_gpio_wr(pc, GPPUD, arg & 3);
+			/*
+			* Docs say to wait 150 cycles, but not of what. We assume a
+			* 1 MHz clock here, which is pretty slow...
+			*/
+			udelay(150);
+			bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit));
+			udelay(150);
+			bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0);
+		} else if (param == BCM2835_PINCONF_PARAM_LEVEL) {
+			/* write in register */
+			bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin);
+		} else {
 			return -EINVAL;
-
-		off = GPIO_REG_OFFSET(pin);
-		bit = GPIO_REG_SHIFT(pin);
-
-		bcm2835_gpio_wr(pc, GPPUD, arg & 3);
-		/*
-		 * BCM2835 datasheet say to wait 150 cycles, but not of what.
-		 * But the VideoCore firmware delay for this operation
-		 * based nearly on the same amount of VPU cycles and this clock
-		 * runs at 250 MHz.
-		 */
-		udelay(1);
-		bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit));
-		udelay(1);
-		bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0);
+		}
 	} /* for each config */
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2018-05-16 12:02 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22 17:44 [PATCH] pinctrl: bc2835: Add brcm,level property Matheus Castello
2018-02-23 14:54 ` Eric Anholt
2018-02-23 15:58   ` Matheus Castello
2018-03-02 10:14 ` Linus Walleij
2018-03-03 14:21 ` Stefan Wahren
2018-03-05  2:29   ` [PATCH v2 0/3] pinctrl: bcm2835: " Matheus Castello
2018-03-05  2:29     ` [PATCH v2 1/3] pinctrl: bcm2835: switch to GENERIC_PINCONF Matheus Castello
2018-03-07 11:51       ` Stefan Wahren
2018-03-05  2:29     ` [PATCH v2 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-03-05 23:21       ` Eric Anholt
2018-03-07  3:28         ` Matheus Castello
2018-03-05  2:29     ` [PATCH v2 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-03-07 11:58     ` [PATCH v2 0/3] pinctrl: bcm2835: Add brcm,level property Stefan Wahren
2018-03-08  0:12       ` Matheus Castello
2018-03-08  8:00         ` Stefan Wahren
2018-03-08 19:47           ` Matheus Castello
2018-03-09  4:16             ` [PATCH v3 " Matheus Castello
2018-03-09  4:16               ` [PATCH v3 1/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-03-09  4:16               ` [PATCH v3 2/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-03-09  4:16               ` [PATCH v3 3/3] pinctrl: bcm2835: Update docs about generic pinctrl bindings support Matheus Castello
2018-03-09 11:46                 ` Stefan Wahren
2018-03-09 17:13                   ` [PATCH v4 0/3] pinctrl: bcm2835: Add generic pinctrl support Matheus Castello
2018-03-09 17:13                     ` [PATCH v4 1/3] dt-bindings: pinctrl: bcm2835-gpio: " Matheus Castello
2018-03-18 12:48                       ` Rob Herring
2018-03-18 15:23                         ` Matheus Castello
2018-04-11  4:58                           ` [PATCH v5 0/3] pinctrl: bcm2835: " Matheus Castello
2018-04-11  4:58                             ` [PATCH v5 1/3] dt-bindings: pinctrl: bcm2835-gpio: " Matheus Castello
2018-04-11 16:02                               ` Eric Anholt
2018-04-16 15:06                               ` Rob Herring
2018-04-26 12:21                               ` Linus Walleij
2018-04-11  4:58                             ` [PATCH v5 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-04-21 10:30                               ` Stefan Wahren
2018-04-22 12:44                               ` Stefan Wahren
2018-04-26 12:24                               ` Linus Walleij
2018-04-11  4:58                             ` [PATCH v5 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-04-26 12:25                               ` Linus Walleij
2018-04-29 19:28                                 ` [PATCH v6 0/3] bcm2835: Add generic pinctrl support Matheus Castello
2018-04-29 19:28                                   ` [PATCH v6 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-04-29 19:28                                   ` [PATCH v6 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-05-01  0:42                                     ` [PATCH v7 0/3] bcm2835: Add generic pinctrl support Matheus Castello
2018-05-01  0:42                                       ` [PATCH v7 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-05-03 17:38                                         ` Stefan Wahren
2018-05-12  9:08                                           ` Stefan Wahren
2018-05-16 12:00                                         ` Linus Walleij
2018-05-01  0:42                                       ` [PATCH v7 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-05-16 12:02                                         ` Linus Walleij
2018-03-09 17:13                     ` [PATCH v4 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-03-12 18:03                       ` Eric Anholt
2018-03-09 17:14                     ` [PATCH v4 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).