Lines Matching +full:device +full:- +full:addr
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>
23 static void spmi_dev_release(struct device *dev) in spmi_dev_release()
34 static void spmi_ctrl_release(struct device *dev) in spmi_ctrl_release()
38 ida_free(&ctrl_ida, ctrl->nr); in spmi_ctrl_release()
46 static int spmi_device_match(struct device *dev, const struct device_driver *drv) in spmi_device_match()
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()
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()
84 * spmi_device_remove(): remove an SPMI device
89 device_unregister(&sdev->dev); in spmi_device_remove()
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()
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()
114 trace_spmi_read_begin(opcode, sid, addr); 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()
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()
130 trace_spmi_write_end(opcode, sid, addr, ret); in spmi_write_cmd()
135 * spmi_register_read() - register read
136 * @sdev: SPMI device.
137 * @addr: slave register address (5-bit address).
140 * Reads 1 byte of data from a Slave device register.
142 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf) in spmi_register_read() argument
144 /* 5-bit register address */ in spmi_register_read()
145 if (addr > 0x1F) 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
155 * @sdev: SPMI device.
156 * @addr: slave register address (8-bit address).
161 * Slave device.
163 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, in spmi_ext_register_read() argument
166 /* 8-bit register address, up to 16 bytes */ 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()
176 * spmi_ext_register_readl() - extended register read long
177 * @sdev: SPMI device.
178 * @addr: slave register address (16-bit address).
183 * Slave device using 16-bit address.
185 int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf, in spmi_ext_register_readl() argument
188 /* 16-bit register address, up to 8 bytes */ 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()
198 * spmi_register_write() - register write
199 * @sdev: SPMI device
200 * @addr: slave register address (5-bit address).
203 * Writes 1 byte of data to a Slave device register.
205 int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data) in spmi_register_write() argument
207 /* 5-bit register address */ in spmi_register_write()
208 if (addr > 0x1F) 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
218 * @sdev: SPMI device.
219 * @data: the data to be written to register 0 (7-bits).
221 * Writes data to register 0 of the Slave device.
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
232 * @sdev: SPMI device.
233 * @addr: slave register address (8-bit address).
238 * Slave device.
240 int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, const u8 *buf, in spmi_ext_register_write() argument
243 /* 8-bit register address, up to 16 bytes */ 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()
253 * spmi_ext_register_writel() - extended register write long
254 * @sdev: SPMI device.
255 * @addr: slave register address (16-bit address).
260 * Slave device using 16-bit address.
262 int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, const u8 *buf, in spmi_ext_register_writel() argument
265 /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */ 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
276 * @sdev: SPMI device.
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
290 * @sdev: 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
302 * @sdev: 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
315 * @sdev: SPMI device.
321 return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid); in spmi_command_shutdown()
325 static int spmi_drv_probe(struct device *dev) in spmi_drv_probe()
327 const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); in spmi_drv_probe()
335 err = sdrv->probe(sdev); in spmi_drv_probe()
348 static void spmi_drv_remove(struct device *dev) in spmi_drv_remove()
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()
362 static void spmi_drv_shutdown(struct device *dev) in spmi_drv_shutdown()
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()
370 static int spmi_drv_uevent(const struct device *dev, struct kobj_uevent_env *env) in spmi_drv_uevent()
375 if (ret != -ENODEV) in spmi_drv_uevent()
391 * spmi_find_device_by_of_node() - look up an SPMI device from a device node
393 * @np: device node
395 * Takes a reference to the embedded struct device which needs to be dropped
398 * Returns the struct spmi_device associated with a device node or NULL.
402 struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np); in spmi_find_device_by_of_node()
411 * spmi_device_alloc() - Allocate a new SPMI device
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
436 * @parent: parent device
444 struct spmi_controller *spmi_controller_alloc(struct device *parent, in spmi_controller_alloc()
451 return ERR_PTR(-EINVAL); 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()
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()
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()
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()
526 "failure adding device. status %d\n", err); in of_spmi_register_devices()
533 * spmi_controller_add() - Add an SPMI controller
545 return -EAGAIN; in spmi_controller_add()
547 ret = device_add(&ctrl->dev); 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()
561 /* Remove a device associated with a controller */
562 static int spmi_ctrl_remove_device(struct device *dev, void *data) in spmi_ctrl_remove_device()
566 if (dev->type == &spmi_dev_type) in spmi_ctrl_remove_device()
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()