aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-mpc.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /drivers/i2c/busses/i2c-mpc.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/i2c/busses/i2c-mpc.c')
-rw-r--r--drivers/i2c/busses/i2c-mpc.c195
1 files changed, 122 insertions, 73 deletions
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index f627001108b8..f1321f763789 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/of_platform.h> 20#include <linux/of_platform.h>
21#include <linux/of_i2c.h> 21#include <linux/of_i2c.h>
22#include <linux/slab.h>
22 23
23#include <linux/io.h> 24#include <linux/io.h>
24#include <linux/fsl_devices.h> 25#include <linux/fsl_devices.h>
@@ -31,6 +32,9 @@
31 32
32#define DRV_NAME "mpc-i2c" 33#define DRV_NAME "mpc-i2c"
33 34
35#define MPC_I2C_CLOCK_LEGACY 0
36#define MPC_I2C_CLOCK_PRESERVE (~0U)
37
34#define MPC_I2C_FDR 0x04 38#define MPC_I2C_FDR 0x04
35#define MPC_I2C_CR 0x08 39#define MPC_I2C_CR 0x08
36#define MPC_I2C_SR 0x0c 40#define MPC_I2C_SR 0x0c
@@ -66,10 +70,9 @@ struct mpc_i2c_divider {
66 u16 fdr; /* including dfsrr */ 70 u16 fdr; /* including dfsrr */
67}; 71};
68 72
69struct mpc_i2c_match_data { 73struct mpc_i2c_data {
70 void (*setclock)(struct device_node *node, 74 void (*setup)(struct device_node *node, struct mpc_i2c *i2c,
71 struct mpc_i2c *i2c, 75 u32 clock, u32 prescaler);
72 u32 clock, u32 prescaler);
73 u32 prescaler; 76 u32 prescaler;
74}; 77};
75 78
@@ -164,8 +167,8 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
164 return 0; 167 return 0;
165} 168}
166 169
167#ifdef CONFIG_PPC_MPC52xx 170#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x)
168static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { 171static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] __devinitconst = {
169 {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, 172 {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23},
170 {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, 173 {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02},
171 {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28}, 174 {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28},
@@ -186,14 +189,15 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = {
186 {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f} 189 {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f}
187}; 190};
188 191
189int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler) 192static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock,
193 int prescaler)
190{ 194{
191 const struct mpc_i2c_divider *div = NULL; 195 const struct mpc_i2c_divider *div = NULL;
192 unsigned int pvr = mfspr(SPRN_PVR); 196 unsigned int pvr = mfspr(SPRN_PVR);
193 u32 divider; 197 u32 divider;
194 int i; 198 int i;
195 199
196 if (!clock) 200 if (clock == MPC_I2C_CLOCK_LEGACY)
197 return -EINVAL; 201 return -EINVAL;
198 202
199 /* Determine divider value */ 203 /* Determine divider value */
@@ -215,12 +219,18 @@ int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler)
215 return div ? (int)div->fdr : -EINVAL; 219 return div ? (int)div->fdr : -EINVAL;
216} 220}
217 221
218static void mpc_i2c_setclock_52xx(struct device_node *node, 222static void __devinit mpc_i2c_setup_52xx(struct device_node *node,
219 struct mpc_i2c *i2c, 223 struct mpc_i2c *i2c,
220 u32 clock, u32 prescaler) 224 u32 clock, u32 prescaler)
221{ 225{
222 int ret, fdr; 226 int ret, fdr;
223 227
228 if (clock == MPC_I2C_CLOCK_PRESERVE) {
229 dev_dbg(i2c->dev, "using fdr %d\n",
230 readb(i2c->base + MPC_I2C_FDR));
231 return;
232 }
233
224 ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); 234 ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler);
225 fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ 235 fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */
226 236
@@ -229,16 +239,52 @@ static void mpc_i2c_setclock_52xx(struct device_node *node,
229 if (ret >= 0) 239 if (ret >= 0)
230 dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr); 240 dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr);
231} 241}
232#else /* !CONFIG_PPC_MPC52xx */ 242#else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */
233static void mpc_i2c_setclock_52xx(struct device_node *node, 243static void __devinit mpc_i2c_setup_52xx(struct device_node *node,
234 struct mpc_i2c *i2c, 244 struct mpc_i2c *i2c,
235 u32 clock, u32 prescaler) 245 u32 clock, u32 prescaler)
246{
247}
248#endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */
249
250#ifdef CONFIG_PPC_MPC512x
251static void __devinit mpc_i2c_setup_512x(struct device_node *node,
252 struct mpc_i2c *i2c,
253 u32 clock, u32 prescaler)
254{
255 struct device_node *node_ctrl;
256 void __iomem *ctrl;
257 const u32 *pval;
258 u32 idx;
259
260 /* Enable I2C interrupts for mpc5121 */
261 node_ctrl = of_find_compatible_node(NULL, NULL,
262 "fsl,mpc5121-i2c-ctrl");
263 if (node_ctrl) {
264 ctrl = of_iomap(node_ctrl, 0);
265 if (ctrl) {
266 /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */
267 pval = of_get_property(node, "reg", NULL);
268 idx = (*pval & 0xff) / 0x20;
269 setbits32(ctrl, 1 << (24 + idx * 2));
270 iounmap(ctrl);
271 }
272 of_node_put(node_ctrl);
273 }
274
275 /* The clock setup for the 52xx works also fine for the 512x */
276 mpc_i2c_setup_52xx(node, i2c, clock, prescaler);
277}
278#else /* CONFIG_PPC_MPC512x */
279static void __devinit mpc_i2c_setup_512x(struct device_node *node,
280 struct mpc_i2c *i2c,
281 u32 clock, u32 prescaler)
236{ 282{
237} 283}
238#endif /* CONFIG_PPC_MPC52xx*/ 284#endif /* CONFIG_PPC_MPC512x */
239 285
240#ifdef CONFIG_FSL_SOC 286#ifdef CONFIG_FSL_SOC
241static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = { 287static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] __devinitconst = {
242 {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123}, 288 {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123},
243 {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102}, 289 {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102},
244 {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127}, 290 {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127},
@@ -258,7 +304,7 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = {
258 {49152, 0x011e}, {61440, 0x011f} 304 {49152, 0x011e}, {61440, 0x011f}
259}; 305};
260 306
261u32 mpc_i2c_get_sec_cfg_8xxx(void) 307static u32 __devinit mpc_i2c_get_sec_cfg_8xxx(void)
262{ 308{
263 struct device_node *node = NULL; 309 struct device_node *node = NULL;
264 u32 __iomem *reg; 310 u32 __iomem *reg;
@@ -287,13 +333,14 @@ u32 mpc_i2c_get_sec_cfg_8xxx(void)
287 return val; 333 return val;
288} 334}
289 335
290int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler) 336static int __devinit mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock,
337 u32 prescaler)
291{ 338{
292 const struct mpc_i2c_divider *div = NULL; 339 const struct mpc_i2c_divider *div = NULL;
293 u32 divider; 340 u32 divider;
294 int i; 341 int i;
295 342
296 if (!clock) 343 if (clock == MPC_I2C_CLOCK_LEGACY)
297 return -EINVAL; 344 return -EINVAL;
298 345
299 /* Determine proper divider value */ 346 /* Determine proper divider value */
@@ -320,12 +367,19 @@ int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler)
320 return div ? (int)div->fdr : -EINVAL; 367 return div ? (int)div->fdr : -EINVAL;
321} 368}
322 369
323static void mpc_i2c_setclock_8xxx(struct device_node *node, 370static void __devinit mpc_i2c_setup_8xxx(struct device_node *node,
324 struct mpc_i2c *i2c, 371 struct mpc_i2c *i2c,
325 u32 clock, u32 prescaler) 372 u32 clock, u32 prescaler)
326{ 373{
327 int ret, fdr; 374 int ret, fdr;
328 375
376 if (clock == MPC_I2C_CLOCK_PRESERVE) {
377 dev_dbg(i2c->dev, "using dfsrr %d, fdr %d\n",
378 readb(i2c->base + MPC_I2C_DFSRR),
379 readb(i2c->base + MPC_I2C_FDR));
380 return;
381 }
382
329 ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler); 383 ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler);
330 fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ 384 fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */
331 385
@@ -338,9 +392,9 @@ static void mpc_i2c_setclock_8xxx(struct device_node *node,
338} 392}
339 393
340#else /* !CONFIG_FSL_SOC */ 394#else /* !CONFIG_FSL_SOC */
341static void mpc_i2c_setclock_8xxx(struct device_node *node, 395static void __devinit mpc_i2c_setup_8xxx(struct device_node *node,
342 struct mpc_i2c *i2c, 396 struct mpc_i2c *i2c,
343 u32 clock, u32 prescaler) 397 u32 clock, u32 prescaler)
344{ 398{
345} 399}
346#endif /* CONFIG_FSL_SOC */ 400#endif /* CONFIG_FSL_SOC */
@@ -494,7 +548,7 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
494{ 548{
495 struct mpc_i2c *i2c; 549 struct mpc_i2c *i2c;
496 const u32 *prop; 550 const u32 *prop;
497 u32 clock = 0; 551 u32 clock = MPC_I2C_CLOCK_LEGACY;
498 int result = 0; 552 int result = 0;
499 int plen; 553 int plen;
500 554
@@ -523,21 +577,21 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
523 } 577 }
524 } 578 }
525 579
526 if (!of_get_property(op->node, "fsl,preserve-clocking", NULL)) { 580 if (of_get_property(op->node, "fsl,preserve-clocking", NULL)) {
581 clock = MPC_I2C_CLOCK_PRESERVE;
582 } else {
527 prop = of_get_property(op->node, "clock-frequency", &plen); 583 prop = of_get_property(op->node, "clock-frequency", &plen);
528 if (prop && plen == sizeof(u32)) 584 if (prop && plen == sizeof(u32))
529 clock = *prop; 585 clock = *prop;
586 }
530 587
531 if (match->data) { 588 if (match->data) {
532 struct mpc_i2c_match_data *data = 589 struct mpc_i2c_data *data = match->data;
533 (struct mpc_i2c_match_data *)match->data; 590 data->setup(op->node, i2c, clock, data->prescaler);
534 data->setclock(op->node, i2c, clock, data->prescaler); 591 } else {
535 } else { 592 /* Backwards compatibility */
536 /* Backwards compatibility */ 593 if (of_get_property(op->node, "dfsrr", NULL))
537 if (of_get_property(op->node, "dfsrr", NULL)) 594 mpc_i2c_setup_8xxx(op->node, i2c, clock, 0);
538 mpc_i2c_setclock_8xxx(op->node, i2c,
539 clock, 0);
540 }
541 } 595 }
542 596
543 dev_set_drvdata(&op->dev, i2c); 597 dev_set_drvdata(&op->dev, i2c);
@@ -582,47 +636,42 @@ static int __devexit fsl_i2c_remove(struct of_device *op)
582 return 0; 636 return 0;
583}; 637};
584 638
639static struct mpc_i2c_data mpc_i2c_data_512x __devinitdata = {
640 .setup = mpc_i2c_setup_512x,
641};
642
643static struct mpc_i2c_data mpc_i2c_data_52xx __devinitdata = {
644 .setup = mpc_i2c_setup_52xx,
645};
646
647static struct mpc_i2c_data mpc_i2c_data_8313 __devinitdata = {
648 .setup = mpc_i2c_setup_8xxx,
649};
650
651static struct mpc_i2c_data mpc_i2c_data_8543 __devinitdata = {
652 .setup = mpc_i2c_setup_8xxx,
653 .prescaler = 2,
654};
655
656static struct mpc_i2c_data mpc_i2c_data_8544 __devinitdata = {
657 .setup = mpc_i2c_setup_8xxx,
658 .prescaler = 3,
659};
660
585static const struct of_device_id mpc_i2c_of_match[] = { 661static const struct of_device_id mpc_i2c_of_match[] = {
586 {.compatible = "mpc5200-i2c", 662 {.compatible = "mpc5200-i2c", .data = &mpc_i2c_data_52xx, },
587 .data = &(struct mpc_i2c_match_data) { 663 {.compatible = "fsl,mpc5200b-i2c", .data = &mpc_i2c_data_52xx, },
588 .setclock = mpc_i2c_setclock_52xx, 664 {.compatible = "fsl,mpc5200-i2c", .data = &mpc_i2c_data_52xx, },
589 }, 665 {.compatible = "fsl,mpc5121-i2c", .data = &mpc_i2c_data_512x, },
590 }, 666 {.compatible = "fsl,mpc8313-i2c", .data = &mpc_i2c_data_8313, },
591 {.compatible = "fsl,mpc5200b-i2c", 667 {.compatible = "fsl,mpc8543-i2c", .data = &mpc_i2c_data_8543, },
592 .data = &(struct mpc_i2c_match_data) { 668 {.compatible = "fsl,mpc8544-i2c", .data = &mpc_i2c_data_8544, },
593 .setclock = mpc_i2c_setclock_52xx,
594 },
595 },
596 {.compatible = "fsl,mpc5200-i2c",
597 .data = &(struct mpc_i2c_match_data) {
598 .setclock = mpc_i2c_setclock_52xx,
599 },
600 },
601 {.compatible = "fsl,mpc8313-i2c",
602 .data = &(struct mpc_i2c_match_data) {
603 .setclock = mpc_i2c_setclock_8xxx,
604 },
605 },
606 {.compatible = "fsl,mpc8543-i2c",
607 .data = &(struct mpc_i2c_match_data) {
608 .setclock = mpc_i2c_setclock_8xxx,
609 .prescaler = 2,
610 },
611 },
612 {.compatible = "fsl,mpc8544-i2c",
613 .data = &(struct mpc_i2c_match_data) {
614 .setclock = mpc_i2c_setclock_8xxx,
615 .prescaler = 3,
616 },
617 /* Backward compatibility */ 669 /* Backward compatibility */
618 },
619 {.compatible = "fsl-i2c", }, 670 {.compatible = "fsl-i2c", },
620 {}, 671 {},
621}; 672};
622
623MODULE_DEVICE_TABLE(of, mpc_i2c_of_match); 673MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
624 674
625
626/* Structure for a device driver */ 675/* Structure for a device driver */
627static struct of_platform_driver mpc_i2c_driver = { 676static struct of_platform_driver mpc_i2c_driver = {
628 .match_table = mpc_i2c_of_match, 677 .match_table = mpc_i2c_of_match,
@@ -655,5 +704,5 @@ module_exit(fsl_i2c_exit);
655 704
656MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 705MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
657MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " 706MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and "
658 "MPC824x/85xx/52xx processors"); 707 "MPC824x/83xx/85xx/86xx/512x/52xx processors");
659MODULE_LICENSE("GPL"); 708MODULE_LICENSE("GPL");