Deleted Added
full compact
tegra_usbphy.c (308335) tegra_usbphy.c (332025)
1/*-
2 * Copyright (c) 2016 Michal Meloun <mmel@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2016 Michal Meloun <mmel@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/11/sys/arm/nvidia/tegra_usbphy.c 308335 2016-11-05 10:56:32Z mmel $");
28__FBSDID("$FreeBSD: stable/11/sys/arm/nvidia/tegra_usbphy.c 332025 2018-04-04 13:23:06Z mmel $");
29
30
31/*
32 * USB phy driver for Tegra SoCs.
33 */
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/bus.h>

--- 10 unchanged lines hidden (view full) ---

47#include <dev/extres/phy/phy.h>
48#include <dev/extres/regulator/regulator.h>
49#include <dev/fdt/fdt_common.h>
50#include <dev/fdt/fdt_pinctrl.h>
51#include <dev/ofw/openfirm.h>
52#include <dev/ofw/ofw_bus.h>
53#include <dev/ofw/ofw_bus_subr.h>
54
29
30
31/*
32 * USB phy driver for Tegra SoCs.
33 */
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/bus.h>

--- 10 unchanged lines hidden (view full) ---

47#include <dev/extres/phy/phy.h>
48#include <dev/extres/regulator/regulator.h>
49#include <dev/fdt/fdt_common.h>
50#include <dev/fdt/fdt_pinctrl.h>
51#include <dev/ofw/openfirm.h>
52#include <dev/ofw/ofw_bus.h>
53#include <dev/ofw/ofw_bus_subr.h>
54
55#include "phy_if.h"
55#include "phynode_if.h"
56
57#define CTRL_ICUSB_CTRL 0x15c
58#define ICUSB_CTR_IC_ENB1 (1 << 3)
59
60#define CTRL_USB_USBMODE 0x1f8
61#define USB_USBMODE_MASK (3 << 0)
62#define USB_USBMODE_HOST (3 << 0)
63#define USB_USBMODE_DEVICE (2 << 0)

--- 231 unchanged lines hidden (view full) ---

295 int xcvr_setup_use_fuses;
296};
297
298static struct ofw_compat_data compat_data[] = {
299 {"nvidia,tegra30-usb-phy", 1},
300 {NULL, 0},
301};
302
56
57#define CTRL_ICUSB_CTRL 0x15c
58#define ICUSB_CTR_IC_ENB1 (1 << 3)
59
60#define CTRL_USB_USBMODE 0x1f8
61#define USB_USBMODE_MASK (3 << 0)
62#define USB_USBMODE_HOST (3 << 0)
63#define USB_USBMODE_DEVICE (2 << 0)

--- 231 unchanged lines hidden (view full) ---

295 int xcvr_setup_use_fuses;
296};
297
298static struct ofw_compat_data compat_data[] = {
299 {"nvidia,tegra30-usb-phy", 1},
300 {NULL, 0},
301};
302
303 /* Phy controller class and methods. */
304static int usbphy_phy_enable(struct phynode *phy, bool enable);
305static phynode_method_t usbphy_phynode_methods[] = {
306 PHYNODEMETHOD(phynode_enable, usbphy_phy_enable),
307
308 PHYNODEMETHOD_END
309};
310DEFINE_CLASS_1(usbphy_phynode, usbphy_phynode_class, usbphy_phynode_methods,
311 0, phynode_class);
312
303#define RD4(sc, offs) \
304 bus_read_4(sc->mem_res, offs)
305
306#define WR4(sc, offs, val) \
307 bus_write_4(sc->mem_res, offs, val)
308
309static int
310reg_wait(struct usbphy_softc *sc, uint32_t reg, uint32_t mask, uint32_t val)

--- 239 unchanged lines hidden (view full) ---

550 "Cannot disable 'utmi-pads' clock\n");
551 return (rv);
552 }
553 }
554 return (0);
555}
556
557static int
313#define RD4(sc, offs) \
314 bus_read_4(sc->mem_res, offs)
315
316#define WR4(sc, offs, val) \
317 bus_write_4(sc->mem_res, offs, val)
318
319static int
320reg_wait(struct usbphy_softc *sc, uint32_t reg, uint32_t mask, uint32_t val)

--- 239 unchanged lines hidden (view full) ---

560 "Cannot disable 'utmi-pads' clock\n");
561 return (rv);
562 }
563 }
564 return (0);
565}
566
567static int
558usbphy_phy_enable(device_t dev, int id, bool enable)
568usbphy_phy_enable(struct phynode *phy, bool enable)
559{
569{
570 device_t dev;
560 struct usbphy_softc *sc;
561 int rv = 0;
562
571 struct usbphy_softc *sc;
572 int rv = 0;
573
574 dev = phynode_get_device(phy);
563 sc = device_get_softc(dev);
564
565 if (sc->ifc_type != USB_IFC_TYPE_UTMI) {
566 device_printf(sc->dev,
567 "Only UTMI interface is supported.\n");
568 return (ENXIO);
569 }
570 if (enable)

--- 125 unchanged lines hidden (view full) ---

696
697 device_set_desc(dev, "Tegra USB phy");
698 return (BUS_PROBE_DEFAULT);
699}
700
701static int
702usbphy_attach(device_t dev)
703{
575 sc = device_get_softc(dev);
576
577 if (sc->ifc_type != USB_IFC_TYPE_UTMI) {
578 device_printf(sc->dev,
579 "Only UTMI interface is supported.\n");
580 return (ENXIO);
581 }
582 if (enable)

--- 125 unchanged lines hidden (view full) ---

708
709 device_set_desc(dev, "Tegra USB phy");
710 return (BUS_PROBE_DEFAULT);
711}
712
713static int
714usbphy_attach(device_t dev)
715{
704 struct usbphy_softc * sc;
716 struct usbphy_softc *sc;
705 int rid, rv;
706 phandle_t node;
717 int rid, rv;
718 phandle_t node;
719 struct phynode *phynode;
720 struct phynode_init_def phy_init;
707
708 sc = device_get_softc(dev);
709 sc->dev = dev;
710
711 rid = 0;
712 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
713 RF_ACTIVE | RF_SHAREABLE);
714 if (sc->mem_res == NULL) {

--- 83 unchanged lines hidden (view full) ---

798 rv = regulator_enable(sc->supply_vbus);
799 if (rv != 0) {
800 device_printf(sc->dev,
801 "Cannot enable \"vbus\" regulator\n");
802 return (rv);
803 }
804 }
805
721
722 sc = device_get_softc(dev);
723 sc->dev = dev;
724
725 rid = 0;
726 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
727 RF_ACTIVE | RF_SHAREABLE);
728 if (sc->mem_res == NULL) {

--- 83 unchanged lines hidden (view full) ---

812 rv = regulator_enable(sc->supply_vbus);
813 if (rv != 0) {
814 device_printf(sc->dev,
815 "Cannot enable \"vbus\" regulator\n");
816 return (rv);
817 }
818 }
819
806 phy_register_provider(dev);
820 /* Create and register phy. */
821 bzero(&phy_init, sizeof(phy_init));
822 phy_init.id = 1;
823 phy_init.ofw_node = node;
824 phynode = phynode_create(dev, &usbphy_phynode_class, &phy_init);
825 if (phynode == NULL) {
826 device_printf(sc->dev, "Cannot create phy\n");
827 return (ENXIO);
828 }
829 if (phynode_register(phynode) == NULL) {
830 device_printf(sc->dev, "Cannot create phy\n");
831 return (ENXIO);
832 }
833
807 return (0);
808}
809
810static int
811usbphy_detach(device_t dev)
812{
813
814 /* This device is always present. */
815 return (EBUSY);
816}
817
818static device_method_t tegra_usbphy_methods[] = {
819 /* Device interface */
820 DEVMETHOD(device_probe, usbphy_probe),
821 DEVMETHOD(device_attach, usbphy_attach),
822 DEVMETHOD(device_detach, usbphy_detach),
823
834 return (0);
835}
836
837static int
838usbphy_detach(device_t dev)
839{
840
841 /* This device is always present. */
842 return (EBUSY);
843}
844
845static device_method_t tegra_usbphy_methods[] = {
846 /* Device interface */
847 DEVMETHOD(device_probe, usbphy_probe),
848 DEVMETHOD(device_attach, usbphy_attach),
849 DEVMETHOD(device_detach, usbphy_detach),
850
824 /* phy interface */
825 DEVMETHOD(phy_enable, usbphy_phy_enable),
826
827 DEVMETHOD_END
828};
829
830static devclass_t tegra_usbphy_devclass;
831static DEFINE_CLASS_0(usbphy, tegra_usbphy_driver, tegra_usbphy_methods,
832 sizeof(struct usbphy_softc));
833EARLY_DRIVER_MODULE(tegra_usbphy, simplebus, tegra_usbphy_driver,
834 tegra_usbphy_devclass, NULL, NULL, 79);
851 DEVMETHOD_END
852};
853
854static devclass_t tegra_usbphy_devclass;
855static DEFINE_CLASS_0(usbphy, tegra_usbphy_driver, tegra_usbphy_methods,
856 sizeof(struct usbphy_softc));
857EARLY_DRIVER_MODULE(tegra_usbphy, simplebus, tegra_usbphy_driver,
858 tegra_usbphy_devclass, NULL, NULL, 79);