Skip to contentSkip to conversation

ZII RAVE platform driver

PATCH RESEND Superseded Andrey Smirnov 3 participants 6 messages Jul 25, 2017 – Jul 27, 2017

Subsystems (2)

v4 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v4 cover ZII RAVE platform driver

Hi everyone,

This patch series is v4 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.

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

NOTE:

* The driver for "zii,rave-sp-watchdog" exists, but I haven't submitted it yet, becuase I wanted to make sure that API exposed by this MFD is acceptable and doesn't need drastic changes.

* This driver is dependent on crc_ccitt_false() introduced in 2da9378d531f8cc6670c7497f20d936b706ab80b in 'linux-next'

Feedback is greatly appreciated!

Thanks,
Andrey Smirnov

[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 (2):
platform: Add driver for RAVE Supervisory Processor
dt-bindings: mfd: Add bindings for ZII RAVE devices

 .../devicetree/bindings/mfd/zii,rave-sp.txt        |   39 +
 drivers/platform/Kconfig                           |    2 +
 drivers/platform/Makefile                          |    1 +
 drivers/platform/rave/Kconfig                      |   26 +
 drivers/platform/rave/Makefile                     |    1 +
 drivers/platform/rave/rave-sp.c                    | 1126 ++++++++++++++++++++
 include/linux/rave-sp.h                            |   54 +
 7 files changed, 1249 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txt
 create mode 100644 drivers/platform/rave/Kconfig
 create mode 100644 drivers/platform/rave/Makefile
 create mode 100644 drivers/platform/rave/rave-sp.c
 create mode 100644 include/linux/rave-sp.h
Signature · 6 lines
2.13.3

--
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
#1 lore raw

PATCH RESEND v4 1/2 platform: Add driver for RAVE Supervisory Processor

Add a driver for RAVE Supervisory Processor, an MCU implementing varoius 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 Andy Shevchenko <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/platform/Kconfig        |    2 +
 drivers/platform/Makefile       |    1 +
 drivers/platform/rave/Kconfig   |   26 +
 drivers/platform/rave/Makefile  |    1 +
 drivers/platform/rave/rave-sp.c | 1126 +++++++++++++++++++++++++++++++++++++++
 include/linux/rave-sp.h         |   54 ++
 6 files changed, 1210 insertions(+)
 create mode 100644 drivers/platform/rave/Kconfig
 create mode 100644 drivers/platform/rave/Makefile
 create mode 100644 drivers/platform/rave/rave-sp.c
 create mode 100644 include/linux/rave-sp.h
drivers/platform/Kconfig +2 -0
index c11db8bceea1..e6db685bb895 100644
@@ -8,3 +8,5 @@ endif
 source "drivers/platform/goldfish/Kconfig"
 
 source "drivers/platform/chrome/Kconfig"
+
+source "drivers/platform/rave/Kconfig"
drivers/platform/Makefile +1 -0
index ca2692510733..17bdec5ece0c 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_MIPS)		+= mips/
 obj-$(CONFIG_OLPC)		+= olpc/
 obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
+obj-y += rave/
drivers/platform/rave/Kconfig new file +26 -0
new file mode 100644
index 000000000000..6fc50ade3871
@@ -0,0 +1,26 @@
+#
+# Platform support for Zodiac RAVE hardware
+#
+
+menuconfig RAVE_PLATFORMS
+	bool "Platform support for Zodiac RAVE hardware"
+	depends on SERIAL_DEV_BUS && SERIAL_DEV_CTRL_TTYPORT
+	help
+	  Say Y here to get to see options for platform support for
+	  various devices present in RAVE hardware. This option alone
+	  does not add any kernel code.
+
+	  If you say N, all options in this submenu will be skipped
+	  and disabled.
+
+if RAVE_PLATFORMS
+
+config RAVE_SP_CORE
+	tristate "RAVE SP MCU core driver"
+	select MFD_CORE
+	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/platform/rave/Makefile new file +1 -0
new file mode 100644
index 000000000000..e4c21ab2d2f5
@@ -0,0 +1 @@
+obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o
drivers/platform/rave/rave-sp.c new file +1126 -0

1,126 lines not on this page · raw message

include/linux/rave-sp.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.13.3
Reviewed-by on v4 1/2
#2 lore raw

Re: [RESEND PATCH v4 1/2] platform: Add driver for RAVE Supervisory Processor

Quoted 7 lines · Andrey Smirnov

Add a driver for RAVE Supervisory Processor, an MCU implementing varoius 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.

Some comments below, and FWIW

Quoted 1 line

+#include <asm/unaligned.h>

Usually we put it below linux/* type of headers.

Quoted 6 lines

+#include <linux/atomic.h>

+ * @variant:                   Device variant specific parameters and
+ *                             functions
+ * @event_notifier_list:       Input event notification chain (used with
+ *                             corresponding input MFD cell driver)

Perhaps make them oneliners?

drivers/platform/rave/rave-sp.c line 414

Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2 -0
+static DEVICE_ATTR(boot_source, 0640,
+                  rave_sp_show_boot_source, rave_sp_store_boot_source);

DEVICE_ATTR_RW() ?
Otherwise a comment is needed here why you can't use it.

drivers/platform/rave/rave-sp.c line 455

Quoted 7 lines
drivers/platform/rave/rave-sp.c new file +7 -0
+static void csum_8b2c(const u8 *buf, size_t size, u8 *crc)
+{
+       *crc = *buf++;
+       size--;
+
+       while (size--)
+               *crc += *buf++;

I don't remember the answer to a proposal to convert this like

*crc = 0;

while (size--)
*crc += *buf++;

drivers/platform/rave/rave-sp.c line 462

Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +6 -0
+
+       *crc = 1 + ~(*crc);
+}
 
+static void csum_ccitt(const u8 *buf, size_t size, u8 *crc)
+{
 
+

Remove this line.

Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +8 -0
+       const u16 calculated = crc_ccitt_false(0xffff, buf, size);
+
+       /*
+        * While the rest of the wire protocol is little-endian,
+        * CCITT-16 CRC in RDU2 device is sent out in big-endian order.
+        */
+       put_unaligned_be16(calculated, crc);
+}
 

drivers/platform/rave/rave-sp.c

Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10 -0
+static int rave_sp_rdu2_cmd_translate(enum rave_sp_command command)
+{
+       if (command >= RAVE_SP_CMD_GET_FIRMWARE_VERSION &&
+           command <= RAVE_SP_CMD_GET_GPIO_STATE)
+               return command;
+
+       if (command == RAVE_SP_CMD_REQ_COPPER_REV) {
+               /*
+                * As per RDU2 ICD 3.4.47 CMD_GET_COPPER_REV code is
+                * different from that for RDU1 and it is set to 0x28

+ period at the end => "...set to 0x28."

Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4 -0
+                */
+               return 0x28;
+       }
+

drivers/platform/rave/rave-sp.c line 764

Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9 -0
+       return rave_sp_rdu1_cmd_translate(command);
+}
 
+
+static int rave_sp_default_cmd_translate(enum rave_sp_command command)
+{
+       /*
+        * All of the following command codes were taken from "Table :
+        * Communications Protocol Message Types" in section 3.3
+        * "MESSAGE TYPES" of Rave PIC24 ICD

Ditto.

Quoted 16 lines
drivers/platform/rave/rave-sp.c new file +14 -0
+        */
 
+}
 
+static void rave_sp_load_silicon_rev(struct rave_sp *sp)
+{
+       struct device *dev = &sp->serdev->dev;
+       u8 cmd[] = {
+               [0] = RAVE_SP_CMD_GET_SP_SILICON_REV,
+               [1] = 0
+       };
+       struct {
+               __le32 devid;
+               __le32 devrev;
+       } __packed reply;
+       int ret;

drivers/platform/rave/rave-sp.c line 833

Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9 -0
+
+       ret = rave_sp_exec(sp, cmd, sizeof(cmd), &reply, sizeof(reply));
+       if (ret) {
+               dev_err(dev, "CMD_GET_SP_SILICON_REV failed %d\n", ret);
+               return;
+       }
+
 
+       reply.devid  = le32_to_cpu(reply.devid);
+       reply.devrev = le32_to_cpu(reply.devrev);

Can you run sparse with endianess check?
I doubt it will be happy about these lines.

Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4 -0
+
+       sp->silicon_devid  = rave_sp_silicon_to_string(dev, reply.devid);
+       sp->silicon_devrev = rave_sp_silicon_to_string(dev, reply.devrev);
+}

drivers/platform/rave/rave-sp.c line 1090

Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8 -0
 
+static int rave_sp_probe(struct serdev_device *serdev)
+{
 
+       /*
+        * Those strings already have a \n embedded so no need to have
+        * one in format string.
+        */
+       dev_info(dev, "Firmware version: %s", sp->part_number_firmware);
+       dev_info(dev, "Bootloader version: %s", sp->part_number_bootloader);

\n missed in both cases.

Quoted 1 line

+}

P.S. Btw, have you consider to use remoteproc framework? Does it suit here?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [RESEND PATCH v4 1/2] platform: Add driver for RAVE Supervisory Processor

Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Andrey Smirnov

Add a driver for RAVE Supervisory Processor, an MCU implementing varoius 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.

Quoted 8 lines

Some comments below, and FWIW

Quoted 1 line

+#include <asm/unaligned.h>

Usually we put it below linux/* type of headers.

OK, will do in v5.

Quoted 9 lines
Quoted 6 lines

+#include <linux/atomic.h>

+ * @variant:                   Device variant specific parameters and
+ *                             functions
+ * @event_notifier_list:       Input event notification chain (used with
+ *                             corresponding input MFD cell driver)

Perhaps make them oneliners?

Sure, coming in v5.

Quoted 6 lines

drivers/platform/rave/rave-sp.c line 414

Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2 -0
+static DEVICE_ATTR(boot_source, 0640,
+                  rave_sp_show_boot_source, rave_sp_store_boot_source);

DEVICE_ATTR_RW() ?
Otherwise a comment is needed here why you can't use it.

DEVICE_ATTR_RW should work just fine, so I'll convert to that in v5.

Quoted 10 lines

drivers/platform/rave/rave-sp.c line 455

Quoted 7 lines
drivers/platform/rave/rave-sp.c new file +7 -0
+static void csum_8b2c(const u8 *buf, size_t size, u8 *crc)
+{
+       *crc = *buf++;
+       size--;
+
+       while (size--)
+               *crc += *buf++;

I don't remember the answer to a proposal to convert this like

Quoted 5 lines

*crc = 0;

while (size--)
*crc += *buf++;

I unrolled first iteration of the loop specifically to avoid having to do "*crc = 0".

Quoted 11 lines

drivers/platform/rave/rave-sp.c line 462

Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +6 -0
+
+       *crc = 1 + ~(*crc);
+}
 
+static void csum_ccitt(const u8 *buf, size_t size, u8 *crc)
+{
 
+

Remove this line.

Sure.

Quoted 29 lines
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +8 -0
+       const u16 calculated = crc_ccitt_false(0xffff, buf, size);
+
+       /*
+        * While the rest of the wire protocol is little-endian,
+        * CCITT-16 CRC in RDU2 device is sent out in big-endian order.
+        */
+       put_unaligned_be16(calculated, crc);
+}
 

drivers/platform/rave/rave-sp.c

Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10 -0
+static int rave_sp_rdu2_cmd_translate(enum rave_sp_command command)
+{
+       if (command >= RAVE_SP_CMD_GET_FIRMWARE_VERSION &&
+           command <= RAVE_SP_CMD_GET_GPIO_STATE)
+               return command;
+
+       if (command == RAVE_SP_CMD_REQ_COPPER_REV) {
+               /*
+                * As per RDU2 ICD 3.4.47 CMD_GET_COPPER_REV code is
+                * different from that for RDU1 and it is set to 0x28

+ period at the end => "...set to 0x28."

Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +6 -0
+                */
+               return 0x28;
+       }
+
+       return rave_sp_rdu1_cmd_translate(command);
+}
Quoted 10 lines

drivers/platform/rave/rave-sp.c line 764

Quoted 7 lines
drivers/platform/rave/rave-sp.c new file +7 -0
+
+static int rave_sp_default_cmd_translate(enum rave_sp_command command)
+{
+       /*
+        * All of the following command codes were taken from "Table :
+        * Communications Protocol Message Types" in section 3.3
+        * "MESSAGE TYPES" of Rave PIC24 ICD

Ditto.

Will fix both in v5.

Quoted 24 lines
Quoted 23 lines
drivers/platform/rave/rave-sp.c new file +21 -0
+        */
 
+}
 
+static void rave_sp_load_silicon_rev(struct rave_sp *sp)
+{
+       struct device *dev = &sp->serdev->dev;
+       u8 cmd[] = {
+               [0] = RAVE_SP_CMD_GET_SP_SILICON_REV,
+               [1] = 0
+       };
+       struct {
+               __le32 devid;
+               __le32 devrev;
+       } __packed reply;
+       int ret;
+
+       ret = rave_sp_exec(sp, cmd, sizeof(cmd), &reply, sizeof(reply));
+       if (ret) {
+               dev_err(dev, "CMD_GET_SP_SILICON_REV failed %d\n", ret);
+               return;
+       }
+
Quoted 6 lines

drivers/platform/rave/rave-sp.c line 833

Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2 -0
+       reply.devid  = le32_to_cpu(reply.devid);
+       reply.devrev = le32_to_cpu(reply.devrev);

Can you run sparse with endianess check?
I doubt it will be happy about these lines.

You're absolutely right, it did not like it. Will fix in v5.

Quoted 8 lines
Quoted 7 lines
drivers/platform/rave/rave-sp.c new file +6 -0
+
+       sp->silicon_devid  = rave_sp_silicon_to_string(dev, reply.devid);
+       sp->silicon_devrev = rave_sp_silicon_to_string(dev, reply.devrev);
+}
 
+static int rave_sp_probe(struct serdev_device *serdev)
+{
Quoted 8 lines

drivers/platform/rave/rave-sp.c line 1090

Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +6 -0
+       /*
+        * Those strings already have a \n embedded so no need to have
+        * one in format string.
+        */
+       dev_info(dev, "Firmware version: %s", sp->part_number_firmware);
+       dev_info(dev, "Bootloader version: %s", sp->part_number_bootloader);

\n missed in both cases.

Did you see the comment above the two lines? ;-)

Quoted 5 lines
Quoted 2 lines

+}

P.S. Btw, have you consider to use remoteproc framework? Does it suit here?

RAVE SP is just a small PIC uC connected to the SoC over UART, it's not really a true co-processor and, while it is technically possible, it's firmware, stored in flash, is rarely re-programmed and it mostly operates as a black box device.

Thanks,
Andrey Smirnov

#4 lore raw

PATCH RESEND v4 2/2 dt-bindings: mfd: Add bindings for ZII RAVE devices

In reply to Andrey Smirnov
---
 .../devicetree/bindings/mfd/zii,rave-sp.txt        | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txt
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +39 -0
new file mode 100644
index 000000000000..088eff9ddb78
@@ -0,0 +1,39 @@
+Zodiac Inflight Innovations RAVE Supervisory Processor
+
+RAVE Supervisory Processor communicates with SoC over UART. It is
+expected that its Device Tree node is specified as a child of a node
+corresponding to UART controller used for communication.
+
+Required parent device properties:
+
+ - compatible: Should be one of:
+	- "zii,rave-sp-niu"
+	- "zii,rave-sp-mezz"
+	- "zii,rave-sp-esb"
+	- "zii,rave-sp-rdu1"
+	- "zii,rave-sp-rdu2"
+
+ - current-speed: Should be set to baud rate SP device is using
+
+RAVE SP consists of the following sub-devices:
+
+Device				 Description
+------				 -----------
+rave-sp-wdt			: Watchdog
+rave-sp-nvmem			: Interface to onborad EEPROM
+rave-sp-backlight		: Display backlight
+rave-sp-hwmon			: Interface to onboard hardware sensors
+rave-sp-leds			: Interface to onboard LEDs
+rave-sp-input			: Interface to onboard power button
+
+Example of usage:
+
+	rdu {
+		compatible = "zii,rave-sp-rdu2";
+		current-speed = <1000000>;
+
+		watchdog {
+			compatible = "zii,rave-sp-watchdog";
+		};
+	};
+
Signature · 1 line
2.13.3
Tested-by on the v4 series
#5 lore raw
In reply to Andrey Smirnov

Full series successfully tested on both RDU1 and RDU2 platforms. Builds and executes correctly.

Quoted 68 lines · Andrey Smirnov

Hi everyone,

This patch series is v4 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.

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

NOTE:

* The driver for "zii,rave-sp-watchdog" exists, but I haven't submitted it yet, becuase I wanted to make sure that API exposed by this MFD is acceptable and doesn't need drastic changes.

* This driver is dependent on crc_ccitt_false() introduced in 2da9378d531f8cc6670c7497f20d936b706ab80b in 'linux-next'

Feedback is greatly appreciated!

Thanks,
Andrey Smirnov

[v3] lkml.kernel.org/r/[email protected] [v2] lkml.kernel.org/r/[email protected] [v1] lkml.kernel.org/r/[email protected]

Andrey Smirnov (2):
platform: Add driver for RAVE Supervisory Processor
dt-bindings: mfd: Add bindings for ZII RAVE devices

 .../devicetree/bindings/mfd/zii,rave-sp.txt        |   39 +
 drivers/platform/Kconfig                           |    2 +
 drivers/platform/Makefile                          |    1 +
 drivers/platform/rave/Kconfig                      |   26 +
 drivers/platform/rave/Makefile                     |    1 +
 drivers/platform/rave/rave-sp.c                    | 1126 ++++++++++++++++++++
 include/linux/rave-sp.h                            |   54 +
 7 files changed, 1249 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txt
 create mode 100644 drivers/platform/rave/Kconfig
 create mode 100644 drivers/platform/rave/Makefile
 create mode 100644 drivers/platform/rave/rave-sp.c
 create mode 100644 include/linux/rave-sp.h

--
2.13.3