1 // SPDX-License-Identifier: GPL-2.0
3 // mach-hmt.c - Platform code for Airgoo HMT
7 #include <linux/kernel.h>
8 #include <linux/init.h>
9 #include <linux/serial_core.h>
10 #include <linux/serial_s3c.h>
11 #include <linux/platform_device.h>
13 #include <linux/i2c.h>
15 #include <linux/gpio.h>
16 #include <linux/delay.h>
17 #include <linux/leds.h>
18 #include <linux/pwm.h>
19 #include <linux/pwm_backlight.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/partitions.h>
23 #include <asm/mach/arch.h>
24 #include <asm/mach/map.h>
25 #include <asm/mach/irq.h>
27 #include <video/samsung_fimd.h>
28 #include <mach/hardware.h>
30 #include <mach/irqs.h>
33 #include <asm/mach-types.h>
35 #include <linux/platform_data/i2c-s3c2410.h>
36 #include <mach/gpio-samsung.h>
38 #include <linux/platform_data/mtd-nand-s3c2410.h>
40 #include <plat/devs.h>
42 #include <plat/samsung-time.h>
46 #define UCON S3C2410_UCON_DEFAULT
47 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
48 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
50 static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = {
74 static struct pwm_lookup hmt_pwm_lookup[] = {
75 PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", NULL,
76 1000000000 / (100 * 256 * 20), PWM_POLARITY_NORMAL),
79 static int hmt_bl_init(struct device *dev)
83 ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable");
85 ret = gpio_direction_output(S3C64XX_GPB(4), 0);
90 static int hmt_bl_notify(struct device *dev, int brightness)
93 * translate from CIELUV/CIELAB L*->brightness, E.G. from
94 * perceived luminance to light output. Assumes range 0..25600
96 if (brightness < 0x800) {
97 /* Y = Yn * L / 903.3 */
98 brightness = (100*256 * brightness + 231245/2) / 231245;
100 /* Y = Yn * ((L + 16) / 116 )^3 */
101 int t = (brightness*4 + 16*1024 + 58)/116;
102 brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
105 gpio_set_value(S3C64XX_GPB(4), brightness);
110 static void hmt_bl_exit(struct device *dev)
112 gpio_free(S3C64XX_GPB(4));
115 static struct platform_pwm_backlight_data hmt_backlight_data = {
116 .max_brightness = 100 * 256,
117 .dft_brightness = 40 * 256,
120 .notify = hmt_bl_notify,
125 static struct platform_device hmt_backlight_device = {
126 .name = "pwm-backlight",
128 .parent = &samsung_device_pwm.dev,
129 .platform_data = &hmt_backlight_data,
133 static struct s3c_fb_pd_win hmt_fb_win0 = {
140 static struct fb_videomode hmt_lcd_timing = {
151 /* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
152 static struct s3c_fb_platdata hmt_lcd_pdata __initdata = {
153 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
154 .vtiming = &hmt_lcd_timing,
155 .win[0] = &hmt_fb_win0,
156 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
157 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
160 static struct mtd_partition hmt_nand_part[] = {
167 .name = "uboot-env1",
172 .name = "uboot-env2",
174 .offset = SZ_512K + SZ_256K,
183 .size = MTDPART_SIZ_FULL,
184 .offset = SZ_1M + SZ_2M,
188 static struct s3c2410_nand_set hmt_nand_sets[] = {
192 .nr_partitions = ARRAY_SIZE(hmt_nand_part),
193 .partitions = hmt_nand_part,
197 static struct s3c2410_platform_nand hmt_nand_info = {
201 .nr_sets = ARRAY_SIZE(hmt_nand_sets),
202 .sets = hmt_nand_sets,
203 .ecc_mode = NAND_ECC_SOFT,
206 static struct gpio_led hmt_leds[] = {
207 { /* left function keys */
209 .gpio = S3C64XX_GPO(12),
210 .default_trigger = "default-on",
212 { /* right function keys - red */
214 .gpio = S3C64XX_GPO(13),
216 { /* right function keys - green */
217 .name = "right:green",
218 .gpio = S3C64XX_GPO(14),
220 { /* right function keys - blue */
221 .name = "right:blue",
222 .gpio = S3C64XX_GPO(15),
223 .default_trigger = "default-on",
227 static struct gpio_led_platform_data hmt_led_data = {
228 .num_leds = ARRAY_SIZE(hmt_leds),
232 static struct platform_device hmt_leds_device = {
235 .dev.platform_data = &hmt_led_data,
238 static struct map_desc hmt_iodesc[] = {};
240 static struct platform_device *hmt_devices[] __initdata = {
246 &hmt_backlight_device,
250 static void __init hmt_map_io(void)
252 s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc));
253 s3c64xx_set_xtal_freq(12000000);
254 s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs));
255 samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
258 static void __init hmt_machine_init(void)
260 s3c_i2c0_set_platdata(NULL);
261 s3c_fb_set_platdata(&hmt_lcd_pdata);
262 s3c_nand_set_platdata(&hmt_nand_info);
264 gpio_request(S3C64XX_GPC(7), "usb power");
265 gpio_direction_output(S3C64XX_GPC(7), 0);
266 gpio_request(S3C64XX_GPM(0), "usb power");
267 gpio_direction_output(S3C64XX_GPM(0), 1);
268 gpio_request(S3C64XX_GPK(7), "usb power");
269 gpio_direction_output(S3C64XX_GPK(7), 1);
270 gpio_request(S3C64XX_GPF(13), "usb power");
271 gpio_direction_output(S3C64XX_GPF(13), 1);
273 pwm_add_table(hmt_pwm_lookup, ARRAY_SIZE(hmt_pwm_lookup));
274 platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices));
277 MACHINE_START(HMT, "Airgoo-HMT")
279 .atag_offset = 0x100,
280 .nr_irqs = S3C64XX_NR_IRQS,
281 .init_irq = s3c6410_init_irq,
282 .map_io = hmt_map_io,
283 .init_machine = hmt_machine_init,
284 .init_time = samsung_timer_init,
285 .restart = s3c64xx_restart,