2 * GSM Management code for the Openmoko Freerunner GSM Phone
4 * (C) 2007 by Openmoko Inc.
5 * Author: Harald Welte <laforge@openmoko.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/platform_device.h>
18 #include <linux/console.h>
19 #include <linux/errno.h>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
23 #include <mach/gpio.h>
24 #include <asm/mach-types.h>
26 #include <mach/hardware.h>
29 #include <mach/gta02.h>
30 #include <linux/mfd/pcf50633/gpio.h>
31 #include <mach/regs-gpio.h>
32 #include <mach/regs-gpioj.h>
34 int gta_gsm_interrupts
;
35 EXPORT_SYMBOL(gta_gsm_interrupts
);
37 extern void s3c24xx_serial_console_set_silence(int);
44 static struct gta02pm_priv gta02_gsm
;
46 static struct console
*find_s3c24xx_console(void)
50 acquire_console_sem();
52 for (con
= console_drivers
; con
; con
= con
->next
) {
53 if (!strcmp(con
->name
, "ttySAC"))
57 release_console_sem();
62 static ssize_t
gsm_read(struct device
*dev
, struct device_attribute
*attr
,
65 if (!strcmp(attr
->attr
.name
, "power_on")) {
66 if (pcf50633_gpio_get(gta02_pcf
, PCF50633_GPIO2
))
68 } else if (!strcmp(attr
->attr
.name
, "download")) {
69 if (!s3c2410_gpio_getpin(GTA02_GPIO_nDL_GSM
))
71 } else if (!strcmp(attr
->attr
.name
, "flowcontrolled")) {
72 if (s3c2410_gpio_getcfg(S3C2410_GPH(1)) == S3C2410_GPIO_OUTPUT
)
76 return strlcpy(buf
, "0\n", 3);
78 return strlcpy(buf
, "1\n", 3);
81 static void gsm_on_off(struct device
*dev
, int on
)
84 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_INPUT
);
85 s3c2410_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPIO_INPUT
);
87 pcf50633_gpio_set(gta02_pcf
, PCF50633_GPIO2
, 0);
90 s3c24xx_serial_console_set_silence(0);
91 console_start(gta02_gsm
.con
);
93 dev_dbg(dev
, "powered down gta02 GSM, enabling "
101 dev_dbg(dev
, "powering up GSM, thus "
102 "disconnecting serial console\n");
104 console_stop(gta02_gsm
.con
);
105 s3c24xx_serial_console_set_silence(1);
108 /* allow UART to talk to GSM side now we will power it */
109 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPH1_nRTS0
);
110 s3c2410_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0
);
112 pcf50633_gpio_set(gta02_pcf
, PCF50633_GPIO2
, 7);
116 s3c2410_gpio_setpin(GTA02_GPIO_MODEM_ON
, 1);
118 s3c2410_gpio_setpin(GTA02_GPIO_MODEM_ON
, 0);
121 * workaround for calypso firmware moko10 and earlier,
122 * without this it will leave IRQ line high after
125 s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
126 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT
);
128 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPH1_nRTS0
);
132 static ssize_t
gsm_write(struct device
*dev
, struct device_attribute
*attr
,
133 const char *buf
, size_t count
)
135 unsigned long on
= simple_strtoul(buf
, NULL
, 10);
137 if (!strcmp(attr
->attr
.name
, "power_on")) {
143 if (!strcmp(attr
->attr
.name
, "download")) {
145 * the keyboard / buttons driver requests and enables
146 * the JACK_INSERT IRQ. We have to take care about
147 * not enabling and disabling the IRQ when it was
148 * already in that state or we get "unblanaced IRQ"
149 * kernel warnings and stack dumps. So we use the
150 * copy of the ndl_gsm state to figure out if we should
151 * enable or disable the jack interrupt
154 if (gta02_gsm
.gpio_ndl_gsm
)
155 disable_irq(gpio_to_irq(
156 GTA02_GPIO_JACK_INSERT
));
158 if (!gta02_gsm
.gpio_ndl_gsm
)
159 enable_irq(gpio_to_irq(
160 GTA02_GPIO_JACK_INSERT
));
163 gta02_gsm
.gpio_ndl_gsm
= !on
;
164 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM
, !on
);
169 if (!strcmp(attr
->attr
.name
, "flowcontrolled")) {
171 gta_gsm_interrupts
= 0;
172 s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
173 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT
);
175 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPH1_nRTS0
);
181 static DEVICE_ATTR(power_on
, 0644, gsm_read
, gsm_write
);
182 static DEVICE_ATTR(reset
, 0644, gsm_read
, gsm_write
);
183 static DEVICE_ATTR(download
, 0644, gsm_read
, gsm_write
);
184 static DEVICE_ATTR(flowcontrolled
, 0644, gsm_read
, gsm_write
);
188 static int gta02_gsm_resume(struct platform_device
*pdev
);
189 static int gta02_gsm_suspend(struct platform_device
*pdev
, pm_message_t state
)
191 /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
192 * don't need to do much here. */
194 /* If flowcontrol asserted, abort if GSM already interrupted */
195 if (s3c2410_gpio_getcfg(S3C2410_GPH(1)) == S3C2410_GPIO_OUTPUT
) {
196 if (gta_gsm_interrupts
)
200 /* disable DL GSM to prevent jack_insert becoming 'floating' */
201 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM
, 1);
209 gta02_gsm_suspend_late(struct platform_device
*pdev
, pm_message_t state
)
211 /* Last chance: abort if GSM already interrupted */
212 if (s3c2410_gpio_getcfg(S3C2410_GPH(1)) == S3C2410_GPIO_OUTPUT
) {
213 if (gta_gsm_interrupts
)
219 static int gta02_gsm_resume(struct platform_device
*pdev
)
221 /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
222 * don't need to do much here. */
224 /* Make sure that the kernel console on the serial port is still
225 * disabled. FIXME: resume ordering race with serial driver! */
226 if (gta02_gsm
.con
&& s3c2410_gpio_getpin(GTA02_GPIO_MODEM_ON
))
227 console_stop(gta02_gsm
.con
);
229 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM
, gta02_gsm
.gpio_ndl_gsm
);
234 #define gta02_gsm_suspend NULL
235 #define gta02_gsm_suspend_late NULL
236 #define gta02_gsm_resume NULL
237 #endif /* CONFIG_PM */
239 static struct attribute
*gta02_gsm_sysfs_entries
[] = {
240 &dev_attr_power_on
.attr
,
241 &dev_attr_reset
.attr
,
242 &dev_attr_download
.attr
,
243 &dev_attr_flowcontrolled
.attr
,
247 static struct attribute_group gta02_gsm_attr_group
= {
249 .attrs
= gta02_gsm_sysfs_entries
,
252 static int __init
gta02_gsm_probe(struct platform_device
*pdev
)
254 switch (S3C_SYSTEM_REV_ATAG
) {
255 case GTA02v1_SYSTEM_REV
:
256 case GTA02v2_SYSTEM_REV
:
257 case GTA02v3_SYSTEM_REV
:
258 case GTA02v4_SYSTEM_REV
:
259 case GTA02v5_SYSTEM_REV
:
260 case GTA02v6_SYSTEM_REV
:
263 dev_warn(&pdev
->dev
, "Unknown Freerunner Revision 0x%x, "
264 "some PM features not available!!!\n",
269 gta02_gsm
.con
= find_s3c24xx_console();
272 "cannot find S3C24xx console driver\n");
274 /* note that download initially disabled, and enforce that */
275 gta02_gsm
.gpio_ndl_gsm
= 1;
276 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM
, 1);
278 /* GSM is to be initially off (at boot, or if this module inserted) */
279 gsm_on_off(&pdev
->dev
, 0);
281 return sysfs_create_group(&pdev
->dev
.kobj
, >a02_gsm_attr_group
);
284 static int gta02_gsm_remove(struct platform_device
*pdev
)
286 sysfs_remove_group(&pdev
->dev
.kobj
, >a02_gsm_attr_group
);
291 static struct platform_driver gta02_gsm_driver
= {
292 .probe
= gta02_gsm_probe
,
293 .remove
= gta02_gsm_remove
,
294 .suspend
= gta02_gsm_suspend
,
295 .suspend_late
= gta02_gsm_suspend_late
,
296 .resume
= gta02_gsm_resume
,
298 .name
= "gta02-pm-gsm",
302 static int __devinit
gta02_gsm_init(void)
304 return platform_driver_register(>a02_gsm_driver
);
307 static void gta02_gsm_exit(void)
309 platform_driver_unregister(>a02_gsm_driver
);
312 module_init(gta02_gsm_init
);
313 module_exit(gta02_gsm_exit
);
315 MODULE_LICENSE("GPL");
316 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
317 MODULE_DESCRIPTION("Openmoko Freerunner GSM Power Management");