blob: eb37416b5e0dd1ba84d0bc873c1696722fc96476 [file] [log] [blame]
Bin Mengeb195bd2019-05-22 00:09:44 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019, Bin Meng <bmeng.cn@gmail.com>
4 */
5
6#include <common.h>
7#include <clk-uclass.h>
8#include <dm.h>
9#include <asm/io.h>
10
11struct gemgxl_mgmt_regs {
12 __u32 tx_clk_sel;
13};
14
15struct gemgxl_mgmt_platdata {
16 struct gemgxl_mgmt_regs *regs;
17};
18
19static int gemgxl_mgmt_ofdata_to_platdata(struct udevice *dev)
20{
21 struct gemgxl_mgmt_platdata *plat = dev_get_platdata(dev);
22
23 plat->regs = (struct gemgxl_mgmt_regs *)dev_read_addr(dev);
24
25 return 0;
26}
27
28static ulong gemgxl_mgmt_set_rate(struct clk *clk, ulong rate)
29{
30 struct gemgxl_mgmt_platdata *plat = dev_get_platdata(clk->dev);
31
32 /*
33 * GEMGXL TX clock operation mode:
34 *
35 * 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic
36 * and output clock on GMII output signal GTX_CLK
37 * 1 = MII mode. Use MII input signal TX_CLK in TX logic
38 */
39 writel(rate != 125000000, &plat->regs->tx_clk_sel);
40
41 return 0;
42}
43
44const struct clk_ops gemgxl_mgmt_ops = {
45 .set_rate = gemgxl_mgmt_set_rate,
46};
47
48static const struct udevice_id gemgxl_mgmt_match[] = {
49 { .compatible = "sifive,cadencegemgxlmgmt0", },
50 { /* sentinel */ }
51};
52
53U_BOOT_DRIVER(sifive_gemgxl_mgmt) = {
54 .name = "sifive-gemgxl-mgmt",
55 .id = UCLASS_CLK,
56 .of_match = gemgxl_mgmt_match,
57 .ofdata_to_platdata = gemgxl_mgmt_ofdata_to_platdata,
58 .platdata_auto_alloc_size = sizeof(struct gemgxl_mgmt_platdata),
59 .ops = &gemgxl_mgmt_ops,
60};