^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * cros_ec_dev - expose the Chrome OS Embedded Controller to user-space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kconfig.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_data/cros_ec_chardev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_data/cros_ec_commands.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_data/cros_ec_proto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DRV_NAME "cros-ec-dev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static struct class cros_class = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .name = "chromeos",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * struct cros_feature_to_name - CrOS feature id to name/short description.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @id: The feature identifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @name: Device name associated with the feature id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * @desc: Short name that will be displayed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct cros_feature_to_name {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const char *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * struct cros_feature_to_cells - CrOS feature id to mfd cells association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * @id: The feature identifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @mfd_cells: Pointer to the array of mfd cells that needs to be added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @num_cells: Number of mfd cells into the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct cros_feature_to_cells {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) const struct mfd_cell *mfd_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int num_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static const struct cros_feature_to_name cros_mcu_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .id = EC_FEATURE_FINGERPRINT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .name = CROS_EC_DEV_FP_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .desc = "Fingerprint",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .id = EC_FEATURE_ISH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .name = CROS_EC_DEV_ISH_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .desc = "Integrated Sensor Hub",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .id = EC_FEATURE_SCP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .name = CROS_EC_DEV_SCP_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .desc = "System Control Processor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .id = EC_FEATURE_TOUCHPAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .name = CROS_EC_DEV_TP_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .desc = "Touchpad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static const struct mfd_cell cros_ec_cec_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) { .name = "cros-ec-cec", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static const struct mfd_cell cros_ec_rtc_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) { .name = "cros-ec-rtc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct mfd_cell cros_ec_sensorhub_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) { .name = "cros-ec-sensorhub", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static const struct mfd_cell cros_usbpd_charger_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) { .name = "cros-usbpd-charger", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) { .name = "cros-usbpd-logger", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static const struct mfd_cell cros_usbpd_notify_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) { .name = "cros-usbpd-notify", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static const struct cros_feature_to_cells cros_subdevices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .id = EC_FEATURE_CEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .mfd_cells = cros_ec_cec_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .num_cells = ARRAY_SIZE(cros_ec_cec_cells),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .id = EC_FEATURE_RTC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .mfd_cells = cros_ec_rtc_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .num_cells = ARRAY_SIZE(cros_ec_rtc_cells),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .id = EC_FEATURE_USB_PD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .mfd_cells = cros_usbpd_charger_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct mfd_cell cros_ec_platform_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { .name = "cros-ec-chardev", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) { .name = "cros-ec-debugfs", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) { .name = "cros-ec-lightbar", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) { .name = "cros-ec-sysfs", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static const struct mfd_cell cros_ec_vbc_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) { .name = "cros-ec-vbc", }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void cros_ec_class_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) kfree(to_cros_ec_dev(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int ec_device_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct cros_ec_platform *ec_platform = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) dev_set_drvdata(dev, ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ec->ec_dev = dev_get_drvdata(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ec->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ec->cmd_offset = ec_platform->cmd_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ec->features[0] = -1U; /* Not cached yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ec->features[1] = -1U; /* Not cached yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) device_initialize(&ec->class_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * Check whether this is actually a dedicated MCU rather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * than an standard EC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (cros_ec_check_features(ec, cros_mcu_devices[i].id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dev_info(dev, "CrOS %s MCU detected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) cros_mcu_devices[i].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * Help userspace differentiating ECs from other MCU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * regardless of the probing order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ec_platform->ec_name = cros_mcu_devices[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * Add the class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ec->class_dev.class = &cros_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ec->class_dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ec->class_dev.release = cros_ec_class_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) dev_err(dev, "dev_set_name failed => %d\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) retval = device_add(&ec->class_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* check whether this EC is a sensor hub. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (cros_ec_get_sensor_count(ec) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) retval = mfd_add_hotplug_devices(ec->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) cros_ec_sensorhub_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ARRAY_SIZE(cros_ec_sensorhub_cells));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) dev_err(ec->dev, "failed to add %s subdevice: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) cros_ec_sensorhub_cells->name, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * The following subdevices can be detected by sending the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * EC_FEATURE_GET_CMD Embedded Controller device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) for (i = 0; i < ARRAY_SIZE(cros_subdevices); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (cros_ec_check_features(ec, cros_subdevices[i].id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) retval = mfd_add_hotplug_devices(ec->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) cros_subdevices[i].mfd_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) cros_subdevices[i].num_cells);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) dev_err(ec->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) "failed to add %s subdevice: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) cros_subdevices[i].mfd_cells->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * The PD notifier driver cell is separate since it only needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * explicitly added on platforms that don't have the PD notifier ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * device entry defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (IS_ENABLED(CONFIG_OF) && ec->ec_dev->dev->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (cros_ec_check_features(ec, EC_FEATURE_USB_PD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) retval = mfd_add_hotplug_devices(ec->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) cros_usbpd_notify_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ARRAY_SIZE(cros_usbpd_notify_cells));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) dev_err(ec->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) "failed to add PD notify devices: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * The following subdevices cannot be detected by sending the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * EC_FEATURE_GET_CMD to the Embedded Controller device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) retval = mfd_add_hotplug_devices(ec->dev, cros_ec_platform_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ARRAY_SIZE(cros_ec_platform_cells));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_warn(ec->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) "failed to add cros-ec platform devices: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Check whether this EC instance has a VBC NVRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) node = ec->ec_dev->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (of_property_read_bool(node, "google,has-vbc-nvram")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) retval = mfd_add_hotplug_devices(ec->dev, cros_ec_vbc_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ARRAY_SIZE(cros_ec_vbc_cells));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) dev_warn(ec->dev, "failed to add VBC devices: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) put_device(&ec->class_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int ec_device_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) mfd_remove_devices(ec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) device_unregister(&ec->class_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct platform_device_id cros_ec_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) { DRV_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) MODULE_DEVICE_TABLE(platform, cros_ec_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static struct platform_driver cros_ec_dev_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .id_table = cros_ec_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .probe = ec_device_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .remove = ec_device_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int __init cros_ec_dev_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ret = class_register(&cros_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) pr_err(CROS_EC_DEV_NAME ": failed to register device class\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* Register the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ret = platform_driver_register(&cros_ec_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) pr_warn(CROS_EC_DEV_NAME ": can't register driver: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) goto failed_devreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) failed_devreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) class_unregister(&cros_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static void __exit cros_ec_dev_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) platform_driver_unregister(&cros_ec_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) class_unregister(&cros_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) module_init(cros_ec_dev_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) module_exit(cros_ec_dev_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) MODULE_ALIAS("platform:" DRV_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_AUTHOR("Bill Richardson <wfrichar@chromium.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) MODULE_DESCRIPTION("Userspace interface to the Chrome OS Embedded Controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_VERSION("1.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_LICENSE("GPL");