4 * Copyright 2015 Google Inc.
5 * Copyright 2014 Linaro Ltd.
7 * Released under the GPLv2 only.
12 /* endo sysfs attributes */
13 static ssize_t serial_number_show(struct device *dev,
14 struct device_attribute *attr, char *buf)
16 struct gb_endo *endo = to_gb_endo(dev);
18 return sprintf(buf, "%s", &endo->svc.serial_number[0]);
20 static DEVICE_ATTR_RO(serial_number);
22 static ssize_t version_show(struct device *dev, struct device_attribute *attr,
25 struct gb_endo *endo = to_gb_endo(dev);
27 return sprintf(buf, "%s", &endo->svc.version[0]);
29 static DEVICE_ATTR_RO(version);
31 static struct attribute *endo_attrs[] = {
32 &dev_attr_serial_number.attr,
33 &dev_attr_version.attr,
36 static const struct attribute_group endo_group = {
40 static const struct attribute_group *endo_groups[] = {
45 static void greybus_endo_release(struct device *dev)
47 struct gb_endo *endo = to_gb_endo(dev);
52 struct device_type greybus_endo_type = {
53 .name = "greybus_endo",
54 .release = greybus_endo_release,
59 * Endo "types" have different module locations, these are tables based on those
60 * types that list the module ids for the different locations.
62 * List must end with 0x00 in order to properly terminate the list.
64 static u8 endo_4755[] = {
79 static int create_modules(struct gb_endo *endo)
81 struct gb_module *module;
85 /* Depending on the endo type, create a bunch of different modules */
88 endo_modules = &endo_4755[0];
91 dev_err(&endo->dev, "Unknown endo type 0x%04x, aborting!",
96 for (i = 0; endo_modules[i] != 0x00; ++i) {
97 module = gb_module_create(&endo->dev, endo_modules[i]);
105 struct gb_endo *gb_endo_create(struct greybus_host_device *hd)
107 struct gb_endo *endo;
110 endo = kzalloc(sizeof(*endo), GFP_KERNEL);
114 endo->dev.parent = hd->parent;
115 endo->dev.bus = &greybus_bus_type;
116 endo->dev.type = &greybus_endo_type;
117 endo->dev.groups = endo_groups;
118 endo->dev.dma_mask = hd->parent->dma_mask;
119 device_initialize(&endo->dev);
121 // FIXME - determine endo "type" from the SVC
122 // Also get the version and serial number from the SVC, right now we are
123 // using "fake" numbers.
124 strcpy(&endo->svc.serial_number[0], "042");
125 strcpy(&endo->svc.version[0], "0.0");
128 dev_set_name(&endo->dev, "endo-0x%04x", endo->type);
129 retval = device_add(&endo->dev);
131 dev_err(hd->parent, "failed to add endo device of type 0x%04x\n",
133 put_device(&endo->dev);
138 retval = create_modules(endo);
140 gb_endo_remove(endo);
147 void gb_endo_remove(struct gb_endo *endo)
152 /* remove all modules for this endo */
153 gb_module_remove_all(endo);
155 device_unregister(&endo->dev);