Lines Matching +full:ctrl +full:- +full:module

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
9 #include <linux/module.h>
16 #include <dt-bindings/spmi/spmi.h>
35 struct spmi_controller *ctrl = to_spmi_controller(dev); in spmi_ctrl_release() local
36 ida_simple_remove(&ctrl_ida, ctrl->nr); in spmi_ctrl_release()
37 kfree(ctrl); in spmi_ctrl_release()
49 if (drv->name) in spmi_device_match()
50 return strncmp(dev_name(dev), drv->name, in spmi_device_match()
57 * spmi_device_add() - add a device previously constructed via spmi_device_alloc()
62 struct spmi_controller *ctrl = sdev->ctrl; in spmi_device_add() local
65 dev_set_name(&sdev->dev, "%d-%02x", ctrl->nr, sdev->usid); in spmi_device_add()
67 err = device_add(&sdev->dev); in spmi_device_add()
69 dev_err(&sdev->dev, "Can't add %s, status %d\n", in spmi_device_add()
70 dev_name(&sdev->dev), err); in spmi_device_add()
74 dev_dbg(&sdev->dev, "device %s registered\n", dev_name(&sdev->dev)); in spmi_device_add()
87 device_unregister(&sdev->dev); in spmi_device_remove()
92 spmi_cmd(struct spmi_controller *ctrl, u8 opcode, u8 sid) in spmi_cmd() argument
96 if (!ctrl || !ctrl->cmd || ctrl->dev.type != &spmi_ctrl_type) in spmi_cmd()
97 return -EINVAL; in spmi_cmd()
99 ret = ctrl->cmd(ctrl, opcode, sid); in spmi_cmd()
104 static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode, in spmi_read_cmd() argument
109 if (!ctrl || !ctrl->read_cmd || ctrl->dev.type != &spmi_ctrl_type) in spmi_read_cmd()
110 return -EINVAL; in spmi_read_cmd()
113 ret = ctrl->read_cmd(ctrl, opcode, sid, addr, buf, len); in spmi_read_cmd()
118 static inline int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode, in spmi_write_cmd() argument
123 if (!ctrl || !ctrl->write_cmd || ctrl->dev.type != &spmi_ctrl_type) in spmi_write_cmd()
124 return -EINVAL; in spmi_write_cmd()
127 ret = ctrl->write_cmd(ctrl, opcode, sid, addr, buf, len); in spmi_write_cmd()
133 * spmi_register_read() - register read
135 * @addr: slave register address (5-bit address).
142 /* 5-bit register address */ in spmi_register_read()
144 return -EINVAL; in spmi_register_read()
146 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_READ, sdev->usid, addr, in spmi_register_read()
152 * spmi_ext_register_read() - extended register read
154 * @addr: slave register address (8-bit address).
164 /* 8-bit register address, up to 16 bytes */ in spmi_ext_register_read()
166 return -EINVAL; in spmi_ext_register_read()
168 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READ, sdev->usid, addr, in spmi_ext_register_read()
174 * spmi_ext_register_readl() - extended register read long
176 * @addr: slave register address (16-bit address).
181 * Slave device using 16-bit address.
186 /* 16-bit register address, up to 8 bytes */ in spmi_ext_register_readl()
188 return -EINVAL; in spmi_ext_register_readl()
190 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READL, sdev->usid, addr, in spmi_ext_register_readl()
196 * spmi_register_write() - register write
198 * @addr: slave register address (5-bit address).
205 /* 5-bit register address */ in spmi_register_write()
207 return -EINVAL; in spmi_register_write()
209 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_WRITE, sdev->usid, addr, in spmi_register_write()
215 * spmi_register_zero_write() - register zero write
217 * @data: the data to be written to register 0 (7-bits).
223 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_ZERO_WRITE, sdev->usid, 0, in spmi_register_zero_write()
229 * spmi_ext_register_write() - extended register write
231 * @addr: slave register address (8-bit address).
241 /* 8-bit register address, up to 16 bytes */ in spmi_ext_register_write()
243 return -EINVAL; in spmi_ext_register_write()
245 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITE, sdev->usid, addr, in spmi_ext_register_write()
251 * spmi_ext_register_writel() - extended register write long
253 * @addr: slave register address (16-bit address).
258 * Slave device using 16-bit address.
263 /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */ in spmi_ext_register_writel()
265 return -EINVAL; in spmi_ext_register_writel()
267 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITEL, sdev->usid, in spmi_ext_register_writel()
273 * spmi_command_reset() - sends RESET command to the specified slave
282 return spmi_cmd(sdev->ctrl, SPMI_CMD_RESET, sdev->usid); in spmi_command_reset()
287 * spmi_command_sleep() - sends SLEEP command to the specified SPMI device
294 return spmi_cmd(sdev->ctrl, SPMI_CMD_SLEEP, sdev->usid); in spmi_command_sleep()
299 * spmi_command_wakeup() - sends WAKEUP command to the specified SPMI device
307 return spmi_cmd(sdev->ctrl, SPMI_CMD_WAKEUP, sdev->usid); in spmi_command_wakeup()
312 * spmi_command_shutdown() - sends SHUTDOWN command to the specified SPMI device
319 return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid); in spmi_command_shutdown()
325 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_probe()
333 err = sdrv->probe(sdev); in spmi_drv_probe()
348 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_remove()
351 sdrv->remove(to_spmi_device(dev)); in spmi_drv_remove()
365 if (ret != -ENODEV) in spmi_drv_uevent()
380 * spmi_controller_alloc() - Allocate a new SPMI device
381 * @ctrl: associated controller
386 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl) in spmi_device_alloc() argument
394 sdev->ctrl = ctrl; in spmi_device_alloc()
395 device_initialize(&sdev->dev); in spmi_device_alloc()
396 sdev->dev.parent = &ctrl->dev; in spmi_device_alloc()
397 sdev->dev.bus = &spmi_bus_type; in spmi_device_alloc()
398 sdev->dev.type = &spmi_dev_type; in spmi_device_alloc()
404 * spmi_controller_alloc() - Allocate a new SPMI controller
416 struct spmi_controller *ctrl; in spmi_controller_alloc() local
422 ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); in spmi_controller_alloc()
423 if (!ctrl) in spmi_controller_alloc()
426 device_initialize(&ctrl->dev); in spmi_controller_alloc()
427 ctrl->dev.type = &spmi_ctrl_type; in spmi_controller_alloc()
428 ctrl->dev.bus = &spmi_bus_type; in spmi_controller_alloc()
429 ctrl->dev.parent = parent; in spmi_controller_alloc()
430 ctrl->dev.of_node = parent->of_node; in spmi_controller_alloc()
431 spmi_controller_set_drvdata(ctrl, &ctrl[1]); in spmi_controller_alloc()
437 spmi_controller_put(ctrl); in spmi_controller_alloc()
441 ctrl->nr = id; in spmi_controller_alloc()
442 dev_set_name(&ctrl->dev, "spmi-%d", id); in spmi_controller_alloc()
444 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in spmi_controller_alloc()
445 return ctrl; in spmi_controller_alloc()
449 static void of_spmi_register_devices(struct spmi_controller *ctrl) in of_spmi_register_devices() argument
454 if (!ctrl->dev.of_node) in of_spmi_register_devices()
457 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_spmi_register_devices()
461 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_spmi_register_devices()
465 dev_err(&ctrl->dev, in of_spmi_register_devices()
472 dev_err(&ctrl->dev, in of_spmi_register_devices()
479 dev_err(&ctrl->dev, "invalid usid on node %pOF\n", node); in of_spmi_register_devices()
483 dev_dbg(&ctrl->dev, "read usid %02x\n", reg[0]); in of_spmi_register_devices()
485 sdev = spmi_device_alloc(ctrl); in of_spmi_register_devices()
489 sdev->dev.of_node = node; in of_spmi_register_devices()
490 sdev->usid = (u8) reg[0]; in of_spmi_register_devices()
494 dev_err(&sdev->dev, in of_spmi_register_devices()
502 * spmi_controller_add() - Add an SPMI controller
503 * @ctrl: controller to be registered.
508 int spmi_controller_add(struct spmi_controller *ctrl) in spmi_controller_add() argument
514 return -EAGAIN; in spmi_controller_add()
516 ret = device_add(&ctrl->dev); in spmi_controller_add()
521 of_spmi_register_devices(ctrl); in spmi_controller_add()
523 dev_dbg(&ctrl->dev, "spmi-%d registered: dev:%p\n", in spmi_controller_add()
524 ctrl->nr, &ctrl->dev); in spmi_controller_add()
534 if (dev->type == &spmi_dev_type) in spmi_ctrl_remove_device()
541 * @ctrl: controller to remove
546 void spmi_controller_remove(struct spmi_controller *ctrl) in spmi_controller_remove() argument
550 if (!ctrl) in spmi_controller_remove()
553 dummy = device_for_each_child(&ctrl->dev, NULL, in spmi_controller_remove()
555 device_del(&ctrl->dev); in spmi_controller_remove()
560 * spmi_driver_register() - Register client driver with SPMI core
561 * @sdrv: client driver to be associated with client-device.
564 * It is typically called from the driver's module-init function.
566 int __spmi_driver_register(struct spmi_driver *sdrv, struct module *owner) in __spmi_driver_register()
568 sdrv->driver.bus = &spmi_bus_type; in __spmi_driver_register()
569 sdrv->driver.owner = owner; in __spmi_driver_register()
570 return driver_register(&sdrv->driver); in __spmi_driver_register()
594 MODULE_DESCRIPTION("SPMI module");