pinctrl: meson: add a new callback for SoCs fixup
authorQianggui Song <qianggui.song@amlogic.com>
Fri, 15 Nov 2019 12:03:47 +0000 (20:03 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 19 Nov 2019 14:53:58 +0000 (15:53 +0100)
In meson_pinctrl_parse_dt, it contains two parts: reg parsing and
SoC relative fixup for AO. Several fixups in the same code make it hard
to maintain, so move all fixups to each SoC's callback and make
meson_pinctrl_parse_dt just do the reg parsing, separate these two
parts.Overview of all current Meson SoCs fixup is as below:

+------+--------------------------------------+--------------------------+
|      |                                      |                          |
| SoC  |                EE domain             |        AO domain         |
+------+--------------------------------------+--------------------------+
|m8    | parse regs:                          | parse regs:              |
|m8b   |   gpio,mux,pull,pull-enable(skip ds) |    gpio,mux,pull(skip ds)|
|gxl   | fixup:                               | fixup:                   |
|gxbb  |   no                                 |     pull-enable = pull;  |
|axg   |                                      |                          |
+------+--------------------------------------+--------------------------+
|g12a  | parse regs:                          | parse regs:              |
|sm1   |   gpio,mux,pull,pull-enable,ds       |   gpio,mux,ds            |
|      | fixup:                               | fixup:                   |
|      |   no                                 |   pull = gpio;           |
|      |                                      |   pull-enable = gpio;    |
+------+--------------------------------------+--------------------------+
|a1 or | parse regs:                                                     |
|later |  gpio/mux (without ao domain)                                   |
|SoCs  | fixup:                                                          |
|      |  pull = gpio; pull-enable = gpio; ds = gpio;                    |
+------+-----------------------------------------------------------------+
Since m8-axg share the same ao fixup, make a common function
meson8_aobus_parse_dt_extra to do the job.

Signed-off-by: Qianggui Song <qianggui.song@amlogic.com>
Link: https://lore.kernel.org/r/1573819429-6937-2-git-send-email-qianggui.song@amlogic.com
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/meson/pinctrl-meson-axg.c
drivers/pinctrl/meson/pinctrl-meson-g12a.c
drivers/pinctrl/meson/pinctrl-meson-gxbb.c
drivers/pinctrl/meson/pinctrl-meson-gxl.c
drivers/pinctrl/meson/pinctrl-meson.c
drivers/pinctrl/meson/pinctrl-meson.h
drivers/pinctrl/meson/pinctrl-meson8.c
drivers/pinctrl/meson/pinctrl-meson8b.c

index ad502eda4afa46ec2b31a62f6204335c64424b7e..072765db93d70bc39b7fdb1610827b6ada25fed3 100644 (file)
@@ -1066,6 +1066,7 @@ static struct meson_pinctrl_data meson_axg_aobus_pinctrl_data = {
        .num_banks      = ARRAY_SIZE(meson_axg_aobus_banks),
        .pmx_ops        = &meson_axg_pmx_ops,
        .pmx_data       = &meson_axg_aobus_pmx_banks_data,
+       .parse_dt       = meson8_aobus_parse_dt_extra,
 };
 
 static const struct of_device_id meson_axg_pinctrl_dt_match[] = {
index 582665fd362a282a077ac42b7cafb075e599366d..41850e3c0091816ee5a8a7b52020f95518fb4bc7 100644 (file)
@@ -1362,6 +1362,14 @@ static struct meson_axg_pmx_data meson_g12a_aobus_pmx_banks_data = {
        .num_pmx_banks  = ARRAY_SIZE(meson_g12a_aobus_pmx_banks),
 };
 
+static int meson_g12a_aobus_parse_dt_extra(struct meson_pinctrl *pc)
+{
+       pc->reg_pull = pc->reg_gpio;
+       pc->reg_pullen = pc->reg_gpio;
+
+       return 0;
+}
+
 static struct meson_pinctrl_data meson_g12a_periphs_pinctrl_data = {
        .name           = "periphs-banks",
        .pins           = meson_g12a_periphs_pins,
@@ -1388,6 +1396,7 @@ static struct meson_pinctrl_data meson_g12a_aobus_pinctrl_data = {
        .num_banks      = ARRAY_SIZE(meson_g12a_aobus_banks),
        .pmx_ops        = &meson_axg_pmx_ops,
        .pmx_data       = &meson_g12a_aobus_pmx_banks_data,
+       .parse_dt       = meson_g12a_aobus_parse_dt_extra,
 };
 
 static const struct of_device_id meson_g12a_pinctrl_dt_match[] = {
index 5bfa56f3847ef47b0a6f3538e25468d975707415..926b9997159a912ac881491f91cc1cd3f99781e7 100644 (file)
@@ -851,6 +851,7 @@ static struct meson_pinctrl_data meson_gxbb_aobus_pinctrl_data = {
        .num_funcs      = ARRAY_SIZE(meson_gxbb_aobus_functions),
        .num_banks      = ARRAY_SIZE(meson_gxbb_aobus_banks),
        .pmx_ops        = &meson8_pmx_ops,
+       .parse_dt       = meson8_aobus_parse_dt_extra,
 };
 
 static const struct of_device_id meson_gxbb_pinctrl_dt_match[] = {
index 72c5373c8dc1e2dfe1682e57d8609f4beda4c2c3..1b6e8646700f9b31510a82ddff5e41e0438dde77 100644 (file)
@@ -820,6 +820,7 @@ static struct meson_pinctrl_data meson_gxl_aobus_pinctrl_data = {
        .num_funcs      = ARRAY_SIZE(meson_gxl_aobus_functions),
        .num_banks      = ARRAY_SIZE(meson_gxl_aobus_banks),
        .pmx_ops        = &meson8_pmx_ops,
+       .parse_dt       = meson8_aobus_parse_dt_extra,
 };
 
 static const struct of_device_id meson_gxl_pinctrl_dt_match[] = {
index 8bba9d053d9f85f56e6c455db77d56ca32f7f810..26c009f175749f83409270f151e70b8590709129 100644 (file)
@@ -625,7 +625,7 @@ static struct regmap *meson_map_resource(struct meson_pinctrl *pc,
 
        i = of_property_match_string(node, "reg-names", name);
        if (of_address_to_resource(node, i, &res))
-               return ERR_PTR(-ENOENT);
+               return NULL;
 
        base = devm_ioremap_resource(pc->dev, &res);
        if (IS_ERR(base))
@@ -665,26 +665,24 @@ static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
        pc->of_node = gpio_np;
 
        pc->reg_mux = meson_map_resource(pc, gpio_np, "mux");
-       if (IS_ERR(pc->reg_mux)) {
+       if (IS_ERR_OR_NULL(pc->reg_mux)) {
                dev_err(pc->dev, "mux registers not found\n");
-               return PTR_ERR(pc->reg_mux);
+               return pc->reg_mux ? PTR_ERR(pc->reg_mux) : -ENOENT;
        }
 
        pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio");
-       if (IS_ERR(pc->reg_gpio)) {
+       if (IS_ERR_OR_NULL(pc->reg_gpio)) {
                dev_err(pc->dev, "gpio registers not found\n");
-               return PTR_ERR(pc->reg_gpio);
+               return pc->reg_gpio ? PTR_ERR(pc->reg_gpio) : -ENOENT;
        }
 
        pc->reg_pull = meson_map_resource(pc, gpio_np, "pull");
-       /* Use gpio region if pull one is not present */
        if (IS_ERR(pc->reg_pull))
-               pc->reg_pull = pc->reg_gpio;
+               pc->reg_pull = NULL;
 
        pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable");
-       /* Use pull region if pull-enable one is not present */
        if (IS_ERR(pc->reg_pullen))
-               pc->reg_pullen = pc->reg_pull;
+               pc->reg_pullen = NULL;
 
        pc->reg_ds = meson_map_resource(pc, gpio_np, "ds");
        if (IS_ERR(pc->reg_ds)) {
@@ -692,6 +690,19 @@ static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
                pc->reg_ds = NULL;
        }
 
+       if (pc->data->parse_dt)
+               return pc->data->parse_dt(pc);
+
+       return 0;
+}
+
+int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc)
+{
+       if (!pc->reg_pull)
+               return -EINVAL;
+
+       pc->reg_pullen = pc->reg_pull;
+
        return 0;
 }
 
index c696f3241a361ccb4efb387ff9e5f608f67b8c8f..bfa1d3599333c564ac328220aa489e377f3a6f73 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/regmap.h>
 #include <linux/types.h>
 
+struct meson_pinctrl;
+
 /**
  * struct meson_pmx_group - a pinmux group
  *
@@ -114,6 +116,7 @@ struct meson_pinctrl_data {
        unsigned int num_banks;
        const struct pinmux_ops *pmx_ops;
        void *pmx_data;
+       int (*parse_dt)(struct meson_pinctrl *pc);
 };
 
 struct meson_pinctrl {
@@ -171,3 +174,5 @@ int meson_pmx_get_groups(struct pinctrl_dev *pcdev,
 
 /* Common probe function */
 int meson_pinctrl_probe(struct platform_device *pdev);
+/* Common ao groups extra dt parse function for SoCs before g12a  */
+int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc);
index 0b97befa6335de5b39fc4558bdecbd1335b76277..dd17100efdcfc2fcacc3cb75a473feebd9559e7e 100644 (file)
@@ -1103,6 +1103,7 @@ static struct meson_pinctrl_data meson8_aobus_pinctrl_data = {
        .num_funcs      = ARRAY_SIZE(meson8_aobus_functions),
        .num_banks      = ARRAY_SIZE(meson8_aobus_banks),
        .pmx_ops        = &meson8_pmx_ops,
+       .parse_dt       = &meson8_aobus_parse_dt_extra,
 };
 
 static const struct of_device_id meson8_pinctrl_dt_match[] = {
index a7de388388e69cb340b84a05d579eaafb41b72e8..2d5339edd0b7ee0c0a289dcd57ee1328018c31ad 100644 (file)
@@ -962,6 +962,7 @@ static struct meson_pinctrl_data meson8b_aobus_pinctrl_data = {
        .num_funcs      = ARRAY_SIZE(meson8b_aobus_functions),
        .num_banks      = ARRAY_SIZE(meson8b_aobus_banks),
        .pmx_ops        = &meson8_pmx_ops,
+       .parse_dt       = &meson8_aobus_parse_dt_extra,
 };
 
 static const struct of_device_id meson8b_pinctrl_dt_match[] = {