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