FreeBSD/sys/dev/fdt/fdt_clock.c
/*
 * Loop through all the tuples in the clocks= property for a device, enabling or
 * disabling each clock.
 *
 * Be liberal about errors for now: warn about a failure to enable but keep
 * trying with any other clocks in the list.  Return ENXIO if any errors were
 * found, and let the caller decide whether the problem is fatal.
 */
Loop through all the tuples in the clocks= property for a device, enabling or
disabling each clock.

Be liberal about errors for now: warn about a failure to enable but keep
trying with any other clocks in the list.  Return ENXIO if any errors were
found, and let the caller decide whether the problem is fatal.
Loop through all the tuples in the clocks = property for a device enabling or disabling each clock . Be liberal about errors for now : warn about a failure to enable but keep trying with any other clocks in the list . Return ENXIO if any errors were found and let the caller decide whether the problem is fatal .
static int
enable_disable_all(device_t consumer, boolean_t enable)
{
	phandle_t cnode;
	device_t clockdev;
	int clocknum, err, i, ncells;
	uint32_t *clks;
	boolean_t anyerrors;
	cnode = ofw_bus_get_node(consumer);
	ncells = OF_getencprop_alloc(cnode, "clocks", sizeof(*clks),
	    (void **)&clks);
	if (enable && ncells < 2) {
		device_printf(consumer, "Warning: No clocks specified in fdt "
		    "data; device may not function.");
		return (ENXIO);
	}
	anyerrors = false;
	for (i = 0; i < ncells; i += 2) {
		clockdev = OF_device_from_xref(clks[i]);
		clocknum = clks[i + 1];
		if (clockdev == NULL) {
			if (enable)
				device_printf(consumer, "Warning: can not find "
				    "driver for clock number %u; device may not "
				    "function\n", clocknum);
			anyerrors = true;
			continue;
		}
		if (enable)
			err = FDT_CLOCK_ENABLE(clockdev, clocknum);
		else
			err = FDT_CLOCK_DISABLE(clockdev, clocknum);
		if (err != 0) {
			if (enable)
				device_printf(consumer, "Warning: failed to "
				    "enable clock number %u; device may not "
				    "function\n", clocknum);
			anyerrors = true;
		}
	}
	OF_prop_free(clks);
	return (anyerrors ? ENXIO : 0);
}
static int enable_disable_all ( device_t consumer , boolean_t enable ) { phandle_t cnode ; device_t clockdev ; int clocknum , err , i , ncells ; uint32_t * clks ; boolean_t anyerrors ; cnode = ofw_bus_get_node ( consumer ) ; ncells = OF_getencprop_alloc ( cnode , " " , sizeof ( * clks ) , ( void * * ) & clks ) ; if ( enable && ncells < 2 ) { device_printf ( consumer , " " " " ) ; return ( ENXIO ) ; } anyerrors = false ; for ( i = 0 ; i < ncells ; i += 2 ) { clockdev = OF_device_from_xref ( clks [ i ] ) ; clocknum = clks [ i + 1 ] ; if ( clockdev == NULL ) { if ( enable ) device_printf ( consumer , " " " " " \n " , clocknum ) ; anyerrors = true ; continue ; } if ( enable ) err = FDT_CLOCK_ENABLE ( clockdev , clocknum ) ; else err = FDT_CLOCK_DISABLE ( clockdev , clocknum ) ; if ( err != 0 ) { if ( enable ) device_printf ( consumer , " " " " " \n " , clocknum ) ; anyerrors = true ; } } OF_prop_free ( clks ) ; return ( anyerrors ? ENXIO : 0 ) ; }
Loop through all the tuples in the clocks= property for a device, enabling or
 disabling each clock.
Loop through all the tuples in the clocks = property for a device enabling or disabling each clock .