Linux sysfs实现hdmi开关,平台是全志A10 Android4.0
linux-3.0/drivers/video/sun4i/disp/dev_disp.c
static ssize_t show_hdmi_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", suspend_status & 1 ? "off":"on");
}
static ssize_t set_hdmi_ctrl(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
unsigned long val = 0;
if (count = 0)
return 0;
val = simple_strtoul(buf, NULL, 0);
/*
* sscanf用于解析echo 0x00,0x2 > hdmi_ctrl这类命令。
* sscanf(buf, "%d,%d", &i2c_reg,&i2c_data);
*/
if (val)
backlight_early_suspend(NULL);
else
backlight_late_resume(NULL);
return count;
}
static DEVICE_ATTR(hdmictrl, S_IRUGO | S_IWUSR, show_hdmi_ctrl, set_hdmion_ctrl);
static struct attribute *dev_attrs[] = {
&dev_attr_hdmion.attr,
NULL,
};
static struct attribute_group dev_attr_grp = {
.attrs = dev_attrs,
};
static int __init disp_probe(struct platform_device *pdev)//called when platform_driver_register
{
int err = 0;
sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp);
err = sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp);
if (err 0)
{
printk("disp : sysfs_create_group err\n");
return err;
}
return 0;
}
static int disp_remove(struct platform_device *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &dev_attr_grp);
return 0;
}
HDMI关:echo 1 > /sys/devices/platform/disp/hdmi_ctrl
HDMI开:echo 0 > /sys/devices/platform/disp/hdmi_ctrl