3
3
#include <linux/delay.h>
4
4
#include <linux/clk-provider.h>
5
5
#include <linux/io.h>
6
- #include <linux/of.h>
7
6
#include <linux/platform_device.h>
7
+ #include <linux/property.h>
8
8
#include <dt-bindings/clock/en7523-clk.h>
9
9
10
10
#define REG_PCI_CONTROL 0x88
11
11
#define REG_PCI_CONTROL_PERSTOUT BIT(29)
12
12
#define REG_PCI_CONTROL_PERSTOUT1 BIT(26)
13
+ #define REG_PCI_CONTROL_REFCLK_EN0 BIT(23)
13
14
#define REG_PCI_CONTROL_REFCLK_EN1 BIT(22)
15
+ #define REG_PCI_CONTROL_PERSTOUT2 BIT(16)
14
16
#define REG_GSW_CLK_DIV_SEL 0x1b4
15
17
#define REG_EMI_CLK_DIV_SEL 0x1b8
16
18
#define REG_BUS_CLK_DIV_SEL 0x1bc
17
19
#define REG_SPI_CLK_DIV_SEL 0x1c4
18
20
#define REG_SPI_CLK_FREQ_SEL 0x1c8
19
21
#define REG_NPU_CLK_DIV_SEL 0x1fc
20
22
#define REG_CRYPTO_CLKSRC 0x200
21
- #define REG_RESET_CONTROL 0x834
23
+ #define REG_RESET_CONTROL2 0x830
24
+ #define REG_RESET2_CONTROL_PCIE2 BIT(27)
25
+ #define REG_RESET_CONTROL1 0x834
22
26
#define REG_RESET_CONTROL_PCIEHB BIT(29)
23
27
#define REG_RESET_CONTROL_PCIE1 BIT(27)
24
28
#define REG_RESET_CONTROL_PCIE2 BIT(26)
29
+ /* EN7581 */
30
+ #define REG_PCIE0_MEM 0x00
31
+ #define REG_PCIE0_MEM_MASK 0x04
32
+ #define REG_PCIE1_MEM 0x08
33
+ #define REG_PCIE1_MEM_MASK 0x0c
34
+ #define REG_PCIE2_MEM 0x10
35
+ #define REG_PCIE2_MEM_MASK 0x14
36
+ #define REG_PCIE_RESET_OPEN_DRAIN 0x018c
37
+ #define REG_PCIE_RESET_OPEN_DRAIN_MASK GENMASK(2, 0)
38
+ #define REG_NP_SCU_PCIC 0x88
39
+ #define REG_NP_SCU_SSTR 0x9c
40
+ #define REG_PCIE_XSI0_SEL_MASK GENMASK(14, 13)
41
+ #define REG_PCIE_XSI1_SEL_MASK GENMASK(12, 11)
25
42
26
43
struct en_clk_desc {
27
44
int id ;
@@ -47,6 +64,12 @@ struct en_clk_gate {
47
64
struct clk_hw hw ;
48
65
};
49
66
67
+ struct en_clk_soc_data {
68
+ const struct clk_ops pcie_ops ;
69
+ int (* hw_init )(struct platform_device * pdev , void __iomem * base ,
70
+ void __iomem * np_base );
71
+ };
72
+
50
73
static const u32 gsw_base [] = { 400000000 , 500000000 };
51
74
static const u32 emi_base [] = { 333000000 , 400000000 };
52
75
static const u32 bus_base [] = { 500000000 , 540000000 };
@@ -145,11 +168,6 @@ static const struct en_clk_desc en7523_base_clks[] = {
145
168
}
146
169
};
147
170
148
- static const struct of_device_id of_match_clk_en7523 [] = {
149
- { .compatible = "airoha,en7523-scu" , },
150
- { /* sentinel */ }
151
- };
152
-
153
171
static unsigned int en7523_get_base_rate (void __iomem * base , unsigned int i )
154
172
{
155
173
const struct en_clk_desc * desc = & en7523_base_clks [i ];
@@ -212,14 +230,14 @@ static int en7523_pci_prepare(struct clk_hw *hw)
212
230
usleep_range (1000 , 2000 );
213
231
214
232
/* Reset to default */
215
- val = readl (np_base + REG_RESET_CONTROL );
233
+ val = readl (np_base + REG_RESET_CONTROL1 );
216
234
mask = REG_RESET_CONTROL_PCIE1 | REG_RESET_CONTROL_PCIE2 |
217
235
REG_RESET_CONTROL_PCIEHB ;
218
- writel (val & ~mask , np_base + REG_RESET_CONTROL );
236
+ writel (val & ~mask , np_base + REG_RESET_CONTROL1 );
219
237
usleep_range (1000 , 2000 );
220
- writel (val | mask , np_base + REG_RESET_CONTROL );
238
+ writel (val | mask , np_base + REG_RESET_CONTROL1 );
221
239
msleep (100 );
222
- writel (val & ~mask , np_base + REG_RESET_CONTROL );
240
+ writel (val & ~mask , np_base + REG_RESET_CONTROL1 );
223
241
usleep_range (5000 , 10000 );
224
242
225
243
/* Release device */
@@ -247,14 +265,10 @@ static void en7523_pci_unprepare(struct clk_hw *hw)
247
265
static struct clk_hw * en7523_register_pcie_clk (struct device * dev ,
248
266
void __iomem * np_base )
249
267
{
250
- static const struct clk_ops pcie_gate_ops = {
251
- .is_enabled = en7523_pci_is_enabled ,
252
- .prepare = en7523_pci_prepare ,
253
- .unprepare = en7523_pci_unprepare ,
254
- };
268
+ const struct en_clk_soc_data * soc_data = device_get_match_data (dev );
255
269
struct clk_init_data init = {
256
270
.name = "pcie" ,
257
- .ops = & pcie_gate_ops ,
271
+ .ops = & soc_data -> pcie_ops ,
258
272
};
259
273
struct en_clk_gate * cg ;
260
274
@@ -264,14 +278,122 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev,
264
278
265
279
cg -> base = np_base ;
266
280
cg -> hw .init = & init ;
267
- en7523_pci_unprepare (& cg -> hw );
281
+
282
+ if (init .ops -> disable )
283
+ init .ops -> disable (& cg -> hw );
284
+ init .ops -> unprepare (& cg -> hw );
268
285
269
286
if (clk_hw_register (dev , & cg -> hw ))
270
287
return NULL ;
271
288
272
289
return & cg -> hw ;
273
290
}
274
291
292
+ static int en7581_pci_is_enabled (struct clk_hw * hw )
293
+ {
294
+ struct en_clk_gate * cg = container_of (hw , struct en_clk_gate , hw );
295
+ u32 val , mask ;
296
+
297
+ mask = REG_PCI_CONTROL_REFCLK_EN0 | REG_PCI_CONTROL_REFCLK_EN1 ;
298
+ val = readl (cg -> base + REG_PCI_CONTROL );
299
+ return (val & mask ) == mask ;
300
+ }
301
+
302
+ static int en7581_pci_prepare (struct clk_hw * hw )
303
+ {
304
+ struct en_clk_gate * cg = container_of (hw , struct en_clk_gate , hw );
305
+ void __iomem * np_base = cg -> base ;
306
+ u32 val , mask ;
307
+
308
+ mask = REG_RESET_CONTROL_PCIE1 | REG_RESET_CONTROL_PCIE2 |
309
+ REG_RESET_CONTROL_PCIEHB ;
310
+ val = readl (np_base + REG_RESET_CONTROL1 );
311
+ writel (val & ~mask , np_base + REG_RESET_CONTROL1 );
312
+ val = readl (np_base + REG_RESET_CONTROL2 );
313
+ writel (val & ~REG_RESET2_CONTROL_PCIE2 , np_base + REG_RESET_CONTROL2 );
314
+ usleep_range (5000 , 10000 );
315
+
316
+ return 0 ;
317
+ }
318
+
319
+ static int en7581_pci_enable (struct clk_hw * hw )
320
+ {
321
+ struct en_clk_gate * cg = container_of (hw , struct en_clk_gate , hw );
322
+ void __iomem * np_base = cg -> base ;
323
+ u32 val , mask ;
324
+
325
+ mask = REG_PCI_CONTROL_REFCLK_EN0 | REG_PCI_CONTROL_REFCLK_EN1 |
326
+ REG_PCI_CONTROL_PERSTOUT1 | REG_PCI_CONTROL_PERSTOUT2 |
327
+ REG_PCI_CONTROL_PERSTOUT ;
328
+ val = readl (np_base + REG_PCI_CONTROL );
329
+ writel (val | mask , np_base + REG_PCI_CONTROL );
330
+ msleep (250 );
331
+
332
+ return 0 ;
333
+ }
334
+
335
+ static void en7581_pci_unprepare (struct clk_hw * hw )
336
+ {
337
+ struct en_clk_gate * cg = container_of (hw , struct en_clk_gate , hw );
338
+ void __iomem * np_base = cg -> base ;
339
+ u32 val , mask ;
340
+
341
+ mask = REG_RESET_CONTROL_PCIE1 | REG_RESET_CONTROL_PCIE2 |
342
+ REG_RESET_CONTROL_PCIEHB ;
343
+ val = readl (np_base + REG_RESET_CONTROL1 );
344
+ writel (val | mask , np_base + REG_RESET_CONTROL1 );
345
+ mask = REG_RESET_CONTROL_PCIE1 | REG_RESET_CONTROL_PCIE2 ;
346
+ writel (val | mask , np_base + REG_RESET_CONTROL1 );
347
+ val = readl (np_base + REG_RESET_CONTROL2 );
348
+ writel (val | REG_RESET_CONTROL_PCIE2 , np_base + REG_RESET_CONTROL2 );
349
+ msleep (100 );
350
+ }
351
+
352
+ static void en7581_pci_disable (struct clk_hw * hw )
353
+ {
354
+ struct en_clk_gate * cg = container_of (hw , struct en_clk_gate , hw );
355
+ void __iomem * np_base = cg -> base ;
356
+ u32 val , mask ;
357
+
358
+ mask = REG_PCI_CONTROL_REFCLK_EN0 | REG_PCI_CONTROL_REFCLK_EN1 |
359
+ REG_PCI_CONTROL_PERSTOUT1 | REG_PCI_CONTROL_PERSTOUT2 |
360
+ REG_PCI_CONTROL_PERSTOUT ;
361
+ val = readl (np_base + REG_PCI_CONTROL );
362
+ writel (val & ~mask , np_base + REG_PCI_CONTROL );
363
+ usleep_range (1000 , 2000 );
364
+ }
365
+
366
+ static int en7581_clk_hw_init (struct platform_device * pdev ,
367
+ void __iomem * base ,
368
+ void __iomem * np_base )
369
+ {
370
+ void __iomem * pb_base ;
371
+ u32 val ;
372
+
373
+ pb_base = devm_platform_ioremap_resource (pdev , 2 );
374
+ if (IS_ERR (pb_base ))
375
+ return PTR_ERR (pb_base );
376
+
377
+ val = readl (np_base + REG_NP_SCU_SSTR );
378
+ val &= ~(REG_PCIE_XSI0_SEL_MASK | REG_PCIE_XSI1_SEL_MASK );
379
+ writel (val , np_base + REG_NP_SCU_SSTR );
380
+ val = readl (np_base + REG_NP_SCU_PCIC );
381
+ writel (val | 3 , np_base + REG_NP_SCU_PCIC );
382
+
383
+ writel (0x20000000 , pb_base + REG_PCIE0_MEM );
384
+ writel (0xfc000000 , pb_base + REG_PCIE0_MEM_MASK );
385
+ writel (0x24000000 , pb_base + REG_PCIE1_MEM );
386
+ writel (0xfc000000 , pb_base + REG_PCIE1_MEM_MASK );
387
+ writel (0x28000000 , pb_base + REG_PCIE2_MEM );
388
+ writel (0xfc000000 , pb_base + REG_PCIE2_MEM_MASK );
389
+
390
+ val = readl (base + REG_PCIE_RESET_OPEN_DRAIN );
391
+ writel (val | REG_PCIE_RESET_OPEN_DRAIN_MASK ,
392
+ base + REG_PCIE_RESET_OPEN_DRAIN );
393
+
394
+ return 0 ;
395
+ }
396
+
275
397
static void en7523_register_clocks (struct device * dev , struct clk_hw_onecell_data * clk_data ,
276
398
void __iomem * base , void __iomem * np_base )
277
399
{
@@ -304,6 +426,7 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat
304
426
static int en7523_clk_probe (struct platform_device * pdev )
305
427
{
306
428
struct device_node * node = pdev -> dev .of_node ;
429
+ const struct en_clk_soc_data * soc_data ;
307
430
struct clk_hw_onecell_data * clk_data ;
308
431
void __iomem * base , * np_base ;
309
432
int r ;
@@ -316,6 +439,13 @@ static int en7523_clk_probe(struct platform_device *pdev)
316
439
if (IS_ERR (np_base ))
317
440
return PTR_ERR (np_base );
318
441
442
+ soc_data = device_get_match_data (& pdev -> dev );
443
+ if (soc_data -> hw_init ) {
444
+ r = soc_data -> hw_init (pdev , base , np_base );
445
+ if (r )
446
+ return r ;
447
+ }
448
+
319
449
clk_data = devm_kzalloc (& pdev -> dev ,
320
450
struct_size (clk_data , hws , EN7523_NUM_CLOCKS ),
321
451
GFP_KERNEL );
@@ -333,6 +463,31 @@ static int en7523_clk_probe(struct platform_device *pdev)
333
463
return r ;
334
464
}
335
465
466
+ static const struct en_clk_soc_data en7523_data = {
467
+ .pcie_ops = {
468
+ .is_enabled = en7523_pci_is_enabled ,
469
+ .prepare = en7523_pci_prepare ,
470
+ .unprepare = en7523_pci_unprepare ,
471
+ },
472
+ };
473
+
474
+ static const struct en_clk_soc_data en7581_data = {
475
+ .pcie_ops = {
476
+ .is_enabled = en7581_pci_is_enabled ,
477
+ .prepare = en7581_pci_prepare ,
478
+ .enable = en7581_pci_enable ,
479
+ .unprepare = en7581_pci_unprepare ,
480
+ .disable = en7581_pci_disable ,
481
+ },
482
+ .hw_init = en7581_clk_hw_init ,
483
+ };
484
+
485
+ static const struct of_device_id of_match_clk_en7523 [] = {
486
+ { .compatible = "airoha,en7523-scu" , .data = & en7523_data },
487
+ { .compatible = "airoha,en7581-scu" , .data = & en7581_data },
488
+ { /* sentinel */ }
489
+ };
490
+
336
491
static struct platform_driver clk_en7523_drv = {
337
492
.probe = en7523_clk_probe ,
338
493
.driver = {
0 commit comments