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>
33 #include <linux/gta02-shadow.h>
35 int gta_gsm_interrupts;
36 EXPORT_SYMBOL(gta_gsm_interrupts);
38 extern void s3c24xx_serial_console_set_silence(int);
45 static struct gta02pm_priv gta02_gsm;
47 static struct console *find_s3c24xx_console(void)
51 acquire_console_sem();
53 for (con = console_drivers; con; con = con->next) {
54 if (!strcmp(con->name, "ttySAC"))
58 release_console_sem();
63 static ssize_t gsm_read(struct device *dev, struct device_attribute *attr,
66 if (!strcmp(attr->attr.name, "power_on")) {
67 if (pcf50633_gpio_get(gta02_pcf, PCF50633_GPIO2))
69 } else if (!strcmp(attr->attr.name, "download")) {
70 if (!s3c2410_gpio_getpin(GTA02_GPIO_nDL_GSM))
72 } else if (!strcmp(attr->attr.name, "flowcontrolled")) {
73 if (s3c2410_gpio_getcfg(S3C2410_GPH1) == S3C2410_GPIO_OUTPUT)
77 return strlcpy(buf, "0\n", 3);
79 return strlcpy(buf, "1\n", 3);
82 static void gsm_on_off(struct device *dev, int on)
85 s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPIO_INPUT);
86 s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPIO_INPUT);
88 pcf50633_gpio_set(gta02_pcf, PCF50633_GPIO2, 0);
91 s3c24xx_serial_console_set_silence(0);
92 console_start(gta02_gsm.con);
94 dev_dbg(dev, "powered down gta02 GSM, enabling "
102 dev_dbg(dev, "powering up GSM, thus "
103 "disconnecting serial console\n");
105 console_stop(gta02_gsm.con);
106 s3c24xx_serial_console_set_silence(1);
109 /* allow UART to talk to GSM side now we will power it */
110 s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_nRTS0);
111 s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPH2_TXD0);
113 pcf50633_gpio_set(gta02_pcf, PCF50633_GPIO2, 7);
117 gta02_gpb_setpin(GTA02_GPIO_MODEM_ON, 1);
119 gta02_gpb_setpin(GTA02_GPIO_MODEM_ON, 0);
122 * workaround for calypso firmware moko10 and earlier,
123 * without this it will leave IRQ line high after
126 s3c2410_gpio_setpin(S3C2410_GPH1, 1);
127 s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_OUTP);
129 s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_nRTS0);
133 static ssize_t gsm_write(struct device *dev, struct device_attribute *attr,
134 const char *buf, size_t count)
136 unsigned long on = simple_strtoul(buf, NULL, 10);
138 if (!strcmp(attr->attr.name, "power_on")) {
144 if (!strcmp(attr->attr.name, "download")) {
146 * the keyboard / buttons driver requests and enables
147 * the JACK_INSERT IRQ. We have to take care about
148 * not enabling and disabling the IRQ when it was
149 * already in that state or we get "unblanaced IRQ"
150 * kernel warnings and stack dumps. So we use the
151 * copy of the ndl_gsm state to figure out if we should
152 * enable or disable the jack interrupt
155 if (gta02_gsm.gpio_ndl_gsm)
156 disable_irq(gpio_to_irq(
157 GTA02_GPIO_JACK_INSERT));
159 if (!gta02_gsm.gpio_ndl_gsm)
160 enable_irq(gpio_to_irq(
161 GTA02_GPIO_JACK_INSERT));
164 gta02_gsm.gpio_ndl_gsm = !on;
165 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM, !on);
170 if (!strcmp(attr->attr.name, "flowcontrolled")) {
172 gta_gsm_interrupts = 0;
173 s3c2410_gpio_setpin(S3C2410_GPH1, 1);
174 s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_OUTP);
176 s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_nRTS0);
182 static DEVICE_ATTR(power_on, 0644, gsm_read, gsm_write);
183 static DEVICE_ATTR(reset, 0644, gsm_read, gsm_write);
184 static DEVICE_ATTR(download, 0644, gsm_read, gsm_write);
185 static DEVICE_ATTR(flowcontrolled, 0644, gsm_read, gsm_write);
189 static int gta02_gsm_resume(struct platform_device *pdev);
190 static int gta02_gsm_suspend(struct platform_device *pdev, pm_message_t state)
192 /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
193 * don't need to do much here. */
195 /* If flowcontrol asserted, abort if GSM already interrupted */
196 if (s3c2410_gpio_getcfg(S3C2410_GPH1) == S3C2410_GPIO_OUTPUT) {
197 if (gta_gsm_interrupts)
201 /* disable DL GSM to prevent jack_insert becoming 'floating' */
202 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM, 1);
210 gta02_gsm_suspend_late(struct platform_device *pdev, pm_message_t state)
212 /* Last chance: abort if GSM already interrupted */
213 if (s3c2410_gpio_getcfg(S3C2410_GPH1) == S3C2410_GPIO_OUTPUT) {
214 if (gta_gsm_interrupts)
220 static int gta02_gsm_resume(struct platform_device *pdev)
222 /* GPIO state is saved/restored by S3C2410 core GPIO driver, so we
223 * don't need to do much here. */
225 /* Make sure that the kernel console on the serial port is still
226 * disabled. FIXME: resume ordering race with serial driver! */
227 if (gta02_gsm.con && s3c2410_gpio_getpin(GTA02_GPIO_MODEM_ON))
228 console_stop(gta02_gsm.con);
230 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM, gta02_gsm.gpio_ndl_gsm);
235 #define gta02_gsm_suspend NULL
236 #define gta02_gsm_suspend_late NULL
237 #define gta02_gsm_resume NULL
238 #endif /* CONFIG_PM */
240 static struct attribute *gta02_gsm_sysfs_entries[] = {
241 &dev_attr_power_on.attr,
242 &dev_attr_reset.attr,
243 &dev_attr_download.attr,
244 &dev_attr_flowcontrolled.attr,
248 static struct attribute_group gta02_gsm_attr_group = {
250 .attrs = gta02_gsm_sysfs_entries,
253 static int __init gta02_gsm_probe(struct platform_device *pdev)
255 switch (S3C_SYSTEM_REV_ATAG) {
256 case GTA02v1_SYSTEM_REV:
257 case GTA02v2_SYSTEM_REV:
258 case GTA02v3_SYSTEM_REV:
259 case GTA02v4_SYSTEM_REV:
260 case GTA02v5_SYSTEM_REV:
261 case GTA02v6_SYSTEM_REV:
264 dev_warn(&pdev->dev, "Unknown Freerunner Revision 0x%x, "
265 "some PM features not available!!!\n",
270 gta02_gsm.con = find_s3c24xx_console();
273 "cannot find S3C24xx console driver\n");
275 /* note that download initially disabled, and enforce that */
276 gta02_gsm.gpio_ndl_gsm = 1;
277 s3c2410_gpio_setpin(GTA02_GPIO_nDL_GSM, 1);
279 /* GSM is to be initially off (at boot, or if this module inserted) */
280 gsm_on_off(&pdev->dev, 0);
282 return sysfs_create_group(&pdev->dev.kobj, >a02_gsm_attr_group);
285 static int gta02_gsm_remove(struct platform_device *pdev)
287 sysfs_remove_group(&pdev->dev.kobj, >a02_gsm_attr_group);
292 static struct platform_driver gta02_gsm_driver = {
293 .probe = gta02_gsm_probe,
294 .remove = gta02_gsm_remove,
295 .suspend = gta02_gsm_suspend,
296 .suspend_late = gta02_gsm_suspend_late,
297 .resume = gta02_gsm_resume,
299 .name = "gta02-pm-gsm",
303 static int __devinit gta02_gsm_init(void)
305 return platform_driver_register(>a02_gsm_driver);
308 static void gta02_gsm_exit(void)
310 platform_driver_unregister(>a02_gsm_driver);
313 module_init(gta02_gsm_init);
314 module_exit(gta02_gsm_exit);
316 MODULE_LICENSE("GPL");
317 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
318 MODULE_DESCRIPTION("Openmoko Freerunner GSM Power Management");