Lines Matching +full:ctrl +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
16 #include <dt-bindings/spmi/spmi.h>
36 struct spmi_controller *ctrl = to_spmi_controller(dev); in spmi_ctrl_release() local
38 ida_free(&ctrl_ida, ctrl->nr); in spmi_ctrl_release()
39 kfree(ctrl); in spmi_ctrl_release()
51 if (drv->name) in spmi_device_match()
52 return strncmp(dev_name(dev), drv->name, in spmi_device_match()
59 * spmi_device_add() - add a device previously constructed via spmi_device_alloc()
64 struct spmi_controller *ctrl = sdev->ctrl; in spmi_device_add() local
67 dev_set_name(&sdev->dev, "%d-%02x", ctrl->nr, sdev->usid); in spmi_device_add()
69 err = device_add(&sdev->dev); in spmi_device_add()
71 dev_err(&sdev->dev, "Can't add %s, status %d\n", in spmi_device_add()
72 dev_name(&sdev->dev), err); in spmi_device_add()
76 dev_dbg(&sdev->dev, "device %s registered\n", dev_name(&sdev->dev)); in spmi_device_add()
89 device_unregister(&sdev->dev); in spmi_device_remove()
94 spmi_cmd(struct spmi_controller *ctrl, u8 opcode, u8 sid) in spmi_cmd() argument
98 if (!ctrl || !ctrl->cmd || ctrl->dev.type != &spmi_ctrl_type) in spmi_cmd()
99 return -EINVAL; in spmi_cmd()
101 ret = ctrl->cmd(ctrl, opcode, sid); in spmi_cmd()
106 static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode, in spmi_read_cmd() argument
107 u8 sid, u16 addr, u8 *buf, size_t len) in spmi_read_cmd() argument
111 if (!ctrl || !ctrl->read_cmd || ctrl->dev.type != &spmi_ctrl_type) in spmi_read_cmd()
112 return -EINVAL; in spmi_read_cmd()
115 ret = ctrl->read_cmd(ctrl, opcode, sid, addr, buf, len); in spmi_read_cmd()
116 trace_spmi_read_end(opcode, sid, addr, ret, len, buf); in spmi_read_cmd()
120 static inline int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode, in spmi_write_cmd() argument
121 u8 sid, u16 addr, const u8 *buf, size_t len) in spmi_write_cmd() argument
125 if (!ctrl || !ctrl->write_cmd || ctrl->dev.type != &spmi_ctrl_type) in spmi_write_cmd()
126 return -EINVAL; in spmi_write_cmd()
128 trace_spmi_write_begin(opcode, sid, addr, len, buf); in spmi_write_cmd()
129 ret = ctrl->write_cmd(ctrl, opcode, sid, addr, buf, len); in spmi_write_cmd()
135 * spmi_register_read() - register read
137 * @addr: slave register address (5-bit address).
144 /* 5-bit register address */ in spmi_register_read()
146 return -EINVAL; in spmi_register_read()
148 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_READ, sdev->usid, addr, in spmi_register_read()
154 * spmi_ext_register_read() - extended register read
156 * @addr: slave register address (8-bit address).
158 * @len: the request number of bytes to read (up to 16 bytes).
164 size_t len) in spmi_ext_register_read() argument
166 /* 8-bit register address, up to 16 bytes */ in spmi_ext_register_read()
167 if (len == 0 || len > 16) in spmi_ext_register_read()
168 return -EINVAL; in spmi_ext_register_read()
170 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READ, sdev->usid, addr, in spmi_ext_register_read()
171 buf, len); in spmi_ext_register_read()
176 * spmi_ext_register_readl() - extended register read long
178 * @addr: slave register address (16-bit address).
180 * @len: the request number of bytes to read (up to 8 bytes).
183 * Slave device using 16-bit address.
186 size_t len) in spmi_ext_register_readl() argument
188 /* 16-bit register address, up to 8 bytes */ in spmi_ext_register_readl()
189 if (len == 0 || len > 8) in spmi_ext_register_readl()
190 return -EINVAL; in spmi_ext_register_readl()
192 return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READL, sdev->usid, addr, in spmi_ext_register_readl()
193 buf, len); in spmi_ext_register_readl()
198 * spmi_register_write() - register write
200 * @addr: slave register address (5-bit address).
207 /* 5-bit register address */ in spmi_register_write()
209 return -EINVAL; in spmi_register_write()
211 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_WRITE, sdev->usid, addr, in spmi_register_write()
217 * spmi_register_zero_write() - register zero write
219 * @data: the data to be written to register 0 (7-bits).
225 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_ZERO_WRITE, sdev->usid, 0, in spmi_register_zero_write()
231 * spmi_ext_register_write() - extended register write
233 * @addr: slave register address (8-bit address).
235 * @len: the request number of bytes to read (up to 16 bytes).
241 size_t len) in spmi_ext_register_write() argument
243 /* 8-bit register address, up to 16 bytes */ in spmi_ext_register_write()
244 if (len == 0 || len > 16) in spmi_ext_register_write()
245 return -EINVAL; in spmi_ext_register_write()
247 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITE, sdev->usid, addr, in spmi_ext_register_write()
248 buf, len); in spmi_ext_register_write()
253 * spmi_ext_register_writel() - extended register write long
255 * @addr: slave register address (16-bit address).
257 * @len: the request number of bytes to read (up to 8 bytes).
260 * Slave device using 16-bit address.
263 size_t len) in spmi_ext_register_writel() argument
265 /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */ in spmi_ext_register_writel()
266 if (len == 0 || len > 8) in spmi_ext_register_writel()
267 return -EINVAL; in spmi_ext_register_writel()
269 return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITEL, sdev->usid, in spmi_ext_register_writel()
270 addr, buf, len); in spmi_ext_register_writel()
275 * spmi_command_reset() - sends RESET command to the specified slave
284 return spmi_cmd(sdev->ctrl, SPMI_CMD_RESET, sdev->usid); in spmi_command_reset()
289 * spmi_command_sleep() - sends SLEEP command to the specified SPMI device
296 return spmi_cmd(sdev->ctrl, SPMI_CMD_SLEEP, sdev->usid); in spmi_command_sleep()
301 * spmi_command_wakeup() - sends WAKEUP command to the specified SPMI device
309 return spmi_cmd(sdev->ctrl, SPMI_CMD_WAKEUP, sdev->usid); in spmi_command_wakeup()
314 * spmi_command_shutdown() - sends SHUTDOWN command to the specified SPMI device
321 return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid); in spmi_command_shutdown()
327 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_probe()
335 err = sdrv->probe(sdev); in spmi_drv_probe()
350 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_remove()
353 if (sdrv->remove) in spmi_drv_remove()
354 sdrv->remove(to_spmi_device(dev)); in spmi_drv_remove()
364 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_shutdown()
366 if (sdrv && sdrv->shutdown) in spmi_drv_shutdown()
367 sdrv->shutdown(to_spmi_device(dev)); in spmi_drv_shutdown()
375 if (ret != -ENODEV) in spmi_drv_uevent()
391 * spmi_find_device_by_of_node() - look up an SPMI device from a device node
411 * spmi_device_alloc() - Allocate a new SPMI device
412 * @ctrl: associated controller
417 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl) in spmi_device_alloc() argument
425 sdev->ctrl = ctrl; in spmi_device_alloc()
426 device_initialize(&sdev->dev); in spmi_device_alloc()
427 sdev->dev.parent = &ctrl->dev; in spmi_device_alloc()
428 sdev->dev.bus = &spmi_bus_type; in spmi_device_alloc()
429 sdev->dev.type = &spmi_dev_type; in spmi_device_alloc()
435 * spmi_controller_alloc() - Allocate a new SPMI controller
447 struct spmi_controller *ctrl; in spmi_controller_alloc() local
451 return ERR_PTR(-EINVAL); in spmi_controller_alloc()
453 ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); in spmi_controller_alloc()
454 if (!ctrl) in spmi_controller_alloc()
455 return ERR_PTR(-ENOMEM); in spmi_controller_alloc()
457 device_initialize(&ctrl->dev); in spmi_controller_alloc()
458 ctrl->dev.type = &spmi_ctrl_type; in spmi_controller_alloc()
459 ctrl->dev.bus = &spmi_bus_type; in spmi_controller_alloc()
460 ctrl->dev.parent = parent; in spmi_controller_alloc()
461 ctrl->dev.of_node = parent->of_node; in spmi_controller_alloc()
462 spmi_controller_set_drvdata(ctrl, &ctrl[1]); in spmi_controller_alloc()
468 spmi_controller_put(ctrl); in spmi_controller_alloc()
472 ctrl->nr = id; in spmi_controller_alloc()
473 dev_set_name(&ctrl->dev, "spmi-%d", id); in spmi_controller_alloc()
475 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in spmi_controller_alloc()
476 return ctrl; in spmi_controller_alloc()
480 static void of_spmi_register_devices(struct spmi_controller *ctrl) in of_spmi_register_devices() argument
485 if (!ctrl->dev.of_node) in of_spmi_register_devices()
488 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_spmi_register_devices()
492 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_spmi_register_devices()
496 dev_err(&ctrl->dev, in of_spmi_register_devices()
503 dev_err(&ctrl->dev, in of_spmi_register_devices()
510 dev_err(&ctrl->dev, "invalid usid on node %pOF\n", node); in of_spmi_register_devices()
514 dev_dbg(&ctrl->dev, "read usid %02x\n", reg[0]); in of_spmi_register_devices()
516 sdev = spmi_device_alloc(ctrl); in of_spmi_register_devices()
520 sdev->dev.of_node = node; in of_spmi_register_devices()
521 sdev->usid = (u8)reg[0]; in of_spmi_register_devices()
525 dev_err(&sdev->dev, in of_spmi_register_devices()
533 * spmi_controller_add() - Add an SPMI controller
534 * @ctrl: controller to be registered.
539 int spmi_controller_add(struct spmi_controller *ctrl) in spmi_controller_add() argument
545 return -EAGAIN; in spmi_controller_add()
547 ret = device_add(&ctrl->dev); in spmi_controller_add()
552 of_spmi_register_devices(ctrl); in spmi_controller_add()
554 dev_dbg(&ctrl->dev, "spmi-%d registered: dev:%p\n", in spmi_controller_add()
555 ctrl->nr, &ctrl->dev); in spmi_controller_add()
566 if (dev->type == &spmi_dev_type) in spmi_ctrl_remove_device()
573 * @ctrl: controller to remove
578 void spmi_controller_remove(struct spmi_controller *ctrl) in spmi_controller_remove() argument
580 if (!ctrl) in spmi_controller_remove()
583 device_for_each_child(&ctrl->dev, NULL, spmi_ctrl_remove_device); in spmi_controller_remove()
584 device_del(&ctrl->dev); in spmi_controller_remove()
589 * __spmi_driver_register() - Register client driver with SPMI core
590 * @sdrv: client driver to be associated with client-device.
594 * It is typically called from the driver's module-init function.
598 sdrv->driver.bus = &spmi_bus_type; in __spmi_driver_register()
599 sdrv->driver.owner = owner; in __spmi_driver_register()
600 return driver_register(&sdrv->driver); in __spmi_driver_register()