I just went on a bugfix frenzy and fixed all printk format warnings
[coreboot.git] / src / southbridge / amd / rs690 / rs690_gfx.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /*
21  *  for rs690 internal graphics device
22  *  device id of internal grphics:
23  *      RS690M/T: 0x791f
24  *    RS690:       0x791e
25  */
26 #include <console/console.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <device/pci_ops.h>
31 #include <delay.h>
32 #include "rs690.h"
33
34 #define CLK_CNTL_INDEX  0x8
35 #define CLK_CNTL_DATA   0xC
36
37 static u32 clkind_read(device_t dev, u32 index)
38 {
39         u32     gfx_bar2 = pci_read_config32(dev, 0x18) & ~0xF;
40
41         *(u32*)(gfx_bar2+CLK_CNTL_INDEX) = index & 0x7F;
42         return *(u32*)(gfx_bar2+CLK_CNTL_DATA);
43 }
44
45 static void clkind_write(device_t dev, u32 index, u32 data)
46 {
47         u32     gfx_bar2 = pci_read_config32(dev, 0x18) & ~0xF;
48         /* printk_info("gfx bar 2 %02x\n", gfx_bar2); */
49
50         *(u32*)(gfx_bar2+CLK_CNTL_INDEX) = index | 1<<7;
51         *(u32*)(gfx_bar2+CLK_CNTL_DATA)  = data;
52 }
53
54 /*
55 * pci_dev_read_resources thinks it is a IO type.
56 * We have to force it to mem type.
57 */
58 static void rs690_gfx_read_resources(device_t dev)
59 {
60         printk_info("rs690_gfx_read_resources.\n");
61
62         /* The initial value of 0x24 is 0xFFFFFFFF, which is confusing.
63            Even if we write 0xFFFFFFFF into it, it will be 0xFFF00000,
64            which tells us it is a memory address base.
65          */
66         pci_write_config32(dev, 0x24, 0x00000000);
67
68         /* Get the normal pci resources of this device */
69         pci_dev_read_resources(dev);
70         compact_resources(dev);
71 }
72
73 static void internal_gfx_pci_dev_init(struct device *dev)
74 {
75         u16 deviceid, vendorid;
76         struct southbridge_amd_rs690_config *cfg =
77             (struct southbridge_amd_rs690_config *)dev->chip_info;
78         deviceid = pci_read_config16(dev, PCI_DEVICE_ID);
79         vendorid = pci_read_config16(dev, PCI_VENDOR_ID);
80         printk_info("internal_gfx_pci_dev_init device=%x, vendor=%x, vga_rom_address=0x%x.\n",
81              deviceid, vendorid, cfg->vga_rom_address);
82
83 #if 0 /* I think these should be done in Config.lb. Please check it. */
84         dev->on_mainboard = 1;
85         dev->rom_address = cfg->vga_rom_address;        /* 0xfff00000; */
86 #endif
87         pci_dev_init(dev);
88
89         /* clk ind */
90         clkind_write(dev, 0x08, 0x01);
91         clkind_write(dev, 0x0C, 0x22);
92         clkind_write(dev, 0x0F, 0x0);
93         clkind_write(dev, 0x11, 0x0);
94         clkind_write(dev, 0x12, 0x0);
95         clkind_write(dev, 0x14, 0x0);
96         clkind_write(dev, 0x15, 0x0);
97         clkind_write(dev, 0x16, 0x0);
98         clkind_write(dev, 0x17, 0x0);
99         clkind_write(dev, 0x18, 0x0);
100         clkind_write(dev, 0x19, 0x0);
101         clkind_write(dev, 0x1A, 0x0);
102         clkind_write(dev, 0x1B, 0x0);
103         clkind_write(dev, 0x1C, 0x0);
104         clkind_write(dev, 0x1D, 0x0);
105         clkind_write(dev, 0x1E, 0x0);
106         clkind_write(dev, 0x26, 0x0);
107         clkind_write(dev, 0x27, 0x0);
108         clkind_write(dev, 0x28, 0x0);
109         clkind_write(dev, 0x5C, 0x0);
110 }
111
112
113 /*
114 * Set registers in RS690 and CPU to enable the internal GFX.
115 * Please refer to CIM source code and BKDG.
116 */
117 static void rs690_internal_gfx_enable(device_t dev)
118 {
119         u32 l_dword;
120         int i;
121         device_t k8_f0 = 0, k8_f2 = 0;
122         device_t nb_dev = dev_find_slot(0, 0);
123
124         printk_info("rs690_internal_gfx_enable dev=0x%p, nb_dev=0x%p.\n", dev,
125                     nb_dev);
126
127         /* set APERTURE_SIZE, 128M. */
128         l_dword = pci_read_config32(nb_dev, 0x8c);
129         printk_info("nb_dev, 0x8c=0x%x\n", l_dword);
130         l_dword &= 0xffffff8f;
131         pci_write_config32(nb_dev, 0x8c, l_dword);
132
133         /* set TOM */
134         rs690_set_tom(nb_dev);
135
136         /* LPC DMA Deadlock workaround? */
137         k8_f0 = dev_find_slot(0, PCI_DEVFN(0x18, 0));
138         l_dword = pci_read_config32(k8_f0, 0x68);
139         l_dword &= ~(1 << 22);
140         l_dword |= (1 << 21);
141         pci_write_config32(k8_f0, 0x68, l_dword);
142
143         /* Enable 64bit mode. */
144         set_nbmc_enable_bits(nb_dev, 0x5f, 0, 1 << 9);
145         set_nbmc_enable_bits(nb_dev, 0xb0, 0, 1 << 8);
146
147         /* 64bit Latency. */
148         set_nbmc_enable_bits(nb_dev, 0x5f, 0x7c00, 0x800);
149
150         /* UMA dual channel control register. */
151         nbmc_write_index(nb_dev, 0x86, 0x3d);
152
153         /* check the setting later!! */
154         set_htiu_enable_bits(nb_dev, 0x07, 1 << 7, 0);
155
156         /* UMA mode, powerdown memory PLL. */
157         set_nbmc_enable_bits(nb_dev, 0x74, 0, 1 << 31);
158
159         /* Copy CPU DDR Controller to NB MC. */
160         /* Why K8_MC_REG80 is special? */
161         k8_f2 = dev_find_slot(0, PCI_DEVFN(0x18, 2));
162         for (i = 0; i <= (0x80 - 0x40) / 4; i++) {
163                 l_dword = pci_read_config32(k8_f2, 0x40 + i * 4);
164                 nbmc_write_index(nb_dev, 0x63 + i, l_dword);
165         }
166
167         /* Set K8 MC for UMA, Family F. */
168         l_dword = pci_read_config32(k8_f2, 0xa0);
169         l_dword |= 0x2c;
170         pci_write_config32(k8_f2, 0xa0, l_dword);
171         l_dword = pci_read_config32(k8_f2, 0x94);
172         l_dword &= 0xf0ffffff;
173         l_dword |= 0x07000000;
174         pci_write_config32(k8_f2, 0x94, l_dword);
175
176         /* set FB size and location. */
177         nbmc_write_index(nb_dev, 0x1b, 0x00);
178         l_dword = nbmc_read_index(nb_dev, 0x1c);
179         l_dword &= 0xffff0;
180         l_dword |= 0x400 << 20;
181         l_dword |= 0x4;
182         nbmc_write_index(nb_dev, 0x1c, l_dword);
183         l_dword = nbmc_read_index(nb_dev, 0x1d);
184         l_dword &= 0xfffff000;
185         l_dword |= 0x0400;
186         nbmc_write_index(nb_dev, 0x1d, l_dword);
187         nbmc_write_index(nb_dev, 0x100, 0x3fff3800);
188
189         /* Program MC table. */
190         set_nbmc_enable_bits(nb_dev, 0x00, 0, 1 << 31);
191         l_dword = nbmc_read_index(nb_dev, 0x91);
192         l_dword |= 0x5;
193         nbmc_write_index(nb_dev, 0x91, l_dword);
194         set_nbmc_enable_bits(nb_dev, 0xb1, 0, 1 << 6);
195         set_nbmc_enable_bits(nb_dev, 0xc3, 0, 1);
196
197         /* TODO: the optimization of voltage and frequency */
198 }
199
200 static struct pci_operations lops_pci = {
201         .set_subsystem = pci_dev_set_subsystem,
202 };
203
204 static struct device_operations pcie_ops = {
205         .read_resources = rs690_gfx_read_resources,
206         .set_resources = pci_dev_set_resources,
207         .enable_resources = pci_dev_enable_resources,
208         .init = internal_gfx_pci_dev_init,      /* The option ROM initializes the device. rs690_gfx_init, */
209         .scan_bus = 0,
210         .enable = rs690_internal_gfx_enable,
211         .ops_pci = &lops_pci,
212 };
213
214 /*
215  * The dev id of 690G is 791E, while the id of 690M, 690T is 791F.
216  * We should list both of them here.
217  * */
218 static struct pci_driver pcie_driver_690t __pci_driver = {
219         .ops = &pcie_ops,
220         .vendor = PCI_VENDOR_ID_ATI,
221         .device = PCI_DEVICE_ID_ATI_RS690MT_INT_GFX,
222 };
223
224 static struct pci_driver pcie_driver_690 __pci_driver = {
225         .ops = &pcie_ops,
226         .vendor = PCI_VENDOR_ID_ATI,
227         .device = PCI_DEVICE_ID_ATI_RS690_INT_GFX,
228 };
229
230 /* step 12 ~ step 14 from rpr */
231 static void single_port_configuration(device_t nb_dev, device_t dev)
232 {
233         u8 result, width;
234         u32 reg32;
235         struct southbridge_amd_rs690_config *cfg =
236             (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
237
238         printk_info("rs690_gfx_init single_port_configuration.\n");
239
240         /* step 12 training, releases hold training for GFX port 0 (device 2) */
241         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 4, 0<<4);
242         PcieReleasePortTraining(nb_dev, dev, 2);
243         result = PcieTrainPort(nb_dev, dev, 2);
244         printk_info("rs690_gfx_init single_port_configuration step12.\n");
245
246         /* step 13 Power Down Control */
247         /* step 13.1 Enables powering down transmitter and receiver pads along with PLL macros. */
248         set_pcie_enable_bits(nb_dev, 0x40, 1 << 0, 1 << 0);
249
250         /* step 13.a Link Training was NOT successful */
251         if (!result) {
252                 set_nbmisc_enable_bits(nb_dev, 0x8, 0, 0x3 << 4); /* prevent from training. */
253                 set_nbmisc_enable_bits(nb_dev, 0xc, 0, 0x3 << 2); /* hide the GFX bridge. */
254                 if (cfg->gfx_tmds)
255                         nbpcie_ind_write_index(nb_dev, 0x65, 0xccf0f0);
256                 else {
257                         nbpcie_ind_write_index(nb_dev, 0x65, 0xffffffff);
258                         set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 3, 1 << 3);
259                 }
260         } else {                /* step 13.b Link Training was successful */
261
262                 reg32 = nbpcie_p_read_index(dev, 0xa2);
263                 width = (reg32 >> 4) & 0x7;
264                 printk_debug("GFX LC_LINK_WIDTH = 0x%x.\n", width);
265                 switch (width) {
266                 case 1:
267                 case 2:
268                         nbpcie_ind_write_index(nb_dev, 0x65,
269                                                cfg->gfx_lane_reversal ? 0x7f7f : 0xccfefe);
270                         break;
271                 case 4:
272                         nbpcie_ind_write_index(nb_dev, 0x65,
273                                                cfg->gfx_lane_reversal ? 0x3f3f : 0xccfcfc);
274                         break;
275                 case 8:
276                         nbpcie_ind_write_index(nb_dev, 0x65,
277                                                cfg->gfx_lane_reversal ? 0x0f0f : 0xccf0f0);
278                         break;
279                 }
280         }
281         printk_info("rs690_gfx_init single_port_configuration step13.\n");
282
283         /* step 14 Reset Enumeration Timer, disables the shortening of the enumeration timer */
284         set_pcie_enable_bits(dev, 0x70, 1 << 19, 0 << 19);
285         printk_info("rs690_gfx_init single_port_configuration step14.\n");
286 }
287
288 /* step 15 ~ step 18 from rpr */
289 static void dual_port_configuration(device_t nb_dev, device_t dev)
290 {
291         u8 result, width;
292         u32 reg32;
293         struct southbridge_amd_rs690_config *cfg =
294                     (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
295
296         /* step 15: Training for Device 2 */
297         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 4, 0 << 4);
298         /* Releases hold training for GFX port 0 (device 2) */
299         PcieReleasePortTraining(nb_dev, dev, 2);
300         /* PCIE Link Training Sequence */
301         result = PcieTrainPort(nb_dev, dev, 2);
302
303         /* step 16: Power Down Control for Device 2 */
304         /* step 16.a Link Training was NOT successful */
305         if (!result) {
306                 /* Powers down all lanes for port A */
307                 nbpcie_ind_write_index(nb_dev, 0x65, 0x0f0f);
308         } else {                /* step 16.b Link Training was successful */
309
310                 reg32 = nbpcie_p_read_index(dev, 0xa2);
311                 width = (reg32 >> 4) & 0x7;
312                 printk_debug("GFX LC_LINK_WIDTH = 0x%x.\n", width);
313                 switch (width) {
314                 case 1:
315                 case 2:
316                         nbpcie_ind_write_index(nb_dev, 0x65,
317                                                cfg->gfx_lane_reversal ? 0x0707 : 0x0e0e);
318                         break;
319                 case 4:
320                         nbpcie_ind_write_index(nb_dev, 0x65,
321                                                cfg->gfx_lane_reversal ? 0x0303 : 0x0c0c);
322                         break;
323                 }
324         }
325
326         /* step 17: Training for Device 3 */
327         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 5, 0 << 5);
328         /* Releases hold training for GFX port 0 (device 3) */
329         PcieReleasePortTraining(nb_dev, dev, 3);
330         /* PCIE Link Training Sequence */
331         result = PcieTrainPort(nb_dev, dev, 3);
332
333         /*step 18: Power Down Control for Device 3 */
334         /* step 18.a Link Training was NOT successful */
335         if (!result) {
336                 /* Powers down all lanes for port B and PLL1 */
337                 nbpcie_ind_write_index(nb_dev, 0x65, 0xccf0f0);
338         } else {                /* step 18.b Link Training was successful */
339
340                 reg32 = nbpcie_p_read_index(dev, 0xa2);
341                 width = (reg32 >> 4) & 0x7;
342                 printk_debug("GFX LC_LINK_WIDTH = 0x%x.\n", width);
343                 switch (width) {
344                 case 1:
345                 case 2:
346                         nbpcie_ind_write_index(nb_dev, 0x65,
347                                                cfg->gfx_lane_reversal ? 0x7070 : 0xe0e0);
348                         break;
349                 case 4:
350                         nbpcie_ind_write_index(nb_dev, 0x65,
351                                                cfg->gfx_lane_reversal ? 0x3030 : 0xc0c0);
352                         break;
353                 }
354         }
355 }
356
357
358 /* For single port GFX configuration Only
359 * width:
360 *       000 = x16
361 *       001 = x1
362 *       010 = x2
363 *       011 = x4
364 *       100 = x8
365 *       101 = x12 (not supported)
366 *       110 = x16
367 */
368 static void dynamic_link_width_control(device_t nb_dev, device_t dev, u8 width)
369 {
370         u32 reg32;
371         device_t sb_dev;
372         struct southbridge_amd_rs690_config *cfg =
373             (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
374
375         /* step 5.9.1.1 */
376         reg32 = nbpcie_p_read_index(dev, 0xa2);
377
378         /* step 5.9.1.2 */
379         set_pcie_enable_bits(nb_dev, 0x40, 1 << 0, 1 << 0);
380         /* step 5.9.1.3 */
381         set_pcie_enable_bits(dev, 0xa2, 3 << 0, width << 0);
382         /* step 5.9.1.4 */
383         set_pcie_enable_bits(dev, 0xa2, 1 << 8, 1 << 8);
384         /* step 5.9.2.4 */
385         if (0 == cfg->gfx_reconfiguration)
386                 set_pcie_enable_bits(dev, 0xa2, 1 << 11, 1 << 11);
387
388         /* step 5.9.1.5 */
389         do {
390                 reg32 = nbpcie_p_read_index(dev, 0xa2);
391         }
392         while (reg32 & 0x100);
393
394         /* step 5.9.1.6 */
395         sb_dev = dev_find_slot(0, PCI_DEVFN(8, 0));
396         do {
397                 reg32 = pci_ext_read_config32(nb_dev, sb_dev,
398                                           PCIE_VC0_RESOURCE_STATUS);
399         } while (reg32 & VC_NEGOTIATION_PENDING);
400
401         /* step 5.9.1.7 */
402         reg32 = nbpcie_p_read_index(dev, 0xa2);
403         if (((reg32 & 0x70) >> 4) != 0x6) {
404                 /* the unused lanes should be powered off. */
405         }
406
407         /* step 5.9.1.8 */
408         set_pcie_enable_bits(nb_dev, 0x40, 1 << 0, 0 << 0);
409 }
410
411 /*
412 * GFX Core initialization, dev2, dev3
413 */
414 void rs690_gfx_init(device_t nb_dev, device_t dev, u32 port)
415 {
416         u16 reg16;
417         struct southbridge_amd_rs690_config *cfg =
418             (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
419
420         printk_info("rs690_gfx_init, nb_dev=0x%p, dev=0x%p, port=0x%x.\n",
421                     nb_dev, dev, port);
422
423         /* step 0, REFCLK_SEL, skip A11 revision */
424         set_nbmisc_enable_bits(nb_dev, 0x6a, 1 << 9,
425                                cfg->gfx_dev2_dev3 ? 1 << 9 : 0 << 9);
426         printk_info("rs690_gfx_init step0.\n");
427
428         /* step 1, lane reversal (only need if CMOS option is enabled) */
429         if (cfg->gfx_lane_reversal) {
430                 set_nbmisc_enable_bits(nb_dev, 0x33, 1 << 2, 1 << 2);
431                 if (cfg->gfx_dual_slot)
432                         set_nbmisc_enable_bits(nb_dev, 0x33, 1 << 3, 1 << 3);
433         }
434         printk_info("rs690_gfx_init step1.\n");
435
436         /* step 1.1, dual-slot gfx configuration (only need if CMOS option is enabled) */
437         /* AMD calls the configuration CrossFire */
438         if (cfg->gfx_dual_slot)
439                 set_nbmisc_enable_bits(nb_dev, 0x0, 0xf << 8, 5 << 8);
440         printk_info("rs690_gfx_init step2.\n");
441
442         /* step 2, TMDS, (only need if CMOS option is enabled) */
443         if (cfg->gfx_tmds) {
444         }
445
446         /* step 3, GFX overclocking, (only need if CMOS option is enabled) */
447         /* skip */
448
449         /* step 4, reset the GFX link */
450         /* step 4.1 asserts both calibration reset and global reset */
451         set_nbmisc_enable_bits(nb_dev, 0x8, 0x3 << 14, 0x3 << 14);
452
453         /* step 4.2 de-asserts calibration reset */
454         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 14, 0 << 14);
455
456         /* step 4.3 wait for at least 200us */
457         udelay(200);
458
459         /* step 4.4 de-asserts global reset */
460         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 15, 0 << 15);
461
462         /* step 4.5 asserts both calibration reset and global reset */
463         /* a weird step in RPR, don't do that */
464         /* set_nbmisc_enable_bits(nb_dev, 0x8, 0x3 << 14, 0x3 << 14); */
465
466         /* step 4.6 bring external GFX device out of reset, wait for 1ms */
467         mdelay(1);
468         printk_info("rs690_gfx_init step4.\n");
469
470         /* step 5 program PCIE memory mapped configuration space */
471         /* done by enable_pci_bar3() before */
472
473         /* step 6 SBIOS compile flags */
474
475         /* step 7 compliance state, (only need if CMOS option is enabled) */
476         /* the compliance stete is just for test. refer to 4.2.5.2 of PCIe specification */
477         if (cfg->gfx_compliance) {
478                 /* force compliance */
479                 set_nbmisc_enable_bits(nb_dev, 0x32, 1 << 6, 1 << 6);
480                 /* release hold training for device 2. GFX initialization is done. */
481                 set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 4, 0 << 4);
482                 dynamic_link_width_control(nb_dev, dev, cfg->gfx_link_width);
483                 printk_info("rs690_gfx_init step7.\n");
484                 return;
485         }
486
487         /* step 8 common initialization */
488         /* step 8.1 sets RCB timeout to be 25ms */
489         set_pcie_enable_bits(dev, 0x70, 7 << 16, 3 << 16);
490         printk_info("rs690_gfx_init step8.1.\n");
491
492         /* step 8.2 disables slave ordering logic */
493         set_pcie_enable_bits(nb_dev, 0x20, 1 << 8, 1 << 8);
494         printk_info("rs690_gfx_init step8.2.\n");
495
496         /* step 8.3 sets DMA payload size to 64 bytes */
497         set_pcie_enable_bits(nb_dev, 0x10, 7 << 10, 4 << 10);
498         printk_info("rs690_gfx_init step8.3.\n");
499
500         /* step 8.4 if the LTSSM could not see all 8 TS1 during Polling Active, it can still
501          * time out and go back to Detect Idle.*/
502         set_pcie_enable_bits(dev, 0x02, 1 << 14, 1 << 14);
503         printk_info("rs690_gfx_init step8.4.\n");
504
505         /* step 8.5 shortens the enumeration timer */
506         set_pcie_enable_bits(dev, 0x70, 1 << 19, 1 << 19);
507         printk_info("rs690_gfx_init step8.5.\n");
508
509         /* step 8.6 blocks DMA traffic during C3 state */
510         set_pcie_enable_bits(dev, 0x10, 1 << 0, 0 << 0);
511         printk_info("rs690_gfx_init step8.6.\n");
512
513         /* step 8.7 Do not gate the electrical idle form the PHY
514          * step 8.8 Enables the escape from L1L23 */
515         set_pcie_enable_bits(dev, 0xa0, 3 << 30, 3 << 30);
516         printk_info("rs690_gfx_init step8.8.\n");
517
518         /* step 8.9 Setting this register to 0x1 will workaround a PCI Compliance failure reported by Vista DTM.
519          * SLOT_IMPLEMENTED@PCIE_CAP */
520         reg16 = pci_read_config16(dev, 0x5a);
521         reg16 |= 0x100;
522         pci_write_config16(dev, 0x5a, reg16);
523         printk_info("rs690_gfx_init step8.9.\n");
524
525         /* step 8.10 Setting this register to 0x1 will hide the Advanced Error Rporting Capabilities in the PCIE Brider.
526          * This will workaround several failures reported by the PCI Compliance test under Vista DTM. */
527         set_nbmisc_enable_bits(nb_dev, 0x33, 1 << 31, 0 << 31);
528         printk_info("rs690_gfx_init step8.10.\n");
529
530         /* step 8.11 Sets REGS_DLP_IGNORE_IN_L1_EN to ignore DLLPs during L1 so that txclk can be turned off. */
531         set_pcie_enable_bits(nb_dev, 0x02, 1 << 0, 1 << 0);
532         printk_info("rs690_gfx_init step8.11.\n");
533
534         /* step 8.12 Sets REGS_LC_DONT_GO_TO_L0S_IF_L1_ARMED to prevent lc to go to from L0 to Rcv_L0s if L1 is armed. */
535         set_pcie_enable_bits(nb_dev, 0x02, 1 << 6, 1 << 6);
536         printk_info("rs690_gfx_init step8.12.\n");
537
538         /* step 8.13 Sets CMGOOD_OVERRIDE. */
539         set_nbmisc_enable_bits(nb_dev, 0x6a, 1 << 17, 1 << 17);
540         printk_info("rs690_gfx_init step8.13.\n");
541
542         /* step 9 Enable TLP Flushing, for non-AMD GFX devices and Hot-Plug devices only. */
543         /* skip */
544
545         /* step 10 Optional Features, only needed if CMOS option is enabled. */
546         /* step 10.a: L0s */
547         /* enabling L0s in the RS690 GFX port(s) */
548         set_pcie_enable_bits(nb_dev, 0xF9, 3 << 13, 2 << 13);
549         set_pcie_enable_bits(dev, 0xA0, 0xf << 8, 8 << 8);
550         reg16 = pci_read_config16(dev, 0x68);
551         reg16 |= 1 << 0;
552         /* L0s is intended as a power saving state */
553         /* pci_write_config16(dev, 0x68, reg16); */
554
555         /* enabling L0s in the External GFX Device(s) */
556
557         /* step 10.b: active state power management (ASPM L1) */
558         /* TO DO */
559
560         /* step 10.c: turning off PLL During L1/L23 */
561         set_pcie_enable_bits(nb_dev, 0x40, 1 << 3, 1 << 3);
562         set_pcie_enable_bits(nb_dev, 0x40, 1 << 9, 1 << 9);
563
564         /* step 10.d: TXCLK clock gating */
565         set_nbmisc_enable_bits(nb_dev, 0x7, 3, 3);
566         set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 22, 1 << 22);
567         set_pcie_enable_bits(nb_dev, 0x11, 0xf << 4, 0xc << 4);
568
569         /* step 10.e: LCLK clock gating, done in rs690_config_misc_clk() */
570
571         /* step 11 Poll GPIO to determine whether it is single-port or dual-port configuration.
572          * While details will be added later in the document, for now assue the single-port configuration. */
573         /* skip */
574
575         /* Single-port/Dual-port configureation. */
576         switch (cfg->gfx_dual_slot) {
577         case 0:
578                 single_port_configuration(nb_dev, dev);
579                 break;
580         case 1:
581                 dual_port_configuration(nb_dev, dev);
582                 break;
583         default:
584                 printk_info("Incorrect configuration of external gfx slot.\n");
585                 break;
586         }
587 }