驱动部分:
u-boot/drivers/video/drm/gpio_init.c
/*
* (C) Copyright 2008-2017 Fuzhou Rockchip Electronics Co., Ltd
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <config.h>
#include <common.h>
#include <errno.h>
#include <malloc.h>
#include <video.h>
#include <backlight.h>
#include <asm/gpio.h>
#include <dm/device.h>
#include <dm/read.h>
#include <dm/uclass.h>
#include <dm/uclass-id.h>
#include <linux/media-bus-format.h>
#include <power/regulator.h>
//DECLARE_GLOBAL_DATA_PTR;
struct customer_gpio_priv {
struct udevice *reg;
struct gpio_desc wifi_power_gpio;
struct gpio_desc usb_switch_gpio;
struct gpio_desc usb_switch_gpio2;
struct gpio_desc wifi_power_gpio_01;
struct gpio_desc power_led_ctrl;
uint default_level;
uint min_level;
uint max_level;
};
static int customer_gpio_ofdata_to_platdata(struct udevice *dev)
{
printf("##fan##%s\n",__func__);
return 0;
}
static int customer_gpio_probe(struct udevice *dev)
{
int ret;
// struct gpio_desc reset_gpio;
struct customer_gpio_priv *priv = dev_get_priv(dev);
ret = gpio_request_by_name(dev, "usb-switch2", 0,&priv->usb_switch_gpio2, GPIOD_IS_OUT);
if (ret && ret != -ENOENT) {
printf("%s: Cannot get usb-switch2: %d\n", __func__, ret);
return ret;
}
printf("####set gpio switch gpio2 low\n");
dm_gpio_set_value(&priv->usb_switch_gpio2, 0);
ret = gpio_request_by_name(dev, "wifi-gpios", 0,
&priv->wifi_power_gpio, GPIOD_IS_OUT);
if (ret && ret != -ENOENT) {
printf("%s: Cannot get wifi GPIO: %d\n", __func__, ret);
return ret;
}
ret = gpio_request_by_name(dev, "usb-switch", 0,&priv->usb_switch_gpio, GPIOD_IS_OUT);
if (ret && ret != -ENOENT) {
printf("%s: Cannot get usb-switch11: %d\n", __func__, ret);
return ret;
}
ret = gpio_request_by_name(dev, "power-led-ctl", 0,&priv->power_led_ctrl, GPIOD_IS_OUT);
if (ret && ret != -ENOENT) {
printf("%s: Cannot get power led ctrl GPIO: %d\n", __func__, ret);
return ret;
}
dm_gpio_set_value(&priv->usb_switch_gpio, 0);
printf("%s: usb-switch---0h:\n", __func__);
mdelay(50);
dm_gpio_set_value(&priv->usb_switch_gpio, 1);
printf("%s: usb-switch---1h:\n", __func__);
dm_gpio_set_value(&priv->wifi_power_gpio, 1);
// dm_gpio_set_value(&priv->wifi_power_gpio_01, 1);
mdelay(50);
dm_gpio_set_value(&priv->wifi_power_gpio, 0);
dm_gpio_set_value(&priv->power_led_ctrl, 1);
return 0;
}
static const struct udevice_id customer_gpio_ids[] = {
//{ .compatible = "mmc-pwrseq-simple"},
{ .compatible = "customer-gpio-init", },
{}
};
U_BOOT_DRIVER(customer_gpio) = {
.name = "customer_gpio",
.id = UCLASS_CUSTOMER_GPIO, // 跟下面定义对应
.of_match = customer_gpio_ids,
.ofdata_to_platdata = customer_gpio_ofdata_to_platdata,
.probe = customer_gpio_probe,
.priv_auto_alloc_size = sizeof(struct customer_gpio_priv),
// .platdata_auto_alloc_size = sizeof(struct customer_gpio_priv),
};
u-boot/drivers/video/drm/Makefile 让驱动编译进来
u-boot/include/dm/uclass-id.h 这个匹配驱动中的.id