ARM: orion5x: Move micon code to a MFD driver
Subsystems (4)
cover ARM: orion5x: Move micon code to a MFD driver
Hi all,
This patch series removes some duplicate code between the Kurobox and the Terastation Pro 2 since they both use the same on-board microcontroller (micon) attached to their UART1 for system restart.
Future patches will add support for the LEDs, temperature, FAN that the micro controller provides.
Florian Fainelli (2):
mfd: micon: Add Buffalo Kurobox Pro, Terastation II Pro/Live driver
ARM: orion5x: Utilize micon MFD driver
arch/arm/mach-orion5x/Kconfig | 4 + arch/arm/mach-orion5x/kurobox_pro-setup.c | 149 +++--------------- arch/arm/mach-orion5x/terastation_pro2-setup.c | 149 +++--------------- drivers/mfd/Kconfig | 8 + drivers/mfd/Makefile | 2 + drivers/mfd/micon.c | 204 +++++++++++++++++++++++++ include/linux/platform_data/micon.h | 10 ++ 7 files changed, 264 insertions(+), 262 deletions(-) create mode 100644 drivers/mfd/micon.c create mode 100644 include/linux/platform_data/micon.h
Signature · 1 line
2.9.3
PATCH 1/2 mfd: micon: Add Buffalo Kurobox Pro, Terastation II Pro/Live driver
This driver is currently only used to reboot the devices, but the microcontroller hanging off UART1 on the Buffalo Kurobox Pro and Terastation II Pro/Live is capable of a lot more than that, which we will support in subsequent patches. For now, just add the reboot functionality to make the kernel reboot correctly.
--- drivers/mfd/Kconfig | 8 ++ drivers/mfd/Makefile | 2 + drivers/mfd/micon.c | 204 ++++++++++++++++++++++++++++++++++++ include/linux/platform_data/micon.h | 10 ++ 4 files changed, 224 insertions(+) create mode 100644 drivers/mfd/micon.c create mode 100644 include/linux/platform_data/micon.h
drivers/mfd/Kconfig +8 -0
@@ -352,6 +352,14 @@ config MFD_MX25_TSADC i.MX25 processors. They consist of a conversion queue for general purpose ADC and a queue for Touchscreens. +config MFD_MICON + bool "Buffalo Kurobox Pro/Terastation II Pro/Live MCU interface" + depends on PLAT_ORION + help + Enables support for the UART1 attached micro controller on Buffalo + Kurobox Pro and Terastation II Pro/Live NAS devices. Used for + machine restart. + config MFD_HI6421_PMIC tristate "HiSilicon Hi6421 PMU/Codec IC" depends on OF
drivers/mfd/Makefile +2 -0
@@ -94,6 +94,8 @@ obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o +obj-$(CONFIG_MFD_MICON) += micon.o + obj-$(CONFIG_MFD_CORE) += mfd-core.o obj-$(CONFIG_EZX_PCAP) += ezx-pcap.o
drivers/mfd/micon.c new file +204 -0
204 lines not on this page · raw message
include/linux/platform_data/micon.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __MICON_PDATA_H +#define __MICON_PDATA_H + +#define MICON_NAME "micon" + +struct micon_platform_data { +int tclk; +}; + +#endif /* __MICON_PDATA_H */
Signature · 1 line
2.9.3
Re: [PATCH 1/2] mfd: micon: Add Buffalo Kurobox Pro, Terastation II Pro/Live driver
Quoted 5 lines · Florian Fainelli
This driver is currently only used to reboot the devices, but the microcontroller hanging off UART1 on the Buffalo Kurobox Pro and Terastation II Pro/Live is capable of a lot more than that, which we will support in subsequent patches. For now, just add the reboot functionality to make the kernel reboot correctly.
This is not an MFD driver. You have written a UART driver.
Please relocate it to drivers/char/tty/serial.
Quoted 267 lines
Signed-off-by Florian Fainelli <[email protected]>--- drivers/mfd/Kconfig | 8 ++ drivers/mfd/Makefile | 2 + drivers/mfd/micon.c | 204 ++++++++++++++++++++++++++++++++++++ include/linux/platform_data/micon.h | 10 ++ 4 files changed, 224 insertions(+) create mode 100644 drivers/mfd/micon.c create mode 100644 include/linux/platform_data/micon.hdrivers/mfd/Kconfig +8
-0@@ -352,6 +352,14 @@ config MFD_MX25_TSADC i.MX25 processors. They consist of a conversion queue for general purpose ADC and a queue for Touchscreens. +config MFD_MICON + bool "Buffalo Kurobox Pro/Terastation II Pro/Live MCU interface" + depends on PLAT_ORION + help + Enables support for the UART1 attached micro controller on Buffalo + Kurobox Pro and Terastation II Pro/Live NAS devices. Used for + machine restart. + config MFD_HI6421_PMIC tristate "HiSilicon Hi6421 PMU/Codec IC" depends on OFdrivers/mfd/Makefile +2
-0@@ -94,6 +94,8 @@ obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o +obj-$(CONFIG_MFD_MICON) += micon.o + obj-$(CONFIG_MFD_CORE) += mfd-core.o obj-$(CONFIG_EZX_PCAP) += ezx-pcap.odrivers/mfd/micon.c new file +203
-0@@ -0,0 +1,204 @@ +/* +* Buffalo Kurobox/Terastation Pro II specific power off method via +* UART1-attached microcontroller +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/kernel.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/platform_device.h> +#include <linux/platform_data/micon.h> +#include <linux/serial_reg.h> +#include <linux/notifier.h> +#include <linux/reboot.h> + +struct micon_priv { +struct device *dev; +void __iomem *base; +int tclk; +struct notifier_block nb; +}; + +#define UART1_REG (x) ((UART_##x) << 2) + +static int miconread (struct micon_priv *priv,unsigned char *buf,int count) +{ +int i; +int timeout; + +for (i =0 ; i < count; i++) { + timeout =10 ; + +while (!(readl (priv->base +UART1_REG (LSR )) &UART_LSR_DR )) { +if (--timeout ==0 ) +break ; +udelay (1000 ); + } + +if (timeout ==0 ) +break ; + buf[i] =readl (priv->base +UART1_REG (RX )); + } + +/* return read bytes */ +return i; +} + +static int miconwrite (struct micon_priv *priv,const unsigned char *buf, +int count) +{ +int i =0 ; + +while (count--) { +while (!(readl (priv->base +UART1_REG (LSR )) &UART_LSR_THRE )) +barrier (); +writel (buf[i++], priv->base +UART1_REG (TX )); + } + +return 0 ; +} + +static int miconsend (struct micon_priv *priv,const unsigned char *data, +int count) +{ +int i; +unsigned char checksum =0 ; +unsigned char recv_buf[40 ]; +unsigned char send_buf[40 ]; +unsigned char correct_ack[3 ]; +int retry =2 ; + +/* Generate checksum */ +for (i =0 ; i < count; i++) + checksum -= data[i]; + +do { +/* Send data */ +miconwrite (priv, data, count); + +/* send checksum */ +miconwrite (priv, &checksum,1 ); + +if (miconread (priv, recv_buf,sizeof (recv_buf)) <=3 ) { +dev_err (priv->dev,">%s: receive failed.\n" , __func__); + +/* send preamble to clear the receive buffer */ +memset (&send_buf,0xff ,sizeof (send_buf)); +miconwrite (priv, send_buf,sizeof (send_buf)); + +/* make dummy reads */ +mdelay (100 ); +miconread (priv, recv_buf,sizeof (recv_buf)); + }else { +/* Generate expected ack */ + correct_ack[0 ] =0x01 ; + correct_ack[1 ] = data[1 ]; + correct_ack[2 ] =0x00 ; + +/* checksum Check */ +if ((recv_buf[0 ] + recv_buf[1 ] + recv_buf[2 ] + + recv_buf[3 ]) &0xFF ) { +dev_err (priv->dev,">%s: Checksum Error : " +"Received data[%02x, %02x, %02x, %02x]" +"\n" , __func__, recv_buf[0 ], + recv_buf[1 ], recv_buf[2 ], recv_buf[3 ]); + }else { +/* Check Received Data */ +if (correct_ack[0 ] == recv_buf[0 ] && + correct_ack[1 ] == recv_buf[1 ] && + correct_ack[2 ] == recv_buf[2 ]) { +/* Interval for next command */ +mdelay (10 ); + +/* Receive ACK */ +return 0 ; + } + } +/* Received NAK or illegal Data */ +dev_err (priv->dev,">%s: Error : NAK or Illegal Data " +"Received\n" , __func__); + } + }while (retry--); + +/* Interval for next command */ +mdelay (10 ); + +return -1 ; +} + +static int restart_handler (struct notifier_block *this, +unsigned long code,void *cmd) +{ + struct micon_priv *priv = container_of(this, struct micon_priv, nb); + +const unsigned char watchdogkill[] = {0x01 ,0x35 ,0x00 }; +const unsigned char shutdownwait[] = {0x00 ,0x0c }; +const unsigned char poweroff[] = {0x00 ,0x06 }; +/* 38400 baud divisor */ +unsigned int divisor = ((priv->tclk + (8 *38400 )) / (16 *38400 )); + +if (code !=SYS_DOWN && code !=SYS_HALT ) +return NOTIFY_DONE ; + +dev_info (priv->dev,"%s: triggering power-off...\n" , __func__); + +/* hijack uart1 and reset into sane state (38400,8n1,even parity) */ +writel (0x83 , priv->base +UART1_REG (LCR )); +writel (divisor &0xff , priv->base +UART1_REG (DLL )); +writel ((divisor >>8 ) &0xff , priv->base +UART1_REG (DLM )); +writel (0x1b , priv->base +UART1_REG (LCR )); +writel (0x00 , priv->base +UART1_REG (IER )); +writel (0x07 , priv->base +UART1_REG (FCR )); +writel (0x00 , priv->base +UART1_REG (MCR )); + +/* Send the commands to shutdown the Terastation Pro II */ +miconsend (priv, watchdogkill,sizeof (watchdogkill)); +miconsend (priv, shutdownwait,sizeof (shutdownwait)); +miconsend (priv, poweroff,sizeof (poweroff)); + +return NOTIFY_DONE ; +} + +static int micon_probe (struct platform_device *pdev) +{ +struct micon_platform_data *pdata = pdev->dev.platform_data; +struct micon_priv *priv; +struct resource *r; +int ret; + +if (!pdata) +return -ENODEV ; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->dev = &pdev->dev; + r =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + +/* Don't request exclusive access since 8250 may also utilize this +* resource +*/ + priv->base =devm_ioremap (&pdev->dev, r->start,resource_size (r)); +if (IS_ERR (priv->base)) +return -ENOMEM ; + + priv->tclk = pdata->tclk; + + priv->nb.notifier_call = restart_handler; + +return register_reboot_notifier (&priv->nb); +} + +static struct platform_driver micon_driver = { + .probe = micon_probe, + .driver = { + .name =MICON_NAME , + }, +}; +builtin_platform_driver (micon_driver);include/linux/platform_data/micon.h new file +10
-0@@ -0,0 +1,10 @@ +#ifndef __MICON_PDATA_H +#define __MICON_PDATA_H + +#define MICON_NAME "micon" + +struct micon_platform_data { +int tclk; +}; + +#endif /* __MICON_PDATA_H */
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH 1/2] mfd: micon: Add Buffalo Kurobox Pro, Terastation II Pro/Live driver
Le 01/04/17 ? 03:22, Lee Jones a ?crit :
Quoted 11 lines · Florian Fainelli
Quoted 6 lines
This driver is currently only used to reboot the devices, but the microcontroller hanging off UART1 on the Buffalo Kurobox Pro and Terastation II Pro/Live is capable of a lot more than that, which we will support in subsequent patches. For now, just add the reboot functionality to make the kernel reboot correctly.
This is not an MFD driver. You have written a UART driver.
Please relocate it to
drivers/char/tty/serial.
Not that simple, and as explained in the cover letter the UART attached micro controller can do a lot more than just reboot the machine, but someone else is working on the driver, so this patch series can be ignored.
Signature · 1 line
Florian
Re: [PATCH 1/2] mfd: micon: Add Buffalo Kurobox Pro, Terastation II Pro/Live driver
Quoted 9 lines · Florian Fainelli
Quoted 8 lines · Lee Jones
Quoted 5 lines · Florian Fainelli
This driver is currently only used to reboot the devices, but the microcontroller hanging off UART1 on the Buffalo Kurobox Pro and Terastation II Pro/Live is capable of a lot more than that, which we will support in subsequent patches. For now, just add the reboot functionality to make the kernel reboot correctly.
Quoted 6 lines
Quoted 3 lines
This is not an MFD driver. You have written a UART driver.
Please relocate it to
drivers/char/tty/serial.Not that simple, and as explained in the cover letter the UART attached micro controller can do a lot more than just reboot the machine, but
That's fine. This is precisely why we have MFD. But the core (MFD) driver should only conduct set-up of shared resources, registration of child devices and maybe some shared functionality required by >1 child device. All child device (i.e. UART) capability should be handled by the child drivers.
Quoted 1 line
someone else is working on the driver, so this patch series can be ignored.
Okay.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 2/2 ARM: orion5x: Utilize micon MFD driver
In reply to Florian FainelliConvert the Kurobox Pro and Terastation Pro II/Live machines to utilize the MFD_MICON driver which currently provides reboot support, but will later be extended to support LEDs, buttons, FAN control and temperature.
--- arch/arm/mach-orion5x/Kconfig | 4 + arch/arm/mach-orion5x/kurobox_pro-setup.c | 149 +++---------------------- arch/arm/mach-orion5x/terastation_pro2-setup.c | 149 +++---------------------- 3 files changed, 40 insertions(+), 262 deletions(-)
arch/arm/mach-orion5x/Kconfig +4 -0
@@ -51,6 +51,8 @@ config MACH_RD88F5182_DT config MACH_KUROBOX_PRO bool "KuroBox Pro" select I2C_BOARDINFO if I2C + select MFD_CORE + select MFD_MICON help Say 'Y' here if you want your kernel to support the KuroBox Pro platform.
@@ -71,6 +73,8 @@ config MACH_TS209 QNAP TS-109/TS-209 platform. config MACH_TERASTATION_PRO2 + select MFD_CORE + select MFD_MICON bool "Buffalo Terastation Pro II/Live" help Say 'Y' here if you want your kernel to support the
arch/arm/mach-orion5x/kurobox_pro-setup.c +18 -131
175 lines not on this page · raw message
arch/arm/mach-orion5x/terastation_pro2-setup.c +18 -131
175 lines not on this page · raw message
Signature · 1 line
2.9.3
Andrew Lunn
maintainerQuoted 8 lines · Florian Fainelli
Hi all,
This patch series removes some duplicate code between the Kurobox and the Terastation Pro 2 since they both use the same on-board microcontroller (micon) attached to their UART1 for system restart.
Future patches will add support for the LEDs, temperature, FAN that the micro controller provides.
Hi Florian
Are you coordinating with Roger Shimizu <[email protected]>. He has a conflicting patchset doing something similar/different.
Andrew