hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
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
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/*
 * Copyright (C) 2015 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
#include <linux/atomic.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/kdev_t.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/semaphore.h>
#include <linux/slab.h>
#include <linux/syscalls.h>
#include <linux/tty.h>
#include <linux/types.h>
#include <linux/vmalloc.h>
#include <linux/vt_kern.h>
#ifdef CONFIG_OF
#include <linux/of_device.h>
#endif
#include <linux/compat.h>
#include <linux/interrupt.h>
#include <linux/kthread.h>
#include <linux/tty_flip.h>
#include <linux/workqueue.h>
 
#include "include/debug.h"
#include "include/hci.h"
#include "include/interface.h"
#include "include/lpm.h"
#include "include/rfkill.h"
#include "include/sdio.h"
#include "include/sitm.h"
#include "include/tty.h"
#include <marlin_platform.h>
 
// #define  UNISOC_AMLOGIC_SUSPEND
#ifdef UNISOC_AMLOGIC_SUSPEND
#include <linux/amlogic/pm.h> //add
static struct early_suspend bt_early_suspend; //add
#endif
 
#if 0
#define DO_SYSCALL_2(sc, t1, a1, t2, a2) \
    (((asmlinkage long (*)(t1, t2))sys_call_table[__NR_##sc])(a1, a2));
#define USER_SYSCALL_2(sc, t1, a1, t2, a2)                   \
    static inline asmlinkage long syscall_##sc(t1 a1, t2 a2) \
    {                                                        \
        return DO_SYSCALL_2(sc, t1, a1, t2, a2)              \
    }
 
USER_SYSCALL_2(chmod, const char __user *, filename, mode_t, mode);
#endif
 
#ifndef USE_DTS
static void __exit uwe5621_bt_tty_exit(void);
#endif
static int mtty_remove(struct platform_device* pdev);
int closeflag = 0;
struct mtty_device* mtty_dev;
 
struct bt_data_interface_t* bt_data_interface;
static struct bt_data_interface_cb_t bt_data_interface_cb;
extern int list_time;
extern unsigned char dis_flag;
static int mtty_open(struct tty_struct* tty, struct file* filp)
{
    struct mtty_device* mtty = NULL;
    struct tty_driver* driver = NULL;
 
    // start_marlin(MARLIN_BLUETOOTH);
    bluetooth_set_power(0, 0);
 
    clear_woble_devices();
 
    if (tty == NULL) {
        pr_err("mtty open input tty is NULL!\n");
        return -ENOMEM;
    }
 
    driver = tty->driver;
    mtty = (struct mtty_device*)driver->driver_state;
 
    if (mtty == NULL) {
        pr_err("mtty open input mtty NULL!\n");
        return -ENOMEM;
    }
 
    mtty->tty = tty;
    tty->driver_data = (void*)mtty;
 
    atomic_set(&mtty->state, MTTY_STATE_OPEN);
    sitm_init();
    // pr_info("%s device success! pid %d %d %d sid %d\n", __func__, task_pid_nr(current), current->pid, pid_nr(get_task_pid(current, PIDTYPE_PID)),
    // pid_nr(get_task_pid(current, PIDTYPE_SID)));
    closeflag = 0;
    list_time = 0x11;
    dis_flag = 0;
    return 0;
}
 
static void mtty_close(struct tty_struct* tty, struct file* filp)
{
    closeflag = 1;
    list_time = 0x11;
    dis_flag = 0;
    pr_info("mtty_close device success _close!\n");
 
    /*
    struct mtty_device *mtty = NULL;
 
    if (tty == NULL)
    {
        pr_err("mtty close input tty is NULL!\n");
        return;
    }
 
    mtty = (struct mtty_device *) tty->driver_data;
 
    if (mtty == NULL)
    {
        pr_err("mtty close s tty is NULL!\n");
        return;
    }
 
    atomic_set(&mtty->state, MTTY_STATE_CLOSE);
    sitm_cleanup();
    pr_info("mtty_close device success !\n");
 
    //stop_marlin(MARLIN_BLUETOOTH);
    bluetooth_set_power(0, 1);
*/
}
 
static inline int mtty_transfer_upper(const unsigned char* buf, int count)
{
    int ret = tty_insert_flip_string(mtty_dev->port, buf, count);
 
    if (ret != count) {
        pr_err("%s err ret %d count %d !!!!!!!!!!!\n", __func__, ret, count);
    }
 
    tty_flip_buffer_push(mtty_dev->port);
    return ret;
}
// add ..... 04 05 04 00 00 02 13
int resume_transfer_upper(const unsigned char* buf, int count)
{
    int ret = tty_insert_flip_string(mtty_dev->port, buf, count);
    pr_err("test_%s\n", __func__); //
    if (ret != count) {
        pr_err("%s err ret %d count %d !!!!!!!!!!!\n", __func__, ret, count);
    }
 
    tty_flip_buffer_push(mtty_dev->port);
    return ret;
}
 
static int mtty_recv(const unsigned char* buf, int count)
{
    // pr_err("mtty_recv count:%d\n", count);
    // hex_dump_block(buf, count);
    // return mtty_transfer_upper(buf, count);
    return rx_data_recv(buf, count, mtty_transfer_upper);
}
 
static int sdio_data_transmit(uint8_t* data, size_t count)
{
    return bt_data_interface->write(data, count);
}
 
static int mtty_write_plus(struct tty_struct* tty,
    const unsigned char* buf, int count)
{
 
    return sitm_write(buf, count, sdio_data_transmit);
}
 
static void mtty_flush_chars(struct tty_struct* tty)
{
}
 
static int mtty_write_room(struct tty_struct* tty)
{
    return INT_MAX;
}
 
static const struct tty_operations mtty_ops = {
    .open = mtty_open,
    .close = mtty_close,
    .write = mtty_write_plus,
    .flush_chars = mtty_flush_chars,
    .write_room = mtty_write_room,
};
 
static struct tty_port* mtty_port_init(void)
{
    struct tty_port* port = NULL;
 
    port = kzalloc(sizeof(struct tty_port), GFP_KERNEL);
 
    if (port == NULL) {
        return NULL;
    }
 
    tty_port_init(port);
 
    return port;
}
 
static int mtty_tty_driver_init(struct mtty_device* device)
{
    struct tty_driver* driver;
    int ret = 0;
 
    device->port = mtty_port_init();
 
    if (!device->port) {
        return -ENOMEM;
    }
 
    driver = alloc_tty_driver(MTTY_DEV_MAX_NR);
 
    if (!driver) {
        return -ENOMEM;
    }
 
    /*
    * Initialize the tty_driver structure
    * Entries in mtty_driver that are NOT initialized:
    * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
    */
    driver->owner = THIS_MODULE;
#ifndef USE_DTS
    driver->driver_name = "ttyBT";
    driver->name = "ttyBT";
#else
    driver->driver_name = device->pdata->name;
    driver->name = device->pdata->name;
#endif
 
#if 1
    driver->major = 0;
#else
    driver->major = TTYAUX_MAJOR;
    driver->minor_start = 2;
#endif
 
    driver->type = TTY_DRIVER_TYPE_SYSTEM;
    driver->subtype = SYSTEM_TYPE_TTY;
    driver->init_termios = tty_std_termios;
    driver->driver_state = (void*)device;
    device->driver = driver;
    device->driver->flags = TTY_DRIVER_REAL_RAW;
    /* initialize the tty driver */
    tty_set_operations(driver, &mtty_ops);
    tty_port_link_device(device->port, driver, 0);
    ret = tty_register_driver(driver);
 
    if (ret) {
        put_tty_driver(driver);
        tty_port_destroy(device->port);
        return ret;
    }
 
    // sys_chmod("/dev/ttyBT0", 0777);
    // syscall_chmod("/dev/ttyBT0", 0777);
    return ret;
}
 
static void mtty_tty_driver_exit(struct mtty_device* device)
{
    struct tty_driver* driver = device->driver;
 
    tty_unregister_driver(driver);
    put_tty_driver(driver);
    tty_port_destroy(device->port);
}
 
static int mtty_parse_dt(struct mtty_init_data** init, struct device* dev)
{
#ifdef CONFIG_OF
    struct device_node* np = dev->of_node;
    struct mtty_init_data* pdata = NULL;
    int ret;
 
    pdata = kzalloc(sizeof(struct mtty_init_data), GFP_KERNEL);
 
    if (!pdata) {
        return -ENOMEM;
    }
 
    ret = of_property_read_string(np,
        "sprd,name",
        (const char**)&pdata->name);
 
    if (ret) {
        goto error;
    }
 
    *init = pdata;
 
    return 0;
error:
    kfree(pdata);
    *init = NULL;
    return ret;
#else
    return -ENODEV;
#endif
}
 
static inline void mtty_destroy_pdata(struct mtty_init_data** init)
{
#if (defined CONFIG_OF) && (defined USE_DTS)
    struct mtty_init_data* pdata = *init;
 
    kfree(pdata);
 
    *init = NULL;
#else
    return;
#endif
}
 
static ssize_t at_store(struct device* dev,
    struct device_attribute* attr,
    const char* buf, size_t count)
{
    pr_info("%s\n", __func__);
    hci_woble_enable();
    return count;
}
 
static ssize_t at_show(struct device* dev,
    struct device_attribute* attr,
    char* buf)
{
    pr_info("%s\n", __func__);
    return 0;
}
 
static ssize_t woble_set_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
{
    unsigned char* p = (unsigned char*)buf;
    unsigned char opcode = 0;
    unsigned short handler = 0;
    STREAM_TO_UINT8(opcode, p);
 
    // pr_info("%s, len %lu op: %d\n", __func__, count, opcode);
 
    switch (opcode) {
    case WOBLE_KERNEL_OP_CLEAR:
        clear_woble_devices();
        break;
 
    case WOBLE_KERNEL_OP_SET_OWN:
        set_random_address(p);
        break;
 
    case WOBLE_KERNEL_OP_ADD_RMT: {
        unsigned char type = 0;
        STREAM_TO_UINT8(type, p);
        STREAM_TO_UINT16(handler, p);
        pr_info("%s, get type: %d\n", __func__, type);
        update_woble_devices(type, handler, p);
    } break;
 
    case WOBLE_KERNEL_OP_DEL_RMT: {
        unsigned char type = 0;
        STREAM_TO_UINT8(type, p);
        pr_info("%s, get type: %d\n", __func__, type);
        del_woble_devices(type, p);
    } break;
 
    case WOBLE_KERNEL_OP_ENABLE_BLE_INDICATE: {
        set_need_indicate_cp2_woble(1);
    } break;
 
    case WOBLE_KERNEL_OP_DISABLE_BLE_INDICATE: {
        set_need_indicate_cp2_woble(0);
    } break;
    }
 
    return count;
}
 
static ssize_t woble_set_show(struct device* dev,
    struct device_attribute* attr,
    char* buf)
{
    pr_info("%s\n", __func__);
    dump_woble_devices();
    return 0;
}
 
static ssize_t ant_num_show(struct device* dev,
    struct device_attribute* attr,
    char* buf)
{
    int num = 2;
 
    num = marlin_get_ant_num();
    pr_err("%s: %d", __func__, num);
 
    return sprintf(buf, "%d", num);
}
 
static ssize_t chipid_show(struct device* dev,
    struct device_attribute* attr,
    char* buf)
{
    int type = 0;
 
    type = wcn_get_chip_model();
    pr_err("%s: %d", __func__, type);
 
    return sprintf(buf, "%d", type);
}
 
static ssize_t misc_node_store(struct device* dev,
    struct device_attribute* attr,
    const char* buf, size_t count)
{
    unsigned char opcode = 0;
    const char* tbuf = buf;
    pr_info("%s\n", __func__);
 
    if (memcmp("AT+BTLOG=", buf, strlen("AT+BTLOG=")) == 0 && count >= strlen("AT+BTLOG=") + 1) {
        tbuf += strlen("AT+BTLOG=");
        STREAM_TO_UINT8(opcode, tbuf);
        set_log_level(opcode - '0');
    } else if (memcmp("AT+SLEEP=", buf, strlen("AT+SLEEP=")) == 0 && count >= strlen("AT+SLEEP=") + 1) {
        unsigned char is_resume = 0;
        tbuf += strlen("AT+SLEEP=");
        STREAM_TO_UINT8(is_resume, tbuf);
        is_resume = is_resume - '0';
        pr_err("%s AT+SLEEP=%d\n", __func__, is_resume);
        switch (is_resume) {
        case 0:
            hci_set_scan_parameters();
            hci_set_scan_enable(1);
            break;
        case 1:
            hci_add_device_to_wakeup_list();
            break;
        case 2:
            hci_set_ap_sleep_mode(WOBLE_IS_NOT_SHUTDOWN, WOBLE_IS_NOT_RESUME);
            break;
        case 3:
            hci_set_ap_start_sleep();
            break;
        case 4:
            hci_set_ap_sleep_mode(WOBLE_IS_NOT_SHUTDOWN, WOBLE_IS_RESUME);
            break;
        default:
            break;
        }
    }
    return count;
}
 
static ssize_t misc_node_show(struct device* dev,
    struct device_attribute* attr,
    char* buf)
{
    pr_info("%s\n", __func__);
 
    return 0;
}
#define ALL_PER 1
 
#if ALL_PER
#pragma push_macro("VERIFY_OCTAL_PERMISSIONS")
#ifdef VERIFY_OCTAL_PERMISSIONS
#undef VERIFY_OCTAL_PERMISSIONS
#endif
 
#define VERIFY_OCTAL_PERMISSIONS(perms) (perms)
#endif
#if ALL_PER
static DEVICE_ATTR(at, 00660, at_show, at_store);
static DEVICE_ATTR(woble_set, 00660, woble_set_show, woble_set_store);
static DEVICE_ATTR(ant_num, 00664, ant_num_show, 0);
static DEVICE_ATTR(chipid, 00664, chipid_show, 0);
static DEVICE_ATTR(misc_node, 00660, misc_node_show, misc_node_store);
 
#pragma pop_macro("VERIFY_OCTAL_PERMISSIONS")
 
#else
static DEVICE_ATTR(at, 00660, at_show, at_store);
static DEVICE_ATTR(woble_set, 00660, woble_set_show, woble_set_store);
static DEVICE_ATTR(ant_num, 00660, ant_num_show, 0);
static DEVICE_ATTR(chipid, 00660, chipid_show, 0);
static DEVICE_ATTR(misc_node, 00660, misc_node_show, misc_node_store);
#endif
 
struct attribute* bluetooth_attrs[] = {
    &dev_attr_at.attr,
    &dev_attr_woble_set.attr,
    &dev_attr_ant_num.attr,
    &dev_attr_chipid.attr,
    &dev_attr_misc_node.attr,
    NULL,
};
 
static struct attribute_group bluetooth_group = {
    .name = NULL,
    .attrs = bluetooth_attrs,
};
 
#ifdef UNISOC_AMLOGIC_SUSPEND
extern unsigned char resume_rxmsg[7];
int early_flag = 0x11;
int dis_cmd_flag = 0x11;
extern unsigned char red_bt_flag; //区分蓝牙,红外待机标志;0x11:红外 0x22: bt
//int  uni_sus_flag =0x11;
//int  uni_resu_flag= 0x11;
//int  resume_suspen_flag=0x11;
//int  firs_dis_flag=0x11;
static void bt_earlysuspend(struct early_suspend* h)
{
    dis_cmd_flag = 0x11;
    early_flag = 0x11;
}
 
static void bt_lateresume(struct early_suspend* h)
{
 
    if (early_flag == 0x22) {
        resume_transfer_upper(resume_rxmsg, 7);
    }
    early_flag = 0x11;
    dis_cmd_flag = 0x11;
    dis_flag =0 ;// 更新狀態
    pr_err("unisoc_lateresume\n"); //
}
#endif
 
#ifdef CP2_RESET_SUPPORT
static void bt_cp2_pre_reset(void) {
   pr_err("%s: entry!\n", __func__);
}
 
static void bt_cp2_post_reset(void) {
#define RESET_BUFSIZE 5
 
   int ret = 0;
   int block_size = RESET_BUFSIZE;
   unsigned char reset_buf[RESET_BUFSIZE]= {0x04, 0xff, 0x02, 0x57, 0xa5};
 
   pr_err("%s: reset callback coming\n", __func__);
   if (mtty_dev != NULL) {
       // if (!work_pending(&mtty_dev->bt_rx_work)) {
       if (atomic_read(&mtty_dev->state) == MTTY_STATE_OPEN && (RESET_BUFSIZE > 0)) {
           pr_err("%s tty_insert_flip_string", __func__);
           while(ret < block_size){
               pr_err("%s before tty_insert_flip_string ret: %d, len: %d\n",
                       __func__, ret, RESET_BUFSIZE);
               ret = tty_insert_flip_string(mtty_dev->port,
                                   (unsigned char *)reset_buf,
                                   RESET_BUFSIZE);   // -BT_SDIO_HEAD_LEN
               pr_err("%s ret: %d, len: %d\n", __func__, ret, RESET_BUFSIZE);
               if (ret)
                   tty_flip_buffer_push(mtty_dev->port);
               block_size = block_size - ret;
               ret = 0;
           }
       }
   }
}
 
 
int bt_cp2_reset_callback(struct notifier_block *nb, unsigned long event, void *v) {
   if (!v) {
       pr_err("%s: v is NULL\n", __func__);
       return NOTIFY_BAD;
   }
 
   pr_err("%s: %s %d\n", __func__, (char *)v, (int)event);
 
   switch(event) {
       case MARLIN_CP2_STS_ASSERTED:
           bt_cp2_pre_reset();
           break;
       case MARLIN_CP2_STS_READY:
           bt_cp2_post_reset();
           break;
       default:
           pr_err("%s: parameter error event: %d\n", __func__, (int)event);
           return NOTIFY_BAD;
   }
 
   return NOTIFY_OK;
}
 
static struct notifier_block bt_cp2_reset_notifier = {
   .notifier_call = bt_cp2_reset_callback,
};
#endif  /*CP2_RESET_SUPPORT*/
 
static int mtty_probe(struct platform_device* pdev)
{
    struct mtty_init_data* pdata = (struct mtty_init_data*)pdev->dev.platform_data;
    struct mtty_device* mtty;
    int rval = 0;
 
    if (marlin_get_wcn_module_vendor() < 0) {
        pr_err("%s not unisoc soc, exit", __func__);
        // mtty_remove(pdev);
        // uwe5621_bt_tty_exit();
        return -EACCES;
    } else {
        pr_err("%s unisoc soc, continue", __func__);
    }
 
    if (pdev->dev.of_node && !pdata) {
        rval = mtty_parse_dt(&pdata, &pdev->dev);
 
        if (rval) {
            pr_err("%s failed to parse mtty device tree, ret=%d\n", __func__,
                rval);
            return rval;
        }
    }
 
    mtty = kzalloc(sizeof(struct mtty_device), GFP_KERNEL);
 
    if (mtty == NULL) {
        mtty_destroy_pdata(&pdata);
        pr_err("%s Failed to allocate device!\n", __func__);
        return -ENOMEM;
    }
 
    mtty->pdata = pdata;
    rval = mtty_tty_driver_init(mtty);
 
    if (rval) {
        mtty_tty_driver_exit(mtty);
        kfree(mtty->port);
        kfree(mtty);
        mtty_destroy_pdata(&pdata);
        pr_err("%s regitster notifier failed (%d)\n", __func__, rval);
        return rval;
    }
 
    pr_info("%s init device addr: 0x%p\n", __func__, mtty);
    platform_set_drvdata(pdev, mtty);
 
    atomic_set(&mtty->state, MTTY_STATE_CLOSE);
 
    mtty_dev = mtty;
 
    if (sysfs_create_group(&(pdev->dev.kobj), &bluetooth_group)) {
        pr_err("%s create dispc attr node failed", __func__);
    }
 
    rfkill_bluetooth_init(pdev);
    // bluesleep_init();
 
    // uwe5621_bt_tty_exit();
    hci_init();
 
    bt_data_interface_cb.size = sizeof(struct bt_data_interface_cb_t);
    bt_data_interface_cb.recv = mtty_recv;
    bt_data_interface = get_marlin_sdio_interface();
    bt_data_interface->init(&bt_data_interface_cb);
 
/********************************************/
#ifdef UNISOC_AMLOGIC_SUSPEND
    bt_early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
    bt_early_suspend.suspend = bt_earlysuspend;
    bt_early_suspend.resume = bt_lateresume;
    bt_early_suspend.param = pdev;
    register_early_suspend(&bt_early_suspend);
#endif
/********************************************/
 
#ifdef CP2_RESET_SUPPORT
       marlin_reset_callback_register(MARLIN_BLUETOOTH, &bt_cp2_reset_notifier);
#endif  /*CP2_RESET_SUPPORT*/
 
    return 0;
}
 
static int mtty_remove(struct platform_device* pdev)
{
    struct mtty_device* mtty = platform_get_drvdata(pdev);
    rfkill_bluetooth_remove(pdev);
    pr_err("%s\n", __func__);
    mtty_tty_driver_exit(mtty);
    bt_data_interface->cleanup();
    kfree(mtty->port);
    mtty_destroy_pdata(&mtty->pdata);
    /* tasklet_kill(&mtty->rx_task); */
    kfree(mtty);
    platform_set_drvdata(pdev, NULL);
    // bluesleep_exit();
    hci_destory();
    return 0;
}
 
static int mtty_suspend(struct platform_device* device, pm_message_t state)
{
    pr_err("%s\n", __func__);
    // at_store(0, 0, 0, 0);
    // stop_marlin(MARLIN_BLUETOOTH);
    // sprdwcn_bus_remove_card();
    return 0;
}
 
static void mtty_shutdown(struct platform_device* device)
{
    pr_err("%s\n", __func__);
    return;
}
static int mtty_resume(struct platform_device* device)
{
    pr_err("%s\n", __func__);
    return 0;
}
 
static void mtty_device_release(struct device* device)
{
    pr_err("%s\n", __func__);
    return;
}
 
static struct platform_device uwe5621_bt_tty_device = {
    .name = "mtty",
    .dev = {
        .release = mtty_device_release,
    },
};
static const struct of_device_id mtty_match_table[] = {
    {
        .compatible = "sprd,mtty",
    },
};
static struct platform_driver uwe5621_bt_tty_driver = {
    .driver = {
        .owner = THIS_MODULE,
        .name = "mtty",
        .of_match_table = mtty_match_table,
    },
    .probe = mtty_probe,
    .remove = mtty_remove,
    .suspend = mtty_suspend,
    .resume = mtty_resume,
    .shutdown = mtty_shutdown,
};
 
#ifdef USE_DTS
// for dts
module_platform_driver(uwe5621_bt_tty_driver);
 
#else
 
static int __init uwe5621_bt_tty_init(void)
{
    pr_err("%s\n", __func__);
    platform_device_register(&uwe5621_bt_tty_device);
    return platform_driver_register(&uwe5621_bt_tty_driver);
}
 
static void __exit uwe5621_bt_tty_exit(void)
{
    pr_err("%s\n", __func__);
    platform_driver_unregister(&uwe5621_bt_tty_driver);
    platform_device_unregister(&uwe5621_bt_tty_device);
}
 
// module_init(uwe5621_bt_tty_init);
late_initcall_sync(uwe5621_bt_tty_init);
module_exit(uwe5621_bt_tty_exit);
 
#endif
 
MODULE_AUTHOR("Unisoc wcn bt");
MODULE_DESCRIPTION("Unisoc marlin tty driver");