Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
drm_encoder_slave.c
Go to the documentation of this file.
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 <linux/module.h>
28 
29 #include <drm/drm_encoder_slave.h>
30 
53  struct drm_encoder_slave *encoder,
54  struct i2c_adapter *adap,
55  const struct i2c_board_info *info)
56 {
57  char modalias[sizeof(I2C_MODULE_PREFIX)
58  + I2C_NAME_SIZE];
59  struct module *module = NULL;
60  struct i2c_client *client;
61  struct drm_i2c_encoder_driver *encoder_drv;
62  int err = 0;
63 
64  snprintf(modalias, sizeof(modalias),
65  "%s%s", I2C_MODULE_PREFIX, info->type);
66  request_module(modalias);
67 
68  client = i2c_new_device(adap, info);
69  if (!client) {
70  err = -ENOMEM;
71  goto fail;
72  }
73 
74  if (!client->driver) {
75  err = -ENODEV;
76  goto fail_unregister;
77  }
78 
79  module = client->driver->driver.owner;
80  if (!try_module_get(module)) {
81  err = -ENODEV;
82  goto fail_unregister;
83  }
84 
85  encoder->bus_priv = client;
86 
87  encoder_drv = to_drm_i2c_encoder_driver(client->driver);
88 
89  err = encoder_drv->encoder_init(client, dev, encoder);
90  if (err)
91  goto fail_unregister;
92 
93  if (info->platform_data)
94  encoder->slave_funcs->set_config(&encoder->base,
95  info->platform_data);
96 
97  return 0;
98 
99 fail_unregister:
100  i2c_unregister_device(client);
101  module_put(module);
102 fail:
103  return err;
104 }
106 
115 {
116  struct drm_encoder_slave *encoder = to_encoder_slave(drm_encoder);
117  struct i2c_client *client = drm_i2c_encoder_get_client(drm_encoder);
118  struct module *module = client->driver->driver.owner;
119 
120  i2c_unregister_device(client);
121  encoder->bus_priv = NULL;
122 
123  module_put(module);
124 }