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
|
/* drivers/muic/muic-core.c
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/i2c-gpio.h>
#include <linux/gpio.h>
/* switch device header */
#ifdef CONFIG_ANDROID_SWITCH
#include "../staging/android/switch/switch.h"
#endif /* CONFIG_ANDROID_SWITCH */
#if defined(CONFIG_USE_SAFEOUT)
#include <linux/regulator/consumer.h>
#endif
#if defined(CONFIG_USB_HW_PARAM)
#include <linux/usb_notify.h>
#endif
#if defined(CONFIG_MFD_MAX77804) || defined(CONFIG_MFD_MAX77804K)
#include <linux/mfd/max77804.h>
#include <linux/mfd/max77804-private.h>
#elif defined(CONFIG_MFD_MAX77828)
#include <linux/mfd/max77828.h>
#include <linux/mfd/max77828-private.h>
#elif defined(CONFIG_MFD_MAX77843)
#include <linux/mfd/max77843.h>
#include <linux/mfd/max77843-private.h>
#elif defined(CONFIG_MFD_MAX77833)
#include <linux/mfd/max77833.h>
#include <linux/mfd/max77833-private.h>
#elif defined(CONFIG_MFD_MAX77888)
#include <linux/mfd/max77888.h>
#include <linux/mfd/max77888-private.h>
#endif
#include <linux/muic/muic.h>
#if defined(CONFIG_MUIC_NOTIFIER)
#include <linux/muic/muic_notifier.h>
#endif /* CONFIG_MUIC_NOTIFIER */
#if defined(CONFIG_MUIC_SUPPORT_CCIC) && defined(CONFIG_CCIC_NOTIFIER)
#include <linux/ccic/ccic_notifier.h>
#endif
#ifdef CONFIG_ANDROID_SWITCH
static struct switch_dev switch_dock = {
.name = "dock",
};
struct switch_dev switch_uart3 = {
.name = "uart3", /* sys/class/switch/uart3/state */
};
#ifdef CONFIG_SEC_FACTORY
struct switch_dev switch_attached_muic_cable = {
.name = "attached_muic_cable", /* sys/class/switch/attached_muic_cable/state */
};
#endif
#endif /* CONFIG_ANDROID_SWITCH */
#if defined(CONFIG_MUIC_NOTIFIER)
static struct notifier_block dock_notifier_block;
static struct notifier_block cable_data_notifier_block;
void muic_send_dock_intent(int type)
{
pr_info("%s: MUIC dock type(%d)\n", __func__, type);
#ifdef CONFIG_ANDROID_SWITCH
switch_set_state(&switch_dock, type);
#endif
}
#ifdef CONFIG_SEC_FACTORY
void muic_send_attached_muic_cable_intent(int type)
{
pr_info("%s: MUIC attached_muic_cable type(%d)\n", __func__, type);
#ifdef CONFIG_ANDROID_SWITCH
switch_set_state(&switch_attached_muic_cable, type);
#endif
}
#endif
static int muic_dock_attach_notify(int type, const char *name)
{
pr_info("%s: %s\n", __func__, name);
muic_send_dock_intent(type);
return NOTIFY_OK;
}
static int muic_dock_detach_notify(void)
{
pr_info("%s\n", __func__);
muic_send_dock_intent(MUIC_DOCK_DETACHED);
return NOTIFY_OK;
}
static int muic_handle_dock_notification(struct notifier_block *nb,
unsigned long action, void *data)
{
#if defined(CONFIG_CCIC_NOTIFIER) && defined(CONFIG_MUIC_SUPPORT_CCIC)
CC_NOTI_ATTACH_TYPEDEF *pnoti = (CC_NOTI_ATTACH_TYPEDEF *)data;
muic_attached_dev_t attached_dev = pnoti->cable_type;
#else
muic_attached_dev_t attached_dev = *(muic_attached_dev_t *)data;
#endif
int type = MUIC_DOCK_DETACHED;
const char *name;
switch (attached_dev) {
case ATTACHED_DEV_DESKDOCK_MUIC:
case ATTACHED_DEV_DESKDOCK_VB_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH) {
type = MUIC_DOCK_DESKDOCK;
name = "Desk Dock Attach";
return muic_dock_attach_notify(type, name);
}
else if (action == MUIC_NOTIFY_CMD_DETACH)
return muic_dock_detach_notify();
break;
case ATTACHED_DEV_CARDOCK_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH) {
type = MUIC_DOCK_CARDOCK;
name = "Car Dock Attach";
return muic_dock_attach_notify(type, name);
}
else if (action == MUIC_NOTIFY_CMD_DETACH)
return muic_dock_detach_notify();
break;
case ATTACHED_DEV_SMARTDOCK_MUIC:
case ATTACHED_DEV_SMARTDOCK_VB_MUIC:
case ATTACHED_DEV_SMARTDOCK_TA_MUIC:
case ATTACHED_DEV_SMARTDOCK_USB_MUIC:
if (action == MUIC_NOTIFY_CMD_LOGICALLY_ATTACH) {
type = MUIC_DOCK_SMARTDOCK;
name = "Smart Dock Attach";
return muic_dock_attach_notify(type, name);
}
else if (action == MUIC_NOTIFY_CMD_LOGICALLY_DETACH)
return muic_dock_detach_notify();
break;
case ATTACHED_DEV_UNIVERSAL_MMDOCK_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH) {
type = MUIC_DOCK_SMARTDOCK;
name = "Universal MMDock Attach";
return muic_dock_attach_notify(type, name);
}
else if (action == MUIC_NOTIFY_CMD_DETACH)
return muic_dock_detach_notify();
break;
case ATTACHED_DEV_AUDIODOCK_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH) {
type = MUIC_DOCK_AUDIODOCK;
name = "Audio Dock Attach";
return muic_dock_attach_notify(type, name);
}
else if (action == MUIC_NOTIFY_CMD_DETACH)
return muic_dock_detach_notify();
break;
case ATTACHED_DEV_HMT_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH) {
type = MUIC_DOCK_HMT;
name = "HMT Attach";
return muic_dock_attach_notify(type, name);
}
else if (action == MUIC_NOTIFY_CMD_DETACH)
return muic_dock_detach_notify();
break;
case ATTACHED_DEV_GAMEPAD_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH) {
type = MUIC_DOCK_GAMEPAD;
name = "Gamepad Attach";
return muic_dock_attach_notify(type, name);
} else if (action == MUIC_NOTIFY_CMD_DETACH)
return muic_dock_detach_notify();
break;
default:
break;
}
pr_info("%s: ignore(%d)\n", __func__, attached_dev);
return NOTIFY_DONE;
}
static int muic_handle_cable_data_notification(struct notifier_block *nb,
unsigned long action, void *data)
{
#if defined(CONFIG_CCIC_NOTIFIER) && defined(CONFIG_MUIC_SUPPORT_CCIC)
CC_NOTI_ATTACH_TYPEDEF *pnoti = (CC_NOTI_ATTACH_TYPEDEF *)data;
muic_attached_dev_t attached_dev = pnoti->cable_type;
#else
muic_attached_dev_t attached_dev = *(muic_attached_dev_t *)data;
#endif
int jig_state = 0;
#if defined(CONFIG_USB_HW_PARAM)
struct otg_notify *o_notify = get_otg_notify();
#endif
switch (attached_dev) {
case ATTACHED_DEV_JIG_UART_OFF_MUIC:
case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC: /* VBUS enabled */
case ATTACHED_DEV_JIG_UART_OFF_VB_OTG_MUIC: /* for otg test */
case ATTACHED_DEV_JIG_UART_OFF_VB_FG_MUIC: /* for fg test */
case ATTACHED_DEV_JIG_UART_ON_MUIC:
case ATTACHED_DEV_JIG_UART_ON_VB_MUIC: /* VBUS enabled */
case ATTACHED_DEV_JIG_USB_OFF_MUIC:
case ATTACHED_DEV_JIG_USB_ON_MUIC:
if (action == MUIC_NOTIFY_CMD_ATTACH)
jig_state = 1;
break;
#if defined(CONFIG_USB_HW_PARAM)
case ATTACHED_DEV_TIMEOUT_OPEN_MUIC:
if (action == MUIC_NOTIFY_CMD_DETACH && o_notify)
inc_hw_param(o_notify, USB_MUIC_DCD_TIMEOUT_COUNT);
break;
#endif
default:
jig_state = 0;
break;
}
pr_info("%s: MUIC uart type(%d)\n", __func__, jig_state);
#ifdef CONFIG_ANDROID_SWITCH
switch_set_state(&switch_uart3, jig_state);
#endif
return NOTIFY_DONE;
}
#endif /* CONFIG_MUIC_NOTIFIER */
#if defined(CONFIG_USE_SAFEOUT)
int muic_set_safeout(int safeout_path)
{
struct regulator *regulator;
int ret;
pr_info("%s:MUIC safeout path=%d\n", __func__, safeout_path);
if (safeout_path == MUIC_PATH_USB_CP) {
regulator = regulator_get(NULL, "safeout1_range");
if (IS_ERR(regulator) || regulator == NULL)
return -ENODEV;
if (regulator_is_enabled(regulator))
regulator_force_disable(regulator);
regulator_put(regulator);
regulator = regulator_get(NULL, "safeout2_range");
if (IS_ERR(regulator) || regulator == NULL)
return -ENODEV;
if (!regulator_is_enabled(regulator)) {
ret = regulator_enable(regulator);
if (ret)
goto err;
}
regulator_put(regulator);
} else if (safeout_path == MUIC_PATH_USB_AP) {
regulator = regulator_get(NULL, "safeout1_range");
if (IS_ERR(regulator) || regulator == NULL)
return -ENODEV;
if (!regulator_is_enabled(regulator)) {
ret = regulator_enable(regulator);
if (ret)
goto err;
}
regulator_put(regulator);
regulator = regulator_get(NULL, "safeout2_range");
if (IS_ERR(regulator) || regulator == NULL)
return -ENODEV;
if (regulator_is_enabled(regulator))
regulator_force_disable(regulator);
regulator_put(regulator);
} else {
pr_info("%s: not control safeout(%d)\n", __func__, safeout_path);
return -EINVAL;
}
return 0;
err:
pr_info("%s: cannot regulator_enable (%d)\n", __func__, ret);
regulator_put(regulator);
return ret;
}
#endif /* CONFIG_USE_SAFEOUT */
static void muic_init_switch_dev_cb(void)
{
#ifdef CONFIG_ANDROID_SWITCH
int ret;
/* for DockObserver */
ret = switch_dev_register(&switch_dock);
if (ret < 0) {
pr_err("%s: Failed to register dock switch(%d)\n",
__func__, ret);
return;
}
/* for UART event */
ret = switch_dev_register(&switch_uart3);
if (ret < 0) {
pr_err("%s: Failed to register uart3 switch(%d)\n",
__func__, ret);
return;
}
#ifdef CONFIG_SEC_FACTORY
/* for cable type event */
ret = switch_dev_register(&switch_attached_muic_cable);
if (ret < 0) {
pr_err("%s: Failed to register attached_muic_cable switch(%d)\n",
__func__, ret);
return;
}
#endif
#endif /* CONFIG_ANDROID_SWITCH */
#if defined(CONFIG_MUIC_NOTIFIER)
muic_notifier_register(&dock_notifier_block,
muic_handle_dock_notification, MUIC_NOTIFY_DEV_DOCK);
muic_notifier_register(&cable_data_notifier_block,
muic_handle_cable_data_notification, MUIC_NOTIFY_DEV_CABLE_DATA);
#endif /* CONFIG_MUIC_NOTIFIER */
pr_info("%s: done\n", __func__);
}
static void muic_cleanup_switch_dev_cb(void)
{
#ifdef CONFIG_ANDROID_SWITCH
#ifdef CONFIG_SEC_FACTORY
/* for cable type event */
switch_dev_unregister(&switch_attached_muic_cable);
#endif
/* for UART event */
switch_dev_unregister(&switch_uart3);
/* for DockObserver */
switch_dev_unregister(&switch_dock);
#endif /* CONFIG_ANDROID_SWITCH */
#if defined(CONFIG_MUIC_NOTIFIER)
muic_notifier_unregister(&dock_notifier_block);
muic_notifier_unregister(&cable_data_notifier_block);
#endif /* CONFIG_MUIC_NOTIFIER */
pr_info("%s: done\n", __func__);
}
extern struct muic_platform_data muic_pdata;
/* func : set_switch_sel
* switch_sel value get from bootloader comand line
* switch_sel data consist 8 bits (xxxxyyyyzzzz)
* first 4bits(zzzz) mean path infomation.
* next 4bits(yyyy) mean if pmic version info
* next 4bits(xxxx) mean afc disable info
*/
static int set_switch_sel(char *str)
{
get_option(&str, &muic_pdata.switch_sel);
muic_pdata.switch_sel = (muic_pdata.switch_sel) & 0xfff;
pr_info("%s: switch_sel: 0x%03x\n", __func__,
muic_pdata.switch_sel);
return muic_pdata.switch_sel;
}
__setup("pmic_info=", set_switch_sel);
int get_switch_sel(void)
{
return muic_pdata.switch_sel;
}
/* afc_mode:
* 0x31 : Disabled
* 0x30 : Enabled
*/
static int afc_mode = 0;
static int __init set_afc_mode(char *str)
{
int mode;
get_option(&str, &mode);
afc_mode = (mode & 0x0000FF00) >> 8;
pr_info("%s: afc_mode is 0x%02x\n", __func__, afc_mode);
return 0;
}
early_param("charging_mode", set_afc_mode);
int get_afc_mode(void)
{
return afc_mode;
}
static int __ccic_info;
/*
* __ccic_info :
* b'0: 1 if an active ccic is present,
* 0 when muic works without ccic chip or
* no ccic Noti. registration is needed
* even though a ccic chip is present.
*/
static int set_ccic_info(char *str)
{
get_option(&str, &__ccic_info);
pr_info("%s: ccic_info: 0x%04x\n", __func__, __ccic_info);
return __ccic_info;
}
__setup("ccic_info=", set_ccic_info);
int get_ccic_info(void)
{
return __ccic_info;
}
bool is_muic_usb_path_ap_usb(void)
{
if (MUIC_PATH_USB_AP == muic_pdata.usb_path) {
pr_info("%s: [%d]\n", __func__, muic_pdata.usb_path);
return true;
}
return false;
}
bool is_muic_usb_path_cp_usb(void)
{
if (MUIC_PATH_USB_CP == muic_pdata.usb_path) {
pr_info("%s: [%d]\n", __func__, muic_pdata.usb_path);
return true;
}
return false;
}
static int muic_init_gpio_cb(int switch_sel)
{
struct muic_platform_data *pdata = &muic_pdata;
const char *usb_mode;
const char *uart_mode;
int ret = 0;
pr_info("%s (%d)\n", __func__, switch_sel);
if (switch_sel & SWITCH_SEL_USB_MASK) {
pdata->usb_path = MUIC_PATH_USB_AP;
usb_mode = "PDA";
} else {
pdata->usb_path = MUIC_PATH_USB_CP;
usb_mode = "MODEM";
}
if (pdata->set_gpio_usb_sel)
ret = pdata->set_gpio_usb_sel(pdata->uart_path);
if (switch_sel & SWITCH_SEL_UART_MASK) {
pdata->uart_path = MUIC_PATH_UART_AP;
uart_mode = "AP";
} else {
pdata->uart_path = MUIC_PATH_UART_CP;
uart_mode = "CP";
}
/* These flags MUST be updated again from probe function */
pdata->rustproof_on = false;
pdata->afc_disable = false;
if (pdata->set_gpio_uart_sel)
ret = pdata->set_gpio_uart_sel(pdata->uart_path);
pr_info("%s: usb_path(%s), uart_path(%s)\n", __func__,
usb_mode, uart_mode);
return ret;
}
int muic_afc_set_voltage(int voltage)
{
struct muic_platform_data *pdata = &muic_pdata;
if (pdata && pdata->muic_afc_set_voltage_cb)
return pdata->muic_afc_set_voltage_cb(voltage);
pr_err("%s: cannot supported\n", __func__);
return -ENODEV;
}
int muic_hv_charger_init(void)
{
struct muic_platform_data *pdata = &muic_pdata;
if (pdata && pdata->muic_hv_charger_init_cb)
return pdata->muic_hv_charger_init_cb();
pr_err("%s: cannot supported\n", __func__);
return -ENODEV;
}
int muic_set_hiccup_mode(int on_off)
{
struct muic_platform_data *pdata = &muic_pdata;
if (pdata && pdata->muic_set_hiccup_mode_cb)
return pdata->muic_set_hiccup_mode_cb(on_off);
pr_err("%s: cannot supported\n", __func__);
return -ENODEV;
}
struct muic_platform_data muic_pdata = {
.init_switch_dev_cb = muic_init_switch_dev_cb,
.cleanup_switch_dev_cb = muic_cleanup_switch_dev_cb,
.init_gpio_cb = muic_init_gpio_cb,
#if defined(CONFIG_USE_SAFEOUT)
.set_safeout = muic_set_safeout,
#endif /* CONFIG_USE_SAFEOUT */
};
|