arm/lpc: Add option to customize device probes

This commit is contained in:
Sebastian Huber 2022-06-30 10:29:02 +02:00
parent b7787bd311
commit 9794487b1f
3 changed files with 67 additions and 9 deletions

View File

@ -0,0 +1,43 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARM_LPC_PROBE_H
#define _ARM_LPC_PROBE_H
#ifdef __cplusplus
extern "C" {
#endif
int lpc_eth_probe(int unit);
int lpc_ohci_probe(int unit);
#ifdef __cplusplus
}
#endif
#endif /* _ARM_LPC_PROBE_H */

View File

@ -43,6 +43,8 @@
#include <rtems/bsd/bsd.h>
#include <arm/lpc/probe.h>
#include <bsp.h>
#include <bsp/irq.h>
#include <bsp/lpc-ethernet-config.h>
@ -1603,15 +1605,19 @@ static void lpc_eth_media_status(struct ifnet *ifp, struct ifmediareq *imr)
}
}
int lpc_eth_probe(device_t dev)
__weak_symbol int lpc_eth_probe(int unit)
{
int unit = device_get_unit(dev);
if (unit != 0) {
return ENXIO;
}
return 0;
return BUS_PROBE_DEFAULT;
}
static int lpc_eth_do_probe(device_t dev)
{
device_set_desc(dev, "LPC32x0 Ethernet controller");
return lpc_eth_probe(device_get_unit(dev));
}
static int lpc_eth_attach(device_t dev)
@ -1743,7 +1749,7 @@ static int lpc_eth_detach(device_t dev)
}
static device_method_t lpe_methods[] = {
DEVMETHOD(device_probe, lpc_eth_probe),
DEVMETHOD(device_probe, lpc_eth_do_probe),
DEVMETHOD(device_attach, lpc_eth_attach),
DEVMETHOD(device_detach, lpc_eth_detach),
DEVMETHOD_END

View File

@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$");
#include <dev/usb/controller/ohci.h>
#include <dev/usb/controller/ohcireg.h>
#include <arm/lpc/probe.h>
#include <arm/lpc/lpcreg.h>
#include <arm/lpc/lpcvar.h>
@ -90,7 +91,7 @@ __FBSDID("$FreeBSD$");
while ((lpc_otg_read_4(_sc, _sreg) & _value) != _value); \
} while (0);
static int lpc_ohci_probe(device_t dev);
static int lpc_ohci_do_probe(device_t dev);
static int lpc_ohci_attach(device_t dev);
static int lpc_ohci_detach(device_t dev);
@ -107,12 +108,20 @@ static int lpc_otg_i2c_wait_for_transaction_done(struct ohci_softc *sc);
static int lpc_otg_i2c_read(const struct usb_otg_transceiver *self, uint8_t reg_addr, uint8_t *value);
static int lpc_otg_i2c_write(const struct usb_otg_transceiver *self, uint8_t reg_addr, uint8_t value);
__weak_symbol int
lpc_ohci_probe(int unit)
{
(void)unit;
return (BUS_PROBE_DEFAULT);
}
static int
lpc_ohci_probe(device_t dev)
lpc_ohci_do_probe(device_t dev)
{
device_set_desc(dev, "LPC32x0 USB OHCI controller");
return (BUS_PROBE_DEFAULT);
return (lpc_ohci_probe(device_get_unit(dev)));
}
static int
@ -473,7 +482,7 @@ lpc_ohci_resume(device_t dev)
static device_method_t lpc_ohci_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, lpc_ohci_probe),
DEVMETHOD(device_probe, lpc_ohci_do_probe),
DEVMETHOD(device_attach, lpc_ohci_attach),
DEVMETHOD(device_detach, lpc_ohci_detach),
DEVMETHOD(device_suspend, bus_generic_suspend),