summaryrefslogtreecommitdiff
path: root/firmware/target/hosted
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted')
-rw-r--r--firmware/target/hosted/ypr0/button-target.h4
-rw-r--r--firmware/target/hosted/ypr0/button-ypr0.c13
-rw-r--r--firmware/target/hosted/ypr0/gpio_ypr0.c54
-rw-r--r--firmware/target/hosted/ypr0/gpio_ypr0.h42
-rw-r--r--firmware/target/hosted/ypr0/r0GPIOIoctl.h185
-rw-r--r--firmware/target/hosted/ypr0/system-ypr0.c3
6 files changed, 300 insertions, 1 deletions
diff --git a/firmware/target/hosted/ypr0/button-target.h b/firmware/target/hosted/ypr0/button-target.h
index 5d65d97607..beddc66c67 100644
--- a/firmware/target/hosted/ypr0/button-target.h
+++ b/firmware/target/hosted/ypr0/button-target.h
@@ -5,7 +5,7 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id: button-target.h 29248 2011-02-08 20:05:25Z thomasjfox $ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2011 by Lorenzo Miori 10 * Copyright (C) 2011 by Lorenzo Miori
11 * 11 *
@@ -25,6 +25,8 @@
25#include <stdbool.h> 25#include <stdbool.h>
26#include "config.h" 26#include "config.h"
27 27
28bool headphones_inserted(void);
29
28void button_init_device(void); 30void button_init_device(void);
29void button_close_device(void); 31void button_close_device(void);
30int button_read_device(void); 32int button_read_device(void);
diff --git a/firmware/target/hosted/ypr0/button-ypr0.c b/firmware/target/hosted/ypr0/button-ypr0.c
index 4298410161..5953bcebf9 100644
--- a/firmware/target/hosted/ypr0/button-ypr0.c
+++ b/firmware/target/hosted/ypr0/button-ypr0.c
@@ -28,6 +28,7 @@
28#include "kernel.h" 28#include "kernel.h"
29#include "system.h" 29#include "system.h"
30#include "button-target.h" 30#include "button-target.h"
31#include <gpio_ypr0.h> /* For headphones sense */
31 32
32/* R0 physical key codes */ 33/* R0 physical key codes */
33enum ypr0_buttons { 34enum ypr0_buttons {
@@ -45,6 +46,7 @@ enum ypr0_buttons {
45 46
46 47
47static int r0_btn_fd = 0; 48static int r0_btn_fd = 0;
49
48/* Samsung keypad driver doesn't allow multiple key combinations :( */ 50/* Samsung keypad driver doesn't allow multiple key combinations :( */
49static enum ypr0_buttons r0_read_key(void) 51static enum ypr0_buttons r0_read_key(void)
50{ 52{
@@ -82,6 +84,11 @@ int button_read_device(void)
82 return key_to_button(r0_read_key()); 84 return key_to_button(r0_read_key());
83} 85}
84 86
87bool headphones_inserted(void)
88{
89 /* GPIO low - 0 - means headphones inserted */
90 return !gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_HEADPHONE_SENSE, 0, 0);
91}
85 92
86/* Open the keypad device: it is offered by r0Btn.ko module */ 93/* Open the keypad device: it is offered by r0Btn.ko module */
87void button_init_device(void) 94void button_init_device(void)
@@ -89,6 +96,10 @@ void button_init_device(void)
89 r0_btn_fd = open("/dev/r0Btn", O_RDONLY); 96 r0_btn_fd = open("/dev/r0Btn", O_RDONLY);
90 if (r0_btn_fd < 0) 97 if (r0_btn_fd < 0)
91 printf("/dev/r0Btn open error!"); 98 printf("/dev/r0Btn open error!");
99
100 /* Setup GPIO pin for headphone sense, copied from OF */
101 gpio_control(DEV_CTRL_GPIO_SET_MUX, GPIO_HEADPHONE_SENSE, CONFIG_SION, PAD_CTL_47K_PU);
102 gpio_control(DEV_CTRL_GPIO_SET_INPUT, GPIO_HEADPHONE_SENSE, CONFIG_SION, PAD_CTL_47K_PU);
92} 103}
93 104
94#ifdef BUTTON_DRIVER_CLOSE 105#ifdef BUTTON_DRIVER_CLOSE
@@ -99,5 +110,7 @@ void button_close_device(void)
99 close(r0_btn_fd); 110 close(r0_btn_fd);
100 printf("/dev/r0Btn closed!"); 111 printf("/dev/r0Btn closed!");
101 } 112 }
113 /* Don't know the precise meaning, but it's done as in the OF, so copied there */
114 gpio_control(DEV_CTRL_GPIO_UNSET_MUX, GPIO_HEADPHONE_SENSE, CONFIG_SION, 0);
102} 115}
103#endif /* BUTTON_DRIVER_CLOSE */ 116#endif /* BUTTON_DRIVER_CLOSE */
diff --git a/firmware/target/hosted/ypr0/gpio_ypr0.c b/firmware/target/hosted/ypr0/gpio_ypr0.c
new file mode 100644
index 0000000000..9c3f186a6b
--- /dev/null
+++ b/firmware/target/hosted/ypr0/gpio_ypr0.c
@@ -0,0 +1,54 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
9 *
10 * Module wrapper for GPIO, using /dev/r0GPIO (r0Gpio.ko) of Samsung YP-R0
11 *
12 * Copyright (c) 2011 Lorenzo Miori
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include <stdio.h>
25#include <unistd.h>
26#include <fcntl.h>
27#include <gpio_ypr0.h> /* includes r0GPIOioctl.h */
28#include <sys/ioctl.h>
29
30static int r0_gpio_dev = 0;
31
32void gpio_init(void)
33{
34 r0_gpio_dev = open("/dev/r0GPIO", O_RDONLY);
35 if (r0_gpio_dev < 0)
36 printf("/dev/r0GPIO open error!");
37}
38
39void gpio_close(void)
40{
41 if (r0_gpio_dev < 0)
42 close(r0_gpio_dev);
43}
44
45int gpio_control_struct(int request, R0GPIOInfo r)
46{
47 return ioctl(r0_gpio_dev, request, &r);
48}
49
50int gpio_control(int request, int num, int mode, int val)
51{
52 R0GPIOInfo r = { .num = num, .mode = mode, .val = val, };
53 return ioctl(r0_gpio_dev, request, &r);
54} \ No newline at end of file
diff --git a/firmware/target/hosted/ypr0/gpio_ypr0.h b/firmware/target/hosted/ypr0/gpio_ypr0.h
new file mode 100644
index 0000000000..9fc7444887
--- /dev/null
+++ b/firmware/target/hosted/ypr0/gpio_ypr0.h
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
9 *
10 * Module wrapper for GPIO, using /dev/r0GPIO (r0Gpio.ko) of Samsung YP-R0
11 *
12 * Copyright (c) 2011 Lorenzo Miori
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#ifndef GPIO_YPR0_H
25#define GPIO_YPR0_H
26
27#include "r0GPIOIoctl.h"
28
29/* Some meaningful pins used in the R0 */
30
31#define GPIO_HEADPHONE_SENSE GPIO1_5
32//26
33#define GPIO_EXT_PWR_SENSE GPIO1_26
34//59
35#define GPIO_SD_SENSE GPIO2_24
36
37void gpio_init(void);
38void gpio_close(void);
39int gpio_control_struct(int request, R0GPIOInfo pin);
40int gpio_control(int request, int num, int mode, int val);
41
42#endif \ No newline at end of file
diff --git a/firmware/target/hosted/ypr0/r0GPIOIoctl.h b/firmware/target/hosted/ypr0/r0GPIOIoctl.h
new file mode 100644
index 0000000000..e77f35fbb7
--- /dev/null
+++ b/firmware/target/hosted/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
11typedef 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
42typedef 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
142typedef 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__
158typedef 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/ypr0/system-ypr0.c b/firmware/target/hosted/ypr0/system-ypr0.c
index bf3b1cd4c9..784b4fe48e 100644
--- a/firmware/target/hosted/ypr0/system-ypr0.c
+++ b/firmware/target/hosted/ypr0/system-ypr0.c
@@ -31,11 +31,13 @@
31#endif 31#endif
32 32
33#include "ascodec-target.h" 33#include "ascodec-target.h"
34#include "gpio_ypr0.h"
34 35
35void power_off(void) 36void power_off(void)
36{ 37{
37 /* Something that we need to do before exit on our platform YPR0 */ 38 /* Something that we need to do before exit on our platform YPR0 */
38 ascodec_close(); 39 ascodec_close();
40 gpio_close();
39 exit(EXIT_SUCCESS); 41 exit(EXIT_SUCCESS);
40} 42}
41 43
@@ -52,6 +54,7 @@ void system_init(void)
52#endif 54#endif
53 /* Here begins our platform specific initilization for various things */ 55 /* Here begins our platform specific initilization for various things */
54 ascodec_init(); 56 ascodec_init();
57 gpio_init();
55} 58}
56 59
57 60