aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/mips/cavium-octeon/octeon-irq.c2
-rw-r--r--arch/mips/cavium-octeon/octeon-platform.c84
-rw-r--r--arch/mips/include/asm/octeon/octeon.h5
-rw-r--r--drivers/i2c/busses/i2c-octeon.c92
4 files changed, 49 insertions, 134 deletions
diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
index 52610ce50dfc..2a661ad35cf7 100644
--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -1192,13 +1192,11 @@ static void __init octeon_irq_init_ciu(void)
1192 for (i = 0; i < 4; i++) 1192 for (i = 0; i < 4; i++)
1193 octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_PCI_MSI0, 0, i + 40, chip, handle_level_irq); 1193 octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_PCI_MSI0, 0, i + 40, chip, handle_level_irq);
1194 1194
1195 octeon_irq_set_ciu_mapping(OCTEON_IRQ_TWSI, 0, 45, chip, handle_level_irq);
1196 octeon_irq_set_ciu_mapping(OCTEON_IRQ_RML, 0, 46, chip, handle_level_irq); 1195 octeon_irq_set_ciu_mapping(OCTEON_IRQ_RML, 0, 46, chip, handle_level_irq);
1197 for (i = 0; i < 4; i++) 1196 for (i = 0; i < 4; i++)
1198 octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_TIMER0, 0, i + 52, chip, handle_edge_irq); 1197 octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_TIMER0, 0, i + 52, chip, handle_edge_irq);
1199 1198
1200 octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB0, 0, 56, chip, handle_level_irq); 1199 octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB0, 0, 56, chip, handle_level_irq);
1201 octeon_irq_set_ciu_mapping(OCTEON_IRQ_TWSI2, 0, 59, chip, handle_level_irq);
1202 octeon_irq_set_ciu_mapping(OCTEON_IRQ_MII0, 0, 62, chip, handle_level_irq); 1200 octeon_irq_set_ciu_mapping(OCTEON_IRQ_MII0, 0, 62, chip, handle_level_irq);
1203 octeon_irq_set_ciu_mapping(OCTEON_IRQ_BOOTDMA, 0, 63, chip, handle_level_irq); 1201 octeon_irq_set_ciu_mapping(OCTEON_IRQ_BOOTDMA, 0, 63, chip, handle_level_irq);
1204 1202
diff --git a/arch/mips/cavium-octeon/octeon-platform.c b/arch/mips/cavium-octeon/octeon-platform.c
index 2754bc225903..f62a40f424ca 100644
--- a/arch/mips/cavium-octeon/octeon-platform.c
+++ b/arch/mips/cavium-octeon/octeon-platform.c
@@ -168,90 +168,6 @@ out:
168} 168}
169device_initcall(octeon_rng_device_init); 169device_initcall(octeon_rng_device_init);
170 170
171static struct i2c_board_info __initdata octeon_i2c_devices[] = {
172 {
173 I2C_BOARD_INFO("ds1337", 0x68),
174 },
175};
176
177static int __init octeon_i2c_devices_init(void)
178{
179 return i2c_register_board_info(0, octeon_i2c_devices,
180 ARRAY_SIZE(octeon_i2c_devices));
181}
182arch_initcall(octeon_i2c_devices_init);
183
184#define OCTEON_I2C_IO_BASE 0x1180000001000ull
185#define OCTEON_I2C_IO_UNIT_OFFSET 0x200
186
187static struct octeon_i2c_data octeon_i2c_data[2];
188
189static int __init octeon_i2c_device_init(void)
190{
191 struct platform_device *pd;
192 int ret = 0;
193 int port, num_ports;
194
195 struct resource i2c_resources[] = {
196 {
197 .flags = IORESOURCE_MEM,
198 }, {
199 .flags = IORESOURCE_IRQ,
200 }
201 };
202
203 if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
204 num_ports = 2;
205 else
206 num_ports = 1;
207
208 for (port = 0; port < num_ports; port++) {
209 octeon_i2c_data[port].sys_freq = octeon_get_io_clock_rate();
210 /*FIXME: should be examined. At the moment is set for 100Khz */
211 octeon_i2c_data[port].i2c_freq = 100000;
212
213 pd = platform_device_alloc("i2c-octeon", port);
214 if (!pd) {
215 ret = -ENOMEM;
216 goto out;
217 }
218
219 pd->dev.platform_data = octeon_i2c_data + port;
220
221 i2c_resources[0].start =
222 OCTEON_I2C_IO_BASE + (port * OCTEON_I2C_IO_UNIT_OFFSET);
223 i2c_resources[0].end = i2c_resources[0].start + 0x1f;
224 switch (port) {
225 case 0:
226 i2c_resources[1].start = OCTEON_IRQ_TWSI;
227 i2c_resources[1].end = OCTEON_IRQ_TWSI;
228 break;
229 case 1:
230 i2c_resources[1].start = OCTEON_IRQ_TWSI2;
231 i2c_resources[1].end = OCTEON_IRQ_TWSI2;
232 break;
233 default:
234 BUG();
235 }
236
237 ret = platform_device_add_resources(pd,
238 i2c_resources,
239 ARRAY_SIZE(i2c_resources));
240 if (ret)
241 goto fail;
242
243 ret = platform_device_add(pd);
244 if (ret)
245 goto fail;
246 }
247 return ret;
248fail:
249 platform_device_put(pd);
250out:
251 return ret;
252}
253device_initcall(octeon_i2c_device_init);
254
255/* Octeon SMI/MDIO interface. */ 171/* Octeon SMI/MDIO interface. */
256static int __init octeon_mdiobus_device_init(void) 172static int __init octeon_mdiobus_device_init(void)
257{ 173{
diff --git a/arch/mips/include/asm/octeon/octeon.h b/arch/mips/include/asm/octeon/octeon.h
index f72f768cd3a4..1e2486e23573 100644
--- a/arch/mips/include/asm/octeon/octeon.h
+++ b/arch/mips/include/asm/octeon/octeon.h
@@ -215,11 +215,6 @@ struct octeon_cf_data {
215 int dma_engine; /* -1 for no DMA */ 215 int dma_engine; /* -1 for no DMA */
216}; 216};
217 217
218struct octeon_i2c_data {
219 unsigned int sys_freq;
220 unsigned int i2c_freq;
221};
222
223extern void octeon_write_lcd(const char *s); 218extern void octeon_write_lcd(const char *s);
224extern void octeon_check_cpu_bist(void); 219extern void octeon_check_cpu_bist(void);
225extern int octeon_get_boot_debug_flag(void); 220extern int octeon_get_boot_debug_flag(void);
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index ee139a598814..f44c83549fe5 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -2,7 +2,7 @@
2 * (C) Copyright 2009-2010 2 * (C) Copyright 2009-2010
3 * Nokia Siemens Networks, michael.lawnick.ext@nsn.com 3 * Nokia Siemens Networks, michael.lawnick.ext@nsn.com
4 * 4 *
5 * Portions Copyright (C) 2010 Cavium Networks, Inc. 5 * Portions Copyright (C) 2010, 2011 Cavium Networks, Inc.
6 * 6 *
7 * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors. 7 * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors.
8 * 8 *
@@ -11,17 +11,18 @@
11 * warranty of any kind, whether express or implied. 11 * warranty of any kind, whether express or implied.
12 */ 12 */
13 13
14#include <linux/platform_device.h>
15#include <linux/interrupt.h>
14#include <linux/kernel.h> 16#include <linux/kernel.h>
15#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of_i2c.h>
19#include <linux/delay.h>
16#include <linux/sched.h> 20#include <linux/sched.h>
17#include <linux/slab.h> 21#include <linux/slab.h>
18#include <linux/init.h> 22#include <linux/init.h>
19
20#include <linux/io.h>
21#include <linux/i2c.h> 23#include <linux/i2c.h>
22#include <linux/interrupt.h> 24#include <linux/io.h>
23#include <linux/delay.h> 25#include <linux/of.h>
24#include <linux/platform_device.h>
25 26
26#include <asm/octeon/octeon.h> 27#include <asm/octeon/octeon.h>
27 28
@@ -65,7 +66,7 @@ struct octeon_i2c {
65 wait_queue_head_t queue; 66 wait_queue_head_t queue;
66 struct i2c_adapter adap; 67 struct i2c_adapter adap;
67 int irq; 68 int irq;
68 int twsi_freq; 69 u32 twsi_freq;
69 int sys_freq; 70 int sys_freq;
70 resource_size_t twsi_phys; 71 resource_size_t twsi_phys;
71 void __iomem *twsi_base; 72 void __iomem *twsi_base;
@@ -121,10 +122,8 @@ static u8 octeon_i2c_read_sw(struct octeon_i2c *i2c, u64 eop_reg)
121 */ 122 */
122static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data) 123static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data)
123{ 124{
124 u64 tmp;
125
126 __raw_writeq(data, i2c->twsi_base + TWSI_INT); 125 __raw_writeq(data, i2c->twsi_base + TWSI_INT);
127 tmp = __raw_readq(i2c->twsi_base + TWSI_INT); 126 __raw_readq(i2c->twsi_base + TWSI_INT);
128} 127}
129 128
130/** 129/**
@@ -515,7 +514,6 @@ static int __devinit octeon_i2c_probe(struct platform_device *pdev)
515{ 514{
516 int irq, result = 0; 515 int irq, result = 0;
517 struct octeon_i2c *i2c; 516 struct octeon_i2c *i2c;
518 struct octeon_i2c_data *i2c_data;
519 struct resource *res_mem; 517 struct resource *res_mem;
520 518
521 /* All adaptors have an irq. */ 519 /* All adaptors have an irq. */
@@ -523,86 +521,90 @@ static int __devinit octeon_i2c_probe(struct platform_device *pdev)
523 if (irq < 0) 521 if (irq < 0)
524 return irq; 522 return irq;
525 523
526 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 524 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
527 if (!i2c) { 525 if (!i2c) {
528 dev_err(&pdev->dev, "kzalloc failed\n"); 526 dev_err(&pdev->dev, "kzalloc failed\n");
529 result = -ENOMEM; 527 result = -ENOMEM;
530 goto out; 528 goto out;
531 } 529 }
532 i2c->dev = &pdev->dev; 530 i2c->dev = &pdev->dev;
533 i2c_data = pdev->dev.platform_data;
534 531
535 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 532 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
536 533
537 if (res_mem == NULL) { 534 if (res_mem == NULL) {
538 dev_err(i2c->dev, "found no memory resource\n"); 535 dev_err(i2c->dev, "found no memory resource\n");
539 result = -ENXIO; 536 result = -ENXIO;
540 goto fail_region; 537 goto out;
541 } 538 }
539 i2c->twsi_phys = res_mem->start;
540 i2c->regsize = resource_size(res_mem);
542 541
543 if (i2c_data == NULL) { 542 /*
544 dev_err(i2c->dev, "no I2C frequency data\n"); 543 * "clock-rate" is a legacy binding, the official binding is
544 * "clock-frequency". Try the official one first and then
545 * fall back if it doesn't exist.
546 */
547 if (of_property_read_u32(pdev->dev.of_node,
548 "clock-frequency", &i2c->twsi_freq) &&
549 of_property_read_u32(pdev->dev.of_node,
550 "clock-rate", &i2c->twsi_freq)) {
551 dev_err(i2c->dev,
552 "no I2C 'clock-rate' or 'clock-frequency' property\n");
545 result = -ENXIO; 553 result = -ENXIO;
546 goto fail_region; 554 goto out;
547 } 555 }
548 556
549 i2c->twsi_phys = res_mem->start; 557 i2c->sys_freq = octeon_get_io_clock_rate();
550 i2c->regsize = resource_size(res_mem);
551 i2c->twsi_freq = i2c_data->i2c_freq;
552 i2c->sys_freq = i2c_data->sys_freq;
553 558
554 if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) { 559 if (!devm_request_mem_region(&pdev->dev, i2c->twsi_phys, i2c->regsize,
560 res_mem->name)) {
555 dev_err(i2c->dev, "request_mem_region failed\n"); 561 dev_err(i2c->dev, "request_mem_region failed\n");
556 goto fail_region; 562 goto out;
557 } 563 }
558 i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize); 564 i2c->twsi_base = devm_ioremap(&pdev->dev, i2c->twsi_phys, i2c->regsize);
559 565
560 init_waitqueue_head(&i2c->queue); 566 init_waitqueue_head(&i2c->queue);
561 567
562 i2c->irq = irq; 568 i2c->irq = irq;
563 569
564 result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c); 570 result = devm_request_irq(&pdev->dev, i2c->irq,
571 octeon_i2c_isr, 0, DRV_NAME, i2c);
565 if (result < 0) { 572 if (result < 0) {
566 dev_err(i2c->dev, "failed to attach interrupt\n"); 573 dev_err(i2c->dev, "failed to attach interrupt\n");
567 goto fail_irq; 574 goto out;
568 } 575 }
569 576
570 result = octeon_i2c_initlowlevel(i2c); 577 result = octeon_i2c_initlowlevel(i2c);
571 if (result) { 578 if (result) {
572 dev_err(i2c->dev, "init low level failed\n"); 579 dev_err(i2c->dev, "init low level failed\n");
573 goto fail_add; 580 goto out;
574 } 581 }
575 582
576 result = octeon_i2c_setclock(i2c); 583 result = octeon_i2c_setclock(i2c);
577 if (result) { 584 if (result) {
578 dev_err(i2c->dev, "clock init failed\n"); 585 dev_err(i2c->dev, "clock init failed\n");
579 goto fail_add; 586 goto out;
580 } 587 }
581 588
582 i2c->adap = octeon_i2c_ops; 589 i2c->adap = octeon_i2c_ops;
583 i2c->adap.dev.parent = &pdev->dev; 590 i2c->adap.dev.parent = &pdev->dev;
584 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0; 591 i2c->adap.dev.of_node = pdev->dev.of_node;
585 i2c_set_adapdata(&i2c->adap, i2c); 592 i2c_set_adapdata(&i2c->adap, i2c);
586 platform_set_drvdata(pdev, i2c); 593 platform_set_drvdata(pdev, i2c);
587 594
588 result = i2c_add_numbered_adapter(&i2c->adap); 595 result = i2c_add_adapter(&i2c->adap);
589 if (result < 0) { 596 if (result < 0) {
590 dev_err(i2c->dev, "failed to add adapter\n"); 597 dev_err(i2c->dev, "failed to add adapter\n");
591 goto fail_add; 598 goto fail_add;
592 } 599 }
593
594 dev_info(i2c->dev, "version %s\n", DRV_VERSION); 600 dev_info(i2c->dev, "version %s\n", DRV_VERSION);
595 601
596 return result; 602 of_i2c_register_devices(&i2c->adap);
603
604 return 0;
597 605
598fail_add: 606fail_add:
599 platform_set_drvdata(pdev, NULL); 607 platform_set_drvdata(pdev, NULL);
600 free_irq(i2c->irq, i2c);
601fail_irq:
602 iounmap(i2c->twsi_base);
603 release_mem_region(i2c->twsi_phys, i2c->regsize);
604fail_region:
605 kfree(i2c);
606out: 608out:
607 return result; 609 return result;
608}; 610};
@@ -613,19 +615,24 @@ static int __devexit octeon_i2c_remove(struct platform_device *pdev)
613 615
614 i2c_del_adapter(&i2c->adap); 616 i2c_del_adapter(&i2c->adap);
615 platform_set_drvdata(pdev, NULL); 617 platform_set_drvdata(pdev, NULL);
616 free_irq(i2c->irq, i2c);
617 iounmap(i2c->twsi_base);
618 release_mem_region(i2c->twsi_phys, i2c->regsize);
619 kfree(i2c);
620 return 0; 618 return 0;
621}; 619};
622 620
621static struct of_device_id octeon_i2c_match[] = {
622 {
623 .compatible = "cavium,octeon-3860-twsi",
624 },
625 {},
626};
627MODULE_DEVICE_TABLE(of, octeon_i2c_match);
628
623static struct platform_driver octeon_i2c_driver = { 629static struct platform_driver octeon_i2c_driver = {
624 .probe = octeon_i2c_probe, 630 .probe = octeon_i2c_probe,
625 .remove = __devexit_p(octeon_i2c_remove), 631 .remove = __devexit_p(octeon_i2c_remove),
626 .driver = { 632 .driver = {
627 .owner = THIS_MODULE, 633 .owner = THIS_MODULE,
628 .name = DRV_NAME, 634 .name = DRV_NAME,
635 .of_match_table = octeon_i2c_match,
629 }, 636 },
630}; 637};
631 638
@@ -635,4 +642,3 @@ MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>");
635MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors"); 642MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
636MODULE_LICENSE("GPL"); 643MODULE_LICENSE("GPL");
637MODULE_VERSION(DRV_VERSION); 644MODULE_VERSION(DRV_VERSION);
638MODULE_ALIAS("platform:" DRV_NAME);