Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Manuel Lauss and committed by
Ralf Baechle
9178af9a 415e0fec

+46 -2
+46 -2
drivers/net/irda/au1k_ir.c
··· 18 18 * with this program; if not, see <http://www.gnu.org/licenses/>. 19 19 */ 20 20 21 + #include <linux/clk.h> 21 22 #include <linux/module.h> 22 23 #include <linux/netdevice.h> 23 24 #include <linux/interrupt.h> ··· 176 175 177 176 struct resource *ioarea; 178 177 struct au1k_irda_platform_data *platdata; 178 + struct clk *irda_clk; 179 179 }; 180 180 181 181 static int qos_mtt_bits = 0x07; /* 1 ms or more */ ··· 516 514 static int au1k_init(struct net_device *dev) 517 515 { 518 516 struct au1k_private *aup = netdev_priv(dev); 519 - u32 enable, ring_address; 517 + u32 enable, ring_address, phyck; 518 + struct clk *c; 520 519 int i; 520 + 521 + c = clk_get(NULL, "irda_clk"); 522 + if (IS_ERR(c)) 523 + return PTR_ERR(c); 524 + i = clk_prepare_enable(c); 525 + if (i) { 526 + clk_put(c); 527 + return i; 528 + } 529 + 530 + switch (clk_get_rate(c)) { 531 + case 40000000: 532 + phyck = IR_PHYCLK_40MHZ; 533 + break; 534 + case 48000000: 535 + phyck = IR_PHYCLK_48MHZ; 536 + break; 537 + case 56000000: 538 + phyck = IR_PHYCLK_56MHZ; 539 + break; 540 + case 64000000: 541 + phyck = IR_PHYCLK_64MHZ; 542 + break; 543 + default: 544 + clk_disable_unprepare(c); 545 + clk_put(c); 546 + return -EINVAL; 547 + } 548 + aup->irda_clk = c; 521 549 522 550 enable = IR_HC | IR_CE | IR_C; 523 551 #ifndef CONFIG_CPU_LITTLE_ENDIAN ··· 577 545 irda_write(aup, IR_RING_SIZE, 578 546 (RING_SIZE_64 << 8) | (RING_SIZE_64 << 12)); 579 547 580 - irda_write(aup, IR_CONFIG_2, IR_PHYCLK_48MHZ | IR_ONE_PIN); 548 + irda_write(aup, IR_CONFIG_2, phyck | IR_ONE_PIN); 581 549 irda_write(aup, IR_RING_ADDR_CMPR, 0); 582 550 583 551 au1k_irda_set_speed(dev, 9600); ··· 650 618 /* disable the interrupt */ 651 619 free_irq(aup->irq_tx, dev); 652 620 free_irq(aup->irq_rx, dev); 621 + 622 + clk_disable_unprepare(aup->irda_clk); 623 + clk_put(aup->irda_clk); 653 624 654 625 return 0; 655 626 } ··· 888 853 struct au1k_private *aup; 889 854 struct net_device *dev; 890 855 struct resource *r; 856 + struct clk *c; 891 857 int err; 892 858 893 859 dev = alloc_irdadev(sizeof(struct au1k_private)); ··· 921 885 pdev->name); 922 886 if (!aup->ioarea) 923 887 goto out; 888 + 889 + /* bail out early if clock doesn't exist */ 890 + c = clk_get(NULL, "irda_clk"); 891 + if (IS_ERR(c)) { 892 + err = PTR_ERR(c); 893 + goto out; 894 + } 895 + clk_put(c); 924 896 925 897 aup->iobase = ioremap_nocache(r->start, resource_size(r)); 926 898 if (!aup->iobase)