blob: b91eef576c54a2a23a6b0c166c4aa456002bdd3c [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2009, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/debugfs.h>
16#include <linux/err.h>
17#include <linux/uaccess.h>
18
19#include <mach/pmic.h>
20
21
22static int debug_lp_mode_control(char *buf, int size)
23{
24 enum switch_cmd cmd;
25 enum vreg_lp_id id;
26 int cnt;
27
28
29 cnt = sscanf(buf, "%u %u", &cmd, &id);
30 if (cnt < 2) {
31 printk(KERN_ERR "%s: sscanf failed cnt=%d", __func__, cnt);
32 return -EINVAL;
33 }
34
35 if (pmic_lp_mode_control(cmd, id) < 0)
36 return -EFAULT;
37
38 return size;
39}
40
41static int debug_vreg_set_level(char *buf, int size)
42{
43 enum vreg_id vreg;
44 int level;
45 int cnt;
46
47 cnt = sscanf(buf, "%u %u", &vreg, &level);
48 if (cnt < 2) {
49 printk(KERN_ERR "%s: sscanf failed cnt=%d", __func__, cnt);
50 return -EINVAL;
51 }
52 if (pmic_vreg_set_level(vreg, level) < 0)
53 return -EFAULT;
54
55 return size;
56}
57
58static int debug_vreg_pull_down_switch(char *buf, int size)
59{
60 enum switch_cmd cmd;
61 enum vreg_pdown_id id;
62 int cnt;
63
64 cnt = sscanf(buf, "%u %u", &cmd, &id);
65 if (cnt < 2) {
66 printk(KERN_ERR "%s: sscanf failed cnt=%d", __func__, cnt);
67 return -EINVAL;
68 }
69 if (pmic_vreg_pull_down_switch(cmd, id) < 0)
70 return -EFAULT;
71
72 return size;
73}
74
75static int debug_secure_mpp_control_digital_output(char *buf, int size)
76{
77 enum mpp_which which;
78 enum mpp_dlogic_level level;
79 enum mpp_dlogic_out_ctrl out;
80 int cnt;
81
82 cnt = sscanf(buf, "%u %u %u", &which, &level, &out);
83 if (cnt < 3) {
84 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
85 return -EINVAL;
86 }
87
88 if (pmic_secure_mpp_control_digital_output(which, level, out) < 0)
89 return -EFAULT;
90
91 return size;
92}
93
94static int debug_secure_mpp_config_i_sink(char *buf, int size)
95{
96 enum mpp_which which;
97 enum mpp_i_sink_level level;
98 enum mpp_i_sink_switch onoff;
99 int cnt;
100
101 cnt = sscanf(buf, "%u %u %u", &which, &level, &onoff);
102 if (cnt < 3) {
103 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
104 return -EINVAL;
105 }
106
107 if (pmic_secure_mpp_config_i_sink(which, level, onoff) < 0)
108 return -EFAULT;
109
110 return size;
111}
112
113static int debug_secure_mpp_config_digital_input(char *buf, int size)
114{
115 enum mpp_which which;
116 enum mpp_dlogic_level level;
117 enum mpp_dlogic_in_dbus dbus;
118 int cnt;
119
120 cnt = sscanf(buf, "%u %u %u", &which, &level, &dbus);
121 if (cnt < 3) {
122 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
123 return -EINVAL;
124 }
125 if (pmic_secure_mpp_config_digital_input(which, level, dbus) < 0)
126 return -EFAULT;
127
128 return size;
129}
130
131static int debug_rtc_start(char *buf, int size)
132{
133 uint time;
134 struct rtc_time *hal;
135 int cnt;
136
137 cnt = sscanf(buf, "%d", &time);
138 if (cnt < 1) {
139 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
140 return -EINVAL;
141 }
142 hal = (struct rtc_time *)&time;
143 if (pmic_rtc_start(hal) < 0)
144 return -EFAULT;
145
146 return size;
147}
148
149static int debug_rtc_stop(char *buf, int size)
150{
151 if (pmic_rtc_stop() < 0)
152 return -EFAULT;
153
154 return size;
155}
156
157static int debug_rtc_get_time(char *buf, int size)
158{
159 uint time;
160 struct rtc_time *hal;
161
162 hal = (struct rtc_time *)&time;
163 if (pmic_rtc_get_time(hal) < 0)
164 return -EFAULT;
165
166 return snprintf(buf, size, "%d\n", time);
167}
168
169static int debug_rtc_alarm_ndx;
170
171int debug_rtc_enable_alarm(char *buf, int size)
172{
173 enum rtc_alarm alarm;
174 struct rtc_time *hal;
175 uint time;
176 int cnt;
177
178
179 cnt = sscanf(buf, "%u %u", &alarm, &time);
180 if (cnt < 2) {
181 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
182 return -EINVAL;
183 }
184 hal = (struct rtc_time *)&time;
185
186 if (pmic_rtc_enable_alarm(alarm, hal) < 0)
187 return -EFAULT;
188
189 debug_rtc_alarm_ndx = alarm;
190 return size;
191}
192
193static int debug_rtc_disable_alarm(char *buf, int size)
194{
195
196 enum rtc_alarm alarm;
197 int cnt;
198
199 cnt = sscanf(buf, "%u", &alarm);
200 if (cnt < 1) {
201 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
202 return -EINVAL;
203 }
204 if (pmic_rtc_disable_alarm(alarm) < 0)
205 return -EFAULT;
206
207 return size;
208}
209
210static int debug_rtc_get_alarm_time(char *buf, int size)
211{
212 uint time;
213 struct rtc_time *hal;
214
215 hal = (struct rtc_time *)&time;
216 if (pmic_rtc_get_alarm_time(debug_rtc_alarm_ndx, hal) < 0)
217 return -EFAULT;
218
219 return snprintf(buf, size, "%d\n", time);
220}
221static int debug_rtc_get_alarm_status(char *buf, int size)
222{
223 int status;;
224
225 if (pmic_rtc_get_alarm_status(&status) < 0)
226 return -EFAULT;
227
228 return snprintf(buf, size, "%d\n", status);
229
230}
231
232static int debug_rtc_set_time_adjust(char *buf, int size)
233{
234 uint adjust;
235 int cnt;
236
237 cnt = sscanf(buf, "%d", &adjust);
238 if (cnt < 1) {
239 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
240 return -EINVAL;
241 }
242 if (pmic_rtc_set_time_adjust(adjust) < 0)
243 return -EFAULT;
244
245 return size;
246}
247
248static int debug_rtc_get_time_adjust(char *buf, int size)
249{
250 int adjust;;
251
252 if (pmic_rtc_get_time_adjust(&adjust) < 0)
253 return -EFAULT;
254
255 return snprintf(buf, size, "%d\n", adjust);
256}
257
258static int debug_set_led_intensity(char *buf, int size)
259{
260 enum ledtype type;
261 int level;
262 int cnt;
263
264 cnt = sscanf(buf, "%u %d", &type, &level);
265 if (cnt < 2) {
266 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
267 return -EINVAL;
268 }
269 if (pmic_set_led_intensity(type, level) < 0)
270 return -EFAULT;
271
272 return size;
273}
274
275static int debug_flash_led_set_current(char *buf, int size)
276{
277 int milliamps;
278 int cnt;
279
280 cnt = sscanf(buf, "%d", &milliamps);
281 if (cnt < 1) {
282 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
283 return -EINVAL;
284 }
285 if (pmic_flash_led_set_current(milliamps) < 0)
286 return -EFAULT;
287
288 return size;
289}
290static int debug_flash_led_set_mode(char *buf, int size)
291{
292
293 uint mode;
294 int cnt;
295
296 cnt = sscanf(buf, "%d", &mode);
297 if (cnt < 1) {
298 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
299 return -EINVAL;
300 }
301 if (pmic_flash_led_set_mode(mode) < 0)
302 return -EFAULT;
303
304 return size;
305}
306
307static int debug_flash_led_set_polarity(char *buf, int size)
308{
309 int pol;
310 int cnt;
311
312 cnt = sscanf(buf, "%d", &pol);
313 if (cnt < 1) {
314 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
315 return -EINVAL;
316 }
317 if (pmic_flash_led_set_polarity(pol) < 0)
318 return -EFAULT;
319
320 return size;
321}
322
323static int debug_speaker_cmd(char *buf, int size)
324{
325 int cmd;
326 int cnt;
327
328 cnt = sscanf(buf, "%d", &cmd);
329 if (cnt < 1) {
330 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
331 return -EINVAL;
332 }
333 if (pmic_speaker_cmd(cmd) < 0)
334 return -EFAULT;
335
336 return size;
337}
338static int debug_set_speaker_gain(char *buf, int size)
339{
340 int gain;
341 int cnt;
342
343 cnt = sscanf(buf, "%d", &gain);
344 if (cnt < 1) {
345 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
346 return -EINVAL;
347 }
348 if (pmic_set_speaker_gain(gain) < 0)
349 return -EFAULT;
350
351 return size;
352}
353
354static int debug_mic_en(char *buf, int size)
355{
356 int enable;
357 int cnt;
358
359 cnt = sscanf(buf, "%d", &enable);
360 if (cnt < 1) {
361 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
362 return -EINVAL;
363 }
364 if (pmic_mic_en(enable) < 0)
365 return -EFAULT;
366
367 return size;
368}
369
370static int debug_mic_is_en(char *buf, int size)
371{
372 int enabled;
373
374 if (pmic_mic_is_en(&enabled) < 0)
375 return -EFAULT;
376
377 return snprintf(buf, size, "%d\n", enabled);
378}
379
380static int debug_mic_set_volt(char *buf, int size)
381{
382 int vol;
383 int cnt;
384
385 cnt = sscanf(buf, "%d", &vol);
386 if (cnt < 1) {
387 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
388 return -EINVAL;
389 }
390 if (pmic_mic_set_volt(vol) < 0)
391 return -EFAULT;
392
393 return size;
394}
395
396static int debug_mic_get_volt(char *buf, int size)
397{
398 uint vol;
399
400 if (pmic_mic_get_volt(&vol) < 0)
401 return -EFAULT;
402
403 return snprintf(buf, size, "%d\n", vol);
404}
405
406static int debug_spkr_en_right_chan(char *buf, int size)
407{
408 int enable;
409 int cnt;
410
411 cnt = sscanf(buf, "%d", &enable);
412 if (cnt < 1) {
413 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
414 return -EINVAL;
415 }
416 if (pmic_spkr_en_right_chan(enable) < 0)
417 return -EFAULT;
418
419 return size;
420}
421
422static int debug_spkr_is_right_chan_en(char *buf, int size)
423{
424 int enabled;
425
426 if (pmic_spkr_is_right_chan_en(&enabled) < 0)
427 return -EFAULT;
428
429 return snprintf(buf, size, "%d\n", enabled);
430}
431static int debug_spkr_en_left_chan(char *buf, int size)
432{
433 int enable;
434 int cnt;
435
436 cnt = sscanf(buf, "%d", &enable);
437 if (cnt < 1) {
438 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
439 return -EINVAL;
440 }
441 if (pmic_spkr_en_left_chan(enable) < 0)
442 return -EFAULT;
443
444 return size;
445}
446
447static int debug_spkr_is_left_chan_en(char *buf, int size)
448{
449 int enabled;
450
451 if (pmic_spkr_is_left_chan_en(&enabled) < 0)
452 return -EFAULT;
453
454 return snprintf(buf, size, "%d\n", enabled);
455}
456
457static int debug_set_spkr_configuration(char *buf, int size)
458{
459
460 struct spkr_config_mode cfg;
461 int cnt;
462
463 cnt = sscanf(buf, "%d %d %d %d %d %d %d %d",
464 &cfg.is_right_chan_en,
465 &cfg.is_left_chan_en,
466 &cfg.is_right_left_chan_added,
467 &cfg.is_stereo_en,
468 &cfg.is_usb_with_hpf_20hz,
469 &cfg.is_mux_bypassed,
470 &cfg.is_hpf_en,
471 &cfg.is_sink_curr_from_ref_volt_cir_en);
472
473 if (cnt < 8) {
474 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
475 return -EINVAL;
476 }
477
478 if (pmic_set_spkr_configuration(&cfg) < 0)
479 return -EFAULT;
480
481 return size;
482}
483
484static int debug_get_spkr_configuration(char *buf, int size)
485{
486 struct spkr_config_mode cfg;
487
488 if (pmic_get_spkr_configuration(&cfg) < 0)
489 return -EFAULT;
490
491 return snprintf(buf, size, "%d %d %d %d %d %d %d %d\n",
492 cfg.is_right_chan_en,
493 cfg.is_left_chan_en,
494 cfg.is_right_left_chan_added,
495 cfg.is_stereo_en,
496 cfg.is_usb_with_hpf_20hz,
497 cfg.is_mux_bypassed,
498 cfg.is_hpf_en,
499 cfg.is_sink_curr_from_ref_volt_cir_en);
500
501}
502
503static int debug_set_speaker_delay(char *buf, int size)
504{
505 int delay;
506 int cnt;
507
508 cnt = sscanf(buf, "%d", &delay);
509 if (cnt < 1) {
510 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
511 return -EINVAL;
512 }
513 if (pmic_set_speaker_delay(delay) < 0)
514 return -EFAULT;
515
516 return size;
517}
518
519static int debug_speaker_1k6_zin_enable(char *buf, int size)
520{
521 uint enable;
522 int cnt;
523
524 cnt = sscanf(buf, "%u", &enable);
525 if (cnt < 1) {
526 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
527 return -EINVAL;
528 }
529 if (pmic_speaker_1k6_zin_enable(enable) < 0)
530 return -EFAULT;
531
532 return size;
533}
534
535static int debug_spkr_set_mux_hpf_corner_freq(char *buf, int size)
536{
537 int freq;
538 int cnt;
539
540 cnt = sscanf(buf, "%d", &freq);
541 if (cnt < 1) {
542 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
543 return -EINVAL;
544 }
545 if (pmic_spkr_set_mux_hpf_corner_freq(freq) < 0)
546 return -EFAULT;
547
548 return size;
549}
550
551static int debug_spkr_get_mux_hpf_corner_freq(char *buf, int size)
552{
553 uint freq;
554
555 if (pmic_spkr_get_mux_hpf_corner_freq(&freq) < 0)
556 return -EFAULT;
557
558 return snprintf(buf, size, "%d\n", freq);
559}
560
561static int debug_spkr_add_right_left_chan(char *buf, int size)
562{
563 int enable;
564 int cnt;
565
566 cnt = sscanf(buf, "%d", &enable);
567 if (cnt < 1) {
568 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
569 return -EINVAL;
570 }
571 if (pmic_spkr_add_right_left_chan(enable) < 0)
572 return -EFAULT;
573
574 return size;
575}
576
577static int debug_spkr_is_right_left_chan_added(char *buf, int size)
578{
579 int enabled;
580
581 if (pmic_spkr_is_right_left_chan_added(&enabled) < 0)
582 return -EFAULT;
583
584 return snprintf(buf, size, "%d\n", enabled);
585}
586
587static int debug_spkr_en_stereo(char *buf, int size)
588{
589 int enable;
590 int cnt;
591
592 cnt = sscanf(buf, "%d", &enable);
593 if (cnt < 1) {
594 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
595 return -EINVAL;
596 }
597 if (pmic_spkr_en_stereo(enable) < 0)
598 return -EFAULT;
599
600 return size;
601}
602static int debug_spkr_is_stereo_en(char *buf, int size)
603{
604 int enabled;
605
606 if (pmic_spkr_is_stereo_en(&enabled) < 0)
607 return -EFAULT;
608
609 return snprintf(buf, size, "%d\n", enabled);
610}
611
612static int debug_spkr_select_usb_with_hpf_20hz(char *buf, int size)
613{
614 int enable;
615 int cnt;
616
617 cnt = sscanf(buf, "%d", &enable);
618 if (cnt < 1) {
619 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
620 return -EINVAL;
621 }
622 if (pmic_spkr_select_usb_with_hpf_20hz(enable) < 0)
623 return -EFAULT;
624
625 return size;
626}
627static int debug_spkr_is_usb_with_hpf_20hz(char *buf, int size)
628{
629 int enabled;
630
631 if (pmic_spkr_is_usb_with_hpf_20hz(&enabled) < 0)
632 return -EFAULT;
633
634 return snprintf(buf, size, "%d\n", enabled);
635}
636
637static int debug_spkr_bypass_mux(char *buf, int size)
638{
639 int enable;
640 int cnt;
641
642 cnt = sscanf(buf, "%d", &enable);
643 if (cnt < 1) {
644 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
645 return -EINVAL;
646 }
647 if (pmic_spkr_bypass_mux(enable) < 0)
648 return -EFAULT;
649
650 return size;
651}
652static int debug_spkr_is_mux_bypassed(char *buf, int size)
653{
654 int enabled;
655
656 if (pmic_spkr_is_mux_bypassed(&enabled) < 0)
657 return -EFAULT;
658
659 return snprintf(buf, size, "%d\n", enabled);
660}
661
662static int debug_spkr_en_hpf(char *buf, int size)
663{
664 int enable;
665 int cnt;
666
667 cnt = sscanf(buf, "%d", &enable);
668 if (cnt < 1) {
669 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
670 return -EINVAL;
671 }
672 if (pmic_spkr_en_hpf(enable) < 0)
673 return -EFAULT;
674
675 return size;
676}
677static int debug_spkr_is_hpf_en(char *buf, int size)
678{
679 int enabled;
680
681 if (pmic_spkr_is_hpf_en(&enabled) < 0)
682 return -EFAULT;
683
684 return snprintf(buf, size, "%d\n", enabled);
685}
686
687static int debug_spkr_en_sink_curr_from_ref_volt_cir(char *buf, int size)
688{
689 int enable;
690 int cnt;
691
692 cnt = sscanf(buf, "%d", &enable);
693 if (cnt < 1) {
694 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
695 return -EINVAL;
696 }
697 if (pmic_spkr_en_sink_curr_from_ref_volt_cir(enable) < 0)
698 return -EFAULT;
699
700 return size;
701}
702
703static int debug_spkr_is_sink_curr_from_ref_volt_cir_en(char *buf, int size)
704{
705 int enabled;
706
707 if (pmic_spkr_is_sink_curr_from_ref_volt_cir_en(&enabled) < 0)
708 return -EFAULT;
709
710 return snprintf(buf, size, "%d\n", enabled);
711}
712
713static int debug_vib_mot_set_volt(char *buf, int size)
714{
715 int vol;
716 int cnt;
717
718 cnt = sscanf(buf, "%d", &vol);
719 if (cnt < 1) {
720 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
721 return -EINVAL;
722 }
723 if (pmic_vib_mot_set_volt(vol) < 0)
724 return -EFAULT;
725
726 return size;
727}
728static int debug_vib_mot_set_mode(char *buf, int size)
729{
730 int mode;
731 int cnt;
732
733 cnt = sscanf(buf, "%d", &mode);
734 if (cnt < 1) {
735 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
736 return -EINVAL;
737 }
738 if (pmic_vib_mot_set_mode(mode) < 0)
739 return -EFAULT;
740
741 return size;
742}
743
744static int debug_vib_mot_set_polarity(char *buf, int size)
745{
746 int pol;
747 int cnt;
748
749 cnt = sscanf(buf, "%d", &pol);
750 if (cnt < 1) {
751 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
752 return -EINVAL;
753 }
754 if (pmic_vib_mot_set_polarity(pol) < 0)
755 return -EFAULT;
756
757 return size;
758}
759static int debug_vid_en(char *buf, int size)
760{
761 int enable;
762 int cnt;
763
764 cnt = sscanf(buf, "%d", &enable);
765 if (cnt < 1) {
766 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
767 return -EINVAL;
768 }
769 if (pmic_vid_en(enable) < 0)
770 return -EFAULT;
771
772 return size;
773}
774static int debug_vid_is_en(char *buf, int size)
775{
776 int enabled;
777
778 if (pmic_vid_is_en(&enabled) < 0)
779 return -EFAULT;
780
781 return snprintf(buf, size, "%d\n", enabled);
782}
783
784static int debug_vid_load_detect_en(char *buf, int size)
785{
786 int enable;
787 int cnt;
788
789 cnt = sscanf(buf, "%d", &enable);
790 if (cnt < 1) {
791 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
792 return -EINVAL;
793 }
794 if (pmic_vid_load_detect_en(enable) < 0)
795 return -EFAULT;
796
797 return size;
798}
799
800/**************************************************
801 * speaker indexed by left_right
802**************************************************/
803static enum spkr_left_right debug_spkr_left_right = LEFT_SPKR;
804
805static int debug_spkr_en(char *buf, int size)
806{
807 int left_right;
808 int enable;
809 int cnt;
810
811 cnt = sscanf(buf, "%d %d", &left_right, &enable);
812 if (cnt < 2) {
813 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
814 return -EINVAL;
815 }
816 if (pmic_spkr_en(left_right, enable) >= 0) {
817 debug_spkr_left_right = left_right;
818 return size;
819 }
820 return -EFAULT;
821}
822
823static int debug_spkr_is_en(char *buf, int size)
824{
825 int enabled;
826
827 if (pmic_spkr_is_en(debug_spkr_left_right, &enabled) < 0)
828 return -EFAULT;
829
830 return snprintf(buf, size, "%d\n", enabled);
831}
832
833static int debug_spkr_set_gain(char *buf, int size)
834{
835 int left_right;
836 int enable;
837 int cnt;
838
839 cnt = sscanf(buf, "%d %d", &left_right, &enable);
840 if (cnt < 2) {
841 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
842 return -EINVAL;
843 }
844 if (pmic_spkr_set_gain(left_right, enable) >= 0) {
845 debug_spkr_left_right = left_right;
846 return size;
847 }
848 return -EFAULT;
849}
850
851static int debug_spkr_get_gain(char *buf, int size)
852{
853 uint gain;
854
855 if (pmic_spkr_get_gain(debug_spkr_left_right, &gain) < 0)
856 return -EFAULT;
857
858 return snprintf(buf, size, "%d\n", gain);
859}
860static int debug_spkr_set_delay(char *buf, int size)
861{
862 int left_right;
863 int delay;
864 int cnt;
865
866 cnt = sscanf(buf, "%d %d", &left_right, &delay);
867 if (cnt < 2) {
868 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
869 return -EINVAL;
870 }
871 if (pmic_spkr_set_delay(left_right, delay) >= 0) {
872 debug_spkr_left_right = left_right;
873 return size;
874 }
875 return -EFAULT;
876}
877
878static int debug_spkr_get_delay(char *buf, int size)
879{
880 uint delay;
881
882 if (pmic_spkr_get_delay(debug_spkr_left_right, &delay) < 0)
883 return -EFAULT;
884
885 return snprintf(buf, size, "%d\n", delay);
886}
887
888static int debug_spkr_en_mute(char *buf, int size)
889{
890 int left_right;
891 int enable;
892 int cnt;
893
894 cnt = sscanf(buf, "%d %d", &left_right, &enable);
895 if (cnt < 2) {
896 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
897 return -EINVAL;
898 }
899 if (pmic_spkr_en_mute(left_right, enable) >= 0) {
900 debug_spkr_left_right = left_right;
901 return size;
902 }
903 return -EFAULT;
904}
905
906static int debug_spkr_is_mute_en(char *buf, int size)
907{
908 int enabled;
909
910 if (pmic_spkr_is_mute_en(debug_spkr_left_right, &enabled) < 0)
911 return -EFAULT;
912
913 return snprintf(buf, size, "%d\n", enabled);
914}
915
916/*******************************************************************
917 * debug function table
918*******************************************************************/
919
920struct pmic_debug_desc {
921 int (*get) (char *, int);
922 int (*set) (char *, int);
923};
924
925struct pmic_debug_desc pmic_debug[] = {
926 {NULL, NULL}, /*LIB_NULL_PROC */
927 {NULL, NULL}, /* LIB_RPC_GLUE_CODE_INFO_REMOTE_PROC */
928 {NULL, debug_lp_mode_control}, /* LP_MODE_CONTROL_PROC */
929 {NULL, debug_vreg_set_level}, /*VREG_SET_LEVEL_PROC */
930 {NULL, debug_vreg_pull_down_switch}, /*VREG_PULL_DOWN_SWITCH_PROC */
931 {NULL, debug_secure_mpp_control_digital_output},
932 /* SECURE_MPP_CONFIG_DIGITAL_OUTPUT_PROC */
933 /*SECURE_MPP_CONFIG_I_SINK_PROC */
934 {NULL, debug_secure_mpp_config_i_sink},
935 {NULL, debug_rtc_start}, /*RTC_START_PROC */
936 {NULL, debug_rtc_stop}, /* RTC_STOP_PROC */
937 {debug_rtc_get_time, NULL}, /* RTC_GET_TIME_PROC */
938 {NULL, debug_rtc_enable_alarm}, /* RTC_ENABLE_ALARM_PROC */
939 {NULL , debug_rtc_disable_alarm}, /*RTC_DISABLE_ALARM_PROC */
940 {debug_rtc_get_alarm_time, NULL}, /* RTC_GET_ALARM_TIME_PROC */
941 {debug_rtc_get_alarm_status, NULL}, /* RTC_GET_ALARM_STATUS_PROC */
942 {NULL, debug_rtc_set_time_adjust}, /* RTC_SET_TIME_ADJUST_PROC */
943 {debug_rtc_get_time_adjust, NULL}, /* RTC_GET_TIME_ADJUST_PROC */
944 {NULL, debug_set_led_intensity}, /* SET_LED_INTENSITY_PROC */
945 {NULL, debug_flash_led_set_current}, /* FLASH_LED_SET_CURRENT_PROC */
946 {NULL, debug_flash_led_set_mode}, /* FLASH_LED_SET_MODE_PROC */
947 {NULL, debug_flash_led_set_polarity}, /* FLASH_LED_SET_POLARITY_PROC */
948 {NULL, debug_speaker_cmd}, /* SPEAKER_CMD_PROC */
949 {NULL, debug_set_speaker_gain}, /* SET_SPEAKER_GAIN_PROC */
950 {NULL, debug_vib_mot_set_volt}, /* VIB_MOT_SET_VOLT_PROC */
951 {NULL, debug_vib_mot_set_mode}, /* VIB_MOT_SET_MODE_PROC */
952 {NULL, debug_vib_mot_set_polarity}, /* VIB_MOT_SET_POLARITY_PROC */
953 {NULL, debug_vid_en}, /* VID_EN_PROC */
954 {debug_vid_is_en, NULL}, /* VID_IS_EN_PROC */
955 {NULL, debug_vid_load_detect_en}, /* VID_LOAD_DETECT_EN_PROC */
956 {NULL, debug_mic_en}, /* MIC_EN_PROC */
957 {debug_mic_is_en, NULL}, /* MIC_IS_EN_PROC */
958 {NULL, debug_mic_set_volt}, /* MIC_SET_VOLT_PROC */
959 {debug_mic_get_volt, NULL}, /* MIC_GET_VOLT_PROC */
960 {NULL, debug_spkr_en_right_chan}, /* SPKR_EN_RIGHT_CHAN_PROC */
961 {debug_spkr_is_right_chan_en, NULL}, /* SPKR_IS_RIGHT_CHAN_EN_PROC */
962 {NULL, debug_spkr_en_left_chan}, /* SPKR_EN_LEFT_CHAN_PROC */
963 {debug_spkr_is_left_chan_en, NULL}, /* SPKR_IS_LEFT_CHAN_EN_PROC */
964 {NULL, debug_set_spkr_configuration}, /* SET_SPKR_CONFIGURATION_PROC */
965 {debug_get_spkr_configuration, NULL}, /* GET_SPKR_CONFIGURATION_PROC */
966 {debug_spkr_get_gain, NULL}, /* SPKR_GET_GAIN_PROC */
967 {debug_spkr_is_en, NULL}, /* SPKR_IS_EN_PROC */
968 {NULL, debug_spkr_en_mute}, /* SPKR_EN_MUTE_PROC */
969 {debug_spkr_is_mute_en, NULL}, /* SPKR_IS_MUTE_EN_PROC */
970 {NULL, debug_spkr_set_delay}, /* SPKR_SET_DELAY_PROC */
971 {debug_spkr_get_delay, NULL}, /* SPKR_GET_DELAY_PROC */
972 /* SECURE_MPP_CONFIG_DIGITAL_INPUT_PROC */
973 {NULL, debug_secure_mpp_config_digital_input},
974 {NULL, debug_set_speaker_delay}, /* SET_SPEAKER_DELAY_PROC */
975 {NULL, debug_speaker_1k6_zin_enable}, /* SPEAKER_1K6_ZIN_ENABLE_PROC */
976 /* SPKR_SET_MUX_HPF_CORNER_FREQ_PROC */
977 {NULL, debug_spkr_set_mux_hpf_corner_freq},
978 /* SPKR_GET_MUX_HPF_CORNER_FREQ_PROC */
979 {debug_spkr_get_mux_hpf_corner_freq, NULL},
980 /* SPKR_IS_RIGHT_LEFT_CHAN_ADDED_PROC */
981 {debug_spkr_is_right_left_chan_added, NULL},
982 {NULL, debug_spkr_en_stereo}, /* SPKR_EN_STEREO_PROC */
983 {debug_spkr_is_stereo_en, NULL}, /* SPKR_IS_STEREO_EN_PROC */
984 /* SPKR_SELECT_USB_WITH_HPF_20HZ_PROC */
985 {NULL, debug_spkr_select_usb_with_hpf_20hz},
986 /* SPKR_IS_USB_WITH_HPF_20HZ_PROC */
987 {debug_spkr_is_usb_with_hpf_20hz, NULL},
988 {NULL, debug_spkr_bypass_mux}, /* SPKR_BYPASS_MUX_PROC */
989 {debug_spkr_is_mux_bypassed, NULL}, /* SPKR_IS_MUX_BYPASSED_PROC */
990 {NULL, debug_spkr_en_hpf}, /* SPKR_EN_HPF_PROC */
991 { debug_spkr_is_hpf_en, NULL}, /* SPKR_IS_HPF_EN_PROC */
992 /* SPKR_EN_SINK_CURR_FROM_REF_VOLT_CIR_PROC */
993 {NULL, debug_spkr_en_sink_curr_from_ref_volt_cir},
994 /* SPKR_IS_SINK_CURR_FROM_REF_VOLT_CIR_EN_PROC */
995 {debug_spkr_is_sink_curr_from_ref_volt_cir_en, NULL},
996 /* SPKR_ADD_RIGHT_LEFT_CHAN_PROC */
997 {NULL, debug_spkr_add_right_left_chan},
998 {NULL, debug_spkr_set_gain}, /* SPKR_SET_GAIN_PROC */
999 {NULL , debug_spkr_en}, /* SPKR_EN_PROC */
1000};
1001
1002/***********************************************************************/
1003
1004#define PROC_END (sizeof(pmic_debug)/sizeof(struct pmic_debug_desc))
1005
1006
1007#define PMIC_DEBUG_BUF 512
1008
1009static int debug_proc; /* PROC's index */
1010
1011static char debug_buf[PMIC_DEBUG_BUF];
1012
1013static int proc_index_set(void *data, u64 val)
1014{
1015 int ndx;
1016
1017 ndx = (int)val;
1018
1019 if (ndx >= 0 && ndx <= PROC_END)
1020 debug_proc = ndx;
1021
1022 return 0;
1023}
1024
1025static int proc_index_get(void *data, u64 *val)
1026{
1027 *val = (u64)debug_proc;
1028 return 0;
1029}
1030
1031DEFINE_SIMPLE_ATTRIBUTE(
1032 proc_index_fops,
1033 proc_index_get,
1034 proc_index_set,
1035 "%llu\n");
1036
1037
1038static int pmic_debugfs_open(struct inode *inode, struct file *file)
1039{
1040 /* non-seekable */
1041 file->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
1042 return 0;
1043}
1044
1045static int pmic_debugfs_release(struct inode *inode, struct file *file)
1046{
1047 return 0;
1048}
1049
1050static ssize_t pmic_debugfs_write(
1051 struct file *file,
1052 const char __user *buff,
1053 size_t count,
1054 loff_t *ppos)
1055{
1056 struct pmic_debug_desc *pd;
1057 int len = 0;
1058
1059 printk(KERN_INFO "%s: proc=%d count=%d *ppos=%d\n",
1060 __func__, debug_proc, count, (uint)*ppos);
1061
1062 if (count > sizeof(debug_buf))
1063 return -EFAULT;
1064
1065 if (copy_from_user(debug_buf, buff, count))
1066 return -EFAULT;
1067
1068
1069 debug_buf[count] = 0; /* end of string */
1070
1071 pd = &pmic_debug[debug_proc];
1072
1073 if (pd->set) {
1074 len = pd->set(debug_buf, count);
1075 printk(KERN_INFO "%s: len=%d\n", __func__, len);
1076 return len;
1077 }
1078
1079 return 0;
1080}
1081
1082static ssize_t pmic_debugfs_read(
1083 struct file *file,
1084 char __user *buff,
1085 size_t count,
1086 loff_t *ppos)
1087{
1088 struct pmic_debug_desc *pd;
1089 int len = 0;
1090
1091 printk(KERN_INFO "%s: proc=%d count=%d *ppos=%d\n",
1092 __func__, debug_proc, count, (uint)*ppos);
1093
1094 pd = &pmic_debug[debug_proc];
1095
1096 if (*ppos)
1097 return 0; /* the end */
1098
1099 if (pd->get) {
1100 len = pd->get(debug_buf, sizeof(debug_buf));
1101 if (len > 0) {
1102 if (len > count)
1103 len = count;
1104 if (copy_to_user(buff, debug_buf, len))
1105 return -EFAULT;
1106 }
1107 }
1108
1109 printk(KERN_INFO "%s: len=%d\n", __func__, len);
1110
1111 if (len < 0)
1112 return 0;
1113
1114 *ppos += len; /* increase offset */
1115
1116 return len;
1117}
1118
1119static const struct file_operations pmic_debugfs_fops = {
1120 .open = pmic_debugfs_open,
1121 .release = pmic_debugfs_release,
1122 .read = pmic_debugfs_read,
1123 .write = pmic_debugfs_write,
1124};
1125
1126static int __init pmic_debugfs_init(void)
1127{
1128 struct dentry *dent = debugfs_create_dir("pmic", NULL);
1129
1130 if (IS_ERR(dent)) {
1131 printk(KERN_ERR "%s(%d): debugfs_create_dir fail, error %ld\n",
1132 __FILE__, __LINE__, PTR_ERR(dent));
1133 return -1;
1134 }
1135
1136 if (debugfs_create_file("index", 0644, dent, 0, &proc_index_fops)
1137 == NULL) {
1138 printk(KERN_ERR "%s(%d): debugfs_create_file: index fail\n",
1139 __FILE__, __LINE__);
1140 return -1;
1141 }
1142
1143 if (debugfs_create_file("debug", 0644, dent, 0, &pmic_debugfs_fops)
1144 == NULL) {
1145 printk(KERN_ERR "%s(%d): debugfs_create_file: debug fail\n",
1146 __FILE__, __LINE__);
1147 return -1;
1148 }
1149
1150 debug_proc = 0;
1151 debug_rtc_alarm_ndx = 0;
1152
1153 return 0;
1154}
1155
1156late_initcall(pmic_debugfs_init);