ZII RAVE platform driver
Subsystems (2)
v2 cover ZII RAVE platform driver
Hi everyone,
This patch series is v2 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 [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
[v1] lkml.kernel.org/r/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/mfd/Makefile | 1 + drivers/platform/Kconfig | 2 + drivers/platform/Makefile | 1 + drivers/platform/rave/Kconfig | 26 + drivers/platform/rave/Makefile | 1 + drivers/platform/rave/rave-sp.c | 1083 ++++++++++++++++++++ include/linux/rave-sp.h | 54 + 8 files changed, 1207 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 · 1 line
2.13.3
PATCH v2 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.
--- drivers/mfd/Makefile | 1 + drivers/platform/Kconfig | 2 + drivers/platform/Makefile | 1 + drivers/platform/rave/Kconfig | 26 + drivers/platform/rave/Makefile | 1 + drivers/platform/rave/rave-sp.c | 1083 +++++++++++++++++++++++++++++++++++++++ include/linux/rave-sp.h | 54 ++ 7 files changed, 1168 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/mfd/Makefile +1 -0
@@ -221,3 +221,4 @@ obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o obj-$(CONFIG_MFD_MXS_LRADC) += mxs-lradc.o +
drivers/platform/Kconfig +2 -0
@@ -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
@@ -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
@@ -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
@@ -0,0 +1 @@ +obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o
drivers/platform/rave/rave-sp.c new file +1083 -0
1,083 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
Re: [PATCH v2 1/2] platform: Add driver for RAVE Supervisory Processor
Quoted 11 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.
+/**
+ * structrave_sp- RAVE supervisory processor core
+ *
Quoted 8 lines
+ * @serdev: Pointer to underlying serdev + * @deframer: Stored state of the protocol deframer + * @ackid: ACK ID used in last reply sent to the device + * @bus_lock: Lock to serialize access to the device+ * @reply_lock: Lock protecting @reply
+ * @reply: Pointer to memory to store reply payload+ *
Do you need it?
Quoted 3 lines
+ * @part_number_firmware: String containing firmware part number
+ * (retrived once during probing)
No need to repeat this over each parameter. Just move it to (long) description part and tell that
"part_*, copper_*, and silicon_* parameters are retrived once during probing."
drivers/platform/rave/rave-sp.c line 250
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+static void +devm_rave_sp_unregister_event_notifier (struct device *dev,void *res)
static devm_*?!
It looks let's say interesting... (yes, better to provide releasing devres API as well)
drivers/platform/rave/rave-sp.c line 286
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+static const char *devm_rave_sp_version (struct device *dev,const char *buf) +{ + return devm_kasprintf(dev, GFP_KERNEL, "%02d%02d%02d.%c%c\n", + buf[0], le16_to_cpup((const __le16 *)&buf[1]),
To cpu_P_?!__le16 and %02d?
Are you sure?
drivers/platform/rave/rave-sp.c line 304
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+ buf[3], buf[4], buf[5]); +} +static ssize_t +rave_sp_show_part_number (char *buf,const char *version,size_t version_length) +{ +memcpy (buf, version, version_length +1 ); +return version_length;
Looks suspicious. If it's string, use snprintf(), it it might have garbage, use %pE.
drivers/platform/rave/rave-sp.c line 347
Quoted 3 lines
drivers/platform/rave/rave-sp.c new file +2
-0+} +return sprintf (buf,"%04x\n" ,le16_to_cpup ((__le16 *)status));
cpu_P_?!
drivers/platform/rave/rave-sp.c line 385
Quoted 12 lines
drivers/platform/rave/rave-sp.c new file +11
-0+static int rave_sp_common_get_boot_source (struct rave_sp *sp) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_BOOT_SOURCE , + [1 ] =0 , + [2 ] =RAVE_SP_BOOT_SOURCE_SET , + [3 ] =0 , + }; +u8 boot_source; +const int ret =rave_sp_exec (sp, cmd,sizeof (cmd), + &boot_source,sizeof (boot_source));
Why not
const int ret;
ret = rave_sp_exec(sp, cmd, sizeof(cmd), &boot_source, sizeof(boot_source));Quoted 1 line
+ return (ret < 0) ? ret :
boot_source;
Ditto for every similar cases.
drivers/platform/rave/rave-sp.c line 463
Quoted 10 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 = 0;
while (size--)
*crc += *buf++;
?
drivers/platform/rave/rave-sp.c line 467
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+ *crc += *buf++; + + *crc =1 + ~(*crc); +}
I dunno if lib/crc8.c helps here, worth to check.
drivers/platform/rave/rave-sp.c line 481
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +5
-0+static void *stuff (unsigned char *dest,const unsigned char *src,size_t n) +{ +size_t i; + +for (i =0 ; i < n; i++) {
Useless i.
while (n--) {
...
}
Quoted 14 lines
drivers/platform/rave/rave-sp.c new file +14
-0+const unsigned char byte = *src++; + +switch (byte) { +case RAVE_SP_STX : +case RAVE_SP_ETX : +case RAVE_SP_DLE : + *dest++ =RAVE_SP_DLE ; +default : + *dest++ = byte; + } + } + +return dest; +}
drivers/platform/rave/rave-sp.c line 529
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +7
-0+static u8 rave_sp_reply_code (u8 command) +{ +switch (command) { + case 0xA0 ... 0xBE: +return command +0x20 ; + case 0xE0 ... 0xEF: +return command |0x01 ;
These all look strange. Perhaps this function needs more comments.
Quoted 11 lines
drivers/platform/rave/rave-sp.c new file +10
-0+default : +return command +0x40 ; + } +} +int rave_sp_exec (struct rave_sp *sp, +void *__data,size_t data_size, +void *reply_data,size_t reply_data_size) +{ +int ret =0 ; +unsigned char *data = __data;
drivers/platform/rave/rave-sp.c line 550
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+const u8 ackid = (u8 )atomic_inc_return (&sp->ackid); +const int command = sp->variant->cmd.translate (data[0 ]); +struct rave_sp_reply reply = { + .code =rave_sp_reply_code ((u8 )command), + .ackid = ackid, + .data = reply_data, + .length = reply_data_size, + .received =COMPLETION_INITIALIZER_ONSTACK (reply.received), + }; +
+ command = ...; here!
Quoted 16 lines
drivers/platform/rave/rave-sp.c new file +15
-0+if (command <0 ) +return command; +static void rave_sp_receive_reply (struct rave_sp *sp, +const unsigned char *data,size_t length) +{ +struct device *dev = &sp->serdev->dev; +struct rave_sp_reply *reply; +const size_t payload_length = length -2 ; + +mutex_lock (&sp->reply_lock); + reply = sp->reply; + +if (reply && reply->code == data[0 ] && reply->ackid == data[1 ] && + payload_length >= reply->length) { +/*
drivers/platform/rave/rave-sp.c line 616
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+* We are relying on memcpy(dst, src, 0) to be a no-op +* when handling commands that have a no-payload reply +*/ +memcpy (reply->data, &data[2 ], reply->length); +complete (&reply->received); + sp->reply =NULL ; + }else { +dev_err (dev,"Ignoring incorrect reply\n" ); +dev_dbg (dev,"Code: expected = 0x%08x received = 0x%08x\n" , + reply->code, data[0 ]);
NULL pointer dereference.
drivers/platform/rave/rave-sp.c line 620
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+dev_dbg (dev,"ACK ID: expected = 0x%08x received = 0x%08x\n" , + reply->ackid, data[1 ]); +dev_dbg (dev,"Length: expected = %zu received = %zu\n" , + reply->length, payload_length);
... in all cases.
Quoted 14 lines
drivers/platform/rave/rave-sp.c new file +13
-0+ } + +mutex_unlock (&sp->reply_lock); +} + +static void rave_sp_receive_frame (struct rave_sp *sp, +const unsigned char *data, +size_t length) +{ +if (rave_sp_id_is_event (data[0 ])) +rave_sp_receive_event (sp, data, length); +else +rave_sp_receive_reply (sp, data, length);
drivers/platform/rave/rave-sp.c line 722
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-0+} + +static int rave_sp_rdu1_cmd_translate (enum rave_sp_command command) +{ +if (command >=RAVE_SP_CMD_STATUS && + command <=RAVE_SP_CMD_CONTROL_EVENTS ) +return command; +else
Redundant.
drivers/platform/rave/rave-sp.c line 734
Quoted 13 lines
drivers/platform/rave/rave-sp.c new file +12
-0+return -EINVAL ; +} + +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; +else if (command ==RAVE_SP_CMD_REQ_COPPER_REV ) +return 0x28 ; +else +return rave_sp_rdu1_cmd_translate (command);
Redundant else in both cases.
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+} +static int rave_sp_default_cmd_translate (enum rave_sp_command command) +{ +switch (command) { +case RAVE_SP_CMD_GET_FIRMWARE_VERSION : +return 0x11 ; +case RAVE_SP_CMD_GET_BOOTLOADER_VERSION :
drivers/platform/rave/rave-sp.c line 751
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+return 0x12 ; +case RAVE_SP_CMD_RESET_REASON : +return 0x1F ; +case RAVE_SP_CMD_BOOT_SOURCE : +return 0x14 ; +case RAVE_SP_CMD_RESET : +return 0x1E ; +case RAVE_SP_CMD_SW_WDT : +return 0x1C ;
Can you set them in order of returned value?
drivers/platform/rave/rave-sp.c line 768
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-0+default : +return -EINVAL ; + } +} + +static void rave_sp_common_init (struct rave_sp *sp) +{ +if (!ret)
Other way around, please.
drivers/platform/rave/rave-sp.c line 849
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +8
-0+ sp->part_number_firmware = +devm_rave_sp_version (dev, version); + else + dev_warn(dev, "CMD_GET_FIRMWARE_VERSION failed %d\n", ret); + + cmd[0 ] =RAVE_SP_CMD_GET_BOOTLOADER_VERSION ; + ret =rave_sp_exec (sp, cmd,sizeof (cmd), version,sizeof (version)); +if (!ret)
Ditto.
Do this for every similar place.
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+ sp->part_number_bootloader = +devm_rave_sp_version (dev, version); + else + dev_warn(dev, "CMD_GET_BOOTLOADER_VERSION failed %d\n", ret);
drivers/platform/rave/rave-sp.c line 871
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +7
-0+} + +static void rave_sp_rdu2_init (struct rave_sp *sp) +{ + ret =rave_sp_exec (sp, cmd,sizeof (cmd), + &copper_rev,sizeof (copper_rev)); +if (!ret) {
This is a bit unusual.
Review
Quoted 2 lines
(quoted diff) +2
-0+ sp->copper_rev_rmb = devm_kasprintf(dev, GFP_KERNEL, "%01x\n", + copper_rev & 0x1F);
%01x and & 0x1f ?!
Quoted 7 lines
drivers/platform/rave/rave-sp.c new file +7
-0+ sp->copper_mod_rmb =devm_kasprintf (dev,GFP_KERNEL ,"%01x\n" , + copper_rev >>5 ); + }else { +dev_warn (dev, +"RAVE_SP_CMD_REQ_COPPER_REV(RMB) failed %d\n" , ret); + } +
drivers/platform/rave/rave-sp.c line 889
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+ cmd[2 ] =RAVE_SP_RDU2_BOARD_TYPE_DEB ; + + ret =rave_sp_exec (sp, cmd,sizeof (cmd), + &copper_rev,sizeof (copper_rev)); +if (!ret) { + sp->copper_rev_deb =devm_kasprintf (dev,GFP_KERNEL ,"%01x\n" , + copper_rev &0x1F ); + sp->copper_mod_deb =devm_kasprintf (dev,GFP_KERNEL ,"%01x\n" , + copper_rev >>5 );
Duplicate! Perhaps, helper function.
Review
Quoted 13 lines
(quoted diff) +11
-0+ } else { + dev_warn(dev, + "RAVE_SP_CMD_REQ_COPPER_REV(DEB) failed %d\n", ret); + } +} +static int rave_sp_probe(struct serdev_device *serdev) +{ + static const struct serdev_device_ops serdev_device_ops = { + .receive_buf = rave_sp_receive_buf, + .write_wakeup = serdev_device_write_wakeup, + };
Please, move outside.
drivers/platform/rave/rave-sp.c line 1000
Quoted 3 lines
drivers/platform/rave/rave-sp.c new file +2
-0+struct rave_sp *sp; +struct device *dev = &serdev->dev;
Make it first line in this function.
drivers/platform/rave/rave-sp.c line 1073
Quoted 13 lines
drivers/platform/rave/rave-sp.c new file +10
-0+u32 baud; +int ret; +mutex_init (&sp->bus_lock); +mutex_init (&sp->reply_lock); +static struct serdev_device_driver rave_sp_drv = { + .probe = rave_sp_probe, + .remove = rave_sp_remove, + .driver = { + .name =KBUILD_MODNAME , + .owner =THIS_MODULE ,
Redundant I suppose.
drivers/platform/rave/rave-sp.c
Quoted 5 lines
drivers/platform/rave/rave-sp.c new file +4
-0+ .of_match_table = rave_sp_dt_ids, + }, +}; +static inline unsigned long rave_sp_action (u8 event,u8 value)
_pack_action?
include/linux/rave-sp.h line 32
Quoted 5 lines
include/linux/rave-sp.h new file +5
-0+{ +return ((unsigned long )value <<8 ) | event; +} + +static inline u8 rave_sp_action_get_event (unsigned long action)
_unpack_event?
include/linux/rave-sp.h line 37
Quoted 5 lines
include/linux/rave-sp.h new file +5
-0+{ +return action &0xff ; +} + +static inline u8 rave_sp_action_get_value (unsigned long action)
_unpack_value?
Quoted 3 lines
include/linux/rave-sp.h new file +3
-0+{ +return (action >>8 ) &0xff ; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/2] platform: Add driver for RAVE Supervisory Processor
Quoted 20 lines · Andy Shevchenko
Quoted 17 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.
+/**
+ * structrave_sp- RAVE supervisory processor core
+ *+ * @serdev: Pointer to underlying serdev + * @deframer: Stored state of the protocol deframer + * @ackid: ACK ID used in last reply sent to the device + * @bus_lock: Lock to serialize access to the device+ * @reply_lock: Lock protecting @reply
+ * @reply: Pointer to memory to store reply payload
Quoted 3 lines
Quoted 1 line
+ *
Do you need it?
Not sure what this is in reference too. The @reply field?
Quoted 9 lines
Quoted 4 lines
+ * @part_number_firmware: String containing firmware part number
+ * (retrived once during probing)
No need to repeat this over each parameter. Just move it to (long) description part and tell that
"part_*, copper_*, and silicon_* parameters are retrived once during probing."
OK, will change in v3.
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 250
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+static void +devm_rave_sp_unregister_event_notifier (struct device *dev,void *res)static devm_*?!
It looks let's say interesting... (yes, better to provide releasing devres API as well)
It's just a callback provided to devres_alloc call below. It could and should not be used as external API, but I can remove devm_ prefix from the name if that makes things better. As for providing API for manual unregistered -- there are no potential users of that functionality in any of the corresponding MFD cell drivers, so I'd rather not add code that'll never get used.
Quoted 6 lines
drivers/platform/rave/rave-sp.c line 286
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+static const char *devm_rave_sp_version (struct device *dev,const char *buf) +{ + return devm_kasprintf(dev, GFP_KERNEL, "%02d%02d%02d.%c%c\n", + buf[0], le16_to_cpup((const __le16 *)&buf[1]),To
cpu_P_?!
Yes, I am not sure why you are surprised. It's used with &buf[1] and it all seems legit, did I miss something?
Quoted 3 lines
__le16and %02d?
Are you sure?
Yeah, legacy userspace daemon that, among other things, was in charge of implementing similar to this driver's functionality was reporting that particular version string in such buggy way. For the sake of backwards compatibility I do the same. I'll add some commentary to explain that.
Quoted 12 lines
drivers/platform/rave/rave-sp.c line 304
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+ buf[3], buf[4], buf[5]); +} +static ssize_t +rave_sp_show_part_number (char *buf,const char *version,size_t version_length) +{ +memcpy (buf, version, version_length +1 ); +return version_length;Looks suspicious. If it's string, use
snprintf(), it it might have garbage, use %pE.
Will change to snprintf in v3.
Quoted 6 lines
drivers/platform/rave/rave-sp.c line 347
Quoted 3 lines
drivers/platform/rave/rave-sp.c new file +2
-0+} +return sprintf (buf,"%04x\n" ,le16_to_cpup ((__le16 *)status));
cpu_P_?!
Status is declared as "u8 status[2]", so this should be OK, no?
Quoted 10 lines
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +9
-0+static int rave_sp_common_get_boot_source (struct rave_sp *sp) +{ +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_BOOT_SOURCE , + [1 ] =0 , + [2 ] =RAVE_SP_BOOT_SOURCE_SET , + [3 ] =0 , + }; +u8 boot_source;
Quoted 9 lines
drivers/platform/rave/rave-sp.c line 385
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+const int ret =rave_sp_exec (sp, cmd,sizeof (cmd), + &boot_source,sizeof (boot_source));Why not
const int ret; ret = rave_sp_exec(sp, cmd, sizeof(cmd), &boot_source, sizeof(boot_source));
You'd have to drop the "const" qualifier from "ret" in order for that snippet to compile, which I was trying to avoid. I'll drop the const and move the call one line down in v3.
Quoted 15 lines
Quoted 1 line
+ return (ret < 0) ? ret :
boot_source;Ditto for every similar cases.
drivers/platform/rave/rave-sp.c line 463
Quoted 10 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--)
Quoted 6 lines
*crc = 0;
while (size--)
*crc += *buf++;?
I partially unrolled that look specifically because I wanted to avoid having that "useless" "*crc = 0" line.
Quoted 8 lines
drivers/platform/rave/rave-sp.c line 467
Quoted 5 lines
drivers/platform/rave/rave-sp.c new file +4
-0+ *crc += *buf++; + + *crc =1 + ~(*crc); +}I dunno if
lib/crc8.chelps here, worth to check.
I did check it out, but I am not sure I can use it: I am hesitant to outright deny the possibility, but I can't think of a straight conversion from "2's complement of sum of all bytes" to polynomial division. Besides csum_8b2c() implements checksum algorithm as it is described in ICD, so it has the advantage of being easier to double check.
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 481
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +5
-0+static void *stuff (unsigned char *dest,const unsigned char *src,size_t n) +{ +size_t i; + +for (i =0 ; i < n; i++) {
Quoted 6 lines
Useless i.
while (n--) {
...
}
Will change in v3.
Quoted 21 lines
Quoted 20 lines
drivers/platform/rave/rave-sp.c new file +19
-0+const unsigned char byte = *src++; + +switch (byte) { +case RAVE_SP_STX : +case RAVE_SP_ETX : +case RAVE_SP_DLE : + *dest++ =RAVE_SP_DLE ; +default : + *dest++ = byte; + } + } + +return dest; +} +static u8 rave_sp_reply_code (u8 command) +{ +switch (command) { + case 0xA0 ... 0xBE: +return command +0x20 ;
Quoted 6 lines
drivers/platform/rave/rave-sp.c line 529
Quoted 3 lines
drivers/platform/rave/rave-sp.c new file +2
-0+ case 0xE0 ... 0xEF: +return command |0x01 ;These all look strange. Perhaps this function needs more comments.
Yeah, you're right, I'll add mover verbiage to explain what's going on there.
Quoted 15 lines
Quoted 15 lines
drivers/platform/rave/rave-sp.c new file +14
-0+default : +return command +0x40 ; + } +} +int rave_sp_exec (struct rave_sp *sp, +void *__data,size_t data_size, +void *reply_data,size_t reply_data_size) +{ +int ret =0 ; +unsigned char *data = __data; +const u8 ackid = (u8 )atomic_inc_return (&sp->ackid); +const int command = sp->variant->cmd.translate (data[0 ]); +struct rave_sp_reply reply = { + .code =rave_sp_reply_code ((u8 )command),
Quoted 9 lines
drivers/platform/rave/rave-sp.c line 550
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +6
-0+ .ackid = ackid, + .data = reply_data, + .length = reply_data_size, + .received = COMPLETION_INITIALIZER_ONSTACK(reply.received), + }; ++ command = ...; here!
"reply.code" initialization depends on the value of "command", so I can't easily move it down here.
Quoted 29 lines
Quoted 16 lines
drivers/platform/rave/rave-sp.c new file +15
-0+if (command <0 ) +return command; +static void rave_sp_receive_reply (struct rave_sp *sp, +const unsigned char *data,size_t length) +{ +struct device *dev = &sp->serdev->dev; +struct rave_sp_reply *reply; +const size_t payload_length = length -2 ; + +mutex_lock (&sp->reply_lock); + reply = sp->reply; + +if (reply && reply->code == data[0 ] && reply->ackid == data[1 ] && + payload_length >= reply->length) { +/* drivers/platform/rave/rave-sp.c line 616
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+* We are relying on memcpy(dst, src, 0) to be a no-op +* when handling commands that have a no-payload reply +*/ +memcpy (reply->data, &data[2 ], reply->length); +complete (&reply->received); + sp->reply =NULL ; + }else { +dev_err (dev,"Ignoring incorrect reply\n" ); +dev_dbg (dev,"Code: expected = 0x%08x received = 0x%08x\n" , + reply->code, data[0 ]);NULL pointer dereference.
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 620
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+dev_dbg (dev,"ACK ID: expected = 0x%08x received = 0x%08x\n" , + reply->ackid, data[1 ]); +dev_dbg (dev,"Length: expected = %zu received = %zu\n" , + reply->length, payload_length);... in all cases.
Good catch, thanks! Will fix in v3.
Quoted 36 lines
Quoted 14 lines
drivers/platform/rave/rave-sp.c new file +13
-0+ } + +mutex_unlock (&sp->reply_lock); +} + +static void rave_sp_receive_frame (struct rave_sp *sp, +const unsigned char *data, +size_t length) +{ +if (rave_sp_id_is_event (data[0 ])) +rave_sp_receive_event (sp, data, length); +else +rave_sp_receive_reply (sp, data, length);drivers/platform/rave/rave-sp.c line 722
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-0+} + +static int rave_sp_rdu1_cmd_translate (enum rave_sp_command command) +{ +if (command >=RAVE_SP_CMD_STATUS && + command <=RAVE_SP_CMD_CONTROL_EVENTS ) +return command; +else Redundant.
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +8
-0+return -EINVAL ; +} + +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;
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 734
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+else if (command ==RAVE_SP_CMD_REQ_COPPER_REV ) +return 0x28 ; +else +return rave_sp_rdu1_cmd_translate (command);Redundant else in both cases.
Will fix both in v3.
Quoted 19 lines
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+} +static int rave_sp_default_cmd_translate (enum rave_sp_command command) +{ +switch (command) { +case RAVE_SP_CMD_GET_FIRMWARE_VERSION : +return 0x11 ; +case RAVE_SP_CMD_GET_BOOTLOADER_VERSION :drivers/platform/rave/rave-sp.c line 751
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+return 0x12 ; +case RAVE_SP_CMD_RESET_REASON : +return 0x1F ; +case RAVE_SP_CMD_BOOT_SOURCE : +return 0x14 ; +case RAVE_SP_CMD_RESET : +return 0x1E ; +case RAVE_SP_CMD_SW_WDT : +return 0x1C ;
Quoted 2 lines
Can you set them in order of returned value?
Sure, sounds like a good idea, will fix in v3.
Quoted 21 lines
drivers/platform/rave/rave-sp.c line 768
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-0+default : +return -EINVAL ; + } +} + +static void rave_sp_common_init (struct rave_sp *sp) +{ +if (!ret)Other way around, please.
Quoted 7 lines
drivers/platform/rave/rave-sp.c new file +7
-0+ sp->part_number_firmware = +devm_rave_sp_version (dev, version); + else + dev_warn(dev, "CMD_GET_FIRMWARE_VERSION failed %d\n", ret); + + cmd[0 ] =RAVE_SP_CMD_GET_BOOTLOADER_VERSION ; + ret =rave_sp_exec (sp, cmd,sizeof (cmd), version,sizeof (version));
Quoted 6 lines
Quoted 1 line
+ if (!ret)
Ditto.
Do this for every similar place.
Will do in v3.
Quoted 13 lines
Quoted 12 lines
drivers/platform/rave/rave-sp.c new file +10
-0+ sp->part_number_bootloader = +devm_rave_sp_version (dev, version); + else + dev_warn(dev, "CMD_GET_BOOTLOADER_VERSION failed %d\n", ret); +} + +static void rave_sp_rdu2_init (struct rave_sp *sp) +{ + ret =rave_sp_exec (sp, cmd,sizeof (cmd), + &copper_rev,sizeof (copper_rev));
Quoted 9 lines
Quoted 1 line
+ if (!ret) {
This is a bit unusual.
Review
Quoted 2 lines
(quoted diff) +2
-0+ sp->copper_rev_rmb = devm_kasprintf(dev, GFP_KERNEL, "%01x\n", + copper_rev & 0x1F);%01x and &
0x1f?!
Ugh, missed this. Will change to "%02x" in v3.
Quoted 13 lines
Quoted 12 lines
drivers/platform/rave/rave-sp.c new file +12
-0+ sp->copper_mod_rmb =devm_kasprintf (dev,GFP_KERNEL ,"%01x\n" , + copper_rev >>5 ); + }else { +dev_warn (dev, +"RAVE_SP_CMD_REQ_COPPER_REV(RMB) failed %d\n" , ret); + } + + cmd[2 ] =RAVE_SP_RDU2_BOARD_TYPE_DEB ; + + ret =rave_sp_exec (sp, cmd,sizeof (cmd), + &copper_rev,sizeof (copper_rev)); +if (!ret) {
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 889
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+ sp->copper_rev_deb =devm_kasprintf (dev,GFP_KERNEL ,"%01x\n" , + copper_rev &0x1F ); + sp->copper_mod_deb =devm_kasprintf (dev,GFP_KERNEL ,"%01x\n" , + copper_rev >>5 );Duplicate! Perhaps, helper function.
Will fix in v3.
Quoted 9 lines
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+ }else { +dev_warn (dev, +"RAVE_SP_CMD_REQ_COPPER_REV(DEB) failed %d\n" , ret); + } +} +static int rave_sp_probe (struct serdev_device *serdev) +{
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 998
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+static const struct serdev_device_ops serdev_device_ops = { + .receive_buf = rave_sp_receive_buf, + .write_wakeup = serdev_device_write_wakeup, + };Please, move outside.
Sure, will fix in v3.
Quoted 6 lines
drivers/platform/rave/rave-sp.c line 1000
Quoted 3 lines
drivers/platform/rave/rave-sp.c new file +2
-0+struct rave_sp *sp; +struct device *dev = &serdev->dev;Make it first line in this function.
OK, will fix in v3.
Quoted 12 lines
Quoted 11 lines
drivers/platform/rave/rave-sp.c new file +9
-0+u32 baud; +int ret; +mutex_init (&sp->bus_lock); +mutex_init (&sp->reply_lock); +static struct serdev_device_driver rave_sp_drv = { + .probe = rave_sp_probe, + .remove = rave_sp_remove, + .driver = { + .name =KBUILD_MODNAME ,
Quoted 4 lines
Quoted 1 line
+ .owner =
THIS_MODULE,Redundant I suppose.
OK, will drop in v3.
Quoted 24 lines
drivers/platform/rave/rave-sp.c
Quoted 5 lines
drivers/platform/rave/rave-sp.c new file +4
-0+ .of_match_table = rave_sp_dt_ids, + }, +}; +static inline unsigned long rave_sp_action (u8 event,u8 value)
_pack_action?include/linux/rave-sp.h line 32
Quoted 5 lines
include/linux/rave-sp.h new file +5
-0+{ +return ((unsigned long )value <<8 ) | event; +} + +static inline u8 rave_sp_action_get_event (unsigned long action)
_unpack_event?include/linux/rave-sp.h line 37
Quoted 5 lines
include/linux/rave-sp.h new file +5
-0+{ +return action &0xff ; +} + +static inline u8 rave_sp_action_get_value (unsigned long action)
_unpack_value?
Quoted 4 lines
include/linux/rave-sp.h line 40
Quoted 3 lines
include/linux/rave-sp.h new file +3
-0+{ +return (action >>8 ) &0xff ; +}
Yeah, sounds reasonable, will rename in v3.
Thanks,
Andrey Smirnov
PATCH v2 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
@@ -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
Re: [PATCH v2 2/2] dt-bindings: mfd: Add bindings for ZII RAVE devices
Where is patch 1?
Quoted 19 lines
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Acked-by Rob Herring <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- .../devicetree/bindings/mfd/zii,rave-sp.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txtDocumentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +0
-0
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +4
-0@@ -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
Nit: Device Tree
Once fixed, please apply my:
For my own reference:
Quoted 35 lines
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +35
-0+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 · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v2 2/2] dt-bindings: mfd: Add bindings for ZII RAVE devices
Quoted 2 lines · Lee Jones
Where is patch 1?
lkml.kernel.org/r/20170718175604.11735-2-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
I dropped you from CC list to spare you the e-mail traffic, but I can add you back if you'd prefer that.
Quoted 26 lines
Quoted 19 lines
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <nikita.yoush-M4DtvfQ/[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Acked-by Rob Herring <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- .../devicetree/bindings/mfd/zii,rave-sp.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txtDocumentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +0
-0Documentation/devicetree/bindings/mfd/zii,rave-sp.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +4
-0@@ -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 nodeNit: Device Tree
Quoted 5 lines
Once fixed, please apply my:
For my own reference:
Acked-for-MFD-by Lee Jones <[email protected]>
OK. Will do.
Thanks,
Andrey Smirnov
--
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
Re: [PATCH v2 2/2] dt-bindings: mfd: Add bindings for ZII RAVE devices
Quoted 8 lines · Andrey Smirnov
Quoted 2 lines · Lee Jones
Where is patch 1?
lkml.kernel.org/r/20170718175604.11735-2-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
I dropped you from CC list to spare you the e-mail traffic, but I can add you back if you'd prefer that.
It's always handy to see the C code which handles these bindings.
Also, it looks like there is an MFD change in that patch, so I should have been Cc'ed anyway.
Quoted 36 lines
Quoted 26 lines
Quoted 19 lines
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <nikita.yoush-M4DtvfQ/[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Acked-by Rob Herring <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>--- .../devicetree/bindings/mfd/zii,rave-sp.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txtDocumentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +0
-0Documentation/devicetree/bindings/mfd/zii,rave-sp.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/mfd/zii,rave-sp.txt new file +4
-0@@ -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 nodeNit: Device Tree
Quoted 5 lines
Once fixed, please apply my:
For my own reference:
Acked-for-MFD-by Lee Jones <[email protected]>OK. Will do.
Thanks,
Andrey Smirnov
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- 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
Re: [PATCH v2 2/2] dt-bindings: mfd: Add bindings for ZII RAVE devices
Quoted 8 lines · Lee Jones
Quoted 6 lines · Andrey Smirnov
Quoted 2 lines · Lee Jones
Where is patch 1?
lkml.kernel.org/r/20170718175604.11735-2-andrew.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 8 lines
Quoted 2 lines
I dropped you from CC list to spare you the e-mail traffic, but I can add you back if you'd prefer that.
It's always handy to see the C code which handles these bindings.
Also, it looks like there is an MFD change in that patch, so I should have been Cc'ed anyway.
OK, I'll add you back on CC list for future versions of the patchset.
Thanks,
Andrey Smirnov
--
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