From patchwork Wed Apr 29 16:34:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 238905 List-Id: U-Boot discussion From: rayagonda.kokatanur at broadcom.com (Rayagonda Kokatanur) Date: Wed, 29 Apr 2020 22:04:46 +0530 Subject: [PATCH v1 3/3] drivers: pinctrl-single: add request api In-Reply-To: <20200429163446.15390-1-rayagonda.kokatanur@broadcom.com> References: <20200429163446.15390-1-rayagonda.kokatanur@broadcom.com> Message-ID: <20200429163446.15390-4-rayagonda.kokatanur@broadcom.com> Add pinctrl_ops->request api to configure pctrl pad register in gpio mode. Signed-off-by: Rayagonda Kokatanur --- drivers/pinctrl/pinctrl-single.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index fe79a218ee..2cdba1d338 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -130,6 +130,34 @@ static int single_configure_pins(struct udevice *dev, return 0; } +static int single_request(struct udevice *dev, int pin, int flags) +{ + struct single_pdata *pdata = dev->platdata; + struct single_gpiofunc_range *frange = NULL; + struct list_head *pos, *tmp; + int mux_bytes = 0; + u32 data; + + if (!pdata->mask) + return -ENOTSUPP; + + list_for_each_safe(pos, tmp, &pdata->gpiofuncs) { + frange = list_entry(pos, struct single_gpiofunc_range, node); + if ((pin >= frange->offset + frange->npins) || + pin < frange->offset) + continue; + + mux_bytes = pdata->width / BITS_PER_BYTE; + data = pdata->read(pdata->base + pin * mux_bytes); + data &= ~pdata->mask; + data |= frange->gpiofunc; + pdata->write(data, pdata->base + pin * mux_bytes); + break; + } + + return 0; +} + static int single_configure_bits(struct udevice *dev, const struct single_fdt_bits_cfg *pins, int size) @@ -288,6 +316,7 @@ static int single_ofdata_to_platdata(struct udevice *dev) const struct pinctrl_ops single_pinctrl_ops = { .set_state = single_set_state, + .request = single_request, }; static const struct udevice_id single_pinctrl_match[] = {