rayddteam

Untitled

Dec 12th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.56 KB | None | 0 0
  1. --- ar71xx_gpio.c 2011-11-23 23:58:51.000000000 +0200
  2. +++ ar724x_gpio.c 2011-11-23 23:59:04.000000000 +0200
  3. @@ -27,11 +27,11 @@
  4. */
  5.  
  6. /*
  7. - * GPIO driver for AR71xx
  8. + * GPIO driver for AR724x
  9. */
  10.  
  11. #include <sys/cdefs.h>
  12. -__FBSDID("$FreeBSD: head/sys/mips/atheros/ar71xx_gpio.c 221518 2011-05-06 02:45:02Z adrian $");
  13. +__FBSDID("$FreeBSD$");
  14.  
  15. #include <sys/param.h>
  16. #include <sys/systm.h>
  17. @@ -47,60 +47,51 @@
  18. #include <machine/bus.h>
  19. #include <machine/resource.h>
  20. #include <mips/atheros/ar71xxreg.h>
  21. +#include <mips/atheros/ar724xreg.h>
  22. #include <mips/atheros/ar71xx_setup.h>
  23. -#include <mips/atheros/ar71xx_gpiovar.h>
  24. +#include <mips/atheros/ar724x_gpiovar.h>
  25.  
  26. #include "gpio_if.h"
  27.  
  28. #define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)
  29.  
  30. /*
  31. -struct ar71xx_gpio_pin {
  32. - const char *name;
  33. - int pin;
  34. - int flags;
  35. -};
  36. -static struct ar71xx_gpio_pin ar71xx_gpio_pins[] = {
  37. - { "RFled", 2, GPIO_PIN_OUTPUT},
  38. - { "SW4", 8, GPIO_PIN_INPUT},
  39. - { NULL, 0, 0},
  40. -};
  41. -*/
  42. -
  43. -/*
  44. * Helpers
  45. */
  46. -static void ar71xx_gpio_function_enable(struct ar71xx_gpio_softc *sc,
  47. +#if 0
  48. +static void ar724x_gpio_function_enable(struct ar724x_gpio_softc *sc,
  49. uint32_t mask);
  50. -static void ar71xx_gpio_function_disable(struct ar71xx_gpio_softc *sc,
  51. +static void ar724x_gpio_function_disable(struct ar724x_gpio_softc *sc,
  52. uint32_t mask);
  53. -static void ar71xx_gpio_pin_configure(struct ar71xx_gpio_softc *sc,
  54. +#endif
  55. +static void ar724x_gpio_pin_configure(struct ar724x_gpio_softc *sc,
  56. struct gpio_pin *pin, uint32_t flags);
  57.  
  58. /*
  59. * Driver stuff
  60. */
  61. -static int ar71xx_gpio_probe(device_t dev);
  62. -static int ar71xx_gpio_attach(device_t dev);
  63. -static int ar71xx_gpio_detach(device_t dev);
  64. -static int ar71xx_gpio_filter(void *arg);
  65. -static void ar71xx_gpio_intr(void *arg);
  66. +static int ar724x_gpio_probe(device_t dev);
  67. +static int ar724x_gpio_attach(device_t dev);
  68. +static int ar724x_gpio_detach(device_t dev);
  69. +static int ar724x_gpio_filter(void *arg);
  70. +static void ar724x_gpio_intr(void *arg);
  71.  
  72. /*
  73. * GPIO interface
  74. */
  75. -static int ar71xx_gpio_pin_max(device_t dev, int *maxpin);
  76. -static int ar71xx_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
  77. -static int ar71xx_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
  78. +static int ar724x_gpio_pin_max(device_t dev, int *maxpin);
  79. +static int ar724x_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
  80. +static int ar724x_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
  81. *flags);
  82. -static int ar71xx_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
  83. -static int ar71xx_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
  84. -static int ar71xx_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
  85. -static int ar71xx_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);
  86. -static int ar71xx_gpio_pin_toggle(device_t dev, uint32_t pin);
  87. +static int ar724x_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
  88. +static int ar724x_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
  89. +static int ar724x_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
  90. +static int ar724x_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);
  91. +static int ar724x_gpio_pin_toggle(device_t dev, uint32_t pin);
  92.  
  93. +#if 0
  94. static void
  95. -ar71xx_gpio_function_enable(struct ar71xx_gpio_softc *sc, uint32_t mask)
  96. +ar724x_gpio_function_enable(struct ar724x_gpio_softc *sc, uint32_t mask)
  97. {
  98. GPIO_LOCK(sc);
  99. GPIO_SET_BITS(sc, AR71XX_GPIO_FUNCTION, mask);
  100. @@ -108,15 +99,16 @@
  101. }
  102.  
  103. static void
  104. -ar71xx_gpio_function_disable(struct ar71xx_gpio_softc *sc, uint32_t mask)
  105. +ar724x_gpio_function_disable(struct ar724x_gpio_softc *sc, uint32_t mask)
  106. {
  107. GPIO_LOCK(sc);
  108. GPIO_CLEAR_BITS(sc, AR71XX_GPIO_FUNCTION, mask);
  109. GPIO_UNLOCK(sc);
  110. }
  111. +#endif
  112.  
  113. static void
  114. -ar71xx_gpio_pin_configure(struct ar71xx_gpio_softc *sc, struct gpio_pin *pin,
  115. +ar724x_gpio_pin_configure(struct ar724x_gpio_softc *sc, struct gpio_pin *pin,
  116. unsigned int flags)
  117. {
  118. uint32_t mask;
  119. @@ -143,29 +135,17 @@
  120. }
  121.  
  122. static int
  123. -ar71xx_gpio_pin_max(device_t dev, int *maxpin)
  124. +ar724x_gpio_pin_max(device_t dev, int *maxpin)
  125. {
  126.  
  127. - switch (ar71xx_soc) {
  128. - case AR71XX_SOC_AR9130:
  129. - case AR71XX_SOC_AR9132:
  130. - *maxpin = AR91XX_GPIO_PINS - 1;
  131. - break;
  132. - case AR71XX_SOC_AR7240:
  133. - case AR71XX_SOC_AR7241:
  134. - case AR71XX_SOC_AR7242:
  135. - *maxpin = AR724X_GPIO_PINS - 1;
  136. - break;
  137. - default:
  138. - *maxpin = AR71XX_GPIO_PINS - 1;
  139. - }
  140. + *maxpin = AR724X_GPIO_PINS - 1;
  141. return (0);
  142. }
  143.  
  144. static int
  145. -ar71xx_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
  146. +ar724x_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
  147. {
  148. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  149. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  150. int i;
  151.  
  152. for (i = 0; i < sc->gpio_npins; i++) {
  153. @@ -184,9 +164,9 @@
  154. }
  155.  
  156. static int
  157. -ar71xx_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
  158. +ar724x_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
  159. {
  160. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  161. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  162. int i;
  163.  
  164. for (i = 0; i < sc->gpio_npins; i++) {
  165. @@ -205,9 +185,9 @@
  166. }
  167.  
  168. static int
  169. -ar71xx_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
  170. +ar724x_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
  171. {
  172. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  173. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  174. int i;
  175.  
  176. for (i = 0; i < sc->gpio_npins; i++) {
  177. @@ -226,10 +206,10 @@
  178. }
  179.  
  180. static int
  181. -ar71xx_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
  182. +ar724x_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
  183. {
  184. int i;
  185. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  186. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  187.  
  188. for (i = 0; i < sc->gpio_npins; i++) {
  189. if (sc->gpio_pins[i].gp_pin == pin)
  190. @@ -248,14 +228,14 @@
  191. (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT))
  192. return (EINVAL);
  193.  
  194. - ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
  195. + ar724x_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
  196. return (0);
  197. }
  198.  
  199. static int
  200. -ar71xx_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
  201. +ar724x_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
  202. {
  203. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  204. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  205. int i;
  206.  
  207. for (i = 0; i < sc->gpio_npins; i++) {
  208. @@ -277,9 +257,9 @@
  209. }
  210.  
  211. static int
  212. -ar71xx_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
  213. +ar724x_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
  214. {
  215. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  216. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  217. int i;
  218.  
  219. for (i = 0; i < sc->gpio_npins; i++) {
  220. @@ -298,10 +278,10 @@
  221. }
  222.  
  223. static int
  224. -ar71xx_gpio_pin_toggle(device_t dev, uint32_t pin)
  225. +ar724x_gpio_pin_toggle(device_t dev, uint32_t pin)
  226. {
  227. int res, i;
  228. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  229. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  230.  
  231. for (i = 0; i < sc->gpio_npins; i++) {
  232. if (sc->gpio_pins[i].gp_pin == pin)
  233. @@ -323,7 +303,7 @@
  234. }
  235.  
  236. static int
  237. -ar71xx_gpio_filter(void *arg)
  238. +ar724x_gpio_filter(void *arg)
  239. {
  240.  
  241. /* TODO: something useful */
  242. @@ -333,41 +313,41 @@
  243.  
  244.  
  245. static void
  246. -ar71xx_gpio_intr(void *arg)
  247. +ar724x_gpio_intr(void *arg)
  248. {
  249. - struct ar71xx_gpio_softc *sc = arg;
  250. + struct ar724x_gpio_softc *sc = arg;
  251. GPIO_LOCK(sc);
  252. /* TODO: something useful */
  253. GPIO_UNLOCK(sc);
  254. }
  255.  
  256. static int
  257. -ar71xx_gpio_probe(device_t dev)
  258. +ar724x_gpio_probe(device_t dev)
  259. {
  260.  
  261. switch (ar71xx_soc) {
  262. case AR71XX_SOC_AR7240:
  263. case AR71XX_SOC_AR7241:
  264. case AR71XX_SOC_AR7242:
  265. - return (ENXIO);
  266. + device_set_desc(dev, "Atheros AR724X GPIO driver");
  267. + return (0);
  268. break;
  269. default:
  270. break;
  271. }
  272. - device_set_desc(dev, "Atheros AR71XX GPIO driver");
  273. - return (0);
  274. + return (ENXIO);
  275. }
  276.  
  277. static int
  278. -ar71xx_gpio_attach(device_t dev)
  279. +ar724x_gpio_attach(device_t dev)
  280. {
  281. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  282. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  283. int error = 0;
  284. -// struct ar71xx_gpio_pin *pinp;
  285. int i, maxpin;
  286. + uint32_t reg;
  287.  
  288. KASSERT((device_get_unit(dev) == 0),
  289. - ("ar71xx_gpio: Only one gpio module supported"));
  290. + ("ar724x_gpio: Only one gpio module supported"));
  291.  
  292. mtx_init(&sc->gpio_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
  293. MTX_DEF);
  294. @@ -380,7 +360,7 @@
  295. if (sc->gpio_mem_res == NULL) {
  296. device_printf(dev, "couldn't map memory\n");
  297. error = ENXIO;
  298. - ar71xx_gpio_detach(dev);
  299. + ar724x_gpio_detach(dev);
  300. return(error);
  301. }
  302.  
  303. @@ -391,48 +371,50 @@
  304. }
  305.  
  306. if ((bus_setup_intr(dev, sc->gpio_irq_res, INTR_TYPE_MISC,
  307. - ar71xx_gpio_filter, ar71xx_gpio_intr, sc, &sc->gpio_ih))) {
  308. + ar724x_gpio_filter, ar724x_gpio_intr, sc, &sc->gpio_ih))) {
  309. device_printf(dev,
  310. "WARNING: unable to register interrupt handler\n");
  311. return (ENXIO);
  312. }
  313.  
  314. sc->dev = dev;
  315. - if (0) {
  316. - ar71xx_gpio_function_enable(sc, GPIO_FUNC_SPI_CS1_EN);
  317. - ar71xx_gpio_function_enable(sc, GPIO_FUNC_SPI_CS2_EN);
  318. - }
  319. +
  320. + /* XXX: use something like hints for it */
  321. + reg = GPIO_READ(sc, AR71XX_GPIO_FUNCTION);
  322. + device_printf(dev, "GPIO Functions reg old value = 0x%08x\n", reg);
  323. +
  324. + /* Disable JTAG on GPIO and enable GE0 MII clock */
  325. + //AR724X_GPIO_FUNC_GE0_MII_CLK_EN |
  326. + reg |= AR724X_GPIO_FUNC_JTAG_DISABLE;
  327. + GPIO_WRITE(sc, AR71XX_GPIO_FUNCTION, reg);
  328. +
  329. + device_printf(dev, "GPIO Functions reg new value = 0x%08x\n",
  330. + GPIO_READ(sc, AR71XX_GPIO_FUNCTION));
  331. +
  332. /* Configure all pins as input */
  333. /* disable interrupts for all pins */
  334. GPIO_WRITE(sc, AR71XX_GPIO_INT_MASK, 0);
  335. - ar71xx_gpio_pin_max(dev, &maxpin);
  336. + ar724x_gpio_pin_max(dev, &maxpin);
  337.  
  338. for (i = 0; i <= maxpin; i++) {
  339. -// strncpy(sc->gpio_pins[i].gp_name, pinp->name, GPIOMAXNAME);
  340. sc->gpio_pins[i].gp_pin = i;
  341. sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
  342. sc->gpio_pins[i].gp_flags = 0;
  343. -// ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], pinp->flags);
  344. -// pinp++;
  345. -// i++;
  346. }
  347.  
  348. sc->gpio_npins = i;
  349.  
  350. - //device_add_child(dev, "gpioc", device_get_unit(dev));
  351. device_add_child(dev, "gpiobus", device_get_unit(dev));
  352. return (bus_generic_attach(dev));
  353. }
  354.  
  355. static int
  356. -ar71xx_gpio_detach(device_t dev)
  357. +ar724x_gpio_detach(device_t dev)
  358. {
  359. - struct ar71xx_gpio_softc *sc = device_get_softc(dev);
  360. + struct ar724x_gpio_softc *sc = device_get_softc(dev);
  361.  
  362. KASSERT(mtx_initialized(&sc->gpio_mtx), ("gpio mutex not initialized"));
  363.  
  364. - ar71xx_gpio_function_disable(sc, GPIO_FUNC_SPI_CS1_EN);
  365. - ar71xx_gpio_function_disable(sc, GPIO_FUNC_SPI_CS2_EN);
  366. bus_generic_detach(dev);
  367.  
  368. if (sc->gpio_mem_res)
  369. @@ -444,28 +426,28 @@
  370. return(0);
  371. }
  372.  
  373. -static device_method_t ar71xx_gpio_methods[] = {
  374. - DEVMETHOD(device_probe, ar71xx_gpio_probe),
  375. - DEVMETHOD(device_attach, ar71xx_gpio_attach),
  376. - DEVMETHOD(device_detach, ar71xx_gpio_detach),
  377. +static device_method_t ar724x_gpio_methods[] = {
  378. + DEVMETHOD(device_probe, ar724x_gpio_probe),
  379. + DEVMETHOD(device_attach, ar724x_gpio_attach),
  380. + DEVMETHOD(device_detach, ar724x_gpio_detach),
  381.  
  382. /* GPIO protocol */
  383. - DEVMETHOD(gpio_pin_max, ar71xx_gpio_pin_max),
  384. - DEVMETHOD(gpio_pin_getname, ar71xx_gpio_pin_getname),
  385. - DEVMETHOD(gpio_pin_getflags, ar71xx_gpio_pin_getflags),
  386. - DEVMETHOD(gpio_pin_getcaps, ar71xx_gpio_pin_getcaps),
  387. - DEVMETHOD(gpio_pin_setflags, ar71xx_gpio_pin_setflags),
  388. - DEVMETHOD(gpio_pin_get, ar71xx_gpio_pin_get),
  389. - DEVMETHOD(gpio_pin_set, ar71xx_gpio_pin_set),
  390. - DEVMETHOD(gpio_pin_toggle, ar71xx_gpio_pin_toggle),
  391. + DEVMETHOD(gpio_pin_max, ar724x_gpio_pin_max),
  392. + DEVMETHOD(gpio_pin_getname, ar724x_gpio_pin_getname),
  393. + DEVMETHOD(gpio_pin_getflags, ar724x_gpio_pin_getflags),
  394. + DEVMETHOD(gpio_pin_getcaps, ar724x_gpio_pin_getcaps),
  395. + DEVMETHOD(gpio_pin_setflags, ar724x_gpio_pin_setflags),
  396. + DEVMETHOD(gpio_pin_get, ar724x_gpio_pin_get),
  397. + DEVMETHOD(gpio_pin_set, ar724x_gpio_pin_set),
  398. + DEVMETHOD(gpio_pin_toggle, ar724x_gpio_pin_toggle),
  399. DEVMETHOD_END
  400. };
  401.  
  402. -static driver_t ar71xx_gpio_driver = {
  403. +static driver_t ar724x_gpio_driver = {
  404. "gpio",
  405. - ar71xx_gpio_methods,
  406. - sizeof(struct ar71xx_gpio_softc),
  407. + ar724x_gpio_methods,
  408. + sizeof(struct ar724x_gpio_softc),
  409. };
  410. -static devclass_t ar71xx_gpio_devclass;
  411. +static devclass_t ar724x_gpio_devclass;
  412.  
  413. -DRIVER_MODULE(ar71xx_gpio, apb, ar71xx_gpio_driver, ar71xx_gpio_devclass, 0, 0);
  414. +DRIVER_MODULE(ar724x_gpio, apb, ar724x_gpio_driver, ar724x_gpio_devclass, 0, 0);
  415.  
  416.  
Advertisement
Add Comment
Please, Sign In to add comment