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 sdrv->remove(to_spmi_device(dev)); in spmi_drv_remove()
363 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_shutdown()
365 if (sdrv && sdrv->shutdown) in spmi_drv_shutdown()
366 sdrv->shutdown(to_spmi_device(dev)); in spmi_drv_shutdown()
374 if (ret != -ENODEV) in spmi_drv_uevent()
390 * spmi_device_from_of() - get the associated SPMI device from a device node
407 * spmi_controller_alloc() - Allocate a new SPMI device
408 * @ctrl: associated controller
413 struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl) in spmi_device_alloc() argument
421 sdev->ctrl = ctrl; in spmi_device_alloc()
422 device_initialize(&sdev->dev); in spmi_device_alloc()
423 sdev->dev.parent = &ctrl->dev; in spmi_device_alloc()
424 sdev->dev.bus = &spmi_bus_type; in spmi_device_alloc()
425 sdev->dev.type = &spmi_dev_type; in spmi_device_alloc()
431 * spmi_controller_alloc() - Allocate a new SPMI controller
443 struct spmi_controller *ctrl; in spmi_controller_alloc() local
449 ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); in spmi_controller_alloc()
450 if (!ctrl) in spmi_controller_alloc()
453 device_initialize(&ctrl->dev); in spmi_controller_alloc()
454 ctrl->dev.type = &spmi_ctrl_type; in spmi_controller_alloc()
455 ctrl->dev.bus = &spmi_bus_type; in spmi_controller_alloc()
456 ctrl->dev.parent = parent; in spmi_controller_alloc()
457 ctrl->dev.of_node = parent->of_node; in spmi_controller_alloc()
458 spmi_controller_set_drvdata(ctrl, &ctrl[1]); in spmi_controller_alloc()
464 spmi_controller_put(ctrl); in spmi_controller_alloc()
468 ctrl->nr = id; in spmi_controller_alloc()
469 dev_set_name(&ctrl->dev, "spmi-%d", id); in spmi_controller_alloc()
471 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in spmi_controller_alloc()
472 return ctrl; in spmi_controller_alloc()
476 static void of_spmi_register_devices(struct spmi_controller *ctrl) in of_spmi_register_devices() argument
481 if (!ctrl->dev.of_node) in of_spmi_register_devices()
484 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_spmi_register_devices()
488 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_spmi_register_devices()
492 dev_err(&ctrl->dev, in of_spmi_register_devices()
499 dev_err(&ctrl->dev, in of_spmi_register_devices()
506 dev_err(&ctrl->dev, "invalid usid on node %pOF\n", node); in of_spmi_register_devices()
510 dev_dbg(&ctrl->dev, "read usid %02x\n", reg[0]); in of_spmi_register_devices()
512 sdev = spmi_device_alloc(ctrl); in of_spmi_register_devices()
516 sdev->dev.of_node = node; in of_spmi_register_devices()
517 sdev->usid = (u8)reg[0]; in of_spmi_register_devices()
521 dev_err(&sdev->dev, in of_spmi_register_devices()
529 * spmi_controller_add() - Add an SPMI controller
530 * @ctrl: controller to be registered.
535 int spmi_controller_add(struct spmi_controller *ctrl) in spmi_controller_add() argument
541 return -EAGAIN; in spmi_controller_add()
543 ret = device_add(&ctrl->dev); in spmi_controller_add()
548 of_spmi_register_devices(ctrl); in spmi_controller_add()
550 dev_dbg(&ctrl->dev, "spmi-%d registered: dev:%p\n", in spmi_controller_add()
551 ctrl->nr, &ctrl->dev); in spmi_controller_add()
562 if (dev->type == &spmi_dev_type) in spmi_ctrl_remove_device()
569 * @ctrl: controller to remove
574 void spmi_controller_remove(struct spmi_controller *ctrl) in spmi_controller_remove() argument
576 if (!ctrl) in spmi_controller_remove()
579 device_for_each_child(&ctrl->dev, NULL, spmi_ctrl_remove_device); in spmi_controller_remove()
580 device_del(&ctrl->dev); in spmi_controller_remove()
585 * spmi_driver_register() - Register client driver with SPMI core
586 * @sdrv: client driver to be associated with client-device.
589 * It is typically called from the driver's module-init function.
593 sdrv->driver.bus = &spmi_bus_type; in __spmi_driver_register()
594 sdrv->driver.owner = owner; in __spmi_driver_register()
595 return driver_register(&sdrv->driver); in __spmi_driver_register()