rmi_driver.c (552c69b36ebd966186573b9c7a286b390935cce1) rmi_driver.c (24d28e4f1271cb2f91613dada8f2acccd00eff56)
1/*
2 * Copyright (c) 2011-2016 Synaptics Incorporated
3 * Copyright (c) 2011 Unixphere
4 *
5 * This driver provides the core support for a single RMI4-based device.
6 *
7 * The RMI4 specification can be found here (URL split for line length):
8 *

--- 7 unchanged lines hidden (view full) ---

16
17#include <linux/bitmap.h>
18#include <linux/delay.h>
19#include <linux/fs.h>
20#include <linux/irq.h>
21#include <linux/pm.h>
22#include <linux/slab.h>
23#include <linux/of.h>
1/*
2 * Copyright (c) 2011-2016 Synaptics Incorporated
3 * Copyright (c) 2011 Unixphere
4 *
5 * This driver provides the core support for a single RMI4-based device.
6 *
7 * The RMI4 specification can be found here (URL split for line length):
8 *

--- 7 unchanged lines hidden (view full) ---

16
17#include <linux/bitmap.h>
18#include <linux/delay.h>
19#include <linux/fs.h>
20#include <linux/irq.h>
21#include <linux/pm.h>
22#include <linux/slab.h>
23#include <linux/of.h>
24#include <linux/irqdomain.h>
24#include <uapi/linux/input.h>
25#include <linux/rmi.h>
26#include "rmi_bus.h"
27#include "rmi_driver.h"
28
29#define HAS_NONSTANDARD_PDT_MASK 0x40
30#define RMI4_MAX_PAGE 0xff
31#define RMI4_PAGE_SIZE 0x100

--- 90 unchanged lines hidden (view full) ---

122 retval = configure_one_function(entry);
123 if (retval < 0)
124 return retval;
125 }
126
127 return 0;
128}
129
25#include <uapi/linux/input.h>
26#include <linux/rmi.h>
27#include "rmi_bus.h"
28#include "rmi_driver.h"
29
30#define HAS_NONSTANDARD_PDT_MASK 0x40
31#define RMI4_MAX_PAGE 0xff
32#define RMI4_PAGE_SIZE 0x100

--- 90 unchanged lines hidden (view full) ---

123 retval = configure_one_function(entry);
124 if (retval < 0)
125 return retval;
126 }
127
128 return 0;
129}
130
130static void process_one_interrupt(struct rmi_driver_data *data,
131 struct rmi_function *fn)
132{
133 struct rmi_function_handler *fh;
134
135 if (!fn || !fn->dev.driver)
136 return;
137
138 fh = to_rmi_function_handler(fn->dev.driver);
139 if (fh->attention) {
140 bitmap_and(data->fn_irq_bits, data->irq_status, fn->irq_mask,
141 data->irq_count);
142 if (!bitmap_empty(data->fn_irq_bits, data->irq_count))
143 fh->attention(fn, data->fn_irq_bits);
144 }
145}
146
147static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
148{
149 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
150 struct device *dev = &rmi_dev->dev;
131static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
132{
133 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
134 struct device *dev = &rmi_dev->dev;
151 struct rmi_function *entry;
135 int i;
152 int error;
153
154 if (!data)
155 return 0;
156
157 if (!data->attn_data.data) {
158 error = rmi_read_block(rmi_dev,
159 data->f01_container->fd.data_base_addr + 1,

--- 8 unchanged lines hidden (view full) ---

168 bitmap_and(data->irq_status, data->irq_status, data->current_irq_mask,
169 data->irq_count);
170 /*
171 * At this point, irq_status has all bits that are set in the
172 * interrupt status register and are enabled.
173 */
174 mutex_unlock(&data->irq_mutex);
175
136 int error;
137
138 if (!data)
139 return 0;
140
141 if (!data->attn_data.data) {
142 error = rmi_read_block(rmi_dev,
143 data->f01_container->fd.data_base_addr + 1,

--- 8 unchanged lines hidden (view full) ---

152 bitmap_and(data->irq_status, data->irq_status, data->current_irq_mask,
153 data->irq_count);
154 /*
155 * At this point, irq_status has all bits that are set in the
156 * interrupt status register and are enabled.
157 */
158 mutex_unlock(&data->irq_mutex);
159
176 /*
177 * It would be nice to be able to use irq_chip to handle these
178 * nested IRQs. Unfortunately, most of the current customers for
179 * this driver are using older kernels (3.0.x) that don't support
180 * the features required for that. Once they've shifted to more
181 * recent kernels (say, 3.3 and higher), this should be switched to
182 * use irq_chip.
183 */
184 list_for_each_entry(entry, &data->function_list, node)
185 process_one_interrupt(data, entry);
160 for_each_set_bit(i, data->irq_status, data->irq_count)
161 handle_nested_irq(irq_find_mapping(data->irqdomain, i));
186
187 if (data->input)
188 input_sync(data->input);
189
190 return 0;
191}
192
193void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,

--- 801 unchanged lines hidden (view full) ---

995
996 return retval;
997}
998EXPORT_SYMBOL_GPL(rmi_driver_resume);
999
1000static int rmi_driver_remove(struct device *dev)
1001{
1002 struct rmi_device *rmi_dev = to_rmi_device(dev);
162
163 if (data->input)
164 input_sync(data->input);
165
166 return 0;
167}
168
169void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,

--- 801 unchanged lines hidden (view full) ---

971
972 return retval;
973}
974EXPORT_SYMBOL_GPL(rmi_driver_resume);
975
976static int rmi_driver_remove(struct device *dev)
977{
978 struct rmi_device *rmi_dev = to_rmi_device(dev);
979 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
1003
1004 rmi_disable_irq(rmi_dev, false);
1005
980
981 rmi_disable_irq(rmi_dev, false);
982
983 irq_domain_remove(data->irqdomain);
984 data->irqdomain = NULL;
985
1006 rmi_f34_remove_sysfs(rmi_dev);
1007 rmi_free_function_list(rmi_dev);
1008
1009 return 0;
1010}
1011
1012#ifdef CONFIG_OF
1013static int rmi_driver_of_probe(struct device *dev,

--- 15 unchanged lines hidden (view full) ---

1029 return -ENODEV;
1030}
1031#endif
1032
1033int rmi_probe_interrupts(struct rmi_driver_data *data)
1034{
1035 struct rmi_device *rmi_dev = data->rmi_dev;
1036 struct device *dev = &rmi_dev->dev;
986 rmi_f34_remove_sysfs(rmi_dev);
987 rmi_free_function_list(rmi_dev);
988
989 return 0;
990}
991
992#ifdef CONFIG_OF
993static int rmi_driver_of_probe(struct device *dev,

--- 15 unchanged lines hidden (view full) ---

1009 return -ENODEV;
1010}
1011#endif
1012
1013int rmi_probe_interrupts(struct rmi_driver_data *data)
1014{
1015 struct rmi_device *rmi_dev = data->rmi_dev;
1016 struct device *dev = &rmi_dev->dev;
1037 int irq_count;
1017 struct fwnode_handle *fwnode = rmi_dev->xport->dev->fwnode;
1018 int irq_count = 0;
1038 size_t size;
1039 int retval;
1040
1041 /*
1042 * We need to count the IRQs and allocate their storage before scanning
1043 * the PDT and creating the function entries, because adding a new
1044 * function can trigger events that result in the IRQ related storage
1045 * being accessed.
1046 */
1047 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Counting IRQs.\n", __func__);
1019 size_t size;
1020 int retval;
1021
1022 /*
1023 * We need to count the IRQs and allocate their storage before scanning
1024 * the PDT and creating the function entries, because adding a new
1025 * function can trigger events that result in the IRQ related storage
1026 * being accessed.
1027 */
1028 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Counting IRQs.\n", __func__);
1048 irq_count = 0;
1049 data->bootloader_mode = false;
1050
1051 retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs);
1052 if (retval < 0) {
1053 dev_err(dev, "IRQ counting failed with code %d.\n", retval);
1054 return retval;
1055 }
1056
1057 if (data->bootloader_mode)
1058 dev_warn(dev, "Device in bootloader mode.\n");
1059
1029 data->bootloader_mode = false;
1030
1031 retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs);
1032 if (retval < 0) {
1033 dev_err(dev, "IRQ counting failed with code %d.\n", retval);
1034 return retval;
1035 }
1036
1037 if (data->bootloader_mode)
1038 dev_warn(dev, "Device in bootloader mode.\n");
1039
1040 /* Allocate and register a linear revmap irq_domain */
1041 data->irqdomain = irq_domain_create_linear(fwnode, irq_count,
1042 &irq_domain_simple_ops,
1043 data);
1044 if (!data->irqdomain) {
1045 dev_err(&rmi_dev->dev, "Failed to create IRQ domain\n");
1046 return PTR_ERR(data->irqdomain);
1047 }
1048
1060 data->irq_count = irq_count;
1061 data->num_of_irq_regs = (data->irq_count + 7) / 8;
1062
1063 size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long);
1064 data->irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL);
1065 if (!data->irq_memory) {
1066 dev_err(dev, "Failed to allocate memory for irq masks.\n");
1067 return -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

1074
1075 return retval;
1076}
1077
1078int rmi_init_functions(struct rmi_driver_data *data)
1079{
1080 struct rmi_device *rmi_dev = data->rmi_dev;
1081 struct device *dev = &rmi_dev->dev;
1049 data->irq_count = irq_count;
1050 data->num_of_irq_regs = (data->irq_count + 7) / 8;
1051
1052 size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long);
1053 data->irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL);
1054 if (!data->irq_memory) {
1055 dev_err(dev, "Failed to allocate memory for irq masks.\n");
1056 return -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

1063
1064 return retval;
1065}
1066
1067int rmi_init_functions(struct rmi_driver_data *data)
1068{
1069 struct rmi_device *rmi_dev = data->rmi_dev;
1070 struct device *dev = &rmi_dev->dev;
1082 int irq_count;
1071 int irq_count = 0;
1083 int retval;
1084
1072 int retval;
1073
1085 irq_count = 0;
1086 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__);
1087 retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function);
1088 if (retval < 0) {
1089 dev_err(dev, "Function creation failed with code %d.\n",
1090 retval);
1091 goto err_destroy_functions;
1092 }
1093

--- 199 unchanged lines hidden ---
1074 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__);
1075 retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function);
1076 if (retval < 0) {
1077 dev_err(dev, "Function creation failed with code %d.\n",
1078 retval);
1079 goto err_destroy_functions;
1080 }
1081

--- 199 unchanged lines hidden ---