1616 */
1717
1818#include <linux/bitops.h>
19+ #include <linux/clk.h>
1920#include <linux/delay.h>
2021#include <linux/gpio/consumer.h>
2122#include <linux/iopoll.h>
4344#define PCIE_FTS_NUM_MASK GENMASK(15, 8)
4445#define PCIE_FTS_NUM_L0 (x ) (((x) & 0xff) << 8)
4546
46- /* rt_sysc_membase relative registers */
47- #define RALINK_CLKCFG1 0x30
48-
4947/* Host-PCI bridge registers */
5048#define RALINK_PCI_PCICFG_ADDR 0x0000
5149#define RALINK_PCI_PCIMSK_ADDR 0x000C
7977#define PCIE_BAR_MAP_MAX GENMASK(30, 16)
8078#define PCIE_BAR_ENABLE BIT(0)
8179#define PCIE_PORT_INT_EN (x ) BIT(20 + (x))
82- #define PCIE_PORT_CLK_EN (x ) BIT(24 + (x))
8380#define PCIE_PORT_LINKUP BIT(0)
8481
8582#define PERST_MODE_MASK GENMASK(11, 10)
9188 * @base: I/O mapped register base
9289 * @list: port list
9390 * @pcie: pointer to PCIe host info
91+ * @clk: pointer to the port clock gate
9492 * @phy: pointer to PHY control block
9593 * @pcie_rst: pointer to port reset control
9694 * @gpio_rst: gpio reset
@@ -102,6 +100,7 @@ struct mt7621_pcie_port {
102100 void __iomem * base ;
103101 struct list_head list ;
104102 struct mt7621_pcie * pcie ;
103+ struct clk * clk ;
105104 struct phy * phy ;
106105 struct reset_control * pcie_rst ;
107106 struct gpio_desc * gpio_rst ;
@@ -222,16 +221,6 @@ static inline bool mt7621_pcie_port_is_linkup(struct mt7621_pcie_port *port)
222221 return (pcie_port_read (port , RALINK_PCI_STATUS ) & PCIE_PORT_LINKUP ) != 0 ;
223222}
224223
225- static inline void mt7621_pcie_port_clk_enable (struct mt7621_pcie_port * port )
226- {
227- rt_sysc_m32 (0 , PCIE_PORT_CLK_EN (port -> slot ), RALINK_CLKCFG1 );
228- }
229-
230- static inline void mt7621_pcie_port_clk_disable (struct mt7621_pcie_port * port )
231- {
232- rt_sysc_m32 (PCIE_PORT_CLK_EN (port -> slot ), 0 , RALINK_CLKCFG1 );
233- }
234-
235224static inline void mt7621_control_assert (struct mt7621_pcie_port * port )
236225{
237226 struct mt7621_pcie * pcie = port -> pcie ;
@@ -351,6 +340,13 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
351340 if (IS_ERR (port -> base ))
352341 return PTR_ERR (port -> base );
353342
343+ snprintf (name , sizeof (name ), "pcie%d" , slot );
344+ port -> clk = devm_clk_get (dev , name );
345+ if (IS_ERR (port -> clk )) {
346+ dev_err (dev , "failed to get pcie%d clock\n" , slot );
347+ return PTR_ERR (port -> clk );
348+ }
349+
354350 snprintf (name , sizeof (name ), "pcie%d" , slot );
355351 port -> pcie_rst = devm_reset_control_get_exclusive (dev , name );
356352 if (PTR_ERR (port -> pcie_rst ) == - EPROBE_DEFER ) {
@@ -512,7 +508,7 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
512508 dev_err (dev , "pcie%d no card, disable it (RST & CLK)\n" ,
513509 slot );
514510 mt7621_control_assert (port );
515- mt7621_pcie_port_clk_disable (port );
511+ clk_disable_unprepare (port -> clk );
516512 port -> enabled = false;
517513
518514 if (slot == 0 ) {
@@ -547,21 +543,27 @@ static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
547543 offset + RALINK_PCI_CLASS );
548544}
549545
550- static void mt7621_pcie_enable_ports (struct mt7621_pcie * pcie )
546+ static int mt7621_pcie_enable_ports (struct mt7621_pcie * pcie )
551547{
552548 struct device * dev = pcie -> dev ;
553549 struct mt7621_pcie_port * port ;
554550 u8 num_slots_enabled = 0 ;
555551 u32 slot ;
556552 u32 val ;
553+ int err ;
557554
558555 /* Setup MEMWIN and IOWIN */
559556 pcie_write (pcie , 0xffffffff , RALINK_PCI_MEMBASE );
560557 pcie_write (pcie , pcie -> io .start , RALINK_PCI_IOBASE );
561558
562559 list_for_each_entry (port , & pcie -> ports , list ) {
563560 if (port -> enabled ) {
564- mt7621_pcie_port_clk_enable (port );
561+ err = clk_prepare_enable (port -> clk );
562+ if (err ) {
563+ dev_err (dev , "enabling clk pcie%d\n" , slot );
564+ return err ;
565+ }
566+
565567 mt7621_pcie_enable_port (port );
566568 dev_info (dev , "PCIE%d enabled\n" , port -> slot );
567569 num_slots_enabled ++ ;
@@ -578,6 +580,8 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
578580 val |= PCIE_FTS_NUM_L0 (0x50 );
579581 write_config (pcie , slot , PCIE_FTS_NUM , val );
580582 }
583+
584+ return 0 ;
581585}
582586
583587static int mt7621_pcie_init_virtual_bridges (struct mt7621_pcie * pcie )
@@ -694,7 +698,11 @@ static int mt7621_pci_probe(struct platform_device *pdev)
694698 return 0 ;
695699 }
696700
697- mt7621_pcie_enable_ports (pcie );
701+ err = mt7621_pcie_enable_ports (pcie );
702+ if (err ) {
703+ dev_err (dev , "Error enabling pcie ports\n" );
704+ return err ;
705+ }
698706
699707 setup_cm_memory_region (pcie );
700708
0 commit comments