Re: i2c slave support für i.mx6

2015-11-24 Thread Wolfram Sang

> Is the recognition of IAAS a hardware interrupt (according to manual,
> yes)? I set IEN (I2C enable) and IIEN (Interrupt Enable).

Ah, I thought you had a question about Renesas hardware. I dunno much
about Freescale anymore.

> I set the slave address to 0x1c (chosen at random). The IMX bus driver
> is unchanged. With my external Master I ask for the address on the
> bus. But the IAAS bit is never set.
> In this test, I want to see if the hardware interrupt work.
> Should i modified the bus driver (IRQ handler???) or is this a real
> hardware interrupt?
> 
> Where is my misconception?

Please send patches what you did. That is easier to talk about.

BTW the video is online now:

https://www.youtube.com/watch?v=JdQ21jlwb58

Regards,

   Wolfram



signature.asc
Description: Digital signature


[RESEND PATCH v2 8/9] eeprom: at24: remove a reduntant if

2015-11-24 Thread Bartosz Golaszewski
It seems as if the second check for I2C_FUNC_I2C functionality had been
introduced accidentally during a merge. Tt's reduntant, so remove it.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 6e28b02..1288193 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -634,10 +634,7 @@ static int at24_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
} else {
return -EPFNOSUPPORT;
}
-   }
 
-   /* Use I2C operations unless we're stuck with SMBus extensions. */
-   if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
if (i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 9/9] eeprom: at24: readability tweaks

2015-11-24 Thread Bartosz Golaszewski
Move the macro definitions above the struct definitions and add some
tabs for better readability.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 1288193..3238bf6 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -53,6 +53,14 @@
  * which won't work on pure SMBus systems.
  */
 
+#define AT24_SIZE_BYTELEN  5
+#define AT24_SIZE_FLAGS8
+
+#define AT24_BITMASK(x)(BIT(x) - 1)
+
+#define AT24CS_SERIAL_SIZE 16
+#define AT24CS_SERIAL_ADDR(addr)   (addr + 0x08)
+
 struct at24_data {
struct at24_platform_data chip;
struct memory_accessor macc;
@@ -99,14 +107,6 @@ static unsigned write_timeout = 25;
 module_param(write_timeout, uint, 0);
 MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)");
 
-#define AT24_SIZE_BYTELEN 5
-#define AT24_SIZE_FLAGS 8
-
-#define AT24_BITMASK(x) (BIT(x) - 1)
-
-#define AT24CS_SERIAL_SIZE 16
-#define AT24CS_SERIAL_ADDR(addr) (addr + 0x08)
-
 /* create non-zero magic value for given eeprom parameters */
 #define AT24_DEVICE_MAGIC(_len, _flags)\
((1 << AT24_SIZE_FLAGS | (_flags))  \
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 7/9] eeprom: at24: add the at24cs series to the list of supported devices

2015-11-24 Thread Bartosz Golaszewski
The infrastructure for reading of the factory-programmed serial number
for at24cs EEPROM series is now in place. Add the chips that are actually
equipped with the serial number memory area to the list of supported
devices.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index d474b6d..6e28b02 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -117,16 +117,25 @@ static const struct i2c_device_id at24_ids[] = {
{ "24c00",  AT24_DEVICE_MAGIC(128 / 8,  AT24_FLAG_TAKE8ADDR) },
/* old variants can't be handled with this generic entry! */
{ "24c01",  AT24_DEVICE_MAGIC(1024 / 8, 0) },
+   { "24cs01", AT24_DEVICE_MAGIC(1024 / 8, AT24_FLAG_SERIAL) },
{ "24c02",  AT24_DEVICE_MAGIC(2048 / 8, 0) },
+   { "24cs02", AT24_DEVICE_MAGIC(2048 / 8, AT24_FLAG_SERIAL) },
/* spd is a 24c02 in memory DIMMs */
{ "spd",AT24_DEVICE_MAGIC(2048 / 8,
AT24_FLAG_READONLY | AT24_FLAG_IRUGO) },
{ "24c04",  AT24_DEVICE_MAGIC(4096 / 8, 0) },
+   { "24cs04", AT24_DEVICE_MAGIC(4096 / 8, AT24_FLAG_SERIAL) },
/* 24rf08 quirk is handled at i2c-core */
{ "24c08",  AT24_DEVICE_MAGIC(8192 / 8, 0) },
+   { "24cs08", AT24_DEVICE_MAGIC(8192 / 8, AT24_FLAG_SERIAL) },
{ "24c16",  AT24_DEVICE_MAGIC(16384 / 8,0) },
+   { "24cs16", AT24_DEVICE_MAGIC(16384 / 8,AT24_FLAG_SERIAL) },
{ "24c32",  AT24_DEVICE_MAGIC(32768 / 8,AT24_FLAG_ADDR16) },
+   { "24cs32", AT24_DEVICE_MAGIC(32768 / 8,
+   AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL) },
{ "24c64",  AT24_DEVICE_MAGIC(65536 / 8,AT24_FLAG_ADDR16) },
+   { "24cs64", AT24_DEVICE_MAGIC(65536 / 8,
+   AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL) },
{ "24c128", AT24_DEVICE_MAGIC(131072 / 8,   AT24_FLAG_ADDR16) },
{ "24c256", AT24_DEVICE_MAGIC(262144 / 8,   AT24_FLAG_ADDR16) },
{ "24c512", AT24_DEVICE_MAGIC(524288 / 8,   AT24_FLAG_ADDR16) },
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 5/9] eeprom: at24: export the serial number through sysfs

2015-11-24 Thread Bartosz Golaszewski
The at24 driver is now capable of reading the serial number from at24cs
EEPROM chips. Export the serial number through sysfs.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 44 
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 6182f47..65fca1e 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -65,6 +65,7 @@ struct at24_data {
 */
struct mutex lock;
struct bin_attribute bin;
+   struct bin_attribute *bin_serial;
 
u8 *writebuf;
unsigned write_max;
@@ -103,6 +104,7 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes 
(default 25)");
 
 #define AT24_BITMASK(x) (BIT(x) - 1)
 
+#define AT24CS_SERIAL_SIZE 16
 #define AT24CS_SERIAL_ADDR(addr) (addr + 0x08)
 
 /* create non-zero magic value for given eeprom parameters */
@@ -163,10 +165,8 @@ static struct i2c_client *at24_translate_offset(struct 
at24_data *at24,
return at24->client[i];
 }
 
-static int __attribute__((unused)) at24cs_eeprom_serial_read(
-   struct at24_data *at24,
-   char *buf, unsigned offset,
-   size_t count)
+static int at24cs_eeprom_serial_read(struct at24_data *at24, char *buf,
+unsigned offset, size_t count)
 {
unsigned long timeout, read_time;
struct i2c_client *client;
@@ -234,6 +234,16 @@ static int __attribute__((unused)) 
at24cs_eeprom_serial_read(
return -ETIMEDOUT;
 }
 
+static ssize_t at24cs_bin_serial_read(struct file *filp, struct kobject *kobj,
+ struct bin_attribute *attr,
+ char *buf, loff_t off, size_t count)
+{
+   struct at24_data *at24;
+
+   at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
+   return at24cs_eeprom_serial_read(at24, buf, off, count);
+}
+
 static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
unsigned offset, size_t count)
 {
@@ -658,6 +668,30 @@ static int at24_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
at24->bin.read = at24_bin_read;
at24->bin.size = chip.byte_len;
 
+   if (at24->chip.flags & AT24_FLAG_SERIAL) {
+   /*
+* For EEPROMs containing the serial number export an
+* additional file allowing allowing convenvient access
+* to it from user-space.
+*/
+   at24->bin_serial = devm_kzalloc(&client->dev,
+   sizeof(struct bin_attribute),
+   GFP_KERNEL);
+   if (!at24->bin_serial)
+   return -ENOMEM;
+
+   sysfs_bin_attr_init(at24->bin_serial);
+   at24->bin_serial->attr.name = "serial";
+   at24->bin_serial->attr.mode = S_IRUSR;
+   at24->bin_serial->read = at24cs_bin_serial_read;
+   at24->bin_serial->size = AT24CS_SERIAL_SIZE;
+
+   err = sysfs_create_bin_file(&client->dev.kobj,
+   at24->bin_serial);
+   if (err)
+   goto err_clients;
+   }
+
at24->macc.read = at24_macc_read;
 
writable = !(chip.flags & AT24_FLAG_READONLY);
@@ -757,6 +791,8 @@ static int at24_remove(struct i2c_client *client)
 
at24 = i2c_get_clientdata(client);
sysfs_remove_bin_file(&client->dev.kobj, &at24->bin);
+   if (at24->bin_serial)
+   sysfs_remove_bin_file(&client->dev.kobj, at24->bin_serial);
 
for (i = 1; i < at24->num_addresses; i++)
i2c_unregister_device(at24->client[i]);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/1] x86/platform/iosf_mbi: Remove duplicate definitions

2015-11-24 Thread Andy Shevchenko
On Wed, 2015-11-11 at 19:59 +0200, Andy Shevchenko wrote:
> The read and write opcodes are global for all units on SoC and even
> across
> Intel SoCs. Remove duplication of corresponding constants. At the
> same time
> convert all current users.
> 
> No functional change.
> 
> Cc: Thomas Gleixner 
> Cc: Ingo Molnar 
> Cc: Peter Anvin 
> Cc: Wolfram Sang 
> Cc: Zhang Rui 
> Cc: Eduardo Valentin 
> Cc: Hock Leong Kweh 

Any concerns, anyone?

Btw, this patch has been tested on Intel BayTrail and Braswell.

> 
> Signed-off-by: Andy Shevchenko 
> ---
> Since v1:
> - satisfy kbuild robot
> 
>  arch/x86/include/asm/iosf_mbi.h  | 49 +-
> 
>  arch/x86/platform/atom/punit_atom_debug.c|  7 +---
>  arch/x86/platform/intel-quark/imr.c  | 28 +
>  drivers/i2c/busses/i2c-designware-baytrail.c | 17 +++-
>  drivers/powercap/intel_rapl.c| 10 ++---
>  drivers/thermal/intel_quark_dts_thermal.c| 61 ++--
> 
>  drivers/thermal/intel_soc_dts_iosf.c | 43 ++--
> 
>  7 files changed, 85 insertions(+), 130 deletions(-)
> 
> diff --git a/arch/x86/include/asm/iosf_mbi.h
> b/arch/x86/include/asm/iosf_mbi.h
> index b72ad0f..cdc5f63 100644
> --- a/arch/x86/include/asm/iosf_mbi.h
> +++ b/arch/x86/include/asm/iosf_mbi.h
> @@ -1,5 +1,5 @@
>  /*
> - * iosf_mbi.h: Intel OnChip System Fabric MailBox access support
> + * Intel OnChip System Fabric MailBox access support
>   */
>  
>  #ifndef IOSF_MBI_SYMS_H
> @@ -16,6 +16,16 @@
>  #define MBI_MASK_LO  0x00FF
>  #define MBI_ENABLE   0xF0
>  
> +/* IOSF SB read/write opcodes */
> +#define MBI_MMIO_READ0x00
> +#define MBI_MMIO_WRITE   0x01
> +#define MBI_CR_READ  0x06
> +#define MBI_CR_WRITE 0x07
> +#define MBI_REG_READ 0x10
> +#define MBI_REG_WRITE0x11
> +#define MBI_ESRAM_READ   0x12
> +#define MBI_ESRAM_WRITE  0x13
> +
>  /* Baytrail available units */
>  #define BT_MBI_UNIT_AUNIT0x00
>  #define BT_MBI_UNIT_SMC  0x01
> @@ -28,50 +38,13 @@
>  #define BT_MBI_UNIT_SATA 0xA3
>  #define BT_MBI_UNIT_PCIE 0xA6
>  
> -/* Baytrail read/write opcodes */
> -#define BT_MBI_AUNIT_READ0x10
> -#define BT_MBI_AUNIT_WRITE   0x11
> -#define BT_MBI_SMC_READ  0x10
> -#define BT_MBI_SMC_WRITE 0x11
> -#define BT_MBI_CPU_READ  0x10
> -#define BT_MBI_CPU_WRITE 0x11
> -#define BT_MBI_BUNIT_READ0x10
> -#define BT_MBI_BUNIT_WRITE   0x11
> -#define BT_MBI_PMC_READ  0x06
> -#define BT_MBI_PMC_WRITE 0x07
> -#define BT_MBI_GFX_READ  0x00
> -#define BT_MBI_GFX_WRITE 0x01
> -#define BT_MBI_SMIO_READ 0x06
> -#define BT_MBI_SMIO_WRITE0x07
> -#define BT_MBI_USB_READ  0x06
> -#define BT_MBI_USB_WRITE 0x07
> -#define BT_MBI_SATA_READ 0x00
> -#define BT_MBI_SATA_WRITE0x01
> -#define BT_MBI_PCIE_READ 0x00
> -#define BT_MBI_PCIE_WRITE0x01
> -
>  /* Quark available units */
>  #define QRK_MBI_UNIT_HBA 0x00
>  #define QRK_MBI_UNIT_HB  0x03
>  #define QRK_MBI_UNIT_RMU 0x04
>  #define QRK_MBI_UNIT_MM  0x05
> -#define QRK_MBI_UNIT_MMESRAM 0x05
>  #define QRK_MBI_UNIT_SOC 0x31
>  
> -/* Quark read/write opcodes */
> -#define QRK_MBI_HBA_READ 0x10
> -#define QRK_MBI_HBA_WRITE0x11
> -#define QRK_MBI_HB_READ  0x10
> -#define QRK_MBI_HB_WRITE 0x11
> -#define QRK_MBI_RMU_READ 0x10
> -#define QRK_MBI_RMU_WRITE0x11
> -#define QRK_MBI_MM_READ  0x10
> -#define QRK_MBI_MM_WRITE 0x11
> -#define QRK_MBI_MMESRAM_READ 0x12
> -#define QRK_MBI_MMESRAM_WRITE0x13
> -#define QRK_MBI_SOC_READ 0x06
> -#define QRK_MBI_SOC_WRITE0x07
> -
>  #if IS_ENABLED(CONFIG_IOSF_MBI)
>  
>  bool iosf_mbi_available(void);
> diff --git a/arch/x86/platform/atom/punit_atom_debug.c
> b/arch/x86/platform/atom/punit_atom_debug.c
> index 5ca8ead..81c769e 100644
> --- a/arch/x86/platform/atom/punit_atom_debug.c
> +++ b/arch/x86/platform/atom/punit_atom_debug.c
> @@ -25,8 +25,6 @@
>  #include 
>  #include 
>  
> -/* Side band Interface port */
> -#define PUNIT_PORT   0x04
>  /* Power gate status reg */
>  #define PWRGT_STATUS 0x61
>  /* Subsystem config/status Video processor */
> @@ -85,9 +83,8 @@ static int punit_dev_state_show(struct seq_file
> *seq_file, void *unused)
>  
>   seq_puts(seq_file, "\n\nPUNIT NORTH COMPLEX DEVICES :\n");
>   while (punit_devp->name) {
> - status = iosf_mbi_read(PUNIT_PORT, BT_MBI_PMC_READ,
> -    punit_devp->reg,
> -    &punit_pwr_status);
> + status = iosf_mbi_read(BT_MBI_UNIT_PMC,
> MBI_REG_READ,
> +    punit_devp->reg,
> &punit_pwr_status);
>   if (status) {
>   seq_printf(seq_file, "%9s : Read Failed\n",
>    

[RESEND PATCH v2 6/9] eeprom: at24: improve the device_id table readability

2015-11-24 Thread Bartosz Golaszewski
Improve the readability of the device table by separating columns with
tabs.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 65fca1e..d474b6d 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -114,23 +114,23 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try 
writes (default 25)");
 
 static const struct i2c_device_id at24_ids[] = {
/* needs 8 addresses as A0-A2 are ignored */
-   { "24c00", AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) },
+   { "24c00",  AT24_DEVICE_MAGIC(128 / 8,  AT24_FLAG_TAKE8ADDR) },
/* old variants can't be handled with this generic entry! */
-   { "24c01", AT24_DEVICE_MAGIC(1024 / 8, 0) },
-   { "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) },
+   { "24c01",  AT24_DEVICE_MAGIC(1024 / 8, 0) },
+   { "24c02",  AT24_DEVICE_MAGIC(2048 / 8, 0) },
/* spd is a 24c02 in memory DIMMs */
-   { "spd", AT24_DEVICE_MAGIC(2048 / 8,
-   AT24_FLAG_READONLY | AT24_FLAG_IRUGO) },
-   { "24c04", AT24_DEVICE_MAGIC(4096 / 8, 0) },
+   { "spd",AT24_DEVICE_MAGIC(2048 / 8,
+   AT24_FLAG_READONLY | AT24_FLAG_IRUGO) },
+   { "24c04",  AT24_DEVICE_MAGIC(4096 / 8, 0) },
/* 24rf08 quirk is handled at i2c-core */
-   { "24c08", AT24_DEVICE_MAGIC(8192 / 8, 0) },
-   { "24c16", AT24_DEVICE_MAGIC(16384 / 8, 0) },
-   { "24c32", AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) },
-   { "24c64", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) },
-   { "24c128", AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) },
-   { "24c256", AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) },
-   { "24c512", AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) },
-   { "24c1024", AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16) },
+   { "24c08",  AT24_DEVICE_MAGIC(8192 / 8, 0) },
+   { "24c16",  AT24_DEVICE_MAGIC(16384 / 8,0) },
+   { "24c32",  AT24_DEVICE_MAGIC(32768 / 8,AT24_FLAG_ADDR16) },
+   { "24c64",  AT24_DEVICE_MAGIC(65536 / 8,AT24_FLAG_ADDR16) },
+   { "24c128", AT24_DEVICE_MAGIC(131072 / 8,   AT24_FLAG_ADDR16) },
+   { "24c256", AT24_DEVICE_MAGIC(262144 / 8,   AT24_FLAG_ADDR16) },
+   { "24c512", AT24_DEVICE_MAGIC(524288 / 8,   AT24_FLAG_ADDR16) },
+   { "24c1024",AT24_DEVICE_MAGIC(1048576 / 8,  AT24_FLAG_ADDR16) },
{ "at24", 0 },
{ /* END OF LIST */ }
 };
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 1/9] eeprom: at24: platform_data: use BIT() macro

2015-11-24 Thread Bartosz Golaszewski
Use BIT() macro to replace the 0xXX constants in platform_data flags
definitions.

Signed-off-by: Bartosz Golaszewski 
---
 include/linux/platform_data/at24.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/platform_data/at24.h 
b/include/linux/platform_data/at24.h
index c42aa89..8d90f52 100644
--- a/include/linux/platform_data/at24.h
+++ b/include/linux/platform_data/at24.h
@@ -43,10 +43,10 @@ struct at24_platform_data {
u32 byte_len;   /* size (sum of all addr) */
u16 page_size;  /* for writes */
u8  flags;
-#define AT24_FLAG_ADDR16   0x80/* address pointer is 16 bit */
-#define AT24_FLAG_READONLY 0x40/* sysfs-entry will be read-only */
-#define AT24_FLAG_IRUGO0x20/* sysfs-entry will be 
world-readable */
-#define AT24_FLAG_TAKE8ADDR0x10/* take always 8 addresses (24c00) */
+#define AT24_FLAG_ADDR16   BIT(7)  /* address pointer is 16 bit */
+#define AT24_FLAG_READONLY BIT(6)  /* sysfs-entry will be read-only */
+#define AT24_FLAG_IRUGOBIT(5)  /* sysfs-entry will be 
world-readable */
+#define AT24_FLAG_TAKE8ADDRBIT(4)  /* take always 8 addresses (24c00) */
 
void(*setup)(struct memory_accessor *, void *context);
void*context;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 0/9] eeprom: at24: at24cs series serial number read

2015-11-24 Thread Bartosz Golaszewski
Chips from the at24cs EEPROM series have an additional read-only memory area
containing a factory pre-programmed serial number. In order to access it, a
dummy write must be executed before reading the serial number bytes.

This series adds support for reading the serial number through a sysfs
attribute.

While we're at it: some of the patches contain readability tweaks and code
organization fixes.

Tested with at24cs64 and at24cs02 chips (for both 16 and 8 bit address
pointers).

(rebased against 4.4-rc2)

v2:
- protect the serial number read with a mutex

v1: https://lkml.org/lkml/2015/10/20/162


Bartosz Golaszewski (9):
  eeprom: at24: platform_data: use BIT() macro
  eeprom: at24: new flag in platform_data
  eeprom: at24: tie up an additional address for at24cs series
  eeprom: at24: support reading of the serial number
  eeprom: at24: export the serial number through sysfs
  eeprom: at24: improve the device_id table readability
  eeprom: at24: add the at24cs series to the list of supported devices
  eeprom: at24: remove a reduntant if
  eeprom: at24: readability tweaks

 drivers/misc/eeprom/at24.c | 187 +++--
 include/linux/platform_data/at24.h |   9 +-
 2 files changed, 166 insertions(+), 30 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 3/9] eeprom: at24: tie up an additional address for at24cs series

2015-11-24 Thread Bartosz Golaszewski
The at24cs series EEPROM chips have an additional read-only memory area,
that is visible on a different i2c slave address. Tie it up with a dummy
device.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 30 ++
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 5d7c090..08cc327 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -103,6 +103,8 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes 
(default 25)");
 
 #define AT24_BITMASK(x) (BIT(x) - 1)
 
+#define AT24CS_SERIAL_ADDR(addr) (addr + 0x08)
+
 /* create non-zero magic value for given eeprom parameters */
 #define AT24_DEVICE_MAGIC(_len, _flags)\
((1 << AT24_SIZE_FLAGS | (_flags))  \
@@ -558,6 +560,8 @@ static int at24_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
 
if (chip.flags & AT24_FLAG_TAKE8ADDR)
num_addresses = 8;
+   else if (chip.flags & AT24_FLAG_SERIAL)
+   num_addresses = 2;
else
num_addresses = DIV_ROUND_UP(chip.byte_len,
(chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
@@ -616,12 +620,30 @@ static int at24_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
at24->client[0] = client;
 
/* use dummy devices for multiple-address chips */
-   for (i = 1; i < num_addresses; i++) {
-   at24->client[i] = i2c_new_dummy(client->adapter,
+   if (at24->chip.flags & AT24_FLAG_TAKE8ADDR) {
+   for (i = 1; i < num_addresses; i++) {
+   at24->client[i] = i2c_new_dummy(client->adapter,
+   client->addr + i);
+   if (!at24->client[i]) {
+   dev_err(&client->dev,
+   "address 0x%02x unavailable\n",
client->addr + i);
-   if (!at24->client[i]) {
+   err = -EADDRINUSE;
+   goto err_clients;
+   }
+   }
+   }
+
+   /*
+* at24cs series tie up an additional address for the memory area
+* contining the serial number
+*/
+   if (at24->chip.flags & AT24_FLAG_SERIAL) {
+   at24->client[1] = i2c_new_dummy(client->adapter,
+   AT24CS_SERIAL_ADDR(client->addr));
+   if (!at24->client[1]) {
dev_err(&client->dev, "address 0x%02x unavailable\n",
-   client->addr + i);
+   AT24CS_SERIAL_ADDR(client->addr));
err = -EADDRINUSE;
goto err_clients;
}
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 2/9] eeprom: at24: new flag in platform_data

2015-11-24 Thread Bartosz Golaszewski
In preparation for supporting the at24cs EEPROM series add a new flag to
platform data. When set, it should tell the driver that the chip has an
additional read-only memory area that holds a factory pre-programmed serial
number.

Signed-off-by: Bartosz Golaszewski 
---
 include/linux/platform_data/at24.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/platform_data/at24.h 
b/include/linux/platform_data/at24.h
index 8d90f52..5686f91 100644
--- a/include/linux/platform_data/at24.h
+++ b/include/linux/platform_data/at24.h
@@ -47,6 +47,7 @@ struct at24_platform_data {
 #define AT24_FLAG_READONLY BIT(6)  /* sysfs-entry will be read-only */
 #define AT24_FLAG_IRUGOBIT(5)  /* sysfs-entry will be 
world-readable */
 #define AT24_FLAG_TAKE8ADDRBIT(4)  /* take always 8 addresses (24c00) */
+#define AT24_FLAG_SERIAL   BIT(3)  /* factory-programmed serial number */
 
void(*setup)(struct memory_accessor *, void *context);
void*context;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH v2 4/9] eeprom: at24: support reading of the serial number

2015-11-24 Thread Bartosz Golaszewski
The at24cs series EEPROM chips have an additional read-only memory area
containing a factory pre-programmed serial number. In order to access
it, one has to perform a dummy write before reading the serial number
bytes.

Add a function that allows to access the serial number.

Signed-off-by: Bartosz Golaszewski 
---
 drivers/misc/eeprom/at24.c | 71 ++
 1 file changed, 71 insertions(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 08cc327..6182f47 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -163,6 +163,77 @@ static struct i2c_client *at24_translate_offset(struct 
at24_data *at24,
return at24->client[i];
 }
 
+static int __attribute__((unused)) at24cs_eeprom_serial_read(
+   struct at24_data *at24,
+   char *buf, unsigned offset,
+   size_t count)
+{
+   unsigned long timeout, read_time;
+   struct i2c_client *client;
+   struct i2c_msg msg[2];
+   u8 addrbuf[2];
+   int status;
+
+   mutex_lock(&at24->lock);
+
+   client = at24->client[1];
+
+   memset(msg, 0, sizeof(msg));
+   msg[0].addr = client->addr;
+   msg[0].buf = addrbuf;
+
+   /*
+* The address pointer of the device is shared between the regular
+* EEPROM array and the serial number block. The dummy write (part of
+* the sequential read protocol) ensures the address pointer is reset
+* to the desired position.
+*/
+   if (at24->chip.flags & AT24_FLAG_ADDR16) {
+   /*
+* For 16 bit address pointers, the word address must contain
+* a '10' sequence in bits 11 and 10 regardless of the
+* intended position of the address pointer.
+*/
+   addrbuf[0] = 0x08;
+   addrbuf[1] = offset;
+   msg[0].len = 2;
+   } else {
+   /*
+* Otherwise the word address must begin with a '10' sequence,
+* regardless of the intended address.
+*/
+   addrbuf[0] = 0x80 + offset;
+   msg[0].len = 1;
+   }
+
+   msg[1].addr = client->addr;
+   msg[1].flags = I2C_M_RD;
+   msg[1].buf = buf;
+   msg[1].len = count;
+
+   /*
+* Reads fail if the previous write didn't complete yet. We may
+* loop a few times until this one succeeds, waiting at least
+* long enough for one entire page write to work.
+*/
+   timeout = jiffies + msecs_to_jiffies(write_timeout);
+   do {
+   read_time = jiffies;
+   status = i2c_transfer(client->adapter, msg, 2);
+   if (status == 2) {
+   mutex_unlock(&at24->lock);
+   return count;
+   }
+
+   /* REVISIT: at HZ=100, this is slw */
+   msleep(1);
+   } while (time_before(read_time, timeout));
+
+   mutex_unlock(&at24->lock);
+
+   return -ETIMEDOUT;
+}
+
 static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
unsigned offset, size_t count)
 {
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 05/13] device property: helper macros for property entry creation

2015-11-24 Thread Andy Shevchenko
From: Heikki Krogerus 

Marcos for easier creation of build-in property entries.

Signed-off-by: Heikki Krogerus 
Signed-off-by: Andy Shevchenko 
---
 include/linux/property.h | 48 
 1 file changed, 48 insertions(+)

diff --git a/include/linux/property.h b/include/linux/property.h
index 5d0b9b6..2528a000 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -173,6 +173,54 @@ struct property_entry {
};
 };
 
+#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _val_)\
+{  \
+   .name = _name_, \
+   .length = ARRAY_SIZE(_val_) * sizeof(_type_),   \
+   .is_array = true,   \
+   .pointer._type_##_data = _val_, \
+}
+
+#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \
+   PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u8, _val_)
+#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_)\
+   PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u16, _val_)
+#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_)\
+   PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u32, _val_)
+#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_)\
+   PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u64, _val_)
+
+#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \
+{  \
+   .name = _name_, \
+   .length = ARRAY_SIZE(_val_) * sizeof(const char *), \
+   .is_array = true,   \
+   .pointer.str = _val_,   \
+}
+
+#define PROPERTY_ENTRY_INTEGER(_name_, _type_, _val_)  \
+{  \
+   .name = _name_, \
+   .length = sizeof(_type_),   \
+   .value._type_##_data = _val_,   \
+}
+
+#define PROPERTY_ENTRY_U8(_name_, _val_)   \
+   PROPERTY_ENTRY_INTEGER(_name_, u8, _val_)
+#define PROPERTY_ENTRY_U16(_name_, _val_)  \
+   PROPERTY_ENTRY_INTEGER(_name_, u16, _val_)
+#define PROPERTY_ENTRY_U32(_name_, _val_)  \
+   PROPERTY_ENTRY_INTEGER(_name_, u32, _val_)
+#define PROPERTY_ENTRY_U64(_name_, _val_)  \
+   PROPERTY_ENTRY_INTEGER(_name_, u64, _val_)
+
+#define PROPERTY_ENTRY_STRING(_name_, _val_)   \
+{  \
+   .name = _name_, \
+   .length = sizeof(_val_),\
+   .value.str = _val_, \
+}
+
 /**
  * struct property_set - Collection of "built-in" device properties.
  * @fwnode: Handle to be pointed to by the fwnode field of struct device.
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 08/13] device property: Fallback to secondary fwnode if primary misses the property

2015-11-24 Thread Andy Shevchenko
The struct fwnode has notion of secondary fwnode. This is supposed to used
as fallback if the primary firmware interface (DT, ACPI) does not have the
property in question.

However, the current implementation never checks the secondary node which
prevents one to add default "built-in" properties to devices.

This patch adds fallback to the secondary fwnode if the primary fwnode
returns that the property does not exists.

Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
---
 drivers/base/property.c | 109 ++--
 1 file changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index c8e9722..1768e61 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -212,12 +212,8 @@ bool device_property_present(struct device *dev, const 
char *propname)
 }
 EXPORT_SYMBOL_GPL(device_property_present);
 
-/**
- * fwnode_property_present - check if a property of a firmware node is present
- * @fwnode: Firmware node whose property to check
- * @propname: Name of the property
- */
-bool fwnode_property_present(struct fwnode_handle *fwnode, const char 
*propname)
+static bool __fwnode_property_present(struct fwnode_handle *fwnode,
+ const char *propname)
 {
if (is_of_node(fwnode))
return of_property_read_bool(to_of_node(fwnode), propname);
@@ -227,6 +223,21 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, 
const char *propname)
return !!pset_prop_get(to_pset_node(fwnode), propname);
return false;
 }
+
+/**
+ * fwnode_property_present - check if a property of a firmware node is present
+ * @fwnode: Firmware node whose property to check
+ * @propname: Name of the property
+ */
+bool fwnode_property_present(struct fwnode_handle *fwnode, const char 
*propname)
+{
+   bool ret;
+
+   ret = __fwnode_property_present(fwnode, propname);
+   if (ret == false && fwnode->secondary)
+   ret = __fwnode_property_present(fwnode->secondary, propname);
+   return ret;
+}
 EXPORT_SYMBOL_GPL(fwnode_property_present);
 
 /**
@@ -406,7 +417,7 @@ EXPORT_SYMBOL_GPL(device_property_match_string);
(val) ? pset_prop_read_##type##_array((node), (propname), (val), 
(nval))\
  : pset_prop_count_elems_of_size((node), (propname), sizeof(type))
 
-#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, 
_val_, _nval_)\
+#define FWNODE_PROP_READ(_fwnode_, _propname_, _type_, _proptype_, _val_, 
_nval_)  \
 ({ 
\
int _ret_;  
\
if (is_of_node(_fwnode_))   
\
@@ -423,6 +434,17 @@ EXPORT_SYMBOL_GPL(device_property_match_string);
_ret_;  
\
 })
 
+#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, 
_val_, _nval_)\
+({ 
\
+   int _ret_;  
\
+   _ret_ = FWNODE_PROP_READ(_fwnode_, _propname_, _type_, _proptype_,  
\
+_val_, _nval_);
\
+   if (_ret_ == -EINVAL && _fwnode_->secondary)
\
+   _ret_ = FWNODE_PROP_READ(_fwnode_->secondary, _propname_, 
_type_,   \
+   _proptype_, _val_, _nval_); 
\
+   _ret_;  
\
+})
+
 /**
  * fwnode_property_read_u8_array - return a u8 array property of firmware node
  * @fwnode: Firmware node to get the property of
@@ -527,6 +549,41 @@ int fwnode_property_read_u64_array(struct fwnode_handle 
*fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array);
 
+static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode,
+  const char *propname,
+  const char **val, size_t nval)
+{
+   if (is_of_node(fwnode))
+   return val ?
+   of_property_read_string_array(to_of_node(fwnode),
+ propname, val, nval) :
+   of_property_count_strings(to_of_node(fwnode), propname);
+   else if (is_acpi_node(fwnode))
+   return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
+  val, nval);
+   else if (is_pset_node(fwnode))
+   return val ?
+   pset_prop_read_string_array(to_pset_node(fwnode),
+  

[PATCH v1 04/13] device property: keep single value inplace

2015-11-24 Thread Andy Shevchenko
We may save a lot of lines of code and space by keeping single values inside
the struct property_entry. Refactor the implementation to do so.

Signed-off-by: Andy Shevchenko 
---
 drivers/base/property.c  | 31 ---
 include/linux/property.h | 29 +
 2 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 86834bd..3e603c0 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -72,7 +72,10 @@ static void *pset_prop_find(struct property_set *pset, const 
char *propname,
prop = pset_prop_get(pset, propname);
if (!prop)
return ERR_PTR(-EINVAL);
-   pointer = prop->value.raw_data;
+   if (prop->is_array)
+   pointer = prop->pointer.raw_data;
+   else
+   pointer = &prop->value.raw_data;
if (!pointer)
return ERR_PTR(-ENODATA);
if (length > prop->length)
@@ -167,6 +170,29 @@ static int pset_prop_read_string_array(struct property_set 
*pset,
return 0;
 }
 
+static int pset_prop_read_string(struct property_set *pset,
+const char *propname, const char **strings)
+{
+   struct property_entry *prop;
+   const char **pointer;
+
+   prop = pset_prop_get(pset, propname);
+   if (!prop)
+   return -EINVAL;
+   if (prop->is_array) {
+   pointer = prop->pointer.str;
+   if (!pointer)
+   return -ENODATA;
+   } else {
+   pointer = &prop->value.str;
+   if (strnlen(*pointer, prop->length) >= prop->length)
+   return -EILSEQ;
+   }
+
+   *strings = *pointer;
+   return 0;
+}
+
 static inline struct fwnode_handle *dev_fwnode(struct device *dev)
 {
return IS_ENABLED(CONFIG_OF) && dev->of_node ?
@@ -566,8 +592,7 @@ int fwnode_property_read_string(struct fwnode_handle 
*fwnode,
return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
   val, 1);
else if (is_pset_node(fwnode))
-   return pset_prop_read_string_array(to_pset_node(fwnode),
-  propname, val, 1);
+   return pset_prop_read_string(to_pset_node(fwnode), propname, 
val);
return -ENXIO;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_string);
diff --git a/include/linux/property.h b/include/linux/property.h
index c29460a..5d0b9b6 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -145,19 +145,32 @@ static inline int fwnode_property_read_u64(struct 
fwnode_handle *fwnode,
  * struct property_entry - "Built-in" device property representation.
  * @name: Name of the property.
  * @length: Length of data making up the value.
- * @value: Value of the property (an array of items of the given type).
+ * @is_array: True when the property is an array.
+ * @pointer: Pointer to the property (an array of items of the given type).
+ * @value: Value of the property (when it is a single item of the given type).
  */
 struct property_entry {
const char *name;
size_t length;
+   bool is_array;
union {
-   void *raw_data;
-   u8 *u8_data;
-   u16 *u16_data;
-   u32 *u32_data;
-   u64 *u64_data;
-   const char **str;
-   } value;
+   union {
+   void *raw_data;
+   u8 *u8_data;
+   u16 *u16_data;
+   u32 *u32_data;
+   u64 *u64_data;
+   const char **str;
+   } pointer;
+   union {
+   unsigned long long raw_data;
+   u8 u8_data;
+   u16 u16_data;
+   u32 u32_data;
+   u64 u64_data;
+   const char *str;
+   } value;
+   };
 };
 
 /**
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 03/13] device property: refactor built-in properties support

2015-11-24 Thread Andy Shevchenko
Instead of using the type and nval fields we will use length (in bytes) of the
value. The sanity check is done in the accessors.

The built-in property accessors are split in the same way such as device tree.

Signed-off-by: Andy Shevchenko 
---
 drivers/base/property.c  | 150 ++-
 include/linux/property.h |   8 +--
 2 files changed, 113 insertions(+), 45 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 2e01f3f..86834bd 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -63,45 +63,107 @@ static struct property_entry *pset_prop_get(struct 
property_set *pset,
return NULL;
 }
 
-static int pset_prop_read_array(struct property_set *pset, const char *name,
-   enum dev_prop_type type, void *val, size_t nval)
+static void *pset_prop_find(struct property_set *pset, const char *propname,
+   size_t length)
 {
struct property_entry *prop;
-   unsigned int item_size;
+   void *pointer;
 
-   prop = pset_prop_get(pset, name);
+   prop = pset_prop_get(pset, propname);
+   if (!prop)
+   return ERR_PTR(-EINVAL);
+   pointer = prop->value.raw_data;
+   if (!pointer)
+   return ERR_PTR(-ENODATA);
+   if (length > prop->length)
+   return ERR_PTR(-EOVERFLOW);
+   return pointer;
+}
+
+static int pset_prop_read_u8_array(struct property_set *pset,
+  const char *propname,
+  u8 *values, size_t nval)
+{
+   void *pointer;
+   size_t length = nval * sizeof(*values);
+
+   pointer = pset_prop_find(pset, propname, length);
+   if (IS_ERR(pointer))
+   return PTR_ERR(pointer);
+
+   memcpy(values, pointer, length);
+   return 0;
+}
+
+static int pset_prop_read_u16_array(struct property_set *pset,
+   const char *propname,
+   u16 *values, size_t nval)
+{
+   void *pointer;
+   size_t length = nval * sizeof(*values);
+
+   pointer = pset_prop_find(pset, propname, length);
+   if (IS_ERR(pointer))
+   return PTR_ERR(pointer);
+
+   memcpy(values, pointer, length);
+   return 0;
+}
+
+static int pset_prop_read_u32_array(struct property_set *pset,
+   const char *propname,
+   u32 *values, size_t nval)
+{
+   void *pointer;
+   size_t length = nval * sizeof(*values);
+
+   pointer = pset_prop_find(pset, propname, length);
+   if (IS_ERR(pointer))
+   return PTR_ERR(pointer);
+
+   memcpy(values, pointer, length);
+   return 0;
+}
+
+static int pset_prop_read_u64_array(struct property_set *pset,
+   const char *propname,
+   u64 *values, size_t nval)
+{
+   void *pointer;
+   size_t length = nval * sizeof(*values);
+
+   pointer = pset_prop_find(pset, propname, length);
+   if (IS_ERR(pointer))
+   return PTR_ERR(pointer);
+
+   memcpy(values, pointer, length);
+   return 0;
+}
+
+static int pset_prop_count_elems_of_size(struct property_set *pset,
+const char *propname, size_t length)
+{
+   struct property_entry *prop;
+
+   prop = pset_prop_get(pset, propname);
if (!prop)
-   return -ENODATA;
-
-   if (prop->type != type)
-   return -EPROTO;
-
-   if (!val)
-   return prop->nval;
-
-   if (prop->nval < nval)
-   return -EOVERFLOW;
-
-   switch (type) {
-   case DEV_PROP_U8:
-   item_size = sizeof(u8);
-   break;
-   case DEV_PROP_U16:
-   item_size = sizeof(u16);
-   break;
-   case DEV_PROP_U32:
-   item_size = sizeof(u32);
-   break;
-   case DEV_PROP_U64:
-   item_size = sizeof(u64);
-   break;
-   case DEV_PROP_STRING:
-   item_size = sizeof(const char *);
-   break;
-   default:
return -EINVAL;
-   }
-   memcpy(val, prop->value.raw_data, nval * item_size);
+
+   return prop->length / length;
+}
+
+static int pset_prop_read_string_array(struct property_set *pset,
+  const char *propname,
+  const char **strings, size_t nval)
+{
+   void *pointer;
+   size_t length = nval * sizeof(*strings);
+
+   pointer = pset_prop_find(pset, propname, length);
+   if (IS_ERR(pointer))
+   return PTR_ERR(pointer);
+
+   memcpy(strings, pointer, length);
return 0;
 }
 
@@ -314,6 +376,10 @@ EXPORT_SYMBOL_GPL(device_property_match_string);
(val) ? of_property_read_##type##_array((node), (propname), (val), 
(nval)) \

[PATCH v1 10/13] mfd: intel-lpss: Add support for passing device properties

2015-11-24 Thread Andy Shevchenko
From: Mika Westerberg 

If the boot firmware does not support ACPI we need a way to pass device
configuration information to the drivers. The unified device properties API
already supports passing platform data via properties so let's take
advantage of that and allow probe drivers to pass set of properties to the
host controller driver.

In order to do that we need to be able to modify the MFD cell corresponding
the host controller, so make the core driver to take copy of the cell
instead of using it directly. Then we can assign info->pset to the
resulting copy of a cell and let the MFD core to assign that to the
resulting device.

Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
---
 drivers/mfd/intel-lpss.c | 16 
 drivers/mfd/intel-lpss.h |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c
index 6255513..1743788 100644
--- a/drivers/mfd/intel-lpss.c
+++ b/drivers/mfd/intel-lpss.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -72,7 +73,7 @@ struct intel_lpss {
enum intel_lpss_dev_type type;
struct clk *clk;
struct clk_lookup *clock;
-   const struct mfd_cell *cell;
+   struct mfd_cell *cell;
struct device *dev;
void __iomem *priv;
int devid;
@@ -217,6 +218,7 @@ static void intel_lpss_ltr_hide(struct intel_lpss *lpss)
 
 static int intel_lpss_assign_devs(struct intel_lpss *lpss)
 {
+   const struct mfd_cell *cell;
unsigned int type;
 
type = lpss->caps & LPSS_PRIV_CAPS_TYPE_MASK;
@@ -224,18 +226,22 @@ static int intel_lpss_assign_devs(struct intel_lpss *lpss)
 
switch (type) {
case LPSS_DEV_I2C:
-   lpss->cell = &intel_lpss_i2c_cell;
+   cell = &intel_lpss_i2c_cell;
break;
case LPSS_DEV_UART:
-   lpss->cell = &intel_lpss_uart_cell;
+   cell = &intel_lpss_uart_cell;
break;
case LPSS_DEV_SPI:
-   lpss->cell = &intel_lpss_spi_cell;
+   cell = &intel_lpss_spi_cell;
break;
default:
return -ENODEV;
}
 
+   lpss->cell = devm_kmemdup(lpss->dev, cell, sizeof(*cell), GFP_KERNEL);
+   if (!lpss->cell)
+   return -ENOMEM;
+
lpss->type = type;
 
return 0;
@@ -401,6 +407,8 @@ int intel_lpss_probe(struct device *dev,
if (ret)
return ret;
 
+   lpss->cell->pset = info->pset;
+
intel_lpss_init_dev(lpss);
 
lpss->devid = ida_simple_get(&intel_lpss_devid_ida, 0, 0, GFP_KERNEL);
diff --git a/drivers/mfd/intel-lpss.h b/drivers/mfd/intel-lpss.h
index 2c7f8d7..0dcea9e 100644
--- a/drivers/mfd/intel-lpss.h
+++ b/drivers/mfd/intel-lpss.h
@@ -16,12 +16,14 @@
 
 struct device;
 struct resource;
+struct property_set;
 
 struct intel_lpss_platform_info {
struct resource *mem;
int irq;
unsigned long clk_rate;
const char *clk_con_id;
+   struct property_set *pset;
 };
 
 int intel_lpss_probe(struct device *dev,
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 02/13] device property: rename helper functions

2015-11-24 Thread Andy Shevchenko
To be in align with the rest of fwnode types we rename the built-in property
set ones, i.e.
is_pset() -> is_pset_node()
to_pset() -> to_pset_node()

There is no functional change.

Signed-off-by: Andy Shevchenko 
---
 drivers/base/property.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 09e488d..2e01f3f 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -37,14 +37,14 @@ void device_add_property_set(struct device *dev, struct 
property_set *pset)
 }
 EXPORT_SYMBOL_GPL(device_add_property_set);
 
-static inline bool is_pset(struct fwnode_handle *fwnode)
+static inline bool is_pset_node(struct fwnode_handle *fwnode)
 {
return fwnode && fwnode->type == FWNODE_PDATA;
 }
 
-static inline struct property_set *to_pset(struct fwnode_handle *fwnode)
+static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode)
 {
-   return is_pset(fwnode) ?
+   return is_pset_node(fwnode) ?
container_of(fwnode, struct property_set, fwnode) : NULL;
 }
 
@@ -135,8 +135,8 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, 
const char *propname)
return of_property_read_bool(to_of_node(fwnode), propname);
else if (is_acpi_node(fwnode))
return !acpi_node_prop_get(fwnode, propname, NULL);
-   else if (is_pset(fwnode))
-   return !!pset_prop_get(to_pset(fwnode), propname);
+   else if (is_pset_node(fwnode))
+   return !!pset_prop_get(to_pset_node(fwnode), propname);
return false;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_present);
@@ -323,8 +323,8 @@ EXPORT_SYMBOL_GPL(device_property_match_string);
else if (is_acpi_node(_fwnode_)) \
_ret_ = acpi_node_prop_read(_fwnode_, _propname_, _proptype_, \
_val_, _nval_); \
-   else if (is_pset(_fwnode_)) \
-   _ret_ = pset_prop_read_array(to_pset(_fwnode_), _propname_, \
+   else if (is_pset_node(_fwnode_))
\
+   _ret_ = pset_prop_read_array(to_pset_node(_fwnode_), 
_propname_,\
 _proptype_, _val_, _nval_); \
else \
_ret_ = -ENXIO; \
@@ -465,8 +465,8 @@ int fwnode_property_read_string_array(struct fwnode_handle 
*fwnode,
else if (is_acpi_node(fwnode))
return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
   val, nval);
-   else if (is_pset(fwnode))
-   return pset_prop_read_array(to_pset(fwnode), propname,
+   else if (is_pset_node(fwnode))
+   return pset_prop_read_array(to_pset_node(fwnode), propname,
DEV_PROP_STRING, val, nval);
return -ENXIO;
 }
@@ -495,8 +495,8 @@ int fwnode_property_read_string(struct fwnode_handle 
*fwnode,
else if (is_acpi_node(fwnode))
return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
   val, 1);
-   else if (is_pset(fwnode))
-   return pset_prop_read_array(to_pset(fwnode), propname,
+   else if (is_pset_node(fwnode))
+   return pset_prop_read_array(to_pset_node(fwnode), propname,
DEV_PROP_STRING, val, 1);
return -ENXIO;
 }
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 13/13] i2c: designware: Convert to use unified device property API

2015-11-24 Thread Andy Shevchenko
From: Mika Westerberg 

With ACPI _DSD (introduced in ACPI v5.1) it is now possible to pass device
configuration information from ACPI in addition to DT. In order to support
this, convert the driver to use the unified device property accessors
instead of DT specific.

Change to ordering a bit so that we first try platform data and if that's
not available look from device properties. ACPI *CNT methods are then used
as last resort to override everything else.

Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 48 +
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 809579e..e9062be 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -156,33 +157,28 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
/* fast mode by default because of legacy reasons */
clk_freq = 40;
 
-   if (has_acpi_companion(&pdev->dev)) {
-   dw_i2c_acpi_configure(pdev);
-   } else if (pdev->dev.of_node) {
-   of_property_read_u32(pdev->dev.of_node,
-   "i2c-sda-hold-time-ns", &ht);
-
-   of_property_read_u32(pdev->dev.of_node,
-"i2c-sda-falling-time-ns",
-&dev->sda_falling_time);
-   of_property_read_u32(pdev->dev.of_node,
-"i2c-scl-falling-time-ns",
-&dev->scl_falling_time);
-
-   of_property_read_u32(pdev->dev.of_node, "clock-frequency",
-&clk_freq);
-
-   /* Only standard mode at 100kHz and fast mode at 400kHz
-* are supported.
-*/
-   if (clk_freq != 10 && clk_freq != 40) {
-   dev_err(&pdev->dev, "Only 100kHz and 400kHz supported");
-   return -EINVAL;
-   }
+   if ((pdata = dev_get_platdata(&pdev->dev))) {
+   clk_freq = pdata->i2c_scl_freq;
} else {
-   pdata = dev_get_platdata(&pdev->dev);
-   if (pdata)
-   clk_freq = pdata->i2c_scl_freq;
+   device_property_read_u32(&pdev->dev, "i2c-sda-hold-time-ns",
+&ht);
+   device_property_read_u32(&pdev->dev, "i2c-sda-falling-time-ns",
+&dev->sda_falling_time);
+   device_property_read_u32(&pdev->dev, "i2c-scl-falling-time-ns",
+&dev->scl_falling_time);
+   device_property_read_u32(&pdev->dev, "clock-frequency",
+&clk_freq);
+   }
+
+   if (has_acpi_companion(&pdev->dev))
+   dw_i2c_acpi_configure(pdev);
+
+   /* Only standard mode at 100kHz and fast mode at 400kHz
+* are supported.
+*/
+   if (clk_freq != 10 && clk_freq != 40) {
+   dev_err(&pdev->dev, "Only 100kHz and 400kHz supported");
+   return -EINVAL;
}
 
r = i2c_dw_eval_lock_support(dev);
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 11/13] mfd: intel-lpss: Pass HSUART configuration via properties

2015-11-24 Thread Andy Shevchenko
From: Mika Westerberg 

The HS-UART host controller driver needs to know certain properties like
width of the register set if it cannot get that information from ACPI or
DT. In order to support non-ACPI systems we pass this information to the
driver via device properties.

Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
---
 drivers/mfd/intel-lpss-pci.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/mfd/intel-lpss-pci.c b/drivers/mfd/intel-lpss-pci.c
index 5bfdfcc..74f0d6d 100644
--- a/drivers/mfd/intel-lpss-pci.c
+++ b/drivers/mfd/intel-lpss-pci.c
@@ -65,9 +65,21 @@ static const struct intel_lpss_platform_info spt_info = {
.clk_rate = 12000,
 };
 
+static struct property_entry uart_properties[] = {
+   PROPERTY_ENTRY_U32("reg-io-width", 4),
+   PROPERTY_ENTRY_U32("reg-shift", 2),
+   PROPERTY_ENTRY_U8("snps,uart-16550-compatible", 1),
+   { },
+};
+
+static struct property_set uart_pset = {
+   .properties = uart_properties,
+};
+
 static const struct intel_lpss_platform_info spt_uart_info = {
.clk_rate = 12000,
.clk_con_id = "baudclk",
+   .pset = &uart_pset,
 };
 
 static const struct intel_lpss_platform_info bxt_info = {
@@ -77,6 +89,7 @@ static const struct intel_lpss_platform_info bxt_info = {
 static const struct intel_lpss_platform_info bxt_uart_info = {
.clk_rate = 1,
.clk_con_id = "baudclk",
+   .pset = &uart_pset,
 };
 
 static const struct intel_lpss_platform_info bxt_i2c_info = {
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 12/13] mfd: intel-lpss: Pass SDA hold time to I2C host controller driver

2015-11-24 Thread Andy Shevchenko
From: Mika Westerberg 

Intel Skylake the LPSS I2C pad circuit has internal delays that require
programming non-zero SDA hold time for the I2C host controller. If this is
not done communication to slave devices may fail with arbitration lost
errors like the one seen below taken from Lenovo Yoga 900:

  i2c_hid i2c-SYNA2B29:00: Fetching the HID descriptor
  i2c_hid i2c-SYNA2B29:00: __i2c_hid_command: cmd=20 00
  i2c_designware i2c_designware.1: i2c_dw_handle_tx_abort: lost arbitration

To fix this we follow what the Windows driver is doing and pass the default
SDA hold time of 230 ns to all Intel Skylake host controllers. This still
allows the platform to override these values by passing special ACPI
methods SSCN and FMCN.

Reported-by: Kevin Fenzi 
Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
---
 drivers/mfd/intel-lpss-acpi.c | 18 --
 drivers/mfd/intel-lpss-pci.c  | 30 ++
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/mfd/intel-lpss-acpi.c b/drivers/mfd/intel-lpss-acpi.c
index b6fd904..6c5bbda 100644
--- a/drivers/mfd/intel-lpss-acpi.c
+++ b/drivers/mfd/intel-lpss-acpi.c
@@ -25,6 +25,20 @@ static const struct intel_lpss_platform_info spt_info = {
.clk_rate = 12000,
 };
 
+static struct property_entry spt_i2c_properties[] = {
+   PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 230),
+   { },
+};
+
+static struct property_set spt_i2c_pset = {
+   .properties = spt_i2c_properties,
+};
+
+static const struct intel_lpss_platform_info spt_i2c_info = {
+   .clk_rate = 12000,
+   .pset = &spt_i2c_pset,
+};
+
 static const struct intel_lpss_platform_info bxt_info = {
.clk_rate = 1,
 };
@@ -35,8 +49,8 @@ static const struct intel_lpss_platform_info bxt_i2c_info = {
 
 static const struct acpi_device_id intel_lpss_acpi_ids[] = {
/* SPT */
-   { "INT3446", (kernel_ulong_t)&spt_info },
-   { "INT3447", (kernel_ulong_t)&spt_info },
+   { "INT3446", (kernel_ulong_t)&spt_i2c_info },
+   { "INT3447", (kernel_ulong_t)&spt_i2c_info },
/* BXT */
{ "80860AAC", (kernel_ulong_t)&bxt_i2c_info },
{ "80860ABC", (kernel_ulong_t)&bxt_info },
diff --git a/drivers/mfd/intel-lpss-pci.c b/drivers/mfd/intel-lpss-pci.c
index 74f0d6d..3c84ceb 100644
--- a/drivers/mfd/intel-lpss-pci.c
+++ b/drivers/mfd/intel-lpss-pci.c
@@ -65,6 +65,20 @@ static const struct intel_lpss_platform_info spt_info = {
.clk_rate = 12000,
 };
 
+static struct property_entry spt_i2c_properties[] = {
+   PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 230),
+   { },
+};
+
+static struct property_set spt_i2c_pset = {
+   .properties = spt_i2c_properties,
+};
+
+static const struct intel_lpss_platform_info spt_i2c_info = {
+   .clk_rate = 12000,
+   .pset = &spt_i2c_pset,
+};
+
 static struct property_entry uart_properties[] = {
PROPERTY_ENTRY_U32("reg-io-width", 4),
PROPERTY_ENTRY_U32("reg-shift", 2),
@@ -134,20 +148,20 @@ static const struct pci_device_id intel_lpss_pci_ids[] = {
{ PCI_VDEVICE(INTEL, 0x9d28), (kernel_ulong_t)&spt_uart_info },
{ PCI_VDEVICE(INTEL, 0x9d29), (kernel_ulong_t)&spt_info },
{ PCI_VDEVICE(INTEL, 0x9d2a), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0x9d60), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0x9d61), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0x9d62), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0x9d63), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0x9d64), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0x9d65), (kernel_ulong_t)&spt_info },
+   { PCI_VDEVICE(INTEL, 0x9d60), (kernel_ulong_t)&spt_i2c_info },
+   { PCI_VDEVICE(INTEL, 0x9d61), (kernel_ulong_t)&spt_i2c_info },
+   { PCI_VDEVICE(INTEL, 0x9d62), (kernel_ulong_t)&spt_i2c_info },
+   { PCI_VDEVICE(INTEL, 0x9d63), (kernel_ulong_t)&spt_i2c_info },
+   { PCI_VDEVICE(INTEL, 0x9d64), (kernel_ulong_t)&spt_i2c_info },
+   { PCI_VDEVICE(INTEL, 0x9d65), (kernel_ulong_t)&spt_i2c_info },
{ PCI_VDEVICE(INTEL, 0x9d66), (kernel_ulong_t)&spt_uart_info },
/* SPT-H */
{ PCI_VDEVICE(INTEL, 0xa127), (kernel_ulong_t)&spt_uart_info },
{ PCI_VDEVICE(INTEL, 0xa128), (kernel_ulong_t)&spt_uart_info },
{ PCI_VDEVICE(INTEL, 0xa129), (kernel_ulong_t)&spt_info },
{ PCI_VDEVICE(INTEL, 0xa12a), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0xa160), (kernel_ulong_t)&spt_info },
-   { PCI_VDEVICE(INTEL, 0xa161), (kernel_ulong_t)&spt_info },
+   { PCI_VDEVICE(INTEL, 0xa160), (kernel_ulong_t)&spt_i2c_info },
+   { PCI_VDEVICE(INTEL, 0xa161), (kernel_ulong_t)&spt_i2c_info },
{ PCI_VDEVICE(INTEL, 0xa166), (kernel_ulong_t)&spt_uart_info },
{ }
 };
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.ker

[PATCH v1 06/13] device property: improve readability of macros

2015-11-24 Thread Andy Shevchenko
There is no functional change.

Signed-off-by: Andy Shevchenko 
---
 drivers/base/property.c  | 28 ++--
 include/linux/property.h |  4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 3e603c0..c8e9722 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -398,29 +398,29 @@ int device_property_match_string(struct device *dev, 
const char *propname,
 }
 EXPORT_SYMBOL_GPL(device_property_match_string);
 
-#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
-   (val) ? of_property_read_##type##_array((node), (propname), (val), 
(nval)) \
+#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval)
\
+   (val) ? of_property_read_##type##_array((node), (propname), (val), 
(nval))  \
  : of_property_count_elems_of_size((node), (propname), 
sizeof(type))
 
 #define PSET_PROP_READ_ARRAY(node, propname, type, val, nval)  
\
(val) ? pset_prop_read_##type##_array((node), (propname), (val), 
(nval))\
  : pset_prop_count_elems_of_size((node), (propname), sizeof(type))
 
-#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, 
_val_, _nval_) \
-({ \
-   int _ret_; \
-   if (is_of_node(_fwnode_)) \
-   _ret_ = OF_DEV_PROP_READ_ARRAY(to_of_node(_fwnode_), 
_propname_, \
-  _type_, _val_, _nval_); \
-   else if (is_acpi_node(_fwnode_)) \
-   _ret_ = acpi_node_prop_read(_fwnode_, _propname_, _proptype_, \
-   _val_, _nval_); \
+#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, 
_val_, _nval_)\
+({ 
\
+   int _ret_;  
\
+   if (is_of_node(_fwnode_))   
\
+   _ret_ = OF_DEV_PROP_READ_ARRAY(to_of_node(_fwnode_), 
_propname_,\
+  _type_, _val_, _nval_);  
\
+   else if (is_acpi_node(_fwnode_))
\
+   _ret_ = acpi_node_prop_read(_fwnode_, _propname_, _proptype_,   
\
+   _val_, _nval_); 
\
else if (is_pset_node(_fwnode_))
\
_ret_ = PSET_PROP_READ_ARRAY(to_pset_node(_fwnode_), 
_propname_,\
 _type_, _val_, _nval_);
\
-   else \
-   _ret_ = -ENXIO; \
-   _ret_; \
+   else
\
+   _ret_ = -ENXIO; 
\
+   _ret_;  
\
 })
 
 /**
diff --git a/include/linux/property.h b/include/linux/property.h
index 2528a000..e947403 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -73,8 +73,8 @@ int fwnode_property_match_string(struct fwnode_handle *fwnode,
 struct fwnode_handle *device_get_next_child_node(struct device *dev,
 struct fwnode_handle *child);
 
-#define device_for_each_child_node(dev, child) \
-   for (child = device_get_next_child_node(dev, NULL); child; \
+#define device_for_each_child_node(dev, child) \
+   for (child = device_get_next_child_node(dev, NULL); child;  \
 child = device_get_next_child_node(dev, child))
 
 void fwnode_handle_put(struct fwnode_handle *fwnode);
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 07/13] device property: return -EINVAL when property isn't found in ACPI

2015-11-24 Thread Andy Shevchenko
Change return code to be in align with OF and built-in device properties error
codes. In particular -EINVAL means property is not found.

Signed-off-by: Andy Shevchenko 
---
 drivers/acpi/property.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 88f4306..2aee416 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -346,7 +346,7 @@ void acpi_free_properties(struct acpi_device *adev)
  *
  * Return: %0 if property with @name has been found (success),
  * %-EINVAL if the arguments are invalid,
- * %-ENODATA if the property doesn't exist,
+ * %-EINVAL if the property doesn't exist,
  * %-EPROTO if the property value type doesn't match @type.
  */
 static int acpi_data_get_property(struct acpi_device_data *data,
@@ -360,7 +360,7 @@ static int acpi_data_get_property(struct acpi_device_data 
*data,
return -EINVAL;
 
if (!data->pointer || !data->properties)
-   return -ENODATA;
+   return -EINVAL;
 
properties = data->properties;
for (i = 0; i < properties->package.count; i++) {
@@ -375,13 +375,13 @@ static int acpi_data_get_property(struct acpi_device_data 
*data,
if (!strcmp(name, propname->string.pointer)) {
if (type != ACPI_TYPE_ANY && propvalue->type != type)
return -EPROTO;
-   else if (obj)
+   if (obj)
*obj = propvalue;
 
return 0;
}
}
-   return -ENODATA;
+   return -EINVAL;
 }
 
 /**
@@ -439,7 +439,7 @@ int acpi_node_prop_get(struct fwnode_handle *fwnode, const 
char *propname,
  *
  * Return: %0 if array property (package) with @name has been found (success),
  * %-EINVAL if the arguments are invalid,
- * %-ENODATA if the property doesn't exist,
+ * %-EINVAL if the property doesn't exist,
  * %-EPROTO if the property is not a package or the type of its 
elements
  *   doesn't match @type.
  */
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 09/13] mfd: core: propagate device properties to sub devices drivers

2015-11-24 Thread Andy Shevchenko
In the similar way like we do for the platform data we propagate the device
properties. For example, in case of Intel LPSS drivers we may provide a
specific property to tell the actual device driver an additional information
such as platform name.

Signed-off-by: Andy Shevchenko 
---
 drivers/mfd/mfd-core.c   | 3 +++
 include/linux/mfd/core.h | 5 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 60b60dc..ec00f6f 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -192,6 +193,8 @@ static int mfd_add_device(struct device *parent, int id,
goto fail_alias;
}
 
+   device_add_property_set(&pdev->dev, cell->pset);
+
ret = mfd_platform_add_cell(pdev, cell, usage_count);
if (ret)
goto fail_alias;
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index 27dac3f..0c62f17 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -15,6 +15,7 @@
 #define MFD_CORE_H
 
 #include 
+#include 
 
 struct irq_domain;
 
@@ -44,6 +45,10 @@ struct mfd_cell {
/* platform data passed to the sub devices drivers */
void*platform_data;
size_t  pdata_size;
+
+   /* device properties passed to the sub devices drivers */
+   struct property_set *pset;
+
/*
 * Device Tree compatible string
 * See: Documentation/devicetree/usage-model.txt Chapter 2.2 for details
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 01/13] device property: always check for fwnode type

2015-11-24 Thread Andy Shevchenko
Currently the property accessors unconditionally fall back to built-in property
set as a last resort. Make this strict and return an error in case the type of
fwnode is unknown.

This is actually a follow up to the commit 4fa7508e9f1c (device property:
Return -ENXIO if there is no suitable FW interface).

Signed-off-by: Andy Shevchenko 
---
 drivers/base/property.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 1325ff2..09e488d 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -135,8 +135,9 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, 
const char *propname)
return of_property_read_bool(to_of_node(fwnode), propname);
else if (is_acpi_node(fwnode))
return !acpi_node_prop_get(fwnode, propname, NULL);
-
-   return !!pset_prop_get(to_pset(fwnode), propname);
+   else if (is_pset(fwnode))
+   return !!pset_prop_get(to_pset(fwnode), propname);
+   return false;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_present);
 
@@ -494,9 +495,10 @@ int fwnode_property_read_string(struct fwnode_handle 
*fwnode,
else if (is_acpi_node(fwnode))
return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
   val, 1);
-
-   return pset_prop_read_array(to_pset(fwnode), propname,
-   DEV_PROP_STRING, val, 1);
+   else if (is_pset(fwnode))
+   return pset_prop_read_array(to_pset(fwnode), propname,
+   DEV_PROP_STRING, val, 1);
+   return -ENXIO;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_string);
 
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 00/13] intel-lpss: support non-ACPI platforms

2015-11-24 Thread Andy Shevchenko
This series includes few logical sets that bring a support of non-ACPI
platforms for Intel Skylake.

First part is a refactoring of built-in device properties support:
 - keep single value inside the structure
 - provide helper macros to define built-in properties
 - fall back to secondary fwnode if primary has no asked property

Second one is modifications to MFD code and intel-lpss.c driver in particular
to define and pass built-in properties to the individual drivers.

Last part is a fix for I2C bug found on Lenovo Yoga hardware and a first
converted user.

Built-in device properties is an alternative to platform data. It provides a
unified API that drivers can use to cover all cases at once: DT, ACPI, and
built-in properties.

With this series applied platform data can be considered obsolete. Moreover,
built-in device properties allows to adjust existing configuration, for
example, in cases when ACPI values are wrong on some platforms.

The series has been tested on available hardware and doesn't break current
behaviour. But we ask you, Kevin, to apply the series on your side and check
with Lenovo hardware.

Andy Shevchenko (8):
  device property: always check for fwnode type
  device property: rename helper functions
  device property: refactor built-in properties support
  device property: keep single value inplace
  device property: improve readability of macros
  device property: return -EINVAL when property isn't found in ACPI
  device property: Fallback to secondary fwnode if primary misses the
property
  mfd: core: propagate device properties to sub devices drivers

Heikki Krogerus (1):
  device property: helper macros for property entry creation

Mika Westerberg (4):
  mfd: intel-lpss: Add support for passing device properties
  mfd: intel-lpss: Pass HSUART configuration via properties
  mfd: intel-lpss: Pass SDA hold time to I2C host controller driver
  i2c: designware: Convert to use unified device property API

 drivers/acpi/property.c |  10 +-
 drivers/base/property.c | 298 +---
 drivers/i2c/busses/i2c-designware-platdrv.c |  48 ++---
 drivers/mfd/intel-lpss-acpi.c   |  18 +-
 drivers/mfd/intel-lpss-pci.c|  43 +++-
 drivers/mfd/intel-lpss.c|  16 +-
 drivers/mfd/intel-lpss.h|   2 +
 drivers/mfd/mfd-core.c  |   3 +
 include/linux/mfd/core.h|   5 +
 include/linux/property.h|  87 ++--
 10 files changed, 394 insertions(+), 136 deletions(-)

-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 11/13] mfd: intel-lpss: Pass HSUART configuration via properties

2015-11-24 Thread kbuild test robot
Hi Mika,

[auto build test ERROR on v4.4-rc2]
[also build test ERROR on next-20151124]
[cannot apply to ljones-mfd/for-mfd-next]

url:
https://github.com/0day-ci/linux/commits/Andy-Shevchenko/device-property-always-check-for-fwnode-type/20151124-183221
config: x86_64-randconfig-x019-11241713 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

>> drivers/mfd/intel-lpss-pci.c:68:30: error: array type has incomplete element 
>> type 'struct property_entry'
static struct property_entry uart_properties[] = {
 ^
>> drivers/mfd/intel-lpss-pci.c:69:2: error: implicit declaration of function 
>> 'PROPERTY_ENTRY_U32' [-Werror=implicit-function-declaration]
 PROPERTY_ENTRY_U32("reg-io-width", 4),
 ^
>> drivers/mfd/intel-lpss-pci.c:71:2: error: implicit declaration of function 
>> 'PROPERTY_ENTRY_U8' [-Werror=implicit-function-declaration]
 PROPERTY_ENTRY_U8("snps,uart-16550-compatible", 1),
 ^
>> drivers/mfd/intel-lpss-pci.c:75:15: error: variable 'uart_pset' has 
>> initializer but incomplete type
static struct property_set uart_pset = {
  ^
>> drivers/mfd/intel-lpss-pci.c:76:2: error: unknown field 'properties' 
>> specified in initializer
 .properties = uart_properties,
 ^
>> drivers/mfd/intel-lpss-pci.c:76:16: warning: excess elements in struct 
>> initializer
 .properties = uart_properties,
   ^
   drivers/mfd/intel-lpss-pci.c:76:16: note: (near initialization for 
'uart_pset')
>> drivers/mfd/intel-lpss-pci.c:68:30: warning: 'uart_properties' defined but 
>> not used [-Wunused-variable]
static struct property_entry uart_properties[] = {
 ^
   cc1: some warnings being treated as errors

vim +68 drivers/mfd/intel-lpss-pci.c

62  static INTEL_LPSS_PM_OPS(intel_lpss_pci_pm_ops);
63  
64  static const struct intel_lpss_platform_info spt_info = {
65  .clk_rate = 12000,
66  };
67  
  > 68  static struct property_entry uart_properties[] = {
  > 69  PROPERTY_ENTRY_U32("reg-io-width", 4),
70  PROPERTY_ENTRY_U32("reg-shift", 2),
  > 71  PROPERTY_ENTRY_U8("snps,uart-16550-compatible", 1),
72  { },
73  };
74  
  > 75  static struct property_set uart_pset = {
  > 76  .properties = uart_properties,
77  };
78  
79  static const struct intel_lpss_platform_info spt_uart_info = {

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [PATCH v1 12/13] mfd: intel-lpss: Pass SDA hold time to I2C host controller driver

2015-11-24 Thread kbuild test robot
Hi Mika,

[auto build test ERROR on v4.4-rc2]
[also build test ERROR on next-20151124]
[cannot apply to ljones-mfd/for-mfd-next]

url:
https://github.com/0day-ci/linux/commits/Andy-Shevchenko/device-property-always-check-for-fwnode-type/20151124-183221
config: x86_64-randconfig-x019-11241713 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/mfd/intel-lpss-pci.c:68:30: error: array type has incomplete element 
type 'struct property_entry'
static struct property_entry spt_i2c_properties[] = {
 ^
   drivers/mfd/intel-lpss-pci.c:69:2: error: implicit declaration of function 
'PROPERTY_ENTRY_U32' [-Werror=implicit-function-declaration]
 PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 230),
 ^
>> drivers/mfd/intel-lpss-pci.c:73:15: error: variable 'spt_i2c_pset' has 
>> initializer but incomplete type
static struct property_set spt_i2c_pset = {
  ^
   drivers/mfd/intel-lpss-pci.c:74:2: error: unknown field 'properties' 
specified in initializer
 .properties = spt_i2c_properties,
 ^
   drivers/mfd/intel-lpss-pci.c:74:16: warning: excess elements in struct 
initializer
 .properties = spt_i2c_properties,
   ^
   drivers/mfd/intel-lpss-pci.c:74:16: note: (near initialization for 
'spt_i2c_pset')
   drivers/mfd/intel-lpss-pci.c:82:30: error: array type has incomplete element 
type 'struct property_entry'
static struct property_entry uart_properties[] = {
 ^
   drivers/mfd/intel-lpss-pci.c:85:2: error: implicit declaration of function 
'PROPERTY_ENTRY_U8' [-Werror=implicit-function-declaration]
 PROPERTY_ENTRY_U8("snps,uart-16550-compatible", 1),
 ^
   drivers/mfd/intel-lpss-pci.c:89:15: error: variable 'uart_pset' has 
initializer but incomplete type
static struct property_set uart_pset = {
  ^
   drivers/mfd/intel-lpss-pci.c:90:2: error: unknown field 'properties' 
specified in initializer
 .properties = uart_properties,
 ^
   drivers/mfd/intel-lpss-pci.c:90:16: warning: excess elements in struct 
initializer
 .properties = uart_properties,
   ^
   drivers/mfd/intel-lpss-pci.c:90:16: note: (near initialization for 
'uart_pset')
>> drivers/mfd/intel-lpss-pci.c:68:30: warning: 'spt_i2c_properties' defined 
>> but not used [-Wunused-variable]
static struct property_entry spt_i2c_properties[] = {
 ^
   drivers/mfd/intel-lpss-pci.c:82:30: warning: 'uart_properties' defined but 
not used [-Wunused-variable]
static struct property_entry uart_properties[] = {
 ^
   cc1: some warnings being treated as errors

vim +/spt_i2c_pset +73 drivers/mfd/intel-lpss-pci.c

62  static INTEL_LPSS_PM_OPS(intel_lpss_pci_pm_ops);
63  
64  static const struct intel_lpss_platform_info spt_info = {
65  .clk_rate = 12000,
66  };
67  
  > 68  static struct property_entry spt_i2c_properties[] = {
69  PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 230),
70  { },
71  };
72  
  > 73  static struct property_set spt_i2c_pset = {
74  .properties = spt_i2c_properties,
75  };
76  
77  static const struct intel_lpss_platform_info spt_i2c_info = {
78  .clk_rate = 12000,
79  .pset = &spt_i2c_pset,
80  };
81  
82  static struct property_entry uart_properties[] = {
83  PROPERTY_ENTRY_U32("reg-io-width", 4),
84  PROPERTY_ENTRY_U32("reg-shift", 2),
85  PROPERTY_ENTRY_U8("snps,uart-16550-compatible", 1),
86  { },
87  };
88  
89  static struct property_set uart_pset = {
  > 90  .properties = uart_properties,
91  };
92  
93  static const struct intel_lpss_platform_info spt_uart_info = {

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [PATCH v1 13/13] i2c: designware: Convert to use unified device property API

2015-11-24 Thread Jarkko Nikula

On 11/24/2015 12:22 PM, Andy Shevchenko wrote:

From: Mika Westerberg 

With ACPI _DSD (introduced in ACPI v5.1) it is now possible to pass device
configuration information from ACPI in addition to DT. In order to support
this, convert the driver to use the unified device property accessors
instead of DT specific.

Change to ordering a bit so that we first try platform data and if that's
not available look from device properties. ACPI *CNT methods are then used
as last resort to override everything else.

Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
---
  drivers/i2c/busses/i2c-designware-platdrv.c | 48 +
  1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 809579e..e9062be 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -36,6 +36,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -156,33 +157,28 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
/* fast mode by default because of legacy reasons */
clk_freq = 40;

-   if (has_acpi_companion(&pdev->dev)) {
-   dw_i2c_acpi_configure(pdev);
-   } else if (pdev->dev.of_node) {
-   of_property_read_u32(pdev->dev.of_node,
-   "i2c-sda-hold-time-ns", &ht);
-
-   of_property_read_u32(pdev->dev.of_node,
-"i2c-sda-falling-time-ns",
-&dev->sda_falling_time);
-   of_property_read_u32(pdev->dev.of_node,
-"i2c-scl-falling-time-ns",
-&dev->scl_falling_time);
-
-   of_property_read_u32(pdev->dev.of_node, "clock-frequency",
-&clk_freq);
-
-   /* Only standard mode at 100kHz and fast mode at 400kHz
-* are supported.
-*/
-   if (clk_freq != 10 && clk_freq != 40) {
-   dev_err(&pdev->dev, "Only 100kHz and 400kHz supported");
-   return -EINVAL;
-   }
+   if ((pdata = dev_get_platdata(&pdev->dev))) {
+   clk_freq = pdata->i2c_scl_freq;
} else {
-   pdata = dev_get_platdata(&pdev->dev);
-   if (pdata)
-   clk_freq = pdata->i2c_scl_freq;
+   device_property_read_u32(&pdev->dev, "i2c-sda-hold-time-ns",
+&ht);
+   device_property_read_u32(&pdev->dev, "i2c-sda-falling-time-ns",
+&dev->sda_falling_time);
+   device_property_read_u32(&pdev->dev, "i2c-scl-falling-time-ns",
+&dev->scl_falling_time);
+   device_property_read_u32(&pdev->dev, "clock-frequency",
+&clk_freq);


Mika, Andy: Was this one able to go separately? At least it builds 
without rest of the set but is there anything that could break DT based 
system if there are no patches 1-8/13?


Acked-by: Jarkko Nikula 
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 13/13] i2c: designware: Convert to use unified device property API

2015-11-24 Thread Mika Westerberg
On Tue, Nov 24, 2015 at 12:53:06PM +0200, Jarkko Nikula wrote:
> Mika, Andy: Was this one able to go separately? At least it builds without
> rest of the set but is there anything that could break DT based system if
> there are no patches 1-8/13?

As far as I can tell this should not break existing DT systems but I
have not been able to test myself since I don't have any DT systems
here.

> Acked-by: Jarkko Nikula 

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 11/13] mfd: intel-lpss: Pass HSUART configuration via properties

2015-11-24 Thread Mika Westerberg
On Tue, Nov 24, 2015 at 06:44:53PM +0800, kbuild test robot wrote:
> Hi Mika,
> 
> [auto build test ERROR on v4.4-rc2]
> [also build test ERROR on next-20151124]
> [cannot apply to ljones-mfd/for-mfd-next]
> 
> url:
> https://github.com/0day-ci/linux/commits/Andy-Shevchenko/device-property-always-check-for-fwnode-type/20151124-183221
> config: x86_64-randconfig-x019-11241713 (attached as .config)
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64 
> 
> All error/warnings (new ones prefixed by >>):
> 
> >> drivers/mfd/intel-lpss-pci.c:68:30: error: array type has incomplete 
> >> element type 'struct property_entry'
> static struct property_entry uart_properties[] = {

Thanks kbuild robot!

This patch misses include of . It seems that it got
added by a subsequent patch which was not sent out.

We will fix this.
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/1] x86/platform/iosf_mbi: Remove duplicate definitions

2015-11-24 Thread Wolfram Sang
On Wed, Nov 11, 2015 at 07:59:29PM +0200, Andy Shevchenko wrote:
> The read and write opcodes are global for all units on SoC and even across
> Intel SoCs. Remove duplication of corresponding constants. At the same time
> convert all current users.
> 
> No functional change.
> 
> Cc: Thomas Gleixner 
> Cc: Ingo Molnar 
> Cc: Peter Anvin 
> Cc: Wolfram Sang 
> Cc: Zhang Rui 
> Cc: Eduardo Valentin 
> Cc: Hock Leong Kweh 
> 
> Signed-off-by: Andy Shevchenko 

For the I2C part:

Acked-by: Wolfram Sang 



signature.asc
Description: Digital signature


[PATCH 1/3] i2c: at91: add setting HOLD field of TWIHS_CWGR via DT

2015-11-24 Thread Ludovic Desroches
From: Wenyou Yang 

Add the HOLD field management. Some i2c devices need a longer data hold
time than the one given in the i2c bus specification. Since this value
depends on the i2c device connected to the bus, add a DT property to
configure it: "atmel,twd-hold-cycles".

Signed-off-by: Wenyou Yang 
Signed-off-by: Ludovic Desroches 
---
 drivers/i2c/busses/i2c-at91.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 10835d1..b3595ea 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -64,6 +64,7 @@
 #defineAT91_TWI_IADR   0x000c  /* Internal Address Register */
 
 #defineAT91_TWI_CWGR   0x0010  /* Clock Waveform Generator Reg 
*/
+#defineAT91_TWI_CWGR_HOLD(x)   (((x) & 0x1f) << 24)
 
 #defineAT91_TWI_SR 0x0020  /* Status Register */
 #defineAT91_TWI_TXCOMP BIT(0)  /* Transmission Complete */
@@ -185,7 +186,8 @@ static void at91_init_twi_bus(struct at91_twi_dev *dev)
  * Calculate symmetric clock as stated in datasheet:
  * twi_clk = F_MAIN / (2 * (cdiv * (1 << ckdiv) + offset))
  */
-static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
+static void at91_calc_twi_clock(struct at91_twi_dev *dev,
+   int twi_clk, u32 twd_hold)
 {
int ckdiv, cdiv, div;
struct at91_twi_pdata *pdata = dev->pdata;
@@ -204,7 +206,9 @@ static void at91_calc_twi_clock(struct at91_twi_dev *dev, 
int twi_clk)
cdiv = 255;
}
 
-   dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv;
+   dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv
+   | AT91_TWI_CWGR_HOLD(twd_hold);
+
dev_dbg(dev->dev, "cdiv %d ckdiv %d\n", cdiv, ckdiv);
 }
 
@@ -994,6 +998,7 @@ static int at91_twi_probe(struct platform_device *pdev)
int rc;
u32 phy_addr;
u32 bus_clk_rate;
+   u32 twd_hold_cycles = 0;
 
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -1050,7 +1055,10 @@ static int at91_twi_probe(struct platform_device *pdev)
if (rc)
bus_clk_rate = DEFAULT_TWI_CLK_HZ;
 
-   at91_calc_twi_clock(dev, bus_clk_rate);
+   of_property_read_u32(dev->dev->of_node, "atmel,twd-hold-cycles",
+&twd_hold_cycles);
+
+   at91_calc_twi_clock(dev, bus_clk_rate, twd_hold_cycles);
at91_init_twi_bus(dev);
 
snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] i2c: at91: add DT property "atmel,twd-hold-cycles" to binding

2015-11-24 Thread Ludovic Desroches
From: Wenyou Yang 

Add a DT property "atmel,twd-hold-cycles" to specify the HOLD
filed of TWIHS_CWGR register to increase the TWD hold time.

Signed-off-by: Wenyou Yang 
Signed-off-by: Ludovic Desroches 
---
 Documentation/devicetree/bindings/i2c/i2c-at91.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt 
b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
index 6e81dc1..c81a0cb 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
@@ -17,6 +17,9 @@ Optional properties:
 - dma-names: should contain "tx" and "rx".
 - atmel,fifo-size: maximum number of data the RX and TX FIFOs can store for 
FIFO
   capable I2C controllers.
+- atmel,twd-hold-cycles: number of cycles for TWD hold time whose value is
+  determinated by (atmel,twd-hold-cycles + 3) x t_peripheral_clock,
+  maximum value is 0x1f.
 - Child nodes conforming to i2c bus binding
 
 Examples :
@@ -29,6 +32,7 @@ i2c0: i2c@fff84000 {
#size-cells = <0>;
clocks = <&twi0_clk>;
clock-frequency = <40>;
+   atmel,twd-hold-cycles = <2>;
 
24c512@50 {
compatible = "24c512";
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] ARM: dts: at91: specify DT property "atmel,twd-hold-cycles"

2015-11-24 Thread Ludovic Desroches
From: Wenyou Yang 

Specify the device tree property "atmel,twd-hold-cycles" to 25
to adapt to the PMIC ACT8945A.

Signed-off-by: Wenyou Yang 
---
 arch/arm/boot/dts/at91-sama5d2_xplained.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/at91-sama5d2_xplained.dts 
b/arch/arm/boot/dts/at91-sama5d2_xplained.dts
index ad6de73..25ffd86 100644
--- a/arch/arm/boot/dts/at91-sama5d2_xplained.dts
+++ b/arch/arm/boot/dts/at91-sama5d2_xplained.dts
@@ -129,6 +129,7 @@
dmas = <0>, <0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c0_default>;
+   atmel,twd-hold-cycles = <25>;
status = "okay";
 
pmic: act8865@5b {
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 03/13] device property: refactor built-in properties support

2015-11-24 Thread Rafael J. Wysocki
On Tuesday, November 24, 2015 12:22:49 PM Andy Shevchenko wrote:
> Instead of using the type and nval fields we will use length (in bytes) of the
> value. The sanity check is done in the accessors.
> 
> The built-in property accessors are split in the same way such as device tree.

Do I understand correctly that this is indended to make the built-in properties
follow the DT layout?

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 03/13] device property: refactor built-in properties support

2015-11-24 Thread Andy Shevchenko
On Tue, 2015-11-24 at 15:37 +0100, Rafael J. Wysocki wrote:
> On Tuesday, November 24, 2015 12:22:49 PM Andy Shevchenko wrote:
> > Instead of using the type and nval fields we will use length (in
> > bytes) of the
> > value. The sanity check is done in the accessors.
> > 
> > The built-in property accessors are split in the same way such as
> > device tree.
> 
> Do I understand correctly that this is indended to make the built-in
> properties
> follow the DT layout?

Correct.

> 
> Thanks,
> Rafael
> 

-- 
Andy Shevchenko 
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 00/13] intel-lpss: support non-ACPI platforms

2015-11-24 Thread Rafael J. Wysocki
On Tuesday, November 24, 2015 12:22:46 PM Andy Shevchenko wrote:
> This series includes few logical sets that bring a support of non-ACPI
> platforms for Intel Skylake.
> 
> First part is a refactoring of built-in device properties support:
>  - keep single value inside the structure
>  - provide helper macros to define built-in properties
>  - fall back to secondary fwnode if primary has no asked property
> 
> Second one is modifications to MFD code and intel-lpss.c driver in particular
> to define and pass built-in properties to the individual drivers.
> 
> Last part is a fix for I2C bug found on Lenovo Yoga hardware and a first
> converted user.
> 
> Built-in device properties is an alternative to platform data. It provides a
> unified API that drivers can use to cover all cases at once: DT, ACPI, and
> built-in properties.
> 
> With this series applied platform data can be considered obsolete. Moreover,
> built-in device properties allows to adjust existing configuration, for
> example, in cases when ACPI values are wrong on some platforms.
> 
> The series has been tested on available hardware and doesn't break current
> behaviour. But we ask you, Kevin, to apply the series on your side and check
> with Lenovo hardware.
> 
> Andy Shevchenko (8):
>   device property: always check for fwnode type
>   device property: rename helper functions
>   device property: refactor built-in properties support
>   device property: keep single value inplace
>   device property: improve readability of macros
>   device property: return -EINVAL when property isn't found in ACPI
>   device property: Fallback to secondary fwnode if primary misses the
> property
>   mfd: core: propagate device properties to sub devices drivers
> 
> Heikki Krogerus (1):
>   device property: helper macros for property entry creation
> 
> Mika Westerberg (4):
>   mfd: intel-lpss: Add support for passing device properties
>   mfd: intel-lpss: Pass HSUART configuration via properties
>   mfd: intel-lpss: Pass SDA hold time to I2C host controller driver
>   i2c: designware: Convert to use unified device property API
> 
>  drivers/acpi/property.c |  10 +-
>  drivers/base/property.c | 298 
> +---
>  drivers/i2c/busses/i2c-designware-platdrv.c |  48 ++---
>  drivers/mfd/intel-lpss-acpi.c   |  18 +-
>  drivers/mfd/intel-lpss-pci.c|  43 +++-
>  drivers/mfd/intel-lpss.c|  16 +-
>  drivers/mfd/intel-lpss.h|   2 +
>  drivers/mfd/mfd-core.c  |   3 +
>  include/linux/mfd/core.h|   5 +
>  include/linux/property.h|  87 ++--
>  10 files changed, 394 insertions(+), 136 deletions(-)

All patches in this series look good to me overall, but please fix the build
problems reported by 0-day and resubmit.

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 00/13] intel-lpss: support non-ACPI platforms

2015-11-24 Thread Andy Shevchenko
On Tue, 2015-11-24 at 16:11 +0100, Rafael J. Wysocki wrote:
> On Tuesday, November 24, 2015 12:22:46 PM Andy Shevchenko wrote:
> > This series includes few logical sets that bring a support of non-
> > ACPI
> > platforms for Intel Skylake.
> > 
> > First part is a refactoring of built-in device properties support:
> >  - keep single value inside the structure
> >  - provide helper macros to define built-in properties
> >  - fall back to secondary fwnode if primary has no asked property
> > 
> > Second one is modifications to MFD code and intel-lpss.c driver in
> > particular
> > to define and pass built-in properties to the individual drivers.
> > 
> > Last part is a fix for I2C bug found on Lenovo Yoga hardware and a
> > first
> > converted user.
> > 
> > Built-in device properties is an alternative to platform data. It
> > provides a
> > unified API that drivers can use to cover all cases at once: DT,
> > ACPI, and
> > built-in properties.
> > 
> > With this series applied platform data can be considered obsolete.
> > Moreover,
> > built-in device properties allows to adjust existing configuration,
> > for
> > example, in cases when ACPI values are wrong on some platforms.
> > 
> > The series has been tested on available hardware and doesn't break
> > current
> > behaviour. But we ask you, Kevin, to apply the series on your side
> > and check
> > with Lenovo hardware.
> > 
> > Andy Shevchenko (8):
> >   device property: always check for fwnode type
> >   device property: rename helper functions
> >   device property: refactor built-in properties support
> >   device property: keep single value inplace
> >   device property: improve readability of macros
> >   device property: return -EINVAL when property isn't found in ACPI
> >   device property: Fallback to secondary fwnode if primary misses
> > the
> > property
> >   mfd: core: propagate device properties to sub devices drivers
> > 
> > Heikki Krogerus (1):
> >   device property: helper macros for property entry creation
> > 
> > Mika Westerberg (4):
> >   mfd: intel-lpss: Add support for passing device properties
> >   mfd: intel-lpss: Pass HSUART configuration via properties
> >   mfd: intel-lpss: Pass SDA hold time to I2C host controller driver
> >   i2c: designware: Convert to use unified device property API
> > 
> >  drivers/acpi/property.c |  10 +-
> >  drivers/base/property.c | 298
> > +---
> >  drivers/i2c/busses/i2c-designware-platdrv.c |  48 ++---
> >  drivers/mfd/intel-lpss-acpi.c   |  18 +-
> >  drivers/mfd/intel-lpss-pci.c|  43 +++-
> >  drivers/mfd/intel-lpss.c|  16 +-
> >  drivers/mfd/intel-lpss.h|   2 +
> >  drivers/mfd/mfd-core.c  |   3 +
> >  include/linux/mfd/core.h|   5 +
> >  include/linux/property.h|  87 ++--
> >  10 files changed, 394 insertions(+), 136 deletions(-)
> 
> All patches in this series look good to me overall, but please fix
> the build
> problems reported by 0-day and resubmit.

Thanks for fast response. We will do that later this week while
gathering comments from others.



> Thanks,
> Rafael
> 

-- 
Andy Shevchenko 
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Handling clocks on external busses

2015-11-24 Thread Charles Keepax
Hi,

When a clock driver is controlling a clock that is controlled
over I2C / SPI, we need to perform a write on that bus to enable
the clock. However, such busses often have their own clocks that
must be enabled. Since all clock prepares are controlled under
one large mutex this easily causes deadlock. The device is
waiting for the I2C / SPI write to complete and the I2C / SPI
driver is waiting for the clock prepare lock to be released so it
can enable its own clock.

I have had a bit of a search and it seems the only really advice
kicking about is that all I2C / SPI drivers should leave the
clock prepared all the time. Is that intended to be the long term
solution, should I treat not leaving the clock prepared as a bug?

Thanks,
Charles
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 11/13] mfd: intel-lpss: Pass HSUART configuration via properties

2015-11-24 Thread Arnd Bergmann
On Tuesday 24 November 2015 12:22:57 Andy Shevchenko wrote:
> +static struct property_entry uart_properties[] = {
> +   PROPERTY_ENTRY_U32("reg-io-width", 4),
> +   PROPERTY_ENTRY_U32("reg-shift", 2),
> +   PROPERTY_ENTRY_U8("snps,uart-16550-compatible", 1),
> +   { },
> 

If I read the binding correctly, the "snps,uart-16550-compatible" property
is meant to be boolean, meaning true if present and zero-length or false
if absent. Using a u8 propert instead feels wrong.

Maybe we can have a PROPERTY_ENTRY_BOOL() for that?

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 00/13] intel-lpss: support non-ACPI platforms

2015-11-24 Thread Arnd Bergmann
On Tuesday 24 November 2015 12:22:46 Andy Shevchenko wrote:
> This series includes few logical sets that bring a support of non-ACPI
> platforms for Intel Skylake.
> 
> First part is a refactoring of built-in device properties support:
>  - keep single value inside the structure
>  - provide helper macros to define built-in properties
>  - fall back to secondary fwnode if primary has no asked property
> 
> Second one is modifications to MFD code and intel-lpss.c driver in particular
> to define and pass built-in properties to the individual drivers.
> 
> Last part is a fix for I2C bug found on Lenovo Yoga hardware and a first
> converted user.
> 
> Built-in device properties is an alternative to platform data. It provides a
> unified API that drivers can use to cover all cases at once: DT, ACPI, and
> built-in properties.
> 
> With this series applied platform data can be considered obsolete. Moreover,
> built-in device properties allows to adjust existing configuration, for
> example, in cases when ACPI values are wrong on some platforms.
> 
> The series has been tested on available hardware and doesn't break current
> behaviour. But we ask you, Kevin, to apply the series on your side and check
> with Lenovo hardware.

I agree with Rafael, this looks really nice. I found one small thing that
could be improved, see the comment on patch 11.

Aside from that, I think we should have a nicer way to pass a property
list through platform_device_info when calling
platform_device_register_full(). You don't do that here because the drivers
you change are based on MFD cells rather than direct platform devices,
but it would fit in the series and should be easy enough to do.

I don't know why Rafael didn't do that for the initial series already, maybe
he had a good reason.

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1 00/13] intel-lpss: support non-ACPI platforms

2015-11-24 Thread Rafael J. Wysocki
On Tue, Nov 24, 2015 at 9:00 PM, Arnd Bergmann  wrote:
> On Tuesday 24 November 2015 12:22:46 Andy Shevchenko wrote:
>> This series includes few logical sets that bring a support of non-ACPI
>> platforms for Intel Skylake.
>>
>> First part is a refactoring of built-in device properties support:
>>  - keep single value inside the structure
>>  - provide helper macros to define built-in properties
>>  - fall back to secondary fwnode if primary has no asked property
>>
>> Second one is modifications to MFD code and intel-lpss.c driver in particular
>> to define and pass built-in properties to the individual drivers.
>>
>> Last part is a fix for I2C bug found on Lenovo Yoga hardware and a first
>> converted user.
>>
>> Built-in device properties is an alternative to platform data. It provides a
>> unified API that drivers can use to cover all cases at once: DT, ACPI, and
>> built-in properties.
>>
>> With this series applied platform data can be considered obsolete. Moreover,
>> built-in device properties allows to adjust existing configuration, for
>> example, in cases when ACPI values are wrong on some platforms.
>>
>> The series has been tested on available hardware and doesn't break current
>> behaviour. But we ask you, Kevin, to apply the series on your side and check
>> with Lenovo hardware.
>
> I agree with Rafael, this looks really nice. I found one small thing that
> could be improved, see the comment on patch 11.
>
> Aside from that, I think we should have a nicer way to pass a property
> list through platform_device_info when calling
> platform_device_register_full(). You don't do that here because the drivers
> you change are based on MFD cells rather than direct platform devices,
> but it would fit in the series and should be easy enough to do.
>
> I don't know why Rafael didn't do that for the initial series already, maybe
> he had a good reason.

I was focusing on the generics rather than on any particular
individual bus type.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html