1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 5773374..b4d917a 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -58,7 +58,6 @@
 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
 #include "disk.h"
 #include "adc.h"
-#include "power.h"
 #include "usb.h"
 #include "rtc.h"
 #include "storage.h"
@@ -75,6 +74,7 @@
 #include "radio.h"
 #endif
 #endif
+#include "power.h"
 
 #ifdef HAVE_LCD_BITMAP
 #include "scrollbar.h"
@@ -900,7 +900,7 @@ static bool tsc2100_debug(void)
     return simplelist_show_list(&info);
 }
 #endif
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
 #ifdef HAVE_LCD_BITMAP
 /*
  * view_battery() shows a automatically scaled graph of the battery voltage
@@ -2168,7 +2168,7 @@ static const struct the_menu_item menuitems[] = {
         { "View CPU stats", dbg_cpuinfo },
 #endif
 #ifdef HAVE_LCD_BITMAP
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
         { "View battery", view_battery },
 #endif
 #ifndef APPLICATION
diff --git a/apps/plugin.c b/apps/plugin.c
index 6dd84af..f17ad3c 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -664,7 +664,7 @@ static const struct plugin_api rockbox_api = {
     battery_level,
     battery_level_safe,
     battery_time,
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
     battery_voltage,
 #endif
 #if CONFIG_CHARGING
diff --git a/apps/plugin.h b/apps/plugin.h
index 3644e64..0bb7262 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -794,7 +794,7 @@ struct plugin_api {
     int (*battery_level)(void);
     bool (*battery_level_safe)(void);
     int (*battery_time)(void);
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
     unsigned int (*battery_voltage)(void);
 #endif
 #if CONFIG_CHARGING
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 387f145..1b14c0d 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -1,4 +1,7 @@
 /* plugins common to all models */
+#ifndef SIMULATOR
+battery_bench.c
+#endif
 chessclock.c
 credits.c
 cube.c
@@ -116,8 +119,6 @@ iriver_flash.c
 rockbox_flash.c
 #endif /* CONFIG_CPU */
 
-battery_bench.c
-
 #if defined(IPOD_NANO2G)
 crypt_firmware.c
 #endif
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index 302d74c..bf40fe1 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -414,7 +414,9 @@ static void thread(void)
             bat[buf_idx].flags = charge_state();
 #endif
             buf_idx++;
+#if USING_STORAGE_CALLBACK
             rb->register_storage_idle_func(flush_buffer);
+#endif
         }
         
         /* What to do when the measurement buffer is full:
@@ -454,8 +456,12 @@ static void thread(void)
         }
     }
 
+#if USING_STORAGE_CALLBACK
     /* unregister flush callback and flush to disk */
     rb->unregister_storage_idle_func(flush_buffer, true);
+#else
+    flush_buffer(NULL);
+#endif
     
     /* log end of bench and exit reason */
     fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND, 0666);
diff --git a/firmware/SOURCES b/firmware/SOURCES
index e80a749..46ef51b 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -13,8 +13,8 @@ powermgmt.c
 target/hosted/cpuinfo-linux.c
 #endif
 
-target/hosted/powermgmt.c
 #ifndef SAMSUNG_YPR0 /* uses as3514 rtc */
+target/hosted/powermgmt.c
 target/hosted/rtc.c
 #endif
 #endif
diff --git a/firmware/export/config/samsungypr0.h b/firmware/export/config/samsungypr0.h
index 25e1906..8d133c4 100644
--- a/firmware/export/config/samsungypr0.h
+++ b/firmware/export/config/samsungypr0.h
@@ -21,7 +21,7 @@
 #define USB_NONE
 
 /* Hardware controlled charging with monitoring */
-//#define CONFIG_CHARGING CHARGING_MONITOR
+#define CONFIG_CHARGING CHARGING_MONITOR
 
 /* There is only USB charging */
 //#define HAVE_USB_POWER
@@ -127,16 +127,16 @@
 
 /* Define current usage levels. */
 /* TODO: to be filled with correct values after implementing power management */
-#define CURRENT_NORMAL     88 /* 18 hours from a 1600 mAh battery */
-#define CURRENT_BACKLIGHT  30 /* TBD */
-#define CURRENT_RECORD     0  /* no recording yet */
+//#define CURRENT_NORMAL     88 /* 18 hours from a 1600 mAh battery */
+//#define CURRENT_BACKLIGHT  30 /* TBD */
+//#define CURRENT_RECORD     0  /* no recording yet */
 
 /* TODO: We need to do battery handling */
-//#define BATTERY_CAPACITY_DEFAULT 600 /* default battery capacity */
-//#define BATTERY_CAPACITY_MIN 600  /* min. capacity selectable */
-//#define BATTERY_CAPACITY_MAX 700 /* max. capacity selectable */
-//#define BATTERY_CAPACITY_INC 50   /* capacity increment */
-//#define BATTERY_TYPES_COUNT  1    /* only one type */
+#define BATTERY_CAPACITY_DEFAULT 600 /* default battery capacity */
+#define BATTERY_CAPACITY_MIN 600  /* min. capacity selectable */
+#define BATTERY_CAPACITY_MAX 600 /* max. capacity selectable */
+#define BATTERY_CAPACITY_INC 0   /* capacity increment */
+#define BATTERY_TYPES_COUNT  1    /* only one type */
 
 /* TODO: We possibly can only watch linux charging */
 //#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/power.h b/firmware/export/power.h
index d46b9ba..4937705 100644
--- a/firmware/export/power.h
+++ b/firmware/export/power.h
@@ -23,6 +23,7 @@
 
 #include "config.h"
 
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
 #if CONFIG_CHARGING
 enum power_input_flags {
     /* No external power source? Default. */
@@ -100,4 +101,6 @@ bool tuner_power(bool status);
 bool tuner_powered(void);
 #endif
 
+#endif
+
 #endif /* _POWER_H_ */
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 808c858..11dd067 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -78,7 +78,7 @@ extern unsigned int power_thread_inputs;
 /* Start up power management thread */
 void powermgmt_init(void) INIT_ATTR;
 
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
 
 /* Generic current values that are intentionally meaningless - config header
  * should define proper numbers.*/
diff --git a/firmware/export/storage.h b/firmware/export/storage.h
index 58d8d32..6c875bc 100644
--- a/firmware/export/storage.h
+++ b/firmware/export/storage.h
@@ -71,7 +71,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; }
 
         #define storage_enable(on)
         #define storage_sleepnow()
-        #define storage_disk_is_active()
+        #define storage_disk_is_active() 0
         #define storage_soft_reset()
         #define storage_init()
         #define storage_close()
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 76322d6..7c6b83c 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -82,7 +82,7 @@ void handle_auto_poweroff(void);
 static int poweroff_timeout = 0;
 static long last_event_tick = 0;
 
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
 /*
  * Average battery voltage and charger voltage, filtered via a digital
  * exponential filter (aka. exponential moving average, scaled):
@@ -104,7 +104,7 @@ static int battery_type = 0;
 /* Power history: power_history[0] is the newest sample */
 unsigned short power_history[POWER_HISTORY_LEN] = {0};
 
-#if CONFIG_CPU == JZ4732 /* FIXME! */
+#if CONFIG_CPU == JZ4732 /* FIXME! */ || (CONFIG_PLATFORM & PLATFORM_HOSTED)
 static char power_stack[DEFAULT_STACK_SIZE + POWERMGMT_DEBUG_STACK];
 #else
 static char power_stack[DEFAULT_STACK_SIZE/2 + POWERMGMT_DEBUG_STACK];
diff --git a/firmware/target/hosted/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
index 5701e9f..3a97331 100644
--- a/firmware/target/hosted/ypr0/powermgmt-ypr0.c
+++ b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
@@ -17,117 +17,72 @@
  *
  ****************************************************************************/
 #include "config.h"
-#include "system.h"
-#include <time.h>
+#include <sys/ioctl.h>
 #include "kernel.h"
 #include "powermgmt.h"
+#include "power.h"
+#include "file.h"
 #include "ascodec-target.h"
-#include "stdio.h"
+#include "as3514.h"
+#include "sc900776.h"
 
-#if 0 /*still unused*/
-/* The battery manufacturer's website shows discharge curves down to 3.0V,
-   so 'dangerous' and 'shutoff' levels of 3.4V and 3.3V should be safe.
- */
 const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
 {
-    3550
+    3500
 };
 
+/* the OF shuts down at this voltage */
 const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
 {
     3450
 };
 
 /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
+/* FIXME: This is guessed. Make proper curve using battery_bench */
 const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
 {
-    { 3300, 3692, 3740, 3772, 3798, 3828, 3876, 3943, 4013, 4094, 4194 }
+    { 3450, 3692, 3740, 3772, 3798, 3828, 3876, 3943, 4013, 4094, 4194 }
 };
 
 #if CONFIG_CHARGING
 /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
-const unsigned short percent_to_volt_charge[11] =
+/* FIXME: This is guessed. Make proper curve using battery_bench */
+const unsigned short const percent_to_volt_charge[11] =
 {
-    3417, 3802, 3856, 3888, 3905, 3931, 3973, 4025, 4084, 4161, 4219
+    3600, 3802, 3856, 3888, 3905, 3931, 3973, 4025, 4084, 4161, 4219
 };
-#endif /* CONFIG_CHARGING */
-#endif
-
-#define BATT_MINMVOLT   3450      /* minimum millivolts of battery */
-#define BATT_MAXMVOLT   4150      /* maximum millivolts of battery */
-#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
-                                     minutes */
-
-extern void send_battery_level_event(void);
-extern int last_sent_battery_level;
-extern int battery_percent;
-
-static unsigned int battery_millivolts = BATT_MAXMVOLT;
-/* estimated remaining time in minutes */
-static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
 
-static void battery_status_update(void)
+unsigned int power_input_status(void)
 {
-    static time_t last_change = 0;
-    time_t now;
-
-    time(&now);
-
-    if (last_change < now) {
-        last_change = now;
-
-        battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
-                            (BATT_MAXMVOLT - BATT_MINMVOLT);
-
-        powermgmt_est_runningtime_min =
-            battery_percent * BATT_MAXRUNTIME / 100;
+    unsigned status = POWER_INPUT_NONE;
+    int fd = open("/dev/minivet", O_RDONLY);
+    if (fd >= 0)
+    {
+        if (ioctl(fd, IOCTL_MINIVET_DET_VBUS, NULL) > 0)
+            status = POWER_INPUT_MAIN_CHARGER;
+        close(fd);
     }
-
-    send_battery_level_event();
+    return status;
 }
 
-void battery_read_info(int *voltage, int *level)
-{
-    battery_status_update();
-
-    if (voltage)
-        *voltage = battery_millivolts;
-
-    if (level)
-        *level = battery_percent;
-}
-
-unsigned int battery_voltage(void)
-{
-    battery_status_update();
-    return battery_millivolts;
-}
-
-int battery_level(void)
-{
-    battery_status_update();
-    return battery_percent;
-}
-
-int battery_time(void)
-{
-    battery_status_update();
-    return powermgmt_est_runningtime_min;
-}
+#endif /* CONFIG_CHARGING */
 
-bool battery_level_safe(void)
-{
-    return battery_level() >= 10;
-}
 
-void set_battery_capacity(int capacity)
+/* Returns battery voltage from ADC [millivolts],
+ * adc returns voltage in 5mV steps */
+unsigned int battery_adc_voltage(void)
 {
-  (void)capacity;
+    return adc_read(3) * 5;
 }
 
-#if BATTERY_TYPES_COUNT > 1
-void set_battery_type(int type)
+bool charging_state(void)
 {
-    (void)type;
+    /* cannot make this static (initializer not constant error), but gcc
+     * seems to calculate at compile time anyway */
+    const unsigned short charged_thres =
+        ((percent_to_volt_charge[9] + percent_to_volt_charge[10]) / 2);
+
+    bool ret = (power_input_status() == POWER_INPUT_MAIN_CHARGER);
+    /* dont indicate for > ~95% */
+    return ret && (battery_adc_voltage() <= charged_thres);
 }
-#endif
diff --git a/firmware/target/hosted/ypr0/sc900776.h b/firmware/target/hosted/ypr0/sc900776.h
new file mode 100644
index 0000000..32eb90f
--- /dev/null
+++ b/firmware/target/hosted/ypr0/sc900776.h
@@ -0,0 +1,134 @@
+/* This file originates from the linux kernel provided in Samsung's YP-R0 Open
+ * Source package.
+ */
+
+/*
+* Bigbang project
+* Copyright (c) 2009 VPS R&D Group, Samsung Electronics, Inc.
+* All rights reserved.
+*/
+
+/**
+* This file defines data structures and APIs for Freescale SC900776
+*
+* @name    sc900776.h
+* @author  Eung Chan Kim (eungc[email protected])
+* @version 0.1
+* @see
+*/
+
+#ifndef __SC900776_H__
+#define __SC900776_H__
+
+
+typedef enum
+{
+	SC900776_DEVICE_ID = 0x01,		/* 01h		R   */
+	SC900776_CONTROL,				/* 02h		R/W */
+	SC900776_INTERRUPT1,			/* 03h		R/C */
+	SC900776_INTERRUPT2,			/* 04h		R/C */
+	SC900776_INTERRUPT_MASK1,		/* 05h		R/W */
+	SC900776_INTERRUPT_MASK2,		/* 06h		R/W */
+	SC900776_ADC_RESULT,			/* 07h		R   */
+	SC900776_TIMING_SET1,			/* 08h		R/W */
+	SC900776_TIMING_SET2,			/* 09h		R/W */
+	SC900776_DEVICE_TYPE1,			/* 0Ah		R   */
+	SC900776_DEVICE_TYPE2,			/* 0Bh		R   */
+	SC900776_BUTTON1,				/* 0Ch		R/C */
+	SC900776_BUTTON2,				/* 0Dh		R/C */
+	/* 0Eh ~ 12h : reserved */
+	SC900776_MANUAL_SWITCH1 = 0x13,	/* 13h		R/W */
+	SC900776_MANUAL_SWITCH2, 		/* 14h		R/W */
+	/* 15h ~ 1Fh : reserved */
+	SC900776_FSL_STATUS = 0x20, 	/* 20h		R   */
+	SC900776_FSL_CONTROL,			/* 21h		R/W */
+	SC900776_TIME_DELAY,			/* 22h		R/W */
+	SC900776_DEVICE_MODE,			/* 23h		R/W */
+
+	SC900776_REG_MAX
+} eSc900776_register_t;
+
+typedef enum
+{
+	DEVICETYPE1_UNDEFINED = 0,
+	DEVICETYPE1_USB,				// 0x04 0x00	// normal usb cable & ad200
+	DEVICETYPE1_DEDICATED, 			// 0x40 0x00	// dedicated charger cable
+	DEVICETYPE2_JIGUARTON,			// 0x00 0x08	// Anygate_UART jig
+	DEVICETYPE2_JIGUSBOFF,			// 0x00 0x01	// USB jig(AS center)
+	DEVICETYPE2_JIGUSBON,			// 0x00 0x02    // Anygate_USB jig with boot-on, not tested
+} eMinivet_device_t;
+
+/*
+ * sc900776 register bit definitions
+ */
+#define MINIVET_DEVICETYPE1_USBOTG 		0x80	/* 1: a USBOTG device is attached */
+#define MINIVET_DEVICETYPE1_DEDICATED 	0x40	/* 1: a dedicated charger is attached */
+#define MINIVET_DEVICETYPE1_USBCHG 		0x20	/* 1: a USB charger is attached */
+#define MINIVET_DEVICETYPE1_5WCHG 		0x10	/* 1: a 5-wire charger (type 1 or 2) is attached */
+#define MINIVET_DEVICETYPE1_UART 		0x08	/* 1: a UART cable is attached */
+#define MINIVET_DEVICETYPE1_USB 		0x04	/* 1: a USB host is attached */
+#define MINIVET_DEVICETYPE1_AUDIO2 		0x02	/* 1: an audio accessory type 2 is attached */
+#define MINIVET_DEVICETYPE1_AUDIO1 		0x01	/* 1: an audio accessory type 1 is attached */
+
+#define MINIVET_DEVICETYPE2_AV			0x40	/* 1: an audio/video cable is attached */
+#define MINIVET_DEVICETYPE2_TTY			0x20	/* 1: a TTY converter is attached */
+#define MINIVET_DEVICETYPE2_PPD			0x10	/* 1: a phone powered device is attached */
+#define MINIVET_DEVICETYPE2_JIGUARTON 	0x08	/* 1: a UART jig cable with the BOOT-on option is attached */
+#define MINIVET_DEVICETYPE2_JIGUARTOFF 	0x04	/* 1: a UART jig cable with the BOOT-off option is attached */
+#define MINIVET_DEVICETYPE2_JIGUSBON 	0x02	/* 1: a USB jig cable with the BOOT-on option is attached */
+#define MINIVET_DEVICETYPE2_JIGUSBOFF 	0x01	/* 1: a USB jig cable with the BOOT-off option is attached */
+
+#define MINIVET_FSLSTATUS_FETSTATUS		0x40	/* 1: The on status of the power MOSFET */
+#define MINIVET_FSLSTATUS_IDDETEND		0x20	/* 1: ID resistance detection finished */
+#define MINIVET_FSLSTATUS_VBUSDETEND	0x10	/* 1: VBUS power supply type identification completed */
+#define MINIVET_FSLSTATUS_IDGND			0x08	/* 1: ID pin is shorted to ground */
+#define MINIVET_FSLSTATUS_IDFLOAT		0x04	/* 1: ID line is floating */
+#define MINIVET_FSLSTATUS_VBUSDET		0x02	/* 1: VBUS voltage is higher than the POR */
+#define MINIVET_FSLSTATUS_ADCSTATUS		0x01	/* 1: ADC conversion completed */
+
+
+#define SC900776_I2C_SLAVE_ADDR			0x25
+
+typedef struct {
+	unsigned char addr;
+	unsigned char value;
+}__attribute__((packed)) sMinivet_t;
+
+
+#define DRV_IOCTL_MINIVET_MAGIC		'M'
+
+
+typedef enum
+{
+	E_IOCTL_MINIVET_INIT = 0,
+	E_IOCTL_MINIVET_WRITE_BYTE,
+	E_IOCTL_MINIVET_READ_BYTE,
+	E_IOCTL_MINIVET_DET_VBUS,
+	E_IOCTL_MINIVET_MANUAL_USB,
+	E_IOCTL_MINIVET_MANUAL_UART,
+
+	E_IOCTL_MINIVET_MAX
+} eSc900776_ioctl_t;
+
+#define IOCTL_MINIVET_INIT 			_IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_INIT)
+#define IOCTL_MINIVET_WRITE_BYTE 	_IOW(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_WRITE_BYTE, sMinivet_t)
+#define IOCTL_MINIVET_READ_BYTE 	_IOR(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_READ_BYTE, sMinivet_t)
+#define IOCTL_MINIVET_DET_VBUS 		_IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_DET_VBUS)
+#define IOCTL_MINIVET_MANUAL_USB 	_IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_MANUAL_USB)
+#define IOCTL_MINIVET_MANUAL_UART 	_IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_MANUAL_UART)
+
+
+#ifndef __MINIVET_ENUM__
+#define __MINIVET_ENUM__
+enum
+{
+	EXT_PWR_UNPLUGGED = 0,
+	EXT_PWR_PLUGGED,
+	EXT_PWR_NOT_OVP,
+	EXT_PWR_OVP,
+};
+
+#endif /* __MINIVET_ENUM__ */
+
+
+#endif /* __MINIVET_IOCTL_H__ */
diff --git a/firmware/target/hosted/ypr0/system-ypr0.c b/firmware/target/hosted/ypr0/system-ypr0.c
index 3a2b303..bf3b1cd 100644
--- a/firmware/target/hosted/ypr0/system-ypr0.c
+++ b/firmware/target/hosted/ypr0/system-ypr0.c
@@ -32,16 +32,11 @@
 
 #include "ascodec-target.h"
 
-void sim_do_exit(void)
-{
-    exit(EXIT_SUCCESS);
-}
-
-void shutdown_hw(void)
+void power_off(void)
 {
     /* Something that we need to do before exit on our platform YPR0 */
     ascodec_close();
-    sim_do_exit();
+    exit(EXIT_SUCCESS);
 }
 
 uintptr_t *stackbegin;
@@ -62,7 +57,7 @@ void system_init(void)
 
 void system_reboot(void)
 {
-    sim_do_exit();
+    power_off();
 }
 
 void system_exception_wait(void)