drm/debugfs: remove redundant info from gem_names
[deliverable/linux.git] / drivers / gpu / drm / shmobile / shmob_drm_drv.c
CommitLineData
51c13278
LP
1/*
2 * shmob_drm_drv.c -- SH Mobile DRM driver
3 *
4 * Copyright (C) 2012 Renesas Corporation
5 *
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/clk.h>
15#include <linux/io.h>
16#include <linux/mm.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/pm.h>
20#include <linux/slab.h>
21
22#include <drm/drmP.h>
23#include <drm/drm_crtc_helper.h>
24#include <drm/drm_gem_cma_helper.h>
25
26#include "shmob_drm_crtc.h"
27#include "shmob_drm_drv.h"
28#include "shmob_drm_kms.h"
29#include "shmob_drm_plane.h"
30#include "shmob_drm_regs.h"
31
32/* -----------------------------------------------------------------------------
33 * Hardware initialization
34 */
35
36static int __devinit shmob_drm_init_interface(struct shmob_drm_device *sdev)
37{
38 static const u32 ldmt1r[] = {
39 [SHMOB_DRM_IFACE_RGB8] = LDMT1R_MIFTYP_RGB8,
40 [SHMOB_DRM_IFACE_RGB9] = LDMT1R_MIFTYP_RGB9,
41 [SHMOB_DRM_IFACE_RGB12A] = LDMT1R_MIFTYP_RGB12A,
42 [SHMOB_DRM_IFACE_RGB12B] = LDMT1R_MIFTYP_RGB12B,
43 [SHMOB_DRM_IFACE_RGB16] = LDMT1R_MIFTYP_RGB16,
44 [SHMOB_DRM_IFACE_RGB18] = LDMT1R_MIFTYP_RGB18,
45 [SHMOB_DRM_IFACE_RGB24] = LDMT1R_MIFTYP_RGB24,
46 [SHMOB_DRM_IFACE_YUV422] = LDMT1R_MIFTYP_YCBCR,
47 [SHMOB_DRM_IFACE_SYS8A] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8A,
48 [SHMOB_DRM_IFACE_SYS8B] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8B,
49 [SHMOB_DRM_IFACE_SYS8C] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8C,
50 [SHMOB_DRM_IFACE_SYS8D] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS8D,
51 [SHMOB_DRM_IFACE_SYS9] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS9,
52 [SHMOB_DRM_IFACE_SYS12] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS12,
53 [SHMOB_DRM_IFACE_SYS16A] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS16A,
54 [SHMOB_DRM_IFACE_SYS16B] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS16B,
55 [SHMOB_DRM_IFACE_SYS16C] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS16C,
56 [SHMOB_DRM_IFACE_SYS18] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS18,
57 [SHMOB_DRM_IFACE_SYS24] = LDMT1R_IFM | LDMT1R_MIFTYP_SYS24,
58 };
59
60 if (sdev->pdata->iface.interface >= ARRAY_SIZE(ldmt1r)) {
61 dev_err(sdev->dev, "invalid interface type %u\n",
62 sdev->pdata->iface.interface);
63 return -EINVAL;
64 }
65
66 sdev->ldmt1r = ldmt1r[sdev->pdata->iface.interface];
67 return 0;
68}
69
70static int __devinit shmob_drm_setup_clocks(struct shmob_drm_device *sdev,
71 enum shmob_drm_clk_source clksrc)
72{
73 struct clk *clk;
74 char *clkname;
75
76 switch (clksrc) {
77 case SHMOB_DRM_CLK_BUS:
78 clkname = "bus_clk";
79 sdev->lddckr = LDDCKR_ICKSEL_BUS;
80 break;
81 case SHMOB_DRM_CLK_PERIPHERAL:
82 clkname = "peripheral_clk";
83 sdev->lddckr = LDDCKR_ICKSEL_MIPI;
84 break;
85 case SHMOB_DRM_CLK_EXTERNAL:
86 clkname = NULL;
87 sdev->lddckr = LDDCKR_ICKSEL_HDMI;
88 break;
89 default:
90 return -EINVAL;
91 }
92
93 clk = clk_get(sdev->dev, clkname);
94 if (IS_ERR(clk)) {
95 dev_err(sdev->dev, "cannot get dot clock %s\n", clkname);
96 return PTR_ERR(clk);
97 }
98
99 sdev->clock = clk;
100 return 0;
101}
102
103/* -----------------------------------------------------------------------------
104 * DRM operations
105 */
106
107static int shmob_drm_unload(struct drm_device *dev)
108{
109 struct shmob_drm_device *sdev = dev->dev_private;
110
111 drm_kms_helper_poll_fini(dev);
112 drm_mode_config_cleanup(dev);
113 drm_vblank_cleanup(dev);
114 drm_irq_uninstall(dev);
115
116 if (sdev->clock)
117 clk_put(sdev->clock);
118
119 if (sdev->mmio)
120 iounmap(sdev->mmio);
121
122 dev->dev_private = NULL;
123 kfree(sdev);
124
125 return 0;
126}
127
128static int shmob_drm_load(struct drm_device *dev, unsigned long flags)
129{
130 struct shmob_drm_platform_data *pdata = dev->dev->platform_data;
131 struct platform_device *pdev = dev->platformdev;
132 struct shmob_drm_device *sdev;
133 struct resource *res;
134 unsigned int i;
135 int ret;
136
137 if (pdata == NULL) {
138 dev_err(dev->dev, "no platform data\n");
139 return -EINVAL;
140 }
141
142 sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
143 if (sdev == NULL) {
144 dev_err(dev->dev, "failed to allocate private data\n");
145 return -ENOMEM;
146 }
147
148 sdev->dev = &pdev->dev;
149 sdev->pdata = pdata;
150 spin_lock_init(&sdev->irq_lock);
151
152 sdev->ddev = dev;
153 dev->dev_private = sdev;
154
155 /* I/O resources and clocks */
156 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
157 if (res == NULL) {
158 dev_err(&pdev->dev, "failed to get memory resource\n");
159 ret = -EINVAL;
160 goto done;
161 }
162
163 sdev->mmio = ioremap_nocache(res->start, resource_size(res));
164 if (sdev->mmio == NULL) {
165 dev_err(&pdev->dev, "failed to remap memory resource\n");
166 ret = -ENOMEM;
167 goto done;
168 }
169
170 ret = shmob_drm_setup_clocks(sdev, pdata->clk_source);
171 if (ret < 0)
172 goto done;
173
174 ret = shmob_drm_init_interface(sdev);
175 if (ret < 0)
176 goto done;
177
178 ret = shmob_drm_modeset_init(sdev);
179 if (ret < 0) {
180 dev_err(&pdev->dev, "failed to initialize mode setting\n");
181 goto done;
182 }
183
184 for (i = 0; i < 4; ++i) {
185 ret = shmob_drm_plane_create(sdev, i);
186 if (ret < 0) {
187 dev_err(&pdev->dev, "failed to create plane %u\n", i);
188 goto done;
189 }
190 }
191
192 ret = drm_vblank_init(dev, 1);
193 if (ret < 0) {
194 dev_err(&pdev->dev, "failed to initialize vblank\n");
195 goto done;
196 }
197
198 ret = drm_irq_install(dev);
199 if (ret < 0) {
200 dev_err(&pdev->dev, "failed to install IRQ handler\n");
201 goto done;
202 }
203
204done:
205 if (ret)
206 shmob_drm_unload(dev);
207
208 return ret;
209}
210
211static void shmob_drm_preclose(struct drm_device *dev, struct drm_file *file)
212{
213 struct shmob_drm_device *sdev = dev->dev_private;
214
215 shmob_drm_crtc_cancel_page_flip(&sdev->crtc, file);
216}
217
218static irqreturn_t shmob_drm_irq(int irq, void *arg)
219{
220 struct drm_device *dev = arg;
221 struct shmob_drm_device *sdev = dev->dev_private;
222 unsigned long flags;
223 u32 status;
224
225 /* Acknowledge interrupts. Putting interrupt enable and interrupt flag
226 * bits in the same register is really brain-dead design and requires
227 * taking a spinlock.
228 */
229 spin_lock_irqsave(&sdev->irq_lock, flags);
230 status = lcdc_read(sdev, LDINTR);
231 lcdc_write(sdev, LDINTR, status ^ LDINTR_STATUS_MASK);
232 spin_unlock_irqrestore(&sdev->irq_lock, flags);
233
234 if (status & LDINTR_VES) {
235 drm_handle_vblank(dev, 0);
236 shmob_drm_crtc_finish_page_flip(&sdev->crtc);
237 }
238
239 return IRQ_HANDLED;
240}
241
242static int shmob_drm_enable_vblank(struct drm_device *dev, int crtc)
243{
244 struct shmob_drm_device *sdev = dev->dev_private;
245
246 shmob_drm_crtc_enable_vblank(sdev, true);
247
248 return 0;
249}
250
251static void shmob_drm_disable_vblank(struct drm_device *dev, int crtc)
252{
253 struct shmob_drm_device *sdev = dev->dev_private;
254
255 shmob_drm_crtc_enable_vblank(sdev, false);
256}
257
258static const struct file_operations shmob_drm_fops = {
259 .owner = THIS_MODULE,
260 .open = drm_open,
261 .release = drm_release,
262 .unlocked_ioctl = drm_ioctl,
263#ifdef CONFIG_COMPAT
264 .compat_ioctl = drm_compat_ioctl,
265#endif
266 .poll = drm_poll,
267 .read = drm_read,
268 .fasync = drm_fasync,
269 .llseek = no_llseek,
270 .mmap = drm_gem_cma_mmap,
271};
272
273static struct drm_driver shmob_drm_driver = {
274 .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET,
275 .load = shmob_drm_load,
276 .unload = shmob_drm_unload,
277 .preclose = shmob_drm_preclose,
278 .irq_handler = shmob_drm_irq,
279 .get_vblank_counter = drm_vblank_count,
280 .enable_vblank = shmob_drm_enable_vblank,
281 .disable_vblank = shmob_drm_disable_vblank,
282 .gem_free_object = drm_gem_cma_free_object,
283 .gem_vm_ops = &drm_gem_cma_vm_ops,
284 .dumb_create = drm_gem_cma_dumb_create,
285 .dumb_map_offset = drm_gem_cma_dumb_map_offset,
286 .dumb_destroy = drm_gem_cma_dumb_destroy,
287 .fops = &shmob_drm_fops,
288 .name = "shmob-drm",
289 .desc = "Renesas SH Mobile DRM",
290 .date = "20120424",
291 .major = 1,
292 .minor = 0,
293};
294
295/* -----------------------------------------------------------------------------
296 * Power management
297 */
298
299#if CONFIG_PM_SLEEP
300static int shmob_drm_pm_suspend(struct device *dev)
301{
302 struct platform_device *pdev = to_platform_device(dev);
303 struct drm_device *ddev = platform_get_drvdata(pdev);
304 struct shmob_drm_device *sdev = ddev->dev_private;
305
306 drm_kms_helper_poll_disable(ddev);
307 shmob_drm_crtc_suspend(&sdev->crtc);
308
309 return 0;
310}
311
312static int shmob_drm_pm_resume(struct device *dev)
313{
314 struct platform_device *pdev = to_platform_device(dev);
315 struct drm_device *ddev = platform_get_drvdata(pdev);
316 struct shmob_drm_device *sdev = ddev->dev_private;
317
318 mutex_lock(&sdev->ddev->mode_config.mutex);
319 shmob_drm_crtc_resume(&sdev->crtc);
320 mutex_unlock(&sdev->ddev->mode_config.mutex);
321
322 drm_kms_helper_poll_enable(sdev->ddev);
323 return 0;
324}
325#endif
326
327static const struct dev_pm_ops shmob_drm_pm_ops = {
328 SET_SYSTEM_SLEEP_PM_OPS(shmob_drm_pm_suspend, shmob_drm_pm_resume)
329};
330
331/* -----------------------------------------------------------------------------
332 * Platform driver
333 */
334
335static int __devinit shmob_drm_probe(struct platform_device *pdev)
336{
337 return drm_platform_init(&shmob_drm_driver, pdev);
338}
339
340static int __devexit shmob_drm_remove(struct platform_device *pdev)
341{
342 drm_platform_exit(&shmob_drm_driver, pdev);
343
344 return 0;
345}
346
347static struct platform_driver shmob_drm_platform_driver = {
348 .probe = shmob_drm_probe,
349 .remove = __devexit_p(shmob_drm_remove),
350 .driver = {
351 .owner = THIS_MODULE,
352 .name = "shmob-drm",
353 .pm = &shmob_drm_pm_ops,
354 },
355};
356
357module_platform_driver(shmob_drm_platform_driver);
358
359MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
360MODULE_DESCRIPTION("Renesas SH Mobile DRM Driver");
361MODULE_LICENSE("GPL");
This page took 0.044603 seconds and 5 git commands to generate.