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