From bddbdaf42a2fea3b662ce9d405050380a10af7d1 Mon Sep 17 00:00:00 2001 From: luowei Date: Fri, 18 Apr 2014 18:20:05 +0800 Subject: [PATCH] pinctrl:add gpio init support --- arch/arm/boot/dts/rk3288-tb.dts | 6 +++ drivers/pinctrl/pinctrl-rockchip.c | 72 +++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) mode change 100644 => 100755 arch/arm/boot/dts/rk3288-tb.dts diff --git a/arch/arm/boot/dts/rk3288-tb.dts b/arch/arm/boot/dts/rk3288-tb.dts old mode 100644 new mode 100755 index fc891e01c8b5..bc471d56a024 --- a/arch/arm/boot/dts/rk3288-tb.dts +++ b/arch/arm/boot/dts/rk3288-tb.dts @@ -167,6 +167,11 @@ }; &pinctrl { + //used for init some gpio + init-gpios = <&gpio0 GPIO_A6 GPIO_ACTIVE_HIGH + /*&gpio0 GPIO_C2 GPIO_ACTIVE_HIGH */ + /*&gpio7 GPIO_B7 GPIO_ACTIVE_LOW */>; + gpio0_gpio { gpio0_c2: gpio0-c2 { rockchip,pins = ; @@ -184,6 +189,7 @@ //to add }; + //could add other pinctrl definition such as gpio }; diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 263f97cb8798..cdbcfcd505b2 100755 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -43,6 +43,8 @@ #include #include #include +#include + #ifdef CONFIG_DEBUG_FS #include @@ -186,6 +188,12 @@ struct rockchip_pmx_func { u8 ngroups; }; +struct gpio_init_config { + struct gpio *gpios; + int nr_gpios; +}; + + struct rockchip_pinctrl { void __iomem *reg_base; @@ -207,6 +215,7 @@ struct rockchip_pinctrl { #ifdef CONFIG_DEBUG_FS struct dentry *debugfs; #endif + struct gpio_init_config *config; }; struct iomux_mode{ @@ -2941,13 +2950,55 @@ static void rockchip_pinctrl_resume(void) #endif + +static struct gpio_init_config * +of_get_gpio_init_config(struct device *dev, struct device_node *np) +{ + struct gpio_init_config *config; + struct property *prop; + const char *regtype; + int proplen, gpio, i; + enum of_gpio_flags flags; + + config = devm_kzalloc(dev, + sizeof(struct gpio_init_config), + GFP_KERNEL); + if (!config) + return ERR_PTR(-ENOMEM); + + /* Fetch GPIOs. */ + config->nr_gpios = of_gpio_named_count(np, "init-gpios"); + + config->gpios = devm_kzalloc(dev, + sizeof(struct gpio) * config->nr_gpios, + GFP_KERNEL); + if (!config->gpios) + return ERR_PTR(-ENOMEM); + + for (i = 0; i < config->nr_gpios; i++) { + //gpio = of_get_named_gpio(np, "gpios", i); + gpio = of_get_named_gpio_flags(np, "init-gpios", i, &flags); + if (gpio < 0) + break; + config->gpios[i].gpio = gpio; + config->gpios[i].flags = flags & OF_GPIO_ACTIVE_LOW; + + printk("%s:gpio[%d] = %d, value = %d\n",__func__, i, gpio, config->gpios[i].flags); + } + + return config; +} + + static int rockchip_pinctrl_probe(struct platform_device *pdev) { struct rockchip_pinctrl *info; struct device *dev = &pdev->dev; struct rockchip_pin_ctrl *ctrl; struct resource *res; - int ret; + int ret; + struct device_node *np; + int i; if (!dev->of_node) { dev_err(dev, "device tree node not found\n"); @@ -3058,6 +3109,25 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) rockchip_gpiolib_unregister(pdev, info); return ret; } + + np = dev->of_node; + if (of_find_property(np, "init-gpios", NULL)) + { + info->config = of_get_gpio_init_config(&pdev->dev, np); + if (IS_ERR(info->config)) + return PTR_ERR(info->config); + + ret = gpio_request_array(info->config->gpios, info->config->nr_gpios); + if (ret) { + dev_err(&pdev->dev, "Could not obtain init GPIOs: %d\n", ret); + return ret; + } + + for(i=0; iconfig->nr_gpios; i++) + { + gpio_direction_output(info->config->gpios[i].gpio, info->config->gpios[i].flags); + } + } pinctrl_debugfs_init(info); -- 2.34.1