]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/pinctrl/pinctrl-ingenic.c
Merge tag 'for-linus-20191129' of git://git.kernel.dk/linux-block
[linux.git] / drivers / pinctrl / pinctrl-ingenic.c
index 6e2683016c1f026a9f9ead20491860a5e73f5c71..24e0e2ef47a4dbad8e6d70771cb973df6ccfb03a 100644 (file)
@@ -686,6 +686,7 @@ static int jz4770_mac_rmii_pins[] = {
        0xa9, 0xab, 0xaa, 0xac, 0xa5, 0xa4, 0xad, 0xae, 0xa6, 0xa8,
 };
 static int jz4770_mac_mii_pins[] = { 0xa7, 0xaf, };
+static int jz4770_otg_pins[] = { 0x8a, };
 
 static int jz4770_uart0_data_funcs[] = { 0, 0, };
 static int jz4770_uart0_hwflow_funcs[] = { 0, 0, };
@@ -744,6 +745,7 @@ static int jz4770_pwm_pwm6_funcs[] = { 0, };
 static int jz4770_pwm_pwm7_funcs[] = { 0, };
 static int jz4770_mac_rmii_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 static int jz4770_mac_mii_funcs[] = { 0, 0, };
+static int jz4770_otg_funcs[] = { 0, };
 
 static const struct group_desc jz4770_groups[] = {
        INGENIC_PIN_GROUP("uart0-data", jz4770_uart0_data),
@@ -799,6 +801,7 @@ static const struct group_desc jz4770_groups[] = {
        INGENIC_PIN_GROUP("pwm7", jz4770_pwm_pwm7),
        INGENIC_PIN_GROUP("mac-rmii", jz4770_mac_rmii),
        INGENIC_PIN_GROUP("mac-mii", jz4770_mac_mii),
+       INGENIC_PIN_GROUP("otg-vbus", jz4770_otg),
 };
 
 static const char *jz4770_uart0_groups[] = { "uart0-data", "uart0-hwflow", };
@@ -841,6 +844,7 @@ static const char *jz4770_pwm5_groups[] = { "pwm5", };
 static const char *jz4770_pwm6_groups[] = { "pwm6", };
 static const char *jz4770_pwm7_groups[] = { "pwm7", };
 static const char *jz4770_mac_groups[] = { "mac-rmii", "mac-mii", };
+static const char *jz4770_otg_groups[] = { "otg-vbus", };
 
 static const struct function_desc jz4770_functions[] = {
        { "uart0", jz4770_uart0_groups, ARRAY_SIZE(jz4770_uart0_groups), },
@@ -871,6 +875,7 @@ static const struct function_desc jz4770_functions[] = {
        { "pwm6", jz4770_pwm6_groups, ARRAY_SIZE(jz4770_pwm6_groups), },
        { "pwm7", jz4770_pwm7_groups, ARRAY_SIZE(jz4770_pwm7_groups), },
        { "mac", jz4770_mac_groups, ARRAY_SIZE(jz4770_mac_groups), },
+       { "otg", jz4770_otg_groups, ARRAY_SIZE(jz4770_otg_groups), },
 };
 
 static const struct ingenic_chip_info jz4770_chip_info = {
@@ -1801,19 +1806,30 @@ static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
                ingenic_config_pin(jzpc, pin, JZ4740_GPIO_PULL_DIS, !enabled);
 }
 
+static void ingenic_set_output_level(struct ingenic_pinctrl *jzpc,
+                                    unsigned int pin, bool high)
+{
+       if (jzpc->version >= ID_JZ4770)
+               ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, high);
+       else
+               ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DATA, high);
+}
+
 static int ingenic_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
                unsigned long *configs, unsigned int num_configs)
 {
        struct ingenic_pinctrl *jzpc = pinctrl_dev_get_drvdata(pctldev);
        unsigned int idx = pin % PINS_PER_GPIO_CHIP;
        unsigned int offt = pin / PINS_PER_GPIO_CHIP;
-       unsigned int cfg;
+       unsigned int cfg, arg;
+       int ret;
 
        for (cfg = 0; cfg < num_configs; cfg++) {
                switch (pinconf_to_config_param(configs[cfg])) {
                case PIN_CONFIG_BIAS_DISABLE:
                case PIN_CONFIG_BIAS_PULL_UP:
                case PIN_CONFIG_BIAS_PULL_DOWN:
+               case PIN_CONFIG_OUTPUT:
                        continue;
                default:
                        return -ENOTSUPP;
@@ -1821,6 +1837,8 @@ static int ingenic_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
        }
 
        for (cfg = 0; cfg < num_configs; cfg++) {
+               arg = pinconf_to_config_argument(configs[cfg]);
+
                switch (pinconf_to_config_param(configs[cfg])) {
                case PIN_CONFIG_BIAS_DISABLE:
                        dev_dbg(jzpc->dev, "disable pull-over for pin P%c%u\n",
@@ -1844,6 +1862,14 @@ static int ingenic_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
                        ingenic_set_bias(jzpc, pin, true);
                        break;
 
+               case PIN_CONFIG_OUTPUT:
+                       ret = pinctrl_gpio_direction_output(pin);
+                       if (ret)
+                               return ret;
+
+                       ingenic_set_output_level(jzpc, pin, arg);
+                       break;
+
                default:
                        unreachable();
                }
@@ -1940,6 +1966,7 @@ static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc,
 {
        struct ingenic_gpio_chip *jzgc;
        struct device *dev = jzpc->dev;
+       struct gpio_irq_chip *girq;
        unsigned int bank;
        int err;
 
@@ -1982,10 +2009,6 @@ static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc,
                jzgc->gc.free = gpiochip_generic_free;
        }
 
-       err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc);
-       if (err)
-               return err;
-
        jzgc->irq = irq_of_parse_and_map(node, 0);
        if (!jzgc->irq)
                return -EINVAL;
@@ -2000,13 +2023,22 @@ static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc,
        jzgc->irq_chip.irq_set_wake = ingenic_gpio_irq_set_wake;
        jzgc->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND;
 
-       err = gpiochip_irqchip_add(&jzgc->gc, &jzgc->irq_chip, 0,
-                       handle_level_irq, IRQ_TYPE_NONE);
+       girq = &jzgc->gc.irq;
+       girq->chip = &jzgc->irq_chip;
+       girq->parent_handler = ingenic_gpio_irq_handler;
+       girq->num_parents = 1;
+       girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
+                                    GFP_KERNEL);
+       if (!girq->parents)
+               return -ENOMEM;
+       girq->parents[0] = jzgc->irq;
+       girq->default_type = IRQ_TYPE_NONE;
+       girq->handler = handle_level_irq;
+
+       err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc);
        if (err)
                return err;
 
-       gpiochip_set_chained_irqchip(&jzgc->gc, &jzgc->irq_chip,
-                       jzgc->irq, ingenic_gpio_irq_handler);
        return 0;
 }