linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 3/9] serial: Add common rs485 device tree parsing function
Date: Sun, 30 Jul 2017 07:49:47 -0700	[thread overview]
Message-ID: <20170730144947.GA18707@kroah.com> (raw)
In-Reply-To: <20170718105948.21986-4-u.kleine-koenig@pengutronix.de>

On Tue, Jul 18, 2017 at 12:59:42PM +0200, Uwe Kleine-K?nig wrote:
> From: Sascha Hauer <s.hauer@pengutronix.de>
> 
> Several drivers have the same device tree parsing code. Create
> a common helper function for it.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> [ukl: implement default <0 0> for rts-delay, unset unspecified flags]
> Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
> Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/tty/serial/Kconfig  |  4 ++++
>  drivers/tty/serial/Makefile |  2 ++
>  drivers/tty/serial/of.c     | 47 +++++++++++++++++++++++++++++++++++++++++++++

Why is this a separate file, with a Kconfig option that is always
enabled?  Why not just add the single function to the serial core?

> +/**
> + * of_get_rs485_mode() - Implement parsing rs485 properties
> + * @np: uart node
> + * @rs485conf: output parameter
> + *
> + * This function implements the device tree binding described in
> + * Documentation/devicetree/bindings/serial/rs485.txt.
> + *
> + * Return: 0 on success, 1 if the node doesn't contain rs485 stuff.

1 is not an error code :(

Return a proper error please.


> + */
> +int of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf)
> +{
> +	u32 rs485_delay[2];
> +	int ret;
> +
> +	if (!IS_ENABLED(CONFIG_OF) || !np)
> +		return 1;
> +
> +	ret = of_property_read_u32_array(np, "rs485-rts-delay", rs485_delay, 2);
> +	if (!ret) {
> +		rs485conf->delay_rts_before_send = rs485_delay[0];
> +		rs485conf->delay_rts_after_send = rs485_delay[1];
> +	} else {
> +		rs485conf->delay_rts_before_send = 0;
> +		rs485conf->delay_rts_after_send = 0;
> +	}
> +
> +	/*
> +	 * clear full-duplex and enabled flags to get to a defined state with
> +	 * the two following properties.
> +	 */
> +	rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED);
> +
> +	if (of_property_read_bool(np, "rs485-rx-during-tx"))
> +		rs485conf->flags |= SER_RS485_RX_DURING_TX;
> +
> +	if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time"))
> +		rs485conf->flags |= SER_RS485_ENABLED;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_get_rs485_mode);
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index 1775500294bb..3a89e8925722 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -501,4 +501,17 @@ static inline int uart_handle_break(struct uart_port *port)
>  					 (cflag) & CRTSCTS || \
>  					 !((cflag) & CLOCAL))
>  
> +/*
> + * Common device tree parsing helpers
> + */
> +#ifdef CONFIG_OF_SERIAL
> +int of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf);
> +#else
> +static inline int of_get_rs485_mode(struct device_node *np,
> +				    struct serial_rs485 *rs485conf)
> +{
> +	return 1;

Again, a real error.

And why not have a "generic" firmware function for this that defaults to
the of_ for that platform type if present?  What's the odds that acpi
will need/want this soon anyway?

thanks,

greg k-h

  reply	other threads:[~2017-07-30 14:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 1/9] serial: fsl_lpuart: clear unsupported options in .rs485_config() Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 2/9] dt-bindings: serial/rs485: make rs485-rts-delay optional Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 3/9] serial: Add common rs485 device tree parsing function Uwe Kleine-König
2017-07-30 14:49   ` Greg KH [this message]
2017-07-31  7:42     ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 4/9] serial: atmel: Use " Uwe Kleine-König
2017-07-30 14:50   ` Greg KH
2017-07-18 10:59 ` [PATCH v4 5/9] serial: fsl_lpuart: " Uwe Kleine-König
2017-07-30 14:50   ` Greg KH
2017-07-18 10:59 ` [PATCH v4 6/9] serial: omap-serial: " Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 7/9] serial: imx: default to half duplex rs485 Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 8/9] serial: imx: Use common rs485 device tree parsing function Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 9/9] dt-bindings: serial: document rs485 bindings for various devices Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170730144947.GA18707@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).