1
0

platform.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #include <rtdevice.h>
  2. #include <string.h>
  3. #include "platform.h"
  4. #ifdef RT_USING_I2C
  5. #include "drv_i2c.h"
  6. #endif
  7. #ifdef RT_USING_SPI
  8. #include "drv_ssi.h"
  9. #endif
  10. #include "gd_gpio.h"
  11. #ifdef RT_USING_ADC
  12. #include "drv_adc.h"
  13. #endif
  14. #ifdef RT_USING_PWM
  15. #include "drv_pwm.h"
  16. #endif
  17. #ifdef RT_USING_WDT
  18. #include "drv_wdt.h"
  19. #endif
  20. #ifdef RT_USING_SDIO
  21. #include "drv_sdio.h"
  22. #endif
  23. struct gk_platform_device
  24. {
  25. char *name;
  26. void *private_data;
  27. };
  28. #ifdef RT_USING_I2C
  29. static struct gk_i2c_obj i2c0_obj = {
  30. .id = 0,
  31. .config = {
  32. .i2cInitParams.priority = 1,//!< Interrupt Request (IRQ) for more general interrupts
  33. .i2cInitParams.mode = 2,//!< Auto master mode.
  34. .i2cInitParams.gpioSclPinCh1 = -1,
  35. .i2cInitParams.gpioSdaPinCh1 = -1,
  36. .i2cInitParams.gpioSclPinCh2 = -1,
  37. .i2cInitParams.gpioSdaPinCh2 = -1,
  38. },
  39. };
  40. static struct gk_i2c_obj i2c1_obj = {
  41. .id = 1,
  42. .config = {
  43. .i2cInitParams.priority = 1,//!< Interrupt Request (IRQ) for more general interrupts
  44. .i2cInitParams.mode = 2,//!< Auto master mode.
  45. .i2cInitParams.gpioSclPinCh1 = -1,
  46. .i2cInitParams.gpioSdaPinCh1 = -1,
  47. .i2cInitParams.gpioSclPinCh2 = -1,
  48. .i2cInitParams.gpioSdaPinCh2 = -1,
  49. },
  50. };
  51. struct gk_platform_device plat_i2c0 = {
  52. .name = "i2c", .private_data = &i2c0_obj,
  53. };
  54. struct gk_platform_device plat_i2c1 = {
  55. .name = "i2c", .private_data = &i2c1_obj,
  56. };
  57. #endif
  58. #ifdef RT_USING_SPI
  59. static struct gk_spi_controller_data spi0_controller_data =
  60. {
  61. .id = 0,
  62. .total_slave = 1,
  63. .slave_cs_pin[0] = GD_GPIO_14,//AT25640B eeprom
  64. .slave_cs_pin[1] = GD_GPIO_NUM,
  65. };
  66. static struct gk_spi_controller_data spi1_controller_data =
  67. {
  68. .id = 1,
  69. .total_slave = 2,
  70. .slave_cs_pin[0] = GD_GPIO_13,//rgb_my280h45p01
  71. .slave_cs_pin[1] = GD_GPIO_18,//rgb_tpo990000072
  72. };
  73. struct gk_platform_device plat_spi0 =
  74. {
  75. .name = "spi", .private_data = &spi0_controller_data,
  76. };
  77. struct gk_platform_device plat_spi1 =
  78. {
  79. .name = "spi", .private_data = &spi1_controller_data,
  80. };
  81. #endif
  82. #ifdef RT_USING_WDT
  83. static struct wdt_driver wdt_obj = {
  84. .in_use = 0,
  85. };
  86. #endif
  87. #ifdef RT_USING_ADC
  88. static struct wrap_adc_obj adc_obj = {
  89. .id = 0, .active_channel_no = 0,
  90. };
  91. #endif
  92. #ifdef RT_USING_PWM
  93. static struct pwm_driver pwm_obj = {
  94. .pwm[0].id = 0, .pwm[0].gpio_id = GD_GPIO_42,
  95. };
  96. #endif
  97. struct gk_platform_device plat_pwm = {
  98. .name = "pwm", .private_data = &pwm_obj,
  99. };
  100. struct gk_platform_device plat_wdt = {
  101. .name = "wdt", .private_data = &wdt_obj,
  102. };
  103. struct gk_platform_device plat_adc = {
  104. .name = "adc", .private_data = &adc_obj,
  105. };
  106. #ifdef RT_USING_SDIO
  107. static struct gk_sdio_info sdio0 =
  108. {
  109. .id = 0,
  110. #ifdef GK7102C_JH
  111. .type = SDIO_DEVICE_TYPE_WIFI,
  112. #else
  113. .type = SDIO_DEVICE_TYPE_NORMAL,
  114. #endif
  115. };
  116. #ifdef CODEC_710XS
  117. static struct gk_sdio_info sdio1 =
  118. {
  119. .id = 1,
  120. .type = SDIO_DEVICE_TYPE_NORMAL,
  121. };
  122. #endif
  123. struct gk_platform_device plat_sdio0 = {
  124. .name = "gk-sdio", .private_data = &sdio0,
  125. };
  126. #ifdef CODEC_710XS
  127. struct gk_platform_device plat_sdio1 = {
  128. .name = "gk-sdio", .private_data = &sdio1,
  129. };
  130. #endif
  131. #endif
  132. const static struct gk_platform_device *platform_device[] = {
  133. #ifdef RT_USING_I2C
  134. &plat_i2c0,
  135. &plat_i2c1,
  136. #endif
  137. #ifdef RT_USING_SPI
  138. &plat_spi0,
  139. &plat_spi1,
  140. #endif
  141. #ifdef RT_USING_WDT
  142. &plat_wdt,
  143. #endif
  144. #ifdef RT_USING_ADC
  145. &plat_adc,
  146. #endif
  147. #ifdef RT_USING_PWM
  148. &plat_pwm,
  149. #endif
  150. #ifdef RT_USING_SDIO
  151. &plat_sdio0,
  152. #ifdef CODEC_710XS
  153. &plat_sdio1,
  154. #endif
  155. #endif
  156. };
  157. int gk_platform_driver_init(struct gk_platform_driver *plat_drv)
  158. {
  159. int i,ret = RT_EOK;
  160. int device_cnt = sizeof(platform_device) / sizeof(platform_device[0]);
  161. if(!plat_drv || !plat_drv->name || !plat_drv->probe)
  162. return -RT_EINVAL;
  163. for (i = 0; i < device_cnt; i++)
  164. {
  165. if (!strcmp(plat_drv->name, platform_device[i]->name))
  166. {
  167. ret = plat_drv->probe(platform_device[i]->private_data);
  168. }
  169. }
  170. return ret;
  171. }
  172. int gk_platform_driver_uninit(struct gk_platform_driver *plat_drv)
  173. {
  174. int i,ret = RT_EOK;
  175. int device_cnt = sizeof(platform_device) / sizeof(platform_device[0]);
  176. if(!plat_drv || !plat_drv->name || !plat_drv->probe)
  177. return -RT_EINVAL;
  178. for (i = 0; i < device_cnt; i++)
  179. {
  180. if (!strcmp(plat_drv->name, platform_device[i]->name))
  181. {
  182. ret = plat_drv->remove(platform_device[i]->private_data);
  183. }
  184. }
  185. return ret;
  186. }