[PATCH] staging: rtl8188eu: cleanup spacing style
This patch fixes a few spacing warnings from checkpatch.pl, as well as an incorrect spacing between a function type and the function name. Signed-off-by: Robert Eshleman --- drivers/staging/rtl8188eu/core/rtw_ap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c index 94c9d9f..fc500da 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ap.c +++ b/drivers/staging/rtl8188eu/core/rtw_ap.c @@ -68,7 +68,7 @@ static void update_BCNTIM(struct adapter *padapter) /* update TIM IE */ p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, - pnetwork_mlmeext->ie_length - _FIXED_IE_LENGTH_); + pnetwork_mlmeext->ie_length - _FIXED_IE_LENGTH_); if (p && tim_ielen > 0) { tim_ielen += 2; premainder_ie = p + tim_ielen; @@ -89,7 +89,7 @@ static void update_BCNTIM(struct adapter *padapter) &tmp_len, (pnetwork_mlmeext->ie_length - _BEACON_IE_OFFSET_)); if (p) - offset += tmp_len+2; + offset += tmp_len + 2; /* DS Parameter Set IE, len = 3 */ offset += 3; @@ -162,7 +162,7 @@ static u8 chk_sta_is_alive(struct sta_info *psta) return ret; } -void expire_timeout_chk(struct adapter *padapter) +void expire_timeout_chk(struct adapter *padapter) { struct list_head *phead, *plist; u8 updated = 0; -- 2.7.4
Re: [PATCH 7/8] net: seeq: replace kmalloc / memset(,0) with kzalloc
On Tue, Feb 26, 2019 at 10:09:54PM -0800, Robert Eshleman wrote: > This patch reduces a call to memset(,0) by replacing > a kmalloc call with a kzalloc call. > > Signed-off-by: Robert Eshleman > --- > drivers/net/ethernet/seeq/ether3.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/seeq/ether3.c > b/drivers/net/ethernet/seeq/ether3.c > index d1bb73bf9914..7456cf08a48f 100644 > --- a/drivers/net/ethernet/seeq/ether3.c > +++ b/drivers/net/ethernet/seeq/ether3.c > @@ -223,7 +223,7 @@ ether3_addr(char *addr, struct expansion_card *ec) > static int > ether3_ramtest(struct net_device *dev, unsigned char byte) > { > - unsigned char *buffer = kmalloc(RX_END, GFP_KERNEL); > + unsigned char *buffer = kzalloc(RX_END, GFP_KERNEL); > int i,ret = 0; > int max_errors = 4; > int bad = -1; > @@ -231,7 +231,6 @@ ether3_ramtest(struct net_device *dev, unsigned char byte) > if (!buffer) > return 1; > > - memset(buffer, byte, RX_END); Byte is not zero, so the intent of this patch does not apply here. Dropping this from the patch set in v2. > ether3_setbuffer(dev, buffer_write, 0); > ether3_writebuffer(dev, buffer, TX_END); > ether3_setbuffer(dev, buffer_write, RX_START); > -- > 2.20.1 >
Re: [PATCH 3/8] tlan: use pci_zalloc instead of pci_alloc
On Tue, Feb 26, 2019 at 10:22:06PM -0800, Joe Perches wrote: > On Tue, 2019-02-26 at 22:09 -0800, Robert Eshleman wrote: > > This patch replaces a pci_alloc_consistent and memset(,0) call > > with a single call to pci_zalloc_consistent. > [] > > diff --git a/drivers/net/ethernet/ti/tlan.c b/drivers/net/ethernet/ti/tlan.c > [] > > @@ -845,17 +845,16 @@ static int tlan_init(struct net_device *dev) > > > > dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS) > > * (sizeof(struct tlan_list)); > > - priv->dma_storage = pci_alloc_consistent(priv->pci_dev, > > -dma_size, > > -&priv->dma_storage_dma); > > + priv->dma_storage = pci_zalloc_consistent(priv->pci_dev, > > + dma_size, > > + &priv->dma_storage_dma); > > priv->dma_size = dma_size; > > > > - if (priv->dma_storage == NULL) { > > + if (!priv->dma_storage) { > > pr_err("Could not allocate lists and buffers for %s\n", > >dev->name); > > unrelated trivia: > > This pr_err (and likely others in this file) > could be replace by netdev_err > Definitely good to know (I may make that change too). Thanks Joe. -Bobby
[PATCH 7/8] net: seeq: replace kmalloc / memset(,0) with kzalloc
This patch reduces a call to memset(,0) by replacing a kmalloc call with a kzalloc call. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/seeq/ether3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/seeq/ether3.c b/drivers/net/ethernet/seeq/ether3.c index d1bb73bf9914..7456cf08a48f 100644 --- a/drivers/net/ethernet/seeq/ether3.c +++ b/drivers/net/ethernet/seeq/ether3.c @@ -223,7 +223,7 @@ ether3_addr(char *addr, struct expansion_card *ec) static int ether3_ramtest(struct net_device *dev, unsigned char byte) { - unsigned char *buffer = kmalloc(RX_END, GFP_KERNEL); + unsigned char *buffer = kzalloc(RX_END, GFP_KERNEL); int i,ret = 0; int max_errors = 4; int bad = -1; @@ -231,7 +231,6 @@ ether3_ramtest(struct net_device *dev, unsigned char byte) if (!buffer) return 1; - memset(buffer, byte, RX_END); ether3_setbuffer(dev, buffer_write, 0); ether3_writebuffer(dev, buffer, TX_END); ether3_setbuffer(dev, buffer_write, RX_START); -- 2.20.1
[PATCH 8/8] net: ethernet: ixp4xx_eth: remove memset(,0) with zalloc
This patch removes a call to memset(,0) by replacing the prior call to dma_pool_alloc with a call to dma_pool_zalloc. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/xscale/ixp4xx_eth.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c index aee55c03def0..8471e1857d53 100644 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c @@ -1107,11 +1107,10 @@ static int init_queues(struct port *port) if (!dma_pool) return -ENOMEM; } - - if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL, - &port->desc_tab_phys))) + port->desc_tab = dma_pool_zalloc(dma_pool, GFP_KERNEL, +&port->desc_tab_phys); + if (!port->desc_tab) return -ENOMEM; - memset(port->desc_tab, 0, POOL_ALLOC_SIZE); memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */ memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab)); -- 2.20.1
[PATCH 1/8] net/mlx4: use kzalloc instead of kmalloc
This patch replaces a kmalloc/memset(,0) call with a call to kzalloc. It also removes a memset(,0) call that always follows a *zalloc call. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/mellanox/mlx4/cmd.c | 1 - drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c index e65bc3c95630..7bfa6e850e5f 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -3307,7 +3307,6 @@ int mlx4_get_counter_stats(struct mlx4_dev *dev, int counter_index, if (IS_ERR(mailbox)) return PTR_ERR(mailbox); - memset(mailbox->buf, 0, sizeof(struct mlx4_counter)); if_stat_in_mod = counter_index; if (reset) if_stat_in_mod |= MLX4_QUERY_IF_STAT_RESET; diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c index 9a0881cb7f51..f55805d206ef 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -1044,7 +1044,7 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn, struct mlx4_qp_context *context; int err = 0; - context = kmalloc(sizeof(*context), GFP_KERNEL); + context = kzalloc(sizeof(*context), GFP_KERNEL); if (!context) return -ENOMEM; @@ -1055,7 +1055,6 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn, } qp->event = mlx4_en_sqp_event; - memset(context, 0, sizeof(*context)); mlx4_en_fill_qp_context(priv, ring->actual_size, ring->stride, 0, 0, qpn, ring->cqn, -1, context); context->db_rec_addr = cpu_to_be64(ring->wqres.db.dma); -- 2.20.1
[PATCH 2/8] net/mlxsw: use pci_zalloc_consistent instead of pci_alloc_consistent
This patch replaces a call to pci_alloc_consistent and then memset(0,) with a single call to pci_zalloc_consistent. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c index a2321fe8d6a0..388f349573f3 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci.c +++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c @@ -830,12 +830,11 @@ static int mlxsw_pci_queue_init(struct mlxsw_pci *mlxsw_pci, char *mbox, tasklet_init(&q->tasklet, q_ops->tasklet, (unsigned long) q); mem_item->size = MLXSW_PCI_AQ_SIZE; - mem_item->buf = pci_alloc_consistent(mlxsw_pci->pdev, -mem_item->size, -&mem_item->mapaddr); + mem_item->buf = pci_zalloc_consistent(mlxsw_pci->pdev, + mem_item->size, + &mem_item->mapaddr); if (!mem_item->buf) return -ENOMEM; - memset(mem_item->buf, 0, mem_item->size); q->elem_info = kcalloc(q->count, sizeof(*q->elem_info), GFP_KERNEL); if (!q->elem_info) { -- 2.20.1
[PATCH 4/8] qed: remove unnecessary memsets
This patch replaces unnecessary memset(,0) calls with simply assigning structs to zero. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 4 +- drivers/net/ethernet/qlogic/qed/qed_hw.c | 3 +- drivers/net/ethernet/qlogic/qed/qed_mcp.c | 70 --- 3 files changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c b/drivers/net/ethernet/qlogic/qed/qed_cxt.c index c2ad405b2f50..0452ef2fdf1d 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c +++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c @@ -902,12 +902,10 @@ static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn) struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr; u32 conn_num, total_size, ent_per_page, psz, i; struct qed_ilt_client_cfg *p_src; - struct qed_src_iids src_iids; + struct qed_src_iids src_iids = {0}; struct qed_dma_mem *p_t2; int rc; - memset(&src_iids, 0, sizeof(src_iids)); - /* if the SRC ILT client is inactive - there are no connection * requiring the searcer, leave. */ diff --git a/drivers/net/ethernet/qlogic/qed/qed_hw.c b/drivers/net/ethernet/qlogic/qed/qed_hw.c index 70504dcf4087..b8ca3a31409b 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_hw.c +++ b/drivers/net/ethernet/qlogic/qed/qed_hw.c @@ -831,7 +831,7 @@ int qed_dmae_sanity(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, const char *phase) { u32 size = PAGE_SIZE / 2, val; - struct qed_dmae_params params; + struct qed_dmae_params params = {0}; int rc = 0; dma_addr_t p_phys; void *p_virt; @@ -864,7 +864,6 @@ int qed_dmae_sanity(struct qed_hwfn *p_hwfn, (u64)p_phys, p_virt, (u64)(p_phys + size), (u8 *)p_virt + size, size); - memset(¶ms, 0, sizeof(params)); rc = qed_dmae_host2host(p_hwfn, p_ptt, p_phys, p_phys + size, size / 4 /* size_in_dwords */, ¶ms); if (rc) { diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.c b/drivers/net/ethernet/qlogic/qed/qed_mcp.c index e7f18e34ff0d..e1b72fc819a9 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_mcp.c +++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.c @@ -642,10 +642,9 @@ int qed_mcp_cmd(struct qed_hwfn *p_hwfn, u32 *o_mcp_resp, u32 *o_mcp_param) { - struct qed_mcp_mb_params mb_params; + struct qed_mcp_mb_params mb_params = {0}; int rc; - memset(&mb_params, 0, sizeof(mb_params)); mb_params.cmd = cmd; mb_params.param = param; @@ -667,10 +666,9 @@ qed_mcp_nvm_wr_cmd(struct qed_hwfn *p_hwfn, u32 *o_mcp_resp, u32 *o_mcp_param, u32 i_txn_size, u32 *i_buf) { - struct qed_mcp_mb_params mb_params; + struct qed_mcp_mb_params mb_params = {0}; int rc; - memset(&mb_params, 0, sizeof(mb_params)); mb_params.cmd = cmd; mb_params.param = param; mb_params.p_data_src = i_buf; @@ -695,11 +693,10 @@ int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn, u32 *o_mcp_resp, u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf) { - struct qed_mcp_mb_params mb_params; + struct qed_mcp_mb_params mb_params = {0}; u8 raw_data[MCP_DRV_NVM_BUF_LEN]; int rc; - memset(&mb_params, 0, sizeof(mb_params)); mb_params.cmd = cmd; mb_params.param = param; mb_params.p_data_dst = raw_data; @@ -821,13 +818,12 @@ __qed_mcp_load_req(struct qed_hwfn *p_hwfn, struct qed_load_req_in_params *p_in_params, struct qed_load_req_out_params *p_out_params) { - struct qed_mcp_mb_params mb_params; - struct load_req_stc load_req; + struct qed_mcp_mb_params mb_params = {0}; + struct load_req_stc load_req = {0}; struct load_rsp_stc load_rsp; u32 hsi_ver; int rc; - memset(&load_req, 0, sizeof(load_req)); load_req.drv_ver_0 = p_in_params->drv_ver_0; load_req.drv_ver_1 = p_in_params->drv_ver_1; load_req.fw_ver = p_in_params->fw_ver; @@ -843,7 +839,6 @@ __qed_mcp_load_req(struct qed_hwfn *p_hwfn, DRV_ID_MCP_HSI_VER_CURRENT : (p_in_params->hsi_ver << DRV_ID_MCP_HSI_VER_SHIFT); - memset(&mb_params, 0, sizeof(mb_params)); mb_params.cmd = DRV_MSG_CODE_LOAD_REQ; mb_params.param = PDA_COMP | hsi_ver | p_hwfn->cdev->drv_type; mb_params.p_data_src = &load_req; @@ -959,12 +954,11 @@ int qed_mcp_load_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, struct qed_load_req_params *p_params) { - struct qed_load_req_out_params out_params; - struct qed_load_req_in_params in_params; + struct qed_load_req_out_params out_params
[PATCH 3/8] tlan: use pci_zalloc instead of pci_alloc
This patch replaces a pci_alloc_consistent and memset(,0) call with a single call to pci_zalloc_consistent. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/ti/tlan.c | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/ti/tlan.c b/drivers/net/ethernet/ti/tlan.c index b4ab1a5f6cd0..e1f7e71c3b21 100644 --- a/drivers/net/ethernet/ti/tlan.c +++ b/drivers/net/ethernet/ti/tlan.c @@ -845,17 +845,16 @@ static int tlan_init(struct net_device *dev) dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS) * (sizeof(struct tlan_list)); - priv->dma_storage = pci_alloc_consistent(priv->pci_dev, -dma_size, -&priv->dma_storage_dma); + priv->dma_storage = pci_zalloc_consistent(priv->pci_dev, + dma_size, + &priv->dma_storage_dma); priv->dma_size = dma_size; - if (priv->dma_storage == NULL) { + if (!priv->dma_storage) { pr_err("Could not allocate lists and buffers for %s\n", dev->name); return -ENOMEM; } - memset(priv->dma_storage, 0, dma_size); priv->rx_list = (struct tlan_list *) ALIGN((unsigned long)priv->dma_storage, 8); priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8); -- 2.20.1
[PATCH 5/8] at12: use pci_zalloc instead of pci_alloc
This patch replaces a pci_alloc and memset(,0) call with a single call to pci_zalloc. Signed-off-by: Robert Eshleman --- drivers/net/ethernet/atheros/atlx/atl2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c index bb41becb6609..a145c2d1b1d2 100644 --- a/drivers/net/ethernet/atheros/atlx/atl2.c +++ b/drivers/net/ethernet/atheros/atlx/atl2.c @@ -300,11 +300,10 @@ static s32 atl2_setup_ring_resources(struct atl2_adapter *adapter) adapter->txs_ring_size * 4 + 7 +/* dword align */ adapter->rxd_ring_size * 1536 + 127;/* 128bytes align */ - adapter->ring_vir_addr = pci_alloc_consistent(pdev, size, - &adapter->ring_dma); + adapter->ring_vir_addr = pci_zalloc_consistent(pdev, size, + &adapter->ring_dma); if (!adapter->ring_vir_addr) return -ENOMEM; - memset(adapter->ring_vir_addr, 0, adapter->ring_size); /* Init TXD Ring */ adapter->txd_dma = adapter->ring_dma ; -- 2.20.1
[PATCH 6/8] netxen: remove unnecessary memset(,0) calls
This patch reduces calls to memset(,0) by replacing memset(,0) calls that only zero-out newly declared structs with simply assigning those structs to zero structs. It also removes a pci_alloc_consistent call followed by a memset(,0) call by simply using pci_zalloc_consistent. Signed-off-by: Robert Eshleman --- .../ethernet/qlogic/netxen/netxen_nic_ctx.c | 36 +++ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c index 7503aa222392..f2010c032361 100644 --- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c @@ -99,8 +99,7 @@ netxen_issue_cmd(struct netxen_adapter *adapter, struct netxen_cmd_args *cmd) static int netxen_get_minidump_template_size(struct netxen_adapter *adapter) { - struct netxen_cmd_args cmd; - memset(&cmd, 0, sizeof(cmd)); + struct netxen_cmd_args cmd = {0}; cmd.req.cmd = NX_CDRP_CMD_TEMP_SIZE; memset(&cmd.rsp, 1, sizeof(struct _cdrp_cmd)); netxen_issue_cmd(adapter, &cmd); @@ -120,7 +119,7 @@ netxen_get_minidump_template(struct netxen_adapter *adapter) dma_addr_t md_template_addr; void *addr; u32 size; - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; size = adapter->mdump.md_template_size; if (size == 0) { @@ -135,7 +134,6 @@ netxen_get_minidump_template(struct netxen_adapter *adapter) return -ENOMEM; } - memset(&cmd, 0, sizeof(cmd)); memset(&cmd.rsp, 1, sizeof(struct _cdrp_cmd)); cmd.req.cmd = NX_CDRP_CMD_GET_TEMP_HDR; cmd.req.arg1 = LSD(md_template_addr); @@ -233,9 +231,8 @@ nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu) { u32 rcode = NX_RCODE_SUCCESS; struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; - memset(&cmd, 0, sizeof(cmd)); cmd.req.cmd = NX_CDRP_CMD_SET_MTU; cmd.req.arg1 = recv_ctx->context_id; cmd.req.arg2 = mtu; @@ -254,9 +251,8 @@ int nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter, u32 speed, u32 duplex, u32 autoneg) { - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; - memset(&cmd, 0, sizeof(cmd)); cmd.req.cmd = NX_CDRP_CMD_CONFIG_GBE_PORT; cmd.req.arg1 = speed; cmd.req.arg2 = duplex; @@ -276,7 +272,7 @@ nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter) nx_cardrsp_sds_ring_t *prsp_sds; struct nx_host_rds_ring *rds_ring; struct nx_host_sds_ring *sds_ring; - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; dma_addr_t hostrq_phys_addr, cardrsp_phys_addr; u64 phys_addr; @@ -359,7 +355,6 @@ nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter) } phys_addr = hostrq_phys_addr; - memset(&cmd, 0, sizeof(cmd)); cmd.req.arg1 = (u32)(phys_addr >> 32); cmd.req.arg2 = (u32)(phys_addr & 0x); cmd.req.arg3 = rq_size; @@ -413,9 +408,8 @@ static void nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter *adapter) { struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; - memset(&cmd, 0, sizeof(cmd)); cmd.req.arg1 = recv_ctx->context_id; cmd.req.arg2 = NX_DESTROY_CTX_RESET; cmd.req.arg3 = 0; @@ -520,9 +514,8 @@ nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter) static void nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter *adapter) { - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; - memset(&cmd, 0, sizeof(cmd)); cmd.req.arg1 = adapter->tx_context_id; cmd.req.arg2 = NX_DESTROY_CTX_RESET; cmd.req.arg3 = 0; @@ -538,9 +531,8 @@ int nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val) { u32 rcode; - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; - memset(&cmd, 0, sizeof(cmd)); cmd.req.arg1 = reg; cmd.req.arg2 = 0; cmd.req.arg3 = 0; @@ -561,9 +553,8 @@ int nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val) { u32 rcode; - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; - memset(&cmd, 0, sizeof(cmd)); cmd.req.arg1 = reg; cmd.req.arg2 = val; cmd.req.arg3 = 0; @@ -763,15 +754,14 @@ int netxen_alloc_hw_resources(struct netxen_adapter *adapter) recv_ctx = &adapter->recv_ctx; tx_ring = adapter->tx_ring; - addr = pci_alloc_consistent(pdev, - sizeof(struct netxen_ring_ct
[PATCH 0/8] net: ethernet: reduce calls to memset(,0)
This patch series removes calls to memset(,0) that are redundant when used in conjunction with a zalloc call or by simple zero-assignment of structs. Robert Eshleman (8): net/mlx4: use kzalloc instead of kmalloc net/mlxsw: use pci_zalloc_consistent instead of pci_alloc_consistent tlan: use pci_zalloc instead of pci_alloc qed: remove unnecessary memsets at12: use pci_zalloc instead of pci_alloc netxen: remove unnecessary memset(,0) calls net: seeq: replace kmalloc / memset(,0) with kzalloc net: ethernet: ixp4xx_eth: remove memset(,0) with zalloc drivers/net/ethernet/atheros/atlx/atl2.c | 5 +- drivers/net/ethernet/mellanox/mlx4/cmd.c | 1 - drivers/net/ethernet/mellanox/mlx4/en_rx.c| 3 +- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 +- .../ethernet/qlogic/netxen/netxen_nic_ctx.c | 36 -- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 4 +- drivers/net/ethernet/qlogic/qed/qed_hw.c | 3 +- drivers/net/ethernet/qlogic/qed/qed_mcp.c | 70 ++- drivers/net/ethernet/seeq/ether3.c| 3 +- drivers/net/ethernet/ti/tlan.c| 9 ++- drivers/net/ethernet/xscale/ixp4xx_eth.c | 7 +- 11 files changed, 52 insertions(+), 96 deletions(-) -- 2.20.1
[PATCH v2 2/3] dt-bindings: vendor-prefix: add prefix for Lite-On Corp.
This patch adds a vendor-prefix for the Lite-On Semiconductor Corporation. Signed-off-by: Robert Eshleman --- Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 389508584f48..e487a5d95ba9 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -219,6 +219,7 @@ linaro Linaro Limited linksysBelkin International, Inc. (Linksys) linux Linux-specific binding linx Linx Technologies +liteon Lite-On Semiconductor Corporation lltc Linear Technology Corporation logicpdLogic PD, Inc. lsiLSI Corp. (LSI Logic) -- 2.20.1
[PATCH v2 1/3] iio: light: Add driver for ap3216c
This patch adds support for the ap3216c ambient light and proximity sensor. Supported features include: * Illuminance (lux) * Proximity (raw) * IR (raw) * Rising/falling threshold events for illuminance and proximity * Calibration scale for illuminance * Calibration bias for proximity Signed-off-by: Robert Eshleman --- Changes in v2: - Add mutex protection in IRQ handler - Support interrupt clearing for PS and ALS separately - Mask away reserved bits when reading device registers - Use regmap_bulk_read and regmap_bulk_write when possible - Style cleanup drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/ap3216c.c | 809 3 files changed, 821 insertions(+) create mode 100644 drivers/iio/light/ap3216c.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 36f458433480..74688d19beb1 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -41,6 +41,17 @@ config AL3320A To compile this driver as a module, choose M here: the module will be called al3320a. +config AP3216C + tristate "AP3216C Ambient Light and Proximity sensor" + select REGMAP_I2C + depends on I2C + help + Say Y here to build a driver for the AP3216C Ambient Light and + Proximity sensor. + + To compile this driver as a module, choose M here: the + module will be called ap3216c. + config APDS9300 tristate "APDS9300 ambient light sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 286bf3975372..7d2f8fa0f30d 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311)+= adjd_s311.o obj-$(CONFIG_AL3320A) += al3320a.o +obj-$(CONFIG_AP3216C) += ap3216c.o obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_APDS9960) += apds9960.o obj-$(CONFIG_BH1750) += bh1750.o diff --git a/drivers/iio/light/ap3216c.c b/drivers/iio/light/ap3216c.c new file mode 100644 index ..aaa319b932e6 --- /dev/null +++ b/drivers/iio/light/ap3216c.c @@ -0,0 +1,809 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AP3216C Ambient Light and Infrared Proximity Sensor + * + * Copyright (c) 2019, Robert Eshleman. + * + * Datasheet: https://pdf-datasheet-datasheet.netdna-ssl.com/pdf-down/A/P/3/AP3216C-LITE-ON.pdf + * + * 7-bit I2C slave address 0x1E + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AP3216C_DRV_NAME "ap3216c" + +/* register addresses */ +#define AP3216C_SYS 0x0 +#define AP3216C_INT_STATUS 0x01 +#define AP3216C_INT_CLR 0x02 +#define AP3216C_IR_DATA_LO 0x0A +#define AP3216C_IR_DATA_HI 0x0B +#define AP3216C_ALS_DATA_LO 0x0C +#define AP3216C_ALS_DATA_HI 0x0D +#define AP3216C_PS_DATA_LO 0x0E +#define AP3216C_PS_DATA_HI 0x0F +#define AP3216C_ALS_CFG 0x10 +#define AP3216C_ALS_CALIB 0x19 +#define AP3216C_ALS_LO_THR_LO 0x1A +#define AP3216C_ALS_LO_THR_HI 0x1B +#define AP3216C_ALS_HI_THR_LO 0x1C +#define AP3216C_ALS_HI_THR_HI 0x1D +#define AP3216C_PS_CFG 0x20 +#define AP3216C_PS_CALIB_LO 0x28 +#define AP3216C_PS_CALIB_HI 0x29 +#define AP3216C_PS_LO_THR_LO 0x2A +#define AP3216C_PS_LO_THR_HI 0x2B +#define AP3216C_PS_HI_THR_LO 0x2C +#define AP3216C_PS_HI_THR_HI 0x2D + +/* SYS_MODE mask and config value */ +#define AP3216C_SYS_MODE_ALS_PS 0x3 + +/* INT_STATUS masks and config value */ +#define AP3216C_INT_STATUS_ALS_MASK BIT(0) +#define AP3216C_INT_STATUS_PS_MASK BIT(1) +#define AP3216C_INT_STATUS_CLR GENMASK(1, 0) +#define AP3216C_INT_ALS_CLR BIT(0) +#define AP3216C_INT_PS_CLR BIT(1) +#define AP3216C_INT_CLR_MANUAL 1 + +/* IR_DATA mask/shift */ +#define AP3216C_IR_DATA_LO_MASK GENMASK(1, 0) +#define AP3216C_IR_DATA_HI_SHIFT 2 + +/* ALS_DATA shift and fractional helper */ +#define AP3216C_ALS_DATA_HI_SHIFT 8 +#define AP3216C_ALS_DATA_DENOM 10 + +/* ALS_CALIB masks/shifts */ +#define AP3216C_ALS_CALIB_INT_MASK GENMASK(7, 6) +#define AP3216C_ALS_CALIB_INT_SHIFT 6 +#define AP3216C_ALS_CALIB_DEC_MASK GENMASK(5, 0) + +/* PS_DATA shifts/masks/bits */ +#define AP3216C_PS_DATA_LO_MASK GENMASK(3, 0) +#define AP3216C_PS_DATA_LO_IR_OF BIT(6) +#define AP3216C_PS_DATA_HI_MASK GENMASK(5, 0) +#define AP3216C_PS_DATA_HI_SHIFT 4 +#define AP3216C_PS_DATA_HI_IR_OF BIT(6) + +/* ALS_CFG masks */ +#define AP3216C_ALS_CFG_GAIN_MASK GENMASK(5, 4) +#define AP3216C_ALS_CFG_GAIN_SHIFT 4 + +/* ALS_CALIB shifts */ +#define AP3216C_ALS_CALIB_INT_SHIFT 6 + +/* ALS_HI_THR masks and shifts */ +#define AP3216C_ALS_HI_THR_LO_MASK GENMASK(7, 0) +#define AP3216C_ALS_HI_THR_HI_SHIFT 8 +#define AP3216C_ALS_HI_THR_HI_MASK GENMASK(16, 8) +#define AP3216C_ALS_HI_THR_HI_READ_MASK GENMASK(7, 0) +#define AP3216C_ALS_HI_THR_HI_SHIFT 8 + +#define AP3216C_ALS_THR_HI_SHIF
[PATCH v2 3/3] dt-bindings: iio: light: Add ap3216c
Adds device tree bindings for the ap3216c ambient light and proximity sensor. Signed-off-by: Robert Eshleman --- .../devicetree/bindings/iio/light/ap3216c.txt | 22 +++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ap3216c.txt diff --git a/Documentation/devicetree/bindings/iio/light/ap3216c.txt b/Documentation/devicetree/bindings/iio/light/ap3216c.txt new file mode 100644 index ..c5ae80c79dd8 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/ap3216c.txt @@ -0,0 +1,22 @@ +* AP3216C Ambient Light and Proximity Sensor + +Required properties: + - compatible: should be "liteon,ap3216c" + - reg: the I2C address of the sensor (default is <0x1e>) + +Optional properties: + - interrupts: interrupt mapping for GPIO IRQ. Should be configured with +IRQ_TYPE_EDGE_FALLING. + +Refer to interrupt-controller/interrupts.txt for generic interrupt client +node bindings. + +Example: + +light-sensor@1e { + compatible = "liteon,ap3216c"; + reg = <0x1e>; + + interrupt-parent = <&gpio1>; + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; +}; -- 2.20.1
Re: [PATCH 1/3] iio: light: Add driver for ap3216c
Hey Peter, Thanks for the feedback. I have a question regarding INFO_SCALE and the calibration scale/bias below. Thanks for the feedback, it's much appreciated. On Mon, Feb 11, 2019 at 03:58:27PM +0100, Peter Meerwald-Stadler wrote: > On Sun, 10 Feb 2019, Robert Eshleman wrote: > > > This patch adds support for the ap3216c ambient light and proximity > > sensor. > > comments below > > > Supported features include: > > > > * Illuminance (lux) > > * Proximity (raw) > > * IR (raw) > > * Rising/falling threshold events for illuminance and proximity > > * Calibration scale for illuminance > > * Calibration bias for proximity > > > > Signed-off-by: Robert Eshleman > > --- > > drivers/iio/light/Kconfig | 11 + > > drivers/iio/light/Makefile | 1 + > > drivers/iio/light/ap3216c.c | 793 > > 3 files changed, 805 insertions(+) > > create mode 100644 drivers/iio/light/ap3216c.c > > > > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig > > index 36f458433480..74688d19beb1 100644 > > --- a/drivers/iio/light/Kconfig > > +++ b/drivers/iio/light/Kconfig > > @@ -41,6 +41,17 @@ config AL3320A > > To compile this driver as a module, choose M here: the > > module will be called al3320a. > > > > +config AP3216C > > + tristate "AP3216C Ambient Light and Proximity sensor" > > + select REGMAP_I2C > > + depends on I2C > > + help > > + Say Y here to build a driver for the AP3216C Ambient Light and > > + Proximity sensor. > > + > > + To compile this driver as a module, choose M here: the > > + module will be called ap3216c. > > + > > config APDS9300 > > tristate "APDS9300 ambient light sensor" > > depends on I2C > > diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile > > index 286bf3975372..7d2f8fa0f30d 100644 > > --- a/drivers/iio/light/Makefile > > +++ b/drivers/iio/light/Makefile > > @@ -7,6 +7,7 @@ > > obj-$(CONFIG_ACPI_ALS) += acpi-als.o > > obj-$(CONFIG_ADJD_S311)+= adjd_s311.o > > obj-$(CONFIG_AL3320A) += al3320a.o > > +obj-$(CONFIG_AP3216C) += ap3216c.o > > obj-$(CONFIG_APDS9300) += apds9300.o > > obj-$(CONFIG_APDS9960) += apds9960.o > > obj-$(CONFIG_BH1750) += bh1750.o > > diff --git a/drivers/iio/light/ap3216c.c b/drivers/iio/light/ap3216c.c > > new file mode 100644 > > index ..12802b45c01c > > --- /dev/null > > +++ b/drivers/iio/light/ap3216c.c > > @@ -0,0 +1,793 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * AP3216C Ambient Light and Infrared Proximity Sensor > > + * > > + * Copyright (c) 2019, Robert Eshleman. > > + * > > + * Datasheet: > > https://pdf-datasheet-datasheet.netdna-ssl.com/pdf-down/A/P/3/AP3216C-LITE-ON.pdf > > + * > > + * 7-bit I2C slave address 0x1E > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define AP3216C_DRV_NAME "ap3216c" > > + > > +/* register addresses */ > > +#define AP3216C_SYS 0x0 > > +#define AP3216C_INT_STATUS 0x01 > > +#define AP3216C_INT_CLR 0x02 > > +#define AP3216C_IR_DATA_LO 0x0A > > +#define AP3216C_IR_DATA_HI 0x0B > > +#define AP3216C_ALS_DATA_LO 0x0C > > +#define AP3216C_ALS_DATA_HI 0x0D > > +#define AP3216C_PS_DATA_LO 0x0E > > +#define AP3216C_PS_DATA_HI 0x0F > > +#define AP3216C_ALS_CFG 0x10 > > +#define AP3216C_ALS_CALIB 0x19 > > +#define AP3216C_ALS_LO_THR_LO 0x1A > > +#define AP3216C_ALS_LO_THR_HI 0x1B > > +#define AP3216C_ALS_HI_THR_LO 0x1C > > +#define AP3216C_ALS_HI_THR_HI 0x1D > > +#define AP3216C_PS_CFG 0x20 > > +#define AP3216C_PS_CALIB_LO 0x28 > > +#define AP3216C_PS_CALIB_HI 0x29 > > +#define AP3216C_PS_LO_THR_LO 0x2A > > +#define AP3216C_PS_LO_THR_HI 0x2B > > +#define AP3216C_PS_HI_THR_LO 0x2C > > +#define AP3216C_PS_HI_THR_HI 0x2D > > + > > +/* SYS_MODE mask and config value */ > > +#define AP3216C_SYS_MODE_ALS_PS GENMASK(1, 0) > > +#define AP3216C_SYS_MODE_ALS_ONLY 0x01 > > + > > +/* INT_STATUS masks and config value */ > > +#define AP3216C_INT_STATUS_ALS_MASK 1 > > +#define AP3216C_INT_STATUS_PS_MASK (1 << 1) > > use BIT()? Got it. > > > +#define AP321
Re: [PATCH 1/3] iio: light: Add driver for ap3216c
On Tue, Feb 12, 2019 at 08:47:30PM +, Jonathan Cameron wrote: > On Mon, 11 Feb 2019 17:30:18 -0500 > Sven Van Asbroeck wrote: > > > On Mon, Feb 11, 2019 at 4:27 PM Jonathan Cameron wrote: > > > > > > Agreed. Or potentially just use regmap_bulk_read and rely on > > > the regmap internal locking to do it for you. > > > > Neat solution. But it may only work correctly iff regmap_bulk_read() > > reads the low > > address first. I'm not sure if this function has that guarantee. If > > somebody changes > > the read order, the driver will break. But I think I'm being overly > > paranoid here :) > > Good question on whether it is guaranteed to read in increasing register > order (I didn't actually check the addresses are in increasing order > but assume they are or you would have pointed that out ;) > > That strikes me as behaviour that should probably be documented as long > as it is true currently. > > > > > > So yes, it's more than possible that userspace won't get the same number > > > of events as samples taken over the limit, but I don't know why we care. > > > We can about missing a threshold being passed entirely, not about knowing > > > how many samples we were above it for. > > > > I suspect that we run a small risk of losing an event, like so: > > > > PS (12.5 ms) > > --> interrupt -> iio event > More interesting if this one never happened, so we got a one off proximity > event missed. > > > ALS (100 ms) > > --> interrupt -> iio event > > PS (12.5 ms) > > --> interrupt = no iio event generated > > ALS (100 ms) > > --> interrupt -> iio event > > > > To see why, imagine that the scheduler decides to move away from the > > threaded interrupt > > handler right before ap3216c_clear_int(). Say 20ms, which I know is a > > lng time, > > but bear with me, the point is that it _could_ happen as we're not a RTOS. > > > > static irqreturn_t ap3216c_event_handler(int irq, void *p) > > { > > /* imagine ALS interrupt came in, INT_STATUS is 0b01 */ > > regmap_read(data->regmap, AP3216C_INT_STATUS, &status); > > if (status & mask1) iio_push_event(PROX); > > if (status & mask2) iio_push_event(LIGHT); > > > > /* imagine schedule happens here */ > > msleep(20); > > /* while we were not running, PS interrupt came in > >INT_STATUS is now 0b11 > >yet no new interrupt is generated, as we are ONESHOT > > */ > > ap3216c_clear_int(data); > > /* clears both bits, interrupt line goes low. > > knowledge that the PS interrupt came in is now lost */ > > } > > > > Not sure if that's acceptable driver behaviour. In real life it > > probably wouldn't matter much, > > except for occasional added latency maybe ? > Good point, I'd missed that a single clear was clearing both bits > rather than just the one we thought had fired. > > If we clear just the right one, (which I think we can do from > the datasheet > "1: Software clear after writing 1 into address 0x01 each bit#" > However the code isn't writing a 3 in that clear, so I'm not > sure if the datasheet is correct or not... > > and it is a level interrupt (which I think it is?) then we would > be safe against this miss. > > If either we can only globally clear or it's not a level interrupt > there isn't much we can do to avoid a miss, it's just a bad hardware > design. This totally makes sense, obviously something I had missed. I think you are right, if each INT bit is cleared individually, then that second event won't be lost. I'll take a closer look at the ideas put forth by you and Sven here on using mutex on some of the other cases (such as the write_event_config vs event_handler race condition) and put those into v2. Thanks again for all the constructive feedback. -Bobby
Re: [PATCH 1/3] iio: light: Add driver for ap3216c
On Mon, Feb 11, 2019 at 02:29:58PM -0500, Sven Van Asbroeck wrote: > On Sun, Feb 10, 2019 at 3:39 PM Robert Eshleman > wrote: > > > > This patch adds support for the ap3216c ambient light and proximity > > sensor. > > PS > > Why not use the chip in the mode where the interrupt is automatically cleared > by > reading the data? This could work if you read the data in the > interrupt routine, store > it in a buffer, then send the event to iio. Then when userspace wants > to read out the > value, don't actually touch the hardware, but return the buffered value. > > I don't think you then need any synchronization primitives to > accomplish this, such as > mutexes, spin locks, etc. Because the interrupt routine is single-threaded. > > You don't even need a memory barrier for the buffered value, > because the iio core uses a waitqueue internally, which automatically issues > an mb(). As far as I know. Hey Sven, First, thank you for the feedback. I had initially went with a similar design, but there is the case in which the interrupt fires and then before the status register is read by the handler a user process reads the data and clears the interrupt. When the handler continues execution it will read a zero status and return IRQ_NONE. My understanding of how Linux handles IRQ_NONE is pretty poor, but I felt that this behavior is incorrect even if inconsequential. This could be avoided by doing a status register read with every data read, and buffering that as well, but then we lose the benefit altogether by increasing I2C reads. In the approach you describe here, it seems like that would work if this driver wasn't supporting shared interrupts. In the case that a user-space read happens to clear the interrupt before the handler reads the status register, I think we would end up falsely returning IRQ_NONE. Is my understanding of this correct? It's very possible I'm misunderstanding IRQ_NONE and shared interrupts. Again, thank you for the feedback. -Bobby
[PATCH 2/3] dt-bindings: vendor-prefix: add prefix for Lite-On Corp.
This patch adds a vendor-prefix for the Lite-On Semiconductor Corporation. Signed-off-by: Robert Eshleman --- Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 389508584f48..e487a5d95ba9 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -219,6 +219,7 @@ linaro Linaro Limited linksysBelkin International, Inc. (Linksys) linux Linux-specific binding linx Linx Technologies +liteon Lite-On Semiconductor Corporation lltc Linear Technology Corporation logicpdLogic PD, Inc. lsiLSI Corp. (LSI Logic) -- 2.20.1
[PATCH 3/3] dt-bindings: iio: light: Add ap3216c
Adds device tree bindings for the ap3216c ambient light and proximity sensor. Signed-off-by: Robert Eshleman --- .../devicetree/bindings/iio/light/ap3216c.txt | 22 +++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ap3216c.txt diff --git a/Documentation/devicetree/bindings/iio/light/ap3216c.txt b/Documentation/devicetree/bindings/iio/light/ap3216c.txt new file mode 100644 index ..c5ae80c79dd8 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/ap3216c.txt @@ -0,0 +1,22 @@ +* AP3216C Ambient Light and Proximity Sensor + +Required properties: + - compatible: should be "liteon,ap3216c" + - reg: the I2C address of the sensor (default is <0x1e>) + +Optional properties: + - interrupts: interrupt mapping for GPIO IRQ. Should be configured with +IRQ_TYPE_EDGE_FALLING. + +Refer to interrupt-controller/interrupts.txt for generic interrupt client +node bindings. + +Example: + +light-sensor@1e { + compatible = "liteon,ap3216c"; + reg = <0x1e>; + + interrupt-parent = <&gpio1>; + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; +}; -- 2.20.1
[PATCH 1/3] iio: light: Add driver for ap3216c
This patch adds support for the ap3216c ambient light and proximity sensor. Supported features include: * Illuminance (lux) * Proximity (raw) * IR (raw) * Rising/falling threshold events for illuminance and proximity * Calibration scale for illuminance * Calibration bias for proximity Signed-off-by: Robert Eshleman --- drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/ap3216c.c | 793 3 files changed, 805 insertions(+) create mode 100644 drivers/iio/light/ap3216c.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 36f458433480..74688d19beb1 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -41,6 +41,17 @@ config AL3320A To compile this driver as a module, choose M here: the module will be called al3320a. +config AP3216C + tristate "AP3216C Ambient Light and Proximity sensor" + select REGMAP_I2C + depends on I2C + help + Say Y here to build a driver for the AP3216C Ambient Light and + Proximity sensor. + + To compile this driver as a module, choose M here: the + module will be called ap3216c. + config APDS9300 tristate "APDS9300 ambient light sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 286bf3975372..7d2f8fa0f30d 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311)+= adjd_s311.o obj-$(CONFIG_AL3320A) += al3320a.o +obj-$(CONFIG_AP3216C) += ap3216c.o obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_APDS9960) += apds9960.o obj-$(CONFIG_BH1750) += bh1750.o diff --git a/drivers/iio/light/ap3216c.c b/drivers/iio/light/ap3216c.c new file mode 100644 index ..12802b45c01c --- /dev/null +++ b/drivers/iio/light/ap3216c.c @@ -0,0 +1,793 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AP3216C Ambient Light and Infrared Proximity Sensor + * + * Copyright (c) 2019, Robert Eshleman. + * + * Datasheet: https://pdf-datasheet-datasheet.netdna-ssl.com/pdf-down/A/P/3/AP3216C-LITE-ON.pdf + * + * 7-bit I2C slave address 0x1E + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AP3216C_DRV_NAME "ap3216c" + +/* register addresses */ +#define AP3216C_SYS 0x0 +#define AP3216C_INT_STATUS 0x01 +#define AP3216C_INT_CLR 0x02 +#define AP3216C_IR_DATA_LO 0x0A +#define AP3216C_IR_DATA_HI 0x0B +#define AP3216C_ALS_DATA_LO 0x0C +#define AP3216C_ALS_DATA_HI 0x0D +#define AP3216C_PS_DATA_LO 0x0E +#define AP3216C_PS_DATA_HI 0x0F +#define AP3216C_ALS_CFG 0x10 +#define AP3216C_ALS_CALIB 0x19 +#define AP3216C_ALS_LO_THR_LO 0x1A +#define AP3216C_ALS_LO_THR_HI 0x1B +#define AP3216C_ALS_HI_THR_LO 0x1C +#define AP3216C_ALS_HI_THR_HI 0x1D +#define AP3216C_PS_CFG 0x20 +#define AP3216C_PS_CALIB_LO 0x28 +#define AP3216C_PS_CALIB_HI 0x29 +#define AP3216C_PS_LO_THR_LO 0x2A +#define AP3216C_PS_LO_THR_HI 0x2B +#define AP3216C_PS_HI_THR_LO 0x2C +#define AP3216C_PS_HI_THR_HI 0x2D + +/* SYS_MODE mask and config value */ +#define AP3216C_SYS_MODE_ALS_PS GENMASK(1, 0) +#define AP3216C_SYS_MODE_ALS_ONLY 0x01 + +/* INT_STATUS masks and config value */ +#define AP3216C_INT_STATUS_ALS_MASK 1 +#define AP3216C_INT_STATUS_PS_MASK (1 << 1) +#define AP3216C_INT_STATUS_CLR GENMASK(1, 0) +#define AP3216C_INT_CLR_MANUAL 1 + +/* IR_DATA mask/shift */ +#define AP3216C_IR_DATA_LO_MASK GENMASK(1, 0) +#define AP3216C_IR_DATA_HI_SHIFT 2 + +/* ALS_DATA shift and fractional helper */ +#define AP3216C_ALS_DATA_HI_SHIFT 8 +#define AP3216C_ALS_DATA_DENOM 10 + +/* ALS_CALIB masks/shifts */ +#define AP3216C_ALS_CALIB_INT_MASK GENMASK(7, 6) +#define AP3216C_ALS_CALIB_INT_SHIFT 6 +#define AP3216C_ALS_CALIB_DEC_MASK GENMASK(5, 0) + +/* PS_DATA shifts/masks/bits */ +#define AP3216C_PS_DATA_LO_MASK GENMASK(3, 0) +#define AP3216C_PS_DATA_LO_IR_OF BIT(6) +#define AP3216C_PS_DATA_HI_MASK GENMASK(5, 0) +#define AP3216C_PS_DATA_HI_SHIFT 4 +#define AP3216C_PS_DATA_HI_IR_OF BIT(6) + +/* ALS_CFG masks */ +#define AP3216C_ALS_CFG_GAIN_MASK GENMASK(5, 4) + +/* ALS_CALIB shifts */ +#define AP3216C_ALS_CALIB_INT_SHIFT 6 + +/* ALS_HI_THR masks and shifts */ +#define AP3216C_ALS_HI_THR_LO_MASK GENMASK(7, 0) +#define AP3216C_ALS_HI_THR_HI_SHIFT 8 +#define AP3216C_ALS_HI_THR_HI_MASK GENMASK(7, 4) +#define AP3216C_ALS_HI_THR_HI_SHIFT 8 + +/* ALS_LO_THR masks and shifts */ +#define AP3216C_ALS_LO_THR_LO_MASK GENMASK(3, 0) +#define AP3216C_ALS_LO_THR_HI_MASK GENMASK(7, 4) +#define AP3216C_ALS_LO_THR_HI_SHIFT 8 + +/* PS_CFG reg mask/shift/bit values */ +#define AP3216C_PS_CFG_GAIN_MASK GENMASK(3, 2) +#define AP3216C_PS_CFG_GAIN_SHIFT 2 +#define AP3216C_PS_CFG_GAIN(val) \ + (1 << ((val & AP3216C_PS_CFG_GAIN_MASK) >> AP3216C_PS_C
[PATCH v4 2/2] dt-bindings: iio: light: Add max44009
Adds device tree bindings for the max44009 light sensor. Signed-off-by: Robert Eshleman --- Changes to v4: - Add subsystem to subject line - Change node name to be 'light-sensor' - Clean up style Changes to v3: - None Changes to v2: - Clean up style .../bindings/iio/light/max44009.txt | 25 +++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/max44009.txt diff --git a/Documentation/devicetree/bindings/iio/light/max44009.txt b/Documentation/devicetree/bindings/iio/light/max44009.txt new file mode 100644 index ..557297c86fba --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/max44009.txt @@ -0,0 +1,25 @@ +* MAX44009 Ambient Light Sensor + +Required properties: + +- compatible: should be "maxim,max44009" +- reg: the I2C address of the device (default is <0x4a>) + +Optional properties: + +- interrupts: interrupt mapping for GPIO IRQ. Should be configured with + IRQ_TYPE_EDGE_FALLING. + +Refer to interrupt-controller/interrupts.txt for generic interrupt client +node bindings. + +Example: + +max44009: light-sensor@4a { + compatible = "maxim,max44009"; + reg = <0x4a>; + + interrupt-parent = <&gpio1>; + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; +}; + -- 2.20.1
[PATCH v4 1/2] iio: light: add driver for MAX44009
The MAX44009 is a low-power ambient light sensor from Maxim Integrated. It differs from the MAX44000 in that it doesn't have proximity sensing and that it requires far less current (1 micro-amp vs 5 micro-amps). The register mapping and feature set between the two are different enough to require a new driver for the MAX44009. Developed and tested with a BeagleBone Black and UDOO Neo (i.MX6SX) Supported features: * Reading lux (processed value) * Rising and falling illuminance threshold events * Configuring integration time https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf Signed-off-by: Robert Eshleman --- Changes to v4: - Reformat subject line - Clean up whitespace Changes to v3: - Remove unnecessary mask when setting integration time - Return IRQ_NONE in IRQ handler when interrupt not from this device - Fix incorrect register usage when reading lux low byte - Clean up style Changes to v2: - Remove unnecessary mutex locking - Remove unnecessary triggered buffer support - Remove unnecessary wrapper functions for smbus reads and writes - Remove scale avail support - Use constant scale to provide processed values instead of raw - Remove IRQ_NONE return for non-shared IRQ - Clean up style drivers/iio/light/Kconfig| 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/max44009.c | 555 +++ 3 files changed, 566 insertions(+) create mode 100644 drivers/iio/light/max44009.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 36f458433480..5190eacfeb0a 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -299,6 +299,16 @@ config MAX44000 To compile this driver as a module, choose M here: the module will be called max44000. +config MAX44009 + tristate "MAX44009 Ambient Light Sensor" + depends on I2C + help +Say Y here if you want to build support for Maxim Integrated's +MAX44009 ambient light sensor device. + +To compile this driver as a module, choose M here: +the module will be called max44009. + config OPT3001 tristate "Texas Instruments OPT3001 Light Sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 286bf3975372..e40794fbb435 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_LTR501) += ltr501.o obj-$(CONFIG_LV0104CS) += lv0104cs.o obj-$(CONFIG_MAX44000) += max44000.o +obj-$(CONFIG_MAX44009) += max44009.o obj-$(CONFIG_OPT3001) += opt3001.o obj-$(CONFIG_PA12203001) += pa12203001.o obj-$(CONFIG_RPR0521) += rpr0521.o diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c new file mode 100644 index ..00ba15499638 --- /dev/null +++ b/drivers/iio/light/max44009.c @@ -0,0 +1,555 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * max44009.c - Support for MAX44009 Ambient Light Sensor + * + * Copyright (c) 2019 Robert Eshleman + * + * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf + * + * TODO: Support continuous mode and configuring from manual mode to + * automatic mode. + * + * Default I2C address: 0x4a + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX44009_DRV_NAME "max44009" + +/* Registers in datasheet order */ +#define MAX44009_REG_INT_STATUS 0x0 +#define MAX44009_REG_INT_EN 0x1 +#define MAX44009_REG_CFG 0x2 +#define MAX44009_REG_LUX_HI 0x3 +#define MAX44009_REG_LUX_LO 0x4 +#define MAX44009_REG_UPPER_THR 0x5 +#define MAX44009_REG_LOWER_THR 0x6 +#define MAX44009_REG_THR_TIMER 0x7 + +#define MAX44009_CFG_TIM_MASK GENMASK(2, 0) +#define MAX44009_CFG_MAN_MODE_MASK BIT(6) + +/* The maximum rising threshold for the max44009 */ +#define MAX44009_MAXIMUM_THRESHOLD 7520256 + +#define MAX44009_THRESH_EXP_MASK (0xf << 4) +#define MAX44009_THRESH_EXP_RSHIFT 4 +#define MAX44009_THRESH_MANT_LSHIFT 4 +#define MAX44009_THRESH_MANT_MASK 0xf + +#define MAX44009_UPPER_THR_MINIMUM 15 + +/* The max44009 always scales raw readings by 0.045 and is non-configurable */ +#define MAX44009_SCALE_NUMERATOR 45 +#define MAX44009_SCALE_DENOMINATOR 1000 + +/* The fixed-point fractional multiplier for de-scaling threshold values */ +#define MAX44009_FRACT_MULT 100 + +static const u32 max44009_int_time_ns_array[] = { + 8, + 4, + 2, + 1, + 5000, /* Manual mode only */ + 2500, /* Manual mode only */ + 1250, /* Manual mode only */ + 625, /* Manual mode only */ +}; + +static const char max44009_int_time_str[] = + "0.8 " + "0.4 " + "0.2 " + "0.1 " + "0.05 " + "0.025 " +
[PATCH v3 2/2] Add device tree binding documentation for MAX44009
This patch adds device tree documentation for the max44009 ambient light sensor. Signed-off-by: Robert Eshleman --- Changes to v3: - None Changes to v2: - Clean up style .../bindings/iio/light/max44009.txt | 25 +++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/max44009.txt diff --git a/Documentation/devicetree/bindings/iio/light/max44009.txt b/Documentation/devicetree/bindings/iio/light/max44009.txt new file mode 100644 index ..b287d7732e37 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/max44009.txt @@ -0,0 +1,25 @@ +* MAX44009 Ambient Light Sensor + +Required properties: + +- compatible: should be "maxim,max44009" +- reg: the I2C address of the device (default is <0x4a>) + +Optional properties: + +- interrupts: interrupt mapping for GPIO IRQ. Should be configured with + IRQ_TYPE_EDGE_FALLING. + +Refer to interrupt-controller/interrupts.txt for generic interrupt client +node bindings. + +Example: + +max44009: max44009@4a { + compatible = "maxim,max44009"; + reg = <0x4a>; + + interrupt-parent = <&gpio1>; + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; +}; + -- 2.20.1
[PATCH v3 1/2] Add driver support for MAX44009 light sensor
The MAX44009 is a low-power ambient light sensor from Maxim Integrated. It differs from the MAX44000 in that it doesn't have proximity sensing and that it requires far less current (1 micro-amp vs 5 micro-amps). The register mapping and feature set between the two are different enough to require a new driver for the MAX44009. Developed and tested with a BeagleBone Black and UDOO Neo (i.MX6SX) Supported features: * Reading lux (processed value) * Rising and falling illuminance threshold events * Configuring integration time https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf Signed-off-by: Robert Eshleman --- Changes to v3: - Remove unnecessary mask when setting integration time - Return IRQ_NONE in IRQ handler when interrupt not from this device - Fix incorrect register usage when reading lux low byte - Clean up style Changes to v2: - Remove unnecessary mutex locking - Remove unnecessary triggered buffer support - Remove unnecessary wrapper functions for smbus reads and writes - Remove scale avail support - Use constant scale to provide processed values instead of raw - Remove IRQ_NONE return for non-shared IRQ - Clean up style drivers/iio/light/Kconfig| 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/max44009.c | 555 +++ 3 files changed, 566 insertions(+) create mode 100644 drivers/iio/light/max44009.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 36f458433480..5190eacfeb0a 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -299,6 +299,16 @@ config MAX44000 To compile this driver as a module, choose M here: the module will be called max44000. +config MAX44009 + tristate "MAX44009 Ambient Light Sensor" + depends on I2C + help +Say Y here if you want to build support for Maxim Integrated's +MAX44009 ambient light sensor device. + +To compile this driver as a module, choose M here: +the module will be called max44009. + config OPT3001 tristate "Texas Instruments OPT3001 Light Sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 286bf3975372..e40794fbb435 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_LTR501) += ltr501.o obj-$(CONFIG_LV0104CS) += lv0104cs.o obj-$(CONFIG_MAX44000) += max44000.o +obj-$(CONFIG_MAX44009) += max44009.o obj-$(CONFIG_OPT3001) += opt3001.o obj-$(CONFIG_PA12203001) += pa12203001.o obj-$(CONFIG_RPR0521) += rpr0521.o diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c new file mode 100644 index ..fdbe2b840b02 --- /dev/null +++ b/drivers/iio/light/max44009.c @@ -0,0 +1,555 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * max44009.c - Support for MAX44009 Ambient Light Sensor + * + * Copyright (c) 2019 Robert Eshleman + * + * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf + * + * TODO: Support continuous mode and configuring from manual mode to + * automatic mode. + * + * Default I2C address: 0x4a + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX44009_DRV_NAME "max44009" + +/* Registers in datasheet order */ +#define MAX44009_REG_INT_STATUS 0x0 +#define MAX44009_REG_INT_EN 0x1 +#define MAX44009_REG_CFG 0x2 +#define MAX44009_REG_LUX_HI 0x3 +#define MAX44009_REG_LUX_LO 0x4 +#define MAX44009_REG_UPPER_THR 0x5 +#define MAX44009_REG_LOWER_THR 0x6 +#define MAX44009_REG_THR_TIMER 0x7 + +#define MAX44009_CFG_TIM_MASK GENMASK(2, 0) +#define MAX44009_CFG_MAN_MODE_MASK BIT(6) + +/* The maximum rising threshold for the max44009 */ +#define MAX44009_MAXIMUM_THRESHOLD 7520256 + +#define MAX44009_THRESH_EXP_MASK (0xf << 4) +#define MAX44009_THRESH_EXP_RSHIFT 4 +#define MAX44009_THRESH_MANT_LSHIFT 4 +#define MAX44009_THRESH_MANT_MASK 0xf + +#define MAX44009_UPPER_THR_MINIMUM 15 + +/* The max44009 always scales raw readings by 0.045 and is non-configurable */ +#define MAX44009_SCALE_NUMERATOR 45 +#define MAX44009_SCALE_DENOMINATOR 1000 + +/* The fixed-point fractional multiplier for de-scaling threshold values */ +#define MAX44009_FRACT_MULT 100 + +static const u32 max44009_int_time_ns_array[] = { + 8, + 4, + 2, + 1, + 5000, /* Manual mode only */ + 2500, /* Manual mode only */ + 1250, /* Manual mode only */ + 625, /* Manual mode only */ +}; + +static const char max44009_int_time_str[] = + "0.8 " + "0.4 " + "0.2 " + "0.1 " + "0.05 " + "0.025 " + "0.0125 " + "0.00625"; + +
[PATCH v2 2/2] Add device tree binding documentation for MAX44009
Signed-off-by: Robert Eshleman --- .../bindings/iio/light/max44009.txt | 25 +++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/max44009.txt diff --git a/Documentation/devicetree/bindings/iio/light/max44009.txt b/Documentation/devicetree/bindings/iio/light/max44009.txt new file mode 100644 index ..b287d7732e37 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/max44009.txt @@ -0,0 +1,25 @@ +* MAX44009 Ambient Light Sensor + +Required properties: + +- compatible: should be "maxim,max44009" +- reg: the I2C address of the device (default is <0x4a>) + +Optional properties: + +- interrupts: interrupt mapping for GPIO IRQ. Should be configured with + IRQ_TYPE_EDGE_FALLING. + +Refer to interrupt-controller/interrupts.txt for generic interrupt client +node bindings. + +Example: + +max44009: max44009@4a { + compatible = "maxim,max44009"; + reg = <0x4a>; + + interrupt-parent = <&gpio1>; + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; +}; + -- 2.20.1
[PATCH v2 1/2] Add driver support for MAX44009 light sensor
The MAX44009 is a low-power ambient light sensor from Maxim Integrated. It differs from the MAX44000 in that it doesn't have proximity sensing and that it requires far less current (1 micro-amp vs 5 micro-amps). The register mapping and feature set between the two are different enough to require a new driver for the MAX44009. Developed and tested with a BeagleBone Black and UDOO Neo (i.MX6SX) Supported features: * Reading lux (processed value) * Rising and falling illuminance threshold events * Configuring integration time https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf Signed-off-by: Robert Eshleman --- Changes to v2: - Remove unnecessary mutex locking - Remove unnecessary triggered buffer support - Remove unnecessary wrapper functions for smbus reads and writes - Remove scale avail support - Use constant scale to provide processed values instead of raw - Remove IRQ_NONE return for non-shared IRQ - Style cleanup drivers/iio/light/Kconfig| 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/max44009.c | 540 +++ 3 files changed, 551 insertions(+) create mode 100644 drivers/iio/light/max44009.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 36f458433480..5190eacfeb0a 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -299,6 +299,16 @@ config MAX44000 To compile this driver as a module, choose M here: the module will be called max44000. +config MAX44009 + tristate "MAX44009 Ambient Light Sensor" + depends on I2C + help +Say Y here if you want to build support for Maxim Integrated's +MAX44009 ambient light sensor device. + +To compile this driver as a module, choose M here: +the module will be called max44009. + config OPT3001 tristate "Texas Instruments OPT3001 Light Sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 286bf3975372..e40794fbb435 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_LTR501) += ltr501.o obj-$(CONFIG_LV0104CS) += lv0104cs.o obj-$(CONFIG_MAX44000) += max44000.o +obj-$(CONFIG_MAX44009) += max44009.o obj-$(CONFIG_OPT3001) += opt3001.o obj-$(CONFIG_PA12203001) += pa12203001.o obj-$(CONFIG_RPR0521) += rpr0521.o diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c new file mode 100644 index ..5294df629ec1 --- /dev/null +++ b/drivers/iio/light/max44009.c @@ -0,0 +1,540 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * max44009.c - Support for MAX44009 Ambient Light Sensor + * + * Copyright (c) 2019 Robert Eshleman + * + * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf + * + * TODO: Support continuous mode and configuring from manual mode to + * automatic mode. + * + * Default I2C address: 0x4a + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX44009_DRV_NAME "max44009" + +/* Registers in datasheet order */ +#define MAX44009_REG_INT_STATUS 0x0 +#define MAX44009_REG_INT_EN 0x1 +#define MAX44009_REG_CFG 0x2 +#define MAX44009_REG_LUX_HI 0x3 +#define MAX44009_REG_LUX_LO 0x4 +#define MAX44009_REG_UPPER_THR 0x5 +#define MAX44009_REG_LOWER_THR 0x6 +#define MAX44009_REG_THR_TIMER 0x7 + +#define MAX44009_CFG_TIM_MASK GENMASK(2, 0) +#define MAX44009_CFG_MAN_MODE_MASK BIT(6) + +/* The maximum raw rising threshold for the max44009 */ +#define MAX44009_MAXIMUM_THRESHOLD 7520256 + +#define MAX44009_THRESH_EXP_MASK (0xf << 4) +#define MAX44009_THRESH_EXP_RSHIFT 4 +#define MAX44009_THRESH_MANT_LSHIFT 4 +#define MAX44009_THRESH_MANT_MASK 0xf + +#define MAX44009_UPPER_THR_MINIMUM 15 + +/* The max44009 always scales raw readings by 0.045 and is non-configurable */ +#define MAX44009_SCALE_NUMERATOR 45 +#define MAX44009_SCALE_DENOMINATOR 1000 + +/* The fixed-point fractional multiplier for de-scaling threshold values */ +#define MAX44009_FRACT_MULT 100 + +static const u32 max44009_int_time_ns_array[] = { + 8, + 4, + 2, + 1, + 5000, /* Manual mode only */ + 2500, /* Manual mode only */ + 1250, /* Manual mode only */ + 625, /* Manual mode only */ +}; + +static const char max44009_int_time_str[] = + "0.8 " + "0.4 " + "0.2 " + "0.1 " + "0.05 " + "0.025 " + "0.0125 " + "0.00625"; + +struct max44009_data { + struct i2c_client *client; + struct mutex lock; +}; + +static const struct iio_event_spec max44009_event_spec[] = { + { + .type = IIO_EV_TYPE_THRESH, +
Re: [PATCH] iio: light: add driver support for MAX44009
On Sat, Jan 19, 2019 at 08:41:46PM +0100, Peter Meerwald-Stadler wrote: Hey Jonathon and Peter, First, thank you for the constructive and in-depth feedback. I have a question below regarding a section of code that will need to be protected against a race condition if future features are added. Mostly this email is just an ack that I've started working on the changes. Thanks again, Robert > On Sat, 19 Jan 2019, Jonathan Cameron wrote: > > some more comments from my side below... > > > On Wed, 16 Jan 2019 22:56:23 -0800 > > Robert Eshleman wrote: > > > > Hi Robert, > > > > Note I review drivers backwards, so comments may make more sense that > > way around. > > > > > The MAX44009 is a low-power ambient light sensor from Maxim Integrated. > > > It differs from the MAX44000 in that it doesn't have proximity sensing > > > and that > > > it requires far less current (1 micro-amp vs 5 micro-amps). The register > > > mapping and feature set between the two are different enough to require a > > > new > > > driver for the MAX44009. > > > > > > Developed and tested with a BeagleBone Black and UDOO Neo (i.MX6SX) > > > > > > Supported features: > > > > > > * Rising and falling illuminance threshold > > > events > > > > Not really on this one. You support using them as a trigger, which > > is not how threshold events should be handled in IIO. Please > > report them as events. This device doesn't seem to have > > a trigger that can be used in general, so you shouldn't provide > > one. > > > > Userspace can use the event to decide to do a read if it wants to > > follow the classic move the thresholds so as to detect big > > 'changes' in light intensity. > > > > Various other comments inline. Quite a bit of style cleanup > > needed as well, please check the kernel docs for coding style > > https://www.kernel.org/doc/Documentation/process/coding-style.rst > > > > Also take a look at other IIO drivers for the bits that are > > noted in there as varying across the kernel. > > > > Whilst there is quite a bit to work on in here yet, great to see > > support for this new part! Looking forward to v2. > > > > Jonathan > > After seeing your notes and looking closer at how userspace leverages triggers, I can see now how it does not make sense to let this device supply one. It is, as you mentioned, events that are the right fit for this device. > > > > > > * Illuminance triggered buffers > > > > > > * Integration time > > > > > > https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf > > > > > > Signed-off-by: Robert Eshleman > > > > > --- > > > .../bindings/iio/light/max44009.txt | 25 + > > > drivers/iio/light/Kconfig | 13 + > > > drivers/iio/light/Makefile| 1 + > > > drivers/iio/light/max44009.c | 696 ++ > > > 4 files changed, 735 insertions(+) > > > create mode 100644 > > > Documentation/devicetree/bindings/iio/light/max44009.txt > > > create mode 100644 drivers/iio/light/max44009.c > > > > > > diff --git a/Documentation/devicetree/bindings/iio/light/max44009.txt > > > b/Documentation/devicetree/bindings/iio/light/max44009.txt > > > new file mode 100644 > > > index ..220c2808dca1 > > > --- /dev/null > > > +++ b/Documentation/devicetree/bindings/iio/light/max44009.txt > > > @@ -0,0 +1,25 @@ > > > +* MAX44009 Ambient Light Sensor > > > + > > > +Required properties: > > > + > > > +- compatible: should be "maxim,max44009" > > > +- reg: the I2C address of the device (default is <0x4a>) > > > + > > > +Optional properties: > > > + > > > +- interrupts : interrupt mapping for GPIO IRQ. Should be configured with > > the space before the colon hurts my eyes > > > > + IRQ_TYPE_EDGE_FALLING. > > > + > > > +Refer to interrupt-controller/interrupts.txt for generic interrupt client > > > +node bindings. > > > + > > > +Example: > > > + > > > +max44009: max44009@4a { > > > + compatible = "maxim,max44009"; > > > + reg = <0x4a>; > > > + > > > + interrupt-parent = <&gpio1>; > > > + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; > > > +}; > > > + > &g
[PATCH] iio: light: add driver support for MAX44009
The MAX44009 is a low-power ambient light sensor from Maxim Integrated. It differs from the MAX44000 in that it doesn't have proximity sensing and that it requires far less current (1 micro-amp vs 5 micro-amps). The register mapping and feature set between the two are different enough to require a new driver for the MAX44009. Developed and tested with a BeagleBone Black and UDOO Neo (i.MX6SX) Supported features: * Rising and falling illuminance threshold events * Illuminance triggered buffers * Integration time https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf Signed-off-by: Robert Eshleman --- .../bindings/iio/light/max44009.txt | 25 + drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile| 1 + drivers/iio/light/max44009.c | 696 ++ 4 files changed, 735 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/max44009.txt create mode 100644 drivers/iio/light/max44009.c diff --git a/Documentation/devicetree/bindings/iio/light/max44009.txt b/Documentation/devicetree/bindings/iio/light/max44009.txt new file mode 100644 index ..220c2808dca1 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/max44009.txt @@ -0,0 +1,25 @@ +* MAX44009 Ambient Light Sensor + +Required properties: + +- compatible: should be "maxim,max44009" +- reg: the I2C address of the device (default is <0x4a>) + +Optional properties: + +- interrupts : interrupt mapping for GPIO IRQ. Should be configured with + IRQ_TYPE_EDGE_FALLING. + +Refer to interrupt-controller/interrupts.txt for generic interrupt client +node bindings. + +Example: + +max44009: max44009@4a { + compatible = "maxim,max44009"; + reg = <0x4a>; + + interrupt-parent = <&gpio1>; + interrupts = <17 IRQ_TYPE_EDGE_FALLING>; +}; + diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 36f458433480..cda544f1047d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -299,6 +299,19 @@ config MAX44000 To compile this driver as a module, choose M here: the module will be called max44000. +config MAX44009 + tristate "MAX44009 Ambient Light Sensor" + depends on I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select IIO_TRIGGERED_EVENT + help +Say Y here if you want to build support for Maxim Integrated's +MAX44009 ambient light sensor device. + +To compile this driver as a module, choose M here: +the module will be called max44009. + config OPT3001 tristate "Texas Instruments OPT3001 Light Sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 286bf3975372..e40794fbb435 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_LTR501) += ltr501.o obj-$(CONFIG_LV0104CS) += lv0104cs.o obj-$(CONFIG_MAX44000) += max44000.o +obj-$(CONFIG_MAX44009) += max44009.o obj-$(CONFIG_OPT3001) += opt3001.o obj-$(CONFIG_PA12203001) += pa12203001.o obj-$(CONFIG_RPR0521) += rpr0521.o diff --git a/drivers/iio/light/max44009.c b/drivers/iio/light/max44009.c new file mode 100644 index ..e15aa8eeb2f6 --- /dev/null +++ b/drivers/iio/light/max44009.c @@ -0,0 +1,696 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * max44009.c - Support for MAX44009 Ambient Light Sensor + * + * Copyright (c) 2019 Robert Eshleman + * + * 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. + * + * + * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf + * + * TODO: Support continuous mode and processed event value (IIO_EV_INFO_VALUE) + * + * Default I2C address: 0x4a + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX44009_DRV_NAME "max44009" +#define MAX44009_IRQ_NAME "max44009_event" + +/* Registers in datasheet order */ +#define MAX44009_REG_STATUS 0x0 +#define MAX44009_REG_ENABLE 0x1 +#define MAX44009_REG_CFG 0x2 +#define MAX44009_REG_LUX_HI 0x3 +#define MAX44009_REG_LUX_LO 0x4 +#define MAX44009_REG_UPPER_THR 0x5 +#define MAX44009_REG_LOWER_THR 0x6 +#define MAX44009_REG_THR_TIMER 0x7 + +#define MAX44009_INT_TIME_MASK (BIT(2) | BIT(1) | BIT(0)) +#define MAX44009_INT_TIME_SHIFT (0) + +#define MAX44009_MANUAL_MODE_MASK BIT(6) + +/* The maxmimum raw rising threshold for the max44009 */ +#define MAX44009_MAXIMUM_THRESHOLD 8355840 + +#define MAX44009_HI_NIBBLE(reg) (((reg) >> 4) & 0xf) +#define MAX4
[PATCH] staging: rtl8712: fix CamelCase in fw_priv struct
Rename fields in fw_priv struct from CamelCase to snake_case. Reported by checkpatch. Signed-off-by: Robert Eshleman --- drivers/staging/rtl8712/hal_init.c| 10 +- drivers/staging/rtl8712/rtl8712_hal.h | 8 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c index 7cdd609..4c6519c 100644 --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -100,11 +100,11 @@ static void fill_fwpriv(struct _adapter *padapter, struct fw_priv *pfwpriv) pfwpriv->rf_config = RTL8712_RFC_1T2R; } pfwpriv->mp_mode = (pregpriv->mp_mode == 1) ? 1 : 0; - pfwpriv->vcsType = pregpriv->vrtl_carrier_sense; /* 0:off 1:on 2:auto */ - pfwpriv->vcsMode = pregpriv->vcs_type; /* 1:RTS/CTS 2:CTS to self */ - /* default enable turboMode */ - pfwpriv->turboMode = ((pregpriv->wifi_test == 1) ? 0 : 1); - pfwpriv->lowPowerMode = pregpriv->low_power; + pfwpriv->vcs_type = pregpriv->vrtl_carrier_sense; /* 0:off 1:on 2:auto */ + pfwpriv->vcs_mode = pregpriv->vcs_type; /* 1:RTS/CTS 2:CTS to self */ + /* default enable turbo_mode */ + pfwpriv->turbo_mode = ((pregpriv->wifi_test == 1) ? 0 : 1); + pfwpriv->low_power_mode = pregpriv->low_power; } static void update_fwhdr(struct fw_hdr *pfwhdr, const u8 *pmappedfw) diff --git a/drivers/staging/rtl8712/rtl8712_hal.h b/drivers/staging/rtl8712/rtl8712_hal.h index 42f5197..66cc464 100644 --- a/drivers/staging/rtl8712/rtl8712_hal.h +++ b/drivers/staging/rtl8712/rtl8712_hal.h @@ -72,13 +72,13 @@ struct fw_priv { /*8-bytes alignment required*/ unsigned char regulatory_class_3; /*regulatory class bit map 3*/ unsigned char rfintfs;/* 0:SWSI, 1:HWSI, 2:HWPI*/ unsigned char def_nettype; - unsigned char turboMode; - unsigned char lowPowerMode;/* 0: normal mode, 1: low power mode*/ + unsigned char turbo_mode; + unsigned char low_power_mode;/* 0: normal mode, 1: low power mode*/ /*--- long word 2 */ unsigned char lbk_mode; /*0x00: normal, 0x03: MACLBK, 0x01: PHYLBK*/ unsigned char mp_mode; /* 1: for MP use, 0: for normal driver */ - unsigned char vcsType; /* 0:off 1:on 2:auto */ - unsigned char vcsMode; /* 1:RTS/CTS 2:CTS to self */ + unsigned char vcs_type; /* 0:off 1:on 2:auto */ + unsigned char vcs_mode; /* 1:RTS/CTS 2:CTS to self */ unsigned char rsvd022; unsigned char rsvd023; unsigned char rsvd024; -- 2.7.4