summaryrefslogtreecommitdiff
path: root/drivers/video/fbdev/mxc/hannstar_cabc.c
blob: 14528c8c6511875a37fbd400a2858c016f70e93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (C) 2014-2015 Freescale Semiconductor, Inc. All Rights Reserved.
 *
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

#include <linux/device.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>

#define DRIVER_NAME "hannstar-cabc"

static const struct of_device_id cabc_dt_ids[] = {
	{ .compatible = "hannstar,cabc", },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, cabc_dt_ids);

static int cabc_probe(struct platform_device *pdev)
{
	struct device_node *np = pdev->dev.of_node, *pp;
	int cabc_gpio, ret = 0;
	bool cabc_enable;
	unsigned long gpio_flag;
	enum of_gpio_flags flags;

	for_each_child_of_node(np, pp) {
		if (!of_find_property(pp, "gpios", NULL)) {
			dev_warn(&pdev->dev, "Found interface without "
				 "gpios\n");
			continue;
		}

		cabc_gpio = of_get_gpio_flags(pp, 0, &flags);
		if (!gpio_is_valid(cabc_gpio)) {
			ret = cabc_gpio;
			if (ret != -EPROBE_DEFER)
				dev_err(&pdev->dev,
					"Failed to get gpio flags, "
					"error: %d\n", ret);
			return ret;
		}

		cabc_enable = of_property_read_bool(pp, "cabc-enable");

		if (flags & OF_GPIO_ACTIVE_LOW)
			gpio_flag = cabc_enable ?
				GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH;
		else
			gpio_flag = cabc_enable ?
				GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;

		devm_gpio_request_one(&pdev->dev, cabc_gpio,
					gpio_flag, "hannstar-cabc");
	}

	return ret;
}

static struct platform_driver cabc_driver = {
	.probe	= cabc_probe,
	.driver = {
		.of_match_table = cabc_dt_ids,
		.name	= DRIVER_NAME,
		.owner	= THIS_MODULE,
	},
};
module_platform_driver(cabc_driver);

MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("Hannstar CABC driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRIVER_NAME);