timberdale.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  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 <linux/platform_data/media/timb_radio.h>
  37. #include <linux/platform_data/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 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 struct ocores_i2c_platform_data
  69. timberdale_ocores_platform_data = {
  70. .reg_shift = 2,
  71. .clock_khz = 62500,
  72. .devices = timberdale_i2c_board_info,
  73. .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
  74. };
  75. static const 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 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. static const struct max7301_platform_data timberdale_max7301_platform_data = {
  100. .base = 200
  101. };
  102. static 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 struct xspi_platform_data timberdale_xspi_platform_data = {
  124. .num_chipselect = 3,
  125. /* bits per word and devices will be filled in runtime depending
  126. * on the HW config
  127. */
  128. };
  129. static const struct resource timberdale_spi_resources[] = {
  130. {
  131. .start = SPIOFFSET,
  132. .end = SPIEND,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. {
  136. .start = IRQ_TIMBERDALE_SPI,
  137. .end = IRQ_TIMBERDALE_SPI,
  138. .flags = IORESOURCE_IRQ,
  139. },
  140. };
  141. static struct ks8842_platform_data
  142. timberdale_ks8842_platform_data = {
  143. .rx_dma_channel = DMA_ETH_RX,
  144. .tx_dma_channel = DMA_ETH_TX
  145. };
  146. static const struct resource timberdale_eth_resources[] = {
  147. {
  148. .start = ETHOFFSET,
  149. .end = ETHEND,
  150. .flags = IORESOURCE_MEM,
  151. },
  152. {
  153. .start = IRQ_TIMBERDALE_ETHSW_IF,
  154. .end = IRQ_TIMBERDALE_ETHSW_IF,
  155. .flags = IORESOURCE_IRQ,
  156. },
  157. };
  158. static struct timbgpio_platform_data
  159. timberdale_gpio_platform_data = {
  160. .gpio_base = 0,
  161. .nr_pins = GPIO_NR_PINS,
  162. .irq_base = 200,
  163. };
  164. static const struct resource timberdale_gpio_resources[] = {
  165. {
  166. .start = GPIOOFFSET,
  167. .end = GPIOEND,
  168. .flags = IORESOURCE_MEM,
  169. },
  170. {
  171. .start = IRQ_TIMBERDALE_GPIO,
  172. .end = IRQ_TIMBERDALE_GPIO,
  173. .flags = IORESOURCE_IRQ,
  174. },
  175. };
  176. static const struct resource timberdale_mlogicore_resources[] = {
  177. {
  178. .start = MLCOREOFFSET,
  179. .end = MLCOREEND,
  180. .flags = IORESOURCE_MEM,
  181. },
  182. {
  183. .start = IRQ_TIMBERDALE_MLCORE,
  184. .end = IRQ_TIMBERDALE_MLCORE,
  185. .flags = IORESOURCE_IRQ,
  186. },
  187. {
  188. .start = IRQ_TIMBERDALE_MLCORE_BUF,
  189. .end = IRQ_TIMBERDALE_MLCORE_BUF,
  190. .flags = IORESOURCE_IRQ,
  191. },
  192. };
  193. static const struct resource timberdale_uart_resources[] = {
  194. {
  195. .start = UARTOFFSET,
  196. .end = UARTEND,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. {
  200. .start = IRQ_TIMBERDALE_UART,
  201. .end = IRQ_TIMBERDALE_UART,
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. static const struct resource timberdale_uartlite_resources[] = {
  206. {
  207. .start = UARTLITEOFFSET,
  208. .end = UARTLITEEND,
  209. .flags = IORESOURCE_MEM,
  210. },
  211. {
  212. .start = IRQ_TIMBERDALE_UARTLITE,
  213. .end = IRQ_TIMBERDALE_UARTLITE,
  214. .flags = IORESOURCE_IRQ,
  215. },
  216. };
  217. static struct i2c_board_info timberdale_adv7180_i2c_board_info = {
  218. /* Requires jumper JP9 to be off */
  219. I2C_BOARD_INFO("adv7180", 0x42 >> 1),
  220. .irq = IRQ_TIMBERDALE_ADV7180
  221. };
  222. static struct timb_video_platform_data
  223. timberdale_video_platform_data = {
  224. .dma_channel = DMA_VIDEO_RX,
  225. .i2c_adapter = 0,
  226. .encoder = {
  227. .info = &timberdale_adv7180_i2c_board_info
  228. }
  229. };
  230. static const struct resource
  231. timberdale_radio_resources[] = {
  232. {
  233. .start = RDSOFFSET,
  234. .end = RDSEND,
  235. .flags = IORESOURCE_MEM,
  236. },
  237. {
  238. .start = IRQ_TIMBERDALE_RDS,
  239. .end = IRQ_TIMBERDALE_RDS,
  240. .flags = IORESOURCE_IRQ,
  241. },
  242. };
  243. static struct i2c_board_info timberdale_tef6868_i2c_board_info = {
  244. I2C_BOARD_INFO("tef6862", 0x60)
  245. };
  246. static struct i2c_board_info timberdale_saa7706_i2c_board_info = {
  247. I2C_BOARD_INFO("saa7706h", 0x1C)
  248. };
  249. static struct timb_radio_platform_data
  250. timberdale_radio_platform_data = {
  251. .i2c_adapter = 0,
  252. .tuner = &timberdale_tef6868_i2c_board_info,
  253. .dsp = &timberdale_saa7706_i2c_board_info
  254. };
  255. static const struct resource timberdale_video_resources[] = {
  256. {
  257. .start = LOGIWOFFSET,
  258. .end = LOGIWEND,
  259. .flags = IORESOURCE_MEM,
  260. },
  261. /*
  262. note that the "frame buffer" is located in DMA area
  263. starting at 0x1200000
  264. */
  265. };
  266. static struct timb_dma_platform_data timb_dma_platform_data = {
  267. .nr_channels = 10,
  268. .channels = {
  269. {
  270. /* UART RX */
  271. .rx = true,
  272. .descriptors = 2,
  273. .descriptor_elements = 1
  274. },
  275. {
  276. /* UART TX */
  277. .rx = false,
  278. .descriptors = 2,
  279. .descriptor_elements = 1
  280. },
  281. {
  282. /* MLB RX */
  283. .rx = true,
  284. .descriptors = 2,
  285. .descriptor_elements = 1
  286. },
  287. {
  288. /* MLB TX */
  289. .rx = false,
  290. .descriptors = 2,
  291. .descriptor_elements = 1
  292. },
  293. {
  294. /* Video RX */
  295. .rx = true,
  296. .bytes_per_line = 1440,
  297. .descriptors = 2,
  298. .descriptor_elements = 16
  299. },
  300. {
  301. /* Video framedrop */
  302. },
  303. {
  304. /* SDHCI RX */
  305. .rx = true,
  306. },
  307. {
  308. /* SDHCI TX */
  309. },
  310. {
  311. /* ETH RX */
  312. .rx = true,
  313. .descriptors = 2,
  314. .descriptor_elements = 1
  315. },
  316. {
  317. /* ETH TX */
  318. .rx = false,
  319. .descriptors = 2,
  320. .descriptor_elements = 1
  321. },
  322. }
  323. };
  324. static const struct resource timberdale_dma_resources[] = {
  325. {
  326. .start = DMAOFFSET,
  327. .end = DMAEND,
  328. .flags = IORESOURCE_MEM,
  329. },
  330. {
  331. .start = IRQ_TIMBERDALE_DMA,
  332. .end = IRQ_TIMBERDALE_DMA,
  333. .flags = IORESOURCE_IRQ,
  334. },
  335. };
  336. static const struct mfd_cell timberdale_cells_bar0_cfg0[] = {
  337. {
  338. .name = "timb-dma",
  339. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  340. .resources = timberdale_dma_resources,
  341. .platform_data = &timb_dma_platform_data,
  342. .pdata_size = sizeof(timb_dma_platform_data),
  343. },
  344. {
  345. .name = "timb-uart",
  346. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  347. .resources = timberdale_uart_resources,
  348. },
  349. {
  350. .name = "xiic-i2c",
  351. .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
  352. .resources = timberdale_xiic_resources,
  353. .platform_data = &timberdale_xiic_platform_data,
  354. .pdata_size = sizeof(timberdale_xiic_platform_data),
  355. },
  356. {
  357. .name = "timb-gpio",
  358. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  359. .resources = timberdale_gpio_resources,
  360. .platform_data = &timberdale_gpio_platform_data,
  361. .pdata_size = sizeof(timberdale_gpio_platform_data),
  362. },
  363. {
  364. .name = "timb-video",
  365. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  366. .resources = timberdale_video_resources,
  367. .platform_data = &timberdale_video_platform_data,
  368. .pdata_size = sizeof(timberdale_video_platform_data),
  369. },
  370. {
  371. .name = "timb-radio",
  372. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  373. .resources = timberdale_radio_resources,
  374. .platform_data = &timberdale_radio_platform_data,
  375. .pdata_size = sizeof(timberdale_radio_platform_data),
  376. },
  377. {
  378. .name = "xilinx_spi",
  379. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  380. .resources = timberdale_spi_resources,
  381. .platform_data = &timberdale_xspi_platform_data,
  382. .pdata_size = sizeof(timberdale_xspi_platform_data),
  383. },
  384. {
  385. .name = "ks8842",
  386. .num_resources = ARRAY_SIZE(timberdale_eth_resources),
  387. .resources = timberdale_eth_resources,
  388. .platform_data = &timberdale_ks8842_platform_data,
  389. .pdata_size = sizeof(timberdale_ks8842_platform_data),
  390. },
  391. };
  392. static const struct mfd_cell timberdale_cells_bar0_cfg1[] = {
  393. {
  394. .name = "timb-dma",
  395. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  396. .resources = timberdale_dma_resources,
  397. .platform_data = &timb_dma_platform_data,
  398. .pdata_size = sizeof(timb_dma_platform_data),
  399. },
  400. {
  401. .name = "timb-uart",
  402. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  403. .resources = timberdale_uart_resources,
  404. },
  405. {
  406. .name = "uartlite",
  407. .num_resources = ARRAY_SIZE(timberdale_uartlite_resources),
  408. .resources = timberdale_uartlite_resources,
  409. },
  410. {
  411. .name = "xiic-i2c",
  412. .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
  413. .resources = timberdale_xiic_resources,
  414. .platform_data = &timberdale_xiic_platform_data,
  415. .pdata_size = sizeof(timberdale_xiic_platform_data),
  416. },
  417. {
  418. .name = "timb-gpio",
  419. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  420. .resources = timberdale_gpio_resources,
  421. .platform_data = &timberdale_gpio_platform_data,
  422. .pdata_size = sizeof(timberdale_gpio_platform_data),
  423. },
  424. {
  425. .name = "timb-mlogicore",
  426. .num_resources = ARRAY_SIZE(timberdale_mlogicore_resources),
  427. .resources = timberdale_mlogicore_resources,
  428. },
  429. {
  430. .name = "timb-video",
  431. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  432. .resources = timberdale_video_resources,
  433. .platform_data = &timberdale_video_platform_data,
  434. .pdata_size = sizeof(timberdale_video_platform_data),
  435. },
  436. {
  437. .name = "timb-radio",
  438. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  439. .resources = timberdale_radio_resources,
  440. .platform_data = &timberdale_radio_platform_data,
  441. .pdata_size = sizeof(timberdale_radio_platform_data),
  442. },
  443. {
  444. .name = "xilinx_spi",
  445. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  446. .resources = timberdale_spi_resources,
  447. .platform_data = &timberdale_xspi_platform_data,
  448. .pdata_size = sizeof(timberdale_xspi_platform_data),
  449. },
  450. {
  451. .name = "ks8842",
  452. .num_resources = ARRAY_SIZE(timberdale_eth_resources),
  453. .resources = timberdale_eth_resources,
  454. .platform_data = &timberdale_ks8842_platform_data,
  455. .pdata_size = sizeof(timberdale_ks8842_platform_data),
  456. },
  457. };
  458. static const struct mfd_cell timberdale_cells_bar0_cfg2[] = {
  459. {
  460. .name = "timb-dma",
  461. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  462. .resources = timberdale_dma_resources,
  463. .platform_data = &timb_dma_platform_data,
  464. .pdata_size = sizeof(timb_dma_platform_data),
  465. },
  466. {
  467. .name = "timb-uart",
  468. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  469. .resources = timberdale_uart_resources,
  470. },
  471. {
  472. .name = "xiic-i2c",
  473. .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
  474. .resources = timberdale_xiic_resources,
  475. .platform_data = &timberdale_xiic_platform_data,
  476. .pdata_size = sizeof(timberdale_xiic_platform_data),
  477. },
  478. {
  479. .name = "timb-gpio",
  480. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  481. .resources = timberdale_gpio_resources,
  482. .platform_data = &timberdale_gpio_platform_data,
  483. .pdata_size = sizeof(timberdale_gpio_platform_data),
  484. },
  485. {
  486. .name = "timb-video",
  487. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  488. .resources = timberdale_video_resources,
  489. .platform_data = &timberdale_video_platform_data,
  490. .pdata_size = sizeof(timberdale_video_platform_data),
  491. },
  492. {
  493. .name = "timb-radio",
  494. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  495. .resources = timberdale_radio_resources,
  496. .platform_data = &timberdale_radio_platform_data,
  497. .pdata_size = sizeof(timberdale_radio_platform_data),
  498. },
  499. {
  500. .name = "xilinx_spi",
  501. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  502. .resources = timberdale_spi_resources,
  503. .platform_data = &timberdale_xspi_platform_data,
  504. .pdata_size = sizeof(timberdale_xspi_platform_data),
  505. },
  506. };
  507. static const struct mfd_cell timberdale_cells_bar0_cfg3[] = {
  508. {
  509. .name = "timb-dma",
  510. .num_resources = ARRAY_SIZE(timberdale_dma_resources),
  511. .resources = timberdale_dma_resources,
  512. .platform_data = &timb_dma_platform_data,
  513. .pdata_size = sizeof(timb_dma_platform_data),
  514. },
  515. {
  516. .name = "timb-uart",
  517. .num_resources = ARRAY_SIZE(timberdale_uart_resources),
  518. .resources = timberdale_uart_resources,
  519. },
  520. {
  521. .name = "ocores-i2c",
  522. .num_resources = ARRAY_SIZE(timberdale_ocores_resources),
  523. .resources = timberdale_ocores_resources,
  524. .platform_data = &timberdale_ocores_platform_data,
  525. .pdata_size = sizeof(timberdale_ocores_platform_data),
  526. },
  527. {
  528. .name = "timb-gpio",
  529. .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
  530. .resources = timberdale_gpio_resources,
  531. .platform_data = &timberdale_gpio_platform_data,
  532. .pdata_size = sizeof(timberdale_gpio_platform_data),
  533. },
  534. {
  535. .name = "timb-video",
  536. .num_resources = ARRAY_SIZE(timberdale_video_resources),
  537. .resources = timberdale_video_resources,
  538. .platform_data = &timberdale_video_platform_data,
  539. .pdata_size = sizeof(timberdale_video_platform_data),
  540. },
  541. {
  542. .name = "timb-radio",
  543. .num_resources = ARRAY_SIZE(timberdale_radio_resources),
  544. .resources = timberdale_radio_resources,
  545. .platform_data = &timberdale_radio_platform_data,
  546. .pdata_size = sizeof(timberdale_radio_platform_data),
  547. },
  548. {
  549. .name = "xilinx_spi",
  550. .num_resources = ARRAY_SIZE(timberdale_spi_resources),
  551. .resources = timberdale_spi_resources,
  552. .platform_data = &timberdale_xspi_platform_data,
  553. .pdata_size = sizeof(timberdale_xspi_platform_data),
  554. },
  555. {
  556. .name = "ks8842",
  557. .num_resources = ARRAY_SIZE(timberdale_eth_resources),
  558. .resources = timberdale_eth_resources,
  559. .platform_data = &timberdale_ks8842_platform_data,
  560. .pdata_size = sizeof(timberdale_ks8842_platform_data),
  561. },
  562. };
  563. static const struct resource timberdale_sdhc_resources[] = {
  564. /* located in bar 1 and bar 2 */
  565. {
  566. .start = SDHC0OFFSET,
  567. .end = SDHC0END,
  568. .flags = IORESOURCE_MEM,
  569. },
  570. {
  571. .start = IRQ_TIMBERDALE_SDHC,
  572. .end = IRQ_TIMBERDALE_SDHC,
  573. .flags = IORESOURCE_IRQ,
  574. },
  575. };
  576. static const struct mfd_cell timberdale_cells_bar1[] = {
  577. {
  578. .name = "sdhci",
  579. .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
  580. .resources = timberdale_sdhc_resources,
  581. },
  582. };
  583. static const struct mfd_cell timberdale_cells_bar2[] = {
  584. {
  585. .name = "sdhci",
  586. .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
  587. .resources = timberdale_sdhc_resources,
  588. },
  589. };
  590. static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
  591. char *buf)
  592. {
  593. struct pci_dev *pdev = to_pci_dev(dev);
  594. struct timberdale_device *priv = pci_get_drvdata(pdev);
  595. return sprintf(buf, "%d.%d.%d\n", priv->fw.major, priv->fw.minor,
  596. priv->fw.config);
  597. }
  598. static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
  599. /*--------------------------------------------------------------------------*/
  600. static int timb_probe(struct pci_dev *dev,
  601. const struct pci_device_id *id)
  602. {
  603. struct timberdale_device *priv;
  604. int err, i;
  605. resource_size_t mapbase;
  606. struct msix_entry *msix_entries = NULL;
  607. u8 ip_setup;
  608. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  609. if (!priv)
  610. return -ENOMEM;
  611. pci_set_drvdata(dev, priv);
  612. err = pci_enable_device(dev);
  613. if (err)
  614. goto err_enable;
  615. mapbase = pci_resource_start(dev, 0);
  616. if (!mapbase) {
  617. dev_err(&dev->dev, "No resource\n");
  618. goto err_start;
  619. }
  620. /* create a resource for the PCI master register */
  621. priv->ctl_mapbase = mapbase + CHIPCTLOFFSET;
  622. if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) {
  623. dev_err(&dev->dev, "Failed to request ctl mem\n");
  624. goto err_start;
  625. }
  626. priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE);
  627. if (!priv->ctl_membase) {
  628. dev_err(&dev->dev, "ioremap failed for ctl mem\n");
  629. goto err_ioremap;
  630. }
  631. /* read the HW config */
  632. priv->fw.major = ioread32(priv->ctl_membase + TIMB_REV_MAJOR);
  633. priv->fw.minor = ioread32(priv->ctl_membase + TIMB_REV_MINOR);
  634. priv->fw.config = ioread32(priv->ctl_membase + TIMB_HW_CONFIG);
  635. if (priv->fw.major > TIMB_SUPPORTED_MAJOR) {
  636. dev_err(&dev->dev, "The driver supports an older "
  637. "version of the FPGA, please update the driver to "
  638. "support %d.%d\n", priv->fw.major, priv->fw.minor);
  639. goto err_config;
  640. }
  641. if (priv->fw.major < TIMB_SUPPORTED_MAJOR ||
  642. priv->fw.minor < TIMB_REQUIRED_MINOR) {
  643. dev_err(&dev->dev, "The FPGA image is too old (%d.%d), "
  644. "please upgrade the FPGA to at least: %d.%d\n",
  645. priv->fw.major, priv->fw.minor,
  646. TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR);
  647. goto err_config;
  648. }
  649. msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries),
  650. GFP_KERNEL);
  651. if (!msix_entries)
  652. goto err_config;
  653. for (i = 0; i < TIMBERDALE_NR_IRQS; i++)
  654. msix_entries[i].entry = i;
  655. err = pci_enable_msix_exact(dev, msix_entries, TIMBERDALE_NR_IRQS);
  656. if (err) {
  657. dev_err(&dev->dev,
  658. "MSI-X init failed: %d, expected entries: %d\n",
  659. err, TIMBERDALE_NR_IRQS);
  660. goto err_msix;
  661. }
  662. err = device_create_file(&dev->dev, &dev_attr_fw_ver);
  663. if (err)
  664. goto err_create_file;
  665. /* Reset all FPGA PLB peripherals */
  666. iowrite32(0x1, priv->ctl_membase + TIMB_SW_RST);
  667. /* update IRQ offsets in I2C board info */
  668. for (i = 0; i < ARRAY_SIZE(timberdale_i2c_board_info); i++)
  669. timberdale_i2c_board_info[i].irq =
  670. msix_entries[timberdale_i2c_board_info[i].irq].vector;
  671. /* Update the SPI configuration depending on the HW (8 or 16 bit) */
  672. if (priv->fw.config & TIMB_HW_CONFIG_SPI_8BIT) {
  673. timberdale_xspi_platform_data.bits_per_word = 8;
  674. timberdale_xspi_platform_data.devices =
  675. timberdale_spi_8bit_board_info;
  676. timberdale_xspi_platform_data.num_devices =
  677. ARRAY_SIZE(timberdale_spi_8bit_board_info);
  678. } else {
  679. timberdale_xspi_platform_data.bits_per_word = 16;
  680. timberdale_xspi_platform_data.devices =
  681. timberdale_spi_16bit_board_info;
  682. timberdale_xspi_platform_data.num_devices =
  683. ARRAY_SIZE(timberdale_spi_16bit_board_info);
  684. }
  685. ip_setup = priv->fw.config & TIMB_HW_VER_MASK;
  686. switch (ip_setup) {
  687. case TIMB_HW_VER0:
  688. err = mfd_add_devices(&dev->dev, -1,
  689. timberdale_cells_bar0_cfg0,
  690. ARRAY_SIZE(timberdale_cells_bar0_cfg0),
  691. &dev->resource[0], msix_entries[0].vector, NULL);
  692. break;
  693. case TIMB_HW_VER1:
  694. err = mfd_add_devices(&dev->dev, -1,
  695. timberdale_cells_bar0_cfg1,
  696. ARRAY_SIZE(timberdale_cells_bar0_cfg1),
  697. &dev->resource[0], msix_entries[0].vector, NULL);
  698. break;
  699. case TIMB_HW_VER2:
  700. err = mfd_add_devices(&dev->dev, -1,
  701. timberdale_cells_bar0_cfg2,
  702. ARRAY_SIZE(timberdale_cells_bar0_cfg2),
  703. &dev->resource[0], msix_entries[0].vector, NULL);
  704. break;
  705. case TIMB_HW_VER3:
  706. err = mfd_add_devices(&dev->dev, -1,
  707. timberdale_cells_bar0_cfg3,
  708. ARRAY_SIZE(timberdale_cells_bar0_cfg3),
  709. &dev->resource[0], msix_entries[0].vector, NULL);
  710. break;
  711. default:
  712. dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n",
  713. priv->fw.major, priv->fw.minor, ip_setup);
  714. err = -ENODEV;
  715. goto err_mfd;
  716. }
  717. if (err) {
  718. dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
  719. goto err_mfd;
  720. }
  721. err = mfd_add_devices(&dev->dev, 0,
  722. timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1),
  723. &dev->resource[1], msix_entries[0].vector, NULL);
  724. if (err) {
  725. dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
  726. goto err_mfd2;
  727. }
  728. /* only version 0 and 3 have the iNand routed to SDHCI */
  729. if (((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER0) ||
  730. ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) {
  731. err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2,
  732. ARRAY_SIZE(timberdale_cells_bar2),
  733. &dev->resource[2], msix_entries[0].vector, NULL);
  734. if (err) {
  735. dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
  736. goto err_mfd2;
  737. }
  738. }
  739. kfree(msix_entries);
  740. dev_info(&dev->dev,
  741. "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
  742. priv->fw.major, priv->fw.minor, priv->fw.config);
  743. return 0;
  744. err_mfd2:
  745. mfd_remove_devices(&dev->dev);
  746. err_mfd:
  747. device_remove_file(&dev->dev, &dev_attr_fw_ver);
  748. err_create_file:
  749. pci_disable_msix(dev);
  750. err_msix:
  751. kfree(msix_entries);
  752. err_config:
  753. iounmap(priv->ctl_membase);
  754. err_ioremap:
  755. release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
  756. err_start:
  757. pci_disable_device(dev);
  758. err_enable:
  759. kfree(priv);
  760. return -ENODEV;
  761. }
  762. static void timb_remove(struct pci_dev *dev)
  763. {
  764. struct timberdale_device *priv = pci_get_drvdata(dev);
  765. mfd_remove_devices(&dev->dev);
  766. device_remove_file(&dev->dev, &dev_attr_fw_ver);
  767. iounmap(priv->ctl_membase);
  768. release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
  769. pci_disable_msix(dev);
  770. pci_disable_device(dev);
  771. kfree(priv);
  772. }
  773. static const struct pci_device_id timberdale_pci_tbl[] = {
  774. { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) },
  775. { 0 }
  776. };
  777. MODULE_DEVICE_TABLE(pci, timberdale_pci_tbl);
  778. static struct pci_driver timberdale_pci_driver = {
  779. .name = DRIVER_NAME,
  780. .id_table = timberdale_pci_tbl,
  781. .probe = timb_probe,
  782. .remove = timb_remove,
  783. };
  784. module_pci_driver(timberdale_pci_driver);
  785. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  786. MODULE_VERSION(DRV_VERSION);
  787. MODULE_LICENSE("GPL v2");