@@ -103,6 +103,7 @@ struct regulator_rpmsg_s
103
103
{
104
104
FAR struct regulator_s * regulator ;
105
105
struct list_node node ;
106
+ bool enable ;
106
107
};
107
108
108
109
/****************************************************************************
@@ -204,7 +205,7 @@ regulator_rpmsg_get_client(FAR const char *name)
204
205
}
205
206
}
206
207
207
- client = kmm_zalloc (sizeof (* client ) + slash - name );
208
+ client = kmm_zalloc (sizeof (* client ) + slash - name + 1 );
208
209
if (client == NULL )
209
210
{
210
211
goto out ;
@@ -253,9 +254,8 @@ regulator_rpmsg_get_ept(FAR const char **name)
253
254
return & client -> ept ;
254
255
}
255
256
256
- static FAR struct regulator_s *
257
- regulator_rpmsg_get_regulator (FAR struct rpmsg_endpoint * ept ,
258
- FAR const char * name )
257
+ static FAR struct regulator_rpmsg_s *
258
+ regulator_rpmsg_get_reg (FAR struct rpmsg_endpoint * ept , FAR const char * name )
259
259
{
260
260
FAR struct regulator_rpmsg_server_s * server = ept -> priv ;
261
261
FAR struct list_node * regulator_list = & server -> regulator_list ;
@@ -268,13 +268,14 @@ regulator_rpmsg_get_regulator(FAR struct rpmsg_endpoint *ept,
268
268
if (strcmp (reg -> regulator -> rdev -> desc -> name , name ) == 0 )
269
269
{
270
270
nxmutex_unlock (& server -> lock );
271
- return reg -> regulator ;
271
+ return reg ;
272
272
}
273
273
}
274
274
275
275
reg = kmm_zalloc (sizeof (* reg ));
276
276
if (reg == NULL )
277
277
{
278
+ nxmutex_unlock (& server -> lock );
278
279
return NULL ;
279
280
}
280
281
@@ -287,8 +288,9 @@ regulator_rpmsg_get_regulator(FAR struct rpmsg_endpoint *ept,
287
288
}
288
289
289
290
list_add_head (regulator_list , & reg -> node );
291
+
290
292
nxmutex_unlock (& server -> lock );
291
- return reg -> regulator ;
293
+ return reg ;
292
294
}
293
295
294
296
static void regulator_rpmsg_client_created (struct rpmsg_device * rdev ,
@@ -321,8 +323,11 @@ static void regulator_rpmsg_client_destroy(struct rpmsg_device *rdev,
321
323
return ;
322
324
}
323
325
324
- nxsem_wait (& client -> sem );
325
- rpmsg_destroy_ept (& client -> ept );
326
+ if (strcmp (client -> cpuname , rpmsg_get_cpuname (rdev )) == 0 )
327
+ {
328
+ nxsem_wait (& client -> sem );
329
+ rpmsg_destroy_ept (& client -> ept );
330
+ }
326
331
}
327
332
328
333
static void regulator_rpmsg_server_unbind (FAR struct rpmsg_endpoint * ept )
@@ -334,7 +339,7 @@ static void regulator_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
334
339
list_for_every_entry_safe (& server -> regulator_list , reg , tmp ,
335
340
struct regulator_rpmsg_s , node )
336
341
{
337
- while ( regulator_is_enabled ( reg -> regulator ) )
342
+ if ( reg -> enable )
338
343
{
339
344
regulator_disable (reg -> regulator );
340
345
}
@@ -411,10 +416,24 @@ static int regulator_rpmsg_enable_handler(FAR struct rpmsg_endpoint *ept,
411
416
uint32_t src , FAR void * priv )
412
417
{
413
418
FAR struct regulator_rpmsg_enable_s * msg = data ;
414
- FAR struct regulator_s * regulator =
415
- regulator_rpmsg_get_regulator (ept , msg -> name );
419
+ FAR struct regulator_rpmsg_s * reg =
420
+ regulator_rpmsg_get_reg (ept , msg -> name );
421
+ int ret = - ENOENT ;
416
422
417
- msg -> header .result = regulator_enable (regulator );
423
+ if (reg && !reg -> enable )
424
+ {
425
+ ret = regulator_enable (reg -> regulator );
426
+ if (ret >= 0 )
427
+ {
428
+ reg -> enable = true;
429
+ }
430
+ }
431
+ else if (reg && reg -> enable )
432
+ {
433
+ ret = 0 ;
434
+ }
435
+
436
+ msg -> header .result = ret ;
418
437
return rpmsg_send (ept , data , len );
419
438
}
420
439
@@ -423,10 +442,24 @@ static int regulator_rpmsg_disable_handler(FAR struct rpmsg_endpoint *ept,
423
442
uint32_t src , FAR void * priv )
424
443
{
425
444
FAR struct regulator_rpmsg_disable_s * msg = data ;
426
- FAR struct regulator_s * regulator =
427
- regulator_rpmsg_get_regulator (ept , msg -> name );
445
+ FAR struct regulator_rpmsg_s * reg =
446
+ regulator_rpmsg_get_reg (ept , msg -> name );
447
+ int ret = - ENOENT ;
428
448
429
- msg -> header .result = regulator_disable (regulator );
449
+ if (reg && reg -> enable )
450
+ {
451
+ ret = regulator_disable (reg -> regulator );
452
+ if (ret >= 0 )
453
+ {
454
+ reg -> enable = false;
455
+ }
456
+ }
457
+ else if (reg && !reg -> enable )
458
+ {
459
+ ret = 0 ;
460
+ }
461
+
462
+ msg -> header .result = ret ;
430
463
return rpmsg_send (ept , data , len );
431
464
}
432
465
@@ -435,10 +468,16 @@ static int regulator_rpmsg_getvol_handler(FAR struct rpmsg_endpoint *ept,
435
468
uint32_t src , FAR void * priv )
436
469
{
437
470
FAR struct regulator_rpmsg_getvol_s * msg = data ;
438
- FAR struct regulator_s * regulator =
439
- regulator_rpmsg_get_regulator (ept , msg -> name );
471
+ FAR struct regulator_rpmsg_s * reg =
472
+ regulator_rpmsg_get_reg (ept , msg -> name );
473
+ int ret = - ENOENT ;
474
+
475
+ if (reg )
476
+ {
477
+ ret = regulator_get_voltage (reg -> regulator );
478
+ }
440
479
441
- msg -> header .result = regulator_get_voltage ( regulator ) ;
480
+ msg -> header .result = ret ;
442
481
return rpmsg_send (ept , data , len );
443
482
}
444
483
@@ -447,11 +486,17 @@ static int regulator_rpmsg_setvol_handler(FAR struct rpmsg_endpoint *ept,
447
486
uint32_t src , FAR void * priv )
448
487
{
449
488
FAR struct regulator_rpmsg_setvol_s * msg = data ;
450
- FAR struct regulator_s * regulator =
451
- regulator_rpmsg_get_regulator (ept , msg -> name );
489
+ FAR struct regulator_rpmsg_s * reg =
490
+ regulator_rpmsg_get_reg (ept , msg -> name );
491
+ int ret = - ENOENT ;
492
+
493
+ if (reg )
494
+ {
495
+ ret = regulator_set_voltage (reg -> regulator ,
496
+ msg -> min_uv , msg -> max_uv );
497
+ }
452
498
453
- msg -> header .result =
454
- regulator_set_voltage (regulator , msg -> min_uv , msg -> max_uv );
499
+ msg -> header .result = ret ;
455
500
return rpmsg_send (ept , data , len );
456
501
}
457
502
@@ -460,10 +505,16 @@ static int regulator_rpmsg_isenabled_handler(FAR struct rpmsg_endpoint *ept,
460
505
uint32_t src , FAR void * priv )
461
506
{
462
507
FAR struct regulator_rpmsg_isenabled_s * msg = data ;
463
- FAR struct regulator_s * regulator =
464
- regulator_rpmsg_get_regulator (ept , msg -> name );
508
+ FAR struct regulator_rpmsg_s * reg =
509
+ regulator_rpmsg_get_reg (ept , msg -> name );
510
+ int ret = - ENOENT ;
465
511
466
- msg -> header .result = regulator_is_enabled (regulator );
512
+ if (reg )
513
+ {
514
+ ret = reg -> enable ;
515
+ }
516
+
517
+ msg -> header .result = ret ;
467
518
return rpmsg_send (ept , data , len );
468
519
}
469
520
@@ -658,6 +709,7 @@ FAR struct regulator_dev_s *regulator_rpmsg_get(FAR const char *name)
658
709
{
659
710
FAR struct regulator_desc_s * desc ;
660
711
FAR struct regulator_dev_s * dev ;
712
+ FAR char * pname ;
661
713
size_t len = strlen (name ) + 1 ;
662
714
663
715
desc = kmm_zalloc (sizeof (* desc ) + len );
@@ -666,9 +718,9 @@ FAR struct regulator_dev_s *regulator_rpmsg_get(FAR const char *name)
666
718
return NULL ;
667
719
}
668
720
669
- desc -> name = desc + 1 ;
670
- memcpy (desc -> name , name , len );
671
-
721
+ pname = ( FAR char * )( desc + 1 ) ;
722
+ memcpy (pname , name , len );
723
+ desc -> name = pname ;
672
724
dev = regulator_register (desc , & g_regulator_rpmsg_ops , NULL );
673
725
if (dev == NULL )
674
726
{
0 commit comments