Here's the big char/misc driver patchset for 4.1-rc1. Lots of different driver subsystem updates here, nothing major, full details are in the shortlog below. All of this has been in linux-next for a while. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEABECAAYFAlU2IMEACgkQMUfUDdst+yloDQCfbyIRL23WVAn9ckQse/y8gbjB OT4AoKTJbwndDP9Kb/lrj2tjd9QjNVrC =xhen -----END PGP SIGNATURE----- Merge tag 'char-misc-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc Pull char/misc driver updates from Greg KH: "Here's the big char/misc driver patchset for 4.1-rc1. Lots of different driver subsystem updates here, nothing major, full details are in the shortlog. All of this has been in linux-next for a while" * tag 'char-misc-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (133 commits) mei: trace: remove unused TRACE_SYSTEM_STRING DTS: ARM: OMAP3-N900: Add lis3lv02d support Documentation: DT: lis302: update wakeup binding lis3lv02d: DT: add wakeup unit 2 and wakeup threshold lis3lv02d: DT: use s32 to support negative values Drivers: hv: hv_balloon: correctly handle num_pages>INT_MAX case Drivers: hv: hv_balloon: correctly handle val.freeram<num_pages case mei: replace check for connection instead of transitioning mei: use mei_cl_is_connected consistently mei: fix mei_poll operation hv_vmbus: Add gradually increased delay for retries in vmbus_post_msg() Drivers: hv: hv_balloon: survive ballooning request with num_pages=0 Drivers: hv: hv_balloon: eliminate jumps in piecewiese linear floor function Drivers: hv: hv_balloon: do not online pages in offline blocks hv: remove the per-channel workqueue hv: don't schedule new works in vmbus_onoffer()/vmbus_onoffer_rescind() hv: run non-blocking message handlers in the dispatch tasklet coresight: moving to new "hwtracing" directory coresight-tmc: Adding a status interface to sysfs coresight: remove the unnecessary configuration coresight-default-sink ...tirimbino
commit
1fc149933f
@ -0,0 +1,18 @@ |
||||
USB GPIO Extcon device |
||||
|
||||
This is a virtual device used to generate USB cable states from the USB ID pin |
||||
connected to a GPIO pin. |
||||
|
||||
Required properties: |
||||
- compatible: Should be "linux,extcon-usb-gpio" |
||||
- id-gpio: gpio for USB ID pin. See gpio binding. |
||||
|
||||
Example: Examples of extcon-usb-gpio node in dra7-evm.dts as listed below: |
||||
extcon_usb1 { |
||||
compatible = "linux,extcon-usb-gpio"; |
||||
id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>; |
||||
} |
||||
|
||||
&omap_dwc3_1 { |
||||
extcon = <&extcon_usb1>; |
||||
}; |
@ -0,0 +1,75 @@ |
||||
* Ingenic JZ4780 NAND/external memory controller (NEMC) |
||||
|
||||
This file documents the device tree bindings for the NEMC external memory |
||||
controller in Ingenic JZ4780 |
||||
|
||||
Required properties: |
||||
- compatible: Should be set to one of: |
||||
"ingenic,jz4780-nemc" (JZ4780) |
||||
- reg: Should specify the NEMC controller registers location and length. |
||||
- clocks: Clock for the NEMC controller. |
||||
- #address-cells: Must be set to 2. |
||||
- #size-cells: Must be set to 1. |
||||
- ranges: A set of ranges for each bank describing the physical memory layout. |
||||
Each should specify the following 4 integer values: |
||||
|
||||
<cs number> 0 <physical address of mapping> <size of mapping> |
||||
|
||||
Each child of the NEMC node describes a device connected to the NEMC. |
||||
|
||||
Required child node properties: |
||||
- reg: Should contain at least one register specifier, given in the following |
||||
format: |
||||
|
||||
<cs number> <offset> <size> |
||||
|
||||
Multiple registers can be specified across multiple banks. This is needed, |
||||
for example, for packaged NAND devices with multiple dies. Such devices |
||||
should be grouped into a single node. |
||||
|
||||
Optional child node properties: |
||||
- ingenic,nemc-bus-width: Specifies the bus width in bits. Defaults to 8 bits. |
||||
- ingenic,nemc-tAS: Address setup time in nanoseconds. |
||||
- ingenic,nemc-tAH: Address hold time in nanoseconds. |
||||
- ingenic,nemc-tBP: Burst pitch time in nanoseconds. |
||||
- ingenic,nemc-tAW: Access wait time in nanoseconds. |
||||
- ingenic,nemc-tSTRV: Static memory recovery time in nanoseconds. |
||||
|
||||
If a child node references multiple banks in its "reg" property, the same value |
||||
for all optional parameters will be configured for all banks. If any optional |
||||
parameters are omitted, they will be left unchanged from whatever they are |
||||
configured to when the NEMC device is probed (which may be the reset value as |
||||
given in the hardware reference manual, or a value configured by the boot |
||||
loader). |
||||
|
||||
Example (NEMC node with a NAND child device attached at CS1): |
||||
|
||||
nemc: nemc@13410000 { |
||||
compatible = "ingenic,jz4780-nemc"; |
||||
reg = <0x13410000 0x10000>; |
||||
|
||||
#address-cells = <2>; |
||||
#size-cells = <1>; |
||||
|
||||
ranges = <1 0 0x1b000000 0x1000000 |
||||
2 0 0x1a000000 0x1000000 |
||||
3 0 0x19000000 0x1000000 |
||||
4 0 0x18000000 0x1000000 |
||||
5 0 0x17000000 0x1000000 |
||||
6 0 0x16000000 0x1000000>; |
||||
|
||||
clocks = <&cgu JZ4780_CLK_NEMC>; |
||||
|
||||
nand: nand@1 { |
||||
compatible = "ingenic,jz4780-nand"; |
||||
reg = <1 0 0x1000000>; |
||||
|
||||
ingenic,nemc-tAS = <10>; |
||||
ingenic,nemc-tAH = <5>; |
||||
ingenic,nemc-tBP = <10>; |
||||
ingenic,nemc-tAW = <15>; |
||||
ingenic,nemc-tSTRV = <100>; |
||||
|
||||
... |
||||
}; |
||||
}; |
@ -0,0 +1,881 @@ |
||||
/*
|
||||
* extcon-max77843.c - Maxim MAX77843 extcon driver to support |
||||
* MUIC(Micro USB Interface Controller) |
||||
* |
||||
* Copyright (C) 2015 Samsung Electronics |
||||
* Author: Jaewon Kim <jaewon02.kim@samsung.com> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 of the License, or |
||||
* (at your option) any later version. |
||||
*/ |
||||
|
||||
#include <linux/extcon.h> |
||||
#include <linux/i2c.h> |
||||
#include <linux/interrupt.h> |
||||
#include <linux/kernel.h> |
||||
#include <linux/mfd/max77843-private.h> |
||||
#include <linux/module.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/workqueue.h> |
||||
|
||||
#define DELAY_MS_DEFAULT 15000 /* unit: millisecond */ |
||||
|
||||
enum max77843_muic_status { |
||||
MAX77843_MUIC_STATUS1 = 0, |
||||
MAX77843_MUIC_STATUS2, |
||||
MAX77843_MUIC_STATUS3, |
||||
|
||||
MAX77843_MUIC_STATUS_NUM, |
||||
}; |
||||
|
||||
struct max77843_muic_info { |
||||
struct device *dev; |
||||
struct max77843 *max77843; |
||||
struct extcon_dev *edev; |
||||
|
||||
struct mutex mutex; |
||||
struct work_struct irq_work; |
||||
struct delayed_work wq_detcable; |
||||
|
||||
u8 status[MAX77843_MUIC_STATUS_NUM]; |
||||
int prev_cable_type; |
||||
int prev_chg_type; |
||||
int prev_gnd_type; |
||||
|
||||
bool irq_adc; |
||||
bool irq_chg; |
||||
}; |
||||
|
||||
enum max77843_muic_cable_group { |
||||
MAX77843_CABLE_GROUP_ADC = 0, |
||||
MAX77843_CABLE_GROUP_ADC_GND, |
||||
MAX77843_CABLE_GROUP_CHG, |
||||
}; |
||||
|
||||
enum max77843_muic_adc_debounce_time { |
||||
MAX77843_DEBOUNCE_TIME_5MS = 0, |
||||
MAX77843_DEBOUNCE_TIME_10MS, |
||||
MAX77843_DEBOUNCE_TIME_25MS, |
||||
MAX77843_DEBOUNCE_TIME_38_62MS, |
||||
}; |
||||
|
||||
/* Define accessory cable type */ |
||||
enum max77843_muic_accessory_type { |
||||
MAX77843_MUIC_ADC_GROUND = 0, |
||||
MAX77843_MUIC_ADC_SEND_END_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S1_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S2_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S3_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S4_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S5_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S6_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S7_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S8_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S9_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S10_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S11_BUTTON, |
||||
MAX77843_MUIC_ADC_REMOTE_S12_BUTTON, |
||||
MAX77843_MUIC_ADC_RESERVED_ACC_1, |
||||
MAX77843_MUIC_ADC_RESERVED_ACC_2, |
||||
MAX77843_MUIC_ADC_RESERVED_ACC_3, |
||||
MAX77843_MUIC_ADC_RESERVED_ACC_4, |
||||
MAX77843_MUIC_ADC_RESERVED_ACC_5, |
||||
MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2, |
||||
MAX77843_MUIC_ADC_PHONE_POWERED_DEV, |
||||
MAX77843_MUIC_ADC_TTY_CONVERTER, |
||||
MAX77843_MUIC_ADC_UART_CABLE, |
||||
MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG, |
||||
MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF, |
||||
MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON, |
||||
MAX77843_MUIC_ADC_AV_CABLE_NOLOAD, |
||||
MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG, |
||||
MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF, |
||||
MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON, |
||||
MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1, |
||||
MAX77843_MUIC_ADC_OPEN, |
||||
|
||||
/* The blow accessories should check
|
||||
not only ADC value but also ADC1K and VBVolt value. */ |
||||
/* Offset|ADC1K|VBVolt| */ |
||||
MAX77843_MUIC_GND_USB_HOST = 0x100, /* 0x1| 0| 0| */ |
||||
MAX77843_MUIC_GND_USB_HOST_VB = 0x101, /* 0x1| 0| 1| */ |
||||
MAX77843_MUIC_GND_MHL = 0x102, /* 0x1| 1| 0| */ |
||||
MAX77843_MUIC_GND_MHL_VB = 0x103, /* 0x1| 1| 1| */ |
||||
}; |
||||
|
||||
/* Define charger cable type */ |
||||
enum max77843_muic_charger_type { |
||||
MAX77843_MUIC_CHG_NONE = 0, |
||||
MAX77843_MUIC_CHG_USB, |
||||
MAX77843_MUIC_CHG_DOWNSTREAM, |
||||
MAX77843_MUIC_CHG_DEDICATED, |
||||
MAX77843_MUIC_CHG_SPECIAL_500MA, |
||||
MAX77843_MUIC_CHG_SPECIAL_1A, |
||||
MAX77843_MUIC_CHG_SPECIAL_BIAS, |
||||
MAX77843_MUIC_CHG_RESERVED, |
||||
MAX77843_MUIC_CHG_GND, |
||||
}; |
||||
|
||||
enum { |
||||
MAX77843_CABLE_USB = 0, |
||||
MAX77843_CABLE_USB_HOST, |
||||
MAX77843_CABLE_TA, |
||||
MAX77843_CABLE_CHARGE_DOWNSTREAM, |
||||
MAX77843_CABLE_FAST_CHARGER, |
||||
MAX77843_CABLE_SLOW_CHARGER, |
||||
MAX77843_CABLE_MHL, |
||||
MAX77843_CABLE_MHL_TA, |
||||
MAX77843_CABLE_JIG_USB_ON, |
||||
MAX77843_CABLE_JIG_USB_OFF, |
||||
MAX77843_CABLE_JIG_UART_ON, |
||||
MAX77843_CABLE_JIG_UART_OFF, |
||||
|
||||
MAX77843_CABLE_NUM, |
||||
}; |
||||
|
||||
static const char *max77843_extcon_cable[] = { |
||||
[MAX77843_CABLE_USB] = "USB", |
||||
[MAX77843_CABLE_USB_HOST] = "USB-HOST", |
||||
[MAX77843_CABLE_TA] = "TA", |
||||
[MAX77843_CABLE_CHARGE_DOWNSTREAM] = "CHARGER-DOWNSTREAM", |
||||
[MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER", |
||||
[MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER", |
||||
[MAX77843_CABLE_MHL] = "MHL", |
||||
[MAX77843_CABLE_MHL_TA] = "MHL-TA", |
||||
[MAX77843_CABLE_JIG_USB_ON] = "JIG-USB-ON", |
||||
[MAX77843_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", |
||||
[MAX77843_CABLE_JIG_UART_ON] = "JIG-UART-ON", |
||||
[MAX77843_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", |
||||
}; |
||||
|
||||
struct max77843_muic_irq { |
||||
unsigned int irq; |
||||
const char *name; |
||||
unsigned int virq; |
||||
}; |
||||
|
||||
static struct max77843_muic_irq max77843_muic_irqs[] = { |
||||
{ MAX77843_MUIC_IRQ_INT1_ADC, "MUIC-ADC" }, |
||||
{ MAX77843_MUIC_IRQ_INT1_ADCERROR, "MUIC-ADC_ERROR" }, |
||||
{ MAX77843_MUIC_IRQ_INT1_ADC1K, "MUIC-ADC1K" }, |
||||
{ MAX77843_MUIC_IRQ_INT2_CHGTYP, "MUIC-CHGTYP" }, |
||||
{ MAX77843_MUIC_IRQ_INT2_CHGDETRUN, "MUIC-CHGDETRUN" }, |
||||
{ MAX77843_MUIC_IRQ_INT2_DCDTMR, "MUIC-DCDTMR" }, |
||||
{ MAX77843_MUIC_IRQ_INT2_DXOVP, "MUIC-DXOVP" }, |
||||
{ MAX77843_MUIC_IRQ_INT2_VBVOLT, "MUIC-VBVOLT" }, |
||||
{ MAX77843_MUIC_IRQ_INT3_VBADC, "MUIC-VBADC" }, |
||||
{ MAX77843_MUIC_IRQ_INT3_VDNMON, "MUIC-VDNMON" }, |
||||
{ MAX77843_MUIC_IRQ_INT3_DNRES, "MUIC-DNRES" }, |
||||
{ MAX77843_MUIC_IRQ_INT3_MPNACK, "MUIC-MPNACK"}, |
||||
{ MAX77843_MUIC_IRQ_INT3_MRXBUFOW, "MUIC-MRXBUFOW"}, |
||||
{ MAX77843_MUIC_IRQ_INT3_MRXTRF, "MUIC-MRXTRF"}, |
||||
{ MAX77843_MUIC_IRQ_INT3_MRXPERR, "MUIC-MRXPERR"}, |
||||
{ MAX77843_MUIC_IRQ_INT3_MRXRDY, "MUIC-MRXRDY"}, |
||||
}; |
||||
|
||||
static const struct regmap_config max77843_muic_regmap_config = { |
||||
.reg_bits = 8, |
||||
.val_bits = 8, |
||||
.max_register = MAX77843_MUIC_REG_END, |
||||
}; |
||||
|
||||
static const struct regmap_irq max77843_muic_irq[] = { |
||||
/* INT1 interrupt */ |
||||
{ .reg_offset = 0, .mask = MAX77843_MUIC_ADC, }, |
||||
{ .reg_offset = 0, .mask = MAX77843_MUIC_ADCERROR, }, |
||||
{ .reg_offset = 0, .mask = MAX77843_MUIC_ADC1K, }, |
||||
|
||||
/* INT2 interrupt */ |
||||
{ .reg_offset = 1, .mask = MAX77843_MUIC_CHGTYP, }, |
||||
{ .reg_offset = 1, .mask = MAX77843_MUIC_CHGDETRUN, }, |
||||
{ .reg_offset = 1, .mask = MAX77843_MUIC_DCDTMR, }, |
||||
{ .reg_offset = 1, .mask = MAX77843_MUIC_DXOVP, }, |
||||
{ .reg_offset = 1, .mask = MAX77843_MUIC_VBVOLT, }, |
||||
|
||||
/* INT3 interrupt */ |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_VBADC, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_VDNMON, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_DNRES, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_MPNACK, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_MRXBUFOW, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_MRXTRF, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_MRXPERR, }, |
||||
{ .reg_offset = 2, .mask = MAX77843_MUIC_MRXRDY, }, |
||||
}; |
||||
|
||||
static const struct regmap_irq_chip max77843_muic_irq_chip = { |
||||
.name = "max77843-muic", |
||||
.status_base = MAX77843_MUIC_REG_INT1, |
||||
.mask_base = MAX77843_MUIC_REG_INTMASK1, |
||||
.mask_invert = true, |
||||
.num_regs = 3, |
||||
.irqs = max77843_muic_irq, |
||||
.num_irqs = ARRAY_SIZE(max77843_muic_irq), |
||||
}; |
||||
|
||||
static int max77843_muic_set_path(struct max77843_muic_info *info, |
||||
u8 val, bool attached) |
||||
{ |
||||
struct max77843 *max77843 = info->max77843; |
||||
int ret = 0; |
||||
unsigned int ctrl1, ctrl2; |
||||
|
||||
if (attached) |
||||
ctrl1 = val; |
||||
else |
||||
ctrl1 = CONTROL1_SW_OPEN; |
||||
|
||||
ret = regmap_update_bits(max77843->regmap_muic, |
||||
MAX77843_MUIC_REG_CONTROL1, |
||||
CONTROL1_COM_SW, ctrl1); |
||||
if (ret < 0) { |
||||
dev_err(info->dev, "Cannot switch MUIC port\n"); |
||||
return ret; |
||||
} |
||||
|
||||
if (attached) |
||||
ctrl2 = MAX77843_MUIC_CONTROL2_CPEN_MASK; |
||||
else |
||||
ctrl2 = MAX77843_MUIC_CONTROL2_LOWPWR_MASK; |
||||
|
||||
ret = regmap_update_bits(max77843->regmap_muic, |
||||
MAX77843_MUIC_REG_CONTROL2, |
||||
MAX77843_MUIC_CONTROL2_LOWPWR_MASK | |
||||
MAX77843_MUIC_CONTROL2_CPEN_MASK, ctrl2); |
||||
if (ret < 0) { |
||||
dev_err(info->dev, "Cannot update lowpower mode\n"); |
||||
return ret; |
||||
} |
||||
|
||||
dev_dbg(info->dev, |
||||
"CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n", |
||||
ctrl1, ctrl2, attached ? "attached" : "detached"); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int max77843_muic_get_cable_type(struct max77843_muic_info *info, |
||||
enum max77843_muic_cable_group group, bool *attached) |
||||
{ |
||||
int adc, chg_type, cable_type, gnd_type; |
||||
|
||||
adc = info->status[MAX77843_MUIC_STATUS1] & |
||||
MAX77843_MUIC_STATUS1_ADC_MASK; |
||||
adc >>= STATUS1_ADC_SHIFT; |
||||
|
||||
switch (group) { |
||||
case MAX77843_CABLE_GROUP_ADC: |
||||
if (adc == MAX77843_MUIC_ADC_OPEN) { |
||||
*attached = false; |
||||
cable_type = info->prev_cable_type; |
||||
info->prev_cable_type = MAX77843_MUIC_ADC_OPEN; |
||||
} else { |
||||
*attached = true; |
||||
cable_type = info->prev_cable_type = adc; |
||||
} |
||||
break; |
||||
case MAX77843_CABLE_GROUP_CHG: |
||||
chg_type = info->status[MAX77843_MUIC_STATUS2] & |
||||
MAX77843_MUIC_STATUS2_CHGTYP_MASK; |
||||
|
||||
/* Check GROUND accessory with charger cable */ |
||||
if (adc == MAX77843_MUIC_ADC_GROUND) { |
||||
if (chg_type == MAX77843_MUIC_CHG_NONE) { |
||||
/* The following state when charger cable is
|
||||
* disconnected but the GROUND accessory still |
||||
* connected */ |
||||
*attached = false; |
||||
cable_type = info->prev_chg_type; |
||||
info->prev_chg_type = MAX77843_MUIC_CHG_NONE; |
||||
} else { |
||||
|
||||
/* The following state when charger cable is
|
||||
* connected on the GROUND accessory */ |
||||
*attached = true; |
||||
cable_type = MAX77843_MUIC_CHG_GND; |
||||
info->prev_chg_type = MAX77843_MUIC_CHG_GND; |
||||
} |
||||
break; |
||||
} |
||||
|
||||
if (chg_type == MAX77843_MUIC_CHG_NONE) { |
||||
*attached = false; |
||||
cable_type = info->prev_chg_type; |
||||
info->prev_chg_type = MAX77843_MUIC_CHG_NONE; |
||||
} else { |
||||
*attached = true; |
||||
cable_type = info->prev_chg_type = chg_type; |
||||
} |
||||
break; |
||||
case MAX77843_CABLE_GROUP_ADC_GND: |
||||
if (adc == MAX77843_MUIC_ADC_OPEN) { |
||||
*attached = false; |
||||
cable_type = info->prev_gnd_type; |
||||
info->prev_gnd_type = MAX77843_MUIC_ADC_OPEN; |
||||
} else { |
||||
*attached = true; |
||||
|
||||
/* Offset|ADC1K|VBVolt|
|
||||
* 0x1| 0| 0| USB-HOST |
||||
* 0x1| 0| 1| USB-HOST with VB |
||||
* 0x1| 1| 0| MHL |
||||
* 0x1| 1| 1| MHL with VB */ |
||||
/* Get ADC1K register bit */ |
||||
gnd_type = (info->status[MAX77843_MUIC_STATUS1] & |
||||
MAX77843_MUIC_STATUS1_ADC1K_MASK); |
||||
|
||||
/* Get VBVolt register bit */ |
||||
gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & |
||||
MAX77843_MUIC_STATUS2_VBVOLT_MASK); |
||||
gnd_type >>= STATUS2_VBVOLT_SHIFT; |
||||
|
||||
/* Offset of GND cable */ |
||||
gnd_type |= MAX77843_MUIC_GND_USB_HOST; |
||||
cable_type = info->prev_gnd_type = gnd_type; |
||||
} |
||||
break; |
||||
default: |
||||
dev_err(info->dev, "Unknown cable group (%d)\n", group); |
||||
cable_type = -EINVAL; |
||||
break; |
||||
} |
||||
|
||||
return cable_type; |
||||
} |
||||
|
||||
static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info) |
||||
{ |
||||
int ret, gnd_cable_type; |
||||
bool attached; |
||||
|
||||
gnd_cable_type = max77843_muic_get_cable_type(info, |
||||
MAX77843_CABLE_GROUP_ADC_GND, &attached); |
||||
dev_dbg(info->dev, "external connector is %s (gnd:0x%02x)\n", |
||||
attached ? "attached" : "detached", gnd_cable_type); |
||||
|
||||
switch (gnd_cable_type) { |
||||
case MAX77843_MUIC_GND_USB_HOST: |
||||
case MAX77843_MUIC_GND_USB_HOST_VB: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, "USB-HOST", attached); |
||||
break; |
||||
case MAX77843_MUIC_GND_MHL_VB: |
||||
case MAX77843_MUIC_GND_MHL: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, "MHL", attached); |
||||
break; |
||||
default: |
||||
dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", |
||||
attached ? "attached" : "detached", gnd_cable_type); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int max77843_muic_jig_handler(struct max77843_muic_info *info, |
||||
int cable_type, bool attached) |
||||
{ |
||||
int ret; |
||||
|
||||
dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", |
||||
attached ? "attached" : "detached", cable_type); |
||||
|
||||
switch (cable_type) { |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
extcon_set_cable_state(info->edev, "JIG-USB-OFF", attached); |
||||
break; |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
extcon_set_cable_state(info->edev, "JIG-USB-ON", attached); |
||||
break; |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_UART, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
extcon_set_cable_state(info->edev, "JIG-UART-OFF", attached); |
||||
break; |
||||
default: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
break; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int max77843_muic_adc_handler(struct max77843_muic_info *info) |
||||
{ |
||||
int ret, cable_type; |
||||
bool attached; |
||||
|
||||
cable_type = max77843_muic_get_cable_type(info, |
||||
MAX77843_CABLE_GROUP_ADC, &attached); |
||||
|
||||
dev_dbg(info->dev, |
||||
"external connector is %s (adc:0x%02x, prev_adc:0x%x)\n", |
||||
attached ? "attached" : "detached", cable_type, |
||||
info->prev_cable_type); |
||||
|
||||
switch (cable_type) { |
||||
case MAX77843_MUIC_ADC_GROUND: |
||||
ret = max77843_muic_adc_gnd_handler(info); |
||||
if (ret < 0) |
||||
return ret; |
||||
break; |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: |
||||
ret = max77843_muic_jig_handler(info, cable_type, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
break; |
||||
case MAX77843_MUIC_ADC_SEND_END_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S1_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S2_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S3_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S4_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S5_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S6_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S7_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S8_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S9_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S10_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S11_BUTTON: |
||||
case MAX77843_MUIC_ADC_REMOTE_S12_BUTTON: |
||||
case MAX77843_MUIC_ADC_RESERVED_ACC_1: |
||||
case MAX77843_MUIC_ADC_RESERVED_ACC_2: |
||||
case MAX77843_MUIC_ADC_RESERVED_ACC_3: |
||||
case MAX77843_MUIC_ADC_RESERVED_ACC_4: |
||||
case MAX77843_MUIC_ADC_RESERVED_ACC_5: |
||||
case MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2: |
||||
case MAX77843_MUIC_ADC_PHONE_POWERED_DEV: |
||||
case MAX77843_MUIC_ADC_TTY_CONVERTER: |
||||
case MAX77843_MUIC_ADC_UART_CABLE: |
||||
case MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG: |
||||
case MAX77843_MUIC_ADC_AV_CABLE_NOLOAD: |
||||
case MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG: |
||||
case MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON: |
||||
case MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1: |
||||
case MAX77843_MUIC_ADC_OPEN: |
||||
dev_err(info->dev, |
||||
"accessory is %s but it isn't used (adc:0x%x)\n", |
||||
attached ? "attached" : "detached", cable_type); |
||||
return -EAGAIN; |
||||
default: |
||||
dev_err(info->dev, |
||||
"failed to detect %s accessory (adc:0x%x)\n", |
||||
attached ? "attached" : "detached", cable_type); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int max77843_muic_chg_handler(struct max77843_muic_info *info) |
||||
{ |
||||
int ret, chg_type, gnd_type; |
||||
bool attached; |
||||
|
||||
chg_type = max77843_muic_get_cable_type(info, |
||||
MAX77843_CABLE_GROUP_CHG, &attached); |
||||
|
||||
dev_dbg(info->dev, |
||||
"external connector is %s(chg_type:0x%x, prev_chg_type:0x%x)\n", |
||||
attached ? "attached" : "detached", |
||||
chg_type, info->prev_chg_type); |
||||
|
||||
switch (chg_type) { |
||||
case MAX77843_MUIC_CHG_USB: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, "USB", attached); |
||||
break; |
||||
case MAX77843_MUIC_CHG_DOWNSTREAM: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, |
||||
"CHARGER-DOWNSTREAM", attached); |
||||
break; |
||||
case MAX77843_MUIC_CHG_DEDICATED: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, "TA", attached); |
||||
break; |
||||
case MAX77843_MUIC_CHG_SPECIAL_500MA: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, "SLOW-CHAREGER", attached); |
||||
break; |
||||
case MAX77843_MUIC_CHG_SPECIAL_1A: |
||||
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
extcon_set_cable_state(info->edev, "FAST-CHARGER", attached); |
||||
break; |
||||
case MAX77843_MUIC_CHG_GND: |
||||
gnd_type = max77843_muic_get_cable_type(info, |
||||
MAX77843_CABLE_GROUP_ADC_GND, &attached); |
||||
|
||||
/* Charger cable on MHL accessory is attach or detach */ |
||||
if (gnd_type == MAX77843_MUIC_GND_MHL_VB) |
||||
extcon_set_cable_state(info->edev, "MHL-TA", true); |
||||
else if (gnd_type == MAX77843_MUIC_GND_MHL) |
||||
extcon_set_cable_state(info->edev, "MHL-TA", false); |
||||
break; |
||||
case MAX77843_MUIC_CHG_NONE: |
||||
break; |
||||
default: |
||||
dev_err(info->dev, |
||||
"failed to detect %s accessory (chg_type:0x%x)\n", |
||||
attached ? "attached" : "detached", chg_type); |
||||
|
||||
max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void max77843_muic_irq_work(struct work_struct *work) |
||||
{ |
||||
struct max77843_muic_info *info = container_of(work, |
||||
struct max77843_muic_info, irq_work); |
||||
struct max77843 *max77843 = info->max77843; |
||||
int ret = 0; |
||||
|
||||
mutex_lock(&info->mutex); |
||||
|
||||
ret = regmap_bulk_read(max77843->regmap_muic, |
||||
MAX77843_MUIC_REG_STATUS1, info->status, |
||||
MAX77843_MUIC_STATUS_NUM); |
||||
if (ret) { |
||||
dev_err(info->dev, "Cannot read STATUS registers\n"); |
||||
mutex_unlock(&info->mutex); |
||||
return; |
||||
} |
||||
|
||||
if (info->irq_adc) { |
||||
ret = max77843_muic_adc_handler(info); |
||||
if (ret) |
||||
dev_err(info->dev, "Unknown cable type\n"); |
||||
info->irq_adc = false; |
||||
} |
||||
|
||||
if (info->irq_chg) { |
||||
ret = max77843_muic_chg_handler(info); |
||||
if (ret) |
||||
dev_err(info->dev, "Unknown charger type\n"); |
||||
info->irq_chg = false; |
||||
} |
||||
|
||||
mutex_unlock(&info->mutex); |
||||
} |
||||
|
||||
static irqreturn_t max77843_muic_irq_handler(int irq, void *data) |
||||
{ |
||||
struct max77843_muic_info *info = data; |
||||
int i, irq_type = -1; |
||||
|
||||
for (i = 0; i < ARRAY_SIZE(max77843_muic_irqs); i++) |
||||
if (irq == max77843_muic_irqs[i].virq) |
||||
irq_type = max77843_muic_irqs[i].irq; |
||||
|
||||
switch (irq_type) { |
||||
case MAX77843_MUIC_IRQ_INT1_ADC: |
||||
case MAX77843_MUIC_IRQ_INT1_ADCERROR: |
||||
case MAX77843_MUIC_IRQ_INT1_ADC1K: |
||||
info->irq_adc = true; |
||||
break; |
||||
case MAX77843_MUIC_IRQ_INT2_CHGTYP: |
||||
case MAX77843_MUIC_IRQ_INT2_CHGDETRUN: |
||||
case MAX77843_MUIC_IRQ_INT2_DCDTMR: |
||||
case MAX77843_MUIC_IRQ_INT2_DXOVP: |
||||
case MAX77843_MUIC_IRQ_INT2_VBVOLT: |
||||
info->irq_chg = true; |
||||
break; |
||||
case MAX77843_MUIC_IRQ_INT3_VBADC: |
||||
case MAX77843_MUIC_IRQ_INT3_VDNMON: |
||||
case MAX77843_MUIC_IRQ_INT3_DNRES: |
||||
case MAX77843_MUIC_IRQ_INT3_MPNACK: |
||||
case MAX77843_MUIC_IRQ_INT3_MRXBUFOW: |
||||
case MAX77843_MUIC_IRQ_INT3_MRXTRF: |
||||
case MAX77843_MUIC_IRQ_INT3_MRXPERR: |
||||
case MAX77843_MUIC_IRQ_INT3_MRXRDY: |
||||
break; |
||||
default: |
||||
dev_err(info->dev, "Cannot recognize IRQ(%d)\n", irq_type); |
||||
break; |
||||
} |
||||
|
||||
schedule_work(&info->irq_work); |
||||
|
||||
return IRQ_HANDLED; |
||||
} |
||||
|
||||
static void max77843_muic_detect_cable_wq(struct work_struct *work) |
||||
{ |
||||
struct max77843_muic_info *info = container_of(to_delayed_work(work), |
||||
struct max77843_muic_info, wq_detcable); |
||||
struct max77843 *max77843 = info->max77843; |
||||
int chg_type, adc, ret; |
||||
bool attached; |
||||
|
||||
mutex_lock(&info->mutex); |
||||
|
||||
ret = regmap_bulk_read(max77843->regmap_muic, |
||||
MAX77843_MUIC_REG_STATUS1, info->status, |
||||
MAX77843_MUIC_STATUS_NUM); |
||||
if (ret) { |
||||
dev_err(info->dev, "Cannot read STATUS registers\n"); |
||||
goto err_cable_wq; |
||||
} |
||||
|
||||
adc = max77843_muic_get_cable_type(info, |
||||
MAX77843_CABLE_GROUP_ADC, &attached); |
||||
if (attached && adc != MAX77843_MUIC_ADC_OPEN) { |
||||
ret = max77843_muic_adc_handler(info); |
||||
if (ret < 0) { |
||||
dev_err(info->dev, "Cannot detect accessory\n"); |
||||
goto err_cable_wq; |
||||
} |
||||
} |
||||
|
||||
chg_type = max77843_muic_get_cable_type(info, |
||||
MAX77843_CABLE_GROUP_CHG, &attached); |
||||
if (attached && chg_type != MAX77843_MUIC_CHG_NONE) { |
||||
ret = max77843_muic_chg_handler(info); |
||||
if (ret < 0) { |
||||
dev_err(info->dev, "Cannot detect charger accessory\n"); |
||||
goto err_cable_wq; |
||||
} |
||||
} |
||||
|
||||
err_cable_wq: |
||||
mutex_unlock(&info->mutex); |
||||
} |
||||
|
||||
static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, |
||||
enum max77843_muic_adc_debounce_time time) |
||||
{ |
||||
struct max77843 *max77843 = info->max77843; |
||||
int ret; |
||||
|
||||
switch (time) { |
||||
case MAX77843_DEBOUNCE_TIME_5MS: |
||||
case MAX77843_DEBOUNCE_TIME_10MS: |
||||
case MAX77843_DEBOUNCE_TIME_25MS: |
||||
case MAX77843_DEBOUNCE_TIME_38_62MS: |
||||
ret = regmap_update_bits(max77843->regmap_muic, |
||||
MAX77843_MUIC_REG_CONTROL4, |
||||
MAX77843_MUIC_CONTROL4_ADCDBSET_MASK, |
||||
time << CONTROL4_ADCDBSET_SHIFT); |
||||
if (ret < 0) { |
||||
dev_err(info->dev, "Cannot write MUIC regmap\n"); |
||||
return ret; |
||||
} |
||||
break; |
||||
default: |
||||
dev_err(info->dev, "Invalid ADC debounce time\n"); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int max77843_init_muic_regmap(struct max77843 *max77843) |
||||
{ |
||||
int ret; |
||||
|
||||
max77843->i2c_muic = i2c_new_dummy(max77843->i2c->adapter, |
||||
I2C_ADDR_MUIC); |
||||
if (!max77843->i2c_muic) { |
||||
dev_err(&max77843->i2c->dev, |
||||
"Cannot allocate I2C device for MUIC\n"); |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
i2c_set_clientdata(max77843->i2c_muic, max77843); |
||||
|
||||
max77843->regmap_muic = devm_regmap_init_i2c(max77843->i2c_muic, |
||||
&max77843_muic_regmap_config); |
||||
if (IS_ERR(max77843->regmap_muic)) { |
||||
ret = PTR_ERR(max77843->regmap_muic); |
||||
goto err_muic_i2c; |
||||
} |
||||
|
||||
ret = regmap_add_irq_chip(max77843->regmap_muic, max77843->irq, |
||||
IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, |
||||
0, &max77843_muic_irq_chip, &max77843->irq_data_muic); |
||||
if (ret < 0) { |
||||
dev_err(&max77843->i2c->dev, "Cannot add MUIC IRQ chip\n"); |
||||
goto err_muic_i2c; |
||||
} |
||||
|
||||
return 0; |
||||
|
||||
err_muic_i2c: |
||||
i2c_unregister_device(max77843->i2c_muic); |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int max77843_muic_probe(struct platform_device *pdev) |
||||
{ |
||||
struct max77843 *max77843 = dev_get_drvdata(pdev->dev.parent); |
||||
struct max77843_muic_info *info; |
||||
unsigned int id; |
||||
int i, ret; |
||||
|
||||
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
||||
if (!info) |
||||
return -ENOMEM; |
||||
|
||||
info->dev = &pdev->dev; |
||||
info->max77843 = max77843; |
||||
|
||||
platform_set_drvdata(pdev, info); |
||||
mutex_init(&info->mutex); |
||||
|
||||
/* Initialize i2c and regmap */ |
||||
ret = max77843_init_muic_regmap(max77843); |
||||
if (ret) { |
||||
dev_err(&pdev->dev, "Failed to init MUIC regmap\n"); |
||||
return ret; |
||||
} |
||||
|
||||
/* Turn off auto detection configuration */ |
||||
ret = regmap_update_bits(max77843->regmap_muic, |
||||
MAX77843_MUIC_REG_CONTROL4, |
||||
MAX77843_MUIC_CONTROL4_USBAUTO_MASK | |
||||
MAX77843_MUIC_CONTROL4_FCTAUTO_MASK, |
||||
CONTROL4_AUTO_DISABLE); |
||||
|
||||
/* Initialize extcon device */ |
||||
info->edev = devm_extcon_dev_allocate(&pdev->dev, |
||||
max77843_extcon_cable); |
||||
if (IS_ERR(info->edev)) { |
||||
dev_err(&pdev->dev, "Failed to allocate memory for extcon\n"); |
||||
ret = -ENODEV; |
||||
goto err_muic_irq; |
||||
} |
||||
|
||||
ret = devm_extcon_dev_register(&pdev->dev, info->edev); |
||||
if (ret) { |
||||
dev_err(&pdev->dev, "Failed to register extcon device\n"); |
||||
goto err_muic_irq; |
||||
} |
||||
|
||||
/* Set ADC debounce time */ |
||||
max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS); |
||||
|
||||
/* Set initial path for UART */ |
||||
max77843_muic_set_path(info, CONTROL1_SW_UART, true); |
||||
|
||||
/* Check revision number of MUIC device */ |
||||
ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); |
||||
if (ret < 0) { |
||||
dev_err(&pdev->dev, "Failed to read revision number\n"); |
||||
goto err_muic_irq; |
||||
} |
||||
dev_info(info->dev, "MUIC device ID : 0x%x\n", id); |
||||
|
||||
/* Support virtual irq domain for max77843 MUIC device */ |
||||
INIT_WORK(&info->irq_work, max77843_muic_irq_work); |
||||
|
||||
for (i = 0; i < ARRAY_SIZE(max77843_muic_irqs); i++) { |
||||
struct max77843_muic_irq *muic_irq = &max77843_muic_irqs[i]; |
||||
unsigned int virq = 0; |
||||
|
||||
virq = regmap_irq_get_virq(max77843->irq_data_muic, |
||||
muic_irq->irq); |
||||
if (virq <= 0) { |
||||
ret = -EINVAL; |
||||
goto err_muic_irq; |
||||
} |
||||
muic_irq->virq = virq; |
||||
|
||||
ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, |
||||
max77843_muic_irq_handler, IRQF_NO_SUSPEND, |
||||
muic_irq->name, info); |
||||
if (ret) { |
||||
dev_err(&pdev->dev, |
||||
"Failed to request irq (IRQ: %d, error: %d)\n", |
||||
muic_irq->irq, ret); |
||||
goto err_muic_irq; |
||||
} |
||||
} |
||||
|
||||
/* Detect accessory after completing the initialization of platform */ |
||||
INIT_DELAYED_WORK(&info->wq_detcable, max77843_muic_detect_cable_wq); |
||||
queue_delayed_work(system_power_efficient_wq, |
||||
&info->wq_detcable, msecs_to_jiffies(DELAY_MS_DEFAULT)); |
||||
|
||||
return 0; |
||||
|
||||
err_muic_irq: |
||||
regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); |
||||
i2c_unregister_device(max77843->i2c_muic); |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int max77843_muic_remove(struct platform_device *pdev) |
||||
{ |
||||
struct max77843_muic_info *info = platform_get_drvdata(pdev); |
||||
struct max77843 *max77843 = info->max77843; |
||||
|
||||
cancel_work_sync(&info->irq_work); |
||||
regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); |
||||
i2c_unregister_device(max77843->i2c_muic); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static const struct platform_device_id max77843_muic_id[] = { |
||||
{ "max77843-muic", }, |
||||
{ /* sentinel */ }, |
||||
}; |
||||
MODULE_DEVICE_TABLE(platform, max77843_muic_id); |
||||
|
||||
static struct platform_driver max77843_muic_driver = { |
||||
.driver = { |
||||
.name = "max77843-muic", |
||||
}, |
||||
.probe = max77843_muic_probe, |
||||
.remove = max77843_muic_remove, |
||||
.id_table = max77843_muic_id, |
||||
}; |
||||
|
||||
static int __init max77843_muic_init(void) |
||||
{ |
||||
return platform_driver_register(&max77843_muic_driver); |
||||
} |
||||
subsys_initcall(max77843_muic_init); |
||||
|
||||
MODULE_DESCRIPTION("Maxim MAX77843 Extcon driver"); |
||||
MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); |
||||
MODULE_LICENSE("GPL"); |
@ -0,0 +1,237 @@ |
||||
/**
|
||||
* drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver |
||||
* |
||||
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
|
||||
* Author: Roger Quadros <rogerq@ti.com> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License version 2 as |
||||
* published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
*/ |
||||
|
||||
#include <linux/extcon.h> |
||||
#include <linux/init.h> |
||||
#include <linux/interrupt.h> |
||||
#include <linux/irq.h> |
||||
#include <linux/kernel.h> |
||||
#include <linux/module.h> |
||||
#include <linux/of_gpio.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/slab.h> |
||||
#include <linux/workqueue.h> |
||||
|
||||
#define USB_GPIO_DEBOUNCE_MS 20 /* ms */ |
||||
|
||||
struct usb_extcon_info { |
||||
struct device *dev; |
||||
struct extcon_dev *edev; |
||||
|
||||
struct gpio_desc *id_gpiod; |
||||
int id_irq; |
||||
|
||||
unsigned long debounce_jiffies; |
||||
struct delayed_work wq_detcable; |
||||
}; |
||||
|
||||
/* List of detectable cables */ |
||||
enum { |
||||
EXTCON_CABLE_USB = 0, |
||||
EXTCON_CABLE_USB_HOST, |
||||
|
||||
EXTCON_CABLE_END, |
||||
}; |
||||
|
||||
static const char *usb_extcon_cable[] = { |
||||
[EXTCON_CABLE_USB] = "USB", |
||||
[EXTCON_CABLE_USB_HOST] = "USB-HOST", |
||||
NULL, |
||||
}; |
||||
|
||||
static void usb_extcon_detect_cable(struct work_struct *work) |
||||
{ |
||||
int id; |
||||
struct usb_extcon_info *info = container_of(to_delayed_work(work), |
||||
struct usb_extcon_info, |
||||
wq_detcable); |
||||
|
||||
/* check ID and update cable state */ |
||||
id = gpiod_get_value_cansleep(info->id_gpiod); |
||||
if (id) { |
||||
/*
|
||||
* ID = 1 means USB HOST cable detached. |
||||
* As we don't have event for USB peripheral cable attached, |
||||
* we simulate USB peripheral attach here. |
||||
*/ |
||||
extcon_set_cable_state(info->edev, |
||||
usb_extcon_cable[EXTCON_CABLE_USB_HOST], |
||||
false); |
||||
extcon_set_cable_state(info->edev, |
||||
usb_extcon_cable[EXTCON_CABLE_USB], |
||||
true); |
||||
} else { |
||||
/*
|
||||
* ID = 0 means USB HOST cable attached. |
||||
* As we don't have event for USB peripheral cable detached, |
||||
* we simulate USB peripheral detach here. |
||||
*/ |
||||
extcon_set_cable_state(info->edev, |
||||
usb_extcon_cable[EXTCON_CABLE_USB], |
||||
false); |
||||
extcon_set_cable_state(info->edev, |
||||
usb_extcon_cable[EXTCON_CABLE_USB_HOST], |
||||
true); |
||||
} |
||||
} |
||||
|
||||
static irqreturn_t usb_irq_handler(int irq, void *dev_id) |
||||
{ |
||||
struct usb_extcon_info *info = dev_id; |
||||
|
||||
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, |
||||
info->debounce_jiffies); |
||||
|
||||
return IRQ_HANDLED; |
||||
} |
||||
|
||||
static int usb_extcon_probe(struct platform_device *pdev) |
||||
{ |
||||
struct device *dev = &pdev->dev; |
||||
struct device_node *np = dev->of_node; |
||||
struct usb_extcon_info *info; |
||||
int ret; |
||||
|
||||
if (!np) |
||||
return -EINVAL; |
||||
|
||||
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
||||
if (!info) |
||||
return -ENOMEM; |
||||
|
||||
info->dev = dev; |
||||
info->id_gpiod = devm_gpiod_get(&pdev->dev, "id"); |
||||
if (IS_ERR(info->id_gpiod)) { |
||||
dev_err(dev, "failed to get ID GPIO\n"); |
||||
return PTR_ERR(info->id_gpiod); |
||||
} |
||||
|
||||
ret = gpiod_set_debounce(info->id_gpiod, |
||||
USB_GPIO_DEBOUNCE_MS * 1000); |
||||
if (ret < 0) |
||||
info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS); |
||||
|
||||
INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable); |
||||
|
||||
info->id_irq = gpiod_to_irq(info->id_gpiod); |
||||
if (info->id_irq < 0) { |
||||
dev_err(dev, "failed to get ID IRQ\n"); |
||||
return info->id_irq; |
||||
} |
||||
|
||||
ret = devm_request_threaded_irq(dev, info->id_irq, NULL, |
||||
usb_irq_handler, |
||||
IRQF_TRIGGER_RISING | |
||||
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
||||
pdev->name, info); |
||||
if (ret < 0) { |
||||
dev_err(dev, "failed to request handler for ID IRQ\n"); |
||||
return ret; |
||||
} |
||||
|
||||
info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable); |
||||
if (IS_ERR(info->edev)) { |
||||
dev_err(dev, "failed to allocate extcon device\n"); |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
ret = devm_extcon_dev_register(dev, info->edev); |
||||
if (ret < 0) { |
||||
dev_err(dev, "failed to register extcon device\n"); |
||||
return ret; |
||||
} |
||||
|
||||
platform_set_drvdata(pdev, info); |
||||
device_init_wakeup(dev, 1); |
||||
|
||||
/* Perform initial detection */ |
||||
usb_extcon_detect_cable(&info->wq_detcable.work); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int usb_extcon_remove(struct platform_device *pdev) |
||||
{ |
||||
struct usb_extcon_info *info = platform_get_drvdata(pdev); |
||||
|
||||
cancel_delayed_work_sync(&info->wq_detcable); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
#ifdef CONFIG_PM_SLEEP |
||||
static int usb_extcon_suspend(struct device *dev) |
||||
{ |
||||
struct usb_extcon_info *info = dev_get_drvdata(dev); |
||||
int ret = 0; |
||||
|
||||
if (device_may_wakeup(dev)) { |
||||
ret = enable_irq_wake(info->id_irq); |
||||
if (ret) |
||||
return ret; |
||||
} |
||||
|
||||
/*
|
||||
* We don't want to process any IRQs after this point |
||||
* as GPIOs used behind I2C subsystem might not be |
||||
* accessible until resume completes. So disable IRQ. |
||||
*/ |
||||
disable_irq(info->id_irq); |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
static int usb_extcon_resume(struct device *dev) |
||||
{ |
||||
struct usb_extcon_info *info = dev_get_drvdata(dev); |
||||
int ret = 0; |
||||
|
||||
if (device_may_wakeup(dev)) { |
||||
ret = disable_irq_wake(info->id_irq); |
||||
if (ret) |
||||
return ret; |
||||
} |
||||
|
||||
enable_irq(info->id_irq); |
||||
|
||||
return ret; |
||||
} |
||||
#endif |
||||
|
||||
static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops, |
||||
usb_extcon_suspend, usb_extcon_resume); |
||||
|
||||
static const struct of_device_id usb_extcon_dt_match[] = { |
||||
{ .compatible = "linux,extcon-usb-gpio", }, |
||||
{ /* sentinel */ } |
||||
}; |
||||
MODULE_DEVICE_TABLE(of, usb_extcon_dt_match); |
||||
|
||||
static struct platform_driver usb_extcon_driver = { |
||||
.probe = usb_extcon_probe, |
||||
.remove = usb_extcon_remove, |
||||
.driver = { |
||||
.name = "extcon-usb-gpio", |
||||
.pm = &usb_extcon_pm_ops, |
||||
.of_match_table = usb_extcon_dt_match, |
||||
}, |
||||
}; |
||||
|
||||
module_platform_driver(usb_extcon_driver); |
||||
|
||||
MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>"); |
||||
MODULE_DESCRIPTION("USB GPIO extcon driver"); |
||||
MODULE_LICENSE("GPL v2"); |
@ -0,0 +1,61 @@ |
||||
# |
||||
# Coresight configuration |
||||
# |
||||
menuconfig CORESIGHT |
||||
bool "CoreSight Tracing Support" |
||||
select ARM_AMBA |
||||
help |
||||
This framework provides a kernel interface for the CoreSight debug |
||||
and trace drivers to register themselves with. It's intended to build |
||||
a topological view of the CoreSight components based on a DT |
||||
specification and configure the right serie of components when a |
||||
trace source gets enabled. |
||||
|
||||
if CORESIGHT |
||||
config CORESIGHT_LINKS_AND_SINKS |
||||
bool "CoreSight Link and Sink drivers" |
||||
help |
||||
This enables support for CoreSight link and sink drivers that are |
||||
responsible for transporting and collecting the trace data |
||||
respectively. Link and sinks are dynamically aggregated with a trace |
||||
entity at run time to form a complete trace path. |
||||
|
||||
config CORESIGHT_LINK_AND_SINK_TMC |
||||
bool "Coresight generic TMC driver" |
||||
depends on CORESIGHT_LINKS_AND_SINKS |
||||
help |
||||
This enables support for the Trace Memory Controller driver. |
||||
Depending on its configuration the device can act as a link (embedded |
||||
trace router - ETR) or sink (embedded trace FIFO). The driver |
||||
complies with the generic implementation of the component without |
||||
special enhancement or added features. |
||||
|
||||
config CORESIGHT_SINK_TPIU |
||||
bool "Coresight generic TPIU driver" |
||||
depends on CORESIGHT_LINKS_AND_SINKS |
||||
help |
||||
This enables support for the Trace Port Interface Unit driver, |
||||
responsible for bridging the gap between the on-chip coresight |
||||
components and a trace for bridging the gap between the on-chip |
||||
coresight components and a trace port collection engine, typically |
||||
connected to an external host for use case capturing more traces than |
||||
the on-board coresight memory can handle. |
||||
|
||||
config CORESIGHT_SINK_ETBV10 |
||||
bool "Coresight ETBv1.0 driver" |
||||
depends on CORESIGHT_LINKS_AND_SINKS |
||||
help |
||||
This enables support for the Embedded Trace Buffer version 1.0 driver |
||||
that complies with the generic implementation of the component without |
||||
special enhancement or added features. |
||||
|
||||
config CORESIGHT_SOURCE_ETM3X |
||||
bool "CoreSight Embedded Trace Macrocell 3.x driver" |
||||
depends on !ARM64 |
||||
select CORESIGHT_LINKS_AND_SINKS |
||||
help |
||||
This driver provides support for processor ETM3.x and PTM1.x modules, |
||||
which allows tracing the instructions that a processor is executing |
||||
This is primarily useful for instruction level tracing. Depending |
||||
the ETM version data tracing may also be available. |
||||
endif |
@ -0,0 +1,391 @@ |
||||
/*
|
||||
* JZ4780 NAND/external memory controller (NEMC) |
||||
* |
||||
* Copyright (c) 2015 Imagination Technologies |
||||
* Author: Alex Smith <alex@alex-smith.me.uk> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it |
||||
* under the terms of the GNU General Public License version 2 as published |
||||
* by the Free Software Foundation. |
||||
*/ |
||||
|
||||
#include <linux/clk.h> |
||||
#include <linux/init.h> |
||||
#include <linux/math64.h> |
||||
#include <linux/of.h> |
||||
#include <linux/of_address.h> |
||||
#include <linux/of_device.h> |
||||
#include <linux/of_platform.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/slab.h> |
||||
#include <linux/spinlock.h> |
||||
|
||||
#include <linux/jz4780-nemc.h> |
||||
|
||||
#define NEMC_SMCRn(n) (0x14 + (((n) - 1) * 4)) |
||||
#define NEMC_NFCSR 0x50 |
||||
|
||||
#define NEMC_SMCR_SMT BIT(0) |
||||
#define NEMC_SMCR_BW_SHIFT 6 |
||||
#define NEMC_SMCR_BW_MASK (0x3 << NEMC_SMCR_BW_SHIFT) |
||||
#define NEMC_SMCR_BW_8 (0 << 6) |
||||
#define NEMC_SMCR_TAS_SHIFT 8 |
||||
#define NEMC_SMCR_TAS_MASK (0xf << NEMC_SMCR_TAS_SHIFT) |
||||
#define NEMC_SMCR_TAH_SHIFT 12 |
||||
#define NEMC_SMCR_TAH_MASK (0xf << NEMC_SMCR_TAH_SHIFT) |
||||
#define NEMC_SMCR_TBP_SHIFT 16 |
||||
#define NEMC_SMCR_TBP_MASK (0xf << NEMC_SMCR_TBP_SHIFT) |
||||
#define NEMC_SMCR_TAW_SHIFT 20 |
||||
#define NEMC_SMCR_TAW_MASK (0xf << NEMC_SMCR_TAW_SHIFT) |
||||
#define NEMC_SMCR_TSTRV_SHIFT 24 |
||||
#define NEMC_SMCR_TSTRV_MASK (0x3f << NEMC_SMCR_TSTRV_SHIFT) |
||||
|
||||
#define NEMC_NFCSR_NFEn(n) BIT(((n) - 1) << 1) |
||||
#define NEMC_NFCSR_NFCEn(n) BIT((((n) - 1) << 1) + 1) |
||||
#define NEMC_NFCSR_TNFEn(n) BIT(16 + (n) - 1) |
||||
|
||||
struct jz4780_nemc { |
||||
spinlock_t lock; |
||||
struct device *dev; |
||||
void __iomem *base; |
||||
struct clk *clk; |
||||
uint32_t clk_period; |
||||
unsigned long banks_present; |
||||
}; |
||||
|
||||
/**
|
||||
* jz4780_nemc_num_banks() - count the number of banks referenced by a device |
||||
* @dev: device to count banks for, must be a child of the NEMC. |
||||
* |
||||
* Return: The number of unique NEMC banks referred to by the specified NEMC |
||||
* child device. Unique here means that a device that references the same bank |
||||
* multiple times in the its "reg" property will only count once. |
||||
*/ |
||||
unsigned int jz4780_nemc_num_banks(struct device *dev) |
||||
{ |
||||
const __be32 *prop; |
||||
unsigned int bank, count = 0; |
||||
unsigned long referenced = 0; |
||||
int i = 0; |
||||
|
||||
while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) { |
||||
bank = of_read_number(prop, 1); |
||||
if (!(referenced & BIT(bank))) { |
||||
referenced |= BIT(bank); |
||||
count++; |
||||
} |
||||
} |
||||
|
||||
return count; |
||||
} |
||||
EXPORT_SYMBOL(jz4780_nemc_num_banks); |
||||
|
||||
/**
|
||||
* jz4780_nemc_set_type() - set the type of device connected to a bank |
||||
* @dev: child device of the NEMC. |
||||
* @bank: bank number to configure. |
||||
* @type: type of device connected to the bank. |
||||
*/ |
||||
void jz4780_nemc_set_type(struct device *dev, unsigned int bank, |
||||
enum jz4780_nemc_bank_type type) |
||||
{ |
||||
struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); |
||||
uint32_t nfcsr; |
||||
|
||||
nfcsr = readl(nemc->base + NEMC_NFCSR); |
||||
|
||||
/* TODO: Support toggle NAND devices. */ |
||||
switch (type) { |
||||
case JZ4780_NEMC_BANK_SRAM: |
||||
nfcsr &= ~(NEMC_NFCSR_TNFEn(bank) | NEMC_NFCSR_NFEn(bank)); |
||||
break; |
||||
case JZ4780_NEMC_BANK_NAND: |
||||
nfcsr &= ~NEMC_NFCSR_TNFEn(bank); |
||||
nfcsr |= NEMC_NFCSR_NFEn(bank); |
||||
break; |
||||
} |
||||
|
||||
writel(nfcsr, nemc->base + NEMC_NFCSR); |
||||
} |
||||
EXPORT_SYMBOL(jz4780_nemc_set_type); |
||||
|
||||
/**
|
||||
* jz4780_nemc_assert() - (de-)assert a NAND device's chip enable pin |
||||
* @dev: child device of the NEMC. |
||||
* @bank: bank number of device. |
||||
* @assert: whether the chip enable pin should be asserted. |
||||
* |
||||
* (De-)asserts the chip enable pin for the NAND device connected to the |
||||
* specified bank. |
||||
*/ |
||||
void jz4780_nemc_assert(struct device *dev, unsigned int bank, bool assert) |
||||
{ |
||||
struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); |
||||
uint32_t nfcsr; |
||||
|
||||
nfcsr = readl(nemc->base + NEMC_NFCSR); |
||||
|
||||
if (assert) |
||||
nfcsr |= NEMC_NFCSR_NFCEn(bank); |
||||
else |
||||
nfcsr &= ~NEMC_NFCSR_NFCEn(bank); |
||||
|
||||
writel(nfcsr, nemc->base + NEMC_NFCSR); |
||||
} |
||||
EXPORT_SYMBOL(jz4780_nemc_assert); |
||||
|
||||
static uint32_t jz4780_nemc_clk_period(struct jz4780_nemc *nemc) |
||||
{ |
||||
unsigned long rate; |
||||
|
||||
rate = clk_get_rate(nemc->clk); |
||||
if (!rate) |
||||
return 0; |
||||
|
||||
/* Return in picoseconds. */ |
||||
return div64_ul(1000000000000ull, rate); |
||||
} |
||||
|
||||
static uint32_t jz4780_nemc_ns_to_cycles(struct jz4780_nemc *nemc, uint32_t ns) |
||||
{ |
||||
return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period; |
||||
} |
||||
|
||||
static bool jz4780_nemc_configure_bank(struct jz4780_nemc *nemc, |
||||
unsigned int bank, |
||||
struct device_node *node) |
||||
{ |
||||
uint32_t smcr, val, cycles; |
||||
|
||||
/*
|
||||
* Conversion of tBP and tAW cycle counts to values supported by the |
||||
* hardware (round up to the next supported value). |
||||
*/ |
||||
static const uint32_t convert_tBP_tAW[] = { |
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
||||
|
||||
/* 11 - 12 -> 12 cycles */ |
||||
11, 11, |
||||
|
||||
/* 13 - 15 -> 15 cycles */ |
||||
12, 12, 12, |
||||
|
||||
/* 16 - 20 -> 20 cycles */ |
||||
13, 13, 13, 13, 13, |
||||
|
||||
/* 21 - 25 -> 25 cycles */ |
||||
14, 14, 14, 14, 14, |
||||
|
||||
/* 26 - 31 -> 31 cycles */ |
||||
15, 15, 15, 15, 15, 15 |
||||
}; |
||||
|
||||
smcr = readl(nemc->base + NEMC_SMCRn(bank)); |
||||
smcr &= ~NEMC_SMCR_SMT; |
||||
|
||||
if (!of_property_read_u32(node, "ingenic,nemc-bus-width", &val)) { |
||||
smcr &= ~NEMC_SMCR_BW_MASK; |
||||
switch (val) { |
||||
case 8: |
||||
smcr |= NEMC_SMCR_BW_8; |
||||
break; |
||||
default: |
||||
/*
|
||||
* Earlier SoCs support a 16 bit bus width (the 4780 |
||||
* does not), until those are properly supported, error. |
||||
*/ |
||||
dev_err(nemc->dev, "unsupported bus width: %u\n", val); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
if (of_property_read_u32(node, "ingenic,nemc-tAS", &val) == 0) { |
||||
smcr &= ~NEMC_SMCR_TAS_MASK; |
||||
cycles = jz4780_nemc_ns_to_cycles(nemc, val); |
||||
if (cycles > 15) { |
||||
dev_err(nemc->dev, "tAS %u is too high (%u cycles)\n", |
||||
val, cycles); |
||||
return false; |
||||
} |
||||
|
||||
smcr |= cycles << NEMC_SMCR_TAS_SHIFT; |
||||
} |
||||
|
||||
if (of_property_read_u32(node, "ingenic,nemc-tAH", &val) == 0) { |
||||
smcr &= ~NEMC_SMCR_TAH_MASK; |
||||
cycles = jz4780_nemc_ns_to_cycles(nemc, val); |
||||
if (cycles > 15) { |
||||
dev_err(nemc->dev, "tAH %u is too high (%u cycles)\n", |
||||
val, cycles); |
||||
return false; |
||||
} |
||||
|
||||
smcr |= cycles << NEMC_SMCR_TAH_SHIFT; |
||||
} |
||||
|
||||
if (of_property_read_u32(node, "ingenic,nemc-tBP", &val) == 0) { |
||||
smcr &= ~NEMC_SMCR_TBP_MASK; |
||||
cycles = jz4780_nemc_ns_to_cycles(nemc, val); |
||||
if (cycles > 31) { |
||||
dev_err(nemc->dev, "tBP %u is too high (%u cycles)\n", |
||||
val, cycles); |
||||
return false; |
||||
} |
||||
|
||||
smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TBP_SHIFT; |
||||
} |
||||
|
||||
if (of_property_read_u32(node, "ingenic,nemc-tAW", &val) == 0) { |
||||
smcr &= ~NEMC_SMCR_TAW_MASK; |
||||
cycles = jz4780_nemc_ns_to_cycles(nemc, val); |
||||
if (cycles > 31) { |
||||
dev_err(nemc->dev, "tAW %u is too high (%u cycles)\n", |
||||
val, cycles); |
||||
return false; |
||||
} |
||||
|
||||
smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TAW_SHIFT; |
||||
} |
||||
|
||||
if (of_property_read_u32(node, "ingenic,nemc-tSTRV", &val) == 0) { |
||||
smcr &= ~NEMC_SMCR_TSTRV_MASK; |
||||
cycles = jz4780_nemc_ns_to_cycles(nemc, val); |
||||
if (cycles > 63) { |
||||
dev_err(nemc->dev, "tSTRV %u is too high (%u cycles)\n", |
||||
val, cycles); |
||||
return false; |
||||
} |
||||
|
||||
smcr |= cycles << NEMC_SMCR_TSTRV_SHIFT; |
||||
} |
||||
|
||||
writel(smcr, nemc->base + NEMC_SMCRn(bank)); |
||||
return true; |
||||
} |
||||
|
||||
static int jz4780_nemc_probe(struct platform_device *pdev) |
||||
{ |
||||
struct device *dev = &pdev->dev; |
||||
struct jz4780_nemc *nemc; |
||||
struct resource *res; |
||||
struct device_node *child; |
||||
const __be32 *prop; |
||||
unsigned int bank; |
||||
unsigned long referenced; |
||||
int i, ret; |
||||
|
||||
nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL); |
||||
if (!nemc) |
||||
return -ENOMEM; |
||||
|
||||
spin_lock_init(&nemc->lock); |
||||
nemc->dev = dev; |
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
||||
nemc->base = devm_ioremap_resource(dev, res); |
||||
if (IS_ERR(nemc->base)) { |
||||
dev_err(dev, "failed to get I/O memory\n"); |
||||
return PTR_ERR(nemc->base); |
||||
} |
||||
|
||||
writel(0, nemc->base + NEMC_NFCSR); |
||||
|
||||
nemc->clk = devm_clk_get(dev, NULL); |
||||
if (IS_ERR(nemc->clk)) { |
||||
dev_err(dev, "failed to get clock\n"); |
||||
return PTR_ERR(nemc->clk); |
||||
} |
||||
|
||||
ret = clk_prepare_enable(nemc->clk); |
||||
if (ret) { |
||||
dev_err(dev, "failed to enable clock: %d\n", ret); |
||||
return ret; |
||||
} |
||||
|
||||
nemc->clk_period = jz4780_nemc_clk_period(nemc); |
||||
if (!nemc->clk_period) { |
||||
dev_err(dev, "failed to calculate clock period\n"); |
||||
clk_disable_unprepare(nemc->clk); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
/*
|
||||
* Iterate over child devices, check that they do not conflict with |
||||
* each other, and register child devices for them. If a child device |
||||
* has invalid properties, it is ignored and no platform device is |
||||
* registered for it. |
||||
*/ |
||||
for_each_child_of_node(nemc->dev->of_node, child) { |
||||
referenced = 0; |
||||
i = 0; |
||||
while ((prop = of_get_address(child, i++, NULL, NULL))) { |
||||
bank = of_read_number(prop, 1); |
||||
if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) { |
||||
dev_err(nemc->dev, |
||||
"%s requests invalid bank %u\n", |
||||
child->full_name, bank); |
||||
|
||||
/* Will continue the outer loop below. */ |
||||
referenced = 0; |
||||
break; |
||||
} |
||||
|
||||
referenced |= BIT(bank); |
||||
} |
||||
|
||||
if (!referenced) { |
||||
dev_err(nemc->dev, "%s has no addresses\n", |
||||
child->full_name); |
||||
continue; |
||||
} else if (nemc->banks_present & referenced) { |
||||
dev_err(nemc->dev, "%s conflicts with another node\n", |
||||
child->full_name); |
||||
continue; |
||||
} |
||||
|
||||
/* Configure bank parameters. */ |
||||
for_each_set_bit(bank, &referenced, JZ4780_NEMC_NUM_BANKS) { |
||||
if (!jz4780_nemc_configure_bank(nemc, bank, child)) { |
||||
referenced = 0; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (referenced) { |
||||
if (of_platform_device_create(child, NULL, nemc->dev)) |
||||
nemc->banks_present |= referenced; |
||||
} |
||||
} |
||||
|
||||
platform_set_drvdata(pdev, nemc); |
||||
dev_info(dev, "JZ4780 NEMC initialised\n"); |
||||
return 0; |
||||
} |
||||
|
||||
static int jz4780_nemc_remove(struct platform_device *pdev) |
||||
{ |
||||
struct jz4780_nemc *nemc = platform_get_drvdata(pdev); |
||||
|
||||
clk_disable_unprepare(nemc->clk); |
||||
return 0; |
||||
} |
||||
|
||||
static const struct of_device_id jz4780_nemc_dt_match[] = { |
||||
{ .compatible = "ingenic,jz4780-nemc" }, |
||||
{}, |
||||
}; |
||||
|
||||
static struct platform_driver jz4780_nemc_driver = { |
||||
.probe = jz4780_nemc_probe, |
||||
.remove = jz4780_nemc_remove, |
||||
.driver = { |
||||
.name = "jz4780-nemc", |
||||
.of_match_table = of_match_ptr(jz4780_nemc_dt_match), |
||||
}, |
||||
}; |
||||
|
||||
static int __init jz4780_nemc_init(void) |
||||
{ |
||||
return platform_driver_register(&jz4780_nemc_driver); |
||||
} |
||||
subsys_initcall(jz4780_nemc_init); |
@ -0,0 +1,25 @@ |
||||
/*
|
||||
* |
||||
* Intel Management Engine Interface (Intel MEI) Linux driver |
||||
* Copyright (c) 2015, Intel Corporation. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it |
||||
* under the terms and conditions of the GNU General Public License, |
||||
* version 2, as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope it will be useful, but WITHOUT |
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
||||
* more details. |
||||
* |
||||
*/ |
||||
#include <linux/module.h> |
||||
|
||||
/* sparse doesn't like tracepoint macros */ |
||||
#ifndef __CHECKER__ |
||||
#define CREATE_TRACE_POINTS |
||||
#include "mei-trace.h" |
||||
|
||||
EXPORT_TRACEPOINT_SYMBOL(mei_reg_read); |
||||
EXPORT_TRACEPOINT_SYMBOL(mei_reg_write); |
||||
#endif /* __CHECKER__ */ |
@ -0,0 +1,74 @@ |
||||
/*
|
||||
* |
||||
* Intel Management Engine Interface (Intel MEI) Linux driver |
||||
* Copyright (c) 2015, Intel Corporation. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it |
||||
* under the terms and conditions of the GNU General Public License, |
||||
* version 2, as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope it will be useful, but WITHOUT |
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
||||
* more details. |
||||
* |
||||
*/ |
||||
|
||||
#if !defined(_MEI_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) |
||||
#define _MEI_TRACE_H_ |
||||
|
||||
#include <linux/stringify.h> |
||||
#include <linux/types.h> |
||||
#include <linux/tracepoint.h> |
||||
|
||||
#include <linux/device.h> |
||||
|
||||
#undef TRACE_SYSTEM |
||||
#define TRACE_SYSTEM mei |
||||
|
||||
TRACE_EVENT(mei_reg_read, |
||||
TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val), |
||||
TP_ARGS(dev, reg, offs, val), |
||||
TP_STRUCT__entry( |
||||
__string(dev, dev_name(dev)) |
||||
__field(const char *, reg) |
||||
__field(u32, offs) |
||||
__field(u32, val) |
||||
), |
||||
TP_fast_assign( |
||||
__assign_str(dev, dev_name(dev)) |
||||
__entry->reg = reg; |
||||
__entry->offs = offs; |
||||
__entry->val = val; |
||||
), |
||||
TP_printk("[%s] read %s:[%#x] = %#x", |
||||
__get_str(dev), __entry->reg, __entry->offs, __entry->val) |
||||
); |
||||
|
||||
TRACE_EVENT(mei_reg_write, |
||||
TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val), |
||||
TP_ARGS(dev, reg, offs, val), |
||||
TP_STRUCT__entry( |
||||
__string(dev, dev_name(dev)) |
||||
__field(const char *, reg) |
||||
__field(u32, offs) |
||||
__field(u32, val) |
||||
), |
||||
TP_fast_assign( |
||||
__assign_str(dev, dev_name(dev)) |
||||
__entry->reg = reg; |
||||
__entry->offs = offs; |
||||
__entry->val = val; |
||||
), |
||||
TP_printk("[%s] write %s[%#x] = %#x)", |
||||
__get_str(dev), __entry->reg, __entry->offs, __entry->val) |
||||
); |
||||
|
||||
#endif /* _MEI_TRACE_H_ */ |
||||
|
||||
/* This part must be outside protection */ |
||||
#undef TRACE_INCLUDE_PATH |
||||
#undef TRACE_INCLUDE_FILE |
||||
#define TRACE_INCLUDE_PATH . |
||||
#define TRACE_INCLUDE_FILE mei-trace |
||||
#include <trace/define_trace.h> |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue