blob: 53d51aa83200627f4223f544a67f03b77f1a8e86 [file] [log] [blame]
Krzysztof Kozlowski84b21702017-12-25 20:54:32 +01001// SPDX-License-Identifier: GPL-2.0
2//
3// Copyright (c) 2003-2005 Simtec Electronics
4// Ben Dooks <ben@simtec.co.uk>
5//
Alexander A. Klimov3ecdf2a2020-07-19 11:39:39 +02006// https://www.handhelds.org/projects/h1940.html
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#include <linux/kernel.h>
9#include <linux/types.h>
10#include <linux/interrupt.h>
11#include <linux/list.h>
Russell King8d717a52010-05-22 19:47:18 +010012#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/timer.h>
14#include <linux/init.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080015#include <linux/device.h>
Ben Dooksb6d1f542006-12-17 23:22:26 +010016#include <linux/serial_core.h>
Tushar Behera334a1c72014-02-14 10:32:45 +090017#include <linux/serial_s3c.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010018#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010019#include <linux/io.h>
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +010020#include <linux/gpio.h>
Linus Walleijd2951df2018-12-02 09:43:20 +010021#include <linux/gpio/machine.h>
Arnaud Patard (Rtp)bbb1c832011-01-06 21:52:46 +020022#include <linux/input.h>
23#include <linux/gpio_keys.h>
Thierry Reding8c78aaa2015-10-13 05:04:21 +090024#include <linux/pwm.h>
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +010025#include <linux/pwm_backlight.h>
Vasily Khoruzhick68730b42010-09-27 09:32:49 +030026#include <linux/i2c.h>
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020027#include <linux/leds.h>
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +020028#include <linux/pda_power.h>
29#include <linux/s3c_adc_battery.h>
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +020030#include <linux/delay.h>
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020031
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +010032#include <video/platform_lcd.h>
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +010033
34#include <linux/mmc/host.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040035#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Kukjin Kim232910d2013-01-02 10:18:58 -080037#include <asm/irq.h>
38#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/mach/arch.h>
40#include <asm/mach/map.h>
41#include <asm/mach/irq.h>
42
Arnd Bergmann436d42c2012-08-24 15:22:12 +020043#include <linux/platform_data/i2c-s3c2410.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020044#include <linux/platform_data/mmc-s3cmci.h>
45#include <linux/platform_data/touchscreen-s3c2410.h>
Kukjin Kim232910d2013-01-02 10:18:58 -080046#include <linux/platform_data/usb-s3c2410_udc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Vasily Khoruzhick68730b42010-09-27 09:32:49 +030048#include <sound/uda1380.h>
49
Arnd Bergmann81994e02019-09-02 22:33:24 +020050#include <linux/platform_data/fb-s3c2410.h>
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020051#include "map.h"
52#include "hardware-s3c24xx.h"
53#include "regs-clock.h"
54#include "regs-gpio.h"
55#include "gpio-samsung.h"
Kukjin Kim232910d2013-01-02 10:18:58 -080056
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020057#include "cpu.h"
58#include "devs.h"
59#include "gpio-cfg.h"
60#include "pm.h"
Kukjin Kim232910d2013-01-02 10:18:58 -080061
Arnd Bergmann71b91142019-09-02 17:47:55 +020062#include "s3c24xx.h"
Kukjin Kim232910d2013-01-02 10:18:58 -080063#include "h1940.h"
Kukjin Kimb27b0722012-01-03 14:02:03 +010064
Vasily Khoruzhick14477092010-09-08 12:39:46 +030065#define H1940_LATCH ((void __force __iomem *)0xF8000000)
66
67#define H1940_PA_LATCH S3C2410_CS2
68
69#define H1940_LATCH_BIT(x) (1 << ((x) + 16 - S3C_GPIO_END))
70
Tomasz Figa32726d22014-07-02 19:42:03 +020071#define S3C24XX_PLL_MDIV_SHIFT (12)
72#define S3C24XX_PLL_PDIV_SHIFT (4)
73#define S3C24XX_PLL_SDIV_SHIFT (0)
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075static struct map_desc h1940_iodesc[] __initdata = {
Ben Dookse1981682006-02-10 22:40:51 +000076 [0] = {
77 .virtual = (unsigned long)H1940_LATCH,
78 .pfn = __phys_to_pfn(H1940_PA_LATCH),
79 .length = SZ_16K,
80 .type = MT_DEVICE
81 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
84#define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
85#define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
86#define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
87
Ben Dooks66a9b492006-06-18 23:04:05 +010088static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 [0] = {
90 .hwport = 0,
91 .flags = 0,
92 .ucon = 0x3c5,
93 .ulcon = 0x03,
94 .ufcon = 0x51,
95 },
96 [1] = {
97 .hwport = 1,
98 .flags = 0,
99 .ucon = 0x245,
100 .ulcon = 0x03,
101 .ufcon = 0x00,
102 },
103 /* IR port */
104 [2] = {
105 .hwport = 2,
106 .flags = 0,
107 .uart_flags = UPF_CONS_FLOW,
108 .ucon = 0x3c5,
109 .ulcon = 0x43,
110 .ufcon = 0x51,
111 }
112};
113
Ben Dookse1981682006-02-10 22:40:51 +0000114/* Board control latch control */
115
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300116static unsigned int latch_state;
Ben Dookse1981682006-02-10 22:40:51 +0000117
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300118static void h1940_latch_control(unsigned int clear, unsigned int set)
Ben Dookse1981682006-02-10 22:40:51 +0000119{
120 unsigned long flags;
121
122 local_irq_save(flags);
123
124 latch_state &= ~clear;
125 latch_state |= set;
126
127 __raw_writel(latch_state, H1940_LATCH);
128
129 local_irq_restore(flags);
130}
131
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300132static inline int h1940_gpiolib_to_latch(int offset)
133{
134 return 1 << (offset + 16);
135}
136
137static void h1940_gpiolib_latch_set(struct gpio_chip *chip,
138 unsigned offset, int value)
139{
140 int latch_bit = h1940_gpiolib_to_latch(offset);
141
142 h1940_latch_control(value ? 0 : latch_bit,
143 value ? latch_bit : 0);
144}
145
146static int h1940_gpiolib_latch_output(struct gpio_chip *chip,
147 unsigned offset, int value)
148{
149 h1940_gpiolib_latch_set(chip, offset, value);
150 return 0;
151}
152
153static int h1940_gpiolib_latch_get(struct gpio_chip *chip,
154 unsigned offset)
155{
156 return (latch_state >> (offset + 16)) & 1;
157}
158
Kukjin Kim4cfb7b72012-01-21 11:46:41 +0900159static struct gpio_chip h1940_latch_gpiochip = {
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300160 .base = H1940_LATCH_GPIO(0),
161 .owner = THIS_MODULE,
162 .label = "H1940_LATCH",
163 .ngpio = 16,
164 .direction_output = h1940_gpiolib_latch_output,
165 .set = h1940_gpiolib_latch_set,
166 .get = h1940_gpiolib_latch_get,
167};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Arnaud Patard71a9c422007-02-13 00:21:26 +0100169static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
Ben Dooks070276d2009-05-17 22:32:23 +0100170 .vbus_pin = S3C2410_GPG(5),
Arnaud Patard71a9c422007-02-13 00:21:26 +0100171 .vbus_pin_inverted = 1,
Lars-Peter Clausene27c3c52011-03-07 08:42:00 +0100172 .pullup_pin = H1940_LATCH_USB_DP,
Arnaud Patard71a9c422007-02-13 00:21:26 +0100173};
174
Arnaud Patardce8877b2009-12-23 19:25:05 +0000175static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
176 .delay = 10000,
177 .presc = 49,
178 .oversampling_shift = 2,
Naveen Krishna5bfdca12010-05-18 20:44:27 +0900179 .cfg_gpio = s3c24xx_ts_cfg_gpio,
Arnaud Patardce8877b2009-12-23 19:25:05 +0000180};
Arnaud Patard71a9c422007-02-13 00:21:26 +0100181
Krzysztof Kozlowskib0b27672020-08-02 22:36:05 +0200182/*
Arnaud Patardf92273c2005-09-09 13:10:10 -0700183 * Set lcd on or off
Krzysztof Kozlowskib0b27672020-08-02 22:36:05 +0200184 */
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700185static struct s3c2410fb_display h1940_lcd __initdata = {
Krzysztof Heltf28ef572007-10-16 01:28:58 -0700186 .lcdcon5= S3C2410_LCDCON5_FRM565 | \
187 S3C2410_LCDCON5_INVVLINE | \
188 S3C2410_LCDCON5_HWSWP,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700189
Krzysztof Helt1f411532007-10-16 01:28:57 -0700190 .type = S3C2410_LCDCON1_TFT,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700191 .width = 240,
192 .height = 320,
Krzysztof Helt69816692007-10-16 01:29:06 -0700193 .pixclock = 260000,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700194 .xres = 240,
195 .yres = 320,
196 .bpp = 16,
Mike Solovyev26be1b72010-05-12 15:38:00 +0400197 .left_margin = 8,
198 .right_margin = 20,
Krzysztof Helt93d11f52007-10-16 01:29:00 -0700199 .hsync_len = 4,
Krzysztof Helt5f20f692007-10-16 01:28:59 -0700200 .upper_margin = 8,
201 .lower_margin = 7,
Krzysztof Helt93d11f52007-10-16 01:29:00 -0700202 .vsync_len = 1,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700203};
204
205static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700206 .displays = &h1940_lcd,
207 .num_displays = 1,
208 .default_display = 0,
209
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200210 .lpcsel = 0x02,
211 .gpccon = 0xaa940659,
212 .gpccon_mask = 0xffffc0f0,
Arnd Bergmann81994e02019-09-02 22:33:24 +0200213 .gpccon_reg = S3C2410_GPCCON,
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200214 .gpcup = 0x0000ffff,
215 .gpcup_mask = 0xffffffff,
Arnd Bergmann81994e02019-09-02 22:33:24 +0200216 .gpcup_reg = S3C2410_GPCUP,
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200217 .gpdcon = 0xaa84aaa0,
218 .gpdcon_mask = 0xffffffff,
Arnd Bergmann81994e02019-09-02 22:33:24 +0200219 .gpdcon_reg = S3C2410_GPDCON,
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200220 .gpdup = 0x0000faff,
221 .gpdup_mask = 0xffffffff,
Arnd Bergmann81994e02019-09-02 22:33:24 +0200222 .gpdup_reg = S3C2410_GPDUP,
Arnaud Patardf92273c2005-09-09 13:10:10 -0700223};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200225static int power_supply_init(struct device *dev)
226{
227 return gpio_request(S3C2410_GPF(2), "cable plugged");
228}
229
230static int h1940_is_ac_online(void)
231{
232 return !gpio_get_value(S3C2410_GPF(2));
233}
234
235static void power_supply_exit(struct device *dev)
236{
237 gpio_free(S3C2410_GPF(2));
238}
239
240static char *h1940_supplicants[] = {
241 "main-battery",
242 "backup-battery",
243};
244
245static struct pda_power_pdata power_supply_info = {
246 .init = power_supply_init,
247 .is_ac_online = h1940_is_ac_online,
248 .exit = power_supply_exit,
249 .supplied_to = h1940_supplicants,
250 .num_supplicants = ARRAY_SIZE(h1940_supplicants),
251};
252
253static struct resource power_supply_resources[] = {
Tushar Behera635a4722012-05-12 16:12:24 +0900254 [0] = DEFINE_RES_NAMED(IRQ_EINT2, 1, "ac", IORESOURCE_IRQ \
255 | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE),
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200256};
257
258static struct platform_device power_supply = {
259 .name = "pda-power",
260 .id = -1,
261 .dev = {
262 .platform_data =
263 &power_supply_info,
264 },
265 .resource = power_supply_resources,
266 .num_resources = ARRAY_SIZE(power_supply_resources),
267};
268
269static const struct s3c_adc_bat_thresh bat_lut_noac[] = {
270 { .volt = 4070, .cur = 162, .level = 100},
271 { .volt = 4040, .cur = 165, .level = 95},
272 { .volt = 4016, .cur = 164, .level = 90},
273 { .volt = 3996, .cur = 166, .level = 85},
274 { .volt = 3971, .cur = 168, .level = 80},
275 { .volt = 3951, .cur = 168, .level = 75},
276 { .volt = 3931, .cur = 170, .level = 70},
277 { .volt = 3903, .cur = 172, .level = 65},
278 { .volt = 3886, .cur = 172, .level = 60},
279 { .volt = 3858, .cur = 176, .level = 55},
280 { .volt = 3842, .cur = 176, .level = 50},
281 { .volt = 3818, .cur = 176, .level = 45},
282 { .volt = 3789, .cur = 180, .level = 40},
283 { .volt = 3769, .cur = 180, .level = 35},
284 { .volt = 3749, .cur = 184, .level = 30},
285 { .volt = 3732, .cur = 184, .level = 25},
286 { .volt = 3716, .cur = 184, .level = 20},
287 { .volt = 3708, .cur = 184, .level = 15},
288 { .volt = 3716, .cur = 96, .level = 10},
289 { .volt = 3700, .cur = 96, .level = 5},
290 { .volt = 3684, .cur = 96, .level = 0},
291};
292
293static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
294 { .volt = 4130, .cur = 0, .level = 100},
295 { .volt = 3982, .cur = 0, .level = 50},
296 { .volt = 3854, .cur = 0, .level = 10},
297 { .volt = 3841, .cur = 0, .level = 0},
298};
299
Kukjin Kim4cfb7b72012-01-21 11:46:41 +0900300static int h1940_bat_init(void)
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200301{
302 int ret;
303
304 ret = gpio_request(H1940_LATCH_SM803_ENABLE, "h1940-charger-enable");
305 if (ret)
306 return ret;
307 gpio_direction_output(H1940_LATCH_SM803_ENABLE, 0);
308
309 return 0;
310
311}
312
Kukjin Kim4cfb7b72012-01-21 11:46:41 +0900313static void h1940_bat_exit(void)
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200314{
315 gpio_free(H1940_LATCH_SM803_ENABLE);
316}
317
Kukjin Kim4cfb7b72012-01-21 11:46:41 +0900318static void h1940_enable_charger(void)
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200319{
320 gpio_set_value(H1940_LATCH_SM803_ENABLE, 1);
321}
322
Kukjin Kim4cfb7b72012-01-21 11:46:41 +0900323static void h1940_disable_charger(void)
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200324{
325 gpio_set_value(H1940_LATCH_SM803_ENABLE, 0);
326}
327
328static struct s3c_adc_bat_pdata h1940_bat_cfg = {
329 .init = h1940_bat_init,
330 .exit = h1940_bat_exit,
331 .enable_charger = h1940_enable_charger,
332 .disable_charger = h1940_disable_charger,
333 .gpio_charge_finished = S3C2410_GPF(3),
334 .gpio_inverted = 1,
335 .lut_noac = bat_lut_noac,
336 .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
337 .lut_acin = bat_lut_acin,
338 .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin),
339 .volt_channel = 0,
340 .current_channel = 1,
341 .volt_mult = 4056,
342 .current_mult = 1893,
343 .internal_impedance = 200,
344 .backup_volt_channel = 3,
345 /* TODO Check backup volt multiplier */
346 .backup_volt_mult = 4056,
347 .backup_volt_min = 0,
348 .backup_volt_max = 4149288
349};
350
351static struct platform_device h1940_battery = {
352 .name = "s3c-adc-battery",
353 .id = -1,
354 .dev = {
355 .parent = &s3c_device_adc.dev,
356 .platform_data = &h1940_bat_cfg,
357 },
358};
359
Kukjin Kim4cfb7b72012-01-21 11:46:41 +0900360static DEFINE_SPINLOCK(h1940_blink_spin);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200361
Mika Westerbergc673a2b2014-10-31 13:40:58 +0200362int h1940_led_blink_set(struct gpio_desc *desc, int state,
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200363 unsigned long *delay_on, unsigned long *delay_off)
364{
365 int blink_gpio, check_gpio1, check_gpio2;
Mika Westerbergc673a2b2014-10-31 13:40:58 +0200366 int gpio = desc ? desc_to_gpio(desc) : -EINVAL;
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200367
368 switch (gpio) {
369 case H1940_LATCH_LED_GREEN:
370 blink_gpio = S3C2410_GPA(7);
371 check_gpio1 = S3C2410_GPA(1);
372 check_gpio2 = S3C2410_GPA(3);
373 break;
374 case H1940_LATCH_LED_RED:
375 blink_gpio = S3C2410_GPA(1);
376 check_gpio1 = S3C2410_GPA(7);
377 check_gpio2 = S3C2410_GPA(3);
378 break;
379 default:
380 blink_gpio = S3C2410_GPA(3);
381 check_gpio1 = S3C2410_GPA(1);
Julia Lawall884dc5a2012-09-13 16:01:09 +0900382 check_gpio2 = S3C2410_GPA(7);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200383 break;
384 }
385
386 if (delay_on && delay_off && !*delay_on && !*delay_off)
387 *delay_on = *delay_off = 500;
388
389 spin_lock(&h1940_blink_spin);
390
391 switch (state) {
392 case GPIO_LED_NO_BLINK_LOW:
393 case GPIO_LED_NO_BLINK_HIGH:
394 if (!gpio_get_value(check_gpio1) &&
395 !gpio_get_value(check_gpio2))
396 gpio_set_value(H1940_LATCH_LED_FLASH, 0);
397 gpio_set_value(blink_gpio, 0);
398 if (gpio_is_valid(gpio))
399 gpio_set_value(gpio, state);
400 break;
401 case GPIO_LED_BLINK:
402 if (gpio_is_valid(gpio))
403 gpio_set_value(gpio, 0);
404 gpio_set_value(H1940_LATCH_LED_FLASH, 1);
405 gpio_set_value(blink_gpio, 1);
406 break;
407 }
408
409 spin_unlock(&h1940_blink_spin);
410
411 return 0;
412}
413EXPORT_SYMBOL(h1940_led_blink_set);
414
415static struct gpio_led h1940_leds_desc[] = {
416 {
417 .name = "Green",
Vasily Khoruzhick9edb24062011-03-17 20:04:57 +0200418 .default_trigger = "main-battery-full",
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200419 .gpio = H1940_LATCH_LED_GREEN,
420 .retain_state_suspended = 1,
421 },
422 {
423 .name = "Red",
Vasily Khoruzhick9edb24062011-03-17 20:04:57 +0200424 .default_trigger
425 = "main-battery-charging-blink-full-solid",
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200426 .gpio = H1940_LATCH_LED_RED,
427 .retain_state_suspended = 1,
428 },
429};
430
431static struct gpio_led_platform_data h1940_leds_pdata = {
432 .num_leds = ARRAY_SIZE(h1940_leds_desc),
433 .leds = h1940_leds_desc,
434 .gpio_blink_set = h1940_led_blink_set,
435};
436
Ben Dooksff34aaa2009-09-28 12:45:47 +0900437static struct platform_device h1940_device_leds = {
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200438 .name = "leds-gpio",
439 .id = -1,
440 .dev = {
441 .platform_data = &h1940_leds_pdata,
442 },
Arnaud Patardd2a76022007-02-13 00:50:34 +0100443};
444
Ben Dooksff34aaa2009-09-28 12:45:47 +0900445static struct platform_device h1940_device_bluetooth = {
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100446 .name = "h1940-bt",
447 .id = -1,
448};
449
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300450static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
451{
Arnd Bergmannf67f6c02020-08-06 20:20:46 +0200452 s3c24xx_mci_def_set_power(power_mode, vdd);
453
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300454 switch (power_mode) {
455 case MMC_POWER_OFF:
456 gpio_set_value(H1940_LATCH_SD_POWER, 0);
457 break;
458 case MMC_POWER_UP:
459 case MMC_POWER_ON:
460 gpio_set_value(H1940_LATCH_SD_POWER, 1);
461 break;
462 default:
463 break;
Peter Senna Tschudindec2e822012-09-13 16:05:21 +0900464 }
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300465}
466
Ben Dooks22c810a2010-01-18 16:24:22 +0900467static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300468 .set_power = h1940_set_mmc_power,
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +0100469 .ocr_avail = MMC_VDD_32_33,
470};
471
Linus Walleijd2951df2018-12-02 09:43:20 +0100472static struct gpiod_lookup_table h1940_mmc_gpio_table = {
473 .dev_id = "s3c2410-sdi",
474 .table = {
475 /* Card detect S3C2410_GPF(5) */
Arnd Bergmann3af4e872020-08-06 20:20:20 +0200476 GPIO_LOOKUP("GPIOF", 5, "cd", GPIO_ACTIVE_LOW),
Linus Walleijd2951df2018-12-02 09:43:20 +0100477 /* Write protect S3C2410_GPH(8) */
Arnd Bergmann3af4e872020-08-06 20:20:20 +0200478 GPIO_LOOKUP("GPIOH", 8, "wp", GPIO_ACTIVE_LOW),
Arnd Bergmannf67f6c02020-08-06 20:20:46 +0200479 /* bus pins */
480 GPIO_LOOKUP_IDX("GPIOE", 5, "bus", 0, GPIO_ACTIVE_HIGH),
481 GPIO_LOOKUP_IDX("GPIOE", 6, "bus", 1, GPIO_ACTIVE_HIGH),
482 GPIO_LOOKUP_IDX("GPIOE", 7, "bus", 2, GPIO_ACTIVE_HIGH),
483 GPIO_LOOKUP_IDX("GPIOE", 8, "bus", 3, GPIO_ACTIVE_HIGH),
484 GPIO_LOOKUP_IDX("GPIOE", 9, "bus", 4, GPIO_ACTIVE_HIGH),
485 GPIO_LOOKUP_IDX("GPIOE", 10, "bus", 5, GPIO_ACTIVE_HIGH),
Linus Walleijd2951df2018-12-02 09:43:20 +0100486 { },
487 },
488};
489
Arnd Bergmann9666e272020-08-06 20:20:41 +0200490static struct gpiod_lookup_table h1940_audio_gpio_table = {
491 .dev_id = "h1940-audio",
492 .table = {
493 GPIO_LOOKUP("H1940_LATCH",
494 H1940_LATCH_AUDIO_POWER - H1940_LATCH_GPIO(0),
495 "speaker-power", GPIO_ACTIVE_HIGH),
496 GPIO_LOOKUP("GPIOG", 4, "hp", GPIO_ACTIVE_HIGH),
497 { },
498 },
499};
500
501static struct platform_device h1940_audio = {
502 .name = "h1940-audio",
503 .id = -1,
504};
505
Thierry Reding8c78aaa2015-10-13 05:04:21 +0900506static struct pwm_lookup h1940_pwm_lookup[] = {
507 PWM_LOOKUP("samsung-pwm", 0, "pwm-backlight", NULL, 36296,
508 PWM_POLARITY_NORMAL),
509};
510
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100511static int h1940_backlight_init(struct device *dev)
512{
513 gpio_request(S3C2410_GPB(0), "Backlight");
514
Ben Dooksdb61ac52010-05-04 11:40:51 +0900515 gpio_direction_output(S3C2410_GPB(0), 0);
Ben Dooksfb378742010-05-06 11:03:50 +0900516 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +0900517 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300518 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100519
520 return 0;
521}
522
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300523static int h1940_backlight_notify(struct device *dev, int brightness)
524{
525 if (!brightness) {
526 gpio_direction_output(S3C2410_GPB(0), 1);
527 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
528 } else {
529 gpio_direction_output(S3C2410_GPB(0), 0);
530 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
531 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
532 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
533 }
534 return brightness;
535}
536
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100537static void h1940_backlight_exit(struct device *dev)
538{
Ben Dooksdb61ac52010-05-04 11:40:51 +0900539 gpio_direction_output(S3C2410_GPB(0), 1);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300540 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100541}
542
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300543
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100544static struct platform_pwm_backlight_data backlight_data = {
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100545 .max_brightness = 100,
546 .dft_brightness = 50,
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100547 .init = h1940_backlight_init,
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300548 .notify = h1940_backlight_notify,
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100549 .exit = h1940_backlight_exit,
550};
551
552static struct platform_device h1940_backlight = {
553 .name = "pwm-backlight",
554 .dev = {
Tomasz Figa7fa33bd2013-03-09 15:37:53 +0100555 .parent = &samsung_device_pwm.dev,
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100556 .platform_data = &backlight_data,
557 },
558 .id = -1,
559};
560
561static void h1940_lcd_power_set(struct plat_lcd_data *pd,
562 unsigned int power)
563{
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200564 int value, retries = 100;
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100565
566 if (!power) {
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300567 gpio_set_value(S3C2410_GPC(0), 0);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100568 /* wait for 3ac */
569 do {
Ben Dooksdb61ac52010-05-04 11:40:51 +0900570 value = gpio_get_value(S3C2410_GPC(6));
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200571 } while (value && retries--);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300572
573 gpio_set_value(H1940_LATCH_LCD_P2, 0);
574 gpio_set_value(H1940_LATCH_LCD_P3, 0);
575 gpio_set_value(H1940_LATCH_LCD_P4, 0);
576
577 gpio_direction_output(S3C2410_GPC(1), 0);
578 gpio_direction_output(S3C2410_GPC(4), 0);
579
580 gpio_set_value(H1940_LATCH_LCD_P1, 0);
581 gpio_set_value(H1940_LATCH_LCD_P0, 0);
582
583 gpio_set_value(S3C2410_GPC(5), 0);
584
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100585 } else {
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300586 gpio_set_value(H1940_LATCH_LCD_P0, 1);
587 gpio_set_value(H1940_LATCH_LCD_P1, 1);
588
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200589 gpio_direction_input(S3C2410_GPC(1));
590 gpio_direction_input(S3C2410_GPC(4));
591 mdelay(10);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300592 s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
593 s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
594
595 gpio_set_value(S3C2410_GPC(5), 1);
596 gpio_set_value(S3C2410_GPC(0), 1);
597
598 gpio_set_value(H1940_LATCH_LCD_P3, 1);
599 gpio_set_value(H1940_LATCH_LCD_P2, 1);
600 gpio_set_value(H1940_LATCH_LCD_P4, 1);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100601 }
602}
603
604static struct plat_lcd_data h1940_lcd_power_data = {
605 .set_power = h1940_lcd_power_set,
606};
607
608static struct platform_device h1940_lcd_powerdev = {
609 .name = "platform-lcd",
610 .dev.parent = &s3c_device_lcd.dev,
611 .dev.platform_data = &h1940_lcd_power_data,
612};
613
Vasily Khoruzhick68730b42010-09-27 09:32:49 +0300614static struct uda1380_platform_data uda1380_info = {
615 .gpio_power = H1940_LATCH_UDA_POWER,
616 .gpio_reset = S3C2410_GPA(12),
617 .dac_clk = UDA1380_DAC_CLK_SYSCLK,
618};
619
620static struct i2c_board_info h1940_i2c_devices[] = {
621 {
622 I2C_BOARD_INFO("uda1380", 0x1a),
623 .platform_data = &uda1380_info,
624 },
625};
626
Arnaud Patard (Rtp)bbb1c832011-01-06 21:52:46 +0200627#define DECLARE_BUTTON(p, k, n, w) \
628 { \
629 .gpio = p, \
630 .code = k, \
631 .desc = n, \
632 .wakeup = w, \
633 .active_low = 1, \
634 }
635
636static struct gpio_keys_button h1940_buttons[] = {
637 DECLARE_BUTTON(S3C2410_GPF(0), KEY_POWER, "Power", 1),
638 DECLARE_BUTTON(S3C2410_GPF(6), KEY_ENTER, "Select", 1),
639 DECLARE_BUTTON(S3C2410_GPF(7), KEY_RECORD, "Record", 0),
640 DECLARE_BUTTON(S3C2410_GPG(0), KEY_F11, "Calendar", 0),
641 DECLARE_BUTTON(S3C2410_GPG(2), KEY_F12, "Contacts", 0),
642 DECLARE_BUTTON(S3C2410_GPG(3), KEY_MAIL, "Mail", 0),
643 DECLARE_BUTTON(S3C2410_GPG(6), KEY_LEFT, "Left_arrow", 0),
644 DECLARE_BUTTON(S3C2410_GPG(7), KEY_HOMEPAGE, "Home", 0),
645 DECLARE_BUTTON(S3C2410_GPG(8), KEY_RIGHT, "Right_arrow", 0),
646 DECLARE_BUTTON(S3C2410_GPG(9), KEY_UP, "Up_arrow", 0),
647 DECLARE_BUTTON(S3C2410_GPG(10), KEY_DOWN, "Down_arrow", 0),
648};
649
650static struct gpio_keys_platform_data h1940_buttons_data = {
651 .buttons = h1940_buttons,
652 .nbuttons = ARRAY_SIZE(h1940_buttons),
653};
654
655static struct platform_device h1940_dev_buttons = {
656 .name = "gpio-keys",
657 .id = -1,
658 .dev = {
659 .platform_data = &h1940_buttons_data,
660 }
661};
662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663static struct platform_device *h1940_devices[] __initdata = {
Arnaud Patard (Rtp)bbb1c832011-01-06 21:52:46 +0200664 &h1940_dev_buttons,
Ben Dooksb8132482009-11-23 00:13:39 +0000665 &s3c_device_ohci,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 &s3c_device_lcd,
667 &s3c_device_wdt,
Ben Dooks3e1b7762008-10-31 16:14:40 +0000668 &s3c_device_i2c0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 &s3c_device_iis,
Arnaud Patard71a9c422007-02-13 00:21:26 +0100670 &s3c_device_usbgadget,
Ben Dooksff34aaa2009-09-28 12:45:47 +0900671 &h1940_device_leds,
672 &h1940_device_bluetooth,
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +0100673 &s3c_device_sdi,
arnaud.patard@rtp-net.org13733d52009-11-17 14:54:57 +0100674 &s3c_device_rtc,
Tomasz Figa7fa33bd2013-03-09 15:37:53 +0100675 &samsung_device_pwm,
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100676 &h1940_backlight,
677 &h1940_lcd_powerdev,
Arnaud Patard17dcd132010-04-22 10:47:43 +0200678 &s3c_device_adc,
679 &s3c_device_ts,
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200680 &power_supply,
681 &h1940_battery,
Arnd Bergmann9666e272020-08-06 20:20:41 +0200682 &h1940_audio,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683};
684
Ben Dooks5fe10ab2005-09-20 17:24:33 +0100685static void __init h1940_map_io(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
687 s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
Krzysztof Kozlowskia1342f62020-08-20 22:42:03 +0200689 s3c24xx_set_timer_source(S3C24XX_PWM3, S3C24XX_PWM4);
Ben Dooks90733412006-12-06 01:50:24 +0100690
691 /* setup PM */
692
Krzysztof Heltb1dfe1f2007-03-19 15:10:20 +0100693#ifdef CONFIG_PM_H1940
Ben Dooks90733412006-12-06 01:50:24 +0100694 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
Krzysztof Heltb1dfe1f2007-03-19 15:10:20 +0100695#endif
Ben Dooks4e59c252008-12-12 00:24:18 +0000696 s3c_pm_init();
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300697
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300698 /* Add latch gpio chip, set latch initial value */
699 h1940_latch_control(0, 0);
Linus Walleij264af422015-12-08 11:16:53 +0100700 WARN_ON(gpiochip_add_data(&h1940_latch_gpiochip, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
Heiko Stuebner07ee5e72014-05-09 05:49:29 +0900703static void __init h1940_init_time(void)
704{
705 s3c2410_init_clocks(12000000);
Krzysztof Kozlowskia1342f62020-08-20 22:42:03 +0200706 s3c24xx_timer_init();
Heiko Stuebner07ee5e72014-05-09 05:49:29 +0900707}
708
Russell King98c672c2010-05-22 18:18:57 +0100709/* H1940 and RX3715 need to reserve this for suspend */
710static void __init h1940_reserve(void)
711{
Russell King8d717a52010-05-22 19:47:18 +0100712 memblock_reserve(0x30003000, 0x1000);
713 memblock_reserve(0x30081000, 0x1000);
Russell King98c672c2010-05-22 18:18:57 +0100714}
715
Ben Dooks5fe10ab2005-09-20 17:24:33 +0100716static void __init h1940_init(void)
Arnaud Patardf92273c2005-09-09 13:10:10 -0700717{
Arnaud Patard71a9c422007-02-13 00:21:26 +0100718 u32 tmp;
719
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700720 s3c24xx_fb_set_platdata(&h1940_fb_info);
Linus Walleijd2951df2018-12-02 09:43:20 +0100721 gpiod_add_lookup_table(&h1940_mmc_gpio_table);
Arnd Bergmann9666e272020-08-06 20:20:41 +0200722 gpiod_add_lookup_table(&h1940_audio_gpio_table);
Arnd Bergmann673085f2020-08-06 20:20:45 +0200723 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
724 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
725 S3C_GPIO_PULL_NONE);
Ben Dooks22c810a2010-01-18 16:24:22 +0900726 s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
Arnaud Patard71a9c422007-02-13 00:21:26 +0100727 s3c24xx_udc_set_platdata(&h1940_udc_cfg);
Arnaud Patardce8877b2009-12-23 19:25:05 +0000728 s3c24xx_ts_set_platdata(&h1940_ts_cfg);
Ben Dooks3e1b7762008-10-31 16:14:40 +0000729 s3c_i2c0_set_platdata(NULL);
Arnaud Patard71a9c422007-02-13 00:21:26 +0100730
731 /* Turn off suspend on both USB ports, and switch the
732 * selectable USB port to USB device mode. */
733
734 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
735 S3C2410_MISCCR_USBSUSPND0 |
736 S3C2410_MISCCR_USBSUSPND1, 0x0);
737
Kukjin Kim52e329e2011-10-04 19:41:43 +0900738 tmp = (0x78 << S3C24XX_PLL_MDIV_SHIFT)
739 | (0x02 << S3C24XX_PLL_PDIV_SHIFT)
740 | (0x03 << S3C24XX_PLL_SDIV_SHIFT);
Arnaud Patard71a9c422007-02-13 00:21:26 +0100741 writel(tmp, S3C2410_UPLLCON);
Ben Dooks57e51712007-04-20 11:19:16 +0100742
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100743 gpio_request(S3C2410_GPC(0), "LCD power");
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300744 gpio_request(S3C2410_GPC(1), "LCD power");
745 gpio_request(S3C2410_GPC(4), "LCD power");
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100746 gpio_request(S3C2410_GPC(5), "LCD power");
747 gpio_request(S3C2410_GPC(6), "LCD power");
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300748 gpio_request(H1940_LATCH_LCD_P0, "LCD power");
749 gpio_request(H1940_LATCH_LCD_P1, "LCD power");
750 gpio_request(H1940_LATCH_LCD_P2, "LCD power");
751 gpio_request(H1940_LATCH_LCD_P3, "LCD power");
752 gpio_request(H1940_LATCH_LCD_P4, "LCD power");
753 gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
754 gpio_direction_output(S3C2410_GPC(0), 0);
755 gpio_direction_output(S3C2410_GPC(1), 0);
756 gpio_direction_output(S3C2410_GPC(4), 0);
757 gpio_direction_output(S3C2410_GPC(5), 0);
Ben Dooksdb61ac52010-05-04 11:40:51 +0900758 gpio_direction_input(S3C2410_GPC(6));
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300759 gpio_direction_output(H1940_LATCH_LCD_P0, 0);
760 gpio_direction_output(H1940_LATCH_LCD_P1, 0);
761 gpio_direction_output(H1940_LATCH_LCD_P2, 0);
762 gpio_direction_output(H1940_LATCH_LCD_P3, 0);
763 gpio_direction_output(H1940_LATCH_LCD_P4, 0);
764 gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100765
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300766 gpio_request(H1940_LATCH_SD_POWER, "SD power");
767 gpio_direction_output(H1940_LATCH_SD_POWER, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Thierry Reding8c78aaa2015-10-13 05:04:21 +0900769 pwm_add_table(h1940_pwm_lookup, ARRAY_SIZE(h1940_pwm_lookup));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
Vasily Khoruzhick68730b42010-09-27 09:32:49 +0300771
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200772 gpio_request(S3C2410_GPA(1), "Red LED blink");
773 gpio_request(S3C2410_GPA(3), "Blue LED blink");
774 gpio_request(S3C2410_GPA(7), "Green LED blink");
775 gpio_request(H1940_LATCH_LED_FLASH, "LED blink");
776 gpio_direction_output(S3C2410_GPA(1), 0);
777 gpio_direction_output(S3C2410_GPA(3), 0);
778 gpio_direction_output(S3C2410_GPA(7), 0);
779 gpio_direction_output(H1940_LATCH_LED_FLASH, 0);
780
Vasily Khoruzhick68730b42010-09-27 09:32:49 +0300781 i2c_register_board_info(0, h1940_i2c_devices,
782 ARRAY_SIZE(h1940_i2c_devices));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783}
784
785MACHINE_START(H1940, "IPAQ-H1940")
Ben Dooksafdd2252010-05-07 09:24:05 +0900786 /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
Nicolas Pitre69d50712011-07-05 22:38:17 -0400787 .atag_offset = 0x100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .map_io = h1940_map_io,
Russell King98c672c2010-05-22 18:18:57 +0100789 .reserve = h1940_reserve,
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900790 .init_irq = s3c2410_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .init_machine = h1940_init,
Heiko Stuebner07ee5e72014-05-09 05:49:29 +0900792 .init_time = h1940_init_time,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793MACHINE_END