Commit 202ff7537558edfd759b400cfe9e56c56fc7868c

Authored by Sean Paul
Committed by Gerald Van Baren
1 parent aadef0a1bc
Exists in master and in 55 other branches 8qm-imx_v2020.04_5.4.70_2.3.0, emb_lf_v2022.04, emb_lf_v2023.04, imx_v2015.04_4.1.15_1.0.0_ga, pitx_8mp_lf_v2020.04, smarc-8m-android-10.0.0_2.6.0, smarc-8m-android-11.0.0_2.0.0, smarc-8mp-android-11.0.0_2.0.0, smarc-emmc-imx_v2014.04_3.10.53_1.1.0_ga, smarc-emmc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx-l5.0.0_1.0.0-ga, smarc-imx6_v2018.03_4.14.98_2.0.0_ga, smarc-imx7_v2017.03_4.9.11_1.0.0_ga, smarc-imx7_v2018.03_4.14.98_2.0.0_ga, smarc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx_v2015.04_4.1.15_1.0.0_ga, smarc-imx_v2017.03_4.9.11_1.0.0_ga, smarc-imx_v2017.03_4.9.88_2.0.0_ga, smarc-imx_v2017.03_o8.1.0_1.3.0_8m, smarc-imx_v2018.03_4.14.78_1.0.0_ga, smarc-m6.0.1_2.1.0-ga, smarc-n7.1.2_2.0.0-ga, smarc-rel_imx_4.1.15_2.0.0_ga, smarc_8m-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8m-imx_v2019.04_4.19.35_1.1.0, smarc_8m_00d0-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2019.04_4.19.35_1.1.0, smarc_8mm-imx_v2020.04_5.4.24_2.1.0, smarc_8mp_lf_v2020.04, smarc_8mq-imx_v2020.04_5.4.24_2.1.0, smarc_8mq_lf_v2020.04, ti-u-boot-2015.07, u-boot-2013.01.y, v2013.10, v2013.10-smarct33, v2013.10-smartmen, v2014.01, v2014.04, v2014.04-smarct33, v2014.04-smarct33-emmc, v2014.04-smartmen, v2014.07, v2014.07-smarct33, v2014.07-smartmen, v2015.07-smarct33, v2015.07-smarct33-emmc, v2015.07-smarct4x, v2016.05-dlt, v2016.05-smarct3x, v2016.05-smarct3x-emmc, v2016.05-smarct4x, v2017.01-smarct3x, v2017.01-smarct3x-emmc, v2017.01-smarct4x

fdt: Add polarity-aware gpio functions to fdtdec

Add get and set gpio functions to fdtdec that take into account the
polarity field in fdtdec_gpio_state.flags.

Signed-off-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 36 additions and 0 deletions Side-by-side Diff

... ... @@ -90,6 +90,22 @@
90 90 #define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE)
91 91  
92 92 /**
  93 + * Read the GPIO taking into account the polarity of the pin.
  94 + *
  95 + * @param gpio pointer to the decoded gpio
  96 + * @return value of the gpio if successful, < 0 if unsuccessful
  97 + */
  98 +int fdtdec_get_gpio(struct fdt_gpio_state *gpio);
  99 +
  100 +/**
  101 + * Write the GPIO taking into account the polarity of the pin.
  102 + *
  103 + * @param gpio pointer to the decoded gpio
  104 + * @return 0 if successful
  105 + */
  106 +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val);
  107 +
  108 +/**
93 109 * Find the next numbered alias for a peripheral. This is used to enumerate
94 110 * all the peripherals of a certain type.
95 111 *
... ... @@ -487,6 +487,26 @@
487 487 return err == 1 ? 0 : err;
488 488 }
489 489  
  490 +int fdtdec_get_gpio(struct fdt_gpio_state *gpio)
  491 +{
  492 + int val;
  493 +
  494 + if (!fdt_gpio_isvalid(gpio))
  495 + return -1;
  496 +
  497 + val = gpio_get_value(gpio->gpio);
  498 + return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
  499 +}
  500 +
  501 +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val)
  502 +{
  503 + if (!fdt_gpio_isvalid(gpio))
  504 + return -1;
  505 +
  506 + val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
  507 + return gpio_set_value(gpio->gpio, val);
  508 +}
  509 +
490 510 int fdtdec_setup_gpio(struct fdt_gpio_state *gpio)
491 511 {
492 512 /*