Index: backports-2017-11-01/drivers/net/wireless/ath/ath9k/ahb.c =================================================================== --- backports-2017-11-01.orig/drivers/net/wireless/ath/ath9k/ahb.c +++ backports-2017-11-01/drivers/net/wireless/ath/ath9k/ahb.c @@ -19,7 +19,15 @@ #include #include #include +#include #include "ath9k.h" +#include + +#ifdef CONFIG_OF +#include +#include +#include +#endif static const struct platform_device_id ath9k_platform_id_table[] = { { @@ -68,6 +76,235 @@ static const struct ath_bus_ops ath_ahb_ .eeprom_read = ath_ahb_eeprom_read, }; +#ifdef CONFIG_OF + +#define QCA955X_DDR_CTL_CONFIG 0x108 +#define QCA955X_DDR_CTL_CONFIG_ACT_WMAC BIT(23) + +static int of_get_wifi_cal(struct device_node *np, struct ath9k_platform_data *pdata) +{ +#ifdef CONFIG_MTD + struct device_node *mtd_np = NULL; + size_t retlen; + int size, ret; + struct mtd_info *mtd; + const char *part; + const __be32 *list; + phandle phandle; + + list = of_get_property(np, "mtd-cal-data", &size); + if (!list) + return 0; + + if (size != (2 * sizeof(*list))) + return 1; + + phandle = be32_to_cpup(list++); + if (phandle) + mtd_np = of_find_node_by_phandle(phandle); + + if (!mtd_np) + return 1; + + part = of_get_property(mtd_np, "label", NULL); + if (!part) + part = mtd_np->name; + + mtd = get_mtd_device_nm(part); + if (IS_ERR(mtd)) + return 1; + + ret = mtd_read(mtd, be32_to_cpup(list), sizeof(pdata->eeprom_data), + &retlen, (u8*)pdata->eeprom_data); + put_mtd_device(mtd); + +#endif + return 0; +} + +static int ar913x_wmac_reset(void) +{ + ath79_device_reset_set(AR913X_RESET_AMBA2WMAC); + mdelay(10); + + ath79_device_reset_clear(AR913X_RESET_AMBA2WMAC); + mdelay(10); + + return 0; +} + +static int ar933x_wmac_reset(void) +{ + int retries = 20; + + ath79_device_reset_set(AR933X_RESET_WMAC); + ath79_device_reset_clear(AR933X_RESET_WMAC); + + while (1) { + u32 bootstrap; + + bootstrap = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP); + if ((bootstrap & AR933X_BOOTSTRAP_EEPBUSY) == 0) + return 0; + + if (retries-- == 0) + break; + + udelay(10000); + } + + pr_err("ar933x: WMAC reset timed out"); + return -ETIMEDOUT; +} + +static int qca955x_wmac_reset(void) +{ + int i; + + /* Try to wait for WMAC DDR activity to stop */ + for (i = 0; i < 10; i++) { + if (!(__raw_readl(ath79_ddr_base + QCA955X_DDR_CTL_CONFIG) & + QCA955X_DDR_CTL_CONFIG_ACT_WMAC)) + break; + + udelay(10); + } + + ath79_device_reset_set(QCA955X_RESET_RTC); + udelay(10); + ath79_device_reset_clear(QCA955X_RESET_RTC); + udelay(10); + + return 0; +} + +enum { + AR913X_WMAC = 0, + AR933X_WMAC, + AR934X_WMAC, + QCA953X_WMAC, + QCA955X_WMAC, + QCA956X_WMAC, +}; + +static int ar9330_get_soc_revision(void) +{ + if (ath79_soc_rev == 1) + return ath79_soc_rev; + + return 0; +} + +static int ath79_get_soc_revision(void) +{ + return ath79_soc_rev; +} + +static const struct of_ath_ahb_data { + u16 dev_id; + u32 bootstrap_reg; + u32 bootstrap_ref; + + int (*soc_revision)(void); + int (*wmac_reset)(void); +} of_ath_ahb_data[] = { + [AR913X_WMAC] = { + .dev_id = AR5416_AR9100_DEVID, + .wmac_reset = ar913x_wmac_reset, + + }, + [AR933X_WMAC] = { + .dev_id = AR9300_DEVID_AR9330, + .bootstrap_reg = AR933X_RESET_REG_BOOTSTRAP, + .bootstrap_ref = AR933X_BOOTSTRAP_REF_CLK_40, + .soc_revision = ar9330_get_soc_revision, + .wmac_reset = ar933x_wmac_reset, + }, + [AR934X_WMAC] = { + .dev_id = AR9300_DEVID_AR9340, + .bootstrap_reg = AR934X_RESET_REG_BOOTSTRAP, + .bootstrap_ref = AR934X_BOOTSTRAP_REF_CLK_40, + .soc_revision = ath79_get_soc_revision, + }, + [QCA953X_WMAC] = { + .dev_id = AR9300_DEVID_AR953X, + .bootstrap_reg = QCA953X_RESET_REG_BOOTSTRAP, + .bootstrap_ref = QCA953X_BOOTSTRAP_REF_CLK_40, + .soc_revision = ath79_get_soc_revision, + }, + [QCA955X_WMAC] = { + .dev_id = AR9300_DEVID_QCA955X, + .bootstrap_reg = QCA955X_RESET_REG_BOOTSTRAP, + .bootstrap_ref = QCA955X_BOOTSTRAP_REF_CLK_40, + .wmac_reset = qca955x_wmac_reset, + }, + [QCA956X_WMAC] = { + .dev_id = AR9300_DEVID_QCA956X, + .bootstrap_reg = QCA956X_RESET_REG_BOOTSTRAP, + .bootstrap_ref = QCA956X_BOOTSTRAP_REF_CLK_40, + .soc_revision = ath79_get_soc_revision, + }, +}; + +const struct of_device_id of_ath_ahb_match[] = { + { .compatible = "qca,ar9130-wmac", .data = &of_ath_ahb_data[AR913X_WMAC] }, + { .compatible = "qca,ar9330-wmac", .data = &of_ath_ahb_data[AR933X_WMAC] }, + { .compatible = "qca,ar9340-wmac", .data = &of_ath_ahb_data[AR934X_WMAC] }, + { .compatible = "qca,qca9530-wmac", .data = &of_ath_ahb_data[QCA953X_WMAC] }, + { .compatible = "qca,qca9550-wmac", .data = &of_ath_ahb_data[QCA955X_WMAC] }, + { .compatible = "qca,qca9560-wmac", .data = &of_ath_ahb_data[QCA956X_WMAC] }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_ath_ahb_match); + +static int of_ath_ahb_probe(struct platform_device *pdev) +{ + struct ath9k_platform_data *pdata; + const struct of_device_id *match; + const struct of_ath_ahb_data *data; + u8 led_pin; + + match = of_match_device(of_ath_ahb_match, &pdev->dev); + data = (const struct of_ath_ahb_data *)match->data; + + pdata = dev_get_platdata(&pdev->dev); + + if (!of_property_read_u8(pdev->dev.of_node, "qca,led-pin", &led_pin)) + pdata->led_pin = led_pin; + else + pdata->led_pin = -1; + + if (of_property_read_bool(pdev->dev.of_node, "qca,disable-2ghz")) + pdata->disable_2ghz = true; + + if (of_property_read_bool(pdev->dev.of_node, "qca,disable-5ghz")) + pdata->disable_5ghz = true; + + if (of_property_read_bool(pdev->dev.of_node, "qca,tx-gain-buffalo")) + pdata->tx_gain_buffalo = true; + + if (data->wmac_reset) { + data->wmac_reset(); + pdata->external_reset = data->wmac_reset; + } + + if (data->bootstrap_reg && data->bootstrap_ref) { + u32 t = ath79_reset_rr(data->bootstrap_reg); + if (t & data->bootstrap_ref) + pdata->is_clk_25mhz = false; + else + pdata->is_clk_25mhz = true; + } + + pdata->get_mac_revision = data->soc_revision; + + if (of_get_wifi_cal(pdev->dev.of_node, pdata)) + dev_err(&pdev->dev, "failed to load calibration data from mtd device\n"); + + return data->dev_id; +} +#endif + static int ath_ahb_probe(struct platform_device *pdev) { void __iomem *mem; @@ -79,6 +316,17 @@ static int ath_ahb_probe(struct platform int ret = 0; struct ath_hw *ah; char hw_name[64]; + u16 dev_id; + + if (id) + dev_id = id->driver_data; + +#ifdef CONFIG_OF + if (pdev->dev.of_node) + pdev->dev.platform_data = devm_kzalloc(&pdev->dev, + sizeof(struct ath9k_platform_data), + GFP_KERNEL); +#endif if (!dev_get_platdata(&pdev->dev)) { dev_err(&pdev->dev, "no platform data specified\n"); @@ -121,13 +369,16 @@ static int ath_ahb_probe(struct platform sc->mem = mem; sc->irq = irq; +#ifdef CONFIG_OF + dev_id = of_ath_ahb_probe(pdev); +#endif ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc); if (ret) { dev_err(&pdev->dev, "request_irq failed\n"); goto err_free_hw; } - ret = ath9k_init_device(id->driver_data, sc, &ath_ahb_bus_ops); + ret = ath9k_init_device(dev_id, sc, &ath_ahb_bus_ops); if (ret) { dev_err(&pdev->dev, "failed to initialize device\n"); goto err_irq; @@ -158,6 +409,9 @@ static int ath_ahb_remove(struct platfor free_irq(sc->irq, sc); ieee80211_free_hw(sc->hw); } +#ifdef CONFIG_OF + pdev->dev.platform_data = NULL; +#endif return 0; } @@ -167,6 +421,9 @@ static struct platform_driver ath_ahb_dr .remove = ath_ahb_remove, .driver = { .name = "ath9k", +#ifdef CONFIG_OF + .of_match_table = of_ath_ahb_match, +#endif }, .id_table = ath9k_platform_id_table, }; Index: backports-2017-11-01/drivers/net/wireless/ath/ath9k/ath9k.h =================================================================== --- backports-2017-11-01.orig/drivers/net/wireless/ath/ath9k/ath9k.h +++ backports-2017-11-01/drivers/net/wireless/ath/ath9k/ath9k.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "common.h" #include "debug.h" @@ -1023,6 +1024,9 @@ struct ath_softc { struct ath_hw *sc_ah; void __iomem *mem; int irq; +#ifdef CONFIG_OF + struct reset_control *reset; +#endif spinlock_t sc_serial_rw; spinlock_t sc_pm_lock; spinlock_t sc_pcu_lock; 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
/ {
	#address-cells = <1>;
	#size-cells = <1>;
	compatible = "lantiq,xway", "lantiq,danube";

	chosen {
		bootargs = "console=ttyLTQ0,115200 init=/etc/preinit";
	};

	cpus {
		cpu@0 {
			compatible = "mips,mips24Kc";
		};
	};

	memory@0 {
		device_type = "memory";
	};

	biu@1F800000 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "lantiq,biu", "simple-bus";
		reg = <0x1F800000 0x800000>;
		ranges = <0x0 0x1F800000 0x7FFFFF>;

		icu0: icu@80200 {
			#interrupt-cells = <1>;
			interrupt-controller;
			compatible = "lantiq,icu";
			reg = <0x80200 0x28
				0x80228 0x28
				0x80250 0x28
				0x80278 0x28
				0x802a0 0x28>;
		};

		watchdog@803F0 {
			compatible = "lantiq,wdt";
			reg = <0x803F0 0x10>;
		};
	};

	sram@1F000000 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "lantiq,sram", "simple-bus";
		reg = <0x1F000000 0x800000>;
		ranges = <0x0 0x1F000000 0x7FFFFF>;

		eiu0: eiu@101000 {
			#interrupt-cells = <1>;
			interrupt-controller;
			compatible = "lantiq,eiu-xway";
			reg = <0x101000 0x1000>;
			interrupt-parent = <&icu0>;
			interrupts = <166 135 66>;
		};

		pmu0: pmu@102000 {
			compatible = "lantiq,pmu-xway";
			reg = <0x102000 0x1000>;
		};

		cgu0: cgu@103000 {
			compatible = "lantiq,cgu-xway";
			reg = <0x103000 0x1000>;
			#clock-cells = <1>;
		};

		vmmc@107000 {
			status = "disabled";
			compatible = "lantiq,vmmc";
			reg = <0x103000 0x400>;
			interrupt-parent = <&icu0>;
			interrupts = <150 151 152 153 154 155>;
		};

		rcu0: rcu@203000 {
			compatible = "lantiq,rcu-xway";
			reg = <0x203000 0x1000>;
		};
	};

	fpi@10000000 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "lantiq,fpi", "simple-bus";
		ranges = <0x0 0x10000000 0xEEFFFFF>;
		reg = <0x10000000 0xEF00000>;

		localbus@0 {
			#address-cells = <2>;
			#size-cells = <1>;
			ranges = <0 0 0x0 0x3ffffff /* addrsel0 */
				1 0 0x4000000 0x4000010>; /* addsel1 */
			compatible = "lantiq,localbus", "simple-bus";
		};

		gptu@E100A00 {
			compatible = "lantiq,gptu-xway";
			reg = <0xE100A00 0x100>;
			interrupt-parent = <&icu0>;
			interrupts = <126 127 128 129 130 131>;
		};

		gpios: stp@E100BB0 {
			#gpio-cells = <2>;
			compatible = "lantiq,gpio-stp-xway";
			gpio-controller;
			reg = <0xE100BB0 0x40>;
			lantiq,shadow = <0xfff>;
			lantiq,groups = <0x3>;
			status = "disabled";
		};

		asc0: serial@E100400 {
			compatible = "lantiq,asc";
			reg = <0xE100400 0x400>;
			interrupt-parent = <&icu0>;
			interrupts = <104 105 106>;
			status = "disabled";
		};

		gpio: pinmux@E100B10 {
			compatible = "lantiq,danube-pinctrl";
			#gpio-cells = <2>;
			gpio-controller;
			reg = <0xE100B10 0xA0>;
		};

		asc1: serial@E100C00 {
			compatible = "lantiq,asc";
			reg = <0xE100C00 0x400>;
			interrupt-parent = <&icu0>;
			interrupts = <112 113 114>;
		};

		ifxhcd@E101000 {
			compatible = "lantiq,ifxhcd-danube";
			reg = <0xE101000 0x1000
				0xE120000 0x3f000>;
			interrupt-parent = <&icu0>;
			interrupts = <62>;
			status = "disabled";
		};

		deu@E103100 {
			compatible = "lantiq,deu-danube";
			reg = <0xE103100 0xf00>;
		};

		dma0: dma@E104100 {
			compatible = "lantiq,dma-xway";
			reg = <0xE104100 0x800>;
		};

		ebu0: ebu@E105300 {
			compatible = "lantiq,ebu-xway";
			reg = <0xE105300 0x100>;
		};

		mei@E116000 {
			compatible = "lantiq,mei-xway";
			interrupt-parent = <&icu0>;
			interrupts = <63>;
		};

		etop@E180000 {
			compatible = "lantiq,etop-xway";
			reg = <0xE180000 0x40000>;
			interrupt-parent = <&icu0>;
			interrupts = <73 78>;
			mac-address = [ 00 11 22 33 44 55 ];
		};

		ppe@E234000 {
			compatible = "lantiq,ppe-danube";
			interrupt-parent = <&icu0>;
			interrupts = <96>;
		};

		pci0: pci@E105400 {
			status = "disabled";

			#address-cells = <3>;
			#size-cells = <2>;
			#interrupt-cells = <1>;
			compatible = "lantiq,pci-xway";
			bus-range = <0x0 0x0>;
			ranges = <0x2000000 0 0x8000000 0x8000000 0 0x2000000	/* pci memory */
				  0x1000000 0 0x00000000 0xAE00000 0 0x200000>;	/* io space */
			reg = <0x7000000 0x8000		/* config space */
				0xE105400 0x400>;	/* pci bridge */
			lantiq,bus-clock = <33333333>;
			interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
			interrupt-map = <0x7000 0 0 1 &icu0 30 1>;
			req-mask = <0x1>;
		};
	};

	adsl {
		compatible = "lantiq,adsl-danube";
	};
};