1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
|
#include <linux/device.h>
#include <linux/module.h>
#include <linux/ifconn/ifconn_notifier.h>
#include <linux/ifconn/ifconn_manager.h>
#include <linux/muic/muic.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/workqueue.h>
#include <linux/delay.h>
#include <linux/time.h>
#include <linux/ktime.h>
#include <linux/rtc.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/of.h>
#if defined(CONFIG_CCIC_NOTIFIER)
#include <linux/ccic/core.h>
#endif
static int _ifconn_manager_template_notify(struct ifconn_notifier_template *template)
{
int ret;
if (template == NULL) {
pr_info("%s: err, template is NULL\n", __func__);
return -1;
}
ret = ifconn_notifier_notify(template->src,
template->dest,
template->id,
template->event,
IFCONN_NOTIFY_PARAM_TEMPLATE, template);
if (ret < 0)
pr_err("%s: Fail to send noti\n", __func__);
return ret;
}
static void ifconn_manager_noti_work(struct ifconn_manager_data *ifconn_manager,
struct ifconn_notifier_template *template)
{
pr_info("%s: enter, template : %p\n", __func__, template);
mutex_lock(&ifconn_manager->noti_mutex);
template->up_src = template->src;
template->src = IFCONN_NOTIFY_MANAGER;
switch (template->up_src) {
case IFCONN_NOTIFY_MUIC:
if (ifconn_manager->ccic_drp_state == IFCONN_MANAGER_USB_STATUS_DETACH) {
if (template->attach && ifconn_manager->vbus_state == IFCONN_MANAGER_VBUS_STATUS_HIGH) {
msleep(2000);
template->drp = IFCONN_MANAGER_USB_STATUS_ATTACH_UFP;
ifconn_manager->ccic_drp_state = IFCONN_MANAGER_USB_STATUS_ATTACH_UFP;
} else {
template->drp = IFCONN_MANAGER_USB_STATUS_DETACH;
ifconn_manager->ccic_drp_state = IFCONN_MANAGER_USB_STATUS_DETACH;
}
template->sub3 = 0;
template->data = NULL;
}
_ifconn_manager_template_notify(template);
break;
case IFCONN_NOTIFY_CCIC:
pr_info("%s: dbg, line : %d\n", __func__, __LINE__);
if ((ifconn_manager->ccic_drp_state !=
IFCONN_MANAGER_USB_STATUS_ATTACH_UFP)
|| ifconn_manager->is_UFPS) {
pr_info("usb: [M] %s: skip case\n", __func__);
goto EXIT_NOTI_WORK;
}
template->src = IFCONN_NOTIFY_MANAGER;
template->data = NULL;
template->id = IFCONN_NOTIFY_ID_USB;
pr_info("usb: [M] %s: usb=%d, pd=%d\n", __func__,
ifconn_manager->usb_enum_state,
ifconn_manager->pd_con_state);
if (!ifconn_manager->usb_enum_state
|| (ifconn_manager->muic_data_refresh
&& ifconn_manager->cable_type ==
IFCONN_CABLE_TYPE_MUIC_CHARGER)) {
/* TA cable Type */
template->dest = IFCONN_NOTIFY_USB;
template->attach = IFCONN_NOTIFY_DETACH;
template->drp = IFCONN_MANAGER_USB_STATUS_DETACH;
template->sub3 = 0;
} else {
/* USB cable Type */
template->dest = IFCONN_NOTIFY_BATTERY;
template->attach = 0;
template->rprd = 0;
template->cable_type = IFCONN_PD_USB_TYPE;
}
_ifconn_manager_template_notify(template);
break;
case IFCONN_NOTIFY_PDIC:
pr_info("%s: pdic case, up_src : %d\n", __func__,
template->up_src);
template->src = IFCONN_NOTIFY_MANAGER;
template->dest = IFCONN_NOTIFY_BATTERY;
template->id = IFCONN_NOTIFY_ID_POWER_STATUS;
template->event = IFCONN_NOTIFY_EVENT_ATTACH;
_ifconn_manager_template_notify(template);
break;
default:
break;
}
EXIT_NOTI_WORK:
mutex_unlock(&ifconn_manager->noti_mutex);
}
static int ifconn_manager_manage_muic(struct ifconn_manager_data *ifconn_manager,
struct ifconn_notifier_template *template)
{
if (ifconn_manager == NULL || template == NULL)
return -1;
ifconn_manager->muic_action = template->attach;
ifconn_manager->muic_cable_type = template->cable_type;
ifconn_manager->muic_data_refresh = 1;
pr_info("%s, usb: [M] %s: cable type : (%d), id : %d\n", __func__,
__func__, template->cable_type,
template->id);
if (template->id == IFCONN_NOTIFY_ID_ATTACH) {
switch (template->cable_type) {
case ATTACHED_DEV_USB_MUIC:
case ATTACHED_DEV_CDP_MUIC:
case ATTACHED_DEV_UNOFFICIAL_ID_USB_MUIC:
case ATTACHED_DEV_UNOFFICIAL_ID_CDP_MUIC:
case ATTACHED_DEV_JIG_USB_OFF_MUIC:
case ATTACHED_DEV_JIG_USB_ON_MUIC:
if (template->attach)
ifconn_manager->cable_type = IFCONN_CABLE_TYPE_MUIC_USB;
template->dest = IFCONN_NOTIFY_USB;
template->id = IFCONN_NOTIFY_ID_USB;
ifconn_manager_noti_work(ifconn_manager, template);
break;
case ATTACHED_DEV_TA_MUIC:
pr_info("usb: [M] %s: TA(%d) %s\n", __func__,
template->cable_type,
template->attach ? "Attached" : "Detached");
if (ifconn_manager->muic_action)
ifconn_manager->cable_type = IFCONN_CABLE_TYPE_MUIC_CHARGER;
if (template->attach
&& ifconn_manager->ccic_drp_state == IFCONN_MANAGER_USB_STATUS_ATTACH_UFP) {
/* Turn off the USB Phy when connected to the charger */
template->src = IFCONN_NOTIFY_MUIC;
template->dest = IFCONN_NOTIFY_USB;
template->id = IFCONN_NOTIFY_ID_USB;
template->attach = IFCONN_NOTIFY_DETACH;
template->drp = IFCONN_NOTIFY_EVENT_DETACH;
template->sub3 = 0;
template->data = NULL;
ifconn_manager_noti_work(ifconn_manager,
template);
}
break;
case ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC:
case ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC:
pr_info("usb: [M] %s: AFC or QC Prepare(%d) %s\n",
__func__, template->cable_type,
template->attach ? "Attached" : "Detached");
break;
case ATTACHED_DEV_TIMEOUT_OPEN_MUIC:
pr_info
("usb: [M] %s: DCD Timeout device is detected(%d) %s\n",
__func__, template->cable_type,
template->attach ? "Attached" : "Detached");
if (ifconn_manager->muic_action) {
ifconn_manager->cable_type =
IFCONN_CABLE_TYPE_MUIC_TIMEOUT_OPEN_DEVICE;
}
break;
default:
break;
}
template->id = IFCONN_NOTIFY_ID_ATTACH;
template->src = IFCONN_NOTIFY_MUIC;
template->dest = IFCONN_NOTIFY_BATTERY;
ifconn_manager_noti_work(ifconn_manager, template);
} else if (template->id == IFCONN_NOTIFY_ID_DETACH) {
template->src = IFCONN_NOTIFY_MUIC;
template->dest = IFCONN_NOTIFY_BATTERY;
ifconn_manager_noti_work(ifconn_manager, template);
}
return 0;
}
static int ifconn_manager_manage_battery(struct ifconn_manager_data *ifconn_manager,
struct ifconn_notifier_template *template)
{
int ret;
if (ifconn_manager == NULL || template == NULL)
return -1;
switch (template->id) {
case IFCONN_NOTIFY_ID_SELECT_PDO:
ret = ifconn_notifier_notify(IFCONN_NOTIFY_MANAGER,
IFCONN_NOTIFY_CCIC,
template->id,
template->event,
IFCONN_NOTIFY_PARAM_TEMPLATE,
template);
break;
default:
break;
}
return 0;
}
static int ifconn_manager_manage_pdic(struct ifconn_manager_data *ifconn_manager,
struct ifconn_notifier_template *template)
{
if (ifconn_manager == NULL || template == NULL)
return -1;
pr_info("%s, usb: [M] %s: cable type : (%d), id : %d\n", __func__,
__func__, template->cable_type,
template->id);
switch (template->id) {
case IFCONN_NOTIFY_ID_POWER_STATUS:
if (template->attach) {
ifconn_manager->pd_con_state = 1;
if ((ifconn_manager->ccic_drp_state == IFCONN_MANAGER_USB_STATUS_ATTACH_UFP)
&& !ifconn_manager->is_UFPS) {
pr_info("usb: [M] %s: PD charger + UFP\n",
__func__);
}
}
template->dest = IFCONN_NOTIFY_BATTERY;
if (ifconn_manager->pd == NULL)
ifconn_manager->pd = template->data;
ifconn_manager_noti_work(ifconn_manager, template);
break;
case IFCONN_NOTIFY_ID_DP_CONNECT:
case IFCONN_NOTIFY_ID_DP_HPD:
case IFCONN_NOTIFY_ID_DP_LINK_CONF:
template->src = IFCONN_NOTIFY_MANAGER;
template->dest = IFCONN_NOTIFY_DP;
_ifconn_manager_template_notify(template);
break;
default:
break;
}
return 0;
}
static int ifconn_manager_manage_ccic(struct ifconn_manager_data *ifconn_manager,
struct ifconn_notifier_template *template)
{
if (ifconn_manager == NULL || template == NULL)
return -1;
switch (template->id) {
case IFCONN_NOTIFY_ID_ATTACH:
if (ifconn_manager->ccic_attach_state != template->sub1) {
/*attach */
ifconn_manager->ccic_attach_state = template->sub1;
ifconn_manager->muic_data_refresh = 0;
ifconn_manager->is_UFPS = 0;
if (ifconn_manager->ccic_attach_state == IFCONN_NOTIFY_ATTACH) {
pr_info("usb: [M] %s: IFCONN_NOTIFY_ATTACH\n", __func__);
ifconn_manager->water_det = 0;
ifconn_manager->pd_con_state = 0;
} else { /* IFCONN_NOTIFY_DETACH */
pr_info
("usb: [M] %s: IFCONN_NOTIFY_DETACH (pd=%d, cable_type=%d)\n",
__func__, ifconn_manager->pd_con_state,
ifconn_manager->cable_type);
if (ifconn_manager->pd_con_state) {
ifconn_manager->pd_con_state = 0;
template->src = IFCONN_NOTIFY_CCIC;
template->dest = IFCONN_NOTIFY_BATTERY;
template->id = IFCONN_NOTIFY_ID_ATTACH;
template->attach = IFCONN_NOTIFY_DETACH;
template->rprd = 0;
template->cable_type = ATTACHED_DEV_UNOFFICIAL_ID_ANY_MUIC;
template->data = NULL;
}
}
}
break;
case IFCONN_NOTIFY_ID_DETACH:
template->src = IFCONN_NOTIFY_MANAGER;
template->dest = IFCONN_NOTIFY_BATTERY;
_ifconn_manager_template_notify(template);
return 0;
case IFCONN_NOTIFY_ID_RID:
ifconn_manager->ccic_rid_state = template->sub1;
break;
case IFCONN_NOTIFY_ID_USB:
if ((ifconn_manager->cable_type ==
IFCONN_CABLE_TYPE_MUIC_CHARGER)
|| (template->sub2 != IFCONN_MANAGER_USB_STATUS_DETACH /*drp */
&& (ifconn_manager->ccic_rid_state ==
IFCONN_MANAGER_RID_523K
|| ifconn_manager->ccic_rid_state ==
IFCONN_MANAGER_RID_619K))) {
return 0;
}
break;
case IFCONN_NOTIFY_ID_WATER:
if (template->sub1) { /* attach */
#ifdef CONFIG_IFCONN_WATER_EVENT_ENABLE
if (!ifconn_manager->water_det) {
ifconn_manager->water_det = 1;
ifconn_manager->water_count++;
complete(&ccic_attach_done);
template->src = IFCONN_NOTIFY_CCIC;
template->dest = IFCONN_NOTIFY_MUIC;
template->id = IFCONN_NOTIFY_ID_WATER;
template->attach = IFCONN_NOTIFY_ATTACH;
template->rprd = 0;
template->cable_type = 0;
template->pd = NULL;
ifconn_manager_noti_work(ifconn_manager, template);
/*update water time */
water_dry_time_update((int)template->sub1);
if (ifconn_manager->muic_action == IFCONN_NOTIFY_ATTACH) {
template->sub3 = ATTACHED_DEV_UNDEFINED_RANGE_MUIC; /* cable_type */
} else {
/* If the cable is not connected, skip the battery event. */
return 0;
}
} else {
/* Ignore duplicate events */
return 0;
}
#else
if (!ifconn_manager->water_det) {
ifconn_manager->water_det = 1;
if (ifconn_manager->muic_action == IFCONN_NOTIFY_ATTACH) {
template->src = IFCONN_NOTIFY_CCIC;
template->dest = IFCONN_NOTIFY_BATTERY;
template->id = IFCONN_NOTIFY_ID_ATTACH;
template->attach = IFCONN_NOTIFY_DETACH;
template->rprd = 0;
template->cable_type =
ifconn_manager->muic_cable_type;
template->data = NULL;
ifconn_manager_noti_work(ifconn_manager,
template);
}
}
return 0;
#endif
} else {
ifconn_manager->water_det = 0;
ifconn_manager->dry_count++;
return 0;
}
break;
default:
break;
}
ifconn_manager_noti_work(ifconn_manager, template);
return 0;
}
static int ifconn_manager_manage_vbus(struct ifconn_manager_data *ifconn_manager,
struct ifconn_notifier_template *template)
{
ifconn_notifier_vbus_t vbus_type = template->vbus_type;
pr_info("usb: [M] %s: vbus_type=%s, WATER DET=%d ATTACH=%s (%d)\n",
__func__, vbus_type == IFCONN_NOTIFY_VBUS_HIGH ? "HIGH" : "LOW",
ifconn_manager->water_det,
ifconn_manager->ccic_attach_state ==
IFCONN_NOTIFY_ATTACH ? "ATTACH" : "DETATCH",
ifconn_manager->muic_attach_state_without_ccic);
ifconn_manager->vbus_state = vbus_type;
#ifdef CONFIG_IFCONN_WATER_EVENT_ENABLE
init_completion(&ccic_attach_done);
if ((ifconn_manager->water_det == 1)
&& (template->vbus_type == IFCONN_NOTIFY_VBUS_HIGH))
wait_for_completion_timeout(&ccic_attach_done,
msecs_to_jiffies(2000));
switch (vbus_type) {
case IFCONN_NOTIFY_VBUS_HIGH:
if (ifconn_manager->water_det) {
ifconn_manager->waterChg_count++;
template->src = IFCONN_NOTIFY_CCIC;
template->dest = IFCONN_NOTIFY_BATTERY;
template->id = IFCONN_NOTIFY_ID_WATER;
template->attach = IFCONN_NOTIFY_ATTACH;
template->rprd = 0;
template->cable_type =
ATTACHED_DEV_UNDEFINED_RANGE_MUIC;
template->data = NULL;
_ifconn_manager_template_notify(template);
}
break;
case IFCONN_NOTIFY_VBUS_LOW:
if (ifconn_manager->water_det) {
template->src = IFCONN_NOTIFY_CCIC;
template->dest = IFCONN_NOTIFY_BATTERY;
template->id = IFCONN_NOTIFY_ID_ATTACH;
template->attach = IFCONN_NOTIFY_DETACH;
template->rprd = 0;
template->cable_type =
ATTACHED_DEV_UNDEFINED_RANGE_MUIC;
template->data = NULL;
_ifconn_manager_template_notify(template);
}
break;
default:
break;
}
#endif
return 0;
}
static int ifconn_manager_parse_dt(struct ifconn_manager_data *ifconn_manager)
{
struct device_node *np = ifconn_manager->dev->of_node;
struct ifconn_manager_platform_data *pdata = ifconn_manager->pdata;
int ret = 0;
if (!np)
return -1;
ret = of_property_read_string(np,
"ifconn,usbpd",
(char const **)&pdata->usbpd_name);
if (ret < 0)
goto err;
ret = of_property_read_string(np,
"ifconn,muic",
(char const **)&pdata->muic_name);
err:
return ret;
}
#ifdef CONFIG_IFCONN_SUPPORT_THREAD
static struct ifconn_notifier_template *_ifconn_manager_dequeue_template
(struct ifconn_manager_data *ifconn_manager)
{
struct ifconn_notifier_template *target = NULL;
struct ifconn_manager_template *step = NULL;
if (ifconn_manager->hp) {
pr_info("%s: ifconn_manager->hp : %p!!!!!\n", __func__, ifconn_manager->hp);
pr_info("%s: ifconn_manager->hp->node : %p!!!!!\n", __func__, &ifconn_manager->hp->node);
_ifconn_show_attr(&ifconn_manager->hp->node);
if (ifconn_manager->hp == ifconn_manager->tp)
step = NULL;
else
step = (struct ifconn_manager_template *)ifconn_manager->hp->np;
target = &ifconn_manager->hp->node;
//kfree(ifconn_manager->hp);
ifconn_manager->hp = step;
ifconn_manager->template_cnt--;
}
pr_info("%s: target : %p!!!!!\n", __func__, target);
_ifconn_show_attr(target);
return target;
}
static void _ifconn_manager_enqueue_template
(struct ifconn_manager_data *ifconn_manager, struct ifconn_notifier_template *template)
{
struct ifconn_manager_template *template_ifc = NULL;
template_ifc = kzalloc(sizeof(struct ifconn_manager_template), GFP_KERNEL);
pr_info("%s: enter --- line : %d!!!!!\n", __func__, __LINE__);
memcpy(&template_ifc->node, template,
sizeof(struct ifconn_notifier_template));
if (template->data != NULL) {
switch (template->id) {
case IFCONN_NOTIFY_ID_POWER_STATUS:
memcpy(template_ifc->node.data, template->data,
sizeof(usbpd_pdic_sink_state_t));
break;
case IFCONN_NOTIFY_ID_DP_CONNECT:
case IFCONN_NOTIFY_ID_DP_HPD:
case IFCONN_NOTIFY_ID_DP_LINK_CONF:
memcpy(template_ifc->node.data, template->data,
sizeof(struct usbpd_info));
break;
default:
break;
}
}
if (ifconn_manager->hp == NULL) {
ifconn_manager->tp = ifconn_manager->hp = template_ifc;
ifconn_manager->template_cnt++;
} else {
if (ifconn_manager->template_cnt < TEMPLATE_MAX)
ifconn_manager->template_cnt++;
else
_ifconn_manager_dequeue_template(ifconn_manager);
template_ifc->rp = (void *)ifconn_manager->tp;
ifconn_manager->tp->np = (void *)template_ifc;
ifconn_manager->tp = template_ifc;
}
pr_info("%s: hp : %p!!!!!\n", __func__, ifconn_manager->hp);
pr_info("%s: tp : %p!!!!!\n", __func__, ifconn_manager->tp);
pr_info("%s: ifconn_manager->hp->node : %p!!!!!\n", __func__, &ifconn_manager->hp->node);
_ifconn_show_attr(&ifconn_manager->hp->node);
_ifconn_show_attr(&ifconn_manager->tp->node);
}
#endif
static void ifconn_manager_work(struct work_struct *work)
{
struct ifconn_manager_data *ifconn_manager =
container_of(work, struct ifconn_manager_data, noti_work);
struct ifconn_notifier_template *template = NULL;
pr_info("%s: enter --- line : %d!!!!!\n", __func__, __LINE__);
template = ifconn_manager->template;
#ifdef CONFIG_IFCONN_SUPPORT_THREAD
if (ifconn_manager->template != NULL)
template = ifconn_manager->template;
else
template = _ifconn_manager_dequeue_template(ifconn_manager);
pr_info("%s: enter line : %d!!!!!\n", __func__, __LINE__);
#endif
switch (template->src) {
case IFCONN_NOTIFY_PDIC:
ifconn_manager_manage_pdic(ifconn_manager, template);
break;
case IFCONN_NOTIFY_MUIC:
ifconn_manager_manage_muic(ifconn_manager, template);
break;
case IFCONN_NOTIFY_CCIC:
ifconn_manager_manage_ccic(ifconn_manager, template);
break;
case IFCONN_NOTIFY_VBUS:
ifconn_manager_manage_vbus(ifconn_manager, template);
break;
case IFCONN_NOTIFY_BATTERY:
ifconn_manager_manage_battery(ifconn_manager, template);
break;
case IFCONN_NOTIFY_DP:
break;
case IFCONN_NOTIFY_USB_DP:
break;
default:
break;
}
}
static int ifconn_manager_isr(struct notifier_block *nb,
unsigned long action, void *data)
{
struct ifconn_manager_data *ifconn_manager =
container_of(nb, struct ifconn_manager_data, nb);
struct ifconn_notifier_template *template =
(struct ifconn_notifier_template *)data;
if (data == NULL) {
pr_info("%s: data NULL\n", __func__);
return -1;
}
pr_info("%s: enter src : %d\n", __func__, template->src);
#ifdef CONFIG_IFCONN_SUPPORT_THREAD
mutex_lock(&ifconn_manager->enqueue_mutex);
ifconn_manager->template = NULL;
if (template->event == IFCONN_NOTIFY_EVENT_IN_HURRY) {
#endif
ifconn_manager->template = template;
ifconn_manager_work(&ifconn_manager->noti_work);
#ifdef CONFIG_IFCONN_SUPPORT_THREAD
} else {
pr_info("%s: enter src : %d, line : %d!!!!!\n", __func__, template->src, __LINE__);
_ifconn_manager_enqueue_template(ifconn_manager, template);
schedule_work(&ifconn_manager->noti_work);
}
mutex_unlock(&ifconn_manager->enqueue_mutex);
#endif
return 0;
}
static int ifconn_manager_probe(struct platform_device *pdev)
{
struct ifconn_manager_data *ifconn_manager;
struct ifconn_manager_platform_data *pdata = NULL;
int ret = 0, i = 0;
pr_info("%s: enter\n", __func__);
ifconn_manager = kzalloc(sizeof(*ifconn_manager), GFP_KERNEL);
if (!ifconn_manager)
return -ENOMEM;
ifconn_manager->dev = &pdev->dev;
dev_set_drvdata(ifconn_manager->dev, ifconn_manager);
if (pdev->dev.of_node) {
pdata = devm_kzalloc(&pdev->dev,
sizeof(struct ifconn_manager_platform_data),
GFP_KERNEL);
if (!pdata) {
dev_err(&pdev->dev, "Failed to allocate memory\n");
ret = -ENOMEM;
goto ERROR_PDATA_FREE;
}
ifconn_manager->pdata = pdata;
if (ifconn_manager_parse_dt(ifconn_manager)) {
dev_err(&pdev->dev,
"%s: Failed to get ifconn manager dt\n", __func__);
ret = -EINVAL;
goto ERROR_IFCONN_FREE;
}
} else {
pdata = dev_get_platdata(&pdev->dev);
ifconn_manager->pdata = pdata;
}
if (ret < 0)
goto ERROR_PDATA_FREE;
mutex_init(&ifconn_manager->noti_mutex);
mutex_init(&ifconn_manager->workqueue_mutex);
#ifdef CONFIG_IFCONN_SUPPORT_THREAD
mutex_init(&ifconn_manager->enqueue_mutex);
INIT_WORK(&ifconn_manager->noti_work, ifconn_manager_work);
ifconn_manager->hp = NULL;
ifconn_manager->tp = NULL;
ifconn_manager->template = NULL;
ifconn_manager->template_cnt = 0;
#endif
for (i = IFCONN_NOTIFY_USB; i <= IFCONN_NOTIFY_USB_DP; i++) {
ret = ifconn_notifier_register(&ifconn_manager->nb,
ifconn_manager_isr,
IFCONN_NOTIFY_MANAGER, i);
}
return 0;
ERROR_PDATA_FREE:
kfree(pdata);
ERROR_IFCONN_FREE:
kfree(ifconn_manager);
return ret;
}
static int ifconn_manager_remove(struct platform_device *pdev)
{
struct ifconn_manager_data *ifconn_manager = platform_get_drvdata(pdev);
mutex_destroy(&ifconn_manager->noti_mutex);
return 0;
}
static void ifconn_manager_shutdown(struct device *dev)
{
}
#ifdef CONFIG_OF
static struct of_device_id ifconn_manager_dt_ids[] = {
{.compatible = "samsung,ifconn"},
{}
};
MODULE_DEVICE_TABLE(of, ifconn_manager_dt_ids);
#endif /* CONFIG_OF */
static struct platform_driver ifconn_manager_driver = {
.driver = {
.name = "ifconn",
.owner = THIS_MODULE,
.shutdown = ifconn_manager_shutdown,
#ifdef CONFIG_OF
.of_match_table = ifconn_manager_dt_ids,
#endif
},
.probe = ifconn_manager_probe,
.remove = ifconn_manager_remove,
};
static int __init ifconn_manager_init(void)
{
return platform_driver_register(&ifconn_manager_driver);
}
static void __exit ifconn_manager_exit(void)
{
platform_driver_unregister(&ifconn_manager_driver);
}
late_initcall(ifconn_manager_init);
module_exit(ifconn_manager_exit);
MODULE_DESCRIPTION("ifconn manager");
MODULE_AUTHOR("Samsung Electronics");
MODULE_LICENSE("GPL");
|