Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 4 | * Copyright 2019 NXP |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 5 | * |
| 6 | * FSL DCU Framebuffer driver |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <common.h> |
| 12 | #include <fsl_dcu_fb.h> |
| 13 | #include <i2c.h> |
| 14 | #include "div64.h" |
| 15 | #include "../common/diu_ch7301.h" |
| 16 | #include "ls1021aqds_qixis.h" |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 20 | static int select_i2c_ch_pca9547(u8 ch, int bus_num) |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 21 | { |
| 22 | int ret; |
Igor Opaniuk | 2147a16 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 23 | #if CONFIG_IS_ENABLED(DM_I2C) |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 24 | struct udevice *dev; |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 25 | |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 26 | ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI, |
| 27 | 1, &dev); |
| 28 | if (ret) { |
| 29 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 30 | bus_num); |
| 31 | return ret; |
| 32 | } |
| 33 | ret = dm_i2c_write(dev, 0, &ch, 1); |
| 34 | #else |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 35 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 36 | #endif |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 37 | if (ret) { |
| 38 | puts("PCA: failed to select proper channel\n"); |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | unsigned int dcu_set_pixel_clock(unsigned int pixclock) |
| 46 | { |
| 47 | unsigned long long div; |
| 48 | |
| 49 | div = (unsigned long long)(gd->bus_clk / 1000); |
| 50 | div *= (unsigned long long)pixclock; |
| 51 | do_div(div, 1000000000); |
| 52 | |
| 53 | return div; |
| 54 | } |
| 55 | |
Igor Opaniuk | a6eedb6 | 2019-06-10 14:47:49 +0300 | [diff] [blame] | 56 | int platform_dcu_init(struct fb_info *fbinfo, |
| 57 | unsigned int xres, |
| 58 | unsigned int yres, |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 59 | const char *port, |
| 60 | struct fb_videomode *dcu_fb_videomode) |
| 61 | { |
| 62 | const char *name; |
| 63 | unsigned int pixel_format; |
| 64 | int ret; |
| 65 | u8 ch; |
| 66 | |
| 67 | /* Mux I2C3+I2C4 as HSYNC+VSYNC */ |
Igor Opaniuk | 2147a16 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 68 | #if CONFIG_IS_ENABLED(DM_I2C) |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 69 | struct udevice *dev; |
| 70 | |
| 71 | /* QIXIS device mount on I2C1 bus*/ |
| 72 | ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_QIXIS_ADDR, |
| 73 | 1, &dev); |
| 74 | if (ret) { |
| 75 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 76 | 0); |
| 77 | return ret; |
| 78 | } |
| 79 | ret = dm_i2c_read(dev, QIXIS_DCU_BRDCFG5, &ch, 1); |
| 80 | if (ret) { |
| 81 | printf("Error: failed to read I2C @%02x\n", |
| 82 | CONFIG_SYS_I2C_QIXIS_ADDR); |
| 83 | return ret; |
| 84 | } |
| 85 | ch &= 0x1F; |
| 86 | ch |= 0xA0; |
| 87 | ret = dm_i2c_write(dev, QIXIS_DCU_BRDCFG5, &ch, 1); |
| 88 | |
| 89 | #else |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 90 | ret = i2c_read(CONFIG_SYS_I2C_QIXIS_ADDR, QIXIS_DCU_BRDCFG5, |
| 91 | 1, &ch, 1); |
| 92 | if (ret) { |
| 93 | printf("Error: failed to read I2C @%02x\n", |
| 94 | CONFIG_SYS_I2C_QIXIS_ADDR); |
| 95 | return ret; |
| 96 | } |
| 97 | ch &= 0x1F; |
| 98 | ch |= 0xA0; |
| 99 | ret = i2c_write(CONFIG_SYS_I2C_QIXIS_ADDR, QIXIS_DCU_BRDCFG5, |
| 100 | 1, &ch, 1); |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 101 | #endif |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 102 | if (ret) { |
| 103 | printf("Error: failed to write I2C @%02x\n", |
| 104 | CONFIG_SYS_I2C_QIXIS_ADDR); |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | if (strncmp(port, "hdmi", 4) == 0) { |
| 109 | unsigned long pixval; |
| 110 | |
| 111 | name = "HDMI"; |
| 112 | |
| 113 | pixval = 1000000000 / dcu_fb_videomode->pixclock; |
| 114 | pixval *= 1000; |
| 115 | |
Igor Opaniuk | 2147a16 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 116 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 117 | i2c_set_bus_num(CONFIG_SYS_I2C_DVI_BUS_NUM); |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 118 | #endif |
| 119 | select_i2c_ch_pca9547(I2C_MUX_CH_CH7301, |
| 120 | CONFIG_SYS_I2C_DVI_BUS_NUM); |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 121 | diu_set_dvi_encoder(pixval); |
Biwen Li | 9ebde88 | 2019-12-31 15:33:44 +0800 | [diff] [blame] | 122 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, |
| 123 | CONFIG_SYS_I2C_DVI_BUS_NUM); |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 124 | } else { |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | printf("DCU: Switching to %s monitor @ %ux%u\n", name, xres, yres); |
| 129 | |
| 130 | pixel_format = 32; |
Igor Opaniuk | a6eedb6 | 2019-06-10 14:47:49 +0300 | [diff] [blame] | 131 | fsl_dcu_init(fbinfo, xres, yres, pixel_format); |
Xiubo Li | dd04832 | 2014-12-16 14:50:33 +0800 | [diff] [blame] | 132 | |
| 133 | return 0; |
| 134 | } |