[pinctrl]Synchronize vic7100&jh7110 pinctrl subsystem
author“jenny.zhang” <“jenny.zhang@starfivetech.com”>
Thu, 3 Mar 2022 06:20:18 +0000 (22:20 -0800)
committerjianlonghuang <jianlong.huang@starfivetech.com>
Thu, 7 Apr 2022 03:26:43 +0000 (11:26 +0800)
arch/riscv/boot/dts/starfive/starfive_jh7110_pinctrl.dtsi
drivers/pinctrl/starfive/Kconfig
drivers/pinctrl/starfive/Makefile
drivers/pinctrl/starfive/pinctrl-starfive.c
drivers/pinctrl/starfive/pinctrl-starfive.h
include/dt-bindings/pinctrl/starfive,jh7110-pinfunc.h

index 7d124e8..d268da7 100755 (executable)
                        sf,pin-gpio-doen = <OEN_LOW>;
                };
        };
+       
+       gmac1_pins: gmac1-pins {
+               gmac1-pins0 {
+                       sf,pins = <PAD_GMAC1_MDC>;
+                       sf,pin-ioconfig = <IO(GPIO_IE(1)|GPIO_SMT(1)|GPIO_DS(3))>;
+                       sf,pin-syscon = <PADCFG_PAD_GMAC1_MDC_SYSCON IO_3_3V>;
+               };
+       };
 
        i2c0_pins: i2c0-pins {
                i2c0-pins-scl {
index e07cec9..82d1e85 100755 (executable)
@@ -18,6 +18,12 @@ config PINCTRL_STARFIVE
          
 config PINCTRL_STARFIVE_JH7110
        bool "Pinctrl and GPIO driver for the StarFive jh7100 SoC"
-       depends on PINCTRL_STARFIVE
+       depends on SOC_STARFIVE_JH7110 || PINCTRL_STARFIVE
        help
-         This selects the pinctrl driver for jh7100 starfive.
\ No newline at end of file
+         This selects the pinctrl driver for jh7100 starfive.
+
+config PINCTRL_STARFIVE_VIC7100
+       bool "Pinctrl and GPIO driver for the StarFive vic7100 SoC"
+       depends on SOC_STARFIVE_VIC7100 || PINCTRL_STARFIVE
+       help
+         This selects the pinctrl driver for vic7100 starfive.
\ No newline at end of file
index 2ddbffb..88a67dd 100755 (executable)
@@ -3,4 +3,5 @@
 obj-$(CONFIG_PINCTRL_STARFIVE) += pinctrl-starfive.o
 
 # SoC Drivers
-obj-$(CONFIG_PINCTRL_STARFIVE_JH7110)  += pinctrl-starfive-jh7110.o
\ No newline at end of file
+obj-$(CONFIG_PINCTRL_STARFIVE_JH7110)  += pinctrl-starfive-jh7110.o
+obj-$(CONFIG_PINCTRL_STARFIVE_VIC7100) += pinctrl-starfive-vic7100.o
\ No newline at end of file
index 91ebf88..72a2bbe 100644 (file)
@@ -74,10 +74,6 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
        int map_num = 1;
        int i, j;       
 
-       /*
-        * first find the group of this node and check if we need create
-        * config maps for pins
-        */
        grp = starfive_pinctrl_find_group_by_name(pctldev, np->name);
        if (!grp) {
                dev_err(pctl->dev, "unable to find group for node %pOFn\n", np);
@@ -93,7 +89,6 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
        *map = new_map;
        *num_maps = map_num;
 
-       /* create mux map */
        parent = of_get_parent(np);
        if (!parent) {
                kfree(new_map);
@@ -104,7 +99,6 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
        new_map[0].data.mux.group = np->name;
        of_node_put(parent);
 
-       /* create config map */
        new_map++;
        for (i = j = 0; i < grp->num_pins; i++) {
                pin = &((struct starfive_pin *)(grp->data))[i];
@@ -115,7 +109,7 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
                new_map[j].data.configs.configs =
                                        &pin->pin_config.io_config;
                new_map[j].data.configs.num_configs = 1;
-               j++;
+               j++;
        }
 
        return 0;
@@ -262,73 +256,6 @@ static const struct pinconf_ops starfive_pinconf_ops = {
 };
 
 
-static void starfive_pinctrl_parse_pin_config(struct starfive_pinctrl *pctl,
-                               unsigned int *pins_id, struct starfive_pin *pin_data,
-                               const __be32 *list_p,
-                               struct device_node *np)
-{
-       const struct starfive_pinctrl_soc_info *info = pctl->info;
-       struct starfive_pin_reg *pin_reg;
-       const __be32 *list = list_p;
-       const __be32 *list_din;
-       int size_din;
-       int pin_size;
-       u32 value;
-       int i;
-
-       *pins_id = be32_to_cpu(*list++);
-       pin_data->pin = *pins_id;
-       
-       pin_reg = &pctl->pin_regs[*pins_id];
-       pin_reg->io_conf_reg = *pins_id;
-
-       if (!of_property_read_u32(np, "sf,pin-ioconfig", &value)) {
-               pin_data->pin_config.io_config = value;
-       }
-
-       if (!of_property_read_u32(np, "sf,pinmux", &value)) {
-                       pin_data->pin_config.pinmux_func = value & PINMUX_GPIO_FUNC_MASK;
-               
-               if(pin_data->pin_config.pinmux_func == PINMUX_GPIO_FUNC){
-                       pin_data->pin_config.gpio_num = value & PINMUX_GPIO_NUM_MASK;
-
-                       if (!of_property_read_u32(np, "sf,pin-gpio-dout", &value)) {
-                               pin_data->pin_config.gpio_dout = value;
-                               pin_reg->gpo_dout_reg = info->dout_reg_base + \
-                                                       (pin_data->pin_config.gpio_num * info->dout_reg_offset);
-                       }
-                       
-                       if (!of_property_read_u32(np, "sf,pin-gpio-doen", &value)) {
-                               pin_data->pin_config.gpio_doen = value;
-                               pin_reg->gpo_doen_reg = info->doen_reg_base + \
-                                                       (pin_data->pin_config.gpio_num * info->doen_reg_offset);
-                       }
-
-                       list_din = of_get_property(np, "sf,pin-gpio-din", &size_din);
-                       if (list_din) {
-                               if (!size_din || size_din % pin_size) {
-                                       dev_err(pctl->dev, 
-                                               "Invalid sf,pin-gpio-din or pins property in node %pOF\n", np);
-                                       return;
-                               }
-                               
-                               pin_data->pin_config.gpio_din_num = size_din / pin_size;
-                               pin_data->pin_config.gpio_din_reg = devm_kcalloc(pctl->dev,
-                                                        pin_data->pin_config.gpio_din_num, sizeof(s32),
-                                                        GFP_KERNEL);
-                               
-                               for(i = 0; i < pin_data->pin_config.gpio_din_num; i++){
-                                       value = be32_to_cpu(*list_din++);
-                                       pin_data->pin_config.gpio_din_reg[i] = info->din_reg_base + \
-                                                                              value*info->din_reg_offset;
-                               }
-                       }
-               }
-       }
-       return;
-}
-
-
 static int starfive_pinctrl_parse_groups(struct device_node *np,
                                        struct group_desc *grp,
                                        struct starfive_pinctrl *pctl,
@@ -360,7 +287,7 @@ static int starfive_pinctrl_parse_groups(struct device_node *np,
        }
 
        if (!size || size % pin_size) {
-               dev_err(pctl->dev, 
+               dev_err(pctl->dev,
                        "Invalid sf,pins or pins property in node %pOF\n", np);
                return -EINVAL;
        }
@@ -384,25 +311,25 @@ static int starfive_pinctrl_parse_groups(struct device_node *np,
                }
                
                child_num_pins = psize / pin_size;
-               
+
                for (j = 0; j < child_num_pins; j++) {
                        pin_data = &((struct starfive_pin *)(grp->data))[j + offset];
                        pins_id =  &(grp->pins)[j + offset];
                        
-                       if (info->flags & STARFIVE_USE_SCU)
-                               info->starfive_pinctrl_parse_pin(pctl, pins_id,
-                                                         pin_data, list, child);
-                       else
-                               starfive_pinctrl_parse_pin_config(pctl, pins_id,
-                                                          pin_data, list, child);
-                       *list++;
+                       if (!info->starfive_pinctrl_parse_pin){
+                               dev_err(pctl->dev, "pinmux ops lacks necessary functions\n");
+                               return -EINVAL;
+                       }
+                               
+                       info->starfive_pinctrl_parse_pin(pctl, pins_id,pin_data, list, child);
+                       list++;
                }
                offset += j;
        }
        
        return 0;
 }
-                                       
+
 static int starfive_pinctrl_parse_functions(struct device_node *np,
                                        struct starfive_pinctrl *pctl,
                                        u32 index)
@@ -412,12 +339,12 @@ static int starfive_pinctrl_parse_functions(struct device_node *np,
        struct function_desc *func;
        struct group_desc *grp;
        u32 i = 0;      
+       int ret;
 
        func = pinmux_generic_get_function(pctldev, index);
        if (!func)
                return -EINVAL;
 
-       /* Initialise function */
        func->name = np->name;
        func->num_group_names = of_get_child_count(np);
        if (func->num_group_names == 0) {
@@ -431,7 +358,7 @@ static int starfive_pinctrl_parse_functions(struct device_node *np,
        
        for_each_child_of_node(np, child) {
                func->group_names[i] = child->name;
-               grp = devm_kzalloc(pctl->dev, sizeof(struct group_desc),
+               grp = devm_kzalloc(pctl->dev, sizeof(struct group_desc),
                                   GFP_KERNEL);
                if (!grp) {
                        of_node_put(child);
@@ -443,7 +370,11 @@ static int starfive_pinctrl_parse_functions(struct device_node *np,
                                  pctl->group_index++, grp);
                mutex_unlock(&pctl->mutex);
 
-               starfive_pinctrl_parse_groups(child, grp, pctl, i++);
+               ret = starfive_pinctrl_parse_groups(child, grp, pctl, i++);
+               if (ret < 0){
+                       dev_err(pctl->dev, "parse groups failed\n");
+                       return ret;
+               }
        }
 
        return 0;
@@ -487,6 +418,7 @@ int starfive_pinctrl_probe(struct platform_device *pdev,
        struct device *dev = &pdev->dev;
        struct pinctrl_desc *starfive_pinctrl_desc;
        struct starfive_pinctrl *pctl;
+       struct resource *res;
        int ret, i;
        u32 value;
 
@@ -495,7 +427,6 @@ int starfive_pinctrl_probe(struct platform_device *pdev,
                return -EINVAL;
        }
 
-       /* Create state holders etc for this driver */
        pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
        if (!pctl)
                return -ENOMEM;
@@ -517,9 +448,16 @@ int starfive_pinctrl_probe(struct platform_device *pdev,
        pctl->padctl_base = devm_platform_ioremap_resource_byname(pdev, "control");
        if (IS_ERR(pctl->padctl_base))
                return PTR_ERR(pctl->padctl_base);
+
+       res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gpio");
+       if (res) {
+               pctl->gpio_base = devm_ioremap_resource(dev, res);
+               if (IS_ERR(pctl->gpio_base))
+                       return PTR_ERR(pctl->gpio_base);
+       }
        
        if (info->starfive_iopad_sel_func) {
-               ret = info->starfive_iopad_sel_func(pctl,value);
+               ret = info->starfive_iopad_sel_func(pdev,pctl,value);
                if (ret) 
                        return ret;
        }
index 97a381f..4bd4ea4 100644 (file)
 
 #define MAX_GPIO                               64
 
-/************vic7100 reg**************/ 
 #define STARFIVE_PINS_SIZE                     4
-//pinmux
-#define PINMUX_GPIO_NUM_MASK                   0xFF
-#define PINMUX_GPIO_FUNC_MASK                  0xF00
-#define PINMUX_GPIO_FUNC                       0x100
-/************vic7100 reg**************/ 
 
 #define STARFIVE_USE_SCU                       BIT(0)
 
@@ -106,8 +100,9 @@ struct starfive_pinctrl_soc_info {
        unsigned int din_reg_offset;
        
        /* sel-function */
-       int (*starfive_iopad_sel_func)(struct starfive_pinctrl *ipctl, 
-                               unsigned int func_id);
+       int (*starfive_iopad_sel_func)(struct platform_device *pdev,
+                                       struct starfive_pinctrl *ipctl,
+                                       unsigned int func_id);
        /* generic pinconf */
        int (*starfive_pinconf_get)(struct pinctrl_dev *pctldev, unsigned int pin_id,
                               unsigned long *config);
@@ -115,8 +110,10 @@ struct starfive_pinctrl_soc_info {
                                unsigned pin_id, unsigned long *configs,
                                unsigned num_configs);
        
+       /* generic pinmux */
        int (*starfive_pmx_set_one_pin_mux)(struct starfive_pinctrl *ipctl,
                                struct starfive_pin *pin);
+       /* gpio chip */
        int (*starfive_gpio_register)(struct platform_device *pdev,
                                struct starfive_pinctrl *ipctl);
        void (*starfive_pinctrl_parse_pin)(struct starfive_pinctrl *ipctl,
index a7655c1..1f8579b 100755 (executable)
 #define IO(config)                     ((config) & 0xFF)
 #define DOUT(dout)                     ((dout) & 0xFF)
 #define DOEN(doen)                     ((doen) & 0xFF) 
-#define DIN(din_reg)           ((din_reg) & 0xFF)
+#define DIN(din_reg)                   ((din_reg) & 0xFF)
+
+//syscon value
+#define IO_3_3V                                0 /*00:3.3v*/
+#define IO_2_5V                                1 /*01:2.5v*/
+#define IO_1_8V                                2 /*10:1.8v*/
 
 #endif