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