Commit Graph

341 Commits

Author SHA1 Message Date
Ian Lepore
02d094ff04 Use the new clock_schedule() to arrange for clock_settime() to be called
at the right time to keep the RTC hardware time in sync, instead of using
pause_sbt() to sleep until the right time.
2017-07-31 01:36:51 +00:00
Ian Lepore
2e639013ed Fix AM/PM mode handling. The bits to mask off in the hours register changes
between 12/24 hour mode.  Also fix conversion between 12 and 24 hour mode.
It's not as easy as adding/subtracting 12, because the clock doesn't roll
over 11->0, it rolls over 12->1; 0 isn't a valid hour in AM/PM mode.
2017-07-30 19:58:31 +00:00
Ian Lepore
d0462804d4 Bugfixes and enhancements...
Don't enable the oscillator when it is found to be stopped at init time,
just let the first setting of valid time start it.  But still report a dead
battery if it's stopped at init time.

Don't force the chip into 24hr mode, just cope with whatever mode it is
already in.

Align the RTC clock to top of second when setting it.
2017-07-30 18:46:38 +00:00
Ian Lepore
723a81dec6 Switch from using iic_transfer() to iicdev_readfrom/writeto(), mostly so
that transfers will be done with proper ownership of the bus. No
behavioral changes.
2017-07-30 16:17:06 +00:00
Ian Lepore
e25f1cf5be Fix building this driver on non-FDT platforms. 2017-07-30 00:00:30 +00:00
Ian Lepore
207fe81ea8 Replace the pcf8563 i2c RTC driver with a new nxprtc driver which handles
all the chips in the NXP PCA212x and PCA/PCF85xx series.  In addition to
supporting more chips, this driver uses the countdown timer on the chips as
a fractional seconds counter, giving it a resolution of about 15 milliseconds.
2017-07-29 23:45:57 +00:00
Ian Lepore
34199ee049 Add support for tracking nested calls to iicbus_request/release_bus().
Usually it is sufficient to use iicbus_transfer_excl(), or one of the
higher-level convenience functions that use it, to reserve the bus for the
duration of each register access.  Occasionally it is important that a
series of accesses or read-modify-write operations must be done without any
other intervening access to the device, to prevent corrupting state.

Without support for nested request/release, slave device drivers would have
to stop using high-level convenience functions and resort to working with
arrays of iic_msg structs just for a few operations (often involving
one-time device setup or infrequent configuration changes).

The changes here appear large from a glance at the diff, but in fact they're
nearly trivial, and the large diff is because of changes in indentation and
the re-wrapping of comments caused by that.  One notable change is that
iicbus_release_bus() now ignores the IICBUS_CALLBACK(IIC_RELEASE_BUS) return
value.  The old error handling left the bus in a kind of limbo state where
it was still owned at the iicbus layer, but drivers rarely check the return
of the release call, and it's unclear what they would do to recover from an
error return anyway.  No existing low-level drivers return any kind of error
from IIC_RELEASE_BUS except one EINVAL for "you don't own the bus", to which
the right response is probably to carry on with the process of releasing the
reference to the bus anyway.
2017-07-26 21:06:26 +00:00
Ian Lepore
7ec74c580d Add a pair of convenience routines for doing simple "register" read/writes
on i2c devices, where the "register" can be any length.

Many (perhaps most) common i2c devices are organized as a collection of
(usually 1-byte-wide) registers, and are accessed by first writing a 1-byte
register index/offset number, then by reading or writing the data.
Generally there is an auto-increment feature so the when multiple bytes
are read or written, multiple contiguous registers are accessed.

Most existing slave device drivers allocate an array of iic_msg structures,
fill in all the transfer info, and invoke iicbus_transfer().  These new
functions commonize all that and reduce register access to a simple call
with a few arguments.
2017-07-26 20:40:24 +00:00
Ian Lepore
a14af83085 Fix drivers that assume ticks starts at zero. These drivers all have logic
similar to "if (ticks > localvar+interval) {localvar=ticks; ...}" where
localvar is initialized to zero.  Ticks is initialized to a negative value
since r278230, and that leads to these if statements never being true.
2017-07-06 17:03:22 +00:00
Ian Lepore
930b312319 Add iic_recover_bus(), a helper function that can be used by any i2c driver
which is able to manipulate the clock and data lines directly.

When an i2c bus is hung by a slave device stuck in the middle of a
transaction that didn't complete properly, this function manipulates the
clock and data lines in a sequence known to reliably reset slave devices.
The most common cause of a hung i2c bus is a system reboot in the middle of
an i2c transfer (so it doesnt' happen often, but now there is a way other
than power cycling to recover from it).
2017-06-29 01:50:58 +00:00
Ian Lepore
f03b277259 If an i2c transfer ends due to error, issue a stop on the bus even if the
nostop option is set, if a start was issued.

The nostop option doesn't mean "never issue a stop" it means "only issue
a stop after the last in a series of transfers".  If the transfer ends
due to error, then that was the last transfer in the series, and a stop
is required.

Before this change, any error during a transfer when nostop is set would
effectively hang the bus, because sc->started would never get cleared,
and that caused all future calls to iicbus_start() to return an error
because it looked like the bus was already active.  (Unrelated errors in
handling the nostop option, to be addressed separately, could lead to
this bus hang condition even on busses that don't set the nostop option.)
2017-06-29 00:29:15 +00:00
Luiz Otavio O Souza
aee2c3a86a Always ignore the START and STOP bits whenever the control register is
being overwritten, they are set only bits (cleared by hardware).

Disable the Acknowledge of the controller slave address.  The slave mode is
not supported.

Make sure the interrupt flag bit is being cleared as recommended, add a
delay() _after_ clear the interrupt bit.

Sponsored by:	Rubicon Communications, LLC (Netgate)
2017-06-20 18:38:51 +00:00
Luiz Otavio O Souza
872625501b Make ofw_iicbus attach to twsi I2C controllers.
Add the ofw_bus_get_node() callback in mv_twsi, it is mandatory for the
ofw_iicbus usage.

Sponsored by:	Rubicon Communications, LLC (Netgate)
2017-06-20 18:25:27 +00:00
Pedro F. Giffuni
4d24901ac9 sys/dev: Replace zero with NULL for pointers.
Makes things easier to read, plus architectures may set NULL to something
different than zero.

Found with:	devel/coccinelle
MFC after:	3 weeks
2017-02-20 03:43:12 +00:00
Andriy Gapon
88cc0bb940 iicsmb: SMB_MAXBLOCKSIZE can be used again
The constant was set to the correct value in r308242.
While there, fix iicsmb_bread() to not use a value of an out parameter
'count'.

MFC after:	3 weeks
X-MFC after:	r308242
2016-11-11 15:11:54 +00:00
Andriy Gapon
448897d366 add iic interface to ig4 driver, move isl and cyapa to iicbus
Summary:
The hardware does not expose a classic SMBus interface.
Instead it has a lower level interface that can express a far richer
I2C protocol than what smbus offers.  However, the interface does not
provide a way to explicitly generate the I2C stop and start conditions.
It's only possible to request that the stop condition is generated
after transferring the next byte in either direction.  So, at least
one data byte must always be transferred.
Thus, some I2C sequences are impossible to generate, e.g., an equivalent
of smbus quick command (<start>-<slave addr>-<r/w bit>-<stop>).

At the same time isl(4) and cyapa(4) are moved to iicbus and now they use
iicbus_transfer for communication.  Previously they used smbus_trans()
interface that is not defined by the SMBus protocol and was implemented
only by ig4(4).  In fact, that interface was impossible to implement
for the typical SMBus controllers like intpm(4) or ichsmb(4) where
a type of the SMBus command must be programmed.

The plan is to remove smbus_trans() and all its uses.
As an aside, the smbus_trans() method deviates from the standard,
but perhaps backwards, FreeBSD convention of using 8-bit slave
addresses (shifted by 1 bit to the left).  The method expects
7-bit addresses.

There is a user facing consequence of this change.
A user must now provide device hints for isl and cyapa that specify an iicbus to use
and a slave address on it.
On Chromebook hardware where isl and cyapa devices are commonly found
it is also possible to use a new chromebook_platform(4) driver that
automatically configures isl and cyapa devices.  There is no need to
provide the device hints in that case,

Right now smbus(4) driver tries to discover all slaves on the bus.
That is very dangerous.  Fortunately, the probing code uses smbus_trans()
to do its job, so it is really enabled for ig4 only.
The plan is to remove that auto-probing code and smbus_trans().

Tested by:	grembo, Matthias Apitz <guru@unixarea.de> (w/o
		chromebook_platform)
Discussed with:	grembo, imp
Reviewed by:	wblock (docs)
MFC after:	1 month
Relnotes:	yes
Differential Revision: https://reviews.freebsd.org/D8172
2016-10-30 12:15:33 +00:00
Andriy Gapon
f1519c0157 convert iicsmb to use iicbus_transfer for all operations
Previously the driver used more low level operations like iicbus_start
and iicbus_write.  The problem is that those operations are not
implemented by iicbus(4) and the calls were effectively routed to
a driver to which the bus is attached.
But not all of the controllers implement such low level operations
while all of the drivers are expected to have iicbus_transfer.

While there fix incorrect implementation of iicsmb_bwrite and iicsmb_bread.
The former should send a byte count before the actual bytes, while the
latter should first receive the byte count and then receive the bytes.

I have tested only these commands:
- quick (r/w)
- send byte
- receive byte
- read byte
- write byte

MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D8170
2016-10-13 07:25:18 +00:00
Warner Losh
604d83bdce Implement iicbus_write_ivar and impelemnt the NOSTOP ivar in both read
and write.
2016-10-02 17:36:55 +00:00
Justin Hibbits
4332304f56 Fix ds1307 probing
'compat' can never be NULL, because the compatible check loop ends when
compat->ocd_str is NULL.  This causes ds1307 to attach to any unclaimed i2c
device.
2016-09-24 05:27:12 +00:00
Jared McNeill
8dd48c60a0 Add driver for Silergy Corp. SY8106A buck regulator. 2016-09-05 13:39:54 +00:00
Michal Meloun
895c8b1c39 INTRNG: Rework handling with resources. Partially revert r301453.
- Read interrupt properties at bus enumeration time and store
   it into global mapping table.
 - At bus_activate_resource() time, given mapping entry is resolved and
   connected to real interrupt source. A copy of mapping entry is attached
   to given resource.
 - At bus_setup_intr() time, mapping entry stored in resource is used
   for delivery of requested interrupt configuration.
 - For MSI/MSIX interrupts, mapping entry is created within
   pci_alloc_msi()/pci_alloc_msix() call.
 - For legacy PCI interrupts, mapping entry must be created within
   pcib_route_interrupt() by pcib driver itself.

Reviewed by: nwhitehorn, andrew
Differential Revision: https://reviews.freebsd.org/D7493
2016-08-19 10:52:39 +00:00
Michal Meloun
dac935533b EXTRES: Add OF node as argument to all <foo>_get_by_ofw_<bar>() functions.
In some cases, the driver must handle given properties located in
specific OF subnode. Instead of creating duplicate set of function, add
'node' as argument to existing functions, defaulting it to device OF node.

MFC after: 3 weeks
2016-07-10 18:28:15 +00:00
Svatopluk Kraus
ad5244ece1 INTRNG - change the way how an interrupt mapping data are provided
to the framework in OFW (FDT) case.

This is a follow-up to r301451.

Differential Revision:	https://reviews.freebsd.org/D6634
2016-06-05 16:20:12 +00:00
Emmanuel Vadot
30068a1de9 Add support for interrupts, sensors and GPIO for AXP209 PMIC.
Pressing the PEK (power enable key) will shutdown the board.
Some events are reported to devd via system "PMU" and subsystem
"Battery", "AC" and "USB" such as connected/disconnected.
Some sensors values (power source voltage/current) are reported via
sysctl (dev.axp209_pmu.X.)
It also expose a gpioc node usable in kernel and userland. Only 3 of
the 4 GPIO are exposed (The GPIO3 is different and mostly unused on
boards). Most popular boards uses GPIO1 as a sense pin for OTG power.
Add a dtsi file that adds gpio-controller capability to the device as
upstream doesn't defined it and include it in our custom DTS.

Reviewed by:	jmcneill
Approved by:	cognet (mentor)
Differential Revision:	https://reviews.freebsd.org/D6135
2016-05-26 21:09:07 +00:00
Luiz Otavio O Souza
8ba8cb912b Move the OFW iicbus code to dev/iicbus to stop polluting dev/ofw with
unrelated code.

Discussed with:		nwhitehorn (a long time ago)
2016-05-24 01:33:49 +00:00
Luiz Otavio O Souza
9d6672e13b Fix the deciKelvin to Celsius conversion in kernel.
After r285994, sysctl(8) was fixed to use 273.15 instead of 273.20 as 0C
reference and as result, the temperature read in sysctl(8) now exibits a
+0.1C difference.

This commit fix the kernel references to match the reference value used in
sysctl(8) after r285994.

Sponsored by:	Rubicon Communications (Netgate)
2016-05-22 13:58:32 +00:00
Luiz Otavio O Souza
ad802dc4e3 Remove a couple of extra blank lines. 2016-05-22 04:09:05 +00:00
Jason A. Harmening
523a6367e4 iic_rdwr_data->nmsgs is uint32_t, so limit the allowable number of messages to prevent memory exhaustion and short allocations on 32-bit systems. Since iicrdwr is intended to be a workalike of a Linux i2c-dev call, use the same limit of 42 that Linux uses.
Also check the return value of copyin(9) to prevent unnecessary allocation in the failure case.

Submitted by:	ngie
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D5155
2016-05-20 03:03:04 +00:00
Oleksandr Tymoshenko
0cc376c134 Use OF_prop_free instead of direct call to free(9)
Reviewed by:	jhibbits
2016-05-14 20:06:38 +00:00
Jared McNeill
c9aad79aa9 Add allwinner,sun8i-a83t-i2c to the list of compatible devices. 2016-05-14 18:02:47 +00:00
Pedro F. Giffuni
453130d9bf sys/dev: minor spelling fixes.
Most affect comments, very few have user-visible effects.
2016-05-03 03:41:25 +00:00
Jared McNeill
6a05f063ed Convert Allwinner port to extres clk/hwreset/regulator APIs.
Reviewed by:		andrew, gonzo, Emmanuel Vadot <manu@bidouilliste.com>
Approved by:		gonzo (mentor)
Differential Revision:	https://reviews.freebsd.org/D5752
2016-04-06 23:11:03 +00:00
Justin Hibbits
cc8a3448d9 Add support for the Microchip mcp7941x.
This is compatible with the ds1307, but comparing the mcp7941x datasheet vs the
ds1307 code, appears there is one bit placement difference, so that is now
accounted for.

Relnotes:	yes
2016-04-05 03:27:33 +00:00
Justin Hibbits
f8fd3fb518 Fix the resource_list_print_type() calls to use uintmax_t.
Missed a bunch from r297000.
2016-03-22 22:25:08 +00:00
Justin Hibbits
c47476d7e6 Migrate many bus_alloc_resource() calls to bus_alloc_resource_anywhere().
Most calls to bus_alloc_resource() use "anywhere" as the range, with a given
count.  Migrate these to use the new bus_alloc_resource_anywhere() API.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D5370
2016-02-27 03:38:01 +00:00
Andrew Turner
461a7671c7 Add the start of support for the Allwinner A31 clocks. It only adds
support for the i2c, mmc, and gmac clocks. Further clocks can be added as
needed.

Submitted by:	Emmanuel Vadot <manu@bidouilliste.com>
Reviewed by:	jmcneill
Differential Revision:	https://reviews.freebsd.org/D5339
2016-02-26 13:53:09 +00:00
Andrew Turner
740be1dc58 Fix the spelling of OF_getencprop. It will fix the data correctly for the
endian of the CPU so there is no need to call fdt32_to_cpu.

Sponsored by:	ABT Systems Ltd
2016-02-15 17:14:10 +00:00
Andrew Turner
5f250b53e8 Add support for the Allwinner i2c device. This is similar to the existing
Marvell twsi part, however uses different register locations, as such split
the existing driver into Marvell and Allwinner attachments.

While here clean a few style issues.

Submitted by:	Emmanuel Vadot <manu@bidouilliste.com>
Differential Revision:	https://reviews.freebsd.org/D4846
2016-02-15 15:11:26 +00:00
Andrew Turner
632381ed9d Move the twsi driver source to be under iicbus. It is in a separate
directory as it is expected multiple attachments will be added for the SoC
families that use this hardware.

Sponsored by:	ABT Systems Ltd
2016-02-14 23:51:13 +00:00
Enji Cooper
d52f763c21 Use the correct type for i when iterating over buf to avoid unlikely
negative array indexing in iicrdwr(..)

Differential Revision: https://reviews.freebsd.org/D5132
Obtained from: HardenedBSD
PR: 206754
Reported by: CTurt <cturt@hardenedbsd.org>
Submitted by: Madhi Moktari <mokhi64@gmail.com>
Sponsored by: EMC / Isilon Storage Division
2016-01-30 18:33:23 +00:00
Ian Lepore
b180eb215d Add FDT compatibility to the icee driver.
The FDT bindings for eeprom parts don't include any metadata about the
device other than the part name encoded in the compatible property.
Instead, a driver is required to have a compiled-in table of information
about the various parts (page size, device capacity, addressing scheme).  So
much for FDT being an abstract description of hardware characteristics, huh?

In addition to the FDT-specific changes, this also switches to using the
newer iicbus_transfer_excl() mechanism which holds bus ownership for the
duration of the transfer.  Previously this code held the bus across all
the transfers needed to complete the user's IO request, which could be
up to 128KB of data which might occupy the bus for 10-20 seconds.  Now the
bus will be released and re-aquired between every page-sized (8-256 byte)
transfer, making this driver a much nicer citizen on the i2c bus.

The hint-based configuration mechanism is still in place for non-FDT systems.

Michal Meloun contributed some of the code for these changes.
2015-10-22 01:04:31 +00:00
Ian Lepore
4c1e5d32b2 Add iicbus_transfer_excl(), a helper routine to do an i2c bus transaction
while holding exclusive ownership of the bus.  This is the routine most
slave drivers should use unless they have a need to acquire and hold the
bus across a series of related operations that involves multiple transfers.
2015-10-22 00:54:59 +00:00
Jean-Sébastien Pédron
238b89fcad iicbus: Use device_delete_children() instead of explicit child removal
If the bus is detached and deleted by a call to device_delete_child() or
device_delete_children() on a device higher in the tree, I²C children
were already detached and deleted. So the device_t pointer stored in sc
points to freed memory: we must not try to delete it again.

By using device_delete_children(), we let subr_bus.c figure out if there
are children to take care of.

While here, make sure iicbus_detach() and iicoc_detach() call
device_delete_children() too, to be safe.

Reviewed by:	jhb, imp
Approved by:	jhb, imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D3926
2015-10-20 19:52:59 +00:00
Jean-Sébastien Pédron
b90d6d94c1 iicbus: Remove trailing whitespaces
MFC after:	1 week
2015-10-20 19:47:08 +00:00
Ian Lepore
73440c336d Replace a local sx lock that allowed only one client at a time to access
an eeprom device with iicbus_request/release_bus(), which achieves the
same effect and also keeps other i2c slave drivers from clashing on the bus.
2015-10-10 19:51:00 +00:00
Ian Lepore
b16c6d237b Translate iic hardware layer status values to errno return values. 2015-10-10 02:29:02 +00:00
Ian Lepore
d0b70953fb Add a short name, IIC_INTRWAIT, for the common case (IIC_INTR | IIC_WAIT). 2015-10-10 02:06:07 +00:00
Ian Lepore
4006520bea Fix more cases of iicbus-layer functions that must return IIC_Exxxx values. 2015-10-10 00:12:03 +00:00
Ian Lepore
48e5b4261a Return only IIC_Exxxx status values from iicbus-layer functions. Most of
these functions are thin wrappers around calling the hardware-layer driver,
but some of them do sanity checks and return an error.  Since the hardware
layer can only return IIC_Exxxxx status values, the iicbus helper functions
must also adhere to that, so that drivers at higher layers can assume that
any non-zero status value is an IIC_Exxxx value that provides details about
what happened at the hardware layer (sometimes those details are important
for certain slave drivers).
2015-10-09 23:58:19 +00:00
Ian Lepore
df38292a85 Add iic2errno(), a helper function to translate IIC_Exxxxx status values to
errno values that are at least vaguely equivelent.  Also add a new status
value, IIC_ERESOURCE, to indicate a failure to acquire memory or other
required resources to complete a transaction.

The IIC_Exxxxxx values are supposed to communicate low-level details of the
i2c transaction status between the lowest-layer hardware driver and
higher-layer bus protocol and device drivers for slave devices on the bus.
Most of those slave drivers just return all status values from the lower
layers directly to their callers, resulting in crazy error reporting from a
user's point of view (things like timeouts being reported as "no such
process").  Now there's a helper function to make it easier to start
cleaning up all those drivers.
2015-10-09 23:20:08 +00:00
Ian Lepore
d1e99670ae Use IIC_EBUSBSY and IIC_BUSERR status values consistantly across all drivers.
Make it clearer what each one means in the comments that define them.

IIC_BUSBSY was used in many places to mean two different things, either
"someone else has reserved the bus so you have to wait until they're done"
or "the signal level on the bus was not in the state I expected before/after
issuing some command".

Now IIC_BUSERR is used consistantly to refer to protocol/signaling errors,
and IIC_BUSBSY refers to ownership/reservation of the bus.
2015-10-09 22:49:50 +00:00
Ian Lepore
848a034922 Bugfix: Exit the transfer loop if any read or write operation fails. Also,
perform a stop operation on the bus if there was an error, otherwise the
bus will remain hung forever.  Consistantly use 'if (error != 0)' style in
the function.
2015-10-09 21:34:46 +00:00
Ian Lepore
6f279052a2 Style and whitespace cleanups. The only functional change is removal of
a printf that appears to be left over from development debugging.
2015-10-09 21:27:30 +00:00
Luiz Otavio O Souza
1b53f6c5a3 Remove unnecessary code and make use of generic implementations for
bus_alloc_resource(), bus_release_resource() and bus_set_resource()
(bus_generic_rl_alloc_resource(), bus_generic_rl_release_resource() and
bus_generic_rl_set_resource() respectively).

Do not print the resources for nomatch devices.

Use the inherited method for bus_get_resource_list() on ofw_iicbus.c.

Submitted by:	jhb and Michal Meloun (D2033)
2015-05-10 02:19:27 +00:00
Luiz Otavio O Souza
3bb6bf473f Handle IRQ resources on iicbus and ofw_iicbus.
Based on a patch submitted by Michal Meloun <meloun@miracle.cz>.
2015-05-09 03:05:44 +00:00
Luiz Otavio O Souza
5791e134f7 Replace spaces with tabs, removes an extra blank line.
No functional changes.
2015-05-08 21:51:37 +00:00
Luiz Otavio O Souza
0261c55538 Make the pcf8563 RTC work on FDT systems and on interrupt based i2c
controllers.

Call iicbus_transfer() from the device context and not from the iicbus
context.

I am committing a slightly different patch, so if something break, it is
probably my fault.

PR:		199496
Submitted by:	Juraj Lutter <otis@sk.FreeBSD.org>
2015-04-25 21:43:29 +00:00
Jason A. Harmening
0afebee290 Fix numerous issues in iic(4) and iicbus(4):
--Allow multiple open iic fds by storing addressing state in cdevpriv
--Fix, as much as possible, the baked-in race conditions in the iic
ioctl interface by requesting bus ownership on I2CSTART, releasing it on
I2CSTOP/I2CRSTCARD, and requiring bus ownership by the current cdevpriv
to use the I/O ioctls
--Reduce internal iic buffer size and remove 1K read/write limit by
iteratively calling iicbus_read/iicbus_write
--Eliminate dynamic allocation in I2CWRITE/I2CREAD
--Move handling of I2CRDWR to separate function and improve error handling
--Add new I2CSADDR ioctl to store address in current cdevpriv so that
I2CSTART is not needed for read(2)/write(2) to work
--Redesign iicbus_request_bus() and iicbus_release_bus():
    --iicbus_request_bus() no longer falls through if the bus is already
owned by the requesting device.  Multiple threads on the same device may
want exclusive access.  Also, iicbus_release_bus() was never
device-recursive anyway.
    --Previously, if IICBUS_CALLBACK failed in iicbus_release_bus(), but
the following iicbus_poll() call succeeded, IICBUS_CALLBACK would not be
issued again
    --Do not hold iicbus mtx during IICBUS_CALLBACK call.  There are
several drivers that may sleep in IICBUS_CALLBACK, if IIC_WAIT is passed.
    --Do not loop in iicbus_request_bus if IICBUS_CALLBACK returns
EWOULDBLOCK; instead pass that to the caller so that it can retry if so
desired.

Differential Revision:	https://reviews.freebsd.org/D2140
Reviewed by:	imp, jhb, loos
Approved by:	kib (mentor)
2015-04-21 11:50:31 +00:00
Luiz Otavio O Souza
d7eb38c008 Add a driver for the Dallas/Maxim DS1307, another common i2c RTC.
Many thanks to ian who gently provided me the DS1307 breakout board.

Tested on:		Raspberry pi
Differential Revision:	https://reviews.freebsd.org/D2022
Reviewed by:		rpaulo
2015-03-20 19:51:24 +00:00
Luiz Otavio O Souza
4a5fa7b2e3 Fix off-by-one bugs.
Spotted by:	rpaulo (on another review)
2015-03-10 14:55:05 +00:00
Luiz Otavio O Souza
befcc3e26b Add a driver for the Maxim DS3231 a low-cost, extremely accurate (+-2PPM)
I2C real-time clock (RTC).

The DS3231 has an integrated temperature-compensated crystal oscillator
(TXCO) and crystal.

DS3231 has a temperature sensor, an independent 32kHz output (which can be
turned on and off by the driver) and another output that can be used as
interrupt for alarms or as a second square-wave output, which frequency and
operation mode can be set by driver sysctl(8) knobs.

Differential Revision:	https://reviews.freebsd.org/D1016
Reviewed by:	ian, rpaulo
Tested on:	Raspberry pi model B
2015-02-28 19:02:44 +00:00
Luiz Otavio O Souza
91e38bd663 Replace hardcoded sizes by sizeof() and nitems().
Set all the sysctls as CTLFLAG_MPSAFE.
2015-02-17 20:29:42 +00:00
Luiz Otavio O Souza
7628ccf06e Fix the display of negative temperatures.
Fix the setting of TOS (overtemperature shutdown) and THYST (hysteresis
temperature).
2015-02-17 20:08:40 +00:00
Justin Hibbits
59bb84753c Use proper signed types. The ADT746x uses signed 8-bit numbers for the
temperature.

MFC after:	2 weeks
2015-01-18 07:08:06 +00:00
Ian Lepore
844aff82a6 Allow i2c bus speed to be configured via hints, FDT data, and sysctl.
The current support for controlling i2c bus speed is an inconsistant mess.
There are 4 symbolic speed values defined, UNKNOWN, SLOW, FAST, FASTEST.
It seems to be universally assumed that SLOW means the standard 100KHz
rate from the original spec.  Nothing ever calls iicbus_reset() with a
speed of FAST, although some drivers would treat it as the 400KHz standard
speed.  Mostly iicbus_reset() is called with the speed set to UNKNOWN or
FASTEST, and there's really no telling what any individual driver will do
with those.

The speed of an i2c bus is limited by the speed of the slowest device on
the bus.  This means that generally the bus speed needs to be configured
based on the board/system and the components within it.  Historically for
i2c we've configured with device hints.  Newer systems use FDT data and it
documents a clock-frequency property for i2c busses.  Hobbyists and
developers are likely to want on the fly changes.  These changes provide
all 3 methods, but do not require any existing drivers to change to use
the new facilities.

This adds an iicbus method, iicbus_get_frequency(dev, speed) that gets the
frequency for the requested symbolic speed.  If the symbolic speed is SLOW
or if there is no speed configured for the bus, the returned value is
100KHz, always.  Otherwise, if bus speed is configured by hints, fdt,
tunable, or sysctl, that speed is returned.  It also adds a helper
function, iicbus_init_frequency() that any bus driver subclassed from
iicbus can initialize the frequency from some other source of info.

Initial driver implementations are provided for Freescale and TI.

Differential Revision:        https://reviews.freebsd.org/D1174
PR:		195009
2014-11-18 01:54:31 +00:00
Konstantin Belousov
9247911a58 Add a method to iicbus to request IIC_M_NOSTOP behaviour for multibyte
transfers to be default.  It simplifies porting code which assumes
such settings.

Discussed with:	avg, llos, nwhitehorn
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-10-27 07:51:26 +00:00
Justin Hibbits
e9152038d3 Move the adm1030 driver to the proper location, and rename it.
For compatibility, 'device windtunnel' is still supported, but one should use
'device adm1030' instead, and this has been updated in GENERIC and NOTES.
2014-10-16 01:32:22 +00:00
Justin Hibbits
6ab4d70393 Check error return from reading integer part of temperature.
There's a very remote, but possible, chance that the integer part read will
fail, but the fraction read succeeds, at which point the reported temperature is
invalid.

Reported by: Matthew Rezny
MFC after:	3 weeks
2014-10-12 23:48:55 +00:00
Gleb Smirnoff
c8dfaf382f Mechanically convert to if_inc_counter(). 2014-09-19 03:51:26 +00:00
Rui Paulo
efce3748f3 Revert r268543.
We should probably fix sys/gpio.h instead.
2014-07-12 06:23:42 +00:00
Rui Paulo
bd08cbb81a Move iic.h to sys/ so that it's automatically installed in /usr/include/sys.
This lets us call iic(4) ioctls without needing the kernel source code
and follows the same model of GPIO.

MFC after:	3 weeks
2014-07-12 01:04:10 +00:00
Luiz Otavio O Souza
34aa2211e7 Ignore IIC_ENOADDR from iicbus_reset() as it only means we have a
master-only controller.

This fixes the iic bus scan with i2c(8) (on supported controllers).

Tested with gpioiic(4).
2014-05-31 14:38:05 +00:00
Luiz Otavio O Souza
dd75f2c5eb Add the lm75 i2c digital temperature sensor driver.
This driver supports the low and high precision models (9 and 11 bits) and
it will auto-detect the both variants.

The driver expose the temperature registers (actual temperature, shutdown
and hysteresys temperature) and also the configuration register.

It was tested on FDT systems: RPi, BBB and on non-FDT systems: AR71xx, with
both, hardware i2c controllers (when available) and gpioiic(4).

This provides a simple and cheap way for verifying the i2c bus on embedded
systems.
2014-05-10 12:19:02 +00:00
Luiz Otavio O Souza
bf17755477 Allow the use of OFW I2C bus together with iicbb(4) on OFW-based systems.
This change makes ofw_iicbus attach to iicbb(4) controllers in addition to
the already supported i2c host bridges (iichb).

On iicbb(4) allow the direct access of the OFW parent node by its children,
so they can be directly attached to iicbb(4) node on the DTS without the
need of describing the i2c bus.

Approved by:	adrian (mentor, implicit)
2014-02-13 18:22:49 +00:00
Justin Hibbits
c017acc769 Add driver for the ADT7460/ADT7467 fan controller found in later PowerBooks
and iBooks.  Original work by andreast.

MFC after:	1 month
2014-02-03 01:22:50 +00:00
Justin Hibbits
e17bec9172 Make more unsigned ints signed.
Found by:	clang (powerpc64)
MFC after:	1 week
2013-12-07 22:25:07 +00:00
Justin Hibbits
8991c54091 Fix some integer signs. These unsigned integers should all be signed.
Found by:	clang (powerpc64)
2013-12-07 19:55:34 +00:00
Gleb Smirnoff
76039bc84f The r48589 promised to remove implicit inclusion of if_var.h soon. Prepare
to this event, adding if_var.h to files that do need it. Also, include
all includes that now are included due to implicit pollution via if_var.h

Sponsored by:	Netflix
Sponsored by:	Nginx, Inc.
2013-10-26 17:58:36 +00:00
Gleb Smirnoff
540b1a7238 Clean up SIOCSIFDSTADDR usage from ifnet drivers. The ioctl itself is
extremely outdated, and I doubt that it was ever used for ifnet drivers.
It was used for AF_INET sockets in pre-FreeBSD time.

Approved by:	re (hrs)
Sponsored by:	Nginx, Inc.
2013-09-11 09:19:44 +00:00
Gleb Smirnoff
47e8d432d5 Add const qualifier to the dst parameter of the ifnet if_output method. 2013-04-26 12:50:32 +00:00
Sofian Brabez
61bfd86762 Use DEVMETHOD_END macro defined in sys/bus.h instead of {0, 0} sentinel on device_method_t arrays
Reviewed by:	cognet
Approved by:	cognet
2013-01-30 18:01:20 +00:00
Kevin Lo
72794e9e2c Check the return value of uiomove(9). 2012-11-13 05:58:52 +00:00
Marius Strobl
f9e26776a6 It turns out that as documented, PCF8563_R_SECOND_VL (i.e. battery low)
doesn't automatically clear when VDD rises above Vlow again and needs to be
cleared manually. However, apparently this needs all of the time registers
to be set, i.e. pcf8563_settime(), and not just PCF8563_R_SECOND in order
for PCF8563_R_SECOND_VL to stick. Thus, we just issue a warning during
pcf8563_attach() rather than failing with ENXIO in case it is set.

MFC after:	3 days
2012-10-18 10:29:16 +00:00
Kevin Lo
374c6ff93a Remove unused variables. 2012-09-29 16:15:27 +00:00
Hiroki Sato
f8e8af9cf2 Add s35390a_rtc(4) driver for Seiko Instruments S-35390A RTC.
Submitted by:	Yusuke Tanaka
2012-08-21 17:31:10 +00:00
Andreas Tobler
a894f6a0d4 Add a new temperature driver for certain PowerMacs. Found here on my Quad G5. 2012-08-19 19:37:14 +00:00
Andreas Tobler
58af3406d2 Unify the sysctl description with the other PowerMac temperature drivers. 2012-08-19 19:34:10 +00:00
Andreas Tobler
3b29957407 Avoid using the degree symbol. Looks ugly on the console. 2012-08-19 19:32:38 +00:00
Andreas Tobler
11e31cd29a Do the ADC init only at startup and not during every sensor read call.
This reduces the number of interrupts.
2012-08-19 19:31:36 +00:00
Marcel Moolenaar
d08dfc3305 Don't include MIPS machine headers. There's no need for it. 2012-05-19 17:42:11 +00:00
Marius Strobl
34f4e555b5 Add a driver for the NXP (Philips) PCF8563 RTC.
Obtained from:	NetBSD (pcf8563reg.h)
2012-04-13 23:07:32 +00:00
Jayachandran C.
1ab68cbb08 Driver for OpenCores I2C controller.
Add a Simple polled driver iicoc for the OpenCores I2C controller. This
is used in Netlogic XLP processors.

Submitted by:	Sreekanth M. S. (kanthms at netlogicmicro com)
2012-03-27 10:44:32 +00:00
Jayachandran C.
1513a6ff90 Move driver for DS1374 RTC to sys/dev/iicbus
The earlier version of the driver is sys/mips/rmi/dev/iic/ds1374u.c
Convert all references to ds1374u to ds1374, and use DEVMETHOD_END.
Also update the license header as Netlogic is now Broadcom.
2012-03-27 09:48:18 +00:00
Andreas Tobler
10520ef88f Fix typo. 2012-03-02 18:18:14 +00:00
Alexander Kabaev
d4280a0fab Provide pre/post transfer method callbacks for icbbb
clients.

These are helful when making certain drivers work on both Linux
and FreeBSD without changing the code flow too much.

Reviewed by: kib, wlosh
MFC after: 1 month
2012-03-01 20:58:20 +00:00
Adrian Chadd
fd06fec782 IIC bitbang changes - prepare to make the bit delay configurable; debug print changes.
* Right now the delay is hard coded at 10uS. This is a bit long when doing lots
  of periodic i2c transactions. So create a 'udelay' parameter and initialise it
  to 10. This can be tuned later.

* Add a newline after a transaction finishes, so the debugging output isn't so
  horrible.
2011-12-20 02:49:01 +00:00
Adrian Chadd
9844b3b3ab Allow the i2c node requirements to be slightly relaxed.
These realtek switch PHYs speak a variant of i2c with some slightly
modified handling.

From the submitter, slightly modified now that some further digging
has been done:

  The I2C framework makes a assumption that the read/not-write bit of the first
  byte (the address) indicates whether reads or writes are to follow.

  The RTL8366 family uses the bus: after sending the address+read/not-write byte,
  two register address bytes are sent, then the 16-bit register value is sent
  or received.  While the register write access can be performed as a 4-byte
  write, the read access requires the read bit to be set, but the first two bytes
  for the register address then need to be transmitted.

This patch maintains the i2c protocol behaviour but allows it to be relaxed
(for these kinds of switch PHYs, and whatever else Realtek may do with this
almost-but-not-quite i2c bus) - by setting the "strict" hint to 0.
The "strict" hint defaults to 1.

Submitted by:	Stefan Bethke <stb@lassitu.de>
2011-12-04 11:55:33 +00:00
Marius Strobl
4b7ec27007 - There's no need to overwrite the default device method with the default
one. Interestingly, these are actually the default for quite some time
  (bus_generic_driver_added(9) since r52045 and bus_generic_print_child(9)
  since r52045) but even recently added device drivers do this unnecessarily.
  Discussed with: jhb, marcel
- While at it, use DEVMETHOD_END.
  Discussed with: jhb
- Also while at it, use __FBSDID.
2011-11-22 21:28:20 +00:00
Ed Schouten
d745c852be Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.
This means that their use is restricted to a single C file.
2011-11-07 06:44:47 +00:00
Christian Brueffer
04c4548981 Revert r226398 and instead move the allocation of usrbufs after the error check.
Suggested by:	pjd
MFC after:	1 week
2011-10-16 17:38:20 +00:00
Christian Brueffer
0ad684e7b4 Properly free resources in an error case.
CID:		4203
Found with:	Coverity Prevent(tm)
MFC after:	1 week
2011-10-15 15:57:55 +00:00
Bjoern A. Zeeb
a34c6aeb85 Tag mbufs of all incoming frames or packets with the interface's FIB
setting (either default or if supported as set by SIOCSIFFIB, e.g.
from ifconfig).

Submitted by:	Alexander V. Chernikov (melifaro ipfw.ru)
Reviewed by:	julian
MFC after:	2 weeks
2011-07-03 16:08:38 +00:00
Kevin Lo
ee6eac62f7 Remove duplicate header includes 2011-06-28 08:36:48 +00:00
Andreas Tobler
d91c258074 - Improve error handling.
- Add retry loops in the i2c read/write functions.
- Combied the ADC channel selection and readout of the value into
  one iicbus_transfer to avoid possible races.

Reviewed by: nwhitehorn
2011-06-08 16:00:30 +00:00
Andreas Tobler
1b49664037 - Improve error handling.
- Add a retry loop for the i2c sensor reading.
- Check on busy status of the chip and on invalid values.
- Fix a typo in a comment.
- Replace the constant 2732 with the ZERO_C_TO_K macro.

Approved by:	nwhitehorn (mentor)
2011-06-04 09:23:54 +00:00
Andreas Tobler
7cced077f8 Replace the FCU_ZERO_C_TO_K with the ZERO_C_TO_K from powermac_thermal.h.
Approved by:	nwhitehorn (mentor)
2011-06-04 09:19:53 +00:00
Andreas Tobler
aa7e99afbd - Improve error handling.
- Add a retry loop for the i2c sensor reading.
- Update the sensor handling for sensors which do not have a location
entry. [1]

Submitted by: [1] Justin Hibbits.
Approved by:	nwhitehorn (mentor)
2011-06-03 18:58:32 +00:00
Nathan Whitehorn
6b9a12b391 Move the celsius-to-kelvin conversion to a place that powermac_thermal can
see it as well.
2011-05-29 19:53:46 +00:00
Nathan Whitehorn
815d7d92c1 Update the I2C-based temperature/fan drivers to connect to the Powermac
thermal control module. This provides automatic fan management on all G5
PowerMacs and Xserves.
2011-05-29 18:35:57 +00:00
Andreas Tobler
d188174a4f Add a new driver, the ad7417, to read temperatures and voltages on some
PowerMac's.

Approved by:	nwhitehorn (mentor)
2011-05-29 14:25:42 +00:00
Andreas Tobler
14be64618e There are PowerMacs which do not have a hwsensor-location property
for this sensor. Instead of leaving this location empty we use here
the default name 'sensor'.

Submitted by: Justin Hibbits <chmeeedalf at gmail dot com>
Approved by: nwhitehorn (mentor)
2011-01-18 21:47:30 +00:00
Andreas Tobler
b919d343a9 Remove unused variable. Spotted by a cppcheck
(devel/cppcheck, http://sourceforge.net/projects/cppcheck) run.

Approved by: nwhitehorn (mentor)
2011-01-15 19:16:56 +00:00
Andreas Tobler
7cea3d952b On the Xserve G5 we find the LM75 instead of the DS1775. The core
functionality is the same, a difference is that the DS1775 has a better
precision than the LM75. But we do not use it in our setup. Make the
LM75 work the same as the DS1775.

Fix a typo in device_set_desc.

Tested by: Paul Mather <paul at gromit dlib vt edu>

Approved by:	nwhitehorn (mentor)
2010-12-10 20:27:50 +00:00
Nathan Whitehorn
134a9563c7 Provide support for IIC_M_NOSTOP/IIC_M_NOSTART for bit-banging and
otherwise low-level controllers.

Reviewed by:	thompsa
2010-11-08 19:53:16 +00:00
Andreas Tobler
da89fa28c6 Add three new drivers for fan control and temperature reading on the
PowerMac7,2.

- The fcu driver lets us read and write the fan RPMs for all fans in the
  PowerMac7,2. This driver is PowerMac specific.
- The ds1775 is a driver to read the temperature for the drive bay sensor.
- The max6690 is another driver to read temperatures. Here it is used to
  read the inlet, the backside and the U3 heatsink temperature.

An additional driver, the ad7417, will follow later.

Thanks to nwhitehorn for guiding me through this driver development.

Approved by:	nwhitehorn (mentor)
2010-10-15 20:08:16 +00:00
Andriy Gapon
3d844eddb7 bus_add_child: change type of order parameter to u_int
This reflects actual type used to store and compare child device orders.
Change is mostly done via a Coccinelle (soon to be devel/coccinelle)
semantic patch.
Verified by LINT+modules kernel builds.

Followup to:	r212213
MFC after:	10 days
2010-09-10 11:19:03 +00:00
Joel Dahl
7f22a6d334 Fix typo in comment. 2010-08-07 08:31:32 +00:00
Nathan Whitehorn
517524ec87 Fix iicbus_get_addr() on 64-bit big-endian systems. The bus accessor
passes a uintptr_t, not a uint32_t.
2010-07-08 14:19:52 +00:00
Nathan Whitehorn
9f220e4d78 Revert changes accidentally committed as part of r209298. 2010-06-18 14:20:54 +00:00
Nathan Whitehorn
eaef5f0af8 Provide for multiple, cascaded PICs on PowerPC systems, and extend the
OFW interrupt map interface to also return the device's interrupt parent.

MFC after:	8.1-RELEASE
2010-06-18 14:06:27 +00:00
Nathan Whitehorn
fed318596c Add two new flags (IIC_M_NOSTOP and IIC_M_NOSTART) to struct iic_msg to
allow consumers of iicbus_transfer() to send messages with repeated starts.

Reviewed by:	imp
2010-06-05 17:48:26 +00:00
Maxim Sobolev
e50d35e6c6 Add new tunable 'net.link.ifqmaxlen' to set default send interface
queue length. The default value for this parameter is 50, which is
quite low for many of today's uses and the only way to modify this
parameter right now is to edit if_var.h file. Also add read-only
sysctl with the same name, so that it's possible to retrieve the
current value.

MFC after:	1 month
2010-05-03 07:32:50 +00:00
Stanislav Sedov
97958cafc8 - Rename ds1672 and ds133x devices to "ds1672_rtc" and "ds133x_rtc"
respectivly. This will allow one to have a kernel with both devices
  present and use it for multiple boards with different types of RTC
  sitting on a bus.

Discussed with:	imp
2009-04-21 22:48:12 +00:00
Stanislav Sedov
50aababbfb - Give a warning and start the oscillator if it was not previously
runned.
- Rename ds1672 -> rtc to follow the other drivers.
- Refactor/simplify the code a bit.

MFC after:	2 weeks
2009-04-20 15:47:06 +00:00
Kip Macy
279aa3d419 Change if_output to take a struct route as its fourth argument in order
to allow passing a cached struct llentry * down to L2

Reviewed by:	rwatson
2009-04-16 20:30:28 +00:00
Warner Losh
b23193a559 Fix iicbus_intr, iicbus_write and device_read_ivar prototypes... 2009-02-10 22:50:23 +00:00
Rafal Jaworowski
1aef11be0e Teach iic(4) the 'repeated start' I2C condition. This will be used by the
upcoming i2c(8) diag utility.

Reviewed by:	bms, stas
Obtained from:	Semihalf
2009-01-26 13:53:39 +00:00
Nathan Whitehorn
f5a78b2f7e Change the probe priority for PCI and I2C generic bus modules from
numerical constants to BUS_PROBE_GENERIC.

Suggested by:	jhb
2009-01-20 00:05:43 +00:00
Nathan Whitehorn
ee9db219df Revert revision 186833 and try a different strategy to allow this device to
work when the bus attaches its own children. Instead of hardcoding a unit
number and returning BUS_PROBE_NOWILDCARD, which will break multiple iicbus
systems, check in the probe routine whether the device address is 0. Real
I2C devices will never have this address, but devices added with
BUS_ADD_CHILD() will.

Requested by:	jhb
Reviewed by:	jhb
2009-01-15 23:14:59 +00:00
Nathan Whitehorn
3bb481ffb0 Import an Open Firmware I2C bus module. This attaches firmware device tree
indicated I2C devices, and provides an ofw_bus interface for driver probing.
This should be MI, but is currently provided only on PowerPC due to lack of
sparc64 hardware with an I2C controller.

Discussed on:	freebsd-arch
2009-01-15 02:46:43 +00:00
Nathan Whitehorn
789c4b9d08 Change the way I2C bus attachment works to allow firmware-assisted bus
subclasses as are available with PCI. Changes I2C device drivers without
real probe logic to return BUS_PROBE_NOWILDWARD to avoid interference with
firmware bus enumeration, and reduces the probe priority of the iicbus
base driver to allow subclass attachment at higher priority.

Discussed on:	freebsd-arch
2009-01-06 17:23:37 +00:00
Rafal Jaworowski
53917bdbd9 Streamline #include sections in ds133x and ds1672 drivers. This unbreaks the
LINT build.
2008-09-08 15:49:07 +00:00
Rafal Jaworowski
286fa44565 ds133x: Introduce device_identify method; update NOTES.
Obtained from:	Semihalf
2008-09-08 10:40:48 +00:00
Warner Losh
da02572e7f Handle errors from device_get_chidlren.
Free child list when there's more children than we expected.
2008-08-23 07:38:00 +00:00
Ed Schouten
94b9bedcb9 Fix compilation of arm's AVILA.
Compilation of the AVILA kernel failed because of two reasons:

- It needed curthread, which is defined through <sys/pcpu.h>.

- It still referred the softc's sc_mtx field, which has been replaced by
  sc_lock three weeks ago.

To solve the first problem, I decided to include <sys/pcpu.h> in
<sys/sx.h>, which also seems to be done by <sys/mutex.h> and
<sys/rwlock.h>. Those header files also require curthread.

Approved by:	jhb
2008-08-13 09:20:52 +00:00
Rafal Jaworowski
c85885020b Rework Dallas Semiconductor RTC support.
- Extend the DS1339 driver to recognize more chips in the family:
  DS1337, DS1338, DS1339 are now supported
- Provide run-time chip detection

Reviewed, tested by:	stas
Obtained from:		Piotr Ziecik kosmo ! semihalf dot com
2008-08-11 19:33:58 +00:00
Rafal Jaworowski
9884d99e9b Rename ds1339 -> ds133x to better fit the upcoming driver extensions. 2008-08-11 19:26:55 +00:00
Stanislav Sedov
4bdfea0f50 - Reflect the iicbus infrastructure changes.
Approved by:	raj
2008-08-05 08:38:33 +00:00
Stanislav Sedov
ea73ef7478 - Reflect changes in iic infrastructure. 2008-08-05 08:20:58 +00:00
John Baldwin
225f9723dc Lock the consumers of the iicbus(4) infrastructure:
- ad7418(4) uses an sx lock instead of a mtx since the iicbus(4) stuff it
  calls can sleep (request_bus()).  Also, I expanded the locking slightly
  to serialize writes to data stored in the softc.
- Similarly, the icee(4) driver now uses an sx lock instead of a mutex.
  I also removed the pointless OPENED flag and flags field from the softc.
- The locking for the ic(4) driver was a bit trickier:
  - Add a mutex to the softc to protect softc data.
  - The driver uses malloc'd buffers that are the size of the interface
    MTU to send and receive packets.  Previously, these were allocated
    every time the interface was brought up and anytime the MTU was
    changed, with various races that could result in memory leaks.  I
    changed this to be a bit simpler and more like other NIC drivers in
    that we allocate buffers during attach for the default MTU size and
    only reallocate them on MTU changes.  The reallocation procedure
    goes to some lengths with various flags to not replace either the
    the receive or transmit buffers while the driver is busy receiving
    or transmitting a packet.
  - Store the device_t of the driver in the softc instead of detours into
    new-bus using if_dunit from the ifnet and an even more bizarre detour
    to get the softc instead of using if_softc.
  - Drop the driver mutex when invoking netisr_dispatch() to pass the
    packet up to IP.
  - Use if_printf().
2008-08-04 21:14:24 +00:00
John Baldwin
313f8941e1 Add locking to the core iicbus(4) drivers:
- Add an sx lock to the iic(4) driver to serialize open(), close(), read(),
  and write and to protect sc_addr and sc_count in the softc.
- Use cdev->si_drv1 instead of using the minor number of the cdev to
  lookup the softc via newbus in iic(4).
- Store the device_t in the softc to avoid a similar detour via minor
  numbers in iic(4).
- Only add at most one instance of iic(4) and iicsmb(4) to each iicbus(4)
  instance, and do it in the child driver.
- Add a mutex to the iicbus(4) softc to synchronize the request/release bus
  stuff.
- Use __BUS_ACCESSOR() for IICBUS_ACCESSOR() instead of rolling our own.
- Add a mutex to the iicsmb(4) softc to protect softc state updated in the
  interrupt handler.
- Remove Giant from all the smbus methods in iicsmb(4) now that all the
  iicbus(4) backend is locked.
2008-08-04 21:03:06 +00:00
John Baldwin
13e3657b7b Add locking to the various iicbus(4) bridge drivers:
- Just grab Giant in the ixp425_iic(4) driver since this driver uses
  a shared address/data register window pair to access the actual
  I2C registers.  None of the other ixp425 drivers lock access to these
  shared address/data registers yet and that would need to be done before
  this could use any meaningful locking.
- Add locking to the interrupt handler and 'iicbus_reset' methods of the
  at91_twi(4) driver.
- Add locking to the pcf(4) driver.  Other pcf(4) fixes include:
  - Don't needlessly zero the softc.
  - Use bus_foo rather than bus_space_foo and remove bus space tag and
    handle from softc.
- The lpbb(4) driver just grabs Giant for now.  This will be refined later
  when ppbus(4) is locked.
- As was done with smbus earlier, move the DRIVER_MODULE() lines to match
  the bus driver (either iicbus or iicbb) to the bridge driver into the
  bridge drivers.

Tested by:	sam (arm/ixp425)
2008-08-04 20:46:15 +00:00
Stanislav Sedov
8e3b2aab49 - Add driver for Dallas Semiconductor DS1339 RTC sitting
on I2C bus.

Reviewed by:	raj
Approved by:	imp
MFC after:	2 week
2008-07-25 19:34:44 +00:00
John Baldwin
0df8f0815a Explicitly lock Giant in smbus_if methods in the bktr_i2c and iicsmb
drivers for now.  This can be replaced with driver locks when these
drivers are locked.
2008-06-06 18:40:38 +00:00
Warner Losh
1a13e01f7f Don't use spinlocks here. The iicbus transactions can take a long
time, and this prevents interrupts (say for Hz/hardclock) from
happening.  Time stands still during the transfers...
2007-04-17 05:48:35 +00:00
Warner Losh
66c7612a8d New device: icee. Generic i2c eeprom driver. 2007-03-23 23:10:35 +00:00
Warner Losh
d4fa68402e MFp4: Make the iicbus fully hinted. We no longer automatically add
some devices (and not others).  To get instances onto the iicbus, one
now needs hints or an identify routine.  We also do not probe the bus
for devices because many iic devices cannot be safely probed (and when
they can, the probe order turns out to be somewhat difficult to get
right).

# I'm not 100% sure that the iicsmb removal is right.  Please contact me if
# this causes difficulty.
2007-03-23 23:08:28 +00:00
Warner Losh
99a1402117 MFp4: Make iicbus_trasnfer_gen suitable for bridge drivers. Use it in the
bitbang bridge.
2007-03-23 23:03:54 +00:00
Warner Losh
ee952d0ef6 MFp4: Create an ivar for each iic device on the iicbus. This ivar
holds the device's address.
2007-03-23 23:02:33 +00:00
Warner Losh
07defc61a9 const poison
submitted by: john wehle
2006-12-05 06:19:36 +00:00