1b01fb15669b825b727e0179f6d231a78242e505
[AGL/meta-agl-demo.git] / recipes-kernel / most / files / 0008-dim2-read-clock-speed-from-the-device-tree.patch
1 From 839ad403a2d8081a6c15f6fc2836b01919338f3c Mon Sep 17 00:00:00 2001
2 From: Andrey Shvetsov <andrey.shvetsov@k2l.de>
3 Date: Mon, 12 Feb 2018 12:24:37 +0100
4 Subject: [PATCH] staging: most: dim2: read clock speed from the device tree
5
6 This implements reading of the clock speed parameter from the device
7 tree.
8
9 Signed-off-by: Andrey Shvetsov <andrey.shvetsov@k2l.de>
10 ---
11  Documentation/devicetree/bindings/inic/microchip,inic-dim2.txt | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12  hdm-dim2/dim2_hdm.c                       | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
13  2 files changed, 113 insertions(+), 1 deletion(-)
14  create mode 100644 Documentation/devicetree/bindings/inic/microchip,inic-dim2.txt
15
16 diff --git a/hdm-dim2/dim2_hdm.c b/hdm-dim2/dim2_hdm.c
17 index 2dba917..05e1896 100644
18 --- a/hdm-dim2/dim2_hdm.c
19 +++ b/hdm-dim2/dim2_hdm.c
20 @@ -698,6 +698,42 @@ static void dma_free(struct mbo *mbo, u32 size)
21
22  static const struct of_device_id dim2_of_match[];
23
24 +static struct {
25 +       const char *clock_speed;
26 +       u8 clk_speed;
27 +} clk_mt[] = {
28 +       { "256fs", CLK_256FS },
29 +       { "512fs", CLK_512FS },
30 +       { "1024fs", CLK_1024FS },
31 +       { "2048fs", CLK_2048FS },
32 +       { "3072fs", CLK_3072FS },
33 +       { "4096fs", CLK_4096FS },
34 +       { "6144fs", CLK_6144FS },
35 +       { "8192fs", CLK_8192FS },
36 +};
37 +
38 +/**
39 + * get_dim2_clk_speed - converts string to DIM2 clock speed value
40 + *
41 + * @clock_speed: string in the format "{NUMBER}fs"
42 + * @val: pointer to get one of the CLK_{NUMBER}FS values
43 + *
44 + * By success stores one of the CLK_{NUMBER}FS in the *val and returns 0,
45 + * otherwise returns -EINVAL.
46 + */
47 +static int get_dim2_clk_speed(const char *clock_speed, u8 *val)
48 +{
49 +       int i;
50 +
51 +       for (i = 0; i < ARRAY_SIZE(clk_mt); i++) {
52 +               if (!strcmp(clock_speed, clk_mt[i].clock_speed)) {
53 +                       *val = clk_mt[i].clk_speed;
54 +                       return 0;
55 +               }
56 +       }
57 +       return -EINVAL;
58 +}
59 +
60  /*
61   * dim2_probe - dim2 probe handler
62   * @pdev: platform device structure
63 @@ -708,6 +744,7 @@ static const struct of_device_id dim2_of_match[];
64  static int dim2_probe(struct platform_device *pdev)
65  {
66         const struct dim2_platform_data *pdata;
67 +       const char *clock_speed;
68         struct dim2_hdm *dev;
69         struct resource *res;
70         int ret, i;
71 @@ -725,7 +762,18 @@ static int dim2_probe(struct platform_device *pdev)
72
73         platform_set_drvdata(pdev, dev);
74
75 -       dev->clk_speed = CLK_4096FS;
76 +       ret = of_property_read_string(pdev->dev.of_node,
77 +                                     "microchip,clock-speed", &clock_speed);
78 +       if (ret) {
79 +               dev_err(&pdev->dev, "missing dt property clock-speed\n");
80 +               return ret;
81 +       }
82 +
83 +       ret = get_dim2_clk_speed(clock_speed, &dev->clk_speed);
84 +       if (ret) {
85 +               dev_err(&pdev->dev, "bad dt property clock-speed\n");
86 +               return ret;
87 +       }
88
89         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90         dev->io_base = devm_ioremap_resource(&pdev->dev, res);
91 --
92 libgit2 0.26.0