Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi/bcm63xx: move register definitions into the driver

Move all register definitions and structs into the driver. This allows
us dropping the platform_data struct and drop any arch specific
includes. Make use of different device names to identify the version of
the block we have.

Since we now have full control over the message width, we can drop the
size check, which was broken anyway, since it never set ret to any error
code.

Also since we now have no arch depedendent resources, we can now allow
compiling it for any arch, hidden behind COMPILE_TEST.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Jonas Gorski and committed by
Mark Brown
44d8fb30 f13a5e8a

+181 -94
+6 -28
arch/mips/bcm63xx/dev-spi.c
··· 18 18 #include <bcm63xx_dev_spi.h> 19 19 #include <bcm63xx_regs.h> 20 20 21 - /* 22 - * register offsets 23 - */ 24 - static const unsigned long bcm6348_regs_spi[] = { 25 - __GEN_SPI_REGS_TABLE(6348) 26 - }; 27 - 28 - static const unsigned long bcm6358_regs_spi[] = { 29 - __GEN_SPI_REGS_TABLE(6358) 30 - }; 31 - 32 - const unsigned long *bcm63xx_regs_spi; 33 - EXPORT_SYMBOL(bcm63xx_regs_spi); 34 - 35 - static __init void bcm63xx_spi_regs_init(void) 36 - { 37 - if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) 38 - bcm63xx_regs_spi = bcm6348_regs_spi; 39 - if (BCMCPU_IS_3368() || BCMCPU_IS_6358() || 40 - BCMCPU_IS_6362() || BCMCPU_IS_6368()) 41 - bcm63xx_regs_spi = bcm6358_regs_spi; 42 - } 43 - 44 21 static struct resource spi_resources[] = { 45 22 { 46 23 .start = -1, /* filled at runtime */ ··· 31 54 }; 32 55 33 56 static struct platform_device bcm63xx_spi_device = { 34 - .name = "bcm63xx-spi", 35 57 .id = -1, 36 58 .num_resources = ARRAY_SIZE(spi_resources), 37 59 .resource = spi_resources, ··· 45 69 spi_resources[0].end = spi_resources[0].start; 46 70 spi_resources[1].start = bcm63xx_get_irq_number(IRQ_SPI); 47 71 48 - if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) 72 + if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) { 73 + bcm63xx_spi_device.name = "bcm6348-spi", 49 74 spi_resources[0].end += BCM_6348_RSET_SPI_SIZE - 1; 75 + } 50 76 51 77 if (BCMCPU_IS_3368() || BCMCPU_IS_6358() || BCMCPU_IS_6362() || 52 - BCMCPU_IS_6368()) 78 + BCMCPU_IS_6368()) { 79 + bcm63xx_spi_device.name = "bcm6358-spi", 53 80 spi_resources[0].end += BCM_6358_RSET_SPI_SIZE - 1; 54 - 55 - bcm63xx_spi_regs_init(); 81 + } 56 82 57 83 return platform_device_register(&bcm63xx_spi_device); 58 84 }
-42
arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h
··· 7 7 8 8 int __init bcm63xx_spi_register(void); 9 9 10 - enum bcm63xx_regs_spi { 11 - SPI_CMD, 12 - SPI_INT_STATUS, 13 - SPI_INT_MASK_ST, 14 - SPI_INT_MASK, 15 - SPI_ST, 16 - SPI_CLK_CFG, 17 - SPI_FILL_BYTE, 18 - SPI_MSG_TAIL, 19 - SPI_RX_TAIL, 20 - SPI_MSG_CTL, 21 - SPI_MSG_DATA, 22 - SPI_RX_DATA, 23 - SPI_MSG_TYPE_SHIFT, 24 - SPI_MSG_CTL_WIDTH, 25 - SPI_MSG_DATA_SIZE, 26 - }; 27 - 28 - #define __GEN_SPI_REGS_TABLE(__cpu) \ 29 - [SPI_CMD] = SPI_## __cpu ##_CMD, \ 30 - [SPI_INT_STATUS] = SPI_## __cpu ##_INT_STATUS, \ 31 - [SPI_INT_MASK_ST] = SPI_## __cpu ##_INT_MASK_ST, \ 32 - [SPI_INT_MASK] = SPI_## __cpu ##_INT_MASK, \ 33 - [SPI_ST] = SPI_## __cpu ##_ST, \ 34 - [SPI_CLK_CFG] = SPI_## __cpu ##_CLK_CFG, \ 35 - [SPI_FILL_BYTE] = SPI_## __cpu ##_FILL_BYTE, \ 36 - [SPI_MSG_TAIL] = SPI_## __cpu ##_MSG_TAIL, \ 37 - [SPI_RX_TAIL] = SPI_## __cpu ##_RX_TAIL, \ 38 - [SPI_MSG_CTL] = SPI_## __cpu ##_MSG_CTL, \ 39 - [SPI_MSG_DATA] = SPI_## __cpu ##_MSG_DATA, \ 40 - [SPI_RX_DATA] = SPI_## __cpu ##_RX_DATA, \ 41 - [SPI_MSG_TYPE_SHIFT] = SPI_## __cpu ##_MSG_TYPE_SHIFT, \ 42 - [SPI_MSG_CTL_WIDTH] = SPI_## __cpu ##_MSG_CTL_WIDTH, \ 43 - [SPI_MSG_DATA_SIZE] = SPI_## __cpu ##_MSG_DATA_SIZE, 44 - 45 - static inline unsigned long bcm63xx_spireg(enum bcm63xx_regs_spi reg) 46 - { 47 - extern const unsigned long *bcm63xx_regs_spi; 48 - 49 - return bcm63xx_regs_spi[reg]; 50 - } 51 - 52 10 #endif /* BCM63XX_DEV_SPI_H */
+1 -1
drivers/spi/Kconfig
··· 125 125 126 126 config SPI_BCM63XX 127 127 tristate "Broadcom BCM63xx SPI controller" 128 - depends on BCM63XX 128 + depends on BCM63XX || COMPILE_TEST 129 129 help 130 130 Enable support for the SPI controller on the Broadcom BCM63xx SoCs. 131 131
+174 -23
drivers/spi/spi-bcm63xx.c
··· 27 27 #include <linux/err.h> 28 28 #include <linux/pm_runtime.h> 29 29 30 - #include <bcm63xx_dev_spi.h> 30 + /* BCM 6338/6348 SPI core */ 31 + #define SPI_6348_RSET_SIZE 64 32 + #define SPI_6348_CMD 0x00 /* 16-bits register */ 33 + #define SPI_6348_INT_STATUS 0x02 34 + #define SPI_6348_INT_MASK_ST 0x03 35 + #define SPI_6348_INT_MASK 0x04 36 + #define SPI_6348_ST 0x05 37 + #define SPI_6348_CLK_CFG 0x06 38 + #define SPI_6348_FILL_BYTE 0x07 39 + #define SPI_6348_MSG_TAIL 0x09 40 + #define SPI_6348_RX_TAIL 0x0b 41 + #define SPI_6348_MSG_CTL 0x40 /* 8-bits register */ 42 + #define SPI_6348_MSG_CTL_WIDTH 8 43 + #define SPI_6348_MSG_DATA 0x41 44 + #define SPI_6348_MSG_DATA_SIZE 0x3f 45 + #define SPI_6348_RX_DATA 0x80 46 + #define SPI_6348_RX_DATA_SIZE 0x3f 47 + 48 + /* BCM 3368/6358/6262/6368 SPI core */ 49 + #define SPI_6358_RSET_SIZE 1804 50 + #define SPI_6358_MSG_CTL 0x00 /* 16-bits register */ 51 + #define SPI_6358_MSG_CTL_WIDTH 16 52 + #define SPI_6358_MSG_DATA 0x02 53 + #define SPI_6358_MSG_DATA_SIZE 0x21e 54 + #define SPI_6358_RX_DATA 0x400 55 + #define SPI_6358_RX_DATA_SIZE 0x220 56 + #define SPI_6358_CMD 0x700 /* 16-bits register */ 57 + #define SPI_6358_INT_STATUS 0x702 58 + #define SPI_6358_INT_MASK_ST 0x703 59 + #define SPI_6358_INT_MASK 0x704 60 + #define SPI_6358_ST 0x705 61 + #define SPI_6358_CLK_CFG 0x706 62 + #define SPI_6358_FILL_BYTE 0x707 63 + #define SPI_6358_MSG_TAIL 0x709 64 + #define SPI_6358_RX_TAIL 0x70B 65 + 66 + /* Shared SPI definitions */ 67 + 68 + /* Message configuration */ 69 + #define SPI_FD_RW 0x00 70 + #define SPI_HD_W 0x01 71 + #define SPI_HD_R 0x02 72 + #define SPI_BYTE_CNT_SHIFT 0 73 + #define SPI_6348_MSG_TYPE_SHIFT 6 74 + #define SPI_6358_MSG_TYPE_SHIFT 14 75 + 76 + /* Command */ 77 + #define SPI_CMD_NOOP 0x00 78 + #define SPI_CMD_SOFT_RESET 0x01 79 + #define SPI_CMD_HARD_RESET 0x02 80 + #define SPI_CMD_START_IMMEDIATE 0x03 81 + #define SPI_CMD_COMMAND_SHIFT 0 82 + #define SPI_CMD_COMMAND_MASK 0x000f 83 + #define SPI_CMD_DEVICE_ID_SHIFT 4 84 + #define SPI_CMD_PREPEND_BYTE_CNT_SHIFT 8 85 + #define SPI_CMD_ONE_BYTE_SHIFT 11 86 + #define SPI_CMD_ONE_WIRE_SHIFT 12 87 + #define SPI_DEV_ID_0 0 88 + #define SPI_DEV_ID_1 1 89 + #define SPI_DEV_ID_2 2 90 + #define SPI_DEV_ID_3 3 91 + 92 + /* Interrupt mask */ 93 + #define SPI_INTR_CMD_DONE 0x01 94 + #define SPI_INTR_RX_OVERFLOW 0x02 95 + #define SPI_INTR_TX_UNDERFLOW 0x04 96 + #define SPI_INTR_TX_OVERFLOW 0x08 97 + #define SPI_INTR_RX_UNDERFLOW 0x10 98 + #define SPI_INTR_CLEAR_ALL 0x1f 99 + 100 + /* Status */ 101 + #define SPI_RX_EMPTY 0x02 102 + #define SPI_CMD_BUSY 0x04 103 + #define SPI_SERIAL_BUSY 0x08 104 + 105 + /* Clock configuration */ 106 + #define SPI_CLK_20MHZ 0x00 107 + #define SPI_CLK_0_391MHZ 0x01 108 + #define SPI_CLK_0_781MHZ 0x02 /* default */ 109 + #define SPI_CLK_1_563MHZ 0x03 110 + #define SPI_CLK_3_125MHZ 0x04 111 + #define SPI_CLK_6_250MHZ 0x05 112 + #define SPI_CLK_12_50MHZ 0x06 113 + #define SPI_CLK_MASK 0x07 114 + #define SPI_SSOFFTIME_MASK 0x38 115 + #define SPI_SSOFFTIME_SHIFT 3 116 + #define SPI_BYTE_SWAP 0x80 117 + 118 + enum bcm63xx_regs_spi { 119 + SPI_CMD, 120 + SPI_INT_STATUS, 121 + SPI_INT_MASK_ST, 122 + SPI_INT_MASK, 123 + SPI_ST, 124 + SPI_CLK_CFG, 125 + SPI_FILL_BYTE, 126 + SPI_MSG_TAIL, 127 + SPI_RX_TAIL, 128 + SPI_MSG_CTL, 129 + SPI_MSG_DATA, 130 + SPI_RX_DATA, 131 + SPI_MSG_TYPE_SHIFT, 132 + SPI_MSG_CTL_WIDTH, 133 + SPI_MSG_DATA_SIZE, 134 + }; 31 135 32 136 #define BCM63XX_SPI_MAX_PREPEND 15 33 137 ··· 145 41 int irq; 146 42 147 43 /* Platform data */ 44 + const unsigned long *reg_offsets; 148 45 unsigned fifo_size; 149 46 unsigned int msg_type_shift; 150 47 unsigned int msg_ctl_width; ··· 159 54 }; 160 55 161 56 static inline u8 bcm_spi_readb(struct bcm63xx_spi *bs, 162 - unsigned int offset) 57 + unsigned int offset) 163 58 { 164 - return readb(bs->regs + bcm63xx_spireg(offset)); 59 + return readb(bs->regs + bs->reg_offsets[offset]); 165 60 } 166 61 167 62 static inline u16 bcm_spi_readw(struct bcm63xx_spi *bs, 168 63 unsigned int offset) 169 64 { 170 65 #ifdef CONFIG_CPU_BIG_ENDIAN 171 - return ioread16be(bs->regs + bcm63xx_spireg(offset)); 66 + return ioread16be(bs->regs + bs->reg_offsets[offset]); 172 67 #else 173 - return readw(bs->regs + bcm63xx_spireg(offset)); 68 + return readw(bs->regs + bs->reg_offsets[offset]); 174 69 #endif 175 70 } 176 71 177 72 static inline void bcm_spi_writeb(struct bcm63xx_spi *bs, 178 73 u8 value, unsigned int offset) 179 74 { 180 - writeb(value, bs->regs + bcm63xx_spireg(offset)); 75 + writeb(value, bs->regs + bs->reg_offsets[offset]); 181 76 } 182 77 183 78 static inline void bcm_spi_writew(struct bcm63xx_spi *bs, 184 79 u16 value, unsigned int offset) 185 80 { 186 81 #ifdef CONFIG_CPU_BIG_ENDIAN 187 - iowrite16be(value, bs->regs + bcm63xx_spireg(offset)); 82 + iowrite16be(value, bs->regs + bs->reg_offsets[offset]); 188 83 #else 189 - writew(value, bs->regs + bcm63xx_spireg(offset)); 84 + writew(value, bs->regs + bs->reg_offsets[offset]); 190 85 #endif 191 86 } 192 87 ··· 429 324 return IRQ_HANDLED; 430 325 } 431 326 327 + static const unsigned long bcm6348_spi_reg_offsets[] = { 328 + [SPI_CMD] = SPI_6348_CMD, 329 + [SPI_INT_STATUS] = SPI_6348_INT_STATUS, 330 + [SPI_INT_MASK_ST] = SPI_6348_INT_MASK_ST, 331 + [SPI_INT_MASK] = SPI_6348_INT_MASK, 332 + [SPI_ST] = SPI_6348_ST, 333 + [SPI_CLK_CFG] = SPI_6348_CLK_CFG, 334 + [SPI_FILL_BYTE] = SPI_6348_FILL_BYTE, 335 + [SPI_MSG_TAIL] = SPI_6348_MSG_TAIL, 336 + [SPI_RX_TAIL] = SPI_6348_RX_TAIL, 337 + [SPI_MSG_CTL] = SPI_6348_MSG_CTL, 338 + [SPI_MSG_DATA] = SPI_6348_MSG_DATA, 339 + [SPI_RX_DATA] = SPI_6348_RX_DATA, 340 + [SPI_MSG_TYPE_SHIFT] = SPI_6348_MSG_TYPE_SHIFT, 341 + [SPI_MSG_CTL_WIDTH] = SPI_6348_MSG_CTL_WIDTH, 342 + [SPI_MSG_DATA_SIZE] = SPI_6348_MSG_DATA_SIZE, 343 + }; 344 + 345 + static const unsigned long bcm6358_spi_reg_offsets[] = { 346 + [SPI_CMD] = SPI_6358_CMD, 347 + [SPI_INT_STATUS] = SPI_6358_INT_STATUS, 348 + [SPI_INT_MASK_ST] = SPI_6358_INT_MASK_ST, 349 + [SPI_INT_MASK] = SPI_6358_INT_MASK, 350 + [SPI_ST] = SPI_6358_ST, 351 + [SPI_CLK_CFG] = SPI_6358_CLK_CFG, 352 + [SPI_FILL_BYTE] = SPI_6358_FILL_BYTE, 353 + [SPI_MSG_TAIL] = SPI_6358_MSG_TAIL, 354 + [SPI_RX_TAIL] = SPI_6358_RX_TAIL, 355 + [SPI_MSG_CTL] = SPI_6358_MSG_CTL, 356 + [SPI_MSG_DATA] = SPI_6358_MSG_DATA, 357 + [SPI_RX_DATA] = SPI_6358_RX_DATA, 358 + [SPI_MSG_TYPE_SHIFT] = SPI_6358_MSG_TYPE_SHIFT, 359 + [SPI_MSG_CTL_WIDTH] = SPI_6358_MSG_CTL_WIDTH, 360 + [SPI_MSG_DATA_SIZE] = SPI_6358_MSG_DATA_SIZE, 361 + }; 362 + 363 + static const struct platform_device_id bcm63xx_spi_dev_match[] = { 364 + { 365 + .name = "bcm6348-spi", 366 + .driver_data = (unsigned long)bcm6348_spi_reg_offsets, 367 + }, 368 + { 369 + .name = "bcm6358-spi", 370 + .driver_data = (unsigned long)bcm6358_spi_reg_offsets, 371 + }, 372 + { 373 + }, 374 + }; 432 375 433 376 static int bcm63xx_spi_probe(struct platform_device *pdev) 434 377 { 435 378 struct resource *r; 379 + const unsigned long *bcm63xx_spireg; 436 380 struct device *dev = &pdev->dev; 437 381 int irq; 438 382 struct spi_master *master; 439 383 struct clk *clk; 440 384 struct bcm63xx_spi *bs; 441 385 int ret; 386 + 387 + if (!pdev->id_entry->driver_data) 388 + return -EINVAL; 389 + 390 + bcm63xx_spireg = (const unsigned long *)pdev->id_entry->driver_data; 442 391 443 392 irq = platform_get_irq(pdev, 0); 444 393 if (irq < 0) { ··· 527 368 528 369 bs->irq = irq; 529 370 bs->clk = clk; 530 - bs->fifo_size = bcm63xx_spireg(SPI_MSG_DATA_SIZE); 371 + bs->reg_offsets = bcm63xx_spireg; 372 + bs->fifo_size = bs->reg_offsets[SPI_MSG_DATA_SIZE]; 531 373 532 374 ret = devm_request_irq(&pdev->dev, irq, bcm63xx_spi_interrupt, 0, 533 375 pdev->name, master); ··· 543 383 master->mode_bits = MODEBITS; 544 384 master->bits_per_word_mask = SPI_BPW_MASK(8); 545 385 master->auto_runtime_pm = true; 546 - bs->msg_type_shift = bcm63xx_spireg(SPI_MSG_TYPE_SHIFT); 547 - bs->msg_ctl_width = bcm63xx_spireg(SPI_MSG_CTL_WIDTH); 548 - bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA)); 549 - bs->rx_io = (const u8 *)(bs->regs + bcm63xx_spireg(SPI_RX_DATA)); 550 - 551 - switch (bs->msg_ctl_width) { 552 - case 8: 553 - case 16: 554 - break; 555 - default: 556 - dev_err(dev, "unsupported MSG_CTL width: %d\n", 557 - bs->msg_ctl_width); 558 - goto out_err; 559 - } 386 + bs->msg_type_shift = bs->reg_offsets[SPI_MSG_TYPE_SHIFT]; 387 + bs->msg_ctl_width = bs->reg_offsets[SPI_MSG_CTL_WIDTH]; 388 + bs->tx_io = (u8 *)(bs->regs + bs->reg_offsets[SPI_MSG_DATA]); 389 + bs->rx_io = (const u8 *)(bs->regs + bs->reg_offsets[SPI_RX_DATA]); 560 390 561 391 /* Initialize hardware */ 562 392 ret = clk_prepare_enable(bs->clk); ··· 626 476 .name = "bcm63xx-spi", 627 477 .pm = &bcm63xx_spi_pm_ops, 628 478 }, 479 + .id_table = bcm63xx_spi_dev_match, 629 480 .probe = bcm63xx_spi_probe, 630 481 .remove = bcm63xx_spi_remove, 631 482 };