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
|
/*
* muic_ccic.c
*
* Copyright (C) 2014 Samsung Electronics
* Thomas Ryu <smilesr.ryu@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/host_notify.h>
#include <linux/string.h>
#if defined (CONFIG_OF)
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#endif
#include <linux/muic/muic.h>
#if defined(CONFIG_MUIC_NOTIFIER)
#include <linux/muic/muic_notifier.h>
#endif
#if defined(CONFIG_USB_EXTERNAL_NOTIFY)
#include <linux/usb_notify.h>
#endif
#include "muic-internal.h"
#include "muic_coagent.h"
#if defined(CONFIG_USB_EXTERNAL_NOTIFY)
extern void muic_send_dock_intent(int type);
/*
* status: normal if 1, abnormal if 0
* return 0 on success, -1 on fail
*/
static int muic_noti_gamepad_status(int status, const char *sender)
{
uint val;
if (!sender) {
pr_info("%s:%s: Illegal argument!\n", MUIC_DEV_NAME, __func__);
return -1;
}
pr_info("%s:%s gamepas_status=[%s] from %s\n", MUIC_DEV_NAME, __func__,
status ? "normal" : "abnormal", sender);
val = status ? COA_STATUS_OK: COA_STATUS_NOK;
val <<= COAGENT_PARAM_BITS;
val |= COA_GAMEPAD_STATUS;
coagent_in(&val);
return 0;
}
static int muic_handle_usb_notification(struct notifier_block *nb,
unsigned long action, void *data)
{
muic_data_t *pmuic =
container_of(nb, muic_data_t, usb_nb);
switch (action) {
/* Abnormal device */
case EXTERNAL_NOTIFY_3S_NODEVICE:
pr_info("%s: 3S_NODEVICE(USB HOST Connection timeout)\n", __func__);
if (pmuic->attached_dev == ATTACHED_DEV_HMT_MUIC)
muic_set_hmt_status(1);
else if ((pmuic->attached_dev == ATTACHED_DEV_GAMEPAD_MUIC) ||
(pmuic->attached_dev == ATTACHED_DEV_OTG_MUIC))
pr_info("%s: Abnormal Gamepad -> do nothing.\n", __func__);
break;
/* Gamepad device connected */
case EXTERNAL_NOTIFY_DEVICE_CONNECT:
pr_info("%s: DEVICE_CONNECT(Gamepad)\n", __func__);
if ((pmuic->attached_dev != ATTACHED_DEV_GAMEPAD_MUIC) &&
(pmuic->attached_dev != ATTACHED_DEV_OTG_MUIC)) {
pr_info("%s: Unexpected scenario.n", __func__);
break;
}
pmuic->is_gamepad = true;
if (pmuic->attached_dev == ATTACHED_DEV_OTG_MUIC)
muic_send_dock_intent(MUIC_DOCK_GAMEPAD_WITH_EARJACK);
muic_noti_gamepad_status(1, "USB");
break;
default:
break;
}
return NOTIFY_DONE;
}
void muic_register_usb_notifier(muic_data_t *pmuic)
{
int ret = 0;
pr_info("%s: Registering EXTERNAL_NOTIFY_DEV_MUIC.\n", __func__);
ret = usb_external_notify_register(&pmuic->usb_nb,
muic_handle_usb_notification, EXTERNAL_NOTIFY_DEV_MUIC);
if (ret < 0) {
pr_info("%s: USB Noti. is not ready.\n", __func__);
return;
}
pr_info("%s: done.\n", __func__);
}
void muic_unregister_usb_notifier(muic_data_t *pmuic)
{
int ret = 0;
pr_info("%s\n", __func__);
ret = usb_external_notify_unregister(&pmuic->usb_nb);
if (ret < 0) {
pr_info("%s: USB Noti. unregister error.\n", __func__);
return;
}
pr_info("%s: done.\n", __func__);
}
#else
void muic_register_usb_notifier(muic_data_t *pmuic){}
void muic_unregister_usb_notifier(muic_data_t *pmuic){}
#endif
|