Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // Copyright (c) 2006-2009 Victor Chukhantsev, Denis Grigoriev, |
| 4 | // Copyright (c) 2007-2010 Vasily Khoruzhick |
| 5 | // |
| 6 | // based on smdk2440 written by Ben Dooks |
| 7 | |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/list.h> |
| 12 | #include <linux/memblock.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/timer.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/gpio.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 17 | #include <linux/gpio/machine.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/serial_core.h> |
| 20 | #include <linux/serial_s3c.h> |
| 21 | #include <linux/input.h> |
| 22 | #include <linux/gpio_keys.h> |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/pda_power.h> |
| 25 | #include <linux/pwm_backlight.h> |
| 26 | #include <linux/pwm.h> |
| 27 | #include <linux/s3c_adc_battery.h> |
| 28 | #include <linux/leds.h> |
| 29 | #include <linux/i2c.h> |
| 30 | |
| 31 | #include <linux/mtd/mtd.h> |
| 32 | #include <linux/mtd/partitions.h> |
| 33 | |
| 34 | #include <linux/mmc/host.h> |
| 35 | |
| 36 | #include <asm/mach-types.h> |
| 37 | #include <asm/mach/arch.h> |
| 38 | #include <asm/mach/map.h> |
| 39 | |
| 40 | #include <linux/platform_data/i2c-s3c2410.h> |
| 41 | #include <linux/platform_data/mmc-s3cmci.h> |
| 42 | #include <linux/platform_data/mtd-nand-s3c2410.h> |
| 43 | #include <linux/platform_data/touchscreen-s3c2410.h> |
| 44 | #include <linux/platform_data/usb-s3c2410_udc.h> |
| 45 | |
| 46 | #include <sound/uda1380.h> |
| 47 | |
| 48 | #include <mach/fb.h> |
| 49 | #include <mach/regs-gpio.h> |
| 50 | #include <mach/regs-lcd.h> |
| 51 | #include <mach/gpio-samsung.h> |
| 52 | |
| 53 | #include <plat/cpu.h> |
| 54 | #include <plat/devs.h> |
| 55 | #include <plat/pm.h> |
| 56 | #include <plat/samsung-time.h> |
| 57 | #include <plat/gpio-cfg.h> |
| 58 | |
| 59 | #include "common.h" |
| 60 | #include "h1940.h" |
| 61 | |
| 62 | #define LCD_PWM_PERIOD 192960 |
| 63 | #define LCD_PWM_DUTY 127353 |
| 64 | |
| 65 | static struct map_desc rx1950_iodesc[] __initdata = { |
| 66 | }; |
| 67 | |
| 68 | static struct s3c2410_uartcfg rx1950_uartcfgs[] __initdata = { |
| 69 | [0] = { |
| 70 | .hwport = 0, |
| 71 | .flags = 0, |
| 72 | .ucon = 0x3c5, |
| 73 | .ulcon = 0x03, |
| 74 | .ufcon = 0x51, |
| 75 | .clk_sel = S3C2410_UCON_CLKSEL3, |
| 76 | }, |
| 77 | [1] = { |
| 78 | .hwport = 1, |
| 79 | .flags = 0, |
| 80 | .ucon = 0x3c5, |
| 81 | .ulcon = 0x03, |
| 82 | .ufcon = 0x51, |
| 83 | .clk_sel = S3C2410_UCON_CLKSEL3, |
| 84 | }, |
| 85 | /* IR port */ |
| 86 | [2] = { |
| 87 | .hwport = 2, |
| 88 | .flags = 0, |
| 89 | .ucon = 0x3c5, |
| 90 | .ulcon = 0x43, |
| 91 | .ufcon = 0xf1, |
| 92 | .clk_sel = S3C2410_UCON_CLKSEL3, |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | static struct s3c2410fb_display rx1950_display = { |
| 97 | .type = S3C2410_LCDCON1_TFT, |
| 98 | .width = 240, |
| 99 | .height = 320, |
| 100 | .xres = 240, |
| 101 | .yres = 320, |
| 102 | .bpp = 16, |
| 103 | |
| 104 | .pixclock = 260000, |
| 105 | .left_margin = 10, |
| 106 | .right_margin = 20, |
| 107 | .hsync_len = 10, |
| 108 | .upper_margin = 2, |
| 109 | .lower_margin = 2, |
| 110 | .vsync_len = 2, |
| 111 | |
| 112 | .lcdcon5 = S3C2410_LCDCON5_FRM565 | |
| 113 | S3C2410_LCDCON5_INVVCLK | |
| 114 | S3C2410_LCDCON5_INVVLINE | |
| 115 | S3C2410_LCDCON5_INVVFRAME | |
| 116 | S3C2410_LCDCON5_HWSWP | |
| 117 | (0x02 << 13) | |
| 118 | (0x02 << 15), |
| 119 | |
| 120 | }; |
| 121 | |
| 122 | static int power_supply_init(struct device *dev) |
| 123 | { |
| 124 | return gpio_request(S3C2410_GPF(2), "cable plugged"); |
| 125 | } |
| 126 | |
| 127 | static int rx1950_is_ac_online(void) |
| 128 | { |
| 129 | return !gpio_get_value(S3C2410_GPF(2)); |
| 130 | } |
| 131 | |
| 132 | static void power_supply_exit(struct device *dev) |
| 133 | { |
| 134 | gpio_free(S3C2410_GPF(2)); |
| 135 | } |
| 136 | |
| 137 | static char *rx1950_supplicants[] = { |
| 138 | "main-battery" |
| 139 | }; |
| 140 | |
| 141 | static struct pda_power_pdata power_supply_info = { |
| 142 | .init = power_supply_init, |
| 143 | .is_ac_online = rx1950_is_ac_online, |
| 144 | .exit = power_supply_exit, |
| 145 | .supplied_to = rx1950_supplicants, |
| 146 | .num_supplicants = ARRAY_SIZE(rx1950_supplicants), |
| 147 | }; |
| 148 | |
| 149 | static struct resource power_supply_resources[] = { |
| 150 | [0] = DEFINE_RES_NAMED(IRQ_EINT2, 1, "ac", IORESOURCE_IRQ \ |
| 151 | | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE), |
| 152 | }; |
| 153 | |
| 154 | static struct platform_device power_supply = { |
| 155 | .name = "pda-power", |
| 156 | .id = -1, |
| 157 | .dev = { |
| 158 | .platform_data = |
| 159 | &power_supply_info, |
| 160 | }, |
| 161 | .resource = power_supply_resources, |
| 162 | .num_resources = ARRAY_SIZE(power_supply_resources), |
| 163 | }; |
| 164 | |
| 165 | static const struct s3c_adc_bat_thresh bat_lut_noac[] = { |
| 166 | { .volt = 4100, .cur = 156, .level = 100}, |
| 167 | { .volt = 4050, .cur = 156, .level = 95}, |
| 168 | { .volt = 4025, .cur = 141, .level = 90}, |
| 169 | { .volt = 3995, .cur = 144, .level = 85}, |
| 170 | { .volt = 3957, .cur = 162, .level = 80}, |
| 171 | { .volt = 3931, .cur = 147, .level = 75}, |
| 172 | { .volt = 3902, .cur = 147, .level = 70}, |
| 173 | { .volt = 3863, .cur = 153, .level = 65}, |
| 174 | { .volt = 3838, .cur = 150, .level = 60}, |
| 175 | { .volt = 3800, .cur = 153, .level = 55}, |
| 176 | { .volt = 3765, .cur = 153, .level = 50}, |
| 177 | { .volt = 3748, .cur = 172, .level = 45}, |
| 178 | { .volt = 3740, .cur = 153, .level = 40}, |
| 179 | { .volt = 3714, .cur = 175, .level = 35}, |
| 180 | { .volt = 3710, .cur = 156, .level = 30}, |
| 181 | { .volt = 3963, .cur = 156, .level = 25}, |
| 182 | { .volt = 3672, .cur = 178, .level = 20}, |
| 183 | { .volt = 3651, .cur = 178, .level = 15}, |
| 184 | { .volt = 3629, .cur = 178, .level = 10}, |
| 185 | { .volt = 3612, .cur = 162, .level = 5}, |
| 186 | { .volt = 3605, .cur = 162, .level = 0}, |
| 187 | }; |
| 188 | |
| 189 | static const struct s3c_adc_bat_thresh bat_lut_acin[] = { |
| 190 | { .volt = 4200, .cur = 0, .level = 100}, |
| 191 | { .volt = 4190, .cur = 0, .level = 99}, |
| 192 | { .volt = 4178, .cur = 0, .level = 95}, |
| 193 | { .volt = 4110, .cur = 0, .level = 70}, |
| 194 | { .volt = 4076, .cur = 0, .level = 65}, |
| 195 | { .volt = 4046, .cur = 0, .level = 60}, |
| 196 | { .volt = 4021, .cur = 0, .level = 55}, |
| 197 | { .volt = 3999, .cur = 0, .level = 50}, |
| 198 | { .volt = 3982, .cur = 0, .level = 45}, |
| 199 | { .volt = 3965, .cur = 0, .level = 40}, |
| 200 | { .volt = 3957, .cur = 0, .level = 35}, |
| 201 | { .volt = 3948, .cur = 0, .level = 30}, |
| 202 | { .volt = 3936, .cur = 0, .level = 25}, |
| 203 | { .volt = 3927, .cur = 0, .level = 20}, |
| 204 | { .volt = 3906, .cur = 0, .level = 15}, |
| 205 | { .volt = 3880, .cur = 0, .level = 10}, |
| 206 | { .volt = 3829, .cur = 0, .level = 5}, |
| 207 | { .volt = 3820, .cur = 0, .level = 0}, |
| 208 | }; |
| 209 | |
| 210 | static int rx1950_bat_init(void) |
| 211 | { |
| 212 | int ret; |
| 213 | |
| 214 | ret = gpio_request(S3C2410_GPJ(2), "rx1950-charger-enable-1"); |
| 215 | if (ret) |
| 216 | goto err_gpio1; |
| 217 | ret = gpio_request(S3C2410_GPJ(3), "rx1950-charger-enable-2"); |
| 218 | if (ret) |
| 219 | goto err_gpio2; |
| 220 | |
| 221 | return 0; |
| 222 | |
| 223 | err_gpio2: |
| 224 | gpio_free(S3C2410_GPJ(2)); |
| 225 | err_gpio1: |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | static void rx1950_bat_exit(void) |
| 230 | { |
| 231 | gpio_free(S3C2410_GPJ(2)); |
| 232 | gpio_free(S3C2410_GPJ(3)); |
| 233 | } |
| 234 | |
| 235 | static void rx1950_enable_charger(void) |
| 236 | { |
| 237 | gpio_direction_output(S3C2410_GPJ(2), 1); |
| 238 | gpio_direction_output(S3C2410_GPJ(3), 1); |
| 239 | } |
| 240 | |
| 241 | static void rx1950_disable_charger(void) |
| 242 | { |
| 243 | gpio_direction_output(S3C2410_GPJ(2), 0); |
| 244 | gpio_direction_output(S3C2410_GPJ(3), 0); |
| 245 | } |
| 246 | |
| 247 | static DEFINE_SPINLOCK(rx1950_blink_spin); |
| 248 | |
| 249 | static int rx1950_led_blink_set(struct gpio_desc *desc, int state, |
| 250 | unsigned long *delay_on, unsigned long *delay_off) |
| 251 | { |
| 252 | int gpio = desc_to_gpio(desc); |
| 253 | int blink_gpio, check_gpio; |
| 254 | |
| 255 | switch (gpio) { |
| 256 | case S3C2410_GPA(6): |
| 257 | blink_gpio = S3C2410_GPA(4); |
| 258 | check_gpio = S3C2410_GPA(3); |
| 259 | break; |
| 260 | case S3C2410_GPA(7): |
| 261 | blink_gpio = S3C2410_GPA(3); |
| 262 | check_gpio = S3C2410_GPA(4); |
| 263 | break; |
| 264 | default: |
| 265 | return -EINVAL; |
| 266 | break; |
| 267 | } |
| 268 | |
| 269 | if (delay_on && delay_off && !*delay_on && !*delay_off) |
| 270 | *delay_on = *delay_off = 500; |
| 271 | |
| 272 | spin_lock(&rx1950_blink_spin); |
| 273 | |
| 274 | switch (state) { |
| 275 | case GPIO_LED_NO_BLINK_LOW: |
| 276 | case GPIO_LED_NO_BLINK_HIGH: |
| 277 | if (!gpio_get_value(check_gpio)) |
| 278 | gpio_set_value(S3C2410_GPJ(6), 0); |
| 279 | gpio_set_value(blink_gpio, 0); |
| 280 | gpio_set_value(gpio, state); |
| 281 | break; |
| 282 | case GPIO_LED_BLINK: |
| 283 | gpio_set_value(gpio, 0); |
| 284 | gpio_set_value(S3C2410_GPJ(6), 1); |
| 285 | gpio_set_value(blink_gpio, 1); |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | spin_unlock(&rx1950_blink_spin); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static struct gpio_led rx1950_leds_desc[] = { |
| 295 | { |
| 296 | .name = "Green", |
| 297 | .default_trigger = "main-battery-full", |
| 298 | .gpio = S3C2410_GPA(6), |
| 299 | .retain_state_suspended = 1, |
| 300 | }, |
| 301 | { |
| 302 | .name = "Red", |
| 303 | .default_trigger |
| 304 | = "main-battery-charging-blink-full-solid", |
| 305 | .gpio = S3C2410_GPA(7), |
| 306 | .retain_state_suspended = 1, |
| 307 | }, |
| 308 | { |
| 309 | .name = "Blue", |
| 310 | .default_trigger = "rx1950-acx-mem", |
| 311 | .gpio = S3C2410_GPA(11), |
| 312 | .retain_state_suspended = 1, |
| 313 | }, |
| 314 | }; |
| 315 | |
| 316 | static struct gpio_led_platform_data rx1950_leds_pdata = { |
| 317 | .num_leds = ARRAY_SIZE(rx1950_leds_desc), |
| 318 | .leds = rx1950_leds_desc, |
| 319 | .gpio_blink_set = rx1950_led_blink_set, |
| 320 | }; |
| 321 | |
| 322 | static struct platform_device rx1950_leds = { |
| 323 | .name = "leds-gpio", |
| 324 | .id = -1, |
| 325 | .dev = { |
| 326 | .platform_data = &rx1950_leds_pdata, |
| 327 | }, |
| 328 | }; |
| 329 | |
| 330 | static struct s3c_adc_bat_pdata rx1950_bat_cfg = { |
| 331 | .init = rx1950_bat_init, |
| 332 | .exit = rx1950_bat_exit, |
| 333 | .enable_charger = rx1950_enable_charger, |
| 334 | .disable_charger = rx1950_disable_charger, |
| 335 | .gpio_charge_finished = S3C2410_GPF(3), |
| 336 | .lut_noac = bat_lut_noac, |
| 337 | .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac), |
| 338 | .lut_acin = bat_lut_acin, |
| 339 | .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin), |
| 340 | .volt_channel = 0, |
| 341 | .current_channel = 1, |
| 342 | .volt_mult = 4235, |
| 343 | .current_mult = 2900, |
| 344 | .internal_impedance = 200, |
| 345 | }; |
| 346 | |
| 347 | static struct platform_device rx1950_battery = { |
| 348 | .name = "s3c-adc-battery", |
| 349 | .id = -1, |
| 350 | .dev = { |
| 351 | .parent = &s3c_device_adc.dev, |
| 352 | .platform_data = &rx1950_bat_cfg, |
| 353 | }, |
| 354 | }; |
| 355 | |
| 356 | static struct s3c2410fb_mach_info rx1950_lcd_cfg = { |
| 357 | .displays = &rx1950_display, |
| 358 | .num_displays = 1, |
| 359 | .default_display = 0, |
| 360 | |
| 361 | .lpcsel = 0x02, |
| 362 | .gpccon = 0xaa9556a9, |
| 363 | .gpccon_mask = 0xffc003fc, |
| 364 | .gpcup = 0x0000ffff, |
| 365 | .gpcup_mask = 0xffffffff, |
| 366 | |
| 367 | .gpdcon = 0xaa90aaa1, |
| 368 | .gpdcon_mask = 0xffc0fff0, |
| 369 | .gpdup = 0x0000fcfd, |
| 370 | .gpdup_mask = 0xffffffff, |
| 371 | |
| 372 | }; |
| 373 | |
| 374 | static struct pwm_lookup rx1950_pwm_lookup[] = { |
| 375 | PWM_LOOKUP("samsung-pwm", 0, "pwm-backlight.0", NULL, 48000, |
| 376 | PWM_POLARITY_NORMAL), |
| 377 | }; |
| 378 | |
| 379 | static struct pwm_device *lcd_pwm; |
| 380 | |
| 381 | static void rx1950_lcd_power(int enable) |
| 382 | { |
| 383 | int i; |
| 384 | static int enabled; |
| 385 | if (enabled == enable) |
| 386 | return; |
| 387 | if (!enable) { |
| 388 | |
| 389 | /* GPC11-GPC15->OUTPUT */ |
| 390 | for (i = 11; i < 16; i++) |
| 391 | gpio_direction_output(S3C2410_GPC(i), 1); |
| 392 | |
| 393 | /* Wait a bit here... */ |
| 394 | mdelay(100); |
| 395 | |
| 396 | /* GPD2-GPD7->OUTPUT */ |
| 397 | /* GPD11-GPD15->OUTPUT */ |
| 398 | /* GPD2-GPD7->1, GPD11-GPD15->1 */ |
| 399 | for (i = 2; i < 8; i++) |
| 400 | gpio_direction_output(S3C2410_GPD(i), 1); |
| 401 | for (i = 11; i < 16; i++) |
| 402 | gpio_direction_output(S3C2410_GPD(i), 1); |
| 403 | |
| 404 | /* Wait a bit here...*/ |
| 405 | mdelay(100); |
| 406 | |
| 407 | /* GPB0->OUTPUT, GPB0->0 */ |
| 408 | gpio_direction_output(S3C2410_GPB(0), 0); |
| 409 | |
| 410 | /* GPC1-GPC4->OUTPUT, GPC1-4->0 */ |
| 411 | for (i = 1; i < 5; i++) |
| 412 | gpio_direction_output(S3C2410_GPC(i), 0); |
| 413 | |
| 414 | /* GPC15-GPC11->0 */ |
| 415 | for (i = 11; i < 16; i++) |
| 416 | gpio_direction_output(S3C2410_GPC(i), 0); |
| 417 | |
| 418 | /* GPD15-GPD11->0, GPD2->GPD7->0 */ |
| 419 | for (i = 11; i < 16; i++) |
| 420 | gpio_direction_output(S3C2410_GPD(i), 0); |
| 421 | |
| 422 | for (i = 2; i < 8; i++) |
| 423 | gpio_direction_output(S3C2410_GPD(i), 0); |
| 424 | |
| 425 | /* GPC6->0, GPC7->0, GPC5->0 */ |
| 426 | gpio_direction_output(S3C2410_GPC(6), 0); |
| 427 | gpio_direction_output(S3C2410_GPC(7), 0); |
| 428 | gpio_direction_output(S3C2410_GPC(5), 0); |
| 429 | |
| 430 | /* GPB1->OUTPUT, GPB1->0 */ |
| 431 | gpio_direction_output(S3C2410_GPB(1), 0); |
| 432 | pwm_config(lcd_pwm, 0, LCD_PWM_PERIOD); |
| 433 | pwm_disable(lcd_pwm); |
| 434 | |
| 435 | /* GPC0->0, GPC10->0 */ |
| 436 | gpio_direction_output(S3C2410_GPC(0), 0); |
| 437 | gpio_direction_output(S3C2410_GPC(10), 0); |
| 438 | } else { |
| 439 | pwm_config(lcd_pwm, LCD_PWM_DUTY, LCD_PWM_PERIOD); |
| 440 | pwm_enable(lcd_pwm); |
| 441 | |
| 442 | gpio_direction_output(S3C2410_GPC(0), 1); |
| 443 | gpio_direction_output(S3C2410_GPC(5), 1); |
| 444 | |
| 445 | s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1); |
| 446 | gpio_direction_output(S3C2410_GPC(7), 1); |
| 447 | |
| 448 | for (i = 1; i < 5; i++) |
| 449 | s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2)); |
| 450 | |
| 451 | for (i = 11; i < 16; i++) |
| 452 | s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2)); |
| 453 | |
| 454 | for (i = 2; i < 8; i++) |
| 455 | s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2)); |
| 456 | |
| 457 | for (i = 11; i < 16; i++) |
| 458 | s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2)); |
| 459 | |
| 460 | gpio_direction_output(S3C2410_GPC(10), 1); |
| 461 | gpio_direction_output(S3C2410_GPC(6), 1); |
| 462 | } |
| 463 | enabled = enable; |
| 464 | } |
| 465 | |
| 466 | static void rx1950_bl_power(int enable) |
| 467 | { |
| 468 | static int enabled; |
| 469 | if (enabled == enable) |
| 470 | return; |
| 471 | if (!enable) { |
| 472 | gpio_direction_output(S3C2410_GPB(0), 0); |
| 473 | } else { |
| 474 | /* LED driver need a "push" to power on */ |
| 475 | gpio_direction_output(S3C2410_GPB(0), 1); |
| 476 | /* Warm up backlight for one period of PWM. |
| 477 | * Without this trick its almost impossible to |
| 478 | * enable backlight with low brightness value |
| 479 | */ |
| 480 | ndelay(48000); |
| 481 | s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0); |
| 482 | } |
| 483 | enabled = enable; |
| 484 | } |
| 485 | |
| 486 | static int rx1950_backlight_init(struct device *dev) |
| 487 | { |
| 488 | WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight")); |
| 489 | lcd_pwm = pwm_request(1, "RX1950 LCD"); |
| 490 | if (IS_ERR(lcd_pwm)) { |
| 491 | dev_err(dev, "Unable to request PWM for LCD power!\n"); |
| 492 | return PTR_ERR(lcd_pwm); |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * FIXME: pwm_apply_args() should be removed when switching to |
| 497 | * the atomic PWM API. |
| 498 | */ |
| 499 | pwm_apply_args(lcd_pwm); |
| 500 | |
| 501 | rx1950_lcd_power(1); |
| 502 | rx1950_bl_power(1); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static void rx1950_backlight_exit(struct device *dev) |
| 508 | { |
| 509 | rx1950_bl_power(0); |
| 510 | rx1950_lcd_power(0); |
| 511 | |
| 512 | pwm_free(lcd_pwm); |
| 513 | gpio_free(S3C2410_GPB(0)); |
| 514 | } |
| 515 | |
| 516 | |
| 517 | static int rx1950_backlight_notify(struct device *dev, int brightness) |
| 518 | { |
| 519 | if (!brightness) { |
| 520 | rx1950_bl_power(0); |
| 521 | rx1950_lcd_power(0); |
| 522 | } else { |
| 523 | rx1950_lcd_power(1); |
| 524 | rx1950_bl_power(1); |
| 525 | } |
| 526 | return brightness; |
| 527 | } |
| 528 | |
| 529 | static struct platform_pwm_backlight_data rx1950_backlight_data = { |
| 530 | .max_brightness = 24, |
| 531 | .dft_brightness = 4, |
| 532 | .enable_gpio = -1, |
| 533 | .init = rx1950_backlight_init, |
| 534 | .notify = rx1950_backlight_notify, |
| 535 | .exit = rx1950_backlight_exit, |
| 536 | }; |
| 537 | |
| 538 | static struct platform_device rx1950_backlight = { |
| 539 | .name = "pwm-backlight", |
| 540 | .dev = { |
| 541 | .parent = &samsung_device_pwm.dev, |
| 542 | .platform_data = &rx1950_backlight_data, |
| 543 | }, |
| 544 | }; |
| 545 | |
| 546 | static void rx1950_set_mmc_power(unsigned char power_mode, unsigned short vdd) |
| 547 | { |
| 548 | switch (power_mode) { |
| 549 | case MMC_POWER_OFF: |
| 550 | gpio_direction_output(S3C2410_GPJ(1), 0); |
| 551 | break; |
| 552 | case MMC_POWER_UP: |
| 553 | case MMC_POWER_ON: |
| 554 | gpio_direction_output(S3C2410_GPJ(1), 1); |
| 555 | break; |
| 556 | default: |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 562 | .set_power = rx1950_set_mmc_power, |
| 563 | .ocr_avail = MMC_VDD_32_33, |
| 564 | }; |
| 565 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 566 | static struct gpiod_lookup_table rx1950_mmc_gpio_table = { |
| 567 | .dev_id = "s3c2410-sdi", |
| 568 | .table = { |
| 569 | /* Card detect S3C2410_GPF(5) */ |
| 570 | GPIO_LOOKUP("GPF", 5, "cd", GPIO_ACTIVE_LOW), |
| 571 | /* Write protect S3C2410_GPH(8) */ |
| 572 | GPIO_LOOKUP("GPH", 8, "wp", GPIO_ACTIVE_LOW), |
| 573 | { }, |
| 574 | }, |
| 575 | }; |
| 576 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 577 | static struct mtd_partition rx1950_nand_part[] = { |
| 578 | [0] = { |
| 579 | .name = "Boot0", |
| 580 | .offset = 0, |
| 581 | .size = 0x4000, |
| 582 | .mask_flags = MTD_WRITEABLE, |
| 583 | }, |
| 584 | [1] = { |
| 585 | .name = "Boot1", |
| 586 | .offset = MTDPART_OFS_APPEND, |
| 587 | .size = 0x40000, |
| 588 | .mask_flags = MTD_WRITEABLE, |
| 589 | }, |
| 590 | [2] = { |
| 591 | .name = "Kernel", |
| 592 | .offset = MTDPART_OFS_APPEND, |
| 593 | .size = 0x300000, |
| 594 | .mask_flags = 0, |
| 595 | }, |
| 596 | [3] = { |
| 597 | .name = "Filesystem", |
| 598 | .offset = MTDPART_OFS_APPEND, |
| 599 | .size = MTDPART_SIZ_FULL, |
| 600 | .mask_flags = 0, |
| 601 | }, |
| 602 | }; |
| 603 | |
| 604 | static struct s3c2410_nand_set rx1950_nand_sets[] = { |
| 605 | [0] = { |
| 606 | .name = "Internal", |
| 607 | .nr_chips = 1, |
| 608 | .nr_partitions = ARRAY_SIZE(rx1950_nand_part), |
| 609 | .partitions = rx1950_nand_part, |
| 610 | }, |
| 611 | }; |
| 612 | |
| 613 | static struct s3c2410_platform_nand rx1950_nand_info = { |
| 614 | .tacls = 25, |
| 615 | .twrph0 = 50, |
| 616 | .twrph1 = 15, |
| 617 | .nr_sets = ARRAY_SIZE(rx1950_nand_sets), |
| 618 | .sets = rx1950_nand_sets, |
| 619 | .ecc_mode = NAND_ECC_SOFT, |
| 620 | }; |
| 621 | |
| 622 | static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = { |
| 623 | .vbus_pin = S3C2410_GPG(5), |
| 624 | .vbus_pin_inverted = 1, |
| 625 | .pullup_pin = S3C2410_GPJ(5), |
| 626 | }; |
| 627 | |
| 628 | static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = { |
| 629 | .delay = 10000, |
| 630 | .presc = 49, |
| 631 | .oversampling_shift = 3, |
| 632 | }; |
| 633 | |
| 634 | static struct gpio_keys_button rx1950_gpio_keys_table[] = { |
| 635 | { |
| 636 | .code = KEY_POWER, |
| 637 | .gpio = S3C2410_GPF(0), |
| 638 | .active_low = 1, |
| 639 | .desc = "Power button", |
| 640 | .wakeup = 1, |
| 641 | }, |
| 642 | { |
| 643 | .code = KEY_F5, |
| 644 | .gpio = S3C2410_GPF(7), |
| 645 | .active_low = 1, |
| 646 | .desc = "Record button", |
| 647 | }, |
| 648 | { |
| 649 | .code = KEY_F1, |
| 650 | .gpio = S3C2410_GPG(0), |
| 651 | .active_low = 1, |
| 652 | .desc = "Calendar button", |
| 653 | }, |
| 654 | { |
| 655 | .code = KEY_F2, |
| 656 | .gpio = S3C2410_GPG(2), |
| 657 | .active_low = 1, |
| 658 | .desc = "Contacts button", |
| 659 | }, |
| 660 | { |
| 661 | .code = KEY_F3, |
| 662 | .gpio = S3C2410_GPG(3), |
| 663 | .active_low = 1, |
| 664 | .desc = "Mail button", |
| 665 | }, |
| 666 | { |
| 667 | .code = KEY_F4, |
| 668 | .gpio = S3C2410_GPG(7), |
| 669 | .active_low = 1, |
| 670 | .desc = "WLAN button", |
| 671 | }, |
| 672 | { |
| 673 | .code = KEY_LEFT, |
| 674 | .gpio = S3C2410_GPG(10), |
| 675 | .active_low = 1, |
| 676 | .desc = "Left button", |
| 677 | }, |
| 678 | { |
| 679 | .code = KEY_RIGHT, |
| 680 | .gpio = S3C2410_GPG(11), |
| 681 | .active_low = 1, |
| 682 | .desc = "Right button", |
| 683 | }, |
| 684 | { |
| 685 | .code = KEY_UP, |
| 686 | .gpio = S3C2410_GPG(4), |
| 687 | .active_low = 1, |
| 688 | .desc = "Up button", |
| 689 | }, |
| 690 | { |
| 691 | .code = KEY_DOWN, |
| 692 | .gpio = S3C2410_GPG(6), |
| 693 | .active_low = 1, |
| 694 | .desc = "Down button", |
| 695 | }, |
| 696 | { |
| 697 | .code = KEY_ENTER, |
| 698 | .gpio = S3C2410_GPG(9), |
| 699 | .active_low = 1, |
| 700 | .desc = "Ok button" |
| 701 | }, |
| 702 | }; |
| 703 | |
| 704 | static struct gpio_keys_platform_data rx1950_gpio_keys_data = { |
| 705 | .buttons = rx1950_gpio_keys_table, |
| 706 | .nbuttons = ARRAY_SIZE(rx1950_gpio_keys_table), |
| 707 | }; |
| 708 | |
| 709 | static struct platform_device rx1950_device_gpiokeys = { |
| 710 | .name = "gpio-keys", |
| 711 | .dev.platform_data = &rx1950_gpio_keys_data, |
| 712 | }; |
| 713 | |
| 714 | static struct uda1380_platform_data uda1380_info = { |
| 715 | .gpio_power = S3C2410_GPJ(0), |
| 716 | .gpio_reset = S3C2410_GPD(0), |
| 717 | .dac_clk = UDA1380_DAC_CLK_SYSCLK, |
| 718 | }; |
| 719 | |
| 720 | static struct i2c_board_info rx1950_i2c_devices[] = { |
| 721 | { |
| 722 | I2C_BOARD_INFO("uda1380", 0x1a), |
| 723 | .platform_data = &uda1380_info, |
| 724 | }, |
| 725 | }; |
| 726 | |
| 727 | static struct platform_device *rx1950_devices[] __initdata = { |
| 728 | &s3c2410_device_dclk, |
| 729 | &s3c_device_lcd, |
| 730 | &s3c_device_wdt, |
| 731 | &s3c_device_i2c0, |
| 732 | &s3c_device_iis, |
| 733 | &s3c_device_usbgadget, |
| 734 | &s3c_device_rtc, |
| 735 | &s3c_device_nand, |
| 736 | &s3c_device_sdi, |
| 737 | &s3c_device_adc, |
| 738 | &s3c_device_ts, |
| 739 | &samsung_device_pwm, |
| 740 | &rx1950_backlight, |
| 741 | &rx1950_device_gpiokeys, |
| 742 | &power_supply, |
| 743 | &rx1950_battery, |
| 744 | &rx1950_leds, |
| 745 | }; |
| 746 | |
| 747 | static void __init rx1950_map_io(void) |
| 748 | { |
| 749 | s3c24xx_init_io(rx1950_iodesc, ARRAY_SIZE(rx1950_iodesc)); |
| 750 | s3c24xx_init_uarts(rx1950_uartcfgs, ARRAY_SIZE(rx1950_uartcfgs)); |
| 751 | samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4); |
| 752 | |
| 753 | /* setup PM */ |
| 754 | |
| 755 | #ifdef CONFIG_PM_H1940 |
| 756 | memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 8); |
| 757 | #endif |
| 758 | |
| 759 | s3c_pm_init(); |
| 760 | } |
| 761 | |
| 762 | static void __init rx1950_init_time(void) |
| 763 | { |
| 764 | s3c2442_init_clocks(16934000); |
| 765 | samsung_timer_init(); |
| 766 | } |
| 767 | |
| 768 | static void __init rx1950_init_machine(void) |
| 769 | { |
| 770 | int i; |
| 771 | |
| 772 | s3c24xx_fb_set_platdata(&rx1950_lcd_cfg); |
| 773 | s3c24xx_udc_set_platdata(&rx1950_udc_cfg); |
| 774 | s3c24xx_ts_set_platdata(&rx1950_ts_cfg); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 775 | gpiod_add_lookup_table(&rx1950_mmc_gpio_table); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 776 | s3c24xx_mci_set_platdata(&rx1950_mmc_cfg); |
| 777 | s3c_i2c0_set_platdata(NULL); |
| 778 | s3c_nand_set_platdata(&rx1950_nand_info); |
| 779 | |
| 780 | /* Turn off suspend on both USB ports, and switch the |
| 781 | * selectable USB port to USB device mode. */ |
| 782 | s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST | |
| 783 | S3C2410_MISCCR_USBSUSPND0 | |
| 784 | S3C2410_MISCCR_USBSUSPND1, 0x0); |
| 785 | |
| 786 | /* mmc power is disabled by default */ |
| 787 | WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power")); |
| 788 | gpio_direction_output(S3C2410_GPJ(1), 0); |
| 789 | |
| 790 | for (i = 0; i < 8; i++) |
| 791 | WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power")); |
| 792 | |
| 793 | for (i = 10; i < 16; i++) |
| 794 | WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power")); |
| 795 | |
| 796 | for (i = 2; i < 8; i++) |
| 797 | WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power")); |
| 798 | |
| 799 | for (i = 11; i < 16; i++) |
| 800 | WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power")); |
| 801 | |
| 802 | WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power")); |
| 803 | |
| 804 | WARN_ON(gpio_request(S3C2410_GPA(3), "Red blink")); |
| 805 | WARN_ON(gpio_request(S3C2410_GPA(4), "Green blink")); |
| 806 | WARN_ON(gpio_request(S3C2410_GPJ(6), "LED blink")); |
| 807 | gpio_direction_output(S3C2410_GPA(3), 0); |
| 808 | gpio_direction_output(S3C2410_GPA(4), 0); |
| 809 | gpio_direction_output(S3C2410_GPJ(6), 0); |
| 810 | |
| 811 | pwm_add_table(rx1950_pwm_lookup, ARRAY_SIZE(rx1950_pwm_lookup)); |
| 812 | platform_add_devices(rx1950_devices, ARRAY_SIZE(rx1950_devices)); |
| 813 | |
| 814 | i2c_register_board_info(0, rx1950_i2c_devices, |
| 815 | ARRAY_SIZE(rx1950_i2c_devices)); |
| 816 | } |
| 817 | |
| 818 | /* H1940 and RX3715 need to reserve this for suspend */ |
| 819 | static void __init rx1950_reserve(void) |
| 820 | { |
| 821 | memblock_reserve(0x30003000, 0x1000); |
| 822 | memblock_reserve(0x30081000, 0x1000); |
| 823 | } |
| 824 | |
| 825 | MACHINE_START(RX1950, "HP iPAQ RX1950") |
| 826 | /* Maintainers: Vasily Khoruzhick */ |
| 827 | .atag_offset = 0x100, |
| 828 | .map_io = rx1950_map_io, |
| 829 | .reserve = rx1950_reserve, |
| 830 | .init_irq = s3c2442_init_irq, |
| 831 | .init_machine = rx1950_init_machine, |
| 832 | .init_time = rx1950_init_time, |
| 833 | MACHINE_END |