Skip to content

Instantly share code, notes, and snippets.

@Scott31393
Last active April 15, 2022 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scott31393/5473e89617356e177dded25ade079147 to your computer and use it in GitHub Desktop.
Save Scott31393/5473e89617356e177dded25ade079147 to your computer and use it in GitHub Desktop.
U-Boot Drivers Coding Cheatsheet.md

U-Boot Coding Cheatsheet

Enable Debug log

define DEBUG before any include in the .c file

#define DEBUG
#undef CONFIG_LOGLEVEL
#define CONFIG_LOGLEVEL 7
#define LOG_DEBUG

#include <common.h>
#include <bmp_layout.h>
#include <dm.h>
#include <mapmem.h>
#include <splash.h>
#include <video.h>
#include <watchdog.h>
#include <asm/unaligned.h>
...

Usage: CONFIG_DM_GPIO (GPIO Driver Model)

dts-side:

rm67191_panel {
		compatible = "raydium,rm67191";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_mipi_dsi_en>;
		reset-gpio = <&gpio1 8 GPIO_ACTIVE_LOW>;
		dsi-lanes = <4>;
		video-mode = <2>;	/* 0: burst mode
					 * 1: non-burst mode with sync event
					 * 2: non-burst mode with sync pulse
					 */
		panel-width-mm = <68>;
		panel-height-mm = <121>;
		status = "okay";

		port {
			rm67191_from_dsim: endpoint {
				remote-endpoint = <&dsim_to_rm67191>;
			};
		};
	};

Driver side:

ret = gpio_request_by_name(dev, "reset-gpio", 0, &priv->reset,
				   GPIOD_IS_OUT);
	if (ret) {
		printf("Warning: cannot get reset GPIO\n");
		if (ret != -ENOENT)
			return ret;
	}

	/* reset panel */
	ret = dm_gpio_set_value(&priv->reset, true);
	if (ret)
		printf("reset gpio fails to set true\n");
	mdelay(100);
	ret = dm_gpio_set_value(&priv->reset, false);
	if (ret)
		printf("reset gpio fails to set true\n");
	mdelay(100);

	return 0;

Usage: get dts property value

dts-side:

rm67191_panel {
		compatible = "raydium,rm67191";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_mipi_dsi_en>;
		reset-gpio = <&gpio1 8 GPIO_ACTIVE_LOW>;
		dsi-lanes = <4>;
		video-mode = <2>;	/* 0: burst mode
					 * 1: non-burst mode with sync event
					 * 2: non-burst mode with sync pulse
					 */
		panel-width-mm = <68>;
		panel-height-mm = <121>;
		status = "okay";

		port {
			rm67191_from_dsim: endpoint {
				remote-endpoint = <&dsim_to_rm67191>;
			};
		};
	};

driver-side:

ret = dev_read_u32(dev, "video-mode", &video_mode);
if (!ret) {
	printf("property read\n");
}

Dump register

#include <asm/io.h>

	u32 val = readl(CCM_BASE_ADDR + 0xbb80);

	printk("KERN_ERR, DEBUG FUNC = %s, LINE = %d, reg = %x\n", __func__, __LINE__, val);
	writel(0x10040032, CCM_BASE_ADDR + 0xbb80);
	printk("KERN_ERR, DEBUG FUNC = %s, LINE = %d, reg = %x\n", __func__, __LINE__, val);

Call device using dts node label

backlight: lcd-backlight {
	status = "okay";
	compatible = "pwm-backlight";
	pwms = <&pwm1 0 5000000>;
	brightness-levels = <0 255>;
	num-interpolated-steps = <255>;
	default-brightness-level = <250>;
};	
struct udevice *backlight;


ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
					   "backlight", &priv->backlight);
if (ret) {
	debug("%s: Warning: cannot get backlight: ret=%d\n",
	      __func__, ret);
	if (ret != -ENOENT)
		return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment