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 3 Required properties : 4 5 - - device_type : Should be "i2c" 6 - reg : Offset and length of the register set for the device 7 8 Recommended properties : 9 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 - interrupts : <a b> where a is the interrupt number and b is a 15 field that represents an encoding of the sense and level 16 information for the interrupt. This should be encoded based on ··· 23 24 Examples : 25 26 i2c@3d00 { 27 #address-cells = <1>; 28 #size-cells = <0>; 29 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 30 - cell-index = <0>; 31 reg = <0x3d00 0x40>; 32 interrupts = <2 15 0>; 33 interrupt-parent = <&mpc5200_pic>; 34 fsl,preserve-clocking; 35 }; 36 37 i2c@3100 { 38 #address-cells = <1>; 39 #size-cells = <0>; 40 - cell-index = <1>; 41 compatible = "fsl,mpc8544-i2c", "fsl-i2c"; 42 reg = <0x3100 0x100>; 43 interrupts = <43 2>; 44 interrupt-parent = <&mpic>; 45 clock-frequency = <400000>; 46 }; 47 -
··· 2 3 Required properties : 4 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. 10 11 Recommended properties : 12 13 - interrupts : <a b> where a is the interrupt number and b is a 14 field that represents an encoding of the sense and level 15 information for the interrupt. This should be encoded based on ··· 24 25 Examples : 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 */ 44 i2c@3d00 { 45 #address-cells = <1>; 46 #size-cells = <0>; 47 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 48 reg = <0x3d00 0x40>; 49 interrupts = <2 15 0>; 50 interrupt-parent = <&mpc5200_pic>; 51 fsl,preserve-clocking; 52 }; 53 54 + /* MPC8544 base board */ 55 i2c@3100 { 56 #address-cells = <1>; 57 #size-cells = <0>; 58 compatible = "fsl,mpc8544-i2c", "fsl-i2c"; 59 reg = <0x3100 0x100>; 60 interrupts = <43 2>; 61 interrupt-parent = <&mpic>; 62 clock-frequency = <400000>; 63 };
+3 -4
drivers/i2c/busses/Kconfig
··· 419 instead. 420 421 config I2C_MPC 422 - tristate "MPC107/824x/85xx/52xx/86xx" 423 depends on PPC32 424 help 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. 429 430 This driver can also be built as a module. If so, the module 431 will be called i2c-mpc.
··· 419 instead. 420 421 config I2C_MPC 422 + tristate "MPC107/824x/85xx/512x/52xx/83xx/86xx" 423 depends on PPC32 424 help 425 If you say yes to this option, support will be included for the 426 + built-in I2C interface on the MPC107, Tsi107, MPC512x, MPC52xx, 427 + MPC8240, MPC8245, MPC83xx, MPC85xx and MPC8641 family processors. 428 429 This driver can also be built as a module. If so, the module 430 will be called i2c-mpc.
+121 -73
drivers/i2c/busses/i2c-mpc.c
··· 31 32 #define DRV_NAME "mpc-i2c" 33 34 #define MPC_I2C_FDR 0x04 35 #define MPC_I2C_CR 0x08 36 #define MPC_I2C_SR 0x0c ··· 69 u16 fdr; /* including dfsrr */ 70 }; 71 72 - struct mpc_i2c_match_data { 73 - void (*setclock)(struct device_node *node, 74 - struct mpc_i2c *i2c, 75 - u32 clock, u32 prescaler); 76 u32 prescaler; 77 }; 78 ··· 166 return 0; 167 } 168 169 - #ifdef CONFIG_PPC_MPC52xx 170 - static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { 171 {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, 172 {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, 173 {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28}, ··· 188 {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f} 189 }; 190 191 - int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler) 192 { 193 const struct mpc_i2c_divider *div = NULL; 194 unsigned int pvr = mfspr(SPRN_PVR); 195 u32 divider; 196 int i; 197 198 - if (!clock) 199 return -EINVAL; 200 201 /* Determine divider value */ ··· 218 return div ? (int)div->fdr : -EINVAL; 219 } 220 221 - static void mpc_i2c_setclock_52xx(struct device_node *node, 222 - struct mpc_i2c *i2c, 223 - u32 clock, u32 prescaler) 224 { 225 int ret, fdr; 226 227 ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); 228 fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ ··· 238 if (ret >= 0) 239 dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr); 240 } 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) 245 { 246 } 247 - #endif /* CONFIG_PPC_MPC52xx*/ 248 249 #ifdef CONFIG_FSL_SOC 250 - static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = { 251 {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123}, 252 {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102}, 253 {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127}, ··· 303 {49152, 0x011e}, {61440, 0x011f} 304 }; 305 306 - u32 mpc_i2c_get_sec_cfg_8xxx(void) 307 { 308 struct device_node *node = NULL; 309 u32 __iomem *reg; ··· 332 return val; 333 } 334 335 - int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler) 336 { 337 const struct mpc_i2c_divider *div = NULL; 338 u32 divider; 339 int i; 340 341 - if (!clock) 342 return -EINVAL; 343 344 /* Determine proper divider value */ ··· 366 return div ? (int)div->fdr : -EINVAL; 367 } 368 369 - static void mpc_i2c_setclock_8xxx(struct device_node *node, 370 - struct mpc_i2c *i2c, 371 - u32 clock, u32 prescaler) 372 { 373 int ret, fdr; 374 375 ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler); 376 fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ ··· 391 } 392 393 #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) 397 { 398 } 399 #endif /* CONFIG_FSL_SOC */ ··· 547 { 548 struct mpc_i2c *i2c; 549 const u32 *prop; 550 - u32 clock = 0; 551 int result = 0; 552 int plen; 553 ··· 576 } 577 } 578 579 - if (!of_get_property(op->node, "fsl,preserve-clocking", NULL)) { 580 prop = of_get_property(op->node, "clock-frequency", &plen); 581 if (prop && plen == sizeof(u32)) 582 clock = *prop; 583 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 - } 594 } 595 596 dev_set_drvdata(&op->dev, i2c); ··· 635 return 0; 636 }; 637 638 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 - }, 670 /* Backward compatibility */ 671 - }, 672 {.compatible = "fsl-i2c", }, 673 {}, 674 }; 675 - 676 MODULE_DEVICE_TABLE(of, mpc_i2c_of_match); 677 - 678 679 /* Structure for a device driver */ 680 static struct of_platform_driver mpc_i2c_driver = { ··· 703 704 MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 705 MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " 706 - "MPC824x/85xx/52xx processors"); 707 MODULE_LICENSE("GPL");
··· 31 32 #define DRV_NAME "mpc-i2c" 33 34 + #define MPC_I2C_CLOCK_LEGACY 0 35 + #define MPC_I2C_CLOCK_PRESERVE (~0U) 36 + 37 #define MPC_I2C_FDR 0x04 38 #define MPC_I2C_CR 0x08 39 #define MPC_I2C_SR 0x0c ··· 66 u16 fdr; /* including dfsrr */ 67 }; 68 69 + struct mpc_i2c_data { 70 + void (*setup)(struct device_node *node, struct mpc_i2c *i2c, 71 + u32 clock, u32 prescaler); 72 u32 prescaler; 73 }; 74 ··· 164 return 0; 165 } 166 167 + #if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) 168 + static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] __devinitconst = { 169 {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, 170 {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, 171 {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28}, ··· 186 {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f} 187 }; 188 189 + static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, 190 + int prescaler) 191 { 192 const struct mpc_i2c_divider *div = NULL; 193 unsigned int pvr = mfspr(SPRN_PVR); 194 u32 divider; 195 int i; 196 197 + if (clock == MPC_I2C_CLOCK_LEGACY) 198 return -EINVAL; 199 200 /* Determine divider value */ ··· 215 return div ? (int)div->fdr : -EINVAL; 216 } 217 218 + static void __devinit mpc_i2c_setup_52xx(struct device_node *node, 219 + struct mpc_i2c *i2c, 220 + u32 clock, u32 prescaler) 221 { 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 + } 229 230 ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); 231 fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ ··· 229 if (ret >= 0) 230 dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr); 231 } 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) 236 { 237 } 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 */ 275 276 #ifdef CONFIG_FSL_SOC 277 + static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] __devinitconst = { 278 {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123}, 279 {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102}, 280 {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127}, ··· 258 {49152, 0x011e}, {61440, 0x011f} 259 }; 260 261 + static u32 __devinit mpc_i2c_get_sec_cfg_8xxx(void) 262 { 263 struct device_node *node = NULL; 264 u32 __iomem *reg; ··· 287 return val; 288 } 289 290 + static int __devinit mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, 291 + u32 prescaler) 292 { 293 const struct mpc_i2c_divider *div = NULL; 294 u32 divider; 295 int i; 296 297 + if (clock == MPC_I2C_CLOCK_LEGACY) 298 return -EINVAL; 299 300 /* Determine proper divider value */ ··· 320 return div ? (int)div->fdr : -EINVAL; 321 } 322 323 + static void __devinit mpc_i2c_setup_8xxx(struct device_node *node, 324 + struct mpc_i2c *i2c, 325 + u32 clock, u32 prescaler) 326 { 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 + } 335 336 ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler); 337 fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ ··· 338 } 339 340 #else /* !CONFIG_FSL_SOC */ 341 + static void __devinit mpc_i2c_setup_8xxx(struct device_node *node, 342 + struct mpc_i2c *i2c, 343 + u32 clock, u32 prescaler) 344 { 345 } 346 #endif /* CONFIG_FSL_SOC */ ··· 494 { 495 struct mpc_i2c *i2c; 496 const u32 *prop; 497 + u32 clock = MPC_I2C_CLOCK_LEGACY; 498 int result = 0; 499 int plen; 500 ··· 523 } 524 } 525 526 + if (of_get_property(op->node, "fsl,preserve-clocking", NULL)) { 527 + clock = MPC_I2C_CLOCK_PRESERVE; 528 + } else { 529 prop = of_get_property(op->node, "clock-frequency", &plen); 530 if (prop && plen == sizeof(u32)) 531 clock = *prop; 532 + } 533 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); 541 } 542 543 dev_set_drvdata(&op->dev, i2c); ··· 582 return 0; 583 }; 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 + 607 static const struct of_device_id mpc_i2c_of_match[] = { 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, }, 615 /* Backward compatibility */ 616 {.compatible = "fsl-i2c", }, 617 {}, 618 }; 619 MODULE_DEVICE_TABLE(of, mpc_i2c_of_match); 620 621 /* Structure for a device driver */ 622 static struct of_platform_driver mpc_i2c_driver = { ··· 655 656 MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 657 MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " 658 + "MPC824x/83xx/85xx/86xx/512x/52xx processors"); 659 MODULE_LICENSE("GPL");