2 * Mainly by David Woodhouse, somewhat modified by Jordan Crouse
4 * Copyright © 2006-2007 Red Hat, Inc.
5 * Copyright © 2006-2007 Advanced Micro Devices, Inc.
6 * Copyright © 2009 VIA Technology, Inc.
7 * Copyright (c) 2010 Andres Salomon <dilinger@queued.net>
9 * This program is free software. You can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 #include <linux/cs5535.h>
14 #include <linux/gpio.h>
15 #include <linux/delay.h>
18 #include "olpc_dcon.h"
20 static int dcon_init_xo_1(struct dcon_priv *dcon)
24 if (gpio_request(OLPC_GPIO_DCON_STAT0, "OLPC-DCON")) {
25 printk(KERN_ERR "olpc-dcon: failed to request STAT0 GPIO\n");
28 if (gpio_request(OLPC_GPIO_DCON_STAT1, "OLPC-DCON")) {
29 printk(KERN_ERR "olpc-dcon: failed to request STAT1 GPIO\n");
32 if (gpio_request(OLPC_GPIO_DCON_IRQ, "OLPC-DCON")) {
33 printk(KERN_ERR "olpc-dcon: failed to request IRQ GPIO\n");
36 if (gpio_request(OLPC_GPIO_DCON_LOAD, "OLPC-DCON")) {
37 printk(KERN_ERR "olpc-dcon: failed to request LOAD GPIO\n");
40 if (gpio_request(OLPC_GPIO_DCON_BLANK, "OLPC-DCON")) {
41 printk(KERN_ERR "olpc-dcon: failed to request BLANK GPIO\n");
45 /* Turn off the event enable for GPIO7 just to be safe */
46 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_EVENTS_ENABLE);
49 * Determine the current state by reading the GPIO bit; earlier
50 * stages of the boot process have established the state.
52 * Note that we read GPIO_OUPUT_VAL rather than GPIO_READ_BACK here;
53 * this is because OFW will disable input for the pin and set a value..
54 * READ_BACK will only contain a valid value if input is enabled and
55 * then a value is set. So, future readings of the pin can use
56 * READ_BACK, but the first one cannot. Awesome, huh?
58 dcon->curr_src = cs5535_gpio_isset(OLPC_GPIO_DCON_LOAD, GPIO_OUTPUT_VAL)
61 dcon->pending_src = dcon->curr_src;
63 /* Set the directions for the GPIO pins */
64 gpio_direction_input(OLPC_GPIO_DCON_STAT0);
65 gpio_direction_input(OLPC_GPIO_DCON_STAT1);
66 gpio_direction_input(OLPC_GPIO_DCON_IRQ);
67 gpio_direction_input(OLPC_GPIO_DCON_BLANK);
68 gpio_direction_output(OLPC_GPIO_DCON_LOAD,
69 dcon->curr_src == DCON_SOURCE_CPU);
71 /* Set up the interrupt mappings */
73 /* Set the IRQ to pair 2 */
74 cs5535_gpio_setup_event(OLPC_GPIO_DCON_IRQ, 2, 0);
76 /* Enable group 2 to trigger the DCON interrupt */
77 cs5535_gpio_set_irq(2, DCON_IRQ);
79 /* Select edge level for interrupt (in PIC) */
81 lob &= ~(1 << DCON_IRQ);
84 /* Register the interrupt handler */
85 if (request_irq(DCON_IRQ, &dcon_interrupt, 0, "DCON", dcon)) {
86 printk(KERN_ERR "olpc-dcon: failed to request DCON's irq\n");
90 /* Clear INV_EN for GPIO7 (DCONIRQ) */
91 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_INPUT_INVERT);
93 /* Enable filter for GPIO12 (DCONBLANK) */
94 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_INPUT_FILTER);
96 /* Disable filter for GPIO7 */
97 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_INPUT_FILTER);
99 /* Disable event counter for GPIO7 (DCONIRQ) and GPIO12 (DCONBLANK) */
100 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_INPUT_EVENT_COUNT);
101 cs5535_gpio_clear(OLPC_GPIO_DCON_BLANK, GPIO_INPUT_EVENT_COUNT);
103 /* Add GPIO12 to the Filter Event Pair #7 */
104 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_FE7_SEL);
106 /* Turn off negative Edge Enable for GPIO12 */
107 cs5535_gpio_clear(OLPC_GPIO_DCON_BLANK, GPIO_NEGATIVE_EDGE_EN);
109 /* Enable negative Edge Enable for GPIO7 */
110 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_EN);
112 /* Zero the filter amount for Filter Event Pair #7 */
113 cs5535_gpio_set(0, GPIO_FLTR7_AMOUNT);
115 /* Clear the negative edge status for GPIO7 and GPIO12 */
116 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_STS);
117 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_NEGATIVE_EDGE_STS);
119 /* FIXME: Clear the positive status as well, just to be sure */
120 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_POSITIVE_EDGE_STS);
121 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_POSITIVE_EDGE_STS);
123 /* Enable events for GPIO7 (DCONIRQ) and GPIO12 (DCONBLANK) */
124 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_EVENTS_ENABLE);
125 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_EVENTS_ENABLE);
130 gpio_free(OLPC_GPIO_DCON_BLANK);
132 gpio_free(OLPC_GPIO_DCON_LOAD);
134 gpio_free(OLPC_GPIO_DCON_IRQ);
136 gpio_free(OLPC_GPIO_DCON_STAT1);
138 gpio_free(OLPC_GPIO_DCON_STAT0);
142 static void dcon_wiggle_xo_1(void)
147 * According to HiMax, when powering the DCON up we should hold
148 * SMB_DATA high for 8 SMB_CLK cycles. This will force the DCON
149 * state machine to reset to a (sane) initial state. Mitch Bradley
150 * did some testing and discovered that holding for 16 SMB_CLK cycles
151 * worked a lot more reliably, so that's what we do here.
153 * According to the cs5536 spec, to set GPIO14 to SMB_CLK we must
154 * simultaneously set AUX1 IN/OUT to GPIO14; ditto for SMB_DATA and
157 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL);
158 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_VAL);
159 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_ENABLE);
160 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_ENABLE);
161 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_AUX1);
162 cs5535_gpio_clear(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX1);
163 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_AUX2);
164 cs5535_gpio_clear(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX2);
165 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_INPUT_AUX1);
166 cs5535_gpio_clear(OLPC_GPIO_SMB_DATA, GPIO_INPUT_AUX1);
168 for (x = 0; x < 16; x++) {
170 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL);
172 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL);
175 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_AUX1);
176 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX1);
177 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_INPUT_AUX1);
178 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_INPUT_AUX1);
181 static void dcon_set_dconload_1(int val)
183 gpio_set_value(OLPC_GPIO_DCON_LOAD, val);
186 static int dcon_read_status_xo_1(u8 *status)
188 *status = gpio_get_value(OLPC_GPIO_DCON_STAT0);
189 *status |= gpio_get_value(OLPC_GPIO_DCON_STAT1) << 1;
191 /* Clear the negative edge status for GPIO7 */
192 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_STS);
197 struct dcon_platform_data dcon_pdata_xo_1 = {
198 .init = dcon_init_xo_1,
199 .bus_stabilize_wiggle = dcon_wiggle_xo_1,
200 .set_dconload = dcon_set_dconload_1,
201 .read_status = dcon_read_status_xo_1,