Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // mach-hmt.c - Platform code for Airgoo HMT
0004 //
0005 // Copyright 2009 Peter Korsgaard <jacmet@sunsite.dk>
0006 
0007 #include <linux/kernel.h>
0008 #include <linux/init.h>
0009 #include <linux/serial_core.h>
0010 #include <linux/serial_s3c.h>
0011 #include <linux/platform_device.h>
0012 #include <linux/io.h>
0013 #include <linux/i2c.h>
0014 #include <linux/fb.h>
0015 #include <linux/gpio.h>
0016 #include <linux/delay.h>
0017 #include <linux/leds.h>
0018 #include <linux/pwm.h>
0019 #include <linux/pwm_backlight.h>
0020 #include <linux/mtd/mtd.h>
0021 #include <linux/mtd/partitions.h>
0022 
0023 #include <asm/mach/arch.h>
0024 #include <asm/mach/map.h>
0025 #include <asm/mach/irq.h>
0026 
0027 #include <video/samsung_fimd.h>
0028 #include "map.h"
0029 #include "irqs.h"
0030 
0031 #include <asm/irq.h>
0032 #include <asm/mach-types.h>
0033 
0034 #include <linux/platform_data/i2c-s3c2410.h>
0035 #include "gpio-samsung.h"
0036 #include "fb.h"
0037 #include <linux/platform_data/mtd-nand-s3c2410.h>
0038 
0039 #include "devs.h"
0040 #include "cpu.h"
0041 
0042 #include "s3c64xx.h"
0043 
0044 #define UCON S3C2410_UCON_DEFAULT
0045 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
0046 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
0047 
0048 static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = {
0049     [0] = {
0050         .hwport      = 0,
0051         .flags       = 0,
0052         .ucon        = UCON,
0053         .ulcon       = ULCON,
0054         .ufcon       = UFCON,
0055     },
0056     [1] = {
0057         .hwport      = 1,
0058         .flags       = 0,
0059         .ucon        = UCON,
0060         .ulcon       = ULCON,
0061         .ufcon       = UFCON,
0062     },
0063     [2] = {
0064         .hwport      = 2,
0065         .flags       = 0,
0066         .ucon        = UCON,
0067         .ulcon       = ULCON,
0068         .ufcon       = UFCON,
0069     },
0070 };
0071 
0072 static struct pwm_lookup hmt_pwm_lookup[] = {
0073     PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", NULL,
0074            1000000000 / (100 * 256 * 20), PWM_POLARITY_NORMAL),
0075 };
0076 
0077 static int hmt_bl_init(struct device *dev)
0078 {
0079     int ret;
0080 
0081     ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable");
0082     if (!ret)
0083         ret = gpio_direction_output(S3C64XX_GPB(4), 0);
0084 
0085     return ret;
0086 }
0087 
0088 static int hmt_bl_notify(struct device *dev, int brightness)
0089 {
0090     /*
0091      * translate from CIELUV/CIELAB L*->brightness, E.G. from
0092      * perceived luminance to light output. Assumes range 0..25600
0093      */
0094     if (brightness < 0x800) {
0095         /* Y = Yn * L / 903.3 */
0096         brightness = (100*256 * brightness + 231245/2) / 231245;
0097     } else {
0098         /* Y = Yn * ((L + 16) / 116 )^3 */
0099         int t = (brightness*4 + 16*1024 + 58)/116;
0100         brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
0101     }
0102 
0103     gpio_set_value(S3C64XX_GPB(4), brightness);
0104 
0105     return brightness;
0106 }
0107 
0108 static void hmt_bl_exit(struct device *dev)
0109 {
0110     gpio_free(S3C64XX_GPB(4));
0111 }
0112 
0113 static struct platform_pwm_backlight_data hmt_backlight_data = {
0114     .max_brightness = 100 * 256,
0115     .dft_brightness = 40 * 256,
0116     .init       = hmt_bl_init,
0117     .notify     = hmt_bl_notify,
0118     .exit       = hmt_bl_exit,
0119 
0120 };
0121 
0122 static struct platform_device hmt_backlight_device = {
0123     .name       = "pwm-backlight",
0124     .dev        = {
0125         .parent = &samsung_device_pwm.dev,
0126         .platform_data = &hmt_backlight_data,
0127     },
0128 };
0129 
0130 static struct s3c_fb_pd_win hmt_fb_win0 = {
0131     .max_bpp    = 32,
0132     .default_bpp    = 16,
0133     .xres       = 800,
0134     .yres       = 480,
0135 };
0136 
0137 static struct fb_videomode hmt_lcd_timing = {
0138     .left_margin    = 8,
0139     .right_margin   = 13,
0140     .upper_margin   = 7,
0141     .lower_margin   = 5,
0142     .hsync_len  = 3,
0143     .vsync_len  = 1,
0144     .xres       = 800,
0145     .yres       = 480,
0146 };
0147 
0148 /* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
0149 static struct s3c_fb_platdata hmt_lcd_pdata __initdata = {
0150     .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
0151     .vtiming    = &hmt_lcd_timing,
0152     .win[0]     = &hmt_fb_win0,
0153     .vidcon0    = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
0154     .vidcon1    = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
0155 };
0156 
0157 static struct mtd_partition hmt_nand_part[] = {
0158     [0] = {
0159         .name   = "uboot",
0160         .size   = SZ_512K,
0161         .offset = 0,
0162     },
0163     [1] = {
0164         .name   = "uboot-env1",
0165         .size   = SZ_256K,
0166         .offset = SZ_512K,
0167     },
0168     [2] = {
0169         .name   = "uboot-env2",
0170         .size   = SZ_256K,
0171         .offset = SZ_512K + SZ_256K,
0172     },
0173     [3] = {
0174         .name   = "kernel",
0175         .size   = SZ_2M,
0176         .offset = SZ_1M,
0177     },
0178     [4] = {
0179         .name   = "rootfs",
0180         .size   = MTDPART_SIZ_FULL,
0181         .offset = SZ_1M + SZ_2M,
0182     },
0183 };
0184 
0185 static struct s3c2410_nand_set hmt_nand_sets[] = {
0186     [0] = {
0187         .name       = "nand",
0188         .nr_chips   = 1,
0189         .nr_partitions  = ARRAY_SIZE(hmt_nand_part),
0190         .partitions = hmt_nand_part,
0191     },
0192 };
0193 
0194 static struct s3c2410_platform_nand hmt_nand_info = {
0195     .tacls      = 25,
0196     .twrph0     = 55,
0197     .twrph1     = 40,
0198     .nr_sets    = ARRAY_SIZE(hmt_nand_sets),
0199     .sets       = hmt_nand_sets,
0200     .engine_type    = NAND_ECC_ENGINE_TYPE_SOFT,
0201 };
0202 
0203 static struct gpio_led hmt_leds[] = {
0204     { /* left function keys */
0205         .name           = "left:blue",
0206         .gpio           = S3C64XX_GPO(12),
0207         .default_trigger    = "default-on",
0208     },
0209     { /* right function keys - red */
0210         .name           = "right:red",
0211         .gpio           = S3C64XX_GPO(13),
0212     },
0213     { /* right function keys - green */
0214         .name           = "right:green",
0215         .gpio           = S3C64XX_GPO(14),
0216     },
0217     { /* right function keys - blue */
0218         .name           = "right:blue",
0219         .gpio           = S3C64XX_GPO(15),
0220         .default_trigger    = "default-on",
0221     },
0222 };
0223 
0224 static struct gpio_led_platform_data hmt_led_data = {
0225     .num_leds = ARRAY_SIZE(hmt_leds),
0226     .leds = hmt_leds,
0227 };
0228 
0229 static struct platform_device hmt_leds_device = {
0230     .name           = "leds-gpio",
0231     .id         = -1,
0232     .dev.platform_data  = &hmt_led_data,
0233 };
0234 
0235 static struct map_desc hmt_iodesc[] = {};
0236 
0237 static struct platform_device *hmt_devices[] __initdata = {
0238     &s3c_device_i2c0,
0239     &s3c_device_nand,
0240     &s3c_device_fb,
0241     &s3c_device_ohci,
0242     &samsung_device_pwm,
0243     &hmt_backlight_device,
0244     &hmt_leds_device,
0245 };
0246 
0247 static void __init hmt_map_io(void)
0248 {
0249     s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc));
0250     s3c64xx_set_xtal_freq(12000000);
0251     s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs));
0252     s3c64xx_set_timer_source(S3C64XX_PWM3, S3C64XX_PWM4);
0253 }
0254 
0255 static void __init hmt_machine_init(void)
0256 {
0257     s3c_i2c0_set_platdata(NULL);
0258     s3c_fb_set_platdata(&hmt_lcd_pdata);
0259     s3c_nand_set_platdata(&hmt_nand_info);
0260 
0261     gpio_request(S3C64XX_GPC(7), "usb power");
0262     gpio_direction_output(S3C64XX_GPC(7), 0);
0263     gpio_request(S3C64XX_GPM(0), "usb power");
0264     gpio_direction_output(S3C64XX_GPM(0), 1);
0265     gpio_request(S3C64XX_GPK(7), "usb power");
0266     gpio_direction_output(S3C64XX_GPK(7), 1);
0267     gpio_request(S3C64XX_GPF(13), "usb power");
0268     gpio_direction_output(S3C64XX_GPF(13), 1);
0269 
0270     pwm_add_table(hmt_pwm_lookup, ARRAY_SIZE(hmt_pwm_lookup));
0271     platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices));
0272 }
0273 
0274 MACHINE_START(HMT, "Airgoo-HMT")
0275     /* Maintainer: Peter Korsgaard <jacmet@sunsite.dk> */
0276     .atag_offset    = 0x100,
0277     .nr_irqs    = S3C64XX_NR_IRQS,
0278     .init_irq   = s3c6410_init_irq,
0279     .map_io     = hmt_map_io,
0280     .init_machine   = hmt_machine_init,
0281     .init_time  = s3c64xx_timer_init,
0282 MACHINE_END