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