forked from openwrt/openwrt
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
0001-MIPS-lantiq-add-pcie-driver.patch
5506 lines (5496 loc) · 224 KB
/
0001-MIPS-lantiq-add-pcie-driver.patch
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
From 6f933347d0b4ed02d9534f5fa07f7b99f13eeaa1 Mon Sep 17 00:00:00 2001
From: John Crispin <blogic@openwrt.org>
Date: Thu, 7 Aug 2014 18:12:28 +0200
Subject: [PATCH 01/36] MIPS: lantiq: add pcie driver
Signed-off-by: John Crispin <blogic@openwrt.org>
---
arch/mips/lantiq/Kconfig | 10 +
arch/mips/lantiq/xway/sysctrl.c | 2 +
arch/mips/pci/Makefile | 2 +
arch/mips/pci/fixup-lantiq-pcie.c | 82 +++
arch/mips/pci/fixup-lantiq.c | 5 +-
arch/mips/pci/ifxmips_pci_common.h | 57 ++
arch/mips/pci/ifxmips_pcie.c | 1099 ++++++++++++++++++++++++++++++
arch/mips/pci/ifxmips_pcie.h | 135 ++++
arch/mips/pci/ifxmips_pcie_ar10.h | 290 ++++++++
arch/mips/pci/ifxmips_pcie_msi.c | 392 +++++++++++
arch/mips/pci/ifxmips_pcie_phy.c | 478 +++++++++++++
arch/mips/pci/ifxmips_pcie_pm.c | 176 +++++
arch/mips/pci/ifxmips_pcie_pm.h | 36 +
arch/mips/pci/ifxmips_pcie_reg.h | 1001 +++++++++++++++++++++++++++
arch/mips/pci/ifxmips_pcie_vr9.h | 271 ++++++++
arch/mips/pci/pci.c | 25 +
arch/mips/pci/pcie-lantiq.h | 1305 ++++++++++++++++++++++++++++++++++++
drivers/pci/pcie/aer/Kconfig | 2 +-
include/linux/pci.h | 2 +
include/linux/pci_ids.h | 6 +
20 files changed, 5374 insertions(+), 2 deletions(-)
create mode 100644 arch/mips/pci/fixup-lantiq-pcie.c
create mode 100644 arch/mips/pci/ifxmips_pci_common.h
create mode 100644 arch/mips/pci/ifxmips_pcie.c
create mode 100644 arch/mips/pci/ifxmips_pcie.h
create mode 100644 arch/mips/pci/ifxmips_pcie_ar10.h
create mode 100644 arch/mips/pci/ifxmips_pcie_msi.c
create mode 100644 arch/mips/pci/ifxmips_pcie_phy.c
create mode 100644 arch/mips/pci/ifxmips_pcie_pm.c
create mode 100644 arch/mips/pci/ifxmips_pcie_pm.h
create mode 100644 arch/mips/pci/ifxmips_pcie_reg.h
create mode 100644 arch/mips/pci/ifxmips_pcie_vr9.h
create mode 100644 arch/mips/pci/pcie-lantiq.h
--- a/arch/mips/lantiq/Kconfig
+++ b/arch/mips/lantiq/Kconfig
@@ -20,6 +20,7 @@ config SOC_XWAY
bool "XWAY"
select SOC_TYPE_XWAY
select HAVE_PCI
+ select ARCH_SUPPORTS_MSI
select MFD_SYSCON
select MFD_CORE
@@ -52,4 +53,13 @@ config PCI_LANTIQ
bool "PCI Support"
depends on SOC_XWAY && PCI
+config PCIE_LANTIQ
+ bool "PCIE Support"
+ depends on SOC_XWAY && PCI
+
+config PCIE_LANTIQ_MSI
+ bool
+ depends on PCIE_LANTIQ && PCI_MSI
+ default y
+
endif
--- a/arch/mips/pci/Makefile
+++ b/arch/mips/pci/Makefile
@@ -51,6 +51,8 @@ obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o
obj-$(CONFIG_SOC_MT7620) += pci-mt7620.o
obj-$(CONFIG_SOC_RT288X) += pci-rt2880.o
obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
+obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
+obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
--- /dev/null
+++ b/arch/mips/pci/fixup-lantiq-pcie.c
@@ -0,0 +1,74 @@
+/******************************************************************************
+**
+** FILE NAME : ifxmips_fixup_pcie.c
+** PROJECT : IFX UEIP for VRX200
+** MODULES : PCIe
+**
+** DATE : 02 Mar 2009
+** AUTHOR : Lei Chuanhua
+** DESCRIPTION : PCIe Root Complex Driver
+** COPYRIGHT : Copyright (c) 2009
+** Infineon Technologies AG
+** Am Campeon 1-12, 85579 Neubiberg, Germany
+**
+** 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.
+** HISTORY
+** $Version $Date $Author $Comment
+** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
+*******************************************************************************/
+/*!
+ \file ifxmips_fixup_pcie.c
+ \ingroup IFX_PCIE
+ \brief PCIe Fixup functions source file
+*/
+#include <linux/pci.h>
+#include <linux/pci_regs.h>
+#include <linux/pci_ids.h>
+
+#include <lantiq_soc.h>
+
+#include "pcie-lantiq.h"
+
+static void
+ifx_pcie_fixup_resource(struct pci_dev *dev)
+{
+ u32 reg;
+
+ IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
+
+ printk("%s: fixup host controller %s (%04x:%04x)\n",
+ __func__, pci_name(dev), dev->vendor, dev->device);
+
+ /* Setup COMMAND register */
+ reg = PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER /* |
+ PCI_COMMAND_INTX_DISABLE */| PCI_COMMAND_SERR;
+ pci_write_config_word(dev, PCI_COMMAND, reg);
+ IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE, ifx_pcie_fixup_resource);
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_VENDOR_ID_LANTIQ, ifx_pcie_fixup_resource);
+
+static void
+ifx_pcie_rc_class_early_fixup(struct pci_dev *dev)
+{
+ IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
+
+ if (dev->devfn == PCI_DEVFN(0, 0) &&
+ (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) {
+
+ dev->class = (PCI_CLASS_BRIDGE_PCI << 8) | (dev->class & 0xff);
+
+ printk(KERN_INFO "%s: fixed pcie host bridge to pci-pci bridge\n", __func__);
+ }
+ IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
+ mdelay(10);
+}
+
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE,
+ ifx_pcie_rc_class_early_fixup);
+
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_DEVICE_ID_LANTIQ_PCIE,
+ ifx_pcie_rc_class_early_fixup);
--- a/arch/mips/pci/fixup-lantiq.c
+++ b/arch/mips/pci/fixup-lantiq.c
@@ -6,12 +6,18 @@
#include <linux/of_irq.h>
#include <linux/of_pci.h>
+#include "ifxmips_pci_common.h"
int (*ltq_pci_plat_arch_init)(struct pci_dev *dev) = NULL;
int (*ltq_pci_plat_dev_init)(struct pci_dev *dev) = NULL;
int pcibios_plat_dev_init(struct pci_dev *dev)
{
+#ifdef CONFIG_PCIE_LANTIQ
+ if (pci_find_capability(dev, PCI_CAP_ID_EXP))
+ ifx_pcie_bios_plat_dev_init(dev);
+#endif
+
if (ltq_pci_plat_arch_init)
return ltq_pci_plat_arch_init(dev);
@@ -23,5 +29,10 @@ int pcibios_plat_dev_init(struct pci_dev
int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
{
+#ifdef CONFIG_PCIE_LANTIQ
+ if (pci_find_capability(dev, PCI_CAP_ID_EXP))
+ return ifx_pcie_bios_map_irq(dev, slot, pin);
+#endif
+
return of_irq_parse_and_map_pci(dev, slot, pin);
}
--- /dev/null
+++ b/arch/mips/pci/ifxmips_pci_common.h
@@ -0,0 +1,53 @@
+/******************************************************************************
+**
+** FILE NAME : ifxmips_pci_common.h
+** PROJECT : IFX UEIP
+** MODULES : PCI subsystem
+**
+** DATE : 30 June 2009
+** AUTHOR : Lei Chuanhua
+** DESCRIPTION : PCIe Root Complex Driver
+** COPYRIGHT : Copyright (c) 2009
+** Infineon Technologies AG
+** Am Campeon 1-12, 85579 Neubiberg, Germany
+**
+** 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.
+** HISTORY
+** $Version $Date $Author $Comment
+** 0.0.1 30 June,2009 Lei Chuanhua Initial version
+*******************************************************************************/
+
+#ifndef IFXMIPS_PCI_COMMON_H
+#define IFXMIPS_PCI_COMMON_H
+#include <linux/version.h>
+/*!
+ \defgroup IFX_PCI_COM IFX PCI/PCIe common parts for OS integration
+ \brief PCI/PCIe common parts
+*/
+
+/*!
+ \defgroup IFX_PCI_COM_OS OS APIs
+ \ingroup IFX_PCI_COM
+ \brief PCI/PCIe bus driver OS interface functions
+*/
+/*!
+ \file ifxmips_pci_common.h
+ \ingroup IFX_PCI_COM
+ \brief PCI/PCIe bus driver common OS header file
+*/
+#define IFX_PCI_CONST const
+#ifdef CONFIG_IFX_PCI
+extern int ifx_pci_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin);
+extern int ifx_pci_bios_plat_dev_init(struct pci_dev *dev);
+#endif /* COFNIG_IFX_PCI */
+
+#ifdef CONFIG_PCIE_LANTIQ
+extern int ifx_pcie_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin);
+extern int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev);
+#endif
+
+#endif /* IFXMIPS_PCI_COMMON_H */
+
--- /dev/null
+++ b/arch/mips/pci/ifxmips_pcie.c
@@ -0,0 +1,1092 @@
+/*
+ * 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.
+ *
+ * Copyright (C) 2009 Lei Chuanhua <chuanhua.lei@infineon.com>
+ * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ */
+
+#include <linux/types.h>
+#include <linux/pci.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/mm.h>
+#include <asm/paccess.h>
+#include <linux/pci.h>
+#include <linux/pci_regs.h>
+#include <linux/module.h>
+
+#include "ifxmips_pcie.h"
+#include "ifxmips_pcie_reg.h"
+
+/* Enable 32bit io due to its mem mapped io nature */
+#define IFX_PCIE_ERROR_INT
+#define IFX_PCIE_IO_32BIT
+
+#define IFX_PCIE_IR (INT_NUM_IM4_IRL0 + 25)
+#define IFX_PCIE_INTA (INT_NUM_IM4_IRL0 + 8)
+#define IFX_PCIE_INTB (INT_NUM_IM4_IRL0 + 9)
+#define IFX_PCIE_INTC (INT_NUM_IM4_IRL0 + 10)
+#define IFX_PCIE_INTD (INT_NUM_IM4_IRL0 + 11)
+#define MS(_v, _f) (((_v) & (_f)) >> _f##_S)
+#define SM(_v, _f) (((_v) << _f##_S) & (_f))
+#define IFX_REG_SET_BIT(_f, _r) \
+ IFX_REG_W32((IFX_REG_R32((_r)) &~ (_f)) | (_f), (_r))
+
+#define IFX_PCIE_LTSSM_ENABLE_TIMEOUT 10
+
+static DEFINE_SPINLOCK(ifx_pcie_lock);
+
+u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
+
+static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
+ {
+ .ir_irq = {
+ .irq = IFX_PCIE_IR,
+ .name = "ifx_pcie_rc0",
+ },
+
+ .legacy_irq = {
+ {
+ .irq_bit = PCIE_IRN_INTA,
+ .irq = IFX_PCIE_INTA,
+ },
+ {
+ .irq_bit = PCIE_IRN_INTB,
+ .irq = IFX_PCIE_INTB,
+ },
+ {
+ .irq_bit = PCIE_IRN_INTC,
+ .irq = IFX_PCIE_INTC,
+ },
+ {
+ .irq_bit = PCIE_IRN_INTD,
+ .irq = IFX_PCIE_INTD,
+ },
+ },
+ },
+
+};
+
+void ifx_pcie_debug(const char *fmt, ...)
+{
+ static char buf[256] = {0}; /* XXX */
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
+ printk("%s", buf);
+}
+
+
+static inline int pcie_ltssm_enable(int pcie_port)
+{
+ int i;
+
+ /* Enable LTSSM */
+ IFX_REG_W32(PCIE_RC_CCR_LTSSM_ENABLE, PCIE_RC_CCR(pcie_port));
+
+ /* Wait for the link to come up */
+ for (i = 0; i < IFX_PCIE_LTSSM_ENABLE_TIMEOUT; i++) {
+ if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_RETRAIN_PENDING))
+ return 0;
+ udelay(10);
+ }
+
+ printk("%s link timeout!!!!!\n", __func__);
+ return -1;
+}
+
+static inline void pcie_status_register_clear(int pcie_port)
+{
+ IFX_REG_W32(0, PCIE_RC_DR(pcie_port));
+ IFX_REG_W32(0, PCIE_PCICMDSTS(pcie_port));
+ IFX_REG_W32(0, PCIE_DCTLSTS(pcie_port));
+ IFX_REG_W32(0, PCIE_LCTLSTS(pcie_port));
+ IFX_REG_W32(0, PCIE_SLCTLSTS(pcie_port));
+ IFX_REG_W32(0, PCIE_RSTS(pcie_port));
+ IFX_REG_W32(0, PCIE_UES_R(pcie_port));
+ IFX_REG_W32(0, PCIE_UEMR(pcie_port));
+ IFX_REG_W32(0, PCIE_UESR(pcie_port));
+ IFX_REG_W32(0, PCIE_CESR(pcie_port));
+ IFX_REG_W32(0, PCIE_CEMR(pcie_port));
+ IFX_REG_W32(0, PCIE_RESR(pcie_port));
+ IFX_REG_W32(0, PCIE_PVCCRSR(pcie_port));
+ IFX_REG_W32(0, PCIE_VC0_RSR0(pcie_port));
+ IFX_REG_W32(0, PCIE_TPFCS(pcie_port));
+ IFX_REG_W32(0, PCIE_TNPFCS(pcie_port));
+ IFX_REG_W32(0, PCIE_TCFCS(pcie_port));
+ IFX_REG_W32(0, PCIE_QSR(pcie_port));
+ IFX_REG_W32(0, PCIE_IOBLSECS(pcie_port));
+}
+
+static inline int ifx_pcie_link_up(int pcie_port)
+{
+ return (IFX_REG_R32(PCIE_PHY_SR(pcie_port)) & PCIE_PHY_SR_PHY_LINK_UP) ? 1 : 0;
+}
+
+
+static inline void pcie_mem_io_setup(int pcie_port)
+{
+ u32 reg;
+ /*
+ * BAR[0:1] readonly register
+ * RC contains only minimal BARs for packets mapped to this device
+ * Mem/IO filters defines a range of memory occupied by memory mapped IO devices that
+ * reside on the downstream side fo the bridge.
+ */
+ reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_MBML_MEM_LIMIT_ADDR)
+ | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_MBML_MEM_BASE_ADDR);
+
+ IFX_REG_W32(reg, PCIE_MBML(pcie_port));
+
+
+#ifdef IFX_PCIE_PREFETCH_MEM_64BIT
+ reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_PMBL_END_ADDR)
+ | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_PMBL_UPPER_12BIT)
+ | PCIE_PMBL_64BIT_ADDR;
+ IFX_REG_W32(reg, PCIE_PMBL(pcie_port));
+
+ /* Must configure upper 32bit */
+ IFX_REG_W32(0, PCIE_PMBU32(pcie_port));
+ IFX_REG_W32(0, PCIE_PMLU32(pcie_port));
+#else
+ /* PCIe_PBML, same as MBML */
+ IFX_REG_W32(IFX_REG_R32(PCIE_MBML(pcie_port)), PCIE_PMBL(pcie_port));
+#endif
+
+ /* IO Address Range */
+ reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 12), PCIE_IOBLSECS_IO_LIMIT_ADDR)
+ | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 12), PCIE_IOBLSECS_IO_BASE_ADDR);
+#ifdef IFX_PCIE_IO_32BIT
+ reg |= PCIE_IOBLSECS_32BIT_IO_ADDR;
+#endif /* IFX_PCIE_IO_32BIT */
+ IFX_REG_W32(reg, PCIE_IOBLSECS(pcie_port));
+
+#ifdef IFX_PCIE_IO_32BIT
+ reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT)
+ | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_BASE);
+ IFX_REG_W32(reg, PCIE_IO_BANDL(pcie_port));
+
+#endif /* IFX_PCIE_IO_32BIT */
+}
+
+static inline void
+pcie_device_setup(int pcie_port)
+{
+ u32 reg;
+
+ /* Device capability register, set up Maximum payload size */
+ reg = IFX_REG_R32(PCIE_DCAP(pcie_port));
+ reg |= PCIE_DCAP_ROLE_BASE_ERR_REPORT;
+ reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCAP_MAX_PAYLOAD_SIZE);
+
+ /* Only available for EP */
+ reg &= ~(PCIE_DCAP_EP_L0S_LATENCY | PCIE_DCAP_EP_L1_LATENCY);
+ IFX_REG_W32(reg, PCIE_DCAP(pcie_port));
+
+ /* Device control and status register */
+ /* Set Maximum Read Request size for the device as a Requestor */
+ reg = IFX_REG_R32(PCIE_DCTLSTS(pcie_port));
+
+ /*
+ * Request size can be larger than the MPS used, but the completions returned
+ * for the read will be bounded by the MPS size.
+ * In our system, Max request size depends on AHB burst size. It is 64 bytes.
+ * but we set it as 128 as minimum one.
+ */
+ reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_READ_SIZE)
+ | SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_PAYLOAD_SIZE);
+
+ /* Enable relaxed ordering, no snoop, and all kinds of errors */
+ reg |= PCIE_DCTLSTS_RELAXED_ORDERING_EN | PCIE_DCTLSTS_ERR_EN | PCIE_DCTLSTS_NO_SNOOP_EN;
+
+ IFX_REG_W32(reg, PCIE_DCTLSTS(pcie_port));
+}
+
+static inline void
+pcie_link_setup(int pcie_port)
+{
+ u32 reg;
+
+ /*
+ * XXX, Link capability register, bit 18 for EP CLKREQ# dynamic clock management for L1, L2/3 CPM
+ * L0s is reported during link training via TS1 order set by N_FTS
+ */
+ reg = IFX_REG_R32(PCIE_LCAP(pcie_port));
+ reg &= ~PCIE_LCAP_L0S_EIXT_LATENCY;
+ reg |= SM(3, PCIE_LCAP_L0S_EIXT_LATENCY);
+ IFX_REG_W32(reg, PCIE_LCAP(pcie_port));
+
+ /* Link control and status register */
+ reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
+
+ /* Link Enable, ASPM enabled */
+ reg &= ~PCIE_LCTLSTS_LINK_DISABLE;
+
+#ifdef CONFIG_PCIEASPM
+ /*
+ * We use the same physical reference clock that the platform provides on the connector
+ * It paved the way for ASPM to calculate the new exit Latency
+ */
+ reg |= PCIE_LCTLSTS_SLOT_CLK_CFG;
+ reg |= PCIE_LCTLSTS_COM_CLK_CFG;
+ /*
+ * We should disable ASPM by default except that we have dedicated power management support
+ * Enable ASPM will cause the system hangup/instability, performance degration
+ */
+ reg |= PCIE_LCTLSTS_ASPM_ENABLE;
+#else
+ reg &= ~PCIE_LCTLSTS_ASPM_ENABLE;
+#endif /* CONFIG_PCIEASPM */
+
+ /*
+ * The maximum size of any completion with data packet is bounded by the MPS setting
+ * in device control register
+ */
+
+ /* RCB may cause multiple split transactions, two options available, we use 64 byte RCB */
+ reg &= ~ PCIE_LCTLSTS_RCB128;
+
+ IFX_REG_W32(reg, PCIE_LCTLSTS(pcie_port));
+}
+
+static inline void pcie_error_setup(int pcie_port)
+{
+ u32 reg;
+
+ /*
+ * Forward ERR_COR, ERR_NONFATAL, ERR_FATAL to the backbone
+ * Poisoned write TLPs and completions indicating poisoned TLPs will set the PCIe_PCICMDSTS.MDPE
+ */
+ reg = IFX_REG_R32(PCIE_INTRBCTRL(pcie_port));
+ reg |= PCIE_INTRBCTRL_SERR_ENABLE | PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE;
+
+ IFX_REG_W32(reg, PCIE_INTRBCTRL(pcie_port));
+
+ /* Uncorrectable Error Mask Register, Unmask <enable> all bits in PCIE_UESR */
+ reg = IFX_REG_R32(PCIE_UEMR(pcie_port));
+ reg &= ~PCIE_ALL_UNCORRECTABLE_ERR;
+ IFX_REG_W32(reg, PCIE_UEMR(pcie_port));
+
+ /* Uncorrectable Error Severity Register, ALL errors are FATAL */
+ IFX_REG_W32(PCIE_ALL_UNCORRECTABLE_ERR, PCIE_UESR(pcie_port));
+
+ /* Correctable Error Mask Register, unmask <enable> all bits */
+ reg = IFX_REG_R32(PCIE_CEMR(pcie_port));
+ reg &= ~PCIE_CORRECTABLE_ERR;
+ IFX_REG_W32(reg, PCIE_CEMR(pcie_port));
+
+ /* Advanced Error Capabilities and Control Registr */
+ reg = IFX_REG_R32(PCIE_AECCR(pcie_port));
+ reg |= PCIE_AECCR_ECRC_CHECK_EN | PCIE_AECCR_ECRC_GEN_EN;
+ IFX_REG_W32(reg, PCIE_AECCR(pcie_port));
+
+ /* Root Error Command Register, Report all types of errors */
+ reg = IFX_REG_R32(PCIE_RECR(pcie_port));
+ reg |= PCIE_RECR_ERR_REPORT_EN;
+ IFX_REG_W32(reg, PCIE_RECR(pcie_port));
+
+ /* Clear the Root status register */
+ reg = IFX_REG_R32(PCIE_RESR(pcie_port));
+ IFX_REG_W32(reg, PCIE_RESR(pcie_port));
+}
+
+static inline void pcie_port_logic_setup(int pcie_port)
+{
+ u32 reg;
+
+ /* FTS number, default 12, increase to 63, may increase time from/to L0s to L0 */
+ reg = IFX_REG_R32(PCIE_AFR(pcie_port));
+ reg &= ~(PCIE_AFR_FTS_NUM | PCIE_AFR_COM_FTS_NUM);
+ reg |= SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_FTS_NUM)
+ | SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_COM_FTS_NUM);
+ /* L0s and L1 entry latency */
+ reg &= ~(PCIE_AFR_L0S_ENTRY_LATENCY | PCIE_AFR_L1_ENTRY_LATENCY);
+ reg |= SM(PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L0S_ENTRY_LATENCY)
+ | SM(PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L1_ENTRY_LATENCY);
+ IFX_REG_W32(reg, PCIE_AFR(pcie_port));
+
+
+ /* Port Link Control Register */
+ reg = IFX_REG_R32(PCIE_PLCR(pcie_port));
+ reg |= PCIE_PLCR_DLL_LINK_EN; /* Enable the DLL link */
+ IFX_REG_W32(reg, PCIE_PLCR(pcie_port));
+
+ /* Lane Skew Register */
+ reg = IFX_REG_R32(PCIE_LSR(pcie_port));
+ /* Enable ACK/NACK and FC */
+ reg &= ~(PCIE_LSR_ACKNAK_DISABLE | PCIE_LSR_FC_DISABLE);
+ IFX_REG_W32(reg, PCIE_LSR(pcie_port));
+
+ /* Symbol Timer Register and Filter Mask Register 1 */
+ reg = IFX_REG_R32(PCIE_STRFMR(pcie_port));
+
+ /* Default SKP interval is very accurate already, 5us */
+ /* Enable IO/CFG transaction */
+ reg |= PCIE_STRFMR_RX_CFG_TRANS_ENABLE | PCIE_STRFMR_RX_IO_TRANS_ENABLE;
+ /* Disable FC WDT */
+ reg &= ~PCIE_STRFMR_FC_WDT_DISABLE;
+ IFX_REG_W32(reg, PCIE_STRFMR(pcie_port));
+
+ /* Filter Masker Register 2 */
+ reg = IFX_REG_R32(PCIE_FMR2(pcie_port));
+ reg |= PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 | PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1;
+ IFX_REG_W32(reg, PCIE_FMR2(pcie_port));
+
+ /* VC0 Completion Receive Queue Control Register */
+ reg = IFX_REG_R32(PCIE_VC0_CRQCR(pcie_port));
+ reg &= ~PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE;
+ reg |= SM(PCIE_VC0_TLP_QUEUE_MODE_BYPASS, PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE);
+ IFX_REG_W32(reg, PCIE_VC0_CRQCR(pcie_port));
+}
+
+static inline void pcie_rc_cfg_reg_setup(int pcie_port)
+{
+ u32 reg;
+
+ /* Disable LTSSM */
+ IFX_REG_W32(0, PCIE_RC_CCR(pcie_port)); /* Disable LTSSM */
+
+ pcie_mem_io_setup(pcie_port);
+
+ /* XXX, MSI stuff should only apply to EP */
+ /* MSI Capability: Only enable 32-bit addresses */
+ reg = IFX_REG_R32(PCIE_MCAPR(pcie_port));
+ reg &= ~PCIE_MCAPR_ADDR64_CAP;
+
+ reg |= PCIE_MCAPR_MSI_ENABLE;
+
+ /* Disable multiple message */
+ reg &= ~(PCIE_MCAPR_MULTI_MSG_CAP | PCIE_MCAPR_MULTI_MSG_ENABLE);
+ IFX_REG_W32(reg, PCIE_MCAPR(pcie_port));
+
+
+ /* Enable PME, Soft reset enabled */
+ reg = IFX_REG_R32(PCIE_PM_CSR(pcie_port));
+ reg |= PCIE_PM_CSR_PME_ENABLE | PCIE_PM_CSR_SW_RST;
+ IFX_REG_W32(reg, PCIE_PM_CSR(pcie_port));
+
+ /* setup the bus */
+ reg = SM(0, PCIE_BNR_PRIMARY_BUS_NUM) | SM(1, PCIE_PNR_SECONDARY_BUS_NUM) | SM(0xFF, PCIE_PNR_SUB_BUS_NUM);
+ IFX_REG_W32(reg, PCIE_BNR(pcie_port));
+
+
+ pcie_device_setup(pcie_port);
+ pcie_link_setup(pcie_port);
+ pcie_error_setup(pcie_port);
+
+ /* Root control and capabilities register */
+ reg = IFX_REG_R32(PCIE_RCTLCAP(pcie_port));
+ reg |= PCIE_RCTLCAP_SERR_ENABLE | PCIE_RCTLCAP_PME_INT_EN;
+ IFX_REG_W32(reg, PCIE_RCTLCAP(pcie_port));
+
+ /* Port VC Capability Register 2 */
+ reg = IFX_REG_R32(PCIE_PVC2(pcie_port));
+ reg &= ~PCIE_PVC2_VC_ARB_WRR;
+ reg |= PCIE_PVC2_VC_ARB_16P_FIXED_WRR;
+ IFX_REG_W32(reg, PCIE_PVC2(pcie_port));
+
+ /* VC0 Resource Capability Register */
+ reg = IFX_REG_R32(PCIE_VC0_RC(pcie_port));
+ reg &= ~PCIE_VC0_RC_REJECT_SNOOP;
+ IFX_REG_W32(reg, PCIE_VC0_RC(pcie_port));
+
+ pcie_port_logic_setup(pcie_port);
+}
+
+static int ifx_pcie_wait_phy_link_up(int pcie_port)
+{
+#define IFX_PCIE_PHY_LINK_UP_TIMEOUT 1000 /* XXX, tunable */
+ int i;
+
+ /* Wait for PHY link is up */
+ for (i = 0; i < IFX_PCIE_PHY_LINK_UP_TIMEOUT; i++) {
+ if (ifx_pcie_link_up(pcie_port)) {
+ break;
+ }
+ udelay(100);
+ }
+ if (i >= IFX_PCIE_PHY_LINK_UP_TIMEOUT) {
+ printk(KERN_ERR "%s timeout\n", __func__);
+ return -1;
+ }
+
+ /* Check data link up or not */
+ if (!(IFX_REG_R32(PCIE_RC_DR(pcie_port)) & PCIE_RC_DR_DLL_UP)) {
+ printk(KERN_ERR "%s DLL link is still down\n", __func__);
+ return -1;
+ }
+
+ /* Check Data link active or not */
+ if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_DLL_ACTIVE)) {
+ printk(KERN_ERR "%s DLL is not active\n", __func__);
+ return -1;
+ }
+ return 0;
+}
+
+static inline int pcie_app_loigc_setup(int pcie_port)
+{
+ /* supress ahb bus errrors */
+ IFX_REG_W32(PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS, PCIE_AHB_CTRL(pcie_port));
+
+ /* Pull PCIe EP out of reset */
+ pcie_device_rst_deassert(pcie_port);
+
+ /* Start LTSSM training between RC and EP */
+ pcie_ltssm_enable(pcie_port);
+
+ /* Check PHY status after enabling LTSSM */
+ if (ifx_pcie_wait_phy_link_up(pcie_port) != 0)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * The numbers below are directly from the PCIe spec table 3-4/5.
+ */
+static inline void pcie_replay_time_update(int pcie_port)
+{
+ u32 reg;
+ int nlw;
+ int rtl;
+
+ reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
+
+ nlw = MS(reg, PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH);
+ switch (nlw) {
+ case PCIE_MAX_LENGTH_WIDTH_X1:
+ rtl = 1677;
+ break;
+ case PCIE_MAX_LENGTH_WIDTH_X2:
+ rtl = 867;
+ break;
+ case PCIE_MAX_LENGTH_WIDTH_X4:
+ rtl = 462;
+ break;
+ case PCIE_MAX_LENGTH_WIDTH_X8:
+ rtl = 258;
+ break;
+ default:
+ rtl = 1677;
+ break;
+ }
+ reg = IFX_REG_R32(PCIE_ALTRT(pcie_port));
+ reg &= ~PCIE_ALTRT_REPLAY_TIME_LIMIT;
+ reg |= SM(rtl, PCIE_ALTRT_REPLAY_TIME_LIMIT);
+ IFX_REG_W32(reg, PCIE_ALTRT(pcie_port));
+}
+
+/*
+ * Table 359 Enhanced Configuration Address Mapping1)
+ * 1) This table is defined in Table 7-1, page 341, PCI Express Base Specification v1.1
+ * Memory Address PCI Express Configuration Space
+ * A[(20+n-1):20] Bus Number 1 < n < 8
+ * A[19:15] Device Number
+ * A[14:12] Function Number
+ * A[11:8] Extended Register Number
+ * A[7:2] Register Number
+ * A[1:0] Along with size of the access, used to generate Byte Enables
+ * For VR9, only the address bits [22:0] are mapped to the configuration space:
+ * . Address bits [22:20] select the target bus (1-of-8)1)
+ * . Address bits [19:15] select the target device (1-of-32) on the bus
+ * . Address bits [14:12] select the target function (1-of-8) within the device.
+ * . Address bits [11:2] selects the target dword (1-of-1024) within the selected function.s configuration space
+ * . Address bits [1:0] define the start byte location within the selected dword.
+ */
+static inline u32 pcie_bus_addr(u8 bus_num, u16 devfn, int where)
+{
+ u32 addr;
+ u8 bus;
+
+ if (!bus_num) {
+ /* type 0 */
+ addr = ((PCI_SLOT(devfn) & 0x1F) << 15) | ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF)& ~3);
+ } else {
+ bus = bus_num;
+ /* type 1, only support 8 buses */
+ addr = ((bus & 0x7) << 20) | ((PCI_SLOT(devfn) & 0x1F) << 15) |
+ ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF) & ~3);
+ }
+ return addr;
+}
+
+static int pcie_valid_config(int pcie_port, int bus, int dev)
+{
+ /* RC itself */
+ if ((bus == 0) && (dev == 0)) {
+ return 1;
+ }
+
+ /* No physical link */
+ if (!ifx_pcie_link_up(pcie_port)) {
+ return 0;
+ }
+
+ /* Bus zero only has RC itself
+ * XXX, check if EP will be integrated
+ */
+ if ((bus == 0) && (dev != 0)) {
+ return 0;
+ }
+
+ /* Maximum 8 buses supported for VRX */
+ if (bus > 9) {
+ return 0;
+ }
+
+ /*
+ * PCIe is PtP link, one bus only supports only one device
+ * except bus zero and PCIe switch which is virtual bus device
+ * The following two conditions really depends on the system design
+ * and attached the device.
+ * XXX, how about more new switch
+ */
+ if ((bus == 1) && (dev != 0)) {
+ return 0;
+ }
+
+ if ((bus >= 3) && (dev != 0)) {
+ return 0;
+ }
+ return 1;
+}
+
+static inline u32 ifx_pcie_cfg_rd(int pcie_port, u32 reg)
+{
+ return IFX_REG_R32((volatile u32 *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
+}
+
+static inline void ifx_pcie_cfg_wr(int pcie_port, unsigned int reg, u32 val)
+{
+ IFX_REG_W32( val, (volatile u32 *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
+}
+
+static inline u32 ifx_pcie_rc_cfg_rd(int pcie_port, u32 reg)
+{
+ return IFX_REG_R32((volatile u32 *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
+}
+
+static inline void ifx_pcie_rc_cfg_wr(int pcie_port, unsigned int reg, u32 val)
+{
+ IFX_REG_W32(val, (volatile u32 *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
+}
+
+u32 ifx_pcie_bus_enum_read_hack(int where, u32 value)
+{
+ u32 tvalue = value;
+
+ if (where == PCI_PRIMARY_BUS) {
+ u8 primary, secondary, subordinate;
+
+ primary = tvalue & 0xFF;
+ secondary = (tvalue >> 8) & 0xFF;
+ subordinate = (tvalue >> 16) & 0xFF;
+ primary += pcibios_1st_host_bus_nr();
+ secondary += pcibios_1st_host_bus_nr();
+ subordinate += pcibios_1st_host_bus_nr();
+ tvalue = (tvalue & 0xFF000000) | (u32)primary | (u32)(secondary << 8) | (u32)(subordinate << 16);
+ }
+ return tvalue;
+}
+
+u32 ifx_pcie_bus_enum_write_hack(int where, u32 value)
+{
+ u32 tvalue = value;
+
+ if (where == PCI_PRIMARY_BUS) {
+ u8 primary, secondary, subordinate;
+
+ primary = tvalue & 0xFF;
+ secondary = (tvalue >> 8) & 0xFF;
+ subordinate = (tvalue >> 16) & 0xFF;
+ if (primary > 0 && primary != 0xFF) {
+ primary -= pcibios_1st_host_bus_nr();
+ }
+
+ if (secondary > 0 && secondary != 0xFF) {
+ secondary -= pcibios_1st_host_bus_nr();
+ }
+ if (subordinate > 0 && subordinate != 0xFF) {
+ subordinate -= pcibios_1st_host_bus_nr();
+ }
+ tvalue = (tvalue & 0xFF000000) | (u32)primary | (u32)(secondary << 8) | (u32)(subordinate << 16);
+ }
+ else if (where == PCI_SUBORDINATE_BUS) {
+ u8 subordinate = tvalue & 0xFF;
+
+ subordinate = subordinate > 0 ? subordinate - pcibios_1st_host_bus_nr() : 0;
+ tvalue = subordinate;
+ }
+ return tvalue;
+}
+
+static int ifx_pcie_read_config(struct pci_bus *bus, u32 devfn,
+ int where, int size, u32 *value)
+{
+ u32 data = 0;
+ int bus_number = bus->number;
+ static const u32 mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
+ int ret = PCIBIOS_SUCCESSFUL;
+ struct ifx_pci_controller *ctrl = bus->sysdata;
+ int pcie_port = ctrl->port;
+
+ if (unlikely(size != 1 && size != 2 && size != 4)){
+ ret = PCIBIOS_BAD_REGISTER_NUMBER;
+ goto out;
+ }
+
+ /* Make sure the address is aligned to natural boundary */
+ if (unlikely(((size - 1) & where))) {
+ ret = PCIBIOS_BAD_REGISTER_NUMBER;
+ goto out;
+ }
+
+ /*
+ * If we are second controller, we have to cheat OS so that it assume
+ * its bus number starts from 0 in host controller
+ */
+ bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
+
+ /*
+ * We need to force the bus number to be zero on the root
+ * bus. Linux numbers the 2nd root bus to start after all
+ * busses on root 0.
+ */
+ if (bus->parent == NULL) {
+ bus_number = 0;
+ }
+
+ /*
+ * PCIe only has a single device connected to it. It is
+ * always device ID 0. Don't bother doing reads for other
+ * device IDs on the first segment.
+ */
+ if ((bus_number == 0) && (PCI_SLOT(devfn) != 0)) {
+ ret = PCIBIOS_FUNC_NOT_SUPPORTED;
+ goto out;
+ }
+
+ if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
+ *value = 0xffffffff;
+ ret = PCIBIOS_DEVICE_NOT_FOUND;
+ goto out;
+ }
+
+ PCIE_IRQ_LOCK(ifx_pcie_lock);
+ if (bus_number == 0) { /* RC itself */
+ u32 t;
+
+ t = (where & ~3);
+ data = ifx_pcie_rc_cfg_rd(pcie_port, t);
+ } else {
+ u32 addr = pcie_bus_addr(bus_number, devfn, where);
+
+ data = ifx_pcie_cfg_rd(pcie_port, addr);
+ #ifdef CONFIG_IFX_PCIE_HW_SWAP
+ data = le32_to_cpu(data);
+ #endif /* CONFIG_IFX_PCIE_HW_SWAP */
+ }
+ /* To get a correct PCI topology, we have to restore the bus number to OS */
+ data = ifx_pcie_bus_enum_hack(bus, devfn, where, data, pcie_port, 1);
+
+ PCIE_IRQ_UNLOCK(ifx_pcie_lock);
+
+ *value = (data >> (8 * (where & 3))) & mask[size & 7];
+out:
+ return ret;
+}
+
+static u32 ifx_pcie_size_to_value(int where, int size, u32 data, u32 value)
+{
+ u32 shift;
+ u32 tdata = data;
+
+ switch (size) {
+ case 1:
+ shift = (where & 0x3) << 3;
+ tdata &= ~(0xffU << shift);
+ tdata |= ((value & 0xffU) << shift);
+ break;
+ case 2:
+ shift = (where & 3) << 3;
+ tdata &= ~(0xffffU << shift);
+ tdata |= ((value & 0xffffU) << shift);
+ break;
+ case 4:
+ tdata = value;
+ break;
+ }
+ return tdata;
+}
+
+static int ifx_pcie_write_config(struct pci_bus *bus, u32 devfn,
+ int where, int size, u32 value)
+{
+ int bus_number = bus->number;
+ int ret = PCIBIOS_SUCCESSFUL;
+ struct ifx_pci_controller *ctrl = bus->sysdata;
+ int pcie_port = ctrl->port;
+ u32 tvalue = value;
+ u32 data;
+
+ /* Make sure the address is aligned to natural boundary */
+ if (unlikely(((size - 1) & where))) {
+ ret = PCIBIOS_BAD_REGISTER_NUMBER;
+ goto out;
+ }
+ /*
+ * If we are second controller, we have to cheat OS so that it assume
+ * its bus number starts from 0 in host controller
+ */
+ bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
+
+ /*
+ * We need to force the bus number to be zero on the root
+ * bus. Linux numbers the 2nd root bus to start after all
+ * busses on root 0.
+ */
+ if (bus->parent == NULL) {
+ bus_number = 0;