5
5
#include <linux/io.h>
6
6
#include <linux/platform_device.h>
7
7
#include <linux/property.h>
8
+ #include <linux/reset-controller.h>
8
9
#include <dt-bindings/clock/en7523-clk.h>
10
+ #include <dt-bindings/reset/airoha,en7581-reset.h>
11
+
12
+ #define RST_NR_PER_BANK 32
9
13
10
14
#define REG_PCI_CONTROL 0x88
11
15
#define REG_PCI_CONTROL_PERSTOUT BIT(29)
40
44
#define REG_PCIE_XSI0_SEL_MASK GENMASK(14, 13)
41
45
#define REG_PCIE_XSI1_SEL_MASK GENMASK(12, 11)
42
46
47
+ #define REG_RST_CTRL2 0x00
48
+ #define REG_RST_CTRL1 0x04
49
+
43
50
struct en_clk_desc {
44
51
int id ;
45
52
const char * name ;
@@ -64,8 +71,20 @@ struct en_clk_gate {
64
71
struct clk_hw hw ;
65
72
};
66
73
74
+ struct en_rst_data {
75
+ const u16 * bank_ofs ;
76
+ const u16 * idx_map ;
77
+ void __iomem * base ;
78
+ struct reset_controller_dev rcdev ;
79
+ };
80
+
67
81
struct en_clk_soc_data {
68
82
const struct clk_ops pcie_ops ;
83
+ struct {
84
+ const u16 * bank_ofs ;
85
+ const u16 * idx_map ;
86
+ u16 idx_map_nr ;
87
+ } reset ;
69
88
int (* hw_init )(struct platform_device * pdev , void __iomem * base ,
70
89
void __iomem * np_base );
71
90
};
@@ -168,6 +187,69 @@ static const struct en_clk_desc en7523_base_clks[] = {
168
187
}
169
188
};
170
189
190
+ static const u16 en7581_rst_ofs [] = {
191
+ REG_RST_CTRL2 ,
192
+ REG_RST_CTRL1 ,
193
+ };
194
+
195
+ static const u16 en7581_rst_map [] = {
196
+ /* RST_CTRL2 */
197
+ [EN7581_XPON_PHY_RST ] = 0 ,
198
+ [EN7581_CPU_TIMER2_RST ] = 2 ,
199
+ [EN7581_HSUART_RST ] = 3 ,
200
+ [EN7581_UART4_RST ] = 4 ,
201
+ [EN7581_UART5_RST ] = 5 ,
202
+ [EN7581_I2C2_RST ] = 6 ,
203
+ [EN7581_XSI_MAC_RST ] = 7 ,
204
+ [EN7581_XSI_PHY_RST ] = 8 ,
205
+ [EN7581_NPU_RST ] = 9 ,
206
+ [EN7581_I2S_RST ] = 10 ,
207
+ [EN7581_TRNG_RST ] = 11 ,
208
+ [EN7581_TRNG_MSTART_RST ] = 12 ,
209
+ [EN7581_DUAL_HSI0_RST ] = 13 ,
210
+ [EN7581_DUAL_HSI1_RST ] = 14 ,
211
+ [EN7581_HSI_RST ] = 15 ,
212
+ [EN7581_DUAL_HSI0_MAC_RST ] = 16 ,
213
+ [EN7581_DUAL_HSI1_MAC_RST ] = 17 ,
214
+ [EN7581_HSI_MAC_RST ] = 18 ,
215
+ [EN7581_WDMA_RST ] = 19 ,
216
+ [EN7581_WOE0_RST ] = 20 ,
217
+ [EN7581_WOE1_RST ] = 21 ,
218
+ [EN7581_HSDMA_RST ] = 22 ,
219
+ [EN7581_TDMA_RST ] = 24 ,
220
+ [EN7581_EMMC_RST ] = 25 ,
221
+ [EN7581_SOE_RST ] = 26 ,
222
+ [EN7581_PCIE2_RST ] = 27 ,
223
+ [EN7581_XFP_MAC_RST ] = 28 ,
224
+ [EN7581_USB_HOST_P1_RST ] = 29 ,
225
+ [EN7581_USB_HOST_P1_U3_PHY_RST ] = 30 ,
226
+ /* RST_CTRL1 */
227
+ [EN7581_PCM1_ZSI_ISI_RST ] = RST_NR_PER_BANK + 0 ,
228
+ [EN7581_FE_PDMA_RST ] = RST_NR_PER_BANK + 1 ,
229
+ [EN7581_FE_QDMA_RST ] = RST_NR_PER_BANK + 2 ,
230
+ [EN7581_PCM_SPIWP_RST ] = RST_NR_PER_BANK + 4 ,
231
+ [EN7581_CRYPTO_RST ] = RST_NR_PER_BANK + 6 ,
232
+ [EN7581_TIMER_RST ] = RST_NR_PER_BANK + 8 ,
233
+ [EN7581_PCM1_RST ] = RST_NR_PER_BANK + 11 ,
234
+ [EN7581_UART_RST ] = RST_NR_PER_BANK + 12 ,
235
+ [EN7581_GPIO_RST ] = RST_NR_PER_BANK + 13 ,
236
+ [EN7581_GDMA_RST ] = RST_NR_PER_BANK + 14 ,
237
+ [EN7581_I2C_MASTER_RST ] = RST_NR_PER_BANK + 16 ,
238
+ [EN7581_PCM2_ZSI_ISI_RST ] = RST_NR_PER_BANK + 17 ,
239
+ [EN7581_SFC_RST ] = RST_NR_PER_BANK + 18 ,
240
+ [EN7581_UART2_RST ] = RST_NR_PER_BANK + 19 ,
241
+ [EN7581_GDMP_RST ] = RST_NR_PER_BANK + 20 ,
242
+ [EN7581_FE_RST ] = RST_NR_PER_BANK + 21 ,
243
+ [EN7581_USB_HOST_P0_RST ] = RST_NR_PER_BANK + 22 ,
244
+ [EN7581_GSW_RST ] = RST_NR_PER_BANK + 23 ,
245
+ [EN7581_SFC2_PCM_RST ] = RST_NR_PER_BANK + 25 ,
246
+ [EN7581_PCIE0_RST ] = RST_NR_PER_BANK + 26 ,
247
+ [EN7581_PCIE1_RST ] = RST_NR_PER_BANK + 27 ,
248
+ [EN7581_CPU_TIMER_RST ] = RST_NR_PER_BANK + 28 ,
249
+ [EN7581_PCIE_HB_RST ] = RST_NR_PER_BANK + 29 ,
250
+ [EN7581_XPON_MAC_RST ] = RST_NR_PER_BANK + 31 ,
251
+ };
252
+
171
253
static unsigned int en7523_get_base_rate (void __iomem * base , unsigned int i )
172
254
{
173
255
const struct en_clk_desc * desc = & en7523_base_clks [i ];
@@ -370,7 +452,7 @@ static int en7581_clk_hw_init(struct platform_device *pdev,
370
452
void __iomem * pb_base ;
371
453
u32 val ;
372
454
373
- pb_base = devm_platform_ioremap_resource (pdev , 2 );
455
+ pb_base = devm_platform_ioremap_resource (pdev , 3 );
374
456
if (IS_ERR (pb_base ))
375
457
return PTR_ERR (pb_base );
376
458
@@ -423,6 +505,95 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat
423
505
clk_data -> num = EN7523_NUM_CLOCKS ;
424
506
}
425
507
508
+ static int en7523_reset_update (struct reset_controller_dev * rcdev ,
509
+ unsigned long id , bool assert )
510
+ {
511
+ struct en_rst_data * rst_data = container_of (rcdev , struct en_rst_data , rcdev );
512
+ void __iomem * addr = rst_data -> base + rst_data -> bank_ofs [id / RST_NR_PER_BANK ];
513
+ u32 val ;
514
+
515
+ val = readl (addr );
516
+ if (assert )
517
+ val |= BIT (id % RST_NR_PER_BANK );
518
+ else
519
+ val &= ~BIT (id % RST_NR_PER_BANK );
520
+ writel (val , addr );
521
+
522
+ return 0 ;
523
+ }
524
+
525
+ static int en7523_reset_assert (struct reset_controller_dev * rcdev ,
526
+ unsigned long id )
527
+ {
528
+ return en7523_reset_update (rcdev , id , true);
529
+ }
530
+
531
+ static int en7523_reset_deassert (struct reset_controller_dev * rcdev ,
532
+ unsigned long id )
533
+ {
534
+ return en7523_reset_update (rcdev , id , false);
535
+ }
536
+
537
+ static int en7523_reset_status (struct reset_controller_dev * rcdev ,
538
+ unsigned long id )
539
+ {
540
+ struct en_rst_data * rst_data = container_of (rcdev , struct en_rst_data , rcdev );
541
+ void __iomem * addr = rst_data -> base + rst_data -> bank_ofs [id / RST_NR_PER_BANK ];
542
+
543
+ return !!(readl (addr ) & BIT (id % RST_NR_PER_BANK ));
544
+ }
545
+
546
+ static int en7523_reset_xlate (struct reset_controller_dev * rcdev ,
547
+ const struct of_phandle_args * reset_spec )
548
+ {
549
+ struct en_rst_data * rst_data = container_of (rcdev , struct en_rst_data , rcdev );
550
+
551
+ if (reset_spec -> args [0 ] >= rcdev -> nr_resets )
552
+ return - EINVAL ;
553
+
554
+ return rst_data -> idx_map [reset_spec -> args [0 ]];
555
+ }
556
+
557
+ static const struct reset_control_ops en7523_reset_ops = {
558
+ .assert = en7523_reset_assert ,
559
+ .deassert = en7523_reset_deassert ,
560
+ .status = en7523_reset_status ,
561
+ };
562
+
563
+ static int en7523_reset_register (struct platform_device * pdev ,
564
+ const struct en_clk_soc_data * soc_data )
565
+ {
566
+ struct device * dev = & pdev -> dev ;
567
+ struct en_rst_data * rst_data ;
568
+ void __iomem * base ;
569
+
570
+ /* no reset lines available */
571
+ if (!soc_data -> reset .idx_map_nr )
572
+ return 0 ;
573
+
574
+ base = devm_platform_ioremap_resource (pdev , 2 );
575
+ if (IS_ERR (base ))
576
+ return PTR_ERR (base );
577
+
578
+ rst_data = devm_kzalloc (dev , sizeof (* rst_data ), GFP_KERNEL );
579
+ if (!rst_data )
580
+ return - ENOMEM ;
581
+
582
+ rst_data -> bank_ofs = soc_data -> reset .bank_ofs ;
583
+ rst_data -> idx_map = soc_data -> reset .idx_map ;
584
+ rst_data -> base = base ;
585
+
586
+ rst_data -> rcdev .nr_resets = soc_data -> reset .idx_map_nr ;
587
+ rst_data -> rcdev .of_xlate = en7523_reset_xlate ;
588
+ rst_data -> rcdev .ops = & en7523_reset_ops ;
589
+ rst_data -> rcdev .of_node = dev -> of_node ;
590
+ rst_data -> rcdev .of_reset_n_cells = 1 ;
591
+ rst_data -> rcdev .owner = THIS_MODULE ;
592
+ rst_data -> rcdev .dev = dev ;
593
+
594
+ return devm_reset_controller_register (dev , & rst_data -> rcdev );
595
+ }
596
+
426
597
static int en7523_clk_probe (struct platform_device * pdev )
427
598
{
428
599
struct device_node * node = pdev -> dev .of_node ;
@@ -456,11 +627,17 @@ static int en7523_clk_probe(struct platform_device *pdev)
456
627
457
628
r = of_clk_add_hw_provider (node , of_clk_hw_onecell_get , clk_data );
458
629
if (r )
459
- dev_err (& pdev -> dev ,
460
- "could not register clock provider: %s: %d\n" ,
461
- pdev -> name , r );
630
+ return dev_err_probe (& pdev -> dev , r , "Could not register clock provider: %s\n" ,
631
+ pdev -> name );
632
+
633
+ r = en7523_reset_register (pdev , soc_data );
634
+ if (r ) {
635
+ of_clk_del_provider (node );
636
+ return dev_err_probe (& pdev -> dev , r , "Could not register reset controller: %s\n" ,
637
+ pdev -> name );
638
+ }
462
639
463
- return r ;
640
+ return 0 ;
464
641
}
465
642
466
643
static const struct en_clk_soc_data en7523_data = {
@@ -479,6 +656,11 @@ static const struct en_clk_soc_data en7581_data = {
479
656
.unprepare = en7581_pci_unprepare ,
480
657
.disable = en7581_pci_disable ,
481
658
},
659
+ .reset = {
660
+ .bank_ofs = en7581_rst_ofs ,
661
+ .idx_map = en7581_rst_map ,
662
+ .idx_map_nr = ARRAY_SIZE (en7581_rst_map ),
663
+ },
482
664
.hw_init = en7581_clk_hw_init ,
483
665
};
484
666
0 commit comments