aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hid/hid-cp2112.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index f31a778b0851..3e0b6bad29f2 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -168,7 +168,7 @@ struct cp2112_device {
168 atomic_t xfer_avail; 168 atomic_t xfer_avail;
169 struct gpio_chip gc; 169 struct gpio_chip gc;
170 u8 *in_out_buffer; 170 u8 *in_out_buffer;
171 spinlock_t lock; 171 struct mutex lock;
172 172
173 struct gpio_desc *desc[8]; 173 struct gpio_desc *desc[8];
174 bool gpio_poll; 174 bool gpio_poll;
@@ -186,10 +186,9 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
186 struct cp2112_device *dev = gpiochip_get_data(chip); 186 struct cp2112_device *dev = gpiochip_get_data(chip);
187 struct hid_device *hdev = dev->hdev; 187 struct hid_device *hdev = dev->hdev;
188 u8 *buf = dev->in_out_buffer; 188 u8 *buf = dev->in_out_buffer;
189 unsigned long flags;
190 int ret; 189 int ret;
191 190
192 spin_lock_irqsave(&dev->lock, flags); 191 mutex_lock(&dev->lock);
193 192
194 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, 193 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
195 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT, 194 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
@@ -213,7 +212,7 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
213 ret = 0; 212 ret = 0;
214 213
215exit: 214exit:
216 spin_unlock_irqrestore(&dev->lock, flags); 215 mutex_unlock(&dev->lock);
217 return ret <= 0 ? ret : -EIO; 216 return ret <= 0 ? ret : -EIO;
218} 217}
219 218
@@ -222,10 +221,9 @@ static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
222 struct cp2112_device *dev = gpiochip_get_data(chip); 221 struct cp2112_device *dev = gpiochip_get_data(chip);
223 struct hid_device *hdev = dev->hdev; 222 struct hid_device *hdev = dev->hdev;
224 u8 *buf = dev->in_out_buffer; 223 u8 *buf = dev->in_out_buffer;
225 unsigned long flags;
226 int ret; 224 int ret;
227 225
228 spin_lock_irqsave(&dev->lock, flags); 226 mutex_lock(&dev->lock);
229 227
230 buf[0] = CP2112_GPIO_SET; 228 buf[0] = CP2112_GPIO_SET;
231 buf[1] = value ? 0xff : 0; 229 buf[1] = value ? 0xff : 0;
@@ -237,7 +235,7 @@ static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
237 if (ret < 0) 235 if (ret < 0)
238 hid_err(hdev, "error setting GPIO values: %d\n", ret); 236 hid_err(hdev, "error setting GPIO values: %d\n", ret);
239 237
240 spin_unlock_irqrestore(&dev->lock, flags); 238 mutex_unlock(&dev->lock);
241} 239}
242 240
243static int cp2112_gpio_get_all(struct gpio_chip *chip) 241static int cp2112_gpio_get_all(struct gpio_chip *chip)
@@ -245,10 +243,9 @@ static int cp2112_gpio_get_all(struct gpio_chip *chip)
245 struct cp2112_device *dev = gpiochip_get_data(chip); 243 struct cp2112_device *dev = gpiochip_get_data(chip);
246 struct hid_device *hdev = dev->hdev; 244 struct hid_device *hdev = dev->hdev;
247 u8 *buf = dev->in_out_buffer; 245 u8 *buf = dev->in_out_buffer;
248 unsigned long flags;
249 int ret; 246 int ret;
250 247
251 spin_lock_irqsave(&dev->lock, flags); 248 mutex_lock(&dev->lock);
252 249
253 ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf, 250 ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf,
254 CP2112_GPIO_GET_LENGTH, HID_FEATURE_REPORT, 251 CP2112_GPIO_GET_LENGTH, HID_FEATURE_REPORT,
@@ -262,7 +259,7 @@ static int cp2112_gpio_get_all(struct gpio_chip *chip)
262 ret = buf[1]; 259 ret = buf[1];
263 260
264exit: 261exit:
265 spin_unlock_irqrestore(&dev->lock, flags); 262 mutex_unlock(&dev->lock);
266 263
267 return ret; 264 return ret;
268} 265}
@@ -284,10 +281,9 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
284 struct cp2112_device *dev = gpiochip_get_data(chip); 281 struct cp2112_device *dev = gpiochip_get_data(chip);
285 struct hid_device *hdev = dev->hdev; 282 struct hid_device *hdev = dev->hdev;
286 u8 *buf = dev->in_out_buffer; 283 u8 *buf = dev->in_out_buffer;
287 unsigned long flags;
288 int ret; 284 int ret;
289 285
290 spin_lock_irqsave(&dev->lock, flags); 286 mutex_lock(&dev->lock);
291 287
292 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, 288 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
293 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT, 289 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
@@ -308,7 +304,7 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
308 goto fail; 304 goto fail;
309 } 305 }
310 306
311 spin_unlock_irqrestore(&dev->lock, flags); 307 mutex_unlock(&dev->lock);
312 308
313 /* 309 /*
314 * Set gpio value when output direction is already set, 310 * Set gpio value when output direction is already set,
@@ -319,7 +315,7 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
319 return 0; 315 return 0;
320 316
321fail: 317fail:
322 spin_unlock_irqrestore(&dev->lock, flags); 318 mutex_unlock(&dev->lock);
323 return ret < 0 ? ret : -EIO; 319 return ret < 0 ? ret : -EIO;
324} 320}
325 321
@@ -1235,7 +1231,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
1235 if (!dev->in_out_buffer) 1231 if (!dev->in_out_buffer)
1236 return -ENOMEM; 1232 return -ENOMEM;
1237 1233
1238 spin_lock_init(&dev->lock); 1234 mutex_init(&dev->lock);
1239 1235
1240 ret = hid_parse(hdev); 1236 ret = hid_parse(hdev);
1241 if (ret) { 1237 if (ret) {