Skip to contentSkip to conversation

pinctrl-baytrail: add function mux checking in gpio pin request

PATCH In review Chew Chiau Ee 5 participants 5 messages Mar 6, 2014 – Mar 11, 2014 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl-baytrail: add function mux checking in gpio pin request

From: Chew, Kean Ho <[email protected]>

The requested gpio pin must has the func_pin_mux field set to GPIO function by BIOS/FW in advanced. Else, the gpio pin request would fail. This is to ensure that we do not expose any gpio pins which shall be used for alternate functions, for eg: wakeup pin, I/O interfaces for LPSS, etc.

---
 drivers/pinctrl/pinctrl-baytrail.c |   42 +++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-baytrail.c +39 -3
index 665b96b..bf2b3f6 100644
@@ -60,6 +60,10 @@
 #define BYT_NGPIO_NCORE		28
 #define BYT_NGPIO_SUS		44
 
+#define BYT_SCORE_ACPI_UID	"1"
+#define BYT_NCORE_ACPI_UID	"2"
+#define BYT_SUS_ACPI_UID	"3"
+
 /*
  * Baytrail gpio controller consist of three separate sub-controllers called
  * SCORE, NCORE and SUS. The sub-controllers are identified by their acpi UID.
@@ -102,17 +106,17 @@ static unsigned const sus_pins[BYT_NGPIO_SUS] = {
 
 static struct pinctrl_gpio_range byt_ranges[] = {
 	{
-		.name = "1", /* match with acpi _UID in probe */
+		.name = BYT_SCORE_ACPI_UID, /* match with acpi _UID in probe */
 		.npins = BYT_NGPIO_SCORE,
 		.pins = score_pins,
 	},
 	{
-		.name = "2",
+		.name = BYT_NCORE_ACPI_UID,
 		.npins = BYT_NGPIO_NCORE,
 		.pins = ncore_pins,
 	},
 	{
-		.name = "3",
+		.name = BYT_SUS_ACPI_UID,
 		.npins = BYT_NGPIO_SUS,
 		.pins = sus_pins,
 	},
@@ -145,9 +149,41 @@ static void __iomem *byt_gpio_reg(struct gpio_chip *chip, unsigned offset,
 	return vg->reg_base + reg_offset + reg;
 }
 
+static bool is_special_pin(struct byt_gpio *vg, unsigned offset)
+{
+	/* SCORE pin 92-93 */
+	if (!strcmp(vg->range->name, BYT_SCORE_ACPI_UID) &&
+		offset >= 92 && offset <= 93)
+		return true;
+
+	/* SUS pin 11-21 */
+	if (!strcmp(vg->range->name, BYT_SUS_ACPI_UID) &&
+		offset >= 11 && offset <= 21)
+		return true;
+
+	return false;
+}
+
 static int byt_gpio_request(struct gpio_chip *chip, unsigned offset)
 {
 	struct byt_gpio *vg = to_byt_gpio(chip);
+	void __iomem *reg = byt_gpio_reg(chip, offset, BYT_CONF0_REG);
+	u32 value;
+	bool special;
+
+	/*
+	 * In most cases, func pin mux 000 means GPIO function.
+	 * But, some pins may have func pin mux 001 represents
+	 * GPIO function. Only allow user to export pin with
+	 * func pin mux preset as GPIO function by BIOS/FW.
+	 */
+	value = readl(reg) & BYT_PIN_MUX;
+	special = is_special_pin(vg, offset);
+	if ((special && value != 1) || (!special && value)) {
+		dev_err(&vg->pdev->dev,
+			"pin %u cannot be used as GPIO.\n", offset);
+		return -EINVAL;
+	}
 
 	pm_runtime_get(&vg->pdev->dev);
 
Signature · 1 line
1.7.4.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Chew Chiau Ee

From: Chew, Kean Ho <[email protected]>

The requested gpio pin must has the func_pin_mux field set to GPIO function by BIOS/FW in advanced. Else, the gpio pin request would fail. This is to ensure that we do not expose any gpio pins which shall be used for alternate functions, for eg: wakeup pin, I/O interfaces for LPSS, etc.

Thanks for sending this out Chiau Ee,

Signature · 3 lines
Darren Hart
Yocto Project - Linux Kernel
Intel Open Source Technology Center
#2 lore raw
In reply to Chew Chiau Ee
Quoted 10 lines · Chew Chiau Ee

From: Chew, Kean Ho <[email protected]>

The requested gpio pin must has the func_pin_mux field set to GPIO function by BIOS/FW in advanced. Else, the gpio pin request would fail. This is to ensure that we do not expose any gpio pins which shall be used for alternate functions, for eg: wakeup pin, I/O interfaces for LPSS, etc.

Patch applied with Darren's ACK.

This confirms my suspicion that you will not be able to hide the pin control interface side of this hardware forever. ;-)

Mika/Mathias: any comments?

Yours,
Linus Walleij

#3 lore raw
Quoted 13 lines · Linus Walleij
Quoted 10 lines · Chew Chiau Ee

From: Chew, Kean Ho <[email protected]>

The requested gpio pin must has the func_pin_mux field set to GPIO function by BIOS/FW in advanced. Else, the gpio pin request would fail. This is to ensure that we do not expose any gpio pins which shall be used for alternate functions, for eg: wakeup pin, I/O interfaces for LPSS, etc.

Quoted 6 lines

Patch applied with Darren's ACK.

This confirms my suspicion that you will not be able to hide the pin control interface side of this hardware forever. ;-)

Mika/Mathias: any comments?

No comments, looks good to me :)

Acked-by
#4 lore raw
In reply to Linus Walleij
Quoted 10 lines · Linus Walleij
Quoted 8 lines · Chew Chiau Ee

From: Chew, Kean Ho <[email protected]>

The requested gpio pin must has the func_pin_mux field set to GPIO function by BIOS/FW in advanced. Else, the gpio pin request would fail. This is to ensure that we do not expose any gpio pins which shall be used for alternate functions, for eg: wakeup pin, I/O interfaces for LPSS, etc.

Quoted 7 lines
Quoted 2 lines

Patch applied with Darren's ACK.

This confirms my suspicion that you will not be able to hide the pin control interface side of this hardware forever. ;-)

Hate to admit it but so it seems :)

Quoted 2 lines

Mika/Mathias: any comments?

Patch looks fine

-Mathias