diff options
author | Lorenzo Miori <memorys60@gmail.com> | 2013-02-23 16:59:49 +0100 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2013-03-06 00:21:22 +0100 |
commit | 60592165ca998875e4bc46c4396c5a123a7e9dbb (patch) | |
tree | 60b53e6b733fd49bef249761789e97a4bedbef03 /firmware/target/hosted/samsungypr/ypr0 | |
parent | 3e4be68f8b596cf3467f993dc9a210a3d901ca1c (diff) | |
download | rockbox-60592165ca998875e4bc46c4396c5a123a7e9dbb.tar.gz rockbox-60592165ca998875e4bc46c4396c5a123a7e9dbb.zip |
Samsung YP-R0 hosted target code refactoring
As per title this patch aims at splitting common target
code and specific target code in a better way to
support future ports within the same environment
(e.g. Samsung YP-R1 where the Linux and the SoC
are the same, with differences in hardware devices
handling)
Change-Id: I67b4918c46403b184d3d8f42ab5aae7d01037fd0
Reviewed-on: http://gerrit.rockbox.org/409
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
Tested-by: Thomas Martitz <kugel@rockbox.org>
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr0')
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/ascodec-ypr0.c | 167 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/audio-ypr0.c | 69 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c | 88 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/button-target.h | 45 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/button-ypr0.c | 87 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/gpio-target.h | 62 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c | 107 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/r0GPIOIoctl.h | 185 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/sc900776.h | 134 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/system-ypr0.c | 104 | ||||
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr0/ypr0.make | 24 |
11 files changed, 1072 insertions, 0 deletions
diff --git a/firmware/target/hosted/samsungypr/ypr0/ascodec-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/ascodec-ypr0.c new file mode 100644 index 0000000000..24362af0c0 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/ascodec-ypr0.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0 | ||
10 | * | ||
11 | * Copyright (c) 2011-2013 Lorenzo Miori | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | #include "fcntl.h" | ||
24 | #include "unistd.h" | ||
25 | #include "stdio.h" | ||
26 | #include "string.h" | ||
27 | #include "sys/ioctl.h" | ||
28 | #include "stdlib.h" | ||
29 | |||
30 | #include "ascodec.h" | ||
31 | |||
32 | static int afe_dev = -1; | ||
33 | |||
34 | /* Structure used for ioctl module call */ | ||
35 | struct codec_req_struct { | ||
36 | unsigned char reg; /* Main register address */ | ||
37 | unsigned char subreg; /* Set this only if you are reading/writing a PMU register*/ | ||
38 | unsigned char value; /* To be read if reading a register; to be set if writing to a register */ | ||
39 | } __attribute__((packed)); | ||
40 | |||
41 | |||
42 | /* Write to a normal register */ | ||
43 | #define IOCTL_REG_WRITE 0x40034101 | ||
44 | /* Write to a PMU register */ | ||
45 | #define IOCTL_SUBREG_WRITE 0x40034103 | ||
46 | /* Read from a normal register */ | ||
47 | #define IOCTL_REG_READ 0x80034102 | ||
48 | /* Read from a PMU register */ | ||
49 | #define IOCTL_SUBREG_READ 0x80034103 | ||
50 | |||
51 | /* Open device */ | ||
52 | void ascodec_init(void) | ||
53 | { | ||
54 | afe_dev = open("/dev/afe", O_RDWR); | ||
55 | } | ||
56 | |||
57 | /* Close device */ | ||
58 | void ascodec_close(void) | ||
59 | { | ||
60 | if (afe_dev >= 0) | ||
61 | close(afe_dev); | ||
62 | } | ||
63 | |||
64 | /* Write register. | ||
65 | * Returns >= 0 if success, -1 if fail | ||
66 | */ | ||
67 | int ascodec_write(unsigned int reg, unsigned int value) | ||
68 | { | ||
69 | struct codec_req_struct r = { .reg = reg, .value = value }; | ||
70 | return ioctl(afe_dev, IOCTL_REG_WRITE, &r); | ||
71 | } | ||
72 | |||
73 | /* Read register. | ||
74 | * Returns -1 if fail, otherwise the register's value if success | ||
75 | */ | ||
76 | int ascodec_read(unsigned int reg) | ||
77 | { | ||
78 | struct codec_req_struct r = { .reg = reg }; | ||
79 | int retval = ioctl(afe_dev, IOCTL_REG_READ, &r); | ||
80 | if (retval >= 0) | ||
81 | return r.value; | ||
82 | else | ||
83 | return retval; | ||
84 | } | ||
85 | |||
86 | /* Write PMU register */ | ||
87 | void ascodec_write_pmu(unsigned int index, unsigned int subreg, | ||
88 | unsigned int value) | ||
89 | { | ||
90 | struct codec_req_struct r = {.reg = index, .subreg = subreg, .value = value}; | ||
91 | ioctl(afe_dev, IOCTL_SUBREG_WRITE, &r); | ||
92 | } | ||
93 | |||
94 | /* Read PMU register */ | ||
95 | int ascodec_read_pmu(unsigned int index, unsigned int subreg) | ||
96 | { | ||
97 | struct codec_req_struct r = { .reg = index, .subreg = subreg, }; | ||
98 | int retval = ioctl(afe_dev, IOCTL_SUBREG_READ, &r); | ||
99 | if (retval >= 0) | ||
100 | return r.value; | ||
101 | else | ||
102 | return retval; | ||
103 | } | ||
104 | |||
105 | int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data) | ||
106 | { | ||
107 | int i, val, ret = 0; | ||
108 | |||
109 | for (i = 0; i < (int)len; i++) | ||
110 | { | ||
111 | val = ascodec_read(i + index); | ||
112 | if (val >= 0) data[i] = val; | ||
113 | else ret = -1; | ||
114 | } | ||
115 | |||
116 | return (ret ?: (int)len); | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * NOTE: | ||
121 | * After the conversion to interrupts, ascodec_(lock|unlock) are only used by | ||
122 | * adc-as3514.c to protect against other threads corrupting the result by using | ||
123 | * the ADC at the same time. this adc_read() doesn't yield but blocks, so | ||
124 | * lock/unlock is not needed | ||
125 | * | ||
126 | * Additionally, concurrent ascodec_?(read|write) calls are instead protected | ||
127 | * by the R0's Kernel I2C driver for ascodec (mutexed), so it's automatically | ||
128 | * safe | ||
129 | */ | ||
130 | |||
131 | void ascodec_lock(void) | ||
132 | { | ||
133 | } | ||
134 | |||
135 | void ascodec_unlock(void) | ||
136 | { | ||
137 | } | ||
138 | |||
139 | bool ascodec_chg_status(void) | ||
140 | { | ||
141 | return ascodec_read(AS3514_IRQ_ENRD0) & CHG_STATUS; | ||
142 | } | ||
143 | |||
144 | bool ascodec_endofch(void) | ||
145 | { | ||
146 | return ascodec_read(AS3514_IRQ_ENRD0) & CHG_ENDOFCH; | ||
147 | } | ||
148 | |||
149 | void ascodec_monitor_endofch(void) | ||
150 | { | ||
151 | ascodec_write(AS3514_IRQ_ENRD0, IRQ_ENDOFCH); | ||
152 | } | ||
153 | |||
154 | |||
155 | void ascodec_write_charger(int value) | ||
156 | { | ||
157 | ascodec_write_pmu(AS3543_CHARGER, 1, value); | ||
158 | } | ||
159 | |||
160 | int ascodec_read_charger(void) | ||
161 | { | ||
162 | return ascodec_read_pmu(AS3543_CHARGER, 1); | ||
163 | } | ||
164 | |||
165 | void ascodec_wait_adc_finished(void) | ||
166 | { | ||
167 | } | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/audio-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/audio-ypr0.c new file mode 100644 index 0000000000..dfd63ef5cd --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/audio-ypr0.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Bertrik Sikken | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "system.h" | ||
23 | #include "cpu.h" | ||
24 | #include "audio.h" | ||
25 | #include "audiohw.h" | ||
26 | #include "sound.h" | ||
27 | |||
28 | int audio_channels = 2; | ||
29 | int audio_output_source = AUDIO_SRC_PLAYBACK; | ||
30 | |||
31 | void audio_set_output_source(int source) | ||
32 | { | ||
33 | if ((unsigned)source >= AUDIO_NUM_SOURCES) | ||
34 | source = AUDIO_SRC_PLAYBACK; | ||
35 | |||
36 | audio_output_source = source; | ||
37 | } /* audio_set_output_source */ | ||
38 | |||
39 | void audio_input_mux(int source, unsigned flags) | ||
40 | { | ||
41 | static int last_source = AUDIO_SRC_PLAYBACK; | ||
42 | |||
43 | (void)flags; | ||
44 | |||
45 | switch (source) | ||
46 | { | ||
47 | default: /* playback - no recording */ | ||
48 | source = AUDIO_SRC_PLAYBACK; | ||
49 | case AUDIO_SRC_PLAYBACK: | ||
50 | audio_channels = 2; | ||
51 | if (source != last_source) | ||
52 | { | ||
53 | audiohw_set_monitor(false); | ||
54 | |||
55 | } | ||
56 | break; | ||
57 | |||
58 | case AUDIO_SRC_FMRADIO: /* recording and playback */ | ||
59 | audio_channels = 2; | ||
60 | if (source == last_source) | ||
61 | break; | ||
62 | |||
63 | audiohw_set_monitor(true); | ||
64 | break; | ||
65 | } /* end switch */ | ||
66 | |||
67 | last_source = source; | ||
68 | } /* audio_input_mux */ | ||
69 | |||
diff --git a/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c new file mode 100644 index 0000000000..551b386f19 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2011 by Lorenzo Miori | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | #include "config.h" | ||
21 | #include "system.h" | ||
22 | #include "backlight.h" | ||
23 | #include "backlight-target.h" | ||
24 | #include "lcd.h" | ||
25 | #include "as3514.h" | ||
26 | #include "ascodec.h" | ||
27 | #include <fcntl.h> | ||
28 | #include "unistd.h" | ||
29 | |||
30 | static bool backlight_on_status = true; /* Is on or off? */ | ||
31 | |||
32 | /*TODO: see if LCD sleep could be implemented in a better way -> ie using a rockbox feature */ | ||
33 | /* Turn off LCD power supply */ | ||
34 | static void _backlight_lcd_sleep(void) | ||
35 | { | ||
36 | int fp = open("/sys/class/graphics/fb0/blank", O_RDWR); | ||
37 | write(fp, "1", 1); | ||
38 | close(fp); | ||
39 | } | ||
40 | /* Turn on LCD screen */ | ||
41 | static void _backlight_lcd_power(void) | ||
42 | { | ||
43 | int fp = open("/sys/class/graphics/fb0/blank", O_RDWR); | ||
44 | write(fp, "0", 1); | ||
45 | close(fp); | ||
46 | } | ||
47 | |||
48 | bool _backlight_init(void) | ||
49 | { | ||
50 | /* We have nothing to do */ | ||
51 | return true; | ||
52 | } | ||
53 | |||
54 | void _backlight_on(void) | ||
55 | { | ||
56 | if (!backlight_on_status) | ||
57 | { | ||
58 | /* Turn on lcd power before backlight */ | ||
59 | _backlight_lcd_power(); | ||
60 | /* Original app sets this to 0xb1 when backlight is on... */ | ||
61 | ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0xb1); | ||
62 | } | ||
63 | |||
64 | backlight_on_status = true; | ||
65 | |||
66 | } | ||
67 | |||
68 | void _backlight_off(void) | ||
69 | { | ||
70 | if (backlight_on_status) { | ||
71 | /* Disabling the DCDC15 completely, keeps brightness register value */ | ||
72 | ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0x00); | ||
73 | /* Turn off lcd power then */ | ||
74 | _backlight_lcd_sleep(); | ||
75 | } | ||
76 | |||
77 | backlight_on_status = false; | ||
78 | } | ||
79 | |||
80 | void _backlight_set_brightness(int brightness) | ||
81 | { | ||
82 | /* Just another check... */ | ||
83 | if (brightness > MAX_BRIGHTNESS_SETTING) | ||
84 | brightness = MAX_BRIGHTNESS_SETTING; | ||
85 | if (brightness < MIN_BRIGHTNESS_SETTING) | ||
86 | brightness = MIN_BRIGHTNESS_SETTING; | ||
87 | ascodec_write_pmu(AS3543_BACKLIGHT, 0x3, brightness << 3 & 0xf8); | ||
88 | } | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/button-target.h b/firmware/target/hosted/samsungypr/ypr0/button-target.h new file mode 100644 index 0000000000..3a3866932a --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/button-target.h | |||
@@ -0,0 +1,45 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Lorenzo Miori | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _BUTTON_TARGET_H_ | ||
23 | #define _BUTTON_TARGET_H_ | ||
24 | |||
25 | void button_close_device(void); | ||
26 | |||
27 | /* Logical buttons key codes */ | ||
28 | #define BUTTON_UP 0x00000001 | ||
29 | #define BUTTON_DOWN 0x00000002 | ||
30 | #define BUTTON_LEFT 0x00000004 | ||
31 | #define BUTTON_RIGHT 0x00000008 | ||
32 | #define BUTTON_USER 0x00000010 | ||
33 | #define BUTTON_MENU 0x00000020 | ||
34 | #define BUTTON_BACK 0x00000040 | ||
35 | #define BUTTON_POWER 0x00000080 | ||
36 | #define BUTTON_SELECT 0x00000100 | ||
37 | |||
38 | #define BUTTON_MAIN (BUTTON_UP|BUTTON_DOWN|BUTTON_LEFT|BUTTON_RIGHT|BUTTON_USER|BUTTON_MENU|BUTTON_BACK|BUTTON_POWER|BUTTON_SELECT) /* all buttons */ | ||
39 | |||
40 | /* Software power-off */ | ||
41 | #define POWEROFF_BUTTON BUTTON_POWER | ||
42 | /* About 3 seconds */ | ||
43 | #define POWEROFF_COUNT 10 | ||
44 | |||
45 | #endif /* _BUTTON_TARGET_H_ */ | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/button-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/button-ypr0.c new file mode 100644 index 0000000000..e3ad309187 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/button-ypr0.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $ | ||
9 | * | ||
10 | * Copyright (C) 2011 Lorenzo Miori | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "button.h" | ||
24 | #include "kernel.h" | ||
25 | #include "system.h" | ||
26 | #include "button-target.h" | ||
27 | #include <gpio-target.h> /* For headphones sense and buttons */ | ||
28 | |||
29 | int button_read_device(void) | ||
30 | { | ||
31 | int key = BUTTON_NONE; | ||
32 | |||
33 | /* Check for all the keys */ | ||
34 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_USER_KEY, 0, 0)) { | ||
35 | key |= BUTTON_USER; | ||
36 | } | ||
37 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_CENTRAL_KEY, 0, 0)) { | ||
38 | key |= BUTTON_SELECT; | ||
39 | } | ||
40 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_UP_KEY, 0, 0)) { | ||
41 | key |= BUTTON_UP; | ||
42 | } | ||
43 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_DOWN_KEY, 0, 0)) { | ||
44 | key |= BUTTON_DOWN; | ||
45 | } | ||
46 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_LEFT_KEY, 0, 0)) { | ||
47 | key |= BUTTON_LEFT; | ||
48 | } | ||
49 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_RIGHT_KEY, 0, 0)) { | ||
50 | key |= BUTTON_RIGHT; | ||
51 | } | ||
52 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_MENU_KEY, 0, 0)) { | ||
53 | key |= BUTTON_MENU; | ||
54 | } | ||
55 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_BACK_KEY, 0, 0)) { | ||
56 | key |= BUTTON_BACK; | ||
57 | } | ||
58 | if (gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_POWER_KEY, 0, 0)) { | ||
59 | key |= BUTTON_POWER; | ||
60 | } | ||
61 | |||
62 | return key; | ||
63 | } | ||
64 | |||
65 | bool headphones_inserted(void) | ||
66 | { | ||
67 | /* GPIO low - 0 - means headphones inserted */ | ||
68 | return !gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_HEADPHONE_SENSE, 0, 0); | ||
69 | } | ||
70 | |||
71 | void button_init_device(void) | ||
72 | { | ||
73 | /* Setup GPIO pin for headphone sense, copied from OF */ | ||
74 | gpio_control(DEV_CTRL_GPIO_SET_MUX, GPIO_HEADPHONE_SENSE, CONFIG_SION, PAD_CTL_47K_PU); | ||
75 | gpio_control(DEV_CTRL_GPIO_SET_INPUT, GPIO_HEADPHONE_SENSE, CONFIG_SION, PAD_CTL_47K_PU); | ||
76 | |||
77 | /* No need to initialize any GPIO pin, since this is done loading the r0Btn module */ | ||
78 | } | ||
79 | |||
80 | #ifdef BUTTON_DRIVER_CLOSE | ||
81 | /* I'm not sure it's called at shutdown...give a check! */ | ||
82 | void button_close_device(void) | ||
83 | { | ||
84 | /* Don't know the precise meaning, but it's done as in the OF, so copied there */ | ||
85 | gpio_control(DEV_CTRL_GPIO_UNSET_MUX, GPIO_HEADPHONE_SENSE, CONFIG_SION, 0); | ||
86 | } | ||
87 | #endif /* BUTTON_DRIVER_CLOSE */ | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/gpio-target.h b/firmware/target/hosted/samsungypr/ypr0/gpio-target.h new file mode 100644 index 0000000000..3c2033baff --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/gpio-target.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Module wrapper for GPIO, using /dev/r0GPIO (r0Gpio.ko) of Samsung YP-R0 | ||
10 | * | ||
11 | * Copyright (c) 2011 Lorenzo Miori | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | #ifndef GPIO_YPR0_H | ||
24 | #define GPIO_YPR0_H | ||
25 | |||
26 | #include "r0GPIOIoctl.h" | ||
27 | |||
28 | /* Some meaningful pins used in the R0 */ | ||
29 | |||
30 | #define GPIO_HEADPHONE_SENSE GPIO1_5 | ||
31 | #define GPIO_EXT_PWR_SENSE GPIO1_26 | ||
32 | #define GPIO_SD_SENSE GPIO2_27 | ||
33 | #define GPIO_AS3543_INTERUPT GPIO1_25 | ||
34 | #define GPIO_PCB_VER_DETECT GPIO_10 | ||
35 | /* I2C bus for AS3543 codec */ | ||
36 | #define GPIO_I2C_CLK0 GPIO_1_0 | ||
37 | #define GPIO_I2C_DAT0 GPIO_1_1 | ||
38 | /* I2C bus for the SI4079 FM radio chip */ | ||
39 | #define GPIO_I2C_CLK1 GPIO_2_12 | ||
40 | #define GPIO_I2C_DAT1 GPIO_2_13 | ||
41 | #define GPIO_FM_SEARCH GPIO1_4 | ||
42 | #define GPIO_FM_BUS_EN GPIO2_19 | ||
43 | |||
44 | /* Keypad */ | ||
45 | |||
46 | #define GPIO_BACK_KEY GPIO2_29 | ||
47 | #define GPIO_USER_KEY GPIO2_30 | ||
48 | #define GPIO_MENU_KEY GPIO2_31 | ||
49 | #define GPIO_POWER_KEY GPIO2_16 | ||
50 | #define GPIO_CENTRAL_KEY GPIO3_5 | ||
51 | #define GPIO_UP_KEY GPIO3_9 | ||
52 | #define GPIO_DOWN_KEY GPIO3_8 | ||
53 | #define GPIO_LEFT_KEY GPIO2_28 | ||
54 | #define GPIO_RIGHT_KEY GPIO3_7 | ||
55 | |||
56 | |||
57 | void gpio_init(void); | ||
58 | void gpio_close(void); | ||
59 | int gpio_control_struct(int request, R0GPIOInfo pin); | ||
60 | int gpio_control(int request, int num, int mode, int val); | ||
61 | |||
62 | #endif | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c new file mode 100644 index 0000000000..6e04d25f58 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/powermgmt-ypr0.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version 2 | ||
12 | * of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | #include "config.h" | ||
19 | #include <sys/ioctl.h> | ||
20 | #include "kernel.h" | ||
21 | #include "powermgmt.h" | ||
22 | #include "power.h" | ||
23 | #include "file.h" | ||
24 | #include "adc.h" | ||
25 | #include "sc900776.h" | ||
26 | #include "radio-ypr.h" | ||
27 | |||
28 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
29 | { | ||
30 | 3470 | ||
31 | }; | ||
32 | |||
33 | /* the OF shuts down at this voltage */ | ||
34 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
35 | { | ||
36 | 3450 | ||
37 | }; | ||
38 | |||
39 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
40 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
41 | { | ||
42 | { 3450, 3502, 3550, 3587, 3623, 3669, 3742, 3836, 3926, 4026, 4200 } | ||
43 | }; | ||
44 | |||
45 | #if CONFIG_CHARGING | ||
46 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
47 | const unsigned short const percent_to_volt_charge[11] = | ||
48 | { | ||
49 | 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200 | ||
50 | }; | ||
51 | |||
52 | unsigned int power_input_status(void) | ||
53 | { | ||
54 | unsigned status = POWER_INPUT_NONE; | ||
55 | int fd = open("/dev/minivet", O_RDONLY); | ||
56 | if (fd >= 0) | ||
57 | { | ||
58 | if (ioctl(fd, IOCTL_MINIVET_DET_VBUS, NULL) > 0) | ||
59 | status = POWER_INPUT_MAIN_CHARGER; | ||
60 | close(fd); | ||
61 | } | ||
62 | return status; | ||
63 | } | ||
64 | |||
65 | #endif /* CONFIG_CHARGING */ | ||
66 | |||
67 | |||
68 | /* Returns battery voltage from ADC [millivolts], | ||
69 | * adc returns voltage in 5mV steps */ | ||
70 | int _battery_voltage(void) | ||
71 | { | ||
72 | return adc_read(3) * 5; | ||
73 | } | ||
74 | |||
75 | bool charging_state(void) | ||
76 | { | ||
77 | const unsigned short charged_thres = 4170; | ||
78 | bool ret = (power_input_status() == POWER_INPUT_MAIN_CHARGER); | ||
79 | /* dont indicate for > ~95% */ | ||
80 | return ret && (_battery_voltage() <= charged_thres); | ||
81 | } | ||
82 | |||
83 | #if CONFIG_TUNER | ||
84 | static bool tuner_on = false; | ||
85 | |||
86 | bool tuner_power(bool status) | ||
87 | { | ||
88 | if (status != tuner_on) | ||
89 | { | ||
90 | tuner_on = status; | ||
91 | status = !status; | ||
92 | if (tuner_on) { | ||
93 | radiodev_open(); | ||
94 | } | ||
95 | else { | ||
96 | radiodev_close(); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | return status; | ||
101 | } | ||
102 | |||
103 | bool tuner_powered(void) | ||
104 | { | ||
105 | return tuner_on; | ||
106 | } | ||
107 | #endif /* #if CONFIG_TUNER */ \ No newline at end of file | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/r0GPIOIoctl.h b/firmware/target/hosted/samsungypr/ypr0/r0GPIOIoctl.h new file mode 100644 index 0000000000..e77f35fbb7 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/r0GPIOIoctl.h | |||
@@ -0,0 +1,185 @@ | |||
1 | /* This file originates from the linux kernel provided in Samsung's YP-R0 Open | ||
2 | * Source package (second release, which includes some driver modules sources). | ||
3 | */ | ||
4 | |||
5 | #ifndef __IOCTL_GPIO_H__ | ||
6 | #define __IOCTL_GPIO_H__ | ||
7 | |||
8 | #include <sys/ioctl.h> | ||
9 | //#include "iomux.h" | ||
10 | |||
11 | typedef struct { | ||
12 | int num; | ||
13 | int mode; | ||
14 | int val; | ||
15 | }__attribute__((packed)) R0GPIOInfo; | ||
16 | |||
17 | |||
18 | #define IOCTL_GPIO_MAGIC 'G' | ||
19 | |||
20 | #define E_IOCTL_GPIO_SET_MUX 0 | ||
21 | #define E_IOCTL_GPIO_UNSET_MUX 1 | ||
22 | #define E_IOCTL_GPIO_SET_TYPE 2 | ||
23 | #define E_IOCTL_GPIO_SET_OUTPUT 3 | ||
24 | #define E_IOCTL_GPIO_SET_INPUT 4 | ||
25 | #define E_IOCTL_GPIO_SET_HIGH 5 | ||
26 | #define E_IOCTL_GPIO_SET_LOW 6 | ||
27 | #define E_IOCTL_GPIO_GET_VAL 7 | ||
28 | #define E_IOCTL_GPIO_IS_HIGH 8 | ||
29 | #define E_IOCTL_GPIO_MAX_NR 9 | ||
30 | |||
31 | #define DEV_CTRL_GPIO_SET_MUX _IOW(IOCTL_GPIO_MAGIC, 0, R0GPIOInfo) | ||
32 | #define DEV_CTRL_GPIO_UNSET_MUX _IOW(IOCTL_GPIO_MAGIC, 1, R0GPIOInfo) | ||
33 | #define DEV_CTRL_GPIO_SET_TYPE _IOW(IOCTL_GPIO_MAGIC, 2, R0GPIOInfo) | ||
34 | #define DEV_CTRL_GPIO_SET_OUTPUT _IOW(IOCTL_GPIO_MAGIC, 3, R0GPIOInfo) | ||
35 | #define DEV_CTRL_GPIO_SET_INPUT _IOW(IOCTL_GPIO_MAGIC, 4, R0GPIOInfo) | ||
36 | #define DEV_CTRL_GPIO_SET_HIGH _IOW(IOCTL_GPIO_MAGIC, 5, R0GPIOInfo) | ||
37 | #define DEV_CTRL_GPIO_SET_LOW _IOW(IOCTL_GPIO_MAGIC, 6, R0GPIOInfo) | ||
38 | #define DEV_CTRL_GPIO_GET_VAL _IOW(IOCTL_GPIO_MAGIC, 7, R0GPIOInfo) | ||
39 | #define DEV_CTRL_GPIO_IS_HIGH _IOW(IOCTL_GPIO_MAGIC, 8, R0GPIOInfo) | ||
40 | |||
41 | |||
42 | typedef enum | ||
43 | { | ||
44 | GPIO1_0 = 0, /* GPIO group 1 start */ | ||
45 | GPIO1_1, | ||
46 | GPIO1_2, | ||
47 | GPIO1_3, | ||
48 | GPIO1_4, | ||
49 | GPIO1_5, | ||
50 | GPIO1_6, | ||
51 | GPIO1_7, | ||
52 | GPIO1_8, | ||
53 | GPIO1_9, | ||
54 | GPIO1_10, | ||
55 | GPIO1_11, | ||
56 | GPIO1_12, | ||
57 | GPIO1_13, | ||
58 | GPIO1_14, | ||
59 | GPIO1_15, | ||
60 | GPIO1_16, | ||
61 | GPIO1_17, | ||
62 | GPIO1_18, | ||
63 | GPIO1_19, | ||
64 | GPIO1_20, | ||
65 | GPIO1_21, | ||
66 | GPIO1_22, | ||
67 | GPIO1_23, | ||
68 | GPIO1_24, | ||
69 | GPIO1_25, | ||
70 | GPIO1_26, | ||
71 | GPIO1_27, | ||
72 | GPIO1_28, | ||
73 | GPIO1_29, | ||
74 | GPIO1_30, | ||
75 | GPIO1_31, | ||
76 | GPIO2_0, /* GPIO group 2 start */ | ||
77 | GPIO2_1, | ||
78 | GPIO2_2, | ||
79 | GPIO2_3, | ||
80 | GPIO2_4, | ||
81 | GPIO2_5, | ||
82 | GPIO2_6, | ||
83 | GPIO2_7, | ||
84 | GPIO2_8, | ||
85 | GPIO2_9, | ||
86 | GPIO2_10, | ||
87 | GPIO2_11, | ||
88 | GPIO2_12, | ||
89 | GPIO2_13, | ||
90 | GPIO2_14, | ||
91 | GPIO2_15, | ||
92 | GPIO2_16, | ||
93 | GPIO2_17, | ||
94 | GPIO2_18, | ||
95 | GPIO2_19, | ||
96 | GPIO2_20, | ||
97 | GPIO2_21, | ||
98 | GPIO2_22, | ||
99 | GPIO2_23, | ||
100 | GPIO2_24, | ||
101 | GPIO2_25, | ||
102 | GPIO2_26, | ||
103 | GPIO2_27, | ||
104 | GPIO2_28, | ||
105 | GPIO2_29, | ||
106 | GPIO2_30, | ||
107 | GPIO2_31, | ||
108 | GPIO3_0, /* GPIO group 3 start */ | ||
109 | GPIO3_1, | ||
110 | GPIO3_2, | ||
111 | GPIO3_3, | ||
112 | GPIO3_4, | ||
113 | GPIO3_5, | ||
114 | GPIO3_6, | ||
115 | GPIO3_7, | ||
116 | GPIO3_8, | ||
117 | GPIO3_9, | ||
118 | GPIO3_10, | ||
119 | GPIO3_11, | ||
120 | GPIO3_12, | ||
121 | GPIO3_13, | ||
122 | GPIO3_14, | ||
123 | GPIO3_15, | ||
124 | GPIO3_16, | ||
125 | GPIO3_17, | ||
126 | GPIO3_18, | ||
127 | GPIO3_19, | ||
128 | GPIO3_20, | ||
129 | GPIO3_21, | ||
130 | GPIO3_22, | ||
131 | GPIO3_23, | ||
132 | GPIO3_24, | ||
133 | GPIO3_25, | ||
134 | GPIO3_26, | ||
135 | GPIO3_27, | ||
136 | GPIO3_28, | ||
137 | GPIO3_29, | ||
138 | GPIO3_30, | ||
139 | GPIO3_31, | ||
140 | }R0_MX37_GPIO; | ||
141 | |||
142 | typedef enum | ||
143 | { | ||
144 | CONFIG_ALT0, | ||
145 | CONFIG_ALT1, | ||
146 | CONFIG_ALT2, | ||
147 | CONFIG_ALT3, | ||
148 | CONFIG_ALT4, | ||
149 | CONFIG_ALT5, | ||
150 | CONFIG_ALT6, | ||
151 | CONFIG_ALT7, | ||
152 | CONFIG_GPIO, | ||
153 | CONFIG_SION = 0x01 << 4, | ||
154 | CONFIG_DEFAULT | ||
155 | } R0_MX37_PIN_CONFIG; | ||
156 | |||
157 | #ifndef __MACH_MX37_IOMUX_H__ | ||
158 | typedef enum | ||
159 | { | ||
160 | PAD_CTL_SRE_SLOW = 0x0 << 0, | ||
161 | PAD_CTL_SRE_FAST = 0x1 << 0, | ||
162 | PAD_CTL_DRV_LOW = 0x0 << 1, | ||
163 | PAD_CTL_DRV_MEDIUM = 0x1 << 1, | ||
164 | PAD_CTL_DRV_HIGH = 0x2 << 1, | ||
165 | PAD_CTL_DRV_MAX = 0x3 << 1, | ||
166 | PAD_CTL_ODE_OPENDRAIN_NONE = 0x0 << 3, | ||
167 | PAD_CTL_ODE_OPENDRAIN_ENABLE = 0x1 << 3, | ||
168 | PAD_CTL_100K_PD = 0x0 << 4, | ||
169 | PAD_CTL_47K_PU = 0x1 << 4, | ||
170 | PAD_CTL_100K_PU = 0x2 << 4, | ||
171 | PAD_CTL_22K_PU = 0x3 << 4, | ||
172 | PAD_CTL_PUE_KEEPER = 0x0 << 6, | ||
173 | PAD_CTL_PUE_PULL = 0x1 << 6, | ||
174 | PAD_CTL_PKE_NONE = 0x0 << 7, | ||
175 | PAD_CTL_PKE_ENABLE = 0x1 << 7, | ||
176 | PAD_CTL_HYS_NONE = 0x0 << 8, | ||
177 | PAD_CTL_HYS_ENABLE = 0x1 << 8, | ||
178 | PAD_CTL_DDR_INPUT_CMOS = 0x0 << 9, | ||
179 | PAD_CTL_DDR_INPUT_DDR = 0x1 << 9, | ||
180 | PAD_CTL_DRV_VOT_LOW = 0x0 << 13, | ||
181 | PAD_CTL_DRV_VOT_HIGH = 0x1 << 13, | ||
182 | } R0_MX37_PAD_CONFIG; | ||
183 | #endif | ||
184 | |||
185 | #endif /* __IOCTL_GPIO__H__ */ | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/sc900776.h b/firmware/target/hosted/samsungypr/ypr0/sc900776.h new file mode 100644 index 0000000000..32eb90f797 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/sc900776.h | |||
@@ -0,0 +1,134 @@ | |||
1 | /* This file originates from the linux kernel provided in Samsung's YP-R0 Open | ||
2 | * Source package. | ||
3 | */ | ||
4 | |||
5 | /* | ||
6 | * Bigbang project | ||
7 | * Copyright (c) 2009 VPS R&D Group, Samsung Electronics, Inc. | ||
8 | * All rights reserved. | ||
9 | */ | ||
10 | |||
11 | /** | ||
12 | * This file defines data structures and APIs for Freescale SC900776 | ||
13 | * | ||
14 | * @name sc900776.h | ||
15 | * @author Eung Chan Kim (eungchan.kim@samsung.com) | ||
16 | * @version 0.1 | ||
17 | * @see | ||
18 | */ | ||
19 | |||
20 | #ifndef __SC900776_H__ | ||
21 | #define __SC900776_H__ | ||
22 | |||
23 | |||
24 | typedef enum | ||
25 | { | ||
26 | SC900776_DEVICE_ID = 0x01, /* 01h R */ | ||
27 | SC900776_CONTROL, /* 02h R/W */ | ||
28 | SC900776_INTERRUPT1, /* 03h R/C */ | ||
29 | SC900776_INTERRUPT2, /* 04h R/C */ | ||
30 | SC900776_INTERRUPT_MASK1, /* 05h R/W */ | ||
31 | SC900776_INTERRUPT_MASK2, /* 06h R/W */ | ||
32 | SC900776_ADC_RESULT, /* 07h R */ | ||
33 | SC900776_TIMING_SET1, /* 08h R/W */ | ||
34 | SC900776_TIMING_SET2, /* 09h R/W */ | ||
35 | SC900776_DEVICE_TYPE1, /* 0Ah R */ | ||
36 | SC900776_DEVICE_TYPE2, /* 0Bh R */ | ||
37 | SC900776_BUTTON1, /* 0Ch R/C */ | ||
38 | SC900776_BUTTON2, /* 0Dh R/C */ | ||
39 | /* 0Eh ~ 12h : reserved */ | ||
40 | SC900776_MANUAL_SWITCH1 = 0x13, /* 13h R/W */ | ||
41 | SC900776_MANUAL_SWITCH2, /* 14h R/W */ | ||
42 | /* 15h ~ 1Fh : reserved */ | ||
43 | SC900776_FSL_STATUS = 0x20, /* 20h R */ | ||
44 | SC900776_FSL_CONTROL, /* 21h R/W */ | ||
45 | SC900776_TIME_DELAY, /* 22h R/W */ | ||
46 | SC900776_DEVICE_MODE, /* 23h R/W */ | ||
47 | |||
48 | SC900776_REG_MAX | ||
49 | } eSc900776_register_t; | ||
50 | |||
51 | typedef enum | ||
52 | { | ||
53 | DEVICETYPE1_UNDEFINED = 0, | ||
54 | DEVICETYPE1_USB, // 0x04 0x00 // normal usb cable & ad200 | ||
55 | DEVICETYPE1_DEDICATED, // 0x40 0x00 // dedicated charger cable | ||
56 | DEVICETYPE2_JIGUARTON, // 0x00 0x08 // Anygate_UART jig | ||
57 | DEVICETYPE2_JIGUSBOFF, // 0x00 0x01 // USB jig(AS center) | ||
58 | DEVICETYPE2_JIGUSBON, // 0x00 0x02 // Anygate_USB jig with boot-on, not tested | ||
59 | } eMinivet_device_t; | ||
60 | |||
61 | /* | ||
62 | * sc900776 register bit definitions | ||
63 | */ | ||
64 | #define MINIVET_DEVICETYPE1_USBOTG 0x80 /* 1: a USBOTG device is attached */ | ||
65 | #define MINIVET_DEVICETYPE1_DEDICATED 0x40 /* 1: a dedicated charger is attached */ | ||
66 | #define MINIVET_DEVICETYPE1_USBCHG 0x20 /* 1: a USB charger is attached */ | ||
67 | #define MINIVET_DEVICETYPE1_5WCHG 0x10 /* 1: a 5-wire charger (type 1 or 2) is attached */ | ||
68 | #define MINIVET_DEVICETYPE1_UART 0x08 /* 1: a UART cable is attached */ | ||
69 | #define MINIVET_DEVICETYPE1_USB 0x04 /* 1: a USB host is attached */ | ||
70 | #define MINIVET_DEVICETYPE1_AUDIO2 0x02 /* 1: an audio accessory type 2 is attached */ | ||
71 | #define MINIVET_DEVICETYPE1_AUDIO1 0x01 /* 1: an audio accessory type 1 is attached */ | ||
72 | |||
73 | #define MINIVET_DEVICETYPE2_AV 0x40 /* 1: an audio/video cable is attached */ | ||
74 | #define MINIVET_DEVICETYPE2_TTY 0x20 /* 1: a TTY converter is attached */ | ||
75 | #define MINIVET_DEVICETYPE2_PPD 0x10 /* 1: a phone powered device is attached */ | ||
76 | #define MINIVET_DEVICETYPE2_JIGUARTON 0x08 /* 1: a UART jig cable with the BOOT-on option is attached */ | ||
77 | #define MINIVET_DEVICETYPE2_JIGUARTOFF 0x04 /* 1: a UART jig cable with the BOOT-off option is attached */ | ||
78 | #define MINIVET_DEVICETYPE2_JIGUSBON 0x02 /* 1: a USB jig cable with the BOOT-on option is attached */ | ||
79 | #define MINIVET_DEVICETYPE2_JIGUSBOFF 0x01 /* 1: a USB jig cable with the BOOT-off option is attached */ | ||
80 | |||
81 | #define MINIVET_FSLSTATUS_FETSTATUS 0x40 /* 1: The on status of the power MOSFET */ | ||
82 | #define MINIVET_FSLSTATUS_IDDETEND 0x20 /* 1: ID resistance detection finished */ | ||
83 | #define MINIVET_FSLSTATUS_VBUSDETEND 0x10 /* 1: VBUS power supply type identification completed */ | ||
84 | #define MINIVET_FSLSTATUS_IDGND 0x08 /* 1: ID pin is shorted to ground */ | ||
85 | #define MINIVET_FSLSTATUS_IDFLOAT 0x04 /* 1: ID line is floating */ | ||
86 | #define MINIVET_FSLSTATUS_VBUSDET 0x02 /* 1: VBUS voltage is higher than the POR */ | ||
87 | #define MINIVET_FSLSTATUS_ADCSTATUS 0x01 /* 1: ADC conversion completed */ | ||
88 | |||
89 | |||
90 | #define SC900776_I2C_SLAVE_ADDR 0x25 | ||
91 | |||
92 | typedef struct { | ||
93 | unsigned char addr; | ||
94 | unsigned char value; | ||
95 | }__attribute__((packed)) sMinivet_t; | ||
96 | |||
97 | |||
98 | #define DRV_IOCTL_MINIVET_MAGIC 'M' | ||
99 | |||
100 | |||
101 | typedef enum | ||
102 | { | ||
103 | E_IOCTL_MINIVET_INIT = 0, | ||
104 | E_IOCTL_MINIVET_WRITE_BYTE, | ||
105 | E_IOCTL_MINIVET_READ_BYTE, | ||
106 | E_IOCTL_MINIVET_DET_VBUS, | ||
107 | E_IOCTL_MINIVET_MANUAL_USB, | ||
108 | E_IOCTL_MINIVET_MANUAL_UART, | ||
109 | |||
110 | E_IOCTL_MINIVET_MAX | ||
111 | } eSc900776_ioctl_t; | ||
112 | |||
113 | #define IOCTL_MINIVET_INIT _IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_INIT) | ||
114 | #define IOCTL_MINIVET_WRITE_BYTE _IOW(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_WRITE_BYTE, sMinivet_t) | ||
115 | #define IOCTL_MINIVET_READ_BYTE _IOR(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_READ_BYTE, sMinivet_t) | ||
116 | #define IOCTL_MINIVET_DET_VBUS _IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_DET_VBUS) | ||
117 | #define IOCTL_MINIVET_MANUAL_USB _IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_MANUAL_USB) | ||
118 | #define IOCTL_MINIVET_MANUAL_UART _IO(DRV_IOCTL_MINIVET_MAGIC, E_IOCTL_MINIVET_MANUAL_UART) | ||
119 | |||
120 | |||
121 | #ifndef __MINIVET_ENUM__ | ||
122 | #define __MINIVET_ENUM__ | ||
123 | enum | ||
124 | { | ||
125 | EXT_PWR_UNPLUGGED = 0, | ||
126 | EXT_PWR_PLUGGED, | ||
127 | EXT_PWR_NOT_OVP, | ||
128 | EXT_PWR_OVP, | ||
129 | }; | ||
130 | |||
131 | #endif /* __MINIVET_ENUM__ */ | ||
132 | |||
133 | |||
134 | #endif /* __MINIVET_IOCTL_H__ */ | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/system-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/system-ypr0.c new file mode 100644 index 0000000000..7ee2697a24 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/system-ypr0.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2011-2013 by Lorenzo Miori | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <inttypes.h> | ||
24 | #include "system.h" | ||
25 | #include "panic.h" | ||
26 | #include "debug.h" | ||
27 | |||
28 | #if defined(HAVE_SDL_AUDIO) || defined(HAVE_SDL_THREADS) || defined(HAVE_SDL) | ||
29 | #include <SDL.h> | ||
30 | #endif | ||
31 | |||
32 | #include "ascodec.h" | ||
33 | #include "gpio-target.h" | ||
34 | |||
35 | void power_off(void) | ||
36 | { | ||
37 | /* Something that we need to do before exit on our platform YPR0 */ | ||
38 | ascodec_close(); | ||
39 | gpio_close(); | ||
40 | exit(EXIT_SUCCESS); | ||
41 | } | ||
42 | |||
43 | uintptr_t *stackbegin; | ||
44 | uintptr_t *stackend; | ||
45 | void system_init(void) | ||
46 | { | ||
47 | int *s; | ||
48 | /* fake stack, OS manages size (and growth) */ | ||
49 | stackbegin = stackend = (uintptr_t*)&s; | ||
50 | |||
51 | #if defined(HAVE_SDL_AUDIO) || defined(HAVE_SDL_THREADS) || defined(HAVE_SDL) | ||
52 | SDL_Init(0); /* need this if using any SDL subsystem */ | ||
53 | #endif | ||
54 | |||
55 | /* Here begins our platform specific initilization for various things */ | ||
56 | ascodec_init(); | ||
57 | gpio_init(); | ||
58 | } | ||
59 | |||
60 | |||
61 | void system_reboot(void) | ||
62 | { | ||
63 | power_off(); | ||
64 | } | ||
65 | |||
66 | void system_exception_wait(void) | ||
67 | { | ||
68 | system_reboot(); | ||
69 | } | ||
70 | |||
71 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
72 | #include <stdio.h> | ||
73 | #include "file.h" | ||
74 | /* This is the Linux Kernel CPU governor... */ | ||
75 | static void set_cpu_freq(int speed) | ||
76 | { | ||
77 | char temp[10]; | ||
78 | int cpu_dev; | ||
79 | cpu_dev = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", O_WRONLY); | ||
80 | if (cpu_dev < 0) | ||
81 | return; | ||
82 | write(cpu_dev, temp, sprintf(temp, "%d", speed) + 1); | ||
83 | close(cpu_dev); | ||
84 | } | ||
85 | |||
86 | void set_cpu_frequency(long frequency) | ||
87 | { | ||
88 | switch (frequency) | ||
89 | { | ||
90 | case CPUFREQ_MAX: | ||
91 | set_cpu_freq(532000); | ||
92 | cpu_frequency = CPUFREQ_MAX; | ||
93 | break; | ||
94 | case CPUFREQ_NORMAL: | ||
95 | set_cpu_freq(400000); | ||
96 | cpu_frequency = CPUFREQ_NORMAL; | ||
97 | break; | ||
98 | default: | ||
99 | set_cpu_freq(200000); | ||
100 | cpu_frequency = CPUFREQ_DEFAULT; | ||
101 | break; | ||
102 | } | ||
103 | } | ||
104 | #endif | ||
diff --git a/firmware/target/hosted/samsungypr/ypr0/ypr0.make b/firmware/target/hosted/samsungypr/ypr0/ypr0.make new file mode 100644 index 0000000000..67ff326de0 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr0/ypr0.make | |||
@@ -0,0 +1,24 @@ | |||
1 | # __________ __ ___. | ||
2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
6 | # \/ \/ \/ \/ \/ | ||
7 | # $Id$ | ||
8 | # | ||
9 | |||
10 | INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR) | ||
11 | |||
12 | SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS) | ||
13 | |||
14 | .SECONDEXPANSION: # $$(OBJ) is not populated until after this | ||
15 | |||
16 | $(BUILDDIR)/rockbox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) | ||
17 | $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \ | ||
18 | -L$(BUILDDIR)/firmware -lfirmware \ | ||
19 | -L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \ | ||
20 | -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \ | ||
21 | $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map | ||
22 | |||
23 | $(BUILDDIR)/rockbox : $(BUILDDIR)/rockbox.elf | ||
24 | $(call PRINTS,OC $(@F))$(call objcopy,$^,$@) | ||