kernel: bump 4.9 to 4.9.65
[oweals/openwrt.git] / target / linux / ramips / patches-4.9 / 0200-linkit_bootstrap.patch
1 --- a/drivers/misc/Makefile
2 +++ b/drivers/misc/Makefile
3 @@ -54,6 +54,7 @@ obj-$(CONFIG_ECHO)            += echo/
4  obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
5  obj-$(CONFIG_CXL_BASE)         += cxl/
6  obj-$(CONFIG_PANEL)             += panel.o
7 +obj-$(CONFIG_SOC_MT7620)       += linkit.o
8  
9  lkdtm-$(CONFIG_LKDTM)          += lkdtm_core.o
10  lkdtm-$(CONFIG_LKDTM)          += lkdtm_bugs.o
11 --- /dev/null
12 +++ b/drivers/misc/linkit.c
13 @@ -0,0 +1,84 @@
14 +/*
15 + *  This program is free software; you can redistribute it and/or modify
16 + *  it under the terms of the GNU General Public License version 2 as
17 + *  publishhed by the Free Software Foundation.
18 + *
19 + *  Copyright (C) 2015 John Crispin <blogic@openwrt.org>
20 + */
21 +
22 +#include <linux/module.h>
23 +#include <linux/platform_device.h>
24 +#include <linux/of.h>
25 +#include <linux/mtd/mtd.h>
26 +#include <linux/gpio.h>
27 +
28 +#define LINKIT_LATCH_GPIO      11
29 +
30 +struct linkit_hw_data {
31 +       char board[16];
32 +       char rev[16];
33 +};
34 +
35 +static void sanify_string(char *s)
36 +{
37 +       int i;
38 +
39 +       for (i = 0; i < 15; i++)
40 +               if (s[i] <= 0x20)
41 +                       s[i] = '\0';
42 +       s[15] = '\0';
43 +}
44 +
45 +static int linkit_probe(struct platform_device *pdev)
46 +{
47 +       struct linkit_hw_data hw;
48 +       struct mtd_info *mtd;
49 +       size_t retlen;
50 +       int ret;
51 +
52 +       mtd = get_mtd_device_nm("factory");
53 +       if (IS_ERR(mtd))
54 +               return PTR_ERR(mtd);
55 +
56 +       ret = mtd_read(mtd, 0x400, sizeof(hw), &retlen, (u_char *) &hw);
57 +       put_mtd_device(mtd);
58 +
59 +       sanify_string(hw.board);
60 +       sanify_string(hw.rev);
61 +
62 +       dev_info(&pdev->dev, "Version  : %s\n", hw.board);
63 +       dev_info(&pdev->dev, "Revision : %s\n", hw.rev);
64 +
65 +       if (!strcmp(hw.board, "LINKITS7688")) {
66 +               dev_info(&pdev->dev, "setting up bootstrap latch\n");
67 +
68 +               if (devm_gpio_request(&pdev->dev, LINKIT_LATCH_GPIO, "bootstrap")) {
69 +                       dev_err(&pdev->dev, "failed to setup bootstrap gpio\n");
70 +                       return -1;
71 +               }
72 +               gpio_direction_output(LINKIT_LATCH_GPIO, 0);
73 +       }
74 +
75 +       return 0;
76 +}
77 +
78 +static const struct of_device_id linkit_match[] = {
79 +       { .compatible = "mediatek,linkit" },
80 +       {},
81 +};
82 +MODULE_DEVICE_TABLE(of, linkit_match);
83 +
84 +static struct platform_driver linkit_driver = {
85 +       .probe = linkit_probe,
86 +       .driver = {
87 +               .name = "mtk-linkit",
88 +               .owner = THIS_MODULE,
89 +               .of_match_table = linkit_match,
90 +       },
91 +};
92 +
93 +int __init linkit_init(void)
94 +{
95 +       return platform_driver_register(&linkit_driver);
96 +}
97 +late_initcall_sync(linkit_init);