hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/pinctrl/renesas/pinctrl-rza2.c
....@@ -14,6 +14,7 @@
1414 #include <linux/gpio/driver.h>
1515 #include <linux/io.h>
1616 #include <linux/module.h>
17
+#include <linux/mutex.h>
1718 #include <linux/of_device.h>
1819 #include <linux/pinctrl/pinmux.h>
1920
....@@ -46,6 +47,7 @@
4647 struct pinctrl_dev *pctl;
4748 struct pinctrl_gpio_range gpio_range;
4849 int npins;
50
+ struct mutex mutex; /* serialize adding groups and functions */
4951 };
5052
5153 #define RZA2_PDR(port) (0x0000 + (port) * 2) /* Direction 16-bit */
....@@ -359,10 +361,14 @@
359361 psel_val[i] = MUX_FUNC(value);
360362 }
361363
364
+ mutex_lock(&priv->mutex);
365
+
362366 /* Register a single pin group listing all the pins we read from DT */
363367 gsel = pinctrl_generic_add_group(pctldev, np->name, pins, npins, NULL);
364
- if (gsel < 0)
365
- return gsel;
368
+ if (gsel < 0) {
369
+ ret = gsel;
370
+ goto unlock;
371
+ }
366372
367373 /*
368374 * Register a single group function where the 'data' is an array PSEL
....@@ -391,6 +397,8 @@
391397 (*map)->data.mux.function = np->name;
392398 *num_maps = 1;
393399
400
+ mutex_unlock(&priv->mutex);
401
+
394402 return 0;
395403
396404 remove_function:
....@@ -398,6 +406,9 @@
398406
399407 remove_group:
400408 pinctrl_generic_remove_group(pctldev, gsel);
409
+
410
+unlock:
411
+ mutex_unlock(&priv->mutex);
401412
402413 dev_err(priv->dev, "Unable to parse DT node %s\n", np->name);
403414
....@@ -474,6 +485,8 @@
474485 if (IS_ERR(priv->base))
475486 return PTR_ERR(priv->base);
476487
488
+ mutex_init(&priv->mutex);
489
+
477490 platform_set_drvdata(pdev, priv);
478491
479492 priv->npins = (int)(uintptr_t)of_device_get_match_data(&pdev->dev) *