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,6 +47,7 @@ struct rza2_pinctrl_priv {
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 */
@@ -358,10 +360,14 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev,
358
360
psel_val [i ] = MUX_FUNC (value );
359
361
}
360
362
363
+ mutex_lock (& priv -> mutex );
364
+
361
365
/* Register a single pin group listing all the pins we read from DT */
362
366
gsel = pinctrl_generic_add_group (pctldev , np -> name , pins , npins , NULL );
363
- if (gsel < 0 )
364
- return gsel ;
367
+ if (gsel < 0 ) {
368
+ ret = gsel ;
369
+ goto unlock ;
370
+ }
365
371
366
372
/*
367
373
* Register a single group function where the 'data' is an array PSEL
@@ -390,6 +396,8 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev,
390
396
(* map )-> data .mux .function = np -> name ;
391
397
* num_maps = 1 ;
392
398
399
+ mutex_unlock (& priv -> mutex );
400
+
393
401
return 0 ;
394
402
395
403
remove_function :
@@ -398,6 +406,9 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev,
398
406
remove_group :
399
407
pinctrl_generic_remove_group (pctldev , gsel );
400
408
409
+ unlock :
410
+ mutex_unlock (& priv -> mutex );
411
+
401
412
dev_err (priv -> dev , "Unable to parse DT node %s\n" , np -> name );
402
413
403
414
return ret ;
@@ -473,6 +484,8 @@ static int rza2_pinctrl_probe(struct platform_device *pdev)
473
484
if (IS_ERR (priv -> base ))
474
485
return PTR_ERR (priv -> base );
475
486
487
+ mutex_init (& priv -> mutex );
488
+
476
489
platform_set_drvdata (pdev , priv );
477
490
478
491
priv -> npins = (int )(uintptr_t )of_device_get_match_data (& pdev -> dev ) *
0 commit comments