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