1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2009,2010 One Laptop per Child
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/acpi.h>
9 #include <linux/delay.h>
10 #include <linux/i2c.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/gpio/machine.h>
15 /* TODO: this eventually belongs in linux/vx855.h */
16 #define NR_VX855_GPI 14
17 #define NR_VX855_GPO 13
18 #define NR_VX855_GPIO 15
20 #define VX855_GPI(n) (n)
21 #define VX855_GPO(n) (NR_VX855_GPI + (n))
22 #define VX855_GPIO(n) (NR_VX855_GPI + NR_VX855_GPO + (n))
24 #include "olpc_dcon.h"
26 /* Hardware setup on the XO 1.5:
27 * DCONLOAD connects to VX855_GPIO1 (not SMBCK2)
28 * DCONBLANK connects to VX855_GPIO8 (not SSPICLK) unused in driver
29 * DCONSTAT0 connects to VX855_GPI10 (not SSPISDI)
30 * DCONSTAT1 connects to VX855_GPI11 (not nSSPISS)
31 * DCONIRQ connects to VX855_GPIO12
32 * DCONSMBDATA connects to VX855 graphics CRTSPD
33 * DCONSMBCLK connects to VX855 graphics CRTSPCLK
36 #define VX855_GENL_PURPOSE_OUTPUT 0x44c /* PMIO_Rx4c-4f */
37 #define VX855_GPI_STATUS_CHG 0x450 /* PMIO_Rx50 */
38 #define VX855_GPI_SCI_SMI 0x452 /* PMIO_Rx52 */
39 #define BIT_GPIO12 0x40
41 #define PREFIX "OLPC DCON:"
49 struct gpiod_lookup_table gpios_table = {
52 GPIO_LOOKUP("VX855 South Bridge", VX855_GPIO(1), "dcon_load",
54 GPIO_LOOKUP("VX855 South Bridge", VX855_GPI(10), "dcon_stat0",
56 GPIO_LOOKUP("VX855 South Bridge", VX855_GPI(11), "dcon_stat1",
62 static const struct dcon_gpio gpios_asis[] = {
63 [OLPC_DCON_STAT0] = { .name = "dcon_stat0", .flags = GPIOD_ASIS },
64 [OLPC_DCON_STAT1] = { .name = "dcon_stat1", .flags = GPIOD_ASIS },
65 [OLPC_DCON_LOAD] = { .name = "dcon_load", .flags = GPIOD_ASIS },
68 static struct gpio_desc *gpios[3];
70 static void dcon_clear_irq(void)
72 /* irq status will appear in PMIO_Rx50[6] (RW1C) on gpio12 */
73 outb(BIT_GPIO12, VX855_GPI_STATUS_CHG);
76 static int dcon_was_irq(void)
80 /* irq status will appear in PMIO_Rx50[6] on gpio12 */
81 tmp = inb(VX855_GPI_STATUS_CHG);
83 return !!(tmp & BIT_GPIO12);
86 static int dcon_init_xo_1_5(struct dcon_priv *dcon)
89 const struct dcon_gpio *pin = &gpios_asis[0];
93 /* Add GPIO look up table */
94 gpios_table.dev_id = dev_name(&dcon->client->dev);
95 gpiod_add_lookup_table(&gpios_table);
97 /* Get GPIO descriptor */
98 for (i = 0; i < ARRAY_SIZE(gpios_asis); i++) {
99 gpios[i] = devm_gpiod_get(&dcon->client->dev, pin[i].name,
101 if (IS_ERR(gpios[i])) {
102 ret = PTR_ERR(gpios[i]);
103 pr_err("failed to request %s GPIO: %d\n", pin[i].name,
111 /* set PMIO_Rx52[6] to enable SCI/SMI on gpio12 */
112 outb(inb(VX855_GPI_SCI_SMI) | BIT_GPIO12, VX855_GPI_SCI_SMI);
114 /* Determine the current state of DCONLOAD, likely set by firmware */
116 dcon->curr_src = (inl(VX855_GENL_PURPOSE_OUTPUT) & 0x1000) ?
117 DCON_SOURCE_CPU : DCON_SOURCE_DCON;
118 dcon->pending_src = dcon->curr_src;
120 /* we're sharing the IRQ with ACPI */
121 irq = acpi_gbl_FADT.sci_interrupt;
122 if (request_irq(irq, &dcon_interrupt, IRQF_SHARED, "DCON", dcon)) {
123 pr_err("DCON (IRQ%d) allocation failed\n", irq);
130 static void set_i2c_line(int sda, int scl)
133 unsigned int port = 0x26;
135 /* FIXME: This directly accesses the CRT GPIO controller !!! */
155 static void dcon_wiggle_xo_1_5(void)
160 * According to HiMax, when powering the DCON up we should hold
161 * SMB_DATA high for 8 SMB_CLK cycles. This will force the DCON
162 * state machine to reset to a (sane) initial state. Mitch Bradley
163 * did some testing and discovered that holding for 16 SMB_CLK cycles
164 * worked a lot more reliably, so that's what we do here.
168 for (x = 0; x < 16; x++) {
176 /* set PMIO_Rx52[6] to enable SCI/SMI on gpio12 */
177 outb(inb(VX855_GPI_SCI_SMI) | BIT_GPIO12, VX855_GPI_SCI_SMI);
180 static void dcon_set_dconload_xo_1_5(int val)
182 gpiod_set_value(gpios[OLPC_DCON_LOAD], val);
185 static int dcon_read_status_xo_1_5(u8 *status)
190 /* i believe this is the same as "inb(0x44b) & 3" */
191 *status = gpiod_get_value(gpios[OLPC_DCON_STAT0]);
192 *status |= gpiod_get_value(gpios[OLPC_DCON_STAT1]) << 1;
199 struct dcon_platform_data dcon_pdata_xo_1_5 = {
200 .init = dcon_init_xo_1_5,
201 .bus_stabilize_wiggle = dcon_wiggle_xo_1_5,
202 .set_dconload = dcon_set_dconload_xo_1_5,
203 .read_status = dcon_read_status_xo_1_5,