Commit Graph

224 Commits

Author SHA1 Message Date
Grant Likely 925bb9c649 of/i2c: Fix module load order issue caused by of_i2c.c
Commit 959e85f7, "i2c: add OF-style registration and binding" caused a
module dependency loop where of_i2c.c calls functions in i2c-core, and
i2c-core calls of_i2c_register_devices() in of_i2c.  This means that
when i2c support is built as a module when CONFIG_OF is set, then
neither i2c_core nor of_i2c are able to be loaded.

This patch fixes the problem by moving the of_i2c_register_devices()
calls back into the device drivers.  Device drivers already
specifically request the core code to parse the device tree for
devices anyway by setting the of_node pointer, so it isn't a big
deal to also call the registration function.  The drivers just become
slightly more verbose.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-09-30 14:14:23 +02:00
Rajendra Nayak 64b4782fc9 i2c: Fix checks which cause legacy suspend to never get called
For devices which are not adapted to runtime PM a call to
pm_runtime_suspended always returns true.

Hence the pm_runtime_suspended checks below prevent legacy
suspend from getting called.

So do a pm_runtime_suspended check only for devices with a
dev_pm_ops populated (which hence do not rely on the legacy
suspend.)

Signed-off-by: Rajendra Nayak <rnayak@ti.com>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Ben Dooks <ben-linux@fluff.org>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Kevin Hilman <khilman@deeprootsystems.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-09-30 14:14:22 +02:00
Vishwanath BS 753419f59e i2c: Fix for suspend/resume issue
In current i2c core driver, call to pm_runtime_set_active from
i2c_device_pm_resume will unconditionally enable i2c module and
increment child count of the parent. Because of this, in CPU Idle
path, i2c does not idle, preventing Core to enter retention. Also i2c
module will not be suspended upon system suspend as
pm_runtime_set_suspended is not called from i2c_device_pm_suspend.

This issue is fixed by removing pm_runtime_set_active call from resume
path which is not necessary.
This fix has been tested on OMAP4430.

Signed-off-by: Partha Basak <p-basak2@ti.com>
Signed-off-by: Vishwanath BS <vishwanath.bs@ti.com>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@deeprootsystems.com>
Cc: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-09-30 14:14:22 +02:00
Michael Lawnick 0826374bff i2c: Multiplexed I2C bus core support
Add multiplexed bus core support. I2C multiplexer and switches
like pca954x get instantiated as new adapters per port.

Signed-off-by: Michael Lawnick <ml.lawnick@gmx.de>
Acked-by: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-08-11 18:21:02 +02:00
Jean Delvare dafc50d141 i2c: Use a separate mutex for userspace client lists
Moving userspace-instantiated clients to separate lists wasn't nearly
enough to avoid deadlocks in multiplexed bus cases. We also want to
have a dedicated mutex to protect each list.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Michael Lawnick <ml.lawnick@gmx.de>
2010-08-11 18:21:01 +02:00
Jean Delvare 8031d79bae i2c: Make i2c_default_probe self-sufficient
Make i2c_default_probe self-sufficient, so that callers don't have to
do functionality checks themselves. This ensures everything is and
will stay consistent.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-08-11 18:21:00 +02:00
Jean Delvare d6703281ff i2c: Drop dummy variable
Now that bus_for_each_drv() is no longer __must_check, we can drop the
dummy variable that was used to store the returned value.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Justin P. Mattock <justinmattock@gmail.com>
2010-08-11 18:20:59 +02:00
Jean Delvare fe61e07e9e i2c: Move adapter locking helpers to i2c-core
Uninline i2c adapter locking helper functions, move them to i2c-core,
and use them in i2c-core itself. The functions are still exported for
external users. This makes future updates to the locking model (which
will be needed for multiplexing support) possible and transparent.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Michael Lawnick <ml.lawnick@gmx.de>
2010-08-11 18:20:58 +02:00
Jean Delvare d44f19d586 V4L/DVB: Use custom I2C probing function mechanism
Now that i2c-core offers the possibility to provide custom probing
function for I2C devices, let's make use of it.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2010-08-11 18:20:57 +02:00
Jean Delvare 9a94241afc i2c: Add support for custom probe function
The probe method used by i2c_new_probed_device() may not be suitable
for all cases. Let the caller provide its own, optional probe
function.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2010-08-11 18:20:56 +02:00
Grant Likely 4e4f62bf73 Merge commit 'v2.6.35-rc6' into devicetree/next
Conflicts:
	arch/sparc/kernel/prom_64.c
2010-07-24 09:49:13 -06:00
Jean Delvare 827900c556 i2c: Fix probability check
The new unified probing function differs from the original code, and
the preliminary test whether probing is possible must be updated
accordingly.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-07-10 09:42:46 +02:00
Grant Likely 959e85f775 i2c: Add OF-style registration and binding
This patch adds OF hooks to the i2c core so that devices can automatically
be registered based on device tree data.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-07-05 16:14:52 -06:00
Jean Delvare 3b5f794b8b i2c: Rename i2c_check_addr to i2c_check_addr_busy
Otherwise it's not clear what it is checking.

Also move the function to save a forward declaration.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-06-03 11:33:55 +02:00
Jean Delvare 656b8761ab i2c: Document reserved I2C addresses
Move strict I2C address validity check to a single function, and
document the reserved I2C addresses there.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Hans Verkuil <hverkuil@xs4all.nl>
2010-06-03 11:33:53 +02:00
Jean Delvare 3a89db5f30 i2c: Check for address validity on client registration
Do basic address validity checks when a client is being registered. We
already had checks in place for devices which are being detected, but
not for devices which are simply instantiated.

This is a very basic check. We don't want to do strict checking here
because some devices are known to infringe the I2C address constraints
(e.g. IR receivers at 7-bit address 0x7a while this value is
supposedly reserved for 10-bit addresses.) So we assume the caller
knows what it is doing.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Matthieu Castet <castet.matthieu@free.fr>
2010-06-03 11:33:52 +02:00
Jean Delvare 63e4e80218 i2c: Share the I2C device presence detection code
Use the same I2C device presence detection code for legacy and new
device detection functions. This is more consistent and makes the code
smaller.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Matthieu Castet <castet.matthieu@free.fr>
2010-06-03 11:33:51 +02:00
Grant Likely cf9b59e9d3 Merge remote branch 'origin' into secretlab/next-devicetree
Merging in current state of Linus' tree to deal with merge conflicts and
build failures in vio.c after merge.

Conflicts:
	drivers/i2c/busses/i2c-cpm.c
	drivers/i2c/busses/i2c-mpc.c
	drivers/net/gianfar.c

Also fixed up one line in arch/powerpc/kernel/vio.c to use the
correct node pointer.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-05-22 00:36:56 -06:00
Farid Hammane 7225acf4aa i2c-core: Fix some coding style issues
Fix up coding style issues found by the checkpatch.pl tool.

Signed-off-by: Farid Hammane <farid.hammane@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-05-21 18:40:58 +02:00
Rafael J. Wysocki 2f60ba706b i2c: Fix bus-level power management callbacks
There are three issues with the i2c bus type's power management
callbacks at the moment.  First, they don't include any hibernate
callbacks, although they should at least include the .restore()
callback (there's no guarantee that the driver will be present in
memory before loading the image kernel and we must restore the
pre-hibernation state of the device).  Second, the "legacy"
callbacks are not going to be invoked by the PM core since the bus
type's pm object is not NULL.  Finally, the system sleep PM
(ie. suspend/resume) callbacks don't check if the device has been
already suspended at run time, in which case they should skip
suspending it.  Also, it looks like the i2c bus type can use the
generic subsystem-level runtime PM callbacks.

For these reasons, rework the system sleep PM callbacks provided by
the i2c bus type to handle hibernation correctly and to invoke the
"legacy" callbacks for drivers that provide them.  In addition to
that make the i2c bus type use the generic subsystem-level runtime
PM callbacks.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2010-05-10 23:09:30 +02:00
Jean Delvare 6629dcff19 i2c-core: Use per-adapter userspace device lists
Using a single list for all userspace devices leads to a dead lock
on multiplexed buses in some circumstances (mux chip instantiated
from userspace). This is solved by using a separate list for each
bus segment.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Michael Lawnick <ml.lawnick@gmx.de>
2010-05-04 11:09:28 +02:00
Jean Delvare b1d4b390ea i2c: Fix probing of FSC hardware monitoring chips
Some FSC hardware monitoring chips (Syleus at least) doesn't like
quick writes we typically use to probe for I2C chips. Use a regular
byte read instead for the address they live at (0x73). These are the
only known chips living at this address on PC systems.

For clarity, this fix should not be needed for kernels 2.6.30 and
later, as we started instantiating the hwmon devices explicitly based
on DMI data. Still, this fix is valuable in the following two cases:
* Support for recent FSC chips on older kernels. The DMI-based device
  instantiation is more difficult to backport than the device support
  itself.
* Case where the DMI-based device instantiation fails, whatever the
  reason. We fall back to probing in that case, so it should work.

This fixes kernel bug #15634:
https://bugzilla.kernel.org/show_bug.cgi?id=15634

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Cc: stable@kernel.org
2010-05-04 11:09:28 +02:00
Wolfram Sang e4a7b9b04d i2c-core: Erase pointer to clientdata on removal
After discovering that a lot of i2c-drivers leave the pointer to their
clientdata dangling, it was decided to let the core handle this issue.
It is assumed that the core may access the private data after remove()
as there are no guarantees for the lifetime of such pointers anyhow (see
thread starting at http://lkml.org/lkml/2010/3/21/68)

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-05-04 11:09:27 +02:00
Grant Likely d12d42f744 i2c/of: Allow device node to be passed via i2c_board_info
The struct device_node *of_node pointer is moving out of dev->archdata
and into the struct device proper.  of_i2c.c needs to set the of_node
pointer before the device is registered.  Since the i2c subsystem
doesn't allow 2 stage allocation and registration of i2c devices, the
of_node pointer needs to be passed via the i2c_board_info structure
so that it is set prior to registration.

This patch adds of_node to struct i2c_board_info (conditional on
CONFIG_OF), sets of_node in i2c_new_device(), and modifies of_i2c.c
to use the new parameter.  The calling of dev_archdata_set_node()
from of_i2c will be removed in a subsequent patch when of_node is
removed from archdata and all users are converted over.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-04-28 18:21:56 -06:00
Zhangfei Gao 0c43ea544c i2c: Document the message size limit
i2c_master_send & i2c_master_recv do not support more than 64 kb
transfer, since msg.len is u16.

Signed-off-by: Zhangfei Gao <zgao6@marvell.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-03-02 12:23:49 +01:00
Mark Brown 6de468ae2d i2c: Hook up runtime PM support
Allow I2C drivers to make use of the runtime PM framework by adding
bus implementations of the runtime PM operations. These simply
immediately suspend when the device is idle. The runtime PM framework
provides drivers with off the shelf refcounts for enables and sysfs
control for managing runtime suspend from userspace so is useful even
without meaningful input from the bus.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-03-02 12:23:46 +01:00
Thadeu Lima de Souza Cascardo c556752109 i2c: Do not use device name after device_unregister
dev_dbg outputs dev_name, which is released with device_unregister. This bug
resulted in output like this:

i2c Xy2�0: adapter [SMBus I801 adapter at 1880] unregistered

The right output would be:
i2c i2c-0: adapter [SMBus I801 adapter at 1880] unregistered

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-01-16 20:43:13 +01:00
Tobias Klauser 0b2c368844 i2c-core: Storage class should be before const qualifier
The C99 specification states in section 6.11.5:

The placement of a storage-class specifier other than at the beginning
of the declaration specifiers in a declaration is an obsolescent
feature.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-01-16 20:43:12 +01:00
sonic zhang 54067ee206 i2c-core: i2c bus should support PM entries in struct dev_pm_ops
Struct dev_pm_ops is not configured in current i2c bus type. i2c drivers
only depends on suspend/resume entries in struct dev_pm_ops are not
informed of PM suspend and resume events by i2c framework.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-12-14 21:17:30 +01:00
Jean Delvare c3813d6af1 i2c: Get rid of struct i2c_client_address_data
Struct i2c_client_address_data only contains one field at this point,
which makes its usefulness questionable. Get rid of it and pass simple
address lists around instead.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Wolfram Sang <w.sang@pengutronix.de>
2009-12-14 21:17:25 +01:00
Jean Delvare 310ec79210 i2c: Drop the kind parameter from detect callbacks
The "kind" parameter always has value -1, and nobody is using it any
longer, so we can remove it.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Wolfram Sang <w.sang@pengutronix.de>
2009-12-14 21:17:23 +01:00
Jean Delvare 69b0089a67 i2c: Refactor for_each callbacks
Functions i2c_do_add_adapter() and __attach_adapter() do essentially
the same thing, differing only in how the parameters are passed. Same
for i2c_do_add_adapter() and __detach_adapter(). Introduce wrappers to
normalize the parameters, so that we do not have to duplicate the
code.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-12-06 17:06:27 +01:00
Jean Delvare ccfbbd082a i2c: Simplify i2c_detect_address
The kind parameter of i2c_detect_address() always has value -1, so we
can get rid of it.

Next step is to update all i2c detect callback functions to get rid of
this now useless parameter.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-12-06 17:06:25 +01:00
Jean Delvare c7b25a9e96 i2c: Drop probe, ignore and force module parameters
The legacy probe and force module parameters are obsolete now, the
same can be achieved using the new_device sysfs interface, which is
both more flexible and cheaper (it is implemented by i2c-core rather
than replicated in every driver module.)

The legacy ignore module parameters can be dropped as well. Ignoring
can be done by instantiating a "dummy" device at the problematic
address.

This is the first step of a huge cleanup to i2c-core's i2c_detect
function, i2c.h's I2C_CLIENT_INSMOD* macros, and all drivers that made
use of them.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-12-06 17:06:24 +01:00
Mika Kuoppala 194684e596 i2c: Prevent priority inversion on top of bus lock
Low priority thread holding the i2c bus mutex could block higher
priority threads to access the bus resulting in unacceptable
latencies. Change the mutex type to rt_mutex preventing priority
inversion.

Tested-by: Peter Ujfalusi <peter.ujfalusi@nokia.com>
Signed-off-by: Mika Kuoppala <mika.kuoppala@nokia.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-12-06 17:06:22 +01:00
Jean Delvare bbd2d9c919 i2c: Fix userspace_device list corruption
Fix userspace_device list corruption. The corruption was caused by
clients not being removed when adapters with such clients were
themselves removed. Something like the following would trigger it
(assuming i2c-stub gets adapter number 3):

# modprobe i2c-stub chip_addr=0x50
# echo 24c08 0x50 > /sys/bus/i2c/devices/i2c-3/new_device 
# rmmod i2c-stub
# modprobe i2c-stub chip_addr=0x50
# echo 24c08 0x50 > /sys/bus/i2c/devices/i2c-3/new_device 

For the records, the stack trace in the kernel logs look like this:

kernel: WARNING: at lib/list_debug.c:30 __list_add+0x8b/0x90()
kernel: Hardware name: (...)
kernel: list_add corruption. prev->next should be next (c137fc84), but was (null). (prev=f57111b8).
kernel: Modules linked in: (...)
kernel: Pid: 4669, comm: bash Not tainted 2.6.32-rc8 #259
kernel: Call Trace:
kernel:  [<c111eb8b>] ? __list_add+0x8b/0x90
kernel:  [<c111eb8b>] ? __list_add+0x8b/0x90
kernel:  [<c103265c>] warn_slowpath_common+0x6c/0xc0
kernel:  [<c111eb8b>] ? __list_add+0x8b/0x90
kernel:  [<c10326f6>] warn_slowpath_fmt+0x26/0x30
kernel:  [<c111eb8b>] __list_add+0x8b/0x90
kernel:  [<c11ba165>] i2c_sysfs_new_device+0x1c5/0x250
kernel:  [<c10861be>] ? might_fault+0x2e/0x80
kernel:  [<c11b9fa0>] ? i2c_sysfs_new_device+0x0/0x250
kernel:  [<c118c625>] dev_attr_store+0x25/0x30
kernel:  [<c10e305c>] sysfs_write_file+0x9c/0xf0
kernel:  [<c109d35c>] vfs_write+0x9c/0x160
kernel:  [<c10e2fc0>] ? sysfs_write_file+0x0/0xf0
kernel:  [<c109d4dd>] sys_write+0x3d/0x70
kernel:  [<c1002ed8>] sysenter_do_call+0x12/0x36

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-11-26 09:22:33 +01:00
Jean Delvare 2bb5095aff i2c: Provide compatibility links for i2c adapters
Some user-space applications may be relying on i2c adapters showing up
as class devices in sysfs. Provide compatibility links for them for
the time being. We will remove them after a long transition period.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
2009-09-18 22:45:46 +02:00
Jean Delvare 4f8cf8240a i2c: Convert i2c adapters to bus devices
Kay says i2c adapters shouldn't be class devices but bus devices.
Convert them that way, using a device type.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
2009-09-18 22:45:46 +02:00
Jean Delvare 51298d1257 i2c: Convert i2c clients to a device type
This is required for upcoming changes.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
2009-09-18 22:45:45 +02:00
Rodolfo Giometti f18c41daea i2c: Use rwsem instead of mutex for board info
By using rwsem we can easily manage recursive calls of
i2c_scan_static_board_info() function without breaking the locking.

Signed-off-by: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-06-19 16:58:20 +02:00
Jean Delvare 99cd8e2587 i2c: Add a sysfs interface to instantiate devices
Add a sysfs interface to instantiate and delete I2C devices. This is
primarily a replacement of the force_* module parameters implemented
by some i2c drivers. These module parameters were implemented
internally by the I2C_CLIENT_INSMOD* macros, which don't scale well.

This can also be used when developing a driver on a self-soldered
board which doesn't yet have proper I2C device declaration at the
platform level, and presumably for various debugging situations.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:20 +02:00
Jean Delvare 35fc37f818 i2c: Limit core locking to the necessary sections
The i2c-core code tends to hold the core lock for longer than it
should. Limit locking to the necessary sections for both performance
and clarity. This is also a requirement to support I2C multiplexers in
the future.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Rodolfo Giometti <giometti@linux.it>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:19 +02:00
Jean Delvare e549c2b54d i2c: Kill the redundant client list
We used to maintain our own per-adapter list of i2c clients, but this
is redundant with what the driver core does, and no longer needed.
Just drop the redundant list.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:19 +02:00
Jean Delvare 1e40ac12da i2c: Kill is_newstyle_driver
Legacy i2c drivers are gone, all drivers are new-style now, so there
is no point to check.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:19 +02:00
Jean Delvare f8a227e8ac i2c: Merge i2c_attach_client into i2c_new_device
Now that i2c_attach_client is no longer exported, it doesn't need to
be a separate function. Merge it into its only user, i2c_new_device.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:18 +02:00
Jean Delvare 36789b5ea5 i2c: Drop i2c_probe function
The legacy i2c_probe() function has no users left, get rid of it.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:18 +02:00
Jean Delvare 729d6dd571 i2c: Get rid of the legacy binding model
We converted all the legacy i2c drivers so we can finally get rid of
the legacy binding model. Hooray!

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:18 +02:00
Jean Delvare 352da9820e i2c: Kill client_register and client_unregister methods
These methods were useful in the legacy binding model but no longer in
the new (standard) binding model. There are no users left so we can
drop them.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-06-19 16:58:17 +02:00
Jean Delvare c52cf01f5b i2c: Do not give adapters a default parent
We don't need to give adapters a parent if they don't have one. The
driver core will put them in the virtual device directory and all will
be fine.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-06-15 18:01:48 +02:00
Clifford Wolf 66b650f045 i2c: Retry automatically on arbitration loss
Some small changes in i2c core to retry i2c xfers until either the
maximum number of retries or the timeout is hit.

Signed-off-by: Clifford Wolf <clifford@clifford.at>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-06-15 18:01:46 +02:00
Jack Stone 1cf92b453a i2c: Remove void casts
Remove uneeded void casts.

Signed-off-by: Jack Stone <jwjstone@fastmail.fm>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-06-15 18:01:46 +02:00
Jean Delvare 935298696f i2c: Let new-style drivers implement attach_adapter
While it isn't the way the standard device binding model works, it is
OK for new-style drivers to implement attach_adapter. It may help
convert the renaming legacy drivers to new style drivers faster.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <dbrownell@users.sourceforge.net>
2009-04-13 17:02:14 +02:00
Zhenwen Xu 09b8ce0a69 i2c-core: Some style cleanups
Some lines over 80. 
The printk(KERN_ERR ... ) should be dev_err.
And some blankspace should be deleted.

Signed-off-by: Zhenwen Xu <helight.xu@gmail.com>
Signed-off-by: Jean Delvare <khlai@linux-fr.org>
2009-03-28 21:34:46 +01:00
Jean Delvare 8fcfef6e65 i2c: Set a default timeout value for all adapters
Setting a default timeout value on a per-algo basis doesn't make any
sense. Move the default value setting to i2c-core. Individual adapter
drivers can specify a different (non-zero) value if they wish.

Also express the timeout value in a way which results in the same
duration regarless of the value of HZ.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
2009-03-28 21:34:43 +01:00
Jean Delvare acec211ca6 i2c: Clarify which clients are auto-removed
The automatic removal of i2c clients only affects the clients which
were created automatically in the first place. Add a comment saying
that to avoid any confusion.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-03-28 21:34:40 +01:00
Ming Lei f67f129e51 Driver core: implement uevent suppress in kobject
This patch implements uevent suppress in kobject and removes it
from struct device, based on the following ideas:

1,Uevent sending should be one attribute of kobject, so suppressing it
in kobject layer is more natural than in device layer. By this way,
we can do it for other objects embedded with kobject.

2,It may save several bytes for each instance of struct device.(On my
omap3(32bit ARM) based box, can save 8bytes per device object)

This patch also introduces dev_set|get_uevent_suppress() helpers to
set and query uevent_suppress attribute in case to help kobject
as private part of struct device in future.

[This version is against the latest driver-core patch set of Greg,please
ignore the last version.]

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-03-24 16:38:26 -07:00
Roel Kluin f29d2e0275 i2c: Fix misplaced parentheses
Fix misplaced parentheses.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-02-24 19:19:48 +01:00
Kay Sievers 27d9c1838f i2c: Replace bus_id with dev_name(), dev_set_name()
This patch is part of a larger patch series which will remove
the "char bus_id[20]" name string from struct device. The device
name is managed in the kobject anyway, and without any size
limitation, and just needlessly copied into "struct device".

To set and read the device name dev_name(dev) and dev_set_name(dev)
must be used. If your code uses static kobjects, which it shouldn't
do, "const char *init_name" can be used to statically provide the
name the registered device should have. At registration time, the
init_name field is cleared, to enforce the use of dev_name(dev) to
access the device name at a later time.

We need to get rid of all occurrences of bus_id in the entire tree
to be able to enable the new interface. Please apply this patch,
and possibly convert any remaining remaining occurrences of bus_id.

We want to submit a patch to -next, which will remove bus_id from
"struct device", to find the remaining pieces to convert, and finally
switch over to the new api, which will remove the 20 bytes array
and does no longer have a size limitation.

Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2009-01-07 14:29:16 +01:00
Jean Delvare 79b93e1359 i2c: Remove i2c clients in reverse order
i2c clients should be removed in reverse order compared to the probe
(actually: bind) order. This matters when several clients depend on
each other.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
2008-11-28 15:24:38 +01:00
Anton Vorontsov 11f1f2afd6 i2c: Add info->archdata field
If present the info->archdata is copied into the dev->archdata.
Some (OpenFirmware) platforms need it.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-10-22 20:21:33 +02:00
Prakash Mortha 596c88f460 i2c: Restore i2c_smbus_process_call function
Restore the i2c_smbus_process_call() as one driver (for the
Micronas MAP5401) will need it soon.

[JD: Update documentation accordingly.]

Signed-off-by: Prakash Mortha <pmortha@escient.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-10-14 17:30:06 +02:00
David Brownell a10f9e7caf i2c: Do earlier driver model init
Move I2C driver model init earlier in the boot sequence.

This avoids oopsing in statically linked systems when some
subsystems register I2C drivers in subsys_initcall() code,
but those subsystems are linked (and initialized) before I2C.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-10-14 17:30:06 +02:00
David Brownell 1d0b19c9a0 i2c: Guard against oopses from bad init sequences
Guard I2C against oopsing because of init sequence problems, by
verifying that i2c_init() has been called before calling any
routines that rely on that initialization.  This specific test
just requires that bus_register(&i2c_bus_type) was called.

Examples of this kind of oopsing come from subystems and drivers
which register I2C drivers in their subsys_initcall code but
which are statically linked before I2C by drivers/Makefile.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-10-14 17:30:05 +02:00
Jean Delvare 4329cf8613 i2c: Prevent log spam on some DVB adapters
Some DVB adapters do not support the special I2C transaction that we
use for probing purposes. There's no point in logging this event, as
there's nothing the user can do and in general there is no actual
problem. So, degrade one of these messages to a debug message, and
move the other one around so that it is only printed on bogus drivers.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Uwe Bugla <uwe.bugla@gmx.de>
2008-08-28 08:33:23 +02:00
Marc Pignat ee35425c8e i2c: Fix device_init_wakeup place
device_init_wakeup must be called after device_register.

Signed-off-by: Marc Pignat <marc.pignat@hevs.ch>
Acked-by: David Brownell <david-b@pacbell.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-08-28 08:33:22 +02:00
Jean Delvare c1159f9e89 i2c: Check for address business before creating clients
We check for address business in i2c_probe_address(),
i2c_detect_address() and i2c_new_probed_device(), but this isn't
sufficient. Drivers can call i2c_attach_client() and
i2c_new_device() on any address, so we must check the address there
as well.

This fixes bug #11239:
http://bugzilla.kernel.org/show_bug.cgi?id=11239

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-08-10 22:56:16 +02:00
Hans Verkuil b25b791b13 i2c: Fix NULL pointer dereference in i2c_new_probed_device
Fix a NULL pointer dereference that happened when calling
i2c_new_probed_device on one of the addresses for which we use byte
reads instead of quick write for detection purpose (that is: 0x30-0x37
and 0x50-0x5f).

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-08-10 22:56:15 +02:00
Greg Kroah-Hartman 93562b5376 Driver Core: add ability for class_for_each_device to start in middle of list
This mirrors the functionality that driver_for_each_device has as well.

We add a start variable, and all callers of the function are fixed up at
the same time.

The block layer will be using this new functionality in a follow-on
patch.


Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-07-21 21:54:47 -07:00
Jean Delvare bd4bc3dbde i2c: Clear i2c_adapter.dev on adapter removal
Clear i2c_adapter.dev on adapter removal. This makes it possible to
re-add the adapter at a later point, which some drivers
(i2c-amd756-s4882, i2c-nforce2-s4985) actually do.

This fixes a bug reported by John Stultz here:
  http://lkml.org/lkml/2008/7/15/720
and by Ingo Molar there:
  http://lkml.org/lkml/2008/7/16/78

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
2008-07-16 19:30:05 +02:00
Jean Delvare 4735c98f84 i2c: Add detection capability to new-style drivers
Add a mechanism to let new-style i2c drivers optionally autodetect
devices they would support on selected buses and ask i2c-core to
instantiate them. This is a replacement for legacy i2c drivers, much
cleaner.

Where drivers had to implement both a legacy i2c_driver and a
new-style i2c_driver so far, this mechanism makes it possible to get
rid of the legacy i2c_driver and implement both enumerated and
detected device support with just one (new-style) i2c_driver.

Here is a quick conversion guide for these drivers, step by step:

* Delete the legacy driver definition, registration and removal.
  Delete the attach_adapter and detach_client methods of the legacy
  driver.

* Change the prototype of the legacy detect function from
    static int foo_detect(struct i2c_adapter *adapter, int address, int kind);
  to
    static int foo_detect(struct i2c_client *client, int kind,
    			  struct i2c_board_info *info);

* Set the new-style driver detect callback to this new function, and
  set its address_data to &addr_data (addr_data is generally provided
  by I2C_CLIENT_INSMOD.)

* Add the appropriate class to the new-style driver. This is
  typically the class the legacy attach_adapter method was checking
  for. Class checking is now mandatory (done by i2c-core.) See
  <linux/i2c.h> for the list of available classes.

* Remove the i2c_client allocation and freeing from the detect
  function. A pre-allocated client is now handed to you by i2c-core,
  and is freed automatically.

* Make the detect function fill the type field of the i2c_board_info
  structure it was passed as a parameter, and return 0, on success. If
  the detection fails, return -ENODEV.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:36 +02:00
Jean Delvare 8508159e2f i2c: Call client_unregister for new-style devices too
We call adapter->client_register for both legacy and new-style i2c
devices, however we only call adapter->client_unregister for legacy
drivers. This doesn't make much sense. Usually, drivers will undo
in client_unregister what they did in client_register, so we should
call neither or both for every given i2c device.

In order to ease the transition from legacy to new-style devices, it
seems preferable to actually call both.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <david-b@pacbell.net>
2008-07-14 22:38:36 +02:00
Jon Smirl e9ca9eb9d7 i2c: Export the i2c_bus_type symbol
Export the root of the i2c bus so that PowerPC device tree code can
iterate over devices on the i2c bus.

Signed-off-by: Jon Smirl <jonsmirl@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:35 +02:00
Jean Delvare e0457442fd i2c: Simplify i2c_device_probe
i2c_driver.id_table is mandatory now, so we can simplify
i2c_device_probe() a bit.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:30 +02:00
Jean Delvare f7050bd716 i2c: Simplify i2c_del_driver()
i2c_del_driver() can be simplified a bit.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:26 +02:00
Matthias Kaehlcke 6a03cd9311 i2c: Use list_for_each_entry_safe
Use list_for_each_entry_safe() in i2c_del_adapter() and i2c_del_driver().

Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:26 +02:00
David Brownell 6ea438ec8d i2c: i2c_use_client() defends against NULL
Defend the i2c refcount calls against NULL pointers, as is important
(and conventional) for such calls.  Note that none of the current
callers of i2c_use_client() use its return value.

[JD: I hate this but apparently all the other subsystems do it so...]

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:24 +02:00
David Brownell a1cdedac63 i2c: Kerneldoc for most I/O calls
Provide kerneldoc for most of the I2C and SMBus I/O calls.  Add a
comment summarizing some fault reporting issues which affect the
ability to provide clean fault reports through I2C master transfer
calls.  (Making it hard to precisely specify their return values...)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:24 +02:00
Jean Delvare 67c2e66571 i2c: Delete unused function i2c_smbus_write_quick
Function i2c_smbus_write_quick has no users left, so we can delete it.

Also update the list of these helper functions which are gone but
could be added back if needed.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:23 +02:00
David Brownell 24a5bb7b18 i2c-core: Return -Errno, not -1
More updates to the I2C stack's fault reporting:  make the core stop
returning "-1" (usually "-EPERM") for all faults.  Instead, pass lower
level fault code up the stack, or return some appropriate errno.

This patch happens to touch almost exclusively SMBus calls.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:23 +02:00
Jean Delvare 75415490d6 i2c-core: Remove needless include
i2c-core doesn't use seq files, so doesn't need to include
<linux/seq_file.h>.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:22 +02:00
Dave Young 7f101a9786 i2c: Use class_for_each_device
Use class_for_each_device for iteration.

Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14 22:38:19 +02:00
Jean Delvare eb8a790809 i2c: Kill the old driver matching scheme
Remove the old driver_name/type scheme for i2c driver matching. Only the
standard aliasing model will be used from now on.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-05-18 20:49:41 +02:00
Jean Delvare 60b129d7bf i2c: Match dummy devices by type
As the old driver_name/type matching scheme is going away soon, change
the dummy device mechanism to use the new matching scheme.

This has the downside that dummy i2c clients can no longer choose
their name, they'll all appear as "dummy" in sysfs and in log
messages. I don't think it is a problem in practice though, as there
is little reason to use these i2c clients to log messages.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-05-11 20:37:06 +02:00
Jean Delvare d2653e9273 i2c: Add support for device alias names
Based on earlier work by Jon Smirl and Jochen Friedrich.

This patch allows new-style i2c chip drivers to have alias names using
the official kernel aliasing system and MODULE_DEVICE_TABLE(). At this
point, the old i2c driver binding scheme (driver_name/type) is still
supported.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Jochen Friedrich <jochen@scram.de>
Cc: Jon Smirl <jonsmirl@gmail.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
2008-04-29 23:11:39 +02:00
Harvey Harrison 08882d2093 i2c: Replace remaining __FUNCTION__ occurrences
__FUNCTION__ is gcc-specific, use __func__.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-04-22 22:16:47 +02:00
Matthew Wilcox 6188e10d38 Convert asm/semaphore.h users to linux/semaphore.h
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
2008-04-18 22:22:54 -04:00
Randy Dunlap 8c07e46f39 i2c: Fix docbook problem
Sometimes kernel-doc and xmlto conspire to create output that is invalid
and causes problems.  Until I know a real/better solution, change the
source code that causes this.

If anyone has better fixes or can just explain what is happening here,
that would be great.

xmlto: input does not validate (status 1)
mmotm-2008-0314-1449/Documentation/DocBook/kernel-api.xml:71468: parser error : Opening and ending tag mismatch: programlisting line 71464 and para
   </para><para>
          ^
mmotm-2008-0314-1449/Documentation/DocBook/kernel-api.xml:71480: parser error : Opening and ending tag mismatch: para line 71473 and programlisting
</programlisting></informalexample>
                 ^
make[1]: *** [Documentation/DocBook/kernel-api.html] Error 1

Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-03-23 20:28:20 +01:00
Hans Verkuil 50c3304a5e i2c: Keep client->driver and client->dev.driver in sync
Ensure that client->driver is set to NULL if the probe() returns an
error (this keeps client->driver and client->dev.driver in sync).

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-03-12 14:15:00 +01:00
David Brownell e9f1373b64 i2c: Add i2c_new_dummy() utility
This adds a i2c_new_dummy() primitive to help work with devices
that consume multiple addresses, which include many I2C eeproms
and at least one RTC.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:52 +01:00
Jean Delvare 0b987dcd3a i2c: Drop legacy locking in i2c_new_probed_device
It is no longer required to hold adapter->clist_lock to call
i2c_check_addr.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <david-b@pacbell.net>
2008-01-27 18:14:52 +01:00
Jean Delvare 9ddced16bb i2c: Limit locking scope in i2c_detach_client
We only need to hold adapter->clist_lock when we touch the client list.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:51 +01:00
David Brownell 86ec5ec872 i2c-remove-redundant-i2c_client-list.patch
This goes on top of the patch removing most i2c_adapter.clients usage,
updating i2c_attach_client:

 - Don't call device_register() while holding clist_lock.  This
   removes a self-deadlock when on the i2c_driver.probe() path,
   for drivers that need to attach new devices (e.g. dummies).

 - Remove a redundant address check.  The driver model core does
   this as a consequence of guaranteeing unique names.

 - Move the "device registered" diagnostic so that it never lies;
   previously, on error paths it would falsely report success.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:51 +01:00
David Brownell 9b766b814d i2c: Stop using the redundant client list
The i2c_adapter.clients list of i2c_client nodes duplicates driver
model state.  This patch starts removing that list, letting us remove
most existing users of those i2c-core lists.

 * The core I2C code now iterates over the driver model's list instead
   of the i2c-internal one in some places where it's safe:
      - Passing a command/ioctl to each client, a mechanims
        used almost exclusively by DVB adapters;
      - Device address checking, in both i2c-core and i2c-dev.

 * Provide i2c_verify_client() to use with driver model iterators.

 * Flag the relevant i2c_adapter and i2c_client fields as deprecated,
   to help prevent new users from appearing.

For the moment the list needs to stick around, since some issues show
up when deleting devices created by legacy I2C drivers.  (They don't
follow standard driver model rules.  Removing those devices can cause
self-deadlocks.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:51 +01:00
Mike Rapoport cea443a81c i2c: Support i2c_transfer in atomic contexts
Allow i2c_transfer to be called in contexts where sleeping is not allowed.
It is the reponsability of the caller to ensure that the underlying i2c bus
driver will not sleep either.

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:50 +01:00
Jean Delvare caada32afe i2c: Rename main mutex
Rename the main mutex in i2c-core from core_lists to core_lock. This
makes more sense now that the redundant lists are gone.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:49 +01:00
Jean Delvare 026526f5af i2c: Drop redundant i2c_driver.list
i2c_driver.list is superfluous, this list duplicates the one
maintained by the driver core. Drop it.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
2008-01-27 18:14:49 +01:00
Jean Delvare 87c6c22945 i2c: Drop redundant i2c_adapter.list
i2c_adapter.list is superfluous, this list duplicates the one
maintained by the driver core. Drop it.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
2008-01-27 18:14:48 +01:00
Jean Delvare e48d33193d i2c: Change prototypes of refcounting functions
Use more standard prototypes for i2c_use_client() and
i2c_release_client(). The former now returns a pointer to the client,
and the latter no longer returns anything. This matches what all other
subsystems do.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <david-b@pacbell.net>
2008-01-27 18:14:48 +01:00
Jean Delvare bdc511f438 i2c: Use the driver model reference counting
Don't implement our own reference counting mechanism for i2c clients
when the driver model already has one.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <david-b@pacbell.net>
2008-01-27 18:14:48 +01:00
Mark M. Hoffman bfb6df24fa i2c: Constify client address data
This patch allows much of the I2C client address data to move from initdata
into text.
    
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27 18:14:46 +01:00