Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions arch/arm/boot/dts/apple/s5l8945x-ipad3.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,26 @@
mask = <0x80>;
enable = <0x80>;
};

/*
* D1974 USB charger: input current limit at 0x3e,
* VBUS online at 0x0b bit 3, 12-bit ADC at 0x44..0x46
* (ch 6 wired to otgphyctrl0 DMON), ceiling 2400 mA
* per ADT /charger usb-input-limit-max 0x960.
*/
charger@3e {
compatible = "apple,pmu-d1974-charger";
reg = <0x3e>;
phys = <&otgphy 0>;
phy-names = "dmon";
input-current-limit-microamp = <2400000>;

port {
charger_usb_role: endpoint {
remote-endpoint = <&dwc2_role_sw>;
};
};
};
};

/*
Expand Down Expand Up @@ -726,10 +746,18 @@
phys = <&otgphy 0>;
phy-names = "usb2-phy";
dr_mode = "peripheral";
usb-role-switch;
usb-psy-name = "apple-pmu-usb";
g-rx-fifo-size = <512>;
g-np-tx-fifo-size = <128>;
g-tx-fifo-size = <128 128 128 128 128 128 128 128>;
status = "okay";

port {
dwc2_role_sw: endpoint {
remote-endpoint = <&charger_usb_role>;
};
};
};

/*
Expand Down
71 changes: 71 additions & 0 deletions drivers/phy/phy-apple-s5l-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/phy/apple-s5l-usb.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/property.h>
Expand All @@ -35,6 +36,12 @@
#define OPHYUNK1_OTG_ENABLE BIT(1)
#define OPHY_UOTGTUNE1 0x40
#define OPHY_UOTGTUNE2 0x44
#define OPHY_DMON 0x48
#define OPHY_DMON_MASK 0x7e06
#define OPHY_DMON_DP 0x0002
#define OPHY_DMON_DM 0x0004
#define OPHY_DMON_BC12_DCD 0x6602
#define OPHY_DMON_BC12_PRIMARY 0x1e04
#define OPHY_UOTGTUNE1_DEVICE 0x549
#define OPHY_UOTGTUNE1_S5L8950X_DEVICE 0x749
#define OPHY_UOTGTUNE2_DEVICE 0x2ff3
Expand Down Expand Up @@ -117,6 +124,7 @@

struct s5l_usbphy_soc_data {
bool cold_init;
bool dmon_bc12; /* phy-version >= 4: BC1.2 DMON modes in +0x48 */
u32 pmgr_uperf;
u32 pmgr_usb_otg;
u32 pmgr_usbreg;
Expand Down Expand Up @@ -158,6 +166,7 @@ static const struct s5l_usbphy_soc_data s5l8942x_usbphy_data = {
*/
static const struct s5l_usbphy_soc_data s5l8950x_usbphy_data = {
.cold_init = true,
.dmon_bc12 = true,
.pmgr_uperf = 0x1084,
.pmgr_usb_otg = 0x1088,
.pmgr_usbreg = 0x109c,
Expand All @@ -182,6 +191,7 @@ static const struct s5l_usbphy_soc_data s5l8950x_usbphy_data = {
*/
static const struct s5l_usbphy_soc_data s5l8955x_usbphy_data = {
.cold_init = false,
.dmon_bc12 = true,
.pmgr_uperf = 0x1084,
.pmgr_usb_otg = 0x1088,
.pmgr_usbreg = 0x109c,
Expand Down Expand Up @@ -477,6 +487,67 @@ static const struct phy_ops s5l_usbphy_ops = {
.owner = THIS_MODULE,
};

/*
* Route USB D+/D- (and, on phy-version >= 4, BC1.2 test sources) to the PMU
* ADC via otgphyctrl +0x48 (AppleS5L8930XUSBPhy DMON). Callers must only
* enable a monitor mode when no USB host session is active, and must always
* restore APPLE_S5L_USBPHY_DMON_OFF after sampling.
*/
int apple_s5l_usbphy_set_dmon(struct phy *phy,
enum apple_s5l_usbphy_dmon_mode mode)
{
struct s5l_usbphy *p;
u32 val, bits;
int ret = 0;

if (!phy || phy->ops != &s5l_usbphy_ops)
return -EINVAL;

p = phy_get_drvdata(phy);
switch (mode) {
case APPLE_S5L_USBPHY_DMON_OFF:
bits = 0;
break;
case APPLE_S5L_USBPHY_DMON_DP:
bits = OPHY_DMON_DP;
break;
case APPLE_S5L_USBPHY_DMON_DM:
bits = OPHY_DMON_DM;
break;
case APPLE_S5L_USBPHY_DMON_BC12_DCD:
if (!p->data || !p->data->dmon_bc12)
return -EOPNOTSUPP;
bits = OPHY_DMON_BC12_DCD;
break;
case APPLE_S5L_USBPHY_DMON_BC12_PRIMARY:
if (!p->data || !p->data->dmon_bc12)
return -EOPNOTSUPP;
bits = OPHY_DMON_BC12_PRIMARY;
break;
default:
return -EINVAL;
}

mutex_lock(&p->lock);
if (!p->init_users) {
ret = s5l_pmgr_on(p, p->data->pmgr_usb_otg);
if (ret)
goto out;
if (p->data->cold_init) {
ret = s5l_pmgr_on(p, p->data->pmgr_usbreg);
if (ret)
goto out;
}
}
val = readl(p->base + OPHY_DMON);
val = (val & ~OPHY_DMON_MASK) | bits;
writel(val, p->base + OPHY_DMON);
out:
mutex_unlock(&p->lock);
return ret;
}
EXPORT_SYMBOL_GPL(apple_s5l_usbphy_set_dmon);

static int s5l_hostphy_power_on(struct phy *phy)
{
struct s5l_usbphy *p = phy_get_drvdata(phy);
Expand Down
18 changes: 12 additions & 6 deletions drivers/power/supply/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,19 @@ config BATTERY_APPLE_HDQ
capacities and cycle count, as the "battery" power supply.

config CHARGER_APPLE_PMU
tristate "Apple iPad mini 1 USB input current limit (D1946 PMU)"
tristate "Apple Dialog PMU adaptive USB charger (D1946/D1974)"
depends on MFD_APPLE_PMU_I2C && POWER_SUPPLY
help
Raises the D1946 PMU's USB input current limit (register 0x3d) the
way iBEC does, so the iPad mini 1 charges under Linux. The driver
is armed by default; apple_pmu_charger.armed=0 on the kernel
command line disables writes.
depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH
depends on PHY_APPLE_S5L_USB || !PHY_APPLE_S5L_USB
help
Adaptive USB input current limit driver for Apple Dialog PMUs
(D1946 on iPad 2/mini 1, D1974 on iPad 3). Identifies attached
sources via USB PHY D+/D- monitoring (Apple BrickID, BC1.2 DCP)
and USB device controller vbus_draw (SDP and Apple host current
grants), ramps the input current limit with VBUS sag backoff and
battery thermal derating, and drops back to 100 mA on unplug or
source swaps. apple_pmu_charger.armed=0 on the kernel command
line disables PMU input-limit writes.

config BATTERY_BQ27XXX
tristate "BQ27xxx battery driver"
Expand Down
Loading
Loading