Deleted Added
full compact
am335x_lcd.c (277716) am335x_lcd.c (283276)
1/*-
2 * Copyright 2013 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright 2013 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/arm/ti/am335x/am335x_lcd.c 277716 2015-01-25 22:08:36Z gonzo $");
28__FBSDID("$FreeBSD: head/sys/arm/ti/am335x/am335x_lcd.c 283276 2015-05-22 03:16:18Z gonzo $");
29
30#include "opt_syscons.h"
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/module.h>
35#include <sys/clock.h>
36#include <sys/time.h>

--- 200 unchanged lines hidden (view full) ---

237 return (error);
238
239 if (backlight < 0)
240 backlight = 0;
241 if (backlight > 100)
242 backlight = 100;
243
244 LCD_LOCK(sc);
29
30#include "opt_syscons.h"
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/module.h>
35#include <sys/clock.h>
36#include <sys/time.h>

--- 200 unchanged lines hidden (view full) ---

237 return (error);
238
239 if (backlight < 0)
240 backlight = 0;
241 if (backlight > 100)
242 backlight = 100;
243
244 LCD_LOCK(sc);
245 error = am335x_pwm_config_ecas(PWM_UNIT, PWM_PERIOD,
245 error = am335x_pwm_config_ecap(PWM_UNIT, PWM_PERIOD,
246 backlight*PWM_PERIOD/100);
247 if (error == 0)
248 sc->sc_backlight = backlight;
249 LCD_UNLOCK(sc);
250
251 return (error);
252}
253
254static int
246 backlight*PWM_PERIOD/100);
247 if (error == 0)
248 sc->sc_backlight = backlight;
249 LCD_UNLOCK(sc);
250
251 return (error);
252}
253
254static int
255am335x_read_panel_property(device_t dev, const char *name, uint32_t *val)
255am335x_read_property(device_t dev, phandle_t node, const char *name, uint32_t *val)
256{
256{
257 phandle_t node;
258 pcell_t cell;
259
257 pcell_t cell;
258
260 node = ofw_bus_get_node(dev);
261 if ((OF_getprop(node, name, &cell, sizeof(cell))) <= 0) {
262 device_printf(dev, "missing '%s' attribute in LCD panel info\n",
263 name);
264 return (ENXIO);
265 }
266
267 *val = fdt32_to_cpu(cell);
268
269 return (0);
270}
271
272static int
259 if ((OF_getprop(node, name, &cell, sizeof(cell))) <= 0) {
260 device_printf(dev, "missing '%s' attribute in LCD panel info\n",
261 name);
262 return (ENXIO);
263 }
264
265 *val = fdt32_to_cpu(cell);
266
267 return (0);
268}
269
270static int
273am335x_read_panel_info(device_t dev, struct panel_info *panel)
271am335x_read_timing(device_t dev, phandle_t node, struct panel_info *panel)
274{
275 int error;
272{
273 int error;
274 phandle_t timings_node, timing_node, native;
276
275
276 timings_node = fdt_find_child(node, "display-timings");
277 if (timings_node == 0) {
278 device_printf(dev, "no \"display-timings\" node\n");
279 return (-1);
280 }
281
282 if (OF_searchencprop(timings_node, "native-mode", &native,
283 sizeof(native)) == -1) {
284 device_printf(dev, "no \"native-mode\" reference in \"timings\" node\n");
285 return (-1);
286 }
287
288 timing_node = OF_node_from_xref(native);
289
277 error = 0;
290 error = 0;
278 if ((error = am335x_read_panel_property(dev,
279 "panel_width", &panel->panel_width)))
291 if ((error = am335x_read_property(dev, timing_node,
292 "hactive", &panel->panel_width)))
280 goto out;
281
293 goto out;
294
282 if ((error = am335x_read_panel_property(dev,
283 "panel_height", &panel->panel_height)))
295 if ((error = am335x_read_property(dev, timing_node,
296 "vactive", &panel->panel_height)))
284 goto out;
285
297 goto out;
298
286 if ((error = am335x_read_panel_property(dev,
287 "panel_hfp", &panel->panel_hfp)))
299 if ((error = am335x_read_property(dev, timing_node,
300 "hfront-porch", &panel->panel_hfp)))
288 goto out;
289
301 goto out;
302
290 if ((error = am335x_read_panel_property(dev,
291 "panel_hbp", &panel->panel_hbp)))
303 if ((error = am335x_read_property(dev, timing_node,
304 "hback-porch", &panel->panel_hbp)))
292 goto out;
293
305 goto out;
306
294 if ((error = am335x_read_panel_property(dev,
295 "panel_hsw", &panel->panel_hsw)))
307 if ((error = am335x_read_property(dev, timing_node,
308 "hsync-len", &panel->panel_hsw)))
296 goto out;
297
309 goto out;
310
298 if ((error = am335x_read_panel_property(dev,
299 "panel_vfp", &panel->panel_vfp)))
311 if ((error = am335x_read_property(dev, timing_node,
312 "vfront-porch", &panel->panel_vfp)))
300 goto out;
301
313 goto out;
314
302 if ((error = am335x_read_panel_property(dev,
303 "panel_vbp", &panel->panel_vbp)))
315 if ((error = am335x_read_property(dev, timing_node,
316 "vback-porch", &panel->panel_vbp)))
304 goto out;
305
317 goto out;
318
306 if ((error = am335x_read_panel_property(dev,
307 "panel_vsw", &panel->panel_vsw)))
319 if ((error = am335x_read_property(dev, timing_node,
320 "vsync-len", &panel->panel_vsw)))
308 goto out;
309
321 goto out;
322
310 if ((error = am335x_read_panel_property(dev,
311 "panel_pxl_clk", &panel->panel_pxl_clk)))
323 if ((error = am335x_read_property(dev, timing_node,
324 "clock-frequency", &panel->panel_pxl_clk)))
312 goto out;
313
325 goto out;
326
314 if ((error = am335x_read_panel_property(dev,
315 "panel_invert_pxl_clk", &panel->panel_invert_pxl_clk)))
327 if ((error = am335x_read_property(dev, timing_node,
328 "pixelclk-active", &panel->pixelclk_active)))
316 goto out;
317
329 goto out;
330
318 if ((error = am335x_read_panel_property(dev,
319 "ac_bias", &panel->ac_bias)))
331 if ((error = am335x_read_property(dev, timing_node,
332 "hsync-active", &panel->hsync_active)))
320 goto out;
321
333 goto out;
334
322 if ((error = am335x_read_panel_property(dev,
323 "ac_bias_intrpt", &panel->ac_bias_intrpt)))
335 if ((error = am335x_read_property(dev, timing_node,
336 "vsync-active", &panel->vsync_active)))
324 goto out;
325
337 goto out;
338
326 if ((error = am335x_read_panel_property(dev,
327 "dma_burst_sz", &panel->dma_burst_sz)))
339out:
340 return (error);
341}
342
343static int
344am335x_read_panel_info(device_t dev, phandle_t node, struct panel_info *panel)
345{
346 int error;
347 phandle_t panel_info_node;
348
349 panel_info_node = fdt_find_child(node, "panel-info");
350 if (panel_info_node == 0)
351 return (-1);
352
353 error = 0;
354
355 if ((error = am335x_read_property(dev, panel_info_node,
356 "ac-bias", &panel->ac_bias)))
328 goto out;
329
357 goto out;
358
330 if ((error = am335x_read_panel_property(dev,
331 "bpp", &panel->bpp)))
359 if ((error = am335x_read_property(dev, panel_info_node,
360 "ac-bias-intrpt", &panel->ac_bias_intrpt)))
332 goto out;
333
361 goto out;
362
334 if ((error = am335x_read_panel_property(dev,
335 "fdd", &panel->fdd)))
363 if ((error = am335x_read_property(dev, panel_info_node,
364 "dma-burst-sz", &panel->dma_burst_sz)))
336 goto out;
337
365 goto out;
366
338 if ((error = am335x_read_panel_property(dev,
339 "invert_line_clock", &panel->invert_line_clock)))
367 if ((error = am335x_read_property(dev, panel_info_node,
368 "bpp", &panel->bpp)))
340 goto out;
341
369 goto out;
370
342 if ((error = am335x_read_panel_property(dev,
343 "invert_frm_clock", &panel->invert_frm_clock)))
371 if ((error = am335x_read_property(dev, panel_info_node,
372 "fdd", &panel->fdd)))
344 goto out;
345
373 goto out;
374
346 if ((error = am335x_read_panel_property(dev,
347 "sync_edge", &panel->sync_edge)))
375 if ((error = am335x_read_property(dev, panel_info_node,
376 "sync-edge", &panel->sync_edge)))
348 goto out;
349
377 goto out;
378
350 error = am335x_read_panel_property(dev,
351 "sync_ctrl", &panel->sync_ctrl);
379 error = am335x_read_property(dev, panel_info_node,
380 "sync-ctrl", &panel->sync_ctrl);
352
353out:
354 return (error);
355}
356
357static void
358am335x_lcd_intr(void *arg)
359{

--- 58 unchanged lines hidden (view full) ---

418{
419#ifdef DEV_SC
420 int err;
421#endif
422
423 if (!ofw_bus_status_okay(dev))
424 return (ENXIO);
425
381
382out:
383 return (error);
384}
385
386static void
387am335x_lcd_intr(void *arg)
388{

--- 58 unchanged lines hidden (view full) ---

447{
448#ifdef DEV_SC
449 int err;
450#endif
451
452 if (!ofw_bus_status_okay(dev))
453 return (ENXIO);
454
426 if (!ofw_bus_is_compatible(dev, "ti,am335x-lcd"))
455 if (!ofw_bus_is_compatible(dev, "ti,am33xx-tilcdc"))
427 return (ENXIO);
428
429 device_set_desc(dev, "AM335x LCD controller");
430
431#ifdef DEV_SC
432 err = sc_probe_unit(device_get_unit(dev),
433 device_get_flags(dev) | SC_AUTODETECT_KBD);
434 if (err != 0)

--- 14 unchanged lines hidden (view full) ---

449 struct sysctl_ctx_list *ctx;
450 struct sysctl_oid *tree;
451 uint32_t burst_log;
452 int err;
453 size_t dma_size;
454 uint32_t hbp, hfp, hsw;
455 uint32_t vbp, vfp, vsw;
456 uint32_t width, height;
456 return (ENXIO);
457
458 device_set_desc(dev, "AM335x LCD controller");
459
460#ifdef DEV_SC
461 err = sc_probe_unit(device_get_unit(dev),
462 device_get_flags(dev) | SC_AUTODETECT_KBD);
463 if (err != 0)

--- 14 unchanged lines hidden (view full) ---

478 struct sysctl_ctx_list *ctx;
479 struct sysctl_oid *tree;
480 uint32_t burst_log;
481 int err;
482 size_t dma_size;
483 uint32_t hbp, hfp, hsw;
484 uint32_t vbp, vfp, vsw;
485 uint32_t width, height;
486 phandle_t root, panel_node;
457
458 sc = device_get_softc(dev);
459 sc->sc_dev = dev;
460
487
488 sc = device_get_softc(dev);
489 sc->sc_dev = dev;
490
461 if (am335x_read_panel_info(dev, &panel))
491 root = OF_finddevice("/");
492 if (root == 0) {
493 device_printf(dev, "failed to get FDT root node\n");
462 return (ENXIO);
494 return (ENXIO);
495 }
463
496
497 panel_node = fdt_find_compatible(root, "ti,tilcdc,panel", 1);
498 if (panel_node == 0) {
499 device_printf(dev, "failed to find compatible panel in FDT blob\n");
500 return (ENXIO);
501 }
502
503 if (am335x_read_panel_info(dev, panel_node, &panel)) {
504 device_printf(dev, "failed to read panel info\n");
505 return (ENXIO);
506 }
507
508 if (am335x_read_timing(dev, panel_node, &panel)) {
509 device_printf(dev, "failed to read timings\n");
510 return (ENXIO);
511 }
512
464 int ref_freq = 0;
465 ti_prcm_clk_enable(LCDC_CLK);
466 if (ti_prcm_clk_get_source_freq(LCDC_CLK, &ref_freq)) {
467 device_printf(dev, "Can't get reference frequency\n");
468 return (ENXIO);
469 }
470
471 rid = 0;

--- 116 unchanged lines hidden (view full) ---

588
589 /* clock signal settings */
590 if (panel.sync_ctrl)
591 timing2 |= RASTER_TIMING_2_PHSVS;
592 if (panel.sync_edge)
593 timing2 |= RASTER_TIMING_2_PHSVS_RISE;
594 else
595 timing2 |= RASTER_TIMING_2_PHSVS_FALL;
513 int ref_freq = 0;
514 ti_prcm_clk_enable(LCDC_CLK);
515 if (ti_prcm_clk_get_source_freq(LCDC_CLK, &ref_freq)) {
516 device_printf(dev, "Can't get reference frequency\n");
517 return (ENXIO);
518 }
519
520 rid = 0;

--- 116 unchanged lines hidden (view full) ---

637
638 /* clock signal settings */
639 if (panel.sync_ctrl)
640 timing2 |= RASTER_TIMING_2_PHSVS;
641 if (panel.sync_edge)
642 timing2 |= RASTER_TIMING_2_PHSVS_RISE;
643 else
644 timing2 |= RASTER_TIMING_2_PHSVS_FALL;
596 if (panel.invert_line_clock)
645 if (panel.hsync_active == 0)
597 timing2 |= RASTER_TIMING_2_IHS;
646 timing2 |= RASTER_TIMING_2_IHS;
598 if (panel.invert_frm_clock)
647 if (panel.vsync_active == 0)
599 timing2 |= RASTER_TIMING_2_IVS;
648 timing2 |= RASTER_TIMING_2_IVS;
600 if (panel.panel_invert_pxl_clk)
649 if (panel.pixelclk_active == 0)
601 timing2 |= RASTER_TIMING_2_IPC;
602
603 /* AC bias */
604 timing2 |= (panel.ac_bias << RASTER_TIMING_2_ACB_SHIFT);
605 timing2 |= (panel.ac_bias_intrpt << RASTER_TIMING_2_ACBI_SHIFT);
606
607 LCD_WRITE4(sc, LCD_RASTER_TIMING_0, timing0);
608 LCD_WRITE4(sc, LCD_RASTER_TIMING_1, timing1);

--- 62 unchanged lines hidden (view full) ---

671 /* Init backlight interface */
672 ctx = device_get_sysctl_ctx(sc->sc_dev);
673 tree = device_get_sysctl_tree(sc->sc_dev);
674 sc->sc_oid = SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
675 "backlight", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
676 am335x_lcd_sysctl_backlight, "I", "LCD backlight");
677 sc->sc_backlight = 0;
678 /* Check if eCAS interface is available at this point */
650 timing2 |= RASTER_TIMING_2_IPC;
651
652 /* AC bias */
653 timing2 |= (panel.ac_bias << RASTER_TIMING_2_ACB_SHIFT);
654 timing2 |= (panel.ac_bias_intrpt << RASTER_TIMING_2_ACBI_SHIFT);
655
656 LCD_WRITE4(sc, LCD_RASTER_TIMING_0, timing0);
657 LCD_WRITE4(sc, LCD_RASTER_TIMING_1, timing1);

--- 62 unchanged lines hidden (view full) ---

720 /* Init backlight interface */
721 ctx = device_get_sysctl_ctx(sc->sc_dev);
722 tree = device_get_sysctl_tree(sc->sc_dev);
723 sc->sc_oid = SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
724 "backlight", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
725 am335x_lcd_sysctl_backlight, "I", "LCD backlight");
726 sc->sc_backlight = 0;
727 /* Check if eCAS interface is available at this point */
679 if (am335x_pwm_config_ecas(PWM_UNIT,
728 if (am335x_pwm_config_ecap(PWM_UNIT,
680 PWM_PERIOD, PWM_PERIOD) == 0)
681 sc->sc_backlight = 100;
682
683 sc->sc_fb_info.fb_name = device_get_nameunit(sc->sc_dev);
684 sc->sc_fb_info.fb_vbase = (intptr_t)sc->sc_fb_base;
685 sc->sc_fb_info.fb_pbase = sc->sc_fb_phys;
686 sc->sc_fb_info.fb_size = sc->sc_fb_size;
687 sc->sc_fb_info.fb_bpp = sc->sc_fb_info.fb_depth = panel.bpp;

--- 72 unchanged lines hidden ---
729 PWM_PERIOD, PWM_PERIOD) == 0)
730 sc->sc_backlight = 100;
731
732 sc->sc_fb_info.fb_name = device_get_nameunit(sc->sc_dev);
733 sc->sc_fb_info.fb_vbase = (intptr_t)sc->sc_fb_base;
734 sc->sc_fb_info.fb_pbase = sc->sc_fb_phys;
735 sc->sc_fb_info.fb_size = sc->sc_fb_size;
736 sc->sc_fb_info.fb_bpp = sc->sc_fb_info.fb_depth = panel.bpp;

--- 72 unchanged lines hidden ---