0200-linkit_bootstrap.patch 2.2 KB

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