Skip to content

Commit 30e1e28

Browse files
sorenb-xlnxMichal Simek
authored andcommitted
arm: zynq: Migrate platform to clock controller
Migrate the Zynq platform and its drivers to use the new clock controller driver. Signed-off-by: Soren Brinkmann <soren.brinkmann@xilinx.com> Cc: John Stultz <john.stultz@linaro.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Jiri Slaby <jslaby@suse.cz> Cc: linux-serial@vger.kernel.org Signed-off-by: Michal Simek <michal.simek@xilinx.com> Acked-by: Mike Turquette <mturquette@linaro.org>
1 parent 0ee52b1 commit 30e1e28

8 files changed

Lines changed: 118 additions & 80 deletions

File tree

‎arch/arm/boot/dts/zynq-7000.dtsi‎

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@
4949

5050
uart0: uart@e0000000 {
5151
compatible = "xlnx,xuartps";
52+
clocks = <&clkc 23>, <&clkc 40>;
53+
clock-names = "ref_clk", "aper_clk";
5254
reg = <0xE0000000 0x1000>;
5355
interrupts = <0 27 4>;
54-
clocks = <&uart_clk 0>;
5556
};
5657

5758
uart1: uart@e0001000 {
5859
compatible = "xlnx,xuartps";
60+
clocks = <&clkc 24>, <&clkc 41>;
61+
clock-names = "ref_clk", "aper_clk";
5962
reg = <0xE0001000 0x1000>;
6063
interrupts = <0 50 4>;
61-
clocks = <&uart_clk 1>;
6264
};
6365

6466
slcr: slcr@f8000000 {
@@ -69,50 +71,21 @@
6971
#address-cells = <1>;
7072
#size-cells = <0>;
7173

72-
ps_clk: ps_clk {
73-
#clock-cells = <0>;
74-
compatible = "fixed-clock";
75-
/* clock-frequency set in board-specific file */
76-
clock-output-names = "ps_clk";
77-
};
78-
armpll: armpll {
79-
#clock-cells = <0>;
80-
compatible = "xlnx,zynq-pll";
81-
clocks = <&ps_clk>;
82-
reg = <0x100 0x110>;
83-
clock-output-names = "armpll";
84-
};
85-
ddrpll: ddrpll {
86-
#clock-cells = <0>;
87-
compatible = "xlnx,zynq-pll";
88-
clocks = <&ps_clk>;
89-
reg = <0x104 0x114>;
90-
clock-output-names = "ddrpll";
91-
};
92-
iopll: iopll {
93-
#clock-cells = <0>;
94-
compatible = "xlnx,zynq-pll";
95-
clocks = <&ps_clk>;
96-
reg = <0x108 0x118>;
97-
clock-output-names = "iopll";
98-
};
99-
uart_clk: uart_clk {
100-
#clock-cells = <1>;
101-
compatible = "xlnx,zynq-periph-clock";
102-
clocks = <&iopll &armpll &ddrpll>;
103-
reg = <0x154>;
104-
clock-output-names = "uart0_ref_clk",
105-
"uart1_ref_clk";
106-
};
107-
cpu_clk: cpu_clk {
74+
clkc: clkc {
10875
#clock-cells = <1>;
109-
compatible = "xlnx,zynq-cpu-clock";
110-
clocks = <&iopll &armpll &ddrpll>;
111-
reg = <0x120 0x1C4>;
112-
clock-output-names = "cpu_6x4x",
113-
"cpu_3x2x",
114-
"cpu_2x",
115-
"cpu_1x";
76+
compatible = "xlnx,ps7-clkc";
77+
ps-clk-frequency = <33333333>;
78+
clock-output-names = "armpll", "ddrpll", "iopll", "cpu_6or4x",
79+
"cpu_3or2x", "cpu_2x", "cpu_1x", "ddr2x", "ddr3x",
80+
"dci", "lqspi", "smc", "pcap", "gem0", "gem1",
81+
"fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1",
82+
"sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1",
83+
"dma", "usb0_aper", "usb1_aper", "gem0_aper",
84+
"gem1_aper", "sdio0_aper", "sdio1_aper",
85+
"spi0_aper", "spi1_aper", "can0_aper", "can1_aper",
86+
"i2c0_aper", "i2c1_aper", "uart0_aper", "uart1_aper",
87+
"gpio_aper", "lqspi_aper", "smc_aper", "swdt",
88+
"dbg_trc", "dbg_apb";
11689
};
11790
};
11891
};
@@ -121,27 +94,25 @@
12194
interrupt-parent = <&intc>;
12295
interrupts = < 0 10 4 0 11 4 0 12 4 >;
12396
compatible = "cdns,ttc";
97+
clocks = <&clkc 6>;
12498
reg = <0xF8001000 0x1000>;
125-
clocks = <&cpu_clk 3>;
126-
clock-names = "cpu_1x";
12799
clock-ranges;
128100
};
129101

130102
ttc1: ttc1@f8002000 {
131103
interrupt-parent = <&intc>;
132104
interrupts = < 0 37 4 0 38 4 0 39 4 >;
133105
compatible = "cdns,ttc";
106+
clocks = <&clkc 6>;
134107
reg = <0xF8002000 0x1000>;
135-
clocks = <&cpu_clk 3>;
136-
clock-names = "cpu_1x";
137108
clock-ranges;
138109
};
139110
scutimer: scutimer@f8f00600 {
140111
interrupt-parent = <&intc>;
141112
interrupts = < 1 13 0x301 >;
142113
compatible = "arm,cortex-a9-twd-timer";
143114
reg = < 0xf8f00600 0x20 >;
144-
clocks = <&cpu_clk 1>;
115+
clocks = <&clkc 4>;
145116
} ;
146117
};
147118
};

‎arch/arm/boot/dts/zynq-zc702.dts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,3 @@
2828
};
2929

3030
};
31-
32-
&ps_clk {
33-
clock-frequency = <33333330>;
34-
};

‎arch/arm/mach-zynq/slcr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int __init zynq_slcr_init(void)
117117

118118
pr_info("%s mapped to %p\n", np->name, zynq_slcr_base);
119119

120-
xilinx_zynq_clocks_init(zynq_slcr_base);
120+
zynq_clock_init(zynq_slcr_base);
121121

122122
of_node_put(np);
123123

‎drivers/clk/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ obj-$(CONFIG_MACH_LOONGSON1) += clk-ls1x.o
2727
obj-$(CONFIG_ARCH_SUNXI) += sunxi/
2828
obj-$(CONFIG_ARCH_U8500) += ux500/
2929
obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
30-
obj-$(CONFIG_ARCH_ZYNQ) += clk-zynq.o
30+
obj-$(CONFIG_ARCH_ZYNQ) += zynq/
3131
obj-$(CONFIG_ARCH_TEGRA) += tegra/
3232
obj-$(CONFIG_PLAT_SAMSUNG) += samsung/
3333

‎drivers/clk/zynq/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Zynq clock specific Makefile
2+
3+
obj-$(CONFIG_ARCH_ZYNQ) += clkc.o pll.o

‎drivers/clocksource/cadence_ttc_timer.c‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
#define TTC_CNT_CNTRL_DISABLE_MASK 0x1
5353

54+
#define TTC_CLK_CNTRL_CSRC_MASK (1 << 5) /* clock source */
55+
5456
/*
5557
* Setup the timers to use pre-scaling, using a fixed value for now that will
5658
* work across most input frequency, but it may need to be more dynamic
@@ -396,8 +398,9 @@ static void __init ttc_timer_init(struct device_node *timer)
396398
{
397399
unsigned int irq;
398400
void __iomem *timer_baseaddr;
399-
struct clk *clk;
401+
struct clk *clk_cs, *clk_ce;
400402
static int initialized;
403+
int clksel;
401404

402405
if (initialized)
403406
return;
@@ -421,14 +424,24 @@ static void __init ttc_timer_init(struct device_node *timer)
421424
BUG();
422425
}
423426

424-
clk = of_clk_get_by_name(timer, "cpu_1x");
425-
if (IS_ERR(clk)) {
427+
clksel = __raw_readl(timer_baseaddr + TTC_CLK_CNTRL_OFFSET);
428+
clksel = !!(clksel & TTC_CLK_CNTRL_CSRC_MASK);
429+
clk_cs = of_clk_get(timer, clksel);
430+
if (IS_ERR(clk_cs)) {
431+
pr_err("ERROR: timer input clock not found\n");
432+
BUG();
433+
}
434+
435+
clksel = __raw_readl(timer_baseaddr + 4 + TTC_CLK_CNTRL_OFFSET);
436+
clksel = !!(clksel & TTC_CLK_CNTRL_CSRC_MASK);
437+
clk_ce = of_clk_get(timer, clksel);
438+
if (IS_ERR(clk_ce)) {
426439
pr_err("ERROR: timer input clock not found\n");
427440
BUG();
428441
}
429442

430-
ttc_setup_clocksource(clk, timer_baseaddr);
431-
ttc_setup_clockevent(clk, timer_baseaddr + 4, irq);
443+
ttc_setup_clocksource(clk_cs, timer_baseaddr);
444+
ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
432445

433446
pr_info("%s #0 at %p, irq=%d\n", timer->name, timer_baseaddr, irq);
434447
}

‎drivers/tty/serial/xilinx_uartps.c‎

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/platform_device.h>
1515
#include <linux/serial.h>
1616
#include <linux/serial_core.h>
17+
#include <linux/slab.h>
1718
#include <linux/tty.h>
1819
#include <linux/tty_flip.h>
1920
#include <linux/console.h>
@@ -138,6 +139,16 @@
138139
#define XUARTPS_SR_TXFULL 0x00000010 /* TX FIFO full */
139140
#define XUARTPS_SR_RXTRIG 0x00000001 /* Rx Trigger */
140141

142+
/**
143+
* struct xuartps - device data
144+
* @refclk Reference clock
145+
* @aperclk APB clock
146+
*/
147+
struct xuartps {
148+
struct clk *refclk;
149+
struct clk *aperclk;
150+
};
151+
141152
/**
142153
* xuartps_isr - Interrupt handler
143154
* @irq: Irq number
@@ -936,34 +947,55 @@ static int xuartps_probe(struct platform_device *pdev)
936947
int rc;
937948
struct uart_port *port;
938949
struct resource *res, *res2;
939-
struct clk *clk;
950+
struct xuartps *xuartps_data;
940951

941-
clk = of_clk_get(pdev->dev.of_node, 0);
942-
if (IS_ERR(clk)) {
943-
dev_err(&pdev->dev, "no clock specified\n");
944-
return PTR_ERR(clk);
952+
xuartps_data = kzalloc(sizeof(*xuartps_data), GFP_KERNEL);
953+
if (!xuartps_data)
954+
return -ENOMEM;
955+
956+
xuartps_data->aperclk = clk_get(&pdev->dev, "aper_clk");
957+
if (IS_ERR(xuartps_data->aperclk)) {
958+
dev_err(&pdev->dev, "aper_clk clock not found.\n");
959+
rc = PTR_ERR(xuartps_data->aperclk);
960+
goto err_out_free;
961+
}
962+
xuartps_data->refclk = clk_get(&pdev->dev, "ref_clk");
963+
if (IS_ERR(xuartps_data->refclk)) {
964+
dev_err(&pdev->dev, "ref_clk clock not found.\n");
965+
rc = PTR_ERR(xuartps_data->refclk);
966+
goto err_out_clk_put_aper;
945967
}
946968

947-
rc = clk_prepare_enable(clk);
969+
rc = clk_prepare_enable(xuartps_data->aperclk);
970+
if (rc) {
971+
dev_err(&pdev->dev, "Unable to enable APER clock.\n");
972+
goto err_out_clk_put;
973+
}
974+
rc = clk_prepare_enable(xuartps_data->refclk);
948975
if (rc) {
949-
dev_err(&pdev->dev, "could not enable clock\n");
950-
return -EBUSY;
976+
dev_err(&pdev->dev, "Unable to enable device clock.\n");
977+
goto err_out_clk_dis_aper;
951978
}
952979

953980
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
954-
if (!res)
955-
return -ENODEV;
981+
if (!res) {
982+
rc = -ENODEV;
983+
goto err_out_clk_disable;
984+
}
956985

957986
res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
958-
if (!res2)
959-
return -ENODEV;
987+
if (!res2) {
988+
rc = -ENODEV;
989+
goto err_out_clk_disable;
990+
}
960991

961992
/* Initialize the port structure */
962993
port = xuartps_get_port();
963994

964995
if (!port) {
965996
dev_err(&pdev->dev, "Cannot get uart_port structure\n");
966-
return -ENODEV;
997+
rc = -ENODEV;
998+
goto err_out_clk_disable;
967999
} else {
9681000
/* Register the port.
9691001
* This function also registers this device with the tty layer
@@ -972,18 +1004,31 @@ static int xuartps_probe(struct platform_device *pdev)
9721004
port->mapbase = res->start;
9731005
port->irq = res2->start;
9741006
port->dev = &pdev->dev;
975-
port->uartclk = clk_get_rate(clk);
976-
port->private_data = clk;
1007+
port->uartclk = clk_get_rate(xuartps_data->refclk);
1008+
port->private_data = xuartps_data;
9771009
dev_set_drvdata(&pdev->dev, port);
9781010
rc = uart_add_one_port(&xuartps_uart_driver, port);
9791011
if (rc) {
9801012
dev_err(&pdev->dev,
9811013
"uart_add_one_port() failed; err=%i\n", rc);
9821014
dev_set_drvdata(&pdev->dev, NULL);
983-
return rc;
1015+
goto err_out_clk_disable;
9841016
}
9851017
return 0;
9861018
}
1019+
1020+
err_out_clk_disable:
1021+
clk_disable_unprepare(xuartps_data->refclk);
1022+
err_out_clk_dis_aper:
1023+
clk_disable_unprepare(xuartps_data->aperclk);
1024+
err_out_clk_put:
1025+
clk_put(xuartps_data->refclk);
1026+
err_out_clk_put_aper:
1027+
clk_put(xuartps_data->aperclk);
1028+
err_out_free:
1029+
kfree(xuartps_data);
1030+
1031+
return rc;
9871032
}
9881033

9891034
/**
@@ -995,14 +1040,18 @@ static int xuartps_probe(struct platform_device *pdev)
9951040
static int xuartps_remove(struct platform_device *pdev)
9961041
{
9971042
struct uart_port *port = dev_get_drvdata(&pdev->dev);
998-
struct clk *clk = port->private_data;
1043+
struct xuartps *xuartps_data = port->private_data;
9991044
int rc;
10001045

10011046
/* Remove the xuartps port from the serial core */
10021047
rc = uart_remove_one_port(&xuartps_uart_driver, port);
10031048
dev_set_drvdata(&pdev->dev, NULL);
10041049
port->mapbase = 0;
1005-
clk_disable_unprepare(clk);
1050+
clk_disable_unprepare(xuartps_data->refclk);
1051+
clk_disable_unprepare(xuartps_data->aperclk);
1052+
clk_put(xuartps_data->refclk);
1053+
clk_put(xuartps_data->aperclk);
1054+
kfree(xuartps_data);
10061055
return rc;
10071056
}
10081057

‎include/linux/clk/zynq.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (C) 2013 Xilinx Inc.
23
* Copyright (C) 2012 National Instruments
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -19,6 +20,11 @@
1920
#ifndef __LINUX_CLK_ZYNQ_H_
2021
#define __LINUX_CLK_ZYNQ_H_
2122

22-
void __init xilinx_zynq_clocks_init(void __iomem *slcr);
23+
#include <linux/spinlock.h>
2324

25+
void zynq_clock_init(void __iomem *slcr);
26+
27+
struct clk *clk_register_zynq_pll(const char *name, const char *parent,
28+
void __iomem *pll_ctrl, void __iomem *pll_status, u8 lock_index,
29+
spinlock_t *lock);
2430
#endif

0 commit comments

Comments
 (0)