-
Notifications
You must be signed in to change notification settings - Fork 9
/
patch-3.6.8-nsa310.diff
1896 lines (1881 loc) · 50.8 KB
/
patch-3.6.8-nsa310.diff
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/Kconfig linux-3.6.8-my/arch/arm/Kconfig
--- linux-3.6.8/arch/arm/Kconfig 2012-11-26 21:15:45.000000000 +0100
+++ linux-3.6.8-my/arch/arm/Kconfig 2012-11-29 16:58:20.627812386 +0100
@@ -584,6 +584,7 @@
config ARCH_KIRKWOOD
bool "Marvell Kirkwood"
select CPU_FEROCEON
+ select ARCH_HAS_CPUFREQ
select PCI
select ARCH_REQUIRE_GPIOLIB
select GENERIC_CLOCKEVENTS
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/mach-kirkwood/cpufreq.c linux-3.6.8-my/arch/arm/mach-kirkwood/cpufreq.c
--- linux-3.6.8/arch/arm/mach-kirkwood/cpufreq.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.6.8-my/arch/arm/mach-kirkwood/cpufreq.c 2012-11-29 16:58:20.631816785 +0100
@@ -0,0 +1,248 @@
+/*
+ * arch/arm/mach-kirkwood/cpufreq.c
+ *
+ * Clock scaling for Kirkwood SoC
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/io.h>
+#include <mach/kirkwood.h>
+#include <mach/bridge-regs.h>
+#include <linux/export.h>
+
+
+
+enum kw_cpufreq_range {
+ KW_CPUFREQ_LOW = 0,
+ KW_CPUFREQ_HIGH = 1
+};
+
+static struct cpufreq_frequency_table kw_freqs[] = {
+ { KW_CPUFREQ_LOW, 0 },
+ { KW_CPUFREQ_HIGH, 0 },
+ { 0, CPUFREQ_TABLE_END }
+};
+
+
+static inline void kw_set_powersave_on(void)
+{
+ unsigned long old,temp;
+ /* Disable int */
+ __asm__ __volatile__("mrs %0, cpsr\n"
+ "orr %1, %0, #0xc0\n"
+ "msr cpsr_c, %1"
+ : "=r" (old), "=r" (temp)
+ :
+ : "memory");
+
+ /* Set SoC in power save */
+ writel(readl(CLOCK_GATING_CTRL) | (1 << 11), CLOCK_GATING_CTRL);
+
+ /* Wait for int */
+ __asm__ __volatile__("mcr p15, 0, r0, c7, c0, 4");
+
+ /* Enabled int */
+ __asm__ __volatile__("msr cpsr_c, %0"
+ :
+ : "r" (old)
+ : "memory");
+}
+
+static inline void kw_set_powersave_off(void)
+{
+ unsigned long old,temp;
+ /* Disable int */
+ __asm__ __volatile__("mrs %0, cpsr\n"
+ "orr %1, %0, #0xc0\n"
+ "msr cpsr_c, %1"
+ : "=r" (old), "=r" (temp)
+ :
+ : "memory");
+
+ /* Set SoC in power save */
+ writel(readl(CLOCK_GATING_CTRL) & (~(1 << 11)), CLOCK_GATING_CTRL);
+
+ /* Wait for int */
+ __asm__ __volatile__("mcr p15, 0, r0, c7, c0, 4");
+
+ /* Enabled int */
+ __asm__ __volatile__("msr cpsr_c, %0"
+ :
+ : "r" (old)
+ : "memory");
+}
+
+/*
+ * Power management function: set or unset powersave mode
+ * FIXME: a better place ?
+ */
+static inline void kw_set_powersave(int on)
+{
+ if (on)
+ kw_set_powersave_on();
+ else
+ kw_set_powersave_off();
+}
+
+static int kw_cpufreq_verify(struct cpufreq_policy *policy)
+{
+ if (unlikely(!cpu_online(policy->cpu)))
+ return -ENODEV;
+
+ return cpufreq_frequency_table_verify(policy, kw_freqs);
+}
+
+/*
+ * Get the current frequency for a given cpu.
+ */
+static unsigned int kw_cpufreq_get(unsigned int cpu)
+{
+ unsigned int freq;
+ u32 reg;
+
+ if (unlikely(!cpu_online(cpu)))
+ return -ENODEV;
+
+ /* To get the current frequency, we have to check if
+ * the powersave mode is set. */
+ reg = readl(CLOCK_GATING_CTRL);
+
+ if (reg & (1 << 11))
+ freq = kw_freqs[KW_CPUFREQ_LOW].frequency;
+ else
+ freq = kw_freqs[KW_CPUFREQ_HIGH].frequency;
+
+ return freq;
+}
+
+/*
+ * Set the frequency for a given cpu.
+ */
+static int kw_cpufreq_target(struct cpufreq_policy *policy,
+ unsigned int target_freq, unsigned int relation)
+{
+ unsigned int index;
+ struct cpufreq_freqs freqs;
+
+ if (unlikely(!cpu_online(policy->cpu)))
+ return -ENODEV;
+
+ /* Lookup the next frequency */
+ if (unlikely(cpufreq_frequency_table_target(policy,
+ kw_freqs, target_freq, relation, &index)))
+ return -EINVAL;
+
+
+ freqs.old = policy->cur;
+ freqs.new = kw_freqs[index].frequency;
+ freqs.cpu = policy->cpu;
+
+ cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ /* Interruptions will be disabled in the low level power mode
+ * functions. */
+ if (index == KW_CPUFREQ_LOW)
+ kw_set_powersave(1);
+ else if (index == KW_CPUFREQ_HIGH)
+ kw_set_powersave(0);
+ else
+ return -EINVAL;
+
+ cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+
+ return 0;
+}
+
+static int kw_cpufreq_cpu_init(struct cpufreq_policy *policy)
+{
+ if (unlikely(!cpu_online(policy->cpu)))
+ return -ENODEV;
+
+#if 0
+ TODO: Read cpu frequencies from register
+ /*
+ * As 6180 board have different reset sample register values,
+ * the board type must be checked first.
+ */
+ if (dev_id == MV_6180_DEV_ID) {
+
+ kw_freqs[KW_CPUFREQ_HIGH].frequency = mvCpuPclkGet()/1000;
+ /* At the lowest frequency CPU goes to DDR data clock rate:
+ * (2 x DDR clock rate). */
+ kw_freqs[KW_CPUFREQ_LOW].frequency = mvBoardSysClkGet()*2/1000;
+
+ } else if ((dev_id == MV_6281_DEV_ID) ||
+ (dev_id == MV_6192_DEV_ID)) {
+
+ kw_freqs[KW_CPUFREQ_HIGH].frequency = mvCpuPclkGet()/1000;
+ /* CPU low frequency is the DDR frequency. */
+ kw_freqs[KW_CPUFREQ_LOW].frequency = mvBoardSysClkGet()/1000;
+
+ } else {
+ return -ENODEV;
+ }
+#endif
+ /* God knows */
+ kw_freqs[KW_CPUFREQ_HIGH].frequency = 1200000;
+ kw_freqs[KW_CPUFREQ_LOW].frequency = 400000;
+
+ printk(KERN_INFO
+ "cpufreq: High frequency: %uKHz - Low frequency: %uKHz\n",
+ kw_freqs[KW_CPUFREQ_HIGH].frequency,
+ kw_freqs[KW_CPUFREQ_LOW].frequency);
+
+ policy->cpuinfo.transition_latency = 1000000;
+ policy->cur = kw_cpufreq_get(0);
+ policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+
+ cpufreq_frequency_table_get_attr(kw_freqs, policy->cpu);
+
+ return cpufreq_frequency_table_cpuinfo(policy, kw_freqs);
+}
+
+
+static int kw_cpufreq_cpu_exit(struct cpufreq_policy *policy)
+{
+ cpufreq_frequency_table_put_attr(policy->cpu);
+ return 0;
+}
+
+static struct freq_attr *kw_freq_attr[] = {
+ &cpufreq_freq_attr_scaling_available_freqs,
+ NULL,
+};
+
+
+static struct cpufreq_driver kw_freq_driver = {
+ .name = "kw_cpufreq",
+ .owner = THIS_MODULE,
+ .init = kw_cpufreq_cpu_init,
+ .verify = kw_cpufreq_verify,
+ .exit = kw_cpufreq_cpu_exit,
+ .target = kw_cpufreq_target,
+ .get = kw_cpufreq_get,
+ .attr = kw_freq_attr,
+};
+
+
+static int __init kw_cpufreq_init(void)
+{
+ printk(KERN_INFO "cpufreq: Init kirkwood cpufreq driver\n");
+
+ return cpufreq_register_driver(&kw_freq_driver);
+}
+
+static void __exit kw_cpufreq_exit(void)
+{
+ cpufreq_unregister_driver(&kw_freq_driver);
+}
+
+module_init(kw_cpufreq_init);
+module_exit(kw_cpufreq_exit);
+
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/mach-kirkwood/Kconfig linux-3.6.8-my/arch/arm/mach-kirkwood/Kconfig
--- linux-3.6.8/arch/arm/mach-kirkwood/Kconfig 2012-11-26 21:15:45.000000000 +0100
+++ linux-3.6.8-my/arch/arm/mach-kirkwood/Kconfig 2012-11-29 16:58:20.631816785 +0100
@@ -195,6 +195,28 @@
Say 'Y' here if you want your kernel to support the
HP t5325 Thin Client.
+config ZYXEL_NAS
+ bool "Support for ZyXEL NAS devices"
+ help
+ Enable this to set more options for ZyXEL NAS.
+
+choice
+ prompt "ZyXEL NAS Model"
+ depends on ZYXEL_NAS
+ default MACH_NSA310
+
+config MACH_NSA310
+ bool "Zyxel NSA310 NAS"
+ help
+ Support for ZyXEL NSA310 board.
+
+config MACH_NSA320
+ bool "Zyxel NSA320 NAS"
+ help
+ Support for ZyXEL NSA320 board.
+
+endchoice
+
endmenu
endif
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/mach-kirkwood/Makefile linux-3.6.8-my/arch/arm/mach-kirkwood/Makefile
--- linux-3.6.8/arch/arm/mach-kirkwood/Makefile 2012-11-26 21:15:45.000000000 +0100
+++ linux-3.6.8-my/arch/arm/mach-kirkwood/Makefile 2012-11-29 16:58:20.631816785 +0100
@@ -18,8 +18,11 @@
obj-$(CONFIG_MACH_NET2BIG_V2) += netxbig_v2-setup.o lacie_v2-common.o
obj-$(CONFIG_MACH_NET5BIG_V2) += netxbig_v2-setup.o lacie_v2-common.o
obj-$(CONFIG_MACH_T5325) += t5325-setup.o
+obj-$(CONFIG_MACH_NSA320) += nsa320-setup.o mcu.o
+obj-$(CONFIG_MACH_NSA310) += nsa310-setup.o
obj-$(CONFIG_CPU_IDLE) += cpuidle.o
+obj-$(CONFIG_ARM_KIRKWOOD_CPUFREQ) += cpufreq.o
obj-$(CONFIG_ARCH_KIRKWOOD_DT) += board-dt.o
obj-$(CONFIG_MACH_DREAMPLUG_DT) += board-dreamplug.o
obj-$(CONFIG_MACH_ICONNECT_DT) += board-iconnect.o
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/mach-kirkwood/mcu.c linux-3.6.8-my/arch/arm/mach-kirkwood/mcu.c
--- linux-3.6.8/arch/arm/mach-kirkwood/mcu.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.6.8-my/arch/arm/mach-kirkwood/mcu.c 2012-11-29 16:58:20.631816785 +0100
@@ -0,0 +1,125 @@
+#include <linux/module.h>
+#include <linux/init.h>
+#include <asm/irq.h>
+#include <asm/delay.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/timer.h>
+#include <linux/syscalls.h>
+#include <linux/kmod.h>
+#include <linux/syscalls.h>
+#include <linux/fs.h>
+#include <asm/fcntl.h>
+#include <asm/hardirq.h>
+#include <linux/ioctl.h>
+#include <linux/cdev.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <asm/io.h>
+#include <linux/spinlock.h>
+#include <mach/hardware.h>
+#include <asm/uaccess.h>
+#include <linux/syscalls.h>
+#include <asm/atomic.h>
+#include <linux/proc_fs.h>
+#include <asm/uaccess.h>
+#include <linux/kernel.h>
+
+#include <mach/kirkwood.h>
+#include <plat/gpio.h>
+#include <linux/gpio.h>
+#include "common.h"
+#include "mpp.h"
+
+
+
+#define MCU_DATA_PIN 14
+#define MCU_CLK_PIN 16
+#define MCU_ACT_PIN 17
+
+MODULE_LICENSE("GPL v2");
+#define MODULE_NAME "mcu"
+
+unsigned long mcu_data = 0;
+unsigned long mcu_counter = 0;
+
+static struct proc_dir_entry *mcu_proc;
+
+static int mcu_status_read_fn(char *buf, char **start, off_t offset,
+ int count, int *eof, void *data)
+{
+ unsigned long len, i;
+
+ mcu_data = 0;
+
+ gpio_request(14, "MCU_DATA");
+ gpio_request(16, "MCU_CLK");
+ gpio_request(17, "MCU_ACT");
+
+ gpio_direction_output(MCU_ACT_PIN, 0);
+ msleep(100);
+ gpio_direction_input(MCU_DATA_PIN);
+ gpio_direction_output(MCU_CLK_PIN, 0);
+ udelay(100);
+
+ for(i = 0 ; i < 32 ; i++)
+ {
+ mcu_data <<= 1;
+ gpio_set_value(MCU_CLK_PIN,1);
+
+ mcu_data |= gpio_get_value(MCU_DATA_PIN)?0x1:0;
+
+ udelay(100);
+
+ gpio_set_value(MCU_CLK_PIN,0);
+
+ udelay(100);
+ }
+
+
+ gpio_set_value(MCU_CLK_PIN,1);
+ gpio_set_value(MCU_ACT_PIN,1);
+
+
+ gpio_free(14);
+ gpio_free(16);
+ gpio_free(17);
+
+ len = sprintf(buf, "MagicNum:%u\nRpss:%u\nTemperature:%u\n",(unsigned int)((mcu_data & 0xff000000) >> 24),
+ (unsigned int)((mcu_data & 0xff0000) >> 16),
+ (unsigned int)((mcu_data & 0xffff)));
+ *eof = 1;
+
+ return len;
+}
+
+static int mcu_status_write_fn(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
+{
+ return 0;
+}
+
+
+static int __init mcu_init(void)
+{
+
+ mcu_proc = create_proc_entry("mcu", 0644, NULL);
+ if(mcu_proc != NULL)
+ {
+ mcu_proc->read_proc = mcu_status_read_fn;
+ mcu_proc->write_proc = mcu_status_write_fn;
+ }
+
+ return 0;
+}
+
+static void __exit mcu_exit(void)
+{
+ remove_proc_entry("mcu", NULL);
+
+}
+
+module_init(mcu_init);
+module_exit(mcu_exit);
+
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/mach-kirkwood/nsa310-setup.c linux-3.6.8-my/arch/arm/mach-kirkwood/nsa310-setup.c
--- linux-3.6.8/arch/arm/mach-kirkwood/nsa310-setup.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.6.8-my/arch/arm/mach-kirkwood/nsa310-setup.c 2012-12-04 23:42:31.280984059 +0100
@@ -0,0 +1,330 @@
+ /*
+ * Zyxel NSA-310 Setup, by AA666 and Peeter123
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/mtd/partitions.h>
+#include <mtd/mtd-abi.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_i2c.h>
+#include <linux/ethtool.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/leds.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <mach/kirkwood.h>
+#include <plat/mvsdio.h>
+#include "common.h"
+#include "mpp.h"
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+
+static void nsa310_timerfunc(unsigned long data);
+static DEFINE_TIMER(timer, nsa310_timerfunc, 0, 0);
+
+static struct mtd_partition nsa310_nand_parts[] = {
+ {
+ .name = "uboot",
+ .offset = 0,
+ .size = 0x100000,
+ .mask_flags = MTD_WRITEABLE
+ }, {
+ .name = "uboot_env",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x80000
+ }, {
+ .name = "key_store",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x80000
+ }, {
+ .name = "info",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x80000
+ }, {
+ .name = "etc",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0xA00000
+ }, {
+ .name = "kernel_1",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0xA00000
+ }, {
+ .name = "rootfs1",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x2FC0000
+ }, {
+ .name = "kernel_2",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0xA00000
+ }, {
+ .name = "rootfs2",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x2FC0000
+ },
+};
+
+static struct mv_sata_platform_data nsa310_sata_data = {
+ .n_ports = 2,
+};
+
+static unsigned int nsa310_mpp_config[] __initdata = {
+ MPP36_GPIO, // Reset button
+ MPP37_GPIO, // Copy button
+ MPP46_GPIO, // Power button
+
+ MPP48_GPIO, // Power Off
+ MPP21_GPIO, // USB Power Off
+
+ MPP28_GPIO, // Sys LED Green
+ MPP29_GPIO, // Sys LED Yellow
+ MPP41_GPIO, // SATA1 LED Green
+ MPP42_GPIO, // SATA1 LED Red
+ MPP12_GPIO, // SATA2 LED Green
+ MPP13_GPIO, // SATA2 LED Red
+ MPP39_GPIO, // Copy LED Green
+ MPP40_GPIO, // Copy LED Red
+ MPP15_GPIO, // USB LED Green
+
+ MPP14_GPIO, // MCU Data
+ MPP16_GPIO, // MCU Clk
+ MPP17_GPIO, // MCU Act
+
+ MPP38_GPIO, // VID B0
+ MPP45_GPIO, // VID B1
+
+ MPP44_GPIO, // Buzzer
+ MPP43_GPIO, // HTP
+
+ MPP47_GPIO, // Power Resume Data
+ MPP49_GPIO, // Power Resume Clock
+
+ 0
+};
+
+static struct gpio_led nsa310_gpio_led[] = {
+ {
+ .name = "nsa310:green:System",
+ .default_trigger = "timer",
+ .gpio = 28,
+ .active_low = 0,
+
+ },
+ {
+ .name = "nsa310:red:System",
+ .default_trigger = "none",
+ .gpio = 29,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:green:SATA1",
+ .default_trigger = "none",
+ .gpio = 41,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:red:SATA1",
+ .default_trigger = "sata-disk",
+ .gpio = 42,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:green:SATA2",
+ .default_trigger = "none",
+ .gpio = 12,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:red:SATA2",
+ .default_trigger = "none",
+ .gpio = 13,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:green:USB",
+ .default_trigger = "none",
+ .gpio = 15,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:green:Copy",
+ .default_trigger = "none",
+ .gpio = 39,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa310:red:Copy",
+ .default_trigger = "none",
+ .gpio = 40,
+ .active_low = 0,
+ },
+};
+
+
+static int nsa310_gpio_blink_set(unsigned gpio, int state,
+ unsigned long *delay_on, unsigned long *delay_off)
+{
+ switch(state) {
+ case GPIO_LED_NO_BLINK_LOW:
+ case GPIO_LED_NO_BLINK_HIGH:
+ orion_gpio_set_blink(gpio, 0);
+ gpio_set_value(gpio, state);
+ break;
+ case GPIO_LED_BLINK:
+ orion_gpio_set_blink(gpio, 1);
+ break;
+ }
+ return 0;
+}
+
+static struct gpio_led_platform_data nsa310_led_data = {
+ .leds = nsa310_gpio_led,
+ .num_leds = ARRAY_SIZE(nsa310_gpio_led),
+ .gpio_blink_set = nsa310_gpio_blink_set,
+};
+
+static struct platform_device nsa310_leds = {
+ .name = "leds-gpio",
+ .id = -1,
+ .dev = { .platform_data = &nsa310_led_data, }
+};
+
+static struct gpio_keys_button nsa310_gpio_keys_button[] = {
+ {
+ .code = KEY_POWER,
+ .type = EV_KEY,
+ .gpio = 46,
+ .desc = "Power Button",
+ .active_low = 0,
+ .debounce_interval = 100,
+ },
+ {
+ .code = KEY_COPY,
+ .type = EV_KEY,
+ .gpio = 37,
+ .desc = "USB Copy",
+ .active_low = 1,
+ .debounce_interval = 100,
+ },
+ {
+ .code = KEY_RESTART,
+ .type = EV_KEY,
+ .gpio = 36,
+ .desc = "Reset",
+ .active_low = 1,
+ .debounce_interval = 100,
+ },
+};
+
+static struct gpio_keys_platform_data nsa310_keys_data = {
+ .buttons = nsa310_gpio_keys_button,
+ .nbuttons = ARRAY_SIZE(nsa310_gpio_keys_button),
+};
+
+
+static struct platform_device nsa310_buttons = {
+ .name = "gpio-keys",
+ .id = -1,
+ .dev = { .platform_data = &nsa310_keys_data, }
+};
+
+static void nsa310_power_off(void)
+{
+ printk(KERN_INFO "NSA310: Activating power off GPIO pin...\n");
+ gpio_set_value(48, 1);
+
+}
+
+static void nsa310_timerfunc(unsigned long data)
+{
+// Activate USB Power
+ if (gpio_request(21, "USB Power") != 0 || gpio_direction_output(21, 1) != 0)
+ printk(KERN_ERR "NSA310: Failed to setup USB power GPIO\n");
+ else
+ printk(KERN_INFO "NSA310: USB power enabled\n");
+ gpio_free(21);
+}
+
+static void __init nsa310_init(void)
+{
+ u32 dev, rev;
+ printk(KERN_INFO "NSA310: Init board\n");
+ kirkwood_init();
+
+ kirkwood_mpp_conf(nsa310_mpp_config);
+ kirkwood_nand_init(ARRAY_AND_SIZE(nsa310_nand_parts), 40);
+ kirkwood_pcie_id(&dev, &rev);
+
+ kirkwood_sata_init(&nsa310_sata_data);
+ kirkwood_uart0_init();
+ kirkwood_i2c_init();
+
+ platform_device_register(&nsa310_leds);
+ platform_device_register(&nsa310_buttons);
+
+ printk(KERN_INFO "NSA310: Start USB and 20 sec USB power delay\n");
+ kirkwood_ehci_init();
+ /* USB Power delay for 20 sec */
+ timer.function = nsa310_timerfunc;
+ timer.data = 0;
+ timer.expires = jiffies + msecs_to_jiffies(20000);
+ add_timer(&timer);
+
+
+/* Power resume control */
+
+ /* Request GPIO access */
+ gpio_request(47, "Power-data");
+ gpio_request(49, "Power-clk");
+
+ /* Set GPIO output */
+ gpio_direction_output(49, 1);
+ gpio_direction_output(47, 1);
+
+ udelay(1000);
+ gpio_set_value(49, 0);
+
+ /* Free GPIO pins */
+ gpio_free(47);
+ gpio_free(49);
+
+ printk(KERN_INFO "NSA310: Power Resume Enabled\n");
+
+ /* Activate Power-off GPIO */
+ if (gpio_request(48, "Power-off") == 0 && gpio_direction_output(48, 0) == 0) {
+ pm_power_off = nsa310_power_off;
+ printk(KERN_INFO "NSA310: Power-off GPIO enabled\n");
+ } else
+ printk(KERN_ERR "NSA310: Failed to configure Power-off GPIO\n");
+
+};
+
+static int __init nsa310_pci_init(void)
+{
+ if (machine_is_nsa310())
+ kirkwood_pcie_init(KW_PCIE0);
+ return 0;
+}
+
+subsys_initcall(nsa310_pci_init);
+
+MACHINE_START(NSA310, "Zyxel NSA-310")
+ .atag_offset = 0x100,
+ .init_machine = nsa310_init,
+ .map_io = kirkwood_map_io,
+ .init_early = kirkwood_init_early,
+ .init_irq = kirkwood_init_irq,
+ .timer = &kirkwood_timer,
+ .restart = kirkwood_restart,
+MACHINE_END
+
diff -uNr '--exclude=out' linux-3.6.8/arch/arm/mach-kirkwood/nsa320-setup.c linux-3.6.8-my/arch/arm/mach-kirkwood/nsa320-setup.c
--- linux-3.6.8/arch/arm/mach-kirkwood/nsa320-setup.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.6.8-my/arch/arm/mach-kirkwood/nsa320-setup.c 2012-11-29 16:58:20.635821184 +0100
@@ -0,0 +1,357 @@
+/*
+ * arch/arm/mach-kirkwood/nsa320-setup.c
+ *
+ * Zyxel NSA-320 Setup, by AA666
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/mtd/partitions.h>
+#include <mtd/mtd-abi.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/mv643xx_i2c.h>
+#include <linux/ethtool.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/leds.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <mach/kirkwood.h>
+#include <plat/mvsdio.h>
+#include "common.h"
+#include "mpp.h"
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+
+static void nsa320_timerfunc(unsigned long data);
+static DEFINE_TIMER(timer, nsa320_timerfunc, 0, 0);
+
+static struct mtd_partition nsa320_nand_parts[] = {
+ {
+ .name = "uboot",
+ .offset = 0,
+ .size = 0x100000,
+ .mask_flags = MTD_WRITEABLE
+ }, {
+ .name = "uboot_env",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x80000
+ }, {
+ .name = "key_store",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x80000
+ }, {
+ .name = "info",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x80000
+ }, {
+ .name = "etc",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0xA00000
+ }, {
+ .name = "kernel_1",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0xA00000
+ }, {
+ .name = "rootfs1",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x2FC0000
+ }, {
+ .name = "kernel_2",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0xA00000
+ }, {
+ .name = "rootfs2",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = 0x2FC0000
+ },
+};
+
+static struct i2c_board_info __initdata nsa320_i2c_rtc = {
+ I2C_BOARD_INFO("pcf8563", 0x51),
+};
+
+static struct mv643xx_eth_platform_data nsa320_ge00_data = {
+ .phy_addr = MV643XX_ETH_PHY_ADDR(0),
+ .speed = SPEED_1000,
+ .duplex = DUPLEX_FULL,
+};
+
+static struct mv_sata_platform_data nsa320_sata_data = {
+ .n_ports = 2,
+};
+
+static unsigned int nsa320_mpp_config[] __initdata = {
+ MPP36_GPIO, // Reset button
+ MPP37_GPIO, // Copy button
+ MPP46_GPIO, // Power button
+
+ MPP48_GPIO, // Power Off
+ MPP21_GPIO, // USB Power Off
+
+ MPP28_GPIO, // Sys LED Green
+ MPP29_GPIO, // Sys LED Yellow
+ MPP41_GPIO, // SATA1 LED Green
+ MPP42_GPIO, // SATA1 LED Red
+ MPP12_GPO, // SATA2 LED Green
+ MPP13_GPIO, // SATA2 LED Red
+ MPP39_GPIO, // Copy LED Green
+ MPP40_GPIO, // Copy LED Red
+ MPP15_GPIO, // USB LED Green
+
+ MPP14_GPIO, // MCU Data
+ MPP16_GPIO, // MCU Clk
+ MPP17_GPIO, // MCU Act
+
+ MPP38_GPIO, // VID B0
+ MPP45_GPIO, // VID B1
+
+ MPP44_GPIO, // Buzzer
+ MPP43_GPIO, // HTP
+
+ MPP47_GPIO, // Power Resume Data
+ MPP49_GPIO, // Power Resume Clock
+
+ 0
+};
+
+static struct gpio_led nsa320_gpio_led[] = {
+ {
+ .name = "nsa320:green:System",
+ .default_trigger = "timer",
+ .gpio = 28,
+ .active_low = 0,
+
+ },
+ {
+ .name = "nsa320:red:System",
+ .default_trigger = "none",
+ .gpio = 29,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:green:SATA1",
+ .default_trigger = "none",
+ .gpio = 41,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:red:SATA1",
+ .default_trigger = "sata-disk",
+ .gpio = 42,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:green:SATA2",
+ .default_trigger = "none",
+ .gpio = 12,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:red:SATA2",
+ .default_trigger = "none",
+ .gpio = 13,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:green:USB",
+ .default_trigger = "none",
+ .gpio = 15,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:green:Copy",
+ .default_trigger = "none",
+ .gpio = 39,
+ .active_low = 0,
+ },
+ {
+ .name = "nsa320:red:Copy",
+ .default_trigger = "none",
+ .gpio = 40,
+ .active_low = 0,
+ },
+};
+
+
+static int nsa320_gpio_blink_set(unsigned gpio, int state,
+ unsigned long *delay_on, unsigned long *delay_off)
+{
+
+// Use hardware acceleration
+// if (delay_on && delay_off && !*delay_on && !*delay_off)
+// *delay_on = *delay_off = 100;
+
+ switch(state) {
+ case GPIO_LED_NO_BLINK_LOW:
+ case GPIO_LED_NO_BLINK_HIGH:
+ orion_gpio_set_blink(gpio, 0);
+ gpio_set_value(gpio, state);
+ break;
+ case GPIO_LED_BLINK:
+ orion_gpio_set_blink(gpio, 1);
+ break;
+ }
+ return 0;
+}
+
+
+static struct gpio_led_platform_data nsa320_led_data = {
+ .leds = nsa320_gpio_led,
+ .num_leds = ARRAY_SIZE(nsa320_gpio_led),
+ .gpio_blink_set = nsa320_gpio_blink_set,
+};
+
+static struct platform_device nsa320_leds = {
+ .name = "leds-gpio",
+ .id = -1,
+ .dev = { .platform_data = &nsa320_led_data, }
+};
+
+static struct gpio_keys_button nsa320_gpio_keys_button[] = {
+ {
+ .code = KEY_POWER,