Merge branch 'next-i2c-mpc-v8' into next-i2c

Ben Dooks aaa02ab5 ad0194e8

+146 -85
+22 -8
Documentation/powerpc/dts-bindings/fsl/i2c.txt
··· 2 2 3 3 Required properties : 4 4 5 - - device_type : Should be "i2c" 6 5 - reg : Offset and length of the register set for the device 6 + - compatible : should be "fsl,CHIP-i2c" where CHIP is the name of a 7 + compatible processor, e.g. mpc8313, mpc8543, mpc8544, mpc5121, 8 + mpc5200 or mpc5200b. For the mpc5121, an additional node 9 + "fsl,mpc5121-i2c-ctrl" is required as shown in the example below. 7 10 8 11 Recommended properties : 9 12 10 - - compatible : compatibility list with 2 entries, the first should 11 - be "fsl,CHIP-i2c" where CHIP is the name of a compatible processor, 12 - e.g. mpc8313, mpc8543, mpc8544, mpc5200 or mpc5200b. The second one 13 - should be "fsl-i2c". 14 13 - interrupts : <a b> where a is the interrupt number and b is a 15 14 field that represents an encoding of the sense and level 16 15 information for the interrupt. This should be encoded based on ··· 23 24 24 25 Examples : 25 26 27 + /* MPC5121 based board */ 28 + i2c@1740 { 29 + #address-cells = <1>; 30 + #size-cells = <0>; 31 + compatible = "fsl,mpc5121-i2c", "fsl-i2c"; 32 + reg = <0x1740 0x20>; 33 + interrupts = <11 0x8>; 34 + interrupt-parent = <&ipic>; 35 + clock-frequency = <100000>; 36 + }; 37 + 38 + i2ccontrol@1760 { 39 + compatible = "fsl,mpc5121-i2c-ctrl"; 40 + reg = <0x1760 0x8>; 41 + }; 42 + 43 + /* MPC5200B based board */ 26 44 i2c@3d00 { 27 45 #address-cells = <1>; 28 46 #size-cells = <0>; 29 47 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 30 - cell-index = <0>; 31 48 reg = <0x3d00 0x40>; 32 49 interrupts = <2 15 0>; 33 50 interrupt-parent = <&mpc5200_pic>; 34 51 fsl,preserve-clocking; 35 52 }; 36 53 54 + /* MPC8544 base board */ 37 55 i2c@3100 { 38 56 #address-cells = <1>; 39 57 #size-cells = <0>; 40 - cell-index = <1>; 41 58 compatible = "fsl,mpc8544-i2c", "fsl-i2c"; 42 59 reg = <0x3100 0x100>; 43 60 interrupts = <43 2>; 44 61 interrupt-parent = <&mpic>; 45 62 clock-frequency = <400000>; 46 63 }; 47 -
+3 -4
drivers/i2c/busses/Kconfig
··· 419 419 instead. 420 420 421 421 config I2C_MPC 422 - tristate "MPC107/824x/85xx/52xx/86xx" 422 + tristate "MPC107/824x/85xx/512x/52xx/83xx/86xx" 423 423 depends on PPC32 424 424 help 425 425 If you say yes to this option, support will be included for the 426 - built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and 427 - MPC85xx/MPC8641 family processors. The driver may also work on 52xx 428 - family processors, though interrupts are known not to work. 426 + built-in I2C interface on the MPC107, Tsi107, MPC512x, MPC52xx, 427 + MPC8240, MPC8245, MPC83xx, MPC85xx and MPC8641 family processors. 429 428 430 429 This driver can also be built as a module. If so, the module 431 430 will be called i2c-mpc.
+121 -73
drivers/i2c/busses/i2c-mpc.c
··· 31 31 32 32 #define DRV_NAME "mpc-i2c" 33 33 34 + #define MPC_I2C_CLOCK_LEGACY 0 35 + #define MPC_I2C_CLOCK_PRESERVE (~0U) 36 + 34 37 #define MPC_I2C_FDR 0x04 35 38 #define MPC_I2C_CR 0x08 36 39 #define MPC_I2C_SR 0x0c ··· 69 66 u16 fdr; /* including dfsrr */ 70 67 }; 71 68 72 - struct mpc_i2c_match_data { 73 - void (*setclock)(struct device_node *node, 74 - struct mpc_i2c *i2c, 75 - u32 clock, u32 prescaler); 69 + struct mpc_i2c_data { 70 + void (*setup)(struct device_node *node, struct mpc_i2c *i2c, 71 + u32 clock, u32 prescaler); 76 72 u32 prescaler; 77 73 }; 78 74 ··· 166 164 return 0; 167 165 } 168 166 169 - #ifdef CONFIG_PPC_MPC52xx 170 - static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { 167 + #if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) 168 + static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] __devinitconst = { 171 169 {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, 172 170 {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, 173 171 {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28}, ··· 188 186 {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f} 189 187 }; 190 188 191 - int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler) 189 + static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, 190 + int prescaler) 192 191 { 193 192 const struct mpc_i2c_divider *div = NULL; 194 193 unsigned int pvr = mfspr(SPRN_PVR); 195 194 u32 divider; 196 195 int i; 197 196 198 - if (!clock) 197 + if (clock == MPC_I2C_CLOCK_LEGACY) 199 198 return -EINVAL; 200 199 201 200 /* Determine divider value */ ··· 218 215 return div ? (int)div->fdr : -EINVAL; 219 216 } 220 217 221 - static void mpc_i2c_setclock_52xx(struct device_node *node, 222 - struct mpc_i2c *i2c, 223 - u32 clock, u32 prescaler) 218 + static void __devinit mpc_i2c_setup_52xx(struct device_node *node, 219 + struct mpc_i2c *i2c, 220 + u32 clock, u32 prescaler) 224 221 { 225 222 int ret, fdr; 223 + 224 + if (clock == MPC_I2C_CLOCK_PRESERVE) { 225 + dev_dbg(i2c->dev, "using fdr %d\n", 226 + readb(i2c->base + MPC_I2C_FDR)); 227 + return; 228 + } 226 229 227 230 ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); 228 231 fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ ··· 238 229 if (ret >= 0) 239 230 dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr); 240 231 } 241 - #else /* !CONFIG_PPC_MPC52xx */ 242 - static void mpc_i2c_setclock_52xx(struct device_node *node, 243 - struct mpc_i2c *i2c, 244 - u32 clock, u32 prescaler) 232 + #else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ 233 + static void __devinit mpc_i2c_setup_52xx(struct device_node *node, 234 + struct mpc_i2c *i2c, 235 + u32 clock, u32 prescaler) 245 236 { 246 237 } 247 - #endif /* CONFIG_PPC_MPC52xx*/ 238 + #endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ 239 + 240 + #ifdef CONFIG_PPC_MPC512x 241 + static void __devinit mpc_i2c_setup_512x(struct device_node *node, 242 + struct mpc_i2c *i2c, 243 + u32 clock, u32 prescaler) 244 + { 245 + struct device_node *node_ctrl; 246 + void __iomem *ctrl; 247 + const u32 *pval; 248 + u32 idx; 249 + 250 + /* Enable I2C interrupts for mpc5121 */ 251 + node_ctrl = of_find_compatible_node(NULL, NULL, 252 + "fsl,mpc5121-i2c-ctrl"); 253 + if (node_ctrl) { 254 + ctrl = of_iomap(node_ctrl, 0); 255 + if (ctrl) { 256 + /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ 257 + pval = of_get_property(node, "reg", NULL); 258 + idx = (*pval & 0xff) / 0x20; 259 + setbits32(ctrl, 1 << (24 + idx * 2)); 260 + iounmap(ctrl); 261 + } 262 + of_node_put(node_ctrl); 263 + } 264 + 265 + /* The clock setup for the 52xx works also fine for the 512x */ 266 + mpc_i2c_setup_52xx(node, i2c, clock, prescaler); 267 + } 268 + #else /* CONFIG_PPC_MPC512x */ 269 + static void __devinit mpc_i2c_setup_512x(struct device_node *node, 270 + struct mpc_i2c *i2c, 271 + u32 clock, u32 prescaler) 272 + { 273 + } 274 + #endif /* CONFIG_PPC_MPC512x */ 248 275 249 276 #ifdef CONFIG_FSL_SOC 250 - static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = { 277 + static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] __devinitconst = { 251 278 {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123}, 252 279 {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102}, 253 280 {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127}, ··· 303 258 {49152, 0x011e}, {61440, 0x011f} 304 259 }; 305 260 306 - u32 mpc_i2c_get_sec_cfg_8xxx(void) 261 + static u32 __devinit mpc_i2c_get_sec_cfg_8xxx(void) 307 262 { 308 263 struct device_node *node = NULL; 309 264 u32 __iomem *reg; ··· 332 287 return val; 333 288 } 334 289 335 - int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler) 290 + static int __devinit mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, 291 + u32 prescaler) 336 292 { 337 293 const struct mpc_i2c_divider *div = NULL; 338 294 u32 divider; 339 295 int i; 340 296 341 - if (!clock) 297 + if (clock == MPC_I2C_CLOCK_LEGACY) 342 298 return -EINVAL; 343 299 344 300 /* Determine proper divider value */ ··· 366 320 return div ? (int)div->fdr : -EINVAL; 367 321 } 368 322 369 - static void mpc_i2c_setclock_8xxx(struct device_node *node, 370 - struct mpc_i2c *i2c, 371 - u32 clock, u32 prescaler) 323 + static void __devinit mpc_i2c_setup_8xxx(struct device_node *node, 324 + struct mpc_i2c *i2c, 325 + u32 clock, u32 prescaler) 372 326 { 373 327 int ret, fdr; 328 + 329 + if (clock == MPC_I2C_CLOCK_PRESERVE) { 330 + dev_dbg(i2c->dev, "using dfsrr %d, fdr %d\n", 331 + readb(i2c->base + MPC_I2C_DFSRR), 332 + readb(i2c->base + MPC_I2C_FDR)); 333 + return; 334 + } 374 335 375 336 ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler); 376 337 fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ ··· 391 338 } 392 339 393 340 #else /* !CONFIG_FSL_SOC */ 394 - static void mpc_i2c_setclock_8xxx(struct device_node *node, 395 - struct mpc_i2c *i2c, 396 - u32 clock, u32 prescaler) 341 + static void __devinit mpc_i2c_setup_8xxx(struct device_node *node, 342 + struct mpc_i2c *i2c, 343 + u32 clock, u32 prescaler) 397 344 { 398 345 } 399 346 #endif /* CONFIG_FSL_SOC */ ··· 547 494 { 548 495 struct mpc_i2c *i2c; 549 496 const u32 *prop; 550 - u32 clock = 0; 497 + u32 clock = MPC_I2C_CLOCK_LEGACY; 551 498 int result = 0; 552 499 int plen; 553 500 ··· 576 523 } 577 524 } 578 525 579 - if (!of_get_property(op->node, "fsl,preserve-clocking", NULL)) { 526 + if (of_get_property(op->node, "fsl,preserve-clocking", NULL)) { 527 + clock = MPC_I2C_CLOCK_PRESERVE; 528 + } else { 580 529 prop = of_get_property(op->node, "clock-frequency", &plen); 581 530 if (prop && plen == sizeof(u32)) 582 531 clock = *prop; 532 + } 583 533 584 - if (match->data) { 585 - struct mpc_i2c_match_data *data = 586 - (struct mpc_i2c_match_data *)match->data; 587 - data->setclock(op->node, i2c, clock, data->prescaler); 588 - } else { 589 - /* Backwards compatibility */ 590 - if (of_get_property(op->node, "dfsrr", NULL)) 591 - mpc_i2c_setclock_8xxx(op->node, i2c, 592 - clock, 0); 593 - } 534 + if (match->data) { 535 + struct mpc_i2c_data *data = match->data; 536 + data->setup(op->node, i2c, clock, data->prescaler); 537 + } else { 538 + /* Backwards compatibility */ 539 + if (of_get_property(op->node, "dfsrr", NULL)) 540 + mpc_i2c_setup_8xxx(op->node, i2c, clock, 0); 594 541 } 595 542 596 543 dev_set_drvdata(&op->dev, i2c); ··· 635 582 return 0; 636 583 }; 637 584 585 + static struct mpc_i2c_data mpc_i2c_data_512x __devinitdata = { 586 + .setup = mpc_i2c_setup_512x, 587 + }; 588 + 589 + static struct mpc_i2c_data mpc_i2c_data_52xx __devinitdata = { 590 + .setup = mpc_i2c_setup_52xx, 591 + }; 592 + 593 + static struct mpc_i2c_data mpc_i2c_data_8313 __devinitdata = { 594 + .setup = mpc_i2c_setup_8xxx, 595 + }; 596 + 597 + static struct mpc_i2c_data mpc_i2c_data_8543 __devinitdata = { 598 + .setup = mpc_i2c_setup_8xxx, 599 + .prescaler = 2, 600 + }; 601 + 602 + static struct mpc_i2c_data mpc_i2c_data_8544 __devinitdata = { 603 + .setup = mpc_i2c_setup_8xxx, 604 + .prescaler = 3, 605 + }; 606 + 638 607 static const struct of_device_id mpc_i2c_of_match[] = { 639 - {.compatible = "mpc5200-i2c", 640 - .data = &(struct mpc_i2c_match_data) { 641 - .setclock = mpc_i2c_setclock_52xx, 642 - }, 643 - }, 644 - {.compatible = "fsl,mpc5200b-i2c", 645 - .data = &(struct mpc_i2c_match_data) { 646 - .setclock = mpc_i2c_setclock_52xx, 647 - }, 648 - }, 649 - {.compatible = "fsl,mpc5200-i2c", 650 - .data = &(struct mpc_i2c_match_data) { 651 - .setclock = mpc_i2c_setclock_52xx, 652 - }, 653 - }, 654 - {.compatible = "fsl,mpc8313-i2c", 655 - .data = &(struct mpc_i2c_match_data) { 656 - .setclock = mpc_i2c_setclock_8xxx, 657 - }, 658 - }, 659 - {.compatible = "fsl,mpc8543-i2c", 660 - .data = &(struct mpc_i2c_match_data) { 661 - .setclock = mpc_i2c_setclock_8xxx, 662 - .prescaler = 2, 663 - }, 664 - }, 665 - {.compatible = "fsl,mpc8544-i2c", 666 - .data = &(struct mpc_i2c_match_data) { 667 - .setclock = mpc_i2c_setclock_8xxx, 668 - .prescaler = 3, 669 - }, 608 + {.compatible = "mpc5200-i2c", .data = &mpc_i2c_data_52xx, }, 609 + {.compatible = "fsl,mpc5200b-i2c", .data = &mpc_i2c_data_52xx, }, 610 + {.compatible = "fsl,mpc5200-i2c", .data = &mpc_i2c_data_52xx, }, 611 + {.compatible = "fsl,mpc5121-i2c", .data = &mpc_i2c_data_512x, }, 612 + {.compatible = "fsl,mpc8313-i2c", .data = &mpc_i2c_data_8313, }, 613 + {.compatible = "fsl,mpc8543-i2c", .data = &mpc_i2c_data_8543, }, 614 + {.compatible = "fsl,mpc8544-i2c", .data = &mpc_i2c_data_8544, }, 670 615 /* Backward compatibility */ 671 - }, 672 616 {.compatible = "fsl-i2c", }, 673 617 {}, 674 618 }; 675 - 676 619 MODULE_DEVICE_TABLE(of, mpc_i2c_of_match); 677 - 678 620 679 621 /* Structure for a device driver */ 680 622 static struct of_platform_driver mpc_i2c_driver = { ··· 703 655 704 656 MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 705 657 MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " 706 - "MPC824x/85xx/52xx processors"); 658 + "MPC824x/83xx/85xx/86xx/512x/52xx processors"); 707 659 MODULE_LICENSE("GPL");