1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. 4 */ 5 #include <linux/kernel.h> 6 #include <linux/errno.h> 7 #include <linux/idr.h> 8 #include <linux/slab.h> 9 #include <linux/module.h> 10 #include <linux/of.h> 11 #include <linux/of_device.h> 12 #include <linux/platform_device.h> 13 #include <linux/spmi.h> 14 #include <linux/pm_runtime.h> 15 16 #include <dt-bindings/spmi/spmi.h> 17 #define CREATE_TRACE_POINTS 18 #include <trace/events/spmi.h> 19 20 static bool is_registered; 21 static DEFINE_IDA(ctrl_ida); 22 static DEFINE_IDA(spmi_subdevice_ida); 23 24 static void spmi_dev_release(struct device *dev) 25 { 26 struct spmi_device *sdev = to_spmi_device(dev); 27 28 of_node_put(dev->of_node); 29 kfree(sdev); 30 } 31 32 static const struct device_type spmi_dev_type = { 33 .release = spmi_dev_release, 34 }; 35 36 static void spmi_subdev_release(struct device *dev) 37 { 38 struct spmi_device *sdev = to_spmi_device(dev); 39 struct spmi_subdevice *sub_sdev = container_of(sdev, struct spmi_subdevice, sdev); 40 41 ida_free(&spmi_subdevice_ida, sub_sdev->devid); 42 kfree(sub_sdev); 43 } 44 45 static const struct device_type spmi_subdev_type = { 46 .release = spmi_subdev_release, 47 }; 48 49 static void spmi_ctrl_release(struct device *dev) 50 { 51 struct spmi_controller *ctrl = to_spmi_controller(dev); 52 53 ida_free(&ctrl_ida, ctrl->nr); 54 kfree(ctrl); 55 } 56 57 static const struct device_type spmi_ctrl_type = { 58 .release = spmi_ctrl_release, 59 }; 60 61 static int spmi_device_match(struct device *dev, const struct device_driver *drv) 62 { 63 if (of_driver_match_device(dev, drv)) 64 return 1; 65 66 if (drv->name) 67 return strncmp(dev_name(dev), drv->name, 68 SPMI_NAME_SIZE) == 0; 69 70 return 0; 71 } 72 73 /** 74 * spmi_device_add() - add a device previously constructed via spmi_device_alloc() 75 * @sdev: spmi_device to be added 76 */ 77 int spmi_device_add(struct spmi_device *sdev) 78 { 79 struct spmi_controller *ctrl = sdev->ctrl; 80 int err; 81 82 dev_set_name(&sdev->dev, "%d-%02x", ctrl->nr, sdev->usid); 83 84 err = device_add(&sdev->dev); 85 if (err < 0) { 86 dev_err(&sdev->dev, "Can't add device, status %pe\n", ERR_PTR(err)); 87 return err; 88 } 89 90 dev_dbg(&sdev->dev, "device registered\n"); 91 return 0; 92 } 93 EXPORT_SYMBOL_GPL(spmi_device_add); 94 95 /** 96 * spmi_device_remove(): remove an SPMI device 97 * @sdev: spmi_device to be removed 98 */ 99 void spmi_device_remove(struct spmi_device *sdev) 100 { 101 device_unregister(&sdev->dev); 102 } 103 EXPORT_SYMBOL_GPL(spmi_device_remove); 104 105 /** 106 * spmi_subdevice_remove() - Remove an SPMI subdevice 107 * @sub_sdev: spmi_device to be removed 108 */ 109 void spmi_subdevice_remove(struct spmi_subdevice *sub_sdev) 110 { 111 struct spmi_device *sdev = &sub_sdev->sdev; 112 113 device_unregister(&sdev->dev); 114 } 115 EXPORT_SYMBOL_NS_GPL(spmi_subdevice_remove, "SPMI"); 116 117 static inline int 118 spmi_cmd(struct spmi_controller *ctrl, u8 opcode, u8 sid) 119 { 120 int ret; 121 122 if (!ctrl || !ctrl->cmd || ctrl->dev.type != &spmi_ctrl_type) 123 return -EINVAL; 124 125 ret = ctrl->cmd(ctrl, opcode, sid); 126 trace_spmi_cmd(opcode, sid, ret); 127 return ret; 128 } 129 130 static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode, 131 u8 sid, u16 addr, u8 *buf, size_t len) 132 { 133 int ret; 134 135 if (!ctrl || !ctrl->read_cmd || ctrl->dev.type != &spmi_ctrl_type) 136 return -EINVAL; 137 138 trace_spmi_read_begin(opcode, sid, addr); 139 ret = ctrl->read_cmd(ctrl, opcode, sid, addr, buf, len); 140 trace_spmi_read_end(opcode, sid, addr, ret, len, buf); 141 return ret; 142 } 143 144 static inline int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode, 145 u8 sid, u16 addr, const u8 *buf, size_t len) 146 { 147 int ret; 148 149 if (!ctrl || !ctrl->write_cmd || ctrl->dev.type != &spmi_ctrl_type) 150 return -EINVAL; 151 152 trace_spmi_write_begin(opcode, sid, addr, len, buf); 153 ret = ctrl->write_cmd(ctrl, opcode, sid, addr, buf, len); 154 trace_spmi_write_end(opcode, sid, addr, ret); 155 return ret; 156 } 157 158 /** 159 * spmi_register_read() - register read 160 * @sdev: SPMI device. 161 * @addr: slave register address (5-bit address). 162 * @buf: buffer to be populated with data from the Slave. 163 * 164 * Reads 1 byte of data from a Slave device register. 165 */ 166 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf) 167 { 168 /* 5-bit register address */ 169 if (addr > 0x1F) 170 return -EINVAL; 171 172 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_READ, sdev->usid, addr, 173 buf, 1); 174 } 175 EXPORT_SYMBOL_GPL(spmi_register_read); 176 177 /** 178 * spmi_ext_register_read() - extended register read 179 * @sdev: SPMI device. 180 * @addr: slave register address (8-bit address). 181 * @buf: buffer to be populated with data from the Slave. 182 * @len: the request number of bytes to read (up to 16 bytes). 183 * 184 * Reads up to 16 bytes of data from the extended register space on a 185 * Slave device. 186 */ 187 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, 188 size_t len) 189 { 190 /* 8-bit register address, up to 16 bytes */ 191 if (len == 0 || len > 16) 192 return -EINVAL; 193 194 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READ, sdev->usid, addr, 195 buf, len); 196 } 197 EXPORT_SYMBOL_GPL(spmi_ext_register_read); 198 199 /** 200 * spmi_ext_register_readl() - extended register read long 201 * @sdev: SPMI device. 202 * @addr: slave register address (16-bit address). 203 * @buf: buffer to be populated with data from the Slave. 204 * @len: the request number of bytes to read (up to 8 bytes). 205 * 206 * Reads up to 8 bytes of data from the extended register space on a 207 * Slave device using 16-bit address. 208 */ 209 int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf, 210 size_t len) 211 { 212 /* 16-bit register address, up to 8 bytes */ 213 if (len == 0 || len > 8) 214 return -EINVAL; 215 216 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READL, sdev->usid, addr, 217 buf, len); 218 } 219 EXPORT_SYMBOL_GPL(spmi_ext_register_readl); 220 221 /** 222 * spmi_register_write() - register write 223 * @sdev: SPMI device 224 * @addr: slave register address (5-bit address). 225 * @data: buffer containing the data to be transferred to the Slave. 226 * 227 * Writes 1 byte of data to a Slave device register. 228 */ 229 int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data) 230 { 231 /* 5-bit register address */ 232 if (addr > 0x1F) 233 return -EINVAL; 234 235 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_WRITE, sdev->usid, addr, 236 &data, 1); 237 } 238 EXPORT_SYMBOL_GPL(spmi_register_write); 239 240 /** 241 * spmi_register_zero_write() - register zero write 242 * @sdev: SPMI device. 243 * @data: the data to be written to register 0 (7-bits). 244 * 245 * Writes data to register 0 of the Slave device. 246 */ 247 int spmi_register_zero_write(struct spmi_device *sdev, u8 data) 248 { 249 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_ZERO_WRITE, sdev->usid, 0, 250 &data, 1); 251 } 252 EXPORT_SYMBOL_GPL(spmi_register_zero_write); 253 254 /** 255 * spmi_ext_register_write() - extended register write 256 * @sdev: SPMI device. 257 * @addr: slave register address (8-bit address). 258 * @buf: buffer containing the data to be transferred to the Slave. 259 * @len: the request number of bytes to read (up to 16 bytes). 260 * 261 * Writes up to 16 bytes of data to the extended register space of a 262 * Slave device. 263 */ 264 int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, const u8 *buf, 265 size_t len) 266 { 267 /* 8-bit register address, up to 16 bytes */ 268 if (len == 0 || len > 16) 269 return -EINVAL; 270 271 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITE, sdev->usid, addr, 272 buf, len); 273 } 274 EXPORT_SYMBOL_GPL(spmi_ext_register_write); 275 276 /** 277 * spmi_ext_register_writel() - extended register write long 278 * @sdev: SPMI device. 279 * @addr: slave register address (16-bit address). 280 * @buf: buffer containing the data to be transferred to the Slave. 281 * @len: the request number of bytes to read (up to 8 bytes). 282 * 283 * Writes up to 8 bytes of data to the extended register space of a 284 * Slave device using 16-bit address. 285 */ 286 int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, const u8 *buf, 287 size_t len) 288 { 289 /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */ 290 if (len == 0 || len > 8) 291 return -EINVAL; 292 293 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITEL, sdev->usid, 294 addr, buf, len); 295 } 296 EXPORT_SYMBOL_GPL(spmi_ext_register_writel); 297 298 /** 299 * spmi_command_reset() - sends RESET command to the specified slave 300 * @sdev: SPMI device. 301 * 302 * The Reset command initializes the Slave and forces all registers to 303 * their reset values. The Slave shall enter the STARTUP state after 304 * receiving a Reset command. 305 */ 306 int spmi_command_reset(struct spmi_device *sdev) 307 { 308 return spmi_cmd(sdev->ctrl, SPMI_CMD_RESET, sdev->usid); 309 } 310 EXPORT_SYMBOL_GPL(spmi_command_reset); 311 312 /** 313 * spmi_command_sleep() - sends SLEEP command to the specified SPMI device 314 * @sdev: SPMI device. 315 * 316 * The Sleep command causes the Slave to enter the user defined SLEEP state. 317 */ 318 int spmi_command_sleep(struct spmi_device *sdev) 319 { 320 return spmi_cmd(sdev->ctrl, SPMI_CMD_SLEEP, sdev->usid); 321 } 322 EXPORT_SYMBOL_GPL(spmi_command_sleep); 323 324 /** 325 * spmi_command_wakeup() - sends WAKEUP command to the specified SPMI device 326 * @sdev: SPMI device. 327 * 328 * The Wakeup command causes the Slave to move from the SLEEP state to 329 * the ACTIVE state. 330 */ 331 int spmi_command_wakeup(struct spmi_device *sdev) 332 { 333 return spmi_cmd(sdev->ctrl, SPMI_CMD_WAKEUP, sdev->usid); 334 } 335 EXPORT_SYMBOL_GPL(spmi_command_wakeup); 336 337 /** 338 * spmi_command_shutdown() - sends SHUTDOWN command to the specified SPMI device 339 * @sdev: SPMI device. 340 * 341 * The Shutdown command causes the Slave to enter the SHUTDOWN state. 342 */ 343 int spmi_command_shutdown(struct spmi_device *sdev) 344 { 345 return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid); 346 } 347 EXPORT_SYMBOL_GPL(spmi_command_shutdown); 348 349 static int spmi_drv_probe(struct device *dev) 350 { 351 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); 352 struct spmi_device *sdev = to_spmi_device(dev); 353 int err; 354 355 pm_runtime_get_noresume(dev); 356 pm_runtime_set_active(dev); 357 pm_runtime_enable(dev); 358 359 err = sdrv->probe(sdev); 360 if (err) 361 goto fail_probe; 362 363 return 0; 364 365 fail_probe: 366 pm_runtime_disable(dev); 367 pm_runtime_set_suspended(dev); 368 pm_runtime_put_noidle(dev); 369 return err; 370 } 371 372 static void spmi_drv_remove(struct device *dev) 373 { 374 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); 375 376 pm_runtime_get_sync(dev); 377 if (sdrv->remove) 378 sdrv->remove(to_spmi_device(dev)); 379 pm_runtime_put_noidle(dev); 380 381 pm_runtime_disable(dev); 382 pm_runtime_set_suspended(dev); 383 pm_runtime_put_noidle(dev); 384 } 385 386 static void spmi_drv_shutdown(struct device *dev) 387 { 388 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); 389 390 if (sdrv && sdrv->shutdown) 391 sdrv->shutdown(to_spmi_device(dev)); 392 } 393 394 static int spmi_drv_uevent(const struct device *dev, struct kobj_uevent_env *env) 395 { 396 int ret; 397 398 ret = of_device_uevent_modalias(dev, env); 399 if (ret != -ENODEV) 400 return ret; 401 402 return 0; 403 } 404 405 static const struct bus_type spmi_bus_type = { 406 .name = "spmi", 407 .match = spmi_device_match, 408 .probe = spmi_drv_probe, 409 .remove = spmi_drv_remove, 410 .shutdown = spmi_drv_shutdown, 411 .uevent = spmi_drv_uevent, 412 }; 413 414 /** 415 * spmi_find_device_by_of_node() - look up an SPMI device from a device node 416 * 417 * @np: device node 418 * 419 * Takes a reference to the embedded struct device which needs to be dropped 420 * after use. 421 * 422 * Returns the struct spmi_device associated with a device node or NULL. 423 */ 424 struct spmi_device *spmi_find_device_by_of_node(struct device_node *np) 425 { 426 struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np); 427 428 if (dev) 429 return to_spmi_device(dev); 430 return NULL; 431 } 432 EXPORT_SYMBOL_GPL(spmi_find_device_by_of_node); 433 434 /** 435 * spmi_get_parent_spmi_device() - get the parent SPMI device from current dev 436 * @dev: pointer to a subdevice on SPMI bus 437 * 438 * Checks if the passed device is a child of an SPMI device and returns a 439 * handle to the parent SPMI device without incrementing any refcount. 440 * 441 * Return: Handle to the parent SPMI device or NULL 442 */ 443 struct spmi_device *spmi_get_parent_spmi_device(struct device *dev) 444 { 445 struct device *parent; 446 447 if (dev && dev->parent) { 448 parent = dev->parent; 449 450 if (parent->type == &spmi_dev_type) 451 return to_spmi_device(parent); 452 } 453 return NULL; 454 } 455 EXPORT_SYMBOL_NS_GPL(spmi_get_parent_spmi_device, "SPMI"); 456 457 /** 458 * spmi_device_alloc() - Allocate a new SPMI device 459 * @ctrl: associated controller 460 * 461 * Caller is responsible for either calling spmi_device_add() to add the 462 * newly allocated controller, or calling spmi_device_put() to discard it. 463 */ 464 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl) 465 { 466 struct spmi_device *sdev; 467 468 sdev = kzalloc_obj(*sdev); 469 if (!sdev) 470 return NULL; 471 472 sdev->ctrl = ctrl; 473 device_initialize(&sdev->dev); 474 sdev->dev.parent = &ctrl->dev; 475 sdev->dev.bus = &spmi_bus_type; 476 sdev->dev.type = &spmi_dev_type; 477 return sdev; 478 } 479 EXPORT_SYMBOL_GPL(spmi_device_alloc); 480 481 /** 482 * spmi_subdevice_alloc_and_add(): Allocate and add a new SPMI sub-device 483 * @sparent: SPMI parent device with previously registered SPMI controller 484 * 485 * Returns: 486 * Pointer to newly allocated SPMI sub-device for success or error pointer. 487 */ 488 struct spmi_subdevice *spmi_subdevice_alloc_and_add(struct spmi_device *sparent) 489 { 490 struct spmi_subdevice *sub_sdev; 491 struct spmi_device *sdev; 492 int ret; 493 494 sub_sdev = kzalloc_obj(*sub_sdev); 495 if (!sub_sdev) 496 return ERR_PTR(-ENOMEM); 497 498 sdev = &sub_sdev->sdev; 499 sdev->ctrl = sparent->ctrl; 500 sdev->usid = sparent->usid; 501 502 ret = ida_alloc(&spmi_subdevice_ida, GFP_KERNEL); 503 if (ret < 0) { 504 kfree(sub_sdev); 505 return ERR_PTR(ret); 506 } 507 sub_sdev->devid = ret; 508 509 device_initialize(&sdev->dev); 510 sdev->dev.parent = &sparent->dev; 511 sdev->dev.bus = &spmi_bus_type; 512 sdev->dev.type = &spmi_subdev_type; 513 514 ret = dev_set_name(&sdev->dev, "%u-%02x.%u.auto", 515 sdev->ctrl->nr, sdev->usid, sub_sdev->devid); 516 if (ret) 517 goto err_put_dev; 518 519 ret = device_add(&sdev->dev); 520 if (ret) { 521 dev_err(&sdev->dev, "Can't add device, status %pe\n", ERR_PTR(ret)); 522 goto err_put_dev; 523 } 524 525 return sub_sdev; 526 527 err_put_dev: 528 put_device(&sdev->dev); 529 return ERR_PTR(ret); 530 } 531 EXPORT_SYMBOL_NS_GPL(spmi_subdevice_alloc_and_add, "SPMI"); 532 533 /** 534 * spmi_controller_alloc() - Allocate a new SPMI controller 535 * @parent: parent device 536 * @size: size of private data 537 * 538 * Caller is responsible for either calling spmi_controller_add() to add the 539 * newly allocated controller, or calling spmi_controller_put() to discard it. 540 * The allocated private data region may be accessed via 541 * spmi_controller_get_drvdata() 542 */ 543 struct spmi_controller *spmi_controller_alloc(struct device *parent, 544 size_t size) 545 { 546 struct spmi_controller *ctrl; 547 int id; 548 549 if (WARN_ON(!parent)) 550 return ERR_PTR(-EINVAL); 551 552 ctrl = kzalloc_flex(*ctrl, priv, size); 553 if (!ctrl) 554 return ERR_PTR(-ENOMEM); 555 556 device_initialize(&ctrl->dev); 557 ctrl->dev.type = &spmi_ctrl_type; 558 ctrl->dev.bus = &spmi_bus_type; 559 ctrl->dev.parent = parent; 560 ctrl->dev.of_node = parent->of_node; 561 spmi_controller_set_drvdata(ctrl, ctrl->priv); 562 563 id = ida_alloc(&ctrl_ida, GFP_KERNEL); 564 if (id < 0) { 565 dev_err(parent, 566 "unable to allocate SPMI controller identifier.\n"); 567 spmi_controller_put(ctrl); 568 return ERR_PTR(id); 569 } 570 571 ctrl->nr = id; 572 dev_set_name(&ctrl->dev, "spmi-%d", id); 573 574 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); 575 return ctrl; 576 } 577 EXPORT_SYMBOL_GPL(spmi_controller_alloc); 578 579 static void of_spmi_register_devices(struct spmi_controller *ctrl) 580 { 581 struct device_node *node; 582 int err; 583 584 if (!ctrl->dev.of_node) 585 return; 586 587 for_each_available_child_of_node(ctrl->dev.of_node, node) { 588 struct spmi_device *sdev; 589 u32 reg[2]; 590 591 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); 592 593 err = of_property_read_u32_array(node, "reg", reg, 2); 594 if (err) { 595 dev_err(&ctrl->dev, 596 "node %pOF err (%pe) does not have 'reg' property\n", 597 node, ERR_PTR(err)); 598 continue; 599 } 600 601 if (reg[1] != SPMI_USID) { 602 dev_err(&ctrl->dev, 603 "node %pOF contains unsupported 'reg' entry\n", 604 node); 605 continue; 606 } 607 608 if (reg[0] >= SPMI_MAX_SLAVE_ID) { 609 dev_err(&ctrl->dev, "invalid usid on node %pOF\n", node); 610 continue; 611 } 612 613 dev_dbg(&ctrl->dev, "read usid %02x\n", reg[0]); 614 615 sdev = spmi_device_alloc(ctrl); 616 if (!sdev) 617 continue; 618 619 device_set_node(&sdev->dev, of_fwnode_handle(of_node_get(node))); 620 sdev->usid = (u8)reg[0]; 621 622 err = spmi_device_add(sdev); 623 if (err) { 624 dev_err(&sdev->dev, 625 "failure adding device. status %pe\n", ERR_PTR(err)); 626 spmi_device_put(sdev); 627 } 628 } 629 } 630 631 /** 632 * spmi_controller_add() - Add an SPMI controller 633 * @ctrl: controller to be registered. 634 * 635 * Register a controller previously allocated via spmi_controller_alloc() with 636 * the SPMI core. 637 */ 638 int spmi_controller_add(struct spmi_controller *ctrl) 639 { 640 int ret; 641 642 /* Can't register until after driver model init */ 643 if (WARN_ON(!is_registered)) 644 return -EAGAIN; 645 646 ret = device_add(&ctrl->dev); 647 if (ret) 648 return ret; 649 650 if (IS_ENABLED(CONFIG_OF)) 651 of_spmi_register_devices(ctrl); 652 653 dev_dbg(&ctrl->dev, "spmi-%d registered: dev:%p\n", 654 ctrl->nr, &ctrl->dev); 655 656 return 0; 657 }; 658 EXPORT_SYMBOL_GPL(spmi_controller_add); 659 660 /* Remove a device associated with a controller */ 661 static int spmi_ctrl_remove_device(struct device *dev, void *data) 662 { 663 struct spmi_device *spmidev = to_spmi_device(dev); 664 665 if (dev->type == &spmi_dev_type) 666 spmi_device_remove(spmidev); 667 return 0; 668 } 669 670 /** 671 * spmi_controller_remove(): remove an SPMI controller 672 * @ctrl: controller to remove 673 * 674 * Remove a SPMI controller. Caller is responsible for calling 675 * spmi_controller_put() to discard the allocated controller. 676 */ 677 void spmi_controller_remove(struct spmi_controller *ctrl) 678 { 679 if (!ctrl) 680 return; 681 682 device_for_each_child(&ctrl->dev, NULL, spmi_ctrl_remove_device); 683 device_del(&ctrl->dev); 684 } 685 EXPORT_SYMBOL_GPL(spmi_controller_remove); 686 687 /** 688 * __spmi_driver_register() - Register client driver with SPMI core 689 * @sdrv: client driver to be associated with client-device. 690 * @owner: module owner 691 * 692 * This API will register the client driver with the SPMI framework. 693 * It is typically called from the driver's module-init function. 694 */ 695 int __spmi_driver_register(struct spmi_driver *sdrv, struct module *owner) 696 { 697 sdrv->driver.bus = &spmi_bus_type; 698 sdrv->driver.owner = owner; 699 return driver_register(&sdrv->driver); 700 } 701 EXPORT_SYMBOL_GPL(__spmi_driver_register); 702 703 static void __exit spmi_exit(void) 704 { 705 bus_unregister(&spmi_bus_type); 706 } 707 module_exit(spmi_exit); 708 709 static int __init spmi_init(void) 710 { 711 int ret; 712 713 ret = bus_register(&spmi_bus_type); 714 if (ret) 715 return ret; 716 717 is_registered = true; 718 return 0; 719 } 720 postcore_initcall(spmi_init); 721 722 MODULE_LICENSE("GPL v2"); 723 MODULE_DESCRIPTION("SPMI module"); 724 MODULE_ALIAS("platform:spmi"); 725