[PATCH v9 08/12] pinctrl: Add pinctrl driver for the RK805 PMIC

2017-08-09 Thread Joseph Chen
RK805 is one of Rockchip PMICs family, it has 2 output only GPIOs.

This driver is also designed for other Rockchip PMICs to expend.
Different PMIC maybe have different pin features, for example,
RK816 has one pin which can be used for TS or GPIO(input/out).
The mainly difference between PMICs pins are pinmux, direction
and output value, that is 'struct rk805_pin_config'.

Signed-off-by: Joseph Chen 
Acked-by: Linus Walleij 
---
 drivers/pinctrl/Kconfig |   9 +
 drivers/pinctrl/Makefile|   1 +
 drivers/pinctrl/pinctrl-rk805.c | 493 
 3 files changed, 503 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-rk805.c

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index 8f8c2af..c33098f 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -285,6 +285,15 @@ config PINCTRL_ZYNQ
help
  This selects the pinctrl driver for Xilinx Zynq.
 
+config PINCTRL_RK805
+   tristate "Pinctrl and GPIO driver for RK805 PMIC"
+   depends on MFD_RK808
+   select GPIOLIB
+   select PINMUX
+   select GENERIC_PINCONF
+   help
+ This selects the pinctrl driver for RK805.
+
 source "drivers/pinctrl/aspeed/Kconfig"
 source "drivers/pinctrl/bcm/Kconfig"
 source "drivers/pinctrl/berlin/Kconfig"
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
index a251f43..7485af3 100644
--- a/drivers/pinctrl/Makefile
+++ b/drivers/pinctrl/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_PINCTRL_LPC18XX) += pinctrl-lpc18xx.o
 obj-$(CONFIG_PINCTRL_TB10X)+= pinctrl-tb10x.o
 obj-$(CONFIG_PINCTRL_ST)   += pinctrl-st.o
 obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o
+obj-$(CONFIG_PINCTRL_RK805)+= pinctrl-rk805.o
 
 obj-$(CONFIG_ARCH_ASPEED)  += aspeed/
 obj-y  += bcm/
diff --git a/drivers/pinctrl/pinctrl-rk805.c b/drivers/pinctrl/pinctrl-rk805.c
new file mode 100644
index 000..b0bfd30
--- /dev/null
+++ b/drivers/pinctrl/pinctrl-rk805.c
@@ -0,0 +1,493 @@
+/*
+ * Pinctrl driver for Rockchip RK805 PMIC
+ *
+ * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Joseph Chen 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under  the terms of the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Based on the pinctrl-as3722 driver
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+#include "pinconf.h"
+#include "pinctrl-utils.h"
+
+struct rk805_pin_function {
+   const char *name;
+   const char *const *groups;
+   unsigned int ngroups;
+   int mux_option;
+};
+
+struct rk805_pin_group {
+   const char *name;
+   const unsigned int pins[1];
+   unsigned int npins;
+};
+
+/*
+ * @reg: gpio setting register;
+ * @fun_mask: functions select mask value, when set is gpio;
+ * @dir_mask: input or output mask value, when set is output, otherwise input;
+ * @val_mask: gpio set value, when set is level high, otherwise low;
+ *
+ * Different PMIC has different pin features, belowing 3 mask members are not
+ * all necessary for every PMIC. For example, RK805 has 2 pins that can be used
+ * as output only GPIOs, so func_mask and dir_mask are not needed. RK816 has 1
+ * pin that can be used as TS/GPIO, so fun_mask, dir_mask and val_mask are all
+ * necessary.
+ */
+struct rk805_pin_config {
+   u8 reg;
+   u8 fun_msk;
+   u8 dir_msk;
+   u8 val_msk;
+};
+
+struct rk805_pctrl_info {
+   struct rk808 *rk808;
+   struct device *dev;
+   struct pinctrl_dev *pctl;
+   struct gpio_chip gpio_chip;
+   struct pinctrl_desc pinctrl_desc;
+   const struct rk805_pin_function *functions;
+   unsigned int num_functions;
+   const struct rk805_pin_group *groups;
+   int num_pin_groups;
+   const struct pinctrl_pin_desc *pins;
+   unsigned int num_pins;
+   struct rk805_pin_config *pin_cfg;
+};
+
+enum rk805_pinmux_option {
+   RK805_PINMUX_GPIO,
+};
+
+enum {
+   RK805_GPIO0,
+   RK805_GPIO1,
+};
+
+static const char *const rk805_gpio_groups[] = {
+   "gpio0",
+   "gpio1",
+};
+
+/* RK805: 2 output only GPIOs */
+static const struct pinctrl_pin_desc rk805_pins_desc[] = {
+   PINCTRL_PIN(RK805_GPIO0, "gpio0"),
+   PINCTRL_PIN(RK805_GPIO1, "gpio1"),
+};
+
+static const struct rk805_pin_function rk805_pin_functions[] = {
+   {
+   .name = "gpio",
+   .groups = rk805_gpio_groups,
+   .ngroups = ARRAY_SIZE(rk805_gpio_groups),
+   .mux_option = RK805_PINMUX_GPIO,
+   },
+};
+
+static const struct rk805_pin_group rk805_pin_groups[] = {
+   {
+ 

[PATCH v9 08/12] pinctrl: Add pinctrl driver for the RK805 PMIC

2017-08-09 Thread Joseph Chen
RK805 is one of Rockchip PMICs family, it has 2 output only GPIOs.

This driver is also designed for other Rockchip PMICs to expend.
Different PMIC maybe have different pin features, for example,
RK816 has one pin which can be used for TS or GPIO(input/out).
The mainly difference between PMICs pins are pinmux, direction
and output value, that is 'struct rk805_pin_config'.

Signed-off-by: Joseph Chen 
Acked-by: Linus Walleij 
---
 drivers/pinctrl/Kconfig |   9 +
 drivers/pinctrl/Makefile|   1 +
 drivers/pinctrl/pinctrl-rk805.c | 493 
 3 files changed, 503 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-rk805.c

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index 8f8c2af..c33098f 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -285,6 +285,15 @@ config PINCTRL_ZYNQ
help
  This selects the pinctrl driver for Xilinx Zynq.
 
+config PINCTRL_RK805
+   tristate "Pinctrl and GPIO driver for RK805 PMIC"
+   depends on MFD_RK808
+   select GPIOLIB
+   select PINMUX
+   select GENERIC_PINCONF
+   help
+ This selects the pinctrl driver for RK805.
+
 source "drivers/pinctrl/aspeed/Kconfig"
 source "drivers/pinctrl/bcm/Kconfig"
 source "drivers/pinctrl/berlin/Kconfig"
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
index a251f43..7485af3 100644
--- a/drivers/pinctrl/Makefile
+++ b/drivers/pinctrl/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_PINCTRL_LPC18XX) += pinctrl-lpc18xx.o
 obj-$(CONFIG_PINCTRL_TB10X)+= pinctrl-tb10x.o
 obj-$(CONFIG_PINCTRL_ST)   += pinctrl-st.o
 obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o
+obj-$(CONFIG_PINCTRL_RK805)+= pinctrl-rk805.o
 
 obj-$(CONFIG_ARCH_ASPEED)  += aspeed/
 obj-y  += bcm/
diff --git a/drivers/pinctrl/pinctrl-rk805.c b/drivers/pinctrl/pinctrl-rk805.c
new file mode 100644
index 000..b0bfd30
--- /dev/null
+++ b/drivers/pinctrl/pinctrl-rk805.c
@@ -0,0 +1,493 @@
+/*
+ * Pinctrl driver for Rockchip RK805 PMIC
+ *
+ * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Joseph Chen 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under  the terms of the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Based on the pinctrl-as3722 driver
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+#include "pinconf.h"
+#include "pinctrl-utils.h"
+
+struct rk805_pin_function {
+   const char *name;
+   const char *const *groups;
+   unsigned int ngroups;
+   int mux_option;
+};
+
+struct rk805_pin_group {
+   const char *name;
+   const unsigned int pins[1];
+   unsigned int npins;
+};
+
+/*
+ * @reg: gpio setting register;
+ * @fun_mask: functions select mask value, when set is gpio;
+ * @dir_mask: input or output mask value, when set is output, otherwise input;
+ * @val_mask: gpio set value, when set is level high, otherwise low;
+ *
+ * Different PMIC has different pin features, belowing 3 mask members are not
+ * all necessary for every PMIC. For example, RK805 has 2 pins that can be used
+ * as output only GPIOs, so func_mask and dir_mask are not needed. RK816 has 1
+ * pin that can be used as TS/GPIO, so fun_mask, dir_mask and val_mask are all
+ * necessary.
+ */
+struct rk805_pin_config {
+   u8 reg;
+   u8 fun_msk;
+   u8 dir_msk;
+   u8 val_msk;
+};
+
+struct rk805_pctrl_info {
+   struct rk808 *rk808;
+   struct device *dev;
+   struct pinctrl_dev *pctl;
+   struct gpio_chip gpio_chip;
+   struct pinctrl_desc pinctrl_desc;
+   const struct rk805_pin_function *functions;
+   unsigned int num_functions;
+   const struct rk805_pin_group *groups;
+   int num_pin_groups;
+   const struct pinctrl_pin_desc *pins;
+   unsigned int num_pins;
+   struct rk805_pin_config *pin_cfg;
+};
+
+enum rk805_pinmux_option {
+   RK805_PINMUX_GPIO,
+};
+
+enum {
+   RK805_GPIO0,
+   RK805_GPIO1,
+};
+
+static const char *const rk805_gpio_groups[] = {
+   "gpio0",
+   "gpio1",
+};
+
+/* RK805: 2 output only GPIOs */
+static const struct pinctrl_pin_desc rk805_pins_desc[] = {
+   PINCTRL_PIN(RK805_GPIO0, "gpio0"),
+   PINCTRL_PIN(RK805_GPIO1, "gpio1"),
+};
+
+static const struct rk805_pin_function rk805_pin_functions[] = {
+   {
+   .name = "gpio",
+   .groups = rk805_gpio_groups,
+   .ngroups = ARRAY_SIZE(rk805_gpio_groups),
+   .mux_option = RK805_PINMUX_GPIO,
+   },
+};
+
+static const struct rk805_pin_group rk805_pin_groups[] = {
+   {
+   .name = "gpio0",
+   .pins = { RK805_GPIO0 },
+