ZII RAVE platform driver
Subsystems (6)
v10 cover ZII RAVE platform driver
Hi everyone,
This patch series is v10 of the driver for supervisory processor found on RAVE series of devices from ZII. Supervisory processor is a PIC microcontroller connected to various electrical subsystems on RAVE devices whose firmware implements protocol to command/qery them.
NOTE:
* This driver dependends on crc_ccitt_false(), added by 2da9378d531f8cc6670c7497f20d936b706ab80b in 'linux-next', the patch was pulled in by Andrew Morton and is currently avaiting users, so this series might have to go in through Andrew's tree
Changes since [v9]:
- Converted watchdog driver to use watchdog_active() instead of watchdog_hw_running() and replaced WARN_ON with a regular error message as per feedback from Guenter
- Changed rave_sp_wdt_start() to set WDOG_HW_RUNNING only if communicating with hardware was sucessful
- Collected Reviewd-by from Sebastian (for serdev related patches)
- Collected Acked-by from Rob (for watchdog DT bindings)
Changes since [v8]:
- Driver moved from drivers/platform to drivers/mfd
- Collected Reviewed-by from Guenter (for patches 1, 2 and 3)
- Incorporated feedback from Guenter into watchdog driver
- Incorporated feedback from Rob into watchdog DT bindings
- Removed struct rave_sp_rsp_status, which was a leftover from v5 -> v6 code removal.
- Fixed minor problems reported by checkpatch
Changes since [v7]:
- Added watchdog driver to the patchset, so it would be easier to understand how parent/children drivers are tied together
- Added serdev patches to implement devm_serdev_device_open() and make .remove optional
- "Added" missing serdev_device_close() by converting the driver to use devm_serdev_device_open()
- Converted the driver to use devm_of_platform_populate()
- Removed needless dependency on MFD_CORE
- Removed dependency on SERIAL_DEV_CTRL_TTYPORT
Changes since [v6]:
- Patch 2/2 has been applied by Lee so it is no longer a part of the series
- Removed all sysfs and debugfs attribute to reduce the scope of the driver propsed for inclusion. This is not a critical to have feature and can be added/discussed later.
Changes since [v5]:
- Fixed a build break, introduced by a last minute change in [v5]
- Moved majority of attributes that were exposed over sysfs to debugfs
- Document remaining sysfs attributes in Documentation/ABI/testing/sysfs-platform-rave-sp
Changes since [v4]:
- Replaced usage of DEVICE_ATTR with DEVICE_ATTR_RW
- Fixed a number of warnings produces by sparse tool
- Incorporated event more feedback from Andy Shevchenko
- Collected Reviewed-by from Andy
Changes since [v3]:
- Re-collected lost Acked-by from Rob
- Incorporated further feedback from Andy Shevchenko
- Dropped useless change (stray newline) to drivers/mfd/Makefile
Changes since [v2]:
- Fixed swapped command codes in rave_sp_common_get_boot_source() and rave_sp_common_set_boot_source() revealed by further testing of the code
- Incorporated feedback from Andy Shevchenko
Changes since [v1]:
- Updated wording in DT-bindings as per Rob's request.
- Collected Rob's Acked-by for patch 2/2
Feedback is greatly appreciated!
Thanks,
Andrey Smirnov
[v9] lkml.kernel.org/r/20171025190421.18415-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v8] lkml.kernel.org/r/20171018170136.12347-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v7] lkml.kernel.org/r/20171013061321.31252-2-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v6] lkml.kernel.org/r/20170828163131.24815-2-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v5] lkml.kernel.org/r/20170728142704.11156-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v4] lkml.kernel.org/r/20170725184450.13171-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v3] lkml.kernel.org/r/20170724150915.4824-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v2] lkml.kernel.org/r/20170718175604.11735-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [v1] lkml.kernel.org/r/20170710170449.4544-1-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Andrey Smirnov (5):
serdev: Make .remove in struct serdev_device_driver optional
serdev: Introduce devm_serdev_device_open()
mfd: Add driver for RAVE Supervisory Processor
watchdog: Add RAVE SP watchdog driver
dt-bindings: watchdog: Add bindings for RAVE SP watchdog driver
.../bindings/watchdog/zii,rave-sp-wdt.txt | 39 ++ Documentation/driver-model/devres.txt | 3 + drivers/mfd/Kconfig | 9 + drivers/mfd/Makefile | 2 + drivers/mfd/rave-sp.c | 659 +++++++++++++++++++++ drivers/platform/Kconfig | 1 + drivers/tty/serdev/core.c | 31 +- drivers/watchdog/Kconfig | 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/rave-sp-wdt.c | 349 +++++++++++ include/linux/rave-sp.h | 54 ++ include/linux/serdev.h | 1 + 12 files changed, 1154 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/watchdog/zii,rave-sp-wdt.txt create mode 100644 drivers/mfd/rave-sp.c create mode 100644 drivers/watchdog/rave-sp-wdt.c create mode 100644 include/linux/rave-sp.h
Signature · 6 lines
2.13.6 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v10 1/5 serdev: Make .remove in struct serdev_device_driver optional
Using devres infrastructure it is possible to write a serdev driver that doesn't have any code that needs to be called as a part of .remove. Add code to make .remove optional.
--- drivers/tty/serdev/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serdev/core.c +2 -2
@@ -252,8 +252,8 @@ static int serdev_drv_probe(struct device *dev)static int serdev_drv_remove (struct device *dev) {const struct serdev_device_driver *sdrv =to_serdev_device_driver (dev->driver); - - sdrv->remove (to_serdev_device (dev)); +if (sdrv->remove) + sdrv->remove (to_serdev_device (dev));return 0 ; }
Signature · 1 line
2.13.6
PATCH v10 2/5 serdev: Introduce devm_serdev_device_open()
In reply to Andrey SmirnovAdd code implementing managed version of serdev_device_open() for serdev device drivers that "open" the device during driver's lifecycle only once (e.g. opened in .probe() and closed in .remove()).
--- Documentation/driver-model/devres.txt | 3 +++ drivers/tty/serdev/core.c | 27 +++++++++++++++++++++++++++ include/linux/serdev.h | 1 + 3 files changed, 31 insertions(+)
Documentation/driver-model/devres.txt +3 -0
@@ -383,6 +383,9 @@ RESET devm_reset_control_get() devm_reset_controller_register() +SERDEV + devm_serdev_device_open() + SLAVE DMA ENGINE devm_acpi_dma_controller_register()
drivers/tty/serdev/core.c +27 -0
@@ -116,6 +116,33 @@ void serdev_device_close(struct serdev_device *serdev) }EXPORT_SYMBOL_GPL (serdev_device_close); +static void devm_serdev_device_release (struct device *dev,void *dr) +{ +serdev_device_close (*(struct serdev_device **)dr); +} + +int devm_serdev_device_open (struct device *dev,struct serdev_device *serdev) +{ +struct serdev_device **dr; +int ret; + + dr =devres_alloc (devm_serdev_device_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =serdev_device_open (serdev); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = serdev; +devres_add (dev, dr); + +return ret; +} +EXPORT_SYMBOL_GPL (devm_serdev_device_open); +void serdev_device_write_wakeup (struct serdev_device *serdev) {complete (&serdev->write_comp);
include/linux/serdev.h +1 -0
@@ -193,6 +193,7 @@ static inline int serdev_controller_receive_buf(struct serdev_controller *ctrl,int serdev_device_open (struct serdev_device *);void serdev_device_close (struct serdev_device *); +int devm_serdev_device_open (struct device *,struct serdev_device *);unsigned int serdev_device_set_baudrate (struct serdev_device *,unsigned int );void serdev_device_set_flow_control (struct serdev_device *,bool );int serdev_device_write_buf (struct serdev_device *,const unsigned char *,size_t );
Signature · 1 line
2.13.6
PATCH v10 4/5 watchdog: Add RAVE SP watchdog driver
In reply to Andrey SmirnovThis driver provides access to RAVE SP watchdog functionality.
--- drivers/watchdog/Kconfig | 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/rave-sp-wdt.c | 349 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 drivers/watchdog/rave-sp-wdt.c
drivers/watchdog/Kconfig +7 -0
@@ -223,6 +223,13 @@ config ZIIRAVE_WATCHDOG To compile this driver as a module, choose M here: the module will be called ziirave_wdt. +config RAVE_SP_WATCHDOG + tristate "RAVE SP Watchdog timer" + depends on RAVE_SP_CORE + select WATCHDOG_CORE + help + Support for the watchdog on RAVE SP device. + # ALPHA Architecture # ARM Architecture
drivers/watchdog/Makefile +1 -0
@@ -223,3 +223,4 @@ obj-$(CONFIG_MAX77620_WATCHDOG) += max77620_wdt.o obj-$(CONFIG_ZIIRAVE_WATCHDOG) += ziirave_wdt.o obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o +obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
drivers/watchdog/rave-sp-wdt.c new file +349 -0
349 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v10 5/5 dt-bindings: watchdog: Add bindings for RAVE SP watchdog driver
In reply to Andrey SmirnovAdd Device Tree bindings for RAVE SP watchdog drvier - an MFD cell of parent RAVE SP driver (documented in Documentation/devicetree/bindings/mfd/zii,rave-sp.txt).
--- .../bindings/watchdog/zii,rave-sp-wdt.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/zii,rave-sp-wdt.txt
Documentation/devicetree/bindings/watchdog/zii,rave-sp-wdt.txt new file +39 -0
@@ -0,0 +1,39 @@ +Zodiac Inflight Innovations RAVE Supervisory Processor Watchdog Bindings + +RAVE SP watchdog device is a "MFD cell" device corresponding to +watchdog functionality of RAVE Supervisory Processor. It is expected +that its Device Tree node is specified as a child of the node +corresponding to the parent RAVE SP device (as documented in +Documentation/devicetree/bindings/mfd/zii,rave-sp.txt) + +Required properties: +- compatible: Should be "zii,rave-sp-watchdog" + +Optional properties: + +- wdt-timeout: Two byte nvmem cell specified as per + Documentation/devicetree/bindings/nvmem/nvmem.txt + +Example: + + rave-sp { + compatible = "zii,rave-sp-rdu1"; + current-speed = <38400>; + + eeprom { + compatible = "zii,pic-main-eeprom"; + #address-cells = <1>; + #size-cells = <1>; + + wdt_timeout: wdt-timeout@8E { + reg = <0x8E 2>; + }; + }; + + watchdog { + compatible = "zii,rave-sp-watchdog"; + nvmem-cells = <&wdt_timeout>; + nvmem-cell-names = "wdt-timeout"; + }; + } +
Signature · 1 line
2.13.6
PATCH v10 3/5 mfd: Add driver for RAVE Supervisory Processor
In reply to Andrey SmirnovAdd a driver for RAVE Supervisory Processor, an MCU implementing various bits of housekeeping functionality (watchdoging, backlight control, LED control, etc) on RAVE family of products by Zodiac Inflight Innovations.
This driver implementes core MFD/serdev device as well as communication subroutines necessary for commanding the device.
--- drivers/mfd/Kconfig | 9 + drivers/mfd/Makefile | 2 + drivers/mfd/rave-sp.c | 659 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/platform/Kconfig | 1 + include/linux/rave-sp.h | 54 ++++ 5 files changed, 725 insertions(+) create mode 100644 drivers/mfd/rave-sp.c create mode 100644 include/linux/rave-sp.h
drivers/mfd/Kconfig +9 -0
@@ -1818,4 +1818,13 @@ config MFD_VEXPRESS_SYSREG on the ARM Ltd. Versatile Express board. endmenu + +config RAVE_SP_CORE + tristate "RAVE SP MCU core driver" + depends on SERIAL_DEV_BUS + select CRC_CCITT + help + Select this to get support for the Supervisory Processor + device found on several devices in RAVE line of hardware. + endif
drivers/mfd/Makefile +2 -0
@@ -226,3 +226,5 @@ obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o obj-$(CONFIG_MFD_STM32_LPTIMER) += stm32-lptimer.o obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o obj-$(CONFIG_MFD_MXS_LRADC) += mxs-lradc.o + +obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o
drivers/mfd/rave-sp.c new file +659 -0
659 lines not on this page · raw message
drivers/platform/Kconfig +1 -0
@@ -8,3 +8,4 @@ endif source "drivers/platform/goldfish/Kconfig" source "drivers/platform/chrome/Kconfig" +
include/linux/rave-sp.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [PATCH v10 4/5] watchdog: Add RAVE SP watchdog driver
In reply to Andrey SmirnovQuoted 17 lines · Andrey Smirnov
This driver provides access to RAVE SP watchdog functionality.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 392 lines
--- drivers/watchdog/Kconfig | 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/rave-sp-wdt.c | 349 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 drivers/watchdog/rave-sp-wdt.cdrivers/watchdog/Kconfig +7
-0@@ -223,6 +223,13 @@ config ZIIRAVE_WATCHDOG To compile this driver as a module, choose M here: the module will be called ziirave_wdt. +config RAVE_SP_WATCHDOG + tristate "RAVE SP Watchdog timer" + depends on RAVE_SP_CORE + select WATCHDOG_CORE + help + Support for the watchdog on RAVE SP device. + # ALPHA Architecture # ARM Architecturedrivers/watchdog/Makefile +1
-0@@ -223,3 +223,4 @@ obj-$(CONFIG_MAX77620_WATCHDOG) += max77620_wdt.o obj-$(CONFIG_ZIIRAVE_WATCHDOG) += ziirave_wdt.o obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o +obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.odrivers/watchdog/rave-sp-wdt.c new file +349
-0@@ -0,0 +1,349 @@ +/* +* rave-sp-wdt.c - Watchdog driver present in RAVE SP +* +* Copyright (C) 2017 Zodiac Inflight Innovation +* +* Driver for parent device can be found in drivers/mfd/rave-sp.c +* +* 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. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/nvmem-consumer.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/rave-sp.h> +#include <linux/reboot.h> +#include <linux/slab.h> +#include <linux/watchdog.h> + +enum { +RAVE_SP_RESET_BYTE =1 , +RAVE_SP_RESET_REASON_NORMAL =0 , +RAVE_SP_RESET_DELAY_MS =500 , +}; + +/** +* struct rave_sp_wdt_variant - RAVE SP watchdog variant +* +* @max_timeout: Largest possible watchdog timeout setting +* @min_timeout: Smallest possible watchdog timeout setting +* +* @configure: Function to send configuration command +* @restart: Function to send "restart" command +*/ +struct rave_sp_wdt_variant { +unsigned int max_timeout; +unsigned int min_timeout; + +int (*configure)(struct watchdog_device *,bool ); +int (*restart)(struct watchdog_device *); +}; + +/** +* struct rave_sp_wdt - RAVE SP watchdog +* +* @wdd: Underlying watchdog device +* @sp: Pointer to parent RAVE SP device +* @variant: Device specific variant information +* @reboot_notifier: Reboot notifier implementing machine reset +*/ +struct rave_sp_wdt { +struct watchdog_device wdd; +struct rave_sp *sp; +const struct rave_sp_wdt_variant *variant; +struct notifier_block reboot_notifier; +}; + +static struct rave_sp_wdt *to_rave_sp_wdt (struct watchdog_device *wdd) +{ + return container_of(wdd, struct rave_sp_wdt, wdd); +} + +static int rave_sp_wdt_exec (struct watchdog_device *wdd,void *data, +size_t data_size) +{ +return rave_sp_exec (to_rave_sp_wdt (wdd)->sp, + data, data_size,NULL ,0 ); +} + +static int rave_sp_wdt_legacy_configure (struct watchdog_device *wdd,bool on) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_SW_WDT , + [1 ] =0 , + [2 ] =0 , + [3 ] = on, + [4 ] = on ? wdd->timeout :0 , + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_rdu_configure (struct watchdog_device *wdd,bool on) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_SW_WDT , + [1 ] =0 , + [2 ] = on, + [3 ] = (u8 )wdd->timeout, + [4 ] = (u8)(wdd->timeout >>8 ), + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +/** +* rave_sp_wdt_configure - Configure watchdog device +* +* @wdd: Device to configure +* @on: Desired state of the watchdog timer (ON/OFF) +* +* This function configures two aspects of the watchdog timer: +* +* - Wheither it is ON or OFF +* - Its timeout duration +* +* with first aspect specified via function argument and second via +* the value of 'wdd->timeout'. +*/ +static int rave_sp_wdt_configure (struct watchdog_device *wdd,bool on) +{ +return to_rave_sp_wdt (wdd)->variant->configure (wdd, on); +} + +static int rave_sp_wdt_legacy_restart (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_RESET , + [1 ] =0 , + [2 ] =RAVE_SP_RESET_BYTE + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_rdu_restart (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_RESET , + [1 ] =0 , + [2 ] =RAVE_SP_RESET_BYTE , + [3 ] =RAVE_SP_RESET_REASON_NORMAL + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_reboot_notifier (struct notifier_block *nb, +unsigned long action,void *data) +{ +/* +* Restart handler is called in atomic context which means we +* can't communicate to SP via UART. Luckily for use SP will +* wait 500ms before actually resetting us, so we ask it to do +* so here and let the rest of the system go on wrapping +* things up. +*/ +if (action ==SYS_DOWN || action ==SYS_HALT ) { +struct rave_sp_wdt *sp_wd = + container_of(nb, struct rave_sp_wdt, reboot_notifier); + +const int ret = sp_wd->variant->restart (&sp_wd->wdd); + +if (ret <0 ) +dev_err (sp_wd->wdd.parent, +"Failed to issue restart command (%d)" , ret); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} + +static int rave_sp_wdt_restart (struct watchdog_device *wdd, +unsigned long action,void *data) +{ +/* +* The actual work was done by reboot notifier above. SP +* firmware waits 500 ms before issuing reset, so let's hang +* here for twice that delay and hopefuly we'd never reach +* the return statement. +*/ +mdelay (2 *RAVE_SP_RESET_DELAY_MS ); + +return -EIO ; +} + +static int rave_sp_wdt_start (struct watchdog_device *wdd) +{ +int ret; + + ret =rave_sp_wdt_configure (wdd, true); +if (!ret) +set_bit (WDOG_HW_RUNNING , &wdd->status); + +return ret; +} + +static int rave_sp_wdt_stop (struct watchdog_device *wdd) +{ +return rave_sp_wdt_configure (wdd, false); +} + +static int rave_sp_wdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ + wdd->timeout = timeout; + +return rave_sp_wdt_configure (wdd,watchdog_active (wdd)); +} + +static int rave_sp_wdt_ping (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_PET_WDT , + [1 ] =0 , + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static const struct watchdog_info rave_sp_wdt_info = { + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE , + .identity ="RAVE SP Watchdog" , +}; + +static const struct watchdog_ops rave_sp_wdt_ops = { + .owner =THIS_MODULE , + .start = rave_sp_wdt_start, + .stop = rave_sp_wdt_stop, + .ping = rave_sp_wdt_ping, + .set_timeout = rave_sp_wdt_set_timeout, + .restart = rave_sp_wdt_restart, +}; + +static const struct of_device_id rave_sp_wdt_of_match[] = { + { .compatible ="zii,rave-sp-watchdog" }, + {} +}; + +static const struct rave_sp_wdt_variant rave_sp_wdt_legacy = { + .max_timeout =255 , + .min_timeout =1 , + .configure = rave_sp_wdt_legacy_configure, + .restart = rave_sp_wdt_legacy_restart, +}; + +static const struct rave_sp_wdt_variant rave_sp_wdt_rdu = { + .max_timeout =180 , + .min_timeout =60 , + .configure = rave_sp_wdt_rdu_configure, + .restart = rave_sp_wdt_rdu_restart, +}; + +static const struct of_device_id rave_sp_wdt_variants[] = { + { .compatible =COMPATIBLE_RAVE_SP_NIU , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_MEZZ , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_ESB , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_RDU1 , .data = &rave_sp_wdt_rdu }, + { .compatible =COMPATIBLE_RAVE_SP_RDU2 , .data = &rave_sp_wdt_rdu }, + {/* sentinel */ } +}; + +static int rave_sp_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct of_device_id *id; +struct watchdog_device *wdd; +struct rave_sp_wdt *sp_wd; +struct nvmem_cell *cell; +__le16 timeout =0 ; +int ret; + + id =of_match_device (rave_sp_wdt_variants, dev->parent); +if (!id) { +dev_err (dev,"Unknown parent device variant. Bailing out\n" ); +return -ENODEV ; + } + + sp_wd =devm_kzalloc (dev,sizeof (*sp_wd),GFP_KERNEL ); +if (!sp_wd) +return -ENOMEM ; + + sp_wd->variant = id->data; + sp_wd->sp =dev_get_drvdata (dev->parent); + + wdd = &sp_wd->wdd; + wdd->parent = dev; + wdd->info = &rave_sp_wdt_info; + wdd->ops = &rave_sp_wdt_ops; + wdd->min_timeout = sp_wd->variant->min_timeout; + wdd->max_timeout = sp_wd->variant->max_timeout; + wdd->status =WATCHDOG_NOWAYOUT_INIT_STATUS ; + wdd->timeout =60 ; + + cell =nvmem_cell_get (dev,"wdt-timeout" ); +if (!IS_ERR (cell)) { +size_t len; +void *value =nvmem_cell_read (cell, &len); + +if (!IS_ERR (value)) { +memcpy (&timeout, value,min (len,sizeof (timeout))); +kfree (value); + } +nvmem_cell_put (cell); + } +watchdog_init_timeout (wdd,le16_to_cpu (timeout), dev); +watchdog_set_restart_priority (wdd,255 ); + + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; + ret =devm_register_reboot_notifier (dev, &sp_wd->reboot_notifier); +if (ret) { +dev_err (dev,"Failed to register reboot notifier\n" ); +return ret; + } + +/* +* We don't know if watchdog is running now. To be sure, let's +* start it and depend on watchdog core to ping it +*/ + wdd->max_hw_heartbeat_ms = wdd->max_timeout *1000 ; + ret =rave_sp_wdt_start (wdd); +if (ret) { +dev_err (dev,"Watchdog didn't start\n" ); +return ret; + } + +return devm_watchdog_register_device (dev, wdd); +} + +static struct platform_driver rave_sp_wdt_driver = { + .probe = rave_sp_wdt_probe, + .driver = { + .name =KBUILD_MODNAME , + .of_match_table = rave_sp_wdt_of_match, + }, +}; + +module_platform_driver (rave_sp_wdt_driver); + +MODULE_DEVICE_TABLE (of, rave_sp_wdt_of_match); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Andrey Vostrikov <[email protected]>" ); +MODULE_AUTHOR ("Nikita Yushchenko <[email protected]>" ); +MODULE_AUTHOR ("Andrey Smirnov <[email protected]>" ); +MODULE_DESCRIPTION ("RAVE SP Watchdog driver" ); +MODULE_ALIAS ("platform:rave-sp-watchdog" );Signature · 1 line
2.13.6
Re: [PATCH v10 5/5] dt-bindings: watchdog: Add bindings for RAVE SP watchdog driver
In reply to Andrey SmirnovQuoted 14 lines · Andrey Smirnov
Add Device Tree bindings for RAVE SP watchdog drvier - an MFD cell of parent RAVE SP driver (documented in
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt).Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>
Quoted 8 lines
Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Mark Rutland <[email protected]>Cc Sebastian Reichel <[email protected]>Acked-by Rob Herring <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 53 lines
--- .../bindings/watchdog/zii,rave-sp-wdt.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/zii,rave-sp-wdt.txtDocumentation/devicetree/bindings/watchdog/zii,rave-sp-wdt.txt new file +39
-0@@ -0,0 +1,39 @@ +Zodiac Inflight Innovations RAVE Supervisory Processor Watchdog Bindings + +RAVE SP watchdog device is a "MFD cell" device corresponding to +watchdog functionality of RAVE Supervisory Processor. It is expected +that its Device Tree node is specified as a child of the node +corresponding to the parent RAVE SP device (as documented in +Documentation/devicetree/bindings/mfd/zii,rave-sp.txt) + +Required properties: +- compatible: Should be "zii,rave-sp-watchdog" + +Optional properties: + +- wdt-timeout: Two byte nvmem cell specified as per + Documentation/devicetree/bindings/nvmem/nvmem.txt + +Example: + + rave-sp { + compatible = "zii,rave-sp-rdu1"; + current-speed = <38400>; + + eeprom { + compatible = "zii,pic-main-eeprom"; + #address-cells = <1>; + #size-cells = <1>; + + wdt_timeout: wdt-timeout@8E { + reg = <0x8E 2>; + }; + }; + + watchdog { + compatible = "zii,rave-sp-watchdog"; + nvmem-cells = <&wdt_timeout>; + nvmem-cell-names = "wdt-timeout"; + }; + } +Signature · 1 line
2.13.6
Re: [PATCH v10 2/5] serdev: Introduce devm_serdev_device_open()
In reply to Andrey SmirnovQuoted 20 lines · Andrey Smirnov
Add code implementing managed version of
serdev_device_open()for serdev device drivers that "open" the device during driver's lifecycle only once (e.g. opened in .probe() and closed in .remove()).Cc Rob Herring <[email protected]>Cc Guenter Roeck <[email protected]>Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 5 lines
--- Documentation/driver-model/devres.txt | 3 +++ drivers/tty/serdev/core.c | 27 +++++++++++++++++++++++++++ include/linux/serdev.h | 1 + 3 files changed, 31 insertions(+)
Re: [PATCH v10 1/5] serdev: Make .remove in struct serdev_device_driver optional
In reply to Andrey SmirnovQuoted 20 lines · Andrey Smirnov
Using devres infrastructure it is possible to write a serdev driver that doesn't have any code that needs to be called as a part of .remove. Add code to make .remove optional.
Cc Rob Herring <[email protected]>Cc Guenter Roeck <[email protected]>Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 3 lines
--- drivers/tty/serdev/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Greg Kroah-Hartman
maintainerRe: [PATCH v10 1/5] serdev: Make .remove in struct serdev_device_driver optional
In reply to Andrey SmirnovQuoted 3 lines · Andrey Smirnov
Using devres infrastructure it is possible to write a serdev driver that doesn't have any code that needs to be called as a part of .remove. Add code to make .remove optional.
What about manual unbind from userspace through sysfs? You need to have a remove function. All drivers need that, to not have it is pretty lazy :)
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH v10 4/5] watchdog: Add RAVE SP watchdog driver
In reply to Andrey SmirnovQuoted 381 lines · Andrey Smirnov
This driver provides access to RAVE SP watchdog functionality.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- drivers/watchdog/Kconfig | 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/rave-sp-wdt.c | 349 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 drivers/watchdog/rave-sp-wdt.cdrivers/watchdog/Kconfig +7
-0@@ -223,6 +223,13 @@ config ZIIRAVE_WATCHDOG To compile this driver as a module, choose M here: the module will be called ziirave_wdt. +config RAVE_SP_WATCHDOG + tristate "RAVE SP Watchdog timer" + depends on RAVE_SP_CORE + select WATCHDOG_CORE + help + Support for the watchdog on RAVE SP device. + # ALPHA Architecture # ARM Architecturedrivers/watchdog/Makefile +1
-0@@ -223,3 +223,4 @@ obj-$(CONFIG_MAX77620_WATCHDOG) += max77620_wdt.o obj-$(CONFIG_ZIIRAVE_WATCHDOG) += ziirave_wdt.o obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o +obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.odrivers/watchdog/rave-sp-wdt.c new file +324
-0@@ -0,0 +1,349 @@ +/* +* rave-sp-wdt.c - Watchdog driver present in RAVE SP +* +* Copyright (C) 2017 Zodiac Inflight Innovation +* +* Driver for parent device can be found in drivers/mfd/rave-sp.c +* +* 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. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/nvmem-consumer.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/rave-sp.h> +#include <linux/reboot.h> +#include <linux/slab.h> +#include <linux/watchdog.h> + +enum { +RAVE_SP_RESET_BYTE =1 , +RAVE_SP_RESET_REASON_NORMAL =0 , +RAVE_SP_RESET_DELAY_MS =500 , +}; + +/** +* struct rave_sp_wdt_variant - RAVE SP watchdog variant +* +* @max_timeout: Largest possible watchdog timeout setting +* @min_timeout: Smallest possible watchdog timeout setting +* +* @configure: Function to send configuration command +* @restart: Function to send "restart" command +*/ +struct rave_sp_wdt_variant { +unsigned int max_timeout; +unsigned int min_timeout; + +int (*configure)(struct watchdog_device *,bool ); +int (*restart)(struct watchdog_device *); +}; + +/** +* struct rave_sp_wdt - RAVE SP watchdog +* +* @wdd: Underlying watchdog device +* @sp: Pointer to parent RAVE SP device +* @variant: Device specific variant information +* @reboot_notifier: Reboot notifier implementing machine reset +*/ +struct rave_sp_wdt { +struct watchdog_device wdd; +struct rave_sp *sp; +const struct rave_sp_wdt_variant *variant; +struct notifier_block reboot_notifier; +}; + +static struct rave_sp_wdt *to_rave_sp_wdt (struct watchdog_device *wdd) +{ + return container_of(wdd, struct rave_sp_wdt, wdd); +} + +static int rave_sp_wdt_exec (struct watchdog_device *wdd,void *data, +size_t data_size) +{ +return rave_sp_exec (to_rave_sp_wdt (wdd)->sp, + data, data_size,NULL ,0 ); +} + +static int rave_sp_wdt_legacy_configure (struct watchdog_device *wdd,bool on) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_SW_WDT , + [1 ] =0 , + [2 ] =0 , + [3 ] = on, + [4 ] = on ? wdd->timeout :0 , + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_rdu_configure (struct watchdog_device *wdd,bool on) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_SW_WDT , + [1 ] =0 , + [2 ] = on, + [3 ] = (u8 )wdd->timeout, + [4 ] = (u8)(wdd->timeout >>8 ), + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +/** +* rave_sp_wdt_configure - Configure watchdog device +* +* @wdd: Device to configure +* @on: Desired state of the watchdog timer (ON/OFF) +* +* This function configures two aspects of the watchdog timer: +* +* - Wheither it is ON or OFF +* - Its timeout duration +* +* with first aspect specified via function argument and second via +* the value of 'wdd->timeout'. +*/ +static int rave_sp_wdt_configure (struct watchdog_device *wdd,bool on) +{ +return to_rave_sp_wdt (wdd)->variant->configure (wdd, on); +} + +static int rave_sp_wdt_legacy_restart (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_RESET , + [1 ] =0 , + [2 ] =RAVE_SP_RESET_BYTE + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_rdu_restart (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_RESET , + [1 ] =0 , + [2 ] =RAVE_SP_RESET_BYTE , + [3 ] =RAVE_SP_RESET_REASON_NORMAL + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_reboot_notifier (struct notifier_block *nb, +unsigned long action,void *data) +{ +/* +* Restart handler is called in atomic context which means we +* can't communicate to SP via UART. Luckily for use SP will +* wait 500ms before actually resetting us, so we ask it to do +* so here and let the rest of the system go on wrapping +* things up. +*/ +if (action ==SYS_DOWN || action ==SYS_HALT ) { +struct rave_sp_wdt *sp_wd = + container_of(nb, struct rave_sp_wdt, reboot_notifier); + +const int ret = sp_wd->variant->restart (&sp_wd->wdd); + +if (ret <0 ) +dev_err (sp_wd->wdd.parent, +"Failed to issue restart command (%d)" , ret); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} + +static int rave_sp_wdt_restart (struct watchdog_device *wdd, +unsigned long action,void *data) +{ +/* +* The actual work was done by reboot notifier above. SP +* firmware waits 500 ms before issuing reset, so let's hang +* here for twice that delay and hopefuly we'd never reach +* the return statement. +*/ +mdelay (2 *RAVE_SP_RESET_DELAY_MS ); + +return -EIO ; +} + +static int rave_sp_wdt_start (struct watchdog_device *wdd) +{ +int ret; + + ret =rave_sp_wdt_configure (wdd, true); +if (!ret) +set_bit (WDOG_HW_RUNNING , &wdd->status); + +return ret; +} + +static int rave_sp_wdt_stop (struct watchdog_device *wdd) +{ +return rave_sp_wdt_configure (wdd, false); +} + +static int rave_sp_wdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ + wdd->timeout = timeout; + +return rave_sp_wdt_configure (wdd,watchdog_active (wdd)); +} + +static int rave_sp_wdt_ping (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_PET_WDT , + [1 ] =0 , + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static const struct watchdog_info rave_sp_wdt_info = { + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE , + .identity ="RAVE SP Watchdog" , +}; + +static const struct watchdog_ops rave_sp_wdt_ops = { + .owner =THIS_MODULE , + .start = rave_sp_wdt_start, + .stop = rave_sp_wdt_stop, + .ping = rave_sp_wdt_ping, + .set_timeout = rave_sp_wdt_set_timeout, + .restart = rave_sp_wdt_restart, +}; + +static const struct of_device_id rave_sp_wdt_of_match[] = { + { .compatible ="zii,rave-sp-watchdog" }, + {} +}; + +static const struct rave_sp_wdt_variant rave_sp_wdt_legacy = { + .max_timeout =255 , + .min_timeout =1 , + .configure = rave_sp_wdt_legacy_configure, + .restart = rave_sp_wdt_legacy_restart, +}; + +static const struct rave_sp_wdt_variant rave_sp_wdt_rdu = { + .max_timeout =180 , + .min_timeout =60 , + .configure = rave_sp_wdt_rdu_configure, + .restart = rave_sp_wdt_rdu_restart, +}; + +static const struct of_device_id rave_sp_wdt_variants[] = { + { .compatible =COMPATIBLE_RAVE_SP_NIU , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_MEZZ , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_ESB , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_RDU1 , .data = &rave_sp_wdt_rdu }, + { .compatible =COMPATIBLE_RAVE_SP_RDU2 , .data = &rave_sp_wdt_rdu }, + {/* sentinel */ } +}; + +static int rave_sp_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct of_device_id *id; +struct watchdog_device *wdd; +struct rave_sp_wdt *sp_wd; +struct nvmem_cell *cell; +__le16 timeout =0 ; +int ret; + + id =of_match_device (rave_sp_wdt_variants, dev->parent); +if (!id) { +dev_err (dev,"Unknown parent device variant. Bailing out\n" ); +return -ENODEV ; + } + + sp_wd =devm_kzalloc (dev,sizeof (*sp_wd),GFP_KERNEL ); +if (!sp_wd) +return -ENOMEM ; + + sp_wd->variant = id->data; + sp_wd->sp =dev_get_drvdata (dev->parent); + + wdd = &sp_wd->wdd; + wdd->parent = dev; + wdd->info = &rave_sp_wdt_info; + wdd->ops = &rave_sp_wdt_ops; + wdd->min_timeout = sp_wd->variant->min_timeout; + wdd->max_timeout = sp_wd->variant->max_timeout; + wdd->status =WATCHDOG_NOWAYOUT_INIT_STATUS ; + wdd->timeout =60 ; + + cell =nvmem_cell_get (dev,"wdt-timeout" ); +if (!IS_ERR (cell)) { +size_t len; +void *value =nvmem_cell_read (cell, &len); + +if (!IS_ERR (value)) { +memcpy (&timeout, value,min (len,sizeof (timeout))); +kfree (value); + } +nvmem_cell_put (cell); + } +watchdog_init_timeout (wdd,le16_to_cpu (timeout), dev); +watchdog_set_restart_priority (wdd,255 ); + + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; + ret =devm_register_reboot_notifier (dev, &sp_wd->reboot_notifier); +if (ret) { +dev_err (dev,"Failed to register reboot notifier\n" ); +return ret; + } + +/* +* We don't know if watchdog is running now. To be sure, let's +* start it and depend on watchdog core to ping it +*/ + wdd->max_hw_heartbeat_ms = wdd->max_timeout *1000 ; + ret =rave_sp_wdt_start (wdd);
drivers/watchdog/rave-sp-wdt.c line 334
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+if (ret) { +dev_err (dev,"Watchdog didn't start\n" ); +return ret; + } + +return devm_watchdog_register_device (dev, wdd); +} + +static struct platform_driver rave_sp_wdt_driver = { + .probe = rave_sp_wdt_probe,
No remove? :)
Re: [PATCH v10 1/5] serdev: Make .remove in struct serdev_device_driver optional
In reply to Greg Kroah-HartmanHi Greg,
Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Andrey Smirnov
Using devres infrastructure it is possible to write a serdev driver that doesn't have any code that needs to be called as a part of .remove. Add code to make .remove optional.
What about manual unbind from userspace through sysfs? You need to have a remove function. All drivers need that, to not have it is pretty lazy :)
Resources,that have been requested via devres are free'd by the devres framework after the driver specific remove function. This also works for manual unbind.
If *all* driver resources are allocated using devres, you will end up with an empty remove function. In that case it makes sense to remove it completly. This is what quite a few (mainline) i2c and spi drivers actually do.
-- Sebastian
Re: [PATCH v10 3/5] mfd: Add driver for RAVE Supervisory Processor
In reply to Andrey SmirnovQuoted 61 lines · Andrey Smirnov
Add a driver for RAVE Supervisory Processor, an MCU implementing various bits of housekeeping functionality (watchdoging, backlight control, LED control, etc) on RAVE family of products by Zodiac Inflight Innovations.
This driver implementes core MFD/serdev device as well as communication subroutines necessary for commanding the device.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Tested-by Chris Healy <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
drivers/mfd/rave-sp.c new file +35
-0+int rave_sp_exec (struct rave_sp *sp, +void *__data,size_t data_size, +void *reply_data,size_t reply_data_size) +{ +struct rave_sp_reply reply = { + .data = reply_data, + .length = reply_data_size, + .received =COMPLETION_INITIALIZER_ONSTACK (reply.received), + }; +unsigned char *data = __data; +int command, ret =0 ; +u8 ackid; + + command = sp->variant->cmd.translate (data[0 ]); +if (command <0 ) +return command; + + ackid =atomic_inc_return (&sp->ackid); + reply.ackid = ackid; + reply.code =rave_sp_reply_code ((u8 )command), + +mutex_lock (&sp->bus_lock); + +mutex_lock (&sp->reply_lock); + sp->reply = &reply; +mutex_unlock (&sp->reply_lock); + + data[0 ] = command; + data[1 ] = ackid; + +rave_sp_write (sp, data, data_size); + +if (!wait_for_completion_timeout (&reply.received,HZ )) { +dev_err (&sp->serdev->dev,"Command timeout\n" ); + ret = -ETIMEDOUT ;
drivers/mfd/rave-sp.c line 369
Quoted 10 lines
drivers/mfd/rave-sp.c new file +10
-0+ +mutex_lock (&sp->reply_lock); + sp->reply =NULL ; +mutex_unlock (&sp->reply_lock); + } + +mutex_unlock (&sp->bus_lock); +return ret; +} +EXPORT_SYMBOL (rave_sp_exec);
EXPORT_SYMBOL_GPL?
Quoted 27 lines
drivers/mfd/rave-sp.c new file +27
-0+static int rave_sp_receive_buf (struct serdev_device *serdev, +const unsigned char *buf,size_t size) +{ +struct device *dev = &serdev->dev; +struct rave_sp *sp =dev_get_drvdata (dev); +struct rave_sp_deframer *deframer = &sp->deframer; +const unsigned char *src = buf; +const unsigned char *end = buf + size; +bool reset_framer = false; + +while (src < end) { +const unsigned char byte = *src++; + +switch (deframer->state) { +case RAVE_SP_EXPECT_SOF : +if (byte ==RAVE_SP_STX ) + deframer->state =RAVE_SP_EXPECT_DATA ; +continue ; + +case RAVE_SP_EXPECT_DATA : +switch (byte) { +case RAVE_SP_ETX : +rave_sp_receive_frame (sp, + deframer->data, + deframer->length); + reset_framer = true; +break ;
drivers/mfd/rave-sp.c line 488
Quoted 10 lines
drivers/mfd/rave-sp.c new file +10
-0+case RAVE_SP_STX : +dev_warn (dev,"Bad frame: STX before ETX\n" ); + reset_framer = true; +break ; +case RAVE_SP_DLE : + deframer->state =RAVE_SP_EXPECT_ESCAPED_DATA ; +continue ; + } + +case RAVE_SP_EXPECT_ESCAPED_DATA :/* FALLTHROUGH */
The fallthrough comment should precede the case statement (or you will soon receive a patch from the people working enabling -Wimplicit-fallthrough).
Quoted 12 lines
drivers/mfd/rave-sp.c new file +12
-0+ deframer->data[deframer->length++] = byte; + +if (deframer->length ==sizeof (deframer->data)) { +dev_warn (dev,"Bad frame: Too long\n" ); + reset_framer = true; +break ; + } + + deframer->state =RAVE_SP_EXPECT_DATA ; +break ; + } + }
drivers/mfd/rave-sp.c
Quoted 10 lines
drivers/mfd/rave-sp.c new file +9
-0+ +if (reset_framer) { + deframer->state =RAVE_SP_EXPECT_SOF ; + deframer->length =0 ; + } + +return src - buf; +} +MODULE_LICENSE ("GPL v2" );
This doesn't match the license text (GPL-2.0+).
drivers/platform/Kconfig endif · line 11
Quoted 13 lines
drivers/mfd/rave-sp.c new file +4
-0+MODULE_AUTHOR ("Andrey Vostrikov <[email protected]>" ); +MODULE_AUTHOR ("Nikita Yushchenko <[email protected]>" ); +MODULE_AUTHOR ("Andrey Smirnov <[email protected]>" ); +MODULE_DESCRIPTION ("RAVE SP core driver" );drivers/platform/Kconfig +1
-0@@ -8,3 +8,4 @@ endif source "drivers/platform/goldfish/Kconfig" source "drivers/platform/chrome/Kconfig" +
This chunk should not be here.
include/linux/rave-sp.h
Quoted 5 lines
include/linux/rave-sp.h new file +0
-0
I think this one should live in include/linux/mfd/
Quoted 14 lines
include/linux/rave-sp.h new file +13
-0@@ -0,0 +1,54 @@ +#ifndef _LINUX_RAVE_SP_H_ +#define _LINUX_RAVE_SP_H_ + +enum rave_sp_command { +RAVE_SP_CMD_GET_FIRMWARE_VERSION =0x20 , +RAVE_SP_CMD_GET_BOOTLOADER_VERSION =0x21 , +RAVE_SP_CMD_BOOT_SOURCE =0x26 , +RAVE_SP_CMD_GET_BOARD_COPPER_REV =0x2B , +RAVE_SP_CMD_GET_GPIO_STATE =0x2F , + +RAVE_SP_CMD_STATUS =0xA0 , +RAVE_SP_CMD_SW_WDT =0xA1 , + RAVE_SP_CMD_PET_WDT = 0xA2,
include/linux/rave-sp.h line 23
Quoted 10 lines
include/linux/rave-sp.h new file +10
-0+RAVE_SP_CMD_RESET =0xA7 , +RAVE_SP_CMD_RESET_REASON =0xA8 , + +RAVE_SP_CMD_REQ_COPPER_REV =0xB6 , +RAVE_SP_CMD_GET_I2C_DEVICE_STATUS =0xBA , +RAVE_SP_CMD_GET_SP_SILICON_REV =0xB9 , +RAVE_SP_CMD_CONTROL_EVENTS =0xBB , + + RAVE_SP_EVNT_BASE = 0xE0, +};
Johan
Re: [PATCH v10 2/5] serdev: Introduce devm_serdev_device_open()
In reply to Andrey SmirnovQuoted 35 lines · Andrey Smirnov
Add code implementing managed version of
serdev_device_open()for serdev device drivers that "open" the device during driver's lifecycle only once (e.g. opened in .probe() and closed in .remove()).Cc Rob Herring <[email protected]>Cc Guenter Roeck <[email protected]>Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- Documentation/driver-model/devres.txt | 3 +++ drivers/tty/serdev/core.c | 27 +++++++++++++++++++++++++++ include/linux/serdev.h | 1 + 3 files changed, 31 insertions(+)drivers/tty/serdev/core.c +9
-0+int devm_serdev_device_open (struct device *dev,struct serdev_device *serdev) +{ +struct serdev_device **dr; +int ret; + + dr =devres_alloc (devm_serdev_device_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; +
drivers/tty/serdev/core.c void serdev_device_close(struct serdev_device *serdev) · line 142
Quoted 10 lines
drivers/tty/serdev/core.c +10
-0+ ret =serdev_device_open (serdev); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = serdev; +devres_add (dev, dr); + +return ret;
This would be more readable as return 0.
Review
Quoted 2 lines
(quoted diff) +2
-0+} +EXPORT_SYMBOL_GPL(devm_serdev_device_open);
Johan
Re: [PATCH v10 4/5] watchdog: Add RAVE SP watchdog driver
In reply to Andrey SmirnovQuoted 33 lines · Andrey Smirnov
This driver provides access to RAVE SP watchdog functionality.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>drivers/watchdog/rave-sp-wdt.c new file +14
-0+static const struct of_device_id rave_sp_wdt_of_match[] = { + { .compatible ="zii,rave-sp-watchdog" }, + {} +}; +static const struct of_device_id rave_sp_wdt_variants[] = { + { .compatible =COMPATIBLE_RAVE_SP_NIU , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_MEZZ , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_ESB , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_RDU1 , .data = &rave_sp_wdt_rdu }, + { .compatible =COMPATIBLE_RAVE_SP_RDU2 , .data = &rave_sp_wdt_rdu }, + {/* sentinel */ } +}; + +static int rave_sp_wdt_probe (struct platform_device *pdev)
drivers/watchdog/rave-sp-wdt.c line 276
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+{ +struct device *dev = &pdev->dev; +const struct of_device_id *id; +struct watchdog_device *wdd; +struct rave_sp_wdt *sp_wd; +struct nvmem_cell *cell; +__le16 timeout =0 ; +int ret; + + id =of_match_device (rave_sp_wdt_variants, dev->parent);
So as I already mentioned in a comment on an earlier version of the MFD driver, I find this matching on the parent of_node to be an odd pattern, which also does not seem to have any precedent in mainline.
It seems you really should be using two compatible strings for the watchdog (for the legacy and rdu variants) rather than keep an entry for every parent compatible-string in every child/cell driver (which all need to be kept in sync).
But let's see what Rob and Lee says about this.
Quoted 44 lines
drivers/watchdog/rave-sp-wdt.c new file +44
-0+if (!id) { +dev_err (dev,"Unknown parent device variant. Bailing out\n" ); +return -ENODEV ; + } + + sp_wd =devm_kzalloc (dev,sizeof (*sp_wd),GFP_KERNEL ); +if (!sp_wd) +return -ENOMEM ; + + sp_wd->variant = id->data; + sp_wd->sp =dev_get_drvdata (dev->parent); + + wdd = &sp_wd->wdd; + wdd->parent = dev; + wdd->info = &rave_sp_wdt_info; + wdd->ops = &rave_sp_wdt_ops; + wdd->min_timeout = sp_wd->variant->min_timeout; + wdd->max_timeout = sp_wd->variant->max_timeout; + wdd->status =WATCHDOG_NOWAYOUT_INIT_STATUS ; + wdd->timeout =60 ; + + cell =nvmem_cell_get (dev,"wdt-timeout" ); +if (!IS_ERR (cell)) { +size_t len; +void *value =nvmem_cell_read (cell, &len); + +if (!IS_ERR (value)) { +memcpy (&timeout, value,min (len,sizeof (timeout))); +kfree (value); + } +nvmem_cell_put (cell); + } +watchdog_init_timeout (wdd,le16_to_cpu (timeout), dev); +watchdog_set_restart_priority (wdd,255 ); + + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; + ret =devm_register_reboot_notifier (dev, &sp_wd->reboot_notifier); +if (ret) { +dev_err (dev,"Failed to register reboot notifier\n" ); +return ret; + } + +/* +* We don't know if watchdog is running now. To be sure, let's
drivers/watchdog/rave-sp-wdt.c line 330
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+* start it and depend on watchdog core to ping it +*/ + wdd->max_hw_heartbeat_ms = wdd->max_timeout *1000 ; + ret =rave_sp_wdt_start (wdd); +if (ret) { +dev_err (dev,"Watchdog didn't start\n" ); +return ret; + } + +return devm_watchdog_register_device (dev, wdd);
What about stopping the watchdog on errors here?
And does watchdog core take care of calling stop() on unregister (i.e. at unbind)?
drivers/watchdog/rave-sp-wdt.c line 339
Quoted 9 lines
drivers/watchdog/rave-sp-wdt.c new file +9
-0+} + +static struct platform_driver rave_sp_wdt_driver = { + .probe = rave_sp_wdt_probe, + .driver = { + .name =KBUILD_MODNAME , + .of_match_table = rave_sp_wdt_of_match, + }, +};
Johan
Guenter Roeck
maintainerRe: [PATCH v10 4/5] watchdog: Add RAVE SP watchdog driver
In reply to Greg Kroah-HartmanQuoted 386 lines · Greg Kroah-Hartman
Quoted 385 lines · Andrey Smirnov
This driver provides access to RAVE SP watchdog functionality.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- drivers/watchdog/Kconfig | 7 + drivers/watchdog/Makefile | 1 + drivers/watchdog/rave-sp-wdt.c | 349 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 357 insertions(+)create mode 100644
drivers/watchdog/rave-sp-wdt.cdrivers/watchdog/Kconfig +7
-0@@ -223,6 +223,13 @@ config ZIIRAVE_WATCHDOG To compile this driver as a module, choose M here: the module will be called ziirave_wdt. +config RAVE_SP_WATCHDOG + tristate "RAVE SP Watchdog timer" + depends on RAVE_SP_CORE + select WATCHDOG_CORE + help + Support for the watchdog on RAVE SP device. + # ALPHA Architecture # ARM Architecturedrivers/watchdog/Makefile +1
-0@@ -223,3 +223,4 @@ obj-$(CONFIG_MAX77620_WATCHDOG) += max77620_wdt.o obj-$(CONFIG_ZIIRAVE_WATCHDOG) += ziirave_wdt.o obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o +obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.odrivers/watchdog/rave-sp-wdt.c new file +328
-0@@ -0,0 +1,349 @@ +/* +* rave-sp-wdt.c - Watchdog driver present in RAVE SP +* +* Copyright (C) 2017 Zodiac Inflight Innovation +* +* Driver for parent device can be found in drivers/mfd/rave-sp.c +* +* 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. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/nvmem-consumer.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/rave-sp.h> +#include <linux/reboot.h> +#include <linux/slab.h> +#include <linux/watchdog.h> + +enum { +RAVE_SP_RESET_BYTE =1 , +RAVE_SP_RESET_REASON_NORMAL =0 , +RAVE_SP_RESET_DELAY_MS =500 , +}; + +/** +* struct rave_sp_wdt_variant - RAVE SP watchdog variant +* +* @max_timeout: Largest possible watchdog timeout setting +* @min_timeout: Smallest possible watchdog timeout setting +* +* @configure: Function to send configuration command +* @restart: Function to send "restart" command +*/ +struct rave_sp_wdt_variant { +unsigned int max_timeout; +unsigned int min_timeout; + +int (*configure)(struct watchdog_device *,bool ); +int (*restart)(struct watchdog_device *); +}; + +/** +* struct rave_sp_wdt - RAVE SP watchdog +* +* @wdd: Underlying watchdog device +* @sp: Pointer to parent RAVE SP device +* @variant: Device specific variant information +* @reboot_notifier: Reboot notifier implementing machine reset +*/ +struct rave_sp_wdt { +struct watchdog_device wdd; +struct rave_sp *sp; +const struct rave_sp_wdt_variant *variant; +struct notifier_block reboot_notifier; +}; + +static struct rave_sp_wdt *to_rave_sp_wdt (struct watchdog_device *wdd) +{ + return container_of(wdd, struct rave_sp_wdt, wdd); +} + +static int rave_sp_wdt_exec (struct watchdog_device *wdd,void *data, +size_t data_size) +{ +return rave_sp_exec (to_rave_sp_wdt (wdd)->sp, + data, data_size,NULL ,0 ); +} + +static int rave_sp_wdt_legacy_configure (struct watchdog_device *wdd,bool on) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_SW_WDT , + [1 ] =0 , + [2 ] =0 , + [3 ] = on, + [4 ] = on ? wdd->timeout :0 , + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_rdu_configure (struct watchdog_device *wdd,bool on) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_SW_WDT , + [1 ] =0 , + [2 ] = on, + [3 ] = (u8 )wdd->timeout, + [4 ] = (u8)(wdd->timeout >>8 ), + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +/** +* rave_sp_wdt_configure - Configure watchdog device +* +* @wdd: Device to configure +* @on: Desired state of the watchdog timer (ON/OFF) +* +* This function configures two aspects of the watchdog timer: +* +* - Wheither it is ON or OFF +* - Its timeout duration +* +* with first aspect specified via function argument and second via +* the value of 'wdd->timeout'. +*/ +static int rave_sp_wdt_configure (struct watchdog_device *wdd,bool on) +{ +return to_rave_sp_wdt (wdd)->variant->configure (wdd, on); +} + +static int rave_sp_wdt_legacy_restart (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_RESET , + [1 ] =0 , + [2 ] =RAVE_SP_RESET_BYTE + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_rdu_restart (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_RESET , + [1 ] =0 , + [2 ] =RAVE_SP_RESET_BYTE , + [3 ] =RAVE_SP_RESET_REASON_NORMAL + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static int rave_sp_wdt_reboot_notifier (struct notifier_block *nb, +unsigned long action,void *data) +{ +/* +* Restart handler is called in atomic context which means we +* can't communicate to SP via UART. Luckily for use SP will +* wait 500ms before actually resetting us, so we ask it to do +* so here and let the rest of the system go on wrapping +* things up. +*/ +if (action ==SYS_DOWN || action ==SYS_HALT ) { +struct rave_sp_wdt *sp_wd = + container_of(nb, struct rave_sp_wdt, reboot_notifier); + +const int ret = sp_wd->variant->restart (&sp_wd->wdd); + +if (ret <0 ) +dev_err (sp_wd->wdd.parent, +"Failed to issue restart command (%d)" , ret); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} + +static int rave_sp_wdt_restart (struct watchdog_device *wdd, +unsigned long action,void *data) +{ +/* +* The actual work was done by reboot notifier above. SP +* firmware waits 500 ms before issuing reset, so let's hang +* here for twice that delay and hopefuly we'd never reach +* the return statement. +*/ +mdelay (2 *RAVE_SP_RESET_DELAY_MS ); + +return -EIO ; +} + +static int rave_sp_wdt_start (struct watchdog_device *wdd) +{ +int ret; + + ret =rave_sp_wdt_configure (wdd, true); +if (!ret) +set_bit (WDOG_HW_RUNNING , &wdd->status); + +return ret; +} + +static int rave_sp_wdt_stop (struct watchdog_device *wdd) +{ +return rave_sp_wdt_configure (wdd, false); +} + +static int rave_sp_wdt_set_timeout (struct watchdog_device *wdd, +unsigned int timeout) +{ + wdd->timeout = timeout; + +return rave_sp_wdt_configure (wdd,watchdog_active (wdd)); +} + +static int rave_sp_wdt_ping (struct watchdog_device *wdd) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_PET_WDT , + [1 ] =0 , + }; + +return rave_sp_wdt_exec (wdd, cmd,sizeof (cmd)); +} + +static const struct watchdog_info rave_sp_wdt_info = { + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE , + .identity ="RAVE SP Watchdog" , +}; + +static const struct watchdog_ops rave_sp_wdt_ops = { + .owner =THIS_MODULE , + .start = rave_sp_wdt_start, + .stop = rave_sp_wdt_stop, + .ping = rave_sp_wdt_ping, + .set_timeout = rave_sp_wdt_set_timeout, + .restart = rave_sp_wdt_restart, +}; + +static const struct of_device_id rave_sp_wdt_of_match[] = { + { .compatible ="zii,rave-sp-watchdog" }, + {} +}; + +static const struct rave_sp_wdt_variant rave_sp_wdt_legacy = { + .max_timeout =255 , + .min_timeout =1 , + .configure = rave_sp_wdt_legacy_configure, + .restart = rave_sp_wdt_legacy_restart, +}; + +static const struct rave_sp_wdt_variant rave_sp_wdt_rdu = { + .max_timeout =180 , + .min_timeout =60 , + .configure = rave_sp_wdt_rdu_configure, + .restart = rave_sp_wdt_rdu_restart, +}; + +static const struct of_device_id rave_sp_wdt_variants[] = { + { .compatible =COMPATIBLE_RAVE_SP_NIU , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_MEZZ , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_ESB , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_RDU1 , .data = &rave_sp_wdt_rdu }, + { .compatible =COMPATIBLE_RAVE_SP_RDU2 , .data = &rave_sp_wdt_rdu }, + {/* sentinel */ } +}; + +static int rave_sp_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct of_device_id *id; +struct watchdog_device *wdd; +struct rave_sp_wdt *sp_wd; +struct nvmem_cell *cell; +__le16 timeout =0 ; +int ret; + + id =of_match_device (rave_sp_wdt_variants, dev->parent); +if (!id) { +dev_err (dev,"Unknown parent device variant. Bailing out\n" ); +return -ENODEV ; + } + + sp_wd =devm_kzalloc (dev,sizeof (*sp_wd),GFP_KERNEL ); +if (!sp_wd) +return -ENOMEM ; + + sp_wd->variant = id->data; + sp_wd->sp =dev_get_drvdata (dev->parent); + + wdd = &sp_wd->wdd; + wdd->parent = dev; + wdd->info = &rave_sp_wdt_info; + wdd->ops = &rave_sp_wdt_ops; + wdd->min_timeout = sp_wd->variant->min_timeout; + wdd->max_timeout = sp_wd->variant->max_timeout; + wdd->status =WATCHDOG_NOWAYOUT_INIT_STATUS ; + wdd->timeout =60 ; + + cell =nvmem_cell_get (dev,"wdt-timeout" ); +if (!IS_ERR (cell)) { +size_t len; +void *value =nvmem_cell_read (cell, &len); + +if (!IS_ERR (value)) { +memcpy (&timeout, value,min (len,sizeof (timeout))); +kfree (value); + } +nvmem_cell_put (cell); + } +watchdog_init_timeout (wdd,le16_to_cpu (timeout), dev); +watchdog_set_restart_priority (wdd,255 ); + + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; + ret =devm_register_reboot_notifier (dev, &sp_wd->reboot_notifier); +if (ret) { +dev_err (dev,"Failed to register reboot notifier\n" ); +return ret; + } + +/* +* We don't know if watchdog is running now. To be sure, let's +* start it and depend on watchdog core to ping it +*/ + wdd->max_hw_heartbeat_ms = wdd->max_timeout *1000 ; + ret =rave_sp_wdt_start (wdd); +if (ret) { +dev_err (dev,"Watchdog didn't start\n" ); +return ret; + }
Quoted 9 lines
drivers/watchdog/rave-sp-wdt.c line 334
Quoted 6 lines
drivers/watchdog/rave-sp-wdt.c new file +6
-0+ +return devm_watchdog_register_device (dev, wdd); +} + +static struct platform_driver rave_sp_wdt_driver = { + .probe = rave_sp_wdt_probe,No remove? :)
It would be an empty function.
Guenter
Guenter Roeck
maintainerRe: [PATCH v10 4/5] watchdog: Add RAVE SP watchdog driver
In reply to Johan HovoldQuoted 113 lines · Johan Hovold
Quoted 33 lines · Andrey Smirnov
This driver provides access to RAVE SP watchdog functionality.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>drivers/watchdog/rave-sp-wdt.c new file +14
-0+static const struct of_device_id rave_sp_wdt_of_match[] = { + { .compatible ="zii,rave-sp-watchdog" }, + {} +}; +static const struct of_device_id rave_sp_wdt_variants[] = { + { .compatible =COMPATIBLE_RAVE_SP_NIU , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_MEZZ , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_ESB , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_RDU1 , .data = &rave_sp_wdt_rdu }, + { .compatible =COMPATIBLE_RAVE_SP_RDU2 , .data = &rave_sp_wdt_rdu }, + {/* sentinel */ } +}; + +static int rave_sp_wdt_probe (struct platform_device *pdev)drivers/watchdog/rave-sp-wdt.c line 276
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+{ +struct device *dev = &pdev->dev; +const struct of_device_id *id; +struct watchdog_device *wdd; +struct rave_sp_wdt *sp_wd; +struct nvmem_cell *cell; +__le16 timeout =0 ; +int ret; + + id =of_match_device (rave_sp_wdt_variants, dev->parent);So as I already mentioned in a comment on an earlier version of the MFD driver, I find this matching on the parent
of_nodeto be an odd pattern, which also does not seem to have any precedent in mainline.It seems you really should be using two compatible strings for the watchdog (for the legacy and rdu variants) rather than keep an entry for every parent compatible-string in every child/cell driver (which all need to be kept in sync).
But let's see what Rob and Lee says about this.
Quoted 44 lines
drivers/watchdog/rave-sp-wdt.c new file +44
-0+if (!id) { +dev_err (dev,"Unknown parent device variant. Bailing out\n" ); +return -ENODEV ; + } + + sp_wd =devm_kzalloc (dev,sizeof (*sp_wd),GFP_KERNEL ); +if (!sp_wd) +return -ENOMEM ; + + sp_wd->variant = id->data; + sp_wd->sp =dev_get_drvdata (dev->parent); + + wdd = &sp_wd->wdd; + wdd->parent = dev; + wdd->info = &rave_sp_wdt_info; + wdd->ops = &rave_sp_wdt_ops; + wdd->min_timeout = sp_wd->variant->min_timeout; + wdd->max_timeout = sp_wd->variant->max_timeout; + wdd->status =WATCHDOG_NOWAYOUT_INIT_STATUS ; + wdd->timeout =60 ; + + cell =nvmem_cell_get (dev,"wdt-timeout" ); +if (!IS_ERR (cell)) { +size_t len; +void *value =nvmem_cell_read (cell, &len); + +if (!IS_ERR (value)) { +memcpy (&timeout, value,min (len,sizeof (timeout))); +kfree (value); + } +nvmem_cell_put (cell); + } +watchdog_init_timeout (wdd,le16_to_cpu (timeout), dev); +watchdog_set_restart_priority (wdd,255 ); + + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; + ret =devm_register_reboot_notifier (dev, &sp_wd->reboot_notifier); +if (ret) { +dev_err (dev,"Failed to register reboot notifier\n" ); +return ret; + } + +/* +* We don't know if watchdog is running now. To be sure, let's drivers/watchdog/rave-sp-wdt.c line 330
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+* start it and depend on watchdog core to ping it +*/ + wdd->max_hw_heartbeat_ms = wdd->max_timeout *1000 ; + ret =rave_sp_wdt_start (wdd); +if (ret) { +dev_err (dev,"Watchdog didn't start\n" ); +return ret; + } + +return devm_watchdog_register_device (dev, wdd);What about stopping the watchdog on errors here?
Quoted 3 lines
And does watchdog core take care of calling
stop()on unregister (i.e. at unbind)?
Both good points. This needs watchdog_stop_on_unregister(), and the probe function needs to stop the watchdog if registration fails.
Guenter
Quoted 16 lines
drivers/watchdog/rave-sp-wdt.c line 339
Quoted 9 lines
drivers/watchdog/rave-sp-wdt.c new file +9
-0+} + +static struct platform_driver rave_sp_wdt_driver = { + .probe = rave_sp_wdt_probe, + .driver = { + .name =KBUILD_MODNAME , + .of_match_table = rave_sp_wdt_of_match, + }, +};Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v10 4/5] watchdog: Add RAVE SP watchdog driver
In reply to Johan HovoldQuoted 49 lines · Johan Hovold
Quoted 33 lines · Andrey Smirnov
This driver provides access to RAVE SP watchdog functionality.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Nikita Yushchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>drivers/watchdog/rave-sp-wdt.c new file +14
-0+static const struct of_device_id rave_sp_wdt_of_match[] = { + { .compatible ="zii,rave-sp-watchdog" }, + {} +}; +static const struct of_device_id rave_sp_wdt_variants[] = { + { .compatible =COMPATIBLE_RAVE_SP_NIU , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_MEZZ , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_ESB , .data = &rave_sp_wdt_legacy }, + { .compatible =COMPATIBLE_RAVE_SP_RDU1 , .data = &rave_sp_wdt_rdu }, + { .compatible =COMPATIBLE_RAVE_SP_RDU2 , .data = &rave_sp_wdt_rdu }, + {/* sentinel */ } +}; + +static int rave_sp_wdt_probe (struct platform_device *pdev)drivers/watchdog/rave-sp-wdt.c line 276
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+{ +struct device *dev = &pdev->dev; +const struct of_device_id *id; +struct watchdog_device *wdd; +struct rave_sp_wdt *sp_wd; +struct nvmem_cell *cell; +__le16 timeout =0 ; +int ret; + + id =of_match_device (rave_sp_wdt_variants, dev->parent);So as I already mentioned in a comment on an earlier version of the MFD driver, I find this matching on the parent
of_nodeto be an odd pattern, which also does not seem to have any precedent in mainline.
Quoted 5 lines
It seems you really should be using two compatible strings for the watchdog (for the legacy and rdu variants) rather than keep an entry for every parent compatible-string in every child/cell driver (which all need to be kept in sync).
That's doable, for sure, but the downside is that it opens the door for nonsensical configurations as, for example, "zii,rave-sp-niu" as a parent SP device and "zii,rave-watchdog-rdu" as child watchdog and it forces majority of child device drivers to split their compatibility strings into 2 or more "flavors". My preference was to avoid that and instead deal with having to having to keep things in sync.
Quoted 59 lines
But let's see what Rob and Lee says about this.
Quoted 44 lines
drivers/watchdog/rave-sp-wdt.c new file +44
-0+if (!id) { +dev_err (dev,"Unknown parent device variant. Bailing out\n" ); +return -ENODEV ; + } + + sp_wd =devm_kzalloc (dev,sizeof (*sp_wd),GFP_KERNEL ); +if (!sp_wd) +return -ENOMEM ; + + sp_wd->variant = id->data; + sp_wd->sp =dev_get_drvdata (dev->parent); + + wdd = &sp_wd->wdd; + wdd->parent = dev; + wdd->info = &rave_sp_wdt_info; + wdd->ops = &rave_sp_wdt_ops; + wdd->min_timeout = sp_wd->variant->min_timeout; + wdd->max_timeout = sp_wd->variant->max_timeout; + wdd->status =WATCHDOG_NOWAYOUT_INIT_STATUS ; + wdd->timeout =60 ; + + cell =nvmem_cell_get (dev,"wdt-timeout" ); +if (!IS_ERR (cell)) { +size_t len; +void *value =nvmem_cell_read (cell, &len); + +if (!IS_ERR (value)) { +memcpy (&timeout, value,min (len,sizeof (timeout))); +kfree (value); + } +nvmem_cell_put (cell); + } +watchdog_init_timeout (wdd,le16_to_cpu (timeout), dev); +watchdog_set_restart_priority (wdd,255 ); + + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; + ret =devm_register_reboot_notifier (dev, &sp_wd->reboot_notifier); +if (ret) { +dev_err (dev,"Failed to register reboot notifier\n" ); +return ret; + } + +/* +* We don't know if watchdog is running now. To be sure, let's drivers/watchdog/rave-sp-wdt.c line 330
Quoted 10 lines
drivers/watchdog/rave-sp-wdt.c new file +10
-0+* start it and depend on watchdog core to ping it +*/ + wdd->max_hw_heartbeat_ms = wdd->max_timeout *1000 ; + ret =rave_sp_wdt_start (wdd); +if (ret) { +dev_err (dev,"Watchdog didn't start\n" ); +return ret; + } + +return devm_watchdog_register_device (dev, wdd);What about stopping the watchdog on errors here?
Quoted 3 lines
And does watchdog core take care of calling
stop()on unregister (i.e. at unbind)?
I think Guenter already addressed those, so I'll update the code with his suggestions in v11.
Thanks,
Andrey Smirnov
Re: [PATCH v10 3/5] mfd: Add driver for RAVE Supervisory Processor
In reply to Johan HovoldQuoted 66 lines · Johan Hovold
Quoted 65 lines · Andrey Smirnov
Add a driver for RAVE Supervisory Processor, an MCU implementing various bits of housekeeping functionality (watchdoging, backlight control, LED control, etc) on RAVE family of products by Zodiac Inflight Innovations.
This driver implementes core MFD/serdev device as well as communication subroutines necessary for commanding the device.
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Guenter Roeck <[email protected]>Cc Rob Herring <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Tested-by Chris Healy <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
drivers/mfd/rave-sp.c new file +39
-0+int rave_sp_exec (struct rave_sp *sp, +void *__data,size_t data_size, +void *reply_data,size_t reply_data_size) +{ +struct rave_sp_reply reply = { + .data = reply_data, + .length = reply_data_size, + .received =COMPLETION_INITIALIZER_ONSTACK (reply.received), + }; +unsigned char *data = __data; +int command, ret =0 ; +u8 ackid; + + command = sp->variant->cmd.translate (data[0 ]); +if (command <0 ) +return command; + + ackid =atomic_inc_return (&sp->ackid); + reply.ackid = ackid; + reply.code =rave_sp_reply_code ((u8 )command), + +mutex_lock (&sp->bus_lock); + +mutex_lock (&sp->reply_lock); + sp->reply = &reply; +mutex_unlock (&sp->reply_lock); + + data[0 ] = command; + data[1 ] = ackid; + +rave_sp_write (sp, data, data_size); + +if (!wait_for_completion_timeout (&reply.received,HZ )) { +dev_err (&sp->serdev->dev,"Command timeout\n" ); + ret = -ETIMEDOUT ; + +mutex_lock (&sp->reply_lock); + sp->reply =NULL ; +mutex_unlock (&sp->reply_lock);
Quoted 9 lines
drivers/mfd/rave-sp.c line 369
Quoted 6 lines
drivers/mfd/rave-sp.c new file +6
-0+ } + +mutex_unlock (&sp->bus_lock); +return ret; +} +EXPORT_SYMBOL (rave_sp_exec);
EXPORT_SYMBOL_GPL?
Yep, will change in v11.
Quoted 33 lines
Quoted 33 lines
drivers/mfd/rave-sp.c new file +33
-0+static int rave_sp_receive_buf (struct serdev_device *serdev, +const unsigned char *buf,size_t size) +{ +struct device *dev = &serdev->dev; +struct rave_sp *sp =dev_get_drvdata (dev); +struct rave_sp_deframer *deframer = &sp->deframer; +const unsigned char *src = buf; +const unsigned char *end = buf + size; +bool reset_framer = false; + +while (src < end) { +const unsigned char byte = *src++; + +switch (deframer->state) { +case RAVE_SP_EXPECT_SOF : +if (byte ==RAVE_SP_STX ) + deframer->state =RAVE_SP_EXPECT_DATA ; +continue ; + +case RAVE_SP_EXPECT_DATA : +switch (byte) { +case RAVE_SP_ETX : +rave_sp_receive_frame (sp, + deframer->data, + deframer->length); + reset_framer = true; +break ; +case RAVE_SP_STX : +dev_warn (dev,"Bad frame: STX before ETX\n" ); + reset_framer = true; +break ; +case RAVE_SP_DLE : + deframer->state =RAVE_SP_EXPECT_ESCAPED_DATA ;
Quoted 9 lines
drivers/mfd/rave-sp.c line 488
Quoted 4 lines
drivers/mfd/rave-sp.c new file +4
-0+continue ; + } + +case RAVE_SP_EXPECT_ESCAPED_DATA :/* FALLTHROUGH */ The fallthrough comment should precede the case statement (or you will soon receive a patch from the people working enabling -Wimplicit-fallthrough).
Sure, will change in v11.
Quoted 21 lines
Quoted 20 lines
drivers/mfd/rave-sp.c new file +20
-0+ deframer->data[deframer->length++] = byte; + +if (deframer->length ==sizeof (deframer->data)) { +dev_warn (dev,"Bad frame: Too long\n" ); + reset_framer = true; +break ; + } + + deframer->state =RAVE_SP_EXPECT_DATA ; +break ; + } + } + +if (reset_framer) { + deframer->state =RAVE_SP_EXPECT_SOF ; + deframer->length =0 ; + } + +return src - buf; +}
Quoted 4 lines
Quoted 1 line
+MODULE_LICENSE("GPL v2");
This doesn't match the license text (GPL-2.0+).
Will update in v11.
Quoted 11 lines
Quoted 11 lines
drivers/mfd/rave-sp.c new file +4
-0+MODULE_AUTHOR ("Andrey Vostrikov <[email protected]>" ); +MODULE_AUTHOR ("Nikita Yushchenko <[email protected]>" ); +MODULE_AUTHOR ("Andrey Smirnov <[email protected]>" ); +MODULE_DESCRIPTION ("RAVE SP core driver" );drivers/platform/Kconfig +0
-0@@ -8,3 +8,4 @@ endif source "drivers/platform/goldfish/Kconfig"
Quoted 5 lines
drivers/platform/Kconfig endif · line 11
Quoted 2 lines
drivers/platform/Kconfig +1
-0source "drivers/platform/chrome/Kconfig" +This chunk should not be here.
Missed this one. Will remove in v11.
Quoted 7 lines
include/linux/rave-sp.h
Quoted 5 lines
include/linux/rave-sp.h new file +0
-0I think this one should live in
include/linux/mfd/
My bad, forgot to move that file. Will do in v11.
Thanks,
Andrey Smirnov
Re: [PATCH v10 2/5] serdev: Introduce devm_serdev_device_open()
In reply to Johan HovoldQuoted 40 lines · Johan Hovold
Quoted 39 lines · Andrey Smirnov
Add code implementing managed version of
serdev_device_open()for serdev device drivers that "open" the device during driver's lifecycle only once (e.g. opened in .probe() and closed in .remove()).Cc Rob Herring <[email protected]>Cc Guenter Roeck <[email protected]>Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Lee Jones <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Pavel Machek <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Johan Hovold <[email protected]>Cc Sebastian Reichel <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- Documentation/driver-model/devres.txt | 3 +++ drivers/tty/serdev/core.c | 27 +++++++++++++++++++++++++++ include/linux/serdev.h | 1 + 3 files changed, 31 insertions(+)drivers/tty/serdev/core.c +13
-0+int devm_serdev_device_open (struct device *dev,struct serdev_device *serdev) +{ +struct serdev_device **dr; +int ret; + + dr =devres_alloc (devm_serdev_device_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =serdev_device_open (serdev); +if (ret) { +devres_free (dr); +return ret;
Quoted 8 lines
drivers/tty/serdev/core.c void serdev_device_close(struct serdev_device *serdev) · line 142
Quoted 6 lines
drivers/tty/serdev/core.c +6
-0+ } + + *dr = serdev; +devres_add (dev, dr); + +return ret;This would be more readable as return 0.
Sure, I'll change that in v11.
Thanks,
Andrey Smrinov