mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-24 00:37:13 +07:00
c55cc97a25
A few bits for the counters subsystem mixed in here as well. There are some late breaking fixes as well, which aren't so urgent they can't wait for the merge window. New Device Support * adf4371 - New driver + bindings. - Support the adf4372 PLL. Mostly ID and bindings. * ad8366 (note includes rework of driver needed to allow support for these). - Support the ADL5240 variable gain amplifier (VGA). - Support the ADA4961 digital gain amplifier (DGA). * dps310 - New driver, in several parts from different authors for this temp and pressure sensor. - Includes errata workaround for a temperature reading issue. * stk3310 - Support the stk3335, mostly ID. Features and cleanups * core - drop error handling on debugfs registration. - harden by making sure we don't overrun iio_chan_info_postfix. * docs - convert remaining docs to rst. At somepoint we'll fit these few into the main IIO docs. - improve sampling_frequency_available docs but explaining the range form. * ad_sigma_delta - Drop a pointless goto. * ad2s1210 - Drop pointless platform data null check seeing as we don't actually use platform data anymore. * ad7124 - Relax limitation on channel numbers to allow pseudo different channels. - Support control of whether the input is buffered via DT. - Use dynamic allocation for channel configuration to make it easier to support new devices. - YAML binding conversion. * ad7150 - Comment tidy up. - Consistent and simple if (ret) handling of i2c errors. - FIELD_GET and GENMASK. - Ternary rather than !!(condition) for readability. - Use macros to avoid repetition of channel definitions. * ad7606 - Add software channel config (rather that pin controlled) - Refactor to simplify addition of new part in future. * ad7746 - of_deivce_id table. * ad7780 - MAINTAINERS entry - YAML DT bindings. * ad8366 - Stop using core mlock in favour of well scoped local lock. - SPDX + copyright date update. * ad9834 - of_device_id table * adf4371 - Add support for output stage muting before lock on has occured. * adis library - MAINTAINERS entry to reflect that this now Alexandru's problem ;) * adis162xx: - Fix a slightly incorrect set of comments and print statements on minimum supported voltage. * adis16203 - of_device_id table. * adis16240 - Add of_device_id table (in two parts as first patch only used it for MODULE_DEVICE_TABLE.) * adt7316-spi - of_device_id table * adxl372 - YAML DT binding conversion. - Cleanup use of buffer callback functions (precursor to core rework). * bh1710 - Simplify getting the i2c adapter from the client. * dht11 - Mote to newer GPIO consumer interface. * kxcjk-1013.c - Add binding for sensor in display of some ultrabooks after userspace tools updated for it not be a problem to report two similar sensors. * imx7d - drop unused variables. - white space - define instead of variable for clock frequency that is fixed. - drop pointless error message. * messon_saradc - SPDX * sps30 - MAINTAINERS entry - YAML binding conversion. * st_accel - Tidy up ordering in various buffer related callbacks. This is part of a long running effort to simplify the core code. * stm32-dfsdm: - Manage the resolution cleanly in triggerd modes. - Add fast mode support which allows more flexible filter choices. - Add a comment on the reason for a 16 bit record when technically not 'required'. * st_lsm6dsx - Embed device name in the sensor_settings struct as i3c doesn't have a convenient name field to use for this. * xilinx-adc - Relax constraints on supported platforms to reflect that this can used with FPGAs on PCIe cards and hence many architectures. * counters/ftm-quaddec - Fix some formatting io MODULE_AUTHOR - MAINTAINERS entry Fixes * tools - fix incorrect handling of 32 bit channels. * sca3000 - Potential endian bug that is unlikely to bite anyone (be64 host seems unlikely for this old part). * stm32-adc - Add vdda-supply. On some boards it needs to be turned on to supply the ADC. DT bindings included. * stm32-dfsdm - Fix output resolution to work with filter orders other than 3. - Fix output datatype as it's signed and previously claimed not to be. -----BEGIN PGP SIGNATURE----- iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAl0VHIkRHGppYzIzQGtl cm5lbC5vcmcACgkQVIU0mcT0FojyxhAAgrLRy2wlHjQCAh0S6J22LKs02uPX1qvY nm1aI/av2DGcMCV2NF6J1sW2Mocvtt5a79/1f/wRqDzOHBrTpFr0Q0Ngwijv9bzc fv6NwfHlWolmXynKx8wK4b6Sa3KVCkltojEVpEVbhkuMkafSQ+pQzYF1Uf7enOrX j3Gq6NYaCks4YtFZsBphgzo3DC0mh7CfunlPiOdVcgcg4Pj/KZY9QCX86fJx972x YI3BRFHnDSMDOxOTjeqeKvMiqU2zLPlqLSEOCUw2XCrh6HI9qFiU+LVsYx6SP0tx aJ2q+qYc9raOTANHk7O2JZYWv/52JXvtKcFSLiuQdABjaAI20xEr1QAZYVYUiXmg dFH6lBsWvQyAy5F/SyZ5tavZvTfGsNDB5LhlpEggeO2W6cIIL4CLfHimB2EcxFSH utqEA72HQZosEUKut1jbmG6iYMiRnHS72pLOqkJ6HC/2/pZfoEWlEH9x/S3xbBsW 918ISs9852VwjebQwck96+Dh0LwiKOl8Aii5ONzfNObJB6/JbULPoKKArsMdENQA mqDXLOMz6GspY3JgiVDCXAwg2x2Ht/ictR6svRJtOTLiBU2Iybpm/HRkPePhoePF HLw8fhwE+mOSWr22KhzjUJBHEAkoejo/14XOgKSTkO9V6amLlOWRDV3uK2PksmdI 7DQyYhX9Tos= =a3vh -----END PGP SIGNATURE----- Merge tag 'iio-for-5.3b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next Jonathan writes: Second set of IIO device support, features, cleanups and minor fixes for 5.3. A few bits for the counters subsystem mixed in here as well. There are some late breaking fixes as well, which aren't so urgent they can't wait for the merge window. New Device Support * adf4371 - New driver + bindings. - Support the adf4372 PLL. Mostly ID and bindings. * ad8366 (note includes rework of driver needed to allow support for these). - Support the ADL5240 variable gain amplifier (VGA). - Support the ADA4961 digital gain amplifier (DGA). * dps310 - New driver, in several parts from different authors for this temp and pressure sensor. - Includes errata workaround for a temperature reading issue. * stk3310 - Support the stk3335, mostly ID. Features and cleanups * core - drop error handling on debugfs registration. - harden by making sure we don't overrun iio_chan_info_postfix. * docs - convert remaining docs to rst. At somepoint we'll fit these few into the main IIO docs. - improve sampling_frequency_available docs but explaining the range form. * ad_sigma_delta - Drop a pointless goto. * ad2s1210 - Drop pointless platform data null check seeing as we don't actually use platform data anymore. * ad7124 - Relax limitation on channel numbers to allow pseudo different channels. - Support control of whether the input is buffered via DT. - Use dynamic allocation for channel configuration to make it easier to support new devices. - YAML binding conversion. * ad7150 - Comment tidy up. - Consistent and simple if (ret) handling of i2c errors. - FIELD_GET and GENMASK. - Ternary rather than !!(condition) for readability. - Use macros to avoid repetition of channel definitions. * ad7606 - Add software channel config (rather that pin controlled) - Refactor to simplify addition of new part in future. * ad7746 - of_deivce_id table. * ad7780 - MAINTAINERS entry - YAML DT bindings. * ad8366 - Stop using core mlock in favour of well scoped local lock. - SPDX + copyright date update. * ad9834 - of_device_id table * adf4371 - Add support for output stage muting before lock on has occured. * adis library - MAINTAINERS entry to reflect that this now Alexandru's problem ;) * adis162xx: - Fix a slightly incorrect set of comments and print statements on minimum supported voltage. * adis16203 - of_device_id table. * adis16240 - Add of_device_id table (in two parts as first patch only used it for MODULE_DEVICE_TABLE.) * adt7316-spi - of_device_id table * adxl372 - YAML DT binding conversion. - Cleanup use of buffer callback functions (precursor to core rework). * bh1710 - Simplify getting the i2c adapter from the client. * dht11 - Mote to newer GPIO consumer interface. * kxcjk-1013.c - Add binding for sensor in display of some ultrabooks after userspace tools updated for it not be a problem to report two similar sensors. * imx7d - drop unused variables. - white space - define instead of variable for clock frequency that is fixed. - drop pointless error message. * messon_saradc - SPDX * sps30 - MAINTAINERS entry - YAML binding conversion. * st_accel - Tidy up ordering in various buffer related callbacks. This is part of a long running effort to simplify the core code. * stm32-dfsdm: - Manage the resolution cleanly in triggerd modes. - Add fast mode support which allows more flexible filter choices. - Add a comment on the reason for a 16 bit record when technically not 'required'. * st_lsm6dsx - Embed device name in the sensor_settings struct as i3c doesn't have a convenient name field to use for this. * xilinx-adc - Relax constraints on supported platforms to reflect that this can used with FPGAs on PCIe cards and hence many architectures. * counters/ftm-quaddec - Fix some formatting io MODULE_AUTHOR - MAINTAINERS entry Fixes * tools - fix incorrect handling of 32 bit channels. * sca3000 - Potential endian bug that is unlikely to bite anyone (be64 host seems unlikely for this old part). * stm32-adc - Add vdda-supply. On some boards it needs to be turned on to supply the ADC. DT bindings included. * stm32-dfsdm - Fix output resolution to work with filter orders other than 3. - Fix output datatype as it's signed and previously claimed not to be. * tag 'iio-for-5.3b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (68 commits) iio: iio-utils: Fix possible incorrect mask calculation iio: frequency: adf4371: Add support for output stage mute dt-bindings: iio: frequency: Add ADF4372 PLL documentation iio: frequency: adf4371: Add support for ADF4372 PLL dt-bindings: iio: adc: Add buffered input property Convert AD7124 bindings documentation to YAML format. iio: adc: ad7124: Shift to dynamic allocation for channel configuration iio: adc: ad7124: Add buffered input support iio: adc: ad7124: Remove input number limitation MAINTAINERS: add ADIS IMU driver library entry iio: adis162xx: fix low-power docs & reports counter/ftm-quaddec: Add missing '>' in MODULE_AUTHOR iio: core: no need to check return value of debugfs_create functions docs: iio: convert to ReST iio: adc: stm32-adc: add missing vdda-supply dt-bindings: iio: adc: stm32: add missing vdda supply iio: adc: stm32-dfsdm: add comment for 16 bits record iio: adc: stm32-dfsdm: add fast mode support iio: adc: stm32-dfsdm: manage data resolution in trigger mode iio: adc: stm32-dfsdm: fix data type ...
300 lines
7.2 KiB
C
300 lines
7.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* ROHM 1780GLI Ambient Light Sensor Driver
|
|
*
|
|
* Copyright (C) 2016 Linaro Ltd.
|
|
* Author: Linus Walleij <linus.walleij@linaro.org>
|
|
* Loosely based on the previous BH1780 ALS misc driver
|
|
* Copyright (C) 2010 Texas Instruments
|
|
* Author: Hemanth V <hemanthv@ti.com>
|
|
*/
|
|
#include <linux/i2c.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/iio/iio.h>
|
|
#include <linux/iio/sysfs.h>
|
|
#include <linux/bitops.h>
|
|
|
|
#define BH1780_CMD_BIT BIT(7)
|
|
#define BH1780_REG_CONTROL 0x00
|
|
#define BH1780_REG_PARTID 0x0A
|
|
#define BH1780_REG_MANFID 0x0B
|
|
#define BH1780_REG_DLOW 0x0C
|
|
#define BH1780_REG_DHIGH 0x0D
|
|
|
|
#define BH1780_REVMASK GENMASK(3,0)
|
|
#define BH1780_POWMASK GENMASK(1,0)
|
|
#define BH1780_POFF (0x0)
|
|
#define BH1780_PON (0x3)
|
|
|
|
/* power on settling time in ms */
|
|
#define BH1780_PON_DELAY 2
|
|
/* max time before value available in ms */
|
|
#define BH1780_INTERVAL 250
|
|
|
|
struct bh1780_data {
|
|
struct i2c_client *client;
|
|
};
|
|
|
|
static int bh1780_write(struct bh1780_data *bh1780, u8 reg, u8 val)
|
|
{
|
|
int ret = i2c_smbus_write_byte_data(bh1780->client,
|
|
BH1780_CMD_BIT | reg,
|
|
val);
|
|
if (ret < 0)
|
|
dev_err(&bh1780->client->dev,
|
|
"i2c_smbus_write_byte_data failed error "
|
|
"%d, register %01x\n",
|
|
ret, reg);
|
|
return ret;
|
|
}
|
|
|
|
static int bh1780_read(struct bh1780_data *bh1780, u8 reg)
|
|
{
|
|
int ret = i2c_smbus_read_byte_data(bh1780->client,
|
|
BH1780_CMD_BIT | reg);
|
|
if (ret < 0)
|
|
dev_err(&bh1780->client->dev,
|
|
"i2c_smbus_read_byte_data failed error "
|
|
"%d, register %01x\n",
|
|
ret, reg);
|
|
return ret;
|
|
}
|
|
|
|
static int bh1780_read_word(struct bh1780_data *bh1780, u8 reg)
|
|
{
|
|
int ret = i2c_smbus_read_word_data(bh1780->client,
|
|
BH1780_CMD_BIT | reg);
|
|
if (ret < 0)
|
|
dev_err(&bh1780->client->dev,
|
|
"i2c_smbus_read_word_data failed error "
|
|
"%d, register %01x\n",
|
|
ret, reg);
|
|
return ret;
|
|
}
|
|
|
|
static int bh1780_debugfs_reg_access(struct iio_dev *indio_dev,
|
|
unsigned int reg, unsigned int writeval,
|
|
unsigned int *readval)
|
|
{
|
|
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
|
int ret;
|
|
|
|
if (!readval)
|
|
return bh1780_write(bh1780, (u8)reg, (u8)writeval);
|
|
|
|
ret = bh1780_read(bh1780, (u8)reg);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
*readval = ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int bh1780_read_raw(struct iio_dev *indio_dev,
|
|
struct iio_chan_spec const *chan,
|
|
int *val, int *val2, long mask)
|
|
{
|
|
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
|
int value;
|
|
|
|
switch (mask) {
|
|
case IIO_CHAN_INFO_RAW:
|
|
switch (chan->type) {
|
|
case IIO_LIGHT:
|
|
pm_runtime_get_sync(&bh1780->client->dev);
|
|
value = bh1780_read_word(bh1780, BH1780_REG_DLOW);
|
|
if (value < 0)
|
|
return value;
|
|
pm_runtime_mark_last_busy(&bh1780->client->dev);
|
|
pm_runtime_put_autosuspend(&bh1780->client->dev);
|
|
*val = value;
|
|
|
|
return IIO_VAL_INT;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
case IIO_CHAN_INFO_INT_TIME:
|
|
*val = 0;
|
|
*val2 = BH1780_INTERVAL * 1000;
|
|
return IIO_VAL_INT_PLUS_MICRO;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
static const struct iio_info bh1780_info = {
|
|
.read_raw = bh1780_read_raw,
|
|
.debugfs_reg_access = bh1780_debugfs_reg_access,
|
|
};
|
|
|
|
static const struct iio_chan_spec bh1780_channels[] = {
|
|
{
|
|
.type = IIO_LIGHT,
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
|
|
BIT(IIO_CHAN_INFO_INT_TIME)
|
|
}
|
|
};
|
|
|
|
static int bh1780_probe(struct i2c_client *client,
|
|
const struct i2c_device_id *id)
|
|
{
|
|
int ret;
|
|
struct bh1780_data *bh1780;
|
|
struct i2c_adapter *adapter = client->adapter;
|
|
struct iio_dev *indio_dev;
|
|
|
|
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
|
|
return -EIO;
|
|
|
|
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*bh1780));
|
|
if (!indio_dev)
|
|
return -ENOMEM;
|
|
|
|
bh1780 = iio_priv(indio_dev);
|
|
bh1780->client = client;
|
|
i2c_set_clientdata(client, indio_dev);
|
|
|
|
/* Power up the device */
|
|
ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_PON);
|
|
if (ret < 0)
|
|
return ret;
|
|
msleep(BH1780_PON_DELAY);
|
|
pm_runtime_get_noresume(&client->dev);
|
|
pm_runtime_set_active(&client->dev);
|
|
pm_runtime_enable(&client->dev);
|
|
|
|
ret = bh1780_read(bh1780, BH1780_REG_PARTID);
|
|
if (ret < 0)
|
|
goto out_disable_pm;
|
|
dev_info(&client->dev,
|
|
"Ambient Light Sensor, Rev : %lu\n",
|
|
(ret & BH1780_REVMASK));
|
|
|
|
/*
|
|
* As the device takes 250 ms to even come up with a fresh
|
|
* measurement after power-on, do not shut it down unnecessarily.
|
|
* Set autosuspend to a five seconds.
|
|
*/
|
|
pm_runtime_set_autosuspend_delay(&client->dev, 5000);
|
|
pm_runtime_use_autosuspend(&client->dev);
|
|
pm_runtime_put(&client->dev);
|
|
|
|
indio_dev->dev.parent = &client->dev;
|
|
indio_dev->info = &bh1780_info;
|
|
indio_dev->name = "bh1780";
|
|
indio_dev->channels = bh1780_channels;
|
|
indio_dev->num_channels = ARRAY_SIZE(bh1780_channels);
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
|
|
ret = iio_device_register(indio_dev);
|
|
if (ret)
|
|
goto out_disable_pm;
|
|
return 0;
|
|
|
|
out_disable_pm:
|
|
pm_runtime_put_noidle(&client->dev);
|
|
pm_runtime_disable(&client->dev);
|
|
return ret;
|
|
}
|
|
|
|
static int bh1780_remove(struct i2c_client *client)
|
|
{
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
|
int ret;
|
|
|
|
iio_device_unregister(indio_dev);
|
|
pm_runtime_get_sync(&client->dev);
|
|
pm_runtime_put_noidle(&client->dev);
|
|
pm_runtime_disable(&client->dev);
|
|
ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_POFF);
|
|
if (ret < 0) {
|
|
dev_err(&client->dev, "failed to power off\n");
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static int bh1780_runtime_suspend(struct device *dev)
|
|
{
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
|
int ret;
|
|
|
|
ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_POFF);
|
|
if (ret < 0) {
|
|
dev_err(dev, "failed to runtime suspend\n");
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int bh1780_runtime_resume(struct device *dev)
|
|
{
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
|
int ret;
|
|
|
|
ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_PON);
|
|
if (ret < 0) {
|
|
dev_err(dev, "failed to runtime resume\n");
|
|
return ret;
|
|
}
|
|
|
|
/* Wait for power on, then for a value to be available */
|
|
msleep(BH1780_PON_DELAY + BH1780_INTERVAL);
|
|
|
|
return 0;
|
|
}
|
|
#endif /* CONFIG_PM */
|
|
|
|
static const struct dev_pm_ops bh1780_dev_pm_ops = {
|
|
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
|
|
pm_runtime_force_resume)
|
|
SET_RUNTIME_PM_OPS(bh1780_runtime_suspend,
|
|
bh1780_runtime_resume, NULL)
|
|
};
|
|
|
|
static const struct i2c_device_id bh1780_id[] = {
|
|
{ "bh1780", 0 },
|
|
{ },
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, bh1780_id);
|
|
|
|
#ifdef CONFIG_OF
|
|
static const struct of_device_id of_bh1780_match[] = {
|
|
{ .compatible = "rohm,bh1780gli", },
|
|
{},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, of_bh1780_match);
|
|
#endif
|
|
|
|
static struct i2c_driver bh1780_driver = {
|
|
.probe = bh1780_probe,
|
|
.remove = bh1780_remove,
|
|
.id_table = bh1780_id,
|
|
.driver = {
|
|
.name = "bh1780",
|
|
.pm = &bh1780_dev_pm_ops,
|
|
.of_match_table = of_match_ptr(of_bh1780_match),
|
|
},
|
|
};
|
|
|
|
module_i2c_driver(bh1780_driver);
|
|
|
|
MODULE_DESCRIPTION("ROHM BH1780GLI Ambient Light Sensor Driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
|