Skip to contentSkip to conversation

dm: gpio: Add driver for MPC85xx GPIO controller

PATCH Superseded Mario Six 3 participants 7 messages May 13, 2016 – May 19, 2016

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Mario Six

author
#0 lore raw

v3 cover dm: gpio: Add driver for MPC85xx GPIO controller

The functions for accessing GPIOs on MPC85xx are hardcoded in arch/powerpc/include/asm/mpc85xx_gpio.h This leads to problems if another GPIO controller supporting the driver model is to be used simultaneously.

Therefore, this patch moves the "static" functions into a DM-compatible driver, and also introduces a set of functions into the GPIO uclass that expose the controller's capability to switch individual GPIOs into open-drain-mode.

v3 also implements shadowing of the GPDAT register to work around a known issue in some MPC85xx GPIO controllers (as pointed out by Joakim Tjernlund).

mario.six at gdsys.cc (3):
dm: gpio: Add driver for MPC85XX GPIO controller
dm: gpio: Add methods for open drain setting
dm: gpio: Implement open drain for MPC85XX GPIO

 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |   2 +
 arch/powerpc/include/asm/immap_85xx.h        |   2 +
 drivers/gpio/Kconfig                         |  25 ++++
 drivers/gpio/Makefile                        |   1 +
 drivers/gpio/gpio-uclass.c                   |  32 +++++
 drivers/gpio/mpc85xx_gpio.c                  | 206 +++++++++++++++++++++++++++
 include/asm-generic/gpio.h                   |  34 +++++
 7 files changed, 302 insertions(+)
 create mode 100644 drivers/gpio/mpc85xx_gpio.c

--
2.7.0.GIT

author
#1 lore raw

PATCH v3 1/3 dm: gpio: Add driver for MPC85XX GPIO controller

From: "[email protected]" <[email protected]>

This patch adds a driver for the built-in GPIO controller of the MPC85XX SoC (probably supporting other PowerQUICC III SoCs as well).

Each GPIO bank is identified by its own entry in the device tree, i.e.

gpio-controller at fc00 {
      #gpio-cells = <2>;
      compatible = "fsl,pq3-gpio";
      reg = <0xfc00 0x100>
}

By default, each bank is assumed to have 32 GPIOs, but the ngpios setting is honored, so the number of GPIOs for each bank in configurable to match the actual GPIO count of the SoC (e.g. the 32/32/23 banks of the P1022 SoC).

The usual functions of GPIO drivers (setting input/output mode and output value setting) are supported.

The driver has been tested on MPC85XX, but it is likely that other PowerQUICC III devices will work as well.

---

v3:
- Added shadow for the GPDAT register, as suggested by Joakim Tjernlund
- Switched to u32 for bit masks
- Added some comments

v2:
- Added missing commit message
- Improved the Kconfig description
- Fixed and documented the mpc85xx_gpio_data members
- Introduced GPIO_MASK macro to simplify the code
- Fixed white space issues in function headers
- Removed unnecessary empty line
- Use fdtdec_get_addr_size_auto_noparent to read the register base data

---
 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |   2 +
 arch/powerpc/include/asm/immap_85xx.h        |   2 +
 drivers/gpio/Kconfig                         |  25 ++++
 drivers/gpio/Makefile                        |   1 +
 drivers/gpio/mpc85xx_gpio.c                  | 187 +++++++++++++++++++++++++++
 5 files changed, 217 insertions(+)
 create mode 100644 drivers/gpio/mpc85xx_gpio.c
arch/powerpc/include/asm/arch-mpc85xx/gpio.h +2 -0
index da7352a..41b6677 100644
@@ -14,6 +14,8 @@
 #ifndef __ASM_ARCH_MX85XX_GPIO_H
 #define __ASM_ARCH_MX85XX_GPIO_H
 
+#ifndef CONFIG_MPC85XX_GPIO
 #include <asm/mpc85xx_gpio.h>
+#endif
 
 #endif
arch/powerpc/include/asm/immap_85xx.h +2 -0
index 53ca6d9..dcc50b2 100644
@@ -265,6 +265,7 @@ typedef struct ccsr_pcix {
 #define PIWAR_WRITE_SNOOP	0x00005000
 #define PIWAR_MEM_2G		0x0000001e
 
+#ifndef CONFIG_MPC85XX_GPIO
 typedef struct ccsr_gpio {
 	u32	gpdir;
 	u32	gpodr;
@@ -273,6 +274,7 @@ typedef struct ccsr_gpio {
 	u32	gpimr;
 	u32	gpicr;
 } ccsr_gpio_t;
+#endif
 
 /* L2 Cache Registers */
 typedef struct ccsr_l2cache {
drivers/gpio/Kconfig +25 -0
index 2b4624d..068ee63 100644
@@ -143,4 +143,29 @@ config ZYNQ_GPIO
 	help
 	  Supports GPIO access on Zynq SoC.
 
+config MPC85XX_GPIO
+	bool "Freescale MPC85XX GPIO driver"
+	depends on DM_GPIO
+	help
+	  This driver supports the built-in GPIO controller of MPC85XX CPUs.
+	  Each GPIO bank is identified by its own entry in the device tree,
+	  i.e.
+
+	  gpio-controller at fc00 {
+		#gpio-cells = <2>;
+		compatible = "fsl,pq3-gpio";
+		reg = <0xfc00 0x100>
+	  }
+
+	  By default, each bank is assumed to have 32 GPIOs, but the ngpios
+	  setting is honored, so the number of GPIOs for each bank is
+	  configurable to match the actual GPIO count of the SoC (e.g. the
+	  32/32/23 banks of the P1022 SoC).
+
+	  The standard functions of input/output mode, and output value setting
+	  are supported; the open-drain capability of the controller is not
+	  supported yet.
+
+	  The driver has been tested on MPC85XX, but it is likely that other
+	  PowerQUICC III devices will work as well.
 endmenu
drivers/gpio/Makefile +1 -0
index 4f071c4..1e4f16b 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_DA8XX_GPIO)	+= da8xx_gpio.o
 obj-$(CONFIG_DM644X_GPIO)	+= da8xx_gpio.o
 obj-$(CONFIG_ALTERA_PIO)	+= altera_pio.o
 obj-$(CONFIG_MPC83XX_GPIO)	+= mpc83xx_gpio.o
+obj-$(CONFIG_MPC85XX_GPIO)	+= mpc85xx_gpio.o
 obj-$(CONFIG_SH_GPIO_PFC)	+= sh_pfc.o
 obj-$(CONFIG_OMAP_GPIO)	+= omap_gpio.o
 obj-$(CONFIG_DB8500_GPIO)	+= db8500_gpio.o
drivers/gpio/mpc85xx_gpio.c new file +187 -0

187 lines not on this page · raw message

--
2.7.0.GIT

#2 lore raw

PATCH v3 1/3 dm: gpio: Add driver for MPC85XX GPIO controller

Quoted 41 lines · Mario Six

From: "mario.six at gdsys.cc" <[email protected]>

This patch adds a driver for the built-in GPIO controller of the MPC85XX SoC (probably supporting other PowerQUICC III SoCs as well).

Each GPIO bank is identified by its own entry in the device tree, i.e.

gpio-controller at fc00 {
      #gpio-cells = <2>;
      compatible = "fsl,pq3-gpio";
      reg = <0xfc00 0x100>
}

By default, each bank is assumed to have 32 GPIOs, but the ngpios setting is honored, so the number of GPIOs for each bank in configurable to match the actual GPIO count of the SoC (e.g. the 32/32/23 banks of the P1022 SoC).

The usual functions of GPIO drivers (setting input/output mode and output value setting) are supported.

The driver has been tested on MPC85XX, but it is likely that other PowerQUICC III devices will work as well.

---

v3:
- Added shadow for the GPDAT register, as suggested by Joakim Tjernlund
- Switched to u32 for bit masks
- Added some comments

v2:
- Added missing commit message
- Improved the Kconfig description
- Fixed and documented the mpc85xx_gpio_data members
- Introduced GPIO_MASK macro to simplify the code
- Fixed white space issues in function headers
- Removed unnecessary empty line
- Use fdtdec_get_addr_size_auto_noparent to read the register base data

Quoted 8 lines
---
 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |   2 +
 arch/powerpc/include/asm/immap_85xx.h        |   2 +
 drivers/gpio/Kconfig                         |  25 ++++
 drivers/gpio/Makefile                        |   1 +
 drivers/gpio/mpc85xx_gpio.c                  | 187 +++++++++++++++++++++++++++
 5 files changed, 217 insertions(+)
 create mode 100644 drivers/gpio/mpc85xx_gpio.c
author
#3 lore raw

PATCH v3 2/3 dm: gpio: Add methods for open drain setting

In reply to Mario Six

From: "[email protected]" <[email protected]>

Certain GPIO devices have the capability to switch their GPIOs into open-drain mode, that is, instead of actively driving the output (Push-pull output), the pin is connected to the collector (for a NPN transistor) or the drain (for a MOSFET) of a transistor, respectively. The pin then either forms an open circuit or a connection to ground, depending on the state of the transistor.

This patch adds functions to the GPIO uclass to switch GPIOs to open-drain mode on devices that support it.

---

v2:
- Added missing commit message
- Fixed error return value of dm_gpio_get_open_drain
- Fixed return value passing in dm_gpio_set_open_drain and added comment
- Added description of open-drain mode

---
 drivers/gpio/gpio-uclass.c | 32 ++++++++++++++++++++++++++++++++
 include/asm-generic/gpio.h | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
drivers/gpio/gpio-uclass.c +32 -0
index b58d4e6..1be9988 100644
@@ -352,6 +352,38 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
 	return 0;
 }
 
+int dm_gpio_get_open_drain(struct gpio_desc *desc)
+{
+	struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
+	int ret;
+
+	ret = check_reserved(desc, "get_open_drain");
+	if (ret)
+		return ret;
+
+	if (ops->set_open_drain)
+		return ops->get_open_drain(desc->dev, desc->offset);
+	else
+		return -ENOSYS;
+}
+
+int dm_gpio_set_open_drain(struct gpio_desc *desc, int value)
+{
+	struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
+	int ret;
+
+	ret = check_reserved(desc, "set_open_drain");
+	if (ret)
+		return ret;
+
+	if (ops->set_open_drain)
+		ret = ops->set_open_drain(desc->dev, desc->offset, value);
+	else
+		return 0; /* feature not supported -> ignore setting */
+
+	return ret;
+}
+
 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
 	struct udevice *dev = desc->dev;
include/asm-generic/gpio.h +34 -0
index 68b5f0b..ece7552 100644
@@ -241,6 +241,8 @@ struct dm_gpio_ops {
 				int value);
 	int (*get_value)(struct udevice *dev, unsigned offset);
 	int (*set_value)(struct udevice *dev, unsigned offset, int value);
+	int (*get_open_drain)(struct udevice *dev, unsigned offset);
+	int (*set_open_drain)(struct udevice *dev, unsigned offset, int value);
 	/**
 	 * get_function() Get the GPIO function
 	 *
@@ -541,6 +543,38 @@ int dm_gpio_get_value(const struct gpio_desc *desc);
 int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 
 /**
+ * dm_gpio_get_open_drain() - Check if open-drain-mode of a GPIO is active
+ *
+ * This checks if open-drain-mode for a GPIO is enabled or not. This method is
+ * optional.
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @return Value of open drain mode for GPIO (0 for inactive, 1 for active) or
+ *	   -ve on error
+ */
+int dm_gpio_get_open_drain(struct gpio_desc *desc);
+
+/**
+ * dm_gpio_set_open_drain() - Switch open-drain-mode of a GPIO on or off
+ *
+ * This enables or disables open-drain mode for a GPIO. This method is
+ * optional; if the driver does not support it, nothing happens when the method
+ * is called.
+ *
+ * In open-drain mode, instead of actively driving the output (Push-pull
+ * output), the GPIO's pin is connected to the collector (for a NPN transistor)
+ * or the drain (for a MOSFET) of a transistor, respectively. The pin then
+ * either forms an open circuit or a connection to ground, depending on the
+ * state of the transistor.
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @return 0 if OK, -ve on error
+ */
+int dm_gpio_set_open_drain(struct gpio_desc *desc, int value);
+
+/**
  * dm_gpio_set_dir() - Set the direction for a GPIO
  *
  * This sets up the direction according tot the provided flags. It will do

--
2.7.0.GIT

author
#4 lore raw

PATCH v3 3/3 dm: gpio: Implement open drain for MPC85XX GPIO

In reply to Mario Six

From: "[email protected]" <[email protected]>

This patch implements the open-drain setting feature for the MPC85XX GPIO controller.

---

v3:
- Added comments

v2:
- Added missing commit message
- Fixed white space issues in function headers

---
 drivers/gpio/Kconfig        |  6 +++---
 drivers/gpio/mpc85xx_gpio.c | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
drivers/gpio/Kconfig +3 -3
index 068ee63..b250622 100644
@@ -162,9 +162,9 @@ config MPC85XX_GPIO
 	  configurable to match the actual GPIO count of the SoC (e.g. the
 	  32/32/23 banks of the P1022 SoC).
 
-	  The standard functions of input/output mode, and output value setting
-	  are supported; the open-drain capability of the controller is not
-	  supported yet.
+	  Aside from the standard functions of input/output mode, and output
+	  value setting, the open-drain feature, which can configure individual
+	  GPIOs to work as open-drain outputs, is supported.
 
 	  The driver has been tested on MPC85XX, but it is likely that other
 	  PowerQUICC III devices will work as well.
drivers/gpio/mpc85xx_gpio.c +19 -0
index 17755df..1c1f6f3 100644
@@ -73,6 +73,25 @@ static inline void mpc85xx_gpio_set_high(struct ccsr_gpio *base, u32 gpios)
 	setbits_be32(&base->gpdir, gpios);
 }
 
+static inline int mpc85xx_gpio_open_drain_val(struct ccsr_gpio *base, u32 mask)
+{
+	return in_be32(&base->gpodr) & mask;
+}
+
+static inline void mpc85xx_gpio_open_drain_on(struct ccsr_gpio *base, u32
+					      gpios)
+{
+	/* GPODR register 1 -> open drain on */
+	setbits_be32(&base->gpodr, gpios);
+}
+
+static inline void mpc85xx_gpio_open_drain_off(struct ccsr_gpio *base,
+					       u32 gpios)
+{
+	/* GPODR register 0 -> open drain off (actively driven) */
+	clrbits_be32(&base->gpodr, gpios);
+}
+
 static int mpc85xx_gpio_direction_input(struct udevice *dev, unsigned gpio)
 {
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);

--
2.7.0.GIT

#5 lore raw

v3 cover dm: gpio: Add driver for MPC85xx GPIO controller

In reply to Mario Six
Quoted 11 lines · Mario Six

The functions for accessing GPIOs on MPC85xx are hardcoded in arch/powerpc/include/asm/mpc85xx_gpio.h This leads to problems if another GPIO controller supporting the driver model is to be used simultaneously.

Therefore, this patch moves the "static" functions into a DM-compatible driver, and also introduces a set of functions into the GPIO uclass that expose the controller's capability to switch individual GPIOs into open-drain-mode.

v3 also implements shadowing of the GPDAT register to work around a known issue in some MPC85xx GPIO controllers (as pointed out by Joakim Tjernlund). ?

Nice, thanks.

Do you have any plans to do mpc83xx also? It needs the same gpdat shadow.

? Jocke

author
#6 lore raw

v3 cover dm: gpio: Add driver for MPC85xx GPIO controller

Quoted 9 lines · Joakim Tjernlund
Quoted 8 lines · Mario Six

The functions for accessing GPIOs on MPC85xx are hardcoded in arch/powerpc/include/asm/mpc85xx_gpio.h This leads to problems if another GPIO controller supporting the driver model is to be used simultaneously.

Therefore, this patch moves the "static" functions into a DM-compatible driver, and also introduces a set of functions into the GPIO uclass that expose the controller's capability to switch individual GPIOs into open-drain-mode.

Quoted 7 lines
Quoted 3 lines

v3 also implements shadowing of the GPDAT register to work around a known issue in some MPC85xx GPIO controllers (as pointed out by Joakim Tjernlund).

Nice, thanks.

Do you have any plans to do mpc83xx also? It needs the same gpdat shadow.

Good to know, thanks.

Possibly, we have boards using MPC8308 SoCs, and they also have to be converted to DM in due time. If it comes to that, I might go the same route the kernel did and do a generic mpc8xxx driver (and port over the special cases from the kernel driver).

Best regards,
Mario