aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_encoder_slave.c116
-rw-r--r--include/drm/drm_encoder_slave.h162
3 files changed, 279 insertions, 1 deletions
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index fe23f29f7cba..5f0aec4f082a 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -11,7 +11,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
11 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \ 11 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
12 drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \ 12 drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
13 drm_crtc.o drm_crtc_helper.o drm_modes.o drm_edid.o \ 13 drm_crtc.o drm_crtc_helper.o drm_modes.o drm_edid.o \
14 drm_info.o drm_debugfs.o 14 drm_info.o drm_debugfs.o drm_encoder_slave.o
15 15
16drm-$(CONFIG_COMPAT) += drm_ioc32.o 16drm-$(CONFIG_COMPAT) += drm_ioc32.o
17 17
diff --git a/drivers/gpu/drm/drm_encoder_slave.c b/drivers/gpu/drm/drm_encoder_slave.c
new file mode 100644
index 000000000000..6ffd600ccfae
--- /dev/null
+++ b/drivers/gpu/drm/drm_encoder_slave.c
@@ -0,0 +1,116 @@
1/*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#include <drm/drm_encoder_slave.h>
28
29/**
30 * drm_i2c_encoder_init - Initialize an I2C slave encoder
31 * @dev: DRM device.
32 * @encoder: Encoder to be attached to the I2C device. You aren't
33 * required to have called drm_encoder_init() before.
34 * @adap: I2C adapter that will be used to communicate with
35 * the device.
36 * @info: Information that will be used to create the I2C device.
37 * Required fields are @addr and @type.
38 *
39 * Create an I2C device on the specified bus (the module containing its
40 * driver is transparently loaded) and attach it to the specified
41 * &drm_encoder_slave. The @slave_funcs field will be initialized with
42 * the hooks provided by the slave driver.
43 *
44 * Returns 0 on success or a negative errno on failure, in particular,
45 * -ENODEV is returned when no matching driver is found.
46 */
47int drm_i2c_encoder_init(struct drm_device *dev,
48 struct drm_encoder_slave *encoder,
49 struct i2c_adapter *adap,
50 const struct i2c_board_info *info)
51{
52 char modalias[sizeof(I2C_MODULE_PREFIX)
53 + I2C_NAME_SIZE];
54 struct module *module = NULL;
55 struct i2c_client *client;
56 struct drm_i2c_encoder_driver *encoder_drv;
57 int err = 0;
58
59 snprintf(modalias, sizeof(modalias),
60 "%s%s", I2C_MODULE_PREFIX, info->type);
61 request_module(modalias);
62
63 client = i2c_new_device(adap, info);
64 if (!client) {
65 err = -ENOMEM;
66 goto fail;
67 }
68
69 if (!client->driver) {
70 err = -ENODEV;
71 goto fail_unregister;
72 }
73
74 module = client->driver->driver.owner;
75 if (!try_module_get(module)) {
76 err = -ENODEV;
77 goto fail_unregister;
78 }
79
80 encoder->bus_priv = client;
81
82 encoder_drv = to_drm_i2c_encoder_driver(client->driver);
83
84 err = encoder_drv->encoder_init(client, dev, encoder);
85 if (err)
86 goto fail_unregister;
87
88 return 0;
89
90fail_unregister:
91 i2c_unregister_device(client);
92 module_put(module);
93fail:
94 return err;
95}
96EXPORT_SYMBOL(drm_i2c_encoder_init);
97
98/**
99 * drm_i2c_encoder_destroy - Unregister the I2C device backing an encoder
100 * @drm_encoder: Encoder to be unregistered.
101 *
102 * This should be called from the @destroy method of an I2C slave
103 * encoder driver once I2C access is no longer needed.
104 */
105void drm_i2c_encoder_destroy(struct drm_encoder *drm_encoder)
106{
107 struct drm_encoder_slave *encoder = to_encoder_slave(drm_encoder);
108 struct i2c_client *client = drm_i2c_encoder_get_client(drm_encoder);
109 struct module *module = client->driver->driver.owner;
110
111 i2c_unregister_device(client);
112 encoder->bus_priv = NULL;
113
114 module_put(module);
115}
116EXPORT_SYMBOL(drm_i2c_encoder_destroy);
diff --git a/include/drm/drm_encoder_slave.h b/include/drm/drm_encoder_slave.h
new file mode 100644
index 000000000000..821ec40c17d8
--- /dev/null
+++ b/include/drm/drm_encoder_slave.h
@@ -0,0 +1,162 @@
1/*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#ifndef __DRM_ENCODER_SLAVE_H__
28#define __DRM_ENCODER_SLAVE_H__
29
30#include <drm/drmP.h>
31#include <drm/drm_crtc.h>
32
33/**
34 * struct drm_encoder_slave_funcs - Entry points exposed by a slave encoder driver
35 * @set_config: Initialize any encoder-specific modesetting parameters.
36 * The meaning of the @params parameter is implementation
37 * dependent. It will usually be a structure with DVO port
38 * data format settings or timings. It's not required for
39 * the new parameters to take effect until the next mode
40 * is set.
41 *
42 * Most of its members are analogous to the function pointers in
43 * &drm_encoder_helper_funcs and they can optionally be used to
44 * initialize the latter. Connector-like methods (e.g. @get_modes and
45 * @set_property) will typically be wrapped around and only be called
46 * if the encoder is the currently selected one for the connector.
47 */
48struct drm_encoder_slave_funcs {
49 void (*set_config)(struct drm_encoder *encoder,
50 void *params);
51
52 void (*destroy)(struct drm_encoder *encoder);
53 void (*dpms)(struct drm_encoder *encoder, int mode);
54 void (*save)(struct drm_encoder *encoder);
55 void (*restore)(struct drm_encoder *encoder);
56 bool (*mode_fixup)(struct drm_encoder *encoder,
57 struct drm_display_mode *mode,
58 struct drm_display_mode *adjusted_mode);
59 int (*mode_valid)(struct drm_encoder *encoder,
60 struct drm_display_mode *mode);
61 void (*mode_set)(struct drm_encoder *encoder,
62 struct drm_display_mode *mode,
63 struct drm_display_mode *adjusted_mode);
64
65 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
66 struct drm_connector *connector);
67 int (*get_modes)(struct drm_encoder *encoder,
68 struct drm_connector *connector);
69 int (*create_resources)(struct drm_encoder *encoder,
70 struct drm_connector *connector);
71 int (*set_property)(struct drm_encoder *encoder,
72 struct drm_connector *connector,
73 struct drm_property *property,
74 uint64_t val);
75
76};
77
78/**
79 * struct drm_encoder_slave - Slave encoder struct
80 * @base: DRM encoder object.
81 * @slave_funcs: Slave encoder callbacks.
82 * @slave_priv: Slave encoder private data.
83 * @bus_priv: Bus specific data.
84 *
85 * A &drm_encoder_slave has two sets of callbacks, @slave_funcs and the
86 * ones in @base. The former are never actually called by the common
87 * CRTC code, it's just a convenience for splitting the encoder
88 * functions in an upper, GPU-specific layer and a (hopefully)
89 * GPU-agnostic lower layer: It's the GPU driver responsibility to
90 * call the slave methods when appropriate.
91 *
92 * drm_i2c_encoder_init() provides a way to get an implementation of
93 * this.
94 */
95struct drm_encoder_slave {
96 struct drm_encoder base;
97
98 struct drm_encoder_slave_funcs *slave_funcs;
99 void *slave_priv;
100 void *bus_priv;
101};
102#define to_encoder_slave(x) container_of((x), struct drm_encoder_slave, base)
103
104int drm_i2c_encoder_init(struct drm_device *dev,
105 struct drm_encoder_slave *encoder,
106 struct i2c_adapter *adap,
107 const struct i2c_board_info *info);
108
109
110/**
111 * struct drm_i2c_encoder_driver
112 *
113 * Describes a device driver for an encoder connected to the GPU
114 * through an I2C bus. In addition to the entry points in @i2c_driver
115 * an @encoder_init function should be provided. It will be called to
116 * give the driver an opportunity to allocate any per-encoder data
117 * structures and to initialize the @slave_funcs and (optionally)
118 * @slave_priv members of @encoder.
119 */
120struct drm_i2c_encoder_driver {
121 struct i2c_driver i2c_driver;
122
123 int (*encoder_init)(struct i2c_client *client,
124 struct drm_device *dev,
125 struct drm_encoder_slave *encoder);
126
127};
128#define to_drm_i2c_encoder_driver(x) container_of((x), \
129 struct drm_i2c_encoder_driver, \
130 i2c_driver)
131
132/**
133 * drm_i2c_encoder_get_client - Get the I2C client corresponding to an encoder
134 */
135static inline struct i2c_client *drm_i2c_encoder_get_client(struct drm_encoder *encoder)
136{
137 return (struct i2c_client *)to_encoder_slave(encoder)->bus_priv;
138}
139
140/**
141 * drm_i2c_encoder_register - Register an I2C encoder driver
142 * @owner: Module containing the driver.
143 * @driver: Driver to be registered.
144 */
145static inline int drm_i2c_encoder_register(struct module *owner,
146 struct drm_i2c_encoder_driver *driver)
147{
148 return i2c_register_driver(owner, &driver->i2c_driver);
149}
150
151/**
152 * drm_i2c_encoder_unregister - Unregister an I2C encoder driver
153 * @driver: Driver to be unregistered.
154 */
155static inline void drm_i2c_encoder_unregister(struct drm_i2c_encoder_driver *driver)
156{
157 return i2c_del_driver(&driver->i2c_driver);
158}
159
160void drm_i2c_encoder_destroy(struct drm_encoder *encoder);
161
162#endif