summaryrefslogtreecommitdiffstats
path: root/drivers/base
Commit message (Collapse)AuthorAgeFilesLines
* regmap: Add regmap_write_bits() functionAndrey Smirnov2017-01-101-0/+27
| | | | | | | Add code implementing a simple version of regmap_write_bits(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Introduce dev_request_mem_resourceSascha Hauer2016-02-231-2/+9
| | | | | | | | | | | | dev_request_mem_region returns a void * which shall be checked with IS_ERR(), but in some cases the valid pointer returned clashes with error values. This is especially the case on some Atmel SoCs. This introduces dev_request_mem_resource which returns a struct resource instead which in any case can be checked with IS_ERR(). It's the drivers responsibility then to get the IOMEM pointer from the resource. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Fix unregister device after device probe failureSascha Hauer2016-02-081-0/+4
| | | | | | | | | When a device probe fails the device is removed from the active list. If then the device is unregistered afterwards it is removed from the active list again resulting in a crash. To fix this initialize the devices active list entry when removing it from the active list. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add initial regmap supportSascha Hauer2016-02-054-0/+374
| | | | | | | | This adds initial regmap support. Function prototypes are from the Kernel, the implemention is mostly rewritten. Currently the regmap support is limited to the bare minimum to get started. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mips'Sascha Hauer2015-12-081-2/+2
|\
| * driver: make all dev_request_mem_region_* routines MIPS compatibleYegor Yefremov2015-12-011-2/+2
| | | | | | | | | | | | | | | | Use IOMEM() macro in all dev_request_mem_region_* routines to allow the proper mapping on all platforms. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | drivers: bus: Match against id_table firstAndrey Smirnov2015-12-071-3/+2
|/ | | | | | | | | | | | | | | | Matching against driver's name before looking throught its id_table can lead to a somewhat strange and unintuitive behaviour where a device whose driver's name matches one of the lines in id_table (which is not unheard of in Linux kernel) will be probed against said driver with 'id_table' field set to NULL which in turn will result in dev_get_drvdata erroring out with -ENODEV. This patch changes the behaviour such that device_match() only tries to match against driver's name only if id_table of that driver is not present. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* exitcall: move device_shutdown to exitcall infrastructureHerve Codina2015-07-131-1/+2
| | | | | Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: detect: detect parent devices aswellSascha Hauer2015-06-261-5/+20
| | | | | | | | | | | | | | Let device_detect_by_name detect parent devices aswell. We separate the devname strings by colons and call device_detect() for each component. This makes it possible for example to detect nand0.root.ubi.root With the above detect will be called for nand0, nand0.root, nand0.root.ubi and nand0.root.ubi.root. The nand0.root detection step will detect the UBI volume and attach it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/of-device-id'Sascha Hauer2015-05-061-2/+2
|\
| * of: use 'const void *' for struct of_device_id.dataAntony Pavlov2015-04-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since 2011 barebox' of_device_id struct uses unsigned long type for data field: struct of_device_id { char *compatible; unsigned long data; }; Almost always struct of_device_id.data field are used as pointer and need 'unsigned long' casting. E.g. see 'git grep -A 4 of_device_id drivers/' output: drivers/ata/sata-imx.c:static __maybe_unused struct of_device_id imx_sata_dt_ids[] = { drivers/ata/sata-imx.c- { drivers/ata/sata-imx.c- .compatible = "fsl,imx6q-ahci", drivers/ata/sata-imx.c- .data = (unsigned long)&data_imx6, drivers/ata/sata-imx.c- }, { Here is of_device_id struct in linux kernel v4.0: struct of_device_id { char name[32]; char type[32]; char compatible[128]; const void *data; }; Changing of_device_id.data type to 'const void *data' will increase barebox' linux kernel compatibility and decrease number of 'unsigned long' casts. Part of the patch was done using the 'coccinelle' tool with the following semantic patch: @rule1@ identifier dev; identifier type; identifier func; @@ func(...) { <... - dev_get_drvdata(dev, (unsigned long *)&type) + dev_get_drvdata(dev, (const void **)&type) ...> } @rule2@ identifier dev; identifier type; identifier func; identifier data; @@ func(...) { <... - dev_get_drvdata(dev, (unsigned long *)&type->data) + dev_get_drvdata(dev, (const void **)&type->data) ...> } Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2015-05-061-2/+2
|\ \
| * | drivers/base: Mark (of|platform)_device_id data as constantUwe Kleine-König2015-04-171-2/+2
| |/ | | | | | | | | | | | | | | | | | | There should be no reason to ever change the data pointed to by id_table or of_compatible. So make this offical by adding some 'const's. In Linux the corresponding pointers are marked as const, too. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / base: Introduce deferred probingSebastian Hesselbarth2015-04-171-3/+53
|/ | | | | | | | | As expected, we would need deferred probing sooner or later. This is a first approach to allow devices to return -EPROBE_DEFER and get sorted into a list of deferred devices that will be re-probed later. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Call bus->remove instead of driver->removeSascha Hauer2015-03-171-2/+2
| | | | | | | | | In devices_shutdown we should call the busses remove function which in turn calls the drivers remove function. Otherwise for example PCI devices never get removed since they do not have a remove function but a pcidev->remove function instead. 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>
* driver: fix device remove orderSascha Hauer2015-03-171-2/+3
| | | | | | | | | | | The active list is supposed to collect active devices in the opposite order they are probed. This is used to remove the devices in the correct order in devices_shutdown. The order is wrong though when in a drivers probe function other devices are registered. To get the order right we have to add the new device to the active list before it is probed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: remove unused function dev_protect()Marc Kleine-Budde2015-03-031-6/+0
| | | | | Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: dev_request_mem_region: fix return value for MIPSAntony Pavlov2015-01-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The commit commit 0d7a21334536cb36b3c9b64d868acc55aec41332 Author: Antony Pavlov <antonynpavlov at gmail.com> Date: Wed Sep 10 11:42:19 2014 +0400 MIPS: dts: use physical addresses (as Linux does) With IOMEM() adapted for MIPS we can use physical addresses in device tree reg property. has switched MIPS dts files to physical addresses usage. The patch was tested on qemu, but qemu malta board is tolerant of using physical addresses for accesing to device (Ingenic JZ4755 and JZ4780 processors are tolerant too!). But other CPUs (e.g. Loongson LS1B) can throw an exception in this situation. Additional physical address to virtual address translation on MIPS is needed. We already have this in include/common.h #if defined(CONFIG_MIPS) #include <asm/addrspace.h> #define IOMEM(addr) ((void __force __iomem *)CKSEG1ADDR(addr)) #else #define IOMEM(addr) ((void __force __iomem *)(addr)) #endif So use IOMEM() to fix dev_request_mem_region() return value. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: workaroud resource request that conflicts with errno PTRJean-Christophe PLAGNIOL-VILLARD2015-01-081-0/+16
| | | | | | | | | | | | | | | | broken since commit ed6e965824303255cacc1c1a195d3684caa26bce Author: Sascha Hauer <s.hauer@pengutronix.de> resource: Let dev_request_mem_region return an error pointer Introduce dev_request_mem_region_err_null only used on platform like at91 where the resource address conflicts with errno PTR. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/resource-err-ptr'Sascha Hauer2014-10-021-14/+20
|\
| * resource: Let dev_request_mem_region return an error pointerSascha Hauer2014-09-161-2/+2
| | | | | | | | | | | | For all users fix or add the error check. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * resource: Let dev_request_mem_region_by_name return an error pointerSascha Hauer2014-09-161-2/+2
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * resource: Let dev_get_mem_region return an error pointerSascha Hauer2014-09-161-1/+6
| | | | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
| * resource: Let dev_get_resource return an error pointerSascha Hauer2014-09-161-3/+3
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * resource: Let request_iomem_region return an error pointerSascha Hauer2014-09-161-2/+2
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * resource: Let dev_get_mem_region_by_name return an error pointerSascha Hauer2014-09-161-1/+1
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * resource: Let dev_get_resource_by_name return an error pointerSascha Hauer2014-09-161-3/+4
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Introduce message logging supportSascha Hauer2014-09-301-22/+0
|/ | | | | | | | | | This adds a buffer for log messages and a 'dmesg' command to print the messages. The log buffer is implemented as log objects rather than a string buffer. This makes it easy to implement limiting the messages, cleaning the buffer and timestamping the messages. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: Allow for I/O mapped I/OMichel Stam2014-04-081-7/+9
| | | | | | | | Rework the current framework so that I/O mapped I/O resources are also possible. Signed-off-by: Michel Stam <michel@reverze.net> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mtd'Sascha Hauer2014-03-071-0/+3
|\ | | | | | | | | | | Conflicts: drivers/mtd/core.c net/eth.c
| * device: remove parameters when unregistering a deviceSascha Hauer2014-02-131-0/+2
| | | | | | | | | | | | | | | | Otherwise we loose memory on each device_unregister. The ethernet code used to do this before calling unregister_device. This can now be removed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * device: init bus listSascha Hauer2014-02-131-0/+1
| | | | | | | | | | | | | | | | bus_list is only initialized when the device has a bus, but it needs to be initialized in unregister_device, so initialize the list unconditionally. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | i2c/spi: match of_modaliasesSascha Hauer2014-02-071-0/+37
|/ | | | | | | | 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>
* net: dm9k: Fix resource sizes in add_dm9000_deviceSascha Hauer2013-12-181-3/+3
| | | | | | | | | The dm9000 needs a resource for an index register and one for the data register. Both should have a size of the access width, and not two times the access width. The current code is probably a leftover when the dm9000 had only one resource. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/omap-drivers'Sascha Hauer2013-12-061-13/+47
|\
| * device: Add functions to add resourcesSascha Hauer2013-11-271-13/+47
| | | | | | | | | | | | | | | | | | We currently have functions to add a device based on function parameters. This adds the corresponding functions to add resources to a device without registering the device itself. This is useful to manipulate devices before registering them. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: Add missing includesSascha Hauer2013-11-083-0/+3
|/ | | | | | | | A lot of files rely on include/driver.h including include/of.h (and this including include/errno.h. include the files explicitly so we can eventually get rid of including of.h from driver.h Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2013-10-071-142/+0
|\ | | | | | | | | Conflicts: commands/Makefile
| * move devinfo command to its own fileSascha Hauer2013-09-271-142/+0
| | | | | | | | | | | | Just like nearly all other commands are in individual files. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | introduce runtime loglevelSascha Hauer2013-09-291-1/+5
|/ | | | | | | With this the verbosity of barebox can be controlled during runtime using the 'loglevel' globalvar. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* base: Transform "platform_match" into "device_match" and make this function ↵Alexander Shiyan2013-07-152-25/+25
| | | | | | | | | public This change will allow reuse this function for other buses. Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: implement device_detect_by_name functionSascha Hauer2013-06-261-0/+10
| | | | | | | It becomes a common pattern for boards to find a device and call device_detect on it. Add a convenience wrapper for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devices: add detect mechanismSascha Hauer2013-05-311-0/+7
| | | | | | | | | | | | | | | We often encounter the situation where slow devices should not be probed during startup since probing is slow and maybe unnecessary for unused devices. With MMC we have the 'probe' device parameter, for ata we have the same, for USB we have the 'usb' command. Overall this is not very consistent. With MMC there is the additional problem that the probe parameter is attached to the logical device when we often have the information which physical device we want to probe. This patch adds a 'detect' callback for devices and adds a command to detect devices and to list the devices which are actually detecable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Attach info callback to device, not to driverSascha Hauer2013-05-301-16/+2
| | | | | | | | Since the info is device specific and not driver specific, attach the callback to the device. This makes it possible to have a info callback for a device which does not have a driver attached. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* param: Add info functionSascha Hauer2013-05-231-2/+6
| | | | | | | Some parameters may wish to provide some information about their meaning or possible values. Provide an info callback for parameters. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add initial pinctrl supportSascha Hauer2013-04-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a massively stripped down pinctrl support. The upper API consists of only of: int pinctrl_select_state(struct device_d *dev, const char *state); This is used to setup the pinmux for a device to a certain state. This function normally does not need to be called manually. The device core will setup the default state before probing a device. The pinctrl core has the job of handling the devicetree. It parses the pinctrl phandles for a device from devicetree, finds the correct pinctrl device and calls its set_state callback with the pinctrl setup device node. The simplicity of this pinctrl framework comes from the fact that we: - Limit usage to devicetree only for now. For non devicetree use the old legacy SoC specific APIs still can be used. - Do not parse the devicetree into internal data structures which are used by the drivers later. This adds the overhead that we may parse the devicetree multiple times for more dynamic setups, but on the other hand we do not need to parse devices from the devicetree we don't use in barebox - Do not detect resource conflicts. Since the framework mainly is a devicetree parser this would be hard to implement. It should be easy for board maintainers to avoid resource conflicts though. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bus: Make struct device a pointerSascha Hauer2013-03-142-4/+5
| | | | | | | | struct bus_type contains an embedded struct device_d which is quite a big structure. Dynamically allocate this instead to save the space in the binary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Make "dev_get_resource" publicly availableAlexander Shiyan2013-02-181-1/+1
| | | | | Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers/base: fix corrupt device treeSascha Hauer2012-12-121-21/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>