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

Input: synaptics-rmi4 - factor out functions from probe

Signed-off-by: Nick Dyer <nick@shmanahar.org>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
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
6bd0dcfa ad338e8b

+86 -53
+86 -53
drivers/input/rmi4/rmi_driver.c
··· 39 39 struct rmi_function *fn, *tmp; 40 40 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); 41 41 42 + rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev, "Freeing function list\n"); 43 + 42 44 data->f01_container = NULL; 43 45 44 46 /* Doing it in the reverse order so F01 will be removed last */ ··· 857 855 } 858 856 #endif 859 857 858 + static int rmi_probe_interrupts(struct rmi_driver_data *data) 859 + { 860 + struct rmi_device *rmi_dev = data->rmi_dev; 861 + struct device *dev = &rmi_dev->dev; 862 + int irq_count; 863 + size_t size; 864 + void *irq_memory; 865 + int retval; 866 + 867 + /* 868 + * We need to count the IRQs and allocate their storage before scanning 869 + * the PDT and creating the function entries, because adding a new 870 + * function can trigger events that result in the IRQ related storage 871 + * being accessed. 872 + */ 873 + rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Counting IRQs.\n", __func__); 874 + irq_count = 0; 875 + retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs); 876 + if (retval < 0) { 877 + dev_err(dev, "IRQ counting failed with code %d.\n", retval); 878 + return retval; 879 + } 880 + data->irq_count = irq_count; 881 + data->num_of_irq_regs = (data->irq_count + 7) / 8; 882 + 883 + size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long); 884 + irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL); 885 + if (!irq_memory) { 886 + dev_err(dev, "Failed to allocate memory for irq masks.\n"); 887 + return retval; 888 + } 889 + 890 + data->irq_status = irq_memory + size * 0; 891 + data->fn_irq_bits = irq_memory + size * 1; 892 + data->current_irq_mask = irq_memory + size * 2; 893 + data->new_irq_mask = irq_memory + size * 3; 894 + 895 + return retval; 896 + } 897 + 898 + static int rmi_init_functions(struct rmi_driver_data *data) 899 + { 900 + struct rmi_device *rmi_dev = data->rmi_dev; 901 + struct device *dev = &rmi_dev->dev; 902 + int irq_count; 903 + int retval; 904 + 905 + irq_count = 0; 906 + rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__); 907 + retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function); 908 + if (retval < 0) { 909 + dev_err(dev, "Function creation failed with code %d.\n", 910 + retval); 911 + goto err_destroy_functions; 912 + } 913 + 914 + if (!data->f01_container) { 915 + dev_err(dev, "Missing F01 container!\n"); 916 + retval = -EINVAL; 917 + goto err_destroy_functions; 918 + } 919 + 920 + retval = rmi_read_block(rmi_dev, 921 + data->f01_container->fd.control_base_addr + 1, 922 + data->current_irq_mask, data->num_of_irq_regs); 923 + if (retval < 0) { 924 + dev_err(dev, "%s: Failed to read current IRQ mask.\n", 925 + __func__); 926 + goto err_destroy_functions; 927 + } 928 + 929 + return 0; 930 + 931 + err_destroy_functions: 932 + rmi_free_function_list(rmi_dev); 933 + return retval; 934 + } 935 + 860 936 static int rmi_driver_probe(struct device *dev) 861 937 { 862 938 struct rmi_driver *rmi_driver; 863 939 struct rmi_driver_data *data; 864 940 struct rmi_device_platform_data *pdata; 865 941 struct rmi_device *rmi_dev; 866 - size_t size; 867 - void *irq_memory; 868 - int irq_count; 869 942 int retval; 870 943 871 944 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Starting probe.\n", ··· 1006 929 PDT_PROPERTIES_LOCATION, retval); 1007 930 } 1008 931 1009 - /* 1010 - * We need to count the IRQs and allocate their storage before scanning 1011 - * the PDT and creating the function entries, because adding a new 1012 - * function can trigger events that result in the IRQ related storage 1013 - * being accessed. 1014 - */ 1015 - rmi_dbg(RMI_DEBUG_CORE, dev, "Counting IRQs.\n"); 1016 - irq_count = 0; 1017 - retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs); 1018 - if (retval < 0) { 1019 - dev_err(dev, "IRQ counting failed with code %d.\n", retval); 1020 - goto err; 1021 - } 1022 - data->irq_count = irq_count; 1023 - data->num_of_irq_regs = (data->irq_count + 7) / 8; 1024 - 1025 932 mutex_init(&data->irq_mutex); 1026 933 1027 - size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long); 1028 - irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL); 1029 - if (!irq_memory) { 1030 - dev_err(dev, "Failed to allocate memory for irq masks.\n"); 934 + retval = rmi_probe_interrupts(data); 935 + if (retval) 1031 936 goto err; 1032 - } 1033 - 1034 - data->irq_status = irq_memory + size * 0; 1035 - data->fn_irq_bits = irq_memory + size * 1; 1036 - data->current_irq_mask = irq_memory + size * 2; 1037 - data->new_irq_mask = irq_memory + size * 3; 1038 937 1039 938 if (rmi_dev->xport->input) { 1040 939 /* ··· 1027 974 dev_err(dev, "%s: Failed to allocate input device.\n", 1028 975 __func__); 1029 976 retval = -ENOMEM; 1030 - goto err_destroy_functions; 977 + goto err; 1031 978 } 1032 979 rmi_driver_set_input_params(rmi_dev, data->input); 1033 980 data->input->phys = devm_kasprintf(dev, GFP_KERNEL, 1034 981 "%s/input0", dev_name(dev)); 1035 982 } 1036 983 1037 - irq_count = 0; 1038 - rmi_dbg(RMI_DEBUG_CORE, dev, "Creating functions."); 1039 - retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function); 1040 - if (retval < 0) { 1041 - dev_err(dev, "Function creation failed with code %d.\n", 1042 - retval); 1043 - goto err_destroy_functions; 1044 - } 1045 - 1046 - if (!data->f01_container) { 1047 - dev_err(dev, "Missing F01 container!\n"); 1048 - retval = -EINVAL; 1049 - goto err_destroy_functions; 1050 - } 1051 - 1052 - retval = rmi_read_block(rmi_dev, 1053 - data->f01_container->fd.control_base_addr + 1, 1054 - data->current_irq_mask, data->num_of_irq_regs); 1055 - if (retval < 0) { 1056 - dev_err(dev, "%s: Failed to read current IRQ mask.\n", 1057 - __func__); 1058 - goto err_destroy_functions; 1059 - } 984 + retval = rmi_init_functions(data); 985 + if (retval) 986 + goto err; 1060 987 1061 988 if (data->input) { 1062 989 rmi_driver_set_input_name(rmi_dev, data->input);