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

Input: synaptics-rmi4 - add support for F34 device reflash

Add support for updating firmware, triggered by a sysfs attribute.

This patch has been tested on Synaptics S7300.

Signed-off-by: Nick Dyer <nick@shmanahar.org>
Tested-by: Chris Healy <cphealy@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Nick Dyer and committed by
Dmitry Torokhov
29fd0ec2 792f497b

+670 -31
+11
drivers/input/rmi4/Kconfig
··· 74 74 Function 30 provides GPIO and LED support for RMI4 devices. This 75 75 includes support for buttons on TouchPads and ClickPads. 76 76 77 + config RMI4_F34 78 + bool "RMI4 Function 34 (Device reflash)" 79 + depends on RMI4_CORE 80 + select FW_LOADER 81 + help 82 + Say Y here if you want to add support for RMI4 function 34. 83 + 84 + Function 34 provides support for upgrading the firmware on the RMI4 85 + device via the firmware loader interface. This is triggered using a 86 + sysfs attribute. 87 + 77 88 config RMI4_F54 78 89 bool "RMI4 Function 54 (Analog diagnostics)" 79 90 depends on RMI4_CORE
+1
drivers/input/rmi4/Makefile
··· 7 7 rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o 8 8 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o 9 9 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o 10 + rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o 10 11 rmi_core-$(CONFIG_RMI4_F54) += rmi_f54.o 11 12 12 13 # Transports
+3
drivers/input/rmi4/rmi_bus.c
··· 315 315 #ifdef CONFIG_RMI4_F30 316 316 &rmi_f30_handler, 317 317 #endif 318 + #ifdef CONFIG_RMI4_F34 319 + &rmi_f34_handler, 320 + #endif 318 321 #ifdef CONFIG_RMI4_F54 319 322 &rmi_f54_handler, 320 323 #endif
+74 -31
drivers/input/rmi4/rmi_driver.c
··· 35 35 #define RMI_DEVICE_RESET_CMD 0x01 36 36 #define DEFAULT_RESET_DELAY_MS 100 37 37 38 - static void rmi_free_function_list(struct rmi_device *rmi_dev) 38 + void rmi_free_function_list(struct rmi_device *rmi_dev) 39 39 { 40 40 struct rmi_function *fn, *tmp; 41 41 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); 42 42 43 43 rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev, "Freeing function list\n"); 44 44 45 + mutex_lock(&data->irq_mutex); 46 + 47 + devm_kfree(&rmi_dev->dev, data->irq_memory); 48 + data->irq_memory = NULL; 49 + data->irq_status = NULL; 50 + data->fn_irq_bits = NULL; 51 + data->current_irq_mask = NULL; 52 + data->new_irq_mask = NULL; 53 + 45 54 data->f01_container = NULL; 55 + data->f34_container = NULL; 46 56 47 57 /* Doing it in the reverse order so F01 will be removed last */ 48 58 list_for_each_entry_safe_reverse(fn, tmp, ··· 60 50 list_del(&fn->node); 61 51 rmi_unregister_function(fn); 62 52 } 53 + 54 + mutex_unlock(&data->irq_mutex); 63 55 } 56 + EXPORT_SYMBOL_GPL(rmi_free_function_list); 64 57 65 58 static int reset_one_function(struct rmi_function *fn) 66 59 { ··· 160 147 if (!data) 161 148 return 0; 162 149 150 + mutex_lock(&data->irq_mutex); 151 + if (!data->irq_status || !data->f01_container) { 152 + mutex_unlock(&data->irq_mutex); 153 + return 0; 154 + } 155 + 163 156 if (!rmi_dev->xport->attn_data) { 164 157 error = rmi_read_block(rmi_dev, 165 158 data->f01_container->fd.data_base_addr + 1, 166 159 data->irq_status, data->num_of_irq_regs); 167 160 if (error < 0) { 168 161 dev_err(dev, "Failed to read irqs, code=%d\n", error); 162 + mutex_unlock(&data->irq_mutex); 169 163 return error; 170 164 } 171 165 } 172 166 173 - mutex_lock(&data->irq_mutex); 174 167 bitmap_and(data->irq_status, data->irq_status, data->current_irq_mask, 175 168 data->irq_count); 176 - /* 177 - * At this point, irq_status has all bits that are set in the 178 - * interrupt status register and are enabled. 179 - */ 180 - mutex_unlock(&data->irq_mutex); 181 169 182 170 /* 183 171 * It would be nice to be able to use irq_chip to handle these ··· 193 179 194 180 if (data->input) 195 181 input_sync(data->input); 182 + 183 + mutex_unlock(&data->irq_mutex); 196 184 197 185 return 0; 198 186 } ··· 260 244 struct rmi_function *entry; 261 245 int retval; 262 246 247 + mutex_lock(&data->irq_mutex); 248 + 263 249 list_for_each_entry(entry, &data->function_list, node) { 264 250 retval = suspend_one_function(entry); 265 - if (retval < 0) 251 + if (retval < 0) { 252 + mutex_unlock(&data->irq_mutex); 266 253 return retval; 254 + } 267 255 } 256 + 257 + mutex_unlock(&data->irq_mutex); 268 258 269 259 return 0; 270 260 } ··· 300 278 struct rmi_function *entry; 301 279 int retval; 302 280 281 + mutex_lock(&data->irq_mutex); 282 + 303 283 list_for_each_entry(entry, &data->function_list, node) { 304 284 retval = resume_one_function(entry); 305 - if (retval < 0) 285 + if (retval < 0) { 286 + mutex_unlock(&data->irq_mutex); 306 287 return retval; 288 + } 307 289 } 290 + 291 + mutex_unlock(&data->irq_mutex); 308 292 309 293 return 0; 310 294 } 311 295 312 - static int enable_sensor(struct rmi_device *rmi_dev) 296 + int rmi_enable_sensor(struct rmi_device *rmi_dev) 313 297 { 314 298 int retval = 0; 315 299 ··· 325 297 326 298 return rmi_process_interrupt_requests(rmi_dev); 327 299 } 300 + EXPORT_SYMBOL_GPL(rmi_enable_sensor); 328 301 329 302 /** 330 303 * rmi_driver_set_input_params - set input device id and other data. ··· 531 502 RMI_SCAN_DONE : RMI_SCAN_CONTINUE; 532 503 } 533 504 534 - static int rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx, 535 - int (*callback)(struct rmi_device *rmi_dev, 536 - void *ctx, 537 - const struct pdt_entry *entry)) 505 + int rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx, 506 + int (*callback)(struct rmi_device *rmi_dev, 507 + void *ctx, const struct pdt_entry *entry)) 538 508 { 539 509 int page; 540 510 int empty_pages = 0; ··· 548 520 549 521 return retval < 0 ? retval : 0; 550 522 } 523 + EXPORT_SYMBOL_GPL(rmi_scan_pdt); 551 524 552 525 int rmi_read_register_desc(struct rmi_device *d, u16 addr, 553 526 struct rmi_register_descriptor *rdesc) ··· 769 740 int *irq_count = ctx; 770 741 771 742 *irq_count += pdt->interrupt_source_count; 772 - if (pdt->function_number == 0x01) { 743 + if (pdt->function_number == 0x01) 773 744 data->f01_bootloader_mode = 774 745 rmi_check_bootloader_mode(rmi_dev, pdt); 775 - if (data->f01_bootloader_mode) 776 - dev_warn(&rmi_dev->dev, 777 - "WARNING: RMI4 device is in bootloader mode!\n"); 778 - } 779 746 780 747 return RMI_SCAN_CONTINUE; 781 748 } 782 749 783 - static int rmi_initial_reset(struct rmi_device *rmi_dev, 784 - void *ctx, const struct pdt_entry *pdt) 750 + int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx, 751 + const struct pdt_entry *pdt) 785 752 { 786 753 int error; 787 754 ··· 812 787 /* F01 should always be on page 0. If we don't find it there, fail. */ 813 788 return pdt->page_start == 0 ? RMI_SCAN_CONTINUE : -ENODEV; 814 789 } 790 + EXPORT_SYMBOL_GPL(rmi_initial_reset); 815 791 816 792 static int rmi_create_function(struct rmi_device *rmi_dev, 817 793 void *ctx, const struct pdt_entry *pdt) ··· 854 828 855 829 if (pdt->function_number == 0x01) 856 830 data->f01_container = fn; 831 + else if (pdt->function_number == 0x34) 832 + data->f34_container = fn; 857 833 858 834 list_add_tail(&fn->node, &data->function_list); 859 835 ··· 921 893 922 894 disable_irq(irq); 923 895 896 + rmi_f34_remove_sysfs(rmi_dev); 924 897 rmi_free_function_list(rmi_dev); 925 898 926 899 return 0; ··· 948 919 } 949 920 #endif 950 921 951 - static int rmi_probe_interrupts(struct rmi_driver_data *data) 922 + int rmi_probe_interrupts(struct rmi_driver_data *data) 952 923 { 953 924 struct rmi_device *rmi_dev = data->rmi_dev; 954 925 struct device *dev = &rmi_dev->dev; 955 926 int irq_count; 956 927 size_t size; 957 - void *irq_memory; 958 928 int retval; 959 929 960 930 /* ··· 969 941 dev_err(dev, "IRQ counting failed with code %d.\n", retval); 970 942 return retval; 971 943 } 944 + 945 + if (data->f01_bootloader_mode) 946 + dev_warn(&rmi_dev->dev, "Device in bootloader mode.\n"); 947 + 972 948 data->irq_count = irq_count; 973 949 data->num_of_irq_regs = (data->irq_count + 7) / 8; 974 950 975 951 size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long); 976 - irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL); 977 - if (!irq_memory) { 952 + data->irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL); 953 + if (!data->irq_memory) { 978 954 dev_err(dev, "Failed to allocate memory for irq masks.\n"); 979 955 return retval; 980 956 } 981 957 982 - data->irq_status = irq_memory + size * 0; 983 - data->fn_irq_bits = irq_memory + size * 1; 984 - data->current_irq_mask = irq_memory + size * 2; 985 - data->new_irq_mask = irq_memory + size * 3; 958 + data->irq_status = data->irq_memory + size * 0; 959 + data->fn_irq_bits = data->irq_memory + size * 1; 960 + data->current_irq_mask = data->irq_memory + size * 2; 961 + data->new_irq_mask = data->irq_memory + size * 3; 986 962 987 963 return retval; 988 964 } 965 + EXPORT_SYMBOL_GPL(rmi_probe_interrupts); 989 966 990 - static int rmi_init_functions(struct rmi_driver_data *data) 967 + int rmi_init_functions(struct rmi_driver_data *data) 991 968 { 992 969 struct rmi_device *rmi_dev = data->rmi_dev; 993 970 struct device *dev = &rmi_dev->dev; 994 971 int irq_count; 995 972 int retval; 973 + 974 + mutex_lock(&data->irq_mutex); 996 975 997 976 irq_count = 0; 998 977 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__); ··· 1025 990 goto err_destroy_functions; 1026 991 } 1027 992 993 + mutex_unlock(&data->irq_mutex); 994 + 1028 995 return 0; 1029 996 1030 997 err_destroy_functions: 1031 998 rmi_free_function_list(rmi_dev); 999 + mutex_unlock(&data->irq_mutex); 1032 1000 return retval; 1033 1001 } 1002 + EXPORT_SYMBOL_GPL(rmi_init_functions); 1034 1003 1035 1004 static int rmi_driver_probe(struct device *dev) 1036 1005 { ··· 1139 1100 if (retval) 1140 1101 goto err; 1141 1102 1103 + retval = rmi_f34_create_sysfs(rmi_dev); 1104 + if (retval) 1105 + goto err; 1106 + 1142 1107 if (data->input) { 1143 1108 rmi_driver_set_input_name(rmi_dev, data->input); 1144 1109 if (!rmi_dev->xport->input) { ··· 1160 1117 1161 1118 if (data->f01_container->dev.driver) 1162 1119 /* Driver already bound, so enable ATTN now. */ 1163 - return enable_sensor(rmi_dev); 1120 + return rmi_enable_sensor(rmi_dev); 1164 1121 1165 1122 return 0; 1166 1123
+24
drivers/input/rmi4/rmi_driver.h
··· 95 95 bool rmi_is_physical_driver(struct device_driver *); 96 96 int rmi_register_physical_driver(void); 97 97 void rmi_unregister_physical_driver(void); 98 + void rmi_free_function_list(struct rmi_device *rmi_dev); 99 + int rmi_enable_sensor(struct rmi_device *rmi_dev); 100 + int rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx, 101 + int (*callback)(struct rmi_device *rmi_dev, void *ctx, 102 + const struct pdt_entry *entry)); 103 + int rmi_probe_interrupts(struct rmi_driver_data *data); 104 + int rmi_init_functions(struct rmi_driver_data *data); 105 + int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx, 106 + const struct pdt_entry *pdt); 98 107 99 108 char *rmi_f01_get_product_ID(struct rmi_function *fn); 109 + 110 + #ifdef CONFIG_RMI4_F34 111 + int rmi_f34_create_sysfs(struct rmi_device *rmi_dev); 112 + void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev); 113 + #else 114 + static inline int rmi_f34_create_sysfs(struct rmi_device *rmi_dev) 115 + { 116 + return 0; 117 + } 118 + 119 + static inline void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev) 120 + { 121 + } 122 + #endif /* CONFIG_RMI_F34 */ 100 123 101 124 extern struct rmi_function_handler rmi_f01_handler; 102 125 extern struct rmi_function_handler rmi_f11_handler; 103 126 extern struct rmi_function_handler rmi_f12_handler; 104 127 extern struct rmi_function_handler rmi_f30_handler; 128 + extern struct rmi_function_handler rmi_f34_handler; 105 129 extern struct rmi_function_handler rmi_f54_handler; 106 130 #endif
+6
drivers/input/rmi4/rmi_f01.c
··· 63 63 #define RMI_F01_STATUS_CODE(status) ((status) & 0x0f) 64 64 /* The device has lost its configuration for some reason. */ 65 65 #define RMI_F01_STATUS_UNCONFIGURED(status) (!!((status) & 0x80)) 66 + /* The device is in bootloader mode */ 67 + #define RMI_F01_STATUS_BOOTLOADER(status) ((status) & 0x40) 66 68 67 69 /* Control register bits */ 68 70 ··· 595 593 "Failed to read device status: %d.\n", error); 596 594 return error; 597 595 } 596 + 597 + if (RMI_F01_STATUS_BOOTLOADER(device_status)) 598 + dev_warn(&fn->dev, 599 + "Device in bootloader mode, please update firmware\n"); 598 600 599 601 if (RMI_F01_STATUS_UNCONFIGURED(device_status)) { 600 602 dev_warn(&fn->dev, "Device reset detected.\n");
+481
drivers/input/rmi4/rmi_f34.c
··· 1 + /* 2 + * Copyright (c) 2007-2016, Synaptics Incorporated 3 + * Copyright (C) 2016 Zodiac Inflight Innovations 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms of the GNU General Public License version 2 as published by 7 + * the Free Software Foundation. 8 + */ 9 + 10 + #include <linux/kernel.h> 11 + #include <linux/rmi.h> 12 + #include <linux/firmware.h> 13 + #include <asm/unaligned.h> 14 + #include <asm/unaligned.h> 15 + 16 + #include "rmi_driver.h" 17 + #include "rmi_f34.h" 18 + 19 + static int rmi_f34_write_bootloader_id(struct f34_data *f34) 20 + { 21 + struct rmi_function *fn = f34->fn; 22 + struct rmi_device *rmi_dev = fn->rmi_dev; 23 + u8 bootloader_id[F34_BOOTLOADER_ID_LEN]; 24 + int ret; 25 + 26 + ret = rmi_read_block(rmi_dev, fn->fd.query_base_addr, 27 + bootloader_id, sizeof(bootloader_id)); 28 + if (ret) { 29 + dev_err(&fn->dev, "%s: Reading bootloader ID failed: %d\n", 30 + __func__, ret); 31 + return ret; 32 + } 33 + 34 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s: writing bootloader id '%c%c'\n", 35 + __func__, bootloader_id[0], bootloader_id[1]); 36 + 37 + ret = rmi_write_block(rmi_dev, 38 + fn->fd.data_base_addr + F34_BLOCK_DATA_OFFSET, 39 + bootloader_id, sizeof(bootloader_id)); 40 + if (ret) { 41 + dev_err(&fn->dev, "Failed to write bootloader ID: %d\n", ret); 42 + return ret; 43 + } 44 + 45 + return 0; 46 + } 47 + 48 + static int rmi_f34_command(struct f34_data *f34, u8 command, 49 + unsigned int timeout, bool write_bl_id) 50 + { 51 + struct rmi_function *fn = f34->fn; 52 + struct rmi_device *rmi_dev = fn->rmi_dev; 53 + int ret; 54 + 55 + if (write_bl_id) { 56 + ret = rmi_f34_write_bootloader_id(f34); 57 + if (ret) 58 + return ret; 59 + } 60 + 61 + init_completion(&f34->v5.cmd_done); 62 + 63 + ret = rmi_read(rmi_dev, f34->v5.ctrl_address, &f34->v5.status); 64 + if (ret) { 65 + dev_err(&f34->fn->dev, 66 + "%s: Failed to read cmd register: %d (command %#02x)\n", 67 + __func__, ret, command); 68 + return ret; 69 + } 70 + 71 + f34->v5.status |= command & 0x0f; 72 + 73 + ret = rmi_write(rmi_dev, f34->v5.ctrl_address, f34->v5.status); 74 + if (ret < 0) { 75 + dev_err(&f34->fn->dev, 76 + "Failed to write F34 command %#02x: %d\n", 77 + command, ret); 78 + return ret; 79 + } 80 + 81 + if (!wait_for_completion_timeout(&f34->v5.cmd_done, 82 + msecs_to_jiffies(timeout))) { 83 + 84 + ret = rmi_read(rmi_dev, f34->v5.ctrl_address, &f34->v5.status); 85 + if (ret) { 86 + dev_err(&f34->fn->dev, 87 + "%s: cmd %#02x timed out: %d\n", 88 + __func__, command, ret); 89 + return ret; 90 + } 91 + 92 + if (f34->v5.status & 0x7f) { 93 + dev_err(&f34->fn->dev, 94 + "%s: cmd %#02x timed out, status: %#02x\n", 95 + __func__, command, f34->v5.status); 96 + return -ETIMEDOUT; 97 + } 98 + } 99 + 100 + return 0; 101 + } 102 + 103 + static int rmi_f34_attention(struct rmi_function *fn, unsigned long *irq_bits) 104 + { 105 + struct f34_data *f34 = dev_get_drvdata(&fn->dev); 106 + int ret; 107 + 108 + ret = rmi_read(f34->fn->rmi_dev, f34->v5.ctrl_address, &f34->v5.status); 109 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s: status: %#02x, ret: %d\n", 110 + __func__, f34->v5.status, ret); 111 + 112 + if (!ret && !(f34->v5.status & 0x7f)) 113 + complete(&f34->v5.cmd_done); 114 + 115 + return 0; 116 + } 117 + 118 + static int rmi_f34_write_blocks(struct f34_data *f34, const void *data, 119 + int block_count, u8 command) 120 + { 121 + struct rmi_function *fn = f34->fn; 122 + struct rmi_device *rmi_dev = fn->rmi_dev; 123 + u16 address = fn->fd.data_base_addr + F34_BLOCK_DATA_OFFSET; 124 + u8 start_address[] = { 0, 0 }; 125 + int i; 126 + int ret; 127 + 128 + ret = rmi_write_block(rmi_dev, fn->fd.data_base_addr, 129 + start_address, sizeof(start_address)); 130 + if (ret) { 131 + dev_err(&fn->dev, "Failed to write initial zeros: %d\n", ret); 132 + return ret; 133 + } 134 + 135 + for (i = 0; i < block_count; i++) { 136 + ret = rmi_write_block(rmi_dev, address, 137 + data, f34->v5.block_size); 138 + if (ret) { 139 + dev_err(&fn->dev, 140 + "failed to write block #%d: %d\n", i, ret); 141 + return ret; 142 + } 143 + 144 + ret = rmi_f34_command(f34, command, F34_IDLE_WAIT_MS, false); 145 + if (ret) { 146 + dev_err(&fn->dev, 147 + "Failed to write command for block #%d: %d\n", 148 + i, ret); 149 + return ret; 150 + } 151 + 152 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "wrote block %d of %d\n", 153 + i + 1, block_count); 154 + 155 + data += f34->v5.block_size; 156 + } 157 + 158 + return 0; 159 + } 160 + 161 + static int rmi_f34_write_firmware(struct f34_data *f34, const void *data) 162 + { 163 + return rmi_f34_write_blocks(f34, data, f34->v5.fw_blocks, 164 + F34_WRITE_FW_BLOCK); 165 + } 166 + 167 + static int rmi_f34_write_config(struct f34_data *f34, const void *data) 168 + { 169 + return rmi_f34_write_blocks(f34, data, f34->v5.config_blocks, 170 + F34_WRITE_CONFIG_BLOCK); 171 + } 172 + 173 + int rmi_f34_enable_flash(struct f34_data *f34) 174 + { 175 + return rmi_f34_command(f34, F34_ENABLE_FLASH_PROG, 176 + F34_ENABLE_WAIT_MS, true); 177 + } 178 + 179 + static int rmi_f34_flash_firmware(struct f34_data *f34, 180 + const struct rmi_f34_firmware *syn_fw) 181 + { 182 + struct rmi_function *fn = f34->fn; 183 + int ret; 184 + 185 + if (syn_fw->image_size) { 186 + dev_info(&fn->dev, "Erasing firmware...\n"); 187 + ret = rmi_f34_command(f34, F34_ERASE_ALL, 188 + F34_ERASE_WAIT_MS, true); 189 + if (ret) 190 + return ret; 191 + 192 + dev_info(&fn->dev, "Writing firmware (%d bytes)...\n", 193 + syn_fw->image_size); 194 + ret = rmi_f34_write_firmware(f34, syn_fw->data); 195 + if (ret) 196 + return ret; 197 + } 198 + 199 + if (syn_fw->config_size) { 200 + /* 201 + * We only need to erase config if we haven't updated 202 + * firmware. 203 + */ 204 + if (!syn_fw->image_size) { 205 + dev_info(&fn->dev, "Erasing config...\n"); 206 + ret = rmi_f34_command(f34, F34_ERASE_CONFIG, 207 + F34_ERASE_WAIT_MS, true); 208 + if (ret) 209 + return ret; 210 + } 211 + 212 + dev_info(&fn->dev, "Writing config (%d bytes)...\n", 213 + syn_fw->config_size); 214 + ret = rmi_f34_write_config(f34, 215 + &syn_fw->data[syn_fw->image_size]); 216 + if (ret) 217 + return ret; 218 + } 219 + 220 + return 0; 221 + } 222 + 223 + int rmi_f34_update_firmware(struct f34_data *f34, const struct firmware *fw) 224 + { 225 + const struct rmi_f34_firmware *syn_fw; 226 + int ret; 227 + 228 + syn_fw = (const struct rmi_f34_firmware *)fw->data; 229 + BUILD_BUG_ON(offsetof(struct rmi_f34_firmware, data) != 230 + F34_FW_IMAGE_OFFSET); 231 + 232 + rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, 233 + "FW size:%d, checksum:%08x, image_size:%d, config_size:%d\n", 234 + (int)fw->size, 235 + le32_to_cpu(syn_fw->checksum), 236 + le32_to_cpu(syn_fw->image_size), 237 + le32_to_cpu(syn_fw->config_size)); 238 + 239 + rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, 240 + "FW bootloader_id:%02x, product_id:%.*s, info: %02x%02x\n", 241 + syn_fw->bootloader_version, 242 + (int)sizeof(syn_fw->product_id), syn_fw->product_id, 243 + syn_fw->product_info[0], syn_fw->product_info[1]); 244 + 245 + if (syn_fw->image_size && 246 + syn_fw->image_size != f34->v5.fw_blocks * f34->v5.block_size) { 247 + dev_err(&f34->fn->dev, 248 + "Bad firmware image: fw size %d, expected %d\n", 249 + syn_fw->image_size, 250 + f34->v5.fw_blocks * f34->v5.block_size); 251 + ret = -EILSEQ; 252 + goto out; 253 + } 254 + 255 + if (syn_fw->config_size && 256 + syn_fw->config_size != f34->v5.config_blocks * f34->v5.block_size) { 257 + dev_err(&f34->fn->dev, 258 + "Bad firmware image: config size %d, expected %d\n", 259 + syn_fw->config_size, 260 + f34->v5.config_blocks * f34->v5.block_size); 261 + ret = -EILSEQ; 262 + goto out; 263 + } 264 + 265 + if (syn_fw->image_size && !syn_fw->config_size) { 266 + dev_err(&f34->fn->dev, "Bad firmware image: no config data\n"); 267 + ret = -EILSEQ; 268 + goto out; 269 + } 270 + 271 + dev_info(&f34->fn->dev, "Firmware image OK\n"); 272 + mutex_lock(&f34->v5.flash_mutex); 273 + 274 + ret = rmi_f34_flash_firmware(f34, syn_fw); 275 + 276 + mutex_unlock(&f34->v5.flash_mutex); 277 + 278 + out: 279 + return ret; 280 + } 281 + 282 + static int rmi_firmware_update(struct rmi_driver_data *data, 283 + const struct firmware *fw) 284 + { 285 + struct device *dev = &data->rmi_dev->dev; 286 + struct f34_data *f34; 287 + int ret; 288 + 289 + if (!data->f34_container) { 290 + dev_warn(dev, "%s: No F34 present!\n", __func__); 291 + return -EINVAL; 292 + } 293 + 294 + /* Only version 0 currently supported */ 295 + if (data->f34_container->fd.function_version != 0) { 296 + dev_warn(dev, "F34 V%d not supported!\n", 297 + data->f34_container->fd.function_version); 298 + return -ENODEV; 299 + } 300 + 301 + f34 = dev_get_drvdata(&data->f34_container->dev); 302 + 303 + /* Enter flash mode */ 304 + ret = rmi_f34_enable_flash(f34); 305 + if (ret) 306 + return ret; 307 + 308 + /* Tear down functions and re-probe */ 309 + rmi_free_function_list(data->rmi_dev); 310 + 311 + ret = rmi_probe_interrupts(data); 312 + if (ret) 313 + return ret; 314 + 315 + ret = rmi_init_functions(data); 316 + if (ret) 317 + return ret; 318 + 319 + if (!data->f01_bootloader_mode || !data->f34_container) { 320 + dev_warn(dev, "%s: No F34 present or not in bootloader!\n", 321 + __func__); 322 + return -EINVAL; 323 + } 324 + 325 + f34 = dev_get_drvdata(&data->f34_container->dev); 326 + 327 + /* Perform firmware update */ 328 + ret = rmi_f34_update_firmware(f34, fw); 329 + 330 + dev_info(&f34->fn->dev, "Firmware update complete, status:%d\n", ret); 331 + 332 + /* Re-probe */ 333 + rmi_dbg(RMI_DEBUG_FN, dev, "Re-probing device\n"); 334 + rmi_free_function_list(data->rmi_dev); 335 + 336 + ret = rmi_scan_pdt(data->rmi_dev, NULL, rmi_initial_reset); 337 + if (ret < 0) 338 + dev_warn(dev, "RMI reset failed!\n"); 339 + 340 + ret = rmi_probe_interrupts(data); 341 + if (ret) 342 + return ret; 343 + 344 + ret = rmi_init_functions(data); 345 + if (ret) 346 + return ret; 347 + 348 + if (data->f01_container->dev.driver) 349 + /* Driver already bound, so enable ATTN now. */ 350 + return rmi_enable_sensor(data->rmi_dev); 351 + 352 + rmi_dbg(RMI_DEBUG_FN, dev, "%s complete\n", __func__); 353 + 354 + return ret; 355 + } 356 + 357 + static ssize_t rmi_driver_update_fw_store(struct device *dev, 358 + struct device_attribute *dattr, 359 + const char *buf, size_t count) 360 + { 361 + struct rmi_driver_data *data = dev_get_drvdata(dev); 362 + char fw_name[NAME_MAX]; 363 + const struct firmware *fw; 364 + size_t copy_count = count; 365 + int ret; 366 + 367 + if (count == 0 || count >= NAME_MAX) 368 + return -EINVAL; 369 + 370 + if (buf[count - 1] == '\0' || buf[count - 1] == '\n') 371 + copy_count -= 1; 372 + 373 + strncpy(fw_name, buf, copy_count); 374 + fw_name[copy_count] = '\0'; 375 + 376 + ret = request_firmware(&fw, fw_name, dev); 377 + if (ret) 378 + return ret; 379 + 380 + dev_info(dev, "Flashing %s\n", fw_name); 381 + 382 + ret = rmi_firmware_update(data, fw); 383 + 384 + release_firmware(fw); 385 + 386 + return ret ?: count; 387 + } 388 + 389 + static DEVICE_ATTR(update_fw, 0200, NULL, rmi_driver_update_fw_store); 390 + 391 + static struct attribute *rmi_firmware_attrs[] = { 392 + &dev_attr_update_fw.attr, 393 + NULL 394 + }; 395 + 396 + static struct attribute_group rmi_firmware_attr_group = { 397 + .attrs = rmi_firmware_attrs, 398 + }; 399 + 400 + static int rmi_f34_probe(struct rmi_function *fn) 401 + { 402 + struct f34_data *f34; 403 + unsigned char f34_queries[9]; 404 + bool has_config_id; 405 + int ret; 406 + 407 + f34 = devm_kzalloc(&fn->dev, sizeof(struct f34_data), GFP_KERNEL); 408 + if (!f34) 409 + return -ENOMEM; 410 + 411 + f34->fn = fn; 412 + dev_set_drvdata(&fn->dev, f34); 413 + 414 + ret = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr, 415 + f34_queries, sizeof(f34_queries)); 416 + if (ret) { 417 + dev_err(&fn->dev, "%s: Failed to query properties\n", 418 + __func__); 419 + return ret; 420 + } 421 + 422 + snprintf(f34->bootloader_id, sizeof(f34->bootloader_id), 423 + "%c%c", f34_queries[0], f34_queries[1]); 424 + 425 + mutex_init(&f34->v5.flash_mutex); 426 + init_completion(&f34->v5.cmd_done); 427 + 428 + f34->v5.block_size = get_unaligned_le16(&f34_queries[3]); 429 + f34->v5.fw_blocks = get_unaligned_le16(&f34_queries[5]); 430 + f34->v5.config_blocks = get_unaligned_le16(&f34_queries[7]); 431 + f34->v5.ctrl_address = fn->fd.data_base_addr + F34_BLOCK_DATA_OFFSET + 432 + f34->v5.block_size; 433 + has_config_id = f34_queries[2] & (1 << 2); 434 + 435 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Bootloader ID: %s\n", 436 + f34->bootloader_id); 437 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Block size: %d\n", 438 + f34->v5.block_size); 439 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "FW blocks: %d\n", 440 + f34->v5.fw_blocks); 441 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "CFG blocks: %d\n", 442 + f34->v5.config_blocks); 443 + 444 + if (has_config_id) { 445 + ret = rmi_read_block(fn->rmi_dev, fn->fd.control_base_addr, 446 + f34_queries, sizeof(f34_queries)); 447 + if (ret) { 448 + dev_err(&fn->dev, "Failed to read F34 config ID\n"); 449 + return ret; 450 + } 451 + 452 + snprintf(f34->configuration_id, sizeof(f34->configuration_id), 453 + "%02x%02x%02x%02x", 454 + f34_queries[0], f34_queries[1], 455 + f34_queries[2], f34_queries[3]); 456 + 457 + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Configuration ID: %s\n", 458 + f34->configuration_id); 459 + } 460 + 461 + return 0; 462 + } 463 + 464 + int rmi_f34_create_sysfs(struct rmi_device *rmi_dev) 465 + { 466 + return sysfs_create_group(&rmi_dev->dev.kobj, &rmi_firmware_attr_group); 467 + } 468 + 469 + void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev) 470 + { 471 + sysfs_remove_group(&rmi_dev->dev.kobj, &rmi_firmware_attr_group); 472 + } 473 + 474 + struct rmi_function_handler rmi_f34_handler = { 475 + .driver = { 476 + .name = "rmi4_f34", 477 + }, 478 + .func = 0x34, 479 + .probe = rmi_f34_probe, 480 + .attention = rmi_f34_attention, 481 + };
+68
drivers/input/rmi4/rmi_f34.h
··· 1 + /* 2 + * Copyright (c) 2007-2016, Synaptics Incorporated 3 + * Copyright (C) 2016 Zodiac Inflight Innovations 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms of the GNU General Public License version 2 as published by 7 + * the Free Software Foundation. 8 + */ 9 + 10 + #ifndef _RMI_F34_H 11 + #define _RMI_F34_H 12 + 13 + /* F34 image file offsets. */ 14 + #define F34_FW_IMAGE_OFFSET 0x100 15 + 16 + /* F34 register offsets. */ 17 + #define F34_BLOCK_DATA_OFFSET 2 18 + 19 + /* F34 commands */ 20 + #define F34_WRITE_FW_BLOCK 0x2 21 + #define F34_ERASE_ALL 0x3 22 + #define F34_READ_CONFIG_BLOCK 0x5 23 + #define F34_WRITE_CONFIG_BLOCK 0x6 24 + #define F34_ERASE_CONFIG 0x7 25 + #define F34_ENABLE_FLASH_PROG 0xf 26 + 27 + #define F34_STATUS_IN_PROGRESS 0xff 28 + #define F34_STATUS_IDLE 0x80 29 + 30 + #define F34_IDLE_WAIT_MS 500 31 + #define F34_ENABLE_WAIT_MS 300 32 + #define F34_ERASE_WAIT_MS 5000 33 + 34 + #define F34_BOOTLOADER_ID_LEN 2 35 + 36 + struct rmi_f34_firmware { 37 + __le32 checksum; 38 + u8 pad1[3]; 39 + u8 bootloader_version; 40 + __le32 image_size; 41 + __le32 config_size; 42 + u8 product_id[10]; 43 + u8 product_info[2]; 44 + u8 pad2[228]; 45 + u8 data[]; 46 + }; 47 + 48 + struct f34v5_data { 49 + u16 block_size; 50 + u16 fw_blocks; 51 + u16 config_blocks; 52 + u16 ctrl_address; 53 + u8 status; 54 + 55 + struct completion cmd_done; 56 + struct mutex flash_mutex; 57 + }; 58 + 59 + struct f34_data { 60 + struct rmi_function *fn; 61 + 62 + unsigned char bootloader_id[5]; 63 + unsigned char configuration_id[9]; 64 + 65 + struct f34v5_data v5; 66 + }; 67 + 68 + #endif /* _RMI_F34_H */
+2
include/linux/rmi.h
··· 337 337 struct rmi_device *rmi_dev; 338 338 339 339 struct rmi_function *f01_container; 340 + struct rmi_function *f34_container; 340 341 bool f01_bootloader_mode; 341 342 342 343 u32 attn_count; 343 344 int num_of_irq_regs; 344 345 int irq_count; 346 + void *irq_memory; 345 347 unsigned long *irq_status; 346 348 unsigned long *fn_irq_bits; 347 349 unsigned long *current_irq_mask;