rk2928: a720: cpufreq(1G) && pmic sleep io && backlight && gsensor
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2928 / board-rk2928-a720.c
1 /* arch/arm/mach-rk2928/board-rk2928-fpga.c
2  *
3  * Copyright (C) 2012 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/skbuff.h>
24 #include <linux/spi/spi.h>
25 #include <linux/mmc/host.h>
26 #include <linux/ion.h>
27 #include <linux/cpufreq.h>
28 #include <linux/clk.h>
29
30 #include <asm/setup.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/flash.h>
35 #include <asm/hardware/gic.h>
36 #include <mach/dvfs.h>
37
38 #include <mach/board.h>
39 #include <mach/hardware.h>
40 #include <mach/io.h>
41 #include <mach/gpio.h>
42 #include <mach/iomux.h>
43 #include <linux/fb.h>
44 #include <linux/regulator/machine.h>
45 #include <linux/rfkill-rk.h>
46 #include <linux/sensor-dev.h>
47 #include <linux/mfd/tps65910.h>
48 #include <linux/regulator/rk29-pwm-regulator.h>
49 #if defined(CONFIG_HDMI_RK30)
50         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
51 #endif
52
53 #if defined(CONFIG_SPIM_RK29)
54 #include "../../../drivers/spi/rk29_spim.h"
55 #endif
56
57 #include "board-rk2928-a720-key.c"
58
59 #ifdef  CONFIG_THREE_FB_BUFFER
60 #define RK30_FB0_MEM_SIZE 12*SZ_1M
61 #else
62 #define RK30_FB0_MEM_SIZE 8*SZ_1M
63 #endif
64
65 static struct spi_board_info board_spi_devices[] = {
66 };
67
68 /***********************************************************
69 *       rk30  backlight
70 ************************************************************/
71 #ifdef CONFIG_BACKLIGHT_RK29_BL
72 #define PWM_ID            0
73 #define PWM_MUX_NAME      GPIO0D2_PWM_0_NAME
74 #define PWM_MUX_MODE      GPIO0D_PWM_0
75 #define PWM_MUX_MODE_GPIO GPIO0D_GPIO0D2
76 #define PWM_GPIO          RK2928_PIN0_PD2
77 #define PWM_EFFECT_VALUE  0
78
79 #define LCD_DISP_ON_PIN
80
81 #ifdef  LCD_DISP_ON_PIN
82
83 #define BL_EN_PIN         RK2928_PIN1_PB0
84 #define BL_EN_VALUE       GPIO_HIGH
85 #endif
86 static int rk29_backlight_io_init(void)
87 {
88         int ret = 0;
89         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
90 #ifdef  LCD_DISP_ON_PIN
91         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
92
93         ret = gpio_request(BL_EN_PIN, NULL);
94         if (ret != 0) {
95                 gpio_free(BL_EN_PIN);
96         }
97
98         gpio_direction_output(BL_EN_PIN, 0);
99         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
100 #endif
101         return ret;
102 }
103
104 static int rk29_backlight_io_deinit(void)
105 {
106         int ret = 0;
107 #ifdef  LCD_DISP_ON_PIN
108         gpio_free(BL_EN_PIN);
109 #endif
110         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
111         return ret;
112 }
113
114 static int rk29_backlight_pwm_suspend(void)
115 {
116         int ret = 0;
117         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
118         if (gpio_request(PWM_GPIO, NULL)) {
119                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
120                 return -1;
121         }
122         gpio_direction_output(PWM_GPIO, GPIO_LOW);
123 #ifdef  LCD_DISP_ON_PIN
124         gpio_direction_output(BL_EN_PIN, 0);
125         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
126 #endif
127
128         return ret;
129 }
130
131 static int rk29_backlight_pwm_resume(void)
132 {
133         gpio_free(PWM_GPIO);
134         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
135 #ifdef  LCD_DISP_ON_PIN
136         msleep(30);
137         gpio_direction_output(BL_EN_PIN, 1);
138         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
139 #endif
140         return 0;
141 }
142
143 static struct rk29_bl_info rk29_bl_info = {
144         .pwm_id = PWM_ID,
145         .bl_ref = PWM_EFFECT_VALUE,
146         .io_init = rk29_backlight_io_init,
147         .io_deinit = rk29_backlight_io_deinit,
148         .pwm_suspend = rk29_backlight_pwm_suspend,
149         .pwm_resume = rk29_backlight_pwm_resume,
150 };
151
152 static struct platform_device rk29_device_backlight = {
153         .name   = "rk29_backlight",
154         .id     = -1,
155         .dev    = {
156                 .platform_data  = &rk29_bl_info,
157         }
158 };
159
160 #endif
161
162 #ifdef CONFIG_FB_ROCKCHIP
163
164 #define LCD_MUX_NAME  GPIO0C2_UART0_RTSN_NAME
165 #define LCD_GPIO_MODE GPIO0C_GPIO0C2
166
167 #define LCD_EN        RK2928_PIN0_PC2
168 #define LCD_EN_VALUE  GPIO_LOW
169
170 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
171 {
172         int ret = 0;
173
174         rk30_mux_api_set(LCD_MUX_NAME, LCD_GPIO_MODE);
175
176         ret = gpio_request(LCD_EN, NULL);
177         if (ret != 0)
178         {
179                 gpio_free(LCD_EN);
180                 printk(KERN_ERR "request lcd en pin fail!\n");
181                 return -1;
182         }
183         else
184         {
185                 gpio_direction_output(LCD_EN, LCD_EN_VALUE); //disable
186         }
187         return 0;
188 }
189 static int rk_fb_io_disable(void)
190 {
191         gpio_set_value(LCD_EN, !LCD_EN_VALUE);
192         return 0;
193 }
194 static int rk_fb_io_enable(void)
195 {
196         gpio_set_value(LCD_EN, LCD_EN_VALUE);
197         return 0;
198 }
199
200 #if defined(CONFIG_LCDC_RK2928)
201 struct rk29fb_info lcdc_screen_info = {
202         .prop      = PRMRY,             //primary display device
203         .io_init   = rk_fb_io_init,
204         .io_disable = rk_fb_io_disable,
205         .io_enable = rk_fb_io_enable,
206         .set_screen_info = set_lcd_info,
207 };
208 #endif
209
210 static struct resource resource_fb[] = {
211         [0] = {
212                 .name  = "fb0 buf",
213                 .start = 0,
214                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
215                 .flags = IORESOURCE_MEM,
216         },
217         [1] = {
218                 .name  = "ipp buf",  //for rotate
219                 .start = 0,
220                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
221                 .flags = IORESOURCE_MEM,
222         },
223         [2] = {
224                 .name  = "fb2 buf",
225                 .start = 0,
226                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
227                 .flags = IORESOURCE_MEM,
228         },
229 };
230
231 static struct platform_device device_fb = {
232         .name           = "rk-fb",
233         .id             = -1,
234         .num_resources  = ARRAY_SIZE(resource_fb),
235         .resource       = resource_fb,
236 };
237 #endif
238
239 #ifdef CONFIG_ION
240 #define ION_RESERVE_SIZE        (80 * SZ_1M)
241 static struct ion_platform_data rk30_ion_pdata = {
242         .nr = 1,
243         .heaps = {
244                 {
245                         .type = ION_HEAP_TYPE_CARVEOUT,
246                         .id = ION_NOR_HEAP_ID,
247                         .name = "norheap",
248                         .size = ION_RESERVE_SIZE,
249                 }
250         },
251 };
252
253 static struct platform_device device_ion = {
254         .name = "ion-rockchip",
255         .id = 0,
256         .dev = {
257                 .platform_data = &rk30_ion_pdata,
258         },
259 };
260 #endif
261
262 /*MMA7660 gsensor*/
263 #if defined (CONFIG_GS_MMA7660)
264 #define MMA7660_INT_PIN   RK2928_PIN1_PB1
265
266 static int mma7660_init_platform_hw(void)
267 {
268         rk30_mux_api_set(GPIO4C0_SMCDATA0_TRACEDATA0_NAME, GPIO4C_GPIO4C0);
269
270         return 0;
271 }
272
273 static struct sensor_platform_data mma7660_info = {
274         .type = SENSOR_TYPE_ACCEL,
275         .irq_enable = 1,
276         .poll_delay_ms = 30,
277         .init_platform_hw = mma7660_init_platform_hw,
278         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
279 };
280 #endif
281
282
283 #if CONFIG_RK30_PWM_REGULATOR
284 const static int pwm_voltage_map[] = {
285         1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
286 };
287
288 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
289         {
290                 .supply = "vdd_core",
291         }
292 };
293
294 struct regulator_init_data pwm_regulator_init_dcdc[1] =
295 {
296         {
297                 .constraints = {
298                         .name = "PWM_DCDC1",
299                         .min_uV = 600000,
300                         .max_uV = 1800000,      //0.6-1.8V
301                         .apply_uV = true,
302                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
303                 },
304                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
305                 .consumer_supplies = pwm_dcdc1_consumers,
306         },
307 };
308
309 static struct pwm_platform_data pwm_regulator_info[1] = {
310         {
311                 .pwm_id = 2,
312                 .pwm_gpio = RK2928_PIN0_PD4,
313                 .pwm_iomux_name = GPIO0D4_PWM_2_NAME,
314                 .pwm_iomux_pwm = GPIO0D_PWM_2, 
315                 .pwm_iomux_gpio = GPIO0D_GPIO0D4,
316                 .pwm_voltage = 1200000,
317                 .suspend_voltage = 1050000,
318                 .min_uV = 1000000,
319                 .max_uV = 1400000,
320                 .coefficient = 455,     //45.5%
321                 .pwm_voltage_map = pwm_voltage_map,
322                 .init_data      = &pwm_regulator_init_dcdc[0],
323         },
324 };
325
326 struct platform_device pwm_regulator_device[1] = {
327         {
328                 .name = "pwm-voltage-regulator",
329                 .id = 0,
330                 .dev            = {
331                         .platform_data = &pwm_regulator_info[0],
332                 }
333         },
334 };
335 #endif
336
337
338 static struct platform_device *devices[] __initdata = {
339 #ifdef CONFIG_BACKLIGHT_RK29_BL
340         &rk29_device_backlight,
341 #endif
342 #ifdef CONFIG_FB_ROCKCHIP
343         &device_fb,
344 #endif
345 #ifdef CONFIG_ION
346         &device_ion,
347 #endif
348 };
349 //i2c
350 #ifdef CONFIG_I2C0_RK30
351 #ifdef CONFIG_MFD_TPS65910
352 #define TPS65910_HOST_IRQ        RK2928_PIN1_PB2
353 #include "board-rk2928-a720-tps65910.c"
354 #endif
355 static struct i2c_board_info __initdata i2c0_info[] = {
356 #if defined (CONFIG_MFD_TPS65910)
357         {
358         .type           = "tps65910",
359         .addr           = TPS65910_I2C_ID0,
360         .flags          = 0,
361         .irq            = TPS65910_HOST_IRQ,
362         .platform_data = &tps65910_data,
363         },
364 #endif
365 };
366 #endif
367 #ifdef CONFIG_I2C1_RK30
368 static struct i2c_board_info __initdata i2c1_info[] = {
369 #if defined (CONFIG_GS_MMA7660)
370                 {
371                         .type           = "gs_mma7660",
372                         .addr           = 0x4c,
373                         .flags          = 0,
374                         .irq            = MMA7660_INT_PIN,
375                         .platform_data = &mma7660_info,
376                 },
377 #endif
378
379 };
380 #endif
381 #ifdef CONFIG_I2C2_RK30
382 static struct i2c_board_info __initdata i2c2_info[] = {
383 };
384 #endif
385 #ifdef CONFIG_I2C3_RK30
386 static struct i2c_board_info __initdata i2c3_info[] = {
387 };
388 #endif
389 #ifdef CONFIG_I2C_GPIO_RK30
390 #define I2C_SDA_PIN     INVALID_GPIO   //set sda_pin here
391 #define I2C_SCL_PIN     INVALID_GPIO   //set scl_pin here
392 static int rk30_i2c_io_init(void)
393 {
394         //set iomux (gpio) here
395
396         return 0;
397 }
398 struct i2c_gpio_platform_data default_i2c_gpio_data = {
399        .sda_pin = I2C_SDA_PIN,
400        .scl_pin = I2C_SCL_PIN,
401        .udelay = 5, // clk = 500/udelay = 100Khz
402        .timeout = 100,//msecs_to_jiffies(100),
403        .bus_num    = 5,
404        .io_init = rk30_i2c_io_init,
405 };
406 static struct i2c_board_info __initdata i2c_gpio_info[] = {
407 };
408 #endif
409 static void __init rk30_i2c_register_board_info(void)
410 {
411 #ifdef CONFIG_I2C0_RK30
412         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
413 #endif
414 #ifdef CONFIG_I2C1_RK30
415         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
416 #endif
417 #ifdef CONFIG_I2C2_RK30
418         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
419 #endif
420 #ifdef CONFIG_I2C3_RK30
421         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
422 #endif
423 #ifdef CONFIG_I2C_GPIO_RK30
424         i2c_register_board_info(4, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
425 #endif
426 }
427 //end of i2c
428
429 #define POWER_ON_PIN RK2928_PIN1_PA4   //power_hold
430 static void rk2928_pm_power_off(void)
431 {
432         printk(KERN_ERR "rk2928_pm_power_off start...\n");
433         
434         #if defined(CONFIG_MFD_TPS65910)
435                 tps65910_device_shutdown();//tps65910 shutdown
436         #endif
437         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
438         
439 };
440
441 static void __init rk2928_board_init(void)
442 {
443         gpio_request(POWER_ON_PIN, "poweronpin");
444         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
445         gpio_free(POWER_ON_PIN);
446         
447         pm_power_off = rk2928_pm_power_off;
448         
449         rk30_i2c_register_board_info();
450         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
451         platform_add_devices(devices, ARRAY_SIZE(devices));
452
453 }
454
455 static void __init rk2928_reserve(void)
456 {
457 #ifdef CONFIG_ION
458         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
459 #endif
460 #ifdef CONFIG_FB_ROCKCHIP
461         resource_fb[0].start = board_mem_reserve_add("fb0", RK30_FB0_MEM_SIZE);
462         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
463 #endif
464 #ifdef CONFIG_VIDEO_RK29
465         rk30_camera_request_reserve_mem();
466 #endif
467         board_mem_reserved();
468 }
469 /**
470  * dvfs_cpu_logic_table: table for arm and logic dvfs 
471  * @frequency   : arm frequency
472  * @cpu_volt    : arm voltage depend on frequency
473  * @logic_volt  : logic voltage arm requests depend on frequency
474  * comments     : min arm/logic voltage
475  */
476 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
477         {.frequency = 216 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//0.975V/1.000V
478         {.frequency = 312 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//0.975V/1.000V
479         {.frequency = 408 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//1.000V/1.025V
480         {.frequency = 504 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//1.000V/1.025V
481         {.frequency = 600 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//1.025V/1.050V
482         {.frequency = 696 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.000V/1.025V
483         {.frequency = 816 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
484         {.frequency = 912 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
485         {.frequency = 1008 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
486 #if 0
487         {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
488         {.frequency = 1200 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
489         {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
490         {.frequency = 1248 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
491 #endif
492         //{.frequency = 1000 * 1000,    .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},//1.150V/1.100V
493         {.frequency = CPUFREQ_TABLE_END},
494 };
495
496 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
497         {.frequency = 266 * 1000,       .index = 1050 * 1000},
498         {.frequency = 400 * 1000,       .index = 1275 * 1000},
499         {.frequency = CPUFREQ_TABLE_END},
500 };
501
502 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
503         {.frequency = 300 * 1000,       .index = 1050 * 1000},
504         {.frequency = 400 * 1000,       .index = 1125 * 1000},
505         {.frequency = CPUFREQ_TABLE_END},
506 };
507
508 #define DVFS_CPU_TABLE_SIZE     (ARRAY_SIZE(dvfs_cpu_logic_table))
509 static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
510 static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
511
512 void __init board_clock_init(void)
513 {
514         rk2928_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
515         dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
516         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
517         //dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
518         printk("%s end\n", __func__);
519 }
520
521
522 MACHINE_START(RK2928, "RK2928board")
523         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
524         .fixup          = rk2928_fixup,
525         .reserve        = &rk2928_reserve,
526         .map_io         = rk2928_map_io,
527         .init_irq       = rk2928_init_irq,
528         .timer          = &rk2928_timer,
529         .init_machine   = rk2928_board_init,
530 MACHINE_END