Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 1 | /* mach-hmt.c - Platform code for Airgoo HMT |
| 2 | * |
| 3 | * Copyright 2009 Peter Korsgaard <jacmet@sunsite.dk> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/serial_core.h> |
Tushar Behera | 334a1c7 | 2014-02-14 10:32:45 +0900 | [diff] [blame] | 14 | #include <linux/serial_s3c.h> |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/i2c.h> |
| 18 | #include <linux/fb.h> |
| 19 | #include <linux/gpio.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/leds.h> |
| 22 | #include <linux/pwm_backlight.h> |
| 23 | #include <linux/mtd/mtd.h> |
| 24 | #include <linux/mtd/partitions.h> |
| 25 | |
| 26 | #include <asm/mach/arch.h> |
| 27 | #include <asm/mach/map.h> |
| 28 | #include <asm/mach/irq.h> |
| 29 | |
Leela Krishna Amudala | 5a213a5 | 2012-08-08 09:44:49 +0900 | [diff] [blame] | 30 | #include <video/samsung_fimd.h> |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 31 | #include <mach/hardware.h> |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 32 | #include <mach/map.h> |
| 33 | |
| 34 | #include <asm/irq.h> |
| 35 | #include <asm/mach-types.h> |
| 36 | |
Arnd Bergmann | 436d42c | 2012-08-24 15:22:12 +0200 | [diff] [blame] | 37 | #include <linux/platform_data/i2c-s3c2410.h> |
Linus Walleij | b0161ca | 2014-01-14 14:24:24 +0100 | [diff] [blame] | 38 | #include <mach/gpio-samsung.h> |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 39 | #include <plat/fb.h> |
Arnd Bergmann | 436d42c | 2012-08-24 15:22:12 +0200 | [diff] [blame] | 40 | #include <linux/platform_data/mtd-nand-s3c2410.h> |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 41 | |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 42 | #include <plat/devs.h> |
| 43 | #include <plat/cpu.h> |
Romain Naour | 04a49b7 | 2013-01-09 18:47:04 -0800 | [diff] [blame] | 44 | #include <plat/samsung-time.h> |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 45 | |
Kukjin Kim | b024043b | 2011-12-22 23:27:42 +0100 | [diff] [blame] | 46 | #include "common.h" |
| 47 | |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 48 | #define UCON S3C2410_UCON_DEFAULT |
| 49 | #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE) |
| 50 | #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE) |
| 51 | |
| 52 | static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = { |
| 53 | [0] = { |
| 54 | .hwport = 0, |
| 55 | .flags = 0, |
| 56 | .ucon = UCON, |
| 57 | .ulcon = ULCON, |
| 58 | .ufcon = UFCON, |
| 59 | }, |
| 60 | [1] = { |
| 61 | .hwport = 1, |
| 62 | .flags = 0, |
| 63 | .ucon = UCON, |
| 64 | .ulcon = ULCON, |
| 65 | .ufcon = UFCON, |
| 66 | }, |
| 67 | [2] = { |
| 68 | .hwport = 2, |
| 69 | .flags = 0, |
| 70 | .ucon = UCON, |
| 71 | .ulcon = ULCON, |
| 72 | .ufcon = UFCON, |
| 73 | }, |
| 74 | }; |
| 75 | |
| 76 | static int hmt_bl_init(struct device *dev) |
| 77 | { |
| 78 | int ret; |
| 79 | |
| 80 | ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable"); |
| 81 | if (!ret) |
| 82 | ret = gpio_direction_output(S3C64XX_GPB(4), 0); |
| 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
Peter Korsgaard | 1619ce1 | 2010-01-21 22:56:58 +0100 | [diff] [blame] | 87 | static int hmt_bl_notify(struct device *dev, int brightness) |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 88 | { |
| 89 | /* |
| 90 | * translate from CIELUV/CIELAB L*->brightness, E.G. from |
| 91 | * perceived luminance to light output. Assumes range 0..25600 |
| 92 | */ |
| 93 | if (brightness < 0x800) { |
| 94 | /* Y = Yn * L / 903.3 */ |
| 95 | brightness = (100*256 * brightness + 231245/2) / 231245; |
| 96 | } else { |
| 97 | /* Y = Yn * ((L + 16) / 116 )^3 */ |
| 98 | int t = (brightness*4 + 16*1024 + 58)/116; |
| 99 | brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000); |
| 100 | } |
| 101 | |
| 102 | gpio_set_value(S3C64XX_GPB(4), brightness); |
| 103 | |
| 104 | return brightness; |
| 105 | } |
| 106 | |
| 107 | static void hmt_bl_exit(struct device *dev) |
| 108 | { |
| 109 | gpio_free(S3C64XX_GPB(4)); |
| 110 | } |
| 111 | |
| 112 | static struct platform_pwm_backlight_data hmt_backlight_data = { |
| 113 | .pwm_id = 1, |
| 114 | .max_brightness = 100 * 256, |
| 115 | .dft_brightness = 40 * 256, |
| 116 | .pwm_period_ns = 1000000000 / (100 * 256 * 20), |
Thierry Reding | a63652f | 2013-08-30 12:19:52 +0200 | [diff] [blame] | 117 | .enable_gpio = -1, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 118 | .init = hmt_bl_init, |
| 119 | .notify = hmt_bl_notify, |
| 120 | .exit = hmt_bl_exit, |
| 121 | |
| 122 | }; |
| 123 | |
| 124 | static struct platform_device hmt_backlight_device = { |
| 125 | .name = "pwm-backlight", |
| 126 | .dev = { |
Tomasz Figa | 7fa33bd | 2013-03-09 15:37:53 +0100 | [diff] [blame] | 127 | .parent = &samsung_device_pwm.dev, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 128 | .platform_data = &hmt_backlight_data, |
| 129 | }, |
| 130 | }; |
| 131 | |
| 132 | static struct s3c_fb_pd_win hmt_fb_win0 = { |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 133 | .max_bpp = 32, |
| 134 | .default_bpp = 16, |
Thomas Abraham | 79d3c41 | 2012-03-24 21:58:48 +0530 | [diff] [blame] | 135 | .xres = 800, |
| 136 | .yres = 480, |
| 137 | }; |
| 138 | |
| 139 | static struct fb_videomode hmt_lcd_timing = { |
| 140 | .left_margin = 8, |
| 141 | .right_margin = 13, |
| 142 | .upper_margin = 7, |
| 143 | .lower_margin = 5, |
| 144 | .hsync_len = 3, |
| 145 | .vsync_len = 1, |
| 146 | .xres = 800, |
| 147 | .yres = 480, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */ |
| 151 | static struct s3c_fb_platdata hmt_lcd_pdata __initdata = { |
| 152 | .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, |
Thomas Abraham | 79d3c41 | 2012-03-24 21:58:48 +0530 | [diff] [blame] | 153 | .vtiming = &hmt_lcd_timing, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 154 | .win[0] = &hmt_fb_win0, |
| 155 | .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, |
| 156 | .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, |
| 157 | }; |
| 158 | |
| 159 | static struct mtd_partition hmt_nand_part[] = { |
| 160 | [0] = { |
| 161 | .name = "uboot", |
| 162 | .size = SZ_512K, |
| 163 | .offset = 0, |
| 164 | }, |
| 165 | [1] = { |
| 166 | .name = "uboot-env1", |
| 167 | .size = SZ_256K, |
| 168 | .offset = SZ_512K, |
| 169 | }, |
| 170 | [2] = { |
| 171 | .name = "uboot-env2", |
| 172 | .size = SZ_256K, |
| 173 | .offset = SZ_512K + SZ_256K, |
| 174 | }, |
| 175 | [3] = { |
| 176 | .name = "kernel", |
| 177 | .size = SZ_2M, |
| 178 | .offset = SZ_1M, |
| 179 | }, |
| 180 | [4] = { |
| 181 | .name = "rootfs", |
| 182 | .size = MTDPART_SIZ_FULL, |
| 183 | .offset = SZ_1M + SZ_2M, |
| 184 | }, |
| 185 | }; |
| 186 | |
| 187 | static struct s3c2410_nand_set hmt_nand_sets[] = { |
| 188 | [0] = { |
| 189 | .name = "nand", |
| 190 | .nr_chips = 1, |
| 191 | .nr_partitions = ARRAY_SIZE(hmt_nand_part), |
| 192 | .partitions = hmt_nand_part, |
| 193 | }, |
| 194 | }; |
| 195 | |
| 196 | static struct s3c2410_platform_nand hmt_nand_info = { |
| 197 | .tacls = 25, |
| 198 | .twrph0 = 55, |
| 199 | .twrph1 = 40, |
| 200 | .nr_sets = ARRAY_SIZE(hmt_nand_sets), |
| 201 | .sets = hmt_nand_sets, |
| 202 | }; |
| 203 | |
| 204 | static struct gpio_led hmt_leds[] = { |
| 205 | { /* left function keys */ |
| 206 | .name = "left:blue", |
| 207 | .gpio = S3C64XX_GPO(12), |
| 208 | .default_trigger = "default-on", |
| 209 | }, |
| 210 | { /* right function keys - red */ |
| 211 | .name = "right:red", |
| 212 | .gpio = S3C64XX_GPO(13), |
| 213 | }, |
| 214 | { /* right function keys - green */ |
| 215 | .name = "right:green", |
| 216 | .gpio = S3C64XX_GPO(14), |
| 217 | }, |
| 218 | { /* right function keys - blue */ |
| 219 | .name = "right:blue", |
| 220 | .gpio = S3C64XX_GPO(15), |
| 221 | .default_trigger = "default-on", |
| 222 | }, |
| 223 | }; |
| 224 | |
| 225 | static struct gpio_led_platform_data hmt_led_data = { |
| 226 | .num_leds = ARRAY_SIZE(hmt_leds), |
| 227 | .leds = hmt_leds, |
| 228 | }; |
| 229 | |
| 230 | static struct platform_device hmt_leds_device = { |
| 231 | .name = "leds-gpio", |
| 232 | .id = -1, |
| 233 | .dev.platform_data = &hmt_led_data, |
| 234 | }; |
| 235 | |
| 236 | static struct map_desc hmt_iodesc[] = {}; |
| 237 | |
| 238 | static struct platform_device *hmt_devices[] __initdata = { |
| 239 | &s3c_device_i2c0, |
| 240 | &s3c_device_nand, |
| 241 | &s3c_device_fb, |
Ben Dooks | b813248 | 2009-11-23 00:13:39 +0000 | [diff] [blame] | 242 | &s3c_device_ohci, |
Tomasz Figa | 7fa33bd | 2013-03-09 15:37:53 +0100 | [diff] [blame] | 243 | &samsung_device_pwm, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 244 | &hmt_backlight_device, |
| 245 | &hmt_leds_device, |
| 246 | }; |
| 247 | |
| 248 | static void __init hmt_map_io(void) |
| 249 | { |
| 250 | s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc)); |
Tomasz Figa | b69f460 | 2013-08-26 02:00:38 +0900 | [diff] [blame] | 251 | s3c64xx_set_xtal_freq(12000000); |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 252 | s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs)); |
Romain Naour | 04a49b7 | 2013-01-09 18:47:04 -0800 | [diff] [blame] | 253 | samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4); |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static void __init hmt_machine_init(void) |
| 257 | { |
| 258 | s3c_i2c0_set_platdata(NULL); |
| 259 | s3c_fb_set_platdata(&hmt_lcd_pdata); |
Ben Dooks | 2a3a180 | 2009-09-28 13:59:49 +0300 | [diff] [blame] | 260 | s3c_nand_set_platdata(&hmt_nand_info); |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 261 | |
| 262 | gpio_request(S3C64XX_GPC(7), "usb power"); |
| 263 | gpio_direction_output(S3C64XX_GPC(7), 0); |
| 264 | gpio_request(S3C64XX_GPM(0), "usb power"); |
| 265 | gpio_direction_output(S3C64XX_GPM(0), 1); |
| 266 | gpio_request(S3C64XX_GPK(7), "usb power"); |
| 267 | gpio_direction_output(S3C64XX_GPK(7), 1); |
| 268 | gpio_request(S3C64XX_GPF(13), "usb power"); |
| 269 | gpio_direction_output(S3C64XX_GPF(13), 1); |
| 270 | |
| 271 | platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices)); |
| 272 | } |
| 273 | |
| 274 | MACHINE_START(HMT, "Airgoo-HMT") |
| 275 | /* Maintainer: Peter Korsgaard <jacmet@sunsite.dk> */ |
Nicolas Pitre | 170a590 | 2011-07-05 22:38:17 -0400 | [diff] [blame] | 276 | .atag_offset = 0x100, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 277 | .init_irq = s3c6410_init_irq, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 278 | .map_io = hmt_map_io, |
| 279 | .init_machine = hmt_machine_init, |
Shawn Guo | cc8f252 | 2012-04-26 21:08:52 +0800 | [diff] [blame] | 280 | .init_late = s3c64xx_init_late, |
Romain Naour | 04a49b7 | 2013-01-09 18:47:04 -0800 | [diff] [blame] | 281 | .init_time = samsung_timer_init, |
Kukjin Kim | ff84ded | 2012-01-03 14:03:30 +0100 | [diff] [blame] | 282 | .restart = s3c64xx_restart, |
Peter Korsgaard | 2896bda | 2009-07-01 17:47:09 +0200 | [diff] [blame] | 283 | MACHINE_END |