Skip to content

Commit 5aabfd9

Browse files
committed
Merge branches 'clk-cleanup', 'clk-airoha', 'clk-mediatek', 'clk-sophgo' and 'clk-loongson' into clk-next
- Airoha EN7581 SoC clk driver - Sophgo CV1800B, CV1812H and SG2000 SoC clk driver - Loongson-2k0500 and Loongson-2k2000 SoC clk driver * clk-cleanup: clk: gemini: Remove an unused field in struct clk_gemini_pci clk: highbank: Remove an unused field in struct hb_clk clk: ti: dpll: fix incorrect #ifdef checks clk: nxp: Remove an unused field in struct lpc18xx_pll * clk-airoha: clk: en7523: Add EN7581 support clk: en7523: Add en_clk_soc_data data structure dt-bindings: clock: airoha: add EN7581 binding * clk-mediatek: clk: mediatek: mt8365-mm: fix DPI0 parent clk: mediatek: pllfh: Don't log error for missing fhctl node * clk-sophgo: clk: sophgo: avoid open-coded 64-bit division clk: sophgo: Make synthesizer struct static clk: sophgo: Add clock support for SG2000 SoC clk: sophgo: Add clock support for CV1810 SoC clk: sophgo: Add clock support for CV1800 SoC dt-bindings: clock: sophgo: Add clock controller of SG2000 series SoC * clk-loongson: clk: clk-loongson2: Add Loongson-2K2000 clock support dt-bindings: clock: loongson2: Add Loongson-2K2000 compatible clk: clk-loongson2: Add Loongson-2K0500 clock support dt-bindings: clock: loongson2: Add Loongson-2K0500 compatible clk: clk-loongson2: Refactor driver for adding new platforms dt-bindings: clock: Add Loongson-2K expand clock index
5 parents 8e931ef + 66bc473 + 4c0c087 + 0a7c2fd + 4f149dd commit 5aabfd9

20 files changed

+4046
-301
lines changed

Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ description: |
2929
properties:
3030
compatible:
3131
items:
32-
- const: airoha,en7523-scu
32+
- enum:
33+
- airoha,en7523-scu
34+
- airoha,en7581-scu
3335

3436
reg:
35-
maxItems: 2
37+
minItems: 2
38+
maxItems: 3
3639

3740
"#clock-cells":
3841
description:
@@ -45,6 +48,30 @@ required:
4548
- reg
4649
- '#clock-cells'
4750

51+
allOf:
52+
- if:
53+
properties:
54+
compatible:
55+
const: airoha,en7523-scu
56+
then:
57+
properties:
58+
reg:
59+
items:
60+
- description: scu base address
61+
- description: misc scu base address
62+
63+
- if:
64+
properties:
65+
compatible:
66+
const: airoha,en7581-scu
67+
then:
68+
properties:
69+
reg:
70+
items:
71+
- description: scu base address
72+
- description: misc scu base address
73+
- description: pb scu base address
74+
4875
additionalProperties: false
4976

5077
examples:

Documentation/devicetree/bindings/clock/loongson,ls2k-clk.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ description: |
1616
properties:
1717
compatible:
1818
enum:
19-
- loongson,ls2k-clk
19+
- loongson,ls2k0500-clk
20+
- loongson,ls2k-clk # This is for Loongson-2K1000
21+
- loongson,ls2k2000-clk
2022

2123
reg:
2224
maxItems: 1

Documentation/devicetree/bindings/clock/sophgo,cv1800-clk.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$id: http://devicetree.org/schemas/clock/sophgo,cv1800-clk.yaml#
55
$schema: http://devicetree.org/meta-schemas/core.yaml#
66

7-
title: Sophgo CV1800 Series Clock Controller
7+
title: Sophgo CV1800/SG2000 Series Clock Controller
88

99
maintainers:
1010
- Inochi Amaoto <inochiama@outlook.com>
@@ -14,6 +14,7 @@ properties:
1414
enum:
1515
- sophgo,cv1800-clk
1616
- sophgo,cv1810-clk
17+
- sophgo,sg2000-clk
1718

1819
reg:
1920
maxItems: 1

drivers/clk/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ source "drivers/clk/rockchip/Kconfig"
489489
source "drivers/clk/samsung/Kconfig"
490490
source "drivers/clk/sifive/Kconfig"
491491
source "drivers/clk/socfpga/Kconfig"
492+
source "drivers/clk/sophgo/Kconfig"
492493
source "drivers/clk/sprd/Kconfig"
493494
source "drivers/clk/starfive/Kconfig"
494495
source "drivers/clk/sunxi/Kconfig"

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
118118
obj-$(CONFIG_COMMON_CLK_SAMSUNG) += samsung/
119119
obj-$(CONFIG_CLK_SIFIVE) += sifive/
120120
obj-y += socfpga/
121+
obj-y += sophgo/
121122
obj-$(CONFIG_PLAT_SPEAR) += spear/
122123
obj-y += sprd/
123124
obj-$(CONFIG_ARCH_STI) += st/

drivers/clk/clk-en7523.c

Lines changed: 173 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,42 @@
33
#include <linux/delay.h>
44
#include <linux/clk-provider.h>
55
#include <linux/io.h>
6-
#include <linux/of.h>
76
#include <linux/platform_device.h>
7+
#include <linux/property.h>
88
#include <dt-bindings/clock/en7523-clk.h>
99

1010
#define REG_PCI_CONTROL 0x88
1111
#define REG_PCI_CONTROL_PERSTOUT BIT(29)
1212
#define REG_PCI_CONTROL_PERSTOUT1 BIT(26)
13+
#define REG_PCI_CONTROL_REFCLK_EN0 BIT(23)
1314
#define REG_PCI_CONTROL_REFCLK_EN1 BIT(22)
15+
#define REG_PCI_CONTROL_PERSTOUT2 BIT(16)
1416
#define REG_GSW_CLK_DIV_SEL 0x1b4
1517
#define REG_EMI_CLK_DIV_SEL 0x1b8
1618
#define REG_BUS_CLK_DIV_SEL 0x1bc
1719
#define REG_SPI_CLK_DIV_SEL 0x1c4
1820
#define REG_SPI_CLK_FREQ_SEL 0x1c8
1921
#define REG_NPU_CLK_DIV_SEL 0x1fc
2022
#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
2226
#define REG_RESET_CONTROL_PCIEHB BIT(29)
2327
#define REG_RESET_CONTROL_PCIE1 BIT(27)
2428
#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)
2542

2643
struct en_clk_desc {
2744
int id;
@@ -47,6 +64,12 @@ struct en_clk_gate {
4764
struct clk_hw hw;
4865
};
4966

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+
5073
static const u32 gsw_base[] = { 400000000, 500000000 };
5174
static const u32 emi_base[] = { 333000000, 400000000 };
5275
static const u32 bus_base[] = { 500000000, 540000000 };
@@ -145,11 +168,6 @@ static const struct en_clk_desc en7523_base_clks[] = {
145168
}
146169
};
147170

148-
static const struct of_device_id of_match_clk_en7523[] = {
149-
{ .compatible = "airoha,en7523-scu", },
150-
{ /* sentinel */ }
151-
};
152-
153171
static unsigned int en7523_get_base_rate(void __iomem *base, unsigned int i)
154172
{
155173
const struct en_clk_desc *desc = &en7523_base_clks[i];
@@ -212,14 +230,14 @@ static int en7523_pci_prepare(struct clk_hw *hw)
212230
usleep_range(1000, 2000);
213231

214232
/* Reset to default */
215-
val = readl(np_base + REG_RESET_CONTROL);
233+
val = readl(np_base + REG_RESET_CONTROL1);
216234
mask = REG_RESET_CONTROL_PCIE1 | REG_RESET_CONTROL_PCIE2 |
217235
REG_RESET_CONTROL_PCIEHB;
218-
writel(val & ~mask, np_base + REG_RESET_CONTROL);
236+
writel(val & ~mask, np_base + REG_RESET_CONTROL1);
219237
usleep_range(1000, 2000);
220-
writel(val | mask, np_base + REG_RESET_CONTROL);
238+
writel(val | mask, np_base + REG_RESET_CONTROL1);
221239
msleep(100);
222-
writel(val & ~mask, np_base + REG_RESET_CONTROL);
240+
writel(val & ~mask, np_base + REG_RESET_CONTROL1);
223241
usleep_range(5000, 10000);
224242

225243
/* Release device */
@@ -247,14 +265,10 @@ static void en7523_pci_unprepare(struct clk_hw *hw)
247265
static struct clk_hw *en7523_register_pcie_clk(struct device *dev,
248266
void __iomem *np_base)
249267
{
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);
255269
struct clk_init_data init = {
256270
.name = "pcie",
257-
.ops = &pcie_gate_ops,
271+
.ops = &soc_data->pcie_ops,
258272
};
259273
struct en_clk_gate *cg;
260274

@@ -264,14 +278,122 @@ static struct clk_hw *en7523_register_pcie_clk(struct device *dev,
264278

265279
cg->base = np_base;
266280
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);
268285

269286
if (clk_hw_register(dev, &cg->hw))
270287
return NULL;
271288

272289
return &cg->hw;
273290
}
274291

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+
275397
static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_data *clk_data,
276398
void __iomem *base, void __iomem *np_base)
277399
{
@@ -304,6 +426,7 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat
304426
static int en7523_clk_probe(struct platform_device *pdev)
305427
{
306428
struct device_node *node = pdev->dev.of_node;
429+
const struct en_clk_soc_data *soc_data;
307430
struct clk_hw_onecell_data *clk_data;
308431
void __iomem *base, *np_base;
309432
int r;
@@ -316,6 +439,13 @@ static int en7523_clk_probe(struct platform_device *pdev)
316439
if (IS_ERR(np_base))
317440
return PTR_ERR(np_base);
318441

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+
319449
clk_data = devm_kzalloc(&pdev->dev,
320450
struct_size(clk_data, hws, EN7523_NUM_CLOCKS),
321451
GFP_KERNEL);
@@ -333,6 +463,31 @@ static int en7523_clk_probe(struct platform_device *pdev)
333463
return r;
334464
}
335465

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+
336491
static struct platform_driver clk_en7523_drv = {
337492
.probe = en7523_clk_probe,
338493
.driver = {

0 commit comments

Comments
 (0)