timberdale.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. /*
  2. * timberdale.c timberdale FPGA MFD driver
  3. * Copyright (c) 2009 Intel Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* Supports:
  19. * Timberdale FPGA
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/pci.h>
  24. #include <linux/msi.h>
  25. #include <linux/mfd/core.h>
  26. #include <linux/slab.h>
  27. #include <linux/timb_gpio.h>
  28. #include <linux/i2c.h>
  29. #include <linux/i2c-ocores.h>
  30. #include <linux/i2c-xiic.h>
  31. #include <linux/i2c/tsc2007.h>
  32. #include <linux/spi/spi.h>
  33. #include <linux/spi/xilinx_spi.h>
  34. #include <linux/spi/max7301.h>
  35. #include <linux/spi/mc33880.h>
  36. #include <media/timb_radio.h>
  37. #include <media/timb_video.h>
  38. #include <linux/timb_dma.h>
  39. #include <linux/ks8842.h>
  40. #include "timberdale.h"
  41. #define DRIVER_NAME "timberdale"
  42. struct timberdale_device {
  43. resource_size_t ctl_mapbase;
  44. unsigned char __iomem *ctl_membase;
  45. struct {
  46. u32 major;
  47. u32 minor;
  48. u32 config;
  49. } fw;
  50. };
  51. /*--------------------------------------------------------------------------*/
  52. static struct tsc2007_platform_data timberdale_tsc2007_platform_data = {
  53. .model = 2003,
  54. .x_plate_ohms = 100
  55. };
  56. static struct i2c_board_info timberdale_i2c_board_info[] = {
  57. {
  58. I2C_BOARD_INFO("tsc2007", 0x48),
  59. .platform_data = &timberdale_tsc2007_platform_data,
  60. .irq = IRQ_TIMBERDALE_TSC_INT
  61. },
  62. };
  63. static __devinitdata struct xiic_i2c_platform_data
  64. timberdale_xiic_platform_data = {
  65. .devices = timberdale_i2c_board_info,
  66. .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
  67. };
  68. static __devinitdata struct ocores_i2c_platform_data
  69. timberdale_ocores_platform_data = {
  70. .regstep = 4,
  71. .clock_khz = 62500,
  72. .devices = timberdale_i2c_board_info,
  73. .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
  74. };
  75. static const __devinitconst struct resource timberdale_xiic_resources[] = {
  76. {
  77. .start = XIICOFFSET,
  78. .end = XIICEND,
  79. .flags = IORESOURCE_MEM,
  80. },
  81. {
  82. .start = IRQ_TIMBERDALE_I2C,
  83. .end = IRQ_TIMBERDALE_I2C,
  84. .flags = IORESOURCE_IRQ,
  85. },
  86. };
  87. static const __devinitconst struct resource timberdale_ocores_resources[] = {
  88. {
  89. .start = OCORESOFFSET,
  90. .end = OCORESEND,
  91. .flags = IORESOURCE_MEM,
  92. },
  93. {
  94. .start = IRQ_TIMBERDALE_I2C,
  95. .end = IRQ_TIMBERDALE_I2C,
  96. .flags = IORESOURCE_IRQ,
  97. },
  98. };
  99. const struct max7301_platform_data timberdale_max7301_platform_data = {
  100. .base = 200
  101. };
  102. const struct mc33880_platform_data timberdale_mc33880_platform_data = {
  103. .base = 100
  104. };
  105. static struct spi_board_info timberdale_spi_16bit_board_info[] = {
  106. {
  107. .modalias = "max7301",
  108. .max_speed_hz = 26000,
  109. .chip_select = 2,
  110. .mode = SPI_MODE_0,
  111. .platform_data = &timberdale_max7301_platform_data
  112. },
  113. };
  114. static struct spi_board_info timberdale_spi_8bit_board_info[] = {
  115. {
  116. .modalias = "mc33880",
  117. .max_speed_hz = 4000,
  118. .chip_select = 1,
  119. .mode = SPI_MODE_1,
  120. .platform_data = &timberdale_mc33880_platform_data
  121. },
  122. };
  123. static __devinitdata struct xspi_platform_data timberdale_xspi_platform_data = {
  124. .num_chipselect = 3,
  125. .little_endian = true,
  126. /* bits per word and devices will be filled in runtime depending
  127. * on the HW config
  128. */
  129. };
  130. static const __devinitconst struct resource timberdale_spi_resources[] = {
  131. {
  132. .start = SPIOFFSET,
  133. .end = SPIEND,
  134. .flags = IORESOURCE_MEM,
  135. },
  136. {
  137. .start = IRQ_TIMBERDALE_SPI,
  138. .end = IRQ_TIMBERDALE_SPI,
  139. .flags = IORESOURCE_IRQ,
  140. },
  141. };
  142. static __devinitdata struct ks8842_platform_data
  143. timberdale_ks8842_platform_data = {
  144. .rx_dma_channel = DMA_ETH_RX,
  145. .tx_dma_channel = DMA_ETH_TX
  146. };
  147. static const __devinitconst struct resource timberdale_eth_resources[] = {
  148. {
  149. .start = ETHOFFSET,
  150. .end = ETHEND,
  151. .flags = IORESOURCE_MEM,
  152. },
  153. {
  154. .start = IRQ_TIMBERDALE_ETHSW_IF,
  155. .end = IRQ_TIMBERDALE_ETHSW_IF,
  156. .flags = IORESOURCE_IRQ,
  157. },
  158. };
  159. static __devinitdata struct timbgpio_platform_data
  160. timberdale_gpio_platform_data = {
  161. .gpio_base = 0,
  162. .nr_pins = GPIO_NR_PINS,
  163. .irq_base = 200,
  164. };
  165. static const __devinitconst struct resource timberdale_gpio_resources[] = {
  166. {
  167. .start = GPIOOFFSET,
  168. .end = GPIOEND,
  169. .flags = IORESOURCE_MEM,
  170. },
  171. {
  172. .start = IRQ_TIMBERDALE_GPIO,
  173. .end = IRQ_TIMBERDALE_GPIO,
  174. .flags = IORESOURCE_IRQ,
  175. },
  176. };
  177. static const __devinitconst struct resource timberdale_mlogicore_resources[] = {
  178. {
  179. .start = MLCOREOFFSET,
  180. .end = MLCOREEND,
  181. .flags = IORESOURCE_MEM,
  182. },
  183. {
  184. .start = IRQ_TIMBERDALE_MLCORE,
  185. .end = IRQ_TIMBERDALE_MLCORE,
  186. .flags = IORESOURCE_IRQ,
  187. },
  188. {
  189. .start = IRQ_TIMBERDALE_MLCORE_BUF,
  190. .end = IRQ_TIMBERDALE_MLCORE_BUF,
  191. .flags = IORESOURCE_IRQ,
  192. },
  193. };
  194. static const __devinitconst struct resource timberdale_uart_resources[] = {
  195. {
  196. .start = UARTOFFSET,
  197. .end = UARTEND,
  198. .flags = IORESOURCE_MEM,
  199. },
  200. {
  201. .start = IRQ_TIMBERDALE_UART,
  202. .end = IRQ_TIMBERDALE_UART,
  203. .flags = IORESOURCE_IRQ,
  204. },
  205. };
  206. static const __devinitconst struct resource timberdale_uartlite_resources[] = {
  207. {
  208. .start = UARTLITEOFFSET,
  209. .end = UARTLITEEND,
  210. .flags = IORESOURCE_MEM,
  211. },
  212. {
  213. .start = IRQ_TIMBERDALE_UARTLITE,
  214. .end = IRQ_TIMBERDALE_UARTLITE,
  215. .flags = IORESOURCE_IRQ,
  216. },
  217. };
  218. static __devinitdata struct i2c_board_info timberdale_adv7180_i2c_board_info = {
  219. /* Requires jumper JP9 to be off */
  220. I2C_BOARD_INFO("adv7180", 0x42 >> 1),
  221. .irq = IRQ_TIMBERDALE_ADV7180
  222. };
  223. static __devinitdata struct timb_video_platform_data
  224. timberdale_video_platform_data = {
  225. .dma_channel = DMA_VIDEO_RX,
  226. .i2c_adapter = 0,
  227. .encoder = {
  228. .info = &timberdale_adv7180_i2c_board_info
  229. }
  230. };
  231. static const __devinitconst struct resource
  232. timberdale_radio_resources[] = {
  233. {
  234. .start = RDSOFFSET,
  235. .end = RDSEND,
  236. .flags = IORESOURCE_MEM,
  237. },
  238. {
  239. .start = IRQ_TIMBERDALE_RDS,
  240. .end = IRQ_TIMBERDALE_RDS,
  241. .flags = IORESOURCE_IRQ,
  242. },
  243. };
  244. static __devinitdata struct i2c_board_info timberdale_tef6868_i2c_board_info = {
  245. I2C_BOARD_INFO("tef6862", 0x60)
  246. };
  247. static __devinitdata struct i2c_board_info timberdale_saa7706_i2c_board_info = {
  248. I2C_BOARD_INFO("saa7706h", 0x1C)
  249. };
  250. static __devinitdata struct timb_radio_platform_data
  251. timberdale_radio_platform_data = {
  252. .i2c_adapter = 0,
  253. .tuner = &timberdale_tef6868_i2c_board_info,
  254. .dsp = &timberdale_saa7706_i2c_board_info
  255. };
  256. static const __devinitconst struct resource timberdale_video_resources[] = {
  257. {
  258. .start = LOGIWOFFSET,
  259. .end = LOGIWEND,
  260. .flags = IORESOURCE_MEM,
  261. },
  262. /*
  263. note that the "frame buffer" is located in DMA area
  264. starting at 0x1200000
  265. */
  266. };
  267. static __devinitdata struct timb_dma_platform_data timb_dma_platform_data = {
  268. .nr_channels = 10,
  269. .channels = {
  270. {
  271. /* UART RX */
  272. .rx = true,
  273. .descriptors = 2,
  274. .descriptor_elements = 1
  275. },
  276. {
  277. /* UART TX */
  278. .rx = false,
  279. .descriptors = 2,
  280. .descriptor_elements = 1
  281. },
  282. {
  283. /* MLB RX */
  284. .rx = true,
  285. .descriptors = 2,
  286. .descriptor_elements = 1
  287. },
  288. {
  289. /* MLB TX */
  290. .rx = false,
  291. .descriptors = 2,
  292. .descriptor_elements = 1
  293. },
  294. {
  295. /* Video RX */
  296. .rx = true,
  297. .bytes_per_line = 1440,
  298. .descriptors = 2,
  299. .descriptor_elements = 16
  300. },
  301. {
  302. /* Video framedrop */
  303. },
  304. {
  305. /* SDHCI RX */
  306. .rx = true,
  307. },
  308. {
  309. /* SDHCI TX */
  310. },
  311. {
  312. /* ETH RX */
  313. .rx = true,
  314. .descriptors = 2,
  315. .descriptor_elements = 1
  316. },
  317. {
  318. /* ETH TX */
  319. .rx = false,
  320. .descriptors = 2,
  321. .descriptor_elements = 1
  322. },
  323. }
  324. };
  325. static const __devinitconst struct resource timberdale_dma_resources[] = {
  326. {
  327. .start = DMAOFFSET,
  328. .end = DMAEND,
  329. .flags = IORESOURCE_MEM,
  330. },
  331. {
  332. .start = IRQ_TIMBERDALE_DMA,
  333. .end = IRQ_TIMBERDALE_DMA,
  334. .flags = IORESOURCE_IRQ,
  335. },
  336. };
  337. static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = {
  338. {
  339. .name = "timb-dma",
  340. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  341. .resources = timberdale_dma_resources,
  342. .platform_data = &timb_dma_platform_data,
  343. .pdata_size = sizeof(timb_dma_platform_data),
  344. },
  345. {
  346. .name = "timb-uart",
  347. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  348. .resources = timberdale_uart_resources,
  349. },
  350. {
  351. .name = "xiic-i2c",
  352. .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
  353. .resources = timberdale_xiic_resources,
  354. .platform_data = &timberdale_xiic_platform_data,
  355. .pdata_size = sizeof(timberdale_xiic_platform_data),
  356. },
  357. {
  358. .name = "timb-gpio",
  359. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  360. .resources = timberdale_gpio_resources,
  361. .platform_data = &timberdale_gpio_platform_data,
  362. .pdata_size = sizeof(timberdale_gpio_platform_data),
  363. },
  364. {
  365. .name = "timb-video",
  366. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  367. .resources = timberdale_video_resources,
  368. .platform_data = &timberdale_video_platform_data,
  369. .pdata_size = sizeof(timberdale_video_platform_data),
  370. },
  371. {
  372. .name = "timb-radio",
  373. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  374. .resources = timberdale_radio_resources,
  375. .platform_data = &timberdale_radio_platform_data,
  376. .pdata_size = sizeof(timberdale_radio_platform_data),
  377. },
  378. {
  379. .name = "xilinx_spi",
  380. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  381. .resources = timberdale_spi_resources,
  382. .platform_data = &timberdale_xspi_platform_data,
  383. .pdata_size = sizeof(timberdale_xspi_platform_data),
  384. },
  385. {
  386. .name = "ks8842",
  387. .num_resources = ARRAY_SIZE(timberdale_eth_resources),
  388. .resources = timberdale_eth_resources,
  389. .platform_data = &timberdale_ks8842_platform_data,
  390. .pdata_size = sizeof(timberdale_ks8842_platform_data),
  391. },
  392. };
  393. static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
  394. {
  395. .name = "timb-dma",
  396. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  397. .resources = timberdale_dma_resources,
  398. .platform_data = &timb_dma_platform_data,
  399. .pdata_size = sizeof(timb_dma_platform_data),
  400. },
  401. {
  402. .name = "timb-uart",
  403. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  404. .resources = timberdale_uart_resources,
  405. },
  406. {
  407. .name = "uartlite",
  408. .num_resources = ARRAY_SIZE(timberdale_uartlite_resources),
  409. .resources = timberdale_uartlite_resources,
  410. },
  411. {
  412. .name = "xiic-i2c",
  413. .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
  414. .resources = timberdale_xiic_resources,
  415. .platform_data = &timberdale_xiic_platform_data,
  416. .pdata_size = sizeof(timberdale_xiic_platform_data),
  417. },
  418. {
  419. .name = "timb-gpio",
  420. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  421. .resources = timberdale_gpio_resources,
  422. .platform_data = &timberdale_gpio_platform_data,
  423. .pdata_size = sizeof(timberdale_gpio_platform_data),
  424. },
  425. {
  426. .name = "timb-mlogicore",
  427. .num_resources = ARRAY_SIZE(timberdale_mlogicore_resources),
  428. .resources = timberdale_mlogicore_resources,
  429. },
  430. {
  431. .name = "timb-video",
  432. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  433. .resources = timberdale_video_resources,
  434. .platform_data = &timberdale_video_platform_data,
  435. .pdata_size = sizeof(timberdale_video_platform_data),
  436. },
  437. {
  438. .name = "timb-radio",
  439. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  440. .resources = timberdale_radio_resources,
  441. .platform_data = &timberdale_radio_platform_data,
  442. .pdata_size = sizeof(timberdale_radio_platform_data),
  443. },
  444. {
  445. .name = "xilinx_spi",
  446. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  447. .resources = timberdale_spi_resources,
  448. .platform_data = &timberdale_xspi_platform_data,
  449. .pdata_size = sizeof(timberdale_xspi_platform_data),
  450. },
  451. {
  452. .name = "ks8842",
  453. .num_resources = ARRAY_SIZE(timberdale_eth_resources),
  454. .resources = timberdale_eth_resources,
  455. .platform_data = &timberdale_ks8842_platform_data,
  456. .pdata_size = sizeof(timberdale_ks8842_platform_data),
  457. },
  458. };
  459. static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
  460. {
  461. .name = "timb-dma",
  462. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  463. .resources = timberdale_dma_resources,
  464. .platform_data = &timb_dma_platform_data,
  465. .pdata_size = sizeof(timb_dma_platform_data),
  466. },
  467. {
  468. .name = "timb-uart",
  469. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  470. .resources = timberdale_uart_resources,
  471. },
  472. {
  473. .name = "xiic-i2c",
  474. .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
  475. .resources = timberdale_xiic_resources,
  476. .platform_data = &timberdale_xiic_platform_data,
  477. .pdata_size = sizeof(timberdale_xiic_platform_data),
  478. },
  479. {
  480. .name = "timb-gpio",
  481. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  482. .resources = timberdale_gpio_resources,
  483. .platform_data = &timberdale_gpio_platform_data,
  484. .pdata_size = sizeof(timberdale_gpio_platform_data),
  485. },
  486. {
  487. .name = "timb-video",
  488. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  489. .resources = timberdale_video_resources,
  490. .platform_data = &timberdale_video_platform_data,
  491. .pdata_size = sizeof(timberdale_video_platform_data),
  492. },
  493. {
  494. .name = "timb-radio",
  495. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  496. .resources = timberdale_radio_resources,
  497. .platform_data = &timberdale_radio_platform_data,
  498. .pdata_size = sizeof(timberdale_radio_platform_data),
  499. },
  500. {
  501. .name = "xilinx_spi",
  502. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  503. .resources = timberdale_spi_resources,
  504. .platform_data = &timberdale_xspi_platform_data,
  505. .pdata_size = sizeof(timberdale_xspi_platform_data),
  506. },
  507. };
  508. static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
  509. {
  510. .name = "timb-dma",
  511. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  512. .resources = timberdale_dma_resources,
  513. .platform_data = &timb_dma_platform_data,
  514. .pdata_size = sizeof(timb_dma_platform_data),
  515. },
  516. {
  517. .name = "timb-uart",
  518. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  519. .resources = timberdale_uart_resources,
  520. },
  521. {
  522. .name = "ocores-i2c",
  523. .num_resources = ARRAY_SIZE(timberdale_ocores_resources),
  524. .resources = timberdale_ocores_resources,
  525. .platform_data = &timberdale_ocores_platform_data,
  526. .pdata_size = sizeof(timberdale_ocores_platform_data),
  527. },
  528. {
  529. .name = "timb-gpio",
  530. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  531. .resources = timberdale_gpio_resources,
  532. .platform_data = &timberdale_gpio_platform_data,
  533. .pdata_size = sizeof(timberdale_gpio_platform_data),
  534. },
  535. {
  536. .name = "timb-video",
  537. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  538. .resources = timberdale_video_resources,
  539. .platform_data = &timberdale_video_platform_data,
  540. .pdata_size = sizeof(timberdale_video_platform_data),
  541. },
  542. {
  543. .name = "timb-radio",
  544. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  545. .resources = timberdale_radio_resources,
  546. .platform_data = &timberdale_radio_platform_data,
  547. .pdata_size = sizeof(timberdale_radio_platform_data),
  548. },
  549. {
  550. .name = "xilinx_spi",
  551. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  552. .resources = timberdale_spi_resources,
  553. .platform_data = &timberdale_xspi_platform_data,
  554. .pdata_size = sizeof(timberdale_xspi_platform_data),
  555. },
  556. {
  557. .name = "ks8842",
  558. .num_resources = ARRAY_SIZE(timberdale_eth_resources),
  559. .resources = timberdale_eth_resources,
  560. .platform_data = &timberdale_ks8842_platform_data,
  561. .pdata_size = sizeof(timberdale_ks8842_platform_data),
  562. },
  563. };
  564. static const __devinitconst struct resource timberdale_sdhc_resources[] = {
  565. /* located in bar 1 and bar 2 */
  566. {
  567. .start = SDHC0OFFSET,
  568. .end = SDHC0END,
  569. .flags = IORESOURCE_MEM,
  570. },
  571. {
  572. .start = IRQ_TIMBERDALE_SDHC,
  573. .end = IRQ_TIMBERDALE_SDHC,
  574. .flags = IORESOURCE_IRQ,
  575. },
  576. };
  577. static __devinitdata struct mfd_cell timberdale_cells_bar1[] = {
  578. {
  579. .name = "sdhci",
  580. .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
  581. .resources = timberdale_sdhc_resources,
  582. },
  583. };
  584. static __devinitdata struct mfd_cell timberdale_cells_bar2[] = {
  585. {
  586. .name = "sdhci",
  587. .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
  588. .resources = timberdale_sdhc_resources,
  589. },
  590. };
  591. static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
  592. char *buf)
  593. {
  594. struct pci_dev *pdev = to_pci_dev(dev);
  595. struct timberdale_device *priv = pci_get_drvdata(pdev);
  596. return sprintf(buf, "%d.%d.%d\n", priv->fw.major, priv->fw.minor,
  597. priv->fw.config);
  598. }
  599. static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
  600. /*--------------------------------------------------------------------------*/
  601. static int __devinit timb_probe(struct pci_dev *dev,
  602. const struct pci_device_id *id)
  603. {
  604. struct timberdale_device *priv;
  605. int err, i;
  606. resource_size_t mapbase;
  607. struct msix_entry *msix_entries = NULL;
  608. u8 ip_setup;
  609. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  610. if (!priv)
  611. return -ENOMEM;
  612. pci_set_drvdata(dev, priv);
  613. err = pci_enable_device(dev);
  614. if (err)
  615. goto err_enable;
  616. mapbase = pci_resource_start(dev, 0);
  617. if (!mapbase) {
  618. dev_err(&dev->dev, "No resource\n");
  619. goto err_start;
  620. }
  621. /* create a resource for the PCI master register */
  622. priv->ctl_mapbase = mapbase + CHIPCTLOFFSET;
  623. if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) {
  624. dev_err(&dev->dev, "Failed to request ctl mem\n");
  625. goto err_request;
  626. }
  627. priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE);
  628. if (!priv->ctl_membase) {
  629. dev_err(&dev->dev, "ioremap failed for ctl mem\n");
  630. goto err_ioremap;
  631. }
  632. /* read the HW config */
  633. priv->fw.major = ioread32(priv->ctl_membase + TIMB_REV_MAJOR);
  634. priv->fw.minor = ioread32(priv->ctl_membase + TIMB_REV_MINOR);
  635. priv->fw.config = ioread32(priv->ctl_membase + TIMB_HW_CONFIG);
  636. if (priv->fw.major > TIMB_SUPPORTED_MAJOR) {
  637. dev_err(&dev->dev, "The driver supports an older "
  638. "version of the FPGA, please update the driver to "
  639. "support %d.%d\n", priv->fw.major, priv->fw.minor);
  640. goto err_config;
  641. }
  642. if (priv->fw.major < TIMB_SUPPORTED_MAJOR ||
  643. priv->fw.minor < TIMB_REQUIRED_MINOR) {
  644. dev_err(&dev->dev, "The FPGA image is too old (%d.%d), "
  645. "please upgrade the FPGA to at least: %d.%d\n",
  646. priv->fw.major, priv->fw.minor,
  647. TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR);
  648. goto err_config;
  649. }
  650. msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries),
  651. GFP_KERNEL);
  652. if (!msix_entries)
  653. goto err_config;
  654. for (i = 0; i < TIMBERDALE_NR_IRQS; i++)
  655. msix_entries[i].entry = i;
  656. err = pci_enable_msix(dev, msix_entries, TIMBERDALE_NR_IRQS);
  657. if (err) {
  658. dev_err(&dev->dev,
  659. "MSI-X init failed: %d, expected entries: %d\n",
  660. err, TIMBERDALE_NR_IRQS);
  661. goto err_msix;
  662. }
  663. err = device_create_file(&dev->dev, &dev_attr_fw_ver);
  664. if (err)
  665. goto err_create_file;
  666. /* Reset all FPGA PLB peripherals */
  667. iowrite32(0x1, priv->ctl_membase + TIMB_SW_RST);
  668. /* update IRQ offsets in I2C board info */
  669. for (i = 0; i < ARRAY_SIZE(timberdale_i2c_board_info); i++)
  670. timberdale_i2c_board_info[i].irq =
  671. msix_entries[timberdale_i2c_board_info[i].irq].vector;
  672. /* Update the SPI configuration depending on the HW (8 or 16 bit) */
  673. if (priv->fw.config & TIMB_HW_CONFIG_SPI_8BIT) {
  674. timberdale_xspi_platform_data.bits_per_word = 8;
  675. timberdale_xspi_platform_data.devices =
  676. timberdale_spi_8bit_board_info;
  677. timberdale_xspi_platform_data.num_devices =
  678. ARRAY_SIZE(timberdale_spi_8bit_board_info);
  679. } else {
  680. timberdale_xspi_platform_data.bits_per_word = 16;
  681. timberdale_xspi_platform_data.devices =
  682. timberdale_spi_16bit_board_info;
  683. timberdale_xspi_platform_data.num_devices =
  684. ARRAY_SIZE(timberdale_spi_16bit_board_info);
  685. }
  686. ip_setup = priv->fw.config & TIMB_HW_VER_MASK;
  687. switch (ip_setup) {
  688. case TIMB_HW_VER0:
  689. err = mfd_add_devices(&dev->dev, -1,
  690. timberdale_cells_bar0_cfg0,
  691. ARRAY_SIZE(timberdale_cells_bar0_cfg0),
  692. &dev->resource[0], msix_entries[0].vector);
  693. break;
  694. case TIMB_HW_VER1:
  695. err = mfd_add_devices(&dev->dev, -1,
  696. timberdale_cells_bar0_cfg1,
  697. ARRAY_SIZE(timberdale_cells_bar0_cfg1),
  698. &dev->resource[0], msix_entries[0].vector);
  699. break;
  700. case TIMB_HW_VER2:
  701. err = mfd_add_devices(&dev->dev, -1,
  702. timberdale_cells_bar0_cfg2,
  703. ARRAY_SIZE(timberdale_cells_bar0_cfg2),
  704. &dev->resource[0], msix_entries[0].vector);
  705. break;
  706. case TIMB_HW_VER3:
  707. err = mfd_add_devices(&dev->dev, -1,
  708. timberdale_cells_bar0_cfg3,
  709. ARRAY_SIZE(timberdale_cells_bar0_cfg3),
  710. &dev->resource[0], msix_entries[0].vector);
  711. break;
  712. default:
  713. dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n",
  714. priv->fw.major, priv->fw.minor, ip_setup);
  715. err = -ENODEV;
  716. goto err_mfd;
  717. break;
  718. }
  719. if (err) {
  720. dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
  721. goto err_mfd;
  722. }
  723. err = mfd_add_devices(&dev->dev, 0,
  724. timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1),
  725. &dev->resource[1], msix_entries[0].vector);
  726. if (err) {
  727. dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
  728. goto err_mfd2;
  729. }
  730. /* only version 0 and 3 have the iNand routed to SDHCI */
  731. if (((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER0) ||
  732. ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) {
  733. err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2,
  734. ARRAY_SIZE(timberdale_cells_bar2),
  735. &dev->resource[2], msix_entries[0].vector);
  736. if (err) {
  737. dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
  738. goto err_mfd2;
  739. }
  740. }
  741. kfree(msix_entries);
  742. dev_info(&dev->dev,
  743. "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
  744. priv->fw.major, priv->fw.minor, priv->fw.config);
  745. return 0;
  746. err_mfd2:
  747. mfd_remove_devices(&dev->dev);
  748. err_mfd:
  749. device_remove_file(&dev->dev, &dev_attr_fw_ver);
  750. err_create_file:
  751. pci_disable_msix(dev);
  752. err_msix:
  753. kfree(msix_entries);
  754. err_config:
  755. iounmap(priv->ctl_membase);
  756. err_ioremap:
  757. release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
  758. err_request:
  759. pci_set_drvdata(dev, NULL);
  760. err_start:
  761. pci_disable_device(dev);
  762. err_enable:
  763. kfree(priv);
  764. pci_set_drvdata(dev, NULL);
  765. return -ENODEV;
  766. }
  767. static void __devexit timb_remove(struct pci_dev *dev)
  768. {
  769. struct timberdale_device *priv = pci_get_drvdata(dev);
  770. mfd_remove_devices(&dev->dev);
  771. device_remove_file(&dev->dev, &dev_attr_fw_ver);
  772. iounmap(priv->ctl_membase);
  773. release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
  774. pci_disable_msix(dev);
  775. pci_disable_device(dev);
  776. pci_set_drvdata(dev, NULL);
  777. kfree(priv);
  778. }
  779. static DEFINE_PCI_DEVICE_TABLE(timberdale_pci_tbl) = {
  780. { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) },
  781. { 0 }
  782. };
  783. MODULE_DEVICE_TABLE(pci, timberdale_pci_tbl);
  784. static struct pci_driver timberdale_pci_driver = {
  785. .name = DRIVER_NAME,
  786. .id_table = timberdale_pci_tbl,
  787. .probe = timb_probe,
  788. .remove = __devexit_p(timb_remove),
  789. };
  790. static int __init timberdale_init(void)
  791. {
  792. int err;
  793. err = pci_register_driver(&timberdale_pci_driver);
  794. if (err < 0) {
  795. printk(KERN_ERR
  796. "Failed to register PCI driver for %s device.\n",
  797. timberdale_pci_driver.name);
  798. return -ENODEV;
  799. }
  800. printk(KERN_INFO "Driver for %s has been successfully registered.\n",
  801. timberdale_pci_driver.name);
  802. return 0;
  803. }
  804. static void __exit timberdale_exit(void)
  805. {
  806. pci_unregister_driver(&timberdale_pci_driver);
  807. printk(KERN_INFO "Driver for %s has been successfully unregistered.\n",
  808. timberdale_pci_driver.name);
  809. }
  810. module_init(timberdale_init);
  811. module_exit(timberdale_exit);
  812. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  813. MODULE_VERSION(DRV_VERSION);
  814. MODULE_LICENSE("GPL v2");