Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
Vasily Khoruzhick | 82e9a5a | 2017-09-20 23:29:07 -0700 | [diff] [blame] | 10 | #include <edid.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 12 | #include <video_bridge.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 14 | |
| 15 | int video_bridge_set_backlight(struct udevice *dev, int percent) |
| 16 | { |
| 17 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
| 18 | |
| 19 | if (!ops->set_backlight) |
| 20 | return -ENOSYS; |
| 21 | |
| 22 | return ops->set_backlight(dev, percent); |
| 23 | } |
| 24 | |
| 25 | int video_bridge_attach(struct udevice *dev) |
| 26 | { |
| 27 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
| 28 | |
| 29 | if (!ops->attach) |
| 30 | return -ENOSYS; |
| 31 | |
| 32 | return ops->attach(dev); |
| 33 | } |
| 34 | |
| 35 | int video_bridge_check_attached(struct udevice *dev) |
| 36 | { |
| 37 | struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev); |
| 38 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
| 39 | int ret; |
| 40 | |
| 41 | if (!ops->check_attached) { |
| 42 | ret = dm_gpio_get_value(&uc_priv->hotplug); |
| 43 | |
| 44 | return ret > 0 ? 0 : ret == 0 ? -ENOTCONN : ret; |
| 45 | } |
| 46 | |
| 47 | return ops->check_attached(dev); |
| 48 | } |
| 49 | |
Vasily Khoruzhick | 82e9a5a | 2017-09-20 23:29:07 -0700 | [diff] [blame] | 50 | int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size) |
| 51 | { |
| 52 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
| 53 | |
| 54 | if (!ops || !ops->read_edid) |
| 55 | return -ENOSYS; |
| 56 | return ops->read_edid(dev, buf, buf_size); |
| 57 | } |
| 58 | |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 59 | static int video_bridge_pre_probe(struct udevice *dev) |
| 60 | { |
| 61 | struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev); |
| 62 | int ret; |
| 63 | |
| 64 | debug("%s\n", __func__); |
| 65 | ret = gpio_request_by_name(dev, "sleep-gpios", 0, |
| 66 | &uc_priv->sleep, GPIOD_IS_OUT); |
| 67 | if (ret) { |
| 68 | debug("%s: Could not decode sleep-gpios (%d)\n", __func__, ret); |
Simon Glass | 661d5de | 2016-01-21 19:44:53 -0700 | [diff] [blame] | 69 | if (ret != -ENOENT) |
| 70 | return ret; |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 71 | } |
Simon Glass | be72e33 | 2015-08-03 08:19:20 -0600 | [diff] [blame] | 72 | /* |
| 73 | * Drop this for now as we do not have driver model pinctrl support |
| 74 | * |
| 75 | * ret = dm_gpio_set_pull(&uc_priv->sleep, GPIO_PULL_NONE); |
| 76 | * if (ret) { |
| 77 | * debug("%s: Could not set sleep pull value\n", __func__); |
| 78 | * return ret; |
| 79 | * } |
| 80 | */ |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 81 | ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset, |
| 82 | GPIOD_IS_OUT); |
| 83 | if (ret) { |
| 84 | debug("%s: Could not decode reset-gpios (%d)\n", __func__, ret); |
Simon Glass | 661d5de | 2016-01-21 19:44:53 -0700 | [diff] [blame] | 85 | if (ret != -ENOENT) |
| 86 | return ret; |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 87 | } |
Simon Glass | be72e33 | 2015-08-03 08:19:20 -0600 | [diff] [blame] | 88 | /* |
| 89 | * Drop this for now as we do not have driver model pinctrl support |
| 90 | * |
| 91 | * ret = dm_gpio_set_pull(&uc_priv->reset, GPIO_PULL_NONE); |
| 92 | * if (ret) { |
| 93 | * debug("%s: Could not set reset pull value\n", __func__); |
| 94 | * return ret; |
| 95 | * } |
| 96 | */ |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 97 | ret = gpio_request_by_name(dev, "hotplug-gpios", 0, &uc_priv->hotplug, |
| 98 | GPIOD_IS_IN); |
Simon Glass | 661d5de | 2016-01-21 19:44:53 -0700 | [diff] [blame] | 99 | if (ret) { |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 100 | debug("%s: Could not decode hotplug (%d)\n", __func__, ret); |
Simon Glass | 661d5de | 2016-01-21 19:44:53 -0700 | [diff] [blame] | 101 | if (ret != -ENOENT) |
| 102 | return ret; |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | int video_bridge_set_active(struct udevice *dev, bool active) |
| 109 | { |
| 110 | struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev); |
Vasily Khoruzhick | e0b2260 | 2018-11-05 20:24:29 -0800 | [diff] [blame] | 111 | int ret = 0; |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 112 | |
| 113 | debug("%s: %d\n", __func__, active); |
Vasily Khoruzhick | e0b2260 | 2018-11-05 20:24:29 -0800 | [diff] [blame] | 114 | if (uc_priv->sleep.dev) { |
| 115 | ret = dm_gpio_set_value(&uc_priv->sleep, !active); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | if (!active) |
| 121 | return 0; |
| 122 | |
| 123 | if (uc_priv->reset.dev) { |
Simon Glass | 7cf1757 | 2015-07-02 18:16:08 -0600 | [diff] [blame] | 124 | ret = dm_gpio_set_value(&uc_priv->reset, true); |
| 125 | if (ret) |
| 126 | return ret; |
| 127 | udelay(10); |
| 128 | ret = dm_gpio_set_value(&uc_priv->reset, false); |
| 129 | } |
| 130 | |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | UCLASS_DRIVER(video_bridge) = { |
| 135 | .id = UCLASS_VIDEO_BRIDGE, |
| 136 | .name = "video_bridge", |
| 137 | .per_device_auto_alloc_size = sizeof(struct video_bridge_priv), |
| 138 | .pre_probe = video_bridge_pre_probe, |
| 139 | }; |