blob: c1d5c4ecdd81b8085ab8b53d623ab19c0329e095 [file] [log] [blame]
Robert Markoe479a7d2020-07-06 10:37:54 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Clock drivers for Qualcomm IPQ40xx
4 *
Robert Marko96d60362020-10-08 22:05:10 +02005 * Copyright (c) 2020 Sartura Ltd.
Robert Markoe479a7d2020-07-06 10:37:54 +02006 *
7 * Author: Robert Marko <robert.marko@sartura.hr>
8 *
9 */
10
Robert Markoe479a7d2020-07-06 10:37:54 +020011#include <clk-uclass.h>
Robert Marko90534532020-10-28 13:56:23 +010012#include <common.h>
Robert Markoe479a7d2020-07-06 10:37:54 +020013#include <dm.h>
14#include <errno.h>
15
Robert Marko5ae15412020-09-10 16:00:00 +020016#include <dt-bindings/clock/qcom,ipq4019-gcc.h>
17
Robert Markoe479a7d2020-07-06 10:37:54 +020018struct msm_clk_priv {
19 phys_addr_t base;
20};
21
22ulong msm_set_rate(struct clk *clk, ulong rate)
23{
24 switch (clk->id) {
Robert Marko5ae15412020-09-10 16:00:00 +020025 case GCC_BLSP1_UART1_APPS_CLK: /*UART1*/
Robert Markoe479a7d2020-07-06 10:37:54 +020026 /* This clock is already initialized by SBL1 */
Robert Marko96d60362020-10-08 22:05:10 +020027 return 0;
Robert Markoe479a7d2020-07-06 10:37:54 +020028 default:
Robert Marko20476b52020-10-28 13:56:25 +010029 return -EINVAL;
Robert Markoe479a7d2020-07-06 10:37:54 +020030 }
31}
32
33static int msm_clk_probe(struct udevice *dev)
34{
35 struct msm_clk_priv *priv = dev_get_priv(dev);
36
Robert Marko90534532020-10-28 13:56:23 +010037 priv->base = dev_read_addr(dev);
Robert Markoe479a7d2020-07-06 10:37:54 +020038 if (priv->base == FDT_ADDR_T_NONE)
39 return -EINVAL;
40
41 return 0;
42}
43
44static ulong msm_clk_set_rate(struct clk *clk, ulong rate)
45{
46 return msm_set_rate(clk, rate);
47}
48
Robert Marko96d60362020-10-08 22:05:10 +020049static int msm_enable(struct clk *clk)
50{
51 switch (clk->id) {
52 case GCC_BLSP1_QUP1_SPI_APPS_CLK: /*SPI1*/
53 /* This clock is already initialized by SBL1 */
54 return 0;
Robert Markocfec8d32020-10-08 22:05:14 +020055 case GCC_PRNG_AHB_CLK: /*PRNG*/
56 /* This clock is already initialized by SBL1 */
57 return 0;
Robert Markoa282ada2020-10-28 13:56:26 +010058 case GCC_USB3_MASTER_CLK:
59 case GCC_USB3_SLEEP_CLK:
60 case GCC_USB3_MOCK_UTMI_CLK:
61 case GCC_USB2_MASTER_CLK:
62 case GCC_USB2_SLEEP_CLK:
63 case GCC_USB2_MOCK_UTMI_CLK:
64 /* These clocks is already initialized by SBL1 */
65 return 0;
Robert Marko96d60362020-10-08 22:05:10 +020066 default:
Robert Marko20476b52020-10-28 13:56:25 +010067 return -EINVAL;
Robert Marko96d60362020-10-08 22:05:10 +020068 }
69}
70
Robert Markoe479a7d2020-07-06 10:37:54 +020071static struct clk_ops msm_clk_ops = {
72 .set_rate = msm_clk_set_rate,
Robert Marko96d60362020-10-08 22:05:10 +020073 .enable = msm_enable,
Robert Markoe479a7d2020-07-06 10:37:54 +020074};
75
76static const struct udevice_id msm_clk_ids[] = {
77 { .compatible = "qcom,gcc-ipq4019" },
78 { }
79};
80
81U_BOOT_DRIVER(clk_msm) = {
82 .name = "clk_msm",
83 .id = UCLASS_CLK,
84 .of_match = msm_clk_ids,
85 .ops = &msm_clk_ops,
Simon Glass41575d82020-12-03 16:55:17 -070086 .priv_auto = sizeof(struct msm_clk_priv),
Robert Markoe479a7d2020-07-06 10:37:54 +020087 .probe = msm_clk_probe,
88};