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