firewall: update to git head
[openwrt.git] / target / linux / lantiq / patches-3.7 / 0006-MIPS-lantiq-adds-GPHY-firmware-loader.patch
1 From 0224cde212df4abf251f89c3724a800b1949a774 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 22 Oct 2012 07:52:50 +0200
4 Subject: [PATCH 6/6] MIPS: lantiq: adds GPHY firmware loader
5
6 The internal GPHYs need a firmware blob to function properly. This patch adds
7 the code needed to request the blob and load it to the PHY.
8
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 Patchwork: http://patchwork.linux-mips.org/patch/4523
11 ---
12  arch/mips/lantiq/Kconfig              |    4 ++
13  arch/mips/lantiq/xway/Makefile        |    2 +
14  arch/mips/lantiq/xway/xrx200_phy_fw.c |   97 +++++++++++++++++++++++++++++++++
15  3 files changed, 103 insertions(+)
16  create mode 100644 arch/mips/lantiq/xway/xrx200_phy_fw.c
17
18 --- a/arch/mips/lantiq/Kconfig
19 +++ b/arch/mips/lantiq/Kconfig
20 @@ -36,4 +36,8 @@ config PCI_LANTIQ
21         bool "PCI Support"
22         depends on SOC_XWAY && PCI
23  
24 +config XRX200_PHY_FW
25 +       bool "XRX200 PHY firmware loader"
26 +       depends on SOC_XWAY
27 +
28  endif
29 --- a/arch/mips/lantiq/xway/Makefile
30 +++ b/arch/mips/lantiq/xway/Makefile
31 @@ -1 +1,3 @@
32  obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o
33 +
34 +obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
35 --- /dev/null
36 +++ b/arch/mips/lantiq/xway/xrx200_phy_fw.c
37 @@ -0,0 +1,97 @@
38 +/*
39 + *  This program is free software; you can redistribute it and/or modify it
40 + *  under the terms of the GNU General Public License version 2 as published
41 + *  by the Free Software Foundation.
42 + *
43 + *  Copyright (C) 2012 John Crispin <blogic@openwrt.org>
44 + */
45 +
46 +#include <linux/delay.h>
47 +#include <linux/dma-mapping.h>
48 +#include <linux/module.h>
49 +#include <linux/firmware.h>
50 +#include <linux/of_platform.h>
51 +
52 +#include <lantiq_soc.h>
53 +
54 +#define XRX200_GPHY_FW_ALIGN   (16 * 1024)
55 +
56 +static dma_addr_t xway_gphy_load(struct platform_device *pdev)
57 +{
58 +       const struct firmware *fw;
59 +       dma_addr_t dev_addr = 0;
60 +       const char *fw_name;
61 +       void *fw_addr;
62 +       size_t size;
63 +
64 +       if (of_property_read_string(pdev->dev.of_node, "firmware", &fw_name)) {
65 +               dev_err(&pdev->dev, "failed to load firmware filename\n");
66 +               return 0;
67 +       }
68 +
69 +       dev_info(&pdev->dev, "requesting %s\n", fw_name);
70 +       if (request_firmware(&fw, fw_name, &pdev->dev)) {
71 +               dev_err(&pdev->dev, "failed to load firmware: %s\n", fw_name);
72 +               return 0;
73 +       }
74 +
75 +       /*
76 +        * GPHY cores need the firmware code in a persistent and contiguous
77 +        * memory area with a 16 kB boundary aligned start address
78 +        */
79 +       size = fw->size + XRX200_GPHY_FW_ALIGN;
80 +
81 +       fw_addr = dma_alloc_coherent(&pdev->dev, size, &dev_addr, GFP_KERNEL);
82 +       if (fw_addr) {
83 +               fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN);
84 +               dev_addr = ALIGN(dev_addr, XRX200_GPHY_FW_ALIGN);
85 +               memcpy(fw_addr, fw->data, fw->size);
86 +       } else {
87 +               dev_err(&pdev->dev, "failed to alloc firmware memory\n");
88 +       }
89 +
90 +       release_firmware(fw);
91 +       return dev_addr;
92 +}
93 +
94 +static int __devinit xway_phy_fw_probe(struct platform_device *pdev)
95 +{
96 +       dma_addr_t fw_addr;
97 +       struct property *pp;
98 +       unsigned char *phyids;
99 +       int i, ret = 0;
100 +
101 +       fw_addr = xway_gphy_load(pdev);
102 +       if (!fw_addr)
103 +               return -EINVAL;
104 +       pp = of_find_property(pdev->dev.of_node, "phys", NULL);
105 +       if (!pp)
106 +               return -ENOENT;
107 +       phyids = pp->value;
108 +       for (i = 0; i < pp->length && !ret; i++)
109 +               ret = xrx200_gphy_boot(&pdev->dev, phyids[i], fw_addr);
110 +       if (!ret)
111 +               mdelay(100);
112 +       return ret;
113 +}
114 +
115 +static const struct of_device_id xway_phy_match[] = {
116 +       { .compatible = "lantiq,phy-xrx200" },
117 +       {},
118 +};
119 +MODULE_DEVICE_TABLE(of, xway_phy_match);
120 +
121 +static struct platform_driver xway_phy_driver = {
122 +       .probe = xway_phy_fw_probe,
123 +       .driver = {
124 +               .name = "phy-xrx200",
125 +               .owner = THIS_MODULE,
126 +               .of_match_table = xway_phy_match,
127 +       },
128 +};
129 +
130 +module_platform_driver(xway_phy_driver);
131 +
132 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
133 +MODULE_DESCRIPTION("Lantiq XRX200 PHY Firmware Loader");
134 +MODULE_LICENSE("GPL");