clk: at91: Add clock driver
PATCH v4 1/1 clk: at91: Add clock driver
The patch is referred to at91 clock driver of Linux, to make the clock node descriptions in DT aligned with the Linux's.
---
Changes in v4:
- Add Reviewed-by tag.
- Add more information in Kconfig help.
- Use u32 for num_parents variable, not u8.
- Change the check return from clk_get_rate().
- Remove return -ENODEV line, use return ret.
- Improve the comments in at91_system_clk_enable().
Changes in v3:
- Update based on [PATCH] clk: convert API to match reset/mailbox style (http://patchwork.ozlabs.org/patch/625342/).
- Remove [PATCH] clk: clk-uclass: Add post binding for CLK uclass, add bind() method to bind the clk node without compatible.
- Add help for Kconfig HAVE_AT91_XX option.
- Add ofdata_to_platdata() method for generated clock driver to handle the device tree.
- Use setbits_le32() to replace readl()/writel().
- Fixed the return value, -ENODEV->-EINVAL.
- Use dev_get_addr_ptr() to replace dev_get_addr().
- Remove check on dev_get_parent() return.
Changes in v2:
- Remove the redundant log print.
arch/arm/mach-at91/include/mach/at91_pmc.h | 11 +- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/at91/Kconfig | 40 +++++++ drivers/clk/at91/Makefile | 11 ++ drivers/clk/at91/clk-generated.c | 162 +++++++++++++++++++++++++++++ drivers/clk/at91/clk-h32mx.c | 56 ++++++++++ drivers/clk/at91/clk-main.c | 55 ++++++++++ drivers/clk/at91/clk-master.c | 33 ++++++ drivers/clk/at91/clk-peripheral.c | 60 +++++++++++ drivers/clk/at91/clk-plla.c | 55 ++++++++++ drivers/clk/at91/clk-slow.c | 37 +++++++ drivers/clk/at91/clk-system.c | 76 ++++++++++++++ drivers/clk/at91/clk-utmi.c | 67 ++++++++++++ drivers/clk/at91/pmc.c | 71 +++++++++++++ drivers/clk/at91/pmc.h | 18 ++++ drivers/clk/at91/sckc.c | 30 ++++++ 17 files changed, 781 insertions(+), 3 deletions(-) create mode 100644 drivers/clk/at91/Kconfig create mode 100644 drivers/clk/at91/Makefile create mode 100644 drivers/clk/at91/clk-generated.c create mode 100644 drivers/clk/at91/clk-h32mx.c create mode 100644 drivers/clk/at91/clk-main.c create mode 100644 drivers/clk/at91/clk-master.c create mode 100644 drivers/clk/at91/clk-peripheral.c create mode 100644 drivers/clk/at91/clk-plla.c create mode 100644 drivers/clk/at91/clk-slow.c create mode 100644 drivers/clk/at91/clk-system.c create mode 100644 drivers/clk/at91/clk-utmi.c create mode 100644 drivers/clk/at91/pmc.c create mode 100644 drivers/clk/at91/pmc.h create mode 100644 drivers/clk/at91/sckc.c
arch/arm/mach-at91/include/mach/at91_pmc.h +8 -3
@@ -149,6 +149,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_PID_MASK (0x3f)#define AT91_PMC_PCR_GCKCSS (0x7 << 8) +#define AT91_PMC_PCR_GCKCSS_MASK 0x07 +#define AT91_PMC_PCR_GCKCSS_OFFSET 8 +#define AT91_PMC_PCR_GCKCSS_ (x) ((x & 0x07) << 8)#define AT91_PMC_PCR_GCKCSS_SLOW_CLK (0x0 << 8)#define AT91_PMC_PCR_GCKCSS_MAIN_CLK (0x1 << 8)#define AT91_PMC_PCR_GCKCSS_PLLA_CLK (0x2 << 8)
@@ -158,8 +161,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCR_CMD_WRITE (0x1 << 12)#define AT91_PMC_PCR_DIV (0x3 << 16)#define AT91_PMC_PCR_GCKDIV (0xff << 20) -#define AT91_PMC_PCR_GCKDIV_ (x) (((x) & 0xff) << 20) -#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_MASK 0xff +#define AT91_PMC_PCR_GCKDIV_OFFSET 20 +#define AT91_PMC_PCR_GCKDIV_ (x) ((x & 0xff) << 20)#define AT91_PMC_PCR_EN (0x1 << 28)#define AT91_PMC_PCR_GCKEN (0x1 << 29)
@@ -243,8 +247,9 @@ typedef struct at91_pmc {#define AT91_PMC_PCK1RDY (1 << 9)/* Programmable Clock 1 */ #define AT91_PMC_PCK2RDY (1 << 10)/* Programmable Clock 2 */ #define AT91_PMC_PCK3RDY (1 << 11)/* Programmable Clock 3 */ +#define AT91_PMC_MOSCSELS BIT(16)/* Main Oscillator Selection Status */ +#define AT91_PMC_MOSCRCS BIT(17)/* 12 MHz RC Oscillator Status */ #define AT91_PMC_GCKRDY (1 << 24) -#define AT91_PMC_PROTKEY 0x504d4301/* Activation Code */ /* PLL Charge Pump Current Register (PMC_PLLICPR) */
drivers/clk/Kconfig +1 -0
@@ -22,5 +22,6 @@ config SPL_CLK source "drivers/clk/uniphier/Kconfig" source "drivers/clk/exynos/Kconfig" +source "drivers/clk/at91/Kconfig" endmenu
drivers/clk/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o obj-$(CONFIG_MACH_PIC32) += clk_pic32.o obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ obj-$(CONFIG_CLK_EXYNOS) += exynos/ +obj-$(CONFIG_CLK_AT91) += at91/
drivers/clk/at91/Kconfig new file +40 -0
@@ -0,0 +1,40 @@ +config CLK_AT91 + bool "AT91 clock drivers" + depends on CLK + help + This option is used to enable the AT91 clock driver. + The driver supports the AT91 clock generator, including + the oscillators and PLLs, such as main clock, slow clock, + PLLA, UTMI PLL. Clocks can also be a source clock of other + clocks a tree structure, such as master clock, usb device + clock, matrix clock and generated clock. + Devices can use a common clock API to request a particular + clock, enable it and get its rate. + +config HAVE_AT91_UTMI + bool + help + This option is used to enable the AT91 UTMI PLL clock + driver. It is the clock provider of USB, and UPLLCK is the + output of 480 MHz UTMI PLL, The souce clock of the UTMI + PLL is the main clock, so the main clock must select the + fast crystal oscillator to meet the frequency accuracy + required by USB. + +config HAVE_AT91_H32MX + bool + help + This option is used to enable the AT91 H32MX matrixes + clock driver. There are H64MX and H32MX matrixes clocks, + H64MX 64-bit matrix clocks are MCK. The H32MX 32-bit + matrix clock is to be configured as MCK if MCK does not + exceed 83 MHz, else it is to be configured as MCK/2. + +config HAVE_AT91_GENERATED_CLK + bool + help + This option is used to enable the AT91 generated clock + driver. Some peripherals may need a second clock source + that may be different from the system clock. This second + clock is the generated clock (GCLK) and is managed by + the PMC via PMC_PCR register.
drivers/clk/at91/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# +# Makefile for at91 specific clk +# + +obj-y += pmc.o sckc.o +obj-y += clk-slow.o clk-main.o clk-plla.o clk-master.o +obj-y += clk-system.o clk-peripheral.o + +obj-$(CONFIG_HAVE_AT91_UTMI) += clk-utmi.o +obj-$(CONFIG_HAVE_AT91_H32MX) += clk-h32mx.o +obj-$(CONFIG_HAVE_AT91_GENERATED_CLK) += clk-generated.o
drivers/clk/at91/clk-generated.c new file +162 -0
162 lines not on this page · raw message
drivers/clk/at91/clk-h32mx.c new file +56 -0
56 lines not on this page · raw message
drivers/clk/at91/clk-main.c new file +55 -0
55 lines not on this page · raw message
drivers/clk/at91/clk-master.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk_uclass.h> +#include <dm/device.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static ulong at91_master_clk_get_rate (struct clk *clk) +{ +return gd->arch.mck_rate_hz; +} + +static struct clk_ops at91_master_clk_ops = { + .get_rate = at91_master_clk_get_rate, +}; + +static const struct udevice_id at91_master_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-master" }, + {} +}; + +U_BOOT_DRIVER (at91_master_clk) = { + .name ="at91-master-clk" , + .id =UCLASS_CLK , + .of_match = at91_master_clk_match, + .ops = &at91_master_clk_ops, +};
drivers/clk/at91/clk-peripheral.c new file +60 -0
60 lines not on this page · raw message
drivers/clk/at91/clk-plla.c new file +55 -0
55 lines not on this page · raw message
drivers/clk/at91/clk-slow.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk_uclass.h> +#include <dm/device.h> + +static int at91_slow_clk_enable (struct clk *clk) +{ +return 0 ; +} + +static ulong at91_slow_clk_get_rate (struct clk *clk) +{ +return CONFIG_SYS_AT91_SLOW_CLOCK ; +} + +static struct clk_ops at91_slow_clk_ops = { + .enable = at91_slow_clk_enable, + .get_rate = at91_slow_clk_get_rate, +}; + +static const struct udevice_id at91_slow_clk_match[] = { + { .compatible ="atmel,at91sam9x5-clk-slow" }, + {} +}; + +U_BOOT_DRIVER (at91_slow_clk) = { + .name ="at91-slow-clk" , + .id =UCLASS_CLK , + .of_match = at91_slow_clk_match, + .ops = &at91_slow_clk_ops, +};
drivers/clk/at91/clk-system.c new file +76 -0
76 lines not on this page · raw message
drivers/clk/at91/clk-utmi.c new file +67 -0
67 lines not on this page · raw message
drivers/clk/at91/pmc.c new file +71 -0
71 lines not on this page · raw message
drivers/clk/at91/pmc.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __AT91_PMC_H__ +#define __AT91_PMC_H__ + +struct pmc_platdata { +struct at91_pmc *reg_base; +}; + +int at91_pmc_core_probe (struct udevice *dev); +int at91_pmc_clk_node_bind (struct udevice *dev); + +#endif
drivers/clk/at91/sckc.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2016 Atmel Corporation +* Wenyou.Yang <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <clk_uclass.h> +#include <dm/device.h> +#include <dm/root.h> + +DECLARE_GLOBAL_DATA_PTR ; + +static int at91_sckc_clk_bind (struct udevice *dev) +{ +return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, false); +} + +static const struct udevice_id at91_sckc_clk_match[] = { + { .compatible ="atmel,at91sam9x5-sckc" }, + {} +}; + +U_BOOT_DRIVER (at91_sckc_clk) = { + .name ="at91_sckc_clk" , + .id =UCLASS_CLK , + .of_match = at91_sckc_clk_match, + .bind = at91_sckc_clk_bind, +};
Signature · 1 line
2.7.4