+ .step_volume = step_volume,
+};
+
+int plat_target_init(void)
+{
+ int rate, timer_div, timer_div2;
+ FILE *f;
+
+ memdev = open("/dev/mem", O_RDWR);
+ if (memdev == -1) {
+ perror("open(/dev/mem) failed");
+ exit(1);
+ }
+
+ memregs = mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED,
+ memdev, 0xc0000000);
+ if (memregs == MAP_FAILED) {
+ perror("mmap(memregs) failed");
+ exit(1);
+ }
+ memregl = (volatile void *)memregs;
+
+ // save video regs of both MLCs
+ save_multiple_regs(saved_video_regs[0], 0x4058, ARRAY_SIZE(saved_video_regs[0]));
+ save_multiple_regs(saved_video_regs[1], 0x4458, ARRAY_SIZE(saved_video_regs[1]));
+
+ /* some firmwares have sys clk on PLL0, we can't adjust CPU clock
+ * by reprogramming the PLL0 then, as it overclocks system bus */
+ if ((memregl[0xf000>>2] & 0x03000030) == 0x01000000)
+ cpu_clock_allowed = 1;
+ else {
+ cpu_clock_allowed = 0;
+ fprintf(stderr, "unexpected PLL config (%08x), overclocking disabled\n",
+ memregl[0xf000>>2]);
+ }
+
+ /* find what PLL1 runs at, for the timer */
+ rate = decode_pll(memregl[0xf008>>2]);
+ printf("PLL1 @ %dHz\n", rate);
+
+ /* setup timer */
+ timer_div = (rate + 500000) / 1000000;
+ timer_div2 = 0;
+ while (timer_div > 256) {
+ timer_div /= 2;
+ timer_div2++;
+ }
+ if (1 <= timer_div && timer_div <= 256 && timer_div2 < 4) {
+ int timer_rate = (rate >> timer_div2) / timer_div;
+ if (TIMER_REG(0x08) & 8) {
+ fprintf(stderr, "warning: timer in use, overriding!\n");
+ timer_cleanup();
+ }
+ if (timer_rate != 1000000)
+ fprintf(stderr, "warning: timer drift %d us\n", timer_rate - 1000000);
+
+ timer_div2 = (timer_div2 + 3) & 3;
+ TIMER_REG(0x44) = ((timer_div - 1) << 4) | 2; /* using PLL1 */
+ TIMER_REG(0x40) = 0x0c; /* clocks on */
+ TIMER_REG(0x08) = 0x68 | timer_div2; /* run timer, clear irq, latch value */
+ }
+ else
+ fprintf(stderr, "warning: could not make use of timer\n");
+
+ battdev = open("/dev/pollux_batt", O_RDONLY);
+ if (battdev < 0)
+ perror("Warning: could't open pollux_batt");
+
+ f = fopen("/dev/accel", "rb");
+ if (f) {
+ printf("detected Caanoo\n");
+ gp2x_dev_id = GP2X_DEV_CAANOO;
+ fclose(f);
+ }
+ else {
+ printf("detected Wiz\n");
+ gp2x_dev_id = GP2X_DEV_WIZ;
+ }
+
+ mixerdev = open("/dev/mixer", O_RDWR);
+ if (mixerdev == -1)
+ perror("open(/dev/mixer)");
+
+ return 0;
+}
+
+/* to be called after in_probe */
+void plat_target_setup_input(void)
+{
+}
+
+void plat_target_finish(void)
+{
+ timer_cleanup();
+
+ restore_multiple_regs(0x4058, saved_video_regs[0],
+ ARRAY_SIZE(saved_video_regs[0]));
+ restore_multiple_regs(0x4458, saved_video_regs[1],
+ ARRAY_SIZE(saved_video_regs[1]));
+ memregl[0x4058>>2] |= 0x10;
+ memregl[0x4458>>2] |= 0x10;
+
+ if (battdev >= 0)
+ close(battdev);
+ if (mixerdev >= 0)
+ close(mixerdev);
+ munmap((void *)memregs, 0x20000);
+ close(memdev);
+}