1aee94f86SFrançois Tigeot /* 2aee94f86SFrançois Tigeot * Copyright (C) 2009 Francisco Jerez. 3aee94f86SFrançois Tigeot * All Rights Reserved. 4aee94f86SFrançois Tigeot * 5aee94f86SFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining 6aee94f86SFrançois Tigeot * a copy of this software and associated documentation files (the 7aee94f86SFrançois Tigeot * "Software"), to deal in the Software without restriction, including 8aee94f86SFrançois Tigeot * without limitation the rights to use, copy, modify, merge, publish, 9aee94f86SFrançois Tigeot * distribute, sublicense, and/or sell copies of the Software, and to 10aee94f86SFrançois Tigeot * permit persons to whom the Software is furnished to do so, subject to 11aee94f86SFrançois Tigeot * the following conditions: 12aee94f86SFrançois Tigeot * 13aee94f86SFrançois Tigeot * The above copyright notice and this permission notice (including the 14aee94f86SFrançois Tigeot * next paragraph) shall be included in all copies or substantial 15aee94f86SFrançois Tigeot * portions of the Software. 16aee94f86SFrançois Tigeot * 17aee94f86SFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18aee94f86SFrançois Tigeot * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19aee94f86SFrançois Tigeot * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20aee94f86SFrançois Tigeot * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 21aee94f86SFrançois Tigeot * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22aee94f86SFrançois Tigeot * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23aee94f86SFrançois Tigeot * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24aee94f86SFrançois Tigeot * 25aee94f86SFrançois Tigeot */ 26aee94f86SFrançois Tigeot 27aee94f86SFrançois Tigeot #include <linux/module.h> 28aee94f86SFrançois Tigeot 29aee94f86SFrançois Tigeot #include <drm/drm_encoder_slave.h> 30aee94f86SFrançois Tigeot 31aee94f86SFrançois Tigeot #if 0 32aee94f86SFrançois Tigeot /** 33aee94f86SFrançois Tigeot * drm_i2c_encoder_init - Initialize an I2C slave encoder 34aee94f86SFrançois Tigeot * @dev: DRM device. 35aee94f86SFrançois Tigeot * @encoder: Encoder to be attached to the I2C device. You aren't 36aee94f86SFrançois Tigeot * required to have called drm_encoder_init() before. 37aee94f86SFrançois Tigeot * @adap: I2C adapter that will be used to communicate with 38aee94f86SFrançois Tigeot * the device. 39aee94f86SFrançois Tigeot * @info: Information that will be used to create the I2C device. 40aee94f86SFrançois Tigeot * Required fields are @addr and @type. 41aee94f86SFrançois Tigeot * 42aee94f86SFrançois Tigeot * Create an I2C device on the specified bus (the module containing its 43aee94f86SFrançois Tigeot * driver is transparently loaded) and attach it to the specified 44aee94f86SFrançois Tigeot * &drm_encoder_slave. The @slave_funcs field will be initialized with 45aee94f86SFrançois Tigeot * the hooks provided by the slave driver. 46aee94f86SFrançois Tigeot * 47aee94f86SFrançois Tigeot * If @info->platform_data is non-NULL it will be used as the initial 48aee94f86SFrançois Tigeot * slave config. 49aee94f86SFrançois Tigeot * 50aee94f86SFrançois Tigeot * Returns 0 on success or a negative errno on failure, in particular, 51aee94f86SFrançois Tigeot * -ENODEV is returned when no matching driver is found. 52aee94f86SFrançois Tigeot */ 53aee94f86SFrançois Tigeot int drm_i2c_encoder_init(struct drm_device *dev, 54aee94f86SFrançois Tigeot struct drm_encoder_slave *encoder, 55aee94f86SFrançois Tigeot struct i2c_adapter *adap, 56aee94f86SFrançois Tigeot const struct i2c_board_info *info) 57aee94f86SFrançois Tigeot { 58aee94f86SFrançois Tigeot struct module *module = NULL; 59aee94f86SFrançois Tigeot struct i2c_client *client; 60aee94f86SFrançois Tigeot struct drm_i2c_encoder_driver *encoder_drv; 61aee94f86SFrançois Tigeot int err = 0; 62aee94f86SFrançois Tigeot 63aee94f86SFrançois Tigeot request_module("%s%s", I2C_MODULE_PREFIX, info->type); 64aee94f86SFrançois Tigeot 65aee94f86SFrançois Tigeot client = i2c_new_device(adap, info); 66aee94f86SFrançois Tigeot if (!client) { 67aee94f86SFrançois Tigeot err = -ENOMEM; 68aee94f86SFrançois Tigeot goto fail; 69aee94f86SFrançois Tigeot } 70aee94f86SFrançois Tigeot 71aee94f86SFrançois Tigeot if (!client->dev.driver) { 72aee94f86SFrançois Tigeot err = -ENODEV; 73aee94f86SFrançois Tigeot goto fail_unregister; 74aee94f86SFrançois Tigeot } 75aee94f86SFrançois Tigeot 76aee94f86SFrançois Tigeot module = client->dev.driver->owner; 77aee94f86SFrançois Tigeot if (!try_module_get(module)) { 78aee94f86SFrançois Tigeot err = -ENODEV; 79aee94f86SFrançois Tigeot goto fail_unregister; 80aee94f86SFrançois Tigeot } 81aee94f86SFrançois Tigeot 82aee94f86SFrançois Tigeot encoder->bus_priv = client; 83aee94f86SFrançois Tigeot 84aee94f86SFrançois Tigeot encoder_drv = to_drm_i2c_encoder_driver(to_i2c_driver(client->dev.driver)); 85aee94f86SFrançois Tigeot 86aee94f86SFrançois Tigeot err = encoder_drv->encoder_init(client, dev, encoder); 87aee94f86SFrançois Tigeot if (err) 88aee94f86SFrançois Tigeot goto fail_unregister; 89aee94f86SFrançois Tigeot 90aee94f86SFrançois Tigeot if (info->platform_data) 91aee94f86SFrançois Tigeot encoder->slave_funcs->set_config(&encoder->base, 92aee94f86SFrançois Tigeot info->platform_data); 93aee94f86SFrançois Tigeot 94aee94f86SFrançois Tigeot return 0; 95aee94f86SFrançois Tigeot 96aee94f86SFrançois Tigeot fail_unregister: 97aee94f86SFrançois Tigeot i2c_unregister_device(client); 98aee94f86SFrançois Tigeot module_put(module); 99aee94f86SFrançois Tigeot fail: 100aee94f86SFrançois Tigeot return err; 101aee94f86SFrançois Tigeot } 102aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_init); 103aee94f86SFrançois Tigeot 104aee94f86SFrançois Tigeot /** 105aee94f86SFrançois Tigeot * drm_i2c_encoder_destroy - Unregister the I2C device backing an encoder 106aee94f86SFrançois Tigeot * @drm_encoder: Encoder to be unregistered. 107aee94f86SFrançois Tigeot * 108aee94f86SFrançois Tigeot * This should be called from the @destroy method of an I2C slave 109aee94f86SFrançois Tigeot * encoder driver once I2C access is no longer needed. 110aee94f86SFrançois Tigeot */ 111aee94f86SFrançois Tigeot void drm_i2c_encoder_destroy(struct drm_encoder *drm_encoder) 112aee94f86SFrançois Tigeot { 113aee94f86SFrançois Tigeot struct drm_encoder_slave *encoder = to_encoder_slave(drm_encoder); 114aee94f86SFrançois Tigeot struct i2c_client *client = drm_i2c_encoder_get_client(drm_encoder); 115aee94f86SFrançois Tigeot struct module *module = client->dev.driver->owner; 116aee94f86SFrançois Tigeot 117aee94f86SFrançois Tigeot i2c_unregister_device(client); 118aee94f86SFrançois Tigeot encoder->bus_priv = NULL; 119aee94f86SFrançois Tigeot 120aee94f86SFrançois Tigeot module_put(module); 121aee94f86SFrançois Tigeot } 122aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_destroy); 123aee94f86SFrançois Tigeot #endif 124aee94f86SFrançois Tigeot 125aee94f86SFrançois Tigeot /* 126aee94f86SFrançois Tigeot * Wrapper fxns which can be plugged in to drm_encoder_helper_funcs: 127aee94f86SFrançois Tigeot */ 128aee94f86SFrançois Tigeot 129aee94f86SFrançois Tigeot static inline const struct drm_encoder_slave_funcs * 130aee94f86SFrançois Tigeot get_slave_funcs(struct drm_encoder *enc) 131aee94f86SFrançois Tigeot { 132aee94f86SFrançois Tigeot return to_encoder_slave(enc)->slave_funcs; 133aee94f86SFrançois Tigeot } 134aee94f86SFrançois Tigeot 135aee94f86SFrançois Tigeot void drm_i2c_encoder_dpms(struct drm_encoder *encoder, int mode) 136aee94f86SFrançois Tigeot { 137aee94f86SFrançois Tigeot get_slave_funcs(encoder)->dpms(encoder, mode); 138aee94f86SFrançois Tigeot } 139aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_dpms); 140aee94f86SFrançois Tigeot 141aee94f86SFrançois Tigeot bool drm_i2c_encoder_mode_fixup(struct drm_encoder *encoder, 142aee94f86SFrançois Tigeot const struct drm_display_mode *mode, 143aee94f86SFrançois Tigeot struct drm_display_mode *adjusted_mode) 144aee94f86SFrançois Tigeot { 145*c0e85e96SFrançois Tigeot if (!get_slave_funcs(encoder)->mode_fixup) 146*c0e85e96SFrançois Tigeot return true; 147*c0e85e96SFrançois Tigeot 148aee94f86SFrançois Tigeot return get_slave_funcs(encoder)->mode_fixup(encoder, mode, adjusted_mode); 149aee94f86SFrançois Tigeot } 150aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_mode_fixup); 151aee94f86SFrançois Tigeot 152aee94f86SFrançois Tigeot void drm_i2c_encoder_prepare(struct drm_encoder *encoder) 153aee94f86SFrançois Tigeot { 154aee94f86SFrançois Tigeot drm_i2c_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 155aee94f86SFrançois Tigeot } 156aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_prepare); 157aee94f86SFrançois Tigeot 158aee94f86SFrançois Tigeot void drm_i2c_encoder_commit(struct drm_encoder *encoder) 159aee94f86SFrançois Tigeot { 160aee94f86SFrançois Tigeot drm_i2c_encoder_dpms(encoder, DRM_MODE_DPMS_ON); 161aee94f86SFrançois Tigeot } 162aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_commit); 163aee94f86SFrançois Tigeot 164aee94f86SFrançois Tigeot void drm_i2c_encoder_mode_set(struct drm_encoder *encoder, 165aee94f86SFrançois Tigeot struct drm_display_mode *mode, 166aee94f86SFrançois Tigeot struct drm_display_mode *adjusted_mode) 167aee94f86SFrançois Tigeot { 168aee94f86SFrançois Tigeot get_slave_funcs(encoder)->mode_set(encoder, mode, adjusted_mode); 169aee94f86SFrançois Tigeot } 170aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_mode_set); 171aee94f86SFrançois Tigeot 172aee94f86SFrançois Tigeot enum drm_connector_status drm_i2c_encoder_detect(struct drm_encoder *encoder, 173aee94f86SFrançois Tigeot struct drm_connector *connector) 174aee94f86SFrançois Tigeot { 175aee94f86SFrançois Tigeot return get_slave_funcs(encoder)->detect(encoder, connector); 176aee94f86SFrançois Tigeot } 177aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_detect); 178aee94f86SFrançois Tigeot 179aee94f86SFrançois Tigeot void drm_i2c_encoder_save(struct drm_encoder *encoder) 180aee94f86SFrançois Tigeot { 181aee94f86SFrançois Tigeot get_slave_funcs(encoder)->save(encoder); 182aee94f86SFrançois Tigeot } 183aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_save); 184aee94f86SFrançois Tigeot 185aee94f86SFrançois Tigeot void drm_i2c_encoder_restore(struct drm_encoder *encoder) 186aee94f86SFrançois Tigeot { 187aee94f86SFrançois Tigeot get_slave_funcs(encoder)->restore(encoder); 188aee94f86SFrançois Tigeot } 189aee94f86SFrançois Tigeot EXPORT_SYMBOL(drm_i2c_encoder_restore); 190