Commit Graph

269 Commits

Author SHA1 Message Date
Adrian Chadd
87a2f105ee Make the apb.c code optional behind ar71xx_apb rather than standard.
The QCA955x has more mux interrupts going on - and the AR934x actually does,
but I cheated and assigned wlan and pcie to the same interrupt line.
They are, there's just a status register mux that I should've been using.

Luckily this isn't too bad a change in itself - almost all of the
Atheros MIPS configurations use a _BASE file to inherit from.
Except PB92, which I should really fix up at some point.

The AR934x will use the legacy apb for now until I write its replacement.

The QCA955x SoC I'm doing bring-up on will have a separate qca955x_apb.c
implementation that includes hooking into IP2/IP3 and doing further
interrupt demuxing as appropriate.
2015-01-06 07:43:07 +00:00
Adrian Chadd
e090d1f591 Add an APB base/size for the QCA955X for an upcoming QCA955x specific
APB mux.

It's larger than the AR71xx because it needs to replace the nexus
for some devices (notably wifi) and the wifi driver (if_ath_ahb.c)
reads the SPI data directly at early boot whilst it's memory mapped
in.

I'm eventually going to rip it out and replace it with a firmware
interface similar to what exists for the if_ath_pci.c path -
something early on (likely something new that I'll write) will
suck in the calibration data into a firmware API blob and that'll
be accessed from if_ath_ahb.c.

But, one thing at a time.

Tested:

* QCA955x SoC, AP135 development board
2015-01-06 07:37:33 +00:00
Adrian Chadd
0723a49181 The QCA955x USB init path doesn't require any of this, so delete it.
Obtained from:	Linux/OpenWRT
2015-01-06 07:35:05 +00:00
Hans Petter Selasky
b217d18412 Add 64-bit DMA support in the XHCI controller driver.
- Fix some comments and whitespace while at it.

MFC after:	1 month
Submitted by:	marius@
2015-01-05 20:22:18 +00:00
Adrian Chadd
cd470fead8 Remove the remnants of the OpenWRT/Linux bits that this was based off
of.

Obtained from:	Linux/OpenWRT
2015-01-05 05:30:07 +00:00
Adrian Chadd
3eda0cb18c Oops - missed refclk.
Tested:

* AP135, QCA955x SoC
2015-01-05 05:26:57 +00:00
Adrian Chadd
855c46100d Add initial Qualcomm Atheros QCA955x SoC support.
This adds the initial frequency poking and configures up enough
for it to boot and spit out data over the console.

There's still a whole bunch of work to do in the reset path
and devices to support this thing, but hey, it's alive!

ath> go 0x80050100
## Starting application at 0x80050100 ...
CPU platform: Atheros AR9558 rev 0
CPU Frequency=720 MHz
CPU DDR Frequency=600 MHz
CPU AHB Frequency=200 MHz
platform frequency: 720 MHz
CPU reference clock: 0 MHz
CPU MDIO clock: 40 MHz

Done at:	hackathon
Obtained from:	Linux OpenWRT, Qualcomm Atheros
2015-01-05 02:06:26 +00:00
Adrian Chadd
917d2c3c3b ACK interrupts on the new SoCs. 2015-01-05 02:00:41 +00:00
Adrian Chadd
dc6fff9835 add QCA955x SoC types. 2015-01-05 01:59:44 +00:00
Adrian Chadd
55b32e75df Add QCA955x series register definitions.
There's likely a bunch of register offsets that I have to add the
register window base to before I use them.

Done at:	Hackathon
Obtained from:	Linux OpenWRT
2015-01-05 01:44:23 +00:00
Adrian Chadd
c69537d018 Add a GPIO output mux configuration method.
The AR934x and later (which will turn up eventually) have a new GPIO
output configuration option - a real MUX rather than a "GPIO or this
function."

For now I'm squirreling it away in the CPU code just so it's done -
I may move this to the GPIO layer later.

Specifically, this is required for setting up some boards that have
external receive side LNA (low noise amplifier) that gets switched on/off
by the on-chip wireless MAC.  If we don't add this support for those
boards then we'll end up with really poor performance.

(I don't yet have one of those APs, but it'll likely show up in a week.)

Obtained from:	Linux OpenWRT
2015-01-03 06:55:58 +00:00
Adrian Chadd
0bd5971780 Add AR934x specific GPIO functions and output MUX configuration.
Obtained from:	Linux OpenWRT
2015-01-03 06:35:53 +00:00
Adrian Chadd
e2fa3a330a Add AR934x GPIO function configuration.
Obtained from:	Linux OpenWRT
2015-01-03 06:30:30 +00:00
Luiz Otavio O Souza
667357dc9b Moves all the duplicate code to a single function.
Verify for invalid modes and unwanted flags before pass the new flags to
driver.
2014-11-18 17:22:08 +00:00
Luiz Otavio O Souza
8839e0e9f3 Make the GPIO children attach to the first unit available and not only to
unit 0.

It seems that this 'simplification' was copied to all GPIO drivers in tree.

This fix a bug where a GPIO controller could fail to attach its children
(gpioc and gpiobus) if another GPIO driver attach first.
2014-10-28 18:33:59 +00:00
Davide Italiano
2be111bf7d Follow up to r225617. In order to maximize the re-usability of kernel code
in userland rename in-kernel getenv()/setenv() to kern_setenv()/kern_getenv().
This fixes a namespace collision with libc symbols.

Submitted by:   kmacy
Tested by:      make universe
2014-10-16 18:04:43 +00:00
Adrian Chadd
08f06f0ace Fix the AR724x PCIe glue to correctly probe the BAR on AR7240 devices.
There's a bug in the AR7240 PCIe hardware where a correct BAR will end
up having the device disappear.

It turns out that for the device address it should be all 0's.

However, this meant that the PCI probe code would try writing 0xffffffff
in to see how big the window was, read back 0x0, and think the window
was 32 bits.  It then ended up calculating a resource size of 0 bytes,
failed to find anything via an rman call, and this would fail to attach.

I have quite absolutely no idea how in the various planes of existence
this particular bit of code and how it worked with the PCI bus code
ever worked.  But, well, it did.

Tested:

* Atheros AP93 - AR7240 + AR9280 reference board
2014-09-28 07:27:58 +00:00
Adrian Chadd
60d2f54e48 Fix the ar724x PCI config space register read.
It was doing incorrect things with masks.  This was fixed in the
AR71xx codebase but it wasn't yet fixed in the AR724x code.

This ended up having config space reads return larger/incorrect values
in some situations.

Tested:

* AR7240

TODO:

* test ar7241, AR7242, and AR934x.
2014-09-28 05:28:11 +00:00
Gleb Smirnoff
d8cc52c9a1 Mechanically convert to if_inc_counter(). 2014-09-19 09:19:49 +00:00
Adrian Chadd
c821a62f9c Commit some sins in the name of "oh god oh god I don't really want to
be able to claim I know how the UART code works."

* Just return 115200 as the current baud rate. I should cache it in the
  device struct and return that but I'm lazy right now.
* don't error out on other ioctl settings for now, just silently ignore them.
* remove some code that was copied from the 8250 driver that isn't needed
  any longer.

Tested:

* AR9331, Carambola-2 board.
2014-07-27 05:44:42 +00:00
Luiz Otavio O Souza
4bd2c6a20d Properly advertise that if_arge can handle long frames (if_arge is set to
handle packets up to 1536 bytes)

This fixes the need to frag that could happen when using vlans on top of
if_arge (which is a common case for the use the switch ports as individual
NICs).

Previously to this commit any vlan setup with if_arge as parent would have
the MTU of the parent interface reduced by the size of dot1q header
(4 bytes).

Tested on TP-Link 1043ND (where the WAN port is just a switch port setup to
tag packets in a different VLAN than the LAN ports).

Reported and tested by:	Harm Weites (harm at weites.com)
2014-07-03 20:16:48 +00:00
John Baldwin
068d8643ad Fix various NIC drivers to properly cleanup static DMA resources.
In particular, don't check the value of the bus_dma map against NULL
to determine if either bus_dmamem_alloc() or bus_dmamap_load() succeeded.
Instead, assume that bus_dmamap_load() succeeeded (and thus that
bus_dmamap_unload() should be called) if the bus address for a resource
is non-zero, and assume that bus_dmamem_alloc() succeeded (and thus
that bus_dmamem_free() should be called) if the virtual address for a
resource is not NULL.

In many cases these bugs could result in leaks when a driver was detached.

Reviewed by:	yongari
MFC after:	2 weeks
2014-06-11 14:53:58 +00:00
Luiz Otavio O Souza
ee454ea929 Do not configure all pins as outputs as this can lead to short circuits when
the GPIO pin is connected to a push button (or other devices).

Instead keep the boot loader settings.

Calling ar71xx_gpio_pin_configure() with DEFAULT_CAPS was probably a
mistake and was causing all the pins to be set as outputs.
2014-05-10 13:16:04 +00:00
Luiz Otavio O Souza
9cce5d9339 Remove an old mistake of mine. This has sneak in the code i sent to gonzo
at that time, but AFAIK it is only used on routerboards.

Enabling GPIO_FUNC_SPI_CS[1|2]_EN will claim the use of gpio pins 0 and 1
respectivelly for use as SPI CS pins.

When really needed, this can still be enabled on kernel hints using the
function_set and function_clear knobs.
2014-05-10 12:58:18 +00:00
Luiz Otavio O Souza
b7c7433150 Add support for reading RouterBoard's memory which is passed by the loader
(RouterBOOT).

Tested on RouterBoards, various and on RSPRO, TP-Link MR3x20
(for regressions).
2014-05-09 14:02:18 +00:00
Luiz Otavio O Souza
3010d2256a When a GPIO pin is set to be turned on by kernel hints (hint.gpio.X.pinon)
make sure the GPIO pin is configured as an output as this is not always the
case.
2014-05-09 13:44:42 +00:00
Adrian Chadd
86ac3134cd Extend the Atheros SoC support to include a method to enable/disable
the NAND flash controller.

Add the AR934x NAND flash controller reset routines.
(It's different on subsequent SoCs.)

Tested:

* AR9344, Atheros DB120 reference platform

Obtained from:	OpenWRT
2014-03-18 12:19:39 +00:00
Adrian Chadd
8ae440511d Add the AR934x NAND flash controller register definitions.
Obtained from:	OpenWRT
2014-03-18 12:18:35 +00:00
Adrian Chadd
22d0785fde Implement apb_print_child().
Tested:

* AR9344, Atheros DB120 Reference board
2014-03-17 23:21:31 +00:00
Adrian Chadd
7afd1d0205 The AR71xx has APB interrupts in the MISC registers from 0-7, later
chips have more.

So for now, let's allow more.  We should teach the apb code to just
reject interrupts that lie outside what the chip can do at runtime.
2014-03-16 08:39:46 +00:00
Adrian Chadd
e581852dd5 * Handle the three other timer interrupts for now, from the AR724x
later.  If the interrupts are ACKed even if they're not masked, we get
  the interrupts again later.  Grr.

* The AR724x and later chips want the interrupt bits cleared by writing the
  relevant bit to it, NOT by writing all but the current interrupt to it.

Tested:

* AR9344, DB120 reference board

TODO:

* Test ar724x and later chips to ensure no regressions have occured.
2014-03-16 08:38:31 +00:00
Adrian Chadd
e93e413461 Handle the case where both arge0 and arge1 MAC addresses are available via
'eeprommac'.

The existing driver would just make arge units past 0 take the primary
MAC and increment it by the unit number, without correct address wrapping.
That has to be fixed at a later date.

Tested:

* Atheros DB120 reference obard
2014-03-16 02:41:47 +00:00
Adrian Chadd
823be7b7a7 Add the USB EHCI flags required for the post-AR71xx devices.
Tested:

* DB120, AR9344
2014-03-02 02:49:20 +00:00
Adrian Chadd
73a9ec2e15 Disable this check for now; it fails on the AR9344 PCI fixup code.
I'll make it conditional later.

Tested:

* DB120
2014-02-14 05:22:28 +00:00
Adrian Chadd
98240e7bc0 Use the correct bitshift operators for the GPIO definitions.
Submitted by:	Daan Vreeken <Daan@vitsch.nl>
MFC after:	1 week
2014-01-22 08:02:07 +00:00
Warner Losh
294ef64a17 Introduce grab and ungrab upcalls. When the kernel desires to grab the
console, it calls the grab functions. These functions should turn off
the RX interrupts, and any others that interfere. This makes mountroot
prompt work again. If there's more generalized need other than
prompting, many of these routines should be expanded to do those new
things.

Reviewed by:	bde (with reservations)
2014-01-19 19:36:11 +00:00
Eitan Adler
7a22215c53 Fix undefined behavior: (1 << 31) is not defined as 1 is an int and this
shifts into the sign bit.  Instead use (1U << 31) which gets the
expected result.

This fix is not ideal as it assumes a 32 bit int, but does fix the issue
for most cases.

A similar change was made in OpenBSD.

Discussed with:	-arch, rdivacky
Reviewed by:	cperciva
2013-11-30 22:17:27 +00:00
Nathan Whitehorn
5543a1b98e Devices that rely on hints or identify routines for discovery need to
return BUS_PROBE_NOWILDCARD from their probe routines to avoid claiming
wildcard devices on their parent bus. Do a sweep through the MIPS tree.

MFC after: 2 weeks
2013-10-29 14:07:31 +00:00
Gleb Smirnoff
104dc21415 - Provide necessary includes, that before came via if.h pollution.
- Remove unnecessary ones.

Sponsored by:	Netflix
Sponsored by:	Nginx, Inc.
2013-10-28 22:26:03 +00:00
Adrian Chadd
ae222aa987 Whilst here, document that this TX alignment requirement may acutally
not be required on later hardware.

It would allow for higher packet rates so yes, it would be nice
to disable it.
2013-10-16 19:53:50 +00:00
Adrian Chadd
c572da7f10 Allow the MDIO bus frequency to be selected.
The MDIO bus frequency is configured as a divisor off of the MDIO bus
reference clock.  For the AR9344 and later, the MDIO bus frequency can
be faster than normal (ie, up to 100MHz) and thus a static divisor may
not be very applicable.

So, for those boards that may require an actual frequency to be selected
regardless of what crazy stuff the vendor throws in uboot, one can now
set the MDIO bus frequency.  It uses the MDIO frequency and the target
frequency to choose a divisor that doesn't exceed the target frequency.

By default it will choose:

* DIV_28 on everything; except
* DIV_58 on the AR9344 to be conservative.

Whilst I'm here, add some comments about the defaults being not quite
right.  For the other internal switch devices (like the AR933x, AR724x)
the divisor can be higher - it's internal and the reference MDIO clock
is much lower than 100MHz.

The divisor tables and loop code is inspired from Linux/OpenWRT.  It's very
simple; I didn't feel that reimplementing it would yield a substantially
different solution.

Tested:

* AR9331 (mips24k)
* AR9344 (mips74k)

Obtained from:	Linux/OpenWRT
2013-10-16 19:36:50 +00:00
Adrian Chadd
0348c9f480 Add in the platform specific quirks to get the AR934x SoC ethernet
up and running.

* The MAC FIFO configurations needed updating;
* Reset the MDIO block at the same time the MAC block is reset;
* The default divisor needs changing as the DB120 runs at a higher
  base MDIO bus clock compared to other chips.

The long-term fix is to allow the system to have a target MDIO bus
clock rate and then calculate the most suitable divider to meet
that.  This will likely need implementing before stable external
PHY or switch support can be committed.

Tested:

* AR9344 (mips74k)
* AR9331 (mips24k)
2013-10-16 03:11:18 +00:00
Adrian Chadd
ff7824ff52 Add in a write barrier after each if_arge write.
Without correct barriers, this code just plain doesn't work on the
mips74k cores (specifically the AR9344.)

In particular, the MDIO register accesses need this barriering or MII bus
access results in out-of-order garbage.

Tested:

* AR9344 (mips74k)
* AR9331 (mips24k)
2013-10-16 02:46:00 +00:00
Adrian Chadd
8c25111afe Add bus space barriers to the AR71xx SPI code.
This is required for correct, stable operation on the MIPS74k SoCs
that are dual-issue, superscalar pipelines.

Tested:

* AR9344 SoC (MIPS74k)
* AR9331 SoC (MIPS24k)
2013-10-16 02:10:35 +00:00
Adrian Chadd
b582e3ab93 Update the AR934x SoC support.
* Add the MDIO clock probe during clock initialisation;
* Update the ethernet PLL configuration function to use the correct
  values;
* Add a GMAC block configuration to pull the configuration out of hints;
* Add an ethernet switch reconfiguration method.

Tested:

* AR9344 SoC (DB120)

.. however, this has been tested with extra patches in my tree (to fix
the ethernet/MDIO support, SPI support, ethernet switch support)
and thus it isn't enough to bring the full board support up.
2013-10-15 03:28:32 +00:00
Adrian Chadd
07e5ae88f0 Update the AR933x SoC support to include a few new knobs:
* Initialise the MDIO clock to default to the reference clock;
* Add some code to allow the hints mechanism to allow setup of the GMAC
  config block.
* Document how the switch is wired up internally.

Tested:

* AR9331 SoC (Carambola 2)
2013-10-15 03:23:08 +00:00
Adrian Chadd
8c56b727e4 Fix the Atheros MIPS startup path a little.
* Print out the platform frequency the same as the other frequencies.
* Print out the MDIO frequency.
* Optionally do GMAC and ethernet switch setup if required.

Tested:

* AR9344
2013-10-15 01:37:00 +00:00
Adrian Chadd
2418402399 Add new features - an MDIO clock, WMAC reset, GMAC reset and ethernet
switch reset/initialise functions.

The AR934x and QC955x SoCs both have a configurable MDIO base clock.
The others have the MDIO clock use the same clock as the system
reference clock, whatever that may be.

Tested:

* AR9344 SoC

TODO:

* mips24k - AR933x would be fine for now, just to ensure that things
  are sane.
2013-10-15 01:35:48 +00:00
Adrian Chadd
1ba1edb39d Add the rest of the AR934x SoC reset register definitions.
Obtained from:	Linux/OpenWRT
2013-10-14 23:58:52 +00:00
Adrian Chadd
34141ebcda Add register definitions for the AR933x SoC GMAC (ie, ethernet MAC)
control block.

The GMAC configuration block allows for some configuration of how
the GMAC0 (ie, arge0) port is connected to the on-board switch
(if indeed there is one.)  It both can be pushed into the on-board
switch; it could also be torn out and exposed via an external
MII (and that operational mode is also controllable.)

Obtained from:	Linux/OpenWRT
2013-10-14 23:57:12 +00:00