Пример #1
0
int sata_remove(int devnum)
{
#ifdef CONFIG_AHCI
	struct udevice *dev;
	int rc;

	rc = uclass_find_device(UCLASS_AHCI, devnum, &dev);
	if (!rc && !dev)
		rc = uclass_find_first_device(UCLASS_AHCI, &dev);
	if (rc || !dev) {
		printf("Cannot find SATA device %d (err=%d)\n", devnum, rc);
		return CMD_RET_FAILURE;
	}

	rc = device_remove(dev, DM_REMOVE_NORMAL);
	if (rc) {
		printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name,
		       rc);
		return CMD_RET_FAILURE;
	}

	return 0;
#else
	return sata_stop();
#endif
}
Пример #2
0
static int qemu_cpu_fixup(void)
{
	int ret;
	int cpu_num;
	int cpu_online;
	struct udevice *dev, *pdev;
	struct cpu_platdata *plat;
	char *cpu;

	/* first we need to find '/cpus' */
	for (device_find_first_child(dm_root(), &pdev);
	     pdev;
	     device_find_next_child(&pdev)) {
		if (!strcmp(pdev->name, "cpus"))
			break;
	}
	if (!pdev) {
		printf("unable to find cpus device\n");
		return -ENODEV;
	}

	/* calculate cpus that are already bound */
	cpu_num = 0;
	for (uclass_find_first_device(UCLASS_CPU, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		cpu_num++;
	}

	/* get actual cpu number */
	cpu_online = qemu_fwcfg_online_cpus();
	if (cpu_online < 0) {
		printf("unable to get online cpu number: %d\n", cpu_online);
		return cpu_online;
	}

	/* bind addtional cpus */
	dev = NULL;
	for (; cpu_num < cpu_online; cpu_num++) {
		/*
		 * allocate device name here as device_bind_driver() does
		 * not copy device name, 8 bytes are enough for
		 * sizeof("cpu@") + 3 digits cpu number + '\0'
		 */
		cpu = malloc(8);
		if (!cpu) {
			printf("unable to allocate device name\n");
			return -ENOMEM;
		}
		sprintf(cpu, "cpu@%d", cpu_num);
		ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev);
		if (ret) {
			printf("binding cpu@%d failed: %d\n", cpu_num, ret);
			return ret;
		}
		plat = dev_get_parent_platdata(dev);
		plat->cpu_id = cpu_num;
	}
	return 0;
}
Пример #3
0
static inline bool supports_extension(char ext)
{
#ifdef CONFIG_CPU
	struct udevice *dev;
	char desc[32];

	uclass_find_first_device(UCLASS_CPU, &dev);
	if (!dev) {
		debug("unable to find the RISC-V cpu device\n");
		return false;
	}
	if (!cpu_get_desc(dev, desc, sizeof(desc))) {
		/* skip the first 4 characters (rv32|rv64) */
		if (strchr(desc + 4, ext))
			return true;
	}

	return false;
#else  /* !CONFIG_CPU */
#ifdef CONFIG_RISCV_MMODE
	return csr_read(misa) & (1 << (ext - 'a'));
#else  /* !CONFIG_RISCV_MMODE */
#warning "There is no way to determine the available extensions in S-mode."
#warning "Please convert your board to use the RISC-V CPU driver."
	return false;
#endif /* CONFIG_RISCV_MMODE */
#endif /* CONFIG_CPU */
}
Пример #4
0
/* Test that binding with uclass platdata allocation occurs correctly */
static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
{
	struct dm_test_perdev_uc_pdata *uc_pdata;
	struct udevice *dev;
	struct uclass *uc;

	ut_assertok(uclass_get(UCLASS_TEST, &uc));
	ut_assert(uc);

	/**
	 * Test if test uclass driver requires allocation for the uclass
	 * platform data and then check the dev->uclass_platdata pointer.
	 */
	ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size);

	for (uclass_find_first_device(UCLASS_TEST, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		ut_assert(dev);

		uc_pdata = dev_get_uclass_platdata(dev);
		ut_assert(uc_pdata);
	}

	return 0;
}
Пример #5
0
static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts)
{
	struct udevice *finddev;
	struct udevice *testdev;
	int findret, ret;

	/*
	 * For each test device found in fdt like: "a-test", "b-test", etc.,
	 * use its name and try to find it by uclass_find_device_by_name().
	 * Then, on success check if:
	 * - current 'testdev' name is equal to the returned 'finddev' name
	 * - current 'testdev' pointer is equal to the returned 'finddev'
	 *
	 * We assume that, each uclass's device name is unique, so if not, then
	 * this will fail on checking condition: testdev == finddev, since the
	 * uclass_find_device_by_name(), returns the first device by given name.
	*/
	for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev);
	     testdev;
	     ret = uclass_find_next_device(&testdev)) {
		ut_assertok(ret);
		ut_assert(testdev);

		findret = uclass_find_device_by_name(UCLASS_TEST_FDT,
						     testdev->name,
						     &finddev);

		ut_assertok(findret);
		ut_assert(testdev);
		ut_asserteq_str(testdev->name, finddev->name);
		ut_asserteq_ptr(testdev, finddev);
	}

	return 0;
}
Пример #6
0
void video_sync_all(void)
{
	struct udevice *dev;

	for (uclass_find_first_device(UCLASS_VIDEO, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		if (device_active(dev))
			video_sync(dev);
	}
}
Пример #7
0
static int dm_test_uclass_devices_find(struct unit_test_state *uts)
{
	struct udevice *dev;
	int ret;

	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
	     dev;
	     ret = uclass_find_next_device(&dev)) {
		ut_assert(!ret);
		ut_assert(dev);
	}

	return 0;
}
Пример #8
0
unsigned long acpi_create_madt_lapics(unsigned long current)
{
	struct udevice *dev;

	for (uclass_find_first_device(UCLASS_CPU, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		struct cpu_platdata *plat = dev_get_parent_platdata(dev);

		current += acpi_create_madt_lapic(
			(struct acpi_madt_lapic *)current,
			plat->cpu_id, plat->cpu_id);
		}
		return current;
}
Пример #9
0
static int find_cpu_by_apid_id(int apic_id, struct udevice **devp)
{
	struct udevice *dev;

	*devp = NULL;
	for (uclass_find_first_device(UCLASS_CPU, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		struct cpu_platdata *plat = dev_get_parent_platdata(dev);

		if (plat->cpu_id == apic_id) {
			*devp = dev;
			return 0;
		}
	}

	return -ENOENT;
}
Пример #10
0
int acpi_create_madt_lapics(u32 current)
{
	struct udevice *dev;
	int total_length = 0;

	for (uclass_find_first_device(UCLASS_CPU, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		struct cpu_platdata *plat = dev_get_parent_platdata(dev);
		int length = acpi_create_madt_lapic(
				(struct acpi_madt_lapic *)current,
				plat->cpu_id, plat->cpu_id);
		current += length;
		total_length += length;
	}

	return total_length;
}
Пример #11
0
int video_reserve(ulong *addrp)
{
	struct udevice *dev;
	ulong size;

	gd->video_top = *addrp;
	for (uclass_find_first_device(UCLASS_VIDEO, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		size = alloc_fb(dev, addrp);
		debug("%s: Reserving %lx bytes at %lx for video device '%s'\n",
		      __func__, size, *addrp, dev->name);
	}
	gd->video_bottom = *addrp;
	debug("Video frame buffers from %lx to %lx\n", gd->video_bottom,
	      gd->video_top);

	return 0;
}
Пример #12
0
static int init_plic(void)
{
	struct udevice *dev;
	int ret;

	ret = uclass_find_first_device(UCLASS_CPU, &dev);
	if (ret)
		return ret;

	if (ret == 0 && dev) {
		ret = cpu_get_count(dev);
		if (ret < 0)
			return ret;

		enable_ipi(ret);
		return 0;
	}

	return -ENODEV;
}
Пример #13
0
void acpi_create_gnvs(struct acpi_global_nvs *gnvs)
{
	struct udevice *dev;
	int ret;

	/* at least we have one processor */
	gnvs->pcnt = 1;
	/* override the processor count with actual number */
	ret = uclass_find_first_device(UCLASS_CPU, &dev);
	if (ret == 0 && dev != NULL) {
		ret = cpu_get_count(dev);
		if (ret > 0)
			gnvs->pcnt = ret;
	}

	/* determine whether internal uart is on */
	if (IS_ENABLED(CONFIG_INTERNAL_UART))
		gnvs->iuart_en = 1;
	else
		gnvs->iuart_en = 0;
}
Пример #14
0
/**
 * for_each_remoteproc_device() - iterate through the list of rproc devices
 * @fn: check function to call per match, if this function returns fail,
 *	iteration is aborted with the resultant error value
 * @skip_dev:	Device to skip calling the callback about.
 * @data:	Data to pass to the callback function
 *
 * Return: 0 if none of the callback returned a non 0 result, else returns the
 * result from the callback function
 */
static int for_each_remoteproc_device(int (*fn) (struct udevice *dev,
					struct dm_rproc_uclass_pdata *uc_pdata,
					const void *data),
				      struct udevice *skip_dev,
				      const void *data)
{
	struct udevice *dev;
	struct dm_rproc_uclass_pdata *uc_pdata;
	int ret;

	for (ret = uclass_find_first_device(UCLASS_REMOTEPROC, &dev); dev;
	     ret = uclass_find_next_device(&dev)) {
		if (ret || dev == skip_dev)
			continue;
		uc_pdata = dev_get_uclass_platdata(dev);
		ret = fn(dev, uc_pdata, data);
		if (ret)
			return ret;
	}

	return 0;
}
Пример #15
0
/* Test that binding with uclass platdata setting occurs correctly */
static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
{
	struct dm_test_perdev_uc_pdata *uc_pdata;
	struct udevice *dev;

	/**
	 * In the test_postbind() method of test uclass driver, the uclass
	 * platform data should be set to three test int values - test it.
	 */
	for (uclass_find_first_device(UCLASS_TEST, &dev);
	     dev;
	     uclass_find_next_device(&dev)) {
		ut_assert(dev);

		uc_pdata = dev_get_uclass_platdata(dev);
		ut_assert(uc_pdata);
		ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1);
		ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2);
		ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3);
	}

	return 0;
}
Пример #16
0
int sata_probe(int devnum)
{
#ifdef CONFIG_AHCI
	struct udevice *dev;
	int rc;

	rc = uclass_get_device(UCLASS_AHCI, devnum, &dev);
	if (rc)
		rc = uclass_find_first_device(UCLASS_AHCI, &dev);
	if (rc) {
		printf("Cannot probe SATA device %d (err=%d)\n", devnum, rc);
		return CMD_RET_FAILURE;
	}
	rc = sata_scan(dev);
	if (rc) {
		printf("Cannot scan SATA device %d (err=%d)\n", devnum, rc);
		return CMD_RET_FAILURE;
	}

	return 0;
#else
	return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
#endif
}
Пример #17
0
int board_init(void)
{
	const char *rev_str;
#ifdef CONFIG_CMD_NAND
	int ret;
#endif

	at91_periph_clk_enable(ATMEL_ID_PIOA);
	at91_periph_clk_enable(ATMEL_ID_PIOB);
	at91_periph_clk_enable(ATMEL_ID_PIOC);
	at91_periph_clk_enable(ATMEL_ID_PIODE);

	at91sam9g45_slowclock_init();

	/*
	 * Clear the RTC IDR to disable all IRQs. Avoid issues when Linux
	 * boots with spurious IRQs.
	 */
	writel(0xffffffff, AT91_RTC_IDR);

	/* Make sure that the reset signal is attached properly */
	setbits_le32(AT91_ASM_RSTC_MR, AT91_RSTC_KEY | AT91_RSTC_MR_URSTEN);

	gd->bd->bi_arch_number = MACH_TYPE_SNAPPER_9260;

	/* Address of boot parameters */
	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;

#ifdef CONFIG_CMD_NAND
	ret = gurnard_nand_hw_init();
	if (ret)
		return ret;
#endif
#ifdef CONFIG_ATMEL_SPI
	at91_spi0_hw_init(1 << 4);
#endif

#ifdef CONFIG_MACB
	gurnard_macb_hw_init();
#endif

#ifdef CONFIG_GURNARD_FPGA
	fpga_hw_init();
#endif

#ifdef CONFIG_CMD_USB
	gurnard_usb_init();
#endif

#ifdef CONFIG_CMD_MMC
	at91_set_A_periph(AT91_PIN_PA12, 0);
	at91_set_gpio_output(AT91_PIN_PA8, 1);
	at91_set_gpio_value(AT91_PIN_PA8, 0);
	at91_mci_hw_init();
#endif

#ifdef CONFIG_DM_VIDEO
	at91sam9g45_lcd_hw_init();
	at91_set_A_periph(AT91_PIN_PE6, 1);	/* power up */

	/* Select the second timing index for board rev 2 */
	rev_str = getenv("board_rev");
	if (rev_str && !strncmp(rev_str, "2", 1)) {
		struct udevice *dev;

		uclass_find_first_device(UCLASS_VIDEO, &dev);
		if (dev) {
			struct atmel_lcd_platdata *plat = dev_get_platdata(dev);

			plat->timing_index = 1;
		}
	}
#endif

	return 0;
}
Пример #18
0
static int display_init(struct udevice *dev, void *lcdbase,
			int fb_bits_per_pixel, struct display_timing *timing)
{
	struct display_plat *disp_uc_plat;
	struct dc_ctlr *dc_ctlr;
	struct udevice *dp_dev;
	const int href_to_sync = 1, vref_to_sync = 1;
	int panel_bpp = 18;	/* default 18 bits per pixel */
	u32 plld_rate;
	int ret;

	/*
	 * Before we probe the display device (eDP), tell it that this device
	 * is the source of the display data.
	 */
	ret = uclass_find_first_device(UCLASS_DISPLAY, &dp_dev);
	if (ret) {
		debug("%s: device '%s' display not found (ret=%d)\n", __func__,
		      dev->name, ret);
		return ret;
	}

	disp_uc_plat = dev_get_uclass_platdata(dp_dev);
	debug("Found device '%s', disp_uc_priv=%p\n", dp_dev->name,
	      disp_uc_plat);
	disp_uc_plat->src_dev = dev;

	ret = uclass_get_device(UCLASS_DISPLAY, 0, &dp_dev);
	if (ret) {
		debug("%s: Failed to probe eDP, ret=%d\n", __func__, ret);
		return ret;
	}

	dc_ctlr = (struct dc_ctlr *)dev_read_addr(dev);
	if (ofnode_decode_display_timing(dev_ofnode(dev), 0, timing)) {
		debug("%s: Failed to decode display timing\n", __func__);
		return -EINVAL;
	}

	ret = display_update_config_from_edid(dp_dev, &panel_bpp, timing);
	if (ret) {
		debug("%s: Failed to decode EDID, using defaults\n", __func__);
		dump_config(panel_bpp, timing);
	}

	/*
	 * The plld is programmed with the assumption of the SHIFT_CLK_DIVIDER
	 * and PIXEL_CLK_DIVIDER are zero (divide by 1). See the
	 * update_display_mode() for detail.
	 */
	plld_rate = clock_set_display_rate(timing->pixelclock.typ * 2);
	if (plld_rate == 0) {
		printf("dc: clock init failed\n");
		return -EIO;
	} else if (plld_rate != timing->pixelclock.typ * 2) {
		debug("dc: plld rounded to %u\n", plld_rate);
		timing->pixelclock.typ = plld_rate / 2;
	}

	/* Init dc */
	ret = tegra_dc_init(dc_ctlr);
	if (ret) {
		debug("dc: init failed\n");
		return ret;
	}

	/* Configure dc mode */
	ret = update_display_mode(dc_ctlr, timing, href_to_sync, vref_to_sync);
	if (ret) {
		debug("dc: failed to configure display mode\n");
		return ret;
	}

	/* Enable dp */
	ret = display_enable(dp_dev, panel_bpp, timing);
	if (ret) {
		debug("dc: failed to enable display: ret=%d\n", ret);
		return ret;
	}

	ret = update_window(dc_ctlr, (ulong)lcdbase, fb_bits_per_pixel, timing);
	if (ret) {
		debug("dc: failed to update window\n");
		return ret;
	}
	debug("%s: ready\n", __func__);

	return 0;
}