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