Skip to content

Commit 36a8032

Browse files
committed
Merge tag 'chrome-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/olof/chrome-platform
Pull chrome platform updates from Olof Johansson: "Here's a set of updates to the Chrome OS platform drivers for this merge window. Main new things this cycle is: - Driver changes to expose the lightbar to users. With this, you can make your own blinkenlights on Chromebook Pixels. - Changes in the way that the atmel_mxt trackpads are probed. The laptop driver is trying to be smart and not instantiate the devices that don't answer to probe. For the trackpad that can come up in two modes (bootloader or regular), this gets complicated since the driver already knows how to handle the two modes including the actual addresses used. So now the laptop driver needs to know more too, instantiating the regular address even if the bootloader one is the probe that passed. - mfd driver improvements by Javier Martines Canillas, and a few bugfixes from him, kbuild and myself" * tag 'chrome-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/olof/chrome-platform: platform/chrome: chromeos_laptop - instantiate Atmel at primary address platform/chrome: cros_ec_lpc - Depend on X86 || COMPILE_TEST platform/chrome: cros_ec_lpc - Include linux/io.h header file platform/chrome: fix platform_no_drv_owner.cocci warnings platform/chrome: cros_ec_lightbar - fix duplicate const warning platform/chrome: cros_ec_dev - fix Unknown escape '%' warning platform/chrome: Expose Chrome OS Lightbar to users platform/chrome: Create sysfs attributes for the ChromeOS EC mfd: cros_ec: Instantiate ChromeOS EC character device platform/chrome: Add Chrome OS EC userspace device interface platform/chrome: Add cros_ec_lpc driver for x86 devices mfd: cros_ec: Add char dev and virtual dev pointers mfd: cros_ec: Use fixed size arrays to transfer data with the EC
2 parents 7f9f443 + 96cba9b commit 36a8032

File tree

13 files changed

+1384
-71
lines changed

13 files changed

+1384
-71
lines changed

Documentation/ioctl/ioctl-number.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ Code Seq#(hex) Include File Comments
321321
0xDB 00-0F drivers/char/mwave/mwavepub.h
322322
0xDD 00-3F ZFCP device driver see drivers/s390/scsi/
323323
324+
0xEC 00-01 drivers/platform/chrome/cros_ec_dev.h ChromeOS EC driver
324325
0xF3 00-3F drivers/usb/misc/sisusbvga/sisusb.h sisfb (in development)
325326
326327
0xF4 00-1F video/mbxfb.h mbxfb

drivers/i2c/busses/i2c-cros-ec-tunnel.c

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -182,72 +182,41 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[],
182182
const u16 bus_num = bus->remote_bus;
183183
int request_len;
184184
int response_len;
185-
u8 *request = NULL;
186-
u8 *response = NULL;
187185
int result;
188-
struct cros_ec_command msg;
186+
struct cros_ec_command msg = { };
189187

190188
request_len = ec_i2c_count_message(i2c_msgs, num);
191189
if (request_len < 0) {
192190
dev_warn(dev, "Error constructing message %d\n", request_len);
193-
result = request_len;
194-
goto exit;
191+
return request_len;
195192
}
193+
196194
response_len = ec_i2c_count_response(i2c_msgs, num);
197195
if (response_len < 0) {
198196
/* Unexpected; no errors should come when NULL response */
199197
dev_warn(dev, "Error preparing response %d\n", response_len);
200-
result = response_len;
201-
goto exit;
202-
}
203-
204-
if (request_len <= ARRAY_SIZE(bus->request_buf)) {
205-
request = bus->request_buf;
206-
} else {
207-
request = kzalloc(request_len, GFP_KERNEL);
208-
if (request == NULL) {
209-
result = -ENOMEM;
210-
goto exit;
211-
}
212-
}
213-
if (response_len <= ARRAY_SIZE(bus->response_buf)) {
214-
response = bus->response_buf;
215-
} else {
216-
response = kzalloc(response_len, GFP_KERNEL);
217-
if (response == NULL) {
218-
result = -ENOMEM;
219-
goto exit;
220-
}
198+
return response_len;
221199
}
222200

223-
result = ec_i2c_construct_message(request, i2c_msgs, num, bus_num);
201+
result = ec_i2c_construct_message(msg.outdata, i2c_msgs, num, bus_num);
224202
if (result)
225-
goto exit;
203+
return result;
226204

227205
msg.version = 0;
228206
msg.command = EC_CMD_I2C_PASSTHRU;
229-
msg.outdata = request;
230207
msg.outsize = request_len;
231-
msg.indata = response;
232208
msg.insize = response_len;
233209

234210
result = cros_ec_cmd_xfer(bus->ec, &msg);
235211
if (result < 0)
236-
goto exit;
212+
return result;
237213

238-
result = ec_i2c_parse_response(response, i2c_msgs, &num);
214+
result = ec_i2c_parse_response(msg.indata, i2c_msgs, &num);
239215
if (result < 0)
240-
goto exit;
216+
return result;
241217

242218
/* Indicate success by saying how many messages were sent */
243-
result = num;
244-
exit:
245-
if (request != bus->request_buf)
246-
kfree(request);
247-
if (response != bus->response_buf)
248-
kfree(response);
249-
250-
return result;
219+
return num;
251220
}
252221

253222
static u32 ec_i2c_functionality(struct i2c_adapter *adap)

drivers/input/keyboard/cros_ec_keyb.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,19 @@ static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev,
148148

149149
static int cros_ec_keyb_get_state(struct cros_ec_keyb *ckdev, uint8_t *kb_state)
150150
{
151+
int ret;
151152
struct cros_ec_command msg = {
152-
.version = 0,
153153
.command = EC_CMD_MKBP_STATE,
154-
.outdata = NULL,
155-
.outsize = 0,
156-
.indata = kb_state,
157154
.insize = ckdev->cols,
158155
};
159156

160-
return cros_ec_cmd_xfer(ckdev->ec, &msg);
157+
ret = cros_ec_cmd_xfer(ckdev->ec, &msg);
158+
if (ret < 0)
159+
return ret;
160+
161+
memcpy(kb_state, msg.indata, ckdev->cols);
162+
163+
return 0;
161164
}
162165

163166
static irqreturn_t cros_ec_keyb_irq(int irq, void *data)

drivers/mfd/cros_ec.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,11 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
7474
ret = ec_dev->cmd_xfer(ec_dev, msg);
7575
if (msg->result == EC_RES_IN_PROGRESS) {
7676
int i;
77-
struct cros_ec_command status_msg;
78-
struct ec_response_get_comms_status status;
77+
struct cros_ec_command status_msg = { };
78+
struct ec_response_get_comms_status *status;
7979

80-
status_msg.version = 0;
8180
status_msg.command = EC_CMD_GET_COMMS_STATUS;
82-
status_msg.outdata = NULL;
83-
status_msg.outsize = 0;
84-
status_msg.indata = (uint8_t *)&status;
85-
status_msg.insize = sizeof(status);
81+
status_msg.insize = sizeof(*status);
8682

8783
/*
8884
* Query the EC's status until it's no longer busy or
@@ -98,7 +94,10 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
9894
msg->result = status_msg.result;
9995
if (status_msg.result != EC_RES_SUCCESS)
10096
break;
101-
if (!(status.flags & EC_COMMS_STATUS_PROCESSING))
97+
98+
status = (struct ec_response_get_comms_status *)
99+
status_msg.indata;
100+
if (!(status->flags & EC_COMMS_STATUS_PROCESSING))
102101
break;
103102
}
104103
}
@@ -119,6 +118,10 @@ static const struct mfd_cell cros_devs[] = {
119118
.id = 2,
120119
.of_compatible = "google,cros-ec-i2c-tunnel",
121120
},
121+
{
122+
.name = "cros-ec-ctl",
123+
.id = 3,
124+
},
122125
};
123126

124127
int cros_ec_register(struct cros_ec_device *ec_dev)

drivers/platform/chrome/Kconfig

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
menuconfig CHROME_PLATFORMS
66
bool "Platform support for Chrome hardware"
7-
depends on X86
7+
depends on X86 || ARM
88
---help---
99
Say Y here to get to see options for platform support for
1010
various Chromebooks and Chromeboxes. This option alone does
@@ -16,8 +16,7 @@ if CHROME_PLATFORMS
1616

1717
config CHROMEOS_LAPTOP
1818
tristate "Chrome OS Laptop"
19-
depends on I2C
20-
depends on DMI
19+
depends on I2C && DMI && X86
2120
---help---
2221
This driver instantiates i2c and smbus devices such as
2322
light sensors and touchpads.
@@ -27,6 +26,7 @@ config CHROMEOS_LAPTOP
2726

2827
config CHROMEOS_PSTORE
2928
tristate "Chrome OS pstore support"
29+
depends on X86
3030
---help---
3131
This module instantiates the persistent storage on x86 ChromeOS
3232
devices. It can be used to store away console logs and crash
@@ -38,5 +38,25 @@ config CHROMEOS_PSTORE
3838
If you have a supported Chromebook, choose Y or M here.
3939
The module will be called chromeos_pstore.
4040

41+
config CROS_EC_CHARDEV
42+
tristate "Chrome OS Embedded Controller userspace device interface"
43+
depends on MFD_CROS_EC
44+
---help---
45+
This driver adds support to talk with the ChromeOS EC from userspace.
46+
47+
If you have a supported Chromebook, choose Y or M here.
48+
The module will be called cros_ec_dev.
49+
50+
config CROS_EC_LPC
51+
tristate "ChromeOS Embedded Controller (LPC)"
52+
depends on MFD_CROS_EC && (X86 || COMPILE_TEST)
53+
help
54+
If you say Y here, you get support for talking to the ChromeOS EC
55+
over an LPC bus. This uses a simple byte-level protocol with a
56+
checksum. This is used for userspace access only. The kernel
57+
typically has its own communication methods.
58+
59+
To compile this driver as a module, choose M here: the
60+
module will be called cros_ec_lpc.
4161

4262
endif # CHROMEOS_PLATFORMS

drivers/platform/chrome/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11

22
obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
33
obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
4+
cros_ec_devs-objs := cros_ec_dev.o cros_ec_sysfs.o cros_ec_lightbar.o
5+
obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_devs.o
6+
obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpc.o

drivers/platform/chrome/chromeos_laptop.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ static struct i2c_client *__add_probed_i2c_device(
133133
const char *name,
134134
int bus,
135135
struct i2c_board_info *info,
136-
const unsigned short *addrs)
136+
const unsigned short *alt_addr_list)
137137
{
138138
const struct dmi_device *dmi_dev;
139139
const struct dmi_dev_onboard *dev_data;
140140
struct i2c_adapter *adapter;
141-
struct i2c_client *client;
141+
struct i2c_client *client = NULL;
142+
const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
142143

143144
if (bus < 0)
144145
return NULL;
@@ -169,8 +170,28 @@ static struct i2c_client *__add_probed_i2c_device(
169170
return NULL;
170171
}
171172

172-
/* add the i2c device */
173-
client = i2c_new_probed_device(adapter, info, addrs, NULL);
173+
/*
174+
* Add the i2c device. If we can't detect it at the primary
175+
* address we scan secondary addresses. In any case the client
176+
* structure gets assigned primary address.
177+
*/
178+
client = i2c_new_probed_device(adapter, info, addr_list, NULL);
179+
if (!client && alt_addr_list) {
180+
struct i2c_board_info dummy_info = {
181+
I2C_BOARD_INFO("dummy", info->addr),
182+
};
183+
struct i2c_client *dummy;
184+
185+
dummy = i2c_new_probed_device(adapter, &dummy_info,
186+
alt_addr_list, NULL);
187+
if (dummy) {
188+
pr_debug("%s %d-%02x is probed at %02x\n",
189+
__func__, bus, info->addr, dummy->addr);
190+
i2c_unregister_device(dummy);
191+
client = i2c_new_device(adapter, info);
192+
}
193+
}
194+
174195
if (!client)
175196
pr_notice("%s failed to register device %d-%02x\n",
176197
__func__, bus, info->addr);
@@ -254,12 +275,10 @@ static struct i2c_client *add_i2c_device(const char *name,
254275
enum i2c_adapter_type type,
255276
struct i2c_board_info *info)
256277
{
257-
const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
258-
259278
return __add_probed_i2c_device(name,
260279
find_i2c_adapter_num(type),
261280
info,
262-
addr_list);
281+
NULL);
263282
}
264283

265284
static int setup_cyapa_tp(enum i2c_adapter_type type)
@@ -275,7 +294,6 @@ static int setup_cyapa_tp(enum i2c_adapter_type type)
275294
static int setup_atmel_224s_tp(enum i2c_adapter_type type)
276295
{
277296
const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
278-
ATMEL_TP_I2C_ADDR,
279297
I2C_CLIENT_END };
280298
if (tp)
281299
return 0;
@@ -289,7 +307,6 @@ static int setup_atmel_224s_tp(enum i2c_adapter_type type)
289307
static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
290308
{
291309
const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
292-
ATMEL_TS_I2C_ADDR,
293310
I2C_CLIENT_END };
294311
if (ts)
295312
return 0;

0 commit comments

Comments
 (0)