summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
Commit message (Collapse)AuthorAgeFilesLines
* treewide: remove bus probe functions that just call driver probeAhmad Fatoum2024-02-291-6/+0
| | | | | | | | | | Now that the driver core will call the driver probe function if there is no bus probe function, remove all bus probe functions that do what the core can do instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240228160518.1589193-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: drop simple bus remove in favor of common implementationAhmad Fatoum2024-02-161-7/+0
| | | | | | | | | | | | | | Now that driver core will call dev->driver->remove if dev->bus->remove is NULL, we cann remove all bus_type::remove functions that do the same. This has the welcome side effect that devices that device_remove will return false when called on a device the neither has a bus remove or driver remove function and thus we can skip tracing these calls when CONFIG_DEBUG_PROBES is enabled. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240215103353.2799723-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Add slices for SPI controllersSascha Hauer2023-09-121-1/+11
| | | | | | | | | Add a slice for SPI controllers so that devices using SPI in the background can check if a SPI bus is busy. Tested-by: Gerald Loacker <gerald.loacker@wolfvision.net> Link: https://lore.barebox.org/20230908131117.1769957-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: implement rescanSascha Hauer2023-03-101-2/+21
| | | | | | | | | | | | | Implement rescan to register and probe newly added devices via device tree overlays. While this is easy to do at SPI core level this is not the whole truth. Many SPI controllers do not use their native chipselects for the SPI devices, but GPIOs instead. These currently won't be rescanned when new devices are added, so the chipselects for the new devices must be be present in the base device tree already. You have been warned. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: reduce scope of 'chip'Sascha Hauer2023-03-101-2/+2
| | | | | | | | Reducde scope of struct spi_board_info chip to the loop where it is actually only used. While at it drop the memset and let the compiler do the work of initialising it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Directly register SPI deviceSascha Hauer2023-03-101-1/+1
| | | | | | | | | | SPI devices described in the device tree are not directly registered, but instead added to the SPI board_list which is normally used to register SPI devices from board code. This seems rather unnecessary, drop this detour and register SPI devices directly from spi_of_register_slaves(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-2/+2
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename device_d::device_node to device_d::of_nodeSascha Hauer2023-01-101-4/+4
| | | | | | | | | | | | | | | | | | | | Linux struct device has the member of_node for the device_node pointer. Rename this in barebox accordingly to minimize the necessary changes when porting Linux code. This was done with the semantic patch: @@ struct device_d E; @@ - E.device_node + E.of_node @@ struct device_d *E; @@ - E->device_node + E->of_node Plus some manual adjustments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: add missing SPDX-License-IdentifierAhmad Fatoum2021-11-011-12/+1
| | | | | | | | | | | | | | | | | | | | This adds the suitable SPDX-License-Identifier to all files in drivers/ that previously lacked one. To aid manual inspection, following heuristics can be used: * No changes outside of comments/whitespace: git show -U0 HEAD | rg -v '^(@@|diff|index)|[-+]([-+]|//|#|[\s/]\*)' * -or-later come in pairs: git show --inter-hunk-context=19 HEAD | \ perl -0777 -F'/^@/gm' -ne 'for (@F) { @m = /later/g; print if @m & 1 }' Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030175632.2276077-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: add initial barebox deep-probe supportMarco Felsch2021-06-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The barebox 'deep probe' or 'probe on demand' mechanism is the answer of unwanted -EPROBE_DEFER failures. The EPROBE_DEFER error code was introduced by commit ab3da15bc14c ("base: Introduce deferred probing") and since then it causes a few problems. The error is returned if either the device is not yet present or the driver is not yet registered. This makes sense on linux systems where modules and hot-plug devices are used very often but not for barebox. The module support is rarely used and devices aren't hot pluggable. The current barebox behaviour populates all devices before the drivers are registered so all devices are present during the driver registration. So the driver probe() function gets called immediately after the driver registration and causes the -EPROBE_DEFER error if this driver depends on an other not yet registered driver. To get rid of the EPROBE_DEFER error code we need to reorder the device population and the driver registration. All drivers must be registered first. In an ideal world all driver can be registered by the same initcall level. Then devices are getting populated which causes calling the driver probe() function but this time resources/devices are created on demand if not yet available. Dependencies between devices are normally expressed as references to other device nodes. With deep probe barebox provides helper functions which take a device node and probe the device behind that node if necessary. This means instead of returning -EPROBE_DEFER, we can now make the desired resources available once we need them. If the resource can't be created we are returning -ENODEV since we are not supporting hot-plugging. Dropping EPROBE_DEFER is the long-term goal, avoid initcall shifting is the short-term goal. Call it deep-probe since the on-demand device creation can create very deep stacks. This commit adds the initial support for: spi, i2c, reset, regulator, gpio and clk resource on-demand creation. The deep-probe mechanism must be enabled for each board to avoid breaking changes using deep_probe_enable(). This can be changed later after all boards are converted to the new mechanism. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/20201021115813.31645-8-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210625072540.32717-10-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: core: don't ignore register_device failuresMarco Felsch2020-09-291-1/+3
| | | | | | | Add missing error handling for spi_new_device(). Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: validate spi messagesSascha Hauer2020-04-141-0/+46
| | | | | | | | | This adds __spi_validate() to validate spi messages. This function is a stripped down version from the Kernel. The motivation for adding this was to fill in xfer->bits_per_word from spi->bits_per_word so that a spi bus driver can use the former. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: fix symbol export for spi_register_controllerLucas Stach2019-12-021-1/+1
| | | | | | Fixes: 812a9ddcdf21 (spi: Generalize SPI "master" to "controller") Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Extend the core to ease integration of SPI memory controllersSteffen Trumtrar2019-05-081-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sync with Linux v5.1-rc1. This is the barebox adoption of the commit commit c36ff266dc82f4ae797a6f3513c6ffa344f7f1c7 Author: Boris Brezillon <boris.brezillon@bootlin.com> Date: Thu Apr 26 18:18:14 2018 +0200 spi: Extend the core to ease integration of SPI memory controllers Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general. This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs). Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Reviewed-by: Frieder Schrempf <frieder.schrempf@exceet.de> Tested-by: Frieder Schrempf <frieder.schrempf@exceet.de> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Generalize SPI "master" to "controller"Steffen Trumtrar2019-05-081-35/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sync with Linux v5.1-rc1. This is the barebox adoption of the commit commit 8caab75fd2c2a92667cbb1cd315720bede3feaa9 Author: Geert Uytterhoeven <geert+renesas@glider.be> Date: Tue Jun 13 13:23:52 2017 +0200 spi: Generalize SPI "master" to "controller" Now struct spi_master is used for both SPI master and slave controllers, it makes sense to rename it to struct spi_controller, and replace "master" by "controller" where appropriate. For now this conversion is done for SPI core infrastructure only. Wrappers are provided for backwards compatibility, until all SPI drivers have been converted. Noteworthy details: - SPI_MASTER_GPIO_SS is retained, as it only makes sense for SPI master controllers, - spi_busnum_to_master() is retained, as it looks up masters only, - A new field spi_device.controller is added, but spi_device.master is retained for compatibility (both are always initialized by spi_alloc_device()), - spi_flash_read() is used by SPI masters only. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: Introduce dev_set_name()Andrey Smirnov2018-10-181-1/+1
| | | | | | | | Introduce dev_set_name() in order to hide implementation details of setting device's name so it'd be easier to change it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: use of_property_read_bool where appropriateSascha Hauer2017-04-121-4/+4
| | | | | | Use of_property_read_bool where boolean properties are read. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: only register enabled child nodesJan Luebbe2015-07-091-1/+1
| | | | | Signed-off-by: Jan Luebbe <jluebbe@debian.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Call remove function only when availableSascha Hauer2015-03-171-1/+2
| | | | | | | | The bus implementations currently call the drivers remove hook unconditionally, but this hook is seldomly populated. Only call it when it's actually populated. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* i2c/spi: match of_modaliasesSascha Hauer2014-02-071-1/+1
| | | | | | | | i2c/spi devices in the devicetree often come with a "vendor,device" comaptible string. These do not match in barebox, so add a device_match_of_modalias function which does exactly that. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Get bus_num from devicetreeSascha Hauer2013-10-311-0/+3
| | | | | | Get the bus_num from devicetree if a "spi" alias exists. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: support dynamic bus idsSascha Hauer2013-10-311-0/+5
| | | | | | | | | When probing spi bus masters from devicetree they got a bus_num of -1. This works with a single bus master only since all bus masters had the same bus_num. Detect this and dynamically assign a valid bus_num. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Call spi_of_register_slaves from coreSascha Hauer2013-10-311-3/+10
| | | | | | Makes individual handling of OF spi slaves unnecessary in the bus drivers. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: Reuse "driver_match" for SPI busAlexander Shiyan2013-07-151-10/+1
| | | | | | | This will allow to use device_ids and make code a bit smaller. Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* OF: base: convert and remove device_node_for_nach_childSebastian Hesselbarth2013-06-201-1/+1
| | | | | | | | Remove device_node_for_nach_child and convert users to corresponding imported OF API functions. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* OF: base: sync of_find_property with linux OF APISebastian Hesselbarth2013-06-201-5/+5
| | | | | | | | To start synchronizing OF API of barebox with linux OF API, this adds a length pointer to of_find_property. Also all current users of that function are updated to reflect the API change. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
* spi: improve devicetree supportSascha Hauer2013-05-211-2/+13
| | | | | | | | | - zero spi_board_info structure to not accidently pass unitilialized fields - parse spi-max-frequency property from devicetree - parse mode flags from devicetree Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers/base: fix corrupt device treeSascha Hauer2012-12-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dev_add_child is a very unsafe function. If called multiple times it allows setting the same device to different parents thus corrupting the siblings list. This happens regularly since: | commit c2e568d19c5c34a05a1002d25280bf113b72b752 | Author: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | Date: Sat Nov 3 16:11:05 2012 +0100 | | bus: add bus device | | automatically add it as parent of any bus device if none already specified | | we have now a nice output per bus If for example a FATfs is mounted this nice output per bus often ends with: > `---- fat0 > `---- 0 > `---- 0x86f0000087020031-0x86f000410df27124: /dev/<NULL> > `---- sram00 > `---- 0x00000000-0xffffffffffffffff: /dev/<NULL> > `---- 0x00000000-0xffffffffffffffff: /dev/<NULL> > unable to handle NULL pointer dereference at address 0x0000000c > pc : [<87f08a20>] lr : [<87f08a04>] > sp : 86eff8c0 ip : 87f3fbde fp : ffffffff > r10: ffffffff r9 : 00000000 r8 : 00000003 > r7 : 86f075b8 r6 : 00000002 r5 : ffffffec r4 : 86f07544 > r3 : 00000000 r2 : 43f900b4 r1 : 00000020 r0 : 00000005 > Flags: Nzcv IRQs off FIQs off Mode SVC_32 > [<87f08a20>] (do_devinfo_subtree+0x90/0x130) from [<87f08a90>] (do_devinfo_subtree+0x100/0x130) > > [<87f3e070>] (unwind_backtrace+0x0/0x90) from [<87f28514>] (panic+0x28/0x3c) > [<87f28514>] (panic+0x28/0x3c) from [<87f3e4b8>] (do_exception+0x10/0x14) > [<87f3e4b8>] (do_exception+0x10/0x14) from [<87f3e544>] (do_data_abort+0x2c/0x38) > [<87f3e544>] (do_data_abort+0x2c/0x38) from [<87f3e268>] (data_abort+0x48/0x60) This patch fixes this by adding a device to its parents children list in register_device so that dev_add_child is no longer needed. This function is removed from the tree. Now callers of register_device have to clearly set the parent *before* registering a device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Jan Lübbe <jlu@pengutronix.de>
* spi: introduce spi_get_masterJean-Christophe PLAGNIOL-VILLARD2012-11-121-0/+12
| | | | | | | so we can request a master usefull for the spi command Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/remove-fsf-address'Sascha Hauer2012-10-031-4/+0
|\ | | | | | | | | | | Conflicts: drivers/net/miidev.c include/miidev.h
| * Treewide: remove address of the Free Software FoundationSascha Hauer2012-09-171-4/+0
| | | | | | | | | | | | | | The FSF address has changed in the past. Instead of updating it each time the address changes, just drop it completely treewide. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | spi: switch from printf back to debugJan Luebbe2012-09-271-1/+1
| | | | | | | | | | | | | | | | Commit 5888a3b5c96cf8381431486416ef2667993c85fc accidentally changed this to printf. Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | driver: register busJean-Christophe PLAGNIOL-VILLARD2012-09-231-0/+6
| | | | | | | | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | spi: add oftree supportSascha Hauer2012-09-141-1/+32
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | SPI: Put SPI devices on their own busSascha Hauer2012-09-141-0/+24
|/ | | | | | | | | This patch adds a SPI bus on which the SPI devices and drivers register. This makes it cleaner as SPI devices won't accidently end up probed by a platform_device driver. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
* drivers/spi/spi.c: use DEVICE_ID_DYNAMIC when allocating a struct device_dJan Luebbe2012-05-141-0/+2
| | | | | | | | This causes allocation of a free id and avoids conflicts if multiple identical SPI devices are attached. Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: enfore default bits_per_word valuePaul Fertser2011-09-291-1/+1
| | | | | | | | Documentation says it should default to 8 when not specified explicitly by the device data. Signed-off-by: Paul Fertser <fercerpav@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: let master a chance to setup device before registering itPaul Fertser2011-09-291-3/+2
| | | | | | | | | Call setup() before registering the device because registering leads to a probe routine of the slave device and that requires an initialised master. Signed-off-by: Paul Fertser <fercerpav@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: make the spi devices children of the parent busSascha Hauer2011-08-171-0/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: unregister dev if master->setup failsFranck Jullien2011-07-061-0/+1
| | | | | | | | If the device setup executed by the spi master fails, unregister the created device. Signed-off-by: Franck Jullien <franck.jullien@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: add bits_per_word to proxy structureFranck Jullien2011-07-061-0/+1
| | | | | | | | | | | | | During the creation of a new spi device, we need to have the possiblility to give the bits_per_word value to master->setup. As a matter of fact, spi master could check the spi device bits_per_word and compare this value against its capabilities. Signed-off-by: Franck Jullien <franck.jullien@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: add more spi transfer functionsHubert Feurstein2011-06-211-0/+41
| | | | | | | | | | | | | This commit adds the following spi transfer functions: - spi_write - spi_read - spi_write_then_read - spi_w8r8 The code has been ported from the linux kernel. Signed-off-by: Hubert Feurstein <h.feurstein@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: add platform_data pointer to spi_board_infoHubert Feurstein2011-06-211-0/+1
| | | | | | | | | In the spi layer this pointer will be assigned to the platform_data pointer of the new spi device, thus it can be accessed in the drivers 'probe' handler. Signed-off-by: Hubert Feurstein <h.feurstein@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* spi: dev->id is an int, not a string, fix debug outputMarc Kleine-Budde2009-11-241-1/+1
| | | | | | Also convert __FUNCTION__ -> __func__ Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
* spi: remove bogus setup of proxy deviceSascha Hauer2009-07-211-3/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* first (partly) running spi supportSascha Hauer2008-03-141-4/+187
|
* beginning of SPI supportSascha Hauer2008-03-111-0/+14