| .. | .. |
|---|
| 14 | 14 | #include <linux/gpio/driver.h> |
|---|
| 15 | 15 | #include <linux/io.h> |
|---|
| 16 | 16 | #include <linux/module.h> |
|---|
| 17 | +#include <linux/mutex.h> |
|---|
| 17 | 18 | #include <linux/of_device.h> |
|---|
| 18 | 19 | #include <linux/pinctrl/pinmux.h> |
|---|
| 19 | 20 | |
|---|
| .. | .. |
|---|
| 46 | 47 | struct pinctrl_dev *pctl; |
|---|
| 47 | 48 | struct pinctrl_gpio_range gpio_range; |
|---|
| 48 | 49 | int npins; |
|---|
| 50 | + struct mutex mutex; /* serialize adding groups and functions */ |
|---|
| 49 | 51 | }; |
|---|
| 50 | 52 | |
|---|
| 51 | 53 | #define RZA2_PDR(port) (0x0000 + (port) * 2) /* Direction 16-bit */ |
|---|
| .. | .. |
|---|
| 359 | 361 | psel_val[i] = MUX_FUNC(value); |
|---|
| 360 | 362 | } |
|---|
| 361 | 363 | |
|---|
| 364 | + mutex_lock(&priv->mutex); |
|---|
| 365 | + |
|---|
| 362 | 366 | /* Register a single pin group listing all the pins we read from DT */ |
|---|
| 363 | 367 | 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 | + } |
|---|
| 366 | 372 | |
|---|
| 367 | 373 | /* |
|---|
| 368 | 374 | * Register a single group function where the 'data' is an array PSEL |
|---|
| .. | .. |
|---|
| 391 | 397 | (*map)->data.mux.function = np->name; |
|---|
| 392 | 398 | *num_maps = 1; |
|---|
| 393 | 399 | |
|---|
| 400 | + mutex_unlock(&priv->mutex); |
|---|
| 401 | + |
|---|
| 394 | 402 | return 0; |
|---|
| 395 | 403 | |
|---|
| 396 | 404 | remove_function: |
|---|
| .. | .. |
|---|
| 398 | 406 | |
|---|
| 399 | 407 | remove_group: |
|---|
| 400 | 408 | pinctrl_generic_remove_group(pctldev, gsel); |
|---|
| 409 | + |
|---|
| 410 | +unlock: |
|---|
| 411 | + mutex_unlock(&priv->mutex); |
|---|
| 401 | 412 | |
|---|
| 402 | 413 | dev_err(priv->dev, "Unable to parse DT node %s\n", np->name); |
|---|
| 403 | 414 | |
|---|
| .. | .. |
|---|
| 474 | 485 | if (IS_ERR(priv->base)) |
|---|
| 475 | 486 | return PTR_ERR(priv->base); |
|---|
| 476 | 487 | |
|---|
| 488 | + mutex_init(&priv->mutex); |
|---|
| 489 | + |
|---|
| 477 | 490 | platform_set_drvdata(pdev, priv); |
|---|
| 478 | 491 | |
|---|
| 479 | 492 | priv->npins = (int)(uintptr_t)of_device_get_match_data(&pdev->dev) * |
|---|