Page MenuHomeFreeBSD

D12649.id34140.diff
No OneTemporary

D12649.id34140.diff

Index: sys/boot/fdt/dts/mips/MZK-W300NAG.dts
===================================================================
--- /dev/null
+++ sys/boot/fdt/dts/mips/MZK-W300NAG.dts
@@ -0,0 +1,104 @@
+/dts-v1/;
+
+#include "rt2880.dtsi"
+
+/ {
+ compatible = "MZK-W300NAG", "ralink,rt2880-soc";
+ model = "Planex MZK-W300NAG";
+
+ memory@0 {
+ device_type = "memory";
+ reg = <0x08000000 0x1000000>;
+ };
+
+ cfi@1f000000 {
+ compatible = "cfi-flash";
+ reg = <0x1f000000 0x800000>;
+ bank-width = <2>;
+ device-width = <2>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ partition@0 {
+ label = "Bootloader";
+ reg = <0x0 0x30000>;
+ read-only;
+ };
+
+ devdata: partition@30000 {
+ label = "Config";
+ reg = <0x00030000 0x00010000>;
+ read-only;
+ };
+
+ factory: partition@40000 {
+ label = "Factory";
+ reg = <0x00040000 0x00010000>;
+ read-only;
+ };
+ kernel: partition@50000 {
+ label = "kernel";
+ reg = <0x00050000 0x000f0000>;
+ read-only;
+ };
+ rootfs: partition@160000 {
+ label = "rootfs";
+ reg = <0x00140000 0x002a0000>;
+ read-only;
+ };
+ cimage: partition@3e0000 {
+ label = "Cimage";
+ reg = <0x003e0000 0x00020000>;
+ read-only;
+ };
+ };
+
+ gpio-leds {
+ compatible = "gpio-leds";
+
+ status {
+ label = "status";
+ gpios = <&gpio0 12 0>;
+ };
+
+ };
+ gpio-keys-polled {
+ compatible = "gpio-keys-polled";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ poll-interval = <20>;
+
+ reset {
+ label = "reset";
+ gpios = <&gpio0 10 1>;
+ linux,code = <0x198>;
+ };
+
+ };
+
+ gpioiic {
+ compatible = "gpioiic";
+ gpios = <&gpio0 23 0
+ &gpio0 22 0>;
+ gpio-names = "scl", "sda";
+ };
+
+ rtl8366rb {
+ compatible = "realtek,rtl8366rb";
+ };
+
+};
+
+&ethernet {
+ mtd-mac-address = <&factory 0x28>;
+ port-mode = "gigasw";
+};
+
+&wmac {
+ ralink,mtd-eeprom = <&factory 0>;
+};
+
+&i2c {
+ status = "okay";
+};
+
Index: sys/dev/etherswitch/rtl8366/rtl8366rb.c
===================================================================
--- sys/dev/etherswitch/rtl8366/rtl8366rb.c
+++ sys/dev/etherswitch/rtl8366/rtl8366rb.c
@@ -27,6 +27,7 @@
* $FreeBSD$
*/
+#include "opt_platform.h"
#include "opt_etherswitch.h"
#include <sys/param.h>
@@ -59,6 +60,12 @@
#include <dev/etherswitch/etherswitch.h>
#include <dev/etherswitch/rtl8366/rtl8366rbvar.h>
+#ifdef FDT
+#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#endif
+
#include "mdio_if.h"
#include "iicbus_if.h"
#include "miibus_if.h"
@@ -143,9 +150,21 @@
rtl8366rb_probe(device_t dev)
{
struct rtl8366rb_softc *sc;
+#ifdef FDT
+ phandle_t rtl8366_node;
- sc = device_get_softc(dev);
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ rtl8366_node = fdt_find_compatible(OF_finddevice("/"),
+ "realtek,rtl8366rb", 0);
+
+ if (rtl8366_node == 0)
+ return (ENXIO);
+#endif
+ sc = device_get_softc(dev);
+
bzero(sc, sizeof(*sc));
if (smi_probe(dev) != 0)
return (ENXIO);
@@ -952,9 +971,13 @@
DRIVER_MODULE(rtl8366rb, iicbus, rtl8366rb_driver, rtl8366rb_devclass, 0, 0);
DRIVER_MODULE(miibus, rtl8366rb, miibus_driver, miibus_devclass, 0, 0);
-DRIVER_MODULE(mdio, rtl8366rb, mdio_driver, mdio_devclass, 0, 0);
DRIVER_MODULE(etherswitch, rtl8366rb, etherswitch_driver, etherswitch_devclass, 0, 0);
MODULE_VERSION(rtl8366rb, 1);
+#ifdef FDT
+MODULE_DEPEND(rtl8366rb, ofwbus, 1, 1, 1); /* XXX which versions? */
+#else
+DRIVER_MODULE(mdio, rtl8366rb, mdio_driver, mdio_devclass, 0, 0);
MODULE_DEPEND(rtl8366rb, iicbus, 1, 1, 1); /* XXX which versions? */
MODULE_DEPEND(rtl8366rb, miibus, 1, 1, 1); /* XXX which versions? */
MODULE_DEPEND(rtl8366rb, etherswitch, 1, 1, 1); /* XXX which versions? */
+#endif
Index: sys/dev/gpio/gpioiic.c
===================================================================
--- sys/dev/gpio/gpioiic.c
+++ sys/dev/gpio/gpioiic.c
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org>
* Copyright (c) 2010 Luiz Otavio O Souza
+ * Copyright (c) 2017 Hiroki Mori
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,8 +58,13 @@
{
device_t sc_dev;
device_t sc_busdev;
+#ifdef FDT
+ gpio_pin_t scl_pin;
+ gpio_pin_t sda_pin;
+#else
int scl_pin;
int sda_pin;
+#endif
};
static int gpioiic_probe(device_t);
@@ -75,14 +81,14 @@
static int
gpioiic_probe(device_t dev)
{
- struct gpiobus_ivar *devi;
-
#ifdef FDT
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_is_compatible(dev, "gpioiic"))
return (ENXIO);
-#endif
+#else
+ struct gpiobus_ivar *devi;
+
devi = GPIOBUS_IVAR(dev);
if (devi->npins < GPIOIIC_MIN_PINS) {
device_printf(dev,
@@ -90,6 +96,7 @@
GPIOIIC_MIN_PINS, devi->npins);
return (ENXIO);
}
+#endif
device_set_desc(dev, "GPIO I2C bit-banging driver");
return (BUS_PROBE_DEFAULT);
@@ -101,14 +108,16 @@
device_t bitbang;
#ifdef FDT
phandle_t node;
- pcell_t pin;
-#endif
+ int err;
+#else
struct gpiobus_ivar *devi;
+#endif
struct gpioiic_softc *sc;
sc = device_get_softc(dev);
sc->sc_dev = dev;
sc->sc_busdev = device_get_parent(dev);
+#ifndef FDT
if (resource_int_value(device_get_name(dev),
device_get_unit(dev), "scl", &sc->scl_pin))
sc->scl_pin = GPIOIIC_SCL_DFLT;
@@ -116,15 +125,6 @@
device_get_unit(dev), "sda", &sc->sda_pin))
sc->sda_pin = GPIOIIC_SDA_DFLT;
-#ifdef FDT
- if ((node = ofw_bus_get_node(dev)) == -1)
- return (ENXIO);
- if (OF_getencprop(node, "scl", &pin, sizeof(pin)) > 0)
- sc->scl_pin = (int)pin;
- if (OF_getencprop(node, "sda", &pin, sizeof(pin)) > 0)
- sc->sda_pin = (int)pin;
-#endif
-
if (sc->scl_pin < 0 || sc->scl_pin > 1)
sc->scl_pin = GPIOIIC_SCL_DFLT;
if (sc->sda_pin < 0 || sc->sda_pin > 1)
@@ -133,6 +133,21 @@
devi = GPIOBUS_IVAR(dev);
device_printf(dev, "SCL pin: %d, SDA pin: %d\n",
devi->pins[sc->scl_pin], devi->pins[sc->sda_pin]);
+#else
+ node = ofw_bus_get_node(sc->sc_dev);
+// err = gpio_pin_get_by_ofw_idx(sc->sc_dev, node, 0, &sc->scl_pin);
+ err = gpio_pin_get_by_ofw_name(sc->sc_dev, node, "scl", &sc->scl_pin);
+ if (err != 0) {
+ device_printf(sc->sc_dev, "cannot get pin scl\n");
+ return (ENXIO);
+ }
+// err = gpio_pin_get_by_ofw_idx(sc->sc_dev, node, 1, &sc->sda_pin);
+ err = gpio_pin_get_by_ofw_name(sc->sc_dev, node, "sda", &sc->sda_pin);
+ if (err != 0) {
+ device_printf(sc->sc_dev, "cannot get pin sda\n");
+ return (ENXIO);
+ }
+#endif
/* add generic bit-banging code */
bitbang = device_add_child(dev, "iicbb", -1);
@@ -148,53 +163,92 @@
static void
gpioiic_reset_bus(device_t dev)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
+ struct gpioiic_softc *sc;
+ sc = device_get_softc(dev);
+
+#ifdef FDT
+ gpio_pin_setflags(sc->sda_pin, GPIO_PIN_INPUT);
+ gpio_pin_setflags(sc->scl_pin, GPIO_PIN_INPUT);
+#else
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
GPIO_PIN_INPUT);
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
GPIO_PIN_INPUT);
+#endif
}
static void
gpioiic_setsda(device_t dev, int val)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
+ struct gpioiic_softc *sc;
+
+ sc = device_get_softc(dev);
if (val == 0) {
+#ifdef FDT
+ gpio_pin_set_active(sc->sda_pin, 0);
+ gpio_pin_setflags(sc->sda_pin, GPIO_PIN_OUTPUT);
+#else
GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, sc->sda_pin, 0);
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
GPIO_PIN_OUTPUT);
+#endif
} else {
+#ifdef FDT
+ gpio_pin_set_active(sc->sda_pin, 1);
+ gpio_pin_setflags(sc->sda_pin, GPIO_PIN_OUTPUT);
+#else
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
GPIO_PIN_INPUT);
+#endif
}
}
static void
gpioiic_setscl(device_t dev, int val)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
+ struct gpioiic_softc *sc;
+
+ sc = device_get_softc(dev);
if (val == 0) {
+#ifdef FDT
+ gpio_pin_set_active(sc->scl_pin, 0);
+ gpio_pin_setflags(sc->scl_pin, GPIO_PIN_OUTPUT);
+#else
GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, sc->scl_pin, 0);
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
GPIO_PIN_OUTPUT);
+#endif
} else {
+#ifdef FDT
+ gpio_pin_set_active(sc->scl_pin, 1);
+ gpio_pin_setflags(sc->scl_pin, GPIO_PIN_OUTPUT);
+#else
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
GPIO_PIN_INPUT);
+#endif
}
}
static int
gpioiic_getscl(device_t dev)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
- unsigned int val;
+ struct gpioiic_softc *sc;
+ sc = device_get_softc(dev);
+
+#ifdef FDT
+ bool val;
+ gpio_pin_setflags(sc->scl_pin, GPIO_PIN_INPUT);
+ gpio_pin_is_active(sc->scl_pin, &val);
+#else
+ unsigned int val;
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
GPIO_PIN_INPUT);
GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, sc->scl_pin, &val);
+#endif
return ((int)val);
}
@@ -202,12 +256,20 @@
static int
gpioiic_getsda(device_t dev)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
- unsigned int val;
+ struct gpioiic_softc *sc;
+ sc = device_get_softc(dev);
+
+#ifdef FDT
+ bool val;
+ gpio_pin_setflags(sc->sda_pin, GPIO_PIN_INPUT);
+ gpio_pin_is_active(sc->sda_pin, &val);
+#else
+ unsigned int val;
GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
GPIO_PIN_INPUT);
GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, sc->sda_pin, &val);
+#endif
return ((int)val);
}
@@ -262,6 +324,9 @@
sizeof(struct gpioiic_softc),
};
+#ifdef FDT
+DRIVER_MODULE(gpioiic, ofwbus, gpioiic_driver, gpioiic_devclass, 0, 0);
+#endif
DRIVER_MODULE(gpioiic, gpiobus, gpioiic_driver, gpioiic_devclass, 0, 0);
DRIVER_MODULE(iicbb, gpioiic, iicbb_driver, iicbb_devclass, 0, 0);
MODULE_DEPEND(gpioiic, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
Index: sys/dev/rt/if_rt.c
===================================================================
--- sys/dev/rt/if_rt.c
+++ sys/dev/rt/if_rt.c
@@ -352,10 +352,18 @@
struct rt_softc *sc;
struct ifnet *ifp;
int error, i;
+#ifdef FDT
+ phandle_t node;
+ char fdtval[32];
+#endif
sc = device_get_softc(dev);
sc->dev = dev;
+#ifdef FDT
+ node = ofw_bus_get_node(sc->dev);
+#endif
+
mtx_init(&sc->lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
MTX_DEF | MTX_RECURSE);
@@ -477,8 +485,16 @@
GDM_DST_PORT_CPU << GDM_OFRC_P_SHIFT /* fwd Other to CPU */
));
- if (sc->rt_chipid == RT_CHIPID_RT2880)
- RT_WRITE(sc, MDIO_CFG, MDIO_2880_100T_INIT);
+ /* RT2880 is only support FDT */
+#ifdef FDT
+ if (sc->rt_chipid == RT_CHIPID_RT2880) {
+ if (OF_getprop(node, "port-mode", fdtval, sizeof(fdtval)) > 0 &&
+ strcmp(fdtval, "gigasw") == 0)
+ RT_WRITE(sc, MDIO_CFG, MDIO_2880_GIGA_INIT);
+ else
+ RT_WRITE(sc, MDIO_CFG, MDIO_2880_100T_INIT);
+ }
+#endif
/* allocate Tx and Rx rings */
for (i = 0; i < RT_SOFTC_TX_RING_COUNT; i++) {
@@ -2909,7 +2925,7 @@
if (!ofw_bus_is_compatible(dev, "ralink,rt2880-mdio"))
return (ENXIO);
- device_set_desc(dev, "FV built-in ethernet interface, MDIO controller");
+ device_set_desc(dev, "RT built-in ethernet interface, MDIO controller");
return(0);
}

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 23, 11:36 PM (4 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32050871
Default Alt Text
D12649.id34140.diff (10 KB)

Event Timeline