From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail.microcatalog.org.uk ([217.6.246.34] helo=root.phytec.de) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cblA7-00067k-TI for barebox@lists.infradead.org; Thu, 09 Feb 2017 09:37:14 +0000 Received: from idefix.phytec.de (idefix.phytec.de [172.16.0.10]) by root.phytec.de (Postfix) with ESMTP id F3566A003B6 for ; Thu, 9 Feb 2017 10:36:59 +0100 (CET) From: Wadim Egorov Date: Thu, 9 Feb 2017 10:36:42 +0100 Message-Id: <1486633003-34908-2-git-send-email-w.egorov@phytec.de> In-Reply-To: <1486633003-34908-1-git-send-email-w.egorov@phytec.de> References: <1486633003-34908-1-git-send-email-w.egorov@phytec.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [RFC] serial: ns16550: Set read/write functions depending on reg-io-width To: barebox@lists.infradead.org Set proper register read/write functions depending on reg-io-width device tree property. Signed-off-by: Wadim Egorov --- of_platform_device_create() creates resources in the device_d struct. ns16550_init_iomem() and ns16550_init_ioport() are reading the resources and it's flags (register width). So both functions are not failing, because there is a valid resource. The res->flags might be not set at all. And if it is not set, the driver will use always IORESOURCE_MEM_8BIT. With this patch the probe_dt() func will override the read/write funcs, if there is a valid reg-io-width property. --- drivers/serial/serial_ns16550.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c index c6548e3..752e77b 100644 --- a/drivers/serial/serial_ns16550.c +++ b/drivers/serial/serial_ns16550.c @@ -287,12 +287,31 @@ static int ns16550_tstc(struct console_device *cdev) static void ns16550_probe_dt(struct device_d *dev, struct ns16550_priv *priv) { struct device_node *np = dev->device_node; + u32 width; if (!IS_ENABLED(CONFIG_OFDEVICE)) return; of_property_read_u32(np, "clock-frequency", &priv->plat.clock); of_property_read_u32(np, "reg-shift", &priv->plat.shift); + if (!of_property_read_u32(np, "reg-io-width", &width)) + switch (width) { + case 1: + priv->read_reg = ns16550_read_reg_mmio_8; + priv->write_reg = ns16550_write_reg_mmio_8; + break; + case 2: + priv->read_reg = ns16550_read_reg_mmio_16; + priv->write_reg = ns16550_write_reg_mmio_16; + break; + case 4: + priv->read_reg = ns16550_read_reg_mmio_32; + priv->write_reg = ns16550_write_reg_mmio_32; + break; + default: + dev_err(dev, "unsupported reg-io-width (%d)\n", + width); + } } static struct ns16550_drvdata ns16450_drvdata = { -- 1.9.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox