[PATCH] staging: olpc_dcon: add a missing dependency

2018-09-18 Thread Lubomir Rintel
  WARNING: unmet direct dependencies detected for BACKLIGHT_CLASS_DEVICE
Depends on [n]: HAS_IOMEM [=y] && BACKLIGHT_LCD_SUPPORT [=n]
Selected by [y]:
- FB_OLPC_DCON [=y] && STAGING [=y] && X86 [=y] && OLPC [=y] && FB [=y]
&& I2C [=y] && (GPIO_CS5535 [=n] || GPIO_CS5535 [=n]=n)

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/olpc_dcon/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/olpc_dcon/Kconfig 
b/drivers/staging/olpc_dcon/Kconfig
index c91a56f77bcb..192cc8d0853f 100644
--- a/drivers/staging/olpc_dcon/Kconfig
+++ b/drivers/staging/olpc_dcon/Kconfig
@@ -2,6 +2,7 @@ config FB_OLPC_DCON
tristate "One Laptop Per Child Display CONtroller support"
depends on OLPC && FB
depends on I2C
+   depends on BACKLIGHT_LCD_SUPPORT
depends on (GPIO_CS5535 || GPIO_CS5535=n)
select BACKLIGHT_CLASS_DEVICE
help
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/15] Revert "platform/olpc: Make ec explicitly non-modular"

2018-10-10 Thread Lubomir Rintel
It doesn't make sense to always have this built-in, e.g. on ARM
multiplatform kernels. A better way to address the problem the original
commit aimed to solve is to fix Kconfig.

This reverts commit f48d1496b8537d75776478c6942dd87f34d7f270.

Signed-off-by: Lubomir Rintel 
---
 drivers/platform/olpc/olpc-ec.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 374a8028fec7..f99b183d5296 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -1,8 +1,6 @@
 /*
  * Generic driver for the OLPC Embedded Controller.
  *
- * Author: Andres Salomon 
- *
  * Copyright (C) 2011-2012 One Laptop per Child Foundation.
  *
  * Licensed under the GPL v2 or later.
@@ -14,7 +12,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -328,4 +326,8 @@ static int __init olpc_ec_init_module(void)
 {
return platform_driver_register(&olpc_ec_plat_driver);
 }
+
 arch_initcall(olpc_ec_init_module);
+
+MODULE_AUTHOR("Andres Salomon ");
+MODULE_LICENSE("GPL");
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/15] Add support for OLPC XO 1.75 Embedded Controller

2018-10-10 Thread Lubomir Rintel
Hi.

This patchset adds support for the Embedded Controller on an OLPC XO
1.75 machine. OLPC XO 1.75 is a MMP2 based ARM laptop. It plugs into
the existing OLPC platform infrastructure, currently used by the x86
based models.

The EC operates in SPI master mode, meaning the SOC is the SPI slave. It
uses extra handshake signal to signal readiness of SOC to accept data
from EC and to initiate a transaction if SOC wishes to submit data.

The SPI slave support for MMP2 was submitted separately:
https://lore.kernel.org/lkml/20181010170936.316862-1-lkund...@v3.sk/T/#t

THe "power: supply: olpc_battery: correct the temperature" patch was
already sent out separately, but I'm including it because the last
commit of the set depends on it.

Tested to work on an OLPC XO 1.75 and also tested not to break x86
support with an OLPC XO 1 machine. I don't have a XO 1.5, but it's
unlikely this breaks it when XO 1 works.

Thanks in advance for reviews and feedback of any kind.

Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/15] dt-bindings: olpc, xo1.75-ec: Add OLPC XO-1.75 EC bindings

2018-10-10 Thread Lubomir Rintel
The OLPC XO-1.75 Embedded Controller is a SPI master that uses extra
signals for handshaking. It needs to know when is the slave (Linux)
side's TX FIFO ready for transfer (the ready-gpio signal on the SPI
controller node) and when does it wish to respond with a command (the
cmd-gpio property).

Signed-off-by: Lubomir Rintel 
---
 .../bindings/misc/olpc,xo1.75-ec.txt  | 24 +++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt

diff --git a/Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt 
b/Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt
new file mode 100644
index ..14385fee65d2
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt
@@ -0,0 +1,24 @@
+OLPC XO-1.75 Embedded Controller
+
+Required properties:
+- compatible: Should be "olpc,xo1.75-ec".
+- cmd-gpio: gpio specifier of the CMD pin
+
+The embedded controller requires the SPI controller driver to signal readiness
+to receive a transfer (that is, when TX FIFO contains the response data) by
+strobing the ACK pin with the ready signal. See the "ready-gpio" property of 
the
+SSP binding as documented in:
+.
+
+Example:
+   &ssp3 {
+   spi-slave;
+   status = "okay";
+   ready-gpio = <&gpio 125 GPIO_ACTIVE_HIGH>;
+
+   slave {
+   compatible = "olpc,xo1.75-ec";
+   spi-cpha;
+   cmd-gpio = <&gpio 155 GPIO_ACTIVE_HIGH>;
+   };
+   };
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/15] Platform: OLPC: Remove an unused include

2018-10-10 Thread Lubomir Rintel
Also, the header is x86 specific, while there are non-x86 OLPC machines.

Signed-off-by: Lubomir Rintel 
---
 drivers/platform/olpc/olpc-ec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index f99b183d5296..35a21c66cd0d 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 #include 
-#include 
 
 struct ec_cmd_desc {
u8 cmd;
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/15] dt-bindings: olpc_battery: Add XO-1.5 battery

2018-10-10 Thread Lubomir Rintel
The XO-1 and XO-1.5 batteries apparently differ in an ability to report
ambient temperature.

Signed-off-by: Lubomir Rintel 
---
 Documentation/devicetree/bindings/power/supply/olpc_battery.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/power/supply/olpc_battery.txt 
b/Documentation/devicetree/bindings/power/supply/olpc_battery.txt
index c8901b3992d9..8d87d6b35a98 100644
--- a/Documentation/devicetree/bindings/power/supply/olpc_battery.txt
+++ b/Documentation/devicetree/bindings/power/supply/olpc_battery.txt
@@ -2,4 +2,4 @@ OLPC battery
 
 
 Required properties:
-  - compatible : "olpc,xo1-battery"
+  - compatible : "olpc,xo1-battery" or "olpc,xo1.5-battery"
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/15] power: supply: olpc_battery: correct the temperature units

2018-10-10 Thread Lubomir Rintel
According to [1] and [2], the temperature values are in tenths of degree
Celsius. Exposing the Celsius value makes the battery appear on fire:

  $ upower -i /org/freedesktop/UPower/devices/battery_olpc_battery
  ...
  temperature: 236.9 degrees C

Tested on OLPC XO-1 and OLPC XO-1.75 laptops.

[1] include/linux/power_supply.h
[2] Documentation/power/power_supply_class.txt

Cc: sta...@vger.kernel.org
Signed-off-by: Lubomir Rintel 
---
 drivers/power/supply/olpc_battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 6da79ae14860..5a97e42a3547 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -428,14 +428,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 100 / 256;
+   val->intval = (s16)be16_to_cpu(ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
 
-   val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
+   val->intval = (int)be16_to_cpu(ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/15] Platform: OLPC: Move OLPC config symbol out of x86 tree

2018-10-10 Thread Lubomir Rintel
There are ARM OLPC machines that use mostly the same drivers, including
EC infrastructure, DCON and Battery.

While at that, fix Kconfig to allow building this as a module.

Signed-off-by: Lubomir Rintel 
---
 arch/x86/Kconfig  | 11 ---
 drivers/input/mouse/Kconfig   |  2 +-
 drivers/platform/Kconfig  |  2 ++
 drivers/platform/olpc/Kconfig | 11 +++
 drivers/staging/olpc_dcon/Kconfig |  2 +-
 5 files changed, 15 insertions(+), 13 deletions(-)
 create mode 100644 drivers/platform/olpc/Kconfig

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1a0be022f91d..be6af341a718 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2729,17 +2729,6 @@ config SCx200HR_TIMER
  processor goes idle (as is done by the scheduler).  The
  other workaround is idle=poll boot option.
 
-config OLPC
-   bool "One Laptop Per Child support"
-   depends on !X86_PAE
-   select GPIOLIB
-   select OF
-   select OF_PROMTREE
-   select IRQ_DOMAIN
-   ---help---
- Add support for detecting the unique features of the OLPC
- XO hardware.
-
 config OLPC_XO1_PM
bool "OLPC XO-1 Power Management"
depends on OLPC && MFD_CS5535 && PM_SLEEP
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 566a1e3aa504..58034892a4df 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -165,7 +165,7 @@ config MOUSE_PS2_TOUCHKIT
 
 config MOUSE_PS2_OLPC
bool "OLPC PS/2 mouse protocol extension"
-   depends on MOUSE_PS2 && OLPC
+   depends on MOUSE_PS2 && X86 && OLPC
help
  Say Y here if you have an OLPC XO-1 laptop (with built-in
  PS/2 touchpad/tablet device).  The manufacturer calls the
diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
index d4c2e424a700..4313d73d3618 100644
--- a/drivers/platform/Kconfig
+++ b/drivers/platform/Kconfig
@@ -10,3 +10,5 @@ source "drivers/platform/goldfish/Kconfig"
 source "drivers/platform/chrome/Kconfig"
 
 source "drivers/platform/mellanox/Kconfig"
+
+source "drivers/platform/olpc/Kconfig"
diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfig
new file mode 100644
index ..7b736c9e67ac
--- /dev/null
+++ b/drivers/platform/olpc/Kconfig
@@ -0,0 +1,11 @@
+config OLPC
+   tristate "One Laptop Per Child support"
+   depends on X86 || ARM || COMPILE_TEST
+   depends on !X86_PAE
+   select GPIOLIB
+   select OF
+   select OF_PROMTREE if X86
+   select IRQ_DOMAIN
+   help
+ Add support for detecting the unique features of the OLPC
+ XO hardware.
diff --git a/drivers/staging/olpc_dcon/Kconfig 
b/drivers/staging/olpc_dcon/Kconfig
index c91a56f77bcb..07f9f1de8667 100644
--- a/drivers/staging/olpc_dcon/Kconfig
+++ b/drivers/staging/olpc_dcon/Kconfig
@@ -1,6 +1,6 @@
 config FB_OLPC_DCON
tristate "One Laptop Per Child Display CONtroller support"
-   depends on OLPC && FB
+   depends on X86 && OLPC && FB
depends on I2C
depends on (GPIO_CS5535 || GPIO_CS5535=n)
select BACKLIGHT_CLASS_DEVICE
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/15] power: supply: olpc_battery: Use DT to get battery version

2018-10-10 Thread Lubomir Rintel
Avoid using the x86 OLPC platform specific call to get the board
version. It won't work on FDT-based ARM MMP2 platform.

Signed-off-by: Lubomir Rintel 
---
 drivers/power/supply/olpc_battery.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 5a97e42a3547..540d44bf536f 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 
@@ -622,11 +623,13 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
if (IS_ERR(olpc_ac))
return PTR_ERR(olpc_ac);
-
-   if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
+   if (of_property_match_string(pdev->dev.of_node, "compatible",
+   "olpc,xo1.5-battery") >= 0) {
+   /* XO-1.5 */
olpc_bat_desc.properties = olpc_xo15_bat_props;
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo15_bat_props);
-   } else { /* XO-1 */
+   } else {
+   /* XO-1 */
olpc_bat_desc.properties = olpc_xo1_bat_props;
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
}
@@ -672,6 +675,7 @@ static int olpc_battery_remove(struct platform_device *pdev)
 
 static const struct of_device_id olpc_battery_ids[] = {
{ .compatible = "olpc,xo1-battery" },
+   { .compatible = "olpc,xo1.5-battery" },
{}
 };
 MODULE_DEVICE_TABLE(of, olpc_battery_ids);
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 14/15] power: supply: olpc_battery: Avoid using platform_info

2018-10-10 Thread Lubomir Rintel
This wouldn't work on the DT-based ARM platform. Let's read the EC version
directly from the EC driver instead.

This makes the driver no longer x86 specific.

Signed-off-by: Lubomir Rintel 
---
 drivers/power/supply/Kconfig|  2 +-
 drivers/power/supply/olpc_battery.c | 35 +
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index ff6dab0bf0dd..f0361e4dd457 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -151,7 +151,7 @@ config BATTERY_PMU
 
 config BATTERY_OLPC
tristate "One Laptop Per Child battery"
-   depends on X86_32 && OLPC
+   depends on OLPC
help
  Say Y to enable support for the battery on the OLPC laptop.
 
diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 2a2d7cc995f0..dde9863e5c4a 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -20,8 +20,6 @@
 #include 
 #include 
 #include 
-#include 
-
 
 #define EC_BAT_VOLTAGE 0x10/* uint16_t,*9.76/32,mV   */
 #define EC_BAT_CURRENT 0x11/* int16_t, *15.625/120, mA   */
@@ -57,6 +55,7 @@ struct olpc_battery_data {
struct power_supply *olpc_ac;
struct power_supply *olpc_bat;
char bat_serial[17];
+   int new_proto;
 };
 
 /*
@@ -100,7 +99,7 @@ static const struct power_supply_desc olpc_ac_desc = {
 static int olpc_bat_get_status(struct olpc_battery_data *data,
union power_supply_propval *val, uint8_t ec_byte)
 {
-   if (olpc_platform_info.ecver > 0x44) {
+   if (data->new_proto) {
if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else if (ec_byte & BAT_STAT_DISCHARGING)
@@ -608,14 +607,32 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
struct power_supply_config psy_cfg = {};
struct olpc_battery_data *data;
uint8_t status;
+   unsigned char ecver[1];
+   int ret;
+
+   data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+   platform_set_drvdata(pdev, data);
+
+   /* See if the EC is already there and get the EC revision */
+   ret = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, ecver, ARRAY_SIZE(ecver));
+   if (ret) {
+   if (ret == -ENODEV)
+   return -EPROBE_DEFER;
+   return ret;
+   }
 
-   /*
-* We've seen a number of EC protocol changes; this driver requires
-* the latest EC protocol, supported by 0x44 and above.
-*/
-   if (olpc_platform_info.ecver < 0x44) {
+   if (ecver[0] > 0x44) {
+   /* XO 1 or 1.5 with a new EC firmware. */
+   data->new_proto = 1;
+   } else if (ecver[0] < 0x44) {
+   /*
+* We've seen a number of EC protocol changes; this driver
+* requires the latest EC protocol, supported by 0x44 and above.
+*/
printk(KERN_NOTICE "OLPC EC version 0x%02x too old for "
-   "battery driver.\n", olpc_platform_info.ecver);
+   "battery driver.\n", ecver[0]);
return -ENXIO;
}
 
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/15] Platform: OLPC: Avoid a warning if the EC didn't register yet

2018-10-10 Thread Lubomir Rintel
Just return ENODEV, so that whoever attempted to use the EC call can
defer their work.

Signed-off-by: Lubomir Rintel 
---
 drivers/platform/olpc/olpc-ec.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 35a21c66cd0d..342f5bb7f7a8 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -116,8 +116,11 @@ int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 
*outbuf, size_t outlen)
struct olpc_ec_priv *ec = ec_priv;
struct ec_cmd_desc desc;
 
-   /* Ensure a driver and ec hook have been registered */
-   if (WARN_ON(!ec_driver || !ec_driver->ec_cmd))
+   /* Driver not yet registered. */
+   if (!ec_driver)
+   return -ENODEV;
+
+   if (WARN_ON(!ec_driver->ec_cmd))
return -ENODEV;
 
if (!ec)
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/15] Platform: OLPC: add a regulator for the DCON

2018-10-10 Thread Lubomir Rintel
All OLPC ECs are able to turn the power to the DCON on an off. Use the
regulator framework to expose the functionality.

Signed-off-by: Lubomir Rintel 
---
 drivers/platform/olpc/Kconfig   |  1 +
 drivers/platform/olpc/olpc-ec.c | 65 +
 2 files changed, 66 insertions(+)

diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfig
index 7c643d24ad0f..c5a872fb286f 100644
--- a/drivers/platform/olpc/Kconfig
+++ b/drivers/platform/olpc/Kconfig
@@ -6,6 +6,7 @@ config OLPC
select OF
select OF_PROMTREE if X86
select IRQ_DOMAIN
+   select REGULATOR
help
  Add support for detecting the unique features of the OLPC
  XO hardware.
diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index b9d9a9897dd5..8f82922631a9 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 struct ec_cmd_desc {
@@ -34,6 +35,10 @@ struct olpc_ec_priv {
struct work_struct worker;
struct mutex cmd_lock;
 
+   /* DCON regulator */
+   struct regulator_dev *dcon_rdev;
+   bool dcon_enabled;
+
/* Pending EC commands */
struct list_head cmd_q;
spinlock_t cmd_q_lock;
@@ -347,9 +352,60 @@ static struct dentry *olpc_ec_setup_debugfs(void)
 
 #endif /* CONFIG_DEBUG_FS */
 
+static int olpc_ec_set_dcon_power(struct olpc_ec_priv *ec, bool state)
+{
+   unsigned char ec_byte = state;
+   int ret;
+
+   if (ec->dcon_enabled == state)
+   return 0;
+
+   ret = olpc_ec_cmd(EC_DCON_POWER_MODE, &ec_byte, 1, NULL, 0);
+   if (ret == 0)
+   ec->dcon_enabled = state;
+
+   return ret;
+}
+
+static int dcon_regulator_enable(struct regulator_dev *rdev)
+{
+   struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
+
+   return olpc_ec_set_dcon_power(ec, 1);
+}
+
+static int dcon_regulator_disable(struct regulator_dev *rdev)
+{
+   struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
+
+   return olpc_ec_set_dcon_power(ec, 0);
+}
+
+static int dcon_regulator_is_enabled(struct regulator_dev *rdev)
+{
+   struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
+
+   return ec->dcon_enabled;
+}
+
+static struct regulator_ops dcon_regulator_ops = {
+   .enable = dcon_regulator_enable,
+   .disable= dcon_regulator_disable,
+   .is_enabled = dcon_regulator_is_enabled,
+};
+
+static const struct regulator_desc dcon_desc = {
+   .name   = "dcon",
+   .id = 0,
+   .ops= &dcon_regulator_ops,
+   .type   = REGULATOR_VOLTAGE,
+   .owner  = THIS_MODULE,
+};
+
 static int olpc_ec_probe(struct platform_device *pdev)
 {
struct olpc_ec_priv *ec;
+   struct regulator_config config = { };
int err;
 
if (!ec_driver)
@@ -378,6 +434,15 @@ static int olpc_ec_probe(struct platform_device *pdev)
return err;
}
 
+   config.dev = pdev->dev.parent;
+   config.driver_data = ec;
+   ec->dcon_enabled = true;
+   ec->dcon_rdev = devm_regulator_register(&pdev->dev, &dcon_desc, 
&config);
+   if (IS_ERR(ec->dcon_rdev)) {
+   dev_err(&pdev->dev, "failed to register DCON regulator\n");
+   return PTR_ERR(ec->dcon_rdev);
+   }
+
ec->dbgfs_dir = olpc_ec_setup_debugfs();
 
return err;
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/15] x86, olpc: Use a correct version when making up a battery node

2018-10-10 Thread Lubomir Rintel
The XO-1 and XO-1.5 batteries apparently differ in an ability to report
ambient temperature. Add a different compatible string to the 1.5
battery.

Signed-off-by: Lubomir Rintel 
---
 arch/x86/platform/olpc/olpc_dt.c | 59 +++-
 1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
index d6ee92986920..6e54e116b0c5 100644
--- a/arch/x86/platform/olpc/olpc_dt.c
+++ b/arch/x86/platform/olpc/olpc_dt.c
@@ -218,10 +218,28 @@ static u32 __init olpc_dt_get_board_revision(void)
return be32_to_cpu(rev);
 }
 
-void __init olpc_dt_fixup(void)
+int olpc_dt_compatible_match(phandle node, const char *compat)
 {
-   int r;
char buf[64];
+   int plen;
+   char *p;
+   int len;
+
+   plen = olpc_dt_getproperty(node, "compatible", buf, sizeof(buf));
+   if (plen <= 0)
+   return 0;
+
+   len = strlen(compat);
+   for (p = buf; p < buf + plen; p += strlen(p) + 1) {
+   if (strcmp(p, compat) == 0)
+   return 1;
+   }
+
+   return 0;
+}
+
+void __init olpc_dt_fixup(void)
+{
phandle node;
u32 board_rev;
 
@@ -229,32 +247,33 @@ void __init olpc_dt_fixup(void)
if (!node)
return;
 
-   /*
-* If the battery node has a compatible property, we are running a new
-* enough firmware and don't have fixups to make.
-*/
-   r = olpc_dt_getproperty(node, "compatible", buf, sizeof(buf));
-   if (r > 0)
-   return;
-
-   pr_info("PROM DT: Old firmware detected, applying fixes\n");
-
-   /* Add olpc,xo1-battery compatible marker to battery node */
-   olpc_dt_interpret("\" /battery@0\" find-device"
-   " \" olpc,xo1-battery\" +compatible"
-   " device-end");
-
board_rev = olpc_dt_get_board_revision();
if (!board_rev)
return;
 
if (board_rev >= olpc_board_pre(0xd0)) {
+   if (olpc_dt_compatible_match(node, "olpc,xo1.5-battery"))
+   return;
+
+   /* Add olpc,xo1.5-battery compatible marker to battery node */
+   olpc_dt_interpret("\" /battery@0\" find-device"
+   " \" olpc,xo1.5-battery\" +compatible"
+   " device-end");
+
+   /* We're running a very old firmware if this is missing. */
+   if (olpc_dt_compatible_match(node, "olpc,xo1-battery"))
+   return;
+
/* XO-1.5: add dcon device */
olpc_dt_interpret("\" /pci/display@1\" find-device"
" new-device"
" \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
" finish-device device-end");
} else {
+   /* We're running a very old firmware if this is missing. */
+   if (olpc_dt_compatible_match(node, "olpc,xo1-battery"))
+   return;
+
/* XO-1: add dcon device, mark RTC as olpc,xo1-rtc */
olpc_dt_interpret("\" /pci/display@1,1\" find-device"
" new-device"
@@ -264,6 +283,11 @@ void __init olpc_dt_fixup(void)
" \" olpc,xo1-rtc\" +compatible"
" device-end");
}
+
+   /* Add olpc,xo1-battery compatible marker to battery node */
+   olpc_dt_interpret("\" /battery@0\" find-device"
+   " \" olpc,xo1-battery\" +compatible"
+   " device-end");
 }
 
 void __init olpc_dt_build_devicetree(void)
@@ -289,6 +313,7 @@ void __init olpc_dt_build_devicetree(void)
 /* A list of DT node/bus matches that we want to expose as platform devices */
 static struct of_device_id __initdata of_ids[] = {
{ .compatible = "olpc,xo1-battery" },
+   { .compatible = "olpc,xo1.5-battery" },
{ .compatible = "olpc,xo1-dcon" },
{ .compatible = "olpc,xo1-rtc" },
{},
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/15] power: supply: olpc_battery: Move priv data to a struct

2018-10-10 Thread Lubomir Rintel
The global variables for private data are not too nice. I'd like some
more, and that would clutter the global name space even further.

Signed-off-by: Lubomir Rintel 
---
 drivers/power/supply/olpc_battery.c | 73 +++--
 1 file changed, 38 insertions(+), 35 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 540d44bf536f..2a2d7cc995f0 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -53,6 +53,12 @@
 
 #define BAT_ADDR_MFR_TYPE  0x5F
 
+struct olpc_battery_data {
+   struct power_supply *olpc_ac;
+   struct power_supply *olpc_bat;
+   char bat_serial[17];
+};
+
 /*
  * Power
  */
@@ -91,11 +97,8 @@ static const struct power_supply_desc olpc_ac_desc = {
.get_property = olpc_ac_get_prop,
 };
 
-static struct power_supply *olpc_ac;
-
-static char bat_serial[17]; /* Ick */
-
-static int olpc_bat_get_status(union power_supply_propval *val, uint8_t 
ec_byte)
+static int olpc_bat_get_status(struct olpc_battery_data *data,
+   union power_supply_propval *val, uint8_t ec_byte)
 {
if (olpc_platform_info.ecver > 0x44) {
if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
@@ -326,6 +329,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
 enum power_supply_property psp,
 union power_supply_propval *val)
 {
+   struct olpc_battery_data *data = power_supply_get_drvdata(psy);
int ret = 0;
__be16 ec_word;
uint8_t ec_byte;
@@ -347,7 +351,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
 
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
-   ret = olpc_bat_get_status(val, ec_byte);
+   ret = olpc_bat_get_status(data, val, ec_byte);
if (ret)
return ret;
break;
@@ -450,8 +454,8 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
-   val->strval = bat_serial;
+   sprintf(data->bat_serial, "%016llx", (long 
long)be64_to_cpu(ser_buf));
+   val->strval = data->bat_serial;
break;
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
ret = olpc_bat_get_voltage_max_design(val);
@@ -579,17 +583,17 @@ static struct power_supply_desc olpc_bat_desc = {
.use_for_apm = 1,
 };
 
-static struct power_supply *olpc_bat;
-
 static int olpc_battery_suspend(struct platform_device *pdev,
pm_message_t state)
 {
-   if (device_may_wakeup(&olpc_ac->dev))
+   struct olpc_battery_data *data = platform_get_drvdata(pdev);
+
+   if (device_may_wakeup(&data->olpc_ac->dev))
olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
else
olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
 
-   if (device_may_wakeup(&olpc_bat->dev))
+   if (device_may_wakeup(&data->olpc_bat->dev))
olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
   | EC_SCI_SRC_BATERR);
else
@@ -601,7 +605,8 @@ static int olpc_battery_suspend(struct platform_device 
*pdev,
 
 static int olpc_battery_probe(struct platform_device *pdev)
 {
-   int ret;
+   struct power_supply_config psy_cfg = {};
+   struct olpc_battery_data *data;
uint8_t status;
 
/*
@@ -620,9 +625,13 @@ static int olpc_battery_probe(struct platform_device *pdev)
 
/* Ignore the status. It doesn't actually matter */
 
-   olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
-   if (IS_ERR(olpc_ac))
-   return PTR_ERR(olpc_ac);
+   psy_cfg.of_node = pdev->dev.of_node;
+   psy_cfg.drv_data = data;
+
+   data->olpc_ac = devm_power_supply_register(&pdev->dev, &olpc_ac_desc, 
&psy_cfg);
+   if (IS_ERR(data->olpc_ac))
+   return PTR_ERR(data->olpc_ac);
+
if (of_property_match_string(pdev->dev.of_node, "compatible",
"olpc,xo1.5-battery") >= 0) {
/* XO-1.5 */
@@ -634,42 +643,36 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
}
 
-   olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, NULL);
-   if (IS_ERR(olpc_bat)) {
-   ret = PTR_ERR(olpc_bat);
-   goto battery_failed;
-   }
+   data-&g

[PATCH 06/15] Platform: OLPC: Add XO-1.75 EC driver

2018-10-10 Thread Lubomir Rintel
It's based off the driver from the OLPC kernel sources. Somewhat
modernized and cleaned up, for better or worse.

Modified to plug into the olpc-ec driver infrastructure (so that battery
interface and debugfs could be reused) and the SPI slave framework.

Signed-off-by: Lubomir Rintel 
---
 drivers/platform/olpc/Kconfig |  15 +
 drivers/platform/olpc/Makefile|   1 +
 drivers/platform/olpc/olpc-xo175-ec.c | 755 ++
 3 files changed, 771 insertions(+)
 create mode 100644 drivers/platform/olpc/olpc-xo175-ec.c

diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfig
index 7b736c9e67ac..7c643d24ad0f 100644
--- a/drivers/platform/olpc/Kconfig
+++ b/drivers/platform/olpc/Kconfig
@@ -9,3 +9,18 @@ config OLPC
help
  Add support for detecting the unique features of the OLPC
  XO hardware.
+
+if OLPC
+
+config OLPC_XO175_EC
+   tristate "OLPC XO 1.75 Embedded Controller"
+   depends on ARCH_MMP || COMPILE_TEST
+   select SPI_SLAVE
+   help
+ Include support for the OLPC XO Embedded Controller (EC). The EC
+ provides various platform services, including support for the power,
+ button, restart, shutdown and battery charging status.
+
+ Unless you have an OLPC XO laptop, you will want to say N.
+
+endif
diff --git a/drivers/platform/olpc/Makefile b/drivers/platform/olpc/Makefile
index dc8b26bc7209..5b43f383289e 100644
--- a/drivers/platform/olpc/Makefile
+++ b/drivers/platform/olpc/Makefile
@@ -2,3 +2,4 @@
 # OLPC XO platform-specific drivers
 #
 obj-$(CONFIG_OLPC) += olpc-ec.o
+obj-$(CONFIG_OLPC_XO175_EC)+= olpc-xo175-ec.o
diff --git a/drivers/platform/olpc/olpc-xo175-ec.c 
b/drivers/platform/olpc/olpc-xo175-ec.c
new file mode 100644
index ..6333a1366730
--- /dev/null
+++ b/drivers/platform/olpc/olpc-xo175-ec.c
@@ -0,0 +1,755 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Driver for the OLPC XO-1.75 Embedded Controller.
+ *
+ * The EC protocol is documented at:
+ * http://wiki.laptop.org/go/XO_1.75_HOST_to_EC_Protocol
+ *
+ * Copyright (C) 2010 One Laptop per Child Foundation.
+ * Copyright (C) 2018 Lubomir Rintel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct ec_cmd_t {
+   u8 cmd;
+   u8 bytes_returned;
+};
+
+enum ec_chan_t {
+   CHAN_NONE = 0,
+   CHAN_SWITCH,
+   CHAN_CMD_RESP,
+   CHAN_KEYBOARD,
+   CHAN_TOUCHPAD,
+   CHAN_EVENT,
+   CHAN_DEBUG,
+   CHAN_CMD_ERROR,
+};
+
+/*
+ * EC events
+ */
+#define EVENT_AC_CHANGE1  /* AC plugged/unplugged */
+#define EVENT_BATTERY_STATUS   2  /* Battery low/full/error/gone */
+#define EVENT_BATTERY_CRITICAL 3  /* Battery critical voltage */
+#define EVENT_BATTERY_SOC_CHANGE   4  /* 1% SOC Change */
+#define EVENT_BATTERY_ERROR5  /* Abnormal error, query for cause */
+#define EVENT_POWER_PRESSED6  /* Power button was pressed */
+#define EVENT_POWER_PRESS_WAKE 7  /* Woken up with a power button */
+#define EVENT_TIMED_HOST_WAKE  8  /* Host wake timer */
+#define EVENT_OLS_HIGH_LIMIT   9  /* OLS crossed dark threshold */
+#define EVENT_OLS_LOW_LIMIT10 /* OLS crossed light threshold */
+
+/*
+ * EC commands
+ * (from http://dev.laptop.org/git/users/rsmith/ec-1.75/tree/ec_cmd.h)
+ */
+#define CMD_GET_API_VERSION0x08 /* out: u8 */
+#define CMD_READ_VOLTAGE   0x10 /* out: u16, *9.76/32, mV */
+#define CMD_READ_CURRENT   0x11 /* out: s16, *15.625/120, mA */
+#define CMD_READ_ACR   0x12 /* out: s16, *6250/15, uAh */
+#define CMD_READ_BATT_TEMPERATURE  0x13 /* out: u16, *100/256, deg C */
+#define CMD_READ_AMBIENT_TEMPERATURE   0x14 /* unimplemented, no hardware */
+#define CMD_READ_BATTERY_STATUS0x15 /* out: u8, bitmask */
+#define CMD_READ_SOC   0x16 /* out: u8, percentage */
+#define CMD_READ_GAUGE_ID  0x17 /* out: u8 * 8 */
+#define CMD_READ_GAUGE_DATA0x18 /* in: u8 addr, out: u8 data */
+#define CMD_READ_BOARD_ID  0x19 /* out: u16 (platform id) */
+#define CMD_READ_BATT_ERR_CODE 0x1f /* out: u8, error bitmask */
+#define CMD_SET_DCON_POWER 0x26 /* in: u8 */
+#define CMD_RESET_EC   0x28 /* none */
+#define CMD_READ_BATTERY_TYPE  0x2c /* out: u8 */
+#define CMD_SET_AUTOWAK0x33 /* out: u8 */
+#define CMD_SET_EC_WAKEUP_TIMER0x36 /* in: u32, out: ? */
+#define CMD_READ_EXT_SCI_MASK  0x37 /* ? */
+#define CMD_WRITE_EXT_SCI_MASK 0x38 /* ? */
+#define CMD_CLEAR_EC_WAKEUP_TIMER  0x39 /* none */
+#define CMD_ENABLE_RUNIN_DISCHARGE 0x3B /* none */
+#define CMD_DISABLE_RUNIN_DISCHARGE0x3C /* n

[PATCH 15/15] power: supply: olpc_battery: Add OLPC XO 1.75 support

2018-10-10 Thread Lubomir Rintel
The battery and the protocol are essentially the same as OLPC XO 1.5,
but the responses from the EC are LSB first.

Signed-off-by: Lubomir Rintel 
---
 drivers/power/supply/olpc_battery.c | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index dde9863e5c4a..2adf33b9f641 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -56,6 +56,7 @@ struct olpc_battery_data {
struct power_supply *olpc_bat;
char bat_serial[17];
int new_proto;
+   int little_endian;
 };
 
 /*
@@ -321,6 +322,14 @@ static int olpc_bat_get_voltage_max_design(union 
power_supply_propval *val)
return ret;
 }
 
+static s16 ecword_to_cpu(struct olpc_battery_data *data, u16 ec_byte)
+{
+   if (data->little_endian)
+   return le16_to_cpu(ec_byte);
+   else
+   return be16_to_cpu(ec_byte);
+}
+
 /*
  * Battery properties
  */
@@ -393,7 +402,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 9760L / 32;
+   val->intval = ecword_to_cpu(data, ec_word) * 9760L / 32;
break;
case POWER_SUPPLY_PROP_CURRENT_AVG:
case POWER_SUPPLY_PROP_CURRENT_NOW:
@@ -401,7 +410,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120;
+   val->intval = ecword_to_cpu(data, ec_word) * 15625L / 120;
break;
case POWER_SUPPLY_PROP_CAPACITY:
ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
@@ -432,21 +441,21 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 10 / 256;
+   val->intval = ecword_to_cpu(data, ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
 
-   val->intval = (int)be16_to_cpu(ec_word) * 10 / 256;
+   val->intval = (int)ecword_to_cpu(data, ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 6250 / 15;
+   val->intval = ecword_to_cpu(data, ec_word) * 6250 / 15;
break;
case POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8);
@@ -626,6 +635,10 @@ static int olpc_battery_probe(struct platform_device *pdev)
if (ecver[0] > 0x44) {
/* XO 1 or 1.5 with a new EC firmware. */
data->new_proto = 1;
+   } else if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) {
+   /* XO 1.75 */
+   data->new_proto = 1;
+   data->little_endian = 1;
} else if (ecver[0] < 0x44) {
/*
 * We've seen a number of EC protocol changes; this driver
-- 
2.19.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/15] Platform: OLPC: Move EC-specific functionality out from x86

2018-10-10 Thread Lubomir Rintel
It is actually plaform independent. Move it to the olpc-ec driver from
the X86 OLPC platform, so that it could be used by the ARM based laptops
too.

Signed-off-by: Lubomir Rintel 
---
 arch/x86/include/asm/olpc.h |  17 -
 arch/x86/platform/olpc/olpc.c   | 119 +---
 drivers/platform/olpc/olpc-ec.c | 103 ++-
 include/linux/olpc-ec.h |  32 -
 4 files changed, 149 insertions(+), 122 deletions(-)

diff --git a/arch/x86/include/asm/olpc.h b/arch/x86/include/asm/olpc.h
index c2bf1de5d901..cf13d1254550 100644
--- a/arch/x86/include/asm/olpc.h
+++ b/arch/x86/include/asm/olpc.h
@@ -9,12 +9,10 @@
 struct olpc_platform_t {
int flags;
uint32_t boardrev;
-   int ecver;
 };
 
 #define OLPC_F_PRESENT 0x01
 #define OLPC_F_DCON0x02
-#define OLPC_F_EC_WIDE_SCI 0x04
 
 #ifdef CONFIG_OLPC
 
@@ -64,13 +62,6 @@ static inline int olpc_board_at_least(uint32_t rev)
return olpc_platform_info.boardrev >= rev;
 }
 
-extern void olpc_ec_wakeup_set(u16 value);
-extern void olpc_ec_wakeup_clear(u16 value);
-extern bool olpc_ec_wakeup_available(void);
-
-extern int olpc_ec_mask_write(u16 bits);
-extern int olpc_ec_sci_query(u16 *sci_value);
-
 #else
 
 static inline int machine_is_olpc(void)
@@ -83,14 +74,6 @@ static inline int olpc_has_dcon(void)
return 0;
 }
 
-static inline void olpc_ec_wakeup_set(u16 value) { }
-static inline void olpc_ec_wakeup_clear(u16 value) { }
-
-static inline bool olpc_ec_wakeup_available(void)
-{
-   return false;
-}
-
 #endif
 
 #ifdef CONFIG_OLPC_XO1_PM
diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
index f0e920fb98ad..c6c62b4f251f 100644
--- a/arch/x86/platform/olpc/olpc.c
+++ b/arch/x86/platform/olpc/olpc.c
@@ -30,9 +30,6 @@
 struct olpc_platform_t olpc_platform_info;
 EXPORT_SYMBOL_GPL(olpc_platform_info);
 
-/* EC event mask to be applied during suspend (defining wakeup sources). */
-static u16 ec_wakeup_mask;
-
 /* what the timeout *should* be (in ms) */
 #define EC_BASE_TIMEOUT 20
 
@@ -186,83 +183,6 @@ static int olpc_xo1_ec_cmd(u8 cmd, u8 *inbuf, size_t 
inlen, u8 *outbuf,
return ret;
 }
 
-void olpc_ec_wakeup_set(u16 value)
-{
-   ec_wakeup_mask |= value;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_wakeup_set);
-
-void olpc_ec_wakeup_clear(u16 value)
-{
-   ec_wakeup_mask &= ~value;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_wakeup_clear);
-
-/*
- * Returns true if the compile and runtime configurations allow for EC events
- * to wake the system.
- */
-bool olpc_ec_wakeup_available(void)
-{
-   if (!machine_is_olpc())
-   return false;
-
-   /*
-* XO-1 EC wakeups are available when olpc-xo1-sci driver is
-* compiled in
-*/
-#ifdef CONFIG_OLPC_XO1_SCI
-   if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) /* XO-1 */
-   return true;
-#endif
-
-   /*
-* XO-1.5 EC wakeups are available when olpc-xo15-sci driver is
-* compiled in
-*/
-#ifdef CONFIG_OLPC_XO15_SCI
-   if (olpc_platform_info.boardrev >= olpc_board_pre(0xd0)) /* XO-1.5 */
-   return true;
-#endif
-
-   return false;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_wakeup_available);
-
-int olpc_ec_mask_write(u16 bits)
-{
-   if (olpc_platform_info.flags & OLPC_F_EC_WIDE_SCI) {
-   __be16 ec_word = cpu_to_be16(bits);
-   return olpc_ec_cmd(EC_WRITE_EXT_SCI_MASK, (void *) &ec_word, 2,
-  NULL, 0);
-   } else {
-   unsigned char ec_byte = bits & 0xff;
-   return olpc_ec_cmd(EC_WRITE_SCI_MASK, &ec_byte, 1, NULL, 0);
-   }
-}
-EXPORT_SYMBOL_GPL(olpc_ec_mask_write);
-
-int olpc_ec_sci_query(u16 *sci_value)
-{
-   int ret;
-
-   if (olpc_platform_info.flags & OLPC_F_EC_WIDE_SCI) {
-   __be16 ec_word;
-   ret = olpc_ec_cmd(EC_EXT_SCI_QUERY,
-   NULL, 0, (void *) &ec_word, 2);
-   if (ret == 0)
-   *sci_value = be16_to_cpu(ec_word);
-   } else {
-   unsigned char ec_byte;
-   ret = olpc_ec_cmd(EC_SCI_QUERY, NULL, 0, &ec_byte, 1);
-   if (ret == 0)
-   *sci_value = ec_byte;
-   }
-
-   return ret;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_sci_query);
-
 static bool __init check_ofw_architecture(struct device_node *root)
 {
const char *olpc_arch;
@@ -296,6 +216,10 @@ static bool __init platform_detect(void)
if (success) {
olpc_platform_info.boardrev = get_board_revision(root);
olpc_platform_info.flags |= OLPC_F_PRESENT;
+
+   pr_info("OLPC board revision %s%X\n",
+   ((olpc_platform_info.boardrev & 0xf) < 8) ? "pre" : "",
+   olpc_platform_info.boardrev >> 4);
}
 
of_

Re: [PATCH 0/15] Add support for OLPC XO 1.75 Embedded Controller

2018-10-11 Thread Lubomir Rintel
On Wed, 2018-10-10 at 14:26 -0500, Rob Herring wrote:
> On Wed, Oct 10, 2018 at 12:23 PM Lubomir Rintel  wrote:
> > Hi.
> > 
> > This patchset adds support for the Embedded Controller on an OLPC XO
> > 1.75 machine. OLPC XO 1.75 is a MMP2 based ARM laptop. It plugs into
> > the existing OLPC platform infrastructure, currently used by the x86
> > based models.
> > 
> > The EC operates in SPI master mode, meaning the SOC is the SPI slave. It
> > uses extra handshake signal to signal readiness of SOC to accept data
> > from EC and to initiate a transaction if SOC wishes to submit data.
> > 
> > The SPI slave support for MMP2 was submitted separately:
> > https://lore.kernel.org/lkml/20181010170936.316862-1-lkund...@v3.sk/T/#t
> > 
> > THe "power: supply: olpc_battery: correct the temperature" patch was
> > already sent out separately, but I'm including it because the last
> > commit of the set depends on it.
> > 
> > Tested to work on an OLPC XO 1.75 and also tested not to break x86
> > support with an OLPC XO 1 machine. I don't have a XO 1.5, but it's
> > unlikely this breaks it when XO 1 works.
> 
> I asked this on the OLPC devel list recently, but I don't think my
> message ever got past the moderator. Could you generate a DT dump from
> /proc/device-tree of an XO 1 and send to me? I have some DT changes
> planned and need to see if they'd be okay for x86 OLPC.

The /proc/device-tree tarball: http://v3.sk/~lkundrak/olpc/xo1.tar
(Mirror: https://people.freedesktop.org/~lkundrak/olpc/xo1.tar)

My distro's dtc crashes with this (could be related to your recent dtc
fixes), the git tip needs -f to work around some funny property names.
I figure a raw data as opposed to a dts/dtb dump would be a better
idea.

Also, there's no phandles, so it's of rather limited use. If you need
those, then I can share a dump directly from ofw instead or patch the
kernel to fabricate and expose the phandle properties.

This is with the latest firmware. I guess the exact version is
somewhere within the device tree.

> 
> Rob

Cheers
Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/15] Add support for OLPC XO 1.75 Embedded Controller

2018-10-23 Thread Lubomir Rintel
On Fri, 2018-10-19 at 16:57 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:23 PM Lubomir Rintel  wrote:
> > Hi.
> > 
> > This patchset adds support for the Embedded Controller on an OLPC XO
> > 1.75 machine. OLPC XO 1.75 is a MMP2 based ARM laptop. It plugs into
> > the existing OLPC platform infrastructure, currently used by the x86
> > based models.
> > 
> > The EC operates in SPI master mode, meaning the SOC is the SPI slave. It
> > uses extra handshake signal to signal readiness of SOC to accept data
> > from EC and to initiate a transaction if SOC wishes to submit data.
> > 
> > The SPI slave support for MMP2 was submitted separately:
> > https://lore.kernel.org/lkml/20181010170936.316862-1-lkund...@v3.sk/T/#t
> > 
> > THe "power: supply: olpc_battery: correct the temperature" patch was
> 
> The
> 
> > already sent out separately, but I'm including it because the last
> > commit of the set depends on it.
> > 
> > Tested to work on an OLPC XO 1.75 and also tested not to break x86
> > support with an OLPC XO 1 machine. I don't have a XO 1.5, but it's
> > unlikely this breaks it when XO 1 works.
> > 
> > Thanks in advance for reviews and feedback of any kind.
> 
> Thanks for the series.
> I'm about to review the patch 6, otherwise read my comments for the
> rest and consider addressing them.

Thank you very much for your feedback, it is very appreciated.

The XO 1.75 patch set has grown somewhat larger than I'm comfortable
with, so I need some time to digest and address the review. I hope I'll
be able to post a v2 some time after the 4.20 merge window closes and
respond to questions raised in individual patches before that.

> 
> > Lubo
> > 
> 
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 04/15] Platform: OLPC: Remove an unused include

2018-11-13 Thread Lubomir Rintel
Hi,

thank you for the response.

On Fri, 2018-10-19 at 16:05 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:23 PM Lubomir Rintel 
> wrote:
> > Also, the header is x86 specific, while there are non-x86 OLPC
> > machines.
> 
> Same concern. as per patch 2.

Which concern? If it's that it doesn't make sense in that particular
place in the patch set, then I don't think so; this header is
unnecessary and the patch has no other dependencies. But the changes
that enable the OLPC EC platform code depend on this.

> Also, you might want to sort headers in alphabetical order.

But should I? Doing so in the same commit would obscure the actual
change, and a separate commit would needlessly clobber git annotate.

Thank you
Lubo

> > Signed-off-by: Lubomir Rintel 
> > ---
> >  drivers/platform/olpc/olpc-ec.c | 1 -
> >  1 file changed, 1 deletion(-)
> > 
> > diff --git a/drivers/platform/olpc/olpc-ec.c
> > b/drivers/platform/olpc/olpc-ec.c
> > index f99b183d5296..35a21c66cd0d 100644
> > --- a/drivers/platform/olpc/olpc-ec.c
> > +++ b/drivers/platform/olpc/olpc-ec.c
> > @@ -15,7 +15,6 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> > 
> >  struct ec_cmd_desc {
> > u8 cmd;
> > --
> > 2.19.0
> > 
> 
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 06/15] Platform: OLPC: Add XO-1.75 EC driver

2018-11-13 Thread Lubomir Rintel
Hi,

first of all -- thanks for such a careful review. It is very helpful.

Wherever I don't respond to you, I'm just following what you wrote. It
would perhaps be tiresome to respond to "Yes, will fix in next version"
to every single point.

I'll be following up with a new version in a few days; I'm mostly done
with this one but I've not finished addressing the followup ones.

On Fri, 2018-10-19 at 19:06 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:24 PM Lubomir Rintel 
> wrote:
> > It's based off the driver from the OLPC kernel sources. Somewhat
> > modernized and cleaned up, for better or worse.
> > 
> > Modified to plug into the olpc-ec driver infrastructure (so that
> > battery
> > interface and debugfs could be reused) and the SPI slave framework.
> > +#include 
> 
> asm/* goes after linux/*
> 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Easy to maintain when it's sorted.
> 
> > +   { 0 },
> 
> Terminators are better without trailing comma.
> 
> > +#define EC_CMD_LEN 8
> > +#define EC_MAX_RESP_LEN16
> > +#define LOG_BUF_SIZE   127
> 
> 127 sounds slightly strange. Is it by specification of protocol?
> Would
> it be better to define it 128 bytes / items?
> 
> > +static int olpc_xo175_ec_is_valid_cmd(u8 cmd)
> > +{
> > +   const struct ec_cmd_t *p;
> > +
> > +   for (p = olpc_xo175_ec_cmds; p->cmd; p++) {
> > +   if (p->cmd == cmd)
> > +   return p->bytes_returned;
> > +   }
> > +
> > +   return -1;
> 
> -EINVAL ?
> 
> > +}
> > +static void olpc_xo175_ec_complete(void *arg);
> 
> Hmm... Can we avoid forward declaration?

I don't think we can.

> > +   channel = priv->rx_buf[0];
> > +   byte = priv->rx_buf[1];
> 
> Maybe specific structures would fit better?
> 
> Like
> 
> struct olpc_ec_resp_hdr {
>  u8 channel;
>  u8 byte;
> ...
> }
> 
> > +   dev_warn(dev, "kbd/tpad not supported\n");
> 
> Please, spell it fully as touchpad and keyboard.
> 
> > +   pm_wakeup_event(priv->pwrbtn->dev.parent,
> > 1000);
> 
> Magic number.
> 
> > +   /* For now, we just ignore the unknown
> > events. */
> 
> dev_dbg(dev, "Ignored unknown event %.2x\n", byte);
> 
> ?
> 
> > if (isprint(byte)) {
> > +   priv->logbuf[priv->logbuf_len++] = byte;
> > +   if (priv->logbuf_len == LOG_BUF_SIZE)
> > +   olpc_xo175_ec_flush_logbuf(priv);
> > +   }
> 
> You may consider to take everything and run %pE when printing instead
> of %s.
> 
> > +static int olpc_xo175_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8
> > *resp,
> > +   size_t resp_len, void
> > *ec_cb_arg)
> > +{
> > +   struct olpc_xo175_ec *priv = ec_cb_arg;
> > +   struct device *dev = &priv->spi->dev;
> > +   unsigned long flags;
> > +   int nr_bytes;
> > +   int ret = 0;
> > +
> > +   dev_dbg(dev, "CMD %x, %d bytes expected\n", cmd, resp_len);
> > +
> > +   if (inlen > 5) {
> 
> Magic number.
> 
> > +   dev_err(dev, "command len %d too big!\n",
> > resp_len);
> > +   return -EOVERFLOW;
> > +   }
> > +   WARN_ON(priv->suspended);
> > +   if (priv->suspended)
> 
> if (WARN_ON(...)) ?
> 
> > +   return -EBUSY;
> > +   if (resp_len > nr_bytes)
> > +   resp_len = nr_bytes;
> 
> resp_len = min(resp_len, nr_bytes);
> 
> > +   priv->cmd[0] = cmd;
> > +   priv->cmd[1] = inlen;
> > +   priv->cmd[2] = 0;
> 
> Perhaps specific struct header for this?
> 
> > +   memset(resp, 0, resp_len);
> 
> Wouldn't be better to do this in where actual response has been
> filled?
> 
> > +   if (!wait_for_completion_timeout(&priv->cmd_done,
> > +   msecs_to_jiffies(4000))) {
> 
> Magic number.
> 
> > +   }
> > +   /* Deal with the results. */
> 
> Somehow feels noisy / unneeded co

Re: [PATCH 08/15] Platform: OLPC: Move EC-specific functionality out from x86

2018-11-14 Thread Lubomir Rintel
Hello,

On Fri, 2018-10-19 at 16:36 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:24 PM Lubomir Rintel 
> wrote:
> > It is actually plaform independent. Move it to the olpc-ec driver
> > from
> > the X86 OLPC platform, so that it could be used by the ARM based
> > laptops
> > too.
> 
> What is platform independent exactly?

The commands with their argument and responses are mostly the same, but
the delivery mechanism is different (SPI on ARM vs. LPC on x86).

Notably, the driver for the OLPC battery (which is the same on all XO
generations) builds on the API provided by the olpc-ec driver.

I'll try to extend the commit message to make this clear.

> >  #define OLPC_F_PRESENT 0x01
> >  #define OLPC_F_DCON0x02
> > -#define OLPC_F_EC_WIDE_SCI 0x04
> 
> I think these lines grouped on purpose. Thus, I don't like this.
> Either move either all or none.

I'm not moving this -- I'm removing it and using the EC version
instead.

This flag doesn't make sense for non-x86 ECs -- they don't use SCIs to
deliver EC-to-CPU communication, but initiate SPI transactions instead.

> 
> > +int olpc_ec_mask_write(u16 bits)
> > +{
> >  #ifdef CONFIG_DEBUG_FS
> > 
> >  /*
> > @@ -277,14 +369,17 @@ static int olpc_ec_probe(struct
> > platform_device *pdev)
> > ec_priv = ec;
> > platform_set_drvdata(pdev, ec);
> > 
> > +   /* EC version 0x5f adds support for wide SCI mask */
> > +   if (ec->version >= 0x5f) {
> > +   __be16 ec_word = cpu_to_be16(bits);
> > +
> > +   return olpc_ec_cmd(EC_WRITE_EXT_SCI_MASK, (void *)
> > &ec_word, 2,
> > +  NULL, 0);
> 
> I would leave it on one line.

Okay. I do agree this looks better, but was not sure how seriously to
take checkpatch.pl's warnings.

> 
> > +   } else {
> > +   unsigned char ec_byte = bits & 0xff;
> 
> You may noticed that the parameter is of type u8, which clearly makes
> & 0xff part redundant.

At least for me, the explicit mask makes this easier for me to read.

But I don't mind really. If you'd really like to see this changes I can
follow up with such change (or am happy to ack such change from you).

> 
> > +   return olpc_ec_cmd(EC_WRITE_SCI_MASK, &ec_byte, 1,
> > NULL, 0);
> > +   }
> > +}
> > +EXPORT_SYMBOL_GPL(olpc_ec_mask_write);
> 
> I see that the above is inherited from older code, so, no need to
> address those comments in here, but consider a follow up fix.
> 
> 
> > +int olpc_ec_sci_query(u16 *sci_value)
> > +{
> > +}
> > +EXPORT_SYMBOL_GPL(olpc_ec_sci_query);
> 
> Similar comments are applied here.
> 
> > +
> > -   err = ec_driver->probe ? ec_driver->probe(pdev) : 0;
> > +   /* get the EC revision */
> > +   err = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0,
> > +   (unsigned char *) &ec->version, 1);
> 
> Perhaps version should be defined as u8.

Yes.

> > +/* SCI source values */
> > +#define EC_SCI_SRC_EMPTY0x00
> > +#define EC_SCI_SRC_GAME 0x01
> > +#define EC_SCI_SRC_BATTERY  0x02
> > +#define EC_SCI_SRC_BATSOC   0x04
> > +#define EC_SCI_SRC_BATERR   0x08
> > +#define EC_SCI_SRC_EBOOK0x10/* XO-1 only */
> > +#define EC_SCI_SRC_WLAN 0x20/* XO-1 only */
> > +#define EC_SCI_SRC_ACPWR0x40
> > +#define EC_SCI_SRC_BATCRIT  0x80
> > +#define EC_SCI_SRC_GPWAKE   0x100   /* XO-1.5 only */
> 
> BIT() ?
> 
> > +#define EC_SCI_SRC_ALL  0x1FF
> 
> GENMASK()?

Yes. I meant to move this, but it turns out I've left the original ones
in place. Will fix them in a follow-up commit also.

Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 11/15] x86, olpc: Use a correct version when making up a battery node

2018-11-14 Thread Lubomir Rintel
Hello,

On Fri, 2018-10-19 at 16:43 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:23 PM Lubomir Rintel 
> wrote:
> > The XO-1 and XO-1.5 batteries apparently differ in an ability to
> > report
> > ambient temperature. Add a different compatible string to the 1.5
> > battery.
> > +int olpc_dt_compatible_match(phandle node, const char *compat)
> >  {
> > char buf[64];
> > +   int plen;
> > +   char *p;
> > +   int len;
> > +
> > +   plen = olpc_dt_getproperty(node, "compatible", buf,
> > sizeof(buf));
> > +   if (plen <= 0)
> > +   return 0;
> > +
> > +   len = strlen(compat);
> > +   for (p = buf; p < buf + plen; p += strlen(p) + 1) {
> > +   if (strcmp(p, compat) == 0)
> > +   return 1;
> > +   }
> > +
> > +   return 0;
> > +}
> 
> DT doesn't still have a helper for that?!
> I hardly believe in that.

There indeed is of_device_compatible_match() (and
of_find_node_by_phandle() for that matter).

However, these fixups are executed before the DT is built with
of_pdt_build_devicetree(), so I don't think any of_*() routines can be
used at that point.

> > +   olpc_dt_interpret("\" /battery@0\" find-device"
> > +   " \" olpc,xo1.5-battery\" +compatible"
> > +   " device-end");
> 
> Please, don't split string literals.
> 
> > olpc_dt_interpret("\" /pci/display@1\" find-device"
> > " new-device"
> > " \" dcon\" device-name \" olpc,xo1-dcon\"
> > +compatible"
> > " finish-device device-end");
> 
> Yeah, this and similar also needs to be fixed.

Okay.

Thank you
Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 13/15] power: supply: olpc_battery: Move priv data to a struct

2018-11-14 Thread Lubomir Rintel
On Sun, 2018-11-04 at 15:37 +0100, Pavel Machek wrote:
> Hi!
> 
> > The global variables for private data are not too nice. I'd like some
> > more, and that would clutter the global name space even further.
> > 
> > Signed-off-by: Lubomir Rintel 
> > Reviewed-by: Andy Shevchenko 
> 
> Ok...
> 
> > -   olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, NULL);
> > -   if (IS_ERR(olpc_bat)) {
> > -   ret = PTR_ERR(olpc_bat);
> > -   goto battery_failed;
> > -   }
> > +   data->olpc_bat = devm_power_supply_register(&pdev->dev, &olpc_bat_desc, 
> > &psy_cfg);
> > +   if (IS_ERR(data->olpc_bat))
> > +   return PTR_ERR(data->olpc_bat);
> >  
> > -   ret = device_create_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> > +   ret = device_create_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> > if (ret)
> > -   goto eeprom_failed;
> > +   return ret;
> >  
> > -   ret = device_create_file(&olpc_bat->dev, &olpc_bat_error);
> > +   ret = device_create_file(&data->olpc_bat->dev, &olpc_bat_error);
> > if (ret)
> > goto error_failed;
> >  
> > if (olpc_ec_wakeup_available()) {
> > -   device_set_wakeup_capable(&olpc_ac->dev, true);
> > -   device_set_wakeup_capable(&olpc_bat->dev, true);
> > +   device_set_wakeup_capable(&data->olpc_ac->dev, true);
> > +   device_set_wakeup_capable(&data->olpc_bat->dev, true);
> > }
> >  
> > return 0;
> >  
> >  error_failed:
> > -   device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> > -eeprom_failed:
> > -   power_supply_unregister(olpc_bat);
> > -battery_failed:
> > -   power_supply_unregister(olpc_ac);
> > +   device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> > return ret;
> >  }
> 
> ...but you are changing error handling here, which is not mentioned in
> the changelog, and I'm nut sure you got it right.
> 
> Are you sure?

I can't see what's wrong. I'll split the priv structure and devm/error
handling changes into two separate patches as you're right they indeed
are somewhat unrelated.

If v2 (tomorrow or so) will still seem wrong to you I'd be thankful if
you could elaborate a bit more.
> 
> >  static int olpc_battery_remove(struct platform_device *pdev)
> >  {
> > -   device_remove_file(&olpc_bat->dev, &olpc_bat_error);
> > -   device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> > -   power_supply_unregister(olpc_bat);
> > -   power_supply_unregister(olpc_ac);
> > +   struct olpc_battery_data *data = platform_get_drvdata(pdev);
> > +
> > +   device_remove_file(&data->olpc_bat->dev, &olpc_bat_error);
> > +   device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> > return 0;
> >  }
> 
> Here too.
>   Pavel

Cheers
Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 14/15] power: supply: olpc_battery: Avoid using platform_info

2018-11-14 Thread Lubomir Rintel
On Fri, 2018-10-19 at 16:50 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:24 PM Lubomir Rintel 
> wrote:
> > This wouldn't work on the DT-based ARM platform. Let's read the EC
> > version
> > directly from the EC driver instead.
> > 
> > This makes the driver no longer x86 specific.
> > 
> > Signed-off-by: Lubomir Rintel 
> > ---
> >  drivers/power/supply/Kconfig|  2 +-
> >  drivers/power/supply/olpc_battery.c | 35 +--
> > --
> >  2 files changed, 27 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/power/supply/Kconfig
> > b/drivers/power/supply/Kconfig
> > index ff6dab0bf0dd..f0361e4dd457 100644
> > --- a/drivers/power/supply/Kconfig
> > +++ b/drivers/power/supply/Kconfig
> > @@ -151,7 +151,7 @@ config BATTERY_PMU
> > 
> >  config BATTERY_OLPC
> > tristate "One Laptop Per Child battery"
> > -   depends on X86_32 && OLPC
> > +   depends on OLPC
> > help
> >   Say Y to enable support for the battery on the OLPC
> > laptop.
> > 
> > diff --git a/drivers/power/supply/olpc_battery.c
> > b/drivers/power/supply/olpc_battery.c
> > index 2a2d7cc995f0..dde9863e5c4a 100644
> > --- a/drivers/power/supply/olpc_battery.c
> > +++ b/drivers/power/supply/olpc_battery.c
> > @@ -20,8 +20,6 @@
> >  #include 
> >  #include 
> >  #include 
> 
> Btw, Kconfig might miss
> depends on OF
> part.

But will it? I thought this header can be included regardless,
providing stubs that always fail instead of actual OF functionality.

It just wouldn't be too useful apart for compile-testing things.

Apart from that, CONFIG_OLPC drags in CONFIG_OF, so we're always
getting CONFIG_OF transitively.

> 
> > -#include 
> > -
> > 
> >  #define EC_BAT_VOLTAGE 0x10/*
> > uint16_t,*9.76/32,mV   */
> >  #define EC_BAT_CURRENT 0x11/* int16_t, *15.625/120,
> > mA   */
> > @@ -57,6 +55,7 @@ struct olpc_battery_data {
> > struct power_supply *olpc_ac;
> > struct power_supply *olpc_bat;
> > char bat_serial[17];
> > +   int new_proto;
> >  };
> > 
> >  /*
> > 
> > @@ -100,7 +99,7 @@ static const struct power_supply_desc
> > olpc_ac_desc = {
> >  static int olpc_bat_get_status(struct olpc_battery_data *data,
> > union power_supply_propval *val, uint8_t ec_byte)
> >  {
> > -   if (olpc_platform_info.ecver > 0x44) {
> > +   if (data->new_proto) {
> > if (ec_byte & (BAT_STAT_CHARGING |
> > BAT_STAT_TRICKLE))
> > val->intval = POWER_SUPPLY_STATUS_CHARGING;
> > else if (ec_byte & BAT_STAT_DISCHARGING)
> > @@ -608,14 +607,32 @@ static int olpc_battery_probe(struct
> > platform_device *pdev)
> > struct power_supply_config psy_cfg = {};
> > struct olpc_battery_data *data;
> > uint8_t status;
> > +   unsigned char ecver[1];
> 
> isn't it simple
>  uint8_t ecver;
> ?

Yes, it's probably going to be nicer that way.

> 
> > +   int ret;
> > +
> > +   data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > +   if (!data)
> > +   return -ENOMEM;
> > +   platform_set_drvdata(pdev, data);
> > +
> > +   /* See if the EC is already there and get the EC revision
> > */
> > +   ret = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, ecver,
> > ARRAY_SIZE(ecver));
> > +   if (ret) {
> > +   if (ret == -ENODEV)
> > +   return -EPROBE_DEFER;
> 
> Yeah, exactly a question I asked somewhere in the first part of the
> series.
> 
> > +   return ret;
> > +   }
> > 
> > -   /*
> > -* We've seen a number of EC protocol changes; this driver
> > requires
> > -* the latest EC protocol, supported by 0x44 and above.
> > -*/
> > -   if (olpc_platform_info.ecver < 0x44) {
> > +   if (ecver[0] > 0x44) {
> > +   /* XO 1 or 1.5 with a new EC firmware. */
> > +   data->new_proto = 1;
> > +   } else if (ecver[0] < 0x44) {
> > +   /*
> > +* We've seen a number of EC protocol changes; this
> > driver
> > +* requires the latest EC protocol, supported by
> > 0x44 and above.
> > +*/
> > printk(KERN_NOTICE "OLPC EC version 0x%02x too old
> > for "
> > -   "battery driver.\n",
> > olpc_platform_info.ecver);
> > +   "battery driver.\n", ecver[0]);
> > return -ENXIO;
> > }
> > 
> > --
> > 2.19.0
> > 

Thanks,
Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 12/15] power: supply: olpc_battery: Use DT to get battery version

2018-11-15 Thread Lubomir Rintel
On Fri, 2018-10-19 at 16:45 +0300, Andy Shevchenko wrote:
> On Wed, Oct 10, 2018 at 8:23 PM Lubomir Rintel 
> wrote:
> > Avoid using the x86 OLPC platform specific call to get the board
> > version. It won't work on FDT-based ARM MMP2 platform.
> > 
> > Signed-off-by: Lubomir Rintel 
> > ---
> >  drivers/power/supply/olpc_battery.c | 10 +++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/power/supply/olpc_battery.c
> > b/drivers/power/supply/olpc_battery.c
> > index 5a97e42a3547..540d44bf536f 100644
> > --- a/drivers/power/supply/olpc_battery.c
> > +++ b/drivers/power/supply/olpc_battery.c
> > @@ -19,6 +19,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> 
> Keep it sorted, otherwise the change is good!

Yes, but... the headers are not sorted at the moment. I'll sort the new
include before  so that I don't mess it up
even more, but I don't feel like just sorting everything so that I
don't obscure the actual change.


> Reviewed-by: Andy Shevchenko 
> 
> > 
> > @@ -622,11 +623,13 @@ static int olpc_battery_probe(struct
> > platform_device *pdev)
> > olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc,
> > NULL);
> > if (IS_ERR(olpc_ac))
> > return PTR_ERR(olpc_ac);
> > -
> > -   if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5
> > */
> > +   if (of_property_match_string(pdev->dev.of_node,
> > "compatible",
> > +   "olpc,xo1.5-battery") >= 0)
> > {
> > +   /* XO-1.5 */
> > olpc_bat_desc.properties = olpc_xo15_bat_props;
> > olpc_bat_desc.num_properties =
> > ARRAY_SIZE(olpc_xo15_bat_props);
> > -   } else { /* XO-1 */
> > +   } else {
> > +   /* XO-1 */
> > olpc_bat_desc.properties = olpc_xo1_bat_props;
> > olpc_bat_desc.num_properties =
> > ARRAY_SIZE(olpc_xo1_bat_props);
> > }
> > @@ -672,6 +675,7 @@ static int olpc_battery_remove(struct
> > platform_device *pdev)
> > 
> >  static const struct of_device_id olpc_battery_ids[] = {
> > { .compatible = "olpc,xo1-battery" },
> > +   { .compatible = "olpc,xo1.5-battery" },
> > {}
> >  };
> >  MODULE_DEVICE_TABLE(of, olpc_battery_ids);
> > --
> > 2.19.0
> > 

Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 12/15] power: supply: olpc_battery: Use DT to get battery version

2018-11-15 Thread Lubomir Rintel
On Sun, 2018-11-04 at 13:37 +0100, Pavel Machek wrote:
> On Wed 2018-10-10 19:22:57, Lubomir Rintel wrote:
> > Avoid using the x86 OLPC platform specific call to get the board
> > version. It won't work on FDT-based ARM MMP2 platform.
> > 
> > Signed-off-by: Lubomir Rintel 
> > Reviewed-by: Andy Shevchenko 
> 
> Acked-by: Pavel Machek 
> 
> AFAICT, this should go earlier in the series; first, add support in
> the code, then switch to new name in DTS.

I think it's all right this way: I'm not removing the old compatible
string -- functionality provided by one version of the battery is a
superset of the another.

Also, the older version of the driver with only the XO-1 compatible
string guesses the actual battery version by querying the board version
directly, so up to this patch things keep working the way they used to
regardless of the new compatible string.

Lubo

>   Pavel
> 
> > ---
> >  drivers/power/supply/olpc_battery.c | 10 +++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/power/supply/olpc_battery.c
> > b/drivers/power/supply/olpc_battery.c
> > index 5a97e42a3547..540d44bf536f 100644
> > --- a/drivers/power/supply/olpc_battery.c
> > +++ b/drivers/power/supply/olpc_battery.c
> > @@ -19,6 +19,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  
> >  
> > @@ -622,11 +623,13 @@ static int olpc_battery_probe(struct
> > platform_device *pdev)
> > olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc,
> > NULL);
> > if (IS_ERR(olpc_ac))
> > return PTR_ERR(olpc_ac);
> > -
> > -   if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
> > +   if (of_property_match_string(pdev->dev.of_node, "compatible",
> > +   "olpc,xo1.5-battery") >= 0) {
> > +   /* XO-1.5 */
> > olpc_bat_desc.properties = olpc_xo15_bat_props;
> > olpc_bat_desc.num_properties =
> > ARRAY_SIZE(olpc_xo15_bat_props);
> > -   } else { /* XO-1 */
> > +   } else {
> > +   /* XO-1 */
> > olpc_bat_desc.properties = olpc_xo1_bat_props;
> > olpc_bat_desc.num_properties =
> > ARRAY_SIZE(olpc_xo1_bat_props);
> > }
> > @@ -672,6 +675,7 @@ static int olpc_battery_remove(struct
> > platform_device *pdev)
> >  
> >  static const struct of_device_id olpc_battery_ids[] = {
> > { .compatible = "olpc,xo1-battery" },
> > +   { .compatible = "olpc,xo1.5-battery" },
> > {}
> >  };
> >  MODULE_DEVICE_TABLE(of, olpc_battery_ids);

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 02/15] Revert "platform/olpc: Make ec explicitly non-modular"

2018-11-15 Thread Lubomir Rintel
On Fri, 2018-11-02 at 23:16 +0100, Pavel Machek wrote:
> On Wed 2018-10-10 19:22:47, Lubomir Rintel wrote:
> > It doesn't make sense to always have this built-in, e.g. on ARM
> > multiplatform kernels. A better way to address the problem the
> > original
> > commit aimed to solve is to fix Kconfig.
> > 
> > This reverts commit f48d1496b8537d75776478c6942dd87f34d7f270.
> 
> This looks ok, but I don't see the Kconfig fix in the series. Is it
> needed?

It's flipped to a tristate in "Platform: OLPC: Move OLPC config symbol
out of x86 tree" and mentioned in the commit message.

Perhaps I could made that clear by separating the change into a
separate patch. I'm keeping it as it is in next version of the patch
set, but I'm going to improve this one's commit message and sort the
patches closer together.

>   Pavel

Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 01/17] power: supply: olpc_battery: correct the temperature units

2018-11-16 Thread Lubomir Rintel
According to [1] and [2], the temperature values are in tenths of degree
Celsius. Exposing the Celsius value makes the battery appear on fire:

  $ upower -i /org/freedesktop/UPower/devices/battery_olpc_battery
  ...
  temperature: 236.9 degrees C

Tested on OLPC XO-1 and OLPC XO-1.75 laptops.

[1] include/linux/power_supply.h
[2] Documentation/power/power_supply_class.txt

Fixes: fb972873a767 ("[BATTERY] One Laptop Per Child power/battery driver")
Cc: sta...@vger.kernel.org
Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- Add Fixes tag and an Ack

 drivers/power/supply/olpc_battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 6da79ae14860..5a97e42a3547 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -428,14 +428,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 100 / 256;
+   val->intval = (s16)be16_to_cpu(ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
 
-   val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
+   val->intval = (int)be16_to_cpu(ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 10/17] Platform: OLPC: add a regulator for the DCON

2018-11-16 Thread Lubomir Rintel
All OLPC ECs are able to turn the power to the DCON on an off. Use the
regulator framework to expose the functionality.

Signed-off-by: Lubomir Rintel 

---
Changes since v1:
- Use idiomatic form of return on error
- Avoid mixing bool and int

 drivers/platform/olpc/Kconfig   |  1 +
 drivers/platform/olpc/olpc-ec.c | 67 +
 2 files changed, 68 insertions(+)

diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfig
index 7c643d24ad0f..c5a872fb286f 100644
--- a/drivers/platform/olpc/Kconfig
+++ b/drivers/platform/olpc/Kconfig
@@ -6,6 +6,7 @@ config OLPC
select OF
select OF_PROMTREE if X86
select IRQ_DOMAIN
+   select REGULATOR
help
  Add support for detecting the unique features of the OLPC
  XO hardware.
diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 2b80174b8f4b..f725ab2a2db9 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 struct ec_cmd_desc {
@@ -34,6 +35,10 @@ struct olpc_ec_priv {
struct work_struct worker;
struct mutex cmd_lock;
 
+   /* DCON regulator */
+   struct regulator_dev *dcon_rdev;
+   bool dcon_enabled;
+
/* Pending EC commands */
struct list_head cmd_q;
spinlock_t cmd_q_lock;
@@ -344,9 +349,61 @@ static struct dentry *olpc_ec_setup_debugfs(void)
 
 #endif /* CONFIG_DEBUG_FS */
 
+static int olpc_ec_set_dcon_power(struct olpc_ec_priv *ec, bool state)
+{
+   unsigned char ec_byte = state;
+   int ret;
+
+   if (ec->dcon_enabled == state)
+   return 0;
+
+   ret = olpc_ec_cmd(EC_DCON_POWER_MODE, &ec_byte, 1, NULL, 0);
+   if (ret)
+   return ret;
+
+   ec->dcon_enabled = state;
+   return 0;
+}
+
+static int dcon_regulator_enable(struct regulator_dev *rdev)
+{
+   struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
+
+   return olpc_ec_set_dcon_power(ec, true);
+}
+
+static int dcon_regulator_disable(struct regulator_dev *rdev)
+{
+   struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
+
+   return olpc_ec_set_dcon_power(ec, false);
+}
+
+static int dcon_regulator_is_enabled(struct regulator_dev *rdev)
+{
+   struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
+
+   return ec->dcon_enabled ? 1 : 0;
+}
+
+static struct regulator_ops dcon_regulator_ops = {
+   .enable = dcon_regulator_enable,
+   .disable= dcon_regulator_disable,
+   .is_enabled = dcon_regulator_is_enabled,
+};
+
+static const struct regulator_desc dcon_desc = {
+   .name   = "dcon",
+   .id = 0,
+   .ops= &dcon_regulator_ops,
+   .type   = REGULATOR_VOLTAGE,
+   .owner  = THIS_MODULE,
+};
+
 static int olpc_ec_probe(struct platform_device *pdev)
 {
struct olpc_ec_priv *ec;
+   struct regulator_config config = { };
int err;
 
if (!ec_driver)
@@ -374,6 +431,16 @@ static int olpc_ec_probe(struct platform_device *pdev)
return err;
}
 
+   config.dev = pdev->dev.parent;
+   config.driver_data = ec;
+   ec->dcon_enabled = true;
+   ec->dcon_rdev = devm_regulator_register(&pdev->dev, &dcon_desc,
+   &config);
+   if (IS_ERR(ec->dcon_rdev)) {
+   dev_err(&pdev->dev, "failed to register DCON regulator\n");
+   return PTR_ERR(ec->dcon_rdev);
+   }
+
ec->dbgfs_dir = olpc_ec_setup_debugfs();
 
return err;
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 13/17] power: supply: olpc_battery: Use DT to get battery version

2018-11-16 Thread Lubomir Rintel
Avoid using the x86 OLPC platform specific call to get the board
version. It won't work on FDT-based ARM MMP2 platform.

Signed-off-by: Lubomir Rintel 
Reviewed-by: Andy Shevchenko 
Acked-by: Pavel Machek 

---
Changes since v1:
- Sort the new include a bit higher

 drivers/power/supply/olpc_battery.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 5a97e42a3547..5323987d9284 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -622,11 +623,13 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
if (IS_ERR(olpc_ac))
return PTR_ERR(olpc_ac);
-
-   if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
+   if (of_property_match_string(pdev->dev.of_node, "compatible",
+   "olpc,xo1.5-battery") >= 0) {
+   /* XO-1.5 */
olpc_bat_desc.properties = olpc_xo15_bat_props;
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo15_bat_props);
-   } else { /* XO-1 */
+   } else {
+   /* XO-1 */
olpc_bat_desc.properties = olpc_xo1_bat_props;
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
}
@@ -672,6 +675,7 @@ static int olpc_battery_remove(struct platform_device *pdev)
 
 static const struct of_device_id olpc_battery_ids[] = {
{ .compatible = "olpc,xo1-battery" },
+   { .compatible = "olpc,xo1.5-battery" },
{}
 };
 MODULE_DEVICE_TABLE(of, olpc_battery_ids);
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/17] Add support for OLPC XO 1.75 Embedded Controller

2018-11-16 Thread Lubomir Rintel
Hi everyone!

This is a second spin of the patch set that adds support for the Embedded
Controller on an OLPC XO 1.75 machine.

OLPC XO 1.75 is a MMP2 based ARM laptop. It plugs into the existing OLPC
platform infrastructure, currently used by the x86 based models.
The slave mode support for MMP2's SPI controller that the EC is hooked to
is now in spi.git's for-4.21 branch.

The v1 received a fair number of comments. I've attempted to address all of
them, either by fixing things or responding to the v1 review.  See the
change logs in the individual patches for details.

If I've overlooked something then I apologize -- I haven't dealt with
a patch set as big as this and I'm struggling to incorporate the
feedback in an organized manner. Advice from the more experienced folks
around here are welcome.

Tested to work on an OLPC XO 1.75 and also tested not to break x86
support with an OLPC XO 1 machine. I don't have a XO 1.5, but it's
unlikely this breaks it when XO 1 works.

Lubo



___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 15/17] power: supply: olpc_battery: Use devm_power_supply_register()

2018-11-16 Thread Lubomir Rintel
This simplifies the error handling.

Signed-off-by: Lubomir Rintel 

---
Changes since v1:
- This was split off the "power: supply: olpc_battery: Move priv data to
  a struct" patch.

 drivers/power/supply/olpc_battery.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index b091f897c1d4..4433eb10a23d 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -628,7 +628,7 @@ static int olpc_battery_probe(struct platform_device *pdev)
psy_cfg.of_node = pdev->dev.of_node;
psy_cfg.drv_data = data;
 
-   data->olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, 
&psy_cfg);
+   data->olpc_ac = devm_power_supply_register(&pdev->dev, &olpc_ac_desc, 
&psy_cfg);
if (IS_ERR(data->olpc_ac))
return PTR_ERR(data->olpc_ac);
 
@@ -643,15 +643,13 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
}
 
-   data->olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, 
&psy_cfg);
-   if (IS_ERR(olpc_bat)) {
-   ret = PTR_ERR(olpc_bat);
-   goto battery_failed;
-   }
+   data->olpc_bat = devm_power_supply_register(&pdev->dev, &olpc_bat_desc, 
&psy_cfg);
+   if (IS_ERR(data->olpc_bat))
+   return PTR_ERR(data->olpc_bat);
 
ret = device_create_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
if (ret)
-   goto eeprom_failed;
+   return ret;
 
ret = device_create_file(&data->olpc_bat->dev, &olpc_bat_error);
if (ret)
@@ -666,10 +664,6 @@ static int olpc_battery_probe(struct platform_device *pdev)
 
 error_failed:
device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
-eeprom_failed:
-   power_supply_unregister(data->olpc_bat);
-battery_failed:
-   power_supply_unregister(data->olpc_ac);
return ret;
 }
 
@@ -679,9 +673,6 @@ static int olpc_battery_remove(struct platform_device *pdev)
 
device_remove_file(&data->olpc_bat->dev, &olpc_bat_error);
device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
-   power_supply_unregister(data->olpc_bat);
-   power_supply_unregister(data->olpc_ac);
-
return 0;
 }
 
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 07/17] Platform: OLPC: Avoid a warning if the EC didn't register yet

2018-11-16 Thread Lubomir Rintel
Just return ENODEV, so that whoever attempted to use the EC call can
defer their work.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- EPROBE_DEFER instead of ENODEV

 drivers/platform/olpc/olpc-ec.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 35a21c66cd0d..9ee993d5d54b 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -116,8 +116,11 @@ int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 
*outbuf, size_t outlen)
struct olpc_ec_priv *ec = ec_priv;
struct ec_cmd_desc desc;
 
-   /* Ensure a driver and ec hook have been registered */
-   if (WARN_ON(!ec_driver || !ec_driver->ec_cmd))
+   /* Driver not yet registered. */
+   if (!ec_driver)
+   return -EPROBE_DEFER;
+
+   if (WARN_ON(!ec_driver->ec_cmd))
return -ENODEV;
 
if (!ec)
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 09/17] Platform: OLPC: Use BIT() and GENMASK() for event masks

2018-11-16 Thread Lubomir Rintel
Just a cosmetic tidy-up.

Signed-off-by: Lubomir Rintel 

---
Changes since v1:
- This patch was added to the set.

 include/linux/olpc-ec.h | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/include/linux/olpc-ec.h b/include/linux/olpc-ec.h
index 7fa3d27f7fee..f7b6a7eda232 100644
--- a/include/linux/olpc-ec.h
+++ b/include/linux/olpc-ec.h
@@ -2,6 +2,8 @@
 #ifndef _LINUX_OLPC_EC_H
 #define _LINUX_OLPC_EC_H
 
+#include 
+
 /* XO-1 EC commands */
 #define EC_FIRMWARE_REV0x08
 #define EC_WRITE_SCI_MASK  0x1b
@@ -17,17 +19,16 @@
 #define EC_EXT_SCI_QUERY   0x85
 
 /* SCI source values */
-#define EC_SCI_SRC_EMPTY0x00
-#define EC_SCI_SRC_GAME 0x01
-#define EC_SCI_SRC_BATTERY  0x02
-#define EC_SCI_SRC_BATSOC   0x04
-#define EC_SCI_SRC_BATERR   0x08
-#define EC_SCI_SRC_EBOOK0x10/* XO-1 only */
-#define EC_SCI_SRC_WLAN 0x20/* XO-1 only */
-#define EC_SCI_SRC_ACPWR0x40
-#define EC_SCI_SRC_BATCRIT  0x80
-#define EC_SCI_SRC_GPWAKE   0x100   /* XO-1.5 only */
-#define EC_SCI_SRC_ALL  0x1FF
+#define EC_SCI_SRC_GAME BIT(0)
+#define EC_SCI_SRC_BATTERY  BIT(1)
+#define EC_SCI_SRC_BATSOC   BIT(2)
+#define EC_SCI_SRC_BATERR   BIT(3)
+#define EC_SCI_SRC_EBOOKBIT(4)/* XO-1 only */
+#define EC_SCI_SRC_WLAN BIT(5)/* XO-1 only */
+#define EC_SCI_SRC_ACPWRBIT(6)
+#define EC_SCI_SRC_BATCRIT  BIT(7)
+#define EC_SCI_SRC_GPWAKE   BIT(8)   /* XO-1.5 only */
+#define EC_SCI_SRC_ALL  GENMASK(8, 0)
 
 struct platform_device;
 
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 05/17] Platform: OLPC: Move OLPC config symbol out of x86 tree

2018-11-16 Thread Lubomir Rintel
There are ARM OLPC machines that use mostly the same drivers, including
EC infrastructure, DCON and Battery.

While at that, fix Kconfig to allow building this as a module.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- Use 'depends on OLPC && X86' idiom (thanks Andy Shevchenko)

 arch/x86/Kconfig  | 11 ---
 drivers/input/mouse/Kconfig   |  3 ++-
 drivers/platform/Kconfig  |  2 ++
 drivers/platform/olpc/Kconfig | 11 +++
 drivers/staging/olpc_dcon/Kconfig |  3 ++-
 5 files changed, 17 insertions(+), 13 deletions(-)
 create mode 100644 drivers/platform/olpc/Kconfig

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 9d734f3c8234..f98f78e317d4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2734,17 +2734,6 @@ config SCx200HR_TIMER
  processor goes idle (as is done by the scheduler).  The
  other workaround is idle=poll boot option.
 
-config OLPC
-   bool "One Laptop Per Child support"
-   depends on !X86_PAE
-   select GPIOLIB
-   select OF
-   select OF_PROMTREE
-   select IRQ_DOMAIN
-   ---help---
- Add support for detecting the unique features of the OLPC
- XO hardware.
-
 config OLPC_XO1_PM
bool "OLPC XO-1 Power Management"
depends on OLPC && MFD_CS5535=y && PM_SLEEP
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 566a1e3aa504..cf12d0e4fba2 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -165,7 +165,8 @@ config MOUSE_PS2_TOUCHKIT
 
 config MOUSE_PS2_OLPC
bool "OLPC PS/2 mouse protocol extension"
-   depends on MOUSE_PS2 && OLPC
+   depends on MOUSE_PS2
+   depends on OLPC && X86
help
  Say Y here if you have an OLPC XO-1 laptop (with built-in
  PS/2 touchpad/tablet device).  The manufacturer calls the
diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
index d4c2e424a700..4313d73d3618 100644
--- a/drivers/platform/Kconfig
+++ b/drivers/platform/Kconfig
@@ -10,3 +10,5 @@ source "drivers/platform/goldfish/Kconfig"
 source "drivers/platform/chrome/Kconfig"
 
 source "drivers/platform/mellanox/Kconfig"
+
+source "drivers/platform/olpc/Kconfig"
diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfig
new file mode 100644
index ..7b736c9e67ac
--- /dev/null
+++ b/drivers/platform/olpc/Kconfig
@@ -0,0 +1,11 @@
+config OLPC
+   tristate "One Laptop Per Child support"
+   depends on X86 || ARM || COMPILE_TEST
+   depends on !X86_PAE
+   select GPIOLIB
+   select OF
+   select OF_PROMTREE if X86
+   select IRQ_DOMAIN
+   help
+ Add support for detecting the unique features of the OLPC
+ XO hardware.
diff --git a/drivers/staging/olpc_dcon/Kconfig 
b/drivers/staging/olpc_dcon/Kconfig
index 192cc8d0853f..ff540350f50f 100644
--- a/drivers/staging/olpc_dcon/Kconfig
+++ b/drivers/staging/olpc_dcon/Kconfig
@@ -1,8 +1,9 @@
 config FB_OLPC_DCON
tristate "One Laptop Per Child Display CONtroller support"
-   depends on OLPC && FB
+   depends on FB
depends on I2C
depends on BACKLIGHT_LCD_SUPPORT
+   depends on OLPC && X86
depends on (GPIO_CS5535 || GPIO_CS5535=n)
select BACKLIGHT_CLASS_DEVICE
help
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 02/17] dt-bindings: olpc, xo1.75-ec: Add OLPC XO-1.75 EC bindings

2018-11-16 Thread Lubomir Rintel
The OLPC XO-1.75 Embedded Controller is a SPI master that uses extra
signals for handshaking. It needs to know when is the slave (Linux)
side's TX FIFO ready for transfer (the ready-gpio signal on the SPI
controller node) and when does it wish to respond with a command (the
cmd-gpio property).

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- s/cmd-gpio/cmd-gpios/
- s/ready-gpio/ready-gpios/ in the documentation paragraph
- Remove status = "okay" from the example

 .../bindings/misc/olpc,xo1.75-ec.txt  | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt

diff --git a/Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt 
b/Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt
new file mode 100644
index ..8c4d649cdd8f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/olpc,xo1.75-ec.txt
@@ -0,0 +1,23 @@
+OLPC XO-1.75 Embedded Controller
+
+Required properties:
+- compatible: Should be "olpc,xo1.75-ec".
+- cmd-gpios: gpio specifier of the CMD pin
+
+The embedded controller requires the SPI controller driver to signal readiness
+to receive a transfer (that is, when TX FIFO contains the response data) by
+strobing the ACK pin with the ready signal. See the "ready-gpios" property of 
the
+SSP binding as documented in:
+.
+
+Example:
+   &ssp3 {
+   spi-slave;
+   ready-gpios = <&gpio 125 GPIO_ACTIVE_HIGH>;
+
+   slave {
+   compatible = "olpc,xo1.75-ec";
+   spi-cpha;
+   cmd-gpios = <&gpio 155 GPIO_ACTIVE_HIGH>;
+   };
+   };
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 03/17] Platform: OLPC: Remove an unused include

2018-11-16 Thread Lubomir Rintel
Also, the header is x86 specific, while there are non-x86 OLPC machines.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 
---
 drivers/platform/olpc/olpc-ec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 374a8028fec7..981955dce926 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 
 struct ec_cmd_desc {
u8 cmd;
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 04/17] Revert "platform/olpc: Make ec explicitly non-modular"

2018-11-16 Thread Lubomir Rintel
It doesn't make sense to always have this built-in, e.g. on ARM
multiplatform kernels.

A better way to address the problem the original commit aimed to solve is
to fix Kconfig. That is what the next commit in the series does.

This reverts commit f48d1496b8537d75776478c6942dd87f34d7f270.

Signed-off-by: Lubomir Rintel 

---
Changes since v1:
- Sort it later in the patch set

 drivers/platform/olpc/olpc-ec.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c
index 981955dce926..35a21c66cd0d 100644
--- a/drivers/platform/olpc/olpc-ec.c
+++ b/drivers/platform/olpc/olpc-ec.c
@@ -1,8 +1,6 @@
 /*
  * Generic driver for the OLPC Embedded Controller.
  *
- * Author: Andres Salomon 
- *
  * Copyright (C) 2011-2012 One Laptop per Child Foundation.
  *
  * Licensed under the GPL v2 or later.
@@ -14,7 +12,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -327,4 +325,8 @@ static int __init olpc_ec_init_module(void)
 {
return platform_driver_register(&olpc_ec_plat_driver);
 }
+
 arch_initcall(olpc_ec_init_module);
+
+MODULE_AUTHOR("Andres Salomon ");
+MODULE_LICENSE("GPL");
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 12/17] x86, olpc: Use a correct version when making up a battery node

2018-11-16 Thread Lubomir Rintel
The XO-1 and XO-1.5 batteries apparently differ in an ability to report
ambient temperature. Add a different compatible string to the 1.5
battery.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- Avoid splitting string literals

 arch/x86/platform/olpc/olpc_dt.c | 85 +---
 1 file changed, 57 insertions(+), 28 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
index 24d2175a9480..6063f52ed807 100644
--- a/arch/x86/platform/olpc/olpc_dt.c
+++ b/arch/x86/platform/olpc/olpc_dt.c
@@ -218,10 +218,28 @@ static u32 __init olpc_dt_get_board_revision(void)
return be32_to_cpu(rev);
 }
 
-void __init olpc_dt_fixup(void)
+int olpc_dt_compatible_match(phandle node, const char *compat)
 {
-   int r;
char buf[64];
+   int plen;
+   char *p;
+   int len;
+
+   plen = olpc_dt_getproperty(node, "compatible", buf, sizeof(buf));
+   if (plen <= 0)
+   return 0;
+
+   len = strlen(compat);
+   for (p = buf; p < buf + plen; p += strlen(p) + 1) {
+   if (strcmp(p, compat) == 0)
+   return 1;
+   }
+
+   return 0;
+}
+
+void __init olpc_dt_fixup(void)
+{
phandle node;
u32 board_rev;
 
@@ -229,41 +247,51 @@ void __init olpc_dt_fixup(void)
if (!node)
return;
 
-   /*
-* If the battery node has a compatible property, we are running a new
-* enough firmware and don't have fixups to make.
-*/
-   r = olpc_dt_getproperty(node, "compatible", buf, sizeof(buf));
-   if (r > 0)
-   return;
-
-   pr_info("PROM DT: Old firmware detected, applying fixes\n");
-
-   /* Add olpc,xo1-battery compatible marker to battery node */
-   olpc_dt_interpret("\" /battery@0\" find-device"
-   " \" olpc,xo1-battery\" +compatible"
-   " device-end");
-
board_rev = olpc_dt_get_board_revision();
if (!board_rev)
return;
 
if (board_rev >= olpc_board_pre(0xd0)) {
+   if (olpc_dt_compatible_match(node, "olpc,xo1.5-battery"))
+   return;
+
+   /* Add olpc,xo1.5-battery compatible marker to battery node */
+   olpc_dt_interpret("\" /battery@0\" find-device");
+   olpc_dt_interpret("  \" olpc,xo1.5-battery\" +compatible");
+   olpc_dt_interpret("device-end");
+
+   /* We're running a very old firmware if this is missing. */
+   if (olpc_dt_compatible_match(node, "olpc,xo1-battery"))
+   return;
+
/* XO-1.5: add dcon device */
-   olpc_dt_interpret("\" /pci/display@1\" find-device"
-   " new-device"
-   " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
-   " finish-device device-end");
+   olpc_dt_interpret("\" /pci/display@1\" find-device");
+   olpc_dt_interpret("  new-device");
+   olpc_dt_interpret("\" dcon\" device-name");
+   olpc_dt_interpret("\" olpc,xo1-dcon\" +compatible");
+   olpc_dt_interpret("  finish-device");
+   olpc_dt_interpret("device-end");
} else {
+   /* We're running a very old firmware if this is missing. */
+   if (olpc_dt_compatible_match(node, "olpc,xo1-battery"))
+   return;
+
/* XO-1: add dcon device, mark RTC as olpc,xo1-rtc */
-   olpc_dt_interpret("\" /pci/display@1,1\" find-device"
-   " new-device"
-   " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
-   " finish-device device-end"
-   " \" /rtc\" find-device"
-   " \" olpc,xo1-rtc\" +compatible"
-   " device-end");
+   olpc_dt_interpret("\" /pci/display@1,1\" find-device");
+   olpc_dt_interpret("  new-device");
+   olpc_dt_interpret("\" dcon\" device-name");
+   olpc_dt_interpret("\" olpc,xo1-dcon\" +compatible");
+   olpc_dt_interpret("  finish-device");
+   olpc_dt_interpret("device-end");
+   olpc_dt_interpret("\" /rtc\" find-device");
+   olpc_dt_i

[PATCH v2 06/17] Platform: OLPC: Add XO-1.75 EC driver

2018-11-16 Thread Lubomir Rintel
It's based off the driver from the OLPC kernel sources. Somewhat
modernized and cleaned up, for better or worse.

Modified to plug into the olpc-ec driver infrastructure (so that battery
interface and debugfs could be reused) and the SPI slave framework.

Signed-off-by: Lubomir Rintel 

---
Changes since v1:
- Cosmetic style changes; whitespace, ordering of declarations and
  #includes, remoted extra comas from sentinels
- Count the terminating NUL in LOG_BUF_SIZE
- Make olpc_xo175_ec_is_valid_cmd() return -EINVAL instead of -1
  on error
- Spell keyboard/touchpad in full for CHAN_KEYBOARD/TOUCHPAD messages
- Use a #define for PM wakeup processing time
- Log a message on unknown event
- Escape logging payload with %*pE
- Replace an open-coded min()
- Correct an error code on short read
- replaced PM callback #ifdefs with __maybe_unusedm SET_RUNTIME_PM_OPS
  and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS
- dev_get_drvdata() instead of a round-trip through platform device
- s/unsigned char x/u8 x/ in olpc_xo175_ec_resume()
- Use GENMASK() instead of 0x for the event mask
- Replace cmd tx/resp rx buffers with structures
- Turned suspend hint arguments into a struct, and tidied up the comment

Basically all of the above is based on the review by Andy Shevchenko.

 drivers/platform/olpc/Kconfig |  15 +
 drivers/platform/olpc/Makefile|   1 +
 drivers/platform/olpc/olpc-xo175-ec.c | 763 ++
 3 files changed, 779 insertions(+)
 create mode 100644 drivers/platform/olpc/olpc-xo175-ec.c

diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfig
index 7b736c9e67ac..7c643d24ad0f 100644
--- a/drivers/platform/olpc/Kconfig
+++ b/drivers/platform/olpc/Kconfig
@@ -9,3 +9,18 @@ config OLPC
help
  Add support for detecting the unique features of the OLPC
  XO hardware.
+
+if OLPC
+
+config OLPC_XO175_EC
+   tristate "OLPC XO 1.75 Embedded Controller"
+   depends on ARCH_MMP || COMPILE_TEST
+   select SPI_SLAVE
+   help
+ Include support for the OLPC XO Embedded Controller (EC). The EC
+ provides various platform services, including support for the power,
+ button, restart, shutdown and battery charging status.
+
+ Unless you have an OLPC XO laptop, you will want to say N.
+
+endif
diff --git a/drivers/platform/olpc/Makefile b/drivers/platform/olpc/Makefile
index dc8b26bc7209..5b43f383289e 100644
--- a/drivers/platform/olpc/Makefile
+++ b/drivers/platform/olpc/Makefile
@@ -2,3 +2,4 @@
 # OLPC XO platform-specific drivers
 #
 obj-$(CONFIG_OLPC) += olpc-ec.o
+obj-$(CONFIG_OLPC_XO175_EC)+= olpc-xo175-ec.o
diff --git a/drivers/platform/olpc/olpc-xo175-ec.c 
b/drivers/platform/olpc/olpc-xo175-ec.c
new file mode 100644
index ..74db06bacc44
--- /dev/null
+++ b/drivers/platform/olpc/olpc-xo175-ec.c
@@ -0,0 +1,763 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Driver for the OLPC XO-1.75 Embedded Controller.
+ *
+ * The EC protocol is documented at:
+ * http://wiki.laptop.org/go/XO_1.75_HOST_to_EC_Protocol
+ *
+ * Copyright (C) 2010 One Laptop per Child Foundation.
+ * Copyright (C) 2018 Lubomir Rintel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct ec_cmd_t {
+   u8 cmd;
+   u8 bytes_returned;
+};
+
+enum ec_chan_t {
+   CHAN_NONE = 0,
+   CHAN_SWITCH,
+   CHAN_CMD_RESP,
+   CHAN_KEYBOARD,
+   CHAN_TOUCHPAD,
+   CHAN_EVENT,
+   CHAN_DEBUG,
+   CHAN_CMD_ERROR,
+};
+
+/*
+ * EC events
+ */
+#define EVENT_AC_CHANGE1  /* AC plugged/unplugged */
+#define EVENT_BATTERY_STATUS   2  /* Battery low/full/error/gone */
+#define EVENT_BATTERY_CRITICAL 3  /* Battery critical voltage */
+#define EVENT_BATTERY_SOC_CHANGE   4  /* 1% SOC Change */
+#define EVENT_BATTERY_ERROR5  /* Abnormal error, query for cause */
+#define EVENT_POWER_PRESSED6  /* Power button was pressed */
+#define EVENT_POWER_PRESS_WAKE 7  /* Woken up with a power button */
+#define EVENT_TIMED_HOST_WAKE  8  /* Host wake timer */
+#define EVENT_OLS_HIGH_LIMIT   9  /* OLS crossed dark threshold */
+#define EVENT_OLS_LOW_LIMIT10 /* OLS crossed light threshold */
+
+/*
+ * EC commands
+ * (from http://dev.laptop.org/git/users/rsmith/ec-1.75/tree/ec_cmd.h)
+ */
+#define CMD_GET_API_VERSION0x08 /* out: u8 */
+#define CMD_READ_VOLTAGE   0x10 /* out: u16, *9.76/32, mV */
+#define CMD_READ_CURRENT   0x11 /* out: s16, *15.625/120, mA */
+#define CMD_READ_ACR   0x12 /* out: s16, *6250/15, uAh */
+#define CMD_READ_BATT_TEMPERATURE  0x13 /* out: u16, *100/256, deg C */
+#define CMD_READ_AMBIENT_TEMPERATURE   0x14 /* unimplemented, no hardware */
+#define CMD_READ_BATTERY_STATUS

[PATCH v2 17/17] power: supply: olpc_battery: Add OLPC XO 1.75 support

2018-11-16 Thread Lubomir Rintel
The battery and the protocol are essentially the same as OLPC XO 1.5,
but the responses from the EC are LSB first.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- s/s16 ecword_to_cpu/u16 ecword_to_cpu/
- s/u16 ec_byte/u16 ec_word/

 drivers/power/supply/olpc_battery.c | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index ec5dfb8fcb8a..898e8a6128bb 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -56,6 +56,7 @@ struct olpc_battery_data {
struct power_supply *olpc_bat;
char bat_serial[17];
int new_proto;
+   int little_endian;
 };
 
 /*
@@ -321,6 +322,14 @@ static int olpc_bat_get_voltage_max_design(union 
power_supply_propval *val)
return ret;
 }
 
+static u16 ecword_to_cpu(struct olpc_battery_data *data, u16 ec_word)
+{
+   if (data->little_endian)
+   return le16_to_cpu(ec_word);
+   else
+   return be16_to_cpu(ec_word);
+}
+
 /*
  * Battery properties
  */
@@ -393,7 +402,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 9760L / 32;
+   val->intval = ecword_to_cpu(data, ec_word) * 9760L / 32;
break;
case POWER_SUPPLY_PROP_CURRENT_AVG:
case POWER_SUPPLY_PROP_CURRENT_NOW:
@@ -401,7 +410,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120;
+   val->intval = ecword_to_cpu(data, ec_word) * 15625L / 120;
break;
case POWER_SUPPLY_PROP_CAPACITY:
ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
@@ -432,21 +441,21 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 10 / 256;
+   val->intval = ecword_to_cpu(data, ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
 
-   val->intval = (int)be16_to_cpu(ec_word) * 10 / 256;
+   val->intval = (int)ecword_to_cpu(data, ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
 
-   val->intval = (s16)be16_to_cpu(ec_word) * 6250 / 15;
+   val->intval = ecword_to_cpu(data, ec_word) * 6250 / 15;
break;
case POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8);
@@ -626,6 +635,10 @@ static int olpc_battery_probe(struct platform_device *pdev)
if (ecver > 0x44) {
/* XO 1 or 1.5 with a new EC firmware. */
data->new_proto = 1;
+   } else if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) {
+   /* XO 1.75 */
+   data->new_proto = 1;
+   data->little_endian = 1;
} else if (ecver < 0x44) {
/*
 * We've seen a number of EC protocol changes; this driver
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 08/17] Platform: OLPC: Move EC-specific functionality out from x86

2018-11-16 Thread Lubomir Rintel
Move the olpc-ec driver away from the X86 OLPC platform so that it could be
used by the ARM based laptops too. Notably, the driver for the OLPC battery,
which is also used on the ARM models, builds on this driver's interface.

It is actually plaform independent: the OLPC EC commands with their argument
and responses are mostly the same despite the delivery mechanism is
different.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- Cosmetic changes in line wrapping.
- Remove an old extra copy of EC_SCI_* defines
- Change version to u8
- Explain which parts are platform independent are in the commit message

 arch/x86/include/asm/olpc.h |  31 -
 arch/x86/platform/olpc/olpc.c   | 119 +---
 drivers/platform/olpc/olpc-ec.c |  99 +-
 include/linux/olpc-ec.h |  32 -
 4 files changed, 145 insertions(+), 136 deletions(-)

diff --git a/arch/x86/include/asm/olpc.h b/arch/x86/include/asm/olpc.h
index c2bf1de5d901..6fe76282aceb 100644
--- a/arch/x86/include/asm/olpc.h
+++ b/arch/x86/include/asm/olpc.h
@@ -9,12 +9,10 @@
 struct olpc_platform_t {
int flags;
uint32_t boardrev;
-   int ecver;
 };
 
 #define OLPC_F_PRESENT 0x01
 #define OLPC_F_DCON0x02
-#define OLPC_F_EC_WIDE_SCI 0x04
 
 #ifdef CONFIG_OLPC
 
@@ -64,13 +62,6 @@ static inline int olpc_board_at_least(uint32_t rev)
return olpc_platform_info.boardrev >= rev;
 }
 
-extern void olpc_ec_wakeup_set(u16 value);
-extern void olpc_ec_wakeup_clear(u16 value);
-extern bool olpc_ec_wakeup_available(void);
-
-extern int olpc_ec_mask_write(u16 bits);
-extern int olpc_ec_sci_query(u16 *sci_value);
-
 #else
 
 static inline int machine_is_olpc(void)
@@ -83,14 +74,6 @@ static inline int olpc_has_dcon(void)
return 0;
 }
 
-static inline void olpc_ec_wakeup_set(u16 value) { }
-static inline void olpc_ec_wakeup_clear(u16 value) { }
-
-static inline bool olpc_ec_wakeup_available(void)
-{
-   return false;
-}
-
 #endif
 
 #ifdef CONFIG_OLPC_XO1_PM
@@ -101,20 +84,6 @@ extern void olpc_xo1_pm_wakeup_clear(u16 value);
 
 extern int pci_olpc_init(void);
 
-/* SCI source values */
-
-#define EC_SCI_SRC_EMPTY   0x00
-#define EC_SCI_SRC_GAME0x01
-#define EC_SCI_SRC_BATTERY 0x02
-#define EC_SCI_SRC_BATSOC  0x04
-#define EC_SCI_SRC_BATERR  0x08
-#define EC_SCI_SRC_EBOOK   0x10/* XO-1 only */
-#define EC_SCI_SRC_WLAN0x20/* XO-1 only */
-#define EC_SCI_SRC_ACPWR   0x40
-#define EC_SCI_SRC_BATCRIT 0x80
-#define EC_SCI_SRC_GPWAKE  0x100   /* XO-1.5 only */
-#define EC_SCI_SRC_ALL 0x1FF
-
 /* GPIO assignments */
 
 #define OLPC_GPIO_MIC_AC   1
diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
index f0e920fb98ad..c6c62b4f251f 100644
--- a/arch/x86/platform/olpc/olpc.c
+++ b/arch/x86/platform/olpc/olpc.c
@@ -30,9 +30,6 @@
 struct olpc_platform_t olpc_platform_info;
 EXPORT_SYMBOL_GPL(olpc_platform_info);
 
-/* EC event mask to be applied during suspend (defining wakeup sources). */
-static u16 ec_wakeup_mask;
-
 /* what the timeout *should* be (in ms) */
 #define EC_BASE_TIMEOUT 20
 
@@ -186,83 +183,6 @@ static int olpc_xo1_ec_cmd(u8 cmd, u8 *inbuf, size_t 
inlen, u8 *outbuf,
return ret;
 }
 
-void olpc_ec_wakeup_set(u16 value)
-{
-   ec_wakeup_mask |= value;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_wakeup_set);
-
-void olpc_ec_wakeup_clear(u16 value)
-{
-   ec_wakeup_mask &= ~value;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_wakeup_clear);
-
-/*
- * Returns true if the compile and runtime configurations allow for EC events
- * to wake the system.
- */
-bool olpc_ec_wakeup_available(void)
-{
-   if (!machine_is_olpc())
-   return false;
-
-   /*
-* XO-1 EC wakeups are available when olpc-xo1-sci driver is
-* compiled in
-*/
-#ifdef CONFIG_OLPC_XO1_SCI
-   if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) /* XO-1 */
-   return true;
-#endif
-
-   /*
-* XO-1.5 EC wakeups are available when olpc-xo15-sci driver is
-* compiled in
-*/
-#ifdef CONFIG_OLPC_XO15_SCI
-   if (olpc_platform_info.boardrev >= olpc_board_pre(0xd0)) /* XO-1.5 */
-   return true;
-#endif
-
-   return false;
-}
-EXPORT_SYMBOL_GPL(olpc_ec_wakeup_available);
-
-int olpc_ec_mask_write(u16 bits)
-{
-   if (olpc_platform_info.flags & OLPC_F_EC_WIDE_SCI) {
-   __be16 ec_word = cpu_to_be16(bits);
-   return olpc_ec_cmd(EC_WRITE_EXT_SCI_MASK, (void *) &ec_word, 2,
-  NULL, 0);
-   } else {
-   unsigned char ec_byte = bits & 0xff;
-   return olpc_ec_cmd(EC_WRITE_SCI_MASK, &ec_byte, 1, NULL, 0);
-   }
-}
-EXPORT_SYMBOL_GPL(olpc_ec_mask_write);
-
-int olpc_ec_sci_query(u16 *sci_value)
-{
-   int ret;
-
-   if (olpc_platfo

[PATCH v2 14/17] power: supply: olpc_battery: Move priv data to a struct

2018-11-16 Thread Lubomir Rintel
The global variables for private data are not too nice. I'd like some
more, and that would clutter the global name space even further.

Signed-off-by: Lubomir Rintel 
Reviewed-by: Andy Shevchenko 

---
Changes since v1:
- Split out the move to devm_* into a separate patch

 drivers/power/supply/olpc_battery.c | 68 +
 1 file changed, 40 insertions(+), 28 deletions(-)

diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 5323987d9284..b091f897c1d4 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -53,6 +53,12 @@
 
 #define BAT_ADDR_MFR_TYPE  0x5F
 
+struct olpc_battery_data {
+   struct power_supply *olpc_ac;
+   struct power_supply *olpc_bat;
+   char bat_serial[17];
+};
+
 /*
  * Power
  */
@@ -91,11 +97,8 @@ static const struct power_supply_desc olpc_ac_desc = {
.get_property = olpc_ac_get_prop,
 };
 
-static struct power_supply *olpc_ac;
-
-static char bat_serial[17]; /* Ick */
-
-static int olpc_bat_get_status(union power_supply_propval *val, uint8_t 
ec_byte)
+static int olpc_bat_get_status(struct olpc_battery_data *data,
+   union power_supply_propval *val, uint8_t ec_byte)
 {
if (olpc_platform_info.ecver > 0x44) {
if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
@@ -326,6 +329,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
 enum power_supply_property psp,
 union power_supply_propval *val)
 {
+   struct olpc_battery_data *data = power_supply_get_drvdata(psy);
int ret = 0;
__be16 ec_word;
uint8_t ec_byte;
@@ -347,7 +351,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
 
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
-   ret = olpc_bat_get_status(val, ec_byte);
+   ret = olpc_bat_get_status(data, val, ec_byte);
if (ret)
return ret;
break;
@@ -450,8 +454,8 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
 
-   sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
-   val->strval = bat_serial;
+   sprintf(data->bat_serial, "%016llx", (long 
long)be64_to_cpu(ser_buf));
+   val->strval = data->bat_serial;
break;
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
ret = olpc_bat_get_voltage_max_design(val);
@@ -579,17 +583,17 @@ static struct power_supply_desc olpc_bat_desc = {
.use_for_apm = 1,
 };
 
-static struct power_supply *olpc_bat;
-
 static int olpc_battery_suspend(struct platform_device *pdev,
pm_message_t state)
 {
-   if (device_may_wakeup(&olpc_ac->dev))
+   struct olpc_battery_data *data = platform_get_drvdata(pdev);
+
+   if (device_may_wakeup(&data->olpc_ac->dev))
olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
else
olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
 
-   if (device_may_wakeup(&olpc_bat->dev))
+   if (device_may_wakeup(&data->olpc_bat->dev))
olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
   | EC_SCI_SRC_BATERR);
else
@@ -601,7 +605,8 @@ static int olpc_battery_suspend(struct platform_device 
*pdev,
 
 static int olpc_battery_probe(struct platform_device *pdev)
 {
-   int ret;
+   struct power_supply_config psy_cfg = {};
+   struct olpc_battery_data *data;
uint8_t status;
 
/*
@@ -620,9 +625,13 @@ static int olpc_battery_probe(struct platform_device *pdev)
 
/* Ignore the status. It doesn't actually matter */
 
-   olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
-   if (IS_ERR(olpc_ac))
-   return PTR_ERR(olpc_ac);
+   psy_cfg.of_node = pdev->dev.of_node;
+   psy_cfg.drv_data = data;
+
+   data->olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, 
&psy_cfg);
+   if (IS_ERR(data->olpc_ac))
+   return PTR_ERR(data->olpc_ac);
+
if (of_property_match_string(pdev->dev.of_node, "compatible",
"olpc,xo1.5-battery") >= 0) {
/* XO-1.5 */
@@ -634,42 +643,45 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
}
 
-   olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, NULL);
+   data->olpc_bat = power_sup

[PATCH v2 11/17] dt-bindings: olpc_battery: Add XO-1.5 battery

2018-11-16 Thread Lubomir Rintel
The XO-1 and XO-1.5 batteries apparently differ in an ability to report
ambient temperature.

Signed-off-by: Lubomir Rintel 
Reviewed-by: Rob Herring 
Acked-by: Pavel Machek 

---
Changes since v1:
- Collected Reviewed-by and Acked-by tags

 Documentation/devicetree/bindings/power/supply/olpc_battery.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/power/supply/olpc_battery.txt 
b/Documentation/devicetree/bindings/power/supply/olpc_battery.txt
index c8901b3992d9..8d87d6b35a98 100644
--- a/Documentation/devicetree/bindings/power/supply/olpc_battery.txt
+++ b/Documentation/devicetree/bindings/power/supply/olpc_battery.txt
@@ -2,4 +2,4 @@ OLPC battery
 
 
 Required properties:
-  - compatible : "olpc,xo1-battery"
+  - compatible : "olpc,xo1-battery" or "olpc,xo1.5-battery"
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 16/17] power: supply: olpc_battery: Avoid using platform_info

2018-11-16 Thread Lubomir Rintel
This wouldn't work on the DT-based ARM platform. Let's read the EC version
directly from the EC driver instead.

This makes the driver no longer x86 specific.

Signed-off-by: Lubomir Rintel 
Acked-by: Pavel Machek 

---
Changes since v1:
- Use uint8_t instead of unsigned char [1] for ecver

 drivers/power/supply/Kconfig|  2 +-
 drivers/power/supply/olpc_battery.c | 35 +
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index f27cf0709500..dd7ae1431098 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -151,7 +151,7 @@ config BATTERY_PMU
 
 config BATTERY_OLPC
tristate "One Laptop Per Child battery"
-   depends on X86_32 && OLPC
+   depends on OLPC
help
  Say Y to enable support for the battery on the OLPC laptop.
 
diff --git a/drivers/power/supply/olpc_battery.c 
b/drivers/power/supply/olpc_battery.c
index 4433eb10a23d..ec5dfb8fcb8a 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -20,8 +20,6 @@
 #include 
 #include 
 #include 
-#include 
-
 
 #define EC_BAT_VOLTAGE 0x10/* uint16_t,*9.76/32,mV   */
 #define EC_BAT_CURRENT 0x11/* int16_t, *15.625/120, mA   */
@@ -57,6 +55,7 @@ struct olpc_battery_data {
struct power_supply *olpc_ac;
struct power_supply *olpc_bat;
char bat_serial[17];
+   int new_proto;
 };
 
 /*
@@ -100,7 +99,7 @@ static const struct power_supply_desc olpc_ac_desc = {
 static int olpc_bat_get_status(struct olpc_battery_data *data,
union power_supply_propval *val, uint8_t ec_byte)
 {
-   if (olpc_platform_info.ecver > 0x44) {
+   if (data->new_proto) {
if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else if (ec_byte & BAT_STAT_DISCHARGING)
@@ -608,14 +607,32 @@ static int olpc_battery_probe(struct platform_device 
*pdev)
struct power_supply_config psy_cfg = {};
struct olpc_battery_data *data;
uint8_t status;
+   uint8_t ecver;
+   int ret;
+
+   data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+   platform_set_drvdata(pdev, data);
+
+   /* See if the EC is already there and get the EC revision */
+   ret = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ecver, 1);
+   if (ret) {
+   if (ret == -ENODEV)
+   return -EPROBE_DEFER;
+   return ret;
+   }
 
-   /*
-* We've seen a number of EC protocol changes; this driver requires
-* the latest EC protocol, supported by 0x44 and above.
-*/
-   if (olpc_platform_info.ecver < 0x44) {
+   if (ecver > 0x44) {
+   /* XO 1 or 1.5 with a new EC firmware. */
+   data->new_proto = 1;
+   } else if (ecver < 0x44) {
+   /*
+* We've seen a number of EC protocol changes; this driver
+* requires the latest EC protocol, supported by 0x44 and above.
+*/
printk(KERN_NOTICE "OLPC EC version 0x%02x too old for "
-   "battery driver.\n", olpc_platform_info.ecver);
+   "battery driver.\n", ecver);
return -ENXIO;
}
 
-- 
2.19.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 06/15] Platform: OLPC: Add XO-1.75 EC driver

2018-11-19 Thread Lubomir Rintel
Hi Pavel,

I've addressed some of Andy's concerns you're replying to below in a
follow-up version of the patch. To many points I'm generally
indifferent and prefer to lean towards making things easy for whoever
may be likely to deal with the code in past. It's not clear to me who
that might be, or how important either of you consider your remarks to
be. I'll be thankful if anyone makes this clearer to me.

(I hoped that you're in the Cc list; thought git send-mail will see
your address in the Acked-by tags and add you. I failed to notice that
it's not the case. I apologize. Here's the v2 posting: [1].)

[1] https://lore.kernel.org/lkml/20181116162403.49854-1-lkund...@v3.sk/


On Mon, 2018-11-19 at 11:40 +0100, Pavel Machek wrote:
> Hi!
> 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > 
> > > Easy to maintain when it's sorted.
> 
> No / it depends.

I've sorted it in the new files; following a rule of keeping things
sorted at the very least has an advantage of being unambiguous.

I'm not sorting things where they currently are not in order, since it
would obscure real changes.

> > > > +   channel = priv->rx_buf[0];
> > > > +   byte = priv->rx_buf[1];
> > > 
> > > Maybe specific structures would fit better?
> > > 
> > > Like
> > > 
> > > struct olpc_ec_resp_hdr {
> > >  u8 channel;
> > >  u8 byte;
> > > ...
> > > }
> 
> Structures have padding and other nastyness...

I've turned them into structs. It perhaps looks a bit better -- the
structure members serving as a documentation for the protocol.

> > > > +   pm_wakeup_event(priv->pwrbtn-
> > > > >dev.parent,
> > > > 1000);
> > > 
> > > Magic number.
> 
> Nothing wrong with magic numbers.

Turned it into a define, but it's not like it's any clearer why that
particular value works...

I actually have little idea. I've copied this from the vendor's
original driver.

> > > > +   args[0] = mask & 0xff;
> > > > +   args[1] = (mask >> 8) & 0xff;
> > > 
> > > ...mask >> 0;
> > > ...mask >> 8;
> 
> No, please.

I've done this too, but I don't see much point either. Perhaps those
within the OCD spectrum may appreciate :)

> > > __maybe_unused  instead of ugly #ifdef?
> > > 
> > > > +{
> > > > +   struct platform_device *pdev = to_platform_device(dev);
> > > > +   struct olpc_xo175_ec *priv =
> > > > platform_get_drvdata(pdev);
> > > 
> > > dev_get_drvdata() or how is it called?
> > > 
> > > > +   unsigned char hintargs[5];
> > > 
> > > struct olpc_ec_hint_cmd {
> > > u8 ...
> > > u32 ...
> > > };
> > > 
> > > ?
> 
> No, unless you want to break the code. Or add __attribute__ packed
> and
> deal with endianness.
> 
> Just no.

Turned it into a packed struct too for the same reasons as above.

The endianness of the hints argument doesn't actually matter, since the
EC firmware actually uses this in a debugging printf. It's not even
cleat what endianness did EC expect initially.

> > > > +   static unsigned int suspend_count;
> > > 
> > > u32 I suppose.
> 
> You know, there's semantic difference between unsigned int and
> u32. And this sounds like candidate for unsigned int.
> 
> > > > +   /* Enable all EC events while we're awake */
> > > > +   olpc_xo175_ec_set_event_mask(0x);
> > > 
> > > #define EC_ALL_EVENTS GENMASK(15, 0)
> 
> Actually that's less readable. Just don't.

Done this too, and, like the points above, I am indifferent too. Both
seem equal to me.

> > > > +static const struct of_device_id olpc_xo175_ec_of_match[] = {
> > > > +   { .compatible = "olpc,xo1.75-ec" },
> > > > +   { },
> > > 
> > > No comma for terminators.
> 
> Comma is fine.

Removed it. Perhaps the lack of a comma could be understood as an
indication that no further initializers shall follow.

>   Pavel

Just in case I didn't stress that enough: I'm much more interested in
things working well than style issues that too often are just matter of
tast. I happily accept advice on those though.

Take care,
Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 17/17] power: supply: olpc_battery: Add OLPC XO 1.75 support

2019-01-07 Thread Lubomir Rintel
On Sun, 2018-12-02 at 15:34 -0800, Darren Hart wrote:
> On Fri, Nov 16, 2018 at 05:24:03PM +0100, Lubomir Rintel wrote:
> > The battery and the protocol are essentially the same as OLPC XO 1.5,
> > but the responses from the EC are LSB first.
> > 
> > Signed-off-by: Lubomir Rintel 
> > Acked-by: Pavel Machek 
> > 
> > ---
> > Changes since v1:
> > - s/s16 ecword_to_cpu/u16 ecword_to_cpu/
> > - s/u16 ec_byte/u16 ec_word/
> > 
> >  drivers/power/supply/olpc_battery.c | 23 ++-
> >  1 file changed, 18 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/power/supply/olpc_battery.c 
> > b/drivers/power/supply/olpc_battery.c
> 
> ...
> 
> > @@ -626,6 +635,10 @@ static int olpc_battery_probe(struct platform_device 
> > *pdev)
> > if (ecver > 0x44) {
> > /* XO 1 or 1.5 with a new EC firmware. */
> > data->new_proto = 1;
> > +   } else if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) {
> 
> This if/else blocks concerns me a bit, but I might just be missing some
> context.
> 
> This tests both ecver as well as the OF compatible string, is this reliable? 
> Do
> we know that for all xo1.75-ec compatible nodes the ecver will be <= 0x44? Or,
> is ecver undefined? If the latter, then perhaps this test should be performed
> first?
> 
> if (of_find_compatible_nodex01.75-ec...)
>   ...
> else if (ecver > 0x44)
>   ...
> else
>   ...
> 
> And what happens when ecver == 0x44? We test for > and < but not ==, <=,
> or >= in this block

You're right, the conditionals are not correct. On XO 1.75 the
versioning is different (now at level 0x05) and uninteresting,
therefore the XO 1.75 check needs to go first.

On XO 1 and XO 1.75, we don't support < 0x44. 0x44 is okay, though uses
stays with an old protocol, and > 0x44 uses a new protocol.

Will follow up with a new version of the patch soon.

> 
> > +   /* XO 1.75 */
> > +   data->new_proto = 1;
> > +   data->little_endian = 1;
> > } else if (ecver < 0x44) {
> > /*
> >  * We've seen a number of EC protocol changes; this driver
> > -- 
> > 2.19.1

Thanks
Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 13/17] power: supply: olpc_battery: Use DT to get battery version

2019-01-07 Thread Lubomir Rintel
On Wed, 2018-12-05 at 21:54 +0100, Sebastian Reichel wrote:
> Hi,
> 
> On Fri, Nov 16, 2018 at 05:23:59PM +0100, Lubomir Rintel wrote:
> > Avoid using the x86 OLPC platform specific call to get the board
> > version. It won't work on FDT-based ARM MMP2 platform.
> > 
> > Signed-off-by: Lubomir Rintel 
> > Reviewed-by: Andy Shevchenko 
> > Acked-by: Pavel Machek 
> > 
> > ---
> 
> Reviewed-by: Sebastian Reichel 
> 
> I assume this patch cannot be applied to power-supply without patch
> 12 having been merged to avoid breaking XO1.5 devices temporarily?

That is true. What's the correct way to deal with a situation like
this? Just hold the patch until the other changes get in, perhaps via
linux-platform-drivers-x86.git? Or maybe this can go in together via
that tree along with the other patches?

Thanks
Lubo

> -- Sebastian
> 
> > Changes since v1:
> > - Sort the new include a bit higher
> > 
> >  drivers/power/supply/olpc_battery.c | 10 +++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/power/supply/olpc_battery.c
> > b/drivers/power/supply/olpc_battery.c
> > index 5a97e42a3547..5323987d9284 100644
> > --- a/drivers/power/supply/olpc_battery.c
> > +++ b/drivers/power/supply/olpc_battery.c
> > @@ -14,6 +14,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -622,11 +623,13 @@ static int olpc_battery_probe(struct
> > platform_device *pdev)
> > olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc,
> > NULL);
> > if (IS_ERR(olpc_ac))
> > return PTR_ERR(olpc_ac);
> > -
> > -   if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
> > +   if (of_property_match_string(pdev->dev.of_node, "compatible",
> > +   "olpc,xo1.5-battery") >= 0) {
> > +   /* XO-1.5 */
> > olpc_bat_desc.properties = olpc_xo15_bat_props;
> > olpc_bat_desc.num_properties =
> > ARRAY_SIZE(olpc_xo15_bat_props);
> > -   } else { /* XO-1 */
> > +   } else {
> > +   /* XO-1 */
> > olpc_bat_desc.properties = olpc_xo1_bat_props;
> > olpc_bat_desc.num_properties =
> > ARRAY_SIZE(olpc_xo1_bat_props);
> > }
> > @@ -672,6 +675,7 @@ static int olpc_battery_remove(struct
> > platform_device *pdev)
> >  
> >  static const struct of_device_id olpc_battery_ids[] = {
> > { .compatible = "olpc,xo1-battery" },
> > +   { .compatible = "olpc,xo1.5-battery" },
> > {}
> >  };
> >  MODULE_DEVICE_TABLE(of, olpc_battery_ids);
> > -- 
> > 2.19.1
> > 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/5] staging: xgifb: Update TODO

2014-05-18 Thread Lubomir Rintel
There's no more printk abuse, it's been sorted out in
448810662ac3 ("Staging: xgifb: Remove printk usage.")

Extra ifdefs have been fixed too, mostly in
800d67cf9f77 ("staging: xgifb: eliminate #ifdef Tap4"),
c39aada6926c ("staging: xgifb: eliminate #ifdef XGIFB_PAN"),
fa4c212f2b81 ("staging: xgifb: delete unused definitions"),
5c167b30c1b4 ("staging: xgifb: eliminate #ifdef NewScratch"),
f059077388b0 ("Staging: xgifb: Remove #ifdef MODULE") and more.

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/xgifb/TODO | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/xgifb/TODO b/drivers/staging/xgifb/TODO
index 392b29d..7eb9914 100644
--- a/drivers/staging/xgifb/TODO
+++ b/drivers/staging/xgifb/TODO
@@ -6,8 +6,7 @@ Arnaud
 TODO:
 - clean ups
 - sort out dup ids with SiS driver
-- remove useless/wrong/unused #ifdef/code/...
-- fix printk usages
+- remove useless/wrong/unused code...
 - get rid of non-linux related stuff
 
 Please send patches to:
-- 
1.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/5] staging: xgifb: Drop some more useless defines

2014-05-18 Thread Lubomir Rintel
SetLCDStdMode is not supported as of 34c13ee2b690 ("staging: xgifb: drop
code for legacy VGA modes").

DisableLCD24bpp defined to zero was never realy useful and went away with
aa56b2790a8b ("staging: xgifb: vb_table: delete XGI21_LCDCapList").

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/xgifb/vb_def.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/xgifb/vb_def.h b/drivers/staging/xgifb/vb_def.h
index 949f0e5..481eb17 100644
--- a/drivers/staging/xgifb/vb_def.h
+++ b/drivers/staging/xgifb/vb_def.h
@@ -44,12 +44,10 @@
 #define SetLCDtoNonExpanding 0x0010
 #define SetLCDDualLink   0x0100
 #define SetLCDLowResolution  0x0200
-#define SetLCDStdMode0x0400
 
 /* LCD Capability shampoo */
 #define DefaultLCDCap0x80ea
 #define EnableLCD24bpp   0x0004 /* default */
-#define DisableLCD24bpp  0x
 #define LCDPolarity  0x00c0 /* default: SyncNN */
 #define XGI_LCDDualLink  0x0100
 #define EnableSpectrum   0x0200
-- 
1.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/5] staging: xgifb: Drop pr_fmt

2014-05-18 Thread Lubomir Rintel
It is neither used nor useful.

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/xgifb/XGI_main_26.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/xgifb/XGI_main_26.c 
b/drivers/staging/xgifb/XGI_main_26.c
index a62d4dd..d61e03f 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -4,8 +4,6 @@
  * Base on TW's sis fbdev code.
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include 
 #include 
 
-- 
1.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/5] staging: xgifb: Eliminate useless ifndefs

2014-05-18 Thread Lubomir Rintel
XGI_VB_CHIP_TYPE, PCI_DEVICE_ID_XGI_42 and PCI_DEVICE_ID_XGI_27
are never defined.

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/xgifb/XGI_main.h | 4 
 drivers/staging/xgifb/vgatypes.h | 2 --
 2 files changed, 6 deletions(-)

diff --git a/drivers/staging/xgifb/XGI_main.h b/drivers/staging/xgifb/XGI_main.h
index 95ce970..85079fe 100644
--- a/drivers/staging/xgifb/XGI_main.h
+++ b/drivers/staging/xgifb/XGI_main.h
@@ -4,12 +4,8 @@
 #include "XGIfb.h"
 #include "vb_def.h"
 
-#ifndef PCI_DEVICE_ID_XGI_42
 #define PCI_DEVICE_ID_XGI_42  0x042
-#endif
-#ifndef PCI_DEVICE_ID_XGI_27
 #define PCI_DEVICE_ID_XGI_27  0x027
-#endif
 
 static const struct pci_device_id xgifb_pci_table[] = {
{PCI_DEVICE(PCI_VENDOR_ID_XGI, PCI_DEVICE_ID_XGI_20)},
diff --git a/drivers/staging/xgifb/vgatypes.h b/drivers/staging/xgifb/vgatypes.h
index 2643514..61fa10f 100644
--- a/drivers/staging/xgifb/vgatypes.h
+++ b/drivers/staging/xgifb/vgatypes.h
@@ -5,7 +5,6 @@
 #include "../../video/fbdev/sis/vgatypes.h"
 #include "../../video/fbdev/sis/sis.h" /* for LCD_TYPE */
 
-#ifndef XGI_VB_CHIP_TYPE
 enum XGI_VB_CHIP_TYPE {
VB_CHIP_Legacy = 0,
VB_CHIP_301,
@@ -19,7 +18,6 @@ enum XGI_VB_CHIP_TYPE {
VB_CHIP_UNKNOWN, /* other video bridge or no video bridge */
MAX_VB_CHIP
 };
-#endif
 
 struct xgi_hw_device_info {
unsigned long ulExternalChip; /* NO VB or other video bridge*/
-- 
1.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/5] staging: xgifb: Initialize Part0Port

2014-05-18 Thread Lubomir Rintel
It was left uninitialized, likely overseen, in this commit:
56810a92c689c6 ("staging: xgifb: use XGIRegInit()
Avoid copy-paste and use XGIRegInit() to initialize registers addresses.")

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/xgifb/XGI_main_26.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/xgifb/XGI_main_26.c 
b/drivers/staging/xgifb/XGI_main_26.c
index d61e03f..6bca72f 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -216,6 +216,7 @@ void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned 
long BaseAddr)
XGI_Pr->P3c8 = BaseAddr + 0x18;
XGI_Pr->P3c9 = BaseAddr + 0x19;
XGI_Pr->P3da = BaseAddr + 0x2A;
+   XGI_Pr->Part0Port = BaseAddr + XGI_CRT2_PORT_00;
/* Digital video interface registers (LCD) */
XGI_Pr->Part1Port = BaseAddr + SIS_CRT2_PORT_04;
/* 301 TV Encoder registers */
-- 
1.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


staging: xgifb: A couple of minor tidyups

2014-05-18 Thread Lubomir Rintel
Hi,

I've cleaned up some small issues in xgifb driver as part of a solution to an 
Eudyptula Challenge [1] task. The patches are chained to this message.

[1] http://eudyptula-challenge.org/

Lubo

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: crystalhd: Do not mix integers and user pointers

2014-06-20 Thread Lubomir Rintel
Fixes the following sparse warnings:

  crystalhd/crystalhd_lnx.c:227:61: warning: incorrect type in argument 3 
(different base types)
  crystalhd/crystalhd_lnx.c:227:61:expected unsigned long [unsigned] ua
  crystalhd/crystalhd_lnx.c:227:61:got void [noderef] *ua
  crystalhd/crystalhd_lnx.c:229:65: warning: incorrect type in argument 4 
(different base types)
  crystalhd/crystalhd_lnx.c:229:65:expected unsigned long [unsigned] ua
  crystalhd/crystalhd_lnx.c:229:65:got void [noderef] *ua

Done for the Eudyptula challenge.

Signed-off-by: Lubomir Rintel 
---
 drivers/staging/crystalhd/crystalhd_lnx.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/crystalhd/crystalhd_lnx.c 
b/drivers/staging/crystalhd/crystalhd_lnx.c
index e6fb331..b2d3ec6 100644
--- a/drivers/staging/crystalhd/crystalhd_lnx.c
+++ b/drivers/staging/crystalhd/crystalhd_lnx.c
@@ -136,9 +136,9 @@ static inline int crystalhd_user_data(void __user *ud, void 
*dr,
 
 static int chd_dec_fetch_cdata(struct crystalhd_adp *adp,
   struct crystalhd_ioctl_data *io, uint32_t m_sz,
-  unsigned long ua)
+  void __user *ua)
 {
-   unsigned long ua_off;
+   void __user *ua_off;
int rc = 0;
 
if (!adp || !io || !ua || !m_sz) {
@@ -157,8 +157,8 @@ static int chd_dec_fetch_cdata(struct crystalhd_adp *adp,
rc = crystalhd_user_data((void __user *)ua_off, io->add_cdata,
 io->add_cdata_sz, 0);
if (rc) {
-   BCMLOG_ERR("failed to pull add_cdata sz:%x ua_off:%x\n",
-  io->add_cdata_sz, (unsigned int)ua_off);
+   BCMLOG_ERR("failed to pull add_cdata sz:%x ua_off:%p\n",
+  io->add_cdata_sz, ua_off);
vfree(io->add_cdata);
io->add_cdata = NULL;
return -ENODATA;
@@ -169,9 +169,9 @@ static int chd_dec_fetch_cdata(struct crystalhd_adp *adp,
 
 static int chd_dec_release_cdata(struct crystalhd_adp *adp,
 struct crystalhd_ioctl_data *io,
-unsigned long ua)
+void __user *ua)
 {
-   unsigned long ua_off;
+   void __user *ua_off;
int rc;
 
if (!adp || !io || !ua) {
@@ -185,8 +185,8 @@ static int chd_dec_release_cdata(struct crystalhd_adp *adp,
 io->add_cdata_sz, 1);
if (rc) {
BCMLOG_ERR(
-   "failed to push add_cdata sz:%x ua_off:%x\n",
-io->add_cdata_sz, (unsigned int)ua_off);
+   "failed to push add_cdata sz:%x ua_off:%p\n",
+io->add_cdata_sz, ua_off);
return -ENODATA;
}
}
@@ -201,7 +201,7 @@ static int chd_dec_release_cdata(struct crystalhd_adp *adp,
 
 static int chd_dec_proc_user_data(struct crystalhd_adp *adp,
  struct crystalhd_ioctl_data *io,
- unsigned long ua, int set)
+ void __user *ua, int set)
 {
int rc;
uint32_t m_sz = 0;
@@ -235,7 +235,7 @@ static int chd_dec_proc_user_data(struct crystalhd_adp *adp,
return rc;
 }
 
-static int chd_dec_api_cmd(struct crystalhd_adp *adp, unsigned long ua,
+static int chd_dec_api_cmd(struct crystalhd_adp *adp, void __user *ua,
   uint32_t uid, uint32_t cmd, crystalhd_cmd_proc func)
 {
int rc;
@@ -266,12 +266,14 @@ static int chd_dec_api_cmd(struct crystalhd_adp *adp, 
unsigned long ua,
 }
 
 /* API interfaces */
-static long chd_dec_ioctl(struct file *fd, unsigned int cmd, unsigned long ua)
+static long chd_dec_ioctl(struct file *fd, unsigned int cmd,
+ unsigned long __ua)
 {
struct crystalhd_adp *adp = chd_get_adp();
crystalhd_cmd_proc cproc;
struct crystalhd_user *uc;
int ret;
+   void __user *ua = (void __user *)__ua;
 
if (!adp || !fd) {
BCMLOG_ERR("Invalid adp\n");
-- 
1.8.3.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel