2007-04-18 06:39:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006-2007 PA Semi, Inc
|
|
|
|
*
|
|
|
|
* Author: Olof Johansson, PA Semi
|
|
|
|
*
|
|
|
|
* Maintained by: Olof Johansson <olof@lixom.net>
|
|
|
|
*
|
|
|
|
* Based on drivers/net/fs_enet/mii-bitbang.c.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2007-04-18 06:39:54 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/phy.h>
|
2013-09-26 12:40:04 +00:00
|
|
|
#include <linux/of_address.h>
|
2009-04-25 12:53:17 +00:00
|
|
|
#include <linux/of_mdio.h>
|
2007-11-13 17:13:03 +00:00
|
|
|
#include <linux/of_platform.h>
|
2007-04-18 06:39:54 +00:00
|
|
|
|
|
|
|
#define DELAY 1
|
|
|
|
|
|
|
|
static void __iomem *gpio_regs;
|
|
|
|
|
|
|
|
struct gpio_priv {
|
|
|
|
int mdc_pin;
|
|
|
|
int mdio_pin;
|
2009-04-25 12:53:17 +00:00
|
|
|
int mdio_irqs[PHY_MAX_ADDR];
|
2007-04-18 06:39:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MDC_PIN(bus) (((struct gpio_priv *)bus->priv)->mdc_pin)
|
|
|
|
#define MDIO_PIN(bus) (((struct gpio_priv *)bus->priv)->mdio_pin)
|
|
|
|
|
|
|
|
static inline void mdio_lo(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
out_le32(gpio_regs+0x10, 1 << MDIO_PIN(bus));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mdio_hi(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
out_le32(gpio_regs, 1 << MDIO_PIN(bus));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mdc_lo(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
out_le32(gpio_regs+0x10, 1 << MDC_PIN(bus));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mdc_hi(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
out_le32(gpio_regs, 1 << MDC_PIN(bus));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mdio_active(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
out_le32(gpio_regs+0x20, (1 << MDC_PIN(bus)) | (1 << MDIO_PIN(bus)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mdio_tristate(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
out_le32(gpio_regs+0x30, (1 << MDIO_PIN(bus)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mdio_read(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
return !!(in_le32(gpio_regs+0x40) & (1 << MDIO_PIN(bus)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clock_out(struct mii_bus *bus, int bit)
|
|
|
|
{
|
|
|
|
if (bit)
|
|
|
|
mdio_hi(bus);
|
|
|
|
else
|
|
|
|
mdio_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_lo(bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Utility to send the preamble, address, and register (common to read and write). */
|
|
|
|
static void bitbang_pre(struct mii_bus *bus, int read, u8 addr, u8 reg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* CFE uses a really long preamble (40 bits). We'll do the same. */
|
|
|
|
mdio_active(bus);
|
|
|
|
for (i = 0; i < 40; i++) {
|
|
|
|
clock_out(bus, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send the start bit (01) and the read opcode (10) or write (10) */
|
|
|
|
clock_out(bus, 0);
|
|
|
|
clock_out(bus, 1);
|
|
|
|
|
|
|
|
clock_out(bus, read);
|
|
|
|
clock_out(bus, !read);
|
|
|
|
|
|
|
|
/* send the PHY address */
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
clock_out(bus, (addr & 0x10) != 0);
|
|
|
|
addr <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send the register address */
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
clock_out(bus, (reg & 0x10) != 0);
|
|
|
|
reg <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mdio_read(struct mii_bus *bus, int phy_id, int location)
|
|
|
|
{
|
|
|
|
u16 rdreg;
|
|
|
|
int ret, i;
|
|
|
|
u8 addr = phy_id & 0xff;
|
|
|
|
u8 reg = location & 0xff;
|
|
|
|
|
|
|
|
bitbang_pre(bus, 1, addr, reg);
|
|
|
|
|
|
|
|
/* tri-state our MDIO I/O pin so we can read */
|
|
|
|
mdio_tristate(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_lo(bus);
|
|
|
|
|
|
|
|
/* read 16 bits of register data, MSB first */
|
|
|
|
rdreg = 0;
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
mdc_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
rdreg <<= 1;
|
|
|
|
rdreg |= mdio_read(bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
|
|
|
|
ret = rdreg;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mdio_write(struct mii_bus *bus, int phy_id, int location, u16 val)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
u8 addr = phy_id & 0xff;
|
|
|
|
u8 reg = location & 0xff;
|
|
|
|
u16 value = val & 0xffff;
|
|
|
|
|
|
|
|
bitbang_pre(bus, 0, addr, reg);
|
|
|
|
|
|
|
|
/* send the turnaround (10) */
|
|
|
|
mdc_lo(bus);
|
|
|
|
mdio_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_lo(bus);
|
|
|
|
mdio_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
|
|
|
|
/* write 16 bits of register data, MSB first */
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
mdc_lo(bus);
|
|
|
|
if (value & 0x8000)
|
|
|
|
mdio_hi(bus);
|
|
|
|
else
|
|
|
|
mdio_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
value <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tri-state the MDIO line.
|
|
|
|
*/
|
|
|
|
mdio_tristate(bus);
|
|
|
|
mdc_lo(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
mdc_hi(bus);
|
|
|
|
udelay(DELAY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mdio_reset(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
/*nothing here - dunno how to reset it*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-21 22:04:10 +00:00
|
|
|
static int gpio_mdio_probe(struct platform_device *ofdev)
|
2007-04-18 06:39:54 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &ofdev->dev;
|
2010-04-13 23:12:29 +00:00
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
2007-04-18 06:39:54 +00:00
|
|
|
struct mii_bus *new_bus;
|
|
|
|
struct gpio_priv *priv;
|
|
|
|
const unsigned int *prop;
|
2007-11-04 21:44:15 +00:00
|
|
|
int err;
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2007-11-04 21:44:15 +00:00
|
|
|
err = -ENOMEM;
|
2007-04-18 06:39:54 +00:00
|
|
|
priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL);
|
2007-11-04 21:44:15 +00:00
|
|
|
if (!priv)
|
|
|
|
goto out;
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2008-10-09 16:45:04 +00:00
|
|
|
new_bus = mdiobus_alloc();
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2007-11-04 21:44:15 +00:00
|
|
|
if (!new_bus)
|
|
|
|
goto out_free_priv;
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2007-11-04 21:44:15 +00:00
|
|
|
new_bus->name = "pasemi gpio mdio bus";
|
|
|
|
new_bus->read = &gpio_mdio_read;
|
|
|
|
new_bus->write = &gpio_mdio_write;
|
|
|
|
new_bus->reset = &gpio_mdio_reset;
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2007-04-29 06:29:08 +00:00
|
|
|
prop = of_get_property(np, "reg", NULL);
|
2008-04-10 00:38:13 +00:00
|
|
|
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop);
|
2007-04-18 06:39:54 +00:00
|
|
|
new_bus->priv = priv;
|
|
|
|
|
2009-04-25 12:53:17 +00:00
|
|
|
new_bus->irq = priv->mdio_irqs;
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2007-04-29 06:29:08 +00:00
|
|
|
prop = of_get_property(np, "mdc-pin", NULL);
|
2007-04-18 06:39:54 +00:00
|
|
|
priv->mdc_pin = *prop;
|
|
|
|
|
2007-04-29 06:29:08 +00:00
|
|
|
prop = of_get_property(np, "mdio-pin", NULL);
|
2007-04-18 06:39:54 +00:00
|
|
|
priv->mdio_pin = *prop;
|
|
|
|
|
2008-10-01 15:41:33 +00:00
|
|
|
new_bus->parent = dev;
|
2007-04-18 06:39:54 +00:00
|
|
|
dev_set_drvdata(dev, new_bus);
|
|
|
|
|
2009-04-25 12:53:17 +00:00
|
|
|
err = of_mdiobus_register(new_bus, np);
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2007-11-04 21:44:15 +00:00
|
|
|
if (err != 0) {
|
2007-04-18 06:39:54 +00:00
|
|
|
printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n",
|
|
|
|
new_bus->name, err);
|
2007-11-04 21:44:15 +00:00
|
|
|
goto out_free_irq;
|
2007-04-18 06:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2007-11-04 21:44:15 +00:00
|
|
|
out_free_irq:
|
2007-04-18 06:39:54 +00:00
|
|
|
kfree(new_bus);
|
2007-11-04 21:44:15 +00:00
|
|
|
out_free_priv:
|
|
|
|
kfree(priv);
|
|
|
|
out:
|
2007-04-18 06:39:54 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 21:52:34 +00:00
|
|
|
static int gpio_mdio_remove(struct platform_device *dev)
|
2007-04-18 06:39:54 +00:00
|
|
|
{
|
|
|
|
struct mii_bus *bus = dev_get_drvdata(&dev->dev);
|
|
|
|
|
|
|
|
mdiobus_unregister(bus);
|
|
|
|
|
|
|
|
dev_set_drvdata(&dev->dev, NULL);
|
|
|
|
|
|
|
|
kfree(bus->priv);
|
|
|
|
bus->priv = NULL;
|
2008-10-09 16:45:04 +00:00
|
|
|
mdiobus_free(bus);
|
2007-04-18 06:39:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:56:38 +00:00
|
|
|
static const struct of_device_id gpio_mdio_match[] =
|
2007-04-18 06:39:54 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
.compatible = "gpio-mdio",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
2007-12-03 04:35:25 +00:00
|
|
|
MODULE_DEVICE_TABLE(of, gpio_mdio_match);
|
2007-04-18 06:39:54 +00:00
|
|
|
|
2011-02-23 02:59:54 +00:00
|
|
|
static struct platform_driver gpio_mdio_driver =
|
2007-04-18 06:39:54 +00:00
|
|
|
{
|
|
|
|
.probe = gpio_mdio_probe,
|
|
|
|
.remove = gpio_mdio_remove,
|
2010-04-13 23:13:02 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "gpio-mdio-bitbang",
|
|
|
|
.of_match_table = gpio_mdio_match,
|
2007-10-11 05:19:03 +00:00
|
|
|
},
|
2007-04-18 06:39:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int gpio_mdio_init(void)
|
|
|
|
{
|
2007-11-04 21:44:15 +00:00
|
|
|
struct device_node *np;
|
|
|
|
|
2007-11-05 02:57:45 +00:00
|
|
|
np = of_find_compatible_node(NULL, NULL, "1682m-gpio");
|
|
|
|
if (!np)
|
|
|
|
np = of_find_compatible_node(NULL, NULL,
|
|
|
|
"pasemi,pwrficient-gpio");
|
2007-11-04 21:44:15 +00:00
|
|
|
if (!np)
|
|
|
|
return -ENODEV;
|
|
|
|
gpio_regs = of_iomap(np, 0);
|
|
|
|
of_node_put(np);
|
|
|
|
|
|
|
|
if (!gpio_regs)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2011-02-23 02:59:54 +00:00
|
|
|
return platform_driver_register(&gpio_mdio_driver);
|
2007-04-18 06:39:54 +00:00
|
|
|
}
|
2007-11-04 21:44:15 +00:00
|
|
|
module_init(gpio_mdio_init);
|
2007-04-18 06:39:54 +00:00
|
|
|
|
|
|
|
void gpio_mdio_exit(void)
|
|
|
|
{
|
2011-02-23 02:59:54 +00:00
|
|
|
platform_driver_unregister(&gpio_mdio_driver);
|
2007-11-04 21:44:15 +00:00
|
|
|
if (gpio_regs)
|
|
|
|
iounmap(gpio_regs);
|
2007-04-18 06:39:54 +00:00
|
|
|
}
|
2007-11-04 21:44:15 +00:00
|
|
|
module_exit(gpio_mdio_exit);
|
2007-12-03 04:35:25 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Olof Johansson <olof@lixom.net>");
|
|
|
|
MODULE_DESCRIPTION("Driver for MDIO over GPIO on PA Semi PWRficient-based boards");
|