ZII RAVE platform driver
Subsystems (2)
v3 cover ZII RAVE platform driver
Hi everyone,
This patch series is v3 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 [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
[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/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 | 1122 ++++++++++++++++++++ include/linux/rave-sp.h | 54 + 8 files changed, 1246 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
PATCH v3 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 | 1122 +++++++++++++++++++++++++++++++++++++++ include/linux/rave-sp.h | 54 ++ 7 files changed, 1207 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 +1122 -0
1,122 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 v3 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.
Thanks for an update!
My (minor) comments below (most of them are related to spelling issues).
drivers/platform/rave/rave-sp.c line 62
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+#define RAVE_SP_RX_BUFFER_SIZE (RAVE_SP_MAX_DATA_SIZE + \ + RAVE_SP_CHECKSUM_SIZE)
Slightly better style is
#define RAVE_SP_RX_BUFFER_SIZE \
(RAVE_SP_MAX_DATA_SIZE + RAVE_SP_CHECKSUM_SIZE)
drivers/platform/rave/rave-sp.c line 70
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+#define RAVE_SP_TX_BUFFER_SIZE (RAVE_SP_STX_ETX_SIZE + \ + 2 * RAVE_SP_RX_BUFFER_SIZE)
Ditto.
Quoted 5 lines
+/**
+ * enumrave_sp_deframer_state- Possible state for de-framer
+ *
+ * @RAVE_SP_EXPECT_SOF: scanning data stream for start of frame
+ * marker
One line?
Quoted 2 lines
+ * @RAVE_SP_EXPECT_DATA: start of frame marker detected, collecting
+ * frame
Ditto
Quoted 2 lines
+ * @RAVE_SP_EXPECT_ESCAPED_DATA: escape character received, collecting
+ * escaped byte
Ditto.
Quoted 8 lines
+ */
+/**
+ * structrave_sp_variant_cmds- Variant specific command vtable
+ *
+ * @translate: Subroutine to translate common command identifiers to
+ * device specific variants. Different generations of the
+ * ICD employed different numberical constants to
Typo: numerical
Quoted 5 lines
+ * represent same/similar commands and this function is
+ * there to address that.
+ *
+ * @get_boot_source: Variant dependent implementaion of "get boot
+ * source" operation
Typo implementation
Quoted 2 lines
+ * @set_boot_source: Variant dependent implementaion of "set boot
+ * source" operation
Ditto.
Field descriptions are supposed to be _short_.
Quoted 7 lines
+ */
+/**
+ * structrave_sp_variant- RAVE supervisory processor core variant
+ *
+ * @checksum: Variant specific checksum implementation
+ * @cmd: Variant specific command vtable
Decode vtable.
Quoted 2 lines
+ * @init: Variant specific initialization sequence implementation
+ * @group: Attrubute group for exposed sysfs entries
Run spell checker over the file, please.
Quoted 11 lines
+ */
+ * @part_number_firmware:
+ * @part_number_bootloader:
+ * @reset_reason:
+ * @copper_rev_rmb:
+ * @copper_rev_deb:
+ * @silicon_devid:
+ * @silicon_devrev:
+ * @copper_mod_rmb:
+ * @copper_mod_deb:
???
Quoted 5 lines
+ *
+ * @variant: Device variant specific parameters and + * functions + * @event_notifier_list: Input event notification chain (used with + * corresponding input MFD cell driver)
Make them _short_.
Quoted 7 lines
+ * @group: Attrubute group for exposed sysfs entries
+ *
+ *
+ * part_number_*,reset_reason, copper_*, and silicon_* fields are all+ * strings retrived from the device during device probing and made
+ * availible for later userspace consumption via sysfs
Spell checker.
Quoted 16 lines
+ *
+ */drivers/platform/rave/rave-sp.c new file +13
-0+int devm_rave_sp_register_event_notifier (struct device *dev, +struct notifier_block *nb) +{ +struct rave_sp *sp =dev_get_drvdata (dev->parent); +struct notifier_block **rcnb; +int ret; + + rcnb =devres_alloc (rave_sp_unregister_event_notifier, +sizeof (*rcnb),GFP_KERNEL ); +if (!rcnb) +return -ENOMEM ; + + ret =blocking_notifier_chain_register (&sp->event_notifier_list, nb);
drivers/platform/rave/rave-sp.c line 277
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+if (!ret) { + *rcnb = nb; +devres_add (dev, rcnb); + }else { +devres_free (rcnb); + } + +return ret; +} +EXPORT_SYMBOL_GPL (devm_rave_sp_register_event_notifier);
Did I miss
EXPORT_SYMBOL_GPL(devm_rave_sp_unregister_event_notifier);
?
drivers/platform/rave/rave-sp.c line 289
Quoted 11 lines
drivers/platform/rave/rave-sp.c new file +11
-0+static const char *devm_rave_sp_version (struct device *dev,const char *buf) +{ +/* +* NOTE: Ther format string below uses %02d to display u16 +* intentionally for the sake of backwards compatibility with +* legacy software. +*/ +return devm_kasprintf (dev,GFP_KERNEL ,"%02d%02d%02d.%c%c\n" , + buf[0 ],le16_to_cpup ((const __le16 *)&buf[1 ]), + buf[3 ], buf[4 ], buf[5 ]); +}
One more question about le16_to_cpup() use. Is the variable in the buffer guaranteed to be always in little endian format? Okay, looks like it's protocol which is little endian. Ok.
By the way, here it might be needed to call get_unaligned().
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +9
-0+static ssize_t +i2c_device_status_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +ssize_t ret; +struct rave_sp *sp =dev_get_drvdata (dev); +u8 status[2 ]; +u8 cmd[] = {
drivers/platform/rave/rave-sp.c line 341
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+ [0] = RAVE_SP_CMD_GET_I2C_DEVICE_STATUS, + [1] = 0 + }; + + ret =rave_sp_exec (sp, cmd,sizeof (cmd), &status,sizeof (status)); +if (ret <0 ) +return ret; + +return sprintf (buf,"%04x\n" ,le16_to_cpup ((__le16 *)status)); +}
Ditto.
drivers/platform/rave/rave-sp.c line 501
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +3
-0+static int rave_sp_write (struct rave_sp *sp,const u8 *data,u8 data_size) +{ +size_t length;
Slightly better to put this line after *dest definition.
drivers/platform/rave/rave-sp.c line 528
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-0+const size_t checksum_length = sp->variant->checksum->length; +unsigned char crc[checksum_length]; +unsigned char frame[RAVE_SP_TX_BUFFER_SIZE ]; +unsigned char *dest = frame; +static u8 rave_sp_reply_code (u8 command) +{ +/* +* There isn't a signle rule that describes command code ->
Typo: single.
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +5
-0+* ACK code transformation, but, going through various +* versions of ICDs, there appear to be three distinct groups +* that can be described by simple transformation. +*/ +switch (command) {
drivers/platform/rave/rave-sp.c line 543
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+ case 0xA0 ... 0xBE: +/* +* Commands implemented by firmware found in RDU1 and +* older devices all seem to obey the following rule +*/ +return command +0x20 ; + case 0xE0 ... 0xEF: +/* +* Events emitted by all version of the firmare use +* least signifiact bit to get an ACK code
Typos.
Quoted 22 lines
drivers/platform/rave/rave-sp.c new file +21
-0+*/ +return command |0x01 ; +default : +/* +* Commands implemented by firmware found in RDU2 are +* similar to "old" commands, but they use slightly +* different offset +*/ +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 = {
drivers/platform/rave/rave-sp.c line 573
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+ .code = rave_sp_reply_code((u8)command), + .ackid = ackid, + .data = reply_data, + .length = reply_data_size, + .received = COMPLETION_INITIALIZER_ONSTACK(reply.received), + }; + +if (command <0 ) +return command;
Shouldn't be like
command = sp->variant->cmd.translate(data[0]);
if (command < 0)
return command;
reply.code = rave_sp_reply_code((u8)command);?
drivers/platform/rave/rave-sp.c line 581
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +8
-0+ +mutex_lock (&sp->bus_lock); + +mutex_lock (&sp->reply_lock); + sp->reply = &reply; +mutex_unlock (&sp->reply_lock); + + data[0 ] = (u8 )command;
unsigned char implies u8.
Quoted 16 lines
drivers/platform/rave/rave-sp.c new file +16
-0+ 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); + } + +mutex_unlock (&sp->bus_lock); +return ret; +}
drivers/platform/rave/rave-sp.c
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-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 ) +return 0x28 ;
Comment for use magic values?
Definition for it?
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +8
-0+ +return rave_sp_rdu1_cmd_translate (command); +} +static int rave_sp_default_cmd_translate (enum rave_sp_command command) +{ +switch (command) { +case RAVE_SP_CMD_GET_FIRMWARE_VERSION : +return 0x11 ;
drivers/platform/rave/rave-sp.c line 775
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+case RAVE_SP_CMD_GET_BOOTLOADER_VERSION : +return 0x12 ; +case RAVE_SP_CMD_BOOT_SOURCE : +return 0x14 ; +case RAVE_SP_CMD_SW_WDT : +return 0x1C ; +case RAVE_SP_CMD_RESET : +return 0x1E ; +case RAVE_SP_CMD_RESET_REASON : +return 0x1F ;
Ditto.
drivers/platform/rave/rave-sp.c line 803
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +8
-0+default : +return -EINVAL ; + } +} +static const char *rave_sp_silicon_to_string (struct device *dev, +const __le32 *version) +{ +return devm_kasprintf (dev,GFP_KERNEL ,"%08x\n" ,le32_to_cpup (version));
I don't see why you can't use version value instead of pointer.
drivers/platform/rave/rave-sp.c line 811
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+} +static const char *rave_sp_copper_to_string (struct device *dev,uint8_t version) +{ +return devm_kasprintf (dev,GFP_KERNEL ,"%02x\n" , version); +} + +
Remove extra empty line.
drivers/platform/rave/rave-sp.c line 1112
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+ .driver = { + .name = KBUILD_MODNAME,
This is bad idea. It might be someone can use a platform driver (as part of MFD, for example) and someone else rename driver at some point.
I understand that in practice it's quite unlikely, though better not to put potential issues in the first place.
include/linux/rave-sp.h line 40
Quoted 12 lines
include/linux/rave-sp.h new file +11
-0+ .of_match_table = rave_sp_dt_ids, + }, +static inline u8 rave_sp_action_unpack_event (unsigned long action) +{ +return action &0xff ; +} + +static inline u8 rave_sp_action_unpack_value (unsigned long action) +{ +return (action >>8 ) &0xff ; +}
You can drop & 0xff in both cases as it's implied by u8.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/2] platform: Add driver for RAVE Supervisory Processor
Quoted 20 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.
Thanks for an update!
My (minor) comments below (most of them are related to spelling issues).
drivers/platform/rave/rave-sp.c line 62
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+#define RAVE_SP_RX_BUFFER_SIZE (RAVE_SP_MAX_DATA_SIZE + \ + RAVE_SP_CHECKSUM_SIZE)Slightly better style is
Quoted 7 lines
#define
RAVE_SP_RX_BUFFER_SIZE\
(RAVE_SP_MAX_DATA_SIZE+RAVE_SP_CHECKSUM_SIZE)drivers/platform/rave/rave-sp.c line 70
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+#define RAVE_SP_TX_BUFFER_SIZE (RAVE_SP_STX_ETX_SIZE + \ + 2 * RAVE_SP_RX_BUFFER_SIZE)Ditto.
Sure, will fix in v4.
Quoted 12 lines
Quoted 6 lines
+/**
+ * enumrave_sp_deframer_state- Possible state for de-framer
+ *
+ * @RAVE_SP_EXPECT_SOF: scanning data stream for start of frame
+ * markerOne line?
Quoted 2 lines
+ * @RAVE_SP_EXPECT_DATA: start of frame marker detected, collecting
+ * frame
Quoted 6 lines
Ditto
Quoted 2 lines
+ * @RAVE_SP_EXPECT_ESCAPED_DATA: escape character received, collecting
+ * escaped byteDitto.
Sure. Will do in v4.
Quoted 35 lines
Quoted 9 lines
+ */
+/**
+ * structrave_sp_variant_cmds- Variant specific command vtable
+ *
+ * @translate: Subroutine to translate common command identifiers to
+ * device specific variants. Different generations of the
+ * ICD employed different numberical constants toTypo: numerical
Quoted 5 lines
+ * represent same/similar commands and this function is
+ * there to address that.
+ *
+ * @get_boot_source: Variant dependent implementaion of "get boot
+ * source" operationTypo implementation
Quoted 2 lines
+ * @set_boot_source: Variant dependent implementaion of "set boot
+ * source" operationDitto.
Field descriptions are supposed to be _short_.
Quoted 7 lines
+ */
+/**
+ * structrave_sp_variant- RAVE supervisory processor core variant
+ *
+ * @checksum: Variant specific checksum implementation
+ * @cmd: Variant specific command vtable
Quoted 7 lines
Decode vtable.
Quoted 2 lines
+ * @init: Variant specific initialization sequence implementation
+ * @group: Attrubute group for exposed sysfs entriesRun spell checker over the file, please.
Hmm, could've sworn I had it as a my pre-commit hook, but it looks like I didn't. Will do in v4.
Quoted 12 lines
Quoted 11 lines
+ */
+ * @part_number_firmware:
+ * @part_number_bootloader:
+ * @reset_reason:
+ * @copper_rev_rmb:
+ * @copper_rev_deb:
+ * @silicon_devid:
+ * @silicon_devrev:
+ * @copper_mod_rmb:
+ * @copper_mod_deb:
Quoted 2 lines
???
That's my interpretation of you advice to describe those fields in detailed comment below.
Quoted 7 lines
Quoted 5 lines
+ *
+ * @variant: Device variant specific parameters and + * functions + * @event_notifier_list: Input event notification chain (used with + * corresponding input MFD cell driver)Make them _short_.
OK, will do in v4.
Quoted 11 lines
Quoted 8 lines
+ * @group: Attrubute group for exposed sysfs entries
+ *
+ *
+ * part_number_*,reset_reason, copper_*, and silicon_* fields are all+ * strings retrived from the device during device probing and made
+ * availible for later userspace consumption via sysfsSpell checker.
Ditto.
Quoted 29 lines
Quoted 16 lines
+ *
+ */drivers/platform/rave/rave-sp.c new file +13
-0+int devm_rave_sp_register_event_notifier (struct device *dev, +struct notifier_block *nb) +{ +struct rave_sp *sp =dev_get_drvdata (dev->parent); +struct notifier_block **rcnb; +int ret; + + rcnb =devres_alloc (rave_sp_unregister_event_notifier, +sizeof (*rcnb),GFP_KERNEL ); +if (!rcnb) +return -ENOMEM ; + + ret =blocking_notifier_chain_register (&sp->event_notifier_list, nb);drivers/platform/rave/rave-sp.c line 277
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+if (!ret) { + *rcnb = nb; +devres_add (dev, rcnb); + }else { +devres_free (rcnb); + } + +return ret; +} +EXPORT_SYMBOL_GPL (devm_rave_sp_register_event_notifier);Did I miss
Quoted 3 lines
EXPORT_SYMBOL_GPL(devm_rave_sp_unregister_event_notifier);?
No, you did not, as I mentioned in my reply for v2 to you, there's no use-case for having that function, there's only one MFD-cell driver that calls devm_rave_sp_register_event_notifier() and it does so as the last step of its probe(), so there's not going to be any users of devm_rave_sp_unregister_event_notifier().
Quoted 17 lines
drivers/platform/rave/rave-sp.c line 289
Quoted 12 lines
drivers/platform/rave/rave-sp.c new file +11
-0+static const char *devm_rave_sp_version (struct device *dev,const char *buf) +{ +/* +* NOTE: Ther format string below uses %02d to display u16 +* intentionally for the sake of backwards compatibility with +* legacy software. +*/ +return devm_kasprintf (dev,GFP_KERNEL ,"%02d%02d%02d.%c%c\n" , + buf[0 ],le16_to_cpup ((const __le16 *)&buf[1 ]), + buf[3 ], buf[4 ], buf[5 ]); +}One more question about
le16_to_cpup()use. Is the variable in the buffer guaranteed to be always in little endian format? Okay, looks like it's protocol which is little endian. Ok.
Quoted 2 lines
By the way, here it might be needed to call
get_unaligned().
Sure, I'll add that just in case.
Quoted 13 lines
Quoted 13 lines
drivers/platform/rave/rave-sp.c new file +13
-0+static ssize_t +i2c_device_status_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +ssize_t ret; +struct rave_sp *sp =dev_get_drvdata (dev); +u8 status[2 ]; +u8 cmd[] = { + [0 ] =RAVE_SP_CMD_GET_I2C_DEVICE_STATUS , + [1 ] =0 + }; +
Quoted 9 lines
drivers/platform/rave/rave-sp.c line 341
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +6
-0+ ret =rave_sp_exec (sp, cmd,sizeof (cmd), &status,sizeof (status)); +if (ret <0 ) +return ret; + +return sprintf (buf,"%04x\n" ,le16_to_cpup ((__le16 *)status)); +}Ditto.
Will add in v4.
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 501
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +3
-0+static int rave_sp_write (struct rave_sp *sp,const u8 *data,u8 data_size) +{ +size_t length;Slightly better to put this line after *dest definition.
OK, coming in v4.
Quoted 30 lines
drivers/platform/rave/rave-sp.c line 528
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-0+const size_t checksum_length = sp->variant->checksum->length; +unsigned char crc[checksum_length]; +unsigned char frame[RAVE_SP_TX_BUFFER_SIZE ]; +unsigned char *dest = frame; +static u8 rave_sp_reply_code (u8 command) +{ +/* +* There isn't a signle rule that describes command code -> Typo: single.
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +5
-0+* ACK code transformation, but, going through various +* versions of ICDs, there appear to be three distinct groups +* that can be described by simple transformation. +*/ +switch (command) {drivers/platform/rave/rave-sp.c line 543
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+ case 0xA0 ... 0xBE: +/* +* Commands implemented by firmware found in RDU1 and +* older devices all seem to obey the following rule +*/ +return command +0x20 ; + case 0xE0 ... 0xEF: +/* +* Events emitted by all version of the firmare use +* least signifiact bit to get an ACK code
Quoted 2 lines
Typos.
Will fix in v4.
Quoted 36 lines
Quoted 22 lines
drivers/platform/rave/rave-sp.c new file +21
-0+*/ +return command |0x01 ; +default : +/* +* Commands implemented by firmware found in RDU2 are +* similar to "old" commands, but they use slightly +* different offset +*/ +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 = {drivers/platform/rave/rave-sp.c line 573
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+ .code = rave_sp_reply_code((u8)command), + .ackid = ackid, + .data = reply_data, + .length = reply_data_size, + .received = COMPLETION_INITIALIZER_ONSTACK(reply.received), + }; + +if (command <0 ) +return command;Shouldn't be like
Quoted 7 lines
command = sp->variant->cmd.translate(data[0]); if (command < 0) return command; reply.code = rave_sp_reply_code((u8)command);?
Shouldn't really make any difference, rave_sp_reply_code() will either return -EINVAL or some ACK code but in either case it would not be used due to early return on "command" being less that 0.
Quoted 9 lines
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+ +mutex_lock (&sp->bus_lock); + +mutex_lock (&sp->reply_lock); + sp->reply = &reply; +mutex_unlock (&sp->reply_lock); +
Quoted 3 lines
Quoted 1 line
+ data[0] = (u8)command;
unsigned char implies u8.
Fair point. Will remove the typecast.
Quoted 44 lines
Quoted 17 lines
drivers/platform/rave/rave-sp.c new file +16
-0+ 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); + } + +mutex_unlock (&sp->bus_lock); +return ret; +}drivers/platform/rave/rave-sp.c
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +8
-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 ) +return 0x28 ;Comment for use magic values?
Definition for it?Quoted 13 lines
drivers/platform/rave/rave-sp.c new file +12
-0+ +return rave_sp_rdu1_cmd_translate (command); +} +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 : +return 0x12 ; +case RAVE_SP_CMD_BOOT_SOURCE : +return 0x14 ;
Quoted 8 lines
drivers/platform/rave/rave-sp.c line 775
Quoted 6 lines
drivers/platform/rave/rave-sp.c new file +6
-0+case RAVE_SP_CMD_SW_WDT : +return 0x1C ; +case RAVE_SP_CMD_RESET : +return 0x1E ; +case RAVE_SP_CMD_RESET_REASON : +return 0x1F ;Ditto.
I'll add comment explaining the origin of the magic values.
Quoted 6 lines
Quoted 5 lines
drivers/platform/rave/rave-sp.c new file +4
-0+default : +return -EINVAL ; + } +}
Quoted 7 lines
drivers/platform/rave/rave-sp.c line 803
Quoted 4 lines
drivers/platform/rave/rave-sp.c new file +4
-0+static const char *rave_sp_silicon_to_string (struct device *dev, +const __le32 *version) +{ +return devm_kasprintf (dev,GFP_KERNEL ,"%08x\n" ,le32_to_cpup (version));I don't see why you can't use version value instead of pointer.
Sure, I can do that.
Quoted 11 lines
drivers/platform/rave/rave-sp.c line 811
Quoted 8 lines
drivers/platform/rave/rave-sp.c new file +7
-0+} +static const char *rave_sp_copper_to_string (struct device *dev,uint8_t version) +{ +return devm_kasprintf (dev,GFP_KERNEL ,"%02x\n" , version); +} + +Remove extra empty line.
Quoted 9 lines
drivers/platform/rave/rave-sp.c line 1112
Quoted 2 lines
drivers/platform/rave/rave-sp.c new file +2
-0+ .driver = { + .name = KBUILD_MODNAME,This is bad idea. It might be someone can use a platform driver (as part of MFD, for example) and someone else rename driver at some point.
I understand that in practice it's quite unlikely, though better not to put potential issues in the first place.
Sure, I can convert it to a explicit string.
Quoted 15 lines
include/linux/rave-sp.h line 40
Quoted 12 lines
include/linux/rave-sp.h new file +11
-0+ .of_match_table = rave_sp_dt_ids, + }, +static inline u8 rave_sp_action_unpack_event (unsigned long action) +{ +return action &0xff ; +} + +static inline u8 rave_sp_action_unpack_value (unsigned long action) +{ +return (action >>8 ) &0xff ; +}You can drop &
0xffin both cases as it's implied by u8.
Will remove in v4.
Thanks,
Andrey Smirnov
Re: [PATCH v3 1/2] platform: Add driver for RAVE Supervisory Processor
Quoted 17 lines · Andrey Smirnov
Quoted 15 lines · Andy Shevchenko
On Mon, Jul 24, 2017 at 6:09 PM, Andrey Smirnov
<[email protected]> wrote:Field descriptions are supposed to be _short_.
Quoted 9 lines
+ * @part_number_firmware:
+ * @part_number_bootloader:
+ * @reset_reason:
+ * @copper_rev_rmb:
+ * @copper_rev_deb:
+ * @silicon_devid:
+ * @silicon_devrev:
+ * @copper_mod_rmb:
+ * @copper_mod_deb:
Quoted 4 lines
Quoted 1 line
???
That's my interpretation of you advice to describe those fields in detailed comment below.
Put there short descriptions and explain them in details (if you want to) below. Don't leave them blank.
Quoted 28 lines
Quoted 28 lines
Quoted 13 lines
drivers/platform/rave/rave-sp.c new file +13
-0+int devm_rave_sp_register_event_notifier (struct device *dev, +struct notifier_block *nb) +{ +struct rave_sp *sp =dev_get_drvdata (dev->parent); +struct notifier_block **rcnb; +int ret; + + rcnb =devres_alloc (rave_sp_unregister_event_notifier, +sizeof (*rcnb),GFP_KERNEL ); +if (!rcnb) +return -ENOMEM ; + + ret =blocking_notifier_chain_register (&sp->event_notifier_list, nb);drivers/platform/rave/rave-sp.c line 277
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+if (!ret) { + *rcnb = nb; +devres_add (dev, rcnb); + }else { +devres_free (rcnb); + } + +return ret; +} +EXPORT_SYMBOL_GPL (devm_rave_sp_register_event_notifier);Did I miss
EXPORT_SYMBOL_GPL(devm_rave_sp_unregister_event_notifier);
Quoted 7 lines
Quoted 1 line
?
No, you did not, as I mentioned in my reply for v2 to you, there's no use-case for having that function, there's only one MFD-cell driver that calls
devm_rave_sp_register_event_notifier()and it does so as the last step of itsprobe(), so there's not going to be any users ofdevm_rave_sp_unregister_event_notifier().
Ok.
Quoted 16 lines
Quoted 16 lines
drivers/platform/rave/rave-sp.c line 289
Quoted 11 lines
drivers/platform/rave/rave-sp.c new file +11
-0+static const char *devm_rave_sp_version (struct device *dev,const char *buf) +{ +/* +* NOTE: Ther format string below uses %02d to display u16 +* intentionally for the sake of backwards compatibility with +* legacy software. +*/ +return devm_kasprintf (dev,GFP_KERNEL ,"%02d%02d%02d.%c%c\n" , + buf[0 ],le16_to_cpup ((const __le16 *)&buf[1 ]), + buf[3 ], buf[4 ], buf[5 ]); +}One more question about
le16_to_cpup()use. Is the variable in the buffer guaranteed to be always in little endian format? Okay, looks like it's protocol which is little endian. Ok.
Quoted 4 lines
Quoted 2 lines
By the way, here it might be needed to call
get_unaligned().Sure, I'll add that just in case.
He-h, "just in case" is not good enough :-) I would like you understand why that might be needed.
When you run on platforms that have issues with unaligned access you might get weird behaviour. To prevent such we have helpers.
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +9
-0+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 = {drivers/platform/rave/rave-sp.c line 573
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+ .code = rave_sp_reply_code((u8)command), + .ackid = ackid, + .data = reply_data, + .length = reply_data_size, + .received = COMPLETION_INITIALIZER_ONSTACK(reply.received), + }; + +if (command <0 ) +return command;Shouldn't be like
command = sp->variant->cmd.translate(data[0]); if (command < 0) return command;
Quoted 7 lines
Quoted 3 lines
reply.code = rave_sp_reply_code((u8)command);?
Shouldn't really make any difference,
rave_sp_reply_code()will either return-EINVALor some ACK code but in either case it would not be used due to early return on "command" being less that 0.
So, why then run a code that will be thrown away?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 1/2] platform: Add driver for RAVE Supervisory Processor
Quoted 19 lines · Andy Shevchenko
Quoted 17 lines · Andrey Smirnov
Quoted 15 lines · Andy Shevchenko
On Mon, Jul 24, 2017 at 6:09 PM, Andrey Smirnov
<[email protected]> wrote:Field descriptions are supposed to be _short_.
Quoted 9 lines
+ * @part_number_firmware:
+ * @part_number_bootloader:
+ * @reset_reason:
+ * @copper_rev_rmb:
+ * @copper_rev_deb:
+ * @silicon_devid:
+ * @silicon_devrev:
+ * @copper_mod_rmb:
+ * @copper_mod_deb:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
???
That's my interpretation of you advice to describe those fields in detailed comment below.
Put there short descriptions and explain them in details (if you want to) below. Don't leave them blank.
OK.
Quoted 57 lines
Quoted 28 lines
Quoted 28 lines
Quoted 13 lines
drivers/platform/rave/rave-sp.c new file +13
-0+int devm_rave_sp_register_event_notifier (struct device *dev, +struct notifier_block *nb) +{ +struct rave_sp *sp =dev_get_drvdata (dev->parent); +struct notifier_block **rcnb; +int ret; + + rcnb =devres_alloc (rave_sp_unregister_event_notifier, +sizeof (*rcnb),GFP_KERNEL ); +if (!rcnb) +return -ENOMEM ; + + ret =blocking_notifier_chain_register (&sp->event_notifier_list, nb);drivers/platform/rave/rave-sp.c line 277
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +10
-0+if (!ret) { + *rcnb = nb; +devres_add (dev, rcnb); + }else { +devres_free (rcnb); + } + +return ret; +} +EXPORT_SYMBOL_GPL (devm_rave_sp_register_event_notifier);Did I miss
EXPORT_SYMBOL_GPL(devm_rave_sp_unregister_event_notifier);Quoted 7 lines
Quoted 1 line
?
No, you did not, as I mentioned in my reply for v2 to you, there's no use-case for having that function, there's only one MFD-cell driver that calls
devm_rave_sp_register_event_notifier()and it does so as the last step of itsprobe(), so there's not going to be any users ofdevm_rave_sp_unregister_event_notifier().Ok.
Quoted 19 lines
Quoted 18 lines
drivers/platform/rave/rave-sp.c line 289
Quoted 11 lines
drivers/platform/rave/rave-sp.c new file +11
-0+static const char *devm_rave_sp_version (struct device *dev,const char *buf) +{ +/* +* NOTE: Ther format string below uses %02d to display u16 +* intentionally for the sake of backwards compatibility with +* legacy software. +*/ +return devm_kasprintf (dev,GFP_KERNEL ,"%02d%02d%02d.%c%c\n" , + buf[0 ],le16_to_cpup ((const __le16 *)&buf[1 ]), + buf[3 ], buf[4 ], buf[5 ]); +}One more question about
le16_to_cpup()use. Is the variable in the buffer guaranteed to be always in little endian format? Okay, looks like it's protocol which is little endian. Ok.By the way, here it might be needed to call
get_unaligned().
Quoted 8 lines
Quoted 1 line
Sure, I'll add that just in case.
He-h, "just in case" is not good enough :-) I would like you understand why that might be needed.
When you run on platforms that have issues with unaligned access you might get weird behaviour. To prevent such we have helpers.
I understand the purpose of get_unaligned(). The reason I say "just in case" is because such platforms don't really exist in practice. All of the devices that ship with RAVE SP MCUs on-board are ARMv7A based CPUs which should be capable of performing unaligned access.
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 9 lines
drivers/platform/rave/rave-sp.c new file +9
-0+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 = {drivers/platform/rave/rave-sp.c line 573
Quoted 10 lines
drivers/platform/rave/rave-sp.c new file +9
-0+ .code = rave_sp_reply_code((u8)command), + .ackid = ackid, + .data = reply_data, + .length = reply_data_size, + .received = COMPLETION_INITIALIZER_ONSTACK(reply.received), + }; + +if (command <0 ) +return command;Shouldn't be like
command = sp->variant->cmd.translate(data[0]); if (command < 0) return command; reply.code = rave_sp_reply_code((u8)command);
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
?
Shouldn't really make any difference,
rave_sp_reply_code()will either return-EINVALor some ACK code but in either case it would not be used due to early return on "command" being less that 0.So, why then run a code that will be thrown away?
Because this way "reply" is initialized in a single place instead of that code being spread around.
Thanks,
Andrey Smirnov
PATCH v3 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 · 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
Rob Herring
maintainerRe: [PATCH v3 2/2] dt-bindings: mfd: Add bindings for ZII RAVE devices
Quoted 8 lines · Andrey Smirnov
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <nikita.yoush-M4DtvfQ/[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Acked-for-MFD-by Lee Jones <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 4 lines
--- .../devicetree/bindings/mfd/zii,rave-sp.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txt
What happened to my ack?
Rob
--
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 v3 2/2] dt-bindings: mfd: Add bindings for ZII RAVE devices
Quoted 14 lines · Rob Herring
Quoted 8 lines · Andrey Smirnov
Cc Lucas Stach <[email protected]>Cc Nikita Yushchenko <nikita.yoush-M4DtvfQ/[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Acked-for-MFD-by Lee Jones <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>Quoted 4 lines
--- .../devicetree/bindings/mfd/zii,rave-sp.txt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/zii,rave-sp.txt
Quoted 1 line
What happened to my ack?
Somehow I lost it, sorry about that. Will put it back in v4.
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