1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2024 The FreeBSD Foundation 5 * 6 * This software was developed by Mitchell Horne <mhorne@FreeBSD.org> under 7 * sponsorship from the FreeBSD Foundation. 8 */ 9 10 /* 11 * StarFive syscon driver. 12 * 13 * On the JH7110, the PLL clock driver is a child of the sys-syscon device. 14 * This needs to probe very early (BUS_PASS_BUS + BUS_PASS_ORDER_EARLY). 15 */ 16 17 #include <sys/param.h> 18 #include <sys/bus.h> 19 #include <sys/kernel.h> 20 #include <sys/module.h> 21 #include <sys/mutex.h> 22 23 #include <machine/bus.h> 24 25 #include <dev/ofw/openfirm.h> 26 #include <dev/ofw/ofw_bus.h> 27 #include <dev/ofw/ofw_bus_subr.h> 28 29 #include <dev/syscon/syscon.h> 30 #include <dev/syscon/syscon_generic.h> 31 32 #include <dev/fdt/simple_mfd.h> 33 34 enum starfive_syscon_type { 35 JH7110_SYSCON_SYS = 1, 36 JH7110_SYSCON_AON, 37 JH7110_SYSCON_STG, 38 }; 39 40 static struct ofw_compat_data compat_data[] = { 41 { "starfive,jh7110-sys-syscon", JH7110_SYSCON_SYS }, 42 { "starfive,jh7110-aon-syscon", JH7110_SYSCON_AON }, 43 { "starfive,jh7110-stg-syscon", JH7110_SYSCON_STG }, 44 45 { NULL, 0 } 46 }; 47 48 static int 49 starfive_syscon_probe(device_t dev) 50 { 51 enum starfive_syscon_type type; 52 53 if (!ofw_bus_status_okay(dev)) 54 return (ENXIO); 55 56 type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; 57 if (type == 0) 58 return (ENXIO); 59 60 switch (type) { 61 case JH7110_SYSCON_SYS: 62 device_set_desc(dev, "JH7110 SYS syscon"); 63 break; 64 case JH7110_SYSCON_AON: 65 device_set_desc(dev, "JH7110 AON syscon"); 66 break; 67 case JH7110_SYSCON_STG: 68 device_set_desc(dev, "JH7110 STG syscon"); 69 break; 70 } 71 72 return (BUS_PROBE_DEFAULT); 73 } 74 75 76 static device_method_t starfive_syscon_methods[] = { 77 DEVMETHOD(device_probe, starfive_syscon_probe), 78 79 DEVMETHOD_END 80 }; 81 82 DEFINE_CLASS_1(starfive_syscon, starfive_syscon_driver, starfive_syscon_methods, 83 sizeof(struct syscon_generic_softc), simple_mfd_driver); 84 85 EARLY_DRIVER_MODULE(starfive_syscon, simplebus, starfive_syscon_driver, 0, 0, 86 BUS_PASS_BUS + BUS_PASS_ORDER_EARLY); 87 MODULE_VERSION(starfive_syscon, 1); 88