aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorManuel Lauss <manuel.lauss@gmail.com>2014-07-23 10:36:53 -0400
committerRalf Baechle <ralf@linux-mips.org>2014-07-30 08:10:19 -0400
commit9178af9aa74edb4b161912ee1a6cbe0cc7ed7975 (patch)
tree06340face6a9234ec2818ba64a97eecf9c17ca75 /drivers
parent415e0fec7a388dbe224057c1134737e23710aa9b (diff)
MIPS: Alchemy: irda: use clk framework
Test the existence of the irda_clk clock object, use it to en/dis- able it when date is being transferred. Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com> Cc: Linux-MIPS <linux-mips@linux-mips.org> Patchwork: https://patchwork.linux-mips.org/patch/7470/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/irda/au1k_ir.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/drivers/net/irda/au1k_ir.c b/drivers/net/irda/au1k_ir.c
index 5f91e3e01c04..aab2cf72d025 100644
--- a/drivers/net/irda/au1k_ir.c
+++ b/drivers/net/irda/au1k_ir.c
@@ -18,6 +18,7 @@
18 * with this program; if not, see <http://www.gnu.org/licenses/>. 18 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 */ 19 */
20 20
21#include <linux/clk.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/netdevice.h> 23#include <linux/netdevice.h>
23#include <linux/interrupt.h> 24#include <linux/interrupt.h>
@@ -175,6 +176,7 @@ struct au1k_private {
175 176
176 struct resource *ioarea; 177 struct resource *ioarea;
177 struct au1k_irda_platform_data *platdata; 178 struct au1k_irda_platform_data *platdata;
179 struct clk *irda_clk;
178}; 180};
179 181
180static int qos_mtt_bits = 0x07; /* 1 ms or more */ 182static int qos_mtt_bits = 0x07; /* 1 ms or more */
@@ -514,9 +516,39 @@ static irqreturn_t au1k_irda_interrupt(int dummy, void *dev_id)
514static int au1k_init(struct net_device *dev) 516static int au1k_init(struct net_device *dev)
515{ 517{
516 struct au1k_private *aup = netdev_priv(dev); 518 struct au1k_private *aup = netdev_priv(dev);
517 u32 enable, ring_address; 519 u32 enable, ring_address, phyck;
520 struct clk *c;
518 int i; 521 int i;
519 522
523 c = clk_get(NULL, "irda_clk");
524 if (IS_ERR(c))
525 return PTR_ERR(c);
526 i = clk_prepare_enable(c);
527 if (i) {
528 clk_put(c);
529 return i;
530 }
531
532 switch (clk_get_rate(c)) {
533 case 40000000:
534 phyck = IR_PHYCLK_40MHZ;
535 break;
536 case 48000000:
537 phyck = IR_PHYCLK_48MHZ;
538 break;
539 case 56000000:
540 phyck = IR_PHYCLK_56MHZ;
541 break;
542 case 64000000:
543 phyck = IR_PHYCLK_64MHZ;
544 break;
545 default:
546 clk_disable_unprepare(c);
547 clk_put(c);
548 return -EINVAL;
549 }
550 aup->irda_clk = c;
551
520 enable = IR_HC | IR_CE | IR_C; 552 enable = IR_HC | IR_CE | IR_C;
521#ifndef CONFIG_CPU_LITTLE_ENDIAN 553#ifndef CONFIG_CPU_LITTLE_ENDIAN
522 enable |= IR_BE; 554 enable |= IR_BE;
@@ -545,7 +577,7 @@ static int au1k_init(struct net_device *dev)
545 irda_write(aup, IR_RING_SIZE, 577 irda_write(aup, IR_RING_SIZE,
546 (RING_SIZE_64 << 8) | (RING_SIZE_64 << 12)); 578 (RING_SIZE_64 << 8) | (RING_SIZE_64 << 12));
547 579
548 irda_write(aup, IR_CONFIG_2, IR_PHYCLK_48MHZ | IR_ONE_PIN); 580 irda_write(aup, IR_CONFIG_2, phyck | IR_ONE_PIN);
549 irda_write(aup, IR_RING_ADDR_CMPR, 0); 581 irda_write(aup, IR_RING_ADDR_CMPR, 0);
550 582
551 au1k_irda_set_speed(dev, 9600); 583 au1k_irda_set_speed(dev, 9600);
@@ -619,6 +651,9 @@ static int au1k_irda_stop(struct net_device *dev)
619 free_irq(aup->irq_tx, dev); 651 free_irq(aup->irq_tx, dev);
620 free_irq(aup->irq_rx, dev); 652 free_irq(aup->irq_rx, dev);
621 653
654 clk_disable_unprepare(aup->irda_clk);
655 clk_put(aup->irda_clk);
656
622 return 0; 657 return 0;
623} 658}
624 659
@@ -853,6 +888,7 @@ static int au1k_irda_probe(struct platform_device *pdev)
853 struct au1k_private *aup; 888 struct au1k_private *aup;
854 struct net_device *dev; 889 struct net_device *dev;
855 struct resource *r; 890 struct resource *r;
891 struct clk *c;
856 int err; 892 int err;
857 893
858 dev = alloc_irdadev(sizeof(struct au1k_private)); 894 dev = alloc_irdadev(sizeof(struct au1k_private));
@@ -886,6 +922,14 @@ static int au1k_irda_probe(struct platform_device *pdev)
886 if (!aup->ioarea) 922 if (!aup->ioarea)
887 goto out; 923 goto out;
888 924
925 /* bail out early if clock doesn't exist */
926 c = clk_get(NULL, "irda_clk");
927 if (IS_ERR(c)) {
928 err = PTR_ERR(c);
929 goto out;
930 }
931 clk_put(c);
932
889 aup->iobase = ioremap_nocache(r->start, resource_size(r)); 933 aup->iobase = ioremap_nocache(r->start, resource_size(r));
890 if (!aup->iobase) 934 if (!aup->iobase)
891 goto out2; 935 goto out2;