Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: rave-sp: Emulate CMD_GET_STATUS on device that don't support it

CMD_GET_STATUS is not supported by some devices implementing
RDU2-compatible ICD as well as "legacy" devices. To account for that
fact, add code that obtains the same information (app/bootloader FW
version) using several different commands.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Andrey Smirnov and committed by
Lee Jones
80d139b8 405dfd48

+63 -33
+63 -33
drivers/mfd/rave-sp.c
··· 117 117 void (*subroutine)(const u8 *, size_t, u8 *); 118 118 }; 119 119 120 + struct rave_sp_version { 121 + u8 hardware; 122 + __le16 major; 123 + u8 minor; 124 + u8 letter[2]; 125 + } __packed; 126 + 127 + struct rave_sp_status { 128 + struct rave_sp_version bootloader_version; 129 + struct rave_sp_version firmware_version; 130 + u16 rdu_eeprom_flag; 131 + u16 dds_eeprom_flag; 132 + u8 pic_flag; 133 + u8 orientation; 134 + u32 etc; 135 + s16 temp[2]; 136 + u8 backlight_current[3]; 137 + u8 dip_switch; 138 + u8 host_interrupt; 139 + u16 voltage_28; 140 + u8 i2c_device_status; 141 + u8 power_status; 142 + u8 general_status; 143 + u8 deprecated1; 144 + u8 power_led_status; 145 + u8 deprecated2; 146 + u8 periph_power_shutoff; 147 + } __packed; 148 + 120 149 /** 121 150 * struct rave_sp_variant_cmds - Variant specific command routines 122 151 * 123 152 * @translate: Generic to variant specific command mapping routine 124 - * 153 + * @get_status: Variant specific implementation of CMD_GET_STATUS 125 154 */ 126 155 struct rave_sp_variant_cmds { 127 156 int (*translate)(enum rave_sp_command); 157 + int (*get_status)(struct rave_sp *sp, struct rave_sp_status *); 128 158 }; 129 159 130 160 /** ··· 199 169 const char *part_number_firmware; 200 170 const char *part_number_bootloader; 201 171 }; 202 - 203 - struct rave_sp_version { 204 - u8 hardware; 205 - __le16 major; 206 - u8 minor; 207 - u8 letter[2]; 208 - } __packed; 209 - 210 - struct rave_sp_status { 211 - struct rave_sp_version bootloader_version; 212 - struct rave_sp_version firmware_version; 213 - u16 rdu_eeprom_flag; 214 - u16 dds_eeprom_flag; 215 - u8 pic_flag; 216 - u8 orientation; 217 - u32 etc; 218 - s16 temp[2]; 219 - u8 backlight_current[3]; 220 - u8 dip_switch; 221 - u8 host_interrupt; 222 - u16 voltage_28; 223 - u8 i2c_device_status; 224 - u8 power_status; 225 - u8 general_status; 226 - u8 deprecated1; 227 - u8 power_led_status; 228 - u8 deprecated2; 229 - u8 periph_power_shutoff; 230 - } __packed; 231 172 232 173 static bool rave_sp_id_is_event(u8 code) 233 174 { ··· 661 660 version->letter[1]); 662 661 } 663 662 664 - static int rave_sp_get_status(struct rave_sp *sp) 663 + static int rave_sp_rdu1_get_status(struct rave_sp *sp, 664 + struct rave_sp_status *status) 665 665 { 666 - struct device *dev = &sp->serdev->dev; 667 666 u8 cmd[] = { 668 667 [0] = RAVE_SP_CMD_STATUS, 669 668 [1] = 0 670 669 }; 670 + 671 + return rave_sp_exec(sp, cmd, sizeof(cmd), status, sizeof(*status)); 672 + } 673 + 674 + static int rave_sp_emulated_get_status(struct rave_sp *sp, 675 + struct rave_sp_status *status) 676 + { 677 + u8 cmd[] = { 678 + [0] = RAVE_SP_CMD_GET_FIRMWARE_VERSION, 679 + [1] = 0, 680 + }; 681 + int ret; 682 + 683 + ret = rave_sp_exec(sp, cmd, sizeof(cmd), &status->firmware_version, 684 + sizeof(status->firmware_version)); 685 + if (ret) 686 + return ret; 687 + 688 + cmd[0] = RAVE_SP_CMD_GET_BOOTLOADER_VERSION; 689 + return rave_sp_exec(sp, cmd, sizeof(cmd), &status->bootloader_version, 690 + sizeof(status->bootloader_version)); 691 + } 692 + 693 + static int rave_sp_get_status(struct rave_sp *sp) 694 + { 695 + struct device *dev = &sp->serdev->dev; 671 696 struct rave_sp_status status; 672 697 const char *version; 673 698 int ret; 674 699 675 - ret = rave_sp_exec(sp, cmd, sizeof(cmd), &status, sizeof(status)); 700 + ret = sp->variant->cmd.get_status(sp, &status); 676 701 if (ret) 677 702 return ret; 678 703 ··· 731 704 .checksum = &rave_sp_checksum_ccitt, 732 705 .cmd = { 733 706 .translate = rave_sp_default_cmd_translate, 707 + .get_status = rave_sp_emulated_get_status, 734 708 }, 735 709 }; 736 710 ··· 739 711 .checksum = &rave_sp_checksum_8b2c, 740 712 .cmd = { 741 713 .translate = rave_sp_rdu1_cmd_translate, 714 + .get_status = rave_sp_rdu1_get_status, 742 715 }, 743 716 }; 744 717 ··· 747 718 .checksum = &rave_sp_checksum_ccitt, 748 719 .cmd = { 749 720 .translate = rave_sp_rdu2_cmd_translate, 721 + .get_status = rave_sp_emulated_get_status, 750 722 }, 751 723 }; 752 724