1 /* 2 * (C) Copyright 2015 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0 5 */ 6 7 #include <common.h> 8 #include <clk.h> 9 #include <dm.h> 10 #include <errno.h> 11 #include <asm/test.h> 12 13 struct sandbox_clk_priv { 14 ulong rate; 15 ulong periph_rate[PERIPH_ID_COUNT]; 16 }; 17 18 static ulong sandbox_clk_get_rate(struct udevice *dev) 19 { 20 struct sandbox_clk_priv *priv = dev_get_priv(dev); 21 22 return priv->rate; 23 } 24 25 static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate) 26 { 27 struct sandbox_clk_priv *priv = dev_get_priv(dev); 28 29 if (!rate) 30 return -EINVAL; 31 priv->rate = rate; 32 return 0; 33 } 34 35 ulong sandbox_get_periph_rate(struct udevice *dev, int periph) 36 { 37 struct sandbox_clk_priv *priv = dev_get_priv(dev); 38 39 if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT) 40 return -EINVAL; 41 return priv->periph_rate[periph]; 42 } 43 44 ulong sandbox_set_periph_rate(struct udevice *dev, int periph, ulong rate) 45 { 46 struct sandbox_clk_priv *priv = dev_get_priv(dev); 47 ulong old_rate; 48 49 if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT) 50 return -EINVAL; 51 old_rate = priv->periph_rate[periph]; 52 priv->periph_rate[periph] = rate; 53 54 return old_rate; 55 } 56 57 static int sandbox_clk_probe(struct udevice *dev) 58 { 59 struct sandbox_clk_priv *priv = dev_get_priv(dev); 60 61 priv->rate = SANDBOX_CLK_RATE; 62 63 return 0; 64 } 65 66 static struct clk_ops sandbox_clk_ops = { 67 .get_rate = sandbox_clk_get_rate, 68 .set_rate = sandbox_clk_set_rate, 69 .get_periph_rate = sandbox_get_periph_rate, 70 .set_periph_rate = sandbox_set_periph_rate, 71 }; 72 73 static const struct udevice_id sandbox_clk_ids[] = { 74 { .compatible = "sandbox,clk" }, 75 { } 76 }; 77 78 U_BOOT_DRIVER(clk_sandbox) = { 79 .name = "clk_sandbox", 80 .id = UCLASS_CLK, 81 .of_match = sandbox_clk_ids, 82 .ops = &sandbox_clk_ops, 83 .priv_auto_alloc_size = sizeof(struct sandbox_clk_priv), 84 .probe = sandbox_clk_probe, 85 }; 86